]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.3.1-201204021758.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.1-201204021758.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 0c083c5..9c2512a 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -5,6 +5,7 @@
6 *.cis
7 *.cpio
8 *.csp
9 +*.dbg
10 *.dsp
11 *.dvi
12 *.elf
13 @@ -14,6 +15,7 @@
14 *.gcov
15 *.gen.S
16 *.gif
17 +*.gmo
18 *.grep
19 *.grp
20 *.gz
21 @@ -48,9 +50,11 @@
22 *.tab.h
23 *.tex
24 *.ver
25 +*.vim
26 *.xml
27 *.xz
28 *_MODULES
29 +*_reg_safe.h
30 *_vga16.c
31 *~
32 \#*#
33 @@ -69,6 +73,7 @@ Image
34 Module.markers
35 Module.symvers
36 PENDING
37 +PERF*
38 SCCS
39 System.map*
40 TAGS
41 @@ -92,19 +97,24 @@ bounds.h
42 bsetup
43 btfixupprep
44 build
45 +builtin-policy.h
46 bvmlinux
47 bzImage*
48 capability_names.h
49 capflags.c
50 classlist.h*
51 +clut_vga16.c
52 +common-cmds.h
53 comp*.log
54 compile.h*
55 conf
56 config
57 config-*
58 config_data.h*
59 +config.c
60 config.mak
61 config.mak.autogen
62 +config.tmp
63 conmakehash
64 consolemap_deftbl.c*
65 cpustr.h
66 @@ -115,9 +125,11 @@ devlist.h*
67 dnotify_test
68 docproc
69 dslm
70 +dtc-lexer.lex.c
71 elf2ecoff
72 elfconfig.h*
73 evergreen_reg_safe.h
74 +exception_policy.conf
75 fixdep
76 flask.h
77 fore200e_mkfirm
78 @@ -125,12 +137,15 @@ fore200e_pca_fw.c*
79 gconf
80 gconf.glade.h
81 gen-devlist
82 +gen-kdb_cmds.c
83 gen_crc32table
84 gen_init_cpio
85 generated
86 genheaders
87 genksyms
88 *_gray256.c
89 +hash
90 +hid-example
91 hpet_example
92 hugepage-mmap
93 hugepage-shm
94 @@ -145,7 +160,7 @@ int32.c
95 int4.c
96 int8.c
97 kallsyms
98 -kconfig
99 +kern_constants.h
100 keywords.c
101 ksym.c*
102 ksym.h*
103 @@ -153,7 +168,7 @@ kxgettext
104 lkc_defs.h
105 lex.c
106 lex.*.c
107 -linux
108 +lib1funcs.S
109 logo_*.c
110 logo_*_clut224.c
111 logo_*_mono.c
112 @@ -165,14 +180,15 @@ machtypes.h
113 map
114 map_hugetlb
115 maui_boot.h
116 -media
117 mconf
118 +mdp
119 miboot*
120 mk_elfconfig
121 mkboot
122 mkbugboot
123 mkcpustr
124 mkdep
125 +mkpiggy
126 mkprep
127 mkregtable
128 mktables
129 @@ -208,6 +224,7 @@ r300_reg_safe.h
130 r420_reg_safe.h
131 r600_reg_safe.h
132 recordmcount
133 +regdb.c
134 relocs
135 rlim_names.h
136 rn50_reg_safe.h
137 @@ -218,6 +235,7 @@ setup
138 setup.bin
139 setup.elf
140 sImage
141 +slabinfo
142 sm_tbl*
143 split-include
144 syscalltab.h
145 @@ -228,6 +246,7 @@ tftpboot.img
146 timeconst.h
147 times.h*
148 trix_boot.h
149 +user_constants.h
150 utsrelease.h*
151 vdso-syms.lds
152 vdso.lds
153 @@ -245,7 +264,9 @@ vmlinux
154 vmlinux-*
155 vmlinux.aout
156 vmlinux.bin.all
157 +vmlinux.bin.bz2
158 vmlinux.lds
159 +vmlinux.relocs
160 vmlinuz
161 voffset.h
162 vsyscall.lds
163 @@ -253,9 +274,11 @@ vsyscall_32.lds
164 wanxlfw.inc
165 uImage
166 unifdef
167 +utsrelease.h
168 wakeup.bin
169 wakeup.elf
170 wakeup.lds
171 zImage*
172 zconf.hash.c
173 +zconf.lex.c
174 zoffset.h
175 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
176 index d99fd9c..8689fef 100644
177 --- a/Documentation/kernel-parameters.txt
178 +++ b/Documentation/kernel-parameters.txt
179 @@ -1977,6 +1977,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
180 the specified number of seconds. This is to be used if
181 your oopses keep scrolling off the screen.
182
183 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
184 + virtualization environments that don't cope well with the
185 + expand down segment used by UDEREF on X86-32 or the frequent
186 + page table updates on X86-64.
187 +
188 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
189 +
190 pcbit= [HW,ISDN]
191
192 pcd. [PARIDE]
193 diff --git a/Makefile b/Makefile
194 index 026a227..22ef9bc 100644
195 --- a/Makefile
196 +++ b/Makefile
197 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
198
199 HOSTCC = gcc
200 HOSTCXX = g++
201 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
202 -HOSTCXXFLAGS = -O2
203 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
204 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
205 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
206
207 # Decide whether to build built-in, modular, or both.
208 # Normally, just do built-in.
209 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
210 # Rules shared between *config targets and build targets
211
212 # Basic helpers built in scripts/
213 -PHONY += scripts_basic
214 -scripts_basic:
215 +PHONY += scripts_basic gcc-plugins
216 +scripts_basic: gcc-plugins
217 $(Q)$(MAKE) $(build)=scripts/basic
218 $(Q)rm -f .tmp_quiet_recordmcount
219
220 @@ -564,6 +565,50 @@ else
221 KBUILD_CFLAGS += -O2
222 endif
223
224 +ifndef DISABLE_PAX_PLUGINS
225 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
226 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
227 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
228 +endif
229 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
230 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
231 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
232 +endif
233 +ifdef CONFIG_KALLOCSTAT_PLUGIN
234 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
235 +endif
236 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
237 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
238 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
239 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
240 +endif
241 +ifdef CONFIG_CHECKER_PLUGIN
242 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
243 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
244 +endif
245 +endif
246 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
247 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
248 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
249 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
250 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
251 +ifeq ($(KBUILD_EXTMOD),)
252 +gcc-plugins:
253 + $(Q)$(MAKE) $(build)=tools/gcc
254 +else
255 +gcc-plugins: ;
256 +endif
257 +else
258 +gcc-plugins:
259 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
260 + $(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.))
261 +else
262 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
263 +endif
264 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
265 +endif
266 +endif
267 +
268 include $(srctree)/arch/$(SRCARCH)/Makefile
269
270 ifneq ($(CONFIG_FRAME_WARN),0)
271 @@ -708,7 +753,7 @@ export mod_strip_cmd
272
273
274 ifeq ($(KBUILD_EXTMOD),)
275 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
276 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
277
278 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
279 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
280 @@ -932,6 +977,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
281
282 # The actual objects are generated when descending,
283 # make sure no implicit rule kicks in
284 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
285 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
286 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
287
288 # Handle descending into subdirectories listed in $(vmlinux-dirs)
289 @@ -941,7 +988,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
290 # Error messages still appears in the original language
291
292 PHONY += $(vmlinux-dirs)
293 -$(vmlinux-dirs): prepare scripts
294 +$(vmlinux-dirs): gcc-plugins prepare scripts
295 $(Q)$(MAKE) $(build)=$@
296
297 # Store (new) KERNELRELASE string in include/config/kernel.release
298 @@ -985,6 +1032,7 @@ prepare0: archprepare FORCE
299 $(Q)$(MAKE) $(build)=.
300
301 # All the preparing..
302 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
303 prepare: prepare0
304
305 # Generate some files
306 @@ -1089,6 +1137,8 @@ all: modules
307 # using awk while concatenating to the final file.
308
309 PHONY += modules
310 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
311 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
312 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
313 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
314 @$(kecho) ' Building modules, stage 2.';
315 @@ -1104,7 +1154,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
316
317 # Target to prepare building external modules
318 PHONY += modules_prepare
319 -modules_prepare: prepare scripts
320 +modules_prepare: gcc-plugins prepare scripts
321
322 # Target to install modules
323 PHONY += modules_install
324 @@ -1201,6 +1251,7 @@ distclean: mrproper
325 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
326 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
327 -o -name '.*.rej' \
328 + -o -name '.*.rej' -o -name '*.so' \
329 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
330 -type f -print | xargs rm -f
331
332 @@ -1361,6 +1412,8 @@ PHONY += $(module-dirs) modules
333 $(module-dirs): crmodverdir $(objtree)/Module.symvers
334 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
335
336 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
337 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
338 modules: $(module-dirs)
339 @$(kecho) ' Building modules, stage 2.';
340 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
341 @@ -1487,17 +1540,21 @@ else
342 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
343 endif
344
345 -%.s: %.c prepare scripts FORCE
346 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
347 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
348 +%.s: %.c gcc-plugins prepare scripts FORCE
349 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
350 %.i: %.c prepare scripts FORCE
351 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
352 -%.o: %.c prepare scripts FORCE
353 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
354 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
355 +%.o: %.c gcc-plugins prepare scripts FORCE
356 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
357 %.lst: %.c prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359 -%.s: %.S prepare scripts FORCE
360 +%.s: %.S gcc-plugins prepare scripts FORCE
361 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
362 -%.o: %.S prepare scripts FORCE
363 +%.o: %.S gcc-plugins prepare scripts FORCE
364 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
365 %.symtypes: %.c prepare scripts FORCE
366 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
367 @@ -1507,11 +1564,15 @@ endif
368 $(cmd_crmodverdir)
369 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
370 $(build)=$(build-dir)
371 -%/: prepare scripts FORCE
372 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
373 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
374 +%/: gcc-plugins prepare scripts FORCE
375 $(cmd_crmodverdir)
376 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
377 $(build)=$(build-dir)
378 -%.ko: prepare scripts FORCE
379 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
380 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
381 +%.ko: gcc-plugins prepare scripts FORCE
382 $(cmd_crmodverdir)
383 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
384 $(build)=$(build-dir) $(@:.ko=.o)
385 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
386 index 640f909..48b6597 100644
387 --- a/arch/alpha/include/asm/atomic.h
388 +++ b/arch/alpha/include/asm/atomic.h
389 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
390 #define atomic_dec(v) atomic_sub(1,(v))
391 #define atomic64_dec(v) atomic64_sub(1,(v))
392
393 +#define atomic64_read_unchecked(v) atomic64_read(v)
394 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
395 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
396 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
397 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
398 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
399 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
400 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
401 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
402 +
403 #define smp_mb__before_atomic_dec() smp_mb()
404 #define smp_mb__after_atomic_dec() smp_mb()
405 #define smp_mb__before_atomic_inc() smp_mb()
406 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
407 index ad368a9..fbe0f25 100644
408 --- a/arch/alpha/include/asm/cache.h
409 +++ b/arch/alpha/include/asm/cache.h
410 @@ -4,19 +4,19 @@
411 #ifndef __ARCH_ALPHA_CACHE_H
412 #define __ARCH_ALPHA_CACHE_H
413
414 +#include <linux/const.h>
415
416 /* Bytes per L1 (data) cache line. */
417 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
418 -# define L1_CACHE_BYTES 64
419 # define L1_CACHE_SHIFT 6
420 #else
421 /* Both EV4 and EV5 are write-through, read-allocate,
422 direct-mapped, physical.
423 */
424 -# define L1_CACHE_BYTES 32
425 # define L1_CACHE_SHIFT 5
426 #endif
427
428 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
429 #define SMP_CACHE_BYTES L1_CACHE_BYTES
430
431 #endif
432 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
433 index da5449e..7418343 100644
434 --- a/arch/alpha/include/asm/elf.h
435 +++ b/arch/alpha/include/asm/elf.h
436 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
437
438 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
439
440 +#ifdef CONFIG_PAX_ASLR
441 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
442 +
443 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
444 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
445 +#endif
446 +
447 /* $0 is set by ld.so to a pointer to a function which might be
448 registered using atexit. This provides a mean for the dynamic
449 linker to call DT_FINI functions for shared libraries that have
450 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
451 index de98a73..bd4f1f8 100644
452 --- a/arch/alpha/include/asm/pgtable.h
453 +++ b/arch/alpha/include/asm/pgtable.h
454 @@ -101,6 +101,17 @@ struct vm_area_struct;
455 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
456 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
457 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
458 +
459 +#ifdef CONFIG_PAX_PAGEEXEC
460 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
461 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
462 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
463 +#else
464 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
465 +# define PAGE_COPY_NOEXEC PAGE_COPY
466 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
467 +#endif
468 +
469 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
470
471 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
472 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
473 index 2fd00b7..cfd5069 100644
474 --- a/arch/alpha/kernel/module.c
475 +++ b/arch/alpha/kernel/module.c
476 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
477
478 /* The small sections were sorted to the end of the segment.
479 The following should definitely cover them. */
480 - gp = (u64)me->module_core + me->core_size - 0x8000;
481 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
482 got = sechdrs[me->arch.gotsecindex].sh_addr;
483
484 for (i = 0; i < n; i++) {
485 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
486 index 01e8715..be0e80f 100644
487 --- a/arch/alpha/kernel/osf_sys.c
488 +++ b/arch/alpha/kernel/osf_sys.c
489 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
490 /* At this point: (!vma || addr < vma->vm_end). */
491 if (limit - len < addr)
492 return -ENOMEM;
493 - if (!vma || addr + len <= vma->vm_start)
494 + if (check_heap_stack_gap(vma, addr, len))
495 return addr;
496 addr = vma->vm_end;
497 vma = vma->vm_next;
498 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
499 merely specific addresses, but regions of memory -- perhaps
500 this feature should be incorporated into all ports? */
501
502 +#ifdef CONFIG_PAX_RANDMMAP
503 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
504 +#endif
505 +
506 if (addr) {
507 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
508 if (addr != (unsigned long) -ENOMEM)
509 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
510 }
511
512 /* Next, try allocating at TASK_UNMAPPED_BASE. */
513 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
514 - len, limit);
515 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
516 +
517 if (addr != (unsigned long) -ENOMEM)
518 return addr;
519
520 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
521 index fadd5f8..904e73a 100644
522 --- a/arch/alpha/mm/fault.c
523 +++ b/arch/alpha/mm/fault.c
524 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
525 __reload_thread(pcb);
526 }
527
528 +#ifdef CONFIG_PAX_PAGEEXEC
529 +/*
530 + * PaX: decide what to do with offenders (regs->pc = fault address)
531 + *
532 + * returns 1 when task should be killed
533 + * 2 when patched PLT trampoline was detected
534 + * 3 when unpatched PLT trampoline was detected
535 + */
536 +static int pax_handle_fetch_fault(struct pt_regs *regs)
537 +{
538 +
539 +#ifdef CONFIG_PAX_EMUPLT
540 + int err;
541 +
542 + do { /* PaX: patched PLT emulation #1 */
543 + unsigned int ldah, ldq, jmp;
544 +
545 + err = get_user(ldah, (unsigned int *)regs->pc);
546 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
547 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
548 +
549 + if (err)
550 + break;
551 +
552 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
553 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
554 + jmp == 0x6BFB0000U)
555 + {
556 + unsigned long r27, addr;
557 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
558 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
559 +
560 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
561 + err = get_user(r27, (unsigned long *)addr);
562 + if (err)
563 + break;
564 +
565 + regs->r27 = r27;
566 + regs->pc = r27;
567 + return 2;
568 + }
569 + } while (0);
570 +
571 + do { /* PaX: patched PLT emulation #2 */
572 + unsigned int ldah, lda, br;
573 +
574 + err = get_user(ldah, (unsigned int *)regs->pc);
575 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
576 + err |= get_user(br, (unsigned int *)(regs->pc+8));
577 +
578 + if (err)
579 + break;
580 +
581 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
582 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
583 + (br & 0xFFE00000U) == 0xC3E00000U)
584 + {
585 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
586 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
587 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
588 +
589 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
590 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
591 + return 2;
592 + }
593 + } while (0);
594 +
595 + do { /* PaX: unpatched PLT emulation */
596 + unsigned int br;
597 +
598 + err = get_user(br, (unsigned int *)regs->pc);
599 +
600 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
601 + unsigned int br2, ldq, nop, jmp;
602 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
603 +
604 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
605 + err = get_user(br2, (unsigned int *)addr);
606 + err |= get_user(ldq, (unsigned int *)(addr+4));
607 + err |= get_user(nop, (unsigned int *)(addr+8));
608 + err |= get_user(jmp, (unsigned int *)(addr+12));
609 + err |= get_user(resolver, (unsigned long *)(addr+16));
610 +
611 + if (err)
612 + break;
613 +
614 + if (br2 == 0xC3600000U &&
615 + ldq == 0xA77B000CU &&
616 + nop == 0x47FF041FU &&
617 + jmp == 0x6B7B0000U)
618 + {
619 + regs->r28 = regs->pc+4;
620 + regs->r27 = addr+16;
621 + regs->pc = resolver;
622 + return 3;
623 + }
624 + }
625 + } while (0);
626 +#endif
627 +
628 + return 1;
629 +}
630 +
631 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
632 +{
633 + unsigned long i;
634 +
635 + printk(KERN_ERR "PAX: bytes at PC: ");
636 + for (i = 0; i < 5; i++) {
637 + unsigned int c;
638 + if (get_user(c, (unsigned int *)pc+i))
639 + printk(KERN_CONT "???????? ");
640 + else
641 + printk(KERN_CONT "%08x ", c);
642 + }
643 + printk("\n");
644 +}
645 +#endif
646
647 /*
648 * This routine handles page faults. It determines the address,
649 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
650 good_area:
651 si_code = SEGV_ACCERR;
652 if (cause < 0) {
653 - if (!(vma->vm_flags & VM_EXEC))
654 + if (!(vma->vm_flags & VM_EXEC)) {
655 +
656 +#ifdef CONFIG_PAX_PAGEEXEC
657 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
658 + goto bad_area;
659 +
660 + up_read(&mm->mmap_sem);
661 + switch (pax_handle_fetch_fault(regs)) {
662 +
663 +#ifdef CONFIG_PAX_EMUPLT
664 + case 2:
665 + case 3:
666 + return;
667 +#endif
668 +
669 + }
670 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
671 + do_group_exit(SIGKILL);
672 +#else
673 goto bad_area;
674 +#endif
675 +
676 + }
677 } else if (!cause) {
678 /* Allow reads even for write-only mappings */
679 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
680 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
681 index 86976d0..8e07f84 100644
682 --- a/arch/arm/include/asm/atomic.h
683 +++ b/arch/arm/include/asm/atomic.h
684 @@ -15,6 +15,10 @@
685 #include <linux/types.h>
686 #include <asm/system.h>
687
688 +#ifdef CONFIG_GENERIC_ATOMIC64
689 +#include <asm-generic/atomic64.h>
690 +#endif
691 +
692 #define ATOMIC_INIT(i) { (i) }
693
694 #ifdef __KERNEL__
695 @@ -25,7 +29,15 @@
696 * atomic_set() is the clrex or dummy strex done on every exception return.
697 */
698 #define atomic_read(v) (*(volatile int *)&(v)->counter)
699 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
700 +{
701 + return v->counter;
702 +}
703 #define atomic_set(v,i) (((v)->counter) = (i))
704 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
705 +{
706 + v->counter = i;
707 +}
708
709 #if __LINUX_ARM_ARCH__ >= 6
710
711 @@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
712 int result;
713
714 __asm__ __volatile__("@ atomic_add\n"
715 +"1: ldrex %1, [%3]\n"
716 +" adds %0, %1, %4\n"
717 +
718 +#ifdef CONFIG_PAX_REFCOUNT
719 +" bvc 3f\n"
720 +"2: bkpt 0xf103\n"
721 +"3:\n"
722 +#endif
723 +
724 +" strex %1, %0, [%3]\n"
725 +" teq %1, #0\n"
726 +" bne 1b"
727 +
728 +#ifdef CONFIG_PAX_REFCOUNT
729 +"\n4:\n"
730 + _ASM_EXTABLE(2b, 4b)
731 +#endif
732 +
733 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
734 + : "r" (&v->counter), "Ir" (i)
735 + : "cc");
736 +}
737 +
738 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
739 +{
740 + unsigned long tmp;
741 + int result;
742 +
743 + __asm__ __volatile__("@ atomic_add_unchecked\n"
744 "1: ldrex %0, [%3]\n"
745 " add %0, %0, %4\n"
746 " strex %1, %0, [%3]\n"
747 @@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
748 smp_mb();
749
750 __asm__ __volatile__("@ atomic_add_return\n"
751 +"1: ldrex %1, [%3]\n"
752 +" adds %0, %1, %4\n"
753 +
754 +#ifdef CONFIG_PAX_REFCOUNT
755 +" bvc 3f\n"
756 +" mov %0, %1\n"
757 +"2: bkpt 0xf103\n"
758 +"3:\n"
759 +#endif
760 +
761 +" strex %1, %0, [%3]\n"
762 +" teq %1, #0\n"
763 +" bne 1b"
764 +
765 +#ifdef CONFIG_PAX_REFCOUNT
766 +"\n4:\n"
767 + _ASM_EXTABLE(2b, 4b)
768 +#endif
769 +
770 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
771 + : "r" (&v->counter), "Ir" (i)
772 + : "cc");
773 +
774 + smp_mb();
775 +
776 + return result;
777 +}
778 +
779 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
780 +{
781 + unsigned long tmp;
782 + int result;
783 +
784 + smp_mb();
785 +
786 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
787 "1: ldrex %0, [%3]\n"
788 " add %0, %0, %4\n"
789 " strex %1, %0, [%3]\n"
790 @@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
791 int result;
792
793 __asm__ __volatile__("@ atomic_sub\n"
794 +"1: ldrex %1, [%3]\n"
795 +" subs %0, %1, %4\n"
796 +
797 +#ifdef CONFIG_PAX_REFCOUNT
798 +" bvc 3f\n"
799 +"2: bkpt 0xf103\n"
800 +"3:\n"
801 +#endif
802 +
803 +" strex %1, %0, [%3]\n"
804 +" teq %1, #0\n"
805 +" bne 1b"
806 +
807 +#ifdef CONFIG_PAX_REFCOUNT
808 +"\n4:\n"
809 + _ASM_EXTABLE(2b, 4b)
810 +#endif
811 +
812 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
813 + : "r" (&v->counter), "Ir" (i)
814 + : "cc");
815 +}
816 +
817 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
818 +{
819 + unsigned long tmp;
820 + int result;
821 +
822 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
823 "1: ldrex %0, [%3]\n"
824 " sub %0, %0, %4\n"
825 " strex %1, %0, [%3]\n"
826 @@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
827 smp_mb();
828
829 __asm__ __volatile__("@ atomic_sub_return\n"
830 -"1: ldrex %0, [%3]\n"
831 -" sub %0, %0, %4\n"
832 +"1: ldrex %1, [%3]\n"
833 +" sub %0, %1, %4\n"
834 +
835 +#ifdef CONFIG_PAX_REFCOUNT
836 +" bvc 3f\n"
837 +" mov %0, %1\n"
838 +"2: bkpt 0xf103\n"
839 +"3:\n"
840 +#endif
841 +
842 " strex %1, %0, [%3]\n"
843 " teq %1, #0\n"
844 " bne 1b"
845 +
846 +#ifdef CONFIG_PAX_REFCOUNT
847 +"\n4:\n"
848 + _ASM_EXTABLE(2b, 4b)
849 +#endif
850 +
851 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
852 : "r" (&v->counter), "Ir" (i)
853 : "cc");
854 @@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
855 return oldval;
856 }
857
858 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
859 +{
860 + unsigned long oldval, res;
861 +
862 + smp_mb();
863 +
864 + do {
865 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
866 + "ldrex %1, [%3]\n"
867 + "mov %0, #0\n"
868 + "teq %1, %4\n"
869 + "strexeq %0, %5, [%3]\n"
870 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
871 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
872 + : "cc");
873 + } while (res);
874 +
875 + smp_mb();
876 +
877 + return oldval;
878 +}
879 +
880 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
881 {
882 unsigned long tmp, tmp2;
883 @@ -165,7 +307,9 @@ static inline int atomic_add_return(int i, atomic_t *v)
884
885 return val;
886 }
887 +#define atomic_add_return_unchecked(i, v) atomic_add_return(i, v)
888 #define atomic_add(i, v) (void) atomic_add_return(i, v)
889 +#define atomic_add_unchecked(i, v) (void) atomic_add_return_unchecked(i, v)
890
891 static inline int atomic_sub_return(int i, atomic_t *v)
892 {
893 @@ -179,7 +323,9 @@ static inline int atomic_sub_return(int i, atomic_t *v)
894
895 return val;
896 }
897 +#define atomic_sub_return_unchecked(i, v) atomic_sub_return(i, v)
898 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
899 +#define atomic_sub_unchecked(i, v) (void) atomic_sub_return_unchecked(i, v)
900
901 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
902 {
903 @@ -194,6 +340,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
904
905 return ret;
906 }
907 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg(v, o, n)
908
909 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
910 {
911 @@ -207,6 +354,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
912 #endif /* __LINUX_ARM_ARCH__ */
913
914 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
915 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
916 +{
917 + return xchg(&v->counter, new);
918 +}
919
920 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
921 {
922 @@ -219,11 +370,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
923 }
924
925 #define atomic_inc(v) atomic_add(1, v)
926 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
927 +{
928 + atomic_add_unchecked(1, v);
929 +}
930 #define atomic_dec(v) atomic_sub(1, v)
931 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
932 +{
933 + atomic_sub_unchecked(1, v);
934 +}
935
936 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
937 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
938 +{
939 + return atomic_add_return_unchecked(1, v) == 0;
940 +}
941 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
942 #define atomic_inc_return(v) (atomic_add_return(1, v))
943 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
944 +{
945 + return atomic_add_return_unchecked(1, v);
946 +}
947 #define atomic_dec_return(v) (atomic_sub_return(1, v))
948 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
949
950 @@ -239,6 +406,14 @@ typedef struct {
951 u64 __aligned(8) counter;
952 } atomic64_t;
953
954 +#ifdef CONFIG_PAX_REFCOUNT
955 +typedef struct {
956 + u64 __aligned(8) counter;
957 +} atomic64_unchecked_t;
958 +#else
959 +typedef atomic64_t atomic64_unchecked_t;
960 +#endif
961 +
962 #define ATOMIC64_INIT(i) { (i) }
963
964 static inline u64 atomic64_read(atomic64_t *v)
965 @@ -254,6 +429,19 @@ static inline u64 atomic64_read(atomic64_t *v)
966 return result;
967 }
968
969 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
970 +{
971 + u64 result;
972 +
973 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
974 +" ldrexd %0, %H0, [%1]"
975 + : "=&r" (result)
976 + : "r" (&v->counter), "Qo" (v->counter)
977 + );
978 +
979 + return result;
980 +}
981 +
982 static inline void atomic64_set(atomic64_t *v, u64 i)
983 {
984 u64 tmp;
985 @@ -268,6 +456,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
986 : "cc");
987 }
988
989 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
990 +{
991 + u64 tmp;
992 +
993 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
994 +"1: ldrexd %0, %H0, [%2]\n"
995 +" strexd %0, %3, %H3, [%2]\n"
996 +" teq %0, #0\n"
997 +" bne 1b"
998 + : "=&r" (tmp), "=Qo" (v->counter)
999 + : "r" (&v->counter), "r" (i)
1000 + : "cc");
1001 +}
1002 +
1003 static inline void atomic64_add(u64 i, atomic64_t *v)
1004 {
1005 u64 result;
1006 @@ -276,6 +478,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1007 __asm__ __volatile__("@ atomic64_add\n"
1008 "1: ldrexd %0, %H0, [%3]\n"
1009 " adds %0, %0, %4\n"
1010 +" adcs %H0, %H0, %H4\n"
1011 +
1012 +#ifdef CONFIG_PAX_REFCOUNT
1013 +" bvc 3f\n"
1014 +"2: bkpt 0xf103\n"
1015 +"3:\n"
1016 +#endif
1017 +
1018 +" strexd %1, %0, %H0, [%3]\n"
1019 +" teq %1, #0\n"
1020 +" bne 1b"
1021 +
1022 +#ifdef CONFIG_PAX_REFCOUNT
1023 +"\n4:\n"
1024 + _ASM_EXTABLE(2b, 4b)
1025 +#endif
1026 +
1027 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1028 + : "r" (&v->counter), "r" (i)
1029 + : "cc");
1030 +}
1031 +
1032 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1033 +{
1034 + u64 result;
1035 + unsigned long tmp;
1036 +
1037 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1038 +"1: ldrexd %0, %H0, [%3]\n"
1039 +" adds %0, %0, %4\n"
1040 " adc %H0, %H0, %H4\n"
1041 " strexd %1, %0, %H0, [%3]\n"
1042 " teq %1, #0\n"
1043 @@ -287,12 +519,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1044
1045 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1046 {
1047 - u64 result;
1048 - unsigned long tmp;
1049 + u64 result, tmp;
1050
1051 smp_mb();
1052
1053 __asm__ __volatile__("@ atomic64_add_return\n"
1054 +"1: ldrexd %1, %H1, [%3]\n"
1055 +" adds %0, %1, %4\n"
1056 +" adcs %H0, %H1, %H4\n"
1057 +
1058 +#ifdef CONFIG_PAX_REFCOUNT
1059 +" bvc 3f\n"
1060 +" mov %0, %1\n"
1061 +" mov %H0, %H1\n"
1062 +"2: bkpt 0xf103\n"
1063 +"3:\n"
1064 +#endif
1065 +
1066 +" strexd %1, %0, %H0, [%3]\n"
1067 +" teq %1, #0\n"
1068 +" bne 1b"
1069 +
1070 +#ifdef CONFIG_PAX_REFCOUNT
1071 +"\n4:\n"
1072 + _ASM_EXTABLE(2b, 4b)
1073 +#endif
1074 +
1075 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1076 + : "r" (&v->counter), "r" (i)
1077 + : "cc");
1078 +
1079 + smp_mb();
1080 +
1081 + return result;
1082 +}
1083 +
1084 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1085 +{
1086 + u64 result;
1087 + unsigned long tmp;
1088 +
1089 + smp_mb();
1090 +
1091 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1092 "1: ldrexd %0, %H0, [%3]\n"
1093 " adds %0, %0, %4\n"
1094 " adc %H0, %H0, %H4\n"
1095 @@ -316,6 +585,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1096 __asm__ __volatile__("@ atomic64_sub\n"
1097 "1: ldrexd %0, %H0, [%3]\n"
1098 " subs %0, %0, %4\n"
1099 +" sbcs %H0, %H0, %H4\n"
1100 +
1101 +#ifdef CONFIG_PAX_REFCOUNT
1102 +" bvc 3f\n"
1103 +"2: bkpt 0xf103\n"
1104 +"3:\n"
1105 +#endif
1106 +
1107 +" strexd %1, %0, %H0, [%3]\n"
1108 +" teq %1, #0\n"
1109 +" bne 1b"
1110 +
1111 +#ifdef CONFIG_PAX_REFCOUNT
1112 +"\n4:\n"
1113 + _ASM_EXTABLE(2b, 4b)
1114 +#endif
1115 +
1116 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1117 + : "r" (&v->counter), "r" (i)
1118 + : "cc");
1119 +}
1120 +
1121 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1122 +{
1123 + u64 result;
1124 + unsigned long tmp;
1125 +
1126 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1127 +"1: ldrexd %0, %H0, [%3]\n"
1128 +" subs %0, %0, %4\n"
1129 " sbc %H0, %H0, %H4\n"
1130 " strexd %1, %0, %H0, [%3]\n"
1131 " teq %1, #0\n"
1132 @@ -327,18 +626,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1133
1134 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1135 {
1136 - u64 result;
1137 - unsigned long tmp;
1138 + u64 result, tmp;
1139
1140 smp_mb();
1141
1142 __asm__ __volatile__("@ atomic64_sub_return\n"
1143 -"1: ldrexd %0, %H0, [%3]\n"
1144 -" subs %0, %0, %4\n"
1145 -" sbc %H0, %H0, %H4\n"
1146 +"1: ldrexd %1, %H1, [%3]\n"
1147 +" subs %0, %1, %4\n"
1148 +" sbc %H0, %H1, %H4\n"
1149 +
1150 +#ifdef CONFIG_PAX_REFCOUNT
1151 +" bvc 3f\n"
1152 +" mov %0, %1\n"
1153 +" mov %H0, %H1\n"
1154 +"2: bkpt 0xf103\n"
1155 +"3:\n"
1156 +#endif
1157 +
1158 " strexd %1, %0, %H0, [%3]\n"
1159 " teq %1, #0\n"
1160 " bne 1b"
1161 +
1162 +#ifdef CONFIG_PAX_REFCOUNT
1163 +"\n4:\n"
1164 + _ASM_EXTABLE(2b, 4b)
1165 +#endif
1166 +
1167 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1168 : "r" (&v->counter), "r" (i)
1169 : "cc");
1170 @@ -372,6 +685,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1171 return oldval;
1172 }
1173
1174 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1175 +{
1176 + u64 oldval;
1177 + unsigned long res;
1178 +
1179 + smp_mb();
1180 +
1181 + do {
1182 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1183 + "ldrexd %1, %H1, [%3]\n"
1184 + "mov %0, #0\n"
1185 + "teq %1, %4\n"
1186 + "teqeq %H1, %H4\n"
1187 + "strexdeq %0, %5, %H5, [%3]"
1188 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1189 + : "r" (&ptr->counter), "r" (old), "r" (new)
1190 + : "cc");
1191 + } while (res);
1192 +
1193 + smp_mb();
1194 +
1195 + return oldval;
1196 +}
1197 +
1198 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1199 {
1200 u64 result;
1201 @@ -395,21 +732,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1202
1203 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1204 {
1205 - u64 result;
1206 - unsigned long tmp;
1207 + u64 result, tmp;
1208
1209 smp_mb();
1210
1211 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1212 -"1: ldrexd %0, %H0, [%3]\n"
1213 -" subs %0, %0, #1\n"
1214 -" sbc %H0, %H0, #0\n"
1215 +"1: ldrexd %1, %H1, [%3]\n"
1216 +" subs %0, %1, #1\n"
1217 +" sbc %H0, %H1, #0\n"
1218 +
1219 +#ifdef CONFIG_PAX_REFCOUNT
1220 +" bvc 3f\n"
1221 +" mov %0, %1\n"
1222 +" mov %H0, %H1\n"
1223 +"2: bkpt 0xf103\n"
1224 +"3:\n"
1225 +#endif
1226 +
1227 " teq %H0, #0\n"
1228 -" bmi 2f\n"
1229 +" bmi 4f\n"
1230 " strexd %1, %0, %H0, [%3]\n"
1231 " teq %1, #0\n"
1232 " bne 1b\n"
1233 -"2:"
1234 +"4:\n"
1235 +
1236 +#ifdef CONFIG_PAX_REFCOUNT
1237 + _ASM_EXTABLE(2b, 4b)
1238 +#endif
1239 +
1240 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1241 : "r" (&v->counter)
1242 : "cc");
1243 @@ -432,13 +782,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1244 " teq %0, %5\n"
1245 " teqeq %H0, %H5\n"
1246 " moveq %1, #0\n"
1247 -" beq 2f\n"
1248 +" beq 4f\n"
1249 " adds %0, %0, %6\n"
1250 " adc %H0, %H0, %H6\n"
1251 +
1252 +#ifdef CONFIG_PAX_REFCOUNT
1253 +" bvc 3f\n"
1254 +"2: bkpt 0xf103\n"
1255 +"3:\n"
1256 +#endif
1257 +
1258 " strexd %2, %0, %H0, [%4]\n"
1259 " teq %2, #0\n"
1260 " bne 1b\n"
1261 -"2:"
1262 +"4:\n"
1263 +
1264 +#ifdef CONFIG_PAX_REFCOUNT
1265 + _ASM_EXTABLE(2b, 4b)
1266 +#endif
1267 +
1268 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1269 : "r" (&v->counter), "r" (u), "r" (a)
1270 : "cc");
1271 @@ -451,10 +813,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1272
1273 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1274 #define atomic64_inc(v) atomic64_add(1LL, (v))
1275 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1276 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1277 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1278 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1279 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1280 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1281 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1282 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1283 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1284 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1285 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1286 index 75fe66b..2255c86 100644
1287 --- a/arch/arm/include/asm/cache.h
1288 +++ b/arch/arm/include/asm/cache.h
1289 @@ -4,8 +4,10 @@
1290 #ifndef __ASMARM_CACHE_H
1291 #define __ASMARM_CACHE_H
1292
1293 +#include <linux/const.h>
1294 +
1295 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1296 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1297 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1298
1299 /*
1300 * Memory returned by kmalloc() may be used for DMA, so we must make
1301 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1302 index d5d8d5c..ad92c96 100644
1303 --- a/arch/arm/include/asm/cacheflush.h
1304 +++ b/arch/arm/include/asm/cacheflush.h
1305 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1306 void (*dma_unmap_area)(const void *, size_t, int);
1307
1308 void (*dma_flush_range)(const void *, const void *);
1309 -};
1310 +} __no_const;
1311
1312 /*
1313 * Select the calling method
1314 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1315 index 0e9ce8d..6ef1e03 100644
1316 --- a/arch/arm/include/asm/elf.h
1317 +++ b/arch/arm/include/asm/elf.h
1318 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1319 the loader. We need to make sure that it is out of the way of the program
1320 that it will "exec", and that there is sufficient room for the brk. */
1321
1322 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1323 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1324 +
1325 +#ifdef CONFIG_PAX_ASLR
1326 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1327 +
1328 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1329 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1330 +#endif
1331
1332 /* When the program starts, a1 contains a pointer to a function to be
1333 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1334 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1335 extern void elf_set_personality(const struct elf32_hdr *);
1336 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1337
1338 -struct mm_struct;
1339 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1340 -#define arch_randomize_brk arch_randomize_brk
1341 -
1342 extern int vectors_user_mapping(void);
1343 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1344 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1345 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1346 index e51b1e8..32a3113 100644
1347 --- a/arch/arm/include/asm/kmap_types.h
1348 +++ b/arch/arm/include/asm/kmap_types.h
1349 @@ -21,6 +21,7 @@ enum km_type {
1350 KM_L1_CACHE,
1351 KM_L2_CACHE,
1352 KM_KDB,
1353 + KM_CLEARPAGE,
1354 KM_TYPE_NR
1355 };
1356
1357 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1358 index 53426c6..c7baff3 100644
1359 --- a/arch/arm/include/asm/outercache.h
1360 +++ b/arch/arm/include/asm/outercache.h
1361 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1362 #endif
1363 void (*set_debug)(unsigned long);
1364 void (*resume)(void);
1365 -};
1366 +} __no_const;
1367
1368 #ifdef CONFIG_OUTER_CACHE
1369
1370 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1371 index 97b440c..b7ff179 100644
1372 --- a/arch/arm/include/asm/page.h
1373 +++ b/arch/arm/include/asm/page.h
1374 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1375 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1376 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1377 unsigned long vaddr, struct vm_area_struct *vma);
1378 -};
1379 +} __no_const;
1380
1381 #ifdef MULTI_USER
1382 extern struct cpu_user_fns cpu_user;
1383 diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1384 index e4c96cc..1145653 100644
1385 --- a/arch/arm/include/asm/system.h
1386 +++ b/arch/arm/include/asm/system.h
1387 @@ -98,6 +98,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1388
1389 #define xchg(ptr,x) \
1390 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1391 +#define xchg_unchecked(ptr,x) \
1392 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1393
1394 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1395
1396 @@ -534,6 +536,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1397
1398 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1399
1400 +#define _ASM_EXTABLE(from, to) \
1401 +" .pushsection __ex_table,\"a\"\n"\
1402 +" .align 3\n" \
1403 +" .long " #from ", " #to"\n" \
1404 +" .popsection"
1405 +
1406 +
1407 #endif /* __ASSEMBLY__ */
1408
1409 #define arch_align_stack(x) (x)
1410 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1411 index 2958976..12ccac4 100644
1412 --- a/arch/arm/include/asm/uaccess.h
1413 +++ b/arch/arm/include/asm/uaccess.h
1414 @@ -22,6 +22,8 @@
1415 #define VERIFY_READ 0
1416 #define VERIFY_WRITE 1
1417
1418 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1419 +
1420 /*
1421 * The exception table consists of pairs of addresses: the first is the
1422 * address of an instruction that is allowed to fault, and the second is
1423 @@ -387,8 +389,23 @@ do { \
1424
1425
1426 #ifdef CONFIG_MMU
1427 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1428 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1429 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1430 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1431 +
1432 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1433 +{
1434 + if (!__builtin_constant_p(n))
1435 + check_object_size(to, n, false);
1436 + return ___copy_from_user(to, from, n);
1437 +}
1438 +
1439 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1440 +{
1441 + if (!__builtin_constant_p(n))
1442 + check_object_size(from, n, true);
1443 + return ___copy_to_user(to, from, n);
1444 +}
1445 +
1446 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1447 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1448 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1449 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1450
1451 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1452 {
1453 + if ((long)n < 0)
1454 + return n;
1455 +
1456 if (access_ok(VERIFY_READ, from, n))
1457 n = __copy_from_user(to, from, n);
1458 else /* security hole - plug it */
1459 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1460
1461 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1462 {
1463 + if ((long)n < 0)
1464 + return n;
1465 +
1466 if (access_ok(VERIFY_WRITE, to, n))
1467 n = __copy_to_user(to, from, n);
1468 return n;
1469 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1470 index 5b0bce6..becd81c 100644
1471 --- a/arch/arm/kernel/armksyms.c
1472 +++ b/arch/arm/kernel/armksyms.c
1473 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1474 #ifdef CONFIG_MMU
1475 EXPORT_SYMBOL(copy_page);
1476
1477 -EXPORT_SYMBOL(__copy_from_user);
1478 -EXPORT_SYMBOL(__copy_to_user);
1479 +EXPORT_SYMBOL(___copy_from_user);
1480 +EXPORT_SYMBOL(___copy_to_user);
1481 EXPORT_SYMBOL(__clear_user);
1482
1483 EXPORT_SYMBOL(__get_user_1);
1484 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1485 index 971d65c..cc936fb 100644
1486 --- a/arch/arm/kernel/process.c
1487 +++ b/arch/arm/kernel/process.c
1488 @@ -28,7 +28,6 @@
1489 #include <linux/tick.h>
1490 #include <linux/utsname.h>
1491 #include <linux/uaccess.h>
1492 -#include <linux/random.h>
1493 #include <linux/hw_breakpoint.h>
1494 #include <linux/cpuidle.h>
1495
1496 @@ -273,9 +272,10 @@ void machine_power_off(void)
1497 machine_shutdown();
1498 if (pm_power_off)
1499 pm_power_off();
1500 + BUG();
1501 }
1502
1503 -void machine_restart(char *cmd)
1504 +__noreturn void machine_restart(char *cmd)
1505 {
1506 machine_shutdown();
1507
1508 @@ -517,12 +517,6 @@ unsigned long get_wchan(struct task_struct *p)
1509 return 0;
1510 }
1511
1512 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1513 -{
1514 - unsigned long range_end = mm->brk + 0x02000000;
1515 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1516 -}
1517 -
1518 #ifdef CONFIG_MMU
1519 /*
1520 * The vectors page is always readable from user space for the
1521 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1522 index a255c39..4a19b25 100644
1523 --- a/arch/arm/kernel/setup.c
1524 +++ b/arch/arm/kernel/setup.c
1525 @@ -109,13 +109,13 @@ struct processor processor __read_mostly;
1526 struct cpu_tlb_fns cpu_tlb __read_mostly;
1527 #endif
1528 #ifdef MULTI_USER
1529 -struct cpu_user_fns cpu_user __read_mostly;
1530 +struct cpu_user_fns cpu_user __read_only;
1531 #endif
1532 #ifdef MULTI_CACHE
1533 -struct cpu_cache_fns cpu_cache __read_mostly;
1534 +struct cpu_cache_fns cpu_cache __read_only;
1535 #endif
1536 #ifdef CONFIG_OUTER_CACHE
1537 -struct outer_cache_fns outer_cache __read_mostly;
1538 +struct outer_cache_fns outer_cache __read_only;
1539 EXPORT_SYMBOL(outer_cache);
1540 #endif
1541
1542 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1543 index f84dfe6..13e94f7 100644
1544 --- a/arch/arm/kernel/traps.c
1545 +++ b/arch/arm/kernel/traps.c
1546 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1547
1548 static DEFINE_RAW_SPINLOCK(die_lock);
1549
1550 +extern void gr_handle_kernel_exploit(void);
1551 +
1552 /*
1553 * This function is protected against re-entrancy.
1554 */
1555 @@ -291,6 +293,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1556 panic("Fatal exception in interrupt");
1557 if (panic_on_oops)
1558 panic("Fatal exception");
1559 +
1560 + gr_handle_kernel_exploit();
1561 +
1562 if (ret != NOTIFY_STOP)
1563 do_exit(SIGSEGV);
1564 }
1565 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1566 index 66a477a..bee61d3 100644
1567 --- a/arch/arm/lib/copy_from_user.S
1568 +++ b/arch/arm/lib/copy_from_user.S
1569 @@ -16,7 +16,7 @@
1570 /*
1571 * Prototype:
1572 *
1573 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1574 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1575 *
1576 * Purpose:
1577 *
1578 @@ -84,11 +84,11 @@
1579
1580 .text
1581
1582 -ENTRY(__copy_from_user)
1583 +ENTRY(___copy_from_user)
1584
1585 #include "copy_template.S"
1586
1587 -ENDPROC(__copy_from_user)
1588 +ENDPROC(___copy_from_user)
1589
1590 .pushsection .fixup,"ax"
1591 .align 0
1592 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1593 index 6ee2f67..d1cce76 100644
1594 --- a/arch/arm/lib/copy_page.S
1595 +++ b/arch/arm/lib/copy_page.S
1596 @@ -10,6 +10,7 @@
1597 * ASM optimised string functions
1598 */
1599 #include <linux/linkage.h>
1600 +#include <linux/const.h>
1601 #include <asm/assembler.h>
1602 #include <asm/asm-offsets.h>
1603 #include <asm/cache.h>
1604 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1605 index d066df6..df28194 100644
1606 --- a/arch/arm/lib/copy_to_user.S
1607 +++ b/arch/arm/lib/copy_to_user.S
1608 @@ -16,7 +16,7 @@
1609 /*
1610 * Prototype:
1611 *
1612 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1613 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1614 *
1615 * Purpose:
1616 *
1617 @@ -88,11 +88,11 @@
1618 .text
1619
1620 ENTRY(__copy_to_user_std)
1621 -WEAK(__copy_to_user)
1622 +WEAK(___copy_to_user)
1623
1624 #include "copy_template.S"
1625
1626 -ENDPROC(__copy_to_user)
1627 +ENDPROC(___copy_to_user)
1628 ENDPROC(__copy_to_user_std)
1629
1630 .pushsection .fixup,"ax"
1631 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1632 index 5c908b1..e712687 100644
1633 --- a/arch/arm/lib/uaccess.S
1634 +++ b/arch/arm/lib/uaccess.S
1635 @@ -20,7 +20,7 @@
1636
1637 #define PAGE_SHIFT 12
1638
1639 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1640 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1641 * Purpose : copy a block to user memory from kernel memory
1642 * Params : to - user memory
1643 * : from - kernel memory
1644 @@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1645 sub r2, r2, ip
1646 b .Lc2u_dest_aligned
1647
1648 -ENTRY(__copy_to_user)
1649 +ENTRY(___copy_to_user)
1650 stmfd sp!, {r2, r4 - r7, lr}
1651 cmp r2, #4
1652 blt .Lc2u_not_enough
1653 @@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1654 ldrgtb r3, [r1], #0
1655 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1656 b .Lc2u_finished
1657 -ENDPROC(__copy_to_user)
1658 +ENDPROC(___copy_to_user)
1659
1660 .pushsection .fixup,"ax"
1661 .align 0
1662 9001: ldmfd sp!, {r0, r4 - r7, pc}
1663 .popsection
1664
1665 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1666 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1667 * Purpose : copy a block from user memory to kernel memory
1668 * Params : to - kernel memory
1669 * : from - user memory
1670 @@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1671 sub r2, r2, ip
1672 b .Lcfu_dest_aligned
1673
1674 -ENTRY(__copy_from_user)
1675 +ENTRY(___copy_from_user)
1676 stmfd sp!, {r0, r2, r4 - r7, lr}
1677 cmp r2, #4
1678 blt .Lcfu_not_enough
1679 @@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1680 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1681 strgtb r3, [r0], #1
1682 b .Lcfu_finished
1683 -ENDPROC(__copy_from_user)
1684 +ENDPROC(___copy_from_user)
1685
1686 .pushsection .fixup,"ax"
1687 .align 0
1688 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1689 index 025f742..8432b08 100644
1690 --- a/arch/arm/lib/uaccess_with_memcpy.c
1691 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1692 @@ -104,7 +104,7 @@ out:
1693 }
1694
1695 unsigned long
1696 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1697 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1698 {
1699 /*
1700 * This test is stubbed out of the main function above to keep
1701 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1702 index 6722627..8f97548c 100644
1703 --- a/arch/arm/mach-omap2/board-n8x0.c
1704 +++ b/arch/arm/mach-omap2/board-n8x0.c
1705 @@ -597,7 +597,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1706 }
1707 #endif
1708
1709 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1710 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1711 .late_init = n8x0_menelaus_late_init,
1712 };
1713
1714 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1715 index 2b2d51c..0127490 100644
1716 --- a/arch/arm/mach-ux500/mbox-db5500.c
1717 +++ b/arch/arm/mach-ux500/mbox-db5500.c
1718 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1719 return sprintf(buf, "0x%X\n", mbox_value);
1720 }
1721
1722 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1723 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1724
1725 static int mbox_show(struct seq_file *s, void *data)
1726 {
1727 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1728 index bb7eac3..3bade16 100644
1729 --- a/arch/arm/mm/fault.c
1730 +++ b/arch/arm/mm/fault.c
1731 @@ -172,6 +172,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1732 }
1733 #endif
1734
1735 +#ifdef CONFIG_PAX_PAGEEXEC
1736 + if (fsr & FSR_LNX_PF) {
1737 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1738 + do_group_exit(SIGKILL);
1739 + }
1740 +#endif
1741 +
1742 tsk->thread.address = addr;
1743 tsk->thread.error_code = fsr;
1744 tsk->thread.trap_no = 14;
1745 @@ -393,6 +400,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1746 }
1747 #endif /* CONFIG_MMU */
1748
1749 +#ifdef CONFIG_PAX_PAGEEXEC
1750 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1751 +{
1752 + long i;
1753 +
1754 + printk(KERN_ERR "PAX: bytes at PC: ");
1755 + for (i = 0; i < 20; i++) {
1756 + unsigned char c;
1757 + if (get_user(c, (__force unsigned char __user *)pc+i))
1758 + printk(KERN_CONT "?? ");
1759 + else
1760 + printk(KERN_CONT "%02x ", c);
1761 + }
1762 + printk("\n");
1763 +
1764 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1765 + for (i = -1; i < 20; i++) {
1766 + unsigned long c;
1767 + if (get_user(c, (__force unsigned long __user *)sp+i))
1768 + printk(KERN_CONT "???????? ");
1769 + else
1770 + printk(KERN_CONT "%08lx ", c);
1771 + }
1772 + printk("\n");
1773 +}
1774 +#endif
1775 +
1776 /*
1777 * First Level Translation Fault Handler
1778 *
1779 @@ -573,6 +607,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1780 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1781 struct siginfo info;
1782
1783 +#ifdef CONFIG_PAX_REFCOUNT
1784 + if (fsr_fs(ifsr) == 2) {
1785 + unsigned int bkpt;
1786 +
1787 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1788 + current->thread.error_code = ifsr;
1789 + current->thread.trap_no = 0;
1790 + pax_report_refcount_overflow(regs);
1791 + fixup_exception(regs);
1792 + return;
1793 + }
1794 + }
1795 +#endif
1796 +
1797 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1798 return;
1799
1800 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1801 index ce8cb19..3ec539d 100644
1802 --- a/arch/arm/mm/mmap.c
1803 +++ b/arch/arm/mm/mmap.c
1804 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1805 if (len > TASK_SIZE)
1806 return -ENOMEM;
1807
1808 +#ifdef CONFIG_PAX_RANDMMAP
1809 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1810 +#endif
1811 +
1812 if (addr) {
1813 if (do_align)
1814 addr = COLOUR_ALIGN(addr, pgoff);
1815 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1816 addr = PAGE_ALIGN(addr);
1817
1818 vma = find_vma(mm, addr);
1819 - if (TASK_SIZE - len >= addr &&
1820 - (!vma || addr + len <= vma->vm_start))
1821 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1822 return addr;
1823 }
1824 if (len > mm->cached_hole_size) {
1825 - start_addr = addr = mm->free_area_cache;
1826 + start_addr = addr = mm->free_area_cache;
1827 } else {
1828 - start_addr = addr = mm->mmap_base;
1829 - mm->cached_hole_size = 0;
1830 + start_addr = addr = mm->mmap_base;
1831 + mm->cached_hole_size = 0;
1832 }
1833
1834 full_search:
1835 @@ -124,14 +127,14 @@ full_search:
1836 * Start a new search - just in case we missed
1837 * some holes.
1838 */
1839 - if (start_addr != TASK_UNMAPPED_BASE) {
1840 - start_addr = addr = TASK_UNMAPPED_BASE;
1841 + if (start_addr != mm->mmap_base) {
1842 + start_addr = addr = mm->mmap_base;
1843 mm->cached_hole_size = 0;
1844 goto full_search;
1845 }
1846 return -ENOMEM;
1847 }
1848 - if (!vma || addr + len <= vma->vm_start) {
1849 + if (check_heap_stack_gap(vma, addr, len)) {
1850 /*
1851 * Remember the place where we stopped the search:
1852 */
1853 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1854
1855 if (mmap_is_legacy()) {
1856 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1857 +
1858 +#ifdef CONFIG_PAX_RANDMMAP
1859 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1860 + mm->mmap_base += mm->delta_mmap;
1861 +#endif
1862 +
1863 mm->get_unmapped_area = arch_get_unmapped_area;
1864 mm->unmap_area = arch_unmap_area;
1865 } else {
1866 mm->mmap_base = mmap_base(random_factor);
1867 +
1868 +#ifdef CONFIG_PAX_RANDMMAP
1869 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1870 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1871 +#endif
1872 +
1873 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1874 mm->unmap_area = arch_unmap_area_topdown;
1875 }
1876 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1877 index 71a6827..e7fbc23 100644
1878 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1879 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1880 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
1881 int (*started)(unsigned ch);
1882 int (*flush)(unsigned ch);
1883 int (*stop)(unsigned ch);
1884 -};
1885 +} __no_const;
1886
1887 extern void *samsung_dmadev_get_ops(void);
1888 extern void *s3c_dma_get_ops(void);
1889 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1890 index 5f28cae..3d23723 100644
1891 --- a/arch/arm/plat-samsung/include/plat/ehci.h
1892 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
1893 @@ -14,7 +14,7 @@
1894 struct s5p_ehci_platdata {
1895 int (*phy_init)(struct platform_device *pdev, int type);
1896 int (*phy_exit)(struct platform_device *pdev, int type);
1897 -};
1898 +} __no_const;
1899
1900 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
1901
1902 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
1903 index c3a58a1..78fbf54 100644
1904 --- a/arch/avr32/include/asm/cache.h
1905 +++ b/arch/avr32/include/asm/cache.h
1906 @@ -1,8 +1,10 @@
1907 #ifndef __ASM_AVR32_CACHE_H
1908 #define __ASM_AVR32_CACHE_H
1909
1910 +#include <linux/const.h>
1911 +
1912 #define L1_CACHE_SHIFT 5
1913 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1914 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1915
1916 /*
1917 * Memory returned by kmalloc() may be used for DMA, so we must make
1918 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1919 index 3b3159b..425ea94 100644
1920 --- a/arch/avr32/include/asm/elf.h
1921 +++ b/arch/avr32/include/asm/elf.h
1922 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1923 the loader. We need to make sure that it is out of the way of the program
1924 that it will "exec", and that there is sufficient room for the brk. */
1925
1926 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1927 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1928
1929 +#ifdef CONFIG_PAX_ASLR
1930 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1931 +
1932 +#define PAX_DELTA_MMAP_LEN 15
1933 +#define PAX_DELTA_STACK_LEN 15
1934 +#endif
1935
1936 /* This yields a mask that user programs can use to figure out what
1937 instruction set this CPU supports. This could be done in user space,
1938 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1939 index b7f5c68..556135c 100644
1940 --- a/arch/avr32/include/asm/kmap_types.h
1941 +++ b/arch/avr32/include/asm/kmap_types.h
1942 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1943 D(11) KM_IRQ1,
1944 D(12) KM_SOFTIRQ0,
1945 D(13) KM_SOFTIRQ1,
1946 -D(14) KM_TYPE_NR
1947 +D(14) KM_CLEARPAGE,
1948 +D(15) KM_TYPE_NR
1949 };
1950
1951 #undef D
1952 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1953 index f7040a1..db9f300 100644
1954 --- a/arch/avr32/mm/fault.c
1955 +++ b/arch/avr32/mm/fault.c
1956 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1957
1958 int exception_trace = 1;
1959
1960 +#ifdef CONFIG_PAX_PAGEEXEC
1961 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1962 +{
1963 + unsigned long i;
1964 +
1965 + printk(KERN_ERR "PAX: bytes at PC: ");
1966 + for (i = 0; i < 20; i++) {
1967 + unsigned char c;
1968 + if (get_user(c, (unsigned char *)pc+i))
1969 + printk(KERN_CONT "???????? ");
1970 + else
1971 + printk(KERN_CONT "%02x ", c);
1972 + }
1973 + printk("\n");
1974 +}
1975 +#endif
1976 +
1977 /*
1978 * This routine handles page faults. It determines the address and the
1979 * problem, and then passes it off to one of the appropriate routines.
1980 @@ -156,6 +173,16 @@ bad_area:
1981 up_read(&mm->mmap_sem);
1982
1983 if (user_mode(regs)) {
1984 +
1985 +#ifdef CONFIG_PAX_PAGEEXEC
1986 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1987 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1988 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1989 + do_group_exit(SIGKILL);
1990 + }
1991 + }
1992 +#endif
1993 +
1994 if (exception_trace && printk_ratelimit())
1995 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1996 "sp %08lx ecr %lu\n",
1997 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
1998 index 568885a..f8008df 100644
1999 --- a/arch/blackfin/include/asm/cache.h
2000 +++ b/arch/blackfin/include/asm/cache.h
2001 @@ -7,6 +7,7 @@
2002 #ifndef __ARCH_BLACKFIN_CACHE_H
2003 #define __ARCH_BLACKFIN_CACHE_H
2004
2005 +#include <linux/const.h>
2006 #include <linux/linkage.h> /* for asmlinkage */
2007
2008 /*
2009 @@ -14,7 +15,7 @@
2010 * Blackfin loads 32 bytes for cache
2011 */
2012 #define L1_CACHE_SHIFT 5
2013 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2014 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2015 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2016
2017 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2018 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2019 index aea2718..3639a60 100644
2020 --- a/arch/cris/include/arch-v10/arch/cache.h
2021 +++ b/arch/cris/include/arch-v10/arch/cache.h
2022 @@ -1,8 +1,9 @@
2023 #ifndef _ASM_ARCH_CACHE_H
2024 #define _ASM_ARCH_CACHE_H
2025
2026 +#include <linux/const.h>
2027 /* Etrax 100LX have 32-byte cache-lines. */
2028 -#define L1_CACHE_BYTES 32
2029 #define L1_CACHE_SHIFT 5
2030 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2031
2032 #endif /* _ASM_ARCH_CACHE_H */
2033 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2034 index 1de779f..336fad3 100644
2035 --- a/arch/cris/include/arch-v32/arch/cache.h
2036 +++ b/arch/cris/include/arch-v32/arch/cache.h
2037 @@ -1,11 +1,12 @@
2038 #ifndef _ASM_CRIS_ARCH_CACHE_H
2039 #define _ASM_CRIS_ARCH_CACHE_H
2040
2041 +#include <linux/const.h>
2042 #include <arch/hwregs/dma.h>
2043
2044 /* A cache-line is 32 bytes. */
2045 -#define L1_CACHE_BYTES 32
2046 #define L1_CACHE_SHIFT 5
2047 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2048
2049 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2050
2051 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2052 index 0d8a7d6..d0c9ff5 100644
2053 --- a/arch/frv/include/asm/atomic.h
2054 +++ b/arch/frv/include/asm/atomic.h
2055 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2056 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2057 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2058
2059 +#define atomic64_read_unchecked(v) atomic64_read(v)
2060 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2061 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2062 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2063 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2064 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2065 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2066 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2067 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2068 +
2069 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2070 {
2071 int c, old;
2072 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2073 index 2797163..c2a401d 100644
2074 --- a/arch/frv/include/asm/cache.h
2075 +++ b/arch/frv/include/asm/cache.h
2076 @@ -12,10 +12,11 @@
2077 #ifndef __ASM_CACHE_H
2078 #define __ASM_CACHE_H
2079
2080 +#include <linux/const.h>
2081
2082 /* bytes per L1 cache line */
2083 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2084 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2085 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2086
2087 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2088 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2089 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2090 index f8e16b2..c73ff79 100644
2091 --- a/arch/frv/include/asm/kmap_types.h
2092 +++ b/arch/frv/include/asm/kmap_types.h
2093 @@ -23,6 +23,7 @@ enum km_type {
2094 KM_IRQ1,
2095 KM_SOFTIRQ0,
2096 KM_SOFTIRQ1,
2097 + KM_CLEARPAGE,
2098 KM_TYPE_NR
2099 };
2100
2101 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2102 index 385fd30..6c3d97e 100644
2103 --- a/arch/frv/mm/elf-fdpic.c
2104 +++ b/arch/frv/mm/elf-fdpic.c
2105 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2106 if (addr) {
2107 addr = PAGE_ALIGN(addr);
2108 vma = find_vma(current->mm, addr);
2109 - if (TASK_SIZE - len >= addr &&
2110 - (!vma || addr + len <= vma->vm_start))
2111 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2112 goto success;
2113 }
2114
2115 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2116 for (; vma; vma = vma->vm_next) {
2117 if (addr > limit)
2118 break;
2119 - if (addr + len <= vma->vm_start)
2120 + if (check_heap_stack_gap(vma, addr, len))
2121 goto success;
2122 addr = vma->vm_end;
2123 }
2124 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2125 for (; vma; vma = vma->vm_next) {
2126 if (addr > limit)
2127 break;
2128 - if (addr + len <= vma->vm_start)
2129 + if (check_heap_stack_gap(vma, addr, len))
2130 goto success;
2131 addr = vma->vm_end;
2132 }
2133 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2134 index c635028..6d9445a 100644
2135 --- a/arch/h8300/include/asm/cache.h
2136 +++ b/arch/h8300/include/asm/cache.h
2137 @@ -1,8 +1,10 @@
2138 #ifndef __ARCH_H8300_CACHE_H
2139 #define __ARCH_H8300_CACHE_H
2140
2141 +#include <linux/const.h>
2142 +
2143 /* bytes per L1 cache line */
2144 -#define L1_CACHE_BYTES 4
2145 +#define L1_CACHE_BYTES _AC(4,UL)
2146
2147 /* m68k-elf-gcc 2.95.2 doesn't like these */
2148
2149 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2150 index 0f01de2..d37d309 100644
2151 --- a/arch/hexagon/include/asm/cache.h
2152 +++ b/arch/hexagon/include/asm/cache.h
2153 @@ -21,9 +21,11 @@
2154 #ifndef __ASM_CACHE_H
2155 #define __ASM_CACHE_H
2156
2157 +#include <linux/const.h>
2158 +
2159 /* Bytes per L1 cache line */
2160 -#define L1_CACHE_SHIFT (5)
2161 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2162 +#define L1_CACHE_SHIFT 5
2163 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2164
2165 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2166 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2167 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2168 index 3fad89e..3047da5 100644
2169 --- a/arch/ia64/include/asm/atomic.h
2170 +++ b/arch/ia64/include/asm/atomic.h
2171 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2172 #define atomic64_inc(v) atomic64_add(1, (v))
2173 #define atomic64_dec(v) atomic64_sub(1, (v))
2174
2175 +#define atomic64_read_unchecked(v) atomic64_read(v)
2176 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2177 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2178 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2179 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2180 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2181 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2182 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2183 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2184 +
2185 /* Atomic operations are already serializing */
2186 #define smp_mb__before_atomic_dec() barrier()
2187 #define smp_mb__after_atomic_dec() barrier()
2188 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2189 index 988254a..e1ee885 100644
2190 --- a/arch/ia64/include/asm/cache.h
2191 +++ b/arch/ia64/include/asm/cache.h
2192 @@ -1,6 +1,7 @@
2193 #ifndef _ASM_IA64_CACHE_H
2194 #define _ASM_IA64_CACHE_H
2195
2196 +#include <linux/const.h>
2197
2198 /*
2199 * Copyright (C) 1998-2000 Hewlett-Packard Co
2200 @@ -9,7 +10,7 @@
2201
2202 /* Bytes per L1 (data) cache line. */
2203 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2204 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2205 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2206
2207 #ifdef CONFIG_SMP
2208 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2209 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2210 index b5298eb..67c6e62 100644
2211 --- a/arch/ia64/include/asm/elf.h
2212 +++ b/arch/ia64/include/asm/elf.h
2213 @@ -42,6 +42,13 @@
2214 */
2215 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2216
2217 +#ifdef CONFIG_PAX_ASLR
2218 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2219 +
2220 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2221 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2222 +#endif
2223 +
2224 #define PT_IA_64_UNWIND 0x70000001
2225
2226 /* IA-64 relocations: */
2227 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2228 index 1a97af3..7529d31 100644
2229 --- a/arch/ia64/include/asm/pgtable.h
2230 +++ b/arch/ia64/include/asm/pgtable.h
2231 @@ -12,7 +12,7 @@
2232 * David Mosberger-Tang <davidm@hpl.hp.com>
2233 */
2234
2235 -
2236 +#include <linux/const.h>
2237 #include <asm/mman.h>
2238 #include <asm/page.h>
2239 #include <asm/processor.h>
2240 @@ -143,6 +143,17 @@
2241 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2242 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2243 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2244 +
2245 +#ifdef CONFIG_PAX_PAGEEXEC
2246 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2247 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2248 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2249 +#else
2250 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2251 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2252 +# define PAGE_COPY_NOEXEC PAGE_COPY
2253 +#endif
2254 +
2255 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2256 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2257 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2258 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2259 index b77768d..e0795eb 100644
2260 --- a/arch/ia64/include/asm/spinlock.h
2261 +++ b/arch/ia64/include/asm/spinlock.h
2262 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2263 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2264
2265 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2266 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2267 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2268 }
2269
2270 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2271 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2272 index 449c8c0..432a3d2 100644
2273 --- a/arch/ia64/include/asm/uaccess.h
2274 +++ b/arch/ia64/include/asm/uaccess.h
2275 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2276 const void *__cu_from = (from); \
2277 long __cu_len = (n); \
2278 \
2279 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2280 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2281 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2282 __cu_len; \
2283 })
2284 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2285 long __cu_len = (n); \
2286 \
2287 __chk_user_ptr(__cu_from); \
2288 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2289 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2290 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2291 __cu_len; \
2292 })
2293 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2294 index 24603be..948052d 100644
2295 --- a/arch/ia64/kernel/module.c
2296 +++ b/arch/ia64/kernel/module.c
2297 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2298 void
2299 module_free (struct module *mod, void *module_region)
2300 {
2301 - if (mod && mod->arch.init_unw_table &&
2302 - module_region == mod->module_init) {
2303 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2304 unw_remove_unwind_table(mod->arch.init_unw_table);
2305 mod->arch.init_unw_table = NULL;
2306 }
2307 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2308 }
2309
2310 static inline int
2311 +in_init_rx (const struct module *mod, uint64_t addr)
2312 +{
2313 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2314 +}
2315 +
2316 +static inline int
2317 +in_init_rw (const struct module *mod, uint64_t addr)
2318 +{
2319 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2320 +}
2321 +
2322 +static inline int
2323 in_init (const struct module *mod, uint64_t addr)
2324 {
2325 - return addr - (uint64_t) mod->module_init < mod->init_size;
2326 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2327 +}
2328 +
2329 +static inline int
2330 +in_core_rx (const struct module *mod, uint64_t addr)
2331 +{
2332 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2333 +}
2334 +
2335 +static inline int
2336 +in_core_rw (const struct module *mod, uint64_t addr)
2337 +{
2338 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2339 }
2340
2341 static inline int
2342 in_core (const struct module *mod, uint64_t addr)
2343 {
2344 - return addr - (uint64_t) mod->module_core < mod->core_size;
2345 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2346 }
2347
2348 static inline int
2349 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2350 break;
2351
2352 case RV_BDREL:
2353 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2354 + if (in_init_rx(mod, val))
2355 + val -= (uint64_t) mod->module_init_rx;
2356 + else if (in_init_rw(mod, val))
2357 + val -= (uint64_t) mod->module_init_rw;
2358 + else if (in_core_rx(mod, val))
2359 + val -= (uint64_t) mod->module_core_rx;
2360 + else if (in_core_rw(mod, val))
2361 + val -= (uint64_t) mod->module_core_rw;
2362 break;
2363
2364 case RV_LTV:
2365 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2366 * addresses have been selected...
2367 */
2368 uint64_t gp;
2369 - if (mod->core_size > MAX_LTOFF)
2370 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2371 /*
2372 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2373 * at the end of the module.
2374 */
2375 - gp = mod->core_size - MAX_LTOFF / 2;
2376 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2377 else
2378 - gp = mod->core_size / 2;
2379 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2380 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2381 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2382 mod->arch.gp = gp;
2383 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2384 }
2385 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2386 index 609d500..7dde2a8 100644
2387 --- a/arch/ia64/kernel/sys_ia64.c
2388 +++ b/arch/ia64/kernel/sys_ia64.c
2389 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2390 if (REGION_NUMBER(addr) == RGN_HPAGE)
2391 addr = 0;
2392 #endif
2393 +
2394 +#ifdef CONFIG_PAX_RANDMMAP
2395 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2396 + addr = mm->free_area_cache;
2397 + else
2398 +#endif
2399 +
2400 if (!addr)
2401 addr = mm->free_area_cache;
2402
2403 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2404 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2405 /* At this point: (!vma || addr < vma->vm_end). */
2406 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2407 - if (start_addr != TASK_UNMAPPED_BASE) {
2408 + if (start_addr != mm->mmap_base) {
2409 /* Start a new search --- just in case we missed some holes. */
2410 - addr = TASK_UNMAPPED_BASE;
2411 + addr = mm->mmap_base;
2412 goto full_search;
2413 }
2414 return -ENOMEM;
2415 }
2416 - if (!vma || addr + len <= vma->vm_start) {
2417 + if (check_heap_stack_gap(vma, addr, len)) {
2418 /* Remember the address where we stopped this search: */
2419 mm->free_area_cache = addr + len;
2420 return addr;
2421 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2422 index 53c0ba0..2accdde 100644
2423 --- a/arch/ia64/kernel/vmlinux.lds.S
2424 +++ b/arch/ia64/kernel/vmlinux.lds.S
2425 @@ -199,7 +199,7 @@ SECTIONS {
2426 /* Per-cpu data: */
2427 . = ALIGN(PERCPU_PAGE_SIZE);
2428 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2429 - __phys_per_cpu_start = __per_cpu_load;
2430 + __phys_per_cpu_start = per_cpu_load;
2431 /*
2432 * ensure percpu data fits
2433 * into percpu page size
2434 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2435 index 20b3593..1ce77f0 100644
2436 --- a/arch/ia64/mm/fault.c
2437 +++ b/arch/ia64/mm/fault.c
2438 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2439 return pte_present(pte);
2440 }
2441
2442 +#ifdef CONFIG_PAX_PAGEEXEC
2443 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2444 +{
2445 + unsigned long i;
2446 +
2447 + printk(KERN_ERR "PAX: bytes at PC: ");
2448 + for (i = 0; i < 8; i++) {
2449 + unsigned int c;
2450 + if (get_user(c, (unsigned int *)pc+i))
2451 + printk(KERN_CONT "???????? ");
2452 + else
2453 + printk(KERN_CONT "%08x ", c);
2454 + }
2455 + printk("\n");
2456 +}
2457 +#endif
2458 +
2459 void __kprobes
2460 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2461 {
2462 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2463 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2464 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2465
2466 - if ((vma->vm_flags & mask) != mask)
2467 + if ((vma->vm_flags & mask) != mask) {
2468 +
2469 +#ifdef CONFIG_PAX_PAGEEXEC
2470 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2471 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2472 + goto bad_area;
2473 +
2474 + up_read(&mm->mmap_sem);
2475 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2476 + do_group_exit(SIGKILL);
2477 + }
2478 +#endif
2479 +
2480 goto bad_area;
2481
2482 + }
2483 +
2484 /*
2485 * If for any reason at all we couldn't handle the fault, make
2486 * sure we exit gracefully rather than endlessly redo the
2487 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2488 index 5ca674b..e0e1b70 100644
2489 --- a/arch/ia64/mm/hugetlbpage.c
2490 +++ b/arch/ia64/mm/hugetlbpage.c
2491 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2492 /* At this point: (!vmm || addr < vmm->vm_end). */
2493 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2494 return -ENOMEM;
2495 - if (!vmm || (addr + len) <= vmm->vm_start)
2496 + if (check_heap_stack_gap(vmm, addr, len))
2497 return addr;
2498 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2499 }
2500 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2501 index 13df239d..cb52116 100644
2502 --- a/arch/ia64/mm/init.c
2503 +++ b/arch/ia64/mm/init.c
2504 @@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2505 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2506 vma->vm_end = vma->vm_start + PAGE_SIZE;
2507 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2508 +
2509 +#ifdef CONFIG_PAX_PAGEEXEC
2510 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2511 + vma->vm_flags &= ~VM_EXEC;
2512 +
2513 +#ifdef CONFIG_PAX_MPROTECT
2514 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2515 + vma->vm_flags &= ~VM_MAYEXEC;
2516 +#endif
2517 +
2518 + }
2519 +#endif
2520 +
2521 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2522 down_write(&current->mm->mmap_sem);
2523 if (insert_vm_struct(current->mm, vma)) {
2524 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2525 index 40b3ee9..8c2c112 100644
2526 --- a/arch/m32r/include/asm/cache.h
2527 +++ b/arch/m32r/include/asm/cache.h
2528 @@ -1,8 +1,10 @@
2529 #ifndef _ASM_M32R_CACHE_H
2530 #define _ASM_M32R_CACHE_H
2531
2532 +#include <linux/const.h>
2533 +
2534 /* L1 cache line size */
2535 #define L1_CACHE_SHIFT 4
2536 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2537 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2538
2539 #endif /* _ASM_M32R_CACHE_H */
2540 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2541 index 82abd15..d95ae5d 100644
2542 --- a/arch/m32r/lib/usercopy.c
2543 +++ b/arch/m32r/lib/usercopy.c
2544 @@ -14,6 +14,9 @@
2545 unsigned long
2546 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2547 {
2548 + if ((long)n < 0)
2549 + return n;
2550 +
2551 prefetch(from);
2552 if (access_ok(VERIFY_WRITE, to, n))
2553 __copy_user(to,from,n);
2554 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2555 unsigned long
2556 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2557 {
2558 + if ((long)n < 0)
2559 + return n;
2560 +
2561 prefetchw(to);
2562 if (access_ok(VERIFY_READ, from, n))
2563 __copy_user_zeroing(to,from,n);
2564 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2565 index 0395c51..5f26031 100644
2566 --- a/arch/m68k/include/asm/cache.h
2567 +++ b/arch/m68k/include/asm/cache.h
2568 @@ -4,9 +4,11 @@
2569 #ifndef __ARCH_M68K_CACHE_H
2570 #define __ARCH_M68K_CACHE_H
2571
2572 +#include <linux/const.h>
2573 +
2574 /* bytes per L1 cache line */
2575 #define L1_CACHE_SHIFT 4
2576 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2577 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2578
2579 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2580
2581 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2582 index 4efe96a..60e8699 100644
2583 --- a/arch/microblaze/include/asm/cache.h
2584 +++ b/arch/microblaze/include/asm/cache.h
2585 @@ -13,11 +13,12 @@
2586 #ifndef _ASM_MICROBLAZE_CACHE_H
2587 #define _ASM_MICROBLAZE_CACHE_H
2588
2589 +#include <linux/const.h>
2590 #include <asm/registers.h>
2591
2592 #define L1_CACHE_SHIFT 5
2593 /* word-granular cache in microblaze */
2594 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2595 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2596
2597 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2598
2599 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2600 index 1d93f81..67794d0 100644
2601 --- a/arch/mips/include/asm/atomic.h
2602 +++ b/arch/mips/include/asm/atomic.h
2603 @@ -21,6 +21,10 @@
2604 #include <asm/war.h>
2605 #include <asm/system.h>
2606
2607 +#ifdef CONFIG_GENERIC_ATOMIC64
2608 +#include <asm-generic/atomic64.h>
2609 +#endif
2610 +
2611 #define ATOMIC_INIT(i) { (i) }
2612
2613 /*
2614 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2615 */
2616 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2617
2618 +#define atomic64_read_unchecked(v) atomic64_read(v)
2619 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2620 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2621 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2622 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2623 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2624 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2625 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2626 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2627 +
2628 #endif /* CONFIG_64BIT */
2629
2630 /*
2631 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2632 index b4db69f..8f3b093 100644
2633 --- a/arch/mips/include/asm/cache.h
2634 +++ b/arch/mips/include/asm/cache.h
2635 @@ -9,10 +9,11 @@
2636 #ifndef _ASM_CACHE_H
2637 #define _ASM_CACHE_H
2638
2639 +#include <linux/const.h>
2640 #include <kmalloc.h>
2641
2642 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2643 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2644 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2645
2646 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2647 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2648 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2649 index 455c0ac..ad65fbe 100644
2650 --- a/arch/mips/include/asm/elf.h
2651 +++ b/arch/mips/include/asm/elf.h
2652 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2653 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2654 #endif
2655
2656 +#ifdef CONFIG_PAX_ASLR
2657 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2658 +
2659 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2660 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2661 +#endif
2662 +
2663 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2664 struct linux_binprm;
2665 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2666 int uses_interp);
2667
2668 -struct mm_struct;
2669 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2670 -#define arch_randomize_brk arch_randomize_brk
2671 -
2672 #endif /* _ASM_ELF_H */
2673 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2674 index da9bd7d..91aa7ab 100644
2675 --- a/arch/mips/include/asm/page.h
2676 +++ b/arch/mips/include/asm/page.h
2677 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2678 #ifdef CONFIG_CPU_MIPS32
2679 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2680 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2681 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2682 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2683 #else
2684 typedef struct { unsigned long long pte; } pte_t;
2685 #define pte_val(x) ((x).pte)
2686 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2687 index 6018c80..7c37203 100644
2688 --- a/arch/mips/include/asm/system.h
2689 +++ b/arch/mips/include/asm/system.h
2690 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2691 */
2692 #define __ARCH_WANT_UNLOCKED_CTXSW
2693
2694 -extern unsigned long arch_align_stack(unsigned long sp);
2695 +#define arch_align_stack(x) ((x) & ~0xfUL)
2696
2697 #endif /* _ASM_SYSTEM_H */
2698 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2699 index 9fdd8bc..4bd7f1a 100644
2700 --- a/arch/mips/kernel/binfmt_elfn32.c
2701 +++ b/arch/mips/kernel/binfmt_elfn32.c
2702 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2703 #undef ELF_ET_DYN_BASE
2704 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2705
2706 +#ifdef CONFIG_PAX_ASLR
2707 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2708 +
2709 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2710 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2711 +#endif
2712 +
2713 #include <asm/processor.h>
2714 #include <linux/module.h>
2715 #include <linux/elfcore.h>
2716 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2717 index ff44823..97f8906 100644
2718 --- a/arch/mips/kernel/binfmt_elfo32.c
2719 +++ b/arch/mips/kernel/binfmt_elfo32.c
2720 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2721 #undef ELF_ET_DYN_BASE
2722 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2723
2724 +#ifdef CONFIG_PAX_ASLR
2725 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2726 +
2727 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2728 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2729 +#endif
2730 +
2731 #include <asm/processor.h>
2732
2733 /*
2734 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2735 index 7955409..ceaea7c 100644
2736 --- a/arch/mips/kernel/process.c
2737 +++ b/arch/mips/kernel/process.c
2738 @@ -483,15 +483,3 @@ unsigned long get_wchan(struct task_struct *task)
2739 out:
2740 return pc;
2741 }
2742 -
2743 -/*
2744 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2745 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2746 - */
2747 -unsigned long arch_align_stack(unsigned long sp)
2748 -{
2749 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2750 - sp -= get_random_int() & ~PAGE_MASK;
2751 -
2752 - return sp & ALMASK;
2753 -}
2754 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2755 index 69ebd58..e4bff83 100644
2756 --- a/arch/mips/mm/fault.c
2757 +++ b/arch/mips/mm/fault.c
2758 @@ -28,6 +28,23 @@
2759 #include <asm/highmem.h> /* For VMALLOC_END */
2760 #include <linux/kdebug.h>
2761
2762 +#ifdef CONFIG_PAX_PAGEEXEC
2763 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2764 +{
2765 + unsigned long i;
2766 +
2767 + printk(KERN_ERR "PAX: bytes at PC: ");
2768 + for (i = 0; i < 5; i++) {
2769 + unsigned int c;
2770 + if (get_user(c, (unsigned int *)pc+i))
2771 + printk(KERN_CONT "???????? ");
2772 + else
2773 + printk(KERN_CONT "%08x ", c);
2774 + }
2775 + printk("\n");
2776 +}
2777 +#endif
2778 +
2779 /*
2780 * This routine handles page faults. It determines the address,
2781 * and the problem, and then passes it off to one of the appropriate
2782 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
2783 index 302d779..7d35bf8 100644
2784 --- a/arch/mips/mm/mmap.c
2785 +++ b/arch/mips/mm/mmap.c
2786 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2787 do_color_align = 1;
2788
2789 /* requesting a specific address */
2790 +
2791 +#ifdef CONFIG_PAX_RANDMMAP
2792 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2793 +#endif
2794 +
2795 if (addr) {
2796 if (do_color_align)
2797 addr = COLOUR_ALIGN(addr, pgoff);
2798 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2799 addr = PAGE_ALIGN(addr);
2800
2801 vma = find_vma(mm, addr);
2802 - if (TASK_SIZE - len >= addr &&
2803 - (!vma || addr + len <= vma->vm_start))
2804 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
2805 return addr;
2806 }
2807
2808 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2809 /* At this point: (!vma || addr < vma->vm_end). */
2810 if (TASK_SIZE - len < addr)
2811 return -ENOMEM;
2812 - if (!vma || addr + len <= vma->vm_start)
2813 + if (check_heap_stack_gap(vmm, addr, len))
2814 return addr;
2815 addr = vma->vm_end;
2816 if (do_color_align)
2817 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2818 /* make sure it can fit in the remaining address space */
2819 if (likely(addr > len)) {
2820 vma = find_vma(mm, addr - len);
2821 - if (!vma || addr <= vma->vm_start) {
2822 + if (check_heap_stack_gap(vmm, addr - len, len))
2823 /* cache the address as a hint for next time */
2824 return mm->free_area_cache = addr - len;
2825 }
2826 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2827 * return with success:
2828 */
2829 vma = find_vma(mm, addr);
2830 - if (likely(!vma || addr + len <= vma->vm_start)) {
2831 + if (check_heap_stack_gap(vmm, addr, len)) {
2832 /* cache the address as a hint for next time */
2833 return mm->free_area_cache = addr;
2834 }
2835 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2836 mm->unmap_area = arch_unmap_area_topdown;
2837 }
2838 }
2839 -
2840 -static inline unsigned long brk_rnd(void)
2841 -{
2842 - unsigned long rnd = get_random_int();
2843 -
2844 - rnd = rnd << PAGE_SHIFT;
2845 - /* 8MB for 32bit, 256MB for 64bit */
2846 - if (TASK_IS_32BIT_ADDR)
2847 - rnd = rnd & 0x7ffffful;
2848 - else
2849 - rnd = rnd & 0xffffffful;
2850 -
2851 - return rnd;
2852 -}
2853 -
2854 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2855 -{
2856 - unsigned long base = mm->brk;
2857 - unsigned long ret;
2858 -
2859 - ret = PAGE_ALIGN(base + brk_rnd());
2860 -
2861 - if (ret < mm->brk)
2862 - return mm->brk;
2863 -
2864 - return ret;
2865 -}
2866 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2867 index 967d144..db12197 100644
2868 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
2869 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2870 @@ -11,12 +11,14 @@
2871 #ifndef _ASM_PROC_CACHE_H
2872 #define _ASM_PROC_CACHE_H
2873
2874 +#include <linux/const.h>
2875 +
2876 /* L1 cache */
2877
2878 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2879 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
2880 -#define L1_CACHE_BYTES 16 /* bytes per entry */
2881 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
2882 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2883 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
2884
2885 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2886 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2887 index bcb5df2..84fabd2 100644
2888 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2889 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2890 @@ -16,13 +16,15 @@
2891 #ifndef _ASM_PROC_CACHE_H
2892 #define _ASM_PROC_CACHE_H
2893
2894 +#include <linux/const.h>
2895 +
2896 /*
2897 * L1 cache
2898 */
2899 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2900 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
2901 -#define L1_CACHE_BYTES 32 /* bytes per entry */
2902 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
2903 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2904 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
2905
2906 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2907 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
2908 index 4ce7a01..449202a 100644
2909 --- a/arch/openrisc/include/asm/cache.h
2910 +++ b/arch/openrisc/include/asm/cache.h
2911 @@ -19,11 +19,13 @@
2912 #ifndef __ASM_OPENRISC_CACHE_H
2913 #define __ASM_OPENRISC_CACHE_H
2914
2915 +#include <linux/const.h>
2916 +
2917 /* FIXME: How can we replace these with values from the CPU...
2918 * they shouldn't be hard-coded!
2919 */
2920
2921 -#define L1_CACHE_BYTES 16
2922 #define L1_CACHE_SHIFT 4
2923 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2924
2925 #endif /* __ASM_OPENRISC_CACHE_H */
2926 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
2927 index 4054b31..a10c105 100644
2928 --- a/arch/parisc/include/asm/atomic.h
2929 +++ b/arch/parisc/include/asm/atomic.h
2930 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2931
2932 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
2933
2934 +#define atomic64_read_unchecked(v) atomic64_read(v)
2935 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2936 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2937 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2938 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2939 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2940 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2941 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2942 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2943 +
2944 #endif /* !CONFIG_64BIT */
2945
2946
2947 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
2948 index 47f11c7..3420df2 100644
2949 --- a/arch/parisc/include/asm/cache.h
2950 +++ b/arch/parisc/include/asm/cache.h
2951 @@ -5,6 +5,7 @@
2952 #ifndef __ARCH_PARISC_CACHE_H
2953 #define __ARCH_PARISC_CACHE_H
2954
2955 +#include <linux/const.h>
2956
2957 /*
2958 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
2959 @@ -15,13 +16,13 @@
2960 * just ruin performance.
2961 */
2962 #ifdef CONFIG_PA20
2963 -#define L1_CACHE_BYTES 64
2964 #define L1_CACHE_SHIFT 6
2965 #else
2966 -#define L1_CACHE_BYTES 32
2967 #define L1_CACHE_SHIFT 5
2968 #endif
2969
2970 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2971 +
2972 #ifndef __ASSEMBLY__
2973
2974 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2975 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2976 index 19f6cb1..6c78cf2 100644
2977 --- a/arch/parisc/include/asm/elf.h
2978 +++ b/arch/parisc/include/asm/elf.h
2979 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
2980
2981 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2982
2983 +#ifdef CONFIG_PAX_ASLR
2984 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2985 +
2986 +#define PAX_DELTA_MMAP_LEN 16
2987 +#define PAX_DELTA_STACK_LEN 16
2988 +#endif
2989 +
2990 /* This yields a mask that user programs can use to figure out what
2991 instruction set this CPU supports. This could be done in user space,
2992 but it's not easy, and we've already done it here. */
2993 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
2994 index 22dadeb..f6c2be4 100644
2995 --- a/arch/parisc/include/asm/pgtable.h
2996 +++ b/arch/parisc/include/asm/pgtable.h
2997 @@ -210,6 +210,17 @@ struct vm_area_struct;
2998 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2999 #define PAGE_COPY PAGE_EXECREAD
3000 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3001 +
3002 +#ifdef CONFIG_PAX_PAGEEXEC
3003 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3004 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3005 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3006 +#else
3007 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3008 +# define PAGE_COPY_NOEXEC PAGE_COPY
3009 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3010 +#endif
3011 +
3012 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3013 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3014 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3015 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3016 index 5e34ccf..672bc9c 100644
3017 --- a/arch/parisc/kernel/module.c
3018 +++ b/arch/parisc/kernel/module.c
3019 @@ -98,16 +98,38 @@
3020
3021 /* three functions to determine where in the module core
3022 * or init pieces the location is */
3023 +static inline int in_init_rx(struct module *me, void *loc)
3024 +{
3025 + return (loc >= me->module_init_rx &&
3026 + loc < (me->module_init_rx + me->init_size_rx));
3027 +}
3028 +
3029 +static inline int in_init_rw(struct module *me, void *loc)
3030 +{
3031 + return (loc >= me->module_init_rw &&
3032 + loc < (me->module_init_rw + me->init_size_rw));
3033 +}
3034 +
3035 static inline int in_init(struct module *me, void *loc)
3036 {
3037 - return (loc >= me->module_init &&
3038 - loc <= (me->module_init + me->init_size));
3039 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3040 +}
3041 +
3042 +static inline int in_core_rx(struct module *me, void *loc)
3043 +{
3044 + return (loc >= me->module_core_rx &&
3045 + loc < (me->module_core_rx + me->core_size_rx));
3046 +}
3047 +
3048 +static inline int in_core_rw(struct module *me, void *loc)
3049 +{
3050 + return (loc >= me->module_core_rw &&
3051 + loc < (me->module_core_rw + me->core_size_rw));
3052 }
3053
3054 static inline int in_core(struct module *me, void *loc)
3055 {
3056 - return (loc >= me->module_core &&
3057 - loc <= (me->module_core + me->core_size));
3058 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3059 }
3060
3061 static inline int in_local(struct module *me, void *loc)
3062 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3063 }
3064
3065 /* align things a bit */
3066 - me->core_size = ALIGN(me->core_size, 16);
3067 - me->arch.got_offset = me->core_size;
3068 - me->core_size += gots * sizeof(struct got_entry);
3069 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3070 + me->arch.got_offset = me->core_size_rw;
3071 + me->core_size_rw += gots * sizeof(struct got_entry);
3072
3073 - me->core_size = ALIGN(me->core_size, 16);
3074 - me->arch.fdesc_offset = me->core_size;
3075 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3076 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3077 + me->arch.fdesc_offset = me->core_size_rw;
3078 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3079
3080 me->arch.got_max = gots;
3081 me->arch.fdesc_max = fdescs;
3082 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3083
3084 BUG_ON(value == 0);
3085
3086 - got = me->module_core + me->arch.got_offset;
3087 + got = me->module_core_rw + me->arch.got_offset;
3088 for (i = 0; got[i].addr; i++)
3089 if (got[i].addr == value)
3090 goto out;
3091 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3092 #ifdef CONFIG_64BIT
3093 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3094 {
3095 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3096 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3097
3098 if (!value) {
3099 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3100 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3101
3102 /* Create new one */
3103 fdesc->addr = value;
3104 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3105 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3106 return (Elf_Addr)fdesc;
3107 }
3108 #endif /* CONFIG_64BIT */
3109 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3110
3111 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3112 end = table + sechdrs[me->arch.unwind_section].sh_size;
3113 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3114 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3115
3116 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3117 me->arch.unwind_section, table, end, gp);
3118 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3119 index c9b9322..02d8940 100644
3120 --- a/arch/parisc/kernel/sys_parisc.c
3121 +++ b/arch/parisc/kernel/sys_parisc.c
3122 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3123 /* At this point: (!vma || addr < vma->vm_end). */
3124 if (TASK_SIZE - len < addr)
3125 return -ENOMEM;
3126 - if (!vma || addr + len <= vma->vm_start)
3127 + if (check_heap_stack_gap(vma, addr, len))
3128 return addr;
3129 addr = vma->vm_end;
3130 }
3131 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3132 /* At this point: (!vma || addr < vma->vm_end). */
3133 if (TASK_SIZE - len < addr)
3134 return -ENOMEM;
3135 - if (!vma || addr + len <= vma->vm_start)
3136 + if (check_heap_stack_gap(vma, addr, len))
3137 return addr;
3138 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3139 if (addr < vma->vm_end) /* handle wraparound */
3140 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3141 if (flags & MAP_FIXED)
3142 return addr;
3143 if (!addr)
3144 - addr = TASK_UNMAPPED_BASE;
3145 + addr = current->mm->mmap_base;
3146
3147 if (filp) {
3148 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3149 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3150 index f19e660..414fe24 100644
3151 --- a/arch/parisc/kernel/traps.c
3152 +++ b/arch/parisc/kernel/traps.c
3153 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3154
3155 down_read(&current->mm->mmap_sem);
3156 vma = find_vma(current->mm,regs->iaoq[0]);
3157 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3158 - && (vma->vm_flags & VM_EXEC)) {
3159 -
3160 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3161 fault_address = regs->iaoq[0];
3162 fault_space = regs->iasq[0];
3163
3164 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3165 index 18162ce..94de376 100644
3166 --- a/arch/parisc/mm/fault.c
3167 +++ b/arch/parisc/mm/fault.c
3168 @@ -15,6 +15,7 @@
3169 #include <linux/sched.h>
3170 #include <linux/interrupt.h>
3171 #include <linux/module.h>
3172 +#include <linux/unistd.h>
3173
3174 #include <asm/uaccess.h>
3175 #include <asm/traps.h>
3176 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3177 static unsigned long
3178 parisc_acctyp(unsigned long code, unsigned int inst)
3179 {
3180 - if (code == 6 || code == 16)
3181 + if (code == 6 || code == 7 || code == 16)
3182 return VM_EXEC;
3183
3184 switch (inst & 0xf0000000) {
3185 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3186 }
3187 #endif
3188
3189 +#ifdef CONFIG_PAX_PAGEEXEC
3190 +/*
3191 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3192 + *
3193 + * returns 1 when task should be killed
3194 + * 2 when rt_sigreturn trampoline was detected
3195 + * 3 when unpatched PLT trampoline was detected
3196 + */
3197 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3198 +{
3199 +
3200 +#ifdef CONFIG_PAX_EMUPLT
3201 + int err;
3202 +
3203 + do { /* PaX: unpatched PLT emulation */
3204 + unsigned int bl, depwi;
3205 +
3206 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3207 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3208 +
3209 + if (err)
3210 + break;
3211 +
3212 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3213 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3214 +
3215 + err = get_user(ldw, (unsigned int *)addr);
3216 + err |= get_user(bv, (unsigned int *)(addr+4));
3217 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3218 +
3219 + if (err)
3220 + break;
3221 +
3222 + if (ldw == 0x0E801096U &&
3223 + bv == 0xEAC0C000U &&
3224 + ldw2 == 0x0E881095U)
3225 + {
3226 + unsigned int resolver, map;
3227 +
3228 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3229 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3230 + if (err)
3231 + break;
3232 +
3233 + regs->gr[20] = instruction_pointer(regs)+8;
3234 + regs->gr[21] = map;
3235 + regs->gr[22] = resolver;
3236 + regs->iaoq[0] = resolver | 3UL;
3237 + regs->iaoq[1] = regs->iaoq[0] + 4;
3238 + return 3;
3239 + }
3240 + }
3241 + } while (0);
3242 +#endif
3243 +
3244 +#ifdef CONFIG_PAX_EMUTRAMP
3245 +
3246 +#ifndef CONFIG_PAX_EMUSIGRT
3247 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3248 + return 1;
3249 +#endif
3250 +
3251 + do { /* PaX: rt_sigreturn emulation */
3252 + unsigned int ldi1, ldi2, bel, nop;
3253 +
3254 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3255 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3256 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3257 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3258 +
3259 + if (err)
3260 + break;
3261 +
3262 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3263 + ldi2 == 0x3414015AU &&
3264 + bel == 0xE4008200U &&
3265 + nop == 0x08000240U)
3266 + {
3267 + regs->gr[25] = (ldi1 & 2) >> 1;
3268 + regs->gr[20] = __NR_rt_sigreturn;
3269 + regs->gr[31] = regs->iaoq[1] + 16;
3270 + regs->sr[0] = regs->iasq[1];
3271 + regs->iaoq[0] = 0x100UL;
3272 + regs->iaoq[1] = regs->iaoq[0] + 4;
3273 + regs->iasq[0] = regs->sr[2];
3274 + regs->iasq[1] = regs->sr[2];
3275 + return 2;
3276 + }
3277 + } while (0);
3278 +#endif
3279 +
3280 + return 1;
3281 +}
3282 +
3283 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3284 +{
3285 + unsigned long i;
3286 +
3287 + printk(KERN_ERR "PAX: bytes at PC: ");
3288 + for (i = 0; i < 5; i++) {
3289 + unsigned int c;
3290 + if (get_user(c, (unsigned int *)pc+i))
3291 + printk(KERN_CONT "???????? ");
3292 + else
3293 + printk(KERN_CONT "%08x ", c);
3294 + }
3295 + printk("\n");
3296 +}
3297 +#endif
3298 +
3299 int fixup_exception(struct pt_regs *regs)
3300 {
3301 const struct exception_table_entry *fix;
3302 @@ -192,8 +303,33 @@ good_area:
3303
3304 acc_type = parisc_acctyp(code,regs->iir);
3305
3306 - if ((vma->vm_flags & acc_type) != acc_type)
3307 + if ((vma->vm_flags & acc_type) != acc_type) {
3308 +
3309 +#ifdef CONFIG_PAX_PAGEEXEC
3310 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3311 + (address & ~3UL) == instruction_pointer(regs))
3312 + {
3313 + up_read(&mm->mmap_sem);
3314 + switch (pax_handle_fetch_fault(regs)) {
3315 +
3316 +#ifdef CONFIG_PAX_EMUPLT
3317 + case 3:
3318 + return;
3319 +#endif
3320 +
3321 +#ifdef CONFIG_PAX_EMUTRAMP
3322 + case 2:
3323 + return;
3324 +#endif
3325 +
3326 + }
3327 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3328 + do_group_exit(SIGKILL);
3329 + }
3330 +#endif
3331 +
3332 goto bad_area;
3333 + }
3334
3335 /*
3336 * If for any reason at all we couldn't handle the fault, make
3337 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3338 index 02e41b5..ec6e26c 100644
3339 --- a/arch/powerpc/include/asm/atomic.h
3340 +++ b/arch/powerpc/include/asm/atomic.h
3341 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3342
3343 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3344
3345 +#define atomic64_read_unchecked(v) atomic64_read(v)
3346 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3347 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3348 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3349 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3350 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3351 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3352 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3353 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3354 +
3355 #endif /* __powerpc64__ */
3356
3357 #endif /* __KERNEL__ */
3358 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3359 index 4b50941..5605819 100644
3360 --- a/arch/powerpc/include/asm/cache.h
3361 +++ b/arch/powerpc/include/asm/cache.h
3362 @@ -3,6 +3,7 @@
3363
3364 #ifdef __KERNEL__
3365
3366 +#include <linux/const.h>
3367
3368 /* bytes per L1 cache line */
3369 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3370 @@ -22,7 +23,7 @@
3371 #define L1_CACHE_SHIFT 7
3372 #endif
3373
3374 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3375 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3376
3377 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3378
3379 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3380 index 3bf9cca..e7457d0 100644
3381 --- a/arch/powerpc/include/asm/elf.h
3382 +++ b/arch/powerpc/include/asm/elf.h
3383 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3384 the loader. We need to make sure that it is out of the way of the program
3385 that it will "exec", and that there is sufficient room for the brk. */
3386
3387 -extern unsigned long randomize_et_dyn(unsigned long base);
3388 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3389 +#define ELF_ET_DYN_BASE (0x20000000)
3390 +
3391 +#ifdef CONFIG_PAX_ASLR
3392 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3393 +
3394 +#ifdef __powerpc64__
3395 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3396 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3397 +#else
3398 +#define PAX_DELTA_MMAP_LEN 15
3399 +#define PAX_DELTA_STACK_LEN 15
3400 +#endif
3401 +#endif
3402
3403 /*
3404 * Our registers are always unsigned longs, whether we're a 32 bit
3405 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3406 (0x7ff >> (PAGE_SHIFT - 12)) : \
3407 (0x3ffff >> (PAGE_SHIFT - 12)))
3408
3409 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3410 -#define arch_randomize_brk arch_randomize_brk
3411 -
3412 #endif /* __KERNEL__ */
3413
3414 /*
3415 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3416 index bca8fdc..61e9580 100644
3417 --- a/arch/powerpc/include/asm/kmap_types.h
3418 +++ b/arch/powerpc/include/asm/kmap_types.h
3419 @@ -27,6 +27,7 @@ enum km_type {
3420 KM_PPC_SYNC_PAGE,
3421 KM_PPC_SYNC_ICACHE,
3422 KM_KDB,
3423 + KM_CLEARPAGE,
3424 KM_TYPE_NR
3425 };
3426
3427 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3428 index d4a7f64..451de1c 100644
3429 --- a/arch/powerpc/include/asm/mman.h
3430 +++ b/arch/powerpc/include/asm/mman.h
3431 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3432 }
3433 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3434
3435 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3436 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3437 {
3438 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3439 }
3440 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3441 index f072e97..b436dee 100644
3442 --- a/arch/powerpc/include/asm/page.h
3443 +++ b/arch/powerpc/include/asm/page.h
3444 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3445 * and needs to be executable. This means the whole heap ends
3446 * up being executable.
3447 */
3448 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3449 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3450 +#define VM_DATA_DEFAULT_FLAGS32 \
3451 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3452 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3453
3454 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3455 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3456 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3457 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3458 #endif
3459
3460 +#define ktla_ktva(addr) (addr)
3461 +#define ktva_ktla(addr) (addr)
3462 +
3463 /*
3464 * Use the top bit of the higher-level page table entries to indicate whether
3465 * the entries we point to contain hugepages. This works because we know that
3466 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3467 index fed85e6..da5c71b 100644
3468 --- a/arch/powerpc/include/asm/page_64.h
3469 +++ b/arch/powerpc/include/asm/page_64.h
3470 @@ -146,15 +146,18 @@ do { \
3471 * stack by default, so in the absence of a PT_GNU_STACK program header
3472 * we turn execute permission off.
3473 */
3474 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3475 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3476 +#define VM_STACK_DEFAULT_FLAGS32 \
3477 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3478 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3479
3480 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3481 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3482
3483 +#ifndef CONFIG_PAX_PAGEEXEC
3484 #define VM_STACK_DEFAULT_FLAGS \
3485 (is_32bit_task() ? \
3486 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3487 +#endif
3488
3489 #include <asm-generic/getorder.h>
3490
3491 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3492 index 2e0e411..7899c68 100644
3493 --- a/arch/powerpc/include/asm/pgtable.h
3494 +++ b/arch/powerpc/include/asm/pgtable.h
3495 @@ -2,6 +2,7 @@
3496 #define _ASM_POWERPC_PGTABLE_H
3497 #ifdef __KERNEL__
3498
3499 +#include <linux/const.h>
3500 #ifndef __ASSEMBLY__
3501 #include <asm/processor.h> /* For TASK_SIZE */
3502 #include <asm/mmu.h>
3503 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3504 index 4aad413..85d86bf 100644
3505 --- a/arch/powerpc/include/asm/pte-hash32.h
3506 +++ b/arch/powerpc/include/asm/pte-hash32.h
3507 @@ -21,6 +21,7 @@
3508 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3509 #define _PAGE_USER 0x004 /* usermode access allowed */
3510 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3511 +#define _PAGE_EXEC _PAGE_GUARDED
3512 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3513 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3514 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3515 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3516 index 7fdc2c0..e47a9b02d3 100644
3517 --- a/arch/powerpc/include/asm/reg.h
3518 +++ b/arch/powerpc/include/asm/reg.h
3519 @@ -212,6 +212,7 @@
3520 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3521 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3522 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3523 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3524 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3525 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3526 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3527 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3528 index c377457..3c69fbc 100644
3529 --- a/arch/powerpc/include/asm/system.h
3530 +++ b/arch/powerpc/include/asm/system.h
3531 @@ -539,7 +539,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3532 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3533 #endif
3534
3535 -extern unsigned long arch_align_stack(unsigned long sp);
3536 +#define arch_align_stack(x) ((x) & ~0xfUL)
3537
3538 /* Used in very early kernel initialization. */
3539 extern unsigned long reloc_offset(void);
3540 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3541 index bd0fb84..a42a14b 100644
3542 --- a/arch/powerpc/include/asm/uaccess.h
3543 +++ b/arch/powerpc/include/asm/uaccess.h
3544 @@ -13,6 +13,8 @@
3545 #define VERIFY_READ 0
3546 #define VERIFY_WRITE 1
3547
3548 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3549 +
3550 /*
3551 * The fs value determines whether argument validity checking should be
3552 * performed or not. If get_fs() == USER_DS, checking is performed, with
3553 @@ -327,52 +329,6 @@ do { \
3554 extern unsigned long __copy_tofrom_user(void __user *to,
3555 const void __user *from, unsigned long size);
3556
3557 -#ifndef __powerpc64__
3558 -
3559 -static inline unsigned long copy_from_user(void *to,
3560 - const void __user *from, unsigned long n)
3561 -{
3562 - unsigned long over;
3563 -
3564 - if (access_ok(VERIFY_READ, from, n))
3565 - return __copy_tofrom_user((__force void __user *)to, from, n);
3566 - if ((unsigned long)from < TASK_SIZE) {
3567 - over = (unsigned long)from + n - TASK_SIZE;
3568 - return __copy_tofrom_user((__force void __user *)to, from,
3569 - n - over) + over;
3570 - }
3571 - return n;
3572 -}
3573 -
3574 -static inline unsigned long copy_to_user(void __user *to,
3575 - const void *from, unsigned long n)
3576 -{
3577 - unsigned long over;
3578 -
3579 - if (access_ok(VERIFY_WRITE, to, n))
3580 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3581 - if ((unsigned long)to < TASK_SIZE) {
3582 - over = (unsigned long)to + n - TASK_SIZE;
3583 - return __copy_tofrom_user(to, (__force void __user *)from,
3584 - n - over) + over;
3585 - }
3586 - return n;
3587 -}
3588 -
3589 -#else /* __powerpc64__ */
3590 -
3591 -#define __copy_in_user(to, from, size) \
3592 - __copy_tofrom_user((to), (from), (size))
3593 -
3594 -extern unsigned long copy_from_user(void *to, const void __user *from,
3595 - unsigned long n);
3596 -extern unsigned long copy_to_user(void __user *to, const void *from,
3597 - unsigned long n);
3598 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3599 - unsigned long n);
3600 -
3601 -#endif /* __powerpc64__ */
3602 -
3603 static inline unsigned long __copy_from_user_inatomic(void *to,
3604 const void __user *from, unsigned long n)
3605 {
3606 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3607 if (ret == 0)
3608 return 0;
3609 }
3610 +
3611 + if (!__builtin_constant_p(n))
3612 + check_object_size(to, n, false);
3613 +
3614 return __copy_tofrom_user((__force void __user *)to, from, n);
3615 }
3616
3617 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3618 if (ret == 0)
3619 return 0;
3620 }
3621 +
3622 + if (!__builtin_constant_p(n))
3623 + check_object_size(from, n, true);
3624 +
3625 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3626 }
3627
3628 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3629 return __copy_to_user_inatomic(to, from, size);
3630 }
3631
3632 +#ifndef __powerpc64__
3633 +
3634 +static inline unsigned long __must_check copy_from_user(void *to,
3635 + const void __user *from, unsigned long n)
3636 +{
3637 + unsigned long over;
3638 +
3639 + if ((long)n < 0)
3640 + return n;
3641 +
3642 + if (access_ok(VERIFY_READ, from, n)) {
3643 + if (!__builtin_constant_p(n))
3644 + check_object_size(to, n, false);
3645 + return __copy_tofrom_user((__force void __user *)to, from, n);
3646 + }
3647 + if ((unsigned long)from < TASK_SIZE) {
3648 + over = (unsigned long)from + n - TASK_SIZE;
3649 + if (!__builtin_constant_p(n - over))
3650 + check_object_size(to, n - over, false);
3651 + return __copy_tofrom_user((__force void __user *)to, from,
3652 + n - over) + over;
3653 + }
3654 + return n;
3655 +}
3656 +
3657 +static inline unsigned long __must_check copy_to_user(void __user *to,
3658 + const void *from, unsigned long n)
3659 +{
3660 + unsigned long over;
3661 +
3662 + if ((long)n < 0)
3663 + return n;
3664 +
3665 + if (access_ok(VERIFY_WRITE, to, n)) {
3666 + if (!__builtin_constant_p(n))
3667 + check_object_size(from, n, true);
3668 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3669 + }
3670 + if ((unsigned long)to < TASK_SIZE) {
3671 + over = (unsigned long)to + n - TASK_SIZE;
3672 + if (!__builtin_constant_p(n))
3673 + check_object_size(from, n - over, true);
3674 + return __copy_tofrom_user(to, (__force void __user *)from,
3675 + n - over) + over;
3676 + }
3677 + return n;
3678 +}
3679 +
3680 +#else /* __powerpc64__ */
3681 +
3682 +#define __copy_in_user(to, from, size) \
3683 + __copy_tofrom_user((to), (from), (size))
3684 +
3685 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3686 +{
3687 + if ((long)n < 0 || n > INT_MAX)
3688 + return n;
3689 +
3690 + if (!__builtin_constant_p(n))
3691 + check_object_size(to, n, false);
3692 +
3693 + if (likely(access_ok(VERIFY_READ, from, n)))
3694 + n = __copy_from_user(to, from, n);
3695 + else
3696 + memset(to, 0, n);
3697 + return n;
3698 +}
3699 +
3700 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3701 +{
3702 + if ((long)n < 0 || n > INT_MAX)
3703 + return n;
3704 +
3705 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3706 + if (!__builtin_constant_p(n))
3707 + check_object_size(from, n, true);
3708 + n = __copy_to_user(to, from, n);
3709 + }
3710 + return n;
3711 +}
3712 +
3713 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3714 + unsigned long n);
3715 +
3716 +#endif /* __powerpc64__ */
3717 +
3718 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3719
3720 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3721 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3722 index 429983c..7af363b 100644
3723 --- a/arch/powerpc/kernel/exceptions-64e.S
3724 +++ b/arch/powerpc/kernel/exceptions-64e.S
3725 @@ -587,6 +587,7 @@ storage_fault_common:
3726 std r14,_DAR(r1)
3727 std r15,_DSISR(r1)
3728 addi r3,r1,STACK_FRAME_OVERHEAD
3729 + bl .save_nvgprs
3730 mr r4,r14
3731 mr r5,r15
3732 ld r14,PACA_EXGEN+EX_R14(r13)
3733 @@ -596,8 +597,7 @@ storage_fault_common:
3734 cmpdi r3,0
3735 bne- 1f
3736 b .ret_from_except_lite
3737 -1: bl .save_nvgprs
3738 - mr r5,r3
3739 +1: mr r5,r3
3740 addi r3,r1,STACK_FRAME_OVERHEAD
3741 ld r4,_DAR(r1)
3742 bl .bad_page_fault
3743 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3744 index 15c5a4f..22a4000 100644
3745 --- a/arch/powerpc/kernel/exceptions-64s.S
3746 +++ b/arch/powerpc/kernel/exceptions-64s.S
3747 @@ -1004,10 +1004,10 @@ handle_page_fault:
3748 11: ld r4,_DAR(r1)
3749 ld r5,_DSISR(r1)
3750 addi r3,r1,STACK_FRAME_OVERHEAD
3751 + bl .save_nvgprs
3752 bl .do_page_fault
3753 cmpdi r3,0
3754 beq+ 13f
3755 - bl .save_nvgprs
3756 mr r5,r3
3757 addi r3,r1,STACK_FRAME_OVERHEAD
3758 lwz r4,_DAR(r1)
3759 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
3760 index 01e2877..a1ba360 100644
3761 --- a/arch/powerpc/kernel/irq.c
3762 +++ b/arch/powerpc/kernel/irq.c
3763 @@ -560,9 +560,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
3764 host->ops = ops;
3765 host->of_node = of_node_get(of_node);
3766
3767 - if (host->ops->match == NULL)
3768 - host->ops->match = default_irq_host_match;
3769 -
3770 raw_spin_lock_irqsave(&irq_big_lock, flags);
3771
3772 /* If it's a legacy controller, check for duplicates and
3773 @@ -635,7 +632,12 @@ struct irq_host *irq_find_host(struct device_node *node)
3774 */
3775 raw_spin_lock_irqsave(&irq_big_lock, flags);
3776 list_for_each_entry(h, &irq_hosts, link)
3777 - if (h->ops->match(h, node)) {
3778 + if (h->ops->match) {
3779 + if (h->ops->match(h, node)) {
3780 + found = h;
3781 + break;
3782 + }
3783 + } else if (default_irq_host_match(h, node)) {
3784 found = h;
3785 break;
3786 }
3787 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3788 index 0b6d796..d760ddb 100644
3789 --- a/arch/powerpc/kernel/module_32.c
3790 +++ b/arch/powerpc/kernel/module_32.c
3791 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3792 me->arch.core_plt_section = i;
3793 }
3794 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3795 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3796 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3797 return -ENOEXEC;
3798 }
3799
3800 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
3801
3802 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3803 /* Init, or core PLT? */
3804 - if (location >= mod->module_core
3805 - && location < mod->module_core + mod->core_size)
3806 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3807 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3808 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3809 - else
3810 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3811 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3812 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3813 + else {
3814 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3815 + return ~0UL;
3816 + }
3817
3818 /* Find this entry, or if that fails, the next avail. entry */
3819 while (entry->jump[0]) {
3820 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3821 index d817ab0..b23b18e 100644
3822 --- a/arch/powerpc/kernel/process.c
3823 +++ b/arch/powerpc/kernel/process.c
3824 @@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
3825 * Lookup NIP late so we have the best change of getting the
3826 * above info out without failing
3827 */
3828 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3829 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3830 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3831 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3832 #endif
3833 show_stack(current, (unsigned long *) regs->gpr[1]);
3834 if (!user_mode(regs))
3835 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3836 newsp = stack[0];
3837 ip = stack[STACK_FRAME_LR_SAVE];
3838 if (!firstframe || ip != lr) {
3839 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3840 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3841 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3842 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3843 - printk(" (%pS)",
3844 + printk(" (%pA)",
3845 (void *)current->ret_stack[curr_frame].ret);
3846 curr_frame--;
3847 }
3848 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3849 struct pt_regs *regs = (struct pt_regs *)
3850 (sp + STACK_FRAME_OVERHEAD);
3851 lr = regs->link;
3852 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3853 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3854 regs->trap, (void *)regs->nip, (void *)lr);
3855 firstframe = 1;
3856 }
3857 @@ -1279,58 +1279,3 @@ void thread_info_cache_init(void)
3858 }
3859
3860 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3861 -
3862 -unsigned long arch_align_stack(unsigned long sp)
3863 -{
3864 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3865 - sp -= get_random_int() & ~PAGE_MASK;
3866 - return sp & ~0xf;
3867 -}
3868 -
3869 -static inline unsigned long brk_rnd(void)
3870 -{
3871 - unsigned long rnd = 0;
3872 -
3873 - /* 8MB for 32bit, 1GB for 64bit */
3874 - if (is_32bit_task())
3875 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3876 - else
3877 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3878 -
3879 - return rnd << PAGE_SHIFT;
3880 -}
3881 -
3882 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3883 -{
3884 - unsigned long base = mm->brk;
3885 - unsigned long ret;
3886 -
3887 -#ifdef CONFIG_PPC_STD_MMU_64
3888 - /*
3889 - * If we are using 1TB segments and we are allowed to randomise
3890 - * the heap, we can put it above 1TB so it is backed by a 1TB
3891 - * segment. Otherwise the heap will be in the bottom 1TB
3892 - * which always uses 256MB segments and this may result in a
3893 - * performance penalty.
3894 - */
3895 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3896 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3897 -#endif
3898 -
3899 - ret = PAGE_ALIGN(base + brk_rnd());
3900 -
3901 - if (ret < mm->brk)
3902 - return mm->brk;
3903 -
3904 - return ret;
3905 -}
3906 -
3907 -unsigned long randomize_et_dyn(unsigned long base)
3908 -{
3909 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3910 -
3911 - if (ret < base)
3912 - return base;
3913 -
3914 - return ret;
3915 -}
3916 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3917 index 836a5a1..27289a3 100644
3918 --- a/arch/powerpc/kernel/signal_32.c
3919 +++ b/arch/powerpc/kernel/signal_32.c
3920 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
3921 /* Save user registers on the stack */
3922 frame = &rt_sf->uc.uc_mcontext;
3923 addr = frame;
3924 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3925 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3926 if (save_user_regs(regs, frame, 0, 1))
3927 goto badframe;
3928 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3929 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3930 index a50b5ec..547078a 100644
3931 --- a/arch/powerpc/kernel/signal_64.c
3932 +++ b/arch/powerpc/kernel/signal_64.c
3933 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
3934 current->thread.fpscr.val = 0;
3935
3936 /* Set up to return from userspace. */
3937 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3938 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3939 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3940 } else {
3941 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3942 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3943 index c091527..5592625 100644
3944 --- a/arch/powerpc/kernel/traps.c
3945 +++ b/arch/powerpc/kernel/traps.c
3946 @@ -131,6 +131,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
3947 return flags;
3948 }
3949
3950 +extern void gr_handle_kernel_exploit(void);
3951 +
3952 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
3953 int signr)
3954 {
3955 @@ -178,6 +180,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
3956 panic("Fatal exception in interrupt");
3957 if (panic_on_oops)
3958 panic("Fatal exception");
3959 +
3960 + gr_handle_kernel_exploit();
3961 +
3962 do_exit(signr);
3963 }
3964
3965 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3966 index 7d14bb6..1305601 100644
3967 --- a/arch/powerpc/kernel/vdso.c
3968 +++ b/arch/powerpc/kernel/vdso.c
3969 @@ -35,6 +35,7 @@
3970 #include <asm/firmware.h>
3971 #include <asm/vdso.h>
3972 #include <asm/vdso_datapage.h>
3973 +#include <asm/mman.h>
3974
3975 #include "setup.h"
3976
3977 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3978 vdso_base = VDSO32_MBASE;
3979 #endif
3980
3981 - current->mm->context.vdso_base = 0;
3982 + current->mm->context.vdso_base = ~0UL;
3983
3984 /* vDSO has a problem and was disabled, just don't "enable" it for the
3985 * process
3986 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3987 vdso_base = get_unmapped_area(NULL, vdso_base,
3988 (vdso_pages << PAGE_SHIFT) +
3989 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3990 - 0, 0);
3991 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3992 if (IS_ERR_VALUE(vdso_base)) {
3993 rc = vdso_base;
3994 goto fail_mmapsem;
3995 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
3996 index 5eea6f3..5d10396 100644
3997 --- a/arch/powerpc/lib/usercopy_64.c
3998 +++ b/arch/powerpc/lib/usercopy_64.c
3999 @@ -9,22 +9,6 @@
4000 #include <linux/module.h>
4001 #include <asm/uaccess.h>
4002
4003 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4004 -{
4005 - if (likely(access_ok(VERIFY_READ, from, n)))
4006 - n = __copy_from_user(to, from, n);
4007 - else
4008 - memset(to, 0, n);
4009 - return n;
4010 -}
4011 -
4012 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4013 -{
4014 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4015 - n = __copy_to_user(to, from, n);
4016 - return n;
4017 -}
4018 -
4019 unsigned long copy_in_user(void __user *to, const void __user *from,
4020 unsigned long n)
4021 {
4022 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4023 return n;
4024 }
4025
4026 -EXPORT_SYMBOL(copy_from_user);
4027 -EXPORT_SYMBOL(copy_to_user);
4028 EXPORT_SYMBOL(copy_in_user);
4029
4030 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4031 index 2f0d1b0..36fb5cc 100644
4032 --- a/arch/powerpc/mm/fault.c
4033 +++ b/arch/powerpc/mm/fault.c
4034 @@ -32,6 +32,10 @@
4035 #include <linux/perf_event.h>
4036 #include <linux/magic.h>
4037 #include <linux/ratelimit.h>
4038 +#include <linux/slab.h>
4039 +#include <linux/pagemap.h>
4040 +#include <linux/compiler.h>
4041 +#include <linux/unistd.h>
4042
4043 #include <asm/firmware.h>
4044 #include <asm/page.h>
4045 @@ -43,6 +47,7 @@
4046 #include <asm/tlbflush.h>
4047 #include <asm/siginfo.h>
4048 #include <mm/mmu_decl.h>
4049 +#include <asm/ptrace.h>
4050
4051 #include "icswx.h"
4052
4053 @@ -68,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4054 }
4055 #endif
4056
4057 +#ifdef CONFIG_PAX_PAGEEXEC
4058 +/*
4059 + * PaX: decide what to do with offenders (regs->nip = fault address)
4060 + *
4061 + * returns 1 when task should be killed
4062 + */
4063 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4064 +{
4065 + return 1;
4066 +}
4067 +
4068 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4069 +{
4070 + unsigned long i;
4071 +
4072 + printk(KERN_ERR "PAX: bytes at PC: ");
4073 + for (i = 0; i < 5; i++) {
4074 + unsigned int c;
4075 + if (get_user(c, (unsigned int __user *)pc+i))
4076 + printk(KERN_CONT "???????? ");
4077 + else
4078 + printk(KERN_CONT "%08x ", c);
4079 + }
4080 + printk("\n");
4081 +}
4082 +#endif
4083 +
4084 /*
4085 * Check whether the instruction at regs->nip is a store using
4086 * an update addressing form which will update r1.
4087 @@ -138,7 +170,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4088 * indicate errors in DSISR but can validly be set in SRR1.
4089 */
4090 if (trap == 0x400)
4091 - error_code &= 0x48200000;
4092 + error_code &= 0x58200000;
4093 else
4094 is_write = error_code & DSISR_ISSTORE;
4095 #else
4096 @@ -276,7 +308,7 @@ good_area:
4097 * "undefined". Of those that can be set, this is the only
4098 * one which seems bad.
4099 */
4100 - if (error_code & 0x10000000)
4101 + if (error_code & DSISR_GUARDED)
4102 /* Guarded storage error. */
4103 goto bad_area;
4104 #endif /* CONFIG_8xx */
4105 @@ -291,7 +323,7 @@ good_area:
4106 * processors use the same I/D cache coherency mechanism
4107 * as embedded.
4108 */
4109 - if (error_code & DSISR_PROTFAULT)
4110 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4111 goto bad_area;
4112 #endif /* CONFIG_PPC_STD_MMU */
4113
4114 @@ -360,6 +392,23 @@ bad_area:
4115 bad_area_nosemaphore:
4116 /* User mode accesses cause a SIGSEGV */
4117 if (user_mode(regs)) {
4118 +
4119 +#ifdef CONFIG_PAX_PAGEEXEC
4120 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4121 +#ifdef CONFIG_PPC_STD_MMU
4122 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4123 +#else
4124 + if (is_exec && regs->nip == address) {
4125 +#endif
4126 + switch (pax_handle_fetch_fault(regs)) {
4127 + }
4128 +
4129 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4130 + do_group_exit(SIGKILL);
4131 + }
4132 + }
4133 +#endif
4134 +
4135 _exception(SIGSEGV, regs, code, address);
4136 return 0;
4137 }
4138 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4139 index 67a42ed..1c7210c 100644
4140 --- a/arch/powerpc/mm/mmap_64.c
4141 +++ b/arch/powerpc/mm/mmap_64.c
4142 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4143 */
4144 if (mmap_is_legacy()) {
4145 mm->mmap_base = TASK_UNMAPPED_BASE;
4146 +
4147 +#ifdef CONFIG_PAX_RANDMMAP
4148 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4149 + mm->mmap_base += mm->delta_mmap;
4150 +#endif
4151 +
4152 mm->get_unmapped_area = arch_get_unmapped_area;
4153 mm->unmap_area = arch_unmap_area;
4154 } else {
4155 mm->mmap_base = mmap_base();
4156 +
4157 +#ifdef CONFIG_PAX_RANDMMAP
4158 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4159 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4160 +#endif
4161 +
4162 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4163 mm->unmap_area = arch_unmap_area_topdown;
4164 }
4165 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4166 index 73709f7..6b90313 100644
4167 --- a/arch/powerpc/mm/slice.c
4168 +++ b/arch/powerpc/mm/slice.c
4169 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4170 if ((mm->task_size - len) < addr)
4171 return 0;
4172 vma = find_vma(mm, addr);
4173 - return (!vma || (addr + len) <= vma->vm_start);
4174 + return check_heap_stack_gap(vma, addr, len);
4175 }
4176
4177 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4178 @@ -256,7 +256,7 @@ full_search:
4179 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4180 continue;
4181 }
4182 - if (!vma || addr + len <= vma->vm_start) {
4183 + if (check_heap_stack_gap(vma, addr, len)) {
4184 /*
4185 * Remember the place where we stopped the search:
4186 */
4187 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4188 }
4189 }
4190
4191 - addr = mm->mmap_base;
4192 - while (addr > len) {
4193 + if (mm->mmap_base < len)
4194 + addr = -ENOMEM;
4195 + else
4196 + addr = mm->mmap_base - len;
4197 +
4198 + while (!IS_ERR_VALUE(addr)) {
4199 /* Go down by chunk size */
4200 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4201 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4202
4203 /* Check for hit with different page size */
4204 mask = slice_range_to_mask(addr, len);
4205 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4206 * return with success:
4207 */
4208 vma = find_vma(mm, addr);
4209 - if (!vma || (addr + len) <= vma->vm_start) {
4210 + if (check_heap_stack_gap(vma, addr, len)) {
4211 /* remember the address as a hint for next time */
4212 if (use_cache)
4213 mm->free_area_cache = addr;
4214 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4215 mm->cached_hole_size = vma->vm_start - addr;
4216
4217 /* try just below the current vma->vm_start */
4218 - addr = vma->vm_start;
4219 + addr = skip_heap_stack_gap(vma, len);
4220 }
4221
4222 /*
4223 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4224 if (fixed && addr > (mm->task_size - len))
4225 return -EINVAL;
4226
4227 +#ifdef CONFIG_PAX_RANDMMAP
4228 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4229 + addr = 0;
4230 +#endif
4231 +
4232 /* If hint, make sure it matches our alignment restrictions */
4233 if (!fixed && addr) {
4234 addr = _ALIGN_UP(addr, 1ul << pshift);
4235 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4236 index 8517d2a..d2738d4 100644
4237 --- a/arch/s390/include/asm/atomic.h
4238 +++ b/arch/s390/include/asm/atomic.h
4239 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4240 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4241 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4242
4243 +#define atomic64_read_unchecked(v) atomic64_read(v)
4244 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4245 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4246 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4247 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4248 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4249 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4250 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4251 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4252 +
4253 #define smp_mb__before_atomic_dec() smp_mb()
4254 #define smp_mb__after_atomic_dec() smp_mb()
4255 #define smp_mb__before_atomic_inc() smp_mb()
4256 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4257 index 2a30d5a..5e5586f 100644
4258 --- a/arch/s390/include/asm/cache.h
4259 +++ b/arch/s390/include/asm/cache.h
4260 @@ -11,8 +11,10 @@
4261 #ifndef __ARCH_S390_CACHE_H
4262 #define __ARCH_S390_CACHE_H
4263
4264 -#define L1_CACHE_BYTES 256
4265 +#include <linux/const.h>
4266 +
4267 #define L1_CACHE_SHIFT 8
4268 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4269 #define NET_SKB_PAD 32
4270
4271 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4272 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4273 index 547f1a6..0b22b53 100644
4274 --- a/arch/s390/include/asm/elf.h
4275 +++ b/arch/s390/include/asm/elf.h
4276 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4277 the loader. We need to make sure that it is out of the way of the program
4278 that it will "exec", and that there is sufficient room for the brk. */
4279
4280 -extern unsigned long randomize_et_dyn(unsigned long base);
4281 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4282 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4283 +
4284 +#ifdef CONFIG_PAX_ASLR
4285 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4286 +
4287 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4288 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4289 +#endif
4290
4291 /* This yields a mask that user programs can use to figure out what
4292 instruction set this CPU supports. */
4293 @@ -211,7 +217,4 @@ struct linux_binprm;
4294 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4295 int arch_setup_additional_pages(struct linux_binprm *, int);
4296
4297 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4298 -#define arch_randomize_brk arch_randomize_brk
4299 -
4300 #endif
4301 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4302 index d73cc6b..1a296ad 100644
4303 --- a/arch/s390/include/asm/system.h
4304 +++ b/arch/s390/include/asm/system.h
4305 @@ -260,7 +260,7 @@ extern void (*_machine_restart)(char *command);
4306 extern void (*_machine_halt)(void);
4307 extern void (*_machine_power_off)(void);
4308
4309 -extern unsigned long arch_align_stack(unsigned long sp);
4310 +#define arch_align_stack(x) ((x) & ~0xfUL)
4311
4312 static inline int tprot(unsigned long addr)
4313 {
4314 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4315 index 2b23885..e136e31 100644
4316 --- a/arch/s390/include/asm/uaccess.h
4317 +++ b/arch/s390/include/asm/uaccess.h
4318 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
4319 copy_to_user(void __user *to, const void *from, unsigned long n)
4320 {
4321 might_fault();
4322 +
4323 + if ((long)n < 0)
4324 + return n;
4325 +
4326 if (access_ok(VERIFY_WRITE, to, n))
4327 n = __copy_to_user(to, from, n);
4328 return n;
4329 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4330 static inline unsigned long __must_check
4331 __copy_from_user(void *to, const void __user *from, unsigned long n)
4332 {
4333 + if ((long)n < 0)
4334 + return n;
4335 +
4336 if (__builtin_constant_p(n) && (n <= 256))
4337 return uaccess.copy_from_user_small(n, from, to);
4338 else
4339 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4340 unsigned int sz = __compiletime_object_size(to);
4341
4342 might_fault();
4343 +
4344 + if ((long)n < 0)
4345 + return n;
4346 +
4347 if (unlikely(sz != -1 && sz < n)) {
4348 copy_from_user_overflow();
4349 return n;
4350 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4351 index dfcb343..eda788a 100644
4352 --- a/arch/s390/kernel/module.c
4353 +++ b/arch/s390/kernel/module.c
4354 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4355
4356 /* Increase core size by size of got & plt and set start
4357 offsets for got and plt. */
4358 - me->core_size = ALIGN(me->core_size, 4);
4359 - me->arch.got_offset = me->core_size;
4360 - me->core_size += me->arch.got_size;
4361 - me->arch.plt_offset = me->core_size;
4362 - me->core_size += me->arch.plt_size;
4363 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4364 + me->arch.got_offset = me->core_size_rw;
4365 + me->core_size_rw += me->arch.got_size;
4366 + me->arch.plt_offset = me->core_size_rx;
4367 + me->core_size_rx += me->arch.plt_size;
4368 return 0;
4369 }
4370
4371 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4372 if (info->got_initialized == 0) {
4373 Elf_Addr *gotent;
4374
4375 - gotent = me->module_core + me->arch.got_offset +
4376 + gotent = me->module_core_rw + me->arch.got_offset +
4377 info->got_offset;
4378 *gotent = val;
4379 info->got_initialized = 1;
4380 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4381 else if (r_type == R_390_GOTENT ||
4382 r_type == R_390_GOTPLTENT)
4383 *(unsigned int *) loc =
4384 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4385 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4386 else if (r_type == R_390_GOT64 ||
4387 r_type == R_390_GOTPLT64)
4388 *(unsigned long *) loc = val;
4389 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4390 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4391 if (info->plt_initialized == 0) {
4392 unsigned int *ip;
4393 - ip = me->module_core + me->arch.plt_offset +
4394 + ip = me->module_core_rx + me->arch.plt_offset +
4395 info->plt_offset;
4396 #ifndef CONFIG_64BIT
4397 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4398 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4399 val - loc + 0xffffUL < 0x1ffffeUL) ||
4400 (r_type == R_390_PLT32DBL &&
4401 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4402 - val = (Elf_Addr) me->module_core +
4403 + val = (Elf_Addr) me->module_core_rx +
4404 me->arch.plt_offset +
4405 info->plt_offset;
4406 val += rela->r_addend - loc;
4407 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4408 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4409 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4410 val = val + rela->r_addend -
4411 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4412 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4413 if (r_type == R_390_GOTOFF16)
4414 *(unsigned short *) loc = val;
4415 else if (r_type == R_390_GOTOFF32)
4416 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4417 break;
4418 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4419 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4420 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4421 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4422 rela->r_addend - loc;
4423 if (r_type == R_390_GOTPC)
4424 *(unsigned int *) loc = val;
4425 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4426 index e795933..b32563c 100644
4427 --- a/arch/s390/kernel/process.c
4428 +++ b/arch/s390/kernel/process.c
4429 @@ -323,39 +323,3 @@ unsigned long get_wchan(struct task_struct *p)
4430 }
4431 return 0;
4432 }
4433 -
4434 -unsigned long arch_align_stack(unsigned long sp)
4435 -{
4436 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4437 - sp -= get_random_int() & ~PAGE_MASK;
4438 - return sp & ~0xf;
4439 -}
4440 -
4441 -static inline unsigned long brk_rnd(void)
4442 -{
4443 - /* 8MB for 32bit, 1GB for 64bit */
4444 - if (is_32bit_task())
4445 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4446 - else
4447 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4448 -}
4449 -
4450 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4451 -{
4452 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4453 -
4454 - if (ret < mm->brk)
4455 - return mm->brk;
4456 - return ret;
4457 -}
4458 -
4459 -unsigned long randomize_et_dyn(unsigned long base)
4460 -{
4461 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4462 -
4463 - if (!(current->flags & PF_RANDOMIZE))
4464 - return base;
4465 - if (ret < base)
4466 - return base;
4467 - return ret;
4468 -}
4469 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4470 index a0155c0..34cc491 100644
4471 --- a/arch/s390/mm/mmap.c
4472 +++ b/arch/s390/mm/mmap.c
4473 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4474 */
4475 if (mmap_is_legacy()) {
4476 mm->mmap_base = TASK_UNMAPPED_BASE;
4477 +
4478 +#ifdef CONFIG_PAX_RANDMMAP
4479 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4480 + mm->mmap_base += mm->delta_mmap;
4481 +#endif
4482 +
4483 mm->get_unmapped_area = arch_get_unmapped_area;
4484 mm->unmap_area = arch_unmap_area;
4485 } else {
4486 mm->mmap_base = mmap_base();
4487 +
4488 +#ifdef CONFIG_PAX_RANDMMAP
4489 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4490 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4491 +#endif
4492 +
4493 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4494 mm->unmap_area = arch_unmap_area_topdown;
4495 }
4496 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4497 */
4498 if (mmap_is_legacy()) {
4499 mm->mmap_base = TASK_UNMAPPED_BASE;
4500 +
4501 +#ifdef CONFIG_PAX_RANDMMAP
4502 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4503 + mm->mmap_base += mm->delta_mmap;
4504 +#endif
4505 +
4506 mm->get_unmapped_area = s390_get_unmapped_area;
4507 mm->unmap_area = arch_unmap_area;
4508 } else {
4509 mm->mmap_base = mmap_base();
4510 +
4511 +#ifdef CONFIG_PAX_RANDMMAP
4512 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4513 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4514 +#endif
4515 +
4516 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4517 mm->unmap_area = arch_unmap_area_topdown;
4518 }
4519 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4520 index ae3d59f..f65f075 100644
4521 --- a/arch/score/include/asm/cache.h
4522 +++ b/arch/score/include/asm/cache.h
4523 @@ -1,7 +1,9 @@
4524 #ifndef _ASM_SCORE_CACHE_H
4525 #define _ASM_SCORE_CACHE_H
4526
4527 +#include <linux/const.h>
4528 +
4529 #define L1_CACHE_SHIFT 4
4530 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4531 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4532
4533 #endif /* _ASM_SCORE_CACHE_H */
4534 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4535 index 589d5c7..669e274 100644
4536 --- a/arch/score/include/asm/system.h
4537 +++ b/arch/score/include/asm/system.h
4538 @@ -17,7 +17,7 @@ do { \
4539 #define finish_arch_switch(prev) do {} while (0)
4540
4541 typedef void (*vi_handler_t)(void);
4542 -extern unsigned long arch_align_stack(unsigned long sp);
4543 +#define arch_align_stack(x) (x)
4544
4545 #define mb() barrier()
4546 #define rmb() barrier()
4547 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4548 index 25d0803..d6c8e36 100644
4549 --- a/arch/score/kernel/process.c
4550 +++ b/arch/score/kernel/process.c
4551 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4552
4553 return task_pt_regs(task)->cp0_epc;
4554 }
4555 -
4556 -unsigned long arch_align_stack(unsigned long sp)
4557 -{
4558 - return sp;
4559 -}
4560 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4561 index ef9e555..331bd29 100644
4562 --- a/arch/sh/include/asm/cache.h
4563 +++ b/arch/sh/include/asm/cache.h
4564 @@ -9,10 +9,11 @@
4565 #define __ASM_SH_CACHE_H
4566 #ifdef __KERNEL__
4567
4568 +#include <linux/const.h>
4569 #include <linux/init.h>
4570 #include <cpu/cache.h>
4571
4572 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4573 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4574
4575 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4576
4577 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4578 index afeb710..d1d1289 100644
4579 --- a/arch/sh/mm/mmap.c
4580 +++ b/arch/sh/mm/mmap.c
4581 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4582 addr = PAGE_ALIGN(addr);
4583
4584 vma = find_vma(mm, addr);
4585 - if (TASK_SIZE - len >= addr &&
4586 - (!vma || addr + len <= vma->vm_start))
4587 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4588 return addr;
4589 }
4590
4591 @@ -106,7 +105,7 @@ full_search:
4592 }
4593 return -ENOMEM;
4594 }
4595 - if (likely(!vma || addr + len <= vma->vm_start)) {
4596 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4597 /*
4598 * Remember the place where we stopped the search:
4599 */
4600 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4601 addr = PAGE_ALIGN(addr);
4602
4603 vma = find_vma(mm, addr);
4604 - if (TASK_SIZE - len >= addr &&
4605 - (!vma || addr + len <= vma->vm_start))
4606 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4607 return addr;
4608 }
4609
4610 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4611 /* make sure it can fit in the remaining address space */
4612 if (likely(addr > len)) {
4613 vma = find_vma(mm, addr-len);
4614 - if (!vma || addr <= vma->vm_start) {
4615 + if (check_heap_stack_gap(vma, addr - len, len)) {
4616 /* remember the address as a hint for next time */
4617 return (mm->free_area_cache = addr-len);
4618 }
4619 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4620 if (unlikely(mm->mmap_base < len))
4621 goto bottomup;
4622
4623 - addr = mm->mmap_base-len;
4624 - if (do_colour_align)
4625 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4626 + addr = mm->mmap_base - len;
4627
4628 do {
4629 + if (do_colour_align)
4630 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4631 /*
4632 * Lookup failure means no vma is above this address,
4633 * else if new region fits below vma->vm_start,
4634 * return with success:
4635 */
4636 vma = find_vma(mm, addr);
4637 - if (likely(!vma || addr+len <= vma->vm_start)) {
4638 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4639 /* remember the address as a hint for next time */
4640 return (mm->free_area_cache = addr);
4641 }
4642 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4643 mm->cached_hole_size = vma->vm_start - addr;
4644
4645 /* try just below the current vma->vm_start */
4646 - addr = vma->vm_start-len;
4647 - if (do_colour_align)
4648 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4649 - } while (likely(len < vma->vm_start));
4650 + addr = skip_heap_stack_gap(vma, len);
4651 + } while (!IS_ERR_VALUE(addr));
4652
4653 bottomup:
4654 /*
4655 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4656 index eddcfb3..b117d90 100644
4657 --- a/arch/sparc/Makefile
4658 +++ b/arch/sparc/Makefile
4659 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4660 # Export what is needed by arch/sparc/boot/Makefile
4661 export VMLINUX_INIT VMLINUX_MAIN
4662 VMLINUX_INIT := $(head-y) $(init-y)
4663 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4664 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4665 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4666 VMLINUX_MAIN += $(drivers-y) $(net-y)
4667
4668 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4669 index 9f421df..b81fc12 100644
4670 --- a/arch/sparc/include/asm/atomic_64.h
4671 +++ b/arch/sparc/include/asm/atomic_64.h
4672 @@ -14,18 +14,40 @@
4673 #define ATOMIC64_INIT(i) { (i) }
4674
4675 #define atomic_read(v) (*(volatile int *)&(v)->counter)
4676 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4677 +{
4678 + return v->counter;
4679 +}
4680 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
4681 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4682 +{
4683 + return v->counter;
4684 +}
4685
4686 #define atomic_set(v, i) (((v)->counter) = i)
4687 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4688 +{
4689 + v->counter = i;
4690 +}
4691 #define atomic64_set(v, i) (((v)->counter) = i)
4692 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4693 +{
4694 + v->counter = i;
4695 +}
4696
4697 extern void atomic_add(int, atomic_t *);
4698 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4699 extern void atomic64_add(long, atomic64_t *);
4700 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4701 extern void atomic_sub(int, atomic_t *);
4702 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4703 extern void atomic64_sub(long, atomic64_t *);
4704 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4705
4706 extern int atomic_add_ret(int, atomic_t *);
4707 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4708 extern long atomic64_add_ret(long, atomic64_t *);
4709 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4710 extern int atomic_sub_ret(int, atomic_t *);
4711 extern long atomic64_sub_ret(long, atomic64_t *);
4712
4713 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4714 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4715
4716 #define atomic_inc_return(v) atomic_add_ret(1, v)
4717 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4718 +{
4719 + return atomic_add_ret_unchecked(1, v);
4720 +}
4721 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4722 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4723 +{
4724 + return atomic64_add_ret_unchecked(1, v);
4725 +}
4726
4727 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4728 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4729
4730 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4731 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4732 +{
4733 + return atomic_add_ret_unchecked(i, v);
4734 +}
4735 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4736 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4737 +{
4738 + return atomic64_add_ret_unchecked(i, v);
4739 +}
4740
4741 /*
4742 * atomic_inc_and_test - increment and test
4743 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4744 * other cases.
4745 */
4746 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4747 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4748 +{
4749 + return atomic_inc_return_unchecked(v) == 0;
4750 +}
4751 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4752
4753 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4754 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4755 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4756
4757 #define atomic_inc(v) atomic_add(1, v)
4758 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4759 +{
4760 + atomic_add_unchecked(1, v);
4761 +}
4762 #define atomic64_inc(v) atomic64_add(1, v)
4763 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4764 +{
4765 + atomic64_add_unchecked(1, v);
4766 +}
4767
4768 #define atomic_dec(v) atomic_sub(1, v)
4769 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4770 +{
4771 + atomic_sub_unchecked(1, v);
4772 +}
4773 #define atomic64_dec(v) atomic64_sub(1, v)
4774 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4775 +{
4776 + atomic64_sub_unchecked(1, v);
4777 +}
4778
4779 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4780 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4781
4782 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4783 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4784 +{
4785 + return cmpxchg(&v->counter, old, new);
4786 +}
4787 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4788 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4789 +{
4790 + return xchg(&v->counter, new);
4791 +}
4792
4793 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4794 {
4795 - int c, old;
4796 + int c, old, new;
4797 c = atomic_read(v);
4798 for (;;) {
4799 - if (unlikely(c == (u)))
4800 + if (unlikely(c == u))
4801 break;
4802 - old = atomic_cmpxchg((v), c, c + (a));
4803 +
4804 + asm volatile("addcc %2, %0, %0\n"
4805 +
4806 +#ifdef CONFIG_PAX_REFCOUNT
4807 + "tvs %%icc, 6\n"
4808 +#endif
4809 +
4810 + : "=r" (new)
4811 + : "0" (c), "ir" (a)
4812 + : "cc");
4813 +
4814 + old = atomic_cmpxchg(v, c, new);
4815 if (likely(old == c))
4816 break;
4817 c = old;
4818 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4819 #define atomic64_cmpxchg(v, o, n) \
4820 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4821 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4822 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4823 +{
4824 + return xchg(&v->counter, new);
4825 +}
4826
4827 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4828 {
4829 - long c, old;
4830 + long c, old, new;
4831 c = atomic64_read(v);
4832 for (;;) {
4833 - if (unlikely(c == (u)))
4834 + if (unlikely(c == u))
4835 break;
4836 - old = atomic64_cmpxchg((v), c, c + (a));
4837 +
4838 + asm volatile("addcc %2, %0, %0\n"
4839 +
4840 +#ifdef CONFIG_PAX_REFCOUNT
4841 + "tvs %%xcc, 6\n"
4842 +#endif
4843 +
4844 + : "=r" (new)
4845 + : "0" (c), "ir" (a)
4846 + : "cc");
4847 +
4848 + old = atomic64_cmpxchg(v, c, new);
4849 if (likely(old == c))
4850 break;
4851 c = old;
4852 }
4853 - return c != (u);
4854 + return c != u;
4855 }
4856
4857 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4858 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4859 index 69358b5..9d0d492 100644
4860 --- a/arch/sparc/include/asm/cache.h
4861 +++ b/arch/sparc/include/asm/cache.h
4862 @@ -7,10 +7,12 @@
4863 #ifndef _SPARC_CACHE_H
4864 #define _SPARC_CACHE_H
4865
4866 +#include <linux/const.h>
4867 +
4868 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
4869
4870 #define L1_CACHE_SHIFT 5
4871 -#define L1_CACHE_BYTES 32
4872 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4873
4874 #ifdef CONFIG_SPARC32
4875 #define SMP_CACHE_BYTES_SHIFT 5
4876 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4877 index 4269ca6..e3da77f 100644
4878 --- a/arch/sparc/include/asm/elf_32.h
4879 +++ b/arch/sparc/include/asm/elf_32.h
4880 @@ -114,6 +114,13 @@ typedef struct {
4881
4882 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4883
4884 +#ifdef CONFIG_PAX_ASLR
4885 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4886 +
4887 +#define PAX_DELTA_MMAP_LEN 16
4888 +#define PAX_DELTA_STACK_LEN 16
4889 +#endif
4890 +
4891 /* This yields a mask that user programs can use to figure out what
4892 instruction set this cpu supports. This can NOT be done in userspace
4893 on Sparc. */
4894 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4895 index 7df8b7f..4946269 100644
4896 --- a/arch/sparc/include/asm/elf_64.h
4897 +++ b/arch/sparc/include/asm/elf_64.h
4898 @@ -180,6 +180,13 @@ typedef struct {
4899 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4900 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4901
4902 +#ifdef CONFIG_PAX_ASLR
4903 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4904 +
4905 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4906 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4907 +#endif
4908 +
4909 extern unsigned long sparc64_elf_hwcap;
4910 #define ELF_HWCAP sparc64_elf_hwcap
4911
4912 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4913 index a790cc6..091ed94 100644
4914 --- a/arch/sparc/include/asm/pgtable_32.h
4915 +++ b/arch/sparc/include/asm/pgtable_32.h
4916 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4917 BTFIXUPDEF_INT(page_none)
4918 BTFIXUPDEF_INT(page_copy)
4919 BTFIXUPDEF_INT(page_readonly)
4920 +
4921 +#ifdef CONFIG_PAX_PAGEEXEC
4922 +BTFIXUPDEF_INT(page_shared_noexec)
4923 +BTFIXUPDEF_INT(page_copy_noexec)
4924 +BTFIXUPDEF_INT(page_readonly_noexec)
4925 +#endif
4926 +
4927 BTFIXUPDEF_INT(page_kernel)
4928
4929 #define PMD_SHIFT SUN4C_PMD_SHIFT
4930 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
4931 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4932 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4933
4934 +#ifdef CONFIG_PAX_PAGEEXEC
4935 +extern pgprot_t PAGE_SHARED_NOEXEC;
4936 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4937 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4938 +#else
4939 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4940 +# define PAGE_COPY_NOEXEC PAGE_COPY
4941 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4942 +#endif
4943 +
4944 extern unsigned long page_kernel;
4945
4946 #ifdef MODULE
4947 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4948 index f6ae2b2..b03ffc7 100644
4949 --- a/arch/sparc/include/asm/pgtsrmmu.h
4950 +++ b/arch/sparc/include/asm/pgtsrmmu.h
4951 @@ -115,6 +115,13 @@
4952 SRMMU_EXEC | SRMMU_REF)
4953 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4954 SRMMU_EXEC | SRMMU_REF)
4955 +
4956 +#ifdef CONFIG_PAX_PAGEEXEC
4957 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4958 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4959 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4960 +#endif
4961 +
4962 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4963 SRMMU_DIRTY | SRMMU_REF)
4964
4965 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4966 index 9689176..63c18ea 100644
4967 --- a/arch/sparc/include/asm/spinlock_64.h
4968 +++ b/arch/sparc/include/asm/spinlock_64.h
4969 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
4970
4971 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4972
4973 -static void inline arch_read_lock(arch_rwlock_t *lock)
4974 +static inline void arch_read_lock(arch_rwlock_t *lock)
4975 {
4976 unsigned long tmp1, tmp2;
4977
4978 __asm__ __volatile__ (
4979 "1: ldsw [%2], %0\n"
4980 " brlz,pn %0, 2f\n"
4981 -"4: add %0, 1, %1\n"
4982 +"4: addcc %0, 1, %1\n"
4983 +
4984 +#ifdef CONFIG_PAX_REFCOUNT
4985 +" tvs %%icc, 6\n"
4986 +#endif
4987 +
4988 " cas [%2], %0, %1\n"
4989 " cmp %0, %1\n"
4990 " bne,pn %%icc, 1b\n"
4991 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
4992 " .previous"
4993 : "=&r" (tmp1), "=&r" (tmp2)
4994 : "r" (lock)
4995 - : "memory");
4996 + : "memory", "cc");
4997 }
4998
4999 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5000 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5001 {
5002 int tmp1, tmp2;
5003
5004 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5005 "1: ldsw [%2], %0\n"
5006 " brlz,a,pn %0, 2f\n"
5007 " mov 0, %0\n"
5008 -" add %0, 1, %1\n"
5009 +" addcc %0, 1, %1\n"
5010 +
5011 +#ifdef CONFIG_PAX_REFCOUNT
5012 +" tvs %%icc, 6\n"
5013 +#endif
5014 +
5015 " cas [%2], %0, %1\n"
5016 " cmp %0, %1\n"
5017 " bne,pn %%icc, 1b\n"
5018 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5019 return tmp1;
5020 }
5021
5022 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5023 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5024 {
5025 unsigned long tmp1, tmp2;
5026
5027 __asm__ __volatile__(
5028 "1: lduw [%2], %0\n"
5029 -" sub %0, 1, %1\n"
5030 +" subcc %0, 1, %1\n"
5031 +
5032 +#ifdef CONFIG_PAX_REFCOUNT
5033 +" tvs %%icc, 6\n"
5034 +#endif
5035 +
5036 " cas [%2], %0, %1\n"
5037 " cmp %0, %1\n"
5038 " bne,pn %%xcc, 1b\n"
5039 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5040 : "memory");
5041 }
5042
5043 -static void inline arch_write_lock(arch_rwlock_t *lock)
5044 +static inline void arch_write_lock(arch_rwlock_t *lock)
5045 {
5046 unsigned long mask, tmp1, tmp2;
5047
5048 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5049 : "memory");
5050 }
5051
5052 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5053 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5054 {
5055 __asm__ __volatile__(
5056 " stw %%g0, [%0]"
5057 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5058 : "memory");
5059 }
5060
5061 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5062 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5063 {
5064 unsigned long mask, tmp1, tmp2, result;
5065
5066 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5067 index c2a1080..21ed218 100644
5068 --- a/arch/sparc/include/asm/thread_info_32.h
5069 +++ b/arch/sparc/include/asm/thread_info_32.h
5070 @@ -50,6 +50,8 @@ struct thread_info {
5071 unsigned long w_saved;
5072
5073 struct restart_block restart_block;
5074 +
5075 + unsigned long lowest_stack;
5076 };
5077
5078 /*
5079 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5080 index 01d057f..0a02f7e 100644
5081 --- a/arch/sparc/include/asm/thread_info_64.h
5082 +++ b/arch/sparc/include/asm/thread_info_64.h
5083 @@ -63,6 +63,8 @@ struct thread_info {
5084 struct pt_regs *kern_una_regs;
5085 unsigned int kern_una_insn;
5086
5087 + unsigned long lowest_stack;
5088 +
5089 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5090 };
5091
5092 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5093 index e88fbe5..96b0ce5 100644
5094 --- a/arch/sparc/include/asm/uaccess.h
5095 +++ b/arch/sparc/include/asm/uaccess.h
5096 @@ -1,5 +1,13 @@
5097 #ifndef ___ASM_SPARC_UACCESS_H
5098 #define ___ASM_SPARC_UACCESS_H
5099 +
5100 +#ifdef __KERNEL__
5101 +#ifndef __ASSEMBLY__
5102 +#include <linux/types.h>
5103 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5104 +#endif
5105 +#endif
5106 +
5107 #if defined(__sparc__) && defined(__arch64__)
5108 #include <asm/uaccess_64.h>
5109 #else
5110 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5111 index 8303ac4..07f333d 100644
5112 --- a/arch/sparc/include/asm/uaccess_32.h
5113 +++ b/arch/sparc/include/asm/uaccess_32.h
5114 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5115
5116 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5117 {
5118 - if (n && __access_ok((unsigned long) to, n))
5119 + if ((long)n < 0)
5120 + return n;
5121 +
5122 + if (n && __access_ok((unsigned long) to, n)) {
5123 + if (!__builtin_constant_p(n))
5124 + check_object_size(from, n, true);
5125 return __copy_user(to, (__force void __user *) from, n);
5126 - else
5127 + } else
5128 return n;
5129 }
5130
5131 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5132 {
5133 + if ((long)n < 0)
5134 + return n;
5135 +
5136 + if (!__builtin_constant_p(n))
5137 + check_object_size(from, n, true);
5138 +
5139 return __copy_user(to, (__force void __user *) from, n);
5140 }
5141
5142 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5143 {
5144 - if (n && __access_ok((unsigned long) from, n))
5145 + if ((long)n < 0)
5146 + return n;
5147 +
5148 + if (n && __access_ok((unsigned long) from, n)) {
5149 + if (!__builtin_constant_p(n))
5150 + check_object_size(to, n, false);
5151 return __copy_user((__force void __user *) to, from, n);
5152 - else
5153 + } else
5154 return n;
5155 }
5156
5157 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5158 {
5159 + if ((long)n < 0)
5160 + return n;
5161 +
5162 return __copy_user((__force void __user *) to, from, n);
5163 }
5164
5165 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5166 index 3e1449f..5293a0e 100644
5167 --- a/arch/sparc/include/asm/uaccess_64.h
5168 +++ b/arch/sparc/include/asm/uaccess_64.h
5169 @@ -10,6 +10,7 @@
5170 #include <linux/compiler.h>
5171 #include <linux/string.h>
5172 #include <linux/thread_info.h>
5173 +#include <linux/kernel.h>
5174 #include <asm/asi.h>
5175 #include <asm/system.h>
5176 #include <asm/spitfire.h>
5177 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5178 static inline unsigned long __must_check
5179 copy_from_user(void *to, const void __user *from, unsigned long size)
5180 {
5181 - unsigned long ret = ___copy_from_user(to, from, size);
5182 + unsigned long ret;
5183
5184 + if ((long)size < 0 || size > INT_MAX)
5185 + return size;
5186 +
5187 + if (!__builtin_constant_p(size))
5188 + check_object_size(to, size, false);
5189 +
5190 + ret = ___copy_from_user(to, from, size);
5191 if (unlikely(ret))
5192 ret = copy_from_user_fixup(to, from, size);
5193
5194 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5195 static inline unsigned long __must_check
5196 copy_to_user(void __user *to, const void *from, unsigned long size)
5197 {
5198 - unsigned long ret = ___copy_to_user(to, from, size);
5199 + unsigned long ret;
5200
5201 + if ((long)size < 0 || size > INT_MAX)
5202 + return size;
5203 +
5204 + if (!__builtin_constant_p(size))
5205 + check_object_size(from, size, true);
5206 +
5207 + ret = ___copy_to_user(to, from, size);
5208 if (unlikely(ret))
5209 ret = copy_to_user_fixup(to, from, size);
5210 return ret;
5211 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5212 index cb85458..e063f17 100644
5213 --- a/arch/sparc/kernel/Makefile
5214 +++ b/arch/sparc/kernel/Makefile
5215 @@ -3,7 +3,7 @@
5216 #
5217
5218 asflags-y := -ansi
5219 -ccflags-y := -Werror
5220 +#ccflags-y := -Werror
5221
5222 extra-y := head_$(BITS).o
5223 extra-y += init_task.o
5224 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5225 index f793742..4d880af 100644
5226 --- a/arch/sparc/kernel/process_32.c
5227 +++ b/arch/sparc/kernel/process_32.c
5228 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5229 rw->ins[4], rw->ins[5],
5230 rw->ins[6],
5231 rw->ins[7]);
5232 - printk("%pS\n", (void *) rw->ins[7]);
5233 + printk("%pA\n", (void *) rw->ins[7]);
5234 rw = (struct reg_window32 *) rw->ins[6];
5235 }
5236 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5237 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5238
5239 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5240 r->psr, r->pc, r->npc, r->y, print_tainted());
5241 - printk("PC: <%pS>\n", (void *) r->pc);
5242 + printk("PC: <%pA>\n", (void *) r->pc);
5243 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5244 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5245 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5246 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5247 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5248 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5249 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5250 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5251
5252 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5253 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5254 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5255 rw = (struct reg_window32 *) fp;
5256 pc = rw->ins[7];
5257 printk("[%08lx : ", pc);
5258 - printk("%pS ] ", (void *) pc);
5259 + printk("%pA ] ", (void *) pc);
5260 fp = rw->ins[6];
5261 } while (++count < 16);
5262 printk("\n");
5263 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5264 index 39d8b05..d1a7d90 100644
5265 --- a/arch/sparc/kernel/process_64.c
5266 +++ b/arch/sparc/kernel/process_64.c
5267 @@ -182,14 +182,14 @@ static void show_regwindow(struct pt_regs *regs)
5268 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5269 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5270 if (regs->tstate & TSTATE_PRIV)
5271 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5272 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5273 }
5274
5275 void show_regs(struct pt_regs *regs)
5276 {
5277 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5278 regs->tpc, regs->tnpc, regs->y, print_tainted());
5279 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5280 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5281 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5282 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5283 regs->u_regs[3]);
5284 @@ -202,7 +202,7 @@ void show_regs(struct pt_regs *regs)
5285 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5286 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5287 regs->u_regs[15]);
5288 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5289 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5290 show_regwindow(regs);
5291 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5292 }
5293 @@ -287,7 +287,7 @@ void arch_trigger_all_cpu_backtrace(void)
5294 ((tp && tp->task) ? tp->task->pid : -1));
5295
5296 if (gp->tstate & TSTATE_PRIV) {
5297 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5298 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5299 (void *) gp->tpc,
5300 (void *) gp->o7,
5301 (void *) gp->i7,
5302 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5303 index 42b282f..28ce9f2 100644
5304 --- a/arch/sparc/kernel/sys_sparc_32.c
5305 +++ b/arch/sparc/kernel/sys_sparc_32.c
5306 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5307 if (ARCH_SUN4C && len > 0x20000000)
5308 return -ENOMEM;
5309 if (!addr)
5310 - addr = TASK_UNMAPPED_BASE;
5311 + addr = current->mm->mmap_base;
5312
5313 if (flags & MAP_SHARED)
5314 addr = COLOUR_ALIGN(addr);
5315 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5316 }
5317 if (TASK_SIZE - PAGE_SIZE - len < addr)
5318 return -ENOMEM;
5319 - if (!vmm || addr + len <= vmm->vm_start)
5320 + if (check_heap_stack_gap(vmm, addr, len))
5321 return addr;
5322 addr = vmm->vm_end;
5323 if (flags & MAP_SHARED)
5324 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5325 index 232df99..cee1f9c 100644
5326 --- a/arch/sparc/kernel/sys_sparc_64.c
5327 +++ b/arch/sparc/kernel/sys_sparc_64.c
5328 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5329 /* We do not accept a shared mapping if it would violate
5330 * cache aliasing constraints.
5331 */
5332 - if ((flags & MAP_SHARED) &&
5333 + if ((filp || (flags & MAP_SHARED)) &&
5334 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5335 return -EINVAL;
5336 return addr;
5337 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5338 if (filp || (flags & MAP_SHARED))
5339 do_color_align = 1;
5340
5341 +#ifdef CONFIG_PAX_RANDMMAP
5342 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5343 +#endif
5344 +
5345 if (addr) {
5346 if (do_color_align)
5347 addr = COLOUR_ALIGN(addr, pgoff);
5348 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5349 addr = PAGE_ALIGN(addr);
5350
5351 vma = find_vma(mm, addr);
5352 - if (task_size - len >= addr &&
5353 - (!vma || addr + len <= vma->vm_start))
5354 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5355 return addr;
5356 }
5357
5358 if (len > mm->cached_hole_size) {
5359 - start_addr = addr = mm->free_area_cache;
5360 + start_addr = addr = mm->free_area_cache;
5361 } else {
5362 - start_addr = addr = TASK_UNMAPPED_BASE;
5363 + start_addr = addr = mm->mmap_base;
5364 mm->cached_hole_size = 0;
5365 }
5366
5367 @@ -174,14 +177,14 @@ full_search:
5368 vma = find_vma(mm, VA_EXCLUDE_END);
5369 }
5370 if (unlikely(task_size < addr)) {
5371 - if (start_addr != TASK_UNMAPPED_BASE) {
5372 - start_addr = addr = TASK_UNMAPPED_BASE;
5373 + if (start_addr != mm->mmap_base) {
5374 + start_addr = addr = mm->mmap_base;
5375 mm->cached_hole_size = 0;
5376 goto full_search;
5377 }
5378 return -ENOMEM;
5379 }
5380 - if (likely(!vma || addr + len <= vma->vm_start)) {
5381 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5382 /*
5383 * Remember the place where we stopped the search:
5384 */
5385 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5386 /* We do not accept a shared mapping if it would violate
5387 * cache aliasing constraints.
5388 */
5389 - if ((flags & MAP_SHARED) &&
5390 + if ((filp || (flags & MAP_SHARED)) &&
5391 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5392 return -EINVAL;
5393 return addr;
5394 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5395 addr = PAGE_ALIGN(addr);
5396
5397 vma = find_vma(mm, addr);
5398 - if (task_size - len >= addr &&
5399 - (!vma || addr + len <= vma->vm_start))
5400 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5401 return addr;
5402 }
5403
5404 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5405 /* make sure it can fit in the remaining address space */
5406 if (likely(addr > len)) {
5407 vma = find_vma(mm, addr-len);
5408 - if (!vma || addr <= vma->vm_start) {
5409 + if (check_heap_stack_gap(vma, addr - len, len)) {
5410 /* remember the address as a hint for next time */
5411 return (mm->free_area_cache = addr-len);
5412 }
5413 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5414 if (unlikely(mm->mmap_base < len))
5415 goto bottomup;
5416
5417 - addr = mm->mmap_base-len;
5418 - if (do_color_align)
5419 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5420 + addr = mm->mmap_base - len;
5421
5422 do {
5423 + if (do_color_align)
5424 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5425 /*
5426 * Lookup failure means no vma is above this address,
5427 * else if new region fits below vma->vm_start,
5428 * return with success:
5429 */
5430 vma = find_vma(mm, addr);
5431 - if (likely(!vma || addr+len <= vma->vm_start)) {
5432 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5433 /* remember the address as a hint for next time */
5434 return (mm->free_area_cache = addr);
5435 }
5436 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5437 mm->cached_hole_size = vma->vm_start - addr;
5438
5439 /* try just below the current vma->vm_start */
5440 - addr = vma->vm_start-len;
5441 - if (do_color_align)
5442 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5443 - } while (likely(len < vma->vm_start));
5444 + addr = skip_heap_stack_gap(vma, len);
5445 + } while (!IS_ERR_VALUE(addr));
5446
5447 bottomup:
5448 /*
5449 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5450 gap == RLIM_INFINITY ||
5451 sysctl_legacy_va_layout) {
5452 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5453 +
5454 +#ifdef CONFIG_PAX_RANDMMAP
5455 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5456 + mm->mmap_base += mm->delta_mmap;
5457 +#endif
5458 +
5459 mm->get_unmapped_area = arch_get_unmapped_area;
5460 mm->unmap_area = arch_unmap_area;
5461 } else {
5462 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5463 gap = (task_size / 6 * 5);
5464
5465 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5466 +
5467 +#ifdef CONFIG_PAX_RANDMMAP
5468 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5469 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5470 +#endif
5471 +
5472 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5473 mm->unmap_area = arch_unmap_area_topdown;
5474 }
5475 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5476 index 591f20c..0f1b925 100644
5477 --- a/arch/sparc/kernel/traps_32.c
5478 +++ b/arch/sparc/kernel/traps_32.c
5479 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
5480 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5481 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5482
5483 +extern void gr_handle_kernel_exploit(void);
5484 +
5485 void die_if_kernel(char *str, struct pt_regs *regs)
5486 {
5487 static int die_counter;
5488 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5489 count++ < 30 &&
5490 (((unsigned long) rw) >= PAGE_OFFSET) &&
5491 !(((unsigned long) rw) & 0x7)) {
5492 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5493 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5494 (void *) rw->ins[7]);
5495 rw = (struct reg_window32 *)rw->ins[6];
5496 }
5497 }
5498 printk("Instruction DUMP:");
5499 instruction_dump ((unsigned long *) regs->pc);
5500 - if(regs->psr & PSR_PS)
5501 + if(regs->psr & PSR_PS) {
5502 + gr_handle_kernel_exploit();
5503 do_exit(SIGKILL);
5504 + }
5505 do_exit(SIGSEGV);
5506 }
5507
5508 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5509 index 0cbdaa4..438e4c9 100644
5510 --- a/arch/sparc/kernel/traps_64.c
5511 +++ b/arch/sparc/kernel/traps_64.c
5512 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5513 i + 1,
5514 p->trapstack[i].tstate, p->trapstack[i].tpc,
5515 p->trapstack[i].tnpc, p->trapstack[i].tt);
5516 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5517 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5518 }
5519 }
5520
5521 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5522
5523 lvl -= 0x100;
5524 if (regs->tstate & TSTATE_PRIV) {
5525 +
5526 +#ifdef CONFIG_PAX_REFCOUNT
5527 + if (lvl == 6)
5528 + pax_report_refcount_overflow(regs);
5529 +#endif
5530 +
5531 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5532 die_if_kernel(buffer, regs);
5533 }
5534 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5535 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5536 {
5537 char buffer[32];
5538 -
5539 +
5540 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5541 0, lvl, SIGTRAP) == NOTIFY_STOP)
5542 return;
5543
5544 +#ifdef CONFIG_PAX_REFCOUNT
5545 + if (lvl == 6)
5546 + pax_report_refcount_overflow(regs);
5547 +#endif
5548 +
5549 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5550
5551 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5552 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5553 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5554 printk("%s" "ERROR(%d): ",
5555 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5556 - printk("TPC<%pS>\n", (void *) regs->tpc);
5557 + printk("TPC<%pA>\n", (void *) regs->tpc);
5558 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5559 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5560 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5561 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5562 smp_processor_id(),
5563 (type & 0x1) ? 'I' : 'D',
5564 regs->tpc);
5565 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5566 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5567 panic("Irrecoverable Cheetah+ parity error.");
5568 }
5569
5570 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5571 smp_processor_id(),
5572 (type & 0x1) ? 'I' : 'D',
5573 regs->tpc);
5574 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5575 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5576 }
5577
5578 struct sun4v_error_entry {
5579 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5580
5581 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5582 regs->tpc, tl);
5583 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5584 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5585 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5586 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5587 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5588 (void *) regs->u_regs[UREG_I7]);
5589 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5590 "pte[%lx] error[%lx]\n",
5591 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5592
5593 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5594 regs->tpc, tl);
5595 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5596 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5597 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5598 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5599 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5600 (void *) regs->u_regs[UREG_I7]);
5601 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5602 "pte[%lx] error[%lx]\n",
5603 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5604 fp = (unsigned long)sf->fp + STACK_BIAS;
5605 }
5606
5607 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5608 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5609 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5610 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
5611 int index = tsk->curr_ret_stack;
5612 if (tsk->ret_stack && index >= graph) {
5613 pc = tsk->ret_stack[index - graph].ret;
5614 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5615 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5616 graph++;
5617 }
5618 }
5619 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5620 return (struct reg_window *) (fp + STACK_BIAS);
5621 }
5622
5623 +extern void gr_handle_kernel_exploit(void);
5624 +
5625 void die_if_kernel(char *str, struct pt_regs *regs)
5626 {
5627 static int die_counter;
5628 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5629 while (rw &&
5630 count++ < 30 &&
5631 kstack_valid(tp, (unsigned long) rw)) {
5632 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
5633 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
5634 (void *) rw->ins[7]);
5635
5636 rw = kernel_stack_up(rw);
5637 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5638 }
5639 user_instruction_dump ((unsigned int __user *) regs->tpc);
5640 }
5641 - if (regs->tstate & TSTATE_PRIV)
5642 + if (regs->tstate & TSTATE_PRIV) {
5643 + gr_handle_kernel_exploit();
5644 do_exit(SIGKILL);
5645 + }
5646 do_exit(SIGSEGV);
5647 }
5648 EXPORT_SYMBOL(die_if_kernel);
5649 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5650 index 76e4ac1..78f8bb1 100644
5651 --- a/arch/sparc/kernel/unaligned_64.c
5652 +++ b/arch/sparc/kernel/unaligned_64.c
5653 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
5654 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
5655
5656 if (__ratelimit(&ratelimit)) {
5657 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
5658 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
5659 regs->tpc, (void *) regs->tpc);
5660 }
5661 }
5662 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5663 index a3fc437..fea9957 100644
5664 --- a/arch/sparc/lib/Makefile
5665 +++ b/arch/sparc/lib/Makefile
5666 @@ -2,7 +2,7 @@
5667 #
5668
5669 asflags-y := -ansi -DST_DIV0=0x02
5670 -ccflags-y := -Werror
5671 +#ccflags-y := -Werror
5672
5673 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5674 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5675 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5676 index 59186e0..f747d7a 100644
5677 --- a/arch/sparc/lib/atomic_64.S
5678 +++ b/arch/sparc/lib/atomic_64.S
5679 @@ -18,7 +18,12 @@
5680 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5681 BACKOFF_SETUP(%o2)
5682 1: lduw [%o1], %g1
5683 - add %g1, %o0, %g7
5684 + addcc %g1, %o0, %g7
5685 +
5686 +#ifdef CONFIG_PAX_REFCOUNT
5687 + tvs %icc, 6
5688 +#endif
5689 +
5690 cas [%o1], %g1, %g7
5691 cmp %g1, %g7
5692 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5693 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5694 2: BACKOFF_SPIN(%o2, %o3, 1b)
5695 .size atomic_add, .-atomic_add
5696
5697 + .globl atomic_add_unchecked
5698 + .type atomic_add_unchecked,#function
5699 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5700 + BACKOFF_SETUP(%o2)
5701 +1: lduw [%o1], %g1
5702 + add %g1, %o0, %g7
5703 + cas [%o1], %g1, %g7
5704 + cmp %g1, %g7
5705 + bne,pn %icc, 2f
5706 + nop
5707 + retl
5708 + nop
5709 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5710 + .size atomic_add_unchecked, .-atomic_add_unchecked
5711 +
5712 .globl atomic_sub
5713 .type atomic_sub,#function
5714 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5715 BACKOFF_SETUP(%o2)
5716 1: lduw [%o1], %g1
5717 - sub %g1, %o0, %g7
5718 + subcc %g1, %o0, %g7
5719 +
5720 +#ifdef CONFIG_PAX_REFCOUNT
5721 + tvs %icc, 6
5722 +#endif
5723 +
5724 cas [%o1], %g1, %g7
5725 cmp %g1, %g7
5726 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5727 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5728 2: BACKOFF_SPIN(%o2, %o3, 1b)
5729 .size atomic_sub, .-atomic_sub
5730
5731 + .globl atomic_sub_unchecked
5732 + .type atomic_sub_unchecked,#function
5733 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5734 + BACKOFF_SETUP(%o2)
5735 +1: lduw [%o1], %g1
5736 + sub %g1, %o0, %g7
5737 + cas [%o1], %g1, %g7
5738 + cmp %g1, %g7
5739 + bne,pn %icc, 2f
5740 + nop
5741 + retl
5742 + nop
5743 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5744 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
5745 +
5746 .globl atomic_add_ret
5747 .type atomic_add_ret,#function
5748 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5749 BACKOFF_SETUP(%o2)
5750 1: lduw [%o1], %g1
5751 - add %g1, %o0, %g7
5752 + addcc %g1, %o0, %g7
5753 +
5754 +#ifdef CONFIG_PAX_REFCOUNT
5755 + tvs %icc, 6
5756 +#endif
5757 +
5758 cas [%o1], %g1, %g7
5759 cmp %g1, %g7
5760 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5761 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5762 2: BACKOFF_SPIN(%o2, %o3, 1b)
5763 .size atomic_add_ret, .-atomic_add_ret
5764
5765 + .globl atomic_add_ret_unchecked
5766 + .type atomic_add_ret_unchecked,#function
5767 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5768 + BACKOFF_SETUP(%o2)
5769 +1: lduw [%o1], %g1
5770 + addcc %g1, %o0, %g7
5771 + cas [%o1], %g1, %g7
5772 + cmp %g1, %g7
5773 + bne,pn %icc, 2f
5774 + add %g7, %o0, %g7
5775 + sra %g7, 0, %o0
5776 + retl
5777 + nop
5778 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5779 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5780 +
5781 .globl atomic_sub_ret
5782 .type atomic_sub_ret,#function
5783 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5784 BACKOFF_SETUP(%o2)
5785 1: lduw [%o1], %g1
5786 - sub %g1, %o0, %g7
5787 + subcc %g1, %o0, %g7
5788 +
5789 +#ifdef CONFIG_PAX_REFCOUNT
5790 + tvs %icc, 6
5791 +#endif
5792 +
5793 cas [%o1], %g1, %g7
5794 cmp %g1, %g7
5795 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5796 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5797 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5798 BACKOFF_SETUP(%o2)
5799 1: ldx [%o1], %g1
5800 - add %g1, %o0, %g7
5801 + addcc %g1, %o0, %g7
5802 +
5803 +#ifdef CONFIG_PAX_REFCOUNT
5804 + tvs %xcc, 6
5805 +#endif
5806 +
5807 casx [%o1], %g1, %g7
5808 cmp %g1, %g7
5809 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5810 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5811 2: BACKOFF_SPIN(%o2, %o3, 1b)
5812 .size atomic64_add, .-atomic64_add
5813
5814 + .globl atomic64_add_unchecked
5815 + .type atomic64_add_unchecked,#function
5816 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5817 + BACKOFF_SETUP(%o2)
5818 +1: ldx [%o1], %g1
5819 + addcc %g1, %o0, %g7
5820 + casx [%o1], %g1, %g7
5821 + cmp %g1, %g7
5822 + bne,pn %xcc, 2f
5823 + nop
5824 + retl
5825 + nop
5826 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5827 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
5828 +
5829 .globl atomic64_sub
5830 .type atomic64_sub,#function
5831 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5832 BACKOFF_SETUP(%o2)
5833 1: ldx [%o1], %g1
5834 - sub %g1, %o0, %g7
5835 + subcc %g1, %o0, %g7
5836 +
5837 +#ifdef CONFIG_PAX_REFCOUNT
5838 + tvs %xcc, 6
5839 +#endif
5840 +
5841 casx [%o1], %g1, %g7
5842 cmp %g1, %g7
5843 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5844 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5845 2: BACKOFF_SPIN(%o2, %o3, 1b)
5846 .size atomic64_sub, .-atomic64_sub
5847
5848 + .globl atomic64_sub_unchecked
5849 + .type atomic64_sub_unchecked,#function
5850 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5851 + BACKOFF_SETUP(%o2)
5852 +1: ldx [%o1], %g1
5853 + subcc %g1, %o0, %g7
5854 + casx [%o1], %g1, %g7
5855 + cmp %g1, %g7
5856 + bne,pn %xcc, 2f
5857 + nop
5858 + retl
5859 + nop
5860 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5861 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5862 +
5863 .globl atomic64_add_ret
5864 .type atomic64_add_ret,#function
5865 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5866 BACKOFF_SETUP(%o2)
5867 1: ldx [%o1], %g1
5868 - add %g1, %o0, %g7
5869 + addcc %g1, %o0, %g7
5870 +
5871 +#ifdef CONFIG_PAX_REFCOUNT
5872 + tvs %xcc, 6
5873 +#endif
5874 +
5875 casx [%o1], %g1, %g7
5876 cmp %g1, %g7
5877 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5878 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5879 2: BACKOFF_SPIN(%o2, %o3, 1b)
5880 .size atomic64_add_ret, .-atomic64_add_ret
5881
5882 + .globl atomic64_add_ret_unchecked
5883 + .type atomic64_add_ret_unchecked,#function
5884 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5885 + BACKOFF_SETUP(%o2)
5886 +1: ldx [%o1], %g1
5887 + addcc %g1, %o0, %g7
5888 + casx [%o1], %g1, %g7
5889 + cmp %g1, %g7
5890 + bne,pn %xcc, 2f
5891 + add %g7, %o0, %g7
5892 + mov %g7, %o0
5893 + retl
5894 + nop
5895 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5896 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5897 +
5898 .globl atomic64_sub_ret
5899 .type atomic64_sub_ret,#function
5900 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5901 BACKOFF_SETUP(%o2)
5902 1: ldx [%o1], %g1
5903 - sub %g1, %o0, %g7
5904 + subcc %g1, %o0, %g7
5905 +
5906 +#ifdef CONFIG_PAX_REFCOUNT
5907 + tvs %xcc, 6
5908 +#endif
5909 +
5910 casx [%o1], %g1, %g7
5911 cmp %g1, %g7
5912 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5913 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5914 index f73c224..662af10 100644
5915 --- a/arch/sparc/lib/ksyms.c
5916 +++ b/arch/sparc/lib/ksyms.c
5917 @@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
5918
5919 /* Atomic counter implementation. */
5920 EXPORT_SYMBOL(atomic_add);
5921 +EXPORT_SYMBOL(atomic_add_unchecked);
5922 EXPORT_SYMBOL(atomic_add_ret);
5923 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
5924 EXPORT_SYMBOL(atomic_sub);
5925 +EXPORT_SYMBOL(atomic_sub_unchecked);
5926 EXPORT_SYMBOL(atomic_sub_ret);
5927 EXPORT_SYMBOL(atomic64_add);
5928 +EXPORT_SYMBOL(atomic64_add_unchecked);
5929 EXPORT_SYMBOL(atomic64_add_ret);
5930 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5931 EXPORT_SYMBOL(atomic64_sub);
5932 +EXPORT_SYMBOL(atomic64_sub_unchecked);
5933 EXPORT_SYMBOL(atomic64_sub_ret);
5934
5935 /* Atomic bit operations. */
5936 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5937 index 301421c..e2535d1 100644
5938 --- a/arch/sparc/mm/Makefile
5939 +++ b/arch/sparc/mm/Makefile
5940 @@ -2,7 +2,7 @@
5941 #
5942
5943 asflags-y := -ansi
5944 -ccflags-y := -Werror
5945 +#ccflags-y := -Werror
5946
5947 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
5948 obj-y += fault_$(BITS).o
5949 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5950 index 8023fd7..c8e89e9 100644
5951 --- a/arch/sparc/mm/fault_32.c
5952 +++ b/arch/sparc/mm/fault_32.c
5953 @@ -21,6 +21,9 @@
5954 #include <linux/perf_event.h>
5955 #include <linux/interrupt.h>
5956 #include <linux/kdebug.h>
5957 +#include <linux/slab.h>
5958 +#include <linux/pagemap.h>
5959 +#include <linux/compiler.h>
5960
5961 #include <asm/system.h>
5962 #include <asm/page.h>
5963 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
5964 return safe_compute_effective_address(regs, insn);
5965 }
5966
5967 +#ifdef CONFIG_PAX_PAGEEXEC
5968 +#ifdef CONFIG_PAX_DLRESOLVE
5969 +static void pax_emuplt_close(struct vm_area_struct *vma)
5970 +{
5971 + vma->vm_mm->call_dl_resolve = 0UL;
5972 +}
5973 +
5974 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5975 +{
5976 + unsigned int *kaddr;
5977 +
5978 + vmf->page = alloc_page(GFP_HIGHUSER);
5979 + if (!vmf->page)
5980 + return VM_FAULT_OOM;
5981 +
5982 + kaddr = kmap(vmf->page);
5983 + memset(kaddr, 0, PAGE_SIZE);
5984 + kaddr[0] = 0x9DE3BFA8U; /* save */
5985 + flush_dcache_page(vmf->page);
5986 + kunmap(vmf->page);
5987 + return VM_FAULT_MAJOR;
5988 +}
5989 +
5990 +static const struct vm_operations_struct pax_vm_ops = {
5991 + .close = pax_emuplt_close,
5992 + .fault = pax_emuplt_fault
5993 +};
5994 +
5995 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5996 +{
5997 + int ret;
5998 +
5999 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6000 + vma->vm_mm = current->mm;
6001 + vma->vm_start = addr;
6002 + vma->vm_end = addr + PAGE_SIZE;
6003 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6004 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6005 + vma->vm_ops = &pax_vm_ops;
6006 +
6007 + ret = insert_vm_struct(current->mm, vma);
6008 + if (ret)
6009 + return ret;
6010 +
6011 + ++current->mm->total_vm;
6012 + return 0;
6013 +}
6014 +#endif
6015 +
6016 +/*
6017 + * PaX: decide what to do with offenders (regs->pc = fault address)
6018 + *
6019 + * returns 1 when task should be killed
6020 + * 2 when patched PLT trampoline was detected
6021 + * 3 when unpatched PLT trampoline was detected
6022 + */
6023 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6024 +{
6025 +
6026 +#ifdef CONFIG_PAX_EMUPLT
6027 + int err;
6028 +
6029 + do { /* PaX: patched PLT emulation #1 */
6030 + unsigned int sethi1, sethi2, jmpl;
6031 +
6032 + err = get_user(sethi1, (unsigned int *)regs->pc);
6033 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6034 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6035 +
6036 + if (err)
6037 + break;
6038 +
6039 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6040 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6041 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6042 + {
6043 + unsigned int addr;
6044 +
6045 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6046 + addr = regs->u_regs[UREG_G1];
6047 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6048 + regs->pc = addr;
6049 + regs->npc = addr+4;
6050 + return 2;
6051 + }
6052 + } while (0);
6053 +
6054 + { /* PaX: patched PLT emulation #2 */
6055 + unsigned int ba;
6056 +
6057 + err = get_user(ba, (unsigned int *)regs->pc);
6058 +
6059 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6060 + unsigned int addr;
6061 +
6062 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6063 + regs->pc = addr;
6064 + regs->npc = addr+4;
6065 + return 2;
6066 + }
6067 + }
6068 +
6069 + do { /* PaX: patched PLT emulation #3 */
6070 + unsigned int sethi, jmpl, nop;
6071 +
6072 + err = get_user(sethi, (unsigned int *)regs->pc);
6073 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6074 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6075 +
6076 + if (err)
6077 + break;
6078 +
6079 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6080 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6081 + nop == 0x01000000U)
6082 + {
6083 + unsigned int addr;
6084 +
6085 + addr = (sethi & 0x003FFFFFU) << 10;
6086 + regs->u_regs[UREG_G1] = addr;
6087 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6088 + regs->pc = addr;
6089 + regs->npc = addr+4;
6090 + return 2;
6091 + }
6092 + } while (0);
6093 +
6094 + do { /* PaX: unpatched PLT emulation step 1 */
6095 + unsigned int sethi, ba, nop;
6096 +
6097 + err = get_user(sethi, (unsigned int *)regs->pc);
6098 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6099 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6100 +
6101 + if (err)
6102 + break;
6103 +
6104 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6105 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6106 + nop == 0x01000000U)
6107 + {
6108 + unsigned int addr, save, call;
6109 +
6110 + if ((ba & 0xFFC00000U) == 0x30800000U)
6111 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6112 + else
6113 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6114 +
6115 + err = get_user(save, (unsigned int *)addr);
6116 + err |= get_user(call, (unsigned int *)(addr+4));
6117 + err |= get_user(nop, (unsigned int *)(addr+8));
6118 + if (err)
6119 + break;
6120 +
6121 +#ifdef CONFIG_PAX_DLRESOLVE
6122 + if (save == 0x9DE3BFA8U &&
6123 + (call & 0xC0000000U) == 0x40000000U &&
6124 + nop == 0x01000000U)
6125 + {
6126 + struct vm_area_struct *vma;
6127 + unsigned long call_dl_resolve;
6128 +
6129 + down_read(&current->mm->mmap_sem);
6130 + call_dl_resolve = current->mm->call_dl_resolve;
6131 + up_read(&current->mm->mmap_sem);
6132 + if (likely(call_dl_resolve))
6133 + goto emulate;
6134 +
6135 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6136 +
6137 + down_write(&current->mm->mmap_sem);
6138 + if (current->mm->call_dl_resolve) {
6139 + call_dl_resolve = current->mm->call_dl_resolve;
6140 + up_write(&current->mm->mmap_sem);
6141 + if (vma)
6142 + kmem_cache_free(vm_area_cachep, vma);
6143 + goto emulate;
6144 + }
6145 +
6146 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6147 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6148 + up_write(&current->mm->mmap_sem);
6149 + if (vma)
6150 + kmem_cache_free(vm_area_cachep, vma);
6151 + return 1;
6152 + }
6153 +
6154 + if (pax_insert_vma(vma, call_dl_resolve)) {
6155 + up_write(&current->mm->mmap_sem);
6156 + kmem_cache_free(vm_area_cachep, vma);
6157 + return 1;
6158 + }
6159 +
6160 + current->mm->call_dl_resolve = call_dl_resolve;
6161 + up_write(&current->mm->mmap_sem);
6162 +
6163 +emulate:
6164 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6165 + regs->pc = call_dl_resolve;
6166 + regs->npc = addr+4;
6167 + return 3;
6168 + }
6169 +#endif
6170 +
6171 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6172 + if ((save & 0xFFC00000U) == 0x05000000U &&
6173 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6174 + nop == 0x01000000U)
6175 + {
6176 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6177 + regs->u_regs[UREG_G2] = addr + 4;
6178 + addr = (save & 0x003FFFFFU) << 10;
6179 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6180 + regs->pc = addr;
6181 + regs->npc = addr+4;
6182 + return 3;
6183 + }
6184 + }
6185 + } while (0);
6186 +
6187 + do { /* PaX: unpatched PLT emulation step 2 */
6188 + unsigned int save, call, nop;
6189 +
6190 + err = get_user(save, (unsigned int *)(regs->pc-4));
6191 + err |= get_user(call, (unsigned int *)regs->pc);
6192 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6193 + if (err)
6194 + break;
6195 +
6196 + if (save == 0x9DE3BFA8U &&
6197 + (call & 0xC0000000U) == 0x40000000U &&
6198 + nop == 0x01000000U)
6199 + {
6200 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6201 +
6202 + regs->u_regs[UREG_RETPC] = regs->pc;
6203 + regs->pc = dl_resolve;
6204 + regs->npc = dl_resolve+4;
6205 + return 3;
6206 + }
6207 + } while (0);
6208 +#endif
6209 +
6210 + return 1;
6211 +}
6212 +
6213 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6214 +{
6215 + unsigned long i;
6216 +
6217 + printk(KERN_ERR "PAX: bytes at PC: ");
6218 + for (i = 0; i < 8; i++) {
6219 + unsigned int c;
6220 + if (get_user(c, (unsigned int *)pc+i))
6221 + printk(KERN_CONT "???????? ");
6222 + else
6223 + printk(KERN_CONT "%08x ", c);
6224 + }
6225 + printk("\n");
6226 +}
6227 +#endif
6228 +
6229 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6230 int text_fault)
6231 {
6232 @@ -280,6 +545,24 @@ good_area:
6233 if(!(vma->vm_flags & VM_WRITE))
6234 goto bad_area;
6235 } else {
6236 +
6237 +#ifdef CONFIG_PAX_PAGEEXEC
6238 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6239 + up_read(&mm->mmap_sem);
6240 + switch (pax_handle_fetch_fault(regs)) {
6241 +
6242 +#ifdef CONFIG_PAX_EMUPLT
6243 + case 2:
6244 + case 3:
6245 + return;
6246 +#endif
6247 +
6248 + }
6249 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6250 + do_group_exit(SIGKILL);
6251 + }
6252 +#endif
6253 +
6254 /* Allow reads even for write-only mappings */
6255 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6256 goto bad_area;
6257 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6258 index 504c062..6fcb9c6 100644
6259 --- a/arch/sparc/mm/fault_64.c
6260 +++ b/arch/sparc/mm/fault_64.c
6261 @@ -21,6 +21,9 @@
6262 #include <linux/kprobes.h>
6263 #include <linux/kdebug.h>
6264 #include <linux/percpu.h>
6265 +#include <linux/slab.h>
6266 +#include <linux/pagemap.h>
6267 +#include <linux/compiler.h>
6268
6269 #include <asm/page.h>
6270 #include <asm/pgtable.h>
6271 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6272 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6273 regs->tpc);
6274 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6275 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6276 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6277 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6278 dump_stack();
6279 unhandled_fault(regs->tpc, current, regs);
6280 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6281 show_regs(regs);
6282 }
6283
6284 +#ifdef CONFIG_PAX_PAGEEXEC
6285 +#ifdef CONFIG_PAX_DLRESOLVE
6286 +static void pax_emuplt_close(struct vm_area_struct *vma)
6287 +{
6288 + vma->vm_mm->call_dl_resolve = 0UL;
6289 +}
6290 +
6291 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6292 +{
6293 + unsigned int *kaddr;
6294 +
6295 + vmf->page = alloc_page(GFP_HIGHUSER);
6296 + if (!vmf->page)
6297 + return VM_FAULT_OOM;
6298 +
6299 + kaddr = kmap(vmf->page);
6300 + memset(kaddr, 0, PAGE_SIZE);
6301 + kaddr[0] = 0x9DE3BFA8U; /* save */
6302 + flush_dcache_page(vmf->page);
6303 + kunmap(vmf->page);
6304 + return VM_FAULT_MAJOR;
6305 +}
6306 +
6307 +static const struct vm_operations_struct pax_vm_ops = {
6308 + .close = pax_emuplt_close,
6309 + .fault = pax_emuplt_fault
6310 +};
6311 +
6312 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6313 +{
6314 + int ret;
6315 +
6316 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6317 + vma->vm_mm = current->mm;
6318 + vma->vm_start = addr;
6319 + vma->vm_end = addr + PAGE_SIZE;
6320 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6321 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6322 + vma->vm_ops = &pax_vm_ops;
6323 +
6324 + ret = insert_vm_struct(current->mm, vma);
6325 + if (ret)
6326 + return ret;
6327 +
6328 + ++current->mm->total_vm;
6329 + return 0;
6330 +}
6331 +#endif
6332 +
6333 +/*
6334 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6335 + *
6336 + * returns 1 when task should be killed
6337 + * 2 when patched PLT trampoline was detected
6338 + * 3 when unpatched PLT trampoline was detected
6339 + */
6340 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6341 +{
6342 +
6343 +#ifdef CONFIG_PAX_EMUPLT
6344 + int err;
6345 +
6346 + do { /* PaX: patched PLT emulation #1 */
6347 + unsigned int sethi1, sethi2, jmpl;
6348 +
6349 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6350 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6351 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6352 +
6353 + if (err)
6354 + break;
6355 +
6356 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6357 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6358 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6359 + {
6360 + unsigned long addr;
6361 +
6362 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6363 + addr = regs->u_regs[UREG_G1];
6364 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6365 +
6366 + if (test_thread_flag(TIF_32BIT))
6367 + addr &= 0xFFFFFFFFUL;
6368 +
6369 + regs->tpc = addr;
6370 + regs->tnpc = addr+4;
6371 + return 2;
6372 + }
6373 + } while (0);
6374 +
6375 + { /* PaX: patched PLT emulation #2 */
6376 + unsigned int ba;
6377 +
6378 + err = get_user(ba, (unsigned int *)regs->tpc);
6379 +
6380 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6381 + unsigned long addr;
6382 +
6383 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6384 +
6385 + if (test_thread_flag(TIF_32BIT))
6386 + addr &= 0xFFFFFFFFUL;
6387 +
6388 + regs->tpc = addr;
6389 + regs->tnpc = addr+4;
6390 + return 2;
6391 + }
6392 + }
6393 +
6394 + do { /* PaX: patched PLT emulation #3 */
6395 + unsigned int sethi, jmpl, nop;
6396 +
6397 + err = get_user(sethi, (unsigned int *)regs->tpc);
6398 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6399 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6400 +
6401 + if (err)
6402 + break;
6403 +
6404 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6405 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6406 + nop == 0x01000000U)
6407 + {
6408 + unsigned long addr;
6409 +
6410 + addr = (sethi & 0x003FFFFFU) << 10;
6411 + regs->u_regs[UREG_G1] = addr;
6412 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6413 +
6414 + if (test_thread_flag(TIF_32BIT))
6415 + addr &= 0xFFFFFFFFUL;
6416 +
6417 + regs->tpc = addr;
6418 + regs->tnpc = addr+4;
6419 + return 2;
6420 + }
6421 + } while (0);
6422 +
6423 + do { /* PaX: patched PLT emulation #4 */
6424 + unsigned int sethi, mov1, call, mov2;
6425 +
6426 + err = get_user(sethi, (unsigned int *)regs->tpc);
6427 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6428 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6429 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6430 +
6431 + if (err)
6432 + break;
6433 +
6434 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6435 + mov1 == 0x8210000FU &&
6436 + (call & 0xC0000000U) == 0x40000000U &&
6437 + mov2 == 0x9E100001U)
6438 + {
6439 + unsigned long addr;
6440 +
6441 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6442 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6443 +
6444 + if (test_thread_flag(TIF_32BIT))
6445 + addr &= 0xFFFFFFFFUL;
6446 +
6447 + regs->tpc = addr;
6448 + regs->tnpc = addr+4;
6449 + return 2;
6450 + }
6451 + } while (0);
6452 +
6453 + do { /* PaX: patched PLT emulation #5 */
6454 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6455 +
6456 + err = get_user(sethi, (unsigned int *)regs->tpc);
6457 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6458 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6459 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6460 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6461 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6462 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6463 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6464 +
6465 + if (err)
6466 + break;
6467 +
6468 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6469 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6470 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6471 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6472 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6473 + sllx == 0x83287020U &&
6474 + jmpl == 0x81C04005U &&
6475 + nop == 0x01000000U)
6476 + {
6477 + unsigned long addr;
6478 +
6479 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6480 + regs->u_regs[UREG_G1] <<= 32;
6481 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6482 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6483 + regs->tpc = addr;
6484 + regs->tnpc = addr+4;
6485 + return 2;
6486 + }
6487 + } while (0);
6488 +
6489 + do { /* PaX: patched PLT emulation #6 */
6490 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6491 +
6492 + err = get_user(sethi, (unsigned int *)regs->tpc);
6493 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6494 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6495 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6496 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6497 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6498 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6499 +
6500 + if (err)
6501 + break;
6502 +
6503 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6504 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6505 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6506 + sllx == 0x83287020U &&
6507 + (or & 0xFFFFE000U) == 0x8A116000U &&
6508 + jmpl == 0x81C04005U &&
6509 + nop == 0x01000000U)
6510 + {
6511 + unsigned long addr;
6512 +
6513 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6514 + regs->u_regs[UREG_G1] <<= 32;
6515 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6516 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6517 + regs->tpc = addr;
6518 + regs->tnpc = addr+4;
6519 + return 2;
6520 + }
6521 + } while (0);
6522 +
6523 + do { /* PaX: unpatched PLT emulation step 1 */
6524 + unsigned int sethi, ba, nop;
6525 +
6526 + err = get_user(sethi, (unsigned int *)regs->tpc);
6527 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6528 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6529 +
6530 + if (err)
6531 + break;
6532 +
6533 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6534 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6535 + nop == 0x01000000U)
6536 + {
6537 + unsigned long addr;
6538 + unsigned int save, call;
6539 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6540 +
6541 + if ((ba & 0xFFC00000U) == 0x30800000U)
6542 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6543 + else
6544 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6545 +
6546 + if (test_thread_flag(TIF_32BIT))
6547 + addr &= 0xFFFFFFFFUL;
6548 +
6549 + err = get_user(save, (unsigned int *)addr);
6550 + err |= get_user(call, (unsigned int *)(addr+4));
6551 + err |= get_user(nop, (unsigned int *)(addr+8));
6552 + if (err)
6553 + break;
6554 +
6555 +#ifdef CONFIG_PAX_DLRESOLVE
6556 + if (save == 0x9DE3BFA8U &&
6557 + (call & 0xC0000000U) == 0x40000000U &&
6558 + nop == 0x01000000U)
6559 + {
6560 + struct vm_area_struct *vma;
6561 + unsigned long call_dl_resolve;
6562 +
6563 + down_read(&current->mm->mmap_sem);
6564 + call_dl_resolve = current->mm->call_dl_resolve;
6565 + up_read(&current->mm->mmap_sem);
6566 + if (likely(call_dl_resolve))
6567 + goto emulate;
6568 +
6569 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6570 +
6571 + down_write(&current->mm->mmap_sem);
6572 + if (current->mm->call_dl_resolve) {
6573 + call_dl_resolve = current->mm->call_dl_resolve;
6574 + up_write(&current->mm->mmap_sem);
6575 + if (vma)
6576 + kmem_cache_free(vm_area_cachep, vma);
6577 + goto emulate;
6578 + }
6579 +
6580 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6581 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6582 + up_write(&current->mm->mmap_sem);
6583 + if (vma)
6584 + kmem_cache_free(vm_area_cachep, vma);
6585 + return 1;
6586 + }
6587 +
6588 + if (pax_insert_vma(vma, call_dl_resolve)) {
6589 + up_write(&current->mm->mmap_sem);
6590 + kmem_cache_free(vm_area_cachep, vma);
6591 + return 1;
6592 + }
6593 +
6594 + current->mm->call_dl_resolve = call_dl_resolve;
6595 + up_write(&current->mm->mmap_sem);
6596 +
6597 +emulate:
6598 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6599 + regs->tpc = call_dl_resolve;
6600 + regs->tnpc = addr+4;
6601 + return 3;
6602 + }
6603 +#endif
6604 +
6605 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6606 + if ((save & 0xFFC00000U) == 0x05000000U &&
6607 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6608 + nop == 0x01000000U)
6609 + {
6610 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6611 + regs->u_regs[UREG_G2] = addr + 4;
6612 + addr = (save & 0x003FFFFFU) << 10;
6613 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6614 +
6615 + if (test_thread_flag(TIF_32BIT))
6616 + addr &= 0xFFFFFFFFUL;
6617 +
6618 + regs->tpc = addr;
6619 + regs->tnpc = addr+4;
6620 + return 3;
6621 + }
6622 +
6623 + /* PaX: 64-bit PLT stub */
6624 + err = get_user(sethi1, (unsigned int *)addr);
6625 + err |= get_user(sethi2, (unsigned int *)(addr+4));
6626 + err |= get_user(or1, (unsigned int *)(addr+8));
6627 + err |= get_user(or2, (unsigned int *)(addr+12));
6628 + err |= get_user(sllx, (unsigned int *)(addr+16));
6629 + err |= get_user(add, (unsigned int *)(addr+20));
6630 + err |= get_user(jmpl, (unsigned int *)(addr+24));
6631 + err |= get_user(nop, (unsigned int *)(addr+28));
6632 + if (err)
6633 + break;
6634 +
6635 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6636 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6637 + (or1 & 0xFFFFE000U) == 0x88112000U &&
6638 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6639 + sllx == 0x89293020U &&
6640 + add == 0x8A010005U &&
6641 + jmpl == 0x89C14000U &&
6642 + nop == 0x01000000U)
6643 + {
6644 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6645 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6646 + regs->u_regs[UREG_G4] <<= 32;
6647 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6648 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6649 + regs->u_regs[UREG_G4] = addr + 24;
6650 + addr = regs->u_regs[UREG_G5];
6651 + regs->tpc = addr;
6652 + regs->tnpc = addr+4;
6653 + return 3;
6654 + }
6655 + }
6656 + } while (0);
6657 +
6658 +#ifdef CONFIG_PAX_DLRESOLVE
6659 + do { /* PaX: unpatched PLT emulation step 2 */
6660 + unsigned int save, call, nop;
6661 +
6662 + err = get_user(save, (unsigned int *)(regs->tpc-4));
6663 + err |= get_user(call, (unsigned int *)regs->tpc);
6664 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6665 + if (err)
6666 + break;
6667 +
6668 + if (save == 0x9DE3BFA8U &&
6669 + (call & 0xC0000000U) == 0x40000000U &&
6670 + nop == 0x01000000U)
6671 + {
6672 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6673 +
6674 + if (test_thread_flag(TIF_32BIT))
6675 + dl_resolve &= 0xFFFFFFFFUL;
6676 +
6677 + regs->u_regs[UREG_RETPC] = regs->tpc;
6678 + regs->tpc = dl_resolve;
6679 + regs->tnpc = dl_resolve+4;
6680 + return 3;
6681 + }
6682 + } while (0);
6683 +#endif
6684 +
6685 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6686 + unsigned int sethi, ba, nop;
6687 +
6688 + err = get_user(sethi, (unsigned int *)regs->tpc);
6689 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6690 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6691 +
6692 + if (err)
6693 + break;
6694 +
6695 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6696 + (ba & 0xFFF00000U) == 0x30600000U &&
6697 + nop == 0x01000000U)
6698 + {
6699 + unsigned long addr;
6700 +
6701 + addr = (sethi & 0x003FFFFFU) << 10;
6702 + regs->u_regs[UREG_G1] = addr;
6703 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6704 +
6705 + if (test_thread_flag(TIF_32BIT))
6706 + addr &= 0xFFFFFFFFUL;
6707 +
6708 + regs->tpc = addr;
6709 + regs->tnpc = addr+4;
6710 + return 2;
6711 + }
6712 + } while (0);
6713 +
6714 +#endif
6715 +
6716 + return 1;
6717 +}
6718 +
6719 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6720 +{
6721 + unsigned long i;
6722 +
6723 + printk(KERN_ERR "PAX: bytes at PC: ");
6724 + for (i = 0; i < 8; i++) {
6725 + unsigned int c;
6726 + if (get_user(c, (unsigned int *)pc+i))
6727 + printk(KERN_CONT "???????? ");
6728 + else
6729 + printk(KERN_CONT "%08x ", c);
6730 + }
6731 + printk("\n");
6732 +}
6733 +#endif
6734 +
6735 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6736 {
6737 struct mm_struct *mm = current->mm;
6738 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6739 if (!vma)
6740 goto bad_area;
6741
6742 +#ifdef CONFIG_PAX_PAGEEXEC
6743 + /* PaX: detect ITLB misses on non-exec pages */
6744 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6745 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6746 + {
6747 + if (address != regs->tpc)
6748 + goto good_area;
6749 +
6750 + up_read(&mm->mmap_sem);
6751 + switch (pax_handle_fetch_fault(regs)) {
6752 +
6753 +#ifdef CONFIG_PAX_EMUPLT
6754 + case 2:
6755 + case 3:
6756 + return;
6757 +#endif
6758 +
6759 + }
6760 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6761 + do_group_exit(SIGKILL);
6762 + }
6763 +#endif
6764 +
6765 /* Pure DTLB misses do not tell us whether the fault causing
6766 * load/store/atomic was a write or not, it only says that there
6767 * was no match. So in such a case we (carefully) read the
6768 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6769 index 07e1453..0a7d9e9 100644
6770 --- a/arch/sparc/mm/hugetlbpage.c
6771 +++ b/arch/sparc/mm/hugetlbpage.c
6772 @@ -67,7 +67,7 @@ full_search:
6773 }
6774 return -ENOMEM;
6775 }
6776 - if (likely(!vma || addr + len <= vma->vm_start)) {
6777 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6778 /*
6779 * Remember the place where we stopped the search:
6780 */
6781 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6782 /* make sure it can fit in the remaining address space */
6783 if (likely(addr > len)) {
6784 vma = find_vma(mm, addr-len);
6785 - if (!vma || addr <= vma->vm_start) {
6786 + if (check_heap_stack_gap(vma, addr - len, len)) {
6787 /* remember the address as a hint for next time */
6788 return (mm->free_area_cache = addr-len);
6789 }
6790 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6791 if (unlikely(mm->mmap_base < len))
6792 goto bottomup;
6793
6794 - addr = (mm->mmap_base-len) & HPAGE_MASK;
6795 + addr = mm->mmap_base - len;
6796
6797 do {
6798 + addr &= HPAGE_MASK;
6799 /*
6800 * Lookup failure means no vma is above this address,
6801 * else if new region fits below vma->vm_start,
6802 * return with success:
6803 */
6804 vma = find_vma(mm, addr);
6805 - if (likely(!vma || addr+len <= vma->vm_start)) {
6806 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6807 /* remember the address as a hint for next time */
6808 return (mm->free_area_cache = addr);
6809 }
6810 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6811 mm->cached_hole_size = vma->vm_start - addr;
6812
6813 /* try just below the current vma->vm_start */
6814 - addr = (vma->vm_start-len) & HPAGE_MASK;
6815 - } while (likely(len < vma->vm_start));
6816 + addr = skip_heap_stack_gap(vma, len);
6817 + } while (!IS_ERR_VALUE(addr));
6818
6819 bottomup:
6820 /*
6821 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6822 if (addr) {
6823 addr = ALIGN(addr, HPAGE_SIZE);
6824 vma = find_vma(mm, addr);
6825 - if (task_size - len >= addr &&
6826 - (!vma || addr + len <= vma->vm_start))
6827 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6828 return addr;
6829 }
6830 if (mm->get_unmapped_area == arch_get_unmapped_area)
6831 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6832 index 7b00de6..78239f4 100644
6833 --- a/arch/sparc/mm/init_32.c
6834 +++ b/arch/sparc/mm/init_32.c
6835 @@ -316,6 +316,9 @@ extern void device_scan(void);
6836 pgprot_t PAGE_SHARED __read_mostly;
6837 EXPORT_SYMBOL(PAGE_SHARED);
6838
6839 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6840 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6841 +
6842 void __init paging_init(void)
6843 {
6844 switch(sparc_cpu_model) {
6845 @@ -344,17 +347,17 @@ void __init paging_init(void)
6846
6847 /* Initialize the protection map with non-constant, MMU dependent values. */
6848 protection_map[0] = PAGE_NONE;
6849 - protection_map[1] = PAGE_READONLY;
6850 - protection_map[2] = PAGE_COPY;
6851 - protection_map[3] = PAGE_COPY;
6852 + protection_map[1] = PAGE_READONLY_NOEXEC;
6853 + protection_map[2] = PAGE_COPY_NOEXEC;
6854 + protection_map[3] = PAGE_COPY_NOEXEC;
6855 protection_map[4] = PAGE_READONLY;
6856 protection_map[5] = PAGE_READONLY;
6857 protection_map[6] = PAGE_COPY;
6858 protection_map[7] = PAGE_COPY;
6859 protection_map[8] = PAGE_NONE;
6860 - protection_map[9] = PAGE_READONLY;
6861 - protection_map[10] = PAGE_SHARED;
6862 - protection_map[11] = PAGE_SHARED;
6863 + protection_map[9] = PAGE_READONLY_NOEXEC;
6864 + protection_map[10] = PAGE_SHARED_NOEXEC;
6865 + protection_map[11] = PAGE_SHARED_NOEXEC;
6866 protection_map[12] = PAGE_READONLY;
6867 protection_map[13] = PAGE_READONLY;
6868 protection_map[14] = PAGE_SHARED;
6869 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6870 index cbef74e..c38fead 100644
6871 --- a/arch/sparc/mm/srmmu.c
6872 +++ b/arch/sparc/mm/srmmu.c
6873 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6874 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6875 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6876 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6877 +
6878 +#ifdef CONFIG_PAX_PAGEEXEC
6879 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6880 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6881 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6882 +#endif
6883 +
6884 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6885 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6886
6887 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
6888 index 27fe667..36d474c 100644
6889 --- a/arch/tile/include/asm/atomic_64.h
6890 +++ b/arch/tile/include/asm/atomic_64.h
6891 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6892
6893 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6894
6895 +#define atomic64_read_unchecked(v) atomic64_read(v)
6896 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6897 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6898 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6899 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6900 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6901 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6902 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6903 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6904 +
6905 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
6906 #define smp_mb__before_atomic_dec() smp_mb()
6907 #define smp_mb__after_atomic_dec() smp_mb()
6908 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
6909 index 392e533..536b092 100644
6910 --- a/arch/tile/include/asm/cache.h
6911 +++ b/arch/tile/include/asm/cache.h
6912 @@ -15,11 +15,12 @@
6913 #ifndef _ASM_TILE_CACHE_H
6914 #define _ASM_TILE_CACHE_H
6915
6916 +#include <linux/const.h>
6917 #include <arch/chip.h>
6918
6919 /* bytes per L1 data cache line */
6920 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
6921 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6922 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6923
6924 /* bytes per L2 cache line */
6925 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
6926 diff --git a/arch/um/Makefile b/arch/um/Makefile
6927 index 28688e6..4c0aa1c 100644
6928 --- a/arch/um/Makefile
6929 +++ b/arch/um/Makefile
6930 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
6931 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
6932 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
6933
6934 +ifdef CONSTIFY_PLUGIN
6935 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6936 +endif
6937 +
6938 #This will adjust *FLAGS accordingly to the platform.
6939 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
6940
6941 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
6942 index 19e1bdd..3665b77 100644
6943 --- a/arch/um/include/asm/cache.h
6944 +++ b/arch/um/include/asm/cache.h
6945 @@ -1,6 +1,7 @@
6946 #ifndef __UM_CACHE_H
6947 #define __UM_CACHE_H
6948
6949 +#include <linux/const.h>
6950
6951 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
6952 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
6953 @@ -12,6 +13,6 @@
6954 # define L1_CACHE_SHIFT 5
6955 #endif
6956
6957 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6958 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6959
6960 #endif
6961 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
6962 index 6c03acd..a5e0215 100644
6963 --- a/arch/um/include/asm/kmap_types.h
6964 +++ b/arch/um/include/asm/kmap_types.h
6965 @@ -23,6 +23,7 @@ enum km_type {
6966 KM_IRQ1,
6967 KM_SOFTIRQ0,
6968 KM_SOFTIRQ1,
6969 + KM_CLEARPAGE,
6970 KM_TYPE_NR
6971 };
6972
6973 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
6974 index 7cfc3ce..cbd1a58 100644
6975 --- a/arch/um/include/asm/page.h
6976 +++ b/arch/um/include/asm/page.h
6977 @@ -14,6 +14,9 @@
6978 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6979 #define PAGE_MASK (~(PAGE_SIZE-1))
6980
6981 +#define ktla_ktva(addr) (addr)
6982 +#define ktva_ktla(addr) (addr)
6983 +
6984 #ifndef __ASSEMBLY__
6985
6986 struct page;
6987 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
6988 index 69f2490..2634831 100644
6989 --- a/arch/um/kernel/process.c
6990 +++ b/arch/um/kernel/process.c
6991 @@ -408,22 +408,6 @@ int singlestepping(void * t)
6992 return 2;
6993 }
6994
6995 -/*
6996 - * Only x86 and x86_64 have an arch_align_stack().
6997 - * All other arches have "#define arch_align_stack(x) (x)"
6998 - * in their asm/system.h
6999 - * As this is included in UML from asm-um/system-generic.h,
7000 - * we can use it to behave as the subarch does.
7001 - */
7002 -#ifndef arch_align_stack
7003 -unsigned long arch_align_stack(unsigned long sp)
7004 -{
7005 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7006 - sp -= get_random_int() % 8192;
7007 - return sp & ~0xf;
7008 -}
7009 -#endif
7010 -
7011 unsigned long get_wchan(struct task_struct *p)
7012 {
7013 unsigned long stack_page, sp, ip;
7014 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7015 index ad8f795..2c7eec6 100644
7016 --- a/arch/unicore32/include/asm/cache.h
7017 +++ b/arch/unicore32/include/asm/cache.h
7018 @@ -12,8 +12,10 @@
7019 #ifndef __UNICORE_CACHE_H__
7020 #define __UNICORE_CACHE_H__
7021
7022 -#define L1_CACHE_SHIFT (5)
7023 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7024 +#include <linux/const.h>
7025 +
7026 +#define L1_CACHE_SHIFT 5
7027 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7028
7029 /*
7030 * Memory returned by kmalloc() may be used for DMA, so we must make
7031 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7032 index 5bed94e..fbcf200 100644
7033 --- a/arch/x86/Kconfig
7034 +++ b/arch/x86/Kconfig
7035 @@ -226,7 +226,7 @@ config X86_HT
7036
7037 config X86_32_LAZY_GS
7038 def_bool y
7039 - depends on X86_32 && !CC_STACKPROTECTOR
7040 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7041
7042 config ARCH_HWEIGHT_CFLAGS
7043 string
7044 @@ -1058,7 +1058,7 @@ choice
7045
7046 config NOHIGHMEM
7047 bool "off"
7048 - depends on !X86_NUMAQ
7049 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7050 ---help---
7051 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7052 However, the address space of 32-bit x86 processors is only 4
7053 @@ -1095,7 +1095,7 @@ config NOHIGHMEM
7054
7055 config HIGHMEM4G
7056 bool "4GB"
7057 - depends on !X86_NUMAQ
7058 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7059 ---help---
7060 Select this if you have a 32-bit processor and between 1 and 4
7061 gigabytes of physical RAM.
7062 @@ -1149,7 +1149,7 @@ config PAGE_OFFSET
7063 hex
7064 default 0xB0000000 if VMSPLIT_3G_OPT
7065 default 0x80000000 if VMSPLIT_2G
7066 - default 0x78000000 if VMSPLIT_2G_OPT
7067 + default 0x70000000 if VMSPLIT_2G_OPT
7068 default 0x40000000 if VMSPLIT_1G
7069 default 0xC0000000
7070 depends on X86_32
7071 @@ -1539,6 +1539,7 @@ config SECCOMP
7072
7073 config CC_STACKPROTECTOR
7074 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7075 + depends on X86_64 || !PAX_MEMORY_UDEREF
7076 ---help---
7077 This option turns on the -fstack-protector GCC feature. This
7078 feature puts, at the beginning of functions, a canary value on
7079 @@ -1596,6 +1597,7 @@ config KEXEC_JUMP
7080 config PHYSICAL_START
7081 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7082 default "0x1000000"
7083 + range 0x400000 0x40000000
7084 ---help---
7085 This gives the physical address where the kernel is loaded.
7086
7087 @@ -1659,6 +1661,7 @@ config X86_NEED_RELOCS
7088 config PHYSICAL_ALIGN
7089 hex "Alignment value to which kernel should be aligned" if X86_32
7090 default "0x1000000"
7091 + range 0x400000 0x1000000 if PAX_KERNEXEC
7092 range 0x2000 0x1000000
7093 ---help---
7094 This value puts the alignment restrictions on physical address
7095 @@ -1690,9 +1693,10 @@ config HOTPLUG_CPU
7096 Say N if you want to disable CPU hotplug.
7097
7098 config COMPAT_VDSO
7099 - def_bool y
7100 + def_bool n
7101 prompt "Compat VDSO support"
7102 depends on X86_32 || IA32_EMULATION
7103 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7104 ---help---
7105 Map the 32-bit VDSO to the predictable old-style address too.
7106
7107 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7108 index 3c57033..22d44aa 100644
7109 --- a/arch/x86/Kconfig.cpu
7110 +++ b/arch/x86/Kconfig.cpu
7111 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7112
7113 config X86_F00F_BUG
7114 def_bool y
7115 - depends on M586MMX || M586TSC || M586 || M486 || M386
7116 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7117
7118 config X86_INVD_BUG
7119 def_bool y
7120 @@ -359,7 +359,7 @@ config X86_POPAD_OK
7121
7122 config X86_ALIGNMENT_16
7123 def_bool y
7124 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7125 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7126
7127 config X86_INTEL_USERCOPY
7128 def_bool y
7129 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
7130 # generates cmov.
7131 config X86_CMOV
7132 def_bool y
7133 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7134 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7135
7136 config X86_MINIMUM_CPU_FAMILY
7137 int
7138 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7139 index e46c214..7c72b55 100644
7140 --- a/arch/x86/Kconfig.debug
7141 +++ b/arch/x86/Kconfig.debug
7142 @@ -84,7 +84,7 @@ config X86_PTDUMP
7143 config DEBUG_RODATA
7144 bool "Write protect kernel read-only data structures"
7145 default y
7146 - depends on DEBUG_KERNEL
7147 + depends on DEBUG_KERNEL && BROKEN
7148 ---help---
7149 Mark the kernel read-only data as write-protected in the pagetables,
7150 in order to catch accidental (and incorrect) writes to such const
7151 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7152
7153 config DEBUG_SET_MODULE_RONX
7154 bool "Set loadable kernel module data as NX and text as RO"
7155 - depends on MODULES
7156 + depends on MODULES && BROKEN
7157 ---help---
7158 This option helps catch unintended modifications to loadable
7159 kernel module's text and read-only data. It also prevents execution
7160 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7161 index 209ba12..15140db 100644
7162 --- a/arch/x86/Makefile
7163 +++ b/arch/x86/Makefile
7164 @@ -46,6 +46,7 @@ else
7165 UTS_MACHINE := x86_64
7166 CHECKFLAGS += -D__x86_64__ -m64
7167
7168 + biarch := $(call cc-option,-m64)
7169 KBUILD_AFLAGS += -m64
7170 KBUILD_CFLAGS += -m64
7171
7172 @@ -201,3 +202,12 @@ define archhelp
7173 echo ' FDARGS="..." arguments for the booted kernel'
7174 echo ' FDINITRD=file initrd for the booted kernel'
7175 endef
7176 +
7177 +define OLD_LD
7178 +
7179 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7180 +*** Please upgrade your binutils to 2.18 or newer
7181 +endef
7182 +
7183 +archprepare:
7184 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7185 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7186 index 95365a8..52f857b 100644
7187 --- a/arch/x86/boot/Makefile
7188 +++ b/arch/x86/boot/Makefile
7189 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7190 $(call cc-option, -fno-stack-protector) \
7191 $(call cc-option, -mpreferred-stack-boundary=2)
7192 KBUILD_CFLAGS += $(call cc-option, -m32)
7193 +ifdef CONSTIFY_PLUGIN
7194 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7195 +endif
7196 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7197 GCOV_PROFILE := n
7198
7199 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7200 index 878e4b9..20537ab 100644
7201 --- a/arch/x86/boot/bitops.h
7202 +++ b/arch/x86/boot/bitops.h
7203 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7204 u8 v;
7205 const u32 *p = (const u32 *)addr;
7206
7207 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7208 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7209 return v;
7210 }
7211
7212 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7213
7214 static inline void set_bit(int nr, void *addr)
7215 {
7216 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7217 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7218 }
7219
7220 #endif /* BOOT_BITOPS_H */
7221 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7222 index c7093bd..d4247ffe0 100644
7223 --- a/arch/x86/boot/boot.h
7224 +++ b/arch/x86/boot/boot.h
7225 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7226 static inline u16 ds(void)
7227 {
7228 u16 seg;
7229 - asm("movw %%ds,%0" : "=rm" (seg));
7230 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7231 return seg;
7232 }
7233
7234 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7235 static inline int memcmp(const void *s1, const void *s2, size_t len)
7236 {
7237 u8 diff;
7238 - asm("repe; cmpsb; setnz %0"
7239 + asm volatile("repe; cmpsb; setnz %0"
7240 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7241 return diff;
7242 }
7243 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7244 index b123b9a..2cf2f23 100644
7245 --- a/arch/x86/boot/compressed/Makefile
7246 +++ b/arch/x86/boot/compressed/Makefile
7247 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7248 KBUILD_CFLAGS += $(cflags-y)
7249 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7250 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7251 +ifdef CONSTIFY_PLUGIN
7252 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7253 +endif
7254
7255 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7256 GCOV_PROFILE := n
7257 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7258 index a055993..47e126c 100644
7259 --- a/arch/x86/boot/compressed/head_32.S
7260 +++ b/arch/x86/boot/compressed/head_32.S
7261 @@ -98,7 +98,7 @@ preferred_addr:
7262 notl %eax
7263 andl %eax, %ebx
7264 #else
7265 - movl $LOAD_PHYSICAL_ADDR, %ebx
7266 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7267 #endif
7268
7269 /* Target address to relocate to for decompression */
7270 @@ -184,7 +184,7 @@ relocated:
7271 * and where it was actually loaded.
7272 */
7273 movl %ebp, %ebx
7274 - subl $LOAD_PHYSICAL_ADDR, %ebx
7275 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7276 jz 2f /* Nothing to be done if loaded at compiled addr. */
7277 /*
7278 * Process relocations.
7279 @@ -192,8 +192,7 @@ relocated:
7280
7281 1: subl $4, %edi
7282 movl (%edi), %ecx
7283 - testl %ecx, %ecx
7284 - jz 2f
7285 + jecxz 2f
7286 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7287 jmp 1b
7288 2:
7289 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7290 index 558d76c..606aa24 100644
7291 --- a/arch/x86/boot/compressed/head_64.S
7292 +++ b/arch/x86/boot/compressed/head_64.S
7293 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7294 notl %eax
7295 andl %eax, %ebx
7296 #else
7297 - movl $LOAD_PHYSICAL_ADDR, %ebx
7298 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7299 #endif
7300
7301 /* Target address to relocate to for decompression */
7302 @@ -253,7 +253,7 @@ preferred_addr:
7303 notq %rax
7304 andq %rax, %rbp
7305 #else
7306 - movq $LOAD_PHYSICAL_ADDR, %rbp
7307 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7308 #endif
7309
7310 /* Target address to relocate to for decompression */
7311 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7312 index 7116dcb..d9ae1d7 100644
7313 --- a/arch/x86/boot/compressed/misc.c
7314 +++ b/arch/x86/boot/compressed/misc.c
7315 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7316 case PT_LOAD:
7317 #ifdef CONFIG_RELOCATABLE
7318 dest = output;
7319 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7320 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7321 #else
7322 dest = (void *)(phdr->p_paddr);
7323 #endif
7324 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7325 error("Destination address too large");
7326 #endif
7327 #ifndef CONFIG_RELOCATABLE
7328 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7329 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7330 error("Wrong destination address");
7331 #endif
7332
7333 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7334 index 89bbf4e..869908e 100644
7335 --- a/arch/x86/boot/compressed/relocs.c
7336 +++ b/arch/x86/boot/compressed/relocs.c
7337 @@ -13,8 +13,11 @@
7338
7339 static void die(char *fmt, ...);
7340
7341 +#include "../../../../include/generated/autoconf.h"
7342 +
7343 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7344 static Elf32_Ehdr ehdr;
7345 +static Elf32_Phdr *phdr;
7346 static unsigned long reloc_count, reloc_idx;
7347 static unsigned long *relocs;
7348
7349 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7350 }
7351 }
7352
7353 +static void read_phdrs(FILE *fp)
7354 +{
7355 + unsigned int i;
7356 +
7357 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7358 + if (!phdr) {
7359 + die("Unable to allocate %d program headers\n",
7360 + ehdr.e_phnum);
7361 + }
7362 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7363 + die("Seek to %d failed: %s\n",
7364 + ehdr.e_phoff, strerror(errno));
7365 + }
7366 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7367 + die("Cannot read ELF program headers: %s\n",
7368 + strerror(errno));
7369 + }
7370 + for(i = 0; i < ehdr.e_phnum; i++) {
7371 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7372 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7373 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7374 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7375 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7376 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7377 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7378 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7379 + }
7380 +
7381 +}
7382 +
7383 static void read_shdrs(FILE *fp)
7384 {
7385 - int i;
7386 + unsigned int i;
7387 Elf32_Shdr shdr;
7388
7389 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7390 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7391
7392 static void read_strtabs(FILE *fp)
7393 {
7394 - int i;
7395 + unsigned int i;
7396 for (i = 0; i < ehdr.e_shnum; i++) {
7397 struct section *sec = &secs[i];
7398 if (sec->shdr.sh_type != SHT_STRTAB) {
7399 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7400
7401 static void read_symtabs(FILE *fp)
7402 {
7403 - int i,j;
7404 + unsigned int i,j;
7405 for (i = 0; i < ehdr.e_shnum; i++) {
7406 struct section *sec = &secs[i];
7407 if (sec->shdr.sh_type != SHT_SYMTAB) {
7408 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7409
7410 static void read_relocs(FILE *fp)
7411 {
7412 - int i,j;
7413 + unsigned int i,j;
7414 + uint32_t base;
7415 +
7416 for (i = 0; i < ehdr.e_shnum; i++) {
7417 struct section *sec = &secs[i];
7418 if (sec->shdr.sh_type != SHT_REL) {
7419 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7420 die("Cannot read symbol table: %s\n",
7421 strerror(errno));
7422 }
7423 + base = 0;
7424 + for (j = 0; j < ehdr.e_phnum; j++) {
7425 + if (phdr[j].p_type != PT_LOAD )
7426 + continue;
7427 + 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)
7428 + continue;
7429 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7430 + break;
7431 + }
7432 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7433 Elf32_Rel *rel = &sec->reltab[j];
7434 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7435 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7436 rel->r_info = elf32_to_cpu(rel->r_info);
7437 }
7438 }
7439 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7440
7441 static void print_absolute_symbols(void)
7442 {
7443 - int i;
7444 + unsigned int i;
7445 printf("Absolute symbols\n");
7446 printf(" Num: Value Size Type Bind Visibility Name\n");
7447 for (i = 0; i < ehdr.e_shnum; i++) {
7448 struct section *sec = &secs[i];
7449 char *sym_strtab;
7450 Elf32_Sym *sh_symtab;
7451 - int j;
7452 + unsigned int j;
7453
7454 if (sec->shdr.sh_type != SHT_SYMTAB) {
7455 continue;
7456 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7457
7458 static void print_absolute_relocs(void)
7459 {
7460 - int i, printed = 0;
7461 + unsigned int i, printed = 0;
7462
7463 for (i = 0; i < ehdr.e_shnum; i++) {
7464 struct section *sec = &secs[i];
7465 struct section *sec_applies, *sec_symtab;
7466 char *sym_strtab;
7467 Elf32_Sym *sh_symtab;
7468 - int j;
7469 + unsigned int j;
7470 if (sec->shdr.sh_type != SHT_REL) {
7471 continue;
7472 }
7473 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7474
7475 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7476 {
7477 - int i;
7478 + unsigned int i;
7479 /* Walk through the relocations */
7480 for (i = 0; i < ehdr.e_shnum; i++) {
7481 char *sym_strtab;
7482 Elf32_Sym *sh_symtab;
7483 struct section *sec_applies, *sec_symtab;
7484 - int j;
7485 + unsigned int j;
7486 struct section *sec = &secs[i];
7487
7488 if (sec->shdr.sh_type != SHT_REL) {
7489 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7490 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7491 continue;
7492 }
7493 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7494 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7495 + continue;
7496 +
7497 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7498 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7499 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7500 + continue;
7501 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7502 + continue;
7503 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7504 + continue;
7505 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7506 + continue;
7507 +#endif
7508 +
7509 switch (r_type) {
7510 case R_386_NONE:
7511 case R_386_PC32:
7512 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
7513
7514 static void emit_relocs(int as_text)
7515 {
7516 - int i;
7517 + unsigned int i;
7518 /* Count how many relocations I have and allocate space for them. */
7519 reloc_count = 0;
7520 walk_relocs(count_reloc);
7521 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7522 fname, strerror(errno));
7523 }
7524 read_ehdr(fp);
7525 + read_phdrs(fp);
7526 read_shdrs(fp);
7527 read_strtabs(fp);
7528 read_symtabs(fp);
7529 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7530 index 4d3ff03..e4972ff 100644
7531 --- a/arch/x86/boot/cpucheck.c
7532 +++ b/arch/x86/boot/cpucheck.c
7533 @@ -74,7 +74,7 @@ static int has_fpu(void)
7534 u16 fcw = -1, fsw = -1;
7535 u32 cr0;
7536
7537 - asm("movl %%cr0,%0" : "=r" (cr0));
7538 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7539 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7540 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7541 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7542 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7543 {
7544 u32 f0, f1;
7545
7546 - asm("pushfl ; "
7547 + asm volatile("pushfl ; "
7548 "pushfl ; "
7549 "popl %0 ; "
7550 "movl %0,%1 ; "
7551 @@ -115,7 +115,7 @@ static void get_flags(void)
7552 set_bit(X86_FEATURE_FPU, cpu.flags);
7553
7554 if (has_eflag(X86_EFLAGS_ID)) {
7555 - asm("cpuid"
7556 + asm volatile("cpuid"
7557 : "=a" (max_intel_level),
7558 "=b" (cpu_vendor[0]),
7559 "=d" (cpu_vendor[1]),
7560 @@ -124,7 +124,7 @@ static void get_flags(void)
7561
7562 if (max_intel_level >= 0x00000001 &&
7563 max_intel_level <= 0x0000ffff) {
7564 - asm("cpuid"
7565 + asm volatile("cpuid"
7566 : "=a" (tfms),
7567 "=c" (cpu.flags[4]),
7568 "=d" (cpu.flags[0])
7569 @@ -136,7 +136,7 @@ static void get_flags(void)
7570 cpu.model += ((tfms >> 16) & 0xf) << 4;
7571 }
7572
7573 - asm("cpuid"
7574 + asm volatile("cpuid"
7575 : "=a" (max_amd_level)
7576 : "a" (0x80000000)
7577 : "ebx", "ecx", "edx");
7578 @@ -144,7 +144,7 @@ static void get_flags(void)
7579 if (max_amd_level >= 0x80000001 &&
7580 max_amd_level <= 0x8000ffff) {
7581 u32 eax = 0x80000001;
7582 - asm("cpuid"
7583 + asm volatile("cpuid"
7584 : "+a" (eax),
7585 "=c" (cpu.flags[6]),
7586 "=d" (cpu.flags[1])
7587 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7588 u32 ecx = MSR_K7_HWCR;
7589 u32 eax, edx;
7590
7591 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7592 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7593 eax &= ~(1 << 15);
7594 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7595 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7596
7597 get_flags(); /* Make sure it really did something */
7598 err = check_flags();
7599 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7600 u32 ecx = MSR_VIA_FCR;
7601 u32 eax, edx;
7602
7603 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7604 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7605 eax |= (1<<1)|(1<<7);
7606 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7607 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7608
7609 set_bit(X86_FEATURE_CX8, cpu.flags);
7610 err = check_flags();
7611 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7612 u32 eax, edx;
7613 u32 level = 1;
7614
7615 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7616 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7617 - asm("cpuid"
7618 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7619 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7620 + asm volatile("cpuid"
7621 : "+a" (level), "=d" (cpu.flags[0])
7622 : : "ecx", "ebx");
7623 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7624 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7625
7626 err = check_flags();
7627 }
7628 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7629 index f1bbeeb..aff09cb 100644
7630 --- a/arch/x86/boot/header.S
7631 +++ b/arch/x86/boot/header.S
7632 @@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7633 # single linked list of
7634 # struct setup_data
7635
7636 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7637 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7638
7639 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7640 #define VO_INIT_SIZE (VO__end - VO__text)
7641 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7642 index db75d07..8e6d0af 100644
7643 --- a/arch/x86/boot/memory.c
7644 +++ b/arch/x86/boot/memory.c
7645 @@ -19,7 +19,7 @@
7646
7647 static int detect_memory_e820(void)
7648 {
7649 - int count = 0;
7650 + unsigned int count = 0;
7651 struct biosregs ireg, oreg;
7652 struct e820entry *desc = boot_params.e820_map;
7653 static struct e820entry buf; /* static so it is zeroed */
7654 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7655 index 11e8c6e..fdbb1ed 100644
7656 --- a/arch/x86/boot/video-vesa.c
7657 +++ b/arch/x86/boot/video-vesa.c
7658 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7659
7660 boot_params.screen_info.vesapm_seg = oreg.es;
7661 boot_params.screen_info.vesapm_off = oreg.di;
7662 + boot_params.screen_info.vesapm_size = oreg.cx;
7663 }
7664
7665 /*
7666 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7667 index 43eda28..5ab5fdb 100644
7668 --- a/arch/x86/boot/video.c
7669 +++ b/arch/x86/boot/video.c
7670 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7671 static unsigned int get_entry(void)
7672 {
7673 char entry_buf[4];
7674 - int i, len = 0;
7675 + unsigned int i, len = 0;
7676 int key;
7677 unsigned int v;
7678
7679 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7680 index 5b577d5..3c1fed4 100644
7681 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
7682 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7683 @@ -8,6 +8,8 @@
7684 * including this sentence is retained in full.
7685 */
7686
7687 +#include <asm/alternative-asm.h>
7688 +
7689 .extern crypto_ft_tab
7690 .extern crypto_it_tab
7691 .extern crypto_fl_tab
7692 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7693 je B192; \
7694 leaq 32(r9),r9;
7695
7696 +#define ret pax_force_retaddr 0, 1; ret
7697 +
7698 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7699 movq r1,r2; \
7700 movq r3,r4; \
7701 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7702 index be6d9e3..21fbbca 100644
7703 --- a/arch/x86/crypto/aesni-intel_asm.S
7704 +++ b/arch/x86/crypto/aesni-intel_asm.S
7705 @@ -31,6 +31,7 @@
7706
7707 #include <linux/linkage.h>
7708 #include <asm/inst.h>
7709 +#include <asm/alternative-asm.h>
7710
7711 #ifdef __x86_64__
7712 .data
7713 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
7714 pop %r14
7715 pop %r13
7716 pop %r12
7717 + pax_force_retaddr 0, 1
7718 ret
7719 +ENDPROC(aesni_gcm_dec)
7720
7721
7722 /*****************************************************************************
7723 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
7724 pop %r14
7725 pop %r13
7726 pop %r12
7727 + pax_force_retaddr 0, 1
7728 ret
7729 +ENDPROC(aesni_gcm_enc)
7730
7731 #endif
7732
7733 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
7734 pxor %xmm1, %xmm0
7735 movaps %xmm0, (TKEYP)
7736 add $0x10, TKEYP
7737 + pax_force_retaddr_bts
7738 ret
7739
7740 .align 4
7741 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
7742 shufps $0b01001110, %xmm2, %xmm1
7743 movaps %xmm1, 0x10(TKEYP)
7744 add $0x20, TKEYP
7745 + pax_force_retaddr_bts
7746 ret
7747
7748 .align 4
7749 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
7750
7751 movaps %xmm0, (TKEYP)
7752 add $0x10, TKEYP
7753 + pax_force_retaddr_bts
7754 ret
7755
7756 .align 4
7757 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
7758 pxor %xmm1, %xmm2
7759 movaps %xmm2, (TKEYP)
7760 add $0x10, TKEYP
7761 + pax_force_retaddr_bts
7762 ret
7763
7764 /*
7765 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
7766 #ifndef __x86_64__
7767 popl KEYP
7768 #endif
7769 + pax_force_retaddr 0, 1
7770 ret
7771 +ENDPROC(aesni_set_key)
7772
7773 /*
7774 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7775 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
7776 popl KLEN
7777 popl KEYP
7778 #endif
7779 + pax_force_retaddr 0, 1
7780 ret
7781 +ENDPROC(aesni_enc)
7782
7783 /*
7784 * _aesni_enc1: internal ABI
7785 @@ -1959,6 +1972,7 @@ _aesni_enc1:
7786 AESENC KEY STATE
7787 movaps 0x70(TKEYP), KEY
7788 AESENCLAST KEY STATE
7789 + pax_force_retaddr_bts
7790 ret
7791
7792 /*
7793 @@ -2067,6 +2081,7 @@ _aesni_enc4:
7794 AESENCLAST KEY STATE2
7795 AESENCLAST KEY STATE3
7796 AESENCLAST KEY STATE4
7797 + pax_force_retaddr_bts
7798 ret
7799
7800 /*
7801 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
7802 popl KLEN
7803 popl KEYP
7804 #endif
7805 + pax_force_retaddr 0, 1
7806 ret
7807 +ENDPROC(aesni_dec)
7808
7809 /*
7810 * _aesni_dec1: internal ABI
7811 @@ -2146,6 +2163,7 @@ _aesni_dec1:
7812 AESDEC KEY STATE
7813 movaps 0x70(TKEYP), KEY
7814 AESDECLAST KEY STATE
7815 + pax_force_retaddr_bts
7816 ret
7817
7818 /*
7819 @@ -2254,6 +2272,7 @@ _aesni_dec4:
7820 AESDECLAST KEY STATE2
7821 AESDECLAST KEY STATE3
7822 AESDECLAST KEY STATE4
7823 + pax_force_retaddr_bts
7824 ret
7825
7826 /*
7827 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
7828 popl KEYP
7829 popl LEN
7830 #endif
7831 + pax_force_retaddr 0, 1
7832 ret
7833 +ENDPROC(aesni_ecb_enc)
7834
7835 /*
7836 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7837 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
7838 popl KEYP
7839 popl LEN
7840 #endif
7841 + pax_force_retaddr 0, 1
7842 ret
7843 +ENDPROC(aesni_ecb_dec)
7844
7845 /*
7846 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7847 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
7848 popl LEN
7849 popl IVP
7850 #endif
7851 + pax_force_retaddr 0, 1
7852 ret
7853 +ENDPROC(aesni_cbc_enc)
7854
7855 /*
7856 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7857 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
7858 popl LEN
7859 popl IVP
7860 #endif
7861 + pax_force_retaddr 0, 1
7862 ret
7863 +ENDPROC(aesni_cbc_dec)
7864
7865 #ifdef __x86_64__
7866 .align 16
7867 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
7868 mov $1, TCTR_LOW
7869 MOVQ_R64_XMM TCTR_LOW INC
7870 MOVQ_R64_XMM CTR TCTR_LOW
7871 + pax_force_retaddr_bts
7872 ret
7873
7874 /*
7875 @@ -2552,6 +2580,7 @@ _aesni_inc:
7876 .Linc_low:
7877 movaps CTR, IV
7878 PSHUFB_XMM BSWAP_MASK IV
7879 + pax_force_retaddr_bts
7880 ret
7881
7882 /*
7883 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
7884 .Lctr_enc_ret:
7885 movups IV, (IVP)
7886 .Lctr_enc_just_ret:
7887 + pax_force_retaddr 0, 1
7888 ret
7889 +ENDPROC(aesni_ctr_enc)
7890 #endif
7891 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7892 index 391d245..67f35c2 100644
7893 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
7894 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7895 @@ -20,6 +20,8 @@
7896 *
7897 */
7898
7899 +#include <asm/alternative-asm.h>
7900 +
7901 .file "blowfish-x86_64-asm.S"
7902 .text
7903
7904 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
7905 jnz __enc_xor;
7906
7907 write_block();
7908 + pax_force_retaddr 0, 1
7909 ret;
7910 __enc_xor:
7911 xor_block();
7912 + pax_force_retaddr 0, 1
7913 ret;
7914
7915 .align 8
7916 @@ -188,6 +192,7 @@ blowfish_dec_blk:
7917
7918 movq %r11, %rbp;
7919
7920 + pax_force_retaddr 0, 1
7921 ret;
7922
7923 /**********************************************************************
7924 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
7925
7926 popq %rbx;
7927 popq %rbp;
7928 + pax_force_retaddr 0, 1
7929 ret;
7930
7931 __enc_xor4:
7932 @@ -349,6 +355,7 @@ __enc_xor4:
7933
7934 popq %rbx;
7935 popq %rbp;
7936 + pax_force_retaddr 0, 1
7937 ret;
7938
7939 .align 8
7940 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
7941 popq %rbx;
7942 popq %rbp;
7943
7944 + pax_force_retaddr 0, 1
7945 ret;
7946
7947 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7948 index 6214a9b..1f4fc9a 100644
7949 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
7950 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7951 @@ -1,3 +1,5 @@
7952 +#include <asm/alternative-asm.h>
7953 +
7954 # enter ECRYPT_encrypt_bytes
7955 .text
7956 .p2align 5
7957 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
7958 add %r11,%rsp
7959 mov %rdi,%rax
7960 mov %rsi,%rdx
7961 + pax_force_retaddr 0, 1
7962 ret
7963 # bytesatleast65:
7964 ._bytesatleast65:
7965 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
7966 add %r11,%rsp
7967 mov %rdi,%rax
7968 mov %rsi,%rdx
7969 + pax_force_retaddr
7970 ret
7971 # enter ECRYPT_ivsetup
7972 .text
7973 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
7974 add %r11,%rsp
7975 mov %rdi,%rax
7976 mov %rsi,%rdx
7977 + pax_force_retaddr
7978 ret
7979 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
7980 index 7f24a15..9cd3ffe 100644
7981 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
7982 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
7983 @@ -24,6 +24,8 @@
7984 *
7985 */
7986
7987 +#include <asm/alternative-asm.h>
7988 +
7989 .file "serpent-sse2-x86_64-asm_64.S"
7990 .text
7991
7992 @@ -695,12 +697,14 @@ __serpent_enc_blk_8way:
7993 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
7994 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
7995
7996 + pax_force_retaddr
7997 ret;
7998
7999 __enc_xor8:
8000 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8001 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8002
8003 + pax_force_retaddr
8004 ret;
8005
8006 .align 8
8007 @@ -758,4 +762,5 @@ serpent_dec_blk_8way:
8008 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8009 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8010
8011 + pax_force_retaddr
8012 ret;
8013 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8014 index b2c2f57..8470cab 100644
8015 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8016 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8017 @@ -28,6 +28,8 @@
8018 * (at your option) any later version.
8019 */
8020
8021 +#include <asm/alternative-asm.h>
8022 +
8023 #define CTX %rdi // arg1
8024 #define BUF %rsi // arg2
8025 #define CNT %rdx // arg3
8026 @@ -104,6 +106,7 @@
8027 pop %r12
8028 pop %rbp
8029 pop %rbx
8030 + pax_force_retaddr 0, 1
8031 ret
8032
8033 .size \name, .-\name
8034 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8035 index 5b012a2..36d5364 100644
8036 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8037 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8038 @@ -20,6 +20,8 @@
8039 *
8040 */
8041
8042 +#include <asm/alternative-asm.h>
8043 +
8044 .file "twofish-x86_64-asm-3way.S"
8045 .text
8046
8047 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8048 popq %r13;
8049 popq %r14;
8050 popq %r15;
8051 + pax_force_retaddr 0, 1
8052 ret;
8053
8054 __enc_xor3:
8055 @@ -271,6 +274,7 @@ __enc_xor3:
8056 popq %r13;
8057 popq %r14;
8058 popq %r15;
8059 + pax_force_retaddr 0, 1
8060 ret;
8061
8062 .global twofish_dec_blk_3way
8063 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8064 popq %r13;
8065 popq %r14;
8066 popq %r15;
8067 + pax_force_retaddr 0, 1
8068 ret;
8069
8070 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8071 index 7bcf3fc..f53832f 100644
8072 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8073 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8074 @@ -21,6 +21,7 @@
8075 .text
8076
8077 #include <asm/asm-offsets.h>
8078 +#include <asm/alternative-asm.h>
8079
8080 #define a_offset 0
8081 #define b_offset 4
8082 @@ -268,6 +269,7 @@ twofish_enc_blk:
8083
8084 popq R1
8085 movq $1,%rax
8086 + pax_force_retaddr 0, 1
8087 ret
8088
8089 twofish_dec_blk:
8090 @@ -319,4 +321,5 @@ twofish_dec_blk:
8091
8092 popq R1
8093 movq $1,%rax
8094 + pax_force_retaddr 0, 1
8095 ret
8096 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8097 index 39e4909..887aa7e 100644
8098 --- a/arch/x86/ia32/ia32_aout.c
8099 +++ b/arch/x86/ia32/ia32_aout.c
8100 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8101 unsigned long dump_start, dump_size;
8102 struct user32 dump;
8103
8104 + memset(&dump, 0, sizeof(dump));
8105 +
8106 fs = get_fs();
8107 set_fs(KERNEL_DS);
8108 has_dumped = 1;
8109 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8110 index 6557769..ef6ae89 100644
8111 --- a/arch/x86/ia32/ia32_signal.c
8112 +++ b/arch/x86/ia32/ia32_signal.c
8113 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8114 }
8115 seg = get_fs();
8116 set_fs(KERNEL_DS);
8117 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8118 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8119 set_fs(seg);
8120 if (ret >= 0 && uoss_ptr) {
8121 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8122 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8123 */
8124 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8125 size_t frame_size,
8126 - void **fpstate)
8127 + void __user **fpstate)
8128 {
8129 unsigned long sp;
8130
8131 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8132
8133 if (used_math()) {
8134 sp = sp - sig_xstate_ia32_size;
8135 - *fpstate = (struct _fpstate_ia32 *) sp;
8136 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8137 if (save_i387_xstate_ia32(*fpstate) < 0)
8138 return (void __user *) -1L;
8139 }
8140 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8141 sp -= frame_size;
8142 /* Align the stack pointer according to the i386 ABI,
8143 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8144 - sp = ((sp + 4) & -16ul) - 4;
8145 + sp = ((sp - 12) & -16ul) - 4;
8146 return (void __user *) sp;
8147 }
8148
8149 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8150 * These are actually not used anymore, but left because some
8151 * gdb versions depend on them as a marker.
8152 */
8153 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8154 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8155 } put_user_catch(err);
8156
8157 if (err)
8158 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8159 0xb8,
8160 __NR_ia32_rt_sigreturn,
8161 0x80cd,
8162 - 0,
8163 + 0
8164 };
8165
8166 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8167 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8168
8169 if (ka->sa.sa_flags & SA_RESTORER)
8170 restorer = ka->sa.sa_restorer;
8171 + else if (current->mm->context.vdso)
8172 + /* Return stub is in 32bit vsyscall page */
8173 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8174 else
8175 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8176 - rt_sigreturn);
8177 + restorer = &frame->retcode;
8178 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8179
8180 /*
8181 * Not actually used anymore, but left because some gdb
8182 * versions need it.
8183 */
8184 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8185 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8186 } put_user_catch(err);
8187
8188 if (err)
8189 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8190 index e3e7340..05ed805 100644
8191 --- a/arch/x86/ia32/ia32entry.S
8192 +++ b/arch/x86/ia32/ia32entry.S
8193 @@ -13,8 +13,10 @@
8194 #include <asm/thread_info.h>
8195 #include <asm/segment.h>
8196 #include <asm/irqflags.h>
8197 +#include <asm/pgtable.h>
8198 #include <linux/linkage.h>
8199 #include <linux/err.h>
8200 +#include <asm/alternative-asm.h>
8201
8202 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8203 #include <linux/elf-em.h>
8204 @@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8205 ENDPROC(native_irq_enable_sysexit)
8206 #endif
8207
8208 + .macro pax_enter_kernel_user
8209 + pax_set_fptr_mask
8210 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8211 + call pax_enter_kernel_user
8212 +#endif
8213 + .endm
8214 +
8215 + .macro pax_exit_kernel_user
8216 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8217 + call pax_exit_kernel_user
8218 +#endif
8219 +#ifdef CONFIG_PAX_RANDKSTACK
8220 + pushq %rax
8221 + pushq %r11
8222 + call pax_randomize_kstack
8223 + popq %r11
8224 + popq %rax
8225 +#endif
8226 + .endm
8227 +
8228 +.macro pax_erase_kstack
8229 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8230 + call pax_erase_kstack
8231 +#endif
8232 +.endm
8233 +
8234 /*
8235 * 32bit SYSENTER instruction entry.
8236 *
8237 @@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8238 CFI_REGISTER rsp,rbp
8239 SWAPGS_UNSAFE_STACK
8240 movq PER_CPU_VAR(kernel_stack), %rsp
8241 - addq $(KERNEL_STACK_OFFSET),%rsp
8242 - /*
8243 - * No need to follow this irqs on/off section: the syscall
8244 - * disabled irqs, here we enable it straight after entry:
8245 - */
8246 - ENABLE_INTERRUPTS(CLBR_NONE)
8247 movl %ebp,%ebp /* zero extension */
8248 pushq_cfi $__USER32_DS
8249 /*CFI_REL_OFFSET ss,0*/
8250 @@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8251 CFI_REL_OFFSET rsp,0
8252 pushfq_cfi
8253 /*CFI_REL_OFFSET rflags,0*/
8254 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8255 - CFI_REGISTER rip,r10
8256 + orl $X86_EFLAGS_IF,(%rsp)
8257 + GET_THREAD_INFO(%r11)
8258 + movl TI_sysenter_return(%r11), %r11d
8259 + CFI_REGISTER rip,r11
8260 pushq_cfi $__USER32_CS
8261 /*CFI_REL_OFFSET cs,0*/
8262 movl %eax, %eax
8263 - pushq_cfi %r10
8264 + pushq_cfi %r11
8265 CFI_REL_OFFSET rip,0
8266 pushq_cfi %rax
8267 cld
8268 SAVE_ARGS 0,1,0
8269 + pax_enter_kernel_user
8270 + /*
8271 + * No need to follow this irqs on/off section: the syscall
8272 + * disabled irqs, here we enable it straight after entry:
8273 + */
8274 + ENABLE_INTERRUPTS(CLBR_NONE)
8275 /* no need to do an access_ok check here because rbp has been
8276 32bit zero extended */
8277 +
8278 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8279 + mov $PAX_USER_SHADOW_BASE,%r11
8280 + add %r11,%rbp
8281 +#endif
8282 +
8283 1: movl (%rbp),%ebp
8284 .section __ex_table,"a"
8285 .quad 1b,ia32_badarg
8286 .previous
8287 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8288 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8289 + GET_THREAD_INFO(%r11)
8290 + orl $TS_COMPAT,TI_status(%r11)
8291 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8292 CFI_REMEMBER_STATE
8293 jnz sysenter_tracesys
8294 cmpq $(IA32_NR_syscalls-1),%rax
8295 @@ -160,12 +197,15 @@ sysenter_do_call:
8296 sysenter_dispatch:
8297 call *ia32_sys_call_table(,%rax,8)
8298 movq %rax,RAX-ARGOFFSET(%rsp)
8299 + GET_THREAD_INFO(%r11)
8300 DISABLE_INTERRUPTS(CLBR_NONE)
8301 TRACE_IRQS_OFF
8302 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8303 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8304 jnz sysexit_audit
8305 sysexit_from_sys_call:
8306 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8307 + pax_exit_kernel_user
8308 + pax_erase_kstack
8309 + andl $~TS_COMPAT,TI_status(%r11)
8310 /* clear IF, that popfq doesn't enable interrupts early */
8311 andl $~0x200,EFLAGS-R11(%rsp)
8312 movl RIP-R11(%rsp),%edx /* User %eip */
8313 @@ -191,6 +231,9 @@ sysexit_from_sys_call:
8314 movl %eax,%esi /* 2nd arg: syscall number */
8315 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8316 call __audit_syscall_entry
8317 +
8318 + pax_erase_kstack
8319 +
8320 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8321 cmpq $(IA32_NR_syscalls-1),%rax
8322 ja ia32_badsys
8323 @@ -202,7 +245,7 @@ sysexit_from_sys_call:
8324 .endm
8325
8326 .macro auditsys_exit exit
8327 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8328 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8329 jnz ia32_ret_from_sys_call
8330 TRACE_IRQS_ON
8331 sti
8332 @@ -213,11 +256,12 @@ sysexit_from_sys_call:
8333 1: setbe %al /* 1 if error, 0 if not */
8334 movzbl %al,%edi /* zero-extend that into %edi */
8335 call __audit_syscall_exit
8336 + GET_THREAD_INFO(%r11)
8337 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8338 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8339 cli
8340 TRACE_IRQS_OFF
8341 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8342 + testl %edi,TI_flags(%r11)
8343 jz \exit
8344 CLEAR_RREGS -ARGOFFSET
8345 jmp int_with_check
8346 @@ -235,7 +279,7 @@ sysexit_audit:
8347
8348 sysenter_tracesys:
8349 #ifdef CONFIG_AUDITSYSCALL
8350 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8351 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8352 jz sysenter_auditsys
8353 #endif
8354 SAVE_REST
8355 @@ -243,6 +287,9 @@ sysenter_tracesys:
8356 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8357 movq %rsp,%rdi /* &pt_regs -> arg1 */
8358 call syscall_trace_enter
8359 +
8360 + pax_erase_kstack
8361 +
8362 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8363 RESTORE_REST
8364 cmpq $(IA32_NR_syscalls-1),%rax
8365 @@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8366 ENTRY(ia32_cstar_target)
8367 CFI_STARTPROC32 simple
8368 CFI_SIGNAL_FRAME
8369 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8370 + CFI_DEF_CFA rsp,0
8371 CFI_REGISTER rip,rcx
8372 /*CFI_REGISTER rflags,r11*/
8373 SWAPGS_UNSAFE_STACK
8374 movl %esp,%r8d
8375 CFI_REGISTER rsp,r8
8376 movq PER_CPU_VAR(kernel_stack),%rsp
8377 + SAVE_ARGS 8*6,0,0
8378 + pax_enter_kernel_user
8379 /*
8380 * No need to follow this irqs on/off section: the syscall
8381 * disabled irqs and here we enable it straight after entry:
8382 */
8383 ENABLE_INTERRUPTS(CLBR_NONE)
8384 - SAVE_ARGS 8,0,0
8385 movl %eax,%eax /* zero extension */
8386 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8387 movq %rcx,RIP-ARGOFFSET(%rsp)
8388 @@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8389 /* no need to do an access_ok check here because r8 has been
8390 32bit zero extended */
8391 /* hardware stack frame is complete now */
8392 +
8393 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8394 + mov $PAX_USER_SHADOW_BASE,%r11
8395 + add %r11,%r8
8396 +#endif
8397 +
8398 1: movl (%r8),%r9d
8399 .section __ex_table,"a"
8400 .quad 1b,ia32_badarg
8401 .previous
8402 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8403 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8404 + GET_THREAD_INFO(%r11)
8405 + orl $TS_COMPAT,TI_status(%r11)
8406 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8407 CFI_REMEMBER_STATE
8408 jnz cstar_tracesys
8409 cmpq $IA32_NR_syscalls-1,%rax
8410 @@ -317,12 +372,15 @@ cstar_do_call:
8411 cstar_dispatch:
8412 call *ia32_sys_call_table(,%rax,8)
8413 movq %rax,RAX-ARGOFFSET(%rsp)
8414 + GET_THREAD_INFO(%r11)
8415 DISABLE_INTERRUPTS(CLBR_NONE)
8416 TRACE_IRQS_OFF
8417 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8418 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8419 jnz sysretl_audit
8420 sysretl_from_sys_call:
8421 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8422 + pax_exit_kernel_user
8423 + pax_erase_kstack
8424 + andl $~TS_COMPAT,TI_status(%r11)
8425 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8426 movl RIP-ARGOFFSET(%rsp),%ecx
8427 CFI_REGISTER rip,rcx
8428 @@ -350,7 +408,7 @@ sysretl_audit:
8429
8430 cstar_tracesys:
8431 #ifdef CONFIG_AUDITSYSCALL
8432 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8433 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8434 jz cstar_auditsys
8435 #endif
8436 xchgl %r9d,%ebp
8437 @@ -359,6 +417,9 @@ cstar_tracesys:
8438 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8439 movq %rsp,%rdi /* &pt_regs -> arg1 */
8440 call syscall_trace_enter
8441 +
8442 + pax_erase_kstack
8443 +
8444 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8445 RESTORE_REST
8446 xchgl %ebp,%r9d
8447 @@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8448 CFI_REL_OFFSET rip,RIP-RIP
8449 PARAVIRT_ADJUST_EXCEPTION_FRAME
8450 SWAPGS
8451 - /*
8452 - * No need to follow this irqs on/off section: the syscall
8453 - * disabled irqs and here we enable it straight after entry:
8454 - */
8455 - ENABLE_INTERRUPTS(CLBR_NONE)
8456 movl %eax,%eax
8457 pushq_cfi %rax
8458 cld
8459 /* note the registers are not zero extended to the sf.
8460 this could be a problem. */
8461 SAVE_ARGS 0,1,0
8462 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8463 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8464 + pax_enter_kernel_user
8465 + /*
8466 + * No need to follow this irqs on/off section: the syscall
8467 + * disabled irqs and here we enable it straight after entry:
8468 + */
8469 + ENABLE_INTERRUPTS(CLBR_NONE)
8470 + GET_THREAD_INFO(%r11)
8471 + orl $TS_COMPAT,TI_status(%r11)
8472 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8473 jnz ia32_tracesys
8474 cmpq $(IA32_NR_syscalls-1),%rax
8475 ja ia32_badsys
8476 @@ -435,6 +498,9 @@ ia32_tracesys:
8477 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8478 movq %rsp,%rdi /* &pt_regs -> arg1 */
8479 call syscall_trace_enter
8480 +
8481 + pax_erase_kstack
8482 +
8483 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8484 RESTORE_REST
8485 cmpq $(IA32_NR_syscalls-1),%rax
8486 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8487 index f6f5c53..b358b28 100644
8488 --- a/arch/x86/ia32/sys_ia32.c
8489 +++ b/arch/x86/ia32/sys_ia32.c
8490 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8491 */
8492 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8493 {
8494 - typeof(ubuf->st_uid) uid = 0;
8495 - typeof(ubuf->st_gid) gid = 0;
8496 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8497 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8498 SET_UID(uid, stat->uid);
8499 SET_GID(gid, stat->gid);
8500 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8501 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8502 }
8503 set_fs(KERNEL_DS);
8504 ret = sys_rt_sigprocmask(how,
8505 - set ? (sigset_t __user *)&s : NULL,
8506 - oset ? (sigset_t __user *)&s : NULL,
8507 + set ? (sigset_t __force_user *)&s : NULL,
8508 + oset ? (sigset_t __force_user *)&s : NULL,
8509 sigsetsize);
8510 set_fs(old_fs);
8511 if (ret)
8512 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8513 return alarm_setitimer(seconds);
8514 }
8515
8516 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8517 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8518 int options)
8519 {
8520 return compat_sys_wait4(pid, stat_addr, options, NULL);
8521 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8522 mm_segment_t old_fs = get_fs();
8523
8524 set_fs(KERNEL_DS);
8525 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8526 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8527 set_fs(old_fs);
8528 if (put_compat_timespec(&t, interval))
8529 return -EFAULT;
8530 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8531 mm_segment_t old_fs = get_fs();
8532
8533 set_fs(KERNEL_DS);
8534 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8535 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8536 set_fs(old_fs);
8537 if (!ret) {
8538 switch (_NSIG_WORDS) {
8539 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8540 if (copy_siginfo_from_user32(&info, uinfo))
8541 return -EFAULT;
8542 set_fs(KERNEL_DS);
8543 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8544 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8545 set_fs(old_fs);
8546 return ret;
8547 }
8548 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8549 return -EFAULT;
8550
8551 set_fs(KERNEL_DS);
8552 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8553 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8554 count);
8555 set_fs(old_fs);
8556
8557 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8558 index 952bd01..7692c6f 100644
8559 --- a/arch/x86/include/asm/alternative-asm.h
8560 +++ b/arch/x86/include/asm/alternative-asm.h
8561 @@ -15,6 +15,45 @@
8562 .endm
8563 #endif
8564
8565 +#ifdef KERNEXEC_PLUGIN
8566 + .macro pax_force_retaddr_bts rip=0
8567 + btsq $63,\rip(%rsp)
8568 + .endm
8569 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8570 + .macro pax_force_retaddr rip=0, reload=0
8571 + btsq $63,\rip(%rsp)
8572 + .endm
8573 + .macro pax_force_fptr ptr
8574 + btsq $63,\ptr
8575 + .endm
8576 + .macro pax_set_fptr_mask
8577 + .endm
8578 +#endif
8579 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8580 + .macro pax_force_retaddr rip=0, reload=0
8581 + .if \reload
8582 + pax_set_fptr_mask
8583 + .endif
8584 + orq %r10,\rip(%rsp)
8585 + .endm
8586 + .macro pax_force_fptr ptr
8587 + orq %r10,\ptr
8588 + .endm
8589 + .macro pax_set_fptr_mask
8590 + movabs $0x8000000000000000,%r10
8591 + .endm
8592 +#endif
8593 +#else
8594 + .macro pax_force_retaddr rip=0, reload=0
8595 + .endm
8596 + .macro pax_force_fptr ptr
8597 + .endm
8598 + .macro pax_force_retaddr_bts rip=0
8599 + .endm
8600 + .macro pax_set_fptr_mask
8601 + .endm
8602 +#endif
8603 +
8604 .macro altinstruction_entry orig alt feature orig_len alt_len
8605 .long \orig - .
8606 .long \alt - .
8607 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8608 index 37ad100..7d47faa 100644
8609 --- a/arch/x86/include/asm/alternative.h
8610 +++ b/arch/x86/include/asm/alternative.h
8611 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
8612 ".section .discard,\"aw\",@progbits\n" \
8613 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8614 ".previous\n" \
8615 - ".section .altinstr_replacement, \"ax\"\n" \
8616 + ".section .altinstr_replacement, \"a\"\n" \
8617 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8618 ".previous"
8619
8620 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8621 index 3ab9bdd..238033e 100644
8622 --- a/arch/x86/include/asm/apic.h
8623 +++ b/arch/x86/include/asm/apic.h
8624 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
8625
8626 #ifdef CONFIG_X86_LOCAL_APIC
8627
8628 -extern unsigned int apic_verbosity;
8629 +extern int apic_verbosity;
8630 extern int local_apic_timer_c2_ok;
8631
8632 extern int disable_apic;
8633 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8634 index 20370c6..a2eb9b0 100644
8635 --- a/arch/x86/include/asm/apm.h
8636 +++ b/arch/x86/include/asm/apm.h
8637 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8638 __asm__ __volatile__(APM_DO_ZERO_SEGS
8639 "pushl %%edi\n\t"
8640 "pushl %%ebp\n\t"
8641 - "lcall *%%cs:apm_bios_entry\n\t"
8642 + "lcall *%%ss:apm_bios_entry\n\t"
8643 "setc %%al\n\t"
8644 "popl %%ebp\n\t"
8645 "popl %%edi\n\t"
8646 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8647 __asm__ __volatile__(APM_DO_ZERO_SEGS
8648 "pushl %%edi\n\t"
8649 "pushl %%ebp\n\t"
8650 - "lcall *%%cs:apm_bios_entry\n\t"
8651 + "lcall *%%ss:apm_bios_entry\n\t"
8652 "setc %%bl\n\t"
8653 "popl %%ebp\n\t"
8654 "popl %%edi\n\t"
8655 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
8656 index 58cb6d4..ca9010d 100644
8657 --- a/arch/x86/include/asm/atomic.h
8658 +++ b/arch/x86/include/asm/atomic.h
8659 @@ -22,7 +22,18 @@
8660 */
8661 static inline int atomic_read(const atomic_t *v)
8662 {
8663 - return (*(volatile int *)&(v)->counter);
8664 + return (*(volatile const int *)&(v)->counter);
8665 +}
8666 +
8667 +/**
8668 + * atomic_read_unchecked - read atomic variable
8669 + * @v: pointer of type atomic_unchecked_t
8670 + *
8671 + * Atomically reads the value of @v.
8672 + */
8673 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8674 +{
8675 + return (*(volatile const int *)&(v)->counter);
8676 }
8677
8678 /**
8679 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
8680 }
8681
8682 /**
8683 + * atomic_set_unchecked - set atomic variable
8684 + * @v: pointer of type atomic_unchecked_t
8685 + * @i: required value
8686 + *
8687 + * Atomically sets the value of @v to @i.
8688 + */
8689 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8690 +{
8691 + v->counter = i;
8692 +}
8693 +
8694 +/**
8695 * atomic_add - add integer to atomic variable
8696 * @i: integer value to add
8697 * @v: pointer of type atomic_t
8698 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
8699 */
8700 static inline void atomic_add(int i, atomic_t *v)
8701 {
8702 - asm volatile(LOCK_PREFIX "addl %1,%0"
8703 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8704 +
8705 +#ifdef CONFIG_PAX_REFCOUNT
8706 + "jno 0f\n"
8707 + LOCK_PREFIX "subl %1,%0\n"
8708 + "int $4\n0:\n"
8709 + _ASM_EXTABLE(0b, 0b)
8710 +#endif
8711 +
8712 + : "+m" (v->counter)
8713 + : "ir" (i));
8714 +}
8715 +
8716 +/**
8717 + * atomic_add_unchecked - add integer to atomic variable
8718 + * @i: integer value to add
8719 + * @v: pointer of type atomic_unchecked_t
8720 + *
8721 + * Atomically adds @i to @v.
8722 + */
8723 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8724 +{
8725 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8726 : "+m" (v->counter)
8727 : "ir" (i));
8728 }
8729 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
8730 */
8731 static inline void atomic_sub(int i, atomic_t *v)
8732 {
8733 - asm volatile(LOCK_PREFIX "subl %1,%0"
8734 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8735 +
8736 +#ifdef CONFIG_PAX_REFCOUNT
8737 + "jno 0f\n"
8738 + LOCK_PREFIX "addl %1,%0\n"
8739 + "int $4\n0:\n"
8740 + _ASM_EXTABLE(0b, 0b)
8741 +#endif
8742 +
8743 + : "+m" (v->counter)
8744 + : "ir" (i));
8745 +}
8746 +
8747 +/**
8748 + * atomic_sub_unchecked - subtract integer from atomic variable
8749 + * @i: integer value to subtract
8750 + * @v: pointer of type atomic_unchecked_t
8751 + *
8752 + * Atomically subtracts @i from @v.
8753 + */
8754 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8755 +{
8756 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8757 : "+m" (v->counter)
8758 : "ir" (i));
8759 }
8760 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8761 {
8762 unsigned char c;
8763
8764 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8765 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8766 +
8767 +#ifdef CONFIG_PAX_REFCOUNT
8768 + "jno 0f\n"
8769 + LOCK_PREFIX "addl %2,%0\n"
8770 + "int $4\n0:\n"
8771 + _ASM_EXTABLE(0b, 0b)
8772 +#endif
8773 +
8774 + "sete %1\n"
8775 : "+m" (v->counter), "=qm" (c)
8776 : "ir" (i) : "memory");
8777 return c;
8778 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8779 */
8780 static inline void atomic_inc(atomic_t *v)
8781 {
8782 - asm volatile(LOCK_PREFIX "incl %0"
8783 + asm volatile(LOCK_PREFIX "incl %0\n"
8784 +
8785 +#ifdef CONFIG_PAX_REFCOUNT
8786 + "jno 0f\n"
8787 + LOCK_PREFIX "decl %0\n"
8788 + "int $4\n0:\n"
8789 + _ASM_EXTABLE(0b, 0b)
8790 +#endif
8791 +
8792 + : "+m" (v->counter));
8793 +}
8794 +
8795 +/**
8796 + * atomic_inc_unchecked - increment atomic variable
8797 + * @v: pointer of type atomic_unchecked_t
8798 + *
8799 + * Atomically increments @v by 1.
8800 + */
8801 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8802 +{
8803 + asm volatile(LOCK_PREFIX "incl %0\n"
8804 : "+m" (v->counter));
8805 }
8806
8807 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
8808 */
8809 static inline void atomic_dec(atomic_t *v)
8810 {
8811 - asm volatile(LOCK_PREFIX "decl %0"
8812 + asm volatile(LOCK_PREFIX "decl %0\n"
8813 +
8814 +#ifdef CONFIG_PAX_REFCOUNT
8815 + "jno 0f\n"
8816 + LOCK_PREFIX "incl %0\n"
8817 + "int $4\n0:\n"
8818 + _ASM_EXTABLE(0b, 0b)
8819 +#endif
8820 +
8821 + : "+m" (v->counter));
8822 +}
8823 +
8824 +/**
8825 + * atomic_dec_unchecked - decrement atomic variable
8826 + * @v: pointer of type atomic_unchecked_t
8827 + *
8828 + * Atomically decrements @v by 1.
8829 + */
8830 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8831 +{
8832 + asm volatile(LOCK_PREFIX "decl %0\n"
8833 : "+m" (v->counter));
8834 }
8835
8836 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8837 {
8838 unsigned char c;
8839
8840 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8841 + asm volatile(LOCK_PREFIX "decl %0\n"
8842 +
8843 +#ifdef CONFIG_PAX_REFCOUNT
8844 + "jno 0f\n"
8845 + LOCK_PREFIX "incl %0\n"
8846 + "int $4\n0:\n"
8847 + _ASM_EXTABLE(0b, 0b)
8848 +#endif
8849 +
8850 + "sete %1\n"
8851 : "+m" (v->counter), "=qm" (c)
8852 : : "memory");
8853 return c != 0;
8854 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8855 {
8856 unsigned char c;
8857
8858 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8859 + asm volatile(LOCK_PREFIX "incl %0\n"
8860 +
8861 +#ifdef CONFIG_PAX_REFCOUNT
8862 + "jno 0f\n"
8863 + LOCK_PREFIX "decl %0\n"
8864 + "int $4\n0:\n"
8865 + _ASM_EXTABLE(0b, 0b)
8866 +#endif
8867 +
8868 + "sete %1\n"
8869 + : "+m" (v->counter), "=qm" (c)
8870 + : : "memory");
8871 + return c != 0;
8872 +}
8873 +
8874 +/**
8875 + * atomic_inc_and_test_unchecked - increment and test
8876 + * @v: pointer of type atomic_unchecked_t
8877 + *
8878 + * Atomically increments @v by 1
8879 + * and returns true if the result is zero, or false for all
8880 + * other cases.
8881 + */
8882 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8883 +{
8884 + unsigned char c;
8885 +
8886 + asm volatile(LOCK_PREFIX "incl %0\n"
8887 + "sete %1\n"
8888 : "+m" (v->counter), "=qm" (c)
8889 : : "memory");
8890 return c != 0;
8891 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8892 {
8893 unsigned char c;
8894
8895 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8896 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8897 +
8898 +#ifdef CONFIG_PAX_REFCOUNT
8899 + "jno 0f\n"
8900 + LOCK_PREFIX "subl %2,%0\n"
8901 + "int $4\n0:\n"
8902 + _ASM_EXTABLE(0b, 0b)
8903 +#endif
8904 +
8905 + "sets %1\n"
8906 : "+m" (v->counter), "=qm" (c)
8907 : "ir" (i) : "memory");
8908 return c;
8909 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
8910 goto no_xadd;
8911 #endif
8912 /* Modern 486+ processor */
8913 - return i + xadd(&v->counter, i);
8914 + return i + xadd_check_overflow(&v->counter, i);
8915
8916 #ifdef CONFIG_M386
8917 no_xadd: /* Legacy 386 processor */
8918 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
8919 }
8920
8921 /**
8922 + * atomic_add_return_unchecked - add integer and return
8923 + * @i: integer value to add
8924 + * @v: pointer of type atomic_unchecked_t
8925 + *
8926 + * Atomically adds @i to @v and returns @i + @v
8927 + */
8928 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8929 +{
8930 +#ifdef CONFIG_M386
8931 + int __i;
8932 + unsigned long flags;
8933 + if (unlikely(boot_cpu_data.x86 <= 3))
8934 + goto no_xadd;
8935 +#endif
8936 + /* Modern 486+ processor */
8937 + return i + xadd(&v->counter, i);
8938 +
8939 +#ifdef CONFIG_M386
8940 +no_xadd: /* Legacy 386 processor */
8941 + raw_local_irq_save(flags);
8942 + __i = atomic_read_unchecked(v);
8943 + atomic_set_unchecked(v, i + __i);
8944 + raw_local_irq_restore(flags);
8945 + return i + __i;
8946 +#endif
8947 +}
8948 +
8949 +/**
8950 * atomic_sub_return - subtract integer and return
8951 * @v: pointer of type atomic_t
8952 * @i: integer value to subtract
8953 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
8954 }
8955
8956 #define atomic_inc_return(v) (atomic_add_return(1, v))
8957 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8958 +{
8959 + return atomic_add_return_unchecked(1, v);
8960 +}
8961 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8962
8963 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8964 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8965 return cmpxchg(&v->counter, old, new);
8966 }
8967
8968 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8969 +{
8970 + return cmpxchg(&v->counter, old, new);
8971 +}
8972 +
8973 static inline int atomic_xchg(atomic_t *v, int new)
8974 {
8975 return xchg(&v->counter, new);
8976 }
8977
8978 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8979 +{
8980 + return xchg(&v->counter, new);
8981 +}
8982 +
8983 /**
8984 * __atomic_add_unless - add unless the number is already a given value
8985 * @v: pointer of type atomic_t
8986 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
8987 */
8988 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8989 {
8990 - int c, old;
8991 + int c, old, new;
8992 c = atomic_read(v);
8993 for (;;) {
8994 - if (unlikely(c == (u)))
8995 + if (unlikely(c == u))
8996 break;
8997 - old = atomic_cmpxchg((v), c, c + (a));
8998 +
8999 + asm volatile("addl %2,%0\n"
9000 +
9001 +#ifdef CONFIG_PAX_REFCOUNT
9002 + "jno 0f\n"
9003 + "subl %2,%0\n"
9004 + "int $4\n0:\n"
9005 + _ASM_EXTABLE(0b, 0b)
9006 +#endif
9007 +
9008 + : "=r" (new)
9009 + : "0" (c), "ir" (a));
9010 +
9011 + old = atomic_cmpxchg(v, c, new);
9012 if (likely(old == c))
9013 break;
9014 c = old;
9015 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9016 return c;
9017 }
9018
9019 +/**
9020 + * atomic_inc_not_zero_hint - increment if not null
9021 + * @v: pointer of type atomic_t
9022 + * @hint: probable value of the atomic before the increment
9023 + *
9024 + * This version of atomic_inc_not_zero() gives a hint of probable
9025 + * value of the atomic. This helps processor to not read the memory
9026 + * before doing the atomic read/modify/write cycle, lowering
9027 + * number of bus transactions on some arches.
9028 + *
9029 + * Returns: 0 if increment was not done, 1 otherwise.
9030 + */
9031 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9032 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9033 +{
9034 + int val, c = hint, new;
9035 +
9036 + /* sanity test, should be removed by compiler if hint is a constant */
9037 + if (!hint)
9038 + return __atomic_add_unless(v, 1, 0);
9039 +
9040 + do {
9041 + asm volatile("incl %0\n"
9042 +
9043 +#ifdef CONFIG_PAX_REFCOUNT
9044 + "jno 0f\n"
9045 + "decl %0\n"
9046 + "int $4\n0:\n"
9047 + _ASM_EXTABLE(0b, 0b)
9048 +#endif
9049 +
9050 + : "=r" (new)
9051 + : "0" (c));
9052 +
9053 + val = atomic_cmpxchg(v, c, new);
9054 + if (val == c)
9055 + return 1;
9056 + c = val;
9057 + } while (c);
9058 +
9059 + return 0;
9060 +}
9061
9062 /*
9063 * atomic_dec_if_positive - decrement by 1 if old value positive
9064 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9065 index fa13f0e..27c2e08 100644
9066 --- a/arch/x86/include/asm/atomic64_32.h
9067 +++ b/arch/x86/include/asm/atomic64_32.h
9068 @@ -12,6 +12,14 @@ typedef struct {
9069 u64 __aligned(8) counter;
9070 } atomic64_t;
9071
9072 +#ifdef CONFIG_PAX_REFCOUNT
9073 +typedef struct {
9074 + u64 __aligned(8) counter;
9075 +} atomic64_unchecked_t;
9076 +#else
9077 +typedef atomic64_t atomic64_unchecked_t;
9078 +#endif
9079 +
9080 #define ATOMIC64_INIT(val) { (val) }
9081
9082 #ifdef CONFIG_X86_CMPXCHG64
9083 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9084 }
9085
9086 /**
9087 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9088 + * @p: pointer to type atomic64_unchecked_t
9089 + * @o: expected value
9090 + * @n: new value
9091 + *
9092 + * Atomically sets @v to @n if it was equal to @o and returns
9093 + * the old value.
9094 + */
9095 +
9096 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9097 +{
9098 + return cmpxchg64(&v->counter, o, n);
9099 +}
9100 +
9101 +/**
9102 * atomic64_xchg - xchg atomic64 variable
9103 * @v: pointer to type atomic64_t
9104 * @n: value to assign
9105 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9106 }
9107
9108 /**
9109 + * atomic64_set_unchecked - set atomic64 variable
9110 + * @v: pointer to type atomic64_unchecked_t
9111 + * @n: value to assign
9112 + *
9113 + * Atomically sets the value of @v to @n.
9114 + */
9115 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9116 +{
9117 + unsigned high = (unsigned)(i >> 32);
9118 + unsigned low = (unsigned)i;
9119 + asm volatile(ATOMIC64_ALTERNATIVE(set)
9120 + : "+b" (low), "+c" (high)
9121 + : "S" (v)
9122 + : "eax", "edx", "memory"
9123 + );
9124 +}
9125 +
9126 +/**
9127 * atomic64_read - read atomic64 variable
9128 * @v: pointer to type atomic64_t
9129 *
9130 @@ -93,6 +134,22 @@ static inline long long atomic64_read(const atomic64_t *v)
9131 }
9132
9133 /**
9134 + * atomic64_read_unchecked - read atomic64 variable
9135 + * @v: pointer to type atomic64_unchecked_t
9136 + *
9137 + * Atomically reads the value of @v and returns it.
9138 + */
9139 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9140 +{
9141 + long long r;
9142 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9143 + : "=A" (r), "+c" (v)
9144 + : : "memory"
9145 + );
9146 + return r;
9147 + }
9148 +
9149 +/**
9150 * atomic64_add_return - add and return
9151 * @i: integer value to add
9152 * @v: pointer to type atomic64_t
9153 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9154 return i;
9155 }
9156
9157 +/**
9158 + * atomic64_add_return_unchecked - add and return
9159 + * @i: integer value to add
9160 + * @v: pointer to type atomic64_unchecked_t
9161 + *
9162 + * Atomically adds @i to @v and returns @i + *@v
9163 + */
9164 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9165 +{
9166 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9167 + : "+A" (i), "+c" (v)
9168 + : : "memory"
9169 + );
9170 + return i;
9171 +}
9172 +
9173 /*
9174 * Other variants with different arithmetic operators:
9175 */
9176 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9177 return a;
9178 }
9179
9180 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9181 +{
9182 + long long a;
9183 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9184 + : "=A" (a)
9185 + : "S" (v)
9186 + : "memory", "ecx"
9187 + );
9188 + return a;
9189 +}
9190 +
9191 static inline long long atomic64_dec_return(atomic64_t *v)
9192 {
9193 long long a;
9194 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9195 }
9196
9197 /**
9198 + * atomic64_add_unchecked - add integer to atomic64 variable
9199 + * @i: integer value to add
9200 + * @v: pointer to type atomic64_unchecked_t
9201 + *
9202 + * Atomically adds @i to @v.
9203 + */
9204 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9205 +{
9206 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9207 + : "+A" (i), "+c" (v)
9208 + : : "memory"
9209 + );
9210 + return i;
9211 +}
9212 +
9213 +/**
9214 * atomic64_sub - subtract the atomic64 variable
9215 * @i: integer value to subtract
9216 * @v: pointer to type atomic64_t
9217 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9218 index 0e1cbfc..5623683 100644
9219 --- a/arch/x86/include/asm/atomic64_64.h
9220 +++ b/arch/x86/include/asm/atomic64_64.h
9221 @@ -18,7 +18,19 @@
9222 */
9223 static inline long atomic64_read(const atomic64_t *v)
9224 {
9225 - return (*(volatile long *)&(v)->counter);
9226 + return (*(volatile const long *)&(v)->counter);
9227 +}
9228 +
9229 +/**
9230 + * atomic64_read_unchecked - read atomic64 variable
9231 + * @v: pointer of type atomic64_unchecked_t
9232 + *
9233 + * Atomically reads the value of @v.
9234 + * Doesn't imply a read memory barrier.
9235 + */
9236 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9237 +{
9238 + return (*(volatile const long *)&(v)->counter);
9239 }
9240
9241 /**
9242 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9243 }
9244
9245 /**
9246 + * atomic64_set_unchecked - set atomic64 variable
9247 + * @v: pointer to type atomic64_unchecked_t
9248 + * @i: required value
9249 + *
9250 + * Atomically sets the value of @v to @i.
9251 + */
9252 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9253 +{
9254 + v->counter = i;
9255 +}
9256 +
9257 +/**
9258 * atomic64_add - add integer to atomic64 variable
9259 * @i: integer value to add
9260 * @v: pointer to type atomic64_t
9261 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9262 */
9263 static inline void atomic64_add(long i, atomic64_t *v)
9264 {
9265 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9266 +
9267 +#ifdef CONFIG_PAX_REFCOUNT
9268 + "jno 0f\n"
9269 + LOCK_PREFIX "subq %1,%0\n"
9270 + "int $4\n0:\n"
9271 + _ASM_EXTABLE(0b, 0b)
9272 +#endif
9273 +
9274 + : "=m" (v->counter)
9275 + : "er" (i), "m" (v->counter));
9276 +}
9277 +
9278 +/**
9279 + * atomic64_add_unchecked - add integer to atomic64 variable
9280 + * @i: integer value to add
9281 + * @v: pointer to type atomic64_unchecked_t
9282 + *
9283 + * Atomically adds @i to @v.
9284 + */
9285 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9286 +{
9287 asm volatile(LOCK_PREFIX "addq %1,%0"
9288 : "=m" (v->counter)
9289 : "er" (i), "m" (v->counter));
9290 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9291 */
9292 static inline void atomic64_sub(long i, atomic64_t *v)
9293 {
9294 - asm volatile(LOCK_PREFIX "subq %1,%0"
9295 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9296 +
9297 +#ifdef CONFIG_PAX_REFCOUNT
9298 + "jno 0f\n"
9299 + LOCK_PREFIX "addq %1,%0\n"
9300 + "int $4\n0:\n"
9301 + _ASM_EXTABLE(0b, 0b)
9302 +#endif
9303 +
9304 + : "=m" (v->counter)
9305 + : "er" (i), "m" (v->counter));
9306 +}
9307 +
9308 +/**
9309 + * atomic64_sub_unchecked - subtract the atomic64 variable
9310 + * @i: integer value to subtract
9311 + * @v: pointer to type atomic64_unchecked_t
9312 + *
9313 + * Atomically subtracts @i from @v.
9314 + */
9315 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9316 +{
9317 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9318 : "=m" (v->counter)
9319 : "er" (i), "m" (v->counter));
9320 }
9321 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9322 {
9323 unsigned char c;
9324
9325 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9326 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9327 +
9328 +#ifdef CONFIG_PAX_REFCOUNT
9329 + "jno 0f\n"
9330 + LOCK_PREFIX "addq %2,%0\n"
9331 + "int $4\n0:\n"
9332 + _ASM_EXTABLE(0b, 0b)
9333 +#endif
9334 +
9335 + "sete %1\n"
9336 : "=m" (v->counter), "=qm" (c)
9337 : "er" (i), "m" (v->counter) : "memory");
9338 return c;
9339 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9340 */
9341 static inline void atomic64_inc(atomic64_t *v)
9342 {
9343 + asm volatile(LOCK_PREFIX "incq %0\n"
9344 +
9345 +#ifdef CONFIG_PAX_REFCOUNT
9346 + "jno 0f\n"
9347 + LOCK_PREFIX "decq %0\n"
9348 + "int $4\n0:\n"
9349 + _ASM_EXTABLE(0b, 0b)
9350 +#endif
9351 +
9352 + : "=m" (v->counter)
9353 + : "m" (v->counter));
9354 +}
9355 +
9356 +/**
9357 + * atomic64_inc_unchecked - increment atomic64 variable
9358 + * @v: pointer to type atomic64_unchecked_t
9359 + *
9360 + * Atomically increments @v by 1.
9361 + */
9362 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9363 +{
9364 asm volatile(LOCK_PREFIX "incq %0"
9365 : "=m" (v->counter)
9366 : "m" (v->counter));
9367 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9368 */
9369 static inline void atomic64_dec(atomic64_t *v)
9370 {
9371 - asm volatile(LOCK_PREFIX "decq %0"
9372 + asm volatile(LOCK_PREFIX "decq %0\n"
9373 +
9374 +#ifdef CONFIG_PAX_REFCOUNT
9375 + "jno 0f\n"
9376 + LOCK_PREFIX "incq %0\n"
9377 + "int $4\n0:\n"
9378 + _ASM_EXTABLE(0b, 0b)
9379 +#endif
9380 +
9381 + : "=m" (v->counter)
9382 + : "m" (v->counter));
9383 +}
9384 +
9385 +/**
9386 + * atomic64_dec_unchecked - decrement atomic64 variable
9387 + * @v: pointer to type atomic64_t
9388 + *
9389 + * Atomically decrements @v by 1.
9390 + */
9391 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9392 +{
9393 + asm volatile(LOCK_PREFIX "decq %0\n"
9394 : "=m" (v->counter)
9395 : "m" (v->counter));
9396 }
9397 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9398 {
9399 unsigned char c;
9400
9401 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9402 + asm volatile(LOCK_PREFIX "decq %0\n"
9403 +
9404 +#ifdef CONFIG_PAX_REFCOUNT
9405 + "jno 0f\n"
9406 + LOCK_PREFIX "incq %0\n"
9407 + "int $4\n0:\n"
9408 + _ASM_EXTABLE(0b, 0b)
9409 +#endif
9410 +
9411 + "sete %1\n"
9412 : "=m" (v->counter), "=qm" (c)
9413 : "m" (v->counter) : "memory");
9414 return c != 0;
9415 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9416 {
9417 unsigned char c;
9418
9419 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9420 + asm volatile(LOCK_PREFIX "incq %0\n"
9421 +
9422 +#ifdef CONFIG_PAX_REFCOUNT
9423 + "jno 0f\n"
9424 + LOCK_PREFIX "decq %0\n"
9425 + "int $4\n0:\n"
9426 + _ASM_EXTABLE(0b, 0b)
9427 +#endif
9428 +
9429 + "sete %1\n"
9430 : "=m" (v->counter), "=qm" (c)
9431 : "m" (v->counter) : "memory");
9432 return c != 0;
9433 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9434 {
9435 unsigned char c;
9436
9437 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9438 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9439 +
9440 +#ifdef CONFIG_PAX_REFCOUNT
9441 + "jno 0f\n"
9442 + LOCK_PREFIX "subq %2,%0\n"
9443 + "int $4\n0:\n"
9444 + _ASM_EXTABLE(0b, 0b)
9445 +#endif
9446 +
9447 + "sets %1\n"
9448 : "=m" (v->counter), "=qm" (c)
9449 : "er" (i), "m" (v->counter) : "memory");
9450 return c;
9451 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9452 */
9453 static inline long atomic64_add_return(long i, atomic64_t *v)
9454 {
9455 + return i + xadd_check_overflow(&v->counter, i);
9456 +}
9457 +
9458 +/**
9459 + * atomic64_add_return_unchecked - add and return
9460 + * @i: integer value to add
9461 + * @v: pointer to type atomic64_unchecked_t
9462 + *
9463 + * Atomically adds @i to @v and returns @i + @v
9464 + */
9465 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9466 +{
9467 return i + xadd(&v->counter, i);
9468 }
9469
9470 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9471 }
9472
9473 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9474 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9475 +{
9476 + return atomic64_add_return_unchecked(1, v);
9477 +}
9478 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9479
9480 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9481 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9482 return cmpxchg(&v->counter, old, new);
9483 }
9484
9485 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9486 +{
9487 + return cmpxchg(&v->counter, old, new);
9488 +}
9489 +
9490 static inline long atomic64_xchg(atomic64_t *v, long new)
9491 {
9492 return xchg(&v->counter, new);
9493 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9494 */
9495 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9496 {
9497 - long c, old;
9498 + long c, old, new;
9499 c = atomic64_read(v);
9500 for (;;) {
9501 - if (unlikely(c == (u)))
9502 + if (unlikely(c == u))
9503 break;
9504 - old = atomic64_cmpxchg((v), c, c + (a));
9505 +
9506 + asm volatile("add %2,%0\n"
9507 +
9508 +#ifdef CONFIG_PAX_REFCOUNT
9509 + "jno 0f\n"
9510 + "sub %2,%0\n"
9511 + "int $4\n0:\n"
9512 + _ASM_EXTABLE(0b, 0b)
9513 +#endif
9514 +
9515 + : "=r" (new)
9516 + : "0" (c), "ir" (a));
9517 +
9518 + old = atomic64_cmpxchg(v, c, new);
9519 if (likely(old == c))
9520 break;
9521 c = old;
9522 }
9523 - return c != (u);
9524 + return c != u;
9525 }
9526
9527 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9528 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9529 index b97596e..9bd48b06 100644
9530 --- a/arch/x86/include/asm/bitops.h
9531 +++ b/arch/x86/include/asm/bitops.h
9532 @@ -38,7 +38,7 @@
9533 * a mask operation on a byte.
9534 */
9535 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9536 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9537 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9538 #define CONST_MASK(nr) (1 << ((nr) & 7))
9539
9540 /**
9541 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9542 index 5e1a2ee..c9f9533 100644
9543 --- a/arch/x86/include/asm/boot.h
9544 +++ b/arch/x86/include/asm/boot.h
9545 @@ -11,10 +11,15 @@
9546 #include <asm/pgtable_types.h>
9547
9548 /* Physical address where kernel should be loaded. */
9549 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9550 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9551 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9552 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9553
9554 +#ifndef __ASSEMBLY__
9555 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9556 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9557 +#endif
9558 +
9559 /* Minimum kernel alignment, as a power of two */
9560 #ifdef CONFIG_X86_64
9561 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9562 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9563 index 48f99f1..d78ebf9 100644
9564 --- a/arch/x86/include/asm/cache.h
9565 +++ b/arch/x86/include/asm/cache.h
9566 @@ -5,12 +5,13 @@
9567
9568 /* L1 cache line size */
9569 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9570 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9571 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9572
9573 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9574 +#define __read_only __attribute__((__section__(".data..read_only")))
9575
9576 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9577 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9578 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
9579
9580 #ifdef CONFIG_X86_VSMP
9581 #ifdef CONFIG_SMP
9582 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9583 index 4e12668..501d239 100644
9584 --- a/arch/x86/include/asm/cacheflush.h
9585 +++ b/arch/x86/include/asm/cacheflush.h
9586 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
9587 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9588
9589 if (pg_flags == _PGMT_DEFAULT)
9590 - return -1;
9591 + return ~0UL;
9592 else if (pg_flags == _PGMT_WC)
9593 return _PAGE_CACHE_WC;
9594 else if (pg_flags == _PGMT_UC_MINUS)
9595 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9596 index 46fc474..b02b0f9 100644
9597 --- a/arch/x86/include/asm/checksum_32.h
9598 +++ b/arch/x86/include/asm/checksum_32.h
9599 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9600 int len, __wsum sum,
9601 int *src_err_ptr, int *dst_err_ptr);
9602
9603 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9604 + int len, __wsum sum,
9605 + int *src_err_ptr, int *dst_err_ptr);
9606 +
9607 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9608 + int len, __wsum sum,
9609 + int *src_err_ptr, int *dst_err_ptr);
9610 +
9611 /*
9612 * Note: when you get a NULL pointer exception here this means someone
9613 * passed in an incorrect kernel address to one of these functions.
9614 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9615 int *err_ptr)
9616 {
9617 might_sleep();
9618 - return csum_partial_copy_generic((__force void *)src, dst,
9619 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9620 len, sum, err_ptr, NULL);
9621 }
9622
9623 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9624 {
9625 might_sleep();
9626 if (access_ok(VERIFY_WRITE, dst, len))
9627 - return csum_partial_copy_generic(src, (__force void *)dst,
9628 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9629 len, sum, NULL, err_ptr);
9630
9631 if (len)
9632 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
9633 index b3b7332..3935f40 100644
9634 --- a/arch/x86/include/asm/cmpxchg.h
9635 +++ b/arch/x86/include/asm/cmpxchg.h
9636 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
9637 __compiletime_error("Bad argument size for cmpxchg");
9638 extern void __xadd_wrong_size(void)
9639 __compiletime_error("Bad argument size for xadd");
9640 +extern void __xadd_check_overflow_wrong_size(void)
9641 + __compiletime_error("Bad argument size for xadd_check_overflow");
9642 extern void __add_wrong_size(void)
9643 __compiletime_error("Bad argument size for add");
9644 +extern void __add_check_overflow_wrong_size(void)
9645 + __compiletime_error("Bad argument size for add_check_overflow");
9646
9647 /*
9648 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
9649 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
9650 __ret; \
9651 })
9652
9653 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
9654 + ({ \
9655 + __typeof__ (*(ptr)) __ret = (arg); \
9656 + switch (sizeof(*(ptr))) { \
9657 + case __X86_CASE_L: \
9658 + asm volatile (lock #op "l %0, %1\n" \
9659 + "jno 0f\n" \
9660 + "mov %0,%1\n" \
9661 + "int $4\n0:\n" \
9662 + _ASM_EXTABLE(0b, 0b) \
9663 + : "+r" (__ret), "+m" (*(ptr)) \
9664 + : : "memory", "cc"); \
9665 + break; \
9666 + case __X86_CASE_Q: \
9667 + asm volatile (lock #op "q %q0, %1\n" \
9668 + "jno 0f\n" \
9669 + "mov %0,%1\n" \
9670 + "int $4\n0:\n" \
9671 + _ASM_EXTABLE(0b, 0b) \
9672 + : "+r" (__ret), "+m" (*(ptr)) \
9673 + : : "memory", "cc"); \
9674 + break; \
9675 + default: \
9676 + __ ## op ## _check_overflow_wrong_size(); \
9677 + } \
9678 + __ret; \
9679 + })
9680 +
9681 /*
9682 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
9683 * Since this is generally used to protect other memory information, we
9684 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
9685 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9686 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9687
9688 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
9689 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9690 +
9691 #define __add(ptr, inc, lock) \
9692 ({ \
9693 __typeof__ (*(ptr)) __ret = (inc); \
9694 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9695 index 8d67d42..183d0eb 100644
9696 --- a/arch/x86/include/asm/cpufeature.h
9697 +++ b/arch/x86/include/asm/cpufeature.h
9698 @@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9699 ".section .discard,\"aw\",@progbits\n"
9700 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9701 ".previous\n"
9702 - ".section .altinstr_replacement,\"ax\"\n"
9703 + ".section .altinstr_replacement,\"a\"\n"
9704 "3: movb $1,%0\n"
9705 "4:\n"
9706 ".previous\n"
9707 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9708 index e95822d..a90010e 100644
9709 --- a/arch/x86/include/asm/desc.h
9710 +++ b/arch/x86/include/asm/desc.h
9711 @@ -4,6 +4,7 @@
9712 #include <asm/desc_defs.h>
9713 #include <asm/ldt.h>
9714 #include <asm/mmu.h>
9715 +#include <asm/pgtable.h>
9716
9717 #include <linux/smp.h>
9718
9719 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9720
9721 desc->type = (info->read_exec_only ^ 1) << 1;
9722 desc->type |= info->contents << 2;
9723 + desc->type |= info->seg_not_present ^ 1;
9724
9725 desc->s = 1;
9726 desc->dpl = 0x3;
9727 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9728 }
9729
9730 extern struct desc_ptr idt_descr;
9731 -extern gate_desc idt_table[];
9732 extern struct desc_ptr nmi_idt_descr;
9733 -extern gate_desc nmi_idt_table[];
9734 -
9735 -struct gdt_page {
9736 - struct desc_struct gdt[GDT_ENTRIES];
9737 -} __attribute__((aligned(PAGE_SIZE)));
9738 -
9739 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9740 +extern gate_desc idt_table[256];
9741 +extern gate_desc nmi_idt_table[256];
9742
9743 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9744 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9745 {
9746 - return per_cpu(gdt_page, cpu).gdt;
9747 + return cpu_gdt_table[cpu];
9748 }
9749
9750 #ifdef CONFIG_X86_64
9751 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9752 unsigned long base, unsigned dpl, unsigned flags,
9753 unsigned short seg)
9754 {
9755 - gate->a = (seg << 16) | (base & 0xffff);
9756 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9757 + gate->gate.offset_low = base;
9758 + gate->gate.seg = seg;
9759 + gate->gate.reserved = 0;
9760 + gate->gate.type = type;
9761 + gate->gate.s = 0;
9762 + gate->gate.dpl = dpl;
9763 + gate->gate.p = 1;
9764 + gate->gate.offset_high = base >> 16;
9765 }
9766
9767 #endif
9768 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9769
9770 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9771 {
9772 + pax_open_kernel();
9773 memcpy(&idt[entry], gate, sizeof(*gate));
9774 + pax_close_kernel();
9775 }
9776
9777 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9778 {
9779 + pax_open_kernel();
9780 memcpy(&ldt[entry], desc, 8);
9781 + pax_close_kernel();
9782 }
9783
9784 static inline void
9785 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9786 default: size = sizeof(*gdt); break;
9787 }
9788
9789 + pax_open_kernel();
9790 memcpy(&gdt[entry], desc, size);
9791 + pax_close_kernel();
9792 }
9793
9794 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9795 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9796
9797 static inline void native_load_tr_desc(void)
9798 {
9799 + pax_open_kernel();
9800 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9801 + pax_close_kernel();
9802 }
9803
9804 static inline void native_load_gdt(const struct desc_ptr *dtr)
9805 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9806 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9807 unsigned int i;
9808
9809 + pax_open_kernel();
9810 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9811 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9812 + pax_close_kernel();
9813 }
9814
9815 #define _LDT_empty(info) \
9816 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9817 }
9818
9819 #ifdef CONFIG_X86_64
9820 -static inline void set_nmi_gate(int gate, void *addr)
9821 +static inline void set_nmi_gate(int gate, const void *addr)
9822 {
9823 gate_desc s;
9824
9825 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
9826 }
9827 #endif
9828
9829 -static inline void _set_gate(int gate, unsigned type, void *addr,
9830 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9831 unsigned dpl, unsigned ist, unsigned seg)
9832 {
9833 gate_desc s;
9834 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9835 * Pentium F0 0F bugfix can have resulted in the mapped
9836 * IDT being write-protected.
9837 */
9838 -static inline void set_intr_gate(unsigned int n, void *addr)
9839 +static inline void set_intr_gate(unsigned int n, const void *addr)
9840 {
9841 BUG_ON((unsigned)n > 0xFF);
9842 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9843 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9844 /*
9845 * This routine sets up an interrupt gate at directory privilege level 3.
9846 */
9847 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9848 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9849 {
9850 BUG_ON((unsigned)n > 0xFF);
9851 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9852 }
9853
9854 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9855 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9856 {
9857 BUG_ON((unsigned)n > 0xFF);
9858 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9859 }
9860
9861 -static inline void set_trap_gate(unsigned int n, void *addr)
9862 +static inline void set_trap_gate(unsigned int n, const void *addr)
9863 {
9864 BUG_ON((unsigned)n > 0xFF);
9865 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9866 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9867 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9868 {
9869 BUG_ON((unsigned)n > 0xFF);
9870 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9871 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9872 }
9873
9874 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9875 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9876 {
9877 BUG_ON((unsigned)n > 0xFF);
9878 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9879 }
9880
9881 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9882 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9883 {
9884 BUG_ON((unsigned)n > 0xFF);
9885 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9886 }
9887
9888 +#ifdef CONFIG_X86_32
9889 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9890 +{
9891 + struct desc_struct d;
9892 +
9893 + if (likely(limit))
9894 + limit = (limit - 1UL) >> PAGE_SHIFT;
9895 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9896 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9897 +}
9898 +#endif
9899 +
9900 #endif /* _ASM_X86_DESC_H */
9901 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9902 index 278441f..b95a174 100644
9903 --- a/arch/x86/include/asm/desc_defs.h
9904 +++ b/arch/x86/include/asm/desc_defs.h
9905 @@ -31,6 +31,12 @@ struct desc_struct {
9906 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9907 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9908 };
9909 + struct {
9910 + u16 offset_low;
9911 + u16 seg;
9912 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9913 + unsigned offset_high: 16;
9914 + } gate;
9915 };
9916 } __attribute__((packed));
9917
9918 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9919 index 3778256..c5d4fce 100644
9920 --- a/arch/x86/include/asm/e820.h
9921 +++ b/arch/x86/include/asm/e820.h
9922 @@ -69,7 +69,7 @@ struct e820map {
9923 #define ISA_START_ADDRESS 0xa0000
9924 #define ISA_END_ADDRESS 0x100000
9925
9926 -#define BIOS_BEGIN 0x000a0000
9927 +#define BIOS_BEGIN 0x000c0000
9928 #define BIOS_END 0x00100000
9929
9930 #define BIOS_ROM_BASE 0xffe00000
9931 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9932 index 5f962df..7289f09 100644
9933 --- a/arch/x86/include/asm/elf.h
9934 +++ b/arch/x86/include/asm/elf.h
9935 @@ -238,7 +238,25 @@ extern int force_personality32;
9936 the loader. We need to make sure that it is out of the way of the program
9937 that it will "exec", and that there is sufficient room for the brk. */
9938
9939 +#ifdef CONFIG_PAX_SEGMEXEC
9940 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9941 +#else
9942 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9943 +#endif
9944 +
9945 +#ifdef CONFIG_PAX_ASLR
9946 +#ifdef CONFIG_X86_32
9947 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9948 +
9949 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9950 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9951 +#else
9952 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9953 +
9954 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9955 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9956 +#endif
9957 +#endif
9958
9959 /* This yields a mask that user programs can use to figure out what
9960 instruction set this CPU supports. This could be done in user space,
9961 @@ -291,9 +309,7 @@ do { \
9962
9963 #define ARCH_DLINFO \
9964 do { \
9965 - if (vdso_enabled) \
9966 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9967 - (unsigned long)current->mm->context.vdso); \
9968 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
9969 } while (0)
9970
9971 #define AT_SYSINFO 32
9972 @@ -304,7 +320,7 @@ do { \
9973
9974 #endif /* !CONFIG_X86_32 */
9975
9976 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9977 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9978
9979 #define VDSO_ENTRY \
9980 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9981 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
9982 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9983 #define compat_arch_setup_additional_pages syscall32_setup_pages
9984
9985 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9986 -#define arch_randomize_brk arch_randomize_brk
9987 -
9988 /*
9989 * True on X86_32 or when emulating IA32 on X86_64
9990 */
9991 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
9992 index cc70c1c..d96d011 100644
9993 --- a/arch/x86/include/asm/emergency-restart.h
9994 +++ b/arch/x86/include/asm/emergency-restart.h
9995 @@ -15,6 +15,6 @@ enum reboot_type {
9996
9997 extern enum reboot_type reboot_type;
9998
9999 -extern void machine_emergency_restart(void);
10000 +extern void machine_emergency_restart(void) __noreturn;
10001
10002 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10003 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10004 index d09bb03..4ea4194 100644
10005 --- a/arch/x86/include/asm/futex.h
10006 +++ b/arch/x86/include/asm/futex.h
10007 @@ -12,16 +12,18 @@
10008 #include <asm/system.h>
10009
10010 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10011 + typecheck(u32 __user *, uaddr); \
10012 asm volatile("1:\t" insn "\n" \
10013 "2:\t.section .fixup,\"ax\"\n" \
10014 "3:\tmov\t%3, %1\n" \
10015 "\tjmp\t2b\n" \
10016 "\t.previous\n" \
10017 _ASM_EXTABLE(1b, 3b) \
10018 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10019 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10020 : "i" (-EFAULT), "0" (oparg), "1" (0))
10021
10022 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10023 + typecheck(u32 __user *, uaddr); \
10024 asm volatile("1:\tmovl %2, %0\n" \
10025 "\tmovl\t%0, %3\n" \
10026 "\t" insn "\n" \
10027 @@ -34,7 +36,7 @@
10028 _ASM_EXTABLE(1b, 4b) \
10029 _ASM_EXTABLE(2b, 4b) \
10030 : "=&a" (oldval), "=&r" (ret), \
10031 - "+m" (*uaddr), "=&r" (tem) \
10032 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10033 : "r" (oparg), "i" (-EFAULT), "1" (0))
10034
10035 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10036 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10037
10038 switch (op) {
10039 case FUTEX_OP_SET:
10040 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10041 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10042 break;
10043 case FUTEX_OP_ADD:
10044 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10045 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10046 uaddr, oparg);
10047 break;
10048 case FUTEX_OP_OR:
10049 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10050 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10051 return -EFAULT;
10052
10053 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10054 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10055 "2:\t.section .fixup, \"ax\"\n"
10056 "3:\tmov %3, %0\n"
10057 "\tjmp 2b\n"
10058 "\t.previous\n"
10059 _ASM_EXTABLE(1b, 3b)
10060 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10061 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10062 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10063 : "memory"
10064 );
10065 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10066 index eb92a6e..b98b2f4 100644
10067 --- a/arch/x86/include/asm/hw_irq.h
10068 +++ b/arch/x86/include/asm/hw_irq.h
10069 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10070 extern void enable_IO_APIC(void);
10071
10072 /* Statistics */
10073 -extern atomic_t irq_err_count;
10074 -extern atomic_t irq_mis_count;
10075 +extern atomic_unchecked_t irq_err_count;
10076 +extern atomic_unchecked_t irq_mis_count;
10077
10078 /* EISA */
10079 extern void eisa_set_level_irq(unsigned int irq);
10080 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10081 index 2479049..3fb9795 100644
10082 --- a/arch/x86/include/asm/i387.h
10083 +++ b/arch/x86/include/asm/i387.h
10084 @@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10085 {
10086 int err;
10087
10088 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10089 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10090 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10091 +#endif
10092 +
10093 /* See comment in fxsave() below. */
10094 #ifdef CONFIG_AS_FXSAVEQ
10095 asm volatile("1: fxrstorq %[fx]\n\t"
10096 @@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10097 {
10098 int err;
10099
10100 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10101 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10102 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10103 +#endif
10104 +
10105 /*
10106 * Clear the bytes not touched by the fxsave and reserved
10107 * for the SW usage.
10108 @@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10109 "emms\n\t" /* clear stack tags */
10110 "fildl %P[addr]", /* set F?P to defined value */
10111 X86_FEATURE_FXSAVE_LEAK,
10112 - [addr] "m" (tsk->thread.fpu.has_fpu));
10113 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10114
10115 return fpu_restore_checking(&tsk->thread.fpu);
10116 }
10117 @@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10118 static inline bool interrupted_user_mode(void)
10119 {
10120 struct pt_regs *regs = get_irq_regs();
10121 - return regs && user_mode_vm(regs);
10122 + return regs && user_mode(regs);
10123 }
10124
10125 /*
10126 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10127 index d8e8eef..99f81ae 100644
10128 --- a/arch/x86/include/asm/io.h
10129 +++ b/arch/x86/include/asm/io.h
10130 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10131
10132 #include <linux/vmalloc.h>
10133
10134 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10135 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10136 +{
10137 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10138 +}
10139 +
10140 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10141 +{
10142 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10143 +}
10144 +
10145 /*
10146 * Convert a virtual cached pointer to an uncached pointer
10147 */
10148 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10149 index bba3cf8..06bc8da 100644
10150 --- a/arch/x86/include/asm/irqflags.h
10151 +++ b/arch/x86/include/asm/irqflags.h
10152 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10153 sti; \
10154 sysexit
10155
10156 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10157 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10158 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10159 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10160 +
10161 #else
10162 #define INTERRUPT_RETURN iret
10163 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10164 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10165 index 5478825..839e88c 100644
10166 --- a/arch/x86/include/asm/kprobes.h
10167 +++ b/arch/x86/include/asm/kprobes.h
10168 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10169 #define RELATIVEJUMP_SIZE 5
10170 #define RELATIVECALL_OPCODE 0xe8
10171 #define RELATIVE_ADDR_SIZE 4
10172 -#define MAX_STACK_SIZE 64
10173 -#define MIN_STACK_SIZE(ADDR) \
10174 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10175 - THREAD_SIZE - (unsigned long)(ADDR))) \
10176 - ? (MAX_STACK_SIZE) \
10177 - : (((unsigned long)current_thread_info()) + \
10178 - THREAD_SIZE - (unsigned long)(ADDR)))
10179 +#define MAX_STACK_SIZE 64UL
10180 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10181
10182 #define flush_insn_slot(p) do { } while (0)
10183
10184 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10185 index 52d6640..a013b87 100644
10186 --- a/arch/x86/include/asm/kvm_host.h
10187 +++ b/arch/x86/include/asm/kvm_host.h
10188 @@ -663,7 +663,7 @@ struct kvm_x86_ops {
10189 int (*check_intercept)(struct kvm_vcpu *vcpu,
10190 struct x86_instruction_info *info,
10191 enum x86_intercept_stage stage);
10192 -};
10193 +} __do_const;
10194
10195 struct kvm_arch_async_pf {
10196 u32 token;
10197 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10198 index 9cdae5d..300d20f 100644
10199 --- a/arch/x86/include/asm/local.h
10200 +++ b/arch/x86/include/asm/local.h
10201 @@ -18,26 +18,58 @@ typedef struct {
10202
10203 static inline void local_inc(local_t *l)
10204 {
10205 - asm volatile(_ASM_INC "%0"
10206 + asm volatile(_ASM_INC "%0\n"
10207 +
10208 +#ifdef CONFIG_PAX_REFCOUNT
10209 + "jno 0f\n"
10210 + _ASM_DEC "%0\n"
10211 + "int $4\n0:\n"
10212 + _ASM_EXTABLE(0b, 0b)
10213 +#endif
10214 +
10215 : "+m" (l->a.counter));
10216 }
10217
10218 static inline void local_dec(local_t *l)
10219 {
10220 - asm volatile(_ASM_DEC "%0"
10221 + asm volatile(_ASM_DEC "%0\n"
10222 +
10223 +#ifdef CONFIG_PAX_REFCOUNT
10224 + "jno 0f\n"
10225 + _ASM_INC "%0\n"
10226 + "int $4\n0:\n"
10227 + _ASM_EXTABLE(0b, 0b)
10228 +#endif
10229 +
10230 : "+m" (l->a.counter));
10231 }
10232
10233 static inline void local_add(long i, local_t *l)
10234 {
10235 - asm volatile(_ASM_ADD "%1,%0"
10236 + asm volatile(_ASM_ADD "%1,%0\n"
10237 +
10238 +#ifdef CONFIG_PAX_REFCOUNT
10239 + "jno 0f\n"
10240 + _ASM_SUB "%1,%0\n"
10241 + "int $4\n0:\n"
10242 + _ASM_EXTABLE(0b, 0b)
10243 +#endif
10244 +
10245 : "+m" (l->a.counter)
10246 : "ir" (i));
10247 }
10248
10249 static inline void local_sub(long i, local_t *l)
10250 {
10251 - asm volatile(_ASM_SUB "%1,%0"
10252 + asm volatile(_ASM_SUB "%1,%0\n"
10253 +
10254 +#ifdef CONFIG_PAX_REFCOUNT
10255 + "jno 0f\n"
10256 + _ASM_ADD "%1,%0\n"
10257 + "int $4\n0:\n"
10258 + _ASM_EXTABLE(0b, 0b)
10259 +#endif
10260 +
10261 : "+m" (l->a.counter)
10262 : "ir" (i));
10263 }
10264 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10265 {
10266 unsigned char c;
10267
10268 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10269 + asm volatile(_ASM_SUB "%2,%0\n"
10270 +
10271 +#ifdef CONFIG_PAX_REFCOUNT
10272 + "jno 0f\n"
10273 + _ASM_ADD "%2,%0\n"
10274 + "int $4\n0:\n"
10275 + _ASM_EXTABLE(0b, 0b)
10276 +#endif
10277 +
10278 + "sete %1\n"
10279 : "+m" (l->a.counter), "=qm" (c)
10280 : "ir" (i) : "memory");
10281 return c;
10282 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10283 {
10284 unsigned char c;
10285
10286 - asm volatile(_ASM_DEC "%0; sete %1"
10287 + asm volatile(_ASM_DEC "%0\n"
10288 +
10289 +#ifdef CONFIG_PAX_REFCOUNT
10290 + "jno 0f\n"
10291 + _ASM_INC "%0\n"
10292 + "int $4\n0:\n"
10293 + _ASM_EXTABLE(0b, 0b)
10294 +#endif
10295 +
10296 + "sete %1\n"
10297 : "+m" (l->a.counter), "=qm" (c)
10298 : : "memory");
10299 return c != 0;
10300 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10301 {
10302 unsigned char c;
10303
10304 - asm volatile(_ASM_INC "%0; sete %1"
10305 + asm volatile(_ASM_INC "%0\n"
10306 +
10307 +#ifdef CONFIG_PAX_REFCOUNT
10308 + "jno 0f\n"
10309 + _ASM_DEC "%0\n"
10310 + "int $4\n0:\n"
10311 + _ASM_EXTABLE(0b, 0b)
10312 +#endif
10313 +
10314 + "sete %1\n"
10315 : "+m" (l->a.counter), "=qm" (c)
10316 : : "memory");
10317 return c != 0;
10318 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10319 {
10320 unsigned char c;
10321
10322 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10323 + asm volatile(_ASM_ADD "%2,%0\n"
10324 +
10325 +#ifdef CONFIG_PAX_REFCOUNT
10326 + "jno 0f\n"
10327 + _ASM_SUB "%2,%0\n"
10328 + "int $4\n0:\n"
10329 + _ASM_EXTABLE(0b, 0b)
10330 +#endif
10331 +
10332 + "sets %1\n"
10333 : "+m" (l->a.counter), "=qm" (c)
10334 : "ir" (i) : "memory");
10335 return c;
10336 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10337 #endif
10338 /* Modern 486+ processor */
10339 __i = i;
10340 - asm volatile(_ASM_XADD "%0, %1;"
10341 + asm volatile(_ASM_XADD "%0, %1\n"
10342 +
10343 +#ifdef CONFIG_PAX_REFCOUNT
10344 + "jno 0f\n"
10345 + _ASM_MOV "%0,%1\n"
10346 + "int $4\n0:\n"
10347 + _ASM_EXTABLE(0b, 0b)
10348 +#endif
10349 +
10350 : "+r" (i), "+m" (l->a.counter)
10351 : : "memory");
10352 return i + __i;
10353 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10354 index 593e51d..fa69c9a 100644
10355 --- a/arch/x86/include/asm/mman.h
10356 +++ b/arch/x86/include/asm/mman.h
10357 @@ -5,4 +5,14 @@
10358
10359 #include <asm-generic/mman.h>
10360
10361 +#ifdef __KERNEL__
10362 +#ifndef __ASSEMBLY__
10363 +#ifdef CONFIG_X86_32
10364 +#define arch_mmap_check i386_mmap_check
10365 +int i386_mmap_check(unsigned long addr, unsigned long len,
10366 + unsigned long flags);
10367 +#endif
10368 +#endif
10369 +#endif
10370 +
10371 #endif /* _ASM_X86_MMAN_H */
10372 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10373 index 5f55e69..e20bfb1 100644
10374 --- a/arch/x86/include/asm/mmu.h
10375 +++ b/arch/x86/include/asm/mmu.h
10376 @@ -9,7 +9,7 @@
10377 * we put the segment information here.
10378 */
10379 typedef struct {
10380 - void *ldt;
10381 + struct desc_struct *ldt;
10382 int size;
10383
10384 #ifdef CONFIG_X86_64
10385 @@ -18,7 +18,19 @@ typedef struct {
10386 #endif
10387
10388 struct mutex lock;
10389 - void *vdso;
10390 + unsigned long vdso;
10391 +
10392 +#ifdef CONFIG_X86_32
10393 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10394 + unsigned long user_cs_base;
10395 + unsigned long user_cs_limit;
10396 +
10397 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10398 + cpumask_t cpu_user_cs_mask;
10399 +#endif
10400 +
10401 +#endif
10402 +#endif
10403 } mm_context_t;
10404
10405 #ifdef CONFIG_SMP
10406 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10407 index 6902152..399f3a2 100644
10408 --- a/arch/x86/include/asm/mmu_context.h
10409 +++ b/arch/x86/include/asm/mmu_context.h
10410 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10411
10412 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10413 {
10414 +
10415 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10416 + unsigned int i;
10417 + pgd_t *pgd;
10418 +
10419 + pax_open_kernel();
10420 + pgd = get_cpu_pgd(smp_processor_id());
10421 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10422 + set_pgd_batched(pgd+i, native_make_pgd(0));
10423 + pax_close_kernel();
10424 +#endif
10425 +
10426 #ifdef CONFIG_SMP
10427 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10428 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10429 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10430 struct task_struct *tsk)
10431 {
10432 unsigned cpu = smp_processor_id();
10433 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10434 + int tlbstate = TLBSTATE_OK;
10435 +#endif
10436
10437 if (likely(prev != next)) {
10438 #ifdef CONFIG_SMP
10439 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10440 + tlbstate = percpu_read(cpu_tlbstate.state);
10441 +#endif
10442 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10443 percpu_write(cpu_tlbstate.active_mm, next);
10444 #endif
10445 cpumask_set_cpu(cpu, mm_cpumask(next));
10446
10447 /* Re-load page tables */
10448 +#ifdef CONFIG_PAX_PER_CPU_PGD
10449 + pax_open_kernel();
10450 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10451 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10452 + pax_close_kernel();
10453 + load_cr3(get_cpu_pgd(cpu));
10454 +#else
10455 load_cr3(next->pgd);
10456 +#endif
10457
10458 /* stop flush ipis for the previous mm */
10459 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10460 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10461 */
10462 if (unlikely(prev->context.ldt != next->context.ldt))
10463 load_LDT_nolock(&next->context);
10464 - }
10465 +
10466 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10467 + if (!(__supported_pte_mask & _PAGE_NX)) {
10468 + smp_mb__before_clear_bit();
10469 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10470 + smp_mb__after_clear_bit();
10471 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10472 + }
10473 +#endif
10474 +
10475 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10476 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10477 + prev->context.user_cs_limit != next->context.user_cs_limit))
10478 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10479 #ifdef CONFIG_SMP
10480 + else if (unlikely(tlbstate != TLBSTATE_OK))
10481 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10482 +#endif
10483 +#endif
10484 +
10485 + }
10486 else {
10487 +
10488 +#ifdef CONFIG_PAX_PER_CPU_PGD
10489 + pax_open_kernel();
10490 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10491 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10492 + pax_close_kernel();
10493 + load_cr3(get_cpu_pgd(cpu));
10494 +#endif
10495 +
10496 +#ifdef CONFIG_SMP
10497 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10498 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10499
10500 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10501 * tlb flush IPI delivery. We must reload CR3
10502 * to make sure to use no freed page tables.
10503 */
10504 +
10505 +#ifndef CONFIG_PAX_PER_CPU_PGD
10506 load_cr3(next->pgd);
10507 +#endif
10508 +
10509 load_LDT_nolock(&next->context);
10510 +
10511 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10512 + if (!(__supported_pte_mask & _PAGE_NX))
10513 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10514 +#endif
10515 +
10516 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10517 +#ifdef CONFIG_PAX_PAGEEXEC
10518 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10519 +#endif
10520 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10521 +#endif
10522 +
10523 }
10524 +#endif
10525 }
10526 -#endif
10527 }
10528
10529 #define activate_mm(prev, next) \
10530 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10531 index 9eae775..c914fea 100644
10532 --- a/arch/x86/include/asm/module.h
10533 +++ b/arch/x86/include/asm/module.h
10534 @@ -5,6 +5,7 @@
10535
10536 #ifdef CONFIG_X86_64
10537 /* X86_64 does not define MODULE_PROC_FAMILY */
10538 +#define MODULE_PROC_FAMILY ""
10539 #elif defined CONFIG_M386
10540 #define MODULE_PROC_FAMILY "386 "
10541 #elif defined CONFIG_M486
10542 @@ -59,8 +60,20 @@
10543 #error unknown processor family
10544 #endif
10545
10546 -#ifdef CONFIG_X86_32
10547 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10548 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10549 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10550 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10551 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10552 +#else
10553 +#define MODULE_PAX_KERNEXEC ""
10554 #endif
10555
10556 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10557 +#define MODULE_PAX_UDEREF "UDEREF "
10558 +#else
10559 +#define MODULE_PAX_UDEREF ""
10560 +#endif
10561 +
10562 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10563 +
10564 #endif /* _ASM_X86_MODULE_H */
10565 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10566 index 7639dbf..e08a58c 100644
10567 --- a/arch/x86/include/asm/page_64_types.h
10568 +++ b/arch/x86/include/asm/page_64_types.h
10569 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10570
10571 /* duplicated to the one in bootmem.h */
10572 extern unsigned long max_pfn;
10573 -extern unsigned long phys_base;
10574 +extern const unsigned long phys_base;
10575
10576 extern unsigned long __phys_addr(unsigned long);
10577 #define __phys_reloc_hide(x) (x)
10578 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10579 index a7d2db9..edb023e 100644
10580 --- a/arch/x86/include/asm/paravirt.h
10581 +++ b/arch/x86/include/asm/paravirt.h
10582 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10583 val);
10584 }
10585
10586 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10587 +{
10588 + pgdval_t val = native_pgd_val(pgd);
10589 +
10590 + if (sizeof(pgdval_t) > sizeof(long))
10591 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10592 + val, (u64)val >> 32);
10593 + else
10594 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10595 + val);
10596 +}
10597 +
10598 static inline void pgd_clear(pgd_t *pgdp)
10599 {
10600 set_pgd(pgdp, __pgd(0));
10601 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10602 pv_mmu_ops.set_fixmap(idx, phys, flags);
10603 }
10604
10605 +#ifdef CONFIG_PAX_KERNEXEC
10606 +static inline unsigned long pax_open_kernel(void)
10607 +{
10608 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10609 +}
10610 +
10611 +static inline unsigned long pax_close_kernel(void)
10612 +{
10613 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10614 +}
10615 +#else
10616 +static inline unsigned long pax_open_kernel(void) { return 0; }
10617 +static inline unsigned long pax_close_kernel(void) { return 0; }
10618 +#endif
10619 +
10620 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10621
10622 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10623 @@ -964,7 +991,7 @@ extern void default_banner(void);
10624
10625 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10626 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10627 -#define PARA_INDIRECT(addr) *%cs:addr
10628 +#define PARA_INDIRECT(addr) *%ss:addr
10629 #endif
10630
10631 #define INTERRUPT_RETURN \
10632 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
10633 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10634 CLBR_NONE, \
10635 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10636 +
10637 +#define GET_CR0_INTO_RDI \
10638 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10639 + mov %rax,%rdi
10640 +
10641 +#define SET_RDI_INTO_CR0 \
10642 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10643 +
10644 +#define GET_CR3_INTO_RDI \
10645 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10646 + mov %rax,%rdi
10647 +
10648 +#define SET_RDI_INTO_CR3 \
10649 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10650 +
10651 #endif /* CONFIG_X86_32 */
10652
10653 #endif /* __ASSEMBLY__ */
10654 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10655 index 8e8b9a4..f07d725 100644
10656 --- a/arch/x86/include/asm/paravirt_types.h
10657 +++ b/arch/x86/include/asm/paravirt_types.h
10658 @@ -84,20 +84,20 @@ struct pv_init_ops {
10659 */
10660 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10661 unsigned long addr, unsigned len);
10662 -};
10663 +} __no_const;
10664
10665
10666 struct pv_lazy_ops {
10667 /* Set deferred update mode, used for batching operations. */
10668 void (*enter)(void);
10669 void (*leave)(void);
10670 -};
10671 +} __no_const;
10672
10673 struct pv_time_ops {
10674 unsigned long long (*sched_clock)(void);
10675 unsigned long long (*steal_clock)(int cpu);
10676 unsigned long (*get_tsc_khz)(void);
10677 -};
10678 +} __no_const;
10679
10680 struct pv_cpu_ops {
10681 /* hooks for various privileged instructions */
10682 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
10683
10684 void (*start_context_switch)(struct task_struct *prev);
10685 void (*end_context_switch)(struct task_struct *next);
10686 -};
10687 +} __no_const;
10688
10689 struct pv_irq_ops {
10690 /*
10691 @@ -224,7 +224,7 @@ struct pv_apic_ops {
10692 unsigned long start_eip,
10693 unsigned long start_esp);
10694 #endif
10695 -};
10696 +} __no_const;
10697
10698 struct pv_mmu_ops {
10699 unsigned long (*read_cr2)(void);
10700 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
10701 struct paravirt_callee_save make_pud;
10702
10703 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10704 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10705 #endif /* PAGETABLE_LEVELS == 4 */
10706 #endif /* PAGETABLE_LEVELS >= 3 */
10707
10708 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
10709 an mfn. We can tell which is which from the index. */
10710 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10711 phys_addr_t phys, pgprot_t flags);
10712 +
10713 +#ifdef CONFIG_PAX_KERNEXEC
10714 + unsigned long (*pax_open_kernel)(void);
10715 + unsigned long (*pax_close_kernel)(void);
10716 +#endif
10717 +
10718 };
10719
10720 struct arch_spinlock;
10721 @@ -334,7 +341,7 @@ struct pv_lock_ops {
10722 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10723 int (*spin_trylock)(struct arch_spinlock *lock);
10724 void (*spin_unlock)(struct arch_spinlock *lock);
10725 -};
10726 +} __no_const;
10727
10728 /* This contains all the paravirt structures: we get a convenient
10729 * number for each function using the offset which we use to indicate
10730 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10731 index b4389a4..b7ff22c 100644
10732 --- a/arch/x86/include/asm/pgalloc.h
10733 +++ b/arch/x86/include/asm/pgalloc.h
10734 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10735 pmd_t *pmd, pte_t *pte)
10736 {
10737 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10738 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10739 +}
10740 +
10741 +static inline void pmd_populate_user(struct mm_struct *mm,
10742 + pmd_t *pmd, pte_t *pte)
10743 +{
10744 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10745 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10746 }
10747
10748 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10749 index 98391db..8f6984e 100644
10750 --- a/arch/x86/include/asm/pgtable-2level.h
10751 +++ b/arch/x86/include/asm/pgtable-2level.h
10752 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10753
10754 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10755 {
10756 + pax_open_kernel();
10757 *pmdp = pmd;
10758 + pax_close_kernel();
10759 }
10760
10761 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10762 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10763 index effff47..f9e4035 100644
10764 --- a/arch/x86/include/asm/pgtable-3level.h
10765 +++ b/arch/x86/include/asm/pgtable-3level.h
10766 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10767
10768 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10769 {
10770 + pax_open_kernel();
10771 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10772 + pax_close_kernel();
10773 }
10774
10775 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10776 {
10777 + pax_open_kernel();
10778 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10779 + pax_close_kernel();
10780 }
10781
10782 /*
10783 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10784 index 49afb3f..ed14d07 100644
10785 --- a/arch/x86/include/asm/pgtable.h
10786 +++ b/arch/x86/include/asm/pgtable.h
10787 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10788
10789 #ifndef __PAGETABLE_PUD_FOLDED
10790 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10791 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10792 #define pgd_clear(pgd) native_pgd_clear(pgd)
10793 #endif
10794
10795 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10796
10797 #define arch_end_context_switch(prev) do {} while(0)
10798
10799 +#define pax_open_kernel() native_pax_open_kernel()
10800 +#define pax_close_kernel() native_pax_close_kernel()
10801 #endif /* CONFIG_PARAVIRT */
10802
10803 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10804 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10805 +
10806 +#ifdef CONFIG_PAX_KERNEXEC
10807 +static inline unsigned long native_pax_open_kernel(void)
10808 +{
10809 + unsigned long cr0;
10810 +
10811 + preempt_disable();
10812 + barrier();
10813 + cr0 = read_cr0() ^ X86_CR0_WP;
10814 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10815 + write_cr0(cr0);
10816 + return cr0 ^ X86_CR0_WP;
10817 +}
10818 +
10819 +static inline unsigned long native_pax_close_kernel(void)
10820 +{
10821 + unsigned long cr0;
10822 +
10823 + cr0 = read_cr0() ^ X86_CR0_WP;
10824 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10825 + write_cr0(cr0);
10826 + barrier();
10827 + preempt_enable_no_resched();
10828 + return cr0 ^ X86_CR0_WP;
10829 +}
10830 +#else
10831 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10832 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10833 +#endif
10834 +
10835 /*
10836 * The following only work if pte_present() is true.
10837 * Undefined behaviour if not..
10838 */
10839 +static inline int pte_user(pte_t pte)
10840 +{
10841 + return pte_val(pte) & _PAGE_USER;
10842 +}
10843 +
10844 static inline int pte_dirty(pte_t pte)
10845 {
10846 return pte_flags(pte) & _PAGE_DIRTY;
10847 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
10848 return pte_clear_flags(pte, _PAGE_RW);
10849 }
10850
10851 +static inline pte_t pte_mkread(pte_t pte)
10852 +{
10853 + return __pte(pte_val(pte) | _PAGE_USER);
10854 +}
10855 +
10856 static inline pte_t pte_mkexec(pte_t pte)
10857 {
10858 - return pte_clear_flags(pte, _PAGE_NX);
10859 +#ifdef CONFIG_X86_PAE
10860 + if (__supported_pte_mask & _PAGE_NX)
10861 + return pte_clear_flags(pte, _PAGE_NX);
10862 + else
10863 +#endif
10864 + return pte_set_flags(pte, _PAGE_USER);
10865 +}
10866 +
10867 +static inline pte_t pte_exprotect(pte_t pte)
10868 +{
10869 +#ifdef CONFIG_X86_PAE
10870 + if (__supported_pte_mask & _PAGE_NX)
10871 + return pte_set_flags(pte, _PAGE_NX);
10872 + else
10873 +#endif
10874 + return pte_clear_flags(pte, _PAGE_USER);
10875 }
10876
10877 static inline pte_t pte_mkdirty(pte_t pte)
10878 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
10879 #endif
10880
10881 #ifndef __ASSEMBLY__
10882 +
10883 +#ifdef CONFIG_PAX_PER_CPU_PGD
10884 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10885 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10886 +{
10887 + return cpu_pgd[cpu];
10888 +}
10889 +#endif
10890 +
10891 #include <linux/mm_types.h>
10892
10893 static inline int pte_none(pte_t pte)
10894 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
10895
10896 static inline int pgd_bad(pgd_t pgd)
10897 {
10898 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10899 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10900 }
10901
10902 static inline int pgd_none(pgd_t pgd)
10903 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
10904 * pgd_offset() returns a (pgd_t *)
10905 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10906 */
10907 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10908 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10909 +
10910 +#ifdef CONFIG_PAX_PER_CPU_PGD
10911 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10912 +#endif
10913 +
10914 /*
10915 * a shortcut which implies the use of the kernel's pgd, instead
10916 * of a process's
10917 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
10918 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10919 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10920
10921 +#ifdef CONFIG_X86_32
10922 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10923 +#else
10924 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10925 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10926 +
10927 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10928 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10929 +#else
10930 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10931 +#endif
10932 +
10933 +#endif
10934 +
10935 #ifndef __ASSEMBLY__
10936
10937 extern int direct_gbpages;
10938 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
10939 * dst and src can be on the same page, but the range must not overlap,
10940 * and must not cross a page boundary.
10941 */
10942 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10943 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10944 {
10945 - memcpy(dst, src, count * sizeof(pgd_t));
10946 + pax_open_kernel();
10947 + while (count--)
10948 + *dst++ = *src++;
10949 + pax_close_kernel();
10950 }
10951
10952 +#ifdef CONFIG_PAX_PER_CPU_PGD
10953 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10954 +#endif
10955 +
10956 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10957 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10958 +#else
10959 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10960 +#endif
10961
10962 #include <asm-generic/pgtable.h>
10963 #endif /* __ASSEMBLY__ */
10964 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
10965 index 0c92113..34a77c6 100644
10966 --- a/arch/x86/include/asm/pgtable_32.h
10967 +++ b/arch/x86/include/asm/pgtable_32.h
10968 @@ -25,9 +25,6 @@
10969 struct mm_struct;
10970 struct vm_area_struct;
10971
10972 -extern pgd_t swapper_pg_dir[1024];
10973 -extern pgd_t initial_page_table[1024];
10974 -
10975 static inline void pgtable_cache_init(void) { }
10976 static inline void check_pgt_cache(void) { }
10977 void paging_init(void);
10978 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
10979 # include <asm/pgtable-2level.h>
10980 #endif
10981
10982 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10983 +extern pgd_t initial_page_table[PTRS_PER_PGD];
10984 +#ifdef CONFIG_X86_PAE
10985 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10986 +#endif
10987 +
10988 #if defined(CONFIG_HIGHPTE)
10989 #define pte_offset_map(dir, address) \
10990 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
10991 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
10992 /* Clear a kernel PTE and flush it from the TLB */
10993 #define kpte_clear_flush(ptep, vaddr) \
10994 do { \
10995 + pax_open_kernel(); \
10996 pte_clear(&init_mm, (vaddr), (ptep)); \
10997 + pax_close_kernel(); \
10998 __flush_tlb_one((vaddr)); \
10999 } while (0)
11000
11001 @@ -74,6 +79,9 @@ do { \
11002
11003 #endif /* !__ASSEMBLY__ */
11004
11005 +#define HAVE_ARCH_UNMAPPED_AREA
11006 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11007 +
11008 /*
11009 * kern_addr_valid() is (1) for FLATMEM and (0) for
11010 * SPARSEMEM and DISCONTIGMEM
11011 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11012 index ed5903b..c7fe163 100644
11013 --- a/arch/x86/include/asm/pgtable_32_types.h
11014 +++ b/arch/x86/include/asm/pgtable_32_types.h
11015 @@ -8,7 +8,7 @@
11016 */
11017 #ifdef CONFIG_X86_PAE
11018 # include <asm/pgtable-3level_types.h>
11019 -# define PMD_SIZE (1UL << PMD_SHIFT)
11020 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11021 # define PMD_MASK (~(PMD_SIZE - 1))
11022 #else
11023 # include <asm/pgtable-2level_types.h>
11024 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11025 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11026 #endif
11027
11028 +#ifdef CONFIG_PAX_KERNEXEC
11029 +#ifndef __ASSEMBLY__
11030 +extern unsigned char MODULES_EXEC_VADDR[];
11031 +extern unsigned char MODULES_EXEC_END[];
11032 +#endif
11033 +#include <asm/boot.h>
11034 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11035 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11036 +#else
11037 +#define ktla_ktva(addr) (addr)
11038 +#define ktva_ktla(addr) (addr)
11039 +#endif
11040 +
11041 #define MODULES_VADDR VMALLOC_START
11042 #define MODULES_END VMALLOC_END
11043 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11044 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11045 index 975f709..107976d 100644
11046 --- a/arch/x86/include/asm/pgtable_64.h
11047 +++ b/arch/x86/include/asm/pgtable_64.h
11048 @@ -16,10 +16,14 @@
11049
11050 extern pud_t level3_kernel_pgt[512];
11051 extern pud_t level3_ident_pgt[512];
11052 +extern pud_t level3_vmalloc_start_pgt[512];
11053 +extern pud_t level3_vmalloc_end_pgt[512];
11054 +extern pud_t level3_vmemmap_pgt[512];
11055 +extern pud_t level2_vmemmap_pgt[512];
11056 extern pmd_t level2_kernel_pgt[512];
11057 extern pmd_t level2_fixmap_pgt[512];
11058 -extern pmd_t level2_ident_pgt[512];
11059 -extern pgd_t init_level4_pgt[];
11060 +extern pmd_t level2_ident_pgt[512*2];
11061 +extern pgd_t init_level4_pgt[512];
11062
11063 #define swapper_pg_dir init_level4_pgt
11064
11065 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11066
11067 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11068 {
11069 + pax_open_kernel();
11070 *pmdp = pmd;
11071 + pax_close_kernel();
11072 }
11073
11074 static inline void native_pmd_clear(pmd_t *pmd)
11075 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
11076
11077 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11078 {
11079 + pax_open_kernel();
11080 + *pgdp = pgd;
11081 + pax_close_kernel();
11082 +}
11083 +
11084 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11085 +{
11086 *pgdp = pgd;
11087 }
11088
11089 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11090 index 766ea16..5b96cb3 100644
11091 --- a/arch/x86/include/asm/pgtable_64_types.h
11092 +++ b/arch/x86/include/asm/pgtable_64_types.h
11093 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11094 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11095 #define MODULES_END _AC(0xffffffffff000000, UL)
11096 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11097 +#define MODULES_EXEC_VADDR MODULES_VADDR
11098 +#define MODULES_EXEC_END MODULES_END
11099 +
11100 +#define ktla_ktva(addr) (addr)
11101 +#define ktva_ktla(addr) (addr)
11102
11103 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11104 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11105 index 013286a..8b42f4f 100644
11106 --- a/arch/x86/include/asm/pgtable_types.h
11107 +++ b/arch/x86/include/asm/pgtable_types.h
11108 @@ -16,13 +16,12 @@
11109 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11110 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11111 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11112 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11113 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11114 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11115 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11116 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11117 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11118 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11119 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11120 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11121 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11122 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11123
11124 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11125 @@ -40,7 +39,6 @@
11126 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11127 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11128 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11129 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11130 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11131 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11132 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11133 @@ -57,8 +55,10 @@
11134
11135 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11136 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11137 -#else
11138 +#elif defined(CONFIG_KMEMCHECK)
11139 #define _PAGE_NX (_AT(pteval_t, 0))
11140 +#else
11141 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11142 #endif
11143
11144 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11145 @@ -96,6 +96,9 @@
11146 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11147 _PAGE_ACCESSED)
11148
11149 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11150 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11151 +
11152 #define __PAGE_KERNEL_EXEC \
11153 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11154 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11155 @@ -106,7 +109,7 @@
11156 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11157 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11158 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11159 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11160 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11161 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11162 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11163 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11164 @@ -168,8 +171,8 @@
11165 * bits are combined, this will alow user to access the high address mapped
11166 * VDSO in the presence of CONFIG_COMPAT_VDSO
11167 */
11168 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11169 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11170 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11171 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11172 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11173 #endif
11174
11175 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11176 {
11177 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11178 }
11179 +#endif
11180
11181 +#if PAGETABLE_LEVELS == 3
11182 +#include <asm-generic/pgtable-nopud.h>
11183 +#endif
11184 +
11185 +#if PAGETABLE_LEVELS == 2
11186 +#include <asm-generic/pgtable-nopmd.h>
11187 +#endif
11188 +
11189 +#ifndef __ASSEMBLY__
11190 #if PAGETABLE_LEVELS > 3
11191 typedef struct { pudval_t pud; } pud_t;
11192
11193 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11194 return pud.pud;
11195 }
11196 #else
11197 -#include <asm-generic/pgtable-nopud.h>
11198 -
11199 static inline pudval_t native_pud_val(pud_t pud)
11200 {
11201 return native_pgd_val(pud.pgd);
11202 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11203 return pmd.pmd;
11204 }
11205 #else
11206 -#include <asm-generic/pgtable-nopmd.h>
11207 -
11208 static inline pmdval_t native_pmd_val(pmd_t pmd)
11209 {
11210 return native_pgd_val(pmd.pud.pgd);
11211 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11212
11213 extern pteval_t __supported_pte_mask;
11214 extern void set_nx(void);
11215 -extern int nx_enabled;
11216
11217 #define pgprot_writecombine pgprot_writecombine
11218 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11219 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11220 index 58545c9..fe6fc38e 100644
11221 --- a/arch/x86/include/asm/processor.h
11222 +++ b/arch/x86/include/asm/processor.h
11223 @@ -266,7 +266,7 @@ struct tss_struct {
11224
11225 } ____cacheline_aligned;
11226
11227 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11228 +extern struct tss_struct init_tss[NR_CPUS];
11229
11230 /*
11231 * Save the original ist values for checking stack pointers during debugging
11232 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11233 */
11234 #define TASK_SIZE PAGE_OFFSET
11235 #define TASK_SIZE_MAX TASK_SIZE
11236 +
11237 +#ifdef CONFIG_PAX_SEGMEXEC
11238 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11239 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11240 +#else
11241 #define STACK_TOP TASK_SIZE
11242 -#define STACK_TOP_MAX STACK_TOP
11243 +#endif
11244 +
11245 +#define STACK_TOP_MAX TASK_SIZE
11246
11247 #define INIT_THREAD { \
11248 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11249 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11250 .vm86_info = NULL, \
11251 .sysenter_cs = __KERNEL_CS, \
11252 .io_bitmap_ptr = NULL, \
11253 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11254 */
11255 #define INIT_TSS { \
11256 .x86_tss = { \
11257 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11258 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11259 .ss0 = __KERNEL_DS, \
11260 .ss1 = __KERNEL_CS, \
11261 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11262 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11263 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11264
11265 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11266 -#define KSTK_TOP(info) \
11267 -({ \
11268 - unsigned long *__ptr = (unsigned long *)(info); \
11269 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11270 -})
11271 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11272
11273 /*
11274 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11275 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11276 #define task_pt_regs(task) \
11277 ({ \
11278 struct pt_regs *__regs__; \
11279 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11280 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11281 __regs__ - 1; \
11282 })
11283
11284 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11285 /*
11286 * User space process size. 47bits minus one guard page.
11287 */
11288 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11289 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11290
11291 /* This decides where the kernel will search for a free chunk of vm
11292 * space during mmap's.
11293 */
11294 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11295 - 0xc0000000 : 0xFFFFe000)
11296 + 0xc0000000 : 0xFFFFf000)
11297
11298 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11299 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11300 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11301 #define STACK_TOP_MAX TASK_SIZE_MAX
11302
11303 #define INIT_THREAD { \
11304 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11305 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11306 }
11307
11308 #define INIT_TSS { \
11309 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11310 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11311 }
11312
11313 /*
11314 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11315 */
11316 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11317
11318 +#ifdef CONFIG_PAX_SEGMEXEC
11319 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11320 +#endif
11321 +
11322 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11323
11324 /* Get/set a process' ability to use the timestamp counter instruction */
11325 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11326 index 3566454..4bdfb8c 100644
11327 --- a/arch/x86/include/asm/ptrace.h
11328 +++ b/arch/x86/include/asm/ptrace.h
11329 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11330 }
11331
11332 /*
11333 - * user_mode_vm(regs) determines whether a register set came from user mode.
11334 + * user_mode(regs) determines whether a register set came from user mode.
11335 * This is true if V8086 mode was enabled OR if the register set was from
11336 * protected mode with RPL-3 CS value. This tricky test checks that with
11337 * one comparison. Many places in the kernel can bypass this full check
11338 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11339 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11340 + * be used.
11341 */
11342 -static inline int user_mode(struct pt_regs *regs)
11343 +static inline int user_mode_novm(struct pt_regs *regs)
11344 {
11345 #ifdef CONFIG_X86_32
11346 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11347 #else
11348 - return !!(regs->cs & 3);
11349 + return !!(regs->cs & SEGMENT_RPL_MASK);
11350 #endif
11351 }
11352
11353 -static inline int user_mode_vm(struct pt_regs *regs)
11354 +static inline int user_mode(struct pt_regs *regs)
11355 {
11356 #ifdef CONFIG_X86_32
11357 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11358 USER_RPL;
11359 #else
11360 - return user_mode(regs);
11361 + return user_mode_novm(regs);
11362 #endif
11363 }
11364
11365 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11366 #ifdef CONFIG_X86_64
11367 static inline bool user_64bit_mode(struct pt_regs *regs)
11368 {
11369 + unsigned long cs = regs->cs & 0xffff;
11370 #ifndef CONFIG_PARAVIRT
11371 /*
11372 * On non-paravirt systems, this is the only long mode CPL 3
11373 * selector. We do not allow long mode selectors in the LDT.
11374 */
11375 - return regs->cs == __USER_CS;
11376 + return cs == __USER_CS;
11377 #else
11378 /* Headers are too twisted for this to go in paravirt.h. */
11379 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11380 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11381 #endif
11382 }
11383 #endif
11384 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11385 index 92f29706..a79cbbb 100644
11386 --- a/arch/x86/include/asm/reboot.h
11387 +++ b/arch/x86/include/asm/reboot.h
11388 @@ -6,19 +6,19 @@
11389 struct pt_regs;
11390
11391 struct machine_ops {
11392 - void (*restart)(char *cmd);
11393 - void (*halt)(void);
11394 - void (*power_off)(void);
11395 + void (* __noreturn restart)(char *cmd);
11396 + void (* __noreturn halt)(void);
11397 + void (* __noreturn power_off)(void);
11398 void (*shutdown)(void);
11399 void (*crash_shutdown)(struct pt_regs *);
11400 - void (*emergency_restart)(void);
11401 -};
11402 + void (* __noreturn emergency_restart)(void);
11403 +} __no_const;
11404
11405 extern struct machine_ops machine_ops;
11406
11407 void native_machine_crash_shutdown(struct pt_regs *regs);
11408 void native_machine_shutdown(void);
11409 -void machine_real_restart(unsigned int type);
11410 +void machine_real_restart(unsigned int type) __noreturn;
11411 /* These must match dispatch_table in reboot_32.S */
11412 #define MRR_BIOS 0
11413 #define MRR_APM 1
11414 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11415 index 2dbe4a7..ce1db00 100644
11416 --- a/arch/x86/include/asm/rwsem.h
11417 +++ b/arch/x86/include/asm/rwsem.h
11418 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11419 {
11420 asm volatile("# beginning down_read\n\t"
11421 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11422 +
11423 +#ifdef CONFIG_PAX_REFCOUNT
11424 + "jno 0f\n"
11425 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11426 + "int $4\n0:\n"
11427 + _ASM_EXTABLE(0b, 0b)
11428 +#endif
11429 +
11430 /* adds 0x00000001 */
11431 " jns 1f\n"
11432 " call call_rwsem_down_read_failed\n"
11433 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11434 "1:\n\t"
11435 " mov %1,%2\n\t"
11436 " add %3,%2\n\t"
11437 +
11438 +#ifdef CONFIG_PAX_REFCOUNT
11439 + "jno 0f\n"
11440 + "sub %3,%2\n"
11441 + "int $4\n0:\n"
11442 + _ASM_EXTABLE(0b, 0b)
11443 +#endif
11444 +
11445 " jle 2f\n\t"
11446 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11447 " jnz 1b\n\t"
11448 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11449 long tmp;
11450 asm volatile("# beginning down_write\n\t"
11451 LOCK_PREFIX " xadd %1,(%2)\n\t"
11452 +
11453 +#ifdef CONFIG_PAX_REFCOUNT
11454 + "jno 0f\n"
11455 + "mov %1,(%2)\n"
11456 + "int $4\n0:\n"
11457 + _ASM_EXTABLE(0b, 0b)
11458 +#endif
11459 +
11460 /* adds 0xffff0001, returns the old value */
11461 " test %1,%1\n\t"
11462 /* was the count 0 before? */
11463 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11464 long tmp;
11465 asm volatile("# beginning __up_read\n\t"
11466 LOCK_PREFIX " xadd %1,(%2)\n\t"
11467 +
11468 +#ifdef CONFIG_PAX_REFCOUNT
11469 + "jno 0f\n"
11470 + "mov %1,(%2)\n"
11471 + "int $4\n0:\n"
11472 + _ASM_EXTABLE(0b, 0b)
11473 +#endif
11474 +
11475 /* subtracts 1, returns the old value */
11476 " jns 1f\n\t"
11477 " call call_rwsem_wake\n" /* expects old value in %edx */
11478 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11479 long tmp;
11480 asm volatile("# beginning __up_write\n\t"
11481 LOCK_PREFIX " xadd %1,(%2)\n\t"
11482 +
11483 +#ifdef CONFIG_PAX_REFCOUNT
11484 + "jno 0f\n"
11485 + "mov %1,(%2)\n"
11486 + "int $4\n0:\n"
11487 + _ASM_EXTABLE(0b, 0b)
11488 +#endif
11489 +
11490 /* subtracts 0xffff0001, returns the old value */
11491 " jns 1f\n\t"
11492 " call call_rwsem_wake\n" /* expects old value in %edx */
11493 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11494 {
11495 asm volatile("# beginning __downgrade_write\n\t"
11496 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11497 +
11498 +#ifdef CONFIG_PAX_REFCOUNT
11499 + "jno 0f\n"
11500 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11501 + "int $4\n0:\n"
11502 + _ASM_EXTABLE(0b, 0b)
11503 +#endif
11504 +
11505 /*
11506 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11507 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11508 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11509 */
11510 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11511 {
11512 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11513 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11514 +
11515 +#ifdef CONFIG_PAX_REFCOUNT
11516 + "jno 0f\n"
11517 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11518 + "int $4\n0:\n"
11519 + _ASM_EXTABLE(0b, 0b)
11520 +#endif
11521 +
11522 : "+m" (sem->count)
11523 : "er" (delta));
11524 }
11525 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11526 */
11527 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11528 {
11529 - return delta + xadd(&sem->count, delta);
11530 + return delta + xadd_check_overflow(&sem->count, delta);
11531 }
11532
11533 #endif /* __KERNEL__ */
11534 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11535 index 5e64171..f58957e 100644
11536 --- a/arch/x86/include/asm/segment.h
11537 +++ b/arch/x86/include/asm/segment.h
11538 @@ -64,10 +64,15 @@
11539 * 26 - ESPFIX small SS
11540 * 27 - per-cpu [ offset to per-cpu data area ]
11541 * 28 - stack_canary-20 [ for stack protector ]
11542 - * 29 - unused
11543 - * 30 - unused
11544 + * 29 - PCI BIOS CS
11545 + * 30 - PCI BIOS DS
11546 * 31 - TSS for double fault handler
11547 */
11548 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11549 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11550 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11551 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11552 +
11553 #define GDT_ENTRY_TLS_MIN 6
11554 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11555
11556 @@ -79,6 +84,8 @@
11557
11558 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11559
11560 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11561 +
11562 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11563
11564 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11565 @@ -104,6 +111,12 @@
11566 #define __KERNEL_STACK_CANARY 0
11567 #endif
11568
11569 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11570 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11571 +
11572 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11573 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11574 +
11575 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11576
11577 /*
11578 @@ -141,7 +154,7 @@
11579 */
11580
11581 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11582 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11583 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11584
11585
11586 #else
11587 @@ -165,6 +178,8 @@
11588 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11589 #define __USER32_DS __USER_DS
11590
11591 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11592 +
11593 #define GDT_ENTRY_TSS 8 /* needs two entries */
11594 #define GDT_ENTRY_LDT 10 /* needs two entries */
11595 #define GDT_ENTRY_TLS_MIN 12
11596 @@ -185,6 +200,7 @@
11597 #endif
11598
11599 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11600 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11601 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11602 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11603 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11604 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11605 index 0434c40..1714bf0 100644
11606 --- a/arch/x86/include/asm/smp.h
11607 +++ b/arch/x86/include/asm/smp.h
11608 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11609 /* cpus sharing the last level cache: */
11610 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11611 DECLARE_PER_CPU(u16, cpu_llc_id);
11612 -DECLARE_PER_CPU(int, cpu_number);
11613 +DECLARE_PER_CPU(unsigned int, cpu_number);
11614
11615 static inline struct cpumask *cpu_sibling_mask(int cpu)
11616 {
11617 @@ -77,7 +77,7 @@ struct smp_ops {
11618
11619 void (*send_call_func_ipi)(const struct cpumask *mask);
11620 void (*send_call_func_single_ipi)(int cpu);
11621 -};
11622 +} __no_const;
11623
11624 /* Globals due to paravirt */
11625 extern void set_cpu_sibling_map(int cpu);
11626 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11627 extern int safe_smp_processor_id(void);
11628
11629 #elif defined(CONFIG_X86_64_SMP)
11630 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11631 -
11632 -#define stack_smp_processor_id() \
11633 -({ \
11634 - struct thread_info *ti; \
11635 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11636 - ti->cpu; \
11637 -})
11638 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11639 +#define stack_smp_processor_id() raw_smp_processor_id()
11640 #define safe_smp_processor_id() smp_processor_id()
11641
11642 #endif
11643 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11644 index a82c2bf..2198f61 100644
11645 --- a/arch/x86/include/asm/spinlock.h
11646 +++ b/arch/x86/include/asm/spinlock.h
11647 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11648 static inline void arch_read_lock(arch_rwlock_t *rw)
11649 {
11650 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11651 +
11652 +#ifdef CONFIG_PAX_REFCOUNT
11653 + "jno 0f\n"
11654 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11655 + "int $4\n0:\n"
11656 + _ASM_EXTABLE(0b, 0b)
11657 +#endif
11658 +
11659 "jns 1f\n"
11660 "call __read_lock_failed\n\t"
11661 "1:\n"
11662 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11663 static inline void arch_write_lock(arch_rwlock_t *rw)
11664 {
11665 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11666 +
11667 +#ifdef CONFIG_PAX_REFCOUNT
11668 + "jno 0f\n"
11669 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11670 + "int $4\n0:\n"
11671 + _ASM_EXTABLE(0b, 0b)
11672 +#endif
11673 +
11674 "jz 1f\n"
11675 "call __write_lock_failed\n\t"
11676 "1:\n"
11677 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11678
11679 static inline void arch_read_unlock(arch_rwlock_t *rw)
11680 {
11681 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11682 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11683 +
11684 +#ifdef CONFIG_PAX_REFCOUNT
11685 + "jno 0f\n"
11686 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11687 + "int $4\n0:\n"
11688 + _ASM_EXTABLE(0b, 0b)
11689 +#endif
11690 +
11691 :"+m" (rw->lock) : : "memory");
11692 }
11693
11694 static inline void arch_write_unlock(arch_rwlock_t *rw)
11695 {
11696 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11697 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11698 +
11699 +#ifdef CONFIG_PAX_REFCOUNT
11700 + "jno 0f\n"
11701 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11702 + "int $4\n0:\n"
11703 + _ASM_EXTABLE(0b, 0b)
11704 +#endif
11705 +
11706 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11707 }
11708
11709 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11710 index 1575177..cb23f52 100644
11711 --- a/arch/x86/include/asm/stackprotector.h
11712 +++ b/arch/x86/include/asm/stackprotector.h
11713 @@ -48,7 +48,7 @@
11714 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11715 */
11716 #define GDT_STACK_CANARY_INIT \
11717 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11718 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11719
11720 /*
11721 * Initialize the stackprotector canary value.
11722 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11723
11724 static inline void load_stack_canary_segment(void)
11725 {
11726 -#ifdef CONFIG_X86_32
11727 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11728 asm volatile ("mov %0, %%gs" : : "r" (0));
11729 #endif
11730 }
11731 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
11732 index 70bbe39..4ae2bd4 100644
11733 --- a/arch/x86/include/asm/stacktrace.h
11734 +++ b/arch/x86/include/asm/stacktrace.h
11735 @@ -11,28 +11,20 @@
11736
11737 extern int kstack_depth_to_print;
11738
11739 -struct thread_info;
11740 +struct task_struct;
11741 struct stacktrace_ops;
11742
11743 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11744 - unsigned long *stack,
11745 - unsigned long bp,
11746 - const struct stacktrace_ops *ops,
11747 - void *data,
11748 - unsigned long *end,
11749 - int *graph);
11750 +typedef unsigned long walk_stack_t(struct task_struct *task,
11751 + void *stack_start,
11752 + unsigned long *stack,
11753 + unsigned long bp,
11754 + const struct stacktrace_ops *ops,
11755 + void *data,
11756 + unsigned long *end,
11757 + int *graph);
11758
11759 -extern unsigned long
11760 -print_context_stack(struct thread_info *tinfo,
11761 - unsigned long *stack, unsigned long bp,
11762 - const struct stacktrace_ops *ops, void *data,
11763 - unsigned long *end, int *graph);
11764 -
11765 -extern unsigned long
11766 -print_context_stack_bp(struct thread_info *tinfo,
11767 - unsigned long *stack, unsigned long bp,
11768 - const struct stacktrace_ops *ops, void *data,
11769 - unsigned long *end, int *graph);
11770 +extern walk_stack_t print_context_stack;
11771 +extern walk_stack_t print_context_stack_bp;
11772
11773 /* Generic stack tracer with callbacks */
11774
11775 @@ -40,7 +32,7 @@ struct stacktrace_ops {
11776 void (*address)(void *data, unsigned long address, int reliable);
11777 /* On negative return stop dumping */
11778 int (*stack)(void *data, char *name);
11779 - walk_stack_t walk_stack;
11780 + walk_stack_t *walk_stack;
11781 };
11782
11783 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11784 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
11785 index cb23852..2dde194 100644
11786 --- a/arch/x86/include/asm/sys_ia32.h
11787 +++ b/arch/x86/include/asm/sys_ia32.h
11788 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
11789 compat_sigset_t __user *, unsigned int);
11790 asmlinkage long sys32_alarm(unsigned int);
11791
11792 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
11793 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
11794 asmlinkage long sys32_sysfs(int, u32, u32);
11795
11796 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
11797 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11798 index 2d2f01c..f985723 100644
11799 --- a/arch/x86/include/asm/system.h
11800 +++ b/arch/x86/include/asm/system.h
11801 @@ -129,7 +129,7 @@ do { \
11802 "call __switch_to\n\t" \
11803 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11804 __switch_canary \
11805 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11806 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11807 "movq %%rax,%%rdi\n\t" \
11808 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11809 "jnz ret_from_fork\n\t" \
11810 @@ -140,7 +140,7 @@ do { \
11811 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11812 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11813 [_tif_fork] "i" (_TIF_FORK), \
11814 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11815 + [thread_info] "m" (current_tinfo), \
11816 [current_task] "m" (current_task) \
11817 __switch_canary_iparam \
11818 : "memory", "cc" __EXTRA_CLOBBER)
11819 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11820 {
11821 unsigned long __limit;
11822 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11823 - return __limit + 1;
11824 + return __limit;
11825 }
11826
11827 static inline void native_clts(void)
11828 @@ -397,13 +397,13 @@ void enable_hlt(void);
11829
11830 void cpu_idle_wait(void);
11831
11832 -extern unsigned long arch_align_stack(unsigned long sp);
11833 +#define arch_align_stack(x) ((x) & ~0xfUL)
11834 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11835
11836 void default_idle(void);
11837 bool set_pm_idle_to_default(void);
11838
11839 -void stop_this_cpu(void *dummy);
11840 +void stop_this_cpu(void *dummy) __noreturn;
11841
11842 /*
11843 * Force strict CPU ordering.
11844 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11845 index cfd8144..1b1127d 100644
11846 --- a/arch/x86/include/asm/thread_info.h
11847 +++ b/arch/x86/include/asm/thread_info.h
11848 @@ -10,6 +10,7 @@
11849 #include <linux/compiler.h>
11850 #include <asm/page.h>
11851 #include <asm/types.h>
11852 +#include <asm/percpu.h>
11853
11854 /*
11855 * low level task data that entry.S needs immediate access to
11856 @@ -24,7 +25,6 @@ struct exec_domain;
11857 #include <linux/atomic.h>
11858
11859 struct thread_info {
11860 - struct task_struct *task; /* main task structure */
11861 struct exec_domain *exec_domain; /* execution domain */
11862 __u32 flags; /* low level flags */
11863 __u32 status; /* thread synchronous flags */
11864 @@ -34,19 +34,13 @@ struct thread_info {
11865 mm_segment_t addr_limit;
11866 struct restart_block restart_block;
11867 void __user *sysenter_return;
11868 -#ifdef CONFIG_X86_32
11869 - unsigned long previous_esp; /* ESP of the previous stack in
11870 - case of nested (IRQ) stacks
11871 - */
11872 - __u8 supervisor_stack[0];
11873 -#endif
11874 + unsigned long lowest_stack;
11875 unsigned int sig_on_uaccess_error:1;
11876 unsigned int uaccess_err:1; /* uaccess failed */
11877 };
11878
11879 -#define INIT_THREAD_INFO(tsk) \
11880 +#define INIT_THREAD_INFO \
11881 { \
11882 - .task = &tsk, \
11883 .exec_domain = &default_exec_domain, \
11884 .flags = 0, \
11885 .cpu = 0, \
11886 @@ -57,7 +51,7 @@ struct thread_info {
11887 }, \
11888 }
11889
11890 -#define init_thread_info (init_thread_union.thread_info)
11891 +#define init_thread_info (init_thread_union.stack)
11892 #define init_stack (init_thread_union.stack)
11893
11894 #else /* !__ASSEMBLY__ */
11895 @@ -169,45 +163,40 @@ struct thread_info {
11896 ret; \
11897 })
11898
11899 -#ifdef CONFIG_X86_32
11900 -
11901 -#define STACK_WARN (THREAD_SIZE/8)
11902 -/*
11903 - * macros/functions for gaining access to the thread information structure
11904 - *
11905 - * preempt_count needs to be 1 initially, until the scheduler is functional.
11906 - */
11907 -#ifndef __ASSEMBLY__
11908 -
11909 -
11910 -/* how to get the current stack pointer from C */
11911 -register unsigned long current_stack_pointer asm("esp") __used;
11912 -
11913 -/* how to get the thread information struct from C */
11914 -static inline struct thread_info *current_thread_info(void)
11915 -{
11916 - return (struct thread_info *)
11917 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11918 -}
11919 -
11920 -#else /* !__ASSEMBLY__ */
11921 -
11922 +#ifdef __ASSEMBLY__
11923 /* how to get the thread information struct from ASM */
11924 #define GET_THREAD_INFO(reg) \
11925 - movl $-THREAD_SIZE, reg; \
11926 - andl %esp, reg
11927 + mov PER_CPU_VAR(current_tinfo), reg
11928
11929 /* use this one if reg already contains %esp */
11930 -#define GET_THREAD_INFO_WITH_ESP(reg) \
11931 - andl $-THREAD_SIZE, reg
11932 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11933 +#else
11934 +/* how to get the thread information struct from C */
11935 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11936 +
11937 +static __always_inline struct thread_info *current_thread_info(void)
11938 +{
11939 + return percpu_read_stable(current_tinfo);
11940 +}
11941 +#endif
11942 +
11943 +#ifdef CONFIG_X86_32
11944 +
11945 +#define STACK_WARN (THREAD_SIZE/8)
11946 +/*
11947 + * macros/functions for gaining access to the thread information structure
11948 + *
11949 + * preempt_count needs to be 1 initially, until the scheduler is functional.
11950 + */
11951 +#ifndef __ASSEMBLY__
11952 +
11953 +/* how to get the current stack pointer from C */
11954 +register unsigned long current_stack_pointer asm("esp") __used;
11955
11956 #endif
11957
11958 #else /* X86_32 */
11959
11960 -#include <asm/percpu.h>
11961 -#define KERNEL_STACK_OFFSET (5*8)
11962 -
11963 /*
11964 * macros/functions for gaining access to the thread information structure
11965 * preempt_count needs to be 1 initially, until the scheduler is functional.
11966 @@ -215,27 +204,8 @@ static inline struct thread_info *current_thread_info(void)
11967 #ifndef __ASSEMBLY__
11968 DECLARE_PER_CPU(unsigned long, kernel_stack);
11969
11970 -static inline struct thread_info *current_thread_info(void)
11971 -{
11972 - struct thread_info *ti;
11973 - ti = (void *)(percpu_read_stable(kernel_stack) +
11974 - KERNEL_STACK_OFFSET - THREAD_SIZE);
11975 - return ti;
11976 -}
11977 -
11978 -#else /* !__ASSEMBLY__ */
11979 -
11980 -/* how to get the thread information struct from ASM */
11981 -#define GET_THREAD_INFO(reg) \
11982 - movq PER_CPU_VAR(kernel_stack),reg ; \
11983 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11984 -
11985 -/*
11986 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
11987 - * a certain register (to be used in assembler memory operands).
11988 - */
11989 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
11990 -
11991 +/* how to get the current stack pointer from C */
11992 +register unsigned long current_stack_pointer asm("rsp") __used;
11993 #endif
11994
11995 #endif /* !X86_32 */
11996 @@ -269,5 +239,16 @@ extern void arch_task_cache_init(void);
11997 extern void free_thread_info(struct thread_info *ti);
11998 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
11999 #define arch_task_cache_init arch_task_cache_init
12000 +
12001 +#define __HAVE_THREAD_FUNCTIONS
12002 +#define task_thread_info(task) (&(task)->tinfo)
12003 +#define task_stack_page(task) ((task)->stack)
12004 +#define setup_thread_stack(p, org) do {} while (0)
12005 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12006 +
12007 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12008 +extern struct task_struct *alloc_task_struct_node(int node);
12009 +extern void free_task_struct(struct task_struct *);
12010 +
12011 #endif
12012 #endif /* _ASM_X86_THREAD_INFO_H */
12013 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12014 index 8be5f54..7ae826d 100644
12015 --- a/arch/x86/include/asm/uaccess.h
12016 +++ b/arch/x86/include/asm/uaccess.h
12017 @@ -7,12 +7,15 @@
12018 #include <linux/compiler.h>
12019 #include <linux/thread_info.h>
12020 #include <linux/string.h>
12021 +#include <linux/sched.h>
12022 #include <asm/asm.h>
12023 #include <asm/page.h>
12024
12025 #define VERIFY_READ 0
12026 #define VERIFY_WRITE 1
12027
12028 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12029 +
12030 /*
12031 * The fs value determines whether argument validity checking should be
12032 * performed or not. If get_fs() == USER_DS, checking is performed, with
12033 @@ -28,7 +31,12 @@
12034
12035 #define get_ds() (KERNEL_DS)
12036 #define get_fs() (current_thread_info()->addr_limit)
12037 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12038 +void __set_fs(mm_segment_t x);
12039 +void set_fs(mm_segment_t x);
12040 +#else
12041 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12042 +#endif
12043
12044 #define segment_eq(a, b) ((a).seg == (b).seg)
12045
12046 @@ -76,7 +84,33 @@
12047 * checks that the pointer is in the user space range - after calling
12048 * this function, memory access functions may still return -EFAULT.
12049 */
12050 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12051 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12052 +#define access_ok(type, addr, size) \
12053 +({ \
12054 + long __size = size; \
12055 + unsigned long __addr = (unsigned long)addr; \
12056 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12057 + unsigned long __end_ao = __addr + __size - 1; \
12058 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12059 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12060 + while(__addr_ao <= __end_ao) { \
12061 + char __c_ao; \
12062 + __addr_ao += PAGE_SIZE; \
12063 + if (__size > PAGE_SIZE) \
12064 + cond_resched(); \
12065 + if (__get_user(__c_ao, (char __user *)__addr)) \
12066 + break; \
12067 + if (type != VERIFY_WRITE) { \
12068 + __addr = __addr_ao; \
12069 + continue; \
12070 + } \
12071 + if (__put_user(__c_ao, (char __user *)__addr)) \
12072 + break; \
12073 + __addr = __addr_ao; \
12074 + } \
12075 + } \
12076 + __ret_ao; \
12077 +})
12078
12079 /*
12080 * The exception table consists of pairs of addresses: the first is the
12081 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12082 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12083 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12084
12085 -
12086 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12087 +#define __copyuser_seg "gs;"
12088 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12089 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12090 +#else
12091 +#define __copyuser_seg
12092 +#define __COPYUSER_SET_ES
12093 +#define __COPYUSER_RESTORE_ES
12094 +#endif
12095
12096 #ifdef CONFIG_X86_32
12097 #define __put_user_asm_u64(x, addr, err, errret) \
12098 - asm volatile("1: movl %%eax,0(%2)\n" \
12099 - "2: movl %%edx,4(%2)\n" \
12100 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12101 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12102 "3:\n" \
12103 ".section .fixup,\"ax\"\n" \
12104 "4: movl %3,%0\n" \
12105 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12106 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12107
12108 #define __put_user_asm_ex_u64(x, addr) \
12109 - asm volatile("1: movl %%eax,0(%1)\n" \
12110 - "2: movl %%edx,4(%1)\n" \
12111 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12112 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12113 "3:\n" \
12114 _ASM_EXTABLE(1b, 2b - 1b) \
12115 _ASM_EXTABLE(2b, 3b - 2b) \
12116 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12117 __typeof__(*(ptr)) __pu_val; \
12118 __chk_user_ptr(ptr); \
12119 might_fault(); \
12120 - __pu_val = x; \
12121 + __pu_val = (x); \
12122 switch (sizeof(*(ptr))) { \
12123 case 1: \
12124 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12125 @@ -373,7 +415,7 @@ do { \
12126 } while (0)
12127
12128 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12129 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12130 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12131 "2:\n" \
12132 ".section .fixup,\"ax\"\n" \
12133 "3: mov %3,%0\n" \
12134 @@ -381,7 +423,7 @@ do { \
12135 " jmp 2b\n" \
12136 ".previous\n" \
12137 _ASM_EXTABLE(1b, 3b) \
12138 - : "=r" (err), ltype(x) \
12139 + : "=r" (err), ltype (x) \
12140 : "m" (__m(addr)), "i" (errret), "0" (err))
12141
12142 #define __get_user_size_ex(x, ptr, size) \
12143 @@ -406,7 +448,7 @@ do { \
12144 } while (0)
12145
12146 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12147 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12148 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12149 "2:\n" \
12150 _ASM_EXTABLE(1b, 2b - 1b) \
12151 : ltype(x) : "m" (__m(addr)))
12152 @@ -423,13 +465,24 @@ do { \
12153 int __gu_err; \
12154 unsigned long __gu_val; \
12155 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12156 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12157 + (x) = (__typeof__(*(ptr)))__gu_val; \
12158 __gu_err; \
12159 })
12160
12161 /* FIXME: this hack is definitely wrong -AK */
12162 struct __large_struct { unsigned long buf[100]; };
12163 -#define __m(x) (*(struct __large_struct __user *)(x))
12164 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12165 +#define ____m(x) \
12166 +({ \
12167 + unsigned long ____x = (unsigned long)(x); \
12168 + if (____x < PAX_USER_SHADOW_BASE) \
12169 + ____x += PAX_USER_SHADOW_BASE; \
12170 + (void __user *)____x; \
12171 +})
12172 +#else
12173 +#define ____m(x) (x)
12174 +#endif
12175 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12176
12177 /*
12178 * Tell gcc we read from memory instead of writing: this is because
12179 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12180 * aliasing issues.
12181 */
12182 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12183 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12184 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12185 "2:\n" \
12186 ".section .fixup,\"ax\"\n" \
12187 "3: mov %3,%0\n" \
12188 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12189 ".previous\n" \
12190 _ASM_EXTABLE(1b, 3b) \
12191 : "=r"(err) \
12192 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12193 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12194
12195 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12196 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12197 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12198 "2:\n" \
12199 _ASM_EXTABLE(1b, 2b - 1b) \
12200 : : ltype(x), "m" (__m(addr)))
12201 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12202 * On error, the variable @x is set to zero.
12203 */
12204
12205 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12206 +#define __get_user(x, ptr) get_user((x), (ptr))
12207 +#else
12208 #define __get_user(x, ptr) \
12209 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12210 +#endif
12211
12212 /**
12213 * __put_user: - Write a simple value into user space, with less checking.
12214 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12215 * Returns zero on success, or -EFAULT on error.
12216 */
12217
12218 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12219 +#define __put_user(x, ptr) put_user((x), (ptr))
12220 +#else
12221 #define __put_user(x, ptr) \
12222 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12223 +#endif
12224
12225 #define __get_user_unaligned __get_user
12226 #define __put_user_unaligned __put_user
12227 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12228 #define get_user_ex(x, ptr) do { \
12229 unsigned long __gue_val; \
12230 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12231 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12232 + (x) = (__typeof__(*(ptr)))__gue_val; \
12233 } while (0)
12234
12235 #ifdef CONFIG_X86_WP_WORKS_OK
12236 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12237 index 566e803..b9521e9 100644
12238 --- a/arch/x86/include/asm/uaccess_32.h
12239 +++ b/arch/x86/include/asm/uaccess_32.h
12240 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12241 static __always_inline unsigned long __must_check
12242 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12243 {
12244 + if ((long)n < 0)
12245 + return n;
12246 +
12247 if (__builtin_constant_p(n)) {
12248 unsigned long ret;
12249
12250 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12251 return ret;
12252 }
12253 }
12254 + if (!__builtin_constant_p(n))
12255 + check_object_size(from, n, true);
12256 return __copy_to_user_ll(to, from, n);
12257 }
12258
12259 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12260 __copy_to_user(void __user *to, const void *from, unsigned long n)
12261 {
12262 might_fault();
12263 +
12264 return __copy_to_user_inatomic(to, from, n);
12265 }
12266
12267 static __always_inline unsigned long
12268 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12269 {
12270 + if ((long)n < 0)
12271 + return n;
12272 +
12273 /* Avoid zeroing the tail if the copy fails..
12274 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12275 * but as the zeroing behaviour is only significant when n is not
12276 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12277 __copy_from_user(void *to, const void __user *from, unsigned long n)
12278 {
12279 might_fault();
12280 +
12281 + if ((long)n < 0)
12282 + return n;
12283 +
12284 if (__builtin_constant_p(n)) {
12285 unsigned long ret;
12286
12287 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12288 return ret;
12289 }
12290 }
12291 + if (!__builtin_constant_p(n))
12292 + check_object_size(to, n, false);
12293 return __copy_from_user_ll(to, from, n);
12294 }
12295
12296 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12297 const void __user *from, unsigned long n)
12298 {
12299 might_fault();
12300 +
12301 + if ((long)n < 0)
12302 + return n;
12303 +
12304 if (__builtin_constant_p(n)) {
12305 unsigned long ret;
12306
12307 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12308 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12309 unsigned long n)
12310 {
12311 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12312 + if ((long)n < 0)
12313 + return n;
12314 +
12315 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12316 }
12317
12318 -unsigned long __must_check copy_to_user(void __user *to,
12319 - const void *from, unsigned long n);
12320 -unsigned long __must_check _copy_from_user(void *to,
12321 - const void __user *from,
12322 - unsigned long n);
12323 -
12324 +extern void copy_to_user_overflow(void)
12325 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12326 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12327 +#else
12328 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12329 +#endif
12330 +;
12331
12332 extern void copy_from_user_overflow(void)
12333 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12334 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12335 #endif
12336 ;
12337
12338 -static inline unsigned long __must_check copy_from_user(void *to,
12339 - const void __user *from,
12340 - unsigned long n)
12341 +/**
12342 + * copy_to_user: - Copy a block of data into user space.
12343 + * @to: Destination address, in user space.
12344 + * @from: Source address, in kernel space.
12345 + * @n: Number of bytes to copy.
12346 + *
12347 + * Context: User context only. This function may sleep.
12348 + *
12349 + * Copy data from kernel space to user space.
12350 + *
12351 + * Returns number of bytes that could not be copied.
12352 + * On success, this will be zero.
12353 + */
12354 +static inline unsigned long __must_check
12355 +copy_to_user(void __user *to, const void *from, unsigned long n)
12356 +{
12357 + int sz = __compiletime_object_size(from);
12358 +
12359 + if (unlikely(sz != -1 && sz < n))
12360 + copy_to_user_overflow();
12361 + else if (access_ok(VERIFY_WRITE, to, n))
12362 + n = __copy_to_user(to, from, n);
12363 + return n;
12364 +}
12365 +
12366 +/**
12367 + * copy_from_user: - Copy a block of data from user space.
12368 + * @to: Destination address, in kernel space.
12369 + * @from: Source address, in user space.
12370 + * @n: Number of bytes to copy.
12371 + *
12372 + * Context: User context only. This function may sleep.
12373 + *
12374 + * Copy data from user space to kernel space.
12375 + *
12376 + * Returns number of bytes that could not be copied.
12377 + * On success, this will be zero.
12378 + *
12379 + * If some data could not be copied, this function will pad the copied
12380 + * data to the requested size using zero bytes.
12381 + */
12382 +static inline unsigned long __must_check
12383 +copy_from_user(void *to, const void __user *from, unsigned long n)
12384 {
12385 int sz = __compiletime_object_size(to);
12386
12387 - if (likely(sz == -1 || sz >= n))
12388 - n = _copy_from_user(to, from, n);
12389 - else
12390 + if (unlikely(sz != -1 && sz < n))
12391 copy_from_user_overflow();
12392 -
12393 + else if (access_ok(VERIFY_READ, from, n))
12394 + n = __copy_from_user(to, from, n);
12395 + else if ((long)n > 0) {
12396 + if (!__builtin_constant_p(n))
12397 + check_object_size(to, n, false);
12398 + memset(to, 0, n);
12399 + }
12400 return n;
12401 }
12402
12403 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12404 index 1c66d30..e66922c 100644
12405 --- a/arch/x86/include/asm/uaccess_64.h
12406 +++ b/arch/x86/include/asm/uaccess_64.h
12407 @@ -10,6 +10,9 @@
12408 #include <asm/alternative.h>
12409 #include <asm/cpufeature.h>
12410 #include <asm/page.h>
12411 +#include <asm/pgtable.h>
12412 +
12413 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12414
12415 /*
12416 * Copy To/From Userspace
12417 @@ -17,12 +20,12 @@
12418
12419 /* Handles exceptions in both to and from, but doesn't do access_ok */
12420 __must_check unsigned long
12421 -copy_user_generic_string(void *to, const void *from, unsigned len);
12422 +copy_user_generic_string(void *to, const void *from, unsigned long len);
12423 __must_check unsigned long
12424 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12425 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len);
12426
12427 static __always_inline __must_check unsigned long
12428 -copy_user_generic(void *to, const void *from, unsigned len)
12429 +copy_user_generic(void *to, const void *from, unsigned long len)
12430 {
12431 unsigned ret;
12432
12433 @@ -32,142 +35,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
12434 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12435 "=d" (len)),
12436 "1" (to), "2" (from), "3" (len)
12437 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12438 + : "memory", "rcx", "r8", "r9", "r11");
12439 return ret;
12440 }
12441
12442 +static __always_inline __must_check unsigned long
12443 +__copy_to_user(void __user *to, const void *from, unsigned long len);
12444 +static __always_inline __must_check unsigned long
12445 +__copy_from_user(void *to, const void __user *from, unsigned long len);
12446 __must_check unsigned long
12447 -_copy_to_user(void __user *to, const void *from, unsigned len);
12448 -__must_check unsigned long
12449 -_copy_from_user(void *to, const void __user *from, unsigned len);
12450 -__must_check unsigned long
12451 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12452 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
12453
12454 static inline unsigned long __must_check copy_from_user(void *to,
12455 const void __user *from,
12456 unsigned long n)
12457 {
12458 - int sz = __compiletime_object_size(to);
12459 -
12460 might_fault();
12461 - if (likely(sz == -1 || sz >= n))
12462 - n = _copy_from_user(to, from, n);
12463 -#ifdef CONFIG_DEBUG_VM
12464 - else
12465 - WARN(1, "Buffer overflow detected!\n");
12466 -#endif
12467 +
12468 + if (access_ok(VERIFY_READ, from, n))
12469 + n = __copy_from_user(to, from, n);
12470 + else if (n < INT_MAX) {
12471 + if (!__builtin_constant_p(n))
12472 + check_object_size(to, n, false);
12473 + memset(to, 0, n);
12474 + }
12475 return n;
12476 }
12477
12478 static __always_inline __must_check
12479 -int copy_to_user(void __user *dst, const void *src, unsigned size)
12480 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
12481 {
12482 might_fault();
12483
12484 - return _copy_to_user(dst, src, size);
12485 + if (access_ok(VERIFY_WRITE, dst, size))
12486 + size = __copy_to_user(dst, src, size);
12487 + return size;
12488 }
12489
12490 static __always_inline __must_check
12491 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12492 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12493 {
12494 - int ret = 0;
12495 + int sz = __compiletime_object_size(dst);
12496 + unsigned ret = 0;
12497
12498 might_fault();
12499 - if (!__builtin_constant_p(size))
12500 - return copy_user_generic(dst, (__force void *)src, size);
12501 +
12502 + if (size > INT_MAX)
12503 + return size;
12504 +
12505 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12506 + if (!__access_ok(VERIFY_READ, src, size))
12507 + return size;
12508 +#endif
12509 +
12510 + if (unlikely(sz != -1 && sz < size)) {
12511 +#ifdef CONFIG_DEBUG_VM
12512 + WARN(1, "Buffer overflow detected!\n");
12513 +#endif
12514 + return size;
12515 + }
12516 +
12517 + if (!__builtin_constant_p(size)) {
12518 + check_object_size(dst, size, false);
12519 +
12520 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12521 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12522 + src += PAX_USER_SHADOW_BASE;
12523 +#endif
12524 +
12525 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12526 + }
12527 switch (size) {
12528 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12529 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12530 ret, "b", "b", "=q", 1);
12531 return ret;
12532 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12533 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12534 ret, "w", "w", "=r", 2);
12535 return ret;
12536 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12537 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12538 ret, "l", "k", "=r", 4);
12539 return ret;
12540 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12541 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12542 ret, "q", "", "=r", 8);
12543 return ret;
12544 case 10:
12545 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12546 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12547 ret, "q", "", "=r", 10);
12548 if (unlikely(ret))
12549 return ret;
12550 __get_user_asm(*(u16 *)(8 + (char *)dst),
12551 - (u16 __user *)(8 + (char __user *)src),
12552 + (const u16 __user *)(8 + (const char __user *)src),
12553 ret, "w", "w", "=r", 2);
12554 return ret;
12555 case 16:
12556 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12557 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12558 ret, "q", "", "=r", 16);
12559 if (unlikely(ret))
12560 return ret;
12561 __get_user_asm(*(u64 *)(8 + (char *)dst),
12562 - (u64 __user *)(8 + (char __user *)src),
12563 + (const u64 __user *)(8 + (const char __user *)src),
12564 ret, "q", "", "=r", 8);
12565 return ret;
12566 default:
12567 - return copy_user_generic(dst, (__force void *)src, size);
12568 +
12569 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12570 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12571 + src += PAX_USER_SHADOW_BASE;
12572 +#endif
12573 +
12574 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12575 }
12576 }
12577
12578 static __always_inline __must_check
12579 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12580 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12581 {
12582 - int ret = 0;
12583 + int sz = __compiletime_object_size(src);
12584 + unsigned ret = 0;
12585
12586 might_fault();
12587 - if (!__builtin_constant_p(size))
12588 - return copy_user_generic((__force void *)dst, src, size);
12589 +
12590 + if (size > INT_MAX)
12591 + return size;
12592 +
12593 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12594 + if (!__access_ok(VERIFY_WRITE, dst, size))
12595 + return size;
12596 +#endif
12597 +
12598 + if (unlikely(sz != -1 && sz < size)) {
12599 +#ifdef CONFIG_DEBUG_VM
12600 + WARN(1, "Buffer overflow detected!\n");
12601 +#endif
12602 + return size;
12603 + }
12604 +
12605 + if (!__builtin_constant_p(size)) {
12606 + check_object_size(src, size, true);
12607 +
12608 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12609 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12610 + dst += PAX_USER_SHADOW_BASE;
12611 +#endif
12612 +
12613 + return copy_user_generic((__force_kernel void *)dst, src, size);
12614 + }
12615 switch (size) {
12616 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12617 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12618 ret, "b", "b", "iq", 1);
12619 return ret;
12620 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12621 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12622 ret, "w", "w", "ir", 2);
12623 return ret;
12624 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12625 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12626 ret, "l", "k", "ir", 4);
12627 return ret;
12628 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12629 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12630 ret, "q", "", "er", 8);
12631 return ret;
12632 case 10:
12633 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12634 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12635 ret, "q", "", "er", 10);
12636 if (unlikely(ret))
12637 return ret;
12638 asm("":::"memory");
12639 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12640 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12641 ret, "w", "w", "ir", 2);
12642 return ret;
12643 case 16:
12644 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12645 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12646 ret, "q", "", "er", 16);
12647 if (unlikely(ret))
12648 return ret;
12649 asm("":::"memory");
12650 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12651 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12652 ret, "q", "", "er", 8);
12653 return ret;
12654 default:
12655 - return copy_user_generic((__force void *)dst, src, size);
12656 +
12657 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12658 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12659 + dst += PAX_USER_SHADOW_BASE;
12660 +#endif
12661 +
12662 + return copy_user_generic((__force_kernel void *)dst, src, size);
12663 }
12664 }
12665
12666 static __always_inline __must_check
12667 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12668 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12669 {
12670 - int ret = 0;
12671 + unsigned ret = 0;
12672
12673 might_fault();
12674 - if (!__builtin_constant_p(size))
12675 - return copy_user_generic((__force void *)dst,
12676 - (__force void *)src, size);
12677 +
12678 + if (size > INT_MAX)
12679 + return size;
12680 +
12681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12682 + if (!__access_ok(VERIFY_READ, src, size))
12683 + return size;
12684 + if (!__access_ok(VERIFY_WRITE, dst, size))
12685 + return size;
12686 +#endif
12687 +
12688 + if (!__builtin_constant_p(size)) {
12689 +
12690 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12691 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12692 + src += PAX_USER_SHADOW_BASE;
12693 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12694 + dst += PAX_USER_SHADOW_BASE;
12695 +#endif
12696 +
12697 + return copy_user_generic((__force_kernel void *)dst,
12698 + (__force_kernel const void *)src, size);
12699 + }
12700 switch (size) {
12701 case 1: {
12702 u8 tmp;
12703 - __get_user_asm(tmp, (u8 __user *)src,
12704 + __get_user_asm(tmp, (const u8 __user *)src,
12705 ret, "b", "b", "=q", 1);
12706 if (likely(!ret))
12707 __put_user_asm(tmp, (u8 __user *)dst,
12708 @@ -176,7 +263,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12709 }
12710 case 2: {
12711 u16 tmp;
12712 - __get_user_asm(tmp, (u16 __user *)src,
12713 + __get_user_asm(tmp, (const u16 __user *)src,
12714 ret, "w", "w", "=r", 2);
12715 if (likely(!ret))
12716 __put_user_asm(tmp, (u16 __user *)dst,
12717 @@ -186,7 +273,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12718
12719 case 4: {
12720 u32 tmp;
12721 - __get_user_asm(tmp, (u32 __user *)src,
12722 + __get_user_asm(tmp, (const u32 __user *)src,
12723 ret, "l", "k", "=r", 4);
12724 if (likely(!ret))
12725 __put_user_asm(tmp, (u32 __user *)dst,
12726 @@ -195,7 +282,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12727 }
12728 case 8: {
12729 u64 tmp;
12730 - __get_user_asm(tmp, (u64 __user *)src,
12731 + __get_user_asm(tmp, (const u64 __user *)src,
12732 ret, "q", "", "=r", 8);
12733 if (likely(!ret))
12734 __put_user_asm(tmp, (u64 __user *)dst,
12735 @@ -203,8 +290,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12736 return ret;
12737 }
12738 default:
12739 - return copy_user_generic((__force void *)dst,
12740 - (__force void *)src, size);
12741 +
12742 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12743 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12744 + src += PAX_USER_SHADOW_BASE;
12745 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12746 + dst += PAX_USER_SHADOW_BASE;
12747 +#endif
12748 +
12749 + return copy_user_generic((__force_kernel void *)dst,
12750 + (__force_kernel const void *)src, size);
12751 }
12752 }
12753
12754 @@ -219,35 +314,72 @@ __must_check unsigned long clear_user(void __user *mem, unsigned long len);
12755 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12756
12757 static __must_check __always_inline int
12758 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12759 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12760 {
12761 - return copy_user_generic(dst, (__force const void *)src, size);
12762 + if (size > INT_MAX)
12763 + return size;
12764 +
12765 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12766 + if (!__access_ok(VERIFY_READ, src, size))
12767 + return size;
12768 +
12769 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12770 + src += PAX_USER_SHADOW_BASE;
12771 +#endif
12772 +
12773 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12774 }
12775
12776 -static __must_check __always_inline int
12777 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12778 +static __must_check __always_inline unsigned long
12779 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12780 {
12781 - return copy_user_generic((__force void *)dst, src, size);
12782 + if (size > INT_MAX)
12783 + return size;
12784 +
12785 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12786 + if (!__access_ok(VERIFY_WRITE, dst, size))
12787 + return size;
12788 +
12789 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12790 + dst += PAX_USER_SHADOW_BASE;
12791 +#endif
12792 +
12793 + return copy_user_generic((__force_kernel void *)dst, src, size);
12794 }
12795
12796 -extern long __copy_user_nocache(void *dst, const void __user *src,
12797 - unsigned size, int zerorest);
12798 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12799 + unsigned long size, int zerorest);
12800
12801 -static inline int
12802 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12803 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12804 {
12805 might_sleep();
12806 +
12807 + if (size > INT_MAX)
12808 + return size;
12809 +
12810 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12811 + if (!__access_ok(VERIFY_READ, src, size))
12812 + return size;
12813 +#endif
12814 +
12815 return __copy_user_nocache(dst, src, size, 1);
12816 }
12817
12818 -static inline int
12819 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12820 - unsigned size)
12821 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12822 + unsigned long size)
12823 {
12824 + if (size > INT_MAX)
12825 + return size;
12826 +
12827 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12828 + if (!__access_ok(VERIFY_READ, src, size))
12829 + return size;
12830 +#endif
12831 +
12832 return __copy_user_nocache(dst, src, size, 0);
12833 }
12834
12835 -unsigned long
12836 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12837 +extern unsigned long
12838 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
12839
12840 #endif /* _ASM_X86_UACCESS_64_H */
12841 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12842 index bb05228..d763d5b 100644
12843 --- a/arch/x86/include/asm/vdso.h
12844 +++ b/arch/x86/include/asm/vdso.h
12845 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
12846 #define VDSO32_SYMBOL(base, name) \
12847 ({ \
12848 extern const char VDSO32_##name[]; \
12849 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12850 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12851 })
12852 #endif
12853
12854 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
12855 index 517d476..a1cb4d9 100644
12856 --- a/arch/x86/include/asm/x86_init.h
12857 +++ b/arch/x86/include/asm/x86_init.h
12858 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
12859 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
12860 void (*find_smp_config)(void);
12861 void (*get_smp_config)(unsigned int early);
12862 -};
12863 +} __no_const;
12864
12865 /**
12866 * struct x86_init_resources - platform specific resource related ops
12867 @@ -43,7 +43,7 @@ struct x86_init_resources {
12868 void (*probe_roms)(void);
12869 void (*reserve_resources)(void);
12870 char *(*memory_setup)(void);
12871 -};
12872 +} __no_const;
12873
12874 /**
12875 * struct x86_init_irqs - platform specific interrupt setup
12876 @@ -56,7 +56,7 @@ struct x86_init_irqs {
12877 void (*pre_vector_init)(void);
12878 void (*intr_init)(void);
12879 void (*trap_init)(void);
12880 -};
12881 +} __no_const;
12882
12883 /**
12884 * struct x86_init_oem - oem platform specific customizing functions
12885 @@ -66,7 +66,7 @@ struct x86_init_irqs {
12886 struct x86_init_oem {
12887 void (*arch_setup)(void);
12888 void (*banner)(void);
12889 -};
12890 +} __no_const;
12891
12892 /**
12893 * struct x86_init_mapping - platform specific initial kernel pagetable setup
12894 @@ -77,7 +77,7 @@ struct x86_init_oem {
12895 */
12896 struct x86_init_mapping {
12897 void (*pagetable_reserve)(u64 start, u64 end);
12898 -};
12899 +} __no_const;
12900
12901 /**
12902 * struct x86_init_paging - platform specific paging functions
12903 @@ -87,7 +87,7 @@ struct x86_init_mapping {
12904 struct x86_init_paging {
12905 void (*pagetable_setup_start)(pgd_t *base);
12906 void (*pagetable_setup_done)(pgd_t *base);
12907 -};
12908 +} __no_const;
12909
12910 /**
12911 * struct x86_init_timers - platform specific timer setup
12912 @@ -102,7 +102,7 @@ struct x86_init_timers {
12913 void (*tsc_pre_init)(void);
12914 void (*timer_init)(void);
12915 void (*wallclock_init)(void);
12916 -};
12917 +} __no_const;
12918
12919 /**
12920 * struct x86_init_iommu - platform specific iommu setup
12921 @@ -110,7 +110,7 @@ struct x86_init_timers {
12922 */
12923 struct x86_init_iommu {
12924 int (*iommu_init)(void);
12925 -};
12926 +} __no_const;
12927
12928 /**
12929 * struct x86_init_pci - platform specific pci init functions
12930 @@ -124,7 +124,7 @@ struct x86_init_pci {
12931 int (*init)(void);
12932 void (*init_irq)(void);
12933 void (*fixup_irqs)(void);
12934 -};
12935 +} __no_const;
12936
12937 /**
12938 * struct x86_init_ops - functions for platform specific setup
12939 @@ -140,7 +140,7 @@ struct x86_init_ops {
12940 struct x86_init_timers timers;
12941 struct x86_init_iommu iommu;
12942 struct x86_init_pci pci;
12943 -};
12944 +} __no_const;
12945
12946 /**
12947 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
12948 @@ -149,7 +149,7 @@ struct x86_init_ops {
12949 struct x86_cpuinit_ops {
12950 void (*setup_percpu_clockev)(void);
12951 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
12952 -};
12953 +} __no_const;
12954
12955 /**
12956 * struct x86_platform_ops - platform specific runtime functions
12957 @@ -171,7 +171,7 @@ struct x86_platform_ops {
12958 void (*nmi_init)(void);
12959 unsigned char (*get_nmi_reason)(void);
12960 int (*i8042_detect)(void);
12961 -};
12962 +} __no_const;
12963
12964 struct pci_dev;
12965
12966 @@ -180,7 +180,7 @@ struct x86_msi_ops {
12967 void (*teardown_msi_irq)(unsigned int irq);
12968 void (*teardown_msi_irqs)(struct pci_dev *dev);
12969 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
12970 -};
12971 +} __no_const;
12972
12973 extern struct x86_init_ops x86_init;
12974 extern struct x86_cpuinit_ops x86_cpuinit;
12975 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
12976 index c6ce245..ffbdab7 100644
12977 --- a/arch/x86/include/asm/xsave.h
12978 +++ b/arch/x86/include/asm/xsave.h
12979 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
12980 {
12981 int err;
12982
12983 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12984 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12985 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12986 +#endif
12987 +
12988 /*
12989 * Clear the xsave header first, so that reserved fields are
12990 * initialized to zero.
12991 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
12992 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
12993 {
12994 int err;
12995 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
12996 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
12997 u32 lmask = mask;
12998 u32 hmask = mask >> 32;
12999
13000 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13001 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13002 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13003 +#endif
13004 +
13005 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13006 "2:\n"
13007 ".section .fixup,\"ax\"\n"
13008 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13009 index 6a564ac..9b1340c 100644
13010 --- a/arch/x86/kernel/acpi/realmode/Makefile
13011 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13012 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13013 $(call cc-option, -fno-stack-protector) \
13014 $(call cc-option, -mpreferred-stack-boundary=2)
13015 KBUILD_CFLAGS += $(call cc-option, -m32)
13016 +ifdef CONSTIFY_PLUGIN
13017 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13018 +endif
13019 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13020 GCOV_PROFILE := n
13021
13022 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13023 index b4fd836..4358fe3 100644
13024 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13025 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13026 @@ -108,6 +108,9 @@ wakeup_code:
13027 /* Do any other stuff... */
13028
13029 #ifndef CONFIG_64BIT
13030 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13031 + call verify_cpu
13032 +
13033 /* This could also be done in C code... */
13034 movl pmode_cr3, %eax
13035 movl %eax, %cr3
13036 @@ -131,6 +134,7 @@ wakeup_code:
13037 movl pmode_cr0, %eax
13038 movl %eax, %cr0
13039 jmp pmode_return
13040 +# include "../../verify_cpu.S"
13041 #else
13042 pushw $0
13043 pushw trampoline_segment
13044 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13045 index 103b6ab..2004d0a 100644
13046 --- a/arch/x86/kernel/acpi/sleep.c
13047 +++ b/arch/x86/kernel/acpi/sleep.c
13048 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13049 header->trampoline_segment = trampoline_address() >> 4;
13050 #ifdef CONFIG_SMP
13051 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13052 +
13053 + pax_open_kernel();
13054 early_gdt_descr.address =
13055 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13056 + pax_close_kernel();
13057 +
13058 initial_gs = per_cpu_offset(smp_processor_id());
13059 #endif
13060 initial_code = (unsigned long)wakeup_long64;
13061 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13062 index 13ab720..95d5442 100644
13063 --- a/arch/x86/kernel/acpi/wakeup_32.S
13064 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13065 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13066 # and restore the stack ... but you need gdt for this to work
13067 movl saved_context_esp, %esp
13068
13069 - movl %cs:saved_magic, %eax
13070 - cmpl $0x12345678, %eax
13071 + cmpl $0x12345678, saved_magic
13072 jne bogus_magic
13073
13074 # jump to place where we left off
13075 - movl saved_eip, %eax
13076 - jmp *%eax
13077 + jmp *(saved_eip)
13078
13079 bogus_magic:
13080 jmp bogus_magic
13081 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13082 index 1f84794..e23f862 100644
13083 --- a/arch/x86/kernel/alternative.c
13084 +++ b/arch/x86/kernel/alternative.c
13085 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13086 */
13087 for (a = start; a < end; a++) {
13088 instr = (u8 *)&a->instr_offset + a->instr_offset;
13089 +
13090 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13091 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13092 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13093 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13094 +#endif
13095 +
13096 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13097 BUG_ON(a->replacementlen > a->instrlen);
13098 BUG_ON(a->instrlen > sizeof(insnbuf));
13099 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13100 for (poff = start; poff < end; poff++) {
13101 u8 *ptr = (u8 *)poff + *poff;
13102
13103 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13104 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13105 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13106 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13107 +#endif
13108 +
13109 if (!*poff || ptr < text || ptr >= text_end)
13110 continue;
13111 /* turn DS segment override prefix into lock prefix */
13112 - if (*ptr == 0x3e)
13113 + if (*ktla_ktva(ptr) == 0x3e)
13114 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13115 };
13116 mutex_unlock(&text_mutex);
13117 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13118 for (poff = start; poff < end; poff++) {
13119 u8 *ptr = (u8 *)poff + *poff;
13120
13121 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13122 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13123 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13124 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13125 +#endif
13126 +
13127 if (!*poff || ptr < text || ptr >= text_end)
13128 continue;
13129 /* turn lock prefix into DS segment override prefix */
13130 - if (*ptr == 0xf0)
13131 + if (*ktla_ktva(ptr) == 0xf0)
13132 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13133 };
13134 mutex_unlock(&text_mutex);
13135 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13136
13137 BUG_ON(p->len > MAX_PATCH_LEN);
13138 /* prep the buffer with the original instructions */
13139 - memcpy(insnbuf, p->instr, p->len);
13140 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13141 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13142 (unsigned long)p->instr, p->len);
13143
13144 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13145 if (smp_alt_once)
13146 free_init_pages("SMP alternatives",
13147 (unsigned long)__smp_locks,
13148 - (unsigned long)__smp_locks_end);
13149 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13150
13151 restart_nmi();
13152 }
13153 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13154 * instructions. And on the local CPU you need to be protected again NMI or MCE
13155 * handlers seeing an inconsistent instruction while you patch.
13156 */
13157 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13158 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13159 size_t len)
13160 {
13161 unsigned long flags;
13162 local_irq_save(flags);
13163 - memcpy(addr, opcode, len);
13164 +
13165 + pax_open_kernel();
13166 + memcpy(ktla_ktva(addr), opcode, len);
13167 sync_core();
13168 + pax_close_kernel();
13169 +
13170 local_irq_restore(flags);
13171 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13172 that causes hangs on some VIA CPUs. */
13173 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13174 */
13175 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13176 {
13177 - unsigned long flags;
13178 - char *vaddr;
13179 + unsigned char *vaddr = ktla_ktva(addr);
13180 struct page *pages[2];
13181 - int i;
13182 + size_t i;
13183
13184 if (!core_kernel_text((unsigned long)addr)) {
13185 - pages[0] = vmalloc_to_page(addr);
13186 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13187 + pages[0] = vmalloc_to_page(vaddr);
13188 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13189 } else {
13190 - pages[0] = virt_to_page(addr);
13191 + pages[0] = virt_to_page(vaddr);
13192 WARN_ON(!PageReserved(pages[0]));
13193 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13194 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13195 }
13196 BUG_ON(!pages[0]);
13197 - local_irq_save(flags);
13198 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13199 - if (pages[1])
13200 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13201 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13202 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13203 - clear_fixmap(FIX_TEXT_POKE0);
13204 - if (pages[1])
13205 - clear_fixmap(FIX_TEXT_POKE1);
13206 - local_flush_tlb();
13207 - sync_core();
13208 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13209 - that causes hangs on some VIA CPUs. */
13210 + text_poke_early(addr, opcode, len);
13211 for (i = 0; i < len; i++)
13212 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13213 - local_irq_restore(flags);
13214 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13215 return addr;
13216 }
13217
13218 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13219 index 2eec05b..fef012b 100644
13220 --- a/arch/x86/kernel/apic/apic.c
13221 +++ b/arch/x86/kernel/apic/apic.c
13222 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13223 /*
13224 * Debug level, exported for io_apic.c
13225 */
13226 -unsigned int apic_verbosity;
13227 +int apic_verbosity;
13228
13229 int pic_mode;
13230
13231 @@ -1908,7 +1908,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13232 apic_write(APIC_ESR, 0);
13233 v1 = apic_read(APIC_ESR);
13234 ack_APIC_irq();
13235 - atomic_inc(&irq_err_count);
13236 + atomic_inc_unchecked(&irq_err_count);
13237
13238 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13239 smp_processor_id(), v0 , v1);
13240 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13241 index 6d10a66..f4687b8 100644
13242 --- a/arch/x86/kernel/apic/io_apic.c
13243 +++ b/arch/x86/kernel/apic/io_apic.c
13244 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13245 }
13246 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13247
13248 -void lock_vector_lock(void)
13249 +void lock_vector_lock(void) __acquires(vector_lock)
13250 {
13251 /* Used to the online set of cpus does not change
13252 * during assign_irq_vector.
13253 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13254 raw_spin_lock(&vector_lock);
13255 }
13256
13257 -void unlock_vector_lock(void)
13258 +void unlock_vector_lock(void) __releases(vector_lock)
13259 {
13260 raw_spin_unlock(&vector_lock);
13261 }
13262 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13263 ack_APIC_irq();
13264 }
13265
13266 -atomic_t irq_mis_count;
13267 +atomic_unchecked_t irq_mis_count;
13268
13269 static void ack_apic_level(struct irq_data *data)
13270 {
13271 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13272 * at the cpu.
13273 */
13274 if (!(v & (1 << (i & 0x1f)))) {
13275 - atomic_inc(&irq_mis_count);
13276 + atomic_inc_unchecked(&irq_mis_count);
13277
13278 eoi_ioapic_irq(irq, cfg);
13279 }
13280 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13281 index f76623c..aab694f 100644
13282 --- a/arch/x86/kernel/apm_32.c
13283 +++ b/arch/x86/kernel/apm_32.c
13284 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13285 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13286 * even though they are called in protected mode.
13287 */
13288 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13289 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13290 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13291
13292 static const char driver_version[] = "1.16ac"; /* no spaces */
13293 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13294 BUG_ON(cpu != 0);
13295 gdt = get_cpu_gdt_table(cpu);
13296 save_desc_40 = gdt[0x40 / 8];
13297 +
13298 + pax_open_kernel();
13299 gdt[0x40 / 8] = bad_bios_desc;
13300 + pax_close_kernel();
13301
13302 apm_irq_save(flags);
13303 APM_DO_SAVE_SEGS;
13304 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13305 &call->esi);
13306 APM_DO_RESTORE_SEGS;
13307 apm_irq_restore(flags);
13308 +
13309 + pax_open_kernel();
13310 gdt[0x40 / 8] = save_desc_40;
13311 + pax_close_kernel();
13312 +
13313 put_cpu();
13314
13315 return call->eax & 0xff;
13316 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13317 BUG_ON(cpu != 0);
13318 gdt = get_cpu_gdt_table(cpu);
13319 save_desc_40 = gdt[0x40 / 8];
13320 +
13321 + pax_open_kernel();
13322 gdt[0x40 / 8] = bad_bios_desc;
13323 + pax_close_kernel();
13324
13325 apm_irq_save(flags);
13326 APM_DO_SAVE_SEGS;
13327 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13328 &call->eax);
13329 APM_DO_RESTORE_SEGS;
13330 apm_irq_restore(flags);
13331 +
13332 + pax_open_kernel();
13333 gdt[0x40 / 8] = save_desc_40;
13334 + pax_close_kernel();
13335 +
13336 put_cpu();
13337 return error;
13338 }
13339 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13340 * code to that CPU.
13341 */
13342 gdt = get_cpu_gdt_table(0);
13343 +
13344 + pax_open_kernel();
13345 set_desc_base(&gdt[APM_CS >> 3],
13346 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13347 set_desc_base(&gdt[APM_CS_16 >> 3],
13348 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13349 set_desc_base(&gdt[APM_DS >> 3],
13350 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13351 + pax_close_kernel();
13352
13353 proc_create("apm", 0, NULL, &apm_file_ops);
13354
13355 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13356 index 68de2dc..1f3c720 100644
13357 --- a/arch/x86/kernel/asm-offsets.c
13358 +++ b/arch/x86/kernel/asm-offsets.c
13359 @@ -33,6 +33,8 @@ void common(void) {
13360 OFFSET(TI_status, thread_info, status);
13361 OFFSET(TI_addr_limit, thread_info, addr_limit);
13362 OFFSET(TI_preempt_count, thread_info, preempt_count);
13363 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13364 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13365
13366 BLANK();
13367 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13368 @@ -53,8 +55,26 @@ void common(void) {
13369 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13370 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13371 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13372 +
13373 +#ifdef CONFIG_PAX_KERNEXEC
13374 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13375 #endif
13376
13377 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13378 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13379 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13380 +#ifdef CONFIG_X86_64
13381 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13382 +#endif
13383 +#endif
13384 +
13385 +#endif
13386 +
13387 + BLANK();
13388 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13389 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13390 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13391 +
13392 #ifdef CONFIG_XEN
13393 BLANK();
13394 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13395 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13396 index 834e897..dacddc8 100644
13397 --- a/arch/x86/kernel/asm-offsets_64.c
13398 +++ b/arch/x86/kernel/asm-offsets_64.c
13399 @@ -70,6 +70,7 @@ int main(void)
13400 BLANK();
13401 #undef ENTRY
13402
13403 + DEFINE(TSS_size, sizeof(struct tss_struct));
13404 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13405 BLANK();
13406
13407 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13408 index 25f24dc..4094a7f 100644
13409 --- a/arch/x86/kernel/cpu/Makefile
13410 +++ b/arch/x86/kernel/cpu/Makefile
13411 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13412 CFLAGS_REMOVE_perf_event.o = -pg
13413 endif
13414
13415 -# Make sure load_percpu_segment has no stackprotector
13416 -nostackp := $(call cc-option, -fno-stack-protector)
13417 -CFLAGS_common.o := $(nostackp)
13418 -
13419 obj-y := intel_cacheinfo.o scattered.o topology.o
13420 obj-y += proc.o capflags.o powerflags.o common.o
13421 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13422 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13423 index f4773f4..b3fb13c 100644
13424 --- a/arch/x86/kernel/cpu/amd.c
13425 +++ b/arch/x86/kernel/cpu/amd.c
13426 @@ -669,7 +669,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13427 unsigned int size)
13428 {
13429 /* AMD errata T13 (order #21922) */
13430 - if ((c->x86 == 6)) {
13431 + if (c->x86 == 6) {
13432 /* Duron Rev A0 */
13433 if (c->x86_model == 3 && c->x86_mask == 0)
13434 size = 64;
13435 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13436 index c0f7d68..aa418f9 100644
13437 --- a/arch/x86/kernel/cpu/common.c
13438 +++ b/arch/x86/kernel/cpu/common.c
13439 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13440
13441 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13442
13443 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13444 -#ifdef CONFIG_X86_64
13445 - /*
13446 - * We need valid kernel segments for data and code in long mode too
13447 - * IRET will check the segment types kkeil 2000/10/28
13448 - * Also sysret mandates a special GDT layout
13449 - *
13450 - * TLS descriptors are currently at a different place compared to i386.
13451 - * Hopefully nobody expects them at a fixed place (Wine?)
13452 - */
13453 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13454 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13455 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13456 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13457 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13458 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13459 -#else
13460 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13461 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13462 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13463 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13464 - /*
13465 - * Segments used for calling PnP BIOS have byte granularity.
13466 - * They code segments and data segments have fixed 64k limits,
13467 - * the transfer segment sizes are set at run time.
13468 - */
13469 - /* 32-bit code */
13470 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13471 - /* 16-bit code */
13472 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13473 - /* 16-bit data */
13474 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13475 - /* 16-bit data */
13476 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13477 - /* 16-bit data */
13478 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13479 - /*
13480 - * The APM segments have byte granularity and their bases
13481 - * are set at run time. All have 64k limits.
13482 - */
13483 - /* 32-bit code */
13484 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13485 - /* 16-bit code */
13486 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13487 - /* data */
13488 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13489 -
13490 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13491 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13492 - GDT_STACK_CANARY_INIT
13493 -#endif
13494 -} };
13495 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13496 -
13497 static int __init x86_xsave_setup(char *s)
13498 {
13499 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13500 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13501 {
13502 struct desc_ptr gdt_descr;
13503
13504 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13505 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13506 gdt_descr.size = GDT_SIZE - 1;
13507 load_gdt(&gdt_descr);
13508 /* Reload the per-cpu base */
13509 @@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13510 /* Filter out anything that depends on CPUID levels we don't have */
13511 filter_cpuid_features(c, true);
13512
13513 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13514 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13515 +#endif
13516 +
13517 /* If the model name is still unset, do table lookup. */
13518 if (!c->x86_model_id[0]) {
13519 const char *p;
13520 @@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
13521 }
13522 __setup("clearcpuid=", setup_disablecpuid);
13523
13524 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13525 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13526 +
13527 #ifdef CONFIG_X86_64
13528 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13529 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
13530 - (unsigned long) nmi_idt_table };
13531 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
13532
13533 DEFINE_PER_CPU_FIRST(union irq_stack_union,
13534 irq_stack_union) __aligned(PAGE_SIZE);
13535 @@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13536 EXPORT_PER_CPU_SYMBOL(current_task);
13537
13538 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13539 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13540 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13541 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13542
13543 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13544 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13545 {
13546 memset(regs, 0, sizeof(struct pt_regs));
13547 regs->fs = __KERNEL_PERCPU;
13548 - regs->gs = __KERNEL_STACK_CANARY;
13549 + savesegment(gs, regs->gs);
13550
13551 return regs;
13552 }
13553 @@ -1190,7 +1142,7 @@ void __cpuinit cpu_init(void)
13554 int i;
13555
13556 cpu = stack_smp_processor_id();
13557 - t = &per_cpu(init_tss, cpu);
13558 + t = init_tss + cpu;
13559 oist = &per_cpu(orig_ist, cpu);
13560
13561 #ifdef CONFIG_NUMA
13562 @@ -1216,7 +1168,7 @@ void __cpuinit cpu_init(void)
13563 switch_to_new_gdt(cpu);
13564 loadsegment(fs, 0);
13565
13566 - load_idt((const struct desc_ptr *)&idt_descr);
13567 + load_idt(&idt_descr);
13568
13569 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13570 syscall_init();
13571 @@ -1225,7 +1177,6 @@ void __cpuinit cpu_init(void)
13572 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13573 barrier();
13574
13575 - x86_configure_nx();
13576 if (cpu != 0)
13577 enable_x2apic();
13578
13579 @@ -1281,7 +1232,7 @@ void __cpuinit cpu_init(void)
13580 {
13581 int cpu = smp_processor_id();
13582 struct task_struct *curr = current;
13583 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13584 + struct tss_struct *t = init_tss + cpu;
13585 struct thread_struct *thread = &curr->thread;
13586
13587 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13588 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13589 index 3e6ff6c..54b4992 100644
13590 --- a/arch/x86/kernel/cpu/intel.c
13591 +++ b/arch/x86/kernel/cpu/intel.c
13592 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13593 * Update the IDT descriptor and reload the IDT so that
13594 * it uses the read-only mapped virtual address.
13595 */
13596 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13597 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13598 load_idt(&idt_descr);
13599 }
13600 #endif
13601 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13602 index 5a11ae2..a1a1c8a 100644
13603 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13604 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13605 @@ -42,6 +42,7 @@
13606 #include <asm/processor.h>
13607 #include <asm/mce.h>
13608 #include <asm/msr.h>
13609 +#include <asm/local.h>
13610
13611 #include "mce-internal.h"
13612
13613 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
13614 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13615 m->cs, m->ip);
13616
13617 - if (m->cs == __KERNEL_CS)
13618 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13619 print_symbol("{%s}", m->ip);
13620 pr_cont("\n");
13621 }
13622 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
13623
13624 #define PANIC_TIMEOUT 5 /* 5 seconds */
13625
13626 -static atomic_t mce_paniced;
13627 +static atomic_unchecked_t mce_paniced;
13628
13629 static int fake_panic;
13630 -static atomic_t mce_fake_paniced;
13631 +static atomic_unchecked_t mce_fake_paniced;
13632
13633 /* Panic in progress. Enable interrupts and wait for final IPI */
13634 static void wait_for_panic(void)
13635 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13636 /*
13637 * Make sure only one CPU runs in machine check panic
13638 */
13639 - if (atomic_inc_return(&mce_paniced) > 1)
13640 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13641 wait_for_panic();
13642 barrier();
13643
13644 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13645 console_verbose();
13646 } else {
13647 /* Don't log too much for fake panic */
13648 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13649 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13650 return;
13651 }
13652 /* First print corrected ones that are still unlogged */
13653 @@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
13654 * might have been modified by someone else.
13655 */
13656 rmb();
13657 - if (atomic_read(&mce_paniced))
13658 + if (atomic_read_unchecked(&mce_paniced))
13659 wait_for_panic();
13660 if (!monarch_timeout)
13661 goto out;
13662 @@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13663 }
13664
13665 /* Call the installed machine check handler for this CPU setup. */
13666 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
13667 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13668 unexpected_machine_check;
13669
13670 /*
13671 @@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13672 return;
13673 }
13674
13675 + pax_open_kernel();
13676 machine_check_vector = do_machine_check;
13677 + pax_close_kernel();
13678
13679 __mcheck_cpu_init_generic();
13680 __mcheck_cpu_init_vendor(c);
13681 @@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13682 */
13683
13684 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
13685 -static int mce_chrdev_open_count; /* #times opened */
13686 +static local_t mce_chrdev_open_count; /* #times opened */
13687 static int mce_chrdev_open_exclu; /* already open exclusive? */
13688
13689 static int mce_chrdev_open(struct inode *inode, struct file *file)
13690 @@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13691 spin_lock(&mce_chrdev_state_lock);
13692
13693 if (mce_chrdev_open_exclu ||
13694 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
13695 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
13696 spin_unlock(&mce_chrdev_state_lock);
13697
13698 return -EBUSY;
13699 @@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13700
13701 if (file->f_flags & O_EXCL)
13702 mce_chrdev_open_exclu = 1;
13703 - mce_chrdev_open_count++;
13704 + local_inc(&mce_chrdev_open_count);
13705
13706 spin_unlock(&mce_chrdev_state_lock);
13707
13708 @@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
13709 {
13710 spin_lock(&mce_chrdev_state_lock);
13711
13712 - mce_chrdev_open_count--;
13713 + local_dec(&mce_chrdev_open_count);
13714 mce_chrdev_open_exclu = 0;
13715
13716 spin_unlock(&mce_chrdev_state_lock);
13717 @@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
13718 static void mce_reset(void)
13719 {
13720 cpu_missing = 0;
13721 - atomic_set(&mce_fake_paniced, 0);
13722 + atomic_set_unchecked(&mce_fake_paniced, 0);
13723 atomic_set(&mce_executing, 0);
13724 atomic_set(&mce_callin, 0);
13725 atomic_set(&global_nwo, 0);
13726 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13727 index 5c0e653..0882b0a 100644
13728 --- a/arch/x86/kernel/cpu/mcheck/p5.c
13729 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
13730 @@ -12,6 +12,7 @@
13731 #include <asm/system.h>
13732 #include <asm/mce.h>
13733 #include <asm/msr.h>
13734 +#include <asm/pgtable.h>
13735
13736 /* By default disabled */
13737 int mce_p5_enabled __read_mostly;
13738 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13739 if (!cpu_has(c, X86_FEATURE_MCE))
13740 return;
13741
13742 + pax_open_kernel();
13743 machine_check_vector = pentium_machine_check;
13744 + pax_close_kernel();
13745 /* Make sure the vector pointer is visible before we enable MCEs: */
13746 wmb();
13747
13748 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13749 index 54060f5..c1a7577 100644
13750 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
13751 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13752 @@ -11,6 +11,7 @@
13753 #include <asm/system.h>
13754 #include <asm/mce.h>
13755 #include <asm/msr.h>
13756 +#include <asm/pgtable.h>
13757
13758 /* Machine check handler for WinChip C6: */
13759 static void winchip_machine_check(struct pt_regs *regs, long error_code)
13760 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13761 {
13762 u32 lo, hi;
13763
13764 + pax_open_kernel();
13765 machine_check_vector = winchip_machine_check;
13766 + pax_close_kernel();
13767 /* Make sure the vector pointer is visible before we enable MCEs: */
13768 wmb();
13769
13770 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
13771 index 6b96110..0da73eb 100644
13772 --- a/arch/x86/kernel/cpu/mtrr/main.c
13773 +++ b/arch/x86/kernel/cpu/mtrr/main.c
13774 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13775 u64 size_or_mask, size_and_mask;
13776 static bool mtrr_aps_delayed_init;
13777
13778 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13779 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13780
13781 const struct mtrr_ops *mtrr_if;
13782
13783 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
13784 index df5e41f..816c719 100644
13785 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
13786 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
13787 @@ -25,7 +25,7 @@ struct mtrr_ops {
13788 int (*validate_add_page)(unsigned long base, unsigned long size,
13789 unsigned int type);
13790 int (*have_wrcomb)(void);
13791 -};
13792 +} __do_const;
13793
13794 extern int generic_get_free_region(unsigned long base, unsigned long size,
13795 int replace_reg);
13796 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
13797 index 5adce10..99284ec 100644
13798 --- a/arch/x86/kernel/cpu/perf_event.c
13799 +++ b/arch/x86/kernel/cpu/perf_event.c
13800 @@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
13801 break;
13802
13803 perf_callchain_store(entry, frame.return_address);
13804 - fp = frame.next_frame;
13805 + fp = (const void __force_user *)frame.next_frame;
13806 }
13807 }
13808
13809 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
13810 index 13ad899..f642b9a 100644
13811 --- a/arch/x86/kernel/crash.c
13812 +++ b/arch/x86/kernel/crash.c
13813 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
13814 {
13815 #ifdef CONFIG_X86_32
13816 struct pt_regs fixed_regs;
13817 -#endif
13818
13819 -#ifdef CONFIG_X86_32
13820 - if (!user_mode_vm(regs)) {
13821 + if (!user_mode(regs)) {
13822 crash_fixup_ss_esp(&fixed_regs, regs);
13823 regs = &fixed_regs;
13824 }
13825 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
13826 index 37250fe..bf2ec74 100644
13827 --- a/arch/x86/kernel/doublefault_32.c
13828 +++ b/arch/x86/kernel/doublefault_32.c
13829 @@ -11,7 +11,7 @@
13830
13831 #define DOUBLEFAULT_STACKSIZE (1024)
13832 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13833 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13834 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13835
13836 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13837
13838 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
13839 unsigned long gdt, tss;
13840
13841 store_gdt(&gdt_desc);
13842 - gdt = gdt_desc.address;
13843 + gdt = (unsigned long)gdt_desc.address;
13844
13845 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13846
13847 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
13848 /* 0x2 bit is always set */
13849 .flags = X86_EFLAGS_SF | 0x2,
13850 .sp = STACK_START,
13851 - .es = __USER_DS,
13852 + .es = __KERNEL_DS,
13853 .cs = __KERNEL_CS,
13854 .ss = __KERNEL_DS,
13855 - .ds = __USER_DS,
13856 + .ds = __KERNEL_DS,
13857 .fs = __KERNEL_PERCPU,
13858
13859 .__cr3 = __pa_nodebug(swapper_pg_dir),
13860 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
13861 index 4025fe4..d8451c6 100644
13862 --- a/arch/x86/kernel/dumpstack.c
13863 +++ b/arch/x86/kernel/dumpstack.c
13864 @@ -2,6 +2,9 @@
13865 * Copyright (C) 1991, 1992 Linus Torvalds
13866 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13867 */
13868 +#ifdef CONFIG_GRKERNSEC_HIDESYM
13869 +#define __INCLUDED_BY_HIDESYM 1
13870 +#endif
13871 #include <linux/kallsyms.h>
13872 #include <linux/kprobes.h>
13873 #include <linux/uaccess.h>
13874 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
13875 static void
13876 print_ftrace_graph_addr(unsigned long addr, void *data,
13877 const struct stacktrace_ops *ops,
13878 - struct thread_info *tinfo, int *graph)
13879 + struct task_struct *task, int *graph)
13880 {
13881 - struct task_struct *task = tinfo->task;
13882 unsigned long ret_addr;
13883 int index = task->curr_ret_stack;
13884
13885 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
13886 static inline void
13887 print_ftrace_graph_addr(unsigned long addr, void *data,
13888 const struct stacktrace_ops *ops,
13889 - struct thread_info *tinfo, int *graph)
13890 + struct task_struct *task, int *graph)
13891 { }
13892 #endif
13893
13894 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
13895 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13896 */
13897
13898 -static inline int valid_stack_ptr(struct thread_info *tinfo,
13899 - void *p, unsigned int size, void *end)
13900 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13901 {
13902 - void *t = tinfo;
13903 if (end) {
13904 if (p < end && p >= (end-THREAD_SIZE))
13905 return 1;
13906 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
13907 }
13908
13909 unsigned long
13910 -print_context_stack(struct thread_info *tinfo,
13911 +print_context_stack(struct task_struct *task, void *stack_start,
13912 unsigned long *stack, unsigned long bp,
13913 const struct stacktrace_ops *ops, void *data,
13914 unsigned long *end, int *graph)
13915 {
13916 struct stack_frame *frame = (struct stack_frame *)bp;
13917
13918 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13919 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13920 unsigned long addr;
13921
13922 addr = *stack;
13923 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
13924 } else {
13925 ops->address(data, addr, 0);
13926 }
13927 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13928 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13929 }
13930 stack++;
13931 }
13932 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
13933 EXPORT_SYMBOL_GPL(print_context_stack);
13934
13935 unsigned long
13936 -print_context_stack_bp(struct thread_info *tinfo,
13937 +print_context_stack_bp(struct task_struct *task, void *stack_start,
13938 unsigned long *stack, unsigned long bp,
13939 const struct stacktrace_ops *ops, void *data,
13940 unsigned long *end, int *graph)
13941 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
13942 struct stack_frame *frame = (struct stack_frame *)bp;
13943 unsigned long *ret_addr = &frame->return_address;
13944
13945 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
13946 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
13947 unsigned long addr = *ret_addr;
13948
13949 if (!__kernel_text_address(addr))
13950 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
13951 ops->address(data, addr, 1);
13952 frame = frame->next_frame;
13953 ret_addr = &frame->return_address;
13954 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13955 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13956 }
13957
13958 return (unsigned long)frame;
13959 @@ -186,7 +186,7 @@ void dump_stack(void)
13960
13961 bp = stack_frame(current, NULL);
13962 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13963 - current->pid, current->comm, print_tainted(),
13964 + task_pid_nr(current), current->comm, print_tainted(),
13965 init_utsname()->release,
13966 (int)strcspn(init_utsname()->version, " "),
13967 init_utsname()->version);
13968 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
13969 }
13970 EXPORT_SYMBOL_GPL(oops_begin);
13971
13972 +extern void gr_handle_kernel_exploit(void);
13973 +
13974 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13975 {
13976 if (regs && kexec_should_crash(current))
13977 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13978 panic("Fatal exception in interrupt");
13979 if (panic_on_oops)
13980 panic("Fatal exception");
13981 - do_exit(signr);
13982 +
13983 + gr_handle_kernel_exploit();
13984 +
13985 + do_group_exit(signr);
13986 }
13987
13988 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13989 @@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13990
13991 show_registers(regs);
13992 #ifdef CONFIG_X86_32
13993 - if (user_mode_vm(regs)) {
13994 + if (user_mode(regs)) {
13995 sp = regs->sp;
13996 ss = regs->ss & 0xffff;
13997 } else {
13998 @@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
13999 unsigned long flags = oops_begin();
14000 int sig = SIGSEGV;
14001
14002 - if (!user_mode_vm(regs))
14003 + if (!user_mode(regs))
14004 report_bug(regs->ip, regs);
14005
14006 if (__die(str, regs, err))
14007 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14008 index c99f9ed..2a15d80 100644
14009 --- a/arch/x86/kernel/dumpstack_32.c
14010 +++ b/arch/x86/kernel/dumpstack_32.c
14011 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14012 bp = stack_frame(task, regs);
14013
14014 for (;;) {
14015 - struct thread_info *context;
14016 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14017
14018 - context = (struct thread_info *)
14019 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14020 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14021 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14022
14023 - stack = (unsigned long *)context->previous_esp;
14024 - if (!stack)
14025 + if (stack_start == task_stack_page(task))
14026 break;
14027 + stack = *(unsigned long **)stack_start;
14028 if (ops->stack(data, "IRQ") < 0)
14029 break;
14030 touch_nmi_watchdog();
14031 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14032 * When in-kernel, we also print out the stack and code at the
14033 * time of the fault..
14034 */
14035 - if (!user_mode_vm(regs)) {
14036 + if (!user_mode(regs)) {
14037 unsigned int code_prologue = code_bytes * 43 / 64;
14038 unsigned int code_len = code_bytes;
14039 unsigned char c;
14040 u8 *ip;
14041 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14042
14043 printk(KERN_EMERG "Stack:\n");
14044 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14045
14046 printk(KERN_EMERG "Code: ");
14047
14048 - ip = (u8 *)regs->ip - code_prologue;
14049 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14050 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14051 /* try starting at IP */
14052 - ip = (u8 *)regs->ip;
14053 + ip = (u8 *)regs->ip + cs_base;
14054 code_len = code_len - code_prologue + 1;
14055 }
14056 for (i = 0; i < code_len; i++, ip++) {
14057 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14058 printk(KERN_CONT " Bad EIP value.");
14059 break;
14060 }
14061 - if (ip == (u8 *)regs->ip)
14062 + if (ip == (u8 *)regs->ip + cs_base)
14063 printk(KERN_CONT "<%02x> ", c);
14064 else
14065 printk(KERN_CONT "%02x ", c);
14066 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14067 {
14068 unsigned short ud2;
14069
14070 + ip = ktla_ktva(ip);
14071 if (ip < PAGE_OFFSET)
14072 return 0;
14073 if (probe_kernel_address((unsigned short *)ip, ud2))
14074 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14075
14076 return ud2 == 0x0b0f;
14077 }
14078 +
14079 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14080 +void pax_check_alloca(unsigned long size)
14081 +{
14082 + unsigned long sp = (unsigned long)&sp, stack_left;
14083 +
14084 + /* all kernel stacks are of the same size */
14085 + stack_left = sp & (THREAD_SIZE - 1);
14086 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14087 +}
14088 +EXPORT_SYMBOL(pax_check_alloca);
14089 +#endif
14090 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14091 index 17107bd..b2deecf 100644
14092 --- a/arch/x86/kernel/dumpstack_64.c
14093 +++ b/arch/x86/kernel/dumpstack_64.c
14094 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14095 unsigned long *irq_stack_end =
14096 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14097 unsigned used = 0;
14098 - struct thread_info *tinfo;
14099 int graph = 0;
14100 unsigned long dummy;
14101 + void *stack_start;
14102
14103 if (!task)
14104 task = current;
14105 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14106 * current stack address. If the stacks consist of nested
14107 * exceptions
14108 */
14109 - tinfo = task_thread_info(task);
14110 for (;;) {
14111 char *id;
14112 unsigned long *estack_end;
14113 +
14114 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14115 &used, &id);
14116
14117 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14118 if (ops->stack(data, id) < 0)
14119 break;
14120
14121 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14122 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14123 data, estack_end, &graph);
14124 ops->stack(data, "<EOE>");
14125 /*
14126 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14127 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14128 if (ops->stack(data, "IRQ") < 0)
14129 break;
14130 - bp = ops->walk_stack(tinfo, stack, bp,
14131 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14132 ops, data, irq_stack_end, &graph);
14133 /*
14134 * We link to the next stack (which would be
14135 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14136 /*
14137 * This handles the process stack:
14138 */
14139 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14140 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14141 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14142 put_cpu();
14143 }
14144 EXPORT_SYMBOL(dump_trace);
14145 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
14146
14147 return ud2 == 0x0b0f;
14148 }
14149 +
14150 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14151 +void pax_check_alloca(unsigned long size)
14152 +{
14153 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14154 + unsigned cpu, used;
14155 + char *id;
14156 +
14157 + /* check the process stack first */
14158 + stack_start = (unsigned long)task_stack_page(current);
14159 + stack_end = stack_start + THREAD_SIZE;
14160 + if (likely(stack_start <= sp && sp < stack_end)) {
14161 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14162 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14163 + return;
14164 + }
14165 +
14166 + cpu = get_cpu();
14167 +
14168 + /* check the irq stacks */
14169 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14170 + stack_start = stack_end - IRQ_STACK_SIZE;
14171 + if (stack_start <= sp && sp < stack_end) {
14172 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14173 + put_cpu();
14174 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14175 + return;
14176 + }
14177 +
14178 + /* check the exception stacks */
14179 + used = 0;
14180 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14181 + stack_start = stack_end - EXCEPTION_STKSZ;
14182 + if (stack_end && stack_start <= sp && sp < stack_end) {
14183 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14184 + put_cpu();
14185 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14186 + return;
14187 + }
14188 +
14189 + put_cpu();
14190 +
14191 + /* unknown stack */
14192 + BUG();
14193 +}
14194 +EXPORT_SYMBOL(pax_check_alloca);
14195 +#endif
14196 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14197 index 9b9f18b..9fcaa04 100644
14198 --- a/arch/x86/kernel/early_printk.c
14199 +++ b/arch/x86/kernel/early_printk.c
14200 @@ -7,6 +7,7 @@
14201 #include <linux/pci_regs.h>
14202 #include <linux/pci_ids.h>
14203 #include <linux/errno.h>
14204 +#include <linux/sched.h>
14205 #include <asm/io.h>
14206 #include <asm/processor.h>
14207 #include <asm/fcntl.h>
14208 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14209 index 7b784f4..76aaad7 100644
14210 --- a/arch/x86/kernel/entry_32.S
14211 +++ b/arch/x86/kernel/entry_32.S
14212 @@ -179,13 +179,146 @@
14213 /*CFI_REL_OFFSET gs, PT_GS*/
14214 .endm
14215 .macro SET_KERNEL_GS reg
14216 +
14217 +#ifdef CONFIG_CC_STACKPROTECTOR
14218 movl $(__KERNEL_STACK_CANARY), \reg
14219 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14220 + movl $(__USER_DS), \reg
14221 +#else
14222 + xorl \reg, \reg
14223 +#endif
14224 +
14225 movl \reg, %gs
14226 .endm
14227
14228 #endif /* CONFIG_X86_32_LAZY_GS */
14229
14230 -.macro SAVE_ALL
14231 +.macro pax_enter_kernel
14232 +#ifdef CONFIG_PAX_KERNEXEC
14233 + call pax_enter_kernel
14234 +#endif
14235 +.endm
14236 +
14237 +.macro pax_exit_kernel
14238 +#ifdef CONFIG_PAX_KERNEXEC
14239 + call pax_exit_kernel
14240 +#endif
14241 +.endm
14242 +
14243 +#ifdef CONFIG_PAX_KERNEXEC
14244 +ENTRY(pax_enter_kernel)
14245 +#ifdef CONFIG_PARAVIRT
14246 + pushl %eax
14247 + pushl %ecx
14248 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14249 + mov %eax, %esi
14250 +#else
14251 + mov %cr0, %esi
14252 +#endif
14253 + bts $16, %esi
14254 + jnc 1f
14255 + mov %cs, %esi
14256 + cmp $__KERNEL_CS, %esi
14257 + jz 3f
14258 + ljmp $__KERNEL_CS, $3f
14259 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14260 +2:
14261 +#ifdef CONFIG_PARAVIRT
14262 + mov %esi, %eax
14263 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14264 +#else
14265 + mov %esi, %cr0
14266 +#endif
14267 +3:
14268 +#ifdef CONFIG_PARAVIRT
14269 + popl %ecx
14270 + popl %eax
14271 +#endif
14272 + ret
14273 +ENDPROC(pax_enter_kernel)
14274 +
14275 +ENTRY(pax_exit_kernel)
14276 +#ifdef CONFIG_PARAVIRT
14277 + pushl %eax
14278 + pushl %ecx
14279 +#endif
14280 + mov %cs, %esi
14281 + cmp $__KERNEXEC_KERNEL_CS, %esi
14282 + jnz 2f
14283 +#ifdef CONFIG_PARAVIRT
14284 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14285 + mov %eax, %esi
14286 +#else
14287 + mov %cr0, %esi
14288 +#endif
14289 + btr $16, %esi
14290 + ljmp $__KERNEL_CS, $1f
14291 +1:
14292 +#ifdef CONFIG_PARAVIRT
14293 + mov %esi, %eax
14294 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14295 +#else
14296 + mov %esi, %cr0
14297 +#endif
14298 +2:
14299 +#ifdef CONFIG_PARAVIRT
14300 + popl %ecx
14301 + popl %eax
14302 +#endif
14303 + ret
14304 +ENDPROC(pax_exit_kernel)
14305 +#endif
14306 +
14307 +.macro pax_erase_kstack
14308 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14309 + call pax_erase_kstack
14310 +#endif
14311 +.endm
14312 +
14313 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14314 +/*
14315 + * ebp: thread_info
14316 + * ecx, edx: can be clobbered
14317 + */
14318 +ENTRY(pax_erase_kstack)
14319 + pushl %edi
14320 + pushl %eax
14321 +
14322 + mov TI_lowest_stack(%ebp), %edi
14323 + mov $-0xBEEF, %eax
14324 + std
14325 +
14326 +1: mov %edi, %ecx
14327 + and $THREAD_SIZE_asm - 1, %ecx
14328 + shr $2, %ecx
14329 + repne scasl
14330 + jecxz 2f
14331 +
14332 + cmp $2*16, %ecx
14333 + jc 2f
14334 +
14335 + mov $2*16, %ecx
14336 + repe scasl
14337 + jecxz 2f
14338 + jne 1b
14339 +
14340 +2: cld
14341 + mov %esp, %ecx
14342 + sub %edi, %ecx
14343 + shr $2, %ecx
14344 + rep stosl
14345 +
14346 + mov TI_task_thread_sp0(%ebp), %edi
14347 + sub $128, %edi
14348 + mov %edi, TI_lowest_stack(%ebp)
14349 +
14350 + popl %eax
14351 + popl %edi
14352 + ret
14353 +ENDPROC(pax_erase_kstack)
14354 +#endif
14355 +
14356 +.macro __SAVE_ALL _DS
14357 cld
14358 PUSH_GS
14359 pushl_cfi %fs
14360 @@ -208,7 +341,7 @@
14361 CFI_REL_OFFSET ecx, 0
14362 pushl_cfi %ebx
14363 CFI_REL_OFFSET ebx, 0
14364 - movl $(__USER_DS), %edx
14365 + movl $\_DS, %edx
14366 movl %edx, %ds
14367 movl %edx, %es
14368 movl $(__KERNEL_PERCPU), %edx
14369 @@ -216,6 +349,15 @@
14370 SET_KERNEL_GS %edx
14371 .endm
14372
14373 +.macro SAVE_ALL
14374 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14375 + __SAVE_ALL __KERNEL_DS
14376 + pax_enter_kernel
14377 +#else
14378 + __SAVE_ALL __USER_DS
14379 +#endif
14380 +.endm
14381 +
14382 .macro RESTORE_INT_REGS
14383 popl_cfi %ebx
14384 CFI_RESTORE ebx
14385 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
14386 popfl_cfi
14387 jmp syscall_exit
14388 CFI_ENDPROC
14389 -END(ret_from_fork)
14390 +ENDPROC(ret_from_fork)
14391
14392 /*
14393 * Interrupt exit functions should be protected against kprobes
14394 @@ -335,7 +477,15 @@ resume_userspace_sig:
14395 andl $SEGMENT_RPL_MASK, %eax
14396 #endif
14397 cmpl $USER_RPL, %eax
14398 +
14399 +#ifdef CONFIG_PAX_KERNEXEC
14400 + jae resume_userspace
14401 +
14402 + PAX_EXIT_KERNEL
14403 + jmp resume_kernel
14404 +#else
14405 jb resume_kernel # not returning to v8086 or userspace
14406 +#endif
14407
14408 ENTRY(resume_userspace)
14409 LOCKDEP_SYS_EXIT
14410 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
14411 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14412 # int/exception return?
14413 jne work_pending
14414 - jmp restore_all
14415 -END(ret_from_exception)
14416 + jmp restore_all_pax
14417 +ENDPROC(ret_from_exception)
14418
14419 #ifdef CONFIG_PREEMPT
14420 ENTRY(resume_kernel)
14421 @@ -363,7 +513,7 @@ need_resched:
14422 jz restore_all
14423 call preempt_schedule_irq
14424 jmp need_resched
14425 -END(resume_kernel)
14426 +ENDPROC(resume_kernel)
14427 #endif
14428 CFI_ENDPROC
14429 /*
14430 @@ -397,23 +547,34 @@ sysenter_past_esp:
14431 /*CFI_REL_OFFSET cs, 0*/
14432 /*
14433 * Push current_thread_info()->sysenter_return to the stack.
14434 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14435 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14436 */
14437 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14438 + pushl_cfi $0
14439 CFI_REL_OFFSET eip, 0
14440
14441 pushl_cfi %eax
14442 SAVE_ALL
14443 + GET_THREAD_INFO(%ebp)
14444 + movl TI_sysenter_return(%ebp),%ebp
14445 + movl %ebp,PT_EIP(%esp)
14446 ENABLE_INTERRUPTS(CLBR_NONE)
14447
14448 /*
14449 * Load the potential sixth argument from user stack.
14450 * Careful about security.
14451 */
14452 + movl PT_OLDESP(%esp),%ebp
14453 +
14454 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14455 + mov PT_OLDSS(%esp),%ds
14456 +1: movl %ds:(%ebp),%ebp
14457 + push %ss
14458 + pop %ds
14459 +#else
14460 cmpl $__PAGE_OFFSET-3,%ebp
14461 jae syscall_fault
14462 1: movl (%ebp),%ebp
14463 +#endif
14464 +
14465 movl %ebp,PT_EBP(%esp)
14466 .section __ex_table,"a"
14467 .align 4
14468 @@ -436,12 +597,24 @@ sysenter_do_call:
14469 testl $_TIF_ALLWORK_MASK, %ecx
14470 jne sysexit_audit
14471 sysenter_exit:
14472 +
14473 +#ifdef CONFIG_PAX_RANDKSTACK
14474 + pushl_cfi %eax
14475 + movl %esp, %eax
14476 + call pax_randomize_kstack
14477 + popl_cfi %eax
14478 +#endif
14479 +
14480 + pax_erase_kstack
14481 +
14482 /* if something modifies registers it must also disable sysexit */
14483 movl PT_EIP(%esp), %edx
14484 movl PT_OLDESP(%esp), %ecx
14485 xorl %ebp,%ebp
14486 TRACE_IRQS_ON
14487 1: mov PT_FS(%esp), %fs
14488 +2: mov PT_DS(%esp), %ds
14489 +3: mov PT_ES(%esp), %es
14490 PTGS_TO_GS
14491 ENABLE_INTERRUPTS_SYSEXIT
14492
14493 @@ -458,6 +631,9 @@ sysenter_audit:
14494 movl %eax,%edx /* 2nd arg: syscall number */
14495 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14496 call __audit_syscall_entry
14497 +
14498 + pax_erase_kstack
14499 +
14500 pushl_cfi %ebx
14501 movl PT_EAX(%esp),%eax /* reload syscall number */
14502 jmp sysenter_do_call
14503 @@ -483,11 +659,17 @@ sysexit_audit:
14504
14505 CFI_ENDPROC
14506 .pushsection .fixup,"ax"
14507 -2: movl $0,PT_FS(%esp)
14508 +4: movl $0,PT_FS(%esp)
14509 + jmp 1b
14510 +5: movl $0,PT_DS(%esp)
14511 + jmp 1b
14512 +6: movl $0,PT_ES(%esp)
14513 jmp 1b
14514 .section __ex_table,"a"
14515 .align 4
14516 - .long 1b,2b
14517 + .long 1b,4b
14518 + .long 2b,5b
14519 + .long 3b,6b
14520 .popsection
14521 PTGS_TO_GS_EX
14522 ENDPROC(ia32_sysenter_target)
14523 @@ -520,6 +702,15 @@ syscall_exit:
14524 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14525 jne syscall_exit_work
14526
14527 +restore_all_pax:
14528 +
14529 +#ifdef CONFIG_PAX_RANDKSTACK
14530 + movl %esp, %eax
14531 + call pax_randomize_kstack
14532 +#endif
14533 +
14534 + pax_erase_kstack
14535 +
14536 restore_all:
14537 TRACE_IRQS_IRET
14538 restore_all_notrace:
14539 @@ -579,14 +770,34 @@ ldt_ss:
14540 * compensating for the offset by changing to the ESPFIX segment with
14541 * a base address that matches for the difference.
14542 */
14543 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14544 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14545 mov %esp, %edx /* load kernel esp */
14546 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14547 mov %dx, %ax /* eax: new kernel esp */
14548 sub %eax, %edx /* offset (low word is 0) */
14549 +#ifdef CONFIG_SMP
14550 + movl PER_CPU_VAR(cpu_number), %ebx
14551 + shll $PAGE_SHIFT_asm, %ebx
14552 + addl $cpu_gdt_table, %ebx
14553 +#else
14554 + movl $cpu_gdt_table, %ebx
14555 +#endif
14556 shr $16, %edx
14557 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14558 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14559 +
14560 +#ifdef CONFIG_PAX_KERNEXEC
14561 + mov %cr0, %esi
14562 + btr $16, %esi
14563 + mov %esi, %cr0
14564 +#endif
14565 +
14566 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14567 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14568 +
14569 +#ifdef CONFIG_PAX_KERNEXEC
14570 + bts $16, %esi
14571 + mov %esi, %cr0
14572 +#endif
14573 +
14574 pushl_cfi $__ESPFIX_SS
14575 pushl_cfi %eax /* new kernel esp */
14576 /* Disable interrupts, but do not irqtrace this section: we
14577 @@ -615,38 +826,30 @@ work_resched:
14578 movl TI_flags(%ebp), %ecx
14579 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14580 # than syscall tracing?
14581 - jz restore_all
14582 + jz restore_all_pax
14583 testb $_TIF_NEED_RESCHED, %cl
14584 jnz work_resched
14585
14586 work_notifysig: # deal with pending signals and
14587 # notify-resume requests
14588 + movl %esp, %eax
14589 #ifdef CONFIG_VM86
14590 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14591 - movl %esp, %eax
14592 - jne work_notifysig_v86 # returning to kernel-space or
14593 + jz 1f # returning to kernel-space or
14594 # vm86-space
14595 - TRACE_IRQS_ON
14596 - ENABLE_INTERRUPTS(CLBR_NONE)
14597 - xorl %edx, %edx
14598 - call do_notify_resume
14599 - jmp resume_userspace_sig
14600
14601 - ALIGN
14602 -work_notifysig_v86:
14603 pushl_cfi %ecx # save ti_flags for do_notify_resume
14604 call save_v86_state # %eax contains pt_regs pointer
14605 popl_cfi %ecx
14606 movl %eax, %esp
14607 -#else
14608 - movl %esp, %eax
14609 +1:
14610 #endif
14611 TRACE_IRQS_ON
14612 ENABLE_INTERRUPTS(CLBR_NONE)
14613 xorl %edx, %edx
14614 call do_notify_resume
14615 jmp resume_userspace_sig
14616 -END(work_pending)
14617 +ENDPROC(work_pending)
14618
14619 # perform syscall exit tracing
14620 ALIGN
14621 @@ -654,11 +857,14 @@ syscall_trace_entry:
14622 movl $-ENOSYS,PT_EAX(%esp)
14623 movl %esp, %eax
14624 call syscall_trace_enter
14625 +
14626 + pax_erase_kstack
14627 +
14628 /* What it returned is what we'll actually use. */
14629 cmpl $(NR_syscalls), %eax
14630 jnae syscall_call
14631 jmp syscall_exit
14632 -END(syscall_trace_entry)
14633 +ENDPROC(syscall_trace_entry)
14634
14635 # perform syscall exit tracing
14636 ALIGN
14637 @@ -671,20 +877,24 @@ syscall_exit_work:
14638 movl %esp, %eax
14639 call syscall_trace_leave
14640 jmp resume_userspace
14641 -END(syscall_exit_work)
14642 +ENDPROC(syscall_exit_work)
14643 CFI_ENDPROC
14644
14645 RING0_INT_FRAME # can't unwind into user space anyway
14646 syscall_fault:
14647 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14648 + push %ss
14649 + pop %ds
14650 +#endif
14651 GET_THREAD_INFO(%ebp)
14652 movl $-EFAULT,PT_EAX(%esp)
14653 jmp resume_userspace
14654 -END(syscall_fault)
14655 +ENDPROC(syscall_fault)
14656
14657 syscall_badsys:
14658 movl $-ENOSYS,PT_EAX(%esp)
14659 jmp resume_userspace
14660 -END(syscall_badsys)
14661 +ENDPROC(syscall_badsys)
14662 CFI_ENDPROC
14663 /*
14664 * End of kprobes section
14665 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
14666 CFI_ENDPROC
14667 ENDPROC(ptregs_clone)
14668
14669 + ALIGN;
14670 +ENTRY(kernel_execve)
14671 + CFI_STARTPROC
14672 + pushl_cfi %ebp
14673 + sub $PT_OLDSS+4,%esp
14674 + pushl_cfi %edi
14675 + pushl_cfi %ecx
14676 + pushl_cfi %eax
14677 + lea 3*4(%esp),%edi
14678 + mov $PT_OLDSS/4+1,%ecx
14679 + xorl %eax,%eax
14680 + rep stosl
14681 + popl_cfi %eax
14682 + popl_cfi %ecx
14683 + popl_cfi %edi
14684 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14685 + pushl_cfi %esp
14686 + call sys_execve
14687 + add $4,%esp
14688 + CFI_ADJUST_CFA_OFFSET -4
14689 + GET_THREAD_INFO(%ebp)
14690 + test %eax,%eax
14691 + jz syscall_exit
14692 + add $PT_OLDSS+4,%esp
14693 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14694 + popl_cfi %ebp
14695 + ret
14696 + CFI_ENDPROC
14697 +ENDPROC(kernel_execve)
14698 +
14699 .macro FIXUP_ESPFIX_STACK
14700 /*
14701 * Switch back for ESPFIX stack to the normal zerobased stack
14702 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
14703 * normal stack and adjusts ESP with the matching offset.
14704 */
14705 /* fixup the stack */
14706 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14707 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14708 +#ifdef CONFIG_SMP
14709 + movl PER_CPU_VAR(cpu_number), %ebx
14710 + shll $PAGE_SHIFT_asm, %ebx
14711 + addl $cpu_gdt_table, %ebx
14712 +#else
14713 + movl $cpu_gdt_table, %ebx
14714 +#endif
14715 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14716 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14717 shl $16, %eax
14718 addl %esp, %eax /* the adjusted stack pointer */
14719 pushl_cfi $__KERNEL_DS
14720 @@ -819,7 +1066,7 @@ vector=vector+1
14721 .endr
14722 2: jmp common_interrupt
14723 .endr
14724 -END(irq_entries_start)
14725 +ENDPROC(irq_entries_start)
14726
14727 .previous
14728 END(interrupt)
14729 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
14730 pushl_cfi $do_coprocessor_error
14731 jmp error_code
14732 CFI_ENDPROC
14733 -END(coprocessor_error)
14734 +ENDPROC(coprocessor_error)
14735
14736 ENTRY(simd_coprocessor_error)
14737 RING0_INT_FRAME
14738 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
14739 #endif
14740 jmp error_code
14741 CFI_ENDPROC
14742 -END(simd_coprocessor_error)
14743 +ENDPROC(simd_coprocessor_error)
14744
14745 ENTRY(device_not_available)
14746 RING0_INT_FRAME
14747 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
14748 pushl_cfi $do_device_not_available
14749 jmp error_code
14750 CFI_ENDPROC
14751 -END(device_not_available)
14752 +ENDPROC(device_not_available)
14753
14754 #ifdef CONFIG_PARAVIRT
14755 ENTRY(native_iret)
14756 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
14757 .align 4
14758 .long native_iret, iret_exc
14759 .previous
14760 -END(native_iret)
14761 +ENDPROC(native_iret)
14762
14763 ENTRY(native_irq_enable_sysexit)
14764 sti
14765 sysexit
14766 -END(native_irq_enable_sysexit)
14767 +ENDPROC(native_irq_enable_sysexit)
14768 #endif
14769
14770 ENTRY(overflow)
14771 @@ -919,7 +1166,7 @@ ENTRY(overflow)
14772 pushl_cfi $do_overflow
14773 jmp error_code
14774 CFI_ENDPROC
14775 -END(overflow)
14776 +ENDPROC(overflow)
14777
14778 ENTRY(bounds)
14779 RING0_INT_FRAME
14780 @@ -927,7 +1174,7 @@ ENTRY(bounds)
14781 pushl_cfi $do_bounds
14782 jmp error_code
14783 CFI_ENDPROC
14784 -END(bounds)
14785 +ENDPROC(bounds)
14786
14787 ENTRY(invalid_op)
14788 RING0_INT_FRAME
14789 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
14790 pushl_cfi $do_invalid_op
14791 jmp error_code
14792 CFI_ENDPROC
14793 -END(invalid_op)
14794 +ENDPROC(invalid_op)
14795
14796 ENTRY(coprocessor_segment_overrun)
14797 RING0_INT_FRAME
14798 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
14799 pushl_cfi $do_coprocessor_segment_overrun
14800 jmp error_code
14801 CFI_ENDPROC
14802 -END(coprocessor_segment_overrun)
14803 +ENDPROC(coprocessor_segment_overrun)
14804
14805 ENTRY(invalid_TSS)
14806 RING0_EC_FRAME
14807 pushl_cfi $do_invalid_TSS
14808 jmp error_code
14809 CFI_ENDPROC
14810 -END(invalid_TSS)
14811 +ENDPROC(invalid_TSS)
14812
14813 ENTRY(segment_not_present)
14814 RING0_EC_FRAME
14815 pushl_cfi $do_segment_not_present
14816 jmp error_code
14817 CFI_ENDPROC
14818 -END(segment_not_present)
14819 +ENDPROC(segment_not_present)
14820
14821 ENTRY(stack_segment)
14822 RING0_EC_FRAME
14823 pushl_cfi $do_stack_segment
14824 jmp error_code
14825 CFI_ENDPROC
14826 -END(stack_segment)
14827 +ENDPROC(stack_segment)
14828
14829 ENTRY(alignment_check)
14830 RING0_EC_FRAME
14831 pushl_cfi $do_alignment_check
14832 jmp error_code
14833 CFI_ENDPROC
14834 -END(alignment_check)
14835 +ENDPROC(alignment_check)
14836
14837 ENTRY(divide_error)
14838 RING0_INT_FRAME
14839 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
14840 pushl_cfi $do_divide_error
14841 jmp error_code
14842 CFI_ENDPROC
14843 -END(divide_error)
14844 +ENDPROC(divide_error)
14845
14846 #ifdef CONFIG_X86_MCE
14847 ENTRY(machine_check)
14848 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
14849 pushl_cfi machine_check_vector
14850 jmp error_code
14851 CFI_ENDPROC
14852 -END(machine_check)
14853 +ENDPROC(machine_check)
14854 #endif
14855
14856 ENTRY(spurious_interrupt_bug)
14857 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
14858 pushl_cfi $do_spurious_interrupt_bug
14859 jmp error_code
14860 CFI_ENDPROC
14861 -END(spurious_interrupt_bug)
14862 +ENDPROC(spurious_interrupt_bug)
14863 /*
14864 * End of kprobes section
14865 */
14866 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
14867
14868 ENTRY(mcount)
14869 ret
14870 -END(mcount)
14871 +ENDPROC(mcount)
14872
14873 ENTRY(ftrace_caller)
14874 cmpl $0, function_trace_stop
14875 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
14876 .globl ftrace_stub
14877 ftrace_stub:
14878 ret
14879 -END(ftrace_caller)
14880 +ENDPROC(ftrace_caller)
14881
14882 #else /* ! CONFIG_DYNAMIC_FTRACE */
14883
14884 @@ -1177,7 +1424,7 @@ trace:
14885 popl %ecx
14886 popl %eax
14887 jmp ftrace_stub
14888 -END(mcount)
14889 +ENDPROC(mcount)
14890 #endif /* CONFIG_DYNAMIC_FTRACE */
14891 #endif /* CONFIG_FUNCTION_TRACER */
14892
14893 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
14894 popl %ecx
14895 popl %eax
14896 ret
14897 -END(ftrace_graph_caller)
14898 +ENDPROC(ftrace_graph_caller)
14899
14900 .globl return_to_handler
14901 return_to_handler:
14902 @@ -1253,15 +1500,18 @@ error_code:
14903 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
14904 REG_TO_PTGS %ecx
14905 SET_KERNEL_GS %ecx
14906 - movl $(__USER_DS), %ecx
14907 + movl $(__KERNEL_DS), %ecx
14908 movl %ecx, %ds
14909 movl %ecx, %es
14910 +
14911 + pax_enter_kernel
14912 +
14913 TRACE_IRQS_OFF
14914 movl %esp,%eax # pt_regs pointer
14915 call *%edi
14916 jmp ret_from_exception
14917 CFI_ENDPROC
14918 -END(page_fault)
14919 +ENDPROC(page_fault)
14920
14921 /*
14922 * Debug traps and NMI can happen at the one SYSENTER instruction
14923 @@ -1303,7 +1553,7 @@ debug_stack_correct:
14924 call do_debug
14925 jmp ret_from_exception
14926 CFI_ENDPROC
14927 -END(debug)
14928 +ENDPROC(debug)
14929
14930 /*
14931 * NMI is doubly nasty. It can happen _while_ we're handling
14932 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
14933 xorl %edx,%edx # zero error code
14934 movl %esp,%eax # pt_regs pointer
14935 call do_nmi
14936 +
14937 + pax_exit_kernel
14938 +
14939 jmp restore_all_notrace
14940 CFI_ENDPROC
14941
14942 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
14943 FIXUP_ESPFIX_STACK # %eax == %esp
14944 xorl %edx,%edx # zero error code
14945 call do_nmi
14946 +
14947 + pax_exit_kernel
14948 +
14949 RESTORE_REGS
14950 lss 12+4(%esp), %esp # back to espfix stack
14951 CFI_ADJUST_CFA_OFFSET -24
14952 jmp irq_return
14953 CFI_ENDPROC
14954 -END(nmi)
14955 +ENDPROC(nmi)
14956
14957 ENTRY(int3)
14958 RING0_INT_FRAME
14959 @@ -1393,14 +1649,14 @@ ENTRY(int3)
14960 call do_int3
14961 jmp ret_from_exception
14962 CFI_ENDPROC
14963 -END(int3)
14964 +ENDPROC(int3)
14965
14966 ENTRY(general_protection)
14967 RING0_EC_FRAME
14968 pushl_cfi $do_general_protection
14969 jmp error_code
14970 CFI_ENDPROC
14971 -END(general_protection)
14972 +ENDPROC(general_protection)
14973
14974 #ifdef CONFIG_KVM_GUEST
14975 ENTRY(async_page_fault)
14976 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
14977 pushl_cfi $do_async_page_fault
14978 jmp error_code
14979 CFI_ENDPROC
14980 -END(async_page_fault)
14981 +ENDPROC(async_page_fault)
14982 #endif
14983
14984 /*
14985 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
14986 index 1333d98..b340ca2 100644
14987 --- a/arch/x86/kernel/entry_64.S
14988 +++ b/arch/x86/kernel/entry_64.S
14989 @@ -56,6 +56,8 @@
14990 #include <asm/ftrace.h>
14991 #include <asm/percpu.h>
14992 #include <linux/err.h>
14993 +#include <asm/pgtable.h>
14994 +#include <asm/alternative-asm.h>
14995
14996 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14997 #include <linux/elf-em.h>
14998 @@ -69,8 +71,9 @@
14999 #ifdef CONFIG_FUNCTION_TRACER
15000 #ifdef CONFIG_DYNAMIC_FTRACE
15001 ENTRY(mcount)
15002 + pax_force_retaddr
15003 retq
15004 -END(mcount)
15005 +ENDPROC(mcount)
15006
15007 ENTRY(ftrace_caller)
15008 cmpl $0, function_trace_stop
15009 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15010 #endif
15011
15012 GLOBAL(ftrace_stub)
15013 + pax_force_retaddr
15014 retq
15015 -END(ftrace_caller)
15016 +ENDPROC(ftrace_caller)
15017
15018 #else /* ! CONFIG_DYNAMIC_FTRACE */
15019 ENTRY(mcount)
15020 @@ -113,6 +117,7 @@ ENTRY(mcount)
15021 #endif
15022
15023 GLOBAL(ftrace_stub)
15024 + pax_force_retaddr
15025 retq
15026
15027 trace:
15028 @@ -122,12 +127,13 @@ trace:
15029 movq 8(%rbp), %rsi
15030 subq $MCOUNT_INSN_SIZE, %rdi
15031
15032 + pax_force_fptr ftrace_trace_function
15033 call *ftrace_trace_function
15034
15035 MCOUNT_RESTORE_FRAME
15036
15037 jmp ftrace_stub
15038 -END(mcount)
15039 +ENDPROC(mcount)
15040 #endif /* CONFIG_DYNAMIC_FTRACE */
15041 #endif /* CONFIG_FUNCTION_TRACER */
15042
15043 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15044
15045 MCOUNT_RESTORE_FRAME
15046
15047 + pax_force_retaddr
15048 retq
15049 -END(ftrace_graph_caller)
15050 +ENDPROC(ftrace_graph_caller)
15051
15052 GLOBAL(return_to_handler)
15053 subq $24, %rsp
15054 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15055 movq 8(%rsp), %rdx
15056 movq (%rsp), %rax
15057 addq $24, %rsp
15058 + pax_force_fptr %rdi
15059 jmp *%rdi
15060 #endif
15061
15062 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15063 ENDPROC(native_usergs_sysret64)
15064 #endif /* CONFIG_PARAVIRT */
15065
15066 + .macro ljmpq sel, off
15067 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15068 + .byte 0x48; ljmp *1234f(%rip)
15069 + .pushsection .rodata
15070 + .align 16
15071 + 1234: .quad \off; .word \sel
15072 + .popsection
15073 +#else
15074 + pushq $\sel
15075 + pushq $\off
15076 + lretq
15077 +#endif
15078 + .endm
15079 +
15080 + .macro pax_enter_kernel
15081 + pax_set_fptr_mask
15082 +#ifdef CONFIG_PAX_KERNEXEC
15083 + call pax_enter_kernel
15084 +#endif
15085 + .endm
15086 +
15087 + .macro pax_exit_kernel
15088 +#ifdef CONFIG_PAX_KERNEXEC
15089 + call pax_exit_kernel
15090 +#endif
15091 + .endm
15092 +
15093 +#ifdef CONFIG_PAX_KERNEXEC
15094 +ENTRY(pax_enter_kernel)
15095 + pushq %rdi
15096 +
15097 +#ifdef CONFIG_PARAVIRT
15098 + PV_SAVE_REGS(CLBR_RDI)
15099 +#endif
15100 +
15101 + GET_CR0_INTO_RDI
15102 + bts $16,%rdi
15103 + jnc 3f
15104 + mov %cs,%edi
15105 + cmp $__KERNEL_CS,%edi
15106 + jnz 2f
15107 +1:
15108 +
15109 +#ifdef CONFIG_PARAVIRT
15110 + PV_RESTORE_REGS(CLBR_RDI)
15111 +#endif
15112 +
15113 + popq %rdi
15114 + pax_force_retaddr
15115 + retq
15116 +
15117 +2: ljmpq __KERNEL_CS,1f
15118 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15119 +4: SET_RDI_INTO_CR0
15120 + jmp 1b
15121 +ENDPROC(pax_enter_kernel)
15122 +
15123 +ENTRY(pax_exit_kernel)
15124 + pushq %rdi
15125 +
15126 +#ifdef CONFIG_PARAVIRT
15127 + PV_SAVE_REGS(CLBR_RDI)
15128 +#endif
15129 +
15130 + mov %cs,%rdi
15131 + cmp $__KERNEXEC_KERNEL_CS,%edi
15132 + jz 2f
15133 +1:
15134 +
15135 +#ifdef CONFIG_PARAVIRT
15136 + PV_RESTORE_REGS(CLBR_RDI);
15137 +#endif
15138 +
15139 + popq %rdi
15140 + pax_force_retaddr
15141 + retq
15142 +
15143 +2: GET_CR0_INTO_RDI
15144 + btr $16,%rdi
15145 + ljmpq __KERNEL_CS,3f
15146 +3: SET_RDI_INTO_CR0
15147 + jmp 1b
15148 +#ifdef CONFIG_PARAVIRT
15149 + PV_RESTORE_REGS(CLBR_RDI);
15150 +#endif
15151 +
15152 + popq %rdi
15153 + pax_force_retaddr
15154 + retq
15155 +ENDPROC(pax_exit_kernel)
15156 +#endif
15157 +
15158 + .macro pax_enter_kernel_user
15159 + pax_set_fptr_mask
15160 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15161 + call pax_enter_kernel_user
15162 +#endif
15163 + .endm
15164 +
15165 + .macro pax_exit_kernel_user
15166 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15167 + call pax_exit_kernel_user
15168 +#endif
15169 +#ifdef CONFIG_PAX_RANDKSTACK
15170 + pushq %rax
15171 + call pax_randomize_kstack
15172 + popq %rax
15173 +#endif
15174 + .endm
15175 +
15176 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15177 +ENTRY(pax_enter_kernel_user)
15178 + pushq %rdi
15179 + pushq %rbx
15180 +
15181 +#ifdef CONFIG_PARAVIRT
15182 + PV_SAVE_REGS(CLBR_RDI)
15183 +#endif
15184 +
15185 + GET_CR3_INTO_RDI
15186 + mov %rdi,%rbx
15187 + add $__START_KERNEL_map,%rbx
15188 + sub phys_base(%rip),%rbx
15189 +
15190 +#ifdef CONFIG_PARAVIRT
15191 + pushq %rdi
15192 + cmpl $0, pv_info+PARAVIRT_enabled
15193 + jz 1f
15194 + i = 0
15195 + .rept USER_PGD_PTRS
15196 + mov i*8(%rbx),%rsi
15197 + mov $0,%sil
15198 + lea i*8(%rbx),%rdi
15199 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15200 + i = i + 1
15201 + .endr
15202 + jmp 2f
15203 +1:
15204 +#endif
15205 +
15206 + i = 0
15207 + .rept USER_PGD_PTRS
15208 + movb $0,i*8(%rbx)
15209 + i = i + 1
15210 + .endr
15211 +
15212 +#ifdef CONFIG_PARAVIRT
15213 +2: popq %rdi
15214 +#endif
15215 + SET_RDI_INTO_CR3
15216 +
15217 +#ifdef CONFIG_PAX_KERNEXEC
15218 + GET_CR0_INTO_RDI
15219 + bts $16,%rdi
15220 + SET_RDI_INTO_CR0
15221 +#endif
15222 +
15223 +#ifdef CONFIG_PARAVIRT
15224 + PV_RESTORE_REGS(CLBR_RDI)
15225 +#endif
15226 +
15227 + popq %rbx
15228 + popq %rdi
15229 + pax_force_retaddr
15230 + retq
15231 +ENDPROC(pax_enter_kernel_user)
15232 +
15233 +ENTRY(pax_exit_kernel_user)
15234 + push %rdi
15235 +
15236 +#ifdef CONFIG_PARAVIRT
15237 + pushq %rbx
15238 + PV_SAVE_REGS(CLBR_RDI)
15239 +#endif
15240 +
15241 +#ifdef CONFIG_PAX_KERNEXEC
15242 + GET_CR0_INTO_RDI
15243 + btr $16,%rdi
15244 + SET_RDI_INTO_CR0
15245 +#endif
15246 +
15247 + GET_CR3_INTO_RDI
15248 + add $__START_KERNEL_map,%rdi
15249 + sub phys_base(%rip),%rdi
15250 +
15251 +#ifdef CONFIG_PARAVIRT
15252 + cmpl $0, pv_info+PARAVIRT_enabled
15253 + jz 1f
15254 + mov %rdi,%rbx
15255 + i = 0
15256 + .rept USER_PGD_PTRS
15257 + mov i*8(%rbx),%rsi
15258 + mov $0x67,%sil
15259 + lea i*8(%rbx),%rdi
15260 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15261 + i = i + 1
15262 + .endr
15263 + jmp 2f
15264 +1:
15265 +#endif
15266 +
15267 + i = 0
15268 + .rept USER_PGD_PTRS
15269 + movb $0x67,i*8(%rdi)
15270 + i = i + 1
15271 + .endr
15272 +
15273 +#ifdef CONFIG_PARAVIRT
15274 +2: PV_RESTORE_REGS(CLBR_RDI)
15275 + popq %rbx
15276 +#endif
15277 +
15278 + popq %rdi
15279 + pax_force_retaddr
15280 + retq
15281 +ENDPROC(pax_exit_kernel_user)
15282 +#endif
15283 +
15284 +.macro pax_erase_kstack
15285 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15286 + call pax_erase_kstack
15287 +#endif
15288 +.endm
15289 +
15290 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15291 +/*
15292 + * r11: thread_info
15293 + * rcx, rdx: can be clobbered
15294 + */
15295 +ENTRY(pax_erase_kstack)
15296 + pushq %rdi
15297 + pushq %rax
15298 + pushq %r11
15299 +
15300 + GET_THREAD_INFO(%r11)
15301 + mov TI_lowest_stack(%r11), %rdi
15302 + mov $-0xBEEF, %rax
15303 + std
15304 +
15305 +1: mov %edi, %ecx
15306 + and $THREAD_SIZE_asm - 1, %ecx
15307 + shr $3, %ecx
15308 + repne scasq
15309 + jecxz 2f
15310 +
15311 + cmp $2*8, %ecx
15312 + jc 2f
15313 +
15314 + mov $2*8, %ecx
15315 + repe scasq
15316 + jecxz 2f
15317 + jne 1b
15318 +
15319 +2: cld
15320 + mov %esp, %ecx
15321 + sub %edi, %ecx
15322 +
15323 + cmp $THREAD_SIZE_asm, %rcx
15324 + jb 3f
15325 + ud2
15326 +3:
15327 +
15328 + shr $3, %ecx
15329 + rep stosq
15330 +
15331 + mov TI_task_thread_sp0(%r11), %rdi
15332 + sub $256, %rdi
15333 + mov %rdi, TI_lowest_stack(%r11)
15334 +
15335 + popq %r11
15336 + popq %rax
15337 + popq %rdi
15338 + pax_force_retaddr
15339 + ret
15340 +ENDPROC(pax_erase_kstack)
15341 +#endif
15342
15343 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15344 #ifdef CONFIG_TRACE_IRQFLAGS
15345 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
15346 .endm
15347
15348 .macro UNFAKE_STACK_FRAME
15349 - addq $8*6, %rsp
15350 - CFI_ADJUST_CFA_OFFSET -(6*8)
15351 + addq $8*6 + ARG_SKIP, %rsp
15352 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15353 .endm
15354
15355 /*
15356 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
15357 movq %rsp, %rsi
15358
15359 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15360 - testl $3, CS(%rdi)
15361 + testb $3, CS(%rdi)
15362 je 1f
15363 SWAPGS
15364 /*
15365 @@ -356,9 +640,10 @@ ENTRY(save_rest)
15366 movq_cfi r15, R15+16
15367 movq %r11, 8(%rsp) /* return address */
15368 FIXUP_TOP_OF_STACK %r11, 16
15369 + pax_force_retaddr
15370 ret
15371 CFI_ENDPROC
15372 -END(save_rest)
15373 +ENDPROC(save_rest)
15374
15375 /* save complete stack frame */
15376 .pushsection .kprobes.text, "ax"
15377 @@ -387,9 +672,10 @@ ENTRY(save_paranoid)
15378 js 1f /* negative -> in kernel */
15379 SWAPGS
15380 xorl %ebx,%ebx
15381 -1: ret
15382 +1: pax_force_retaddr_bts
15383 + ret
15384 CFI_ENDPROC
15385 -END(save_paranoid)
15386 +ENDPROC(save_paranoid)
15387 .popsection
15388
15389 /*
15390 @@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
15391
15392 RESTORE_REST
15393
15394 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15395 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15396 jz retint_restore_args
15397
15398 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15399 @@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
15400 jmp ret_from_sys_call # go to the SYSRET fastpath
15401
15402 CFI_ENDPROC
15403 -END(ret_from_fork)
15404 +ENDPROC(ret_from_fork)
15405
15406 /*
15407 * System call entry. Up to 6 arguments in registers are supported.
15408 @@ -457,7 +743,7 @@ END(ret_from_fork)
15409 ENTRY(system_call)
15410 CFI_STARTPROC simple
15411 CFI_SIGNAL_FRAME
15412 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15413 + CFI_DEF_CFA rsp,0
15414 CFI_REGISTER rip,rcx
15415 /*CFI_REGISTER rflags,r11*/
15416 SWAPGS_UNSAFE_STACK
15417 @@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
15418
15419 movq %rsp,PER_CPU_VAR(old_rsp)
15420 movq PER_CPU_VAR(kernel_stack),%rsp
15421 + SAVE_ARGS 8*6,0
15422 + pax_enter_kernel_user
15423 /*
15424 * No need to follow this irqs off/on section - it's straight
15425 * and short:
15426 */
15427 ENABLE_INTERRUPTS(CLBR_NONE)
15428 - SAVE_ARGS 8,0
15429 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15430 movq %rcx,RIP-ARGOFFSET(%rsp)
15431 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15432 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15433 + GET_THREAD_INFO(%rcx)
15434 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
15435 jnz tracesys
15436 system_call_fastpath:
15437 cmpq $__NR_syscall_max,%rax
15438 ja badsys
15439 - movq %r10,%rcx
15440 + movq R10-ARGOFFSET(%rsp),%rcx
15441 call *sys_call_table(,%rax,8) # XXX: rip relative
15442 movq %rax,RAX-ARGOFFSET(%rsp)
15443 /*
15444 @@ -498,10 +786,13 @@ sysret_check:
15445 LOCKDEP_SYS_EXIT
15446 DISABLE_INTERRUPTS(CLBR_NONE)
15447 TRACE_IRQS_OFF
15448 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
15449 + GET_THREAD_INFO(%rcx)
15450 + movl TI_flags(%rcx),%edx
15451 andl %edi,%edx
15452 jnz sysret_careful
15453 CFI_REMEMBER_STATE
15454 + pax_exit_kernel_user
15455 + pax_erase_kstack
15456 /*
15457 * sysretq will re-enable interrupts:
15458 */
15459 @@ -553,14 +844,18 @@ badsys:
15460 * jump back to the normal fast path.
15461 */
15462 auditsys:
15463 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
15464 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15465 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15466 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15467 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15468 movq %rax,%rsi /* 2nd arg: syscall number */
15469 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15470 call __audit_syscall_entry
15471 +
15472 + pax_erase_kstack
15473 +
15474 LOAD_ARGS 0 /* reload call-clobbered registers */
15475 + pax_set_fptr_mask
15476 jmp system_call_fastpath
15477
15478 /*
15479 @@ -581,7 +876,7 @@ sysret_audit:
15480 /* Do syscall tracing */
15481 tracesys:
15482 #ifdef CONFIG_AUDITSYSCALL
15483 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15484 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
15485 jz auditsys
15486 #endif
15487 SAVE_REST
15488 @@ -589,16 +884,20 @@ tracesys:
15489 FIXUP_TOP_OF_STACK %rdi
15490 movq %rsp,%rdi
15491 call syscall_trace_enter
15492 +
15493 + pax_erase_kstack
15494 +
15495 /*
15496 * Reload arg registers from stack in case ptrace changed them.
15497 * We don't reload %rax because syscall_trace_enter() returned
15498 * the value it wants us to use in the table lookup.
15499 */
15500 LOAD_ARGS ARGOFFSET, 1
15501 + pax_set_fptr_mask
15502 RESTORE_REST
15503 cmpq $__NR_syscall_max,%rax
15504 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15505 - movq %r10,%rcx /* fixup for C */
15506 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15507 call *sys_call_table(,%rax,8)
15508 movq %rax,RAX-ARGOFFSET(%rsp)
15509 /* Use IRET because user could have changed frame */
15510 @@ -619,6 +918,7 @@ GLOBAL(int_with_check)
15511 andl %edi,%edx
15512 jnz int_careful
15513 andl $~TS_COMPAT,TI_status(%rcx)
15514 + pax_erase_kstack
15515 jmp retint_swapgs
15516
15517 /* Either reschedule or signal or syscall exit tracking needed. */
15518 @@ -665,7 +965,7 @@ int_restore_rest:
15519 TRACE_IRQS_OFF
15520 jmp int_with_check
15521 CFI_ENDPROC
15522 -END(system_call)
15523 +ENDPROC(system_call)
15524
15525 /*
15526 * Certain special system calls that need to save a complete full stack frame.
15527 @@ -681,7 +981,7 @@ ENTRY(\label)
15528 call \func
15529 jmp ptregscall_common
15530 CFI_ENDPROC
15531 -END(\label)
15532 +ENDPROC(\label)
15533 .endm
15534
15535 PTREGSCALL stub_clone, sys_clone, %r8
15536 @@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
15537 movq_cfi_restore R12+8, r12
15538 movq_cfi_restore RBP+8, rbp
15539 movq_cfi_restore RBX+8, rbx
15540 + pax_force_retaddr
15541 ret $REST_SKIP /* pop extended registers */
15542 CFI_ENDPROC
15543 -END(ptregscall_common)
15544 +ENDPROC(ptregscall_common)
15545
15546 ENTRY(stub_execve)
15547 CFI_STARTPROC
15548 @@ -716,7 +1017,7 @@ ENTRY(stub_execve)
15549 RESTORE_REST
15550 jmp int_ret_from_sys_call
15551 CFI_ENDPROC
15552 -END(stub_execve)
15553 +ENDPROC(stub_execve)
15554
15555 /*
15556 * sigreturn is special because it needs to restore all registers on return.
15557 @@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
15558 RESTORE_REST
15559 jmp int_ret_from_sys_call
15560 CFI_ENDPROC
15561 -END(stub_rt_sigreturn)
15562 +ENDPROC(stub_rt_sigreturn)
15563
15564 /*
15565 * Build the entry stubs and pointer table with some assembler magic.
15566 @@ -769,7 +1070,7 @@ vector=vector+1
15567 2: jmp common_interrupt
15568 .endr
15569 CFI_ENDPROC
15570 -END(irq_entries_start)
15571 +ENDPROC(irq_entries_start)
15572
15573 .previous
15574 END(interrupt)
15575 @@ -789,6 +1090,16 @@ END(interrupt)
15576 subq $ORIG_RAX-RBP, %rsp
15577 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15578 SAVE_ARGS_IRQ
15579 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15580 + testb $3, CS(%rdi)
15581 + jnz 1f
15582 + pax_enter_kernel
15583 + jmp 2f
15584 +1: pax_enter_kernel_user
15585 +2:
15586 +#else
15587 + pax_enter_kernel
15588 +#endif
15589 call \func
15590 .endm
15591
15592 @@ -820,7 +1131,7 @@ ret_from_intr:
15593
15594 exit_intr:
15595 GET_THREAD_INFO(%rcx)
15596 - testl $3,CS-ARGOFFSET(%rsp)
15597 + testb $3,CS-ARGOFFSET(%rsp)
15598 je retint_kernel
15599
15600 /* Interrupt came from user space */
15601 @@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
15602 * The iretq could re-enable interrupts:
15603 */
15604 DISABLE_INTERRUPTS(CLBR_ANY)
15605 + pax_exit_kernel_user
15606 TRACE_IRQS_IRETQ
15607 SWAPGS
15608 jmp restore_args
15609
15610 retint_restore_args: /* return to kernel space */
15611 DISABLE_INTERRUPTS(CLBR_ANY)
15612 + pax_exit_kernel
15613 + pax_force_retaddr RIP-ARGOFFSET
15614 /*
15615 * The iretq could re-enable interrupts:
15616 */
15617 @@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
15618 #endif
15619
15620 CFI_ENDPROC
15621 -END(common_interrupt)
15622 +ENDPROC(common_interrupt)
15623 /*
15624 * End of kprobes section
15625 */
15626 @@ -953,7 +1267,7 @@ ENTRY(\sym)
15627 interrupt \do_sym
15628 jmp ret_from_intr
15629 CFI_ENDPROC
15630 -END(\sym)
15631 +ENDPROC(\sym)
15632 .endm
15633
15634 #ifdef CONFIG_SMP
15635 @@ -1026,12 +1340,22 @@ ENTRY(\sym)
15636 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15637 call error_entry
15638 DEFAULT_FRAME 0
15639 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15640 + testb $3, CS(%rsp)
15641 + jnz 1f
15642 + pax_enter_kernel
15643 + jmp 2f
15644 +1: pax_enter_kernel_user
15645 +2:
15646 +#else
15647 + pax_enter_kernel
15648 +#endif
15649 movq %rsp,%rdi /* pt_regs pointer */
15650 xorl %esi,%esi /* no error code */
15651 call \do_sym
15652 jmp error_exit /* %ebx: no swapgs flag */
15653 CFI_ENDPROC
15654 -END(\sym)
15655 +ENDPROC(\sym)
15656 .endm
15657
15658 .macro paranoidzeroentry sym do_sym
15659 @@ -1043,15 +1367,25 @@ ENTRY(\sym)
15660 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15661 call save_paranoid
15662 TRACE_IRQS_OFF
15663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15664 + testb $3, CS(%rsp)
15665 + jnz 1f
15666 + pax_enter_kernel
15667 + jmp 2f
15668 +1: pax_enter_kernel_user
15669 +2:
15670 +#else
15671 + pax_enter_kernel
15672 +#endif
15673 movq %rsp,%rdi /* pt_regs pointer */
15674 xorl %esi,%esi /* no error code */
15675 call \do_sym
15676 jmp paranoid_exit /* %ebx: no swapgs flag */
15677 CFI_ENDPROC
15678 -END(\sym)
15679 +ENDPROC(\sym)
15680 .endm
15681
15682 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
15683 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
15684 .macro paranoidzeroentry_ist sym do_sym ist
15685 ENTRY(\sym)
15686 INTR_FRAME
15687 @@ -1061,14 +1395,30 @@ ENTRY(\sym)
15688 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15689 call save_paranoid
15690 TRACE_IRQS_OFF
15691 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15692 + testb $3, CS(%rsp)
15693 + jnz 1f
15694 + pax_enter_kernel
15695 + jmp 2f
15696 +1: pax_enter_kernel_user
15697 +2:
15698 +#else
15699 + pax_enter_kernel
15700 +#endif
15701 movq %rsp,%rdi /* pt_regs pointer */
15702 xorl %esi,%esi /* no error code */
15703 +#ifdef CONFIG_SMP
15704 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
15705 + lea init_tss(%r12), %r12
15706 +#else
15707 + lea init_tss(%rip), %r12
15708 +#endif
15709 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15710 call \do_sym
15711 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15712 jmp paranoid_exit /* %ebx: no swapgs flag */
15713 CFI_ENDPROC
15714 -END(\sym)
15715 +ENDPROC(\sym)
15716 .endm
15717
15718 .macro errorentry sym do_sym
15719 @@ -1079,13 +1429,23 @@ ENTRY(\sym)
15720 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15721 call error_entry
15722 DEFAULT_FRAME 0
15723 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15724 + testb $3, CS(%rsp)
15725 + jnz 1f
15726 + pax_enter_kernel
15727 + jmp 2f
15728 +1: pax_enter_kernel_user
15729 +2:
15730 +#else
15731 + pax_enter_kernel
15732 +#endif
15733 movq %rsp,%rdi /* pt_regs pointer */
15734 movq ORIG_RAX(%rsp),%rsi /* get error code */
15735 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15736 call \do_sym
15737 jmp error_exit /* %ebx: no swapgs flag */
15738 CFI_ENDPROC
15739 -END(\sym)
15740 +ENDPROC(\sym)
15741 .endm
15742
15743 /* error code is on the stack already */
15744 @@ -1098,13 +1458,23 @@ ENTRY(\sym)
15745 call save_paranoid
15746 DEFAULT_FRAME 0
15747 TRACE_IRQS_OFF
15748 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15749 + testb $3, CS(%rsp)
15750 + jnz 1f
15751 + pax_enter_kernel
15752 + jmp 2f
15753 +1: pax_enter_kernel_user
15754 +2:
15755 +#else
15756 + pax_enter_kernel
15757 +#endif
15758 movq %rsp,%rdi /* pt_regs pointer */
15759 movq ORIG_RAX(%rsp),%rsi /* get error code */
15760 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15761 call \do_sym
15762 jmp paranoid_exit /* %ebx: no swapgs flag */
15763 CFI_ENDPROC
15764 -END(\sym)
15765 +ENDPROC(\sym)
15766 .endm
15767
15768 zeroentry divide_error do_divide_error
15769 @@ -1134,9 +1504,10 @@ gs_change:
15770 2: mfence /* workaround */
15771 SWAPGS
15772 popfq_cfi
15773 + pax_force_retaddr
15774 ret
15775 CFI_ENDPROC
15776 -END(native_load_gs_index)
15777 +ENDPROC(native_load_gs_index)
15778
15779 .section __ex_table,"a"
15780 .align 8
15781 @@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
15782 * Here we are in the child and the registers are set as they were
15783 * at kernel_thread() invocation in the parent.
15784 */
15785 + pax_force_fptr %rsi
15786 call *%rsi
15787 # exit
15788 mov %eax, %edi
15789 call do_exit
15790 ud2 # padding for call trace
15791 CFI_ENDPROC
15792 -END(kernel_thread_helper)
15793 +ENDPROC(kernel_thread_helper)
15794
15795 /*
15796 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
15797 @@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
15798 RESTORE_REST
15799 testq %rax,%rax
15800 je int_ret_from_sys_call
15801 - RESTORE_ARGS
15802 UNFAKE_STACK_FRAME
15803 + pax_force_retaddr
15804 ret
15805 CFI_ENDPROC
15806 -END(kernel_execve)
15807 +ENDPROC(kernel_execve)
15808
15809 /* Call softirq on interrupt stack. Interrupts are off. */
15810 ENTRY(call_softirq)
15811 @@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
15812 CFI_DEF_CFA_REGISTER rsp
15813 CFI_ADJUST_CFA_OFFSET -8
15814 decl PER_CPU_VAR(irq_count)
15815 + pax_force_retaddr
15816 ret
15817 CFI_ENDPROC
15818 -END(call_softirq)
15819 +ENDPROC(call_softirq)
15820
15821 #ifdef CONFIG_XEN
15822 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
15823 @@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
15824 decl PER_CPU_VAR(irq_count)
15825 jmp error_exit
15826 CFI_ENDPROC
15827 -END(xen_do_hypervisor_callback)
15828 +ENDPROC(xen_do_hypervisor_callback)
15829
15830 /*
15831 * Hypervisor uses this for application faults while it executes.
15832 @@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
15833 SAVE_ALL
15834 jmp error_exit
15835 CFI_ENDPROC
15836 -END(xen_failsafe_callback)
15837 +ENDPROC(xen_failsafe_callback)
15838
15839 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
15840 xen_hvm_callback_vector xen_evtchn_do_upcall
15841 @@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
15842 TRACE_IRQS_OFF
15843 testl %ebx,%ebx /* swapgs needed? */
15844 jnz paranoid_restore
15845 - testl $3,CS(%rsp)
15846 + testb $3,CS(%rsp)
15847 jnz paranoid_userspace
15848 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15849 + pax_exit_kernel
15850 + TRACE_IRQS_IRETQ 0
15851 + SWAPGS_UNSAFE_STACK
15852 + RESTORE_ALL 8
15853 + pax_force_retaddr_bts
15854 + jmp irq_return
15855 +#endif
15856 paranoid_swapgs:
15857 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15858 + pax_exit_kernel_user
15859 +#else
15860 + pax_exit_kernel
15861 +#endif
15862 TRACE_IRQS_IRETQ 0
15863 SWAPGS_UNSAFE_STACK
15864 RESTORE_ALL 8
15865 jmp irq_return
15866 paranoid_restore:
15867 + pax_exit_kernel
15868 TRACE_IRQS_IRETQ 0
15869 RESTORE_ALL 8
15870 + pax_force_retaddr_bts
15871 jmp irq_return
15872 paranoid_userspace:
15873 GET_THREAD_INFO(%rcx)
15874 @@ -1399,7 +1787,7 @@ paranoid_schedule:
15875 TRACE_IRQS_OFF
15876 jmp paranoid_userspace
15877 CFI_ENDPROC
15878 -END(paranoid_exit)
15879 +ENDPROC(paranoid_exit)
15880
15881 /*
15882 * Exception entry point. This expects an error code/orig_rax on the stack.
15883 @@ -1426,12 +1814,13 @@ ENTRY(error_entry)
15884 movq_cfi r14, R14+8
15885 movq_cfi r15, R15+8
15886 xorl %ebx,%ebx
15887 - testl $3,CS+8(%rsp)
15888 + testb $3,CS+8(%rsp)
15889 je error_kernelspace
15890 error_swapgs:
15891 SWAPGS
15892 error_sti:
15893 TRACE_IRQS_OFF
15894 + pax_force_retaddr_bts
15895 ret
15896
15897 /*
15898 @@ -1458,7 +1847,7 @@ bstep_iret:
15899 movq %rcx,RIP+8(%rsp)
15900 jmp error_swapgs
15901 CFI_ENDPROC
15902 -END(error_entry)
15903 +ENDPROC(error_entry)
15904
15905
15906 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
15907 @@ -1478,7 +1867,7 @@ ENTRY(error_exit)
15908 jnz retint_careful
15909 jmp retint_swapgs
15910 CFI_ENDPROC
15911 -END(error_exit)
15912 +ENDPROC(error_exit)
15913
15914 /*
15915 * Test if a given stack is an NMI stack or not.
15916 @@ -1535,9 +1924,11 @@ ENTRY(nmi)
15917 * If %cs was not the kernel segment, then the NMI triggered in user
15918 * space, which means it is definitely not nested.
15919 */
15920 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
15921 + je 1f
15922 cmpl $__KERNEL_CS, 16(%rsp)
15923 jne first_nmi
15924 -
15925 +1:
15926 /*
15927 * Check the special variable on the stack to see if NMIs are
15928 * executing.
15929 @@ -1659,6 +2050,16 @@ restart_nmi:
15930 */
15931 call save_paranoid
15932 DEFAULT_FRAME 0
15933 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15934 + testb $3, CS(%rsp)
15935 + jnz 1f
15936 + pax_enter_kernel
15937 + jmp 2f
15938 +1: pax_enter_kernel_user
15939 +2:
15940 +#else
15941 + pax_enter_kernel
15942 +#endif
15943 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
15944 movq %rsp,%rdi
15945 movq $-1,%rsi
15946 @@ -1666,14 +2067,25 @@ restart_nmi:
15947 testl %ebx,%ebx /* swapgs needed? */
15948 jnz nmi_restore
15949 nmi_swapgs:
15950 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15951 + pax_exit_kernel_user
15952 +#else
15953 + pax_exit_kernel
15954 +#endif
15955 SWAPGS_UNSAFE_STACK
15956 + RESTORE_ALL 8
15957 + /* Clear the NMI executing stack variable */
15958 + movq $0, 10*8(%rsp)
15959 + jmp irq_return
15960 nmi_restore:
15961 + pax_exit_kernel
15962 RESTORE_ALL 8
15963 + pax_force_retaddr_bts
15964 /* Clear the NMI executing stack variable */
15965 movq $0, 10*8(%rsp)
15966 jmp irq_return
15967 CFI_ENDPROC
15968 -END(nmi)
15969 +ENDPROC(nmi)
15970
15971 /*
15972 * If an NMI hit an iret because of an exception or breakpoint,
15973 @@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
15974 mov $-ENOSYS,%eax
15975 sysret
15976 CFI_ENDPROC
15977 -END(ignore_sysret)
15978 +ENDPROC(ignore_sysret)
15979
15980 /*
15981 * End of kprobes section
15982 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
15983 index c9a281f..ce2f317 100644
15984 --- a/arch/x86/kernel/ftrace.c
15985 +++ b/arch/x86/kernel/ftrace.c
15986 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
15987 static const void *mod_code_newcode; /* holds the text to write to the IP */
15988
15989 static unsigned nmi_wait_count;
15990 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
15991 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
15992
15993 int ftrace_arch_read_dyn_info(char *buf, int size)
15994 {
15995 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
15996
15997 r = snprintf(buf, size, "%u %u",
15998 nmi_wait_count,
15999 - atomic_read(&nmi_update_count));
16000 + atomic_read_unchecked(&nmi_update_count));
16001 return r;
16002 }
16003
16004 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16005
16006 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16007 smp_rmb();
16008 + pax_open_kernel();
16009 ftrace_mod_code();
16010 - atomic_inc(&nmi_update_count);
16011 + pax_close_kernel();
16012 + atomic_inc_unchecked(&nmi_update_count);
16013 }
16014 /* Must have previous changes seen before executions */
16015 smp_mb();
16016 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16017 {
16018 unsigned char replaced[MCOUNT_INSN_SIZE];
16019
16020 + ip = ktla_ktva(ip);
16021 +
16022 /*
16023 * Note: Due to modules and __init, code can
16024 * disappear and change, we need to protect against faulting
16025 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16026 unsigned char old[MCOUNT_INSN_SIZE], *new;
16027 int ret;
16028
16029 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16030 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16031 new = ftrace_call_replace(ip, (unsigned long)func);
16032 ret = ftrace_modify_code(ip, old, new);
16033
16034 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16035 {
16036 unsigned char code[MCOUNT_INSN_SIZE];
16037
16038 + ip = ktla_ktva(ip);
16039 +
16040 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16041 return -EFAULT;
16042
16043 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16044 index 51ff186..9e77418 100644
16045 --- a/arch/x86/kernel/head32.c
16046 +++ b/arch/x86/kernel/head32.c
16047 @@ -19,6 +19,7 @@
16048 #include <asm/io_apic.h>
16049 #include <asm/bios_ebda.h>
16050 #include <asm/tlbflush.h>
16051 +#include <asm/boot.h>
16052
16053 static void __init i386_default_early_setup(void)
16054 {
16055 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16056
16057 void __init i386_start_kernel(void)
16058 {
16059 - memblock_reserve(__pa_symbol(&_text),
16060 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16061 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16062
16063 #ifdef CONFIG_BLK_DEV_INITRD
16064 /* Reserve INITRD */
16065 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16066 index ce0be7c..c41476e 100644
16067 --- a/arch/x86/kernel/head_32.S
16068 +++ b/arch/x86/kernel/head_32.S
16069 @@ -25,6 +25,12 @@
16070 /* Physical address */
16071 #define pa(X) ((X) - __PAGE_OFFSET)
16072
16073 +#ifdef CONFIG_PAX_KERNEXEC
16074 +#define ta(X) (X)
16075 +#else
16076 +#define ta(X) ((X) - __PAGE_OFFSET)
16077 +#endif
16078 +
16079 /*
16080 * References to members of the new_cpu_data structure.
16081 */
16082 @@ -54,11 +60,7 @@
16083 * and small than max_low_pfn, otherwise will waste some page table entries
16084 */
16085
16086 -#if PTRS_PER_PMD > 1
16087 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16088 -#else
16089 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16090 -#endif
16091 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16092
16093 /* Number of possible pages in the lowmem region */
16094 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16095 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16096 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16097
16098 /*
16099 + * Real beginning of normal "text" segment
16100 + */
16101 +ENTRY(stext)
16102 +ENTRY(_stext)
16103 +
16104 +/*
16105 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16106 * %esi points to the real-mode code as a 32-bit pointer.
16107 * CS and DS must be 4 GB flat segments, but we don't depend on
16108 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16109 * can.
16110 */
16111 __HEAD
16112 +
16113 +#ifdef CONFIG_PAX_KERNEXEC
16114 + jmp startup_32
16115 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16116 +.fill PAGE_SIZE-5,1,0xcc
16117 +#endif
16118 +
16119 ENTRY(startup_32)
16120 movl pa(stack_start),%ecx
16121
16122 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16123 2:
16124 leal -__PAGE_OFFSET(%ecx),%esp
16125
16126 +#ifdef CONFIG_SMP
16127 + movl $pa(cpu_gdt_table),%edi
16128 + movl $__per_cpu_load,%eax
16129 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16130 + rorl $16,%eax
16131 + movb %al,__KERNEL_PERCPU + 4(%edi)
16132 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16133 + movl $__per_cpu_end - 1,%eax
16134 + subl $__per_cpu_start,%eax
16135 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16136 +#endif
16137 +
16138 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16139 + movl $NR_CPUS,%ecx
16140 + movl $pa(cpu_gdt_table),%edi
16141 +1:
16142 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16143 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16144 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16145 + addl $PAGE_SIZE_asm,%edi
16146 + loop 1b
16147 +#endif
16148 +
16149 +#ifdef CONFIG_PAX_KERNEXEC
16150 + movl $pa(boot_gdt),%edi
16151 + movl $__LOAD_PHYSICAL_ADDR,%eax
16152 + movw %ax,__BOOT_CS + 2(%edi)
16153 + rorl $16,%eax
16154 + movb %al,__BOOT_CS + 4(%edi)
16155 + movb %ah,__BOOT_CS + 7(%edi)
16156 + rorl $16,%eax
16157 +
16158 + ljmp $(__BOOT_CS),$1f
16159 +1:
16160 +
16161 + movl $NR_CPUS,%ecx
16162 + movl $pa(cpu_gdt_table),%edi
16163 + addl $__PAGE_OFFSET,%eax
16164 +1:
16165 + movw %ax,__KERNEL_CS + 2(%edi)
16166 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16167 + rorl $16,%eax
16168 + movb %al,__KERNEL_CS + 4(%edi)
16169 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16170 + movb %ah,__KERNEL_CS + 7(%edi)
16171 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16172 + rorl $16,%eax
16173 + addl $PAGE_SIZE_asm,%edi
16174 + loop 1b
16175 +#endif
16176 +
16177 /*
16178 * Clear BSS first so that there are no surprises...
16179 */
16180 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16181 movl %eax, pa(max_pfn_mapped)
16182
16183 /* Do early initialization of the fixmap area */
16184 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16185 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16186 +#ifdef CONFIG_COMPAT_VDSO
16187 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16188 +#else
16189 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16190 +#endif
16191 #else /* Not PAE */
16192
16193 page_pde_offset = (__PAGE_OFFSET >> 20);
16194 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16195 movl %eax, pa(max_pfn_mapped)
16196
16197 /* Do early initialization of the fixmap area */
16198 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16199 - movl %eax,pa(initial_page_table+0xffc)
16200 +#ifdef CONFIG_COMPAT_VDSO
16201 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16202 +#else
16203 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16204 +#endif
16205 #endif
16206
16207 #ifdef CONFIG_PARAVIRT
16208 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16209 cmpl $num_subarch_entries, %eax
16210 jae bad_subarch
16211
16212 - movl pa(subarch_entries)(,%eax,4), %eax
16213 - subl $__PAGE_OFFSET, %eax
16214 - jmp *%eax
16215 + jmp *pa(subarch_entries)(,%eax,4)
16216
16217 bad_subarch:
16218 WEAK(lguest_entry)
16219 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16220 __INITDATA
16221
16222 subarch_entries:
16223 - .long default_entry /* normal x86/PC */
16224 - .long lguest_entry /* lguest hypervisor */
16225 - .long xen_entry /* Xen hypervisor */
16226 - .long default_entry /* Moorestown MID */
16227 + .long ta(default_entry) /* normal x86/PC */
16228 + .long ta(lguest_entry) /* lguest hypervisor */
16229 + .long ta(xen_entry) /* Xen hypervisor */
16230 + .long ta(default_entry) /* Moorestown MID */
16231 num_subarch_entries = (. - subarch_entries) / 4
16232 .previous
16233 #else
16234 @@ -312,6 +382,7 @@ default_entry:
16235 orl %edx,%eax
16236 movl %eax,%cr4
16237
16238 +#ifdef CONFIG_X86_PAE
16239 testb $X86_CR4_PAE, %al # check if PAE is enabled
16240 jz 6f
16241
16242 @@ -340,6 +411,9 @@ default_entry:
16243 /* Make changes effective */
16244 wrmsr
16245
16246 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16247 +#endif
16248 +
16249 6:
16250
16251 /*
16252 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16253 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16254 movl %eax,%ss # after changing gdt.
16255
16256 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16257 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16258 movl %eax,%ds
16259 movl %eax,%es
16260
16261 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16262 */
16263 cmpb $0,ready
16264 jne 1f
16265 - movl $gdt_page,%eax
16266 + movl $cpu_gdt_table,%eax
16267 movl $stack_canary,%ecx
16268 +#ifdef CONFIG_SMP
16269 + addl $__per_cpu_load,%ecx
16270 +#endif
16271 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16272 shrl $16, %ecx
16273 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16274 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16275 1:
16276 -#endif
16277 movl $(__KERNEL_STACK_CANARY),%eax
16278 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16279 + movl $(__USER_DS),%eax
16280 +#else
16281 + xorl %eax,%eax
16282 +#endif
16283 movl %eax,%gs
16284
16285 xorl %eax,%eax # Clear LDT
16286 @@ -558,22 +639,22 @@ early_page_fault:
16287 jmp early_fault
16288
16289 early_fault:
16290 - cld
16291 #ifdef CONFIG_PRINTK
16292 + cmpl $1,%ss:early_recursion_flag
16293 + je hlt_loop
16294 + incl %ss:early_recursion_flag
16295 + cld
16296 pusha
16297 movl $(__KERNEL_DS),%eax
16298 movl %eax,%ds
16299 movl %eax,%es
16300 - cmpl $2,early_recursion_flag
16301 - je hlt_loop
16302 - incl early_recursion_flag
16303 movl %cr2,%eax
16304 pushl %eax
16305 pushl %edx /* trapno */
16306 pushl $fault_msg
16307 call printk
16308 +; call dump_stack
16309 #endif
16310 - call dump_stack
16311 hlt_loop:
16312 hlt
16313 jmp hlt_loop
16314 @@ -581,8 +662,11 @@ hlt_loop:
16315 /* This is the default interrupt "handler" :-) */
16316 ALIGN
16317 ignore_int:
16318 - cld
16319 #ifdef CONFIG_PRINTK
16320 + cmpl $2,%ss:early_recursion_flag
16321 + je hlt_loop
16322 + incl %ss:early_recursion_flag
16323 + cld
16324 pushl %eax
16325 pushl %ecx
16326 pushl %edx
16327 @@ -591,9 +675,6 @@ ignore_int:
16328 movl $(__KERNEL_DS),%eax
16329 movl %eax,%ds
16330 movl %eax,%es
16331 - cmpl $2,early_recursion_flag
16332 - je hlt_loop
16333 - incl early_recursion_flag
16334 pushl 16(%esp)
16335 pushl 24(%esp)
16336 pushl 32(%esp)
16337 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16338 /*
16339 * BSS section
16340 */
16341 -__PAGE_ALIGNED_BSS
16342 - .align PAGE_SIZE
16343 #ifdef CONFIG_X86_PAE
16344 +.section .initial_pg_pmd,"a",@progbits
16345 initial_pg_pmd:
16346 .fill 1024*KPMDS,4,0
16347 #else
16348 +.section .initial_page_table,"a",@progbits
16349 ENTRY(initial_page_table)
16350 .fill 1024,4,0
16351 #endif
16352 +.section .initial_pg_fixmap,"a",@progbits
16353 initial_pg_fixmap:
16354 .fill 1024,4,0
16355 +.section .empty_zero_page,"a",@progbits
16356 ENTRY(empty_zero_page)
16357 .fill 4096,1,0
16358 +.section .swapper_pg_dir,"a",@progbits
16359 ENTRY(swapper_pg_dir)
16360 +#ifdef CONFIG_X86_PAE
16361 + .fill 4,8,0
16362 +#else
16363 .fill 1024,4,0
16364 +#endif
16365 +
16366 +/*
16367 + * The IDT has to be page-aligned to simplify the Pentium
16368 + * F0 0F bug workaround.. We have a special link segment
16369 + * for this.
16370 + */
16371 +.section .idt,"a",@progbits
16372 +ENTRY(idt_table)
16373 + .fill 256,8,0
16374
16375 /*
16376 * This starts the data section.
16377 */
16378 #ifdef CONFIG_X86_PAE
16379 -__PAGE_ALIGNED_DATA
16380 - /* Page-aligned for the benefit of paravirt? */
16381 - .align PAGE_SIZE
16382 +.section .initial_page_table,"a",@progbits
16383 ENTRY(initial_page_table)
16384 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16385 # if KPMDS == 3
16386 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16387 # error "Kernel PMDs should be 1, 2 or 3"
16388 # endif
16389 .align PAGE_SIZE /* needs to be page-sized too */
16390 +
16391 +#ifdef CONFIG_PAX_PER_CPU_PGD
16392 +ENTRY(cpu_pgd)
16393 + .rept NR_CPUS
16394 + .fill 4,8,0
16395 + .endr
16396 +#endif
16397 +
16398 #endif
16399
16400 .data
16401 .balign 4
16402 ENTRY(stack_start)
16403 - .long init_thread_union+THREAD_SIZE
16404 + .long init_thread_union+THREAD_SIZE-8
16405
16406 +ready: .byte 0
16407 +
16408 +.section .rodata,"a",@progbits
16409 early_recursion_flag:
16410 .long 0
16411
16412 -ready: .byte 0
16413 -
16414 int_msg:
16415 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16416
16417 @@ -707,7 +811,7 @@ fault_msg:
16418 .word 0 # 32 bit align gdt_desc.address
16419 boot_gdt_descr:
16420 .word __BOOT_DS+7
16421 - .long boot_gdt - __PAGE_OFFSET
16422 + .long pa(boot_gdt)
16423
16424 .word 0 # 32-bit align idt_desc.address
16425 idt_descr:
16426 @@ -718,7 +822,7 @@ idt_descr:
16427 .word 0 # 32 bit align gdt_desc.address
16428 ENTRY(early_gdt_descr)
16429 .word GDT_ENTRIES*8-1
16430 - .long gdt_page /* Overwritten for secondary CPUs */
16431 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16432
16433 /*
16434 * The boot_gdt must mirror the equivalent in setup.S and is
16435 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16436 .align L1_CACHE_BYTES
16437 ENTRY(boot_gdt)
16438 .fill GDT_ENTRY_BOOT_CS,8,0
16439 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16440 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16441 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16442 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16443 +
16444 + .align PAGE_SIZE_asm
16445 +ENTRY(cpu_gdt_table)
16446 + .rept NR_CPUS
16447 + .quad 0x0000000000000000 /* NULL descriptor */
16448 + .quad 0x0000000000000000 /* 0x0b reserved */
16449 + .quad 0x0000000000000000 /* 0x13 reserved */
16450 + .quad 0x0000000000000000 /* 0x1b reserved */
16451 +
16452 +#ifdef CONFIG_PAX_KERNEXEC
16453 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16454 +#else
16455 + .quad 0x0000000000000000 /* 0x20 unused */
16456 +#endif
16457 +
16458 + .quad 0x0000000000000000 /* 0x28 unused */
16459 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16460 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16461 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16462 + .quad 0x0000000000000000 /* 0x4b reserved */
16463 + .quad 0x0000000000000000 /* 0x53 reserved */
16464 + .quad 0x0000000000000000 /* 0x5b reserved */
16465 +
16466 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16467 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16468 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16469 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16470 +
16471 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16472 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16473 +
16474 + /*
16475 + * Segments used for calling PnP BIOS have byte granularity.
16476 + * The code segments and data segments have fixed 64k limits,
16477 + * the transfer segment sizes are set at run time.
16478 + */
16479 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
16480 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
16481 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
16482 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
16483 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
16484 +
16485 + /*
16486 + * The APM segments have byte granularity and their bases
16487 + * are set at run time. All have 64k limits.
16488 + */
16489 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16490 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16491 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
16492 +
16493 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16494 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16495 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16496 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16497 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16498 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16499 +
16500 + /* Be sure this is zeroed to avoid false validations in Xen */
16501 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16502 + .endr
16503 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16504 index 40f4eb3..6d24d9d 100644
16505 --- a/arch/x86/kernel/head_64.S
16506 +++ b/arch/x86/kernel/head_64.S
16507 @@ -19,6 +19,8 @@
16508 #include <asm/cache.h>
16509 #include <asm/processor-flags.h>
16510 #include <asm/percpu.h>
16511 +#include <asm/cpufeature.h>
16512 +#include <asm/alternative-asm.h>
16513
16514 #ifdef CONFIG_PARAVIRT
16515 #include <asm/asm-offsets.h>
16516 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16517 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16518 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16519 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16520 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
16521 +L3_VMALLOC_START = pud_index(VMALLOC_START)
16522 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
16523 +L3_VMALLOC_END = pud_index(VMALLOC_END)
16524 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16525 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16526
16527 .text
16528 __HEAD
16529 @@ -85,35 +93,23 @@ startup_64:
16530 */
16531 addq %rbp, init_level4_pgt + 0(%rip)
16532 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16533 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16534 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16535 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16536 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16537
16538 addq %rbp, level3_ident_pgt + 0(%rip)
16539 +#ifndef CONFIG_XEN
16540 + addq %rbp, level3_ident_pgt + 8(%rip)
16541 +#endif
16542
16543 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16544 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16545 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16546 +
16547 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16548 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16549
16550 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16551 -
16552 - /* Add an Identity mapping if I am above 1G */
16553 - leaq _text(%rip), %rdi
16554 - andq $PMD_PAGE_MASK, %rdi
16555 -
16556 - movq %rdi, %rax
16557 - shrq $PUD_SHIFT, %rax
16558 - andq $(PTRS_PER_PUD - 1), %rax
16559 - jz ident_complete
16560 -
16561 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16562 - leaq level3_ident_pgt(%rip), %rbx
16563 - movq %rdx, 0(%rbx, %rax, 8)
16564 -
16565 - movq %rdi, %rax
16566 - shrq $PMD_SHIFT, %rax
16567 - andq $(PTRS_PER_PMD - 1), %rax
16568 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16569 - leaq level2_spare_pgt(%rip), %rbx
16570 - movq %rdx, 0(%rbx, %rax, 8)
16571 -ident_complete:
16572 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16573
16574 /*
16575 * Fixup the kernel text+data virtual addresses. Note that
16576 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16577 * after the boot processor executes this code.
16578 */
16579
16580 - /* Enable PAE mode and PGE */
16581 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16582 + /* Enable PAE mode and PSE/PGE */
16583 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16584 movq %rax, %cr4
16585
16586 /* Setup early boot stage 4 level pagetables. */
16587 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16588 movl $MSR_EFER, %ecx
16589 rdmsr
16590 btsl $_EFER_SCE, %eax /* Enable System Call */
16591 - btl $20,%edi /* No Execute supported? */
16592 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16593 jnc 1f
16594 btsl $_EFER_NX, %eax
16595 + leaq init_level4_pgt(%rip), %rdi
16596 +#ifndef CONFIG_EFI
16597 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16598 +#endif
16599 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
16600 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
16601 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
16602 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
16603 1: wrmsr /* Make changes effective */
16604
16605 /* Setup cr0 */
16606 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
16607 * jump. In addition we need to ensure %cs is set so we make this
16608 * a far return.
16609 */
16610 + pax_set_fptr_mask
16611 movq initial_code(%rip),%rax
16612 pushq $0 # fake return address to stop unwinder
16613 pushq $__KERNEL_CS # set correct cs
16614 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
16615 bad_address:
16616 jmp bad_address
16617
16618 - .section ".init.text","ax"
16619 + __INIT
16620 #ifdef CONFIG_EARLY_PRINTK
16621 .globl early_idt_handlers
16622 early_idt_handlers:
16623 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
16624 #endif /* EARLY_PRINTK */
16625 1: hlt
16626 jmp 1b
16627 + .previous
16628
16629 #ifdef CONFIG_EARLY_PRINTK
16630 + __INITDATA
16631 early_recursion_flag:
16632 .long 0
16633 + .previous
16634
16635 + .section .rodata,"a",@progbits
16636 early_idt_msg:
16637 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
16638 early_idt_ripmsg:
16639 .asciz "RIP %s\n"
16640 + .previous
16641 #endif /* CONFIG_EARLY_PRINTK */
16642 - .previous
16643
16644 + .section .rodata,"a",@progbits
16645 #define NEXT_PAGE(name) \
16646 .balign PAGE_SIZE; \
16647 ENTRY(name)
16648 @@ -338,7 +348,6 @@ ENTRY(name)
16649 i = i + 1 ; \
16650 .endr
16651
16652 - .data
16653 /*
16654 * This default setting generates an ident mapping at address 0x100000
16655 * and a mapping for the kernel that precisely maps virtual address
16656 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
16657 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16658 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
16659 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16660 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
16661 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
16662 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
16663 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
16664 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
16665 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16666 .org init_level4_pgt + L4_START_KERNEL*8, 0
16667 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
16668 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
16669
16670 +#ifdef CONFIG_PAX_PER_CPU_PGD
16671 +NEXT_PAGE(cpu_pgd)
16672 + .rept NR_CPUS
16673 + .fill 512,8,0
16674 + .endr
16675 +#endif
16676 +
16677 NEXT_PAGE(level3_ident_pgt)
16678 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16679 +#ifdef CONFIG_XEN
16680 .fill 511,8,0
16681 +#else
16682 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16683 + .fill 510,8,0
16684 +#endif
16685 +
16686 +NEXT_PAGE(level3_vmalloc_start_pgt)
16687 + .fill 512,8,0
16688 +
16689 +NEXT_PAGE(level3_vmalloc_end_pgt)
16690 + .fill 512,8,0
16691 +
16692 +NEXT_PAGE(level3_vmemmap_pgt)
16693 + .fill L3_VMEMMAP_START,8,0
16694 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16695
16696 NEXT_PAGE(level3_kernel_pgt)
16697 .fill L3_START_KERNEL,8,0
16698 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
16699 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16700 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16701
16702 +NEXT_PAGE(level2_vmemmap_pgt)
16703 + .fill 512,8,0
16704 +
16705 NEXT_PAGE(level2_fixmap_pgt)
16706 - .fill 506,8,0
16707 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16708 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16709 - .fill 5,8,0
16710 + .fill 507,8,0
16711 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16712 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16713 + .fill 4,8,0
16714
16715 -NEXT_PAGE(level1_fixmap_pgt)
16716 +NEXT_PAGE(level1_vsyscall_pgt)
16717 .fill 512,8,0
16718
16719 -NEXT_PAGE(level2_ident_pgt)
16720 - /* Since I easily can, map the first 1G.
16721 + /* Since I easily can, map the first 2G.
16722 * Don't set NX because code runs from these pages.
16723 */
16724 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16725 +NEXT_PAGE(level2_ident_pgt)
16726 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16727
16728 NEXT_PAGE(level2_kernel_pgt)
16729 /*
16730 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
16731 * If you want to increase this then increase MODULES_VADDR
16732 * too.)
16733 */
16734 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16735 - KERNEL_IMAGE_SIZE/PMD_SIZE)
16736 -
16737 -NEXT_PAGE(level2_spare_pgt)
16738 - .fill 512, 8, 0
16739 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16740
16741 #undef PMDS
16742 #undef NEXT_PAGE
16743
16744 - .data
16745 + .align PAGE_SIZE
16746 +ENTRY(cpu_gdt_table)
16747 + .rept NR_CPUS
16748 + .quad 0x0000000000000000 /* NULL descriptor */
16749 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16750 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
16751 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
16752 + .quad 0x00cffb000000ffff /* __USER32_CS */
16753 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16754 + .quad 0x00affb000000ffff /* __USER_CS */
16755 +
16756 +#ifdef CONFIG_PAX_KERNEXEC
16757 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16758 +#else
16759 + .quad 0x0 /* unused */
16760 +#endif
16761 +
16762 + .quad 0,0 /* TSS */
16763 + .quad 0,0 /* LDT */
16764 + .quad 0,0,0 /* three TLS descriptors */
16765 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
16766 + /* asm/segment.h:GDT_ENTRIES must match this */
16767 +
16768 + /* zero the remaining page */
16769 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16770 + .endr
16771 +
16772 .align 16
16773 .globl early_gdt_descr
16774 early_gdt_descr:
16775 .word GDT_ENTRIES*8-1
16776 early_gdt_descr_base:
16777 - .quad INIT_PER_CPU_VAR(gdt_page)
16778 + .quad cpu_gdt_table
16779
16780 ENTRY(phys_base)
16781 /* This must match the first entry in level2_kernel_pgt */
16782 .quad 0x0000000000000000
16783
16784 #include "../../x86/xen/xen-head.S"
16785 -
16786 - .section .bss, "aw", @nobits
16787 +
16788 + .section .rodata,"a",@progbits
16789 .align L1_CACHE_BYTES
16790 ENTRY(idt_table)
16791 - .skip IDT_ENTRIES * 16
16792 + .fill 512,8,0
16793
16794 .align L1_CACHE_BYTES
16795 ENTRY(nmi_idt_table)
16796 - .skip IDT_ENTRIES * 16
16797 + .fill 512,8,0
16798
16799 __PAGE_ALIGNED_BSS
16800 .align PAGE_SIZE
16801 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
16802 index 9c3bd4a..e1d9b35 100644
16803 --- a/arch/x86/kernel/i386_ksyms_32.c
16804 +++ b/arch/x86/kernel/i386_ksyms_32.c
16805 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
16806 EXPORT_SYMBOL(cmpxchg8b_emu);
16807 #endif
16808
16809 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
16810 +
16811 /* Networking helper routines. */
16812 EXPORT_SYMBOL(csum_partial_copy_generic);
16813 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
16814 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
16815
16816 EXPORT_SYMBOL(__get_user_1);
16817 EXPORT_SYMBOL(__get_user_2);
16818 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
16819
16820 EXPORT_SYMBOL(csum_partial);
16821 EXPORT_SYMBOL(empty_zero_page);
16822 +
16823 +#ifdef CONFIG_PAX_KERNEXEC
16824 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
16825 +#endif
16826 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
16827 index 6104852..6114160 100644
16828 --- a/arch/x86/kernel/i8259.c
16829 +++ b/arch/x86/kernel/i8259.c
16830 @@ -210,7 +210,7 @@ spurious_8259A_irq:
16831 "spurious 8259A interrupt: IRQ%d.\n", irq);
16832 spurious_irq_mask |= irqmask;
16833 }
16834 - atomic_inc(&irq_err_count);
16835 + atomic_inc_unchecked(&irq_err_count);
16836 /*
16837 * Theoretically we do not have to handle this IRQ,
16838 * but in Linux this does not cause problems and is
16839 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
16840 index 43e9ccf..44ccf6f 100644
16841 --- a/arch/x86/kernel/init_task.c
16842 +++ b/arch/x86/kernel/init_task.c
16843 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
16844 * way process stacks are handled. This is done by having a special
16845 * "init_task" linker map entry..
16846 */
16847 -union thread_union init_thread_union __init_task_data =
16848 - { INIT_THREAD_INFO(init_task) };
16849 +union thread_union init_thread_union __init_task_data;
16850
16851 /*
16852 * Initial task structure.
16853 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
16854 * section. Since TSS's are completely CPU-local, we want them
16855 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
16856 */
16857 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
16858 -
16859 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
16860 +EXPORT_SYMBOL(init_tss);
16861 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
16862 index 8c96897..be66bfa 100644
16863 --- a/arch/x86/kernel/ioport.c
16864 +++ b/arch/x86/kernel/ioport.c
16865 @@ -6,6 +6,7 @@
16866 #include <linux/sched.h>
16867 #include <linux/kernel.h>
16868 #include <linux/capability.h>
16869 +#include <linux/security.h>
16870 #include <linux/errno.h>
16871 #include <linux/types.h>
16872 #include <linux/ioport.h>
16873 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
16874
16875 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
16876 return -EINVAL;
16877 +#ifdef CONFIG_GRKERNSEC_IO
16878 + if (turn_on && grsec_disable_privio) {
16879 + gr_handle_ioperm();
16880 + return -EPERM;
16881 + }
16882 +#endif
16883 if (turn_on && !capable(CAP_SYS_RAWIO))
16884 return -EPERM;
16885
16886 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
16887 * because the ->io_bitmap_max value must match the bitmap
16888 * contents:
16889 */
16890 - tss = &per_cpu(init_tss, get_cpu());
16891 + tss = init_tss + get_cpu();
16892
16893 if (turn_on)
16894 bitmap_clear(t->io_bitmap_ptr, from, num);
16895 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
16896 return -EINVAL;
16897 /* Trying to gain more privileges? */
16898 if (level > old) {
16899 +#ifdef CONFIG_GRKERNSEC_IO
16900 + if (grsec_disable_privio) {
16901 + gr_handle_iopl();
16902 + return -EPERM;
16903 + }
16904 +#endif
16905 if (!capable(CAP_SYS_RAWIO))
16906 return -EPERM;
16907 }
16908 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
16909 index 7943e0c..dd32c5c 100644
16910 --- a/arch/x86/kernel/irq.c
16911 +++ b/arch/x86/kernel/irq.c
16912 @@ -18,7 +18,7 @@
16913 #include <asm/mce.h>
16914 #include <asm/hw_irq.h>
16915
16916 -atomic_t irq_err_count;
16917 +atomic_unchecked_t irq_err_count;
16918
16919 /* Function pointer for generic interrupt vector handling */
16920 void (*x86_platform_ipi_callback)(void) = NULL;
16921 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
16922 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
16923 seq_printf(p, " Machine check polls\n");
16924 #endif
16925 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
16926 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
16927 #if defined(CONFIG_X86_IO_APIC)
16928 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
16929 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
16930 #endif
16931 return 0;
16932 }
16933 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
16934
16935 u64 arch_irq_stat(void)
16936 {
16937 - u64 sum = atomic_read(&irq_err_count);
16938 + u64 sum = atomic_read_unchecked(&irq_err_count);
16939
16940 #ifdef CONFIG_X86_IO_APIC
16941 - sum += atomic_read(&irq_mis_count);
16942 + sum += atomic_read_unchecked(&irq_mis_count);
16943 #endif
16944 return sum;
16945 }
16946 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
16947 index 40fc861..9b8739b 100644
16948 --- a/arch/x86/kernel/irq_32.c
16949 +++ b/arch/x86/kernel/irq_32.c
16950 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
16951 __asm__ __volatile__("andl %%esp,%0" :
16952 "=r" (sp) : "0" (THREAD_SIZE - 1));
16953
16954 - return sp < (sizeof(struct thread_info) + STACK_WARN);
16955 + return sp < STACK_WARN;
16956 }
16957
16958 static void print_stack_overflow(void)
16959 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
16960 * per-CPU IRQ handling contexts (thread information and stack)
16961 */
16962 union irq_ctx {
16963 - struct thread_info tinfo;
16964 - u32 stack[THREAD_SIZE/sizeof(u32)];
16965 + unsigned long previous_esp;
16966 + u32 stack[THREAD_SIZE/sizeof(u32)];
16967 } __attribute__((aligned(THREAD_SIZE)));
16968
16969 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
16970 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
16971 static inline int
16972 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16973 {
16974 - union irq_ctx *curctx, *irqctx;
16975 + union irq_ctx *irqctx;
16976 u32 *isp, arg1, arg2;
16977
16978 - curctx = (union irq_ctx *) current_thread_info();
16979 irqctx = __this_cpu_read(hardirq_ctx);
16980
16981 /*
16982 @@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16983 * handler) we can't do that and just have to keep using the
16984 * current stack (which is the irq stack already after all)
16985 */
16986 - if (unlikely(curctx == irqctx))
16987 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
16988 return 0;
16989
16990 /* build the stack frame on the IRQ stack */
16991 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
16992 - irqctx->tinfo.task = curctx->tinfo.task;
16993 - irqctx->tinfo.previous_esp = current_stack_pointer;
16994 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
16995 + irqctx->previous_esp = current_stack_pointer;
16996
16997 - /*
16998 - * Copy the softirq bits in preempt_count so that the
16999 - * softirq checks work in the hardirq context.
17000 - */
17001 - irqctx->tinfo.preempt_count =
17002 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17003 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17004 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17005 + __set_fs(MAKE_MM_SEG(0));
17006 +#endif
17007
17008 if (unlikely(overflow))
17009 call_on_stack(print_stack_overflow, isp);
17010 @@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17011 : "0" (irq), "1" (desc), "2" (isp),
17012 "D" (desc->handle_irq)
17013 : "memory", "cc", "ecx");
17014 +
17015 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17016 + __set_fs(current_thread_info()->addr_limit);
17017 +#endif
17018 +
17019 return 1;
17020 }
17021
17022 @@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17023 */
17024 void __cpuinit irq_ctx_init(int cpu)
17025 {
17026 - union irq_ctx *irqctx;
17027 -
17028 if (per_cpu(hardirq_ctx, cpu))
17029 return;
17030
17031 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17032 - THREAD_FLAGS,
17033 - THREAD_ORDER));
17034 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17035 - irqctx->tinfo.cpu = cpu;
17036 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17037 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17038 -
17039 - per_cpu(hardirq_ctx, cpu) = irqctx;
17040 -
17041 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17042 - THREAD_FLAGS,
17043 - THREAD_ORDER));
17044 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17045 - irqctx->tinfo.cpu = cpu;
17046 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17047 -
17048 - per_cpu(softirq_ctx, cpu) = irqctx;
17049 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17050 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17051
17052 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17053 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17054 @@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17055 asmlinkage void do_softirq(void)
17056 {
17057 unsigned long flags;
17058 - struct thread_info *curctx;
17059 union irq_ctx *irqctx;
17060 u32 *isp;
17061
17062 @@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17063 local_irq_save(flags);
17064
17065 if (local_softirq_pending()) {
17066 - curctx = current_thread_info();
17067 irqctx = __this_cpu_read(softirq_ctx);
17068 - irqctx->tinfo.task = curctx->task;
17069 - irqctx->tinfo.previous_esp = current_stack_pointer;
17070 + irqctx->previous_esp = current_stack_pointer;
17071
17072 /* build the stack frame on the softirq stack */
17073 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17074 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17075 +
17076 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17077 + __set_fs(MAKE_MM_SEG(0));
17078 +#endif
17079
17080 call_on_stack(__do_softirq, isp);
17081 +
17082 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17083 + __set_fs(current_thread_info()->addr_limit);
17084 +#endif
17085 +
17086 /*
17087 * Shouldn't happen, we returned above if in_interrupt():
17088 */
17089 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17090 index d04d3ec..ea4b374 100644
17091 --- a/arch/x86/kernel/irq_64.c
17092 +++ b/arch/x86/kernel/irq_64.c
17093 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17094 u64 estack_top, estack_bottom;
17095 u64 curbase = (u64)task_stack_page(current);
17096
17097 - if (user_mode_vm(regs))
17098 + if (user_mode(regs))
17099 return;
17100
17101 if (regs->sp >= curbase + sizeof(struct thread_info) +
17102 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17103 index faba577..93b9e71 100644
17104 --- a/arch/x86/kernel/kgdb.c
17105 +++ b/arch/x86/kernel/kgdb.c
17106 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17107 #ifdef CONFIG_X86_32
17108 switch (regno) {
17109 case GDB_SS:
17110 - if (!user_mode_vm(regs))
17111 + if (!user_mode(regs))
17112 *(unsigned long *)mem = __KERNEL_DS;
17113 break;
17114 case GDB_SP:
17115 - if (!user_mode_vm(regs))
17116 + if (!user_mode(regs))
17117 *(unsigned long *)mem = kernel_stack_pointer(regs);
17118 break;
17119 case GDB_GS:
17120 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17121 case 'k':
17122 /* clear the trace bit */
17123 linux_regs->flags &= ~X86_EFLAGS_TF;
17124 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17125 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17126
17127 /* set the trace bit if we're stepping */
17128 if (remcomInBuffer[0] == 's') {
17129 linux_regs->flags |= X86_EFLAGS_TF;
17130 - atomic_set(&kgdb_cpu_doing_single_step,
17131 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17132 raw_smp_processor_id());
17133 }
17134
17135 @@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17136
17137 switch (cmd) {
17138 case DIE_DEBUG:
17139 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17140 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17141 if (user_mode(regs))
17142 return single_step_cont(regs, args);
17143 break;
17144 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17145 index 7da647d..56fe348 100644
17146 --- a/arch/x86/kernel/kprobes.c
17147 +++ b/arch/x86/kernel/kprobes.c
17148 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17149 } __attribute__((packed)) *insn;
17150
17151 insn = (struct __arch_relative_insn *)from;
17152 +
17153 + pax_open_kernel();
17154 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17155 insn->op = op;
17156 + pax_close_kernel();
17157 }
17158
17159 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17160 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17161 kprobe_opcode_t opcode;
17162 kprobe_opcode_t *orig_opcodes = opcodes;
17163
17164 - if (search_exception_tables((unsigned long)opcodes))
17165 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17166 return 0; /* Page fault may occur on this address. */
17167
17168 retry:
17169 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17170 }
17171 }
17172 insn_get_length(&insn);
17173 + pax_open_kernel();
17174 memcpy(dest, insn.kaddr, insn.length);
17175 + pax_close_kernel();
17176
17177 #ifdef CONFIG_X86_64
17178 if (insn_rip_relative(&insn)) {
17179 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17180 (u8 *) dest;
17181 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17182 disp = (u8 *) dest + insn_offset_displacement(&insn);
17183 + pax_open_kernel();
17184 *(s32 *) disp = (s32) newdisp;
17185 + pax_close_kernel();
17186 }
17187 #endif
17188 return insn.length;
17189 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17190 */
17191 __copy_instruction(p->ainsn.insn, p->addr, 0);
17192
17193 - if (can_boost(p->addr))
17194 + if (can_boost(ktla_ktva(p->addr)))
17195 p->ainsn.boostable = 0;
17196 else
17197 p->ainsn.boostable = -1;
17198
17199 - p->opcode = *p->addr;
17200 + p->opcode = *(ktla_ktva(p->addr));
17201 }
17202
17203 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17204 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17205 * nor set current_kprobe, because it doesn't use single
17206 * stepping.
17207 */
17208 - regs->ip = (unsigned long)p->ainsn.insn;
17209 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17210 preempt_enable_no_resched();
17211 return;
17212 }
17213 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17214 if (p->opcode == BREAKPOINT_INSTRUCTION)
17215 regs->ip = (unsigned long)p->addr;
17216 else
17217 - regs->ip = (unsigned long)p->ainsn.insn;
17218 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17219 }
17220
17221 /*
17222 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17223 setup_singlestep(p, regs, kcb, 0);
17224 return 1;
17225 }
17226 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17227 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17228 /*
17229 * The breakpoint instruction was removed right
17230 * after we hit it. Another cpu has removed
17231 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17232 " movq %rax, 152(%rsp)\n"
17233 RESTORE_REGS_STRING
17234 " popfq\n"
17235 +#ifdef KERNEXEC_PLUGIN
17236 + " btsq $63,(%rsp)\n"
17237 +#endif
17238 #else
17239 " pushf\n"
17240 SAVE_REGS_STRING
17241 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17242 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17243 {
17244 unsigned long *tos = stack_addr(regs);
17245 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17246 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17247 unsigned long orig_ip = (unsigned long)p->addr;
17248 kprobe_opcode_t *insn = p->ainsn.insn;
17249
17250 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17251 struct die_args *args = data;
17252 int ret = NOTIFY_DONE;
17253
17254 - if (args->regs && user_mode_vm(args->regs))
17255 + if (args->regs && user_mode(args->regs))
17256 return ret;
17257
17258 switch (val) {
17259 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17260 * Verify if the address gap is in 2GB range, because this uses
17261 * a relative jump.
17262 */
17263 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17264 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17265 if (abs(rel) > 0x7fffffff)
17266 return -ERANGE;
17267
17268 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17269 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17270
17271 /* Set probe function call */
17272 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17273 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17274
17275 /* Set returning jmp instruction at the tail of out-of-line buffer */
17276 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17277 - (u8 *)op->kp.addr + op->optinsn.size);
17278 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17279
17280 flush_icache_range((unsigned long) buf,
17281 (unsigned long) buf + TMPL_END_IDX +
17282 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17283 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17284
17285 /* Backup instructions which will be replaced by jump address */
17286 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17287 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17288 RELATIVE_ADDR_SIZE);
17289
17290 insn_buf[0] = RELATIVEJUMP_OPCODE;
17291 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17292 index ea69726..604d066 100644
17293 --- a/arch/x86/kernel/ldt.c
17294 +++ b/arch/x86/kernel/ldt.c
17295 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17296 if (reload) {
17297 #ifdef CONFIG_SMP
17298 preempt_disable();
17299 - load_LDT(pc);
17300 + load_LDT_nolock(pc);
17301 if (!cpumask_equal(mm_cpumask(current->mm),
17302 cpumask_of(smp_processor_id())))
17303 smp_call_function(flush_ldt, current->mm, 1);
17304 preempt_enable();
17305 #else
17306 - load_LDT(pc);
17307 + load_LDT_nolock(pc);
17308 #endif
17309 }
17310 if (oldsize) {
17311 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17312 return err;
17313
17314 for (i = 0; i < old->size; i++)
17315 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17316 + write_ldt_entry(new->ldt, i, old->ldt + i);
17317 return 0;
17318 }
17319
17320 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17321 retval = copy_ldt(&mm->context, &old_mm->context);
17322 mutex_unlock(&old_mm->context.lock);
17323 }
17324 +
17325 + if (tsk == current) {
17326 + mm->context.vdso = 0;
17327 +
17328 +#ifdef CONFIG_X86_32
17329 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17330 + mm->context.user_cs_base = 0UL;
17331 + mm->context.user_cs_limit = ~0UL;
17332 +
17333 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17334 + cpus_clear(mm->context.cpu_user_cs_mask);
17335 +#endif
17336 +
17337 +#endif
17338 +#endif
17339 +
17340 + }
17341 +
17342 return retval;
17343 }
17344
17345 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17346 }
17347 }
17348
17349 +#ifdef CONFIG_PAX_SEGMEXEC
17350 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17351 + error = -EINVAL;
17352 + goto out_unlock;
17353 + }
17354 +#endif
17355 +
17356 fill_ldt(&ldt, &ldt_info);
17357 if (oldmode)
17358 ldt.avl = 0;
17359 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17360 index a3fa43b..8966f4c 100644
17361 --- a/arch/x86/kernel/machine_kexec_32.c
17362 +++ b/arch/x86/kernel/machine_kexec_32.c
17363 @@ -27,7 +27,7 @@
17364 #include <asm/cacheflush.h>
17365 #include <asm/debugreg.h>
17366
17367 -static void set_idt(void *newidt, __u16 limit)
17368 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17369 {
17370 struct desc_ptr curidt;
17371
17372 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17373 }
17374
17375
17376 -static void set_gdt(void *newgdt, __u16 limit)
17377 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17378 {
17379 struct desc_ptr curgdt;
17380
17381 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17382 }
17383
17384 control_page = page_address(image->control_code_page);
17385 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17386 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17387
17388 relocate_kernel_ptr = control_page;
17389 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17390 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17391 index 3ca42d0..7cff8cc 100644
17392 --- a/arch/x86/kernel/microcode_intel.c
17393 +++ b/arch/x86/kernel/microcode_intel.c
17394 @@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17395
17396 static int get_ucode_user(void *to, const void *from, size_t n)
17397 {
17398 - return copy_from_user(to, from, n);
17399 + return copy_from_user(to, (const void __force_user *)from, n);
17400 }
17401
17402 static enum ucode_state
17403 request_microcode_user(int cpu, const void __user *buf, size_t size)
17404 {
17405 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17406 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17407 }
17408
17409 static void microcode_fini_cpu(int cpu)
17410 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17411 index 925179f..267ac7a 100644
17412 --- a/arch/x86/kernel/module.c
17413 +++ b/arch/x86/kernel/module.c
17414 @@ -36,15 +36,60 @@
17415 #define DEBUGP(fmt...)
17416 #endif
17417
17418 -void *module_alloc(unsigned long size)
17419 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17420 {
17421 - if (PAGE_ALIGN(size) > MODULES_LEN)
17422 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17423 return NULL;
17424 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17425 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17426 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17427 -1, __builtin_return_address(0));
17428 }
17429
17430 +void *module_alloc(unsigned long size)
17431 +{
17432 +
17433 +#ifdef CONFIG_PAX_KERNEXEC
17434 + return __module_alloc(size, PAGE_KERNEL);
17435 +#else
17436 + return __module_alloc(size, PAGE_KERNEL_EXEC);
17437 +#endif
17438 +
17439 +}
17440 +
17441 +#ifdef CONFIG_PAX_KERNEXEC
17442 +#ifdef CONFIG_X86_32
17443 +void *module_alloc_exec(unsigned long size)
17444 +{
17445 + struct vm_struct *area;
17446 +
17447 + if (size == 0)
17448 + return NULL;
17449 +
17450 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17451 + return area ? area->addr : NULL;
17452 +}
17453 +EXPORT_SYMBOL(module_alloc_exec);
17454 +
17455 +void module_free_exec(struct module *mod, void *module_region)
17456 +{
17457 + vunmap(module_region);
17458 +}
17459 +EXPORT_SYMBOL(module_free_exec);
17460 +#else
17461 +void module_free_exec(struct module *mod, void *module_region)
17462 +{
17463 + module_free(mod, module_region);
17464 +}
17465 +EXPORT_SYMBOL(module_free_exec);
17466 +
17467 +void *module_alloc_exec(unsigned long size)
17468 +{
17469 + return __module_alloc(size, PAGE_KERNEL_RX);
17470 +}
17471 +EXPORT_SYMBOL(module_alloc_exec);
17472 +#endif
17473 +#endif
17474 +
17475 #ifdef CONFIG_X86_32
17476 int apply_relocate(Elf32_Shdr *sechdrs,
17477 const char *strtab,
17478 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17479 unsigned int i;
17480 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17481 Elf32_Sym *sym;
17482 - uint32_t *location;
17483 + uint32_t *plocation, location;
17484
17485 DEBUGP("Applying relocate section %u to %u\n", relsec,
17486 sechdrs[relsec].sh_info);
17487 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17488 /* This is where to make the change */
17489 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17490 - + rel[i].r_offset;
17491 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17492 + location = (uint32_t)plocation;
17493 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
17494 + plocation = ktla_ktva((void *)plocation);
17495 /* This is the symbol it is referring to. Note that all
17496 undefined symbols have been resolved. */
17497 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
17498 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17499 switch (ELF32_R_TYPE(rel[i].r_info)) {
17500 case R_386_32:
17501 /* We add the value into the location given */
17502 - *location += sym->st_value;
17503 + pax_open_kernel();
17504 + *plocation += sym->st_value;
17505 + pax_close_kernel();
17506 break;
17507 case R_386_PC32:
17508 /* Add the value, subtract its postition */
17509 - *location += sym->st_value - (uint32_t)location;
17510 + pax_open_kernel();
17511 + *plocation += sym->st_value - location;
17512 + pax_close_kernel();
17513 break;
17514 default:
17515 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
17516 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
17517 case R_X86_64_NONE:
17518 break;
17519 case R_X86_64_64:
17520 + pax_open_kernel();
17521 *(u64 *)loc = val;
17522 + pax_close_kernel();
17523 break;
17524 case R_X86_64_32:
17525 + pax_open_kernel();
17526 *(u32 *)loc = val;
17527 + pax_close_kernel();
17528 if (val != *(u32 *)loc)
17529 goto overflow;
17530 break;
17531 case R_X86_64_32S:
17532 + pax_open_kernel();
17533 *(s32 *)loc = val;
17534 + pax_close_kernel();
17535 if ((s64)val != *(s32 *)loc)
17536 goto overflow;
17537 break;
17538 case R_X86_64_PC32:
17539 val -= (u64)loc;
17540 + pax_open_kernel();
17541 *(u32 *)loc = val;
17542 + pax_close_kernel();
17543 +
17544 #if 0
17545 if ((s64)val != *(s32 *)loc)
17546 goto overflow;
17547 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
17548 index 47acaf3..ec48ab6 100644
17549 --- a/arch/x86/kernel/nmi.c
17550 +++ b/arch/x86/kernel/nmi.c
17551 @@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
17552 dotraplinkage notrace __kprobes void
17553 do_nmi(struct pt_regs *regs, long error_code)
17554 {
17555 +
17556 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17557 + if (!user_mode(regs)) {
17558 + unsigned long cs = regs->cs & 0xFFFF;
17559 + unsigned long ip = ktva_ktla(regs->ip);
17560 +
17561 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17562 + regs->ip = ip;
17563 + }
17564 +#endif
17565 +
17566 nmi_nesting_preprocess(regs);
17567
17568 nmi_enter();
17569 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
17570 index 676b8c7..870ba04 100644
17571 --- a/arch/x86/kernel/paravirt-spinlocks.c
17572 +++ b/arch/x86/kernel/paravirt-spinlocks.c
17573 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
17574 arch_spin_lock(lock);
17575 }
17576
17577 -struct pv_lock_ops pv_lock_ops = {
17578 +struct pv_lock_ops pv_lock_ops __read_only = {
17579 #ifdef CONFIG_SMP
17580 .spin_is_locked = __ticket_spin_is_locked,
17581 .spin_is_contended = __ticket_spin_is_contended,
17582 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
17583 index d90272e..6bb013b 100644
17584 --- a/arch/x86/kernel/paravirt.c
17585 +++ b/arch/x86/kernel/paravirt.c
17586 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
17587 {
17588 return x;
17589 }
17590 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17591 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
17592 +#endif
17593
17594 void __init default_banner(void)
17595 {
17596 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
17597 if (opfunc == NULL)
17598 /* If there's no function, patch it with a ud2a (BUG) */
17599 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
17600 - else if (opfunc == _paravirt_nop)
17601 + else if (opfunc == (void *)_paravirt_nop)
17602 /* If the operation is a nop, then nop the callsite */
17603 ret = paravirt_patch_nop();
17604
17605 /* identity functions just return their single argument */
17606 - else if (opfunc == _paravirt_ident_32)
17607 + else if (opfunc == (void *)_paravirt_ident_32)
17608 ret = paravirt_patch_ident_32(insnbuf, len);
17609 - else if (opfunc == _paravirt_ident_64)
17610 + else if (opfunc == (void *)_paravirt_ident_64)
17611 ret = paravirt_patch_ident_64(insnbuf, len);
17612 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17613 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
17614 + ret = paravirt_patch_ident_64(insnbuf, len);
17615 +#endif
17616
17617 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
17618 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
17619 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
17620 if (insn_len > len || start == NULL)
17621 insn_len = len;
17622 else
17623 - memcpy(insnbuf, start, insn_len);
17624 + memcpy(insnbuf, ktla_ktva(start), insn_len);
17625
17626 return insn_len;
17627 }
17628 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
17629 preempt_enable();
17630 }
17631
17632 -struct pv_info pv_info = {
17633 +struct pv_info pv_info __read_only = {
17634 .name = "bare hardware",
17635 .paravirt_enabled = 0,
17636 .kernel_rpl = 0,
17637 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
17638 #endif
17639 };
17640
17641 -struct pv_init_ops pv_init_ops = {
17642 +struct pv_init_ops pv_init_ops __read_only = {
17643 .patch = native_patch,
17644 };
17645
17646 -struct pv_time_ops pv_time_ops = {
17647 +struct pv_time_ops pv_time_ops __read_only = {
17648 .sched_clock = native_sched_clock,
17649 .steal_clock = native_steal_clock,
17650 };
17651
17652 -struct pv_irq_ops pv_irq_ops = {
17653 +struct pv_irq_ops pv_irq_ops __read_only = {
17654 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
17655 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
17656 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
17657 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
17658 #endif
17659 };
17660
17661 -struct pv_cpu_ops pv_cpu_ops = {
17662 +struct pv_cpu_ops pv_cpu_ops __read_only = {
17663 .cpuid = native_cpuid,
17664 .get_debugreg = native_get_debugreg,
17665 .set_debugreg = native_set_debugreg,
17666 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
17667 .end_context_switch = paravirt_nop,
17668 };
17669
17670 -struct pv_apic_ops pv_apic_ops = {
17671 +struct pv_apic_ops pv_apic_ops __read_only = {
17672 #ifdef CONFIG_X86_LOCAL_APIC
17673 .startup_ipi_hook = paravirt_nop,
17674 #endif
17675 };
17676
17677 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
17678 +#ifdef CONFIG_X86_32
17679 +#ifdef CONFIG_X86_PAE
17680 +/* 64-bit pagetable entries */
17681 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
17682 +#else
17683 /* 32-bit pagetable entries */
17684 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
17685 +#endif
17686 #else
17687 /* 64-bit pagetable entries */
17688 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
17689 #endif
17690
17691 -struct pv_mmu_ops pv_mmu_ops = {
17692 +struct pv_mmu_ops pv_mmu_ops __read_only = {
17693
17694 .read_cr2 = native_read_cr2,
17695 .write_cr2 = native_write_cr2,
17696 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
17697 .make_pud = PTE_IDENT,
17698
17699 .set_pgd = native_set_pgd,
17700 + .set_pgd_batched = native_set_pgd_batched,
17701 #endif
17702 #endif /* PAGETABLE_LEVELS >= 3 */
17703
17704 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
17705 },
17706
17707 .set_fixmap = native_set_fixmap,
17708 +
17709 +#ifdef CONFIG_PAX_KERNEXEC
17710 + .pax_open_kernel = native_pax_open_kernel,
17711 + .pax_close_kernel = native_pax_close_kernel,
17712 +#endif
17713 +
17714 };
17715
17716 EXPORT_SYMBOL_GPL(pv_time_ops);
17717 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
17718 index 35ccf75..7a15747 100644
17719 --- a/arch/x86/kernel/pci-iommu_table.c
17720 +++ b/arch/x86/kernel/pci-iommu_table.c
17721 @@ -2,7 +2,7 @@
17722 #include <asm/iommu_table.h>
17723 #include <linux/string.h>
17724 #include <linux/kallsyms.h>
17725 -
17726 +#include <linux/sched.h>
17727
17728 #define DEBUG 1
17729
17730 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
17731 index 15763af..da59ada 100644
17732 --- a/arch/x86/kernel/process.c
17733 +++ b/arch/x86/kernel/process.c
17734 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
17735
17736 void free_thread_info(struct thread_info *ti)
17737 {
17738 - free_thread_xstate(ti->task);
17739 free_pages((unsigned long)ti, THREAD_ORDER);
17740 }
17741
17742 +static struct kmem_cache *task_struct_cachep;
17743 +
17744 void arch_task_cache_init(void)
17745 {
17746 - task_xstate_cachep =
17747 - kmem_cache_create("task_xstate", xstate_size,
17748 + /* create a slab on which task_structs can be allocated */
17749 + task_struct_cachep =
17750 + kmem_cache_create("task_struct", sizeof(struct task_struct),
17751 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
17752 +
17753 + task_xstate_cachep =
17754 + kmem_cache_create("task_xstate", xstate_size,
17755 __alignof__(union thread_xstate),
17756 - SLAB_PANIC | SLAB_NOTRACK, NULL);
17757 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
17758 +}
17759 +
17760 +struct task_struct *alloc_task_struct_node(int node)
17761 +{
17762 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
17763 +}
17764 +
17765 +void free_task_struct(struct task_struct *task)
17766 +{
17767 + free_thread_xstate(task);
17768 + kmem_cache_free(task_struct_cachep, task);
17769 }
17770
17771 /*
17772 @@ -70,7 +87,7 @@ void exit_thread(void)
17773 unsigned long *bp = t->io_bitmap_ptr;
17774
17775 if (bp) {
17776 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
17777 + struct tss_struct *tss = init_tss + get_cpu();
17778
17779 t->io_bitmap_ptr = NULL;
17780 clear_thread_flag(TIF_IO_BITMAP);
17781 @@ -106,7 +123,7 @@ void show_regs_common(void)
17782
17783 printk(KERN_CONT "\n");
17784 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
17785 - current->pid, current->comm, print_tainted(),
17786 + task_pid_nr(current), current->comm, print_tainted(),
17787 init_utsname()->release,
17788 (int)strcspn(init_utsname()->version, " "),
17789 init_utsname()->version);
17790 @@ -120,6 +137,9 @@ void flush_thread(void)
17791 {
17792 struct task_struct *tsk = current;
17793
17794 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17795 + loadsegment(gs, 0);
17796 +#endif
17797 flush_ptrace_hw_breakpoint(tsk);
17798 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
17799 /*
17800 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
17801 regs.di = (unsigned long) arg;
17802
17803 #ifdef CONFIG_X86_32
17804 - regs.ds = __USER_DS;
17805 - regs.es = __USER_DS;
17806 + regs.ds = __KERNEL_DS;
17807 + regs.es = __KERNEL_DS;
17808 regs.fs = __KERNEL_PERCPU;
17809 - regs.gs = __KERNEL_STACK_CANARY;
17810 + savesegment(gs, regs.gs);
17811 #else
17812 regs.ss = __KERNEL_DS;
17813 #endif
17814 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
17815
17816 return ret;
17817 }
17818 -void stop_this_cpu(void *dummy)
17819 +__noreturn void stop_this_cpu(void *dummy)
17820 {
17821 local_irq_disable();
17822 /*
17823 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
17824 }
17825 early_param("idle", idle_setup);
17826
17827 -unsigned long arch_align_stack(unsigned long sp)
17828 +#ifdef CONFIG_PAX_RANDKSTACK
17829 +void pax_randomize_kstack(struct pt_regs *regs)
17830 {
17831 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
17832 - sp -= get_random_int() % 8192;
17833 - return sp & ~0xf;
17834 -}
17835 + struct thread_struct *thread = &current->thread;
17836 + unsigned long time;
17837
17838 -unsigned long arch_randomize_brk(struct mm_struct *mm)
17839 -{
17840 - unsigned long range_end = mm->brk + 0x02000000;
17841 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
17842 -}
17843 + if (!randomize_va_space)
17844 + return;
17845 +
17846 + if (v8086_mode(regs))
17847 + return;
17848
17849 + rdtscl(time);
17850 +
17851 + /* P4 seems to return a 0 LSB, ignore it */
17852 +#ifdef CONFIG_MPENTIUM4
17853 + time &= 0x3EUL;
17854 + time <<= 2;
17855 +#elif defined(CONFIG_X86_64)
17856 + time &= 0xFUL;
17857 + time <<= 4;
17858 +#else
17859 + time &= 0x1FUL;
17860 + time <<= 3;
17861 +#endif
17862 +
17863 + thread->sp0 ^= time;
17864 + load_sp0(init_tss + smp_processor_id(), thread);
17865 +
17866 +#ifdef CONFIG_X86_64
17867 + percpu_write(kernel_stack, thread->sp0);
17868 +#endif
17869 +}
17870 +#endif
17871 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
17872 index c08d1ff..6ae1c81 100644
17873 --- a/arch/x86/kernel/process_32.c
17874 +++ b/arch/x86/kernel/process_32.c
17875 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
17876 unsigned long thread_saved_pc(struct task_struct *tsk)
17877 {
17878 return ((unsigned long *)tsk->thread.sp)[3];
17879 +//XXX return tsk->thread.eip;
17880 }
17881
17882 #ifndef CONFIG_SMP
17883 @@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
17884 unsigned long sp;
17885 unsigned short ss, gs;
17886
17887 - if (user_mode_vm(regs)) {
17888 + if (user_mode(regs)) {
17889 sp = regs->sp;
17890 ss = regs->ss & 0xffff;
17891 - gs = get_user_gs(regs);
17892 } else {
17893 sp = kernel_stack_pointer(regs);
17894 savesegment(ss, ss);
17895 - savesegment(gs, gs);
17896 }
17897 + gs = get_user_gs(regs);
17898
17899 show_regs_common();
17900
17901 @@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17902 struct task_struct *tsk;
17903 int err;
17904
17905 - childregs = task_pt_regs(p);
17906 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
17907 *childregs = *regs;
17908 childregs->ax = 0;
17909 childregs->sp = sp;
17910
17911 p->thread.sp = (unsigned long) childregs;
17912 p->thread.sp0 = (unsigned long) (childregs+1);
17913 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17914
17915 p->thread.ip = (unsigned long) ret_from_fork;
17916
17917 @@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17918 struct thread_struct *prev = &prev_p->thread,
17919 *next = &next_p->thread;
17920 int cpu = smp_processor_id();
17921 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
17922 + struct tss_struct *tss = init_tss + cpu;
17923 fpu_switch_t fpu;
17924
17925 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
17926 @@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17927 */
17928 lazy_save_gs(prev->gs);
17929
17930 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17931 + __set_fs(task_thread_info(next_p)->addr_limit);
17932 +#endif
17933 +
17934 /*
17935 * Load the per-thread Thread-Local Storage descriptor.
17936 */
17937 @@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17938 */
17939 arch_end_context_switch(next_p);
17940
17941 + percpu_write(current_task, next_p);
17942 + percpu_write(current_tinfo, &next_p->tinfo);
17943 +
17944 /*
17945 * Restore %gs if needed (which is common)
17946 */
17947 @@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17948
17949 switch_fpu_finish(next_p, fpu);
17950
17951 - percpu_write(current_task, next_p);
17952 -
17953 return prev_p;
17954 }
17955
17956 @@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
17957 } while (count++ < 16);
17958 return 0;
17959 }
17960 -
17961 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
17962 index cfa5c90..4facd28 100644
17963 --- a/arch/x86/kernel/process_64.c
17964 +++ b/arch/x86/kernel/process_64.c
17965 @@ -89,7 +89,7 @@ static void __exit_idle(void)
17966 void exit_idle(void)
17967 {
17968 /* idle loop has pid 0 */
17969 - if (current->pid)
17970 + if (task_pid_nr(current))
17971 return;
17972 __exit_idle();
17973 }
17974 @@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17975 struct pt_regs *childregs;
17976 struct task_struct *me = current;
17977
17978 - childregs = ((struct pt_regs *)
17979 - (THREAD_SIZE + task_stack_page(p))) - 1;
17980 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
17981 *childregs = *regs;
17982
17983 childregs->ax = 0;
17984 @@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17985 p->thread.sp = (unsigned long) childregs;
17986 p->thread.sp0 = (unsigned long) (childregs+1);
17987 p->thread.usersp = me->thread.usersp;
17988 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17989
17990 set_tsk_thread_flag(p, TIF_FORK);
17991
17992 @@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17993 struct thread_struct *prev = &prev_p->thread;
17994 struct thread_struct *next = &next_p->thread;
17995 int cpu = smp_processor_id();
17996 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
17997 + struct tss_struct *tss = init_tss + cpu;
17998 unsigned fsindex, gsindex;
17999 fpu_switch_t fpu;
18000
18001 @@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18002 prev->usersp = percpu_read(old_rsp);
18003 percpu_write(old_rsp, next->usersp);
18004 percpu_write(current_task, next_p);
18005 + percpu_write(current_tinfo, &next_p->tinfo);
18006
18007 - percpu_write(kernel_stack,
18008 - (unsigned long)task_stack_page(next_p) +
18009 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18010 + percpu_write(kernel_stack, next->sp0);
18011
18012 /*
18013 * Now maybe reload the debug registers and handle I/O bitmaps
18014 @@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18015 if (!p || p == current || p->state == TASK_RUNNING)
18016 return 0;
18017 stack = (unsigned long)task_stack_page(p);
18018 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18019 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18020 return 0;
18021 fp = *(u64 *)(p->thread.sp);
18022 do {
18023 - if (fp < (unsigned long)stack ||
18024 - fp >= (unsigned long)stack+THREAD_SIZE)
18025 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18026 return 0;
18027 ip = *(u64 *)(fp+8);
18028 if (!in_sched_functions(ip))
18029 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18030 index 5026738..9e6d6dc 100644
18031 --- a/arch/x86/kernel/ptrace.c
18032 +++ b/arch/x86/kernel/ptrace.c
18033 @@ -823,7 +823,7 @@ long arch_ptrace(struct task_struct *child, long request,
18034 unsigned long addr, unsigned long data)
18035 {
18036 int ret;
18037 - unsigned long __user *datap = (unsigned long __user *)data;
18038 + unsigned long __user *datap = (__force unsigned long __user *)data;
18039
18040 switch (request) {
18041 /* read the word at location addr in the USER area. */
18042 @@ -908,14 +908,14 @@ long arch_ptrace(struct task_struct *child, long request,
18043 if ((int) addr < 0)
18044 return -EIO;
18045 ret = do_get_thread_area(child, addr,
18046 - (struct user_desc __user *)data);
18047 + (__force struct user_desc __user *) data);
18048 break;
18049
18050 case PTRACE_SET_THREAD_AREA:
18051 if ((int) addr < 0)
18052 return -EIO;
18053 ret = do_set_thread_area(child, addr,
18054 - (struct user_desc __user *)data, 0);
18055 + (__force struct user_desc __user *) data, 0);
18056 break;
18057 #endif
18058
18059 @@ -1332,7 +1332,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18060 memset(info, 0, sizeof(*info));
18061 info->si_signo = SIGTRAP;
18062 info->si_code = si_code;
18063 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18064 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18065 }
18066
18067 void user_single_step_siginfo(struct task_struct *tsk,
18068 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18069 index 42eb330..139955c 100644
18070 --- a/arch/x86/kernel/pvclock.c
18071 +++ b/arch/x86/kernel/pvclock.c
18072 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18073 return pv_tsc_khz;
18074 }
18075
18076 -static atomic64_t last_value = ATOMIC64_INIT(0);
18077 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18078
18079 void pvclock_resume(void)
18080 {
18081 - atomic64_set(&last_value, 0);
18082 + atomic64_set_unchecked(&last_value, 0);
18083 }
18084
18085 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18086 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18087 * updating at the same time, and one of them could be slightly behind,
18088 * making the assumption that last_value always go forward fail to hold.
18089 */
18090 - last = atomic64_read(&last_value);
18091 + last = atomic64_read_unchecked(&last_value);
18092 do {
18093 if (ret < last)
18094 return last;
18095 - last = atomic64_cmpxchg(&last_value, last, ret);
18096 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18097 } while (unlikely(last != ret));
18098
18099 return ret;
18100 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18101 index d840e69..98e9581 100644
18102 --- a/arch/x86/kernel/reboot.c
18103 +++ b/arch/x86/kernel/reboot.c
18104 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18105 EXPORT_SYMBOL(pm_power_off);
18106
18107 static const struct desc_ptr no_idt = {};
18108 -static int reboot_mode;
18109 +static unsigned short reboot_mode;
18110 enum reboot_type reboot_type = BOOT_ACPI;
18111 int reboot_force;
18112
18113 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18114 extern const unsigned char machine_real_restart_asm[];
18115 extern const u64 machine_real_restart_gdt[3];
18116
18117 -void machine_real_restart(unsigned int type)
18118 +__noreturn void machine_real_restart(unsigned int type)
18119 {
18120 void *restart_va;
18121 unsigned long restart_pa;
18122 - void (*restart_lowmem)(unsigned int);
18123 + void (* __noreturn restart_lowmem)(unsigned int);
18124 u64 *lowmem_gdt;
18125
18126 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18127 + struct desc_struct *gdt;
18128 +#endif
18129 +
18130 local_irq_disable();
18131
18132 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18133 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18134 boot)". This seems like a fairly standard thing that gets set by
18135 REBOOT.COM programs, and the previous reset routine did this
18136 too. */
18137 - *((unsigned short *)0x472) = reboot_mode;
18138 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18139
18140 /* Patch the GDT in the low memory trampoline */
18141 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18142
18143 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18144 restart_pa = virt_to_phys(restart_va);
18145 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18146 + restart_lowmem = (void *)restart_pa;
18147
18148 /* GDT[0]: GDT self-pointer */
18149 lowmem_gdt[0] =
18150 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18151 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18152
18153 /* Jump to the identity-mapped low memory code */
18154 +
18155 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18156 + gdt = get_cpu_gdt_table(smp_processor_id());
18157 + pax_open_kernel();
18158 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18159 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18160 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18161 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18162 +#endif
18163 +#ifdef CONFIG_PAX_KERNEXEC
18164 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18165 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18166 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18167 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18168 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18169 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18170 +#endif
18171 + pax_close_kernel();
18172 +#endif
18173 +
18174 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18175 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18176 + unreachable();
18177 +#else
18178 restart_lowmem(type);
18179 +#endif
18180 +
18181 }
18182 #ifdef CONFIG_APM_MODULE
18183 EXPORT_SYMBOL(machine_real_restart);
18184 @@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18185 * try to force a triple fault and then cycle between hitting the keyboard
18186 * controller and doing that
18187 */
18188 -static void native_machine_emergency_restart(void)
18189 +__noreturn static void native_machine_emergency_restart(void)
18190 {
18191 int i;
18192 int attempt = 0;
18193 @@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18194 #endif
18195 }
18196
18197 -static void __machine_emergency_restart(int emergency)
18198 +static __noreturn void __machine_emergency_restart(int emergency)
18199 {
18200 reboot_emergency = emergency;
18201 machine_ops.emergency_restart();
18202 }
18203
18204 -static void native_machine_restart(char *__unused)
18205 +static __noreturn void native_machine_restart(char *__unused)
18206 {
18207 printk("machine restart\n");
18208
18209 @@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18210 __machine_emergency_restart(0);
18211 }
18212
18213 -static void native_machine_halt(void)
18214 +static __noreturn void native_machine_halt(void)
18215 {
18216 /* stop other cpus and apics */
18217 machine_shutdown();
18218 @@ -706,7 +736,7 @@ static void native_machine_halt(void)
18219 stop_this_cpu(NULL);
18220 }
18221
18222 -static void native_machine_power_off(void)
18223 +__noreturn static void native_machine_power_off(void)
18224 {
18225 if (pm_power_off) {
18226 if (!reboot_force)
18227 @@ -715,6 +745,7 @@ static void native_machine_power_off(void)
18228 }
18229 /* a fallback in case there is no PM info available */
18230 tboot_shutdown(TB_SHUTDOWN_HALT);
18231 + unreachable();
18232 }
18233
18234 struct machine_ops machine_ops = {
18235 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18236 index 7a6f3b3..bed145d7 100644
18237 --- a/arch/x86/kernel/relocate_kernel_64.S
18238 +++ b/arch/x86/kernel/relocate_kernel_64.S
18239 @@ -11,6 +11,7 @@
18240 #include <asm/kexec.h>
18241 #include <asm/processor-flags.h>
18242 #include <asm/pgtable_types.h>
18243 +#include <asm/alternative-asm.h>
18244
18245 /*
18246 * Must be relocatable PIC code callable as a C function
18247 @@ -160,13 +161,14 @@ identity_mapped:
18248 xorq %rbp, %rbp
18249 xorq %r8, %r8
18250 xorq %r9, %r9
18251 - xorq %r10, %r9
18252 + xorq %r10, %r10
18253 xorq %r11, %r11
18254 xorq %r12, %r12
18255 xorq %r13, %r13
18256 xorq %r14, %r14
18257 xorq %r15, %r15
18258
18259 + pax_force_retaddr 0, 1
18260 ret
18261
18262 1:
18263 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18264 index d7d5099..28555d0 100644
18265 --- a/arch/x86/kernel/setup.c
18266 +++ b/arch/x86/kernel/setup.c
18267 @@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
18268
18269 switch (data->type) {
18270 case SETUP_E820_EXT:
18271 - parse_e820_ext(data);
18272 + parse_e820_ext((struct setup_data __force_kernel *)data);
18273 break;
18274 case SETUP_DTB:
18275 add_dtb(pa_data);
18276 @@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
18277 * area (640->1Mb) as ram even though it is not.
18278 * take them out.
18279 */
18280 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18281 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18282 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18283 }
18284
18285 @@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
18286
18287 if (!boot_params.hdr.root_flags)
18288 root_mountflags &= ~MS_RDONLY;
18289 - init_mm.start_code = (unsigned long) _text;
18290 - init_mm.end_code = (unsigned long) _etext;
18291 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18292 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18293 init_mm.end_data = (unsigned long) _edata;
18294 init_mm.brk = _brk_end;
18295
18296 - code_resource.start = virt_to_phys(_text);
18297 - code_resource.end = virt_to_phys(_etext)-1;
18298 - data_resource.start = virt_to_phys(_etext);
18299 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18300 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18301 + data_resource.start = virt_to_phys(_sdata);
18302 data_resource.end = virt_to_phys(_edata)-1;
18303 bss_resource.start = virt_to_phys(&__bss_start);
18304 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18305 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18306 index 71f4727..16dc9f7 100644
18307 --- a/arch/x86/kernel/setup_percpu.c
18308 +++ b/arch/x86/kernel/setup_percpu.c
18309 @@ -21,19 +21,17 @@
18310 #include <asm/cpu.h>
18311 #include <asm/stackprotector.h>
18312
18313 -DEFINE_PER_CPU(int, cpu_number);
18314 +#ifdef CONFIG_SMP
18315 +DEFINE_PER_CPU(unsigned int, cpu_number);
18316 EXPORT_PER_CPU_SYMBOL(cpu_number);
18317 +#endif
18318
18319 -#ifdef CONFIG_X86_64
18320 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18321 -#else
18322 -#define BOOT_PERCPU_OFFSET 0
18323 -#endif
18324
18325 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18326 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18327
18328 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18329 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18330 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18331 };
18332 EXPORT_SYMBOL(__per_cpu_offset);
18333 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18334 {
18335 #ifdef CONFIG_X86_32
18336 struct desc_struct gdt;
18337 + unsigned long base = per_cpu_offset(cpu);
18338
18339 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18340 - 0x2 | DESCTYPE_S, 0x8);
18341 - gdt.s = 1;
18342 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18343 + 0x83 | DESCTYPE_S, 0xC);
18344 write_gdt_entry(get_cpu_gdt_table(cpu),
18345 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18346 #endif
18347 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
18348 /* alrighty, percpu areas up and running */
18349 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18350 for_each_possible_cpu(cpu) {
18351 +#ifdef CONFIG_CC_STACKPROTECTOR
18352 +#ifdef CONFIG_X86_32
18353 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18354 +#endif
18355 +#endif
18356 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18357 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18358 per_cpu(cpu_number, cpu) = cpu;
18359 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
18360 */
18361 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18362 #endif
18363 +#ifdef CONFIG_CC_STACKPROTECTOR
18364 +#ifdef CONFIG_X86_32
18365 + if (!cpu)
18366 + per_cpu(stack_canary.canary, cpu) = canary;
18367 +#endif
18368 +#endif
18369 /*
18370 * Up to this point, the boot CPU has been using .init.data
18371 * area. Reload any changed state for the boot CPU.
18372 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18373 index 46a01bd..2e88e6d 100644
18374 --- a/arch/x86/kernel/signal.c
18375 +++ b/arch/x86/kernel/signal.c
18376 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18377 * Align the stack pointer according to the i386 ABI,
18378 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18379 */
18380 - sp = ((sp + 4) & -16ul) - 4;
18381 + sp = ((sp - 12) & -16ul) - 4;
18382 #else /* !CONFIG_X86_32 */
18383 sp = round_down(sp, 16) - 8;
18384 #endif
18385 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18386 * Return an always-bogus address instead so we will die with SIGSEGV.
18387 */
18388 if (onsigstack && !likely(on_sig_stack(sp)))
18389 - return (void __user *)-1L;
18390 + return (__force void __user *)-1L;
18391
18392 /* save i387 state */
18393 if (used_math() && save_i387_xstate(*fpstate) < 0)
18394 - return (void __user *)-1L;
18395 + return (__force void __user *)-1L;
18396
18397 return (void __user *)sp;
18398 }
18399 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18400 }
18401
18402 if (current->mm->context.vdso)
18403 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18404 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18405 else
18406 - restorer = &frame->retcode;
18407 + restorer = (void __user *)&frame->retcode;
18408 if (ka->sa.sa_flags & SA_RESTORER)
18409 restorer = ka->sa.sa_restorer;
18410
18411 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18412 * reasons and because gdb uses it as a signature to notice
18413 * signal handler stack frames.
18414 */
18415 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18416 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18417
18418 if (err)
18419 return -EFAULT;
18420 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18421 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18422
18423 /* Set up to return from userspace. */
18424 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18425 + if (current->mm->context.vdso)
18426 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18427 + else
18428 + restorer = (void __user *)&frame->retcode;
18429 if (ka->sa.sa_flags & SA_RESTORER)
18430 restorer = ka->sa.sa_restorer;
18431 put_user_ex(restorer, &frame->pretcode);
18432 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18433 * reasons and because gdb uses it as a signature to notice
18434 * signal handler stack frames.
18435 */
18436 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18437 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18438 } put_user_catch(err);
18439
18440 if (err)
18441 @@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
18442 * X86_32: vm86 regs switched out by assembly code before reaching
18443 * here, so testing against kernel CS suffices.
18444 */
18445 - if (!user_mode(regs))
18446 + if (!user_mode_novm(regs))
18447 return;
18448
18449 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18450 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18451 index 66d250c..f1b10bd 100644
18452 --- a/arch/x86/kernel/smpboot.c
18453 +++ b/arch/x86/kernel/smpboot.c
18454 @@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18455 set_idle_for_cpu(cpu, c_idle.idle);
18456 do_rest:
18457 per_cpu(current_task, cpu) = c_idle.idle;
18458 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18459 #ifdef CONFIG_X86_32
18460 /* Stack for startup_32 can be just as for start_secondary onwards */
18461 irq_ctx_init(cpu);
18462 #else
18463 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18464 initial_gs = per_cpu_offset(cpu);
18465 - per_cpu(kernel_stack, cpu) =
18466 - (unsigned long)task_stack_page(c_idle.idle) -
18467 - KERNEL_STACK_OFFSET + THREAD_SIZE;
18468 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
18469 #endif
18470 +
18471 + pax_open_kernel();
18472 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18473 + pax_close_kernel();
18474 +
18475 initial_code = (unsigned long)start_secondary;
18476 stack_start = c_idle.idle->thread.sp;
18477
18478 @@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
18479
18480 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
18481
18482 +#ifdef CONFIG_PAX_PER_CPU_PGD
18483 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
18484 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18485 + KERNEL_PGD_PTRS);
18486 +#endif
18487 +
18488 err = do_boot_cpu(apicid, cpu);
18489 if (err) {
18490 pr_debug("do_boot_cpu failed %d\n", err);
18491 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
18492 index c346d11..d43b163 100644
18493 --- a/arch/x86/kernel/step.c
18494 +++ b/arch/x86/kernel/step.c
18495 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18496 struct desc_struct *desc;
18497 unsigned long base;
18498
18499 - seg &= ~7UL;
18500 + seg >>= 3;
18501
18502 mutex_lock(&child->mm->context.lock);
18503 - if (unlikely((seg >> 3) >= child->mm->context.size))
18504 + if (unlikely(seg >= child->mm->context.size))
18505 addr = -1L; /* bogus selector, access would fault */
18506 else {
18507 desc = child->mm->context.ldt + seg;
18508 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18509 addr += base;
18510 }
18511 mutex_unlock(&child->mm->context.lock);
18512 - }
18513 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
18514 + addr = ktla_ktva(addr);
18515
18516 return addr;
18517 }
18518 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
18519 unsigned char opcode[15];
18520 unsigned long addr = convert_ip_to_linear(child, regs);
18521
18522 + if (addr == -EINVAL)
18523 + return 0;
18524 +
18525 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
18526 for (i = 0; i < copied; i++) {
18527 switch (opcode[i]) {
18528 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
18529 index 0b0cb5f..db6b9ed 100644
18530 --- a/arch/x86/kernel/sys_i386_32.c
18531 +++ b/arch/x86/kernel/sys_i386_32.c
18532 @@ -24,17 +24,224 @@
18533
18534 #include <asm/syscalls.h>
18535
18536 -/*
18537 - * Do a system call from kernel instead of calling sys_execve so we
18538 - * end up with proper pt_regs.
18539 - */
18540 -int kernel_execve(const char *filename,
18541 - const char *const argv[],
18542 - const char *const envp[])
18543 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
18544 {
18545 - long __res;
18546 - asm volatile ("int $0x80"
18547 - : "=a" (__res)
18548 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
18549 - return __res;
18550 + unsigned long pax_task_size = TASK_SIZE;
18551 +
18552 +#ifdef CONFIG_PAX_SEGMEXEC
18553 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18554 + pax_task_size = SEGMEXEC_TASK_SIZE;
18555 +#endif
18556 +
18557 + if (len > pax_task_size || addr > pax_task_size - len)
18558 + return -EINVAL;
18559 +
18560 + return 0;
18561 +}
18562 +
18563 +unsigned long
18564 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
18565 + unsigned long len, unsigned long pgoff, unsigned long flags)
18566 +{
18567 + struct mm_struct *mm = current->mm;
18568 + struct vm_area_struct *vma;
18569 + unsigned long start_addr, pax_task_size = TASK_SIZE;
18570 +
18571 +#ifdef CONFIG_PAX_SEGMEXEC
18572 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18573 + pax_task_size = SEGMEXEC_TASK_SIZE;
18574 +#endif
18575 +
18576 + pax_task_size -= PAGE_SIZE;
18577 +
18578 + if (len > pax_task_size)
18579 + return -ENOMEM;
18580 +
18581 + if (flags & MAP_FIXED)
18582 + return addr;
18583 +
18584 +#ifdef CONFIG_PAX_RANDMMAP
18585 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18586 +#endif
18587 +
18588 + if (addr) {
18589 + addr = PAGE_ALIGN(addr);
18590 + if (pax_task_size - len >= addr) {
18591 + vma = find_vma(mm, addr);
18592 + if (check_heap_stack_gap(vma, addr, len))
18593 + return addr;
18594 + }
18595 + }
18596 + if (len > mm->cached_hole_size) {
18597 + start_addr = addr = mm->free_area_cache;
18598 + } else {
18599 + start_addr = addr = mm->mmap_base;
18600 + mm->cached_hole_size = 0;
18601 + }
18602 +
18603 +#ifdef CONFIG_PAX_PAGEEXEC
18604 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
18605 + start_addr = 0x00110000UL;
18606 +
18607 +#ifdef CONFIG_PAX_RANDMMAP
18608 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18609 + start_addr += mm->delta_mmap & 0x03FFF000UL;
18610 +#endif
18611 +
18612 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
18613 + start_addr = addr = mm->mmap_base;
18614 + else
18615 + addr = start_addr;
18616 + }
18617 +#endif
18618 +
18619 +full_search:
18620 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
18621 + /* At this point: (!vma || addr < vma->vm_end). */
18622 + if (pax_task_size - len < addr) {
18623 + /*
18624 + * Start a new search - just in case we missed
18625 + * some holes.
18626 + */
18627 + if (start_addr != mm->mmap_base) {
18628 + start_addr = addr = mm->mmap_base;
18629 + mm->cached_hole_size = 0;
18630 + goto full_search;
18631 + }
18632 + return -ENOMEM;
18633 + }
18634 + if (check_heap_stack_gap(vma, addr, len))
18635 + break;
18636 + if (addr + mm->cached_hole_size < vma->vm_start)
18637 + mm->cached_hole_size = vma->vm_start - addr;
18638 + addr = vma->vm_end;
18639 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
18640 + start_addr = addr = mm->mmap_base;
18641 + mm->cached_hole_size = 0;
18642 + goto full_search;
18643 + }
18644 + }
18645 +
18646 + /*
18647 + * Remember the place where we stopped the search:
18648 + */
18649 + mm->free_area_cache = addr + len;
18650 + return addr;
18651 +}
18652 +
18653 +unsigned long
18654 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18655 + const unsigned long len, const unsigned long pgoff,
18656 + const unsigned long flags)
18657 +{
18658 + struct vm_area_struct *vma;
18659 + struct mm_struct *mm = current->mm;
18660 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
18661 +
18662 +#ifdef CONFIG_PAX_SEGMEXEC
18663 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18664 + pax_task_size = SEGMEXEC_TASK_SIZE;
18665 +#endif
18666 +
18667 + pax_task_size -= PAGE_SIZE;
18668 +
18669 + /* requested length too big for entire address space */
18670 + if (len > pax_task_size)
18671 + return -ENOMEM;
18672 +
18673 + if (flags & MAP_FIXED)
18674 + return addr;
18675 +
18676 +#ifdef CONFIG_PAX_PAGEEXEC
18677 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
18678 + goto bottomup;
18679 +#endif
18680 +
18681 +#ifdef CONFIG_PAX_RANDMMAP
18682 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18683 +#endif
18684 +
18685 + /* requesting a specific address */
18686 + if (addr) {
18687 + addr = PAGE_ALIGN(addr);
18688 + if (pax_task_size - len >= addr) {
18689 + vma = find_vma(mm, addr);
18690 + if (check_heap_stack_gap(vma, addr, len))
18691 + return addr;
18692 + }
18693 + }
18694 +
18695 + /* check if free_area_cache is useful for us */
18696 + if (len <= mm->cached_hole_size) {
18697 + mm->cached_hole_size = 0;
18698 + mm->free_area_cache = mm->mmap_base;
18699 + }
18700 +
18701 + /* either no address requested or can't fit in requested address hole */
18702 + addr = mm->free_area_cache;
18703 +
18704 + /* make sure it can fit in the remaining address space */
18705 + if (addr > len) {
18706 + vma = find_vma(mm, addr-len);
18707 + if (check_heap_stack_gap(vma, addr - len, len))
18708 + /* remember the address as a hint for next time */
18709 + return (mm->free_area_cache = addr-len);
18710 + }
18711 +
18712 + if (mm->mmap_base < len)
18713 + goto bottomup;
18714 +
18715 + addr = mm->mmap_base-len;
18716 +
18717 + do {
18718 + /*
18719 + * Lookup failure means no vma is above this address,
18720 + * else if new region fits below vma->vm_start,
18721 + * return with success:
18722 + */
18723 + vma = find_vma(mm, addr);
18724 + if (check_heap_stack_gap(vma, addr, len))
18725 + /* remember the address as a hint for next time */
18726 + return (mm->free_area_cache = addr);
18727 +
18728 + /* remember the largest hole we saw so far */
18729 + if (addr + mm->cached_hole_size < vma->vm_start)
18730 + mm->cached_hole_size = vma->vm_start - addr;
18731 +
18732 + /* try just below the current vma->vm_start */
18733 + addr = skip_heap_stack_gap(vma, len);
18734 + } while (!IS_ERR_VALUE(addr));
18735 +
18736 +bottomup:
18737 + /*
18738 + * A failed mmap() very likely causes application failure,
18739 + * so fall back to the bottom-up function here. This scenario
18740 + * can happen with large stack limits and large mmap()
18741 + * allocations.
18742 + */
18743 +
18744 +#ifdef CONFIG_PAX_SEGMEXEC
18745 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18746 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
18747 + else
18748 +#endif
18749 +
18750 + mm->mmap_base = TASK_UNMAPPED_BASE;
18751 +
18752 +#ifdef CONFIG_PAX_RANDMMAP
18753 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18754 + mm->mmap_base += mm->delta_mmap;
18755 +#endif
18756 +
18757 + mm->free_area_cache = mm->mmap_base;
18758 + mm->cached_hole_size = ~0UL;
18759 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18760 + /*
18761 + * Restore the topdown base:
18762 + */
18763 + mm->mmap_base = base;
18764 + mm->free_area_cache = base;
18765 + mm->cached_hole_size = ~0UL;
18766 +
18767 + return addr;
18768 }
18769 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
18770 index 0514890..3dbebce 100644
18771 --- a/arch/x86/kernel/sys_x86_64.c
18772 +++ b/arch/x86/kernel/sys_x86_64.c
18773 @@ -95,8 +95,8 @@ out:
18774 return error;
18775 }
18776
18777 -static void find_start_end(unsigned long flags, unsigned long *begin,
18778 - unsigned long *end)
18779 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
18780 + unsigned long *begin, unsigned long *end)
18781 {
18782 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
18783 unsigned long new_begin;
18784 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
18785 *begin = new_begin;
18786 }
18787 } else {
18788 - *begin = TASK_UNMAPPED_BASE;
18789 + *begin = mm->mmap_base;
18790 *end = TASK_SIZE;
18791 }
18792 }
18793 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
18794 if (flags & MAP_FIXED)
18795 return addr;
18796
18797 - find_start_end(flags, &begin, &end);
18798 + find_start_end(mm, flags, &begin, &end);
18799
18800 if (len > end)
18801 return -ENOMEM;
18802
18803 +#ifdef CONFIG_PAX_RANDMMAP
18804 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18805 +#endif
18806 +
18807 if (addr) {
18808 addr = PAGE_ALIGN(addr);
18809 vma = find_vma(mm, addr);
18810 - if (end - len >= addr &&
18811 - (!vma || addr + len <= vma->vm_start))
18812 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
18813 return addr;
18814 }
18815 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
18816 @@ -172,7 +175,7 @@ full_search:
18817 }
18818 return -ENOMEM;
18819 }
18820 - if (!vma || addr + len <= vma->vm_start) {
18821 + if (check_heap_stack_gap(vma, addr, len)) {
18822 /*
18823 * Remember the place where we stopped the search:
18824 */
18825 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18826 {
18827 struct vm_area_struct *vma;
18828 struct mm_struct *mm = current->mm;
18829 - unsigned long addr = addr0;
18830 + unsigned long base = mm->mmap_base, addr = addr0;
18831
18832 /* requested length too big for entire address space */
18833 if (len > TASK_SIZE)
18834 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18835 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
18836 goto bottomup;
18837
18838 +#ifdef CONFIG_PAX_RANDMMAP
18839 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18840 +#endif
18841 +
18842 /* requesting a specific address */
18843 if (addr) {
18844 addr = PAGE_ALIGN(addr);
18845 - vma = find_vma(mm, addr);
18846 - if (TASK_SIZE - len >= addr &&
18847 - (!vma || addr + len <= vma->vm_start))
18848 - return addr;
18849 + if (TASK_SIZE - len >= addr) {
18850 + vma = find_vma(mm, addr);
18851 + if (check_heap_stack_gap(vma, addr, len))
18852 + return addr;
18853 + }
18854 }
18855
18856 /* check if free_area_cache is useful for us */
18857 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18858 ALIGN_TOPDOWN);
18859
18860 vma = find_vma(mm, tmp_addr);
18861 - if (!vma || tmp_addr + len <= vma->vm_start)
18862 + if (check_heap_stack_gap(vma, tmp_addr, len))
18863 /* remember the address as a hint for next time */
18864 return mm->free_area_cache = tmp_addr;
18865 }
18866 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18867 * return with success:
18868 */
18869 vma = find_vma(mm, addr);
18870 - if (!vma || addr+len <= vma->vm_start)
18871 + if (check_heap_stack_gap(vma, addr, len))
18872 /* remember the address as a hint for next time */
18873 return mm->free_area_cache = addr;
18874
18875 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18876 mm->cached_hole_size = vma->vm_start - addr;
18877
18878 /* try just below the current vma->vm_start */
18879 - addr = vma->vm_start-len;
18880 - } while (len < vma->vm_start);
18881 + addr = skip_heap_stack_gap(vma, len);
18882 + } while (!IS_ERR_VALUE(addr));
18883
18884 bottomup:
18885 /*
18886 @@ -270,13 +278,21 @@ bottomup:
18887 * can happen with large stack limits and large mmap()
18888 * allocations.
18889 */
18890 + mm->mmap_base = TASK_UNMAPPED_BASE;
18891 +
18892 +#ifdef CONFIG_PAX_RANDMMAP
18893 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18894 + mm->mmap_base += mm->delta_mmap;
18895 +#endif
18896 +
18897 + mm->free_area_cache = mm->mmap_base;
18898 mm->cached_hole_size = ~0UL;
18899 - mm->free_area_cache = TASK_UNMAPPED_BASE;
18900 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18901 /*
18902 * Restore the topdown base:
18903 */
18904 - mm->free_area_cache = mm->mmap_base;
18905 + mm->mmap_base = base;
18906 + mm->free_area_cache = base;
18907 mm->cached_hole_size = ~0UL;
18908
18909 return addr;
18910 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
18911 index e2410e2..4fe3fbc 100644
18912 --- a/arch/x86/kernel/tboot.c
18913 +++ b/arch/x86/kernel/tboot.c
18914 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
18915
18916 void tboot_shutdown(u32 shutdown_type)
18917 {
18918 - void (*shutdown)(void);
18919 + void (* __noreturn shutdown)(void);
18920
18921 if (!tboot_enabled())
18922 return;
18923 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
18924
18925 switch_to_tboot_pt();
18926
18927 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
18928 + shutdown = (void *)tboot->shutdown_entry;
18929 shutdown();
18930
18931 /* should not reach here */
18932 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
18933 tboot_shutdown(acpi_shutdown_map[sleep_state]);
18934 }
18935
18936 -static atomic_t ap_wfs_count;
18937 +static atomic_unchecked_t ap_wfs_count;
18938
18939 static int tboot_wait_for_aps(int num_aps)
18940 {
18941 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
18942 {
18943 switch (action) {
18944 case CPU_DYING:
18945 - atomic_inc(&ap_wfs_count);
18946 + atomic_inc_unchecked(&ap_wfs_count);
18947 if (num_online_cpus() == 1)
18948 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
18949 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
18950 return NOTIFY_BAD;
18951 break;
18952 }
18953 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
18954
18955 tboot_create_trampoline();
18956
18957 - atomic_set(&ap_wfs_count, 0);
18958 + atomic_set_unchecked(&ap_wfs_count, 0);
18959 register_hotcpu_notifier(&tboot_cpu_notifier);
18960 return 0;
18961 }
18962 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
18963 index dd5fbf4..b7f2232 100644
18964 --- a/arch/x86/kernel/time.c
18965 +++ b/arch/x86/kernel/time.c
18966 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
18967 {
18968 unsigned long pc = instruction_pointer(regs);
18969
18970 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
18971 + if (!user_mode(regs) && in_lock_functions(pc)) {
18972 #ifdef CONFIG_FRAME_POINTER
18973 - return *(unsigned long *)(regs->bp + sizeof(long));
18974 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
18975 #else
18976 unsigned long *sp =
18977 (unsigned long *)kernel_stack_pointer(regs);
18978 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
18979 * or above a saved flags. Eflags has bits 22-31 zero,
18980 * kernel addresses don't.
18981 */
18982 +
18983 +#ifdef CONFIG_PAX_KERNEXEC
18984 + return ktla_ktva(sp[0]);
18985 +#else
18986 if (sp[0] >> 22)
18987 return sp[0];
18988 if (sp[1] >> 22)
18989 return sp[1];
18990 #endif
18991 +
18992 +#endif
18993 }
18994 return pc;
18995 }
18996 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
18997 index bcfec2d..8f88b4a 100644
18998 --- a/arch/x86/kernel/tls.c
18999 +++ b/arch/x86/kernel/tls.c
19000 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19001 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19002 return -EINVAL;
19003
19004 +#ifdef CONFIG_PAX_SEGMEXEC
19005 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19006 + return -EINVAL;
19007 +#endif
19008 +
19009 set_tls_desc(p, idx, &info, 1);
19010
19011 return 0;
19012 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19013 index 451c0a7..e57f551 100644
19014 --- a/arch/x86/kernel/trampoline_32.S
19015 +++ b/arch/x86/kernel/trampoline_32.S
19016 @@ -32,6 +32,12 @@
19017 #include <asm/segment.h>
19018 #include <asm/page_types.h>
19019
19020 +#ifdef CONFIG_PAX_KERNEXEC
19021 +#define ta(X) (X)
19022 +#else
19023 +#define ta(X) ((X) - __PAGE_OFFSET)
19024 +#endif
19025 +
19026 #ifdef CONFIG_SMP
19027
19028 .section ".x86_trampoline","a"
19029 @@ -62,7 +68,7 @@ r_base = .
19030 inc %ax # protected mode (PE) bit
19031 lmsw %ax # into protected mode
19032 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19033 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19034 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19035
19036 # These need to be in the same 64K segment as the above;
19037 # hence we don't use the boot_gdt_descr defined in head.S
19038 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19039 index 09ff517..df19fbff 100644
19040 --- a/arch/x86/kernel/trampoline_64.S
19041 +++ b/arch/x86/kernel/trampoline_64.S
19042 @@ -90,7 +90,7 @@ startup_32:
19043 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19044 movl %eax, %ds
19045
19046 - movl $X86_CR4_PAE, %eax
19047 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19048 movl %eax, %cr4 # Enable PAE mode
19049
19050 # Setup trampoline 4 level pagetables
19051 @@ -138,7 +138,7 @@ tidt:
19052 # so the kernel can live anywhere
19053 .balign 4
19054 tgdt:
19055 - .short tgdt_end - tgdt # gdt limit
19056 + .short tgdt_end - tgdt - 1 # gdt limit
19057 .long tgdt - r_base
19058 .short 0
19059 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19060 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19061 index 4bbe04d..41d0943 100644
19062 --- a/arch/x86/kernel/traps.c
19063 +++ b/arch/x86/kernel/traps.c
19064 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19065
19066 /* Do we ignore FPU interrupts ? */
19067 char ignore_fpu_irq;
19068 -
19069 -/*
19070 - * The IDT has to be page-aligned to simplify the Pentium
19071 - * F0 0F bug workaround.
19072 - */
19073 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19074 #endif
19075
19076 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19077 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19078 }
19079
19080 static void __kprobes
19081 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19082 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19083 long error_code, siginfo_t *info)
19084 {
19085 struct task_struct *tsk = current;
19086
19087 #ifdef CONFIG_X86_32
19088 - if (regs->flags & X86_VM_MASK) {
19089 + if (v8086_mode(regs)) {
19090 /*
19091 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19092 * On nmi (interrupt 2), do_trap should not be called.
19093 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19094 }
19095 #endif
19096
19097 - if (!user_mode(regs))
19098 + if (!user_mode_novm(regs))
19099 goto kernel_trap;
19100
19101 #ifdef CONFIG_X86_32
19102 @@ -148,7 +142,7 @@ trap_signal:
19103 printk_ratelimit()) {
19104 printk(KERN_INFO
19105 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19106 - tsk->comm, tsk->pid, str,
19107 + tsk->comm, task_pid_nr(tsk), str,
19108 regs->ip, regs->sp, error_code);
19109 print_vma_addr(" in ", regs->ip);
19110 printk("\n");
19111 @@ -165,8 +159,20 @@ kernel_trap:
19112 if (!fixup_exception(regs)) {
19113 tsk->thread.error_code = error_code;
19114 tsk->thread.trap_no = trapnr;
19115 +
19116 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19117 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19118 + str = "PAX: suspicious stack segment fault";
19119 +#endif
19120 +
19121 die(str, regs, error_code);
19122 }
19123 +
19124 +#ifdef CONFIG_PAX_REFCOUNT
19125 + if (trapnr == 4)
19126 + pax_report_refcount_overflow(regs);
19127 +#endif
19128 +
19129 return;
19130
19131 #ifdef CONFIG_X86_32
19132 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19133 conditional_sti(regs);
19134
19135 #ifdef CONFIG_X86_32
19136 - if (regs->flags & X86_VM_MASK)
19137 + if (v8086_mode(regs))
19138 goto gp_in_vm86;
19139 #endif
19140
19141 tsk = current;
19142 - if (!user_mode(regs))
19143 + if (!user_mode_novm(regs))
19144 goto gp_in_kernel;
19145
19146 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19147 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19148 + struct mm_struct *mm = tsk->mm;
19149 + unsigned long limit;
19150 +
19151 + down_write(&mm->mmap_sem);
19152 + limit = mm->context.user_cs_limit;
19153 + if (limit < TASK_SIZE) {
19154 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19155 + up_write(&mm->mmap_sem);
19156 + return;
19157 + }
19158 + up_write(&mm->mmap_sem);
19159 + }
19160 +#endif
19161 +
19162 tsk->thread.error_code = error_code;
19163 tsk->thread.trap_no = 13;
19164
19165 @@ -295,6 +317,13 @@ gp_in_kernel:
19166 if (notify_die(DIE_GPF, "general protection fault", regs,
19167 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19168 return;
19169 +
19170 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19171 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19172 + die("PAX: suspicious general protection fault", regs, error_code);
19173 + else
19174 +#endif
19175 +
19176 die("general protection fault", regs, error_code);
19177 }
19178
19179 @@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19180 /* It's safe to allow irq's after DR6 has been saved */
19181 preempt_conditional_sti(regs);
19182
19183 - if (regs->flags & X86_VM_MASK) {
19184 + if (v8086_mode(regs)) {
19185 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19186 error_code, 1);
19187 preempt_conditional_cli(regs);
19188 @@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19189 * We already checked v86 mode above, so we can check for kernel mode
19190 * by just checking the CPL of CS.
19191 */
19192 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19193 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19194 tsk->thread.debugreg6 &= ~DR_STEP;
19195 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19196 regs->flags &= ~X86_EFLAGS_TF;
19197 @@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19198 return;
19199 conditional_sti(regs);
19200
19201 - if (!user_mode_vm(regs))
19202 + if (!user_mode(regs))
19203 {
19204 if (!fixup_exception(regs)) {
19205 task->thread.error_code = error_code;
19206 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19207 index b9242ba..50c5edd 100644
19208 --- a/arch/x86/kernel/verify_cpu.S
19209 +++ b/arch/x86/kernel/verify_cpu.S
19210 @@ -20,6 +20,7 @@
19211 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19212 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19213 * arch/x86/kernel/head_32.S: processor startup
19214 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19215 *
19216 * verify_cpu, returns the status of longmode and SSE in register %eax.
19217 * 0: Success 1: Failure
19218 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19219 index 328cb37..56556b4 100644
19220 --- a/arch/x86/kernel/vm86_32.c
19221 +++ b/arch/x86/kernel/vm86_32.c
19222 @@ -41,6 +41,7 @@
19223 #include <linux/ptrace.h>
19224 #include <linux/audit.h>
19225 #include <linux/stddef.h>
19226 +#include <linux/grsecurity.h>
19227
19228 #include <asm/uaccess.h>
19229 #include <asm/io.h>
19230 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19231 do_exit(SIGSEGV);
19232 }
19233
19234 - tss = &per_cpu(init_tss, get_cpu());
19235 + tss = init_tss + get_cpu();
19236 current->thread.sp0 = current->thread.saved_sp0;
19237 current->thread.sysenter_cs = __KERNEL_CS;
19238 load_sp0(tss, &current->thread);
19239 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19240 struct task_struct *tsk;
19241 int tmp, ret = -EPERM;
19242
19243 +#ifdef CONFIG_GRKERNSEC_VM86
19244 + if (!capable(CAP_SYS_RAWIO)) {
19245 + gr_handle_vm86();
19246 + goto out;
19247 + }
19248 +#endif
19249 +
19250 tsk = current;
19251 if (tsk->thread.saved_sp0)
19252 goto out;
19253 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19254 int tmp, ret;
19255 struct vm86plus_struct __user *v86;
19256
19257 +#ifdef CONFIG_GRKERNSEC_VM86
19258 + if (!capable(CAP_SYS_RAWIO)) {
19259 + gr_handle_vm86();
19260 + ret = -EPERM;
19261 + goto out;
19262 + }
19263 +#endif
19264 +
19265 tsk = current;
19266 switch (cmd) {
19267 case VM86_REQUEST_IRQ:
19268 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19269 tsk->thread.saved_fs = info->regs32->fs;
19270 tsk->thread.saved_gs = get_user_gs(info->regs32);
19271
19272 - tss = &per_cpu(init_tss, get_cpu());
19273 + tss = init_tss + get_cpu();
19274 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19275 if (cpu_has_sep)
19276 tsk->thread.sysenter_cs = 0;
19277 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19278 goto cannot_handle;
19279 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19280 goto cannot_handle;
19281 - intr_ptr = (unsigned long __user *) (i << 2);
19282 + intr_ptr = (__force unsigned long __user *) (i << 2);
19283 if (get_user(segoffs, intr_ptr))
19284 goto cannot_handle;
19285 if ((segoffs >> 16) == BIOSSEG)
19286 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19287 index 0f703f1..9e15f64 100644
19288 --- a/arch/x86/kernel/vmlinux.lds.S
19289 +++ b/arch/x86/kernel/vmlinux.lds.S
19290 @@ -26,6 +26,13 @@
19291 #include <asm/page_types.h>
19292 #include <asm/cache.h>
19293 #include <asm/boot.h>
19294 +#include <asm/segment.h>
19295 +
19296 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19297 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19298 +#else
19299 +#define __KERNEL_TEXT_OFFSET 0
19300 +#endif
19301
19302 #undef i386 /* in case the preprocessor is a 32bit one */
19303
19304 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19305
19306 PHDRS {
19307 text PT_LOAD FLAGS(5); /* R_E */
19308 +#ifdef CONFIG_X86_32
19309 + module PT_LOAD FLAGS(5); /* R_E */
19310 +#endif
19311 +#ifdef CONFIG_XEN
19312 + rodata PT_LOAD FLAGS(5); /* R_E */
19313 +#else
19314 + rodata PT_LOAD FLAGS(4); /* R__ */
19315 +#endif
19316 data PT_LOAD FLAGS(6); /* RW_ */
19317 -#ifdef CONFIG_X86_64
19318 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19319 #ifdef CONFIG_SMP
19320 percpu PT_LOAD FLAGS(6); /* RW_ */
19321 #endif
19322 + text.init PT_LOAD FLAGS(5); /* R_E */
19323 + text.exit PT_LOAD FLAGS(5); /* R_E */
19324 init PT_LOAD FLAGS(7); /* RWE */
19325 -#endif
19326 note PT_NOTE FLAGS(0); /* ___ */
19327 }
19328
19329 SECTIONS
19330 {
19331 #ifdef CONFIG_X86_32
19332 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19333 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19334 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19335 #else
19336 - . = __START_KERNEL;
19337 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19338 + . = __START_KERNEL;
19339 #endif
19340
19341 /* Text and read-only data */
19342 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19343 - _text = .;
19344 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19345 /* bootstrapping code */
19346 +#ifdef CONFIG_X86_32
19347 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19348 +#else
19349 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19350 +#endif
19351 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19352 + _text = .;
19353 HEAD_TEXT
19354 #ifdef CONFIG_X86_32
19355 . = ALIGN(PAGE_SIZE);
19356 @@ -108,13 +128,47 @@ SECTIONS
19357 IRQENTRY_TEXT
19358 *(.fixup)
19359 *(.gnu.warning)
19360 - /* End of text section */
19361 - _etext = .;
19362 } :text = 0x9090
19363
19364 - NOTES :text :note
19365 + . += __KERNEL_TEXT_OFFSET;
19366
19367 - EXCEPTION_TABLE(16) :text = 0x9090
19368 +#ifdef CONFIG_X86_32
19369 + . = ALIGN(PAGE_SIZE);
19370 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19371 +
19372 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19373 + MODULES_EXEC_VADDR = .;
19374 + BYTE(0)
19375 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19376 + . = ALIGN(HPAGE_SIZE);
19377 + MODULES_EXEC_END = . - 1;
19378 +#endif
19379 +
19380 + } :module
19381 +#endif
19382 +
19383 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19384 + /* End of text section */
19385 + _etext = . - __KERNEL_TEXT_OFFSET;
19386 + }
19387 +
19388 +#ifdef CONFIG_X86_32
19389 + . = ALIGN(PAGE_SIZE);
19390 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19391 + *(.idt)
19392 + . = ALIGN(PAGE_SIZE);
19393 + *(.empty_zero_page)
19394 + *(.initial_pg_fixmap)
19395 + *(.initial_pg_pmd)
19396 + *(.initial_page_table)
19397 + *(.swapper_pg_dir)
19398 + } :rodata
19399 +#endif
19400 +
19401 + . = ALIGN(PAGE_SIZE);
19402 + NOTES :rodata :note
19403 +
19404 + EXCEPTION_TABLE(16) :rodata
19405
19406 #if defined(CONFIG_DEBUG_RODATA)
19407 /* .text should occupy whole number of pages */
19408 @@ -126,16 +180,20 @@ SECTIONS
19409
19410 /* Data */
19411 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19412 +
19413 +#ifdef CONFIG_PAX_KERNEXEC
19414 + . = ALIGN(HPAGE_SIZE);
19415 +#else
19416 + . = ALIGN(PAGE_SIZE);
19417 +#endif
19418 +
19419 /* Start of data section */
19420 _sdata = .;
19421
19422 /* init_task */
19423 INIT_TASK_DATA(THREAD_SIZE)
19424
19425 -#ifdef CONFIG_X86_32
19426 - /* 32 bit has nosave before _edata */
19427 NOSAVE_DATA
19428 -#endif
19429
19430 PAGE_ALIGNED_DATA(PAGE_SIZE)
19431
19432 @@ -176,12 +234,19 @@ SECTIONS
19433 #endif /* CONFIG_X86_64 */
19434
19435 /* Init code and data - will be freed after init */
19436 - . = ALIGN(PAGE_SIZE);
19437 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19438 + BYTE(0)
19439 +
19440 +#ifdef CONFIG_PAX_KERNEXEC
19441 + . = ALIGN(HPAGE_SIZE);
19442 +#else
19443 + . = ALIGN(PAGE_SIZE);
19444 +#endif
19445 +
19446 __init_begin = .; /* paired with __init_end */
19447 - }
19448 + } :init.begin
19449
19450 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19451 +#ifdef CONFIG_SMP
19452 /*
19453 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19454 * output PHDR, so the next output section - .init.text - should
19455 @@ -190,12 +255,27 @@ SECTIONS
19456 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19457 #endif
19458
19459 - INIT_TEXT_SECTION(PAGE_SIZE)
19460 -#ifdef CONFIG_X86_64
19461 - :init
19462 -#endif
19463 + . = ALIGN(PAGE_SIZE);
19464 + init_begin = .;
19465 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19466 + VMLINUX_SYMBOL(_sinittext) = .;
19467 + INIT_TEXT
19468 + VMLINUX_SYMBOL(_einittext) = .;
19469 + . = ALIGN(PAGE_SIZE);
19470 + } :text.init
19471
19472 - INIT_DATA_SECTION(16)
19473 + /*
19474 + * .exit.text is discard at runtime, not link time, to deal with
19475 + * references from .altinstructions and .eh_frame
19476 + */
19477 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19478 + EXIT_TEXT
19479 + . = ALIGN(16);
19480 + } :text.exit
19481 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19482 +
19483 + . = ALIGN(PAGE_SIZE);
19484 + INIT_DATA_SECTION(16) :init
19485
19486 /*
19487 * Code and data for a variety of lowlevel trampolines, to be
19488 @@ -269,19 +349,12 @@ SECTIONS
19489 }
19490
19491 . = ALIGN(8);
19492 - /*
19493 - * .exit.text is discard at runtime, not link time, to deal with
19494 - * references from .altinstructions and .eh_frame
19495 - */
19496 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19497 - EXIT_TEXT
19498 - }
19499
19500 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19501 EXIT_DATA
19502 }
19503
19504 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19505 +#ifndef CONFIG_SMP
19506 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
19507 #endif
19508
19509 @@ -300,16 +373,10 @@ SECTIONS
19510 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
19511 __smp_locks = .;
19512 *(.smp_locks)
19513 - . = ALIGN(PAGE_SIZE);
19514 __smp_locks_end = .;
19515 + . = ALIGN(PAGE_SIZE);
19516 }
19517
19518 -#ifdef CONFIG_X86_64
19519 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19520 - NOSAVE_DATA
19521 - }
19522 -#endif
19523 -
19524 /* BSS */
19525 . = ALIGN(PAGE_SIZE);
19526 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19527 @@ -325,6 +392,7 @@ SECTIONS
19528 __brk_base = .;
19529 . += 64 * 1024; /* 64k alignment slop space */
19530 *(.brk_reservation) /* areas brk users have reserved */
19531 + . = ALIGN(HPAGE_SIZE);
19532 __brk_limit = .;
19533 }
19534
19535 @@ -351,13 +419,12 @@ SECTIONS
19536 * for the boot processor.
19537 */
19538 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
19539 -INIT_PER_CPU(gdt_page);
19540 INIT_PER_CPU(irq_stack_union);
19541
19542 /*
19543 * Build-time check on the image size:
19544 */
19545 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19546 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19547 "kernel image bigger than KERNEL_IMAGE_SIZE");
19548
19549 #ifdef CONFIG_SMP
19550 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
19551 index b07ba93..a212969 100644
19552 --- a/arch/x86/kernel/vsyscall_64.c
19553 +++ b/arch/x86/kernel/vsyscall_64.c
19554 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
19555 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
19556 };
19557
19558 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
19559 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
19560
19561 static int __init vsyscall_setup(char *str)
19562 {
19563 if (str) {
19564 if (!strcmp("emulate", str))
19565 vsyscall_mode = EMULATE;
19566 - else if (!strcmp("native", str))
19567 - vsyscall_mode = NATIVE;
19568 else if (!strcmp("none", str))
19569 vsyscall_mode = NONE;
19570 else
19571 @@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19572
19573 tsk = current;
19574 if (seccomp_mode(&tsk->seccomp))
19575 - do_exit(SIGKILL);
19576 + do_group_exit(SIGKILL);
19577
19578 /*
19579 * With a real vsyscall, page faults cause SIGSEGV. We want to
19580 @@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19581 return true;
19582
19583 sigsegv:
19584 - force_sig(SIGSEGV, current);
19585 - return true;
19586 + do_group_exit(SIGKILL);
19587 }
19588
19589 /*
19590 @@ -333,10 +330,7 @@ void __init map_vsyscall(void)
19591 extern char __vvar_page;
19592 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
19593
19594 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
19595 - vsyscall_mode == NATIVE
19596 - ? PAGE_KERNEL_VSYSCALL
19597 - : PAGE_KERNEL_VVAR);
19598 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
19599 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
19600 (unsigned long)VSYSCALL_START);
19601
19602 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
19603 index 9796c2f..f686fbf 100644
19604 --- a/arch/x86/kernel/x8664_ksyms_64.c
19605 +++ b/arch/x86/kernel/x8664_ksyms_64.c
19606 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
19607 EXPORT_SYMBOL(copy_user_generic_string);
19608 EXPORT_SYMBOL(copy_user_generic_unrolled);
19609 EXPORT_SYMBOL(__copy_user_nocache);
19610 -EXPORT_SYMBOL(_copy_from_user);
19611 -EXPORT_SYMBOL(_copy_to_user);
19612
19613 EXPORT_SYMBOL(copy_page);
19614 EXPORT_SYMBOL(clear_page);
19615 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
19616 index 7110911..e8cdee5 100644
19617 --- a/arch/x86/kernel/xsave.c
19618 +++ b/arch/x86/kernel/xsave.c
19619 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
19620 fx_sw_user->xstate_size > fx_sw_user->extended_size)
19621 return -EINVAL;
19622
19623 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
19624 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
19625 fx_sw_user->extended_size -
19626 FP_XSTATE_MAGIC2_SIZE));
19627 if (err)
19628 @@ -266,7 +266,7 @@ fx_only:
19629 * the other extended state.
19630 */
19631 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
19632 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
19633 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
19634 }
19635
19636 /*
19637 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
19638 if (use_xsave())
19639 err = restore_user_xstate(buf);
19640 else
19641 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
19642 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
19643 buf);
19644 if (unlikely(err)) {
19645 /*
19646 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
19647 index 89b02bf..0f6511d 100644
19648 --- a/arch/x86/kvm/cpuid.c
19649 +++ b/arch/x86/kvm/cpuid.c
19650 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
19651 struct kvm_cpuid2 *cpuid,
19652 struct kvm_cpuid_entry2 __user *entries)
19653 {
19654 - int r;
19655 + int r, i;
19656
19657 r = -E2BIG;
19658 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
19659 goto out;
19660 r = -EFAULT;
19661 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
19662 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19663 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19664 goto out;
19665 + for (i = 0; i < cpuid->nent; ++i) {
19666 + struct kvm_cpuid_entry2 cpuid_entry;
19667 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
19668 + goto out;
19669 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
19670 + }
19671 vcpu->arch.cpuid_nent = cpuid->nent;
19672 kvm_apic_set_version(vcpu);
19673 kvm_x86_ops->cpuid_update(vcpu);
19674 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
19675 struct kvm_cpuid2 *cpuid,
19676 struct kvm_cpuid_entry2 __user *entries)
19677 {
19678 - int r;
19679 + int r, i;
19680
19681 r = -E2BIG;
19682 if (cpuid->nent < vcpu->arch.cpuid_nent)
19683 goto out;
19684 r = -EFAULT;
19685 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
19686 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19687 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19688 goto out;
19689 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
19690 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
19691 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
19692 + goto out;
19693 + }
19694 return 0;
19695
19696 out:
19697 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
19698 index 0982507..7f6d72f 100644
19699 --- a/arch/x86/kvm/emulate.c
19700 +++ b/arch/x86/kvm/emulate.c
19701 @@ -250,6 +250,7 @@ struct gprefix {
19702
19703 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
19704 do { \
19705 + unsigned long _tmp; \
19706 __asm__ __volatile__ ( \
19707 _PRE_EFLAGS("0", "4", "2") \
19708 _op _suffix " %"_x"3,%1; " \
19709 @@ -264,8 +265,6 @@ struct gprefix {
19710 /* Raw emulation: instruction has two explicit operands. */
19711 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
19712 do { \
19713 - unsigned long _tmp; \
19714 - \
19715 switch ((ctxt)->dst.bytes) { \
19716 case 2: \
19717 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
19718 @@ -281,7 +280,6 @@ struct gprefix {
19719
19720 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
19721 do { \
19722 - unsigned long _tmp; \
19723 switch ((ctxt)->dst.bytes) { \
19724 case 1: \
19725 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
19726 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
19727 index cfdc6e0..ab92e84 100644
19728 --- a/arch/x86/kvm/lapic.c
19729 +++ b/arch/x86/kvm/lapic.c
19730 @@ -54,7 +54,7 @@
19731 #define APIC_BUS_CYCLE_NS 1
19732
19733 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
19734 -#define apic_debug(fmt, arg...)
19735 +#define apic_debug(fmt, arg...) do {} while (0)
19736
19737 #define APIC_LVT_NUM 6
19738 /* 14 is the version for Xeon and Pentium 8.4.8*/
19739 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
19740 index 1561028..0ed7f14 100644
19741 --- a/arch/x86/kvm/paging_tmpl.h
19742 +++ b/arch/x86/kvm/paging_tmpl.h
19743 @@ -197,7 +197,7 @@ retry_walk:
19744 if (unlikely(kvm_is_error_hva(host_addr)))
19745 goto error;
19746
19747 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
19748 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
19749 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
19750 goto error;
19751
19752 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
19753 index e385214..f8df033 100644
19754 --- a/arch/x86/kvm/svm.c
19755 +++ b/arch/x86/kvm/svm.c
19756 @@ -3420,7 +3420,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
19757 int cpu = raw_smp_processor_id();
19758
19759 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
19760 +
19761 + pax_open_kernel();
19762 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
19763 + pax_close_kernel();
19764 +
19765 load_TR_desc();
19766 }
19767
19768 @@ -3798,6 +3802,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
19769 #endif
19770 #endif
19771
19772 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19773 + __set_fs(current_thread_info()->addr_limit);
19774 +#endif
19775 +
19776 reload_tss(vcpu);
19777
19778 local_irq_disable();
19779 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
19780 index 3b4c8d8..f457b63 100644
19781 --- a/arch/x86/kvm/vmx.c
19782 +++ b/arch/x86/kvm/vmx.c
19783 @@ -1306,7 +1306,11 @@ static void reload_tss(void)
19784 struct desc_struct *descs;
19785
19786 descs = (void *)gdt->address;
19787 +
19788 + pax_open_kernel();
19789 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
19790 + pax_close_kernel();
19791 +
19792 load_TR_desc();
19793 }
19794
19795 @@ -2631,8 +2635,11 @@ static __init int hardware_setup(void)
19796 if (!cpu_has_vmx_flexpriority())
19797 flexpriority_enabled = 0;
19798
19799 - if (!cpu_has_vmx_tpr_shadow())
19800 - kvm_x86_ops->update_cr8_intercept = NULL;
19801 + if (!cpu_has_vmx_tpr_shadow()) {
19802 + pax_open_kernel();
19803 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
19804 + pax_close_kernel();
19805 + }
19806
19807 if (enable_ept && !cpu_has_vmx_ept_2m_page())
19808 kvm_disable_largepages();
19809 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
19810 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
19811
19812 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
19813 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
19814 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
19815
19816 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
19817 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
19818 @@ -6184,6 +6191,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19819 "jmp .Lkvm_vmx_return \n\t"
19820 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
19821 ".Lkvm_vmx_return: "
19822 +
19823 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19824 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
19825 + ".Lkvm_vmx_return2: "
19826 +#endif
19827 +
19828 /* Save guest registers, load host registers, keep flags */
19829 "mov %0, %c[wordsize](%%"R"sp) \n\t"
19830 "pop %0 \n\t"
19831 @@ -6232,6 +6245,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19832 #endif
19833 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
19834 [wordsize]"i"(sizeof(ulong))
19835 +
19836 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19837 + ,[cs]"i"(__KERNEL_CS)
19838 +#endif
19839 +
19840 : "cc", "memory"
19841 , R"ax", R"bx", R"di", R"si"
19842 #ifdef CONFIG_X86_64
19843 @@ -6260,7 +6278,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19844 }
19845 }
19846
19847 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
19848 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
19849 +
19850 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19851 + loadsegment(fs, __KERNEL_PERCPU);
19852 +#endif
19853 +
19854 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19855 + __set_fs(current_thread_info()->addr_limit);
19856 +#endif
19857 +
19858 vmx->loaded_vmcs->launched = 1;
19859
19860 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
19861 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
19862 index 9cbfc06..7ddc9fa 100644
19863 --- a/arch/x86/kvm/x86.c
19864 +++ b/arch/x86/kvm/x86.c
19865 @@ -1311,8 +1311,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
19866 {
19867 struct kvm *kvm = vcpu->kvm;
19868 int lm = is_long_mode(vcpu);
19869 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
19870 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
19871 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
19872 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
19873 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
19874 : kvm->arch.xen_hvm_config.blob_size_32;
19875 u32 page_num = data & ~PAGE_MASK;
19876 @@ -2145,6 +2145,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
19877 if (n < msr_list.nmsrs)
19878 goto out;
19879 r = -EFAULT;
19880 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
19881 + goto out;
19882 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
19883 num_msrs_to_save * sizeof(u32)))
19884 goto out;
19885 @@ -2266,7 +2268,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
19886 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
19887 struct kvm_interrupt *irq)
19888 {
19889 - if (irq->irq < 0 || irq->irq >= 256)
19890 + if (irq->irq >= 256)
19891 return -EINVAL;
19892 if (irqchip_in_kernel(vcpu->kvm))
19893 return -ENXIO;
19894 @@ -4780,7 +4782,7 @@ static void kvm_set_mmio_spte_mask(void)
19895 kvm_mmu_set_mmio_spte_mask(mask);
19896 }
19897
19898 -int kvm_arch_init(void *opaque)
19899 +int kvm_arch_init(const void *opaque)
19900 {
19901 int r;
19902 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
19903 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
19904 index 642d880..44e0f3f 100644
19905 --- a/arch/x86/lguest/boot.c
19906 +++ b/arch/x86/lguest/boot.c
19907 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
19908 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
19909 * Launcher to reboot us.
19910 */
19911 -static void lguest_restart(char *reason)
19912 +static __noreturn void lguest_restart(char *reason)
19913 {
19914 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
19915 + BUG();
19916 }
19917
19918 /*G:050
19919 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
19920 index 042f682..c92afb6 100644
19921 --- a/arch/x86/lib/atomic64_32.c
19922 +++ b/arch/x86/lib/atomic64_32.c
19923 @@ -8,18 +8,30 @@
19924
19925 long long atomic64_read_cx8(long long, const atomic64_t *v);
19926 EXPORT_SYMBOL(atomic64_read_cx8);
19927 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
19928 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
19929 long long atomic64_set_cx8(long long, const atomic64_t *v);
19930 EXPORT_SYMBOL(atomic64_set_cx8);
19931 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
19932 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
19933 long long atomic64_xchg_cx8(long long, unsigned high);
19934 EXPORT_SYMBOL(atomic64_xchg_cx8);
19935 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
19936 EXPORT_SYMBOL(atomic64_add_return_cx8);
19937 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19938 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
19939 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
19940 EXPORT_SYMBOL(atomic64_sub_return_cx8);
19941 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19942 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
19943 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
19944 EXPORT_SYMBOL(atomic64_inc_return_cx8);
19945 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19946 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
19947 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
19948 EXPORT_SYMBOL(atomic64_dec_return_cx8);
19949 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19950 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
19951 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
19952 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
19953 int atomic64_inc_not_zero_cx8(atomic64_t *v);
19954 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
19955 #ifndef CONFIG_X86_CMPXCHG64
19956 long long atomic64_read_386(long long, const atomic64_t *v);
19957 EXPORT_SYMBOL(atomic64_read_386);
19958 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
19959 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
19960 long long atomic64_set_386(long long, const atomic64_t *v);
19961 EXPORT_SYMBOL(atomic64_set_386);
19962 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
19963 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
19964 long long atomic64_xchg_386(long long, unsigned high);
19965 EXPORT_SYMBOL(atomic64_xchg_386);
19966 long long atomic64_add_return_386(long long a, atomic64_t *v);
19967 EXPORT_SYMBOL(atomic64_add_return_386);
19968 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19969 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
19970 long long atomic64_sub_return_386(long long a, atomic64_t *v);
19971 EXPORT_SYMBOL(atomic64_sub_return_386);
19972 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19973 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
19974 long long atomic64_inc_return_386(long long a, atomic64_t *v);
19975 EXPORT_SYMBOL(atomic64_inc_return_386);
19976 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19977 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
19978 long long atomic64_dec_return_386(long long a, atomic64_t *v);
19979 EXPORT_SYMBOL(atomic64_dec_return_386);
19980 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19981 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
19982 long long atomic64_add_386(long long a, atomic64_t *v);
19983 EXPORT_SYMBOL(atomic64_add_386);
19984 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
19985 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
19986 long long atomic64_sub_386(long long a, atomic64_t *v);
19987 EXPORT_SYMBOL(atomic64_sub_386);
19988 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
19989 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
19990 long long atomic64_inc_386(long long a, atomic64_t *v);
19991 EXPORT_SYMBOL(atomic64_inc_386);
19992 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
19993 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
19994 long long atomic64_dec_386(long long a, atomic64_t *v);
19995 EXPORT_SYMBOL(atomic64_dec_386);
19996 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
19997 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
19998 long long atomic64_dec_if_positive_386(atomic64_t *v);
19999 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20000 int atomic64_inc_not_zero_386(atomic64_t *v);
20001 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20002 index e8e7e0d..56fd1b0 100644
20003 --- a/arch/x86/lib/atomic64_386_32.S
20004 +++ b/arch/x86/lib/atomic64_386_32.S
20005 @@ -48,6 +48,10 @@ BEGIN(read)
20006 movl (v), %eax
20007 movl 4(v), %edx
20008 RET_ENDP
20009 +BEGIN(read_unchecked)
20010 + movl (v), %eax
20011 + movl 4(v), %edx
20012 +RET_ENDP
20013 #undef v
20014
20015 #define v %esi
20016 @@ -55,6 +59,10 @@ BEGIN(set)
20017 movl %ebx, (v)
20018 movl %ecx, 4(v)
20019 RET_ENDP
20020 +BEGIN(set_unchecked)
20021 + movl %ebx, (v)
20022 + movl %ecx, 4(v)
20023 +RET_ENDP
20024 #undef v
20025
20026 #define v %esi
20027 @@ -70,6 +78,20 @@ RET_ENDP
20028 BEGIN(add)
20029 addl %eax, (v)
20030 adcl %edx, 4(v)
20031 +
20032 +#ifdef CONFIG_PAX_REFCOUNT
20033 + jno 0f
20034 + subl %eax, (v)
20035 + sbbl %edx, 4(v)
20036 + int $4
20037 +0:
20038 + _ASM_EXTABLE(0b, 0b)
20039 +#endif
20040 +
20041 +RET_ENDP
20042 +BEGIN(add_unchecked)
20043 + addl %eax, (v)
20044 + adcl %edx, 4(v)
20045 RET_ENDP
20046 #undef v
20047
20048 @@ -77,6 +99,24 @@ RET_ENDP
20049 BEGIN(add_return)
20050 addl (v), %eax
20051 adcl 4(v), %edx
20052 +
20053 +#ifdef CONFIG_PAX_REFCOUNT
20054 + into
20055 +1234:
20056 + _ASM_EXTABLE(1234b, 2f)
20057 +#endif
20058 +
20059 + movl %eax, (v)
20060 + movl %edx, 4(v)
20061 +
20062 +#ifdef CONFIG_PAX_REFCOUNT
20063 +2:
20064 +#endif
20065 +
20066 +RET_ENDP
20067 +BEGIN(add_return_unchecked)
20068 + addl (v), %eax
20069 + adcl 4(v), %edx
20070 movl %eax, (v)
20071 movl %edx, 4(v)
20072 RET_ENDP
20073 @@ -86,6 +126,20 @@ RET_ENDP
20074 BEGIN(sub)
20075 subl %eax, (v)
20076 sbbl %edx, 4(v)
20077 +
20078 +#ifdef CONFIG_PAX_REFCOUNT
20079 + jno 0f
20080 + addl %eax, (v)
20081 + adcl %edx, 4(v)
20082 + int $4
20083 +0:
20084 + _ASM_EXTABLE(0b, 0b)
20085 +#endif
20086 +
20087 +RET_ENDP
20088 +BEGIN(sub_unchecked)
20089 + subl %eax, (v)
20090 + sbbl %edx, 4(v)
20091 RET_ENDP
20092 #undef v
20093
20094 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20095 sbbl $0, %edx
20096 addl (v), %eax
20097 adcl 4(v), %edx
20098 +
20099 +#ifdef CONFIG_PAX_REFCOUNT
20100 + into
20101 +1234:
20102 + _ASM_EXTABLE(1234b, 2f)
20103 +#endif
20104 +
20105 + movl %eax, (v)
20106 + movl %edx, 4(v)
20107 +
20108 +#ifdef CONFIG_PAX_REFCOUNT
20109 +2:
20110 +#endif
20111 +
20112 +RET_ENDP
20113 +BEGIN(sub_return_unchecked)
20114 + negl %edx
20115 + negl %eax
20116 + sbbl $0, %edx
20117 + addl (v), %eax
20118 + adcl 4(v), %edx
20119 movl %eax, (v)
20120 movl %edx, 4(v)
20121 RET_ENDP
20122 @@ -105,6 +180,20 @@ RET_ENDP
20123 BEGIN(inc)
20124 addl $1, (v)
20125 adcl $0, 4(v)
20126 +
20127 +#ifdef CONFIG_PAX_REFCOUNT
20128 + jno 0f
20129 + subl $1, (v)
20130 + sbbl $0, 4(v)
20131 + int $4
20132 +0:
20133 + _ASM_EXTABLE(0b, 0b)
20134 +#endif
20135 +
20136 +RET_ENDP
20137 +BEGIN(inc_unchecked)
20138 + addl $1, (v)
20139 + adcl $0, 4(v)
20140 RET_ENDP
20141 #undef v
20142
20143 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20144 movl 4(v), %edx
20145 addl $1, %eax
20146 adcl $0, %edx
20147 +
20148 +#ifdef CONFIG_PAX_REFCOUNT
20149 + into
20150 +1234:
20151 + _ASM_EXTABLE(1234b, 2f)
20152 +#endif
20153 +
20154 + movl %eax, (v)
20155 + movl %edx, 4(v)
20156 +
20157 +#ifdef CONFIG_PAX_REFCOUNT
20158 +2:
20159 +#endif
20160 +
20161 +RET_ENDP
20162 +BEGIN(inc_return_unchecked)
20163 + movl (v), %eax
20164 + movl 4(v), %edx
20165 + addl $1, %eax
20166 + adcl $0, %edx
20167 movl %eax, (v)
20168 movl %edx, 4(v)
20169 RET_ENDP
20170 @@ -123,6 +232,20 @@ RET_ENDP
20171 BEGIN(dec)
20172 subl $1, (v)
20173 sbbl $0, 4(v)
20174 +
20175 +#ifdef CONFIG_PAX_REFCOUNT
20176 + jno 0f
20177 + addl $1, (v)
20178 + adcl $0, 4(v)
20179 + int $4
20180 +0:
20181 + _ASM_EXTABLE(0b, 0b)
20182 +#endif
20183 +
20184 +RET_ENDP
20185 +BEGIN(dec_unchecked)
20186 + subl $1, (v)
20187 + sbbl $0, 4(v)
20188 RET_ENDP
20189 #undef v
20190
20191 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20192 movl 4(v), %edx
20193 subl $1, %eax
20194 sbbl $0, %edx
20195 +
20196 +#ifdef CONFIG_PAX_REFCOUNT
20197 + into
20198 +1234:
20199 + _ASM_EXTABLE(1234b, 2f)
20200 +#endif
20201 +
20202 + movl %eax, (v)
20203 + movl %edx, 4(v)
20204 +
20205 +#ifdef CONFIG_PAX_REFCOUNT
20206 +2:
20207 +#endif
20208 +
20209 +RET_ENDP
20210 +BEGIN(dec_return_unchecked)
20211 + movl (v), %eax
20212 + movl 4(v), %edx
20213 + subl $1, %eax
20214 + sbbl $0, %edx
20215 movl %eax, (v)
20216 movl %edx, 4(v)
20217 RET_ENDP
20218 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20219 adcl %edx, %edi
20220 addl (v), %eax
20221 adcl 4(v), %edx
20222 +
20223 +#ifdef CONFIG_PAX_REFCOUNT
20224 + into
20225 +1234:
20226 + _ASM_EXTABLE(1234b, 2f)
20227 +#endif
20228 +
20229 cmpl %eax, %esi
20230 je 3f
20231 1:
20232 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20233 1:
20234 addl $1, %eax
20235 adcl $0, %edx
20236 +
20237 +#ifdef CONFIG_PAX_REFCOUNT
20238 + into
20239 +1234:
20240 + _ASM_EXTABLE(1234b, 2f)
20241 +#endif
20242 +
20243 movl %eax, (v)
20244 movl %edx, 4(v)
20245 movl $1, %eax
20246 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20247 movl 4(v), %edx
20248 subl $1, %eax
20249 sbbl $0, %edx
20250 +
20251 +#ifdef CONFIG_PAX_REFCOUNT
20252 + into
20253 +1234:
20254 + _ASM_EXTABLE(1234b, 1f)
20255 +#endif
20256 +
20257 js 1f
20258 movl %eax, (v)
20259 movl %edx, 4(v)
20260 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20261 index 391a083..d658e9f 100644
20262 --- a/arch/x86/lib/atomic64_cx8_32.S
20263 +++ b/arch/x86/lib/atomic64_cx8_32.S
20264 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20265 CFI_STARTPROC
20266
20267 read64 %ecx
20268 + pax_force_retaddr
20269 ret
20270 CFI_ENDPROC
20271 ENDPROC(atomic64_read_cx8)
20272
20273 +ENTRY(atomic64_read_unchecked_cx8)
20274 + CFI_STARTPROC
20275 +
20276 + read64 %ecx
20277 + pax_force_retaddr
20278 + ret
20279 + CFI_ENDPROC
20280 +ENDPROC(atomic64_read_unchecked_cx8)
20281 +
20282 ENTRY(atomic64_set_cx8)
20283 CFI_STARTPROC
20284
20285 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20286 cmpxchg8b (%esi)
20287 jne 1b
20288
20289 + pax_force_retaddr
20290 ret
20291 CFI_ENDPROC
20292 ENDPROC(atomic64_set_cx8)
20293
20294 +ENTRY(atomic64_set_unchecked_cx8)
20295 + CFI_STARTPROC
20296 +
20297 +1:
20298 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20299 + * are atomic on 586 and newer */
20300 + cmpxchg8b (%esi)
20301 + jne 1b
20302 +
20303 + pax_force_retaddr
20304 + ret
20305 + CFI_ENDPROC
20306 +ENDPROC(atomic64_set_unchecked_cx8)
20307 +
20308 ENTRY(atomic64_xchg_cx8)
20309 CFI_STARTPROC
20310
20311 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20312 cmpxchg8b (%esi)
20313 jne 1b
20314
20315 + pax_force_retaddr
20316 ret
20317 CFI_ENDPROC
20318 ENDPROC(atomic64_xchg_cx8)
20319
20320 -.macro addsub_return func ins insc
20321 -ENTRY(atomic64_\func\()_return_cx8)
20322 +.macro addsub_return func ins insc unchecked=""
20323 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20324 CFI_STARTPROC
20325 SAVE ebp
20326 SAVE ebx
20327 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20328 movl %edx, %ecx
20329 \ins\()l %esi, %ebx
20330 \insc\()l %edi, %ecx
20331 +
20332 +.ifb \unchecked
20333 +#ifdef CONFIG_PAX_REFCOUNT
20334 + into
20335 +2:
20336 + _ASM_EXTABLE(2b, 3f)
20337 +#endif
20338 +.endif
20339 +
20340 LOCK_PREFIX
20341 cmpxchg8b (%ebp)
20342 jne 1b
20343 -
20344 -10:
20345 movl %ebx, %eax
20346 movl %ecx, %edx
20347 +
20348 +.ifb \unchecked
20349 +#ifdef CONFIG_PAX_REFCOUNT
20350 +3:
20351 +#endif
20352 +.endif
20353 +
20354 RESTORE edi
20355 RESTORE esi
20356 RESTORE ebx
20357 RESTORE ebp
20358 + pax_force_retaddr
20359 ret
20360 CFI_ENDPROC
20361 -ENDPROC(atomic64_\func\()_return_cx8)
20362 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20363 .endm
20364
20365 addsub_return add add adc
20366 addsub_return sub sub sbb
20367 +addsub_return add add adc _unchecked
20368 +addsub_return sub sub sbb _unchecked
20369
20370 -.macro incdec_return func ins insc
20371 -ENTRY(atomic64_\func\()_return_cx8)
20372 +.macro incdec_return func ins insc unchecked
20373 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20374 CFI_STARTPROC
20375 SAVE ebx
20376
20377 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20378 movl %edx, %ecx
20379 \ins\()l $1, %ebx
20380 \insc\()l $0, %ecx
20381 +
20382 +.ifb \unchecked
20383 +#ifdef CONFIG_PAX_REFCOUNT
20384 + into
20385 +2:
20386 + _ASM_EXTABLE(2b, 3f)
20387 +#endif
20388 +.endif
20389 +
20390 LOCK_PREFIX
20391 cmpxchg8b (%esi)
20392 jne 1b
20393
20394 -10:
20395 movl %ebx, %eax
20396 movl %ecx, %edx
20397 +
20398 +.ifb \unchecked
20399 +#ifdef CONFIG_PAX_REFCOUNT
20400 +3:
20401 +#endif
20402 +.endif
20403 +
20404 RESTORE ebx
20405 + pax_force_retaddr
20406 ret
20407 CFI_ENDPROC
20408 -ENDPROC(atomic64_\func\()_return_cx8)
20409 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20410 .endm
20411
20412 incdec_return inc add adc
20413 incdec_return dec sub sbb
20414 +incdec_return inc add adc _unchecked
20415 +incdec_return dec sub sbb _unchecked
20416
20417 ENTRY(atomic64_dec_if_positive_cx8)
20418 CFI_STARTPROC
20419 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20420 movl %edx, %ecx
20421 subl $1, %ebx
20422 sbb $0, %ecx
20423 +
20424 +#ifdef CONFIG_PAX_REFCOUNT
20425 + into
20426 +1234:
20427 + _ASM_EXTABLE(1234b, 2f)
20428 +#endif
20429 +
20430 js 2f
20431 LOCK_PREFIX
20432 cmpxchg8b (%esi)
20433 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20434 movl %ebx, %eax
20435 movl %ecx, %edx
20436 RESTORE ebx
20437 + pax_force_retaddr
20438 ret
20439 CFI_ENDPROC
20440 ENDPROC(atomic64_dec_if_positive_cx8)
20441 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
20442 movl %edx, %ecx
20443 addl %esi, %ebx
20444 adcl %edi, %ecx
20445 +
20446 +#ifdef CONFIG_PAX_REFCOUNT
20447 + into
20448 +1234:
20449 + _ASM_EXTABLE(1234b, 3f)
20450 +#endif
20451 +
20452 LOCK_PREFIX
20453 cmpxchg8b (%ebp)
20454 jne 1b
20455 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
20456 CFI_ADJUST_CFA_OFFSET -8
20457 RESTORE ebx
20458 RESTORE ebp
20459 + pax_force_retaddr
20460 ret
20461 4:
20462 cmpl %edx, 4(%esp)
20463 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20464 movl %edx, %ecx
20465 addl $1, %ebx
20466 adcl $0, %ecx
20467 +
20468 +#ifdef CONFIG_PAX_REFCOUNT
20469 + into
20470 +1234:
20471 + _ASM_EXTABLE(1234b, 3f)
20472 +#endif
20473 +
20474 LOCK_PREFIX
20475 cmpxchg8b (%esi)
20476 jne 1b
20477 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20478 movl $1, %eax
20479 3:
20480 RESTORE ebx
20481 + pax_force_retaddr
20482 ret
20483 4:
20484 testl %edx, %edx
20485 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20486 index 78d16a5..fbcf666 100644
20487 --- a/arch/x86/lib/checksum_32.S
20488 +++ b/arch/x86/lib/checksum_32.S
20489 @@ -28,7 +28,8 @@
20490 #include <linux/linkage.h>
20491 #include <asm/dwarf2.h>
20492 #include <asm/errno.h>
20493 -
20494 +#include <asm/segment.h>
20495 +
20496 /*
20497 * computes a partial checksum, e.g. for TCP/UDP fragments
20498 */
20499 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20500
20501 #define ARGBASE 16
20502 #define FP 12
20503 -
20504 -ENTRY(csum_partial_copy_generic)
20505 +
20506 +ENTRY(csum_partial_copy_generic_to_user)
20507 CFI_STARTPROC
20508 +
20509 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20510 + pushl_cfi %gs
20511 + popl_cfi %es
20512 + jmp csum_partial_copy_generic
20513 +#endif
20514 +
20515 +ENTRY(csum_partial_copy_generic_from_user)
20516 +
20517 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20518 + pushl_cfi %gs
20519 + popl_cfi %ds
20520 +#endif
20521 +
20522 +ENTRY(csum_partial_copy_generic)
20523 subl $4,%esp
20524 CFI_ADJUST_CFA_OFFSET 4
20525 pushl_cfi %edi
20526 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
20527 jmp 4f
20528 SRC(1: movw (%esi), %bx )
20529 addl $2, %esi
20530 -DST( movw %bx, (%edi) )
20531 +DST( movw %bx, %es:(%edi) )
20532 addl $2, %edi
20533 addw %bx, %ax
20534 adcl $0, %eax
20535 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
20536 SRC(1: movl (%esi), %ebx )
20537 SRC( movl 4(%esi), %edx )
20538 adcl %ebx, %eax
20539 -DST( movl %ebx, (%edi) )
20540 +DST( movl %ebx, %es:(%edi) )
20541 adcl %edx, %eax
20542 -DST( movl %edx, 4(%edi) )
20543 +DST( movl %edx, %es:4(%edi) )
20544
20545 SRC( movl 8(%esi), %ebx )
20546 SRC( movl 12(%esi), %edx )
20547 adcl %ebx, %eax
20548 -DST( movl %ebx, 8(%edi) )
20549 +DST( movl %ebx, %es:8(%edi) )
20550 adcl %edx, %eax
20551 -DST( movl %edx, 12(%edi) )
20552 +DST( movl %edx, %es:12(%edi) )
20553
20554 SRC( movl 16(%esi), %ebx )
20555 SRC( movl 20(%esi), %edx )
20556 adcl %ebx, %eax
20557 -DST( movl %ebx, 16(%edi) )
20558 +DST( movl %ebx, %es:16(%edi) )
20559 adcl %edx, %eax
20560 -DST( movl %edx, 20(%edi) )
20561 +DST( movl %edx, %es:20(%edi) )
20562
20563 SRC( movl 24(%esi), %ebx )
20564 SRC( movl 28(%esi), %edx )
20565 adcl %ebx, %eax
20566 -DST( movl %ebx, 24(%edi) )
20567 +DST( movl %ebx, %es:24(%edi) )
20568 adcl %edx, %eax
20569 -DST( movl %edx, 28(%edi) )
20570 +DST( movl %edx, %es:28(%edi) )
20571
20572 lea 32(%esi), %esi
20573 lea 32(%edi), %edi
20574 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
20575 shrl $2, %edx # This clears CF
20576 SRC(3: movl (%esi), %ebx )
20577 adcl %ebx, %eax
20578 -DST( movl %ebx, (%edi) )
20579 +DST( movl %ebx, %es:(%edi) )
20580 lea 4(%esi), %esi
20581 lea 4(%edi), %edi
20582 dec %edx
20583 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
20584 jb 5f
20585 SRC( movw (%esi), %cx )
20586 leal 2(%esi), %esi
20587 -DST( movw %cx, (%edi) )
20588 +DST( movw %cx, %es:(%edi) )
20589 leal 2(%edi), %edi
20590 je 6f
20591 shll $16,%ecx
20592 SRC(5: movb (%esi), %cl )
20593 -DST( movb %cl, (%edi) )
20594 +DST( movb %cl, %es:(%edi) )
20595 6: addl %ecx, %eax
20596 adcl $0, %eax
20597 7:
20598 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
20599
20600 6001:
20601 movl ARGBASE+20(%esp), %ebx # src_err_ptr
20602 - movl $-EFAULT, (%ebx)
20603 + movl $-EFAULT, %ss:(%ebx)
20604
20605 # zero the complete destination - computing the rest
20606 # is too much work
20607 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
20608
20609 6002:
20610 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20611 - movl $-EFAULT,(%ebx)
20612 + movl $-EFAULT,%ss:(%ebx)
20613 jmp 5000b
20614
20615 .previous
20616
20617 + pushl_cfi %ss
20618 + popl_cfi %ds
20619 + pushl_cfi %ss
20620 + popl_cfi %es
20621 popl_cfi %ebx
20622 CFI_RESTORE ebx
20623 popl_cfi %esi
20624 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
20625 popl_cfi %ecx # equivalent to addl $4,%esp
20626 ret
20627 CFI_ENDPROC
20628 -ENDPROC(csum_partial_copy_generic)
20629 +ENDPROC(csum_partial_copy_generic_to_user)
20630
20631 #else
20632
20633 /* Version for PentiumII/PPro */
20634
20635 #define ROUND1(x) \
20636 + nop; nop; nop; \
20637 SRC(movl x(%esi), %ebx ) ; \
20638 addl %ebx, %eax ; \
20639 - DST(movl %ebx, x(%edi) ) ;
20640 + DST(movl %ebx, %es:x(%edi)) ;
20641
20642 #define ROUND(x) \
20643 + nop; nop; nop; \
20644 SRC(movl x(%esi), %ebx ) ; \
20645 adcl %ebx, %eax ; \
20646 - DST(movl %ebx, x(%edi) ) ;
20647 + DST(movl %ebx, %es:x(%edi)) ;
20648
20649 #define ARGBASE 12
20650 -
20651 -ENTRY(csum_partial_copy_generic)
20652 +
20653 +ENTRY(csum_partial_copy_generic_to_user)
20654 CFI_STARTPROC
20655 +
20656 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20657 + pushl_cfi %gs
20658 + popl_cfi %es
20659 + jmp csum_partial_copy_generic
20660 +#endif
20661 +
20662 +ENTRY(csum_partial_copy_generic_from_user)
20663 +
20664 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20665 + pushl_cfi %gs
20666 + popl_cfi %ds
20667 +#endif
20668 +
20669 +ENTRY(csum_partial_copy_generic)
20670 pushl_cfi %ebx
20671 CFI_REL_OFFSET ebx, 0
20672 pushl_cfi %edi
20673 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
20674 subl %ebx, %edi
20675 lea -1(%esi),%edx
20676 andl $-32,%edx
20677 - lea 3f(%ebx,%ebx), %ebx
20678 + lea 3f(%ebx,%ebx,2), %ebx
20679 testl %esi, %esi
20680 jmp *%ebx
20681 1: addl $64,%esi
20682 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
20683 jb 5f
20684 SRC( movw (%esi), %dx )
20685 leal 2(%esi), %esi
20686 -DST( movw %dx, (%edi) )
20687 +DST( movw %dx, %es:(%edi) )
20688 leal 2(%edi), %edi
20689 je 6f
20690 shll $16,%edx
20691 5:
20692 SRC( movb (%esi), %dl )
20693 -DST( movb %dl, (%edi) )
20694 +DST( movb %dl, %es:(%edi) )
20695 6: addl %edx, %eax
20696 adcl $0, %eax
20697 7:
20698 .section .fixup, "ax"
20699 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
20700 - movl $-EFAULT, (%ebx)
20701 + movl $-EFAULT, %ss:(%ebx)
20702 # zero the complete destination (computing the rest is too much work)
20703 movl ARGBASE+8(%esp),%edi # dst
20704 movl ARGBASE+12(%esp),%ecx # len
20705 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
20706 rep; stosb
20707 jmp 7b
20708 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20709 - movl $-EFAULT, (%ebx)
20710 + movl $-EFAULT, %ss:(%ebx)
20711 jmp 7b
20712 .previous
20713
20714 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20715 + pushl_cfi %ss
20716 + popl_cfi %ds
20717 + pushl_cfi %ss
20718 + popl_cfi %es
20719 +#endif
20720 +
20721 popl_cfi %esi
20722 CFI_RESTORE esi
20723 popl_cfi %edi
20724 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
20725 CFI_RESTORE ebx
20726 ret
20727 CFI_ENDPROC
20728 -ENDPROC(csum_partial_copy_generic)
20729 +ENDPROC(csum_partial_copy_generic_to_user)
20730
20731 #undef ROUND
20732 #undef ROUND1
20733 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
20734 index f2145cf..cea889d 100644
20735 --- a/arch/x86/lib/clear_page_64.S
20736 +++ b/arch/x86/lib/clear_page_64.S
20737 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
20738 movl $4096/8,%ecx
20739 xorl %eax,%eax
20740 rep stosq
20741 + pax_force_retaddr
20742 ret
20743 CFI_ENDPROC
20744 ENDPROC(clear_page_c)
20745 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
20746 movl $4096,%ecx
20747 xorl %eax,%eax
20748 rep stosb
20749 + pax_force_retaddr
20750 ret
20751 CFI_ENDPROC
20752 ENDPROC(clear_page_c_e)
20753 @@ -43,6 +45,7 @@ ENTRY(clear_page)
20754 leaq 64(%rdi),%rdi
20755 jnz .Lloop
20756 nop
20757 + pax_force_retaddr
20758 ret
20759 CFI_ENDPROC
20760 .Lclear_page_end:
20761 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
20762
20763 #include <asm/cpufeature.h>
20764
20765 - .section .altinstr_replacement,"ax"
20766 + .section .altinstr_replacement,"a"
20767 1: .byte 0xeb /* jmp <disp8> */
20768 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
20769 2: .byte 0xeb /* jmp <disp8> */
20770 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
20771 index 1e572c5..2a162cd 100644
20772 --- a/arch/x86/lib/cmpxchg16b_emu.S
20773 +++ b/arch/x86/lib/cmpxchg16b_emu.S
20774 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
20775
20776 popf
20777 mov $1, %al
20778 + pax_force_retaddr
20779 ret
20780
20781 not_same:
20782 popf
20783 xor %al,%al
20784 + pax_force_retaddr
20785 ret
20786
20787 CFI_ENDPROC
20788 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
20789 index 01c805b..dccb07f 100644
20790 --- a/arch/x86/lib/copy_page_64.S
20791 +++ b/arch/x86/lib/copy_page_64.S
20792 @@ -9,6 +9,7 @@ copy_page_c:
20793 CFI_STARTPROC
20794 movl $4096/8,%ecx
20795 rep movsq
20796 + pax_force_retaddr
20797 ret
20798 CFI_ENDPROC
20799 ENDPROC(copy_page_c)
20800 @@ -39,7 +40,7 @@ ENTRY(copy_page)
20801 movq 16 (%rsi), %rdx
20802 movq 24 (%rsi), %r8
20803 movq 32 (%rsi), %r9
20804 - movq 40 (%rsi), %r10
20805 + movq 40 (%rsi), %r13
20806 movq 48 (%rsi), %r11
20807 movq 56 (%rsi), %r12
20808
20809 @@ -50,7 +51,7 @@ ENTRY(copy_page)
20810 movq %rdx, 16 (%rdi)
20811 movq %r8, 24 (%rdi)
20812 movq %r9, 32 (%rdi)
20813 - movq %r10, 40 (%rdi)
20814 + movq %r13, 40 (%rdi)
20815 movq %r11, 48 (%rdi)
20816 movq %r12, 56 (%rdi)
20817
20818 @@ -69,7 +70,7 @@ ENTRY(copy_page)
20819 movq 16 (%rsi), %rdx
20820 movq 24 (%rsi), %r8
20821 movq 32 (%rsi), %r9
20822 - movq 40 (%rsi), %r10
20823 + movq 40 (%rsi), %r13
20824 movq 48 (%rsi), %r11
20825 movq 56 (%rsi), %r12
20826
20827 @@ -78,7 +79,7 @@ ENTRY(copy_page)
20828 movq %rdx, 16 (%rdi)
20829 movq %r8, 24 (%rdi)
20830 movq %r9, 32 (%rdi)
20831 - movq %r10, 40 (%rdi)
20832 + movq %r13, 40 (%rdi)
20833 movq %r11, 48 (%rdi)
20834 movq %r12, 56 (%rdi)
20835
20836 @@ -95,6 +96,7 @@ ENTRY(copy_page)
20837 CFI_RESTORE r13
20838 addq $3*8,%rsp
20839 CFI_ADJUST_CFA_OFFSET -3*8
20840 + pax_force_retaddr
20841 ret
20842 .Lcopy_page_end:
20843 CFI_ENDPROC
20844 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
20845
20846 #include <asm/cpufeature.h>
20847
20848 - .section .altinstr_replacement,"ax"
20849 + .section .altinstr_replacement,"a"
20850 1: .byte 0xeb /* jmp <disp8> */
20851 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
20852 2:
20853 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
20854 index 0248402..821c786 100644
20855 --- a/arch/x86/lib/copy_user_64.S
20856 +++ b/arch/x86/lib/copy_user_64.S
20857 @@ -16,6 +16,7 @@
20858 #include <asm/thread_info.h>
20859 #include <asm/cpufeature.h>
20860 #include <asm/alternative-asm.h>
20861 +#include <asm/pgtable.h>
20862
20863 /*
20864 * By placing feature2 after feature1 in altinstructions section, we logically
20865 @@ -29,7 +30,7 @@
20866 .byte 0xe9 /* 32bit jump */
20867 .long \orig-1f /* by default jump to orig */
20868 1:
20869 - .section .altinstr_replacement,"ax"
20870 + .section .altinstr_replacement,"a"
20871 2: .byte 0xe9 /* near jump with 32bit immediate */
20872 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
20873 3: .byte 0xe9 /* near jump with 32bit immediate */
20874 @@ -71,47 +72,20 @@
20875 #endif
20876 .endm
20877
20878 -/* Standard copy_to_user with segment limit checking */
20879 -ENTRY(_copy_to_user)
20880 - CFI_STARTPROC
20881 - GET_THREAD_INFO(%rax)
20882 - movq %rdi,%rcx
20883 - addq %rdx,%rcx
20884 - jc bad_to_user
20885 - cmpq TI_addr_limit(%rax),%rcx
20886 - ja bad_to_user
20887 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
20888 - copy_user_generic_unrolled,copy_user_generic_string, \
20889 - copy_user_enhanced_fast_string
20890 - CFI_ENDPROC
20891 -ENDPROC(_copy_to_user)
20892 -
20893 -/* Standard copy_from_user with segment limit checking */
20894 -ENTRY(_copy_from_user)
20895 - CFI_STARTPROC
20896 - GET_THREAD_INFO(%rax)
20897 - movq %rsi,%rcx
20898 - addq %rdx,%rcx
20899 - jc bad_from_user
20900 - cmpq TI_addr_limit(%rax),%rcx
20901 - ja bad_from_user
20902 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
20903 - copy_user_generic_unrolled,copy_user_generic_string, \
20904 - copy_user_enhanced_fast_string
20905 - CFI_ENDPROC
20906 -ENDPROC(_copy_from_user)
20907 -
20908 .section .fixup,"ax"
20909 /* must zero dest */
20910 ENTRY(bad_from_user)
20911 bad_from_user:
20912 CFI_STARTPROC
20913 + testl %edx,%edx
20914 + js bad_to_user
20915 movl %edx,%ecx
20916 xorl %eax,%eax
20917 rep
20918 stosb
20919 bad_to_user:
20920 movl %edx,%eax
20921 + pax_force_retaddr
20922 ret
20923 CFI_ENDPROC
20924 ENDPROC(bad_from_user)
20925 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
20926 jz 17f
20927 1: movq (%rsi),%r8
20928 2: movq 1*8(%rsi),%r9
20929 -3: movq 2*8(%rsi),%r10
20930 +3: movq 2*8(%rsi),%rax
20931 4: movq 3*8(%rsi),%r11
20932 5: movq %r8,(%rdi)
20933 6: movq %r9,1*8(%rdi)
20934 -7: movq %r10,2*8(%rdi)
20935 +7: movq %rax,2*8(%rdi)
20936 8: movq %r11,3*8(%rdi)
20937 9: movq 4*8(%rsi),%r8
20938 10: movq 5*8(%rsi),%r9
20939 -11: movq 6*8(%rsi),%r10
20940 +11: movq 6*8(%rsi),%rax
20941 12: movq 7*8(%rsi),%r11
20942 13: movq %r8,4*8(%rdi)
20943 14: movq %r9,5*8(%rdi)
20944 -15: movq %r10,6*8(%rdi)
20945 +15: movq %rax,6*8(%rdi)
20946 16: movq %r11,7*8(%rdi)
20947 leaq 64(%rsi),%rsi
20948 leaq 64(%rdi),%rdi
20949 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
20950 decl %ecx
20951 jnz 21b
20952 23: xor %eax,%eax
20953 + pax_force_retaddr
20954 ret
20955
20956 .section .fixup,"ax"
20957 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
20958 3: rep
20959 movsb
20960 4: xorl %eax,%eax
20961 + pax_force_retaddr
20962 ret
20963
20964 .section .fixup,"ax"
20965 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
20966 1: rep
20967 movsb
20968 2: xorl %eax,%eax
20969 + pax_force_retaddr
20970 ret
20971
20972 .section .fixup,"ax"
20973 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
20974 index cb0c112..e3a6895 100644
20975 --- a/arch/x86/lib/copy_user_nocache_64.S
20976 +++ b/arch/x86/lib/copy_user_nocache_64.S
20977 @@ -8,12 +8,14 @@
20978
20979 #include <linux/linkage.h>
20980 #include <asm/dwarf2.h>
20981 +#include <asm/alternative-asm.h>
20982
20983 #define FIX_ALIGNMENT 1
20984
20985 #include <asm/current.h>
20986 #include <asm/asm-offsets.h>
20987 #include <asm/thread_info.h>
20988 +#include <asm/pgtable.h>
20989
20990 .macro ALIGN_DESTINATION
20991 #ifdef FIX_ALIGNMENT
20992 @@ -50,6 +52,15 @@
20993 */
20994 ENTRY(__copy_user_nocache)
20995 CFI_STARTPROC
20996 +
20997 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20998 + mov $PAX_USER_SHADOW_BASE,%rcx
20999 + cmp %rcx,%rsi
21000 + jae 1f
21001 + add %rcx,%rsi
21002 +1:
21003 +#endif
21004 +
21005 cmpl $8,%edx
21006 jb 20f /* less then 8 bytes, go to byte copy loop */
21007 ALIGN_DESTINATION
21008 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21009 jz 17f
21010 1: movq (%rsi),%r8
21011 2: movq 1*8(%rsi),%r9
21012 -3: movq 2*8(%rsi),%r10
21013 +3: movq 2*8(%rsi),%rax
21014 4: movq 3*8(%rsi),%r11
21015 5: movnti %r8,(%rdi)
21016 6: movnti %r9,1*8(%rdi)
21017 -7: movnti %r10,2*8(%rdi)
21018 +7: movnti %rax,2*8(%rdi)
21019 8: movnti %r11,3*8(%rdi)
21020 9: movq 4*8(%rsi),%r8
21021 10: movq 5*8(%rsi),%r9
21022 -11: movq 6*8(%rsi),%r10
21023 +11: movq 6*8(%rsi),%rax
21024 12: movq 7*8(%rsi),%r11
21025 13: movnti %r8,4*8(%rdi)
21026 14: movnti %r9,5*8(%rdi)
21027 -15: movnti %r10,6*8(%rdi)
21028 +15: movnti %rax,6*8(%rdi)
21029 16: movnti %r11,7*8(%rdi)
21030 leaq 64(%rsi),%rsi
21031 leaq 64(%rdi),%rdi
21032 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21033 jnz 21b
21034 23: xorl %eax,%eax
21035 sfence
21036 + pax_force_retaddr
21037 ret
21038
21039 .section .fixup,"ax"
21040 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21041 index fb903b7..c92b7f7 100644
21042 --- a/arch/x86/lib/csum-copy_64.S
21043 +++ b/arch/x86/lib/csum-copy_64.S
21044 @@ -8,6 +8,7 @@
21045 #include <linux/linkage.h>
21046 #include <asm/dwarf2.h>
21047 #include <asm/errno.h>
21048 +#include <asm/alternative-asm.h>
21049
21050 /*
21051 * Checksum copy with exception handling.
21052 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21053 CFI_RESTORE rbp
21054 addq $7*8, %rsp
21055 CFI_ADJUST_CFA_OFFSET -7*8
21056 + pax_force_retaddr 0, 1
21057 ret
21058 CFI_RESTORE_STATE
21059
21060 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21061 index 459b58a..9570bc7 100644
21062 --- a/arch/x86/lib/csum-wrappers_64.c
21063 +++ b/arch/x86/lib/csum-wrappers_64.c
21064 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21065 len -= 2;
21066 }
21067 }
21068 - isum = csum_partial_copy_generic((__force const void *)src,
21069 +
21070 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21071 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21072 + src += PAX_USER_SHADOW_BASE;
21073 +#endif
21074 +
21075 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21076 dst, len, isum, errp, NULL);
21077 if (unlikely(*errp))
21078 goto out_err;
21079 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21080 }
21081
21082 *errp = 0;
21083 - return csum_partial_copy_generic(src, (void __force *)dst,
21084 +
21085 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21086 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21087 + dst += PAX_USER_SHADOW_BASE;
21088 +#endif
21089 +
21090 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21091 len, isum, NULL, errp);
21092 }
21093 EXPORT_SYMBOL(csum_partial_copy_to_user);
21094 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21095 index 51f1504..ddac4c1 100644
21096 --- a/arch/x86/lib/getuser.S
21097 +++ b/arch/x86/lib/getuser.S
21098 @@ -33,15 +33,38 @@
21099 #include <asm/asm-offsets.h>
21100 #include <asm/thread_info.h>
21101 #include <asm/asm.h>
21102 +#include <asm/segment.h>
21103 +#include <asm/pgtable.h>
21104 +#include <asm/alternative-asm.h>
21105 +
21106 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21107 +#define __copyuser_seg gs;
21108 +#else
21109 +#define __copyuser_seg
21110 +#endif
21111
21112 .text
21113 ENTRY(__get_user_1)
21114 CFI_STARTPROC
21115 +
21116 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21117 GET_THREAD_INFO(%_ASM_DX)
21118 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21119 jae bad_get_user
21120 -1: movzb (%_ASM_AX),%edx
21121 +
21122 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21123 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21124 + cmp %_ASM_DX,%_ASM_AX
21125 + jae 1234f
21126 + add %_ASM_DX,%_ASM_AX
21127 +1234:
21128 +#endif
21129 +
21130 +#endif
21131 +
21132 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21133 xor %eax,%eax
21134 + pax_force_retaddr
21135 ret
21136 CFI_ENDPROC
21137 ENDPROC(__get_user_1)
21138 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21139 ENTRY(__get_user_2)
21140 CFI_STARTPROC
21141 add $1,%_ASM_AX
21142 +
21143 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21144 jc bad_get_user
21145 GET_THREAD_INFO(%_ASM_DX)
21146 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21147 jae bad_get_user
21148 -2: movzwl -1(%_ASM_AX),%edx
21149 +
21150 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21151 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21152 + cmp %_ASM_DX,%_ASM_AX
21153 + jae 1234f
21154 + add %_ASM_DX,%_ASM_AX
21155 +1234:
21156 +#endif
21157 +
21158 +#endif
21159 +
21160 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21161 xor %eax,%eax
21162 + pax_force_retaddr
21163 ret
21164 CFI_ENDPROC
21165 ENDPROC(__get_user_2)
21166 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21167 ENTRY(__get_user_4)
21168 CFI_STARTPROC
21169 add $3,%_ASM_AX
21170 +
21171 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21172 jc bad_get_user
21173 GET_THREAD_INFO(%_ASM_DX)
21174 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21175 jae bad_get_user
21176 -3: mov -3(%_ASM_AX),%edx
21177 +
21178 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21179 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21180 + cmp %_ASM_DX,%_ASM_AX
21181 + jae 1234f
21182 + add %_ASM_DX,%_ASM_AX
21183 +1234:
21184 +#endif
21185 +
21186 +#endif
21187 +
21188 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21189 xor %eax,%eax
21190 + pax_force_retaddr
21191 ret
21192 CFI_ENDPROC
21193 ENDPROC(__get_user_4)
21194 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21195 GET_THREAD_INFO(%_ASM_DX)
21196 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21197 jae bad_get_user
21198 +
21199 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21200 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21201 + cmp %_ASM_DX,%_ASM_AX
21202 + jae 1234f
21203 + add %_ASM_DX,%_ASM_AX
21204 +1234:
21205 +#endif
21206 +
21207 4: movq -7(%_ASM_AX),%_ASM_DX
21208 xor %eax,%eax
21209 + pax_force_retaddr
21210 ret
21211 CFI_ENDPROC
21212 ENDPROC(__get_user_8)
21213 @@ -91,6 +152,7 @@ bad_get_user:
21214 CFI_STARTPROC
21215 xor %edx,%edx
21216 mov $(-EFAULT),%_ASM_AX
21217 + pax_force_retaddr
21218 ret
21219 CFI_ENDPROC
21220 END(bad_get_user)
21221 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21222 index 5a1f9f3..ba9f577 100644
21223 --- a/arch/x86/lib/insn.c
21224 +++ b/arch/x86/lib/insn.c
21225 @@ -21,6 +21,11 @@
21226 #include <linux/string.h>
21227 #include <asm/inat.h>
21228 #include <asm/insn.h>
21229 +#ifdef __KERNEL__
21230 +#include <asm/pgtable_types.h>
21231 +#else
21232 +#define ktla_ktva(addr) addr
21233 +#endif
21234
21235 /* Verify next sizeof(t) bytes can be on the same instruction */
21236 #define validate_next(t, insn, n) \
21237 @@ -49,8 +54,8 @@
21238 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21239 {
21240 memset(insn, 0, sizeof(*insn));
21241 - insn->kaddr = kaddr;
21242 - insn->next_byte = kaddr;
21243 + insn->kaddr = ktla_ktva(kaddr);
21244 + insn->next_byte = ktla_ktva(kaddr);
21245 insn->x86_64 = x86_64 ? 1 : 0;
21246 insn->opnd_bytes = 4;
21247 if (x86_64)
21248 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21249 index 05a95e7..326f2fa 100644
21250 --- a/arch/x86/lib/iomap_copy_64.S
21251 +++ b/arch/x86/lib/iomap_copy_64.S
21252 @@ -17,6 +17,7 @@
21253
21254 #include <linux/linkage.h>
21255 #include <asm/dwarf2.h>
21256 +#include <asm/alternative-asm.h>
21257
21258 /*
21259 * override generic version in lib/iomap_copy.c
21260 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21261 CFI_STARTPROC
21262 movl %edx,%ecx
21263 rep movsd
21264 + pax_force_retaddr
21265 ret
21266 CFI_ENDPROC
21267 ENDPROC(__iowrite32_copy)
21268 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21269 index efbf2a0..8893637 100644
21270 --- a/arch/x86/lib/memcpy_64.S
21271 +++ b/arch/x86/lib/memcpy_64.S
21272 @@ -34,6 +34,7 @@
21273 rep movsq
21274 movl %edx, %ecx
21275 rep movsb
21276 + pax_force_retaddr
21277 ret
21278 .Lmemcpy_e:
21279 .previous
21280 @@ -51,6 +52,7 @@
21281
21282 movl %edx, %ecx
21283 rep movsb
21284 + pax_force_retaddr
21285 ret
21286 .Lmemcpy_e_e:
21287 .previous
21288 @@ -81,13 +83,13 @@ ENTRY(memcpy)
21289 */
21290 movq 0*8(%rsi), %r8
21291 movq 1*8(%rsi), %r9
21292 - movq 2*8(%rsi), %r10
21293 + movq 2*8(%rsi), %rcx
21294 movq 3*8(%rsi), %r11
21295 leaq 4*8(%rsi), %rsi
21296
21297 movq %r8, 0*8(%rdi)
21298 movq %r9, 1*8(%rdi)
21299 - movq %r10, 2*8(%rdi)
21300 + movq %rcx, 2*8(%rdi)
21301 movq %r11, 3*8(%rdi)
21302 leaq 4*8(%rdi), %rdi
21303 jae .Lcopy_forward_loop
21304 @@ -110,12 +112,12 @@ ENTRY(memcpy)
21305 subq $0x20, %rdx
21306 movq -1*8(%rsi), %r8
21307 movq -2*8(%rsi), %r9
21308 - movq -3*8(%rsi), %r10
21309 + movq -3*8(%rsi), %rcx
21310 movq -4*8(%rsi), %r11
21311 leaq -4*8(%rsi), %rsi
21312 movq %r8, -1*8(%rdi)
21313 movq %r9, -2*8(%rdi)
21314 - movq %r10, -3*8(%rdi)
21315 + movq %rcx, -3*8(%rdi)
21316 movq %r11, -4*8(%rdi)
21317 leaq -4*8(%rdi), %rdi
21318 jae .Lcopy_backward_loop
21319 @@ -135,12 +137,13 @@ ENTRY(memcpy)
21320 */
21321 movq 0*8(%rsi), %r8
21322 movq 1*8(%rsi), %r9
21323 - movq -2*8(%rsi, %rdx), %r10
21324 + movq -2*8(%rsi, %rdx), %rcx
21325 movq -1*8(%rsi, %rdx), %r11
21326 movq %r8, 0*8(%rdi)
21327 movq %r9, 1*8(%rdi)
21328 - movq %r10, -2*8(%rdi, %rdx)
21329 + movq %rcx, -2*8(%rdi, %rdx)
21330 movq %r11, -1*8(%rdi, %rdx)
21331 + pax_force_retaddr
21332 retq
21333 .p2align 4
21334 .Lless_16bytes:
21335 @@ -153,6 +156,7 @@ ENTRY(memcpy)
21336 movq -1*8(%rsi, %rdx), %r9
21337 movq %r8, 0*8(%rdi)
21338 movq %r9, -1*8(%rdi, %rdx)
21339 + pax_force_retaddr
21340 retq
21341 .p2align 4
21342 .Lless_8bytes:
21343 @@ -166,6 +170,7 @@ ENTRY(memcpy)
21344 movl -4(%rsi, %rdx), %r8d
21345 movl %ecx, (%rdi)
21346 movl %r8d, -4(%rdi, %rdx)
21347 + pax_force_retaddr
21348 retq
21349 .p2align 4
21350 .Lless_3bytes:
21351 @@ -183,6 +188,7 @@ ENTRY(memcpy)
21352 jnz .Lloop_1
21353
21354 .Lend:
21355 + pax_force_retaddr
21356 retq
21357 CFI_ENDPROC
21358 ENDPROC(memcpy)
21359 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21360 index ee16461..c39c199 100644
21361 --- a/arch/x86/lib/memmove_64.S
21362 +++ b/arch/x86/lib/memmove_64.S
21363 @@ -61,13 +61,13 @@ ENTRY(memmove)
21364 5:
21365 sub $0x20, %rdx
21366 movq 0*8(%rsi), %r11
21367 - movq 1*8(%rsi), %r10
21368 + movq 1*8(%rsi), %rcx
21369 movq 2*8(%rsi), %r9
21370 movq 3*8(%rsi), %r8
21371 leaq 4*8(%rsi), %rsi
21372
21373 movq %r11, 0*8(%rdi)
21374 - movq %r10, 1*8(%rdi)
21375 + movq %rcx, 1*8(%rdi)
21376 movq %r9, 2*8(%rdi)
21377 movq %r8, 3*8(%rdi)
21378 leaq 4*8(%rdi), %rdi
21379 @@ -81,10 +81,10 @@ ENTRY(memmove)
21380 4:
21381 movq %rdx, %rcx
21382 movq -8(%rsi, %rdx), %r11
21383 - lea -8(%rdi, %rdx), %r10
21384 + lea -8(%rdi, %rdx), %r9
21385 shrq $3, %rcx
21386 rep movsq
21387 - movq %r11, (%r10)
21388 + movq %r11, (%r9)
21389 jmp 13f
21390 .Lmemmove_end_forward:
21391
21392 @@ -95,14 +95,14 @@ ENTRY(memmove)
21393 7:
21394 movq %rdx, %rcx
21395 movq (%rsi), %r11
21396 - movq %rdi, %r10
21397 + movq %rdi, %r9
21398 leaq -8(%rsi, %rdx), %rsi
21399 leaq -8(%rdi, %rdx), %rdi
21400 shrq $3, %rcx
21401 std
21402 rep movsq
21403 cld
21404 - movq %r11, (%r10)
21405 + movq %r11, (%r9)
21406 jmp 13f
21407
21408 /*
21409 @@ -127,13 +127,13 @@ ENTRY(memmove)
21410 8:
21411 subq $0x20, %rdx
21412 movq -1*8(%rsi), %r11
21413 - movq -2*8(%rsi), %r10
21414 + movq -2*8(%rsi), %rcx
21415 movq -3*8(%rsi), %r9
21416 movq -4*8(%rsi), %r8
21417 leaq -4*8(%rsi), %rsi
21418
21419 movq %r11, -1*8(%rdi)
21420 - movq %r10, -2*8(%rdi)
21421 + movq %rcx, -2*8(%rdi)
21422 movq %r9, -3*8(%rdi)
21423 movq %r8, -4*8(%rdi)
21424 leaq -4*8(%rdi), %rdi
21425 @@ -151,11 +151,11 @@ ENTRY(memmove)
21426 * Move data from 16 bytes to 31 bytes.
21427 */
21428 movq 0*8(%rsi), %r11
21429 - movq 1*8(%rsi), %r10
21430 + movq 1*8(%rsi), %rcx
21431 movq -2*8(%rsi, %rdx), %r9
21432 movq -1*8(%rsi, %rdx), %r8
21433 movq %r11, 0*8(%rdi)
21434 - movq %r10, 1*8(%rdi)
21435 + movq %rcx, 1*8(%rdi)
21436 movq %r9, -2*8(%rdi, %rdx)
21437 movq %r8, -1*8(%rdi, %rdx)
21438 jmp 13f
21439 @@ -167,9 +167,9 @@ ENTRY(memmove)
21440 * Move data from 8 bytes to 15 bytes.
21441 */
21442 movq 0*8(%rsi), %r11
21443 - movq -1*8(%rsi, %rdx), %r10
21444 + movq -1*8(%rsi, %rdx), %r9
21445 movq %r11, 0*8(%rdi)
21446 - movq %r10, -1*8(%rdi, %rdx)
21447 + movq %r9, -1*8(%rdi, %rdx)
21448 jmp 13f
21449 10:
21450 cmpq $4, %rdx
21451 @@ -178,9 +178,9 @@ ENTRY(memmove)
21452 * Move data from 4 bytes to 7 bytes.
21453 */
21454 movl (%rsi), %r11d
21455 - movl -4(%rsi, %rdx), %r10d
21456 + movl -4(%rsi, %rdx), %r9d
21457 movl %r11d, (%rdi)
21458 - movl %r10d, -4(%rdi, %rdx)
21459 + movl %r9d, -4(%rdi, %rdx)
21460 jmp 13f
21461 11:
21462 cmp $2, %rdx
21463 @@ -189,9 +189,9 @@ ENTRY(memmove)
21464 * Move data from 2 bytes to 3 bytes.
21465 */
21466 movw (%rsi), %r11w
21467 - movw -2(%rsi, %rdx), %r10w
21468 + movw -2(%rsi, %rdx), %r9w
21469 movw %r11w, (%rdi)
21470 - movw %r10w, -2(%rdi, %rdx)
21471 + movw %r9w, -2(%rdi, %rdx)
21472 jmp 13f
21473 12:
21474 cmp $1, %rdx
21475 @@ -202,6 +202,7 @@ ENTRY(memmove)
21476 movb (%rsi), %r11b
21477 movb %r11b, (%rdi)
21478 13:
21479 + pax_force_retaddr
21480 retq
21481 CFI_ENDPROC
21482
21483 @@ -210,6 +211,7 @@ ENTRY(memmove)
21484 /* Forward moving data. */
21485 movq %rdx, %rcx
21486 rep movsb
21487 + pax_force_retaddr
21488 retq
21489 .Lmemmove_end_forward_efs:
21490 .previous
21491 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21492 index 79bd454..dff325a 100644
21493 --- a/arch/x86/lib/memset_64.S
21494 +++ b/arch/x86/lib/memset_64.S
21495 @@ -31,6 +31,7 @@
21496 movl %r8d,%ecx
21497 rep stosb
21498 movq %r9,%rax
21499 + pax_force_retaddr
21500 ret
21501 .Lmemset_e:
21502 .previous
21503 @@ -53,6 +54,7 @@
21504 movl %edx,%ecx
21505 rep stosb
21506 movq %r9,%rax
21507 + pax_force_retaddr
21508 ret
21509 .Lmemset_e_e:
21510 .previous
21511 @@ -60,13 +62,13 @@
21512 ENTRY(memset)
21513 ENTRY(__memset)
21514 CFI_STARTPROC
21515 - movq %rdi,%r10
21516 movq %rdx,%r11
21517
21518 /* expand byte value */
21519 movzbl %sil,%ecx
21520 movabs $0x0101010101010101,%rax
21521 mul %rcx /* with rax, clobbers rdx */
21522 + movq %rdi,%rdx
21523
21524 /* align dst */
21525 movl %edi,%r9d
21526 @@ -120,7 +122,8 @@ ENTRY(__memset)
21527 jnz .Lloop_1
21528
21529 .Lende:
21530 - movq %r10,%rax
21531 + movq %rdx,%rax
21532 + pax_force_retaddr
21533 ret
21534
21535 CFI_RESTORE_STATE
21536 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21537 index c9f2d9b..e7fd2c0 100644
21538 --- a/arch/x86/lib/mmx_32.c
21539 +++ b/arch/x86/lib/mmx_32.c
21540 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21541 {
21542 void *p;
21543 int i;
21544 + unsigned long cr0;
21545
21546 if (unlikely(in_interrupt()))
21547 return __memcpy(to, from, len);
21548 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21549 kernel_fpu_begin();
21550
21551 __asm__ __volatile__ (
21552 - "1: prefetch (%0)\n" /* This set is 28 bytes */
21553 - " prefetch 64(%0)\n"
21554 - " prefetch 128(%0)\n"
21555 - " prefetch 192(%0)\n"
21556 - " prefetch 256(%0)\n"
21557 + "1: prefetch (%1)\n" /* This set is 28 bytes */
21558 + " prefetch 64(%1)\n"
21559 + " prefetch 128(%1)\n"
21560 + " prefetch 192(%1)\n"
21561 + " prefetch 256(%1)\n"
21562 "2: \n"
21563 ".section .fixup, \"ax\"\n"
21564 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21565 + "3: \n"
21566 +
21567 +#ifdef CONFIG_PAX_KERNEXEC
21568 + " movl %%cr0, %0\n"
21569 + " movl %0, %%eax\n"
21570 + " andl $0xFFFEFFFF, %%eax\n"
21571 + " movl %%eax, %%cr0\n"
21572 +#endif
21573 +
21574 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21575 +
21576 +#ifdef CONFIG_PAX_KERNEXEC
21577 + " movl %0, %%cr0\n"
21578 +#endif
21579 +
21580 " jmp 2b\n"
21581 ".previous\n"
21582 _ASM_EXTABLE(1b, 3b)
21583 - : : "r" (from));
21584 + : "=&r" (cr0) : "r" (from) : "ax");
21585
21586 for ( ; i > 5; i--) {
21587 __asm__ __volatile__ (
21588 - "1: prefetch 320(%0)\n"
21589 - "2: movq (%0), %%mm0\n"
21590 - " movq 8(%0), %%mm1\n"
21591 - " movq 16(%0), %%mm2\n"
21592 - " movq 24(%0), %%mm3\n"
21593 - " movq %%mm0, (%1)\n"
21594 - " movq %%mm1, 8(%1)\n"
21595 - " movq %%mm2, 16(%1)\n"
21596 - " movq %%mm3, 24(%1)\n"
21597 - " movq 32(%0), %%mm0\n"
21598 - " movq 40(%0), %%mm1\n"
21599 - " movq 48(%0), %%mm2\n"
21600 - " movq 56(%0), %%mm3\n"
21601 - " movq %%mm0, 32(%1)\n"
21602 - " movq %%mm1, 40(%1)\n"
21603 - " movq %%mm2, 48(%1)\n"
21604 - " movq %%mm3, 56(%1)\n"
21605 + "1: prefetch 320(%1)\n"
21606 + "2: movq (%1), %%mm0\n"
21607 + " movq 8(%1), %%mm1\n"
21608 + " movq 16(%1), %%mm2\n"
21609 + " movq 24(%1), %%mm3\n"
21610 + " movq %%mm0, (%2)\n"
21611 + " movq %%mm1, 8(%2)\n"
21612 + " movq %%mm2, 16(%2)\n"
21613 + " movq %%mm3, 24(%2)\n"
21614 + " movq 32(%1), %%mm0\n"
21615 + " movq 40(%1), %%mm1\n"
21616 + " movq 48(%1), %%mm2\n"
21617 + " movq 56(%1), %%mm3\n"
21618 + " movq %%mm0, 32(%2)\n"
21619 + " movq %%mm1, 40(%2)\n"
21620 + " movq %%mm2, 48(%2)\n"
21621 + " movq %%mm3, 56(%2)\n"
21622 ".section .fixup, \"ax\"\n"
21623 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21624 + "3:\n"
21625 +
21626 +#ifdef CONFIG_PAX_KERNEXEC
21627 + " movl %%cr0, %0\n"
21628 + " movl %0, %%eax\n"
21629 + " andl $0xFFFEFFFF, %%eax\n"
21630 + " movl %%eax, %%cr0\n"
21631 +#endif
21632 +
21633 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21634 +
21635 +#ifdef CONFIG_PAX_KERNEXEC
21636 + " movl %0, %%cr0\n"
21637 +#endif
21638 +
21639 " jmp 2b\n"
21640 ".previous\n"
21641 _ASM_EXTABLE(1b, 3b)
21642 - : : "r" (from), "r" (to) : "memory");
21643 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21644
21645 from += 64;
21646 to += 64;
21647 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
21648 static void fast_copy_page(void *to, void *from)
21649 {
21650 int i;
21651 + unsigned long cr0;
21652
21653 kernel_fpu_begin();
21654
21655 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
21656 * but that is for later. -AV
21657 */
21658 __asm__ __volatile__(
21659 - "1: prefetch (%0)\n"
21660 - " prefetch 64(%0)\n"
21661 - " prefetch 128(%0)\n"
21662 - " prefetch 192(%0)\n"
21663 - " prefetch 256(%0)\n"
21664 + "1: prefetch (%1)\n"
21665 + " prefetch 64(%1)\n"
21666 + " prefetch 128(%1)\n"
21667 + " prefetch 192(%1)\n"
21668 + " prefetch 256(%1)\n"
21669 "2: \n"
21670 ".section .fixup, \"ax\"\n"
21671 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21672 + "3: \n"
21673 +
21674 +#ifdef CONFIG_PAX_KERNEXEC
21675 + " movl %%cr0, %0\n"
21676 + " movl %0, %%eax\n"
21677 + " andl $0xFFFEFFFF, %%eax\n"
21678 + " movl %%eax, %%cr0\n"
21679 +#endif
21680 +
21681 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21682 +
21683 +#ifdef CONFIG_PAX_KERNEXEC
21684 + " movl %0, %%cr0\n"
21685 +#endif
21686 +
21687 " jmp 2b\n"
21688 ".previous\n"
21689 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
21690 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
21691
21692 for (i = 0; i < (4096-320)/64; i++) {
21693 __asm__ __volatile__ (
21694 - "1: prefetch 320(%0)\n"
21695 - "2: movq (%0), %%mm0\n"
21696 - " movntq %%mm0, (%1)\n"
21697 - " movq 8(%0), %%mm1\n"
21698 - " movntq %%mm1, 8(%1)\n"
21699 - " movq 16(%0), %%mm2\n"
21700 - " movntq %%mm2, 16(%1)\n"
21701 - " movq 24(%0), %%mm3\n"
21702 - " movntq %%mm3, 24(%1)\n"
21703 - " movq 32(%0), %%mm4\n"
21704 - " movntq %%mm4, 32(%1)\n"
21705 - " movq 40(%0), %%mm5\n"
21706 - " movntq %%mm5, 40(%1)\n"
21707 - " movq 48(%0), %%mm6\n"
21708 - " movntq %%mm6, 48(%1)\n"
21709 - " movq 56(%0), %%mm7\n"
21710 - " movntq %%mm7, 56(%1)\n"
21711 + "1: prefetch 320(%1)\n"
21712 + "2: movq (%1), %%mm0\n"
21713 + " movntq %%mm0, (%2)\n"
21714 + " movq 8(%1), %%mm1\n"
21715 + " movntq %%mm1, 8(%2)\n"
21716 + " movq 16(%1), %%mm2\n"
21717 + " movntq %%mm2, 16(%2)\n"
21718 + " movq 24(%1), %%mm3\n"
21719 + " movntq %%mm3, 24(%2)\n"
21720 + " movq 32(%1), %%mm4\n"
21721 + " movntq %%mm4, 32(%2)\n"
21722 + " movq 40(%1), %%mm5\n"
21723 + " movntq %%mm5, 40(%2)\n"
21724 + " movq 48(%1), %%mm6\n"
21725 + " movntq %%mm6, 48(%2)\n"
21726 + " movq 56(%1), %%mm7\n"
21727 + " movntq %%mm7, 56(%2)\n"
21728 ".section .fixup, \"ax\"\n"
21729 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21730 + "3:\n"
21731 +
21732 +#ifdef CONFIG_PAX_KERNEXEC
21733 + " movl %%cr0, %0\n"
21734 + " movl %0, %%eax\n"
21735 + " andl $0xFFFEFFFF, %%eax\n"
21736 + " movl %%eax, %%cr0\n"
21737 +#endif
21738 +
21739 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21740 +
21741 +#ifdef CONFIG_PAX_KERNEXEC
21742 + " movl %0, %%cr0\n"
21743 +#endif
21744 +
21745 " jmp 2b\n"
21746 ".previous\n"
21747 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
21748 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21749
21750 from += 64;
21751 to += 64;
21752 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
21753 static void fast_copy_page(void *to, void *from)
21754 {
21755 int i;
21756 + unsigned long cr0;
21757
21758 kernel_fpu_begin();
21759
21760 __asm__ __volatile__ (
21761 - "1: prefetch (%0)\n"
21762 - " prefetch 64(%0)\n"
21763 - " prefetch 128(%0)\n"
21764 - " prefetch 192(%0)\n"
21765 - " prefetch 256(%0)\n"
21766 + "1: prefetch (%1)\n"
21767 + " prefetch 64(%1)\n"
21768 + " prefetch 128(%1)\n"
21769 + " prefetch 192(%1)\n"
21770 + " prefetch 256(%1)\n"
21771 "2: \n"
21772 ".section .fixup, \"ax\"\n"
21773 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21774 + "3: \n"
21775 +
21776 +#ifdef CONFIG_PAX_KERNEXEC
21777 + " movl %%cr0, %0\n"
21778 + " movl %0, %%eax\n"
21779 + " andl $0xFFFEFFFF, %%eax\n"
21780 + " movl %%eax, %%cr0\n"
21781 +#endif
21782 +
21783 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21784 +
21785 +#ifdef CONFIG_PAX_KERNEXEC
21786 + " movl %0, %%cr0\n"
21787 +#endif
21788 +
21789 " jmp 2b\n"
21790 ".previous\n"
21791 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
21792 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
21793
21794 for (i = 0; i < 4096/64; i++) {
21795 __asm__ __volatile__ (
21796 - "1: prefetch 320(%0)\n"
21797 - "2: movq (%0), %%mm0\n"
21798 - " movq 8(%0), %%mm1\n"
21799 - " movq 16(%0), %%mm2\n"
21800 - " movq 24(%0), %%mm3\n"
21801 - " movq %%mm0, (%1)\n"
21802 - " movq %%mm1, 8(%1)\n"
21803 - " movq %%mm2, 16(%1)\n"
21804 - " movq %%mm3, 24(%1)\n"
21805 - " movq 32(%0), %%mm0\n"
21806 - " movq 40(%0), %%mm1\n"
21807 - " movq 48(%0), %%mm2\n"
21808 - " movq 56(%0), %%mm3\n"
21809 - " movq %%mm0, 32(%1)\n"
21810 - " movq %%mm1, 40(%1)\n"
21811 - " movq %%mm2, 48(%1)\n"
21812 - " movq %%mm3, 56(%1)\n"
21813 + "1: prefetch 320(%1)\n"
21814 + "2: movq (%1), %%mm0\n"
21815 + " movq 8(%1), %%mm1\n"
21816 + " movq 16(%1), %%mm2\n"
21817 + " movq 24(%1), %%mm3\n"
21818 + " movq %%mm0, (%2)\n"
21819 + " movq %%mm1, 8(%2)\n"
21820 + " movq %%mm2, 16(%2)\n"
21821 + " movq %%mm3, 24(%2)\n"
21822 + " movq 32(%1), %%mm0\n"
21823 + " movq 40(%1), %%mm1\n"
21824 + " movq 48(%1), %%mm2\n"
21825 + " movq 56(%1), %%mm3\n"
21826 + " movq %%mm0, 32(%2)\n"
21827 + " movq %%mm1, 40(%2)\n"
21828 + " movq %%mm2, 48(%2)\n"
21829 + " movq %%mm3, 56(%2)\n"
21830 ".section .fixup, \"ax\"\n"
21831 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21832 + "3:\n"
21833 +
21834 +#ifdef CONFIG_PAX_KERNEXEC
21835 + " movl %%cr0, %0\n"
21836 + " movl %0, %%eax\n"
21837 + " andl $0xFFFEFFFF, %%eax\n"
21838 + " movl %%eax, %%cr0\n"
21839 +#endif
21840 +
21841 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21842 +
21843 +#ifdef CONFIG_PAX_KERNEXEC
21844 + " movl %0, %%cr0\n"
21845 +#endif
21846 +
21847 " jmp 2b\n"
21848 ".previous\n"
21849 _ASM_EXTABLE(1b, 3b)
21850 - : : "r" (from), "r" (to) : "memory");
21851 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21852
21853 from += 64;
21854 to += 64;
21855 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
21856 index 69fa106..adda88b 100644
21857 --- a/arch/x86/lib/msr-reg.S
21858 +++ b/arch/x86/lib/msr-reg.S
21859 @@ -3,6 +3,7 @@
21860 #include <asm/dwarf2.h>
21861 #include <asm/asm.h>
21862 #include <asm/msr.h>
21863 +#include <asm/alternative-asm.h>
21864
21865 #ifdef CONFIG_X86_64
21866 /*
21867 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
21868 CFI_STARTPROC
21869 pushq_cfi %rbx
21870 pushq_cfi %rbp
21871 - movq %rdi, %r10 /* Save pointer */
21872 + movq %rdi, %r9 /* Save pointer */
21873 xorl %r11d, %r11d /* Return value */
21874 movl (%rdi), %eax
21875 movl 4(%rdi), %ecx
21876 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
21877 movl 28(%rdi), %edi
21878 CFI_REMEMBER_STATE
21879 1: \op
21880 -2: movl %eax, (%r10)
21881 +2: movl %eax, (%r9)
21882 movl %r11d, %eax /* Return value */
21883 - movl %ecx, 4(%r10)
21884 - movl %edx, 8(%r10)
21885 - movl %ebx, 12(%r10)
21886 - movl %ebp, 20(%r10)
21887 - movl %esi, 24(%r10)
21888 - movl %edi, 28(%r10)
21889 + movl %ecx, 4(%r9)
21890 + movl %edx, 8(%r9)
21891 + movl %ebx, 12(%r9)
21892 + movl %ebp, 20(%r9)
21893 + movl %esi, 24(%r9)
21894 + movl %edi, 28(%r9)
21895 popq_cfi %rbp
21896 popq_cfi %rbx
21897 + pax_force_retaddr
21898 ret
21899 3:
21900 CFI_RESTORE_STATE
21901 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
21902 index 36b0d15..d381858 100644
21903 --- a/arch/x86/lib/putuser.S
21904 +++ b/arch/x86/lib/putuser.S
21905 @@ -15,7 +15,9 @@
21906 #include <asm/thread_info.h>
21907 #include <asm/errno.h>
21908 #include <asm/asm.h>
21909 -
21910 +#include <asm/segment.h>
21911 +#include <asm/pgtable.h>
21912 +#include <asm/alternative-asm.h>
21913
21914 /*
21915 * __put_user_X
21916 @@ -29,52 +31,119 @@
21917 * as they get called from within inline assembly.
21918 */
21919
21920 -#define ENTER CFI_STARTPROC ; \
21921 - GET_THREAD_INFO(%_ASM_BX)
21922 -#define EXIT ret ; \
21923 +#define ENTER CFI_STARTPROC
21924 +#define EXIT pax_force_retaddr; ret ; \
21925 CFI_ENDPROC
21926
21927 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21928 +#define _DEST %_ASM_CX,%_ASM_BX
21929 +#else
21930 +#define _DEST %_ASM_CX
21931 +#endif
21932 +
21933 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21934 +#define __copyuser_seg gs;
21935 +#else
21936 +#define __copyuser_seg
21937 +#endif
21938 +
21939 .text
21940 ENTRY(__put_user_1)
21941 ENTER
21942 +
21943 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21944 + GET_THREAD_INFO(%_ASM_BX)
21945 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
21946 jae bad_put_user
21947 -1: movb %al,(%_ASM_CX)
21948 +
21949 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21950 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21951 + cmp %_ASM_BX,%_ASM_CX
21952 + jb 1234f
21953 + xor %ebx,%ebx
21954 +1234:
21955 +#endif
21956 +
21957 +#endif
21958 +
21959 +1: __copyuser_seg movb %al,(_DEST)
21960 xor %eax,%eax
21961 EXIT
21962 ENDPROC(__put_user_1)
21963
21964 ENTRY(__put_user_2)
21965 ENTER
21966 +
21967 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21968 + GET_THREAD_INFO(%_ASM_BX)
21969 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21970 sub $1,%_ASM_BX
21971 cmp %_ASM_BX,%_ASM_CX
21972 jae bad_put_user
21973 -2: movw %ax,(%_ASM_CX)
21974 +
21975 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21976 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21977 + cmp %_ASM_BX,%_ASM_CX
21978 + jb 1234f
21979 + xor %ebx,%ebx
21980 +1234:
21981 +#endif
21982 +
21983 +#endif
21984 +
21985 +2: __copyuser_seg movw %ax,(_DEST)
21986 xor %eax,%eax
21987 EXIT
21988 ENDPROC(__put_user_2)
21989
21990 ENTRY(__put_user_4)
21991 ENTER
21992 +
21993 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21994 + GET_THREAD_INFO(%_ASM_BX)
21995 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21996 sub $3,%_ASM_BX
21997 cmp %_ASM_BX,%_ASM_CX
21998 jae bad_put_user
21999 -3: movl %eax,(%_ASM_CX)
22000 +
22001 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22002 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22003 + cmp %_ASM_BX,%_ASM_CX
22004 + jb 1234f
22005 + xor %ebx,%ebx
22006 +1234:
22007 +#endif
22008 +
22009 +#endif
22010 +
22011 +3: __copyuser_seg movl %eax,(_DEST)
22012 xor %eax,%eax
22013 EXIT
22014 ENDPROC(__put_user_4)
22015
22016 ENTRY(__put_user_8)
22017 ENTER
22018 +
22019 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22020 + GET_THREAD_INFO(%_ASM_BX)
22021 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22022 sub $7,%_ASM_BX
22023 cmp %_ASM_BX,%_ASM_CX
22024 jae bad_put_user
22025 -4: mov %_ASM_AX,(%_ASM_CX)
22026 +
22027 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22028 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22029 + cmp %_ASM_BX,%_ASM_CX
22030 + jb 1234f
22031 + xor %ebx,%ebx
22032 +1234:
22033 +#endif
22034 +
22035 +#endif
22036 +
22037 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22038 #ifdef CONFIG_X86_32
22039 -5: movl %edx,4(%_ASM_CX)
22040 +5: __copyuser_seg movl %edx,4(_DEST)
22041 #endif
22042 xor %eax,%eax
22043 EXIT
22044 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22045 index 1cad221..de671ee 100644
22046 --- a/arch/x86/lib/rwlock.S
22047 +++ b/arch/x86/lib/rwlock.S
22048 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22049 FRAME
22050 0: LOCK_PREFIX
22051 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22052 +
22053 +#ifdef CONFIG_PAX_REFCOUNT
22054 + jno 1234f
22055 + LOCK_PREFIX
22056 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22057 + int $4
22058 +1234:
22059 + _ASM_EXTABLE(1234b, 1234b)
22060 +#endif
22061 +
22062 1: rep; nop
22063 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22064 jne 1b
22065 LOCK_PREFIX
22066 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22067 +
22068 +#ifdef CONFIG_PAX_REFCOUNT
22069 + jno 1234f
22070 + LOCK_PREFIX
22071 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22072 + int $4
22073 +1234:
22074 + _ASM_EXTABLE(1234b, 1234b)
22075 +#endif
22076 +
22077 jnz 0b
22078 ENDFRAME
22079 + pax_force_retaddr
22080 ret
22081 CFI_ENDPROC
22082 END(__write_lock_failed)
22083 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22084 FRAME
22085 0: LOCK_PREFIX
22086 READ_LOCK_SIZE(inc) (%__lock_ptr)
22087 +
22088 +#ifdef CONFIG_PAX_REFCOUNT
22089 + jno 1234f
22090 + LOCK_PREFIX
22091 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22092 + int $4
22093 +1234:
22094 + _ASM_EXTABLE(1234b, 1234b)
22095 +#endif
22096 +
22097 1: rep; nop
22098 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22099 js 1b
22100 LOCK_PREFIX
22101 READ_LOCK_SIZE(dec) (%__lock_ptr)
22102 +
22103 +#ifdef CONFIG_PAX_REFCOUNT
22104 + jno 1234f
22105 + LOCK_PREFIX
22106 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22107 + int $4
22108 +1234:
22109 + _ASM_EXTABLE(1234b, 1234b)
22110 +#endif
22111 +
22112 js 0b
22113 ENDFRAME
22114 + pax_force_retaddr
22115 ret
22116 CFI_ENDPROC
22117 END(__read_lock_failed)
22118 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22119 index 5dff5f0..cadebf4 100644
22120 --- a/arch/x86/lib/rwsem.S
22121 +++ b/arch/x86/lib/rwsem.S
22122 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22123 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22124 CFI_RESTORE __ASM_REG(dx)
22125 restore_common_regs
22126 + pax_force_retaddr
22127 ret
22128 CFI_ENDPROC
22129 ENDPROC(call_rwsem_down_read_failed)
22130 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22131 movq %rax,%rdi
22132 call rwsem_down_write_failed
22133 restore_common_regs
22134 + pax_force_retaddr
22135 ret
22136 CFI_ENDPROC
22137 ENDPROC(call_rwsem_down_write_failed)
22138 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22139 movq %rax,%rdi
22140 call rwsem_wake
22141 restore_common_regs
22142 -1: ret
22143 +1: pax_force_retaddr
22144 + ret
22145 CFI_ENDPROC
22146 ENDPROC(call_rwsem_wake)
22147
22148 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22149 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22150 CFI_RESTORE __ASM_REG(dx)
22151 restore_common_regs
22152 + pax_force_retaddr
22153 ret
22154 CFI_ENDPROC
22155 ENDPROC(call_rwsem_downgrade_wake)
22156 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22157 index a63efd6..ccecad8 100644
22158 --- a/arch/x86/lib/thunk_64.S
22159 +++ b/arch/x86/lib/thunk_64.S
22160 @@ -8,6 +8,7 @@
22161 #include <linux/linkage.h>
22162 #include <asm/dwarf2.h>
22163 #include <asm/calling.h>
22164 +#include <asm/alternative-asm.h>
22165
22166 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22167 .macro THUNK name, func, put_ret_addr_in_rdi=0
22168 @@ -41,5 +42,6 @@
22169 SAVE_ARGS
22170 restore:
22171 RESTORE_ARGS
22172 + pax_force_retaddr
22173 ret
22174 CFI_ENDPROC
22175 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22176 index e218d5d..35679b4 100644
22177 --- a/arch/x86/lib/usercopy_32.c
22178 +++ b/arch/x86/lib/usercopy_32.c
22179 @@ -43,7 +43,7 @@ do { \
22180 __asm__ __volatile__( \
22181 " testl %1,%1\n" \
22182 " jz 2f\n" \
22183 - "0: lodsb\n" \
22184 + "0: "__copyuser_seg"lodsb\n" \
22185 " stosb\n" \
22186 " testb %%al,%%al\n" \
22187 " jz 1f\n" \
22188 @@ -128,10 +128,12 @@ do { \
22189 int __d0; \
22190 might_fault(); \
22191 __asm__ __volatile__( \
22192 + __COPYUSER_SET_ES \
22193 "0: rep; stosl\n" \
22194 " movl %2,%0\n" \
22195 "1: rep; stosb\n" \
22196 "2:\n" \
22197 + __COPYUSER_RESTORE_ES \
22198 ".section .fixup,\"ax\"\n" \
22199 "3: lea 0(%2,%0,4),%0\n" \
22200 " jmp 2b\n" \
22201 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
22202 might_fault();
22203
22204 __asm__ __volatile__(
22205 + __COPYUSER_SET_ES
22206 " testl %0, %0\n"
22207 " jz 3f\n"
22208 " andl %0,%%ecx\n"
22209 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
22210 " subl %%ecx,%0\n"
22211 " addl %0,%%eax\n"
22212 "1:\n"
22213 + __COPYUSER_RESTORE_ES
22214 ".section .fixup,\"ax\"\n"
22215 "2: xorl %%eax,%%eax\n"
22216 " jmp 1b\n"
22217 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22218
22219 #ifdef CONFIG_X86_INTEL_USERCOPY
22220 static unsigned long
22221 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22222 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22223 {
22224 int d0, d1;
22225 __asm__ __volatile__(
22226 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22227 " .align 2,0x90\n"
22228 "3: movl 0(%4), %%eax\n"
22229 "4: movl 4(%4), %%edx\n"
22230 - "5: movl %%eax, 0(%3)\n"
22231 - "6: movl %%edx, 4(%3)\n"
22232 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22233 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22234 "7: movl 8(%4), %%eax\n"
22235 "8: movl 12(%4),%%edx\n"
22236 - "9: movl %%eax, 8(%3)\n"
22237 - "10: movl %%edx, 12(%3)\n"
22238 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22239 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22240 "11: movl 16(%4), %%eax\n"
22241 "12: movl 20(%4), %%edx\n"
22242 - "13: movl %%eax, 16(%3)\n"
22243 - "14: movl %%edx, 20(%3)\n"
22244 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22245 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22246 "15: movl 24(%4), %%eax\n"
22247 "16: movl 28(%4), %%edx\n"
22248 - "17: movl %%eax, 24(%3)\n"
22249 - "18: movl %%edx, 28(%3)\n"
22250 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22251 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22252 "19: movl 32(%4), %%eax\n"
22253 "20: movl 36(%4), %%edx\n"
22254 - "21: movl %%eax, 32(%3)\n"
22255 - "22: movl %%edx, 36(%3)\n"
22256 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22257 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22258 "23: movl 40(%4), %%eax\n"
22259 "24: movl 44(%4), %%edx\n"
22260 - "25: movl %%eax, 40(%3)\n"
22261 - "26: movl %%edx, 44(%3)\n"
22262 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22263 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22264 "27: movl 48(%4), %%eax\n"
22265 "28: movl 52(%4), %%edx\n"
22266 - "29: movl %%eax, 48(%3)\n"
22267 - "30: movl %%edx, 52(%3)\n"
22268 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22269 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22270 "31: movl 56(%4), %%eax\n"
22271 "32: movl 60(%4), %%edx\n"
22272 - "33: movl %%eax, 56(%3)\n"
22273 - "34: movl %%edx, 60(%3)\n"
22274 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22275 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22276 " addl $-64, %0\n"
22277 " addl $64, %4\n"
22278 " addl $64, %3\n"
22279 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22280 " shrl $2, %0\n"
22281 " andl $3, %%eax\n"
22282 " cld\n"
22283 + __COPYUSER_SET_ES
22284 "99: rep; movsl\n"
22285 "36: movl %%eax, %0\n"
22286 "37: rep; movsb\n"
22287 "100:\n"
22288 + __COPYUSER_RESTORE_ES
22289 + ".section .fixup,\"ax\"\n"
22290 + "101: lea 0(%%eax,%0,4),%0\n"
22291 + " jmp 100b\n"
22292 + ".previous\n"
22293 + ".section __ex_table,\"a\"\n"
22294 + " .align 4\n"
22295 + " .long 1b,100b\n"
22296 + " .long 2b,100b\n"
22297 + " .long 3b,100b\n"
22298 + " .long 4b,100b\n"
22299 + " .long 5b,100b\n"
22300 + " .long 6b,100b\n"
22301 + " .long 7b,100b\n"
22302 + " .long 8b,100b\n"
22303 + " .long 9b,100b\n"
22304 + " .long 10b,100b\n"
22305 + " .long 11b,100b\n"
22306 + " .long 12b,100b\n"
22307 + " .long 13b,100b\n"
22308 + " .long 14b,100b\n"
22309 + " .long 15b,100b\n"
22310 + " .long 16b,100b\n"
22311 + " .long 17b,100b\n"
22312 + " .long 18b,100b\n"
22313 + " .long 19b,100b\n"
22314 + " .long 20b,100b\n"
22315 + " .long 21b,100b\n"
22316 + " .long 22b,100b\n"
22317 + " .long 23b,100b\n"
22318 + " .long 24b,100b\n"
22319 + " .long 25b,100b\n"
22320 + " .long 26b,100b\n"
22321 + " .long 27b,100b\n"
22322 + " .long 28b,100b\n"
22323 + " .long 29b,100b\n"
22324 + " .long 30b,100b\n"
22325 + " .long 31b,100b\n"
22326 + " .long 32b,100b\n"
22327 + " .long 33b,100b\n"
22328 + " .long 34b,100b\n"
22329 + " .long 35b,100b\n"
22330 + " .long 36b,100b\n"
22331 + " .long 37b,100b\n"
22332 + " .long 99b,101b\n"
22333 + ".previous"
22334 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22335 + : "1"(to), "2"(from), "0"(size)
22336 + : "eax", "edx", "memory");
22337 + return size;
22338 +}
22339 +
22340 +static unsigned long
22341 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22342 +{
22343 + int d0, d1;
22344 + __asm__ __volatile__(
22345 + " .align 2,0x90\n"
22346 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22347 + " cmpl $67, %0\n"
22348 + " jbe 3f\n"
22349 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22350 + " .align 2,0x90\n"
22351 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22352 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22353 + "5: movl %%eax, 0(%3)\n"
22354 + "6: movl %%edx, 4(%3)\n"
22355 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22356 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22357 + "9: movl %%eax, 8(%3)\n"
22358 + "10: movl %%edx, 12(%3)\n"
22359 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22360 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22361 + "13: movl %%eax, 16(%3)\n"
22362 + "14: movl %%edx, 20(%3)\n"
22363 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22364 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22365 + "17: movl %%eax, 24(%3)\n"
22366 + "18: movl %%edx, 28(%3)\n"
22367 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22368 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22369 + "21: movl %%eax, 32(%3)\n"
22370 + "22: movl %%edx, 36(%3)\n"
22371 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22372 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22373 + "25: movl %%eax, 40(%3)\n"
22374 + "26: movl %%edx, 44(%3)\n"
22375 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22376 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22377 + "29: movl %%eax, 48(%3)\n"
22378 + "30: movl %%edx, 52(%3)\n"
22379 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22380 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22381 + "33: movl %%eax, 56(%3)\n"
22382 + "34: movl %%edx, 60(%3)\n"
22383 + " addl $-64, %0\n"
22384 + " addl $64, %4\n"
22385 + " addl $64, %3\n"
22386 + " cmpl $63, %0\n"
22387 + " ja 1b\n"
22388 + "35: movl %0, %%eax\n"
22389 + " shrl $2, %0\n"
22390 + " andl $3, %%eax\n"
22391 + " cld\n"
22392 + "99: rep; "__copyuser_seg" movsl\n"
22393 + "36: movl %%eax, %0\n"
22394 + "37: rep; "__copyuser_seg" movsb\n"
22395 + "100:\n"
22396 ".section .fixup,\"ax\"\n"
22397 "101: lea 0(%%eax,%0,4),%0\n"
22398 " jmp 100b\n"
22399 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22400 int d0, d1;
22401 __asm__ __volatile__(
22402 " .align 2,0x90\n"
22403 - "0: movl 32(%4), %%eax\n"
22404 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22405 " cmpl $67, %0\n"
22406 " jbe 2f\n"
22407 - "1: movl 64(%4), %%eax\n"
22408 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22409 " .align 2,0x90\n"
22410 - "2: movl 0(%4), %%eax\n"
22411 - "21: movl 4(%4), %%edx\n"
22412 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22413 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22414 " movl %%eax, 0(%3)\n"
22415 " movl %%edx, 4(%3)\n"
22416 - "3: movl 8(%4), %%eax\n"
22417 - "31: movl 12(%4),%%edx\n"
22418 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22419 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22420 " movl %%eax, 8(%3)\n"
22421 " movl %%edx, 12(%3)\n"
22422 - "4: movl 16(%4), %%eax\n"
22423 - "41: movl 20(%4), %%edx\n"
22424 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22425 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22426 " movl %%eax, 16(%3)\n"
22427 " movl %%edx, 20(%3)\n"
22428 - "10: movl 24(%4), %%eax\n"
22429 - "51: movl 28(%4), %%edx\n"
22430 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22431 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22432 " movl %%eax, 24(%3)\n"
22433 " movl %%edx, 28(%3)\n"
22434 - "11: movl 32(%4), %%eax\n"
22435 - "61: movl 36(%4), %%edx\n"
22436 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22437 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22438 " movl %%eax, 32(%3)\n"
22439 " movl %%edx, 36(%3)\n"
22440 - "12: movl 40(%4), %%eax\n"
22441 - "71: movl 44(%4), %%edx\n"
22442 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22443 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22444 " movl %%eax, 40(%3)\n"
22445 " movl %%edx, 44(%3)\n"
22446 - "13: movl 48(%4), %%eax\n"
22447 - "81: movl 52(%4), %%edx\n"
22448 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22449 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22450 " movl %%eax, 48(%3)\n"
22451 " movl %%edx, 52(%3)\n"
22452 - "14: movl 56(%4), %%eax\n"
22453 - "91: movl 60(%4), %%edx\n"
22454 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22455 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22456 " movl %%eax, 56(%3)\n"
22457 " movl %%edx, 60(%3)\n"
22458 " addl $-64, %0\n"
22459 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22460 " shrl $2, %0\n"
22461 " andl $3, %%eax\n"
22462 " cld\n"
22463 - "6: rep; movsl\n"
22464 + "6: rep; "__copyuser_seg" movsl\n"
22465 " movl %%eax,%0\n"
22466 - "7: rep; movsb\n"
22467 + "7: rep; "__copyuser_seg" movsb\n"
22468 "8:\n"
22469 ".section .fixup,\"ax\"\n"
22470 "9: lea 0(%%eax,%0,4),%0\n"
22471 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22472
22473 __asm__ __volatile__(
22474 " .align 2,0x90\n"
22475 - "0: movl 32(%4), %%eax\n"
22476 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22477 " cmpl $67, %0\n"
22478 " jbe 2f\n"
22479 - "1: movl 64(%4), %%eax\n"
22480 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22481 " .align 2,0x90\n"
22482 - "2: movl 0(%4), %%eax\n"
22483 - "21: movl 4(%4), %%edx\n"
22484 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22485 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22486 " movnti %%eax, 0(%3)\n"
22487 " movnti %%edx, 4(%3)\n"
22488 - "3: movl 8(%4), %%eax\n"
22489 - "31: movl 12(%4),%%edx\n"
22490 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22491 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22492 " movnti %%eax, 8(%3)\n"
22493 " movnti %%edx, 12(%3)\n"
22494 - "4: movl 16(%4), %%eax\n"
22495 - "41: movl 20(%4), %%edx\n"
22496 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22497 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22498 " movnti %%eax, 16(%3)\n"
22499 " movnti %%edx, 20(%3)\n"
22500 - "10: movl 24(%4), %%eax\n"
22501 - "51: movl 28(%4), %%edx\n"
22502 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22503 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22504 " movnti %%eax, 24(%3)\n"
22505 " movnti %%edx, 28(%3)\n"
22506 - "11: movl 32(%4), %%eax\n"
22507 - "61: movl 36(%4), %%edx\n"
22508 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22509 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22510 " movnti %%eax, 32(%3)\n"
22511 " movnti %%edx, 36(%3)\n"
22512 - "12: movl 40(%4), %%eax\n"
22513 - "71: movl 44(%4), %%edx\n"
22514 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22515 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22516 " movnti %%eax, 40(%3)\n"
22517 " movnti %%edx, 44(%3)\n"
22518 - "13: movl 48(%4), %%eax\n"
22519 - "81: movl 52(%4), %%edx\n"
22520 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22521 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22522 " movnti %%eax, 48(%3)\n"
22523 " movnti %%edx, 52(%3)\n"
22524 - "14: movl 56(%4), %%eax\n"
22525 - "91: movl 60(%4), %%edx\n"
22526 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22527 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22528 " movnti %%eax, 56(%3)\n"
22529 " movnti %%edx, 60(%3)\n"
22530 " addl $-64, %0\n"
22531 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22532 " shrl $2, %0\n"
22533 " andl $3, %%eax\n"
22534 " cld\n"
22535 - "6: rep; movsl\n"
22536 + "6: rep; "__copyuser_seg" movsl\n"
22537 " movl %%eax,%0\n"
22538 - "7: rep; movsb\n"
22539 + "7: rep; "__copyuser_seg" movsb\n"
22540 "8:\n"
22541 ".section .fixup,\"ax\"\n"
22542 "9: lea 0(%%eax,%0,4),%0\n"
22543 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
22544
22545 __asm__ __volatile__(
22546 " .align 2,0x90\n"
22547 - "0: movl 32(%4), %%eax\n"
22548 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22549 " cmpl $67, %0\n"
22550 " jbe 2f\n"
22551 - "1: movl 64(%4), %%eax\n"
22552 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22553 " .align 2,0x90\n"
22554 - "2: movl 0(%4), %%eax\n"
22555 - "21: movl 4(%4), %%edx\n"
22556 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22557 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22558 " movnti %%eax, 0(%3)\n"
22559 " movnti %%edx, 4(%3)\n"
22560 - "3: movl 8(%4), %%eax\n"
22561 - "31: movl 12(%4),%%edx\n"
22562 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22563 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22564 " movnti %%eax, 8(%3)\n"
22565 " movnti %%edx, 12(%3)\n"
22566 - "4: movl 16(%4), %%eax\n"
22567 - "41: movl 20(%4), %%edx\n"
22568 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22569 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22570 " movnti %%eax, 16(%3)\n"
22571 " movnti %%edx, 20(%3)\n"
22572 - "10: movl 24(%4), %%eax\n"
22573 - "51: movl 28(%4), %%edx\n"
22574 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22575 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22576 " movnti %%eax, 24(%3)\n"
22577 " movnti %%edx, 28(%3)\n"
22578 - "11: movl 32(%4), %%eax\n"
22579 - "61: movl 36(%4), %%edx\n"
22580 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22581 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22582 " movnti %%eax, 32(%3)\n"
22583 " movnti %%edx, 36(%3)\n"
22584 - "12: movl 40(%4), %%eax\n"
22585 - "71: movl 44(%4), %%edx\n"
22586 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22587 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22588 " movnti %%eax, 40(%3)\n"
22589 " movnti %%edx, 44(%3)\n"
22590 - "13: movl 48(%4), %%eax\n"
22591 - "81: movl 52(%4), %%edx\n"
22592 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22593 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22594 " movnti %%eax, 48(%3)\n"
22595 " movnti %%edx, 52(%3)\n"
22596 - "14: movl 56(%4), %%eax\n"
22597 - "91: movl 60(%4), %%edx\n"
22598 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22599 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22600 " movnti %%eax, 56(%3)\n"
22601 " movnti %%edx, 60(%3)\n"
22602 " addl $-64, %0\n"
22603 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
22604 " shrl $2, %0\n"
22605 " andl $3, %%eax\n"
22606 " cld\n"
22607 - "6: rep; movsl\n"
22608 + "6: rep; "__copyuser_seg" movsl\n"
22609 " movl %%eax,%0\n"
22610 - "7: rep; movsb\n"
22611 + "7: rep; "__copyuser_seg" movsb\n"
22612 "8:\n"
22613 ".section .fixup,\"ax\"\n"
22614 "9: lea 0(%%eax,%0,4),%0\n"
22615 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
22616 */
22617 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
22618 unsigned long size);
22619 -unsigned long __copy_user_intel(void __user *to, const void *from,
22620 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
22621 + unsigned long size);
22622 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
22623 unsigned long size);
22624 unsigned long __copy_user_zeroing_intel_nocache(void *to,
22625 const void __user *from, unsigned long size);
22626 #endif /* CONFIG_X86_INTEL_USERCOPY */
22627
22628 /* Generic arbitrary sized copy. */
22629 -#define __copy_user(to, from, size) \
22630 +#define __copy_user(to, from, size, prefix, set, restore) \
22631 do { \
22632 int __d0, __d1, __d2; \
22633 __asm__ __volatile__( \
22634 + set \
22635 " cmp $7,%0\n" \
22636 " jbe 1f\n" \
22637 " movl %1,%0\n" \
22638 " negl %0\n" \
22639 " andl $7,%0\n" \
22640 " subl %0,%3\n" \
22641 - "4: rep; movsb\n" \
22642 + "4: rep; "prefix"movsb\n" \
22643 " movl %3,%0\n" \
22644 " shrl $2,%0\n" \
22645 " andl $3,%3\n" \
22646 " .align 2,0x90\n" \
22647 - "0: rep; movsl\n" \
22648 + "0: rep; "prefix"movsl\n" \
22649 " movl %3,%0\n" \
22650 - "1: rep; movsb\n" \
22651 + "1: rep; "prefix"movsb\n" \
22652 "2:\n" \
22653 + restore \
22654 ".section .fixup,\"ax\"\n" \
22655 "5: addl %3,%0\n" \
22656 " jmp 2b\n" \
22657 @@ -682,14 +799,14 @@ do { \
22658 " negl %0\n" \
22659 " andl $7,%0\n" \
22660 " subl %0,%3\n" \
22661 - "4: rep; movsb\n" \
22662 + "4: rep; "__copyuser_seg"movsb\n" \
22663 " movl %3,%0\n" \
22664 " shrl $2,%0\n" \
22665 " andl $3,%3\n" \
22666 " .align 2,0x90\n" \
22667 - "0: rep; movsl\n" \
22668 + "0: rep; "__copyuser_seg"movsl\n" \
22669 " movl %3,%0\n" \
22670 - "1: rep; movsb\n" \
22671 + "1: rep; "__copyuser_seg"movsb\n" \
22672 "2:\n" \
22673 ".section .fixup,\"ax\"\n" \
22674 "5: addl %3,%0\n" \
22675 @@ -775,9 +892,9 @@ survive:
22676 }
22677 #endif
22678 if (movsl_is_ok(to, from, n))
22679 - __copy_user(to, from, n);
22680 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
22681 else
22682 - n = __copy_user_intel(to, from, n);
22683 + n = __generic_copy_to_user_intel(to, from, n);
22684 return n;
22685 }
22686 EXPORT_SYMBOL(__copy_to_user_ll);
22687 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
22688 unsigned long n)
22689 {
22690 if (movsl_is_ok(to, from, n))
22691 - __copy_user(to, from, n);
22692 + __copy_user(to, from, n, __copyuser_seg, "", "");
22693 else
22694 - n = __copy_user_intel((void __user *)to,
22695 - (const void *)from, n);
22696 + n = __generic_copy_from_user_intel(to, from, n);
22697 return n;
22698 }
22699 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
22700 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
22701 if (n > 64 && cpu_has_xmm2)
22702 n = __copy_user_intel_nocache(to, from, n);
22703 else
22704 - __copy_user(to, from, n);
22705 + __copy_user(to, from, n, __copyuser_seg, "", "");
22706 #else
22707 - __copy_user(to, from, n);
22708 + __copy_user(to, from, n, __copyuser_seg, "", "");
22709 #endif
22710 return n;
22711 }
22712 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
22713
22714 -/**
22715 - * copy_to_user: - Copy a block of data into user space.
22716 - * @to: Destination address, in user space.
22717 - * @from: Source address, in kernel space.
22718 - * @n: Number of bytes to copy.
22719 - *
22720 - * Context: User context only. This function may sleep.
22721 - *
22722 - * Copy data from kernel space to user space.
22723 - *
22724 - * Returns number of bytes that could not be copied.
22725 - * On success, this will be zero.
22726 - */
22727 -unsigned long
22728 -copy_to_user(void __user *to, const void *from, unsigned long n)
22729 -{
22730 - if (access_ok(VERIFY_WRITE, to, n))
22731 - n = __copy_to_user(to, from, n);
22732 - return n;
22733 -}
22734 -EXPORT_SYMBOL(copy_to_user);
22735 -
22736 -/**
22737 - * copy_from_user: - Copy a block of data from user space.
22738 - * @to: Destination address, in kernel space.
22739 - * @from: Source address, in user space.
22740 - * @n: Number of bytes to copy.
22741 - *
22742 - * Context: User context only. This function may sleep.
22743 - *
22744 - * Copy data from user space to kernel space.
22745 - *
22746 - * Returns number of bytes that could not be copied.
22747 - * On success, this will be zero.
22748 - *
22749 - * If some data could not be copied, this function will pad the copied
22750 - * data to the requested size using zero bytes.
22751 - */
22752 -unsigned long
22753 -_copy_from_user(void *to, const void __user *from, unsigned long n)
22754 -{
22755 - if (access_ok(VERIFY_READ, from, n))
22756 - n = __copy_from_user(to, from, n);
22757 - else
22758 - memset(to, 0, n);
22759 - return n;
22760 -}
22761 -EXPORT_SYMBOL(_copy_from_user);
22762 -
22763 void copy_from_user_overflow(void)
22764 {
22765 WARN(1, "Buffer overflow detected!\n");
22766 }
22767 EXPORT_SYMBOL(copy_from_user_overflow);
22768 +
22769 +void copy_to_user_overflow(void)
22770 +{
22771 + WARN(1, "Buffer overflow detected!\n");
22772 +}
22773 +EXPORT_SYMBOL(copy_to_user_overflow);
22774 +
22775 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22776 +void __set_fs(mm_segment_t x)
22777 +{
22778 + switch (x.seg) {
22779 + case 0:
22780 + loadsegment(gs, 0);
22781 + break;
22782 + case TASK_SIZE_MAX:
22783 + loadsegment(gs, __USER_DS);
22784 + break;
22785 + case -1UL:
22786 + loadsegment(gs, __KERNEL_DS);
22787 + break;
22788 + default:
22789 + BUG();
22790 + }
22791 + return;
22792 +}
22793 +EXPORT_SYMBOL(__set_fs);
22794 +
22795 +void set_fs(mm_segment_t x)
22796 +{
22797 + current_thread_info()->addr_limit = x;
22798 + __set_fs(x);
22799 +}
22800 +EXPORT_SYMBOL(set_fs);
22801 +#endif
22802 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
22803 index b7c2849..8633ad8 100644
22804 --- a/arch/x86/lib/usercopy_64.c
22805 +++ b/arch/x86/lib/usercopy_64.c
22806 @@ -42,6 +42,12 @@ long
22807 __strncpy_from_user(char *dst, const char __user *src, long count)
22808 {
22809 long res;
22810 +
22811 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22812 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
22813 + src += PAX_USER_SHADOW_BASE;
22814 +#endif
22815 +
22816 __do_strncpy_from_user(dst, src, count, res);
22817 return res;
22818 }
22819 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
22820 {
22821 long __d0;
22822 might_fault();
22823 +
22824 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22825 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
22826 + addr += PAX_USER_SHADOW_BASE;
22827 +#endif
22828 +
22829 /* no memory constraint because it doesn't change any memory gcc knows
22830 about */
22831 asm volatile(
22832 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
22833 }
22834 EXPORT_SYMBOL(strlen_user);
22835
22836 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
22837 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
22838 {
22839 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
22840 - return copy_user_generic((__force void *)to, (__force void *)from, len);
22841 - }
22842 - return len;
22843 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
22844 +
22845 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22846 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
22847 + to += PAX_USER_SHADOW_BASE;
22848 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
22849 + from += PAX_USER_SHADOW_BASE;
22850 +#endif
22851 +
22852 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
22853 + }
22854 + return len;
22855 }
22856 EXPORT_SYMBOL(copy_in_user);
22857
22858 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
22859 * it is not necessary to optimize tail handling.
22860 */
22861 unsigned long
22862 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
22863 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
22864 {
22865 char c;
22866 unsigned zero_len;
22867 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
22868 index 1fb85db..8b3540b 100644
22869 --- a/arch/x86/mm/extable.c
22870 +++ b/arch/x86/mm/extable.c
22871 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
22872 const struct exception_table_entry *fixup;
22873
22874 #ifdef CONFIG_PNPBIOS
22875 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
22876 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
22877 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
22878 extern u32 pnp_bios_is_utter_crap;
22879 pnp_bios_is_utter_crap = 1;
22880 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
22881 index f0b4caf..d92fd42 100644
22882 --- a/arch/x86/mm/fault.c
22883 +++ b/arch/x86/mm/fault.c
22884 @@ -13,11 +13,18 @@
22885 #include <linux/perf_event.h> /* perf_sw_event */
22886 #include <linux/hugetlb.h> /* hstate_index_to_shift */
22887 #include <linux/prefetch.h> /* prefetchw */
22888 +#include <linux/unistd.h>
22889 +#include <linux/compiler.h>
22890
22891 #include <asm/traps.h> /* dotraplinkage, ... */
22892 #include <asm/pgalloc.h> /* pgd_*(), ... */
22893 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
22894 #include <asm/fixmap.h> /* VSYSCALL_START */
22895 +#include <asm/tlbflush.h>
22896 +
22897 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22898 +#include <asm/stacktrace.h>
22899 +#endif
22900
22901 /*
22902 * Page fault error code bits:
22903 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
22904 int ret = 0;
22905
22906 /* kprobe_running() needs smp_processor_id() */
22907 - if (kprobes_built_in() && !user_mode_vm(regs)) {
22908 + if (kprobes_built_in() && !user_mode(regs)) {
22909 preempt_disable();
22910 if (kprobe_running() && kprobe_fault_handler(regs, 14))
22911 ret = 1;
22912 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
22913 return !instr_lo || (instr_lo>>1) == 1;
22914 case 0x00:
22915 /* Prefetch instruction is 0x0F0D or 0x0F18 */
22916 - if (probe_kernel_address(instr, opcode))
22917 + if (user_mode(regs)) {
22918 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22919 + return 0;
22920 + } else if (probe_kernel_address(instr, opcode))
22921 return 0;
22922
22923 *prefetch = (instr_lo == 0xF) &&
22924 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
22925 while (instr < max_instr) {
22926 unsigned char opcode;
22927
22928 - if (probe_kernel_address(instr, opcode))
22929 + if (user_mode(regs)) {
22930 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22931 + break;
22932 + } else if (probe_kernel_address(instr, opcode))
22933 break;
22934
22935 instr++;
22936 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
22937 force_sig_info(si_signo, &info, tsk);
22938 }
22939
22940 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22941 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
22942 +#endif
22943 +
22944 +#ifdef CONFIG_PAX_EMUTRAMP
22945 +static int pax_handle_fetch_fault(struct pt_regs *regs);
22946 +#endif
22947 +
22948 +#ifdef CONFIG_PAX_PAGEEXEC
22949 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
22950 +{
22951 + pgd_t *pgd;
22952 + pud_t *pud;
22953 + pmd_t *pmd;
22954 +
22955 + pgd = pgd_offset(mm, address);
22956 + if (!pgd_present(*pgd))
22957 + return NULL;
22958 + pud = pud_offset(pgd, address);
22959 + if (!pud_present(*pud))
22960 + return NULL;
22961 + pmd = pmd_offset(pud, address);
22962 + if (!pmd_present(*pmd))
22963 + return NULL;
22964 + return pmd;
22965 +}
22966 +#endif
22967 +
22968 DEFINE_SPINLOCK(pgd_lock);
22969 LIST_HEAD(pgd_list);
22970
22971 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
22972 for (address = VMALLOC_START & PMD_MASK;
22973 address >= TASK_SIZE && address < FIXADDR_TOP;
22974 address += PMD_SIZE) {
22975 +
22976 +#ifdef CONFIG_PAX_PER_CPU_PGD
22977 + unsigned long cpu;
22978 +#else
22979 struct page *page;
22980 +#endif
22981
22982 spin_lock(&pgd_lock);
22983 +
22984 +#ifdef CONFIG_PAX_PER_CPU_PGD
22985 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
22986 + pgd_t *pgd = get_cpu_pgd(cpu);
22987 + pmd_t *ret;
22988 +#else
22989 list_for_each_entry(page, &pgd_list, lru) {
22990 + pgd_t *pgd = page_address(page);
22991 spinlock_t *pgt_lock;
22992 pmd_t *ret;
22993
22994 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
22995 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22996
22997 spin_lock(pgt_lock);
22998 - ret = vmalloc_sync_one(page_address(page), address);
22999 +#endif
23000 +
23001 + ret = vmalloc_sync_one(pgd, address);
23002 +
23003 +#ifndef CONFIG_PAX_PER_CPU_PGD
23004 spin_unlock(pgt_lock);
23005 +#endif
23006
23007 if (!ret)
23008 break;
23009 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23010 * an interrupt in the middle of a task switch..
23011 */
23012 pgd_paddr = read_cr3();
23013 +
23014 +#ifdef CONFIG_PAX_PER_CPU_PGD
23015 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23016 +#endif
23017 +
23018 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23019 if (!pmd_k)
23020 return -1;
23021 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23022 * happen within a race in page table update. In the later
23023 * case just flush:
23024 */
23025 +
23026 +#ifdef CONFIG_PAX_PER_CPU_PGD
23027 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23028 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23029 +#else
23030 pgd = pgd_offset(current->active_mm, address);
23031 +#endif
23032 +
23033 pgd_ref = pgd_offset_k(address);
23034 if (pgd_none(*pgd_ref))
23035 return -1;
23036 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23037 static int is_errata100(struct pt_regs *regs, unsigned long address)
23038 {
23039 #ifdef CONFIG_X86_64
23040 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23041 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23042 return 1;
23043 #endif
23044 return 0;
23045 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23046 }
23047
23048 static const char nx_warning[] = KERN_CRIT
23049 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23050 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23051
23052 static void
23053 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23054 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23055 if (!oops_may_print())
23056 return;
23057
23058 - if (error_code & PF_INSTR) {
23059 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23060 unsigned int level;
23061
23062 pte_t *pte = lookup_address(address, &level);
23063
23064 if (pte && pte_present(*pte) && !pte_exec(*pte))
23065 - printk(nx_warning, current_uid());
23066 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23067 }
23068
23069 +#ifdef CONFIG_PAX_KERNEXEC
23070 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23071 + if (current->signal->curr_ip)
23072 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23073 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23074 + else
23075 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23076 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23077 + }
23078 +#endif
23079 +
23080 printk(KERN_ALERT "BUG: unable to handle kernel ");
23081 if (address < PAGE_SIZE)
23082 printk(KERN_CONT "NULL pointer dereference");
23083 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23084 }
23085 #endif
23086
23087 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23088 + if (pax_is_fetch_fault(regs, error_code, address)) {
23089 +
23090 +#ifdef CONFIG_PAX_EMUTRAMP
23091 + switch (pax_handle_fetch_fault(regs)) {
23092 + case 2:
23093 + return;
23094 + }
23095 +#endif
23096 +
23097 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23098 + do_group_exit(SIGKILL);
23099 + }
23100 +#endif
23101 +
23102 if (unlikely(show_unhandled_signals))
23103 show_signal_msg(regs, error_code, address, tsk);
23104
23105 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23106 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23107 printk(KERN_ERR
23108 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23109 - tsk->comm, tsk->pid, address);
23110 + tsk->comm, task_pid_nr(tsk), address);
23111 code = BUS_MCEERR_AR;
23112 }
23113 #endif
23114 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23115 return 1;
23116 }
23117
23118 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23119 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23120 +{
23121 + pte_t *pte;
23122 + pmd_t *pmd;
23123 + spinlock_t *ptl;
23124 + unsigned char pte_mask;
23125 +
23126 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23127 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23128 + return 0;
23129 +
23130 + /* PaX: it's our fault, let's handle it if we can */
23131 +
23132 + /* PaX: take a look at read faults before acquiring any locks */
23133 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23134 + /* instruction fetch attempt from a protected page in user mode */
23135 + up_read(&mm->mmap_sem);
23136 +
23137 +#ifdef CONFIG_PAX_EMUTRAMP
23138 + switch (pax_handle_fetch_fault(regs)) {
23139 + case 2:
23140 + return 1;
23141 + }
23142 +#endif
23143 +
23144 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23145 + do_group_exit(SIGKILL);
23146 + }
23147 +
23148 + pmd = pax_get_pmd(mm, address);
23149 + if (unlikely(!pmd))
23150 + return 0;
23151 +
23152 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23153 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23154 + pte_unmap_unlock(pte, ptl);
23155 + return 0;
23156 + }
23157 +
23158 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23159 + /* write attempt to a protected page in user mode */
23160 + pte_unmap_unlock(pte, ptl);
23161 + return 0;
23162 + }
23163 +
23164 +#ifdef CONFIG_SMP
23165 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23166 +#else
23167 + if (likely(address > get_limit(regs->cs)))
23168 +#endif
23169 + {
23170 + set_pte(pte, pte_mkread(*pte));
23171 + __flush_tlb_one(address);
23172 + pte_unmap_unlock(pte, ptl);
23173 + up_read(&mm->mmap_sem);
23174 + return 1;
23175 + }
23176 +
23177 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23178 +
23179 + /*
23180 + * PaX: fill DTLB with user rights and retry
23181 + */
23182 + __asm__ __volatile__ (
23183 + "orb %2,(%1)\n"
23184 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23185 +/*
23186 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23187 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23188 + * page fault when examined during a TLB load attempt. this is true not only
23189 + * for PTEs holding a non-present entry but also present entries that will
23190 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23191 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23192 + * for our target pages since their PTEs are simply not in the TLBs at all.
23193 +
23194 + * the best thing in omitting it is that we gain around 15-20% speed in the
23195 + * fast path of the page fault handler and can get rid of tracing since we
23196 + * can no longer flush unintended entries.
23197 + */
23198 + "invlpg (%0)\n"
23199 +#endif
23200 + __copyuser_seg"testb $0,(%0)\n"
23201 + "xorb %3,(%1)\n"
23202 + :
23203 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23204 + : "memory", "cc");
23205 + pte_unmap_unlock(pte, ptl);
23206 + up_read(&mm->mmap_sem);
23207 + return 1;
23208 +}
23209 +#endif
23210 +
23211 /*
23212 * Handle a spurious fault caused by a stale TLB entry.
23213 *
23214 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23215 static inline int
23216 access_error(unsigned long error_code, struct vm_area_struct *vma)
23217 {
23218 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23219 + return 1;
23220 +
23221 if (error_code & PF_WRITE) {
23222 /* write, present and write, not present: */
23223 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23224 @@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23225 {
23226 struct vm_area_struct *vma;
23227 struct task_struct *tsk;
23228 - unsigned long address;
23229 struct mm_struct *mm;
23230 int fault;
23231 int write = error_code & PF_WRITE;
23232 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23233 (write ? FAULT_FLAG_WRITE : 0);
23234
23235 - tsk = current;
23236 - mm = tsk->mm;
23237 -
23238 /* Get the faulting address: */
23239 - address = read_cr2();
23240 + unsigned long address = read_cr2();
23241 +
23242 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23243 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23244 + if (!search_exception_tables(regs->ip)) {
23245 + bad_area_nosemaphore(regs, error_code, address);
23246 + return;
23247 + }
23248 + if (address < PAX_USER_SHADOW_BASE) {
23249 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23250 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23251 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23252 + } else
23253 + address -= PAX_USER_SHADOW_BASE;
23254 + }
23255 +#endif
23256 +
23257 + tsk = current;
23258 + mm = tsk->mm;
23259
23260 /*
23261 * Detect and handle instructions that would cause a page fault for
23262 @@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23263 * User-mode registers count as a user access even for any
23264 * potential system fault or CPU buglet:
23265 */
23266 - if (user_mode_vm(regs)) {
23267 + if (user_mode(regs)) {
23268 local_irq_enable();
23269 error_code |= PF_USER;
23270 } else {
23271 @@ -1132,6 +1338,11 @@ retry:
23272 might_sleep();
23273 }
23274
23275 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23276 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23277 + return;
23278 +#endif
23279 +
23280 vma = find_vma(mm, address);
23281 if (unlikely(!vma)) {
23282 bad_area(regs, error_code, address);
23283 @@ -1143,18 +1354,24 @@ retry:
23284 bad_area(regs, error_code, address);
23285 return;
23286 }
23287 - if (error_code & PF_USER) {
23288 - /*
23289 - * Accessing the stack below %sp is always a bug.
23290 - * The large cushion allows instructions like enter
23291 - * and pusha to work. ("enter $65535, $31" pushes
23292 - * 32 pointers and then decrements %sp by 65535.)
23293 - */
23294 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23295 - bad_area(regs, error_code, address);
23296 - return;
23297 - }
23298 + /*
23299 + * Accessing the stack below %sp is always a bug.
23300 + * The large cushion allows instructions like enter
23301 + * and pusha to work. ("enter $65535, $31" pushes
23302 + * 32 pointers and then decrements %sp by 65535.)
23303 + */
23304 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23305 + bad_area(regs, error_code, address);
23306 + return;
23307 }
23308 +
23309 +#ifdef CONFIG_PAX_SEGMEXEC
23310 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23311 + bad_area(regs, error_code, address);
23312 + return;
23313 + }
23314 +#endif
23315 +
23316 if (unlikely(expand_stack(vma, address))) {
23317 bad_area(regs, error_code, address);
23318 return;
23319 @@ -1209,3 +1426,292 @@ good_area:
23320
23321 up_read(&mm->mmap_sem);
23322 }
23323 +
23324 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23325 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23326 +{
23327 + struct mm_struct *mm = current->mm;
23328 + unsigned long ip = regs->ip;
23329 +
23330 + if (v8086_mode(regs))
23331 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23332 +
23333 +#ifdef CONFIG_PAX_PAGEEXEC
23334 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23335 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23336 + return true;
23337 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23338 + return true;
23339 + return false;
23340 + }
23341 +#endif
23342 +
23343 +#ifdef CONFIG_PAX_SEGMEXEC
23344 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23345 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23346 + return true;
23347 + return false;
23348 + }
23349 +#endif
23350 +
23351 + return false;
23352 +}
23353 +#endif
23354 +
23355 +#ifdef CONFIG_PAX_EMUTRAMP
23356 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23357 +{
23358 + int err;
23359 +
23360 + do { /* PaX: libffi trampoline emulation */
23361 + unsigned char mov, jmp;
23362 + unsigned int addr1, addr2;
23363 +
23364 +#ifdef CONFIG_X86_64
23365 + if ((regs->ip + 9) >> 32)
23366 + break;
23367 +#endif
23368 +
23369 + err = get_user(mov, (unsigned char __user *)regs->ip);
23370 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23371 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23372 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23373 +
23374 + if (err)
23375 + break;
23376 +
23377 + if (mov == 0xB8 && jmp == 0xE9) {
23378 + regs->ax = addr1;
23379 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23380 + return 2;
23381 + }
23382 + } while (0);
23383 +
23384 + do { /* PaX: gcc trampoline emulation #1 */
23385 + unsigned char mov1, mov2;
23386 + unsigned short jmp;
23387 + unsigned int addr1, addr2;
23388 +
23389 +#ifdef CONFIG_X86_64
23390 + if ((regs->ip + 11) >> 32)
23391 + break;
23392 +#endif
23393 +
23394 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23395 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23396 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23397 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23398 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23399 +
23400 + if (err)
23401 + break;
23402 +
23403 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23404 + regs->cx = addr1;
23405 + regs->ax = addr2;
23406 + regs->ip = addr2;
23407 + return 2;
23408 + }
23409 + } while (0);
23410 +
23411 + do { /* PaX: gcc trampoline emulation #2 */
23412 + unsigned char mov, jmp;
23413 + unsigned int addr1, addr2;
23414 +
23415 +#ifdef CONFIG_X86_64
23416 + if ((regs->ip + 9) >> 32)
23417 + break;
23418 +#endif
23419 +
23420 + err = get_user(mov, (unsigned char __user *)regs->ip);
23421 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23422 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23423 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23424 +
23425 + if (err)
23426 + break;
23427 +
23428 + if (mov == 0xB9 && jmp == 0xE9) {
23429 + regs->cx = addr1;
23430 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23431 + return 2;
23432 + }
23433 + } while (0);
23434 +
23435 + return 1; /* PaX in action */
23436 +}
23437 +
23438 +#ifdef CONFIG_X86_64
23439 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23440 +{
23441 + int err;
23442 +
23443 + do { /* PaX: libffi trampoline emulation */
23444 + unsigned short mov1, mov2, jmp1;
23445 + unsigned char stcclc, jmp2;
23446 + unsigned long addr1, addr2;
23447 +
23448 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23449 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23450 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23451 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23452 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23453 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23454 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23455 +
23456 + if (err)
23457 + break;
23458 +
23459 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23460 + regs->r11 = addr1;
23461 + regs->r10 = addr2;
23462 + if (stcclc == 0xF8)
23463 + regs->flags &= ~X86_EFLAGS_CF;
23464 + else
23465 + regs->flags |= X86_EFLAGS_CF;
23466 + regs->ip = addr1;
23467 + return 2;
23468 + }
23469 + } while (0);
23470 +
23471 + do { /* PaX: gcc trampoline emulation #1 */
23472 + unsigned short mov1, mov2, jmp1;
23473 + unsigned char jmp2;
23474 + unsigned int addr1;
23475 + unsigned long addr2;
23476 +
23477 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23478 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23479 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23480 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23481 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23482 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23483 +
23484 + if (err)
23485 + break;
23486 +
23487 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23488 + regs->r11 = addr1;
23489 + regs->r10 = addr2;
23490 + regs->ip = addr1;
23491 + return 2;
23492 + }
23493 + } while (0);
23494 +
23495 + do { /* PaX: gcc trampoline emulation #2 */
23496 + unsigned short mov1, mov2, jmp1;
23497 + unsigned char jmp2;
23498 + unsigned long addr1, addr2;
23499 +
23500 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23501 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23502 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23503 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23504 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
23505 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
23506 +
23507 + if (err)
23508 + break;
23509 +
23510 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23511 + regs->r11 = addr1;
23512 + regs->r10 = addr2;
23513 + regs->ip = addr1;
23514 + return 2;
23515 + }
23516 + } while (0);
23517 +
23518 + return 1; /* PaX in action */
23519 +}
23520 +#endif
23521 +
23522 +/*
23523 + * PaX: decide what to do with offenders (regs->ip = fault address)
23524 + *
23525 + * returns 1 when task should be killed
23526 + * 2 when gcc trampoline was detected
23527 + */
23528 +static int pax_handle_fetch_fault(struct pt_regs *regs)
23529 +{
23530 + if (v8086_mode(regs))
23531 + return 1;
23532 +
23533 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
23534 + return 1;
23535 +
23536 +#ifdef CONFIG_X86_32
23537 + return pax_handle_fetch_fault_32(regs);
23538 +#else
23539 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
23540 + return pax_handle_fetch_fault_32(regs);
23541 + else
23542 + return pax_handle_fetch_fault_64(regs);
23543 +#endif
23544 +}
23545 +#endif
23546 +
23547 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23548 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
23549 +{
23550 + long i;
23551 +
23552 + printk(KERN_ERR "PAX: bytes at PC: ");
23553 + for (i = 0; i < 20; i++) {
23554 + unsigned char c;
23555 + if (get_user(c, (unsigned char __force_user *)pc+i))
23556 + printk(KERN_CONT "?? ");
23557 + else
23558 + printk(KERN_CONT "%02x ", c);
23559 + }
23560 + printk("\n");
23561 +
23562 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
23563 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
23564 + unsigned long c;
23565 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
23566 +#ifdef CONFIG_X86_32
23567 + printk(KERN_CONT "???????? ");
23568 +#else
23569 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
23570 + printk(KERN_CONT "???????? ???????? ");
23571 + else
23572 + printk(KERN_CONT "???????????????? ");
23573 +#endif
23574 + } else {
23575 +#ifdef CONFIG_X86_64
23576 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
23577 + printk(KERN_CONT "%08x ", (unsigned int)c);
23578 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
23579 + } else
23580 +#endif
23581 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
23582 + }
23583 + }
23584 + printk("\n");
23585 +}
23586 +#endif
23587 +
23588 +/**
23589 + * probe_kernel_write(): safely attempt to write to a location
23590 + * @dst: address to write to
23591 + * @src: pointer to the data that shall be written
23592 + * @size: size of the data chunk
23593 + *
23594 + * Safely write to address @dst from the buffer at @src. If a kernel fault
23595 + * happens, handle that and return -EFAULT.
23596 + */
23597 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
23598 +{
23599 + long ret;
23600 + mm_segment_t old_fs = get_fs();
23601 +
23602 + set_fs(KERNEL_DS);
23603 + pagefault_disable();
23604 + pax_open_kernel();
23605 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
23606 + pax_close_kernel();
23607 + pagefault_enable();
23608 + set_fs(old_fs);
23609 +
23610 + return ret ? -EFAULT : 0;
23611 +}
23612 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
23613 index dd74e46..7d26398 100644
23614 --- a/arch/x86/mm/gup.c
23615 +++ b/arch/x86/mm/gup.c
23616 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
23617 addr = start;
23618 len = (unsigned long) nr_pages << PAGE_SHIFT;
23619 end = start + len;
23620 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
23621 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
23622 (void __user *)start, len)))
23623 return 0;
23624
23625 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
23626 index f4f29b1..5cac4fb 100644
23627 --- a/arch/x86/mm/highmem_32.c
23628 +++ b/arch/x86/mm/highmem_32.c
23629 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
23630 idx = type + KM_TYPE_NR*smp_processor_id();
23631 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
23632 BUG_ON(!pte_none(*(kmap_pte-idx)));
23633 +
23634 + pax_open_kernel();
23635 set_pte(kmap_pte-idx, mk_pte(page, prot));
23636 + pax_close_kernel();
23637 +
23638 arch_flush_lazy_mmu_mode();
23639
23640 return (void *)vaddr;
23641 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
23642 index 8ecbb4b..29efd37 100644
23643 --- a/arch/x86/mm/hugetlbpage.c
23644 +++ b/arch/x86/mm/hugetlbpage.c
23645 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
23646 struct hstate *h = hstate_file(file);
23647 struct mm_struct *mm = current->mm;
23648 struct vm_area_struct *vma;
23649 - unsigned long start_addr;
23650 + unsigned long start_addr, pax_task_size = TASK_SIZE;
23651 +
23652 +#ifdef CONFIG_PAX_SEGMEXEC
23653 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23654 + pax_task_size = SEGMEXEC_TASK_SIZE;
23655 +#endif
23656 +
23657 + pax_task_size -= PAGE_SIZE;
23658
23659 if (len > mm->cached_hole_size) {
23660 - start_addr = mm->free_area_cache;
23661 + start_addr = mm->free_area_cache;
23662 } else {
23663 - start_addr = TASK_UNMAPPED_BASE;
23664 - mm->cached_hole_size = 0;
23665 + start_addr = mm->mmap_base;
23666 + mm->cached_hole_size = 0;
23667 }
23668
23669 full_search:
23670 @@ -280,26 +287,27 @@ full_search:
23671
23672 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
23673 /* At this point: (!vma || addr < vma->vm_end). */
23674 - if (TASK_SIZE - len < addr) {
23675 + if (pax_task_size - len < addr) {
23676 /*
23677 * Start a new search - just in case we missed
23678 * some holes.
23679 */
23680 - if (start_addr != TASK_UNMAPPED_BASE) {
23681 - start_addr = TASK_UNMAPPED_BASE;
23682 + if (start_addr != mm->mmap_base) {
23683 + start_addr = mm->mmap_base;
23684 mm->cached_hole_size = 0;
23685 goto full_search;
23686 }
23687 return -ENOMEM;
23688 }
23689 - if (!vma || addr + len <= vma->vm_start) {
23690 - mm->free_area_cache = addr + len;
23691 - return addr;
23692 - }
23693 + if (check_heap_stack_gap(vma, addr, len))
23694 + break;
23695 if (addr + mm->cached_hole_size < vma->vm_start)
23696 mm->cached_hole_size = vma->vm_start - addr;
23697 addr = ALIGN(vma->vm_end, huge_page_size(h));
23698 }
23699 +
23700 + mm->free_area_cache = addr + len;
23701 + return addr;
23702 }
23703
23704 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23705 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23706 {
23707 struct hstate *h = hstate_file(file);
23708 struct mm_struct *mm = current->mm;
23709 - struct vm_area_struct *vma, *prev_vma;
23710 - unsigned long base = mm->mmap_base, addr = addr0;
23711 + struct vm_area_struct *vma;
23712 + unsigned long base = mm->mmap_base, addr;
23713 unsigned long largest_hole = mm->cached_hole_size;
23714 - int first_time = 1;
23715
23716 /* don't allow allocations above current base */
23717 if (mm->free_area_cache > base)
23718 @@ -321,66 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23719 largest_hole = 0;
23720 mm->free_area_cache = base;
23721 }
23722 -try_again:
23723 +
23724 /* make sure it can fit in the remaining address space */
23725 if (mm->free_area_cache < len)
23726 goto fail;
23727
23728 /* either no address requested or can't fit in requested address hole */
23729 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
23730 + addr = (mm->free_area_cache - len);
23731 do {
23732 + addr &= huge_page_mask(h);
23733 + vma = find_vma(mm, addr);
23734 /*
23735 * Lookup failure means no vma is above this address,
23736 * i.e. return with success:
23737 - */
23738 - vma = find_vma(mm, addr);
23739 - if (!vma)
23740 - return addr;
23741 -
23742 - /*
23743 * new region fits between prev_vma->vm_end and
23744 * vma->vm_start, use it:
23745 */
23746 - prev_vma = vma->vm_prev;
23747 - if (addr + len <= vma->vm_start &&
23748 - (!prev_vma || (addr >= prev_vma->vm_end))) {
23749 + if (check_heap_stack_gap(vma, addr, len)) {
23750 /* remember the address as a hint for next time */
23751 - mm->cached_hole_size = largest_hole;
23752 - return (mm->free_area_cache = addr);
23753 - } else {
23754 - /* pull free_area_cache down to the first hole */
23755 - if (mm->free_area_cache == vma->vm_end) {
23756 - mm->free_area_cache = vma->vm_start;
23757 - mm->cached_hole_size = largest_hole;
23758 - }
23759 + mm->cached_hole_size = largest_hole;
23760 + return (mm->free_area_cache = addr);
23761 + }
23762 + /* pull free_area_cache down to the first hole */
23763 + if (mm->free_area_cache == vma->vm_end) {
23764 + mm->free_area_cache = vma->vm_start;
23765 + mm->cached_hole_size = largest_hole;
23766 }
23767
23768 /* remember the largest hole we saw so far */
23769 if (addr + largest_hole < vma->vm_start)
23770 - largest_hole = vma->vm_start - addr;
23771 + largest_hole = vma->vm_start - addr;
23772
23773 /* try just below the current vma->vm_start */
23774 - addr = (vma->vm_start - len) & huge_page_mask(h);
23775 - } while (len <= vma->vm_start);
23776 + addr = skip_heap_stack_gap(vma, len);
23777 + } while (!IS_ERR_VALUE(addr));
23778
23779 fail:
23780 /*
23781 - * if hint left us with no space for the requested
23782 - * mapping then try again:
23783 - */
23784 - if (first_time) {
23785 - mm->free_area_cache = base;
23786 - largest_hole = 0;
23787 - first_time = 0;
23788 - goto try_again;
23789 - }
23790 - /*
23791 * A failed mmap() very likely causes application failure,
23792 * so fall back to the bottom-up function here. This scenario
23793 * can happen with large stack limits and large mmap()
23794 * allocations.
23795 */
23796 - mm->free_area_cache = TASK_UNMAPPED_BASE;
23797 +
23798 +#ifdef CONFIG_PAX_SEGMEXEC
23799 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23800 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23801 + else
23802 +#endif
23803 +
23804 + mm->mmap_base = TASK_UNMAPPED_BASE;
23805 +
23806 +#ifdef CONFIG_PAX_RANDMMAP
23807 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23808 + mm->mmap_base += mm->delta_mmap;
23809 +#endif
23810 +
23811 + mm->free_area_cache = mm->mmap_base;
23812 mm->cached_hole_size = ~0UL;
23813 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
23814 len, pgoff, flags);
23815 @@ -388,6 +392,7 @@ fail:
23816 /*
23817 * Restore the topdown base:
23818 */
23819 + mm->mmap_base = base;
23820 mm->free_area_cache = base;
23821 mm->cached_hole_size = ~0UL;
23822
23823 @@ -401,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
23824 struct hstate *h = hstate_file(file);
23825 struct mm_struct *mm = current->mm;
23826 struct vm_area_struct *vma;
23827 + unsigned long pax_task_size = TASK_SIZE;
23828
23829 if (len & ~huge_page_mask(h))
23830 return -EINVAL;
23831 - if (len > TASK_SIZE)
23832 +
23833 +#ifdef CONFIG_PAX_SEGMEXEC
23834 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23835 + pax_task_size = SEGMEXEC_TASK_SIZE;
23836 +#endif
23837 +
23838 + pax_task_size -= PAGE_SIZE;
23839 +
23840 + if (len > pax_task_size)
23841 return -ENOMEM;
23842
23843 if (flags & MAP_FIXED) {
23844 @@ -416,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
23845 if (addr) {
23846 addr = ALIGN(addr, huge_page_size(h));
23847 vma = find_vma(mm, addr);
23848 - if (TASK_SIZE - len >= addr &&
23849 - (!vma || addr + len <= vma->vm_start))
23850 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
23851 return addr;
23852 }
23853 if (mm->get_unmapped_area == arch_get_unmapped_area)
23854 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
23855 index 6cabf65..77e9c1c 100644
23856 --- a/arch/x86/mm/init.c
23857 +++ b/arch/x86/mm/init.c
23858 @@ -17,6 +17,7 @@
23859 #include <asm/tlb.h>
23860 #include <asm/proto.h>
23861 #include <asm/dma.h> /* for MAX_DMA_PFN */
23862 +#include <asm/desc.h>
23863
23864 unsigned long __initdata pgt_buf_start;
23865 unsigned long __meminitdata pgt_buf_end;
23866 @@ -33,7 +34,7 @@ int direct_gbpages
23867 static void __init find_early_table_space(unsigned long end, int use_pse,
23868 int use_gbpages)
23869 {
23870 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
23871 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
23872 phys_addr_t base;
23873
23874 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
23875 @@ -314,8 +315,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
23876 */
23877 int devmem_is_allowed(unsigned long pagenr)
23878 {
23879 +#ifdef CONFIG_GRKERNSEC_KMEM
23880 + /* allow BDA */
23881 + if (!pagenr)
23882 + return 1;
23883 + /* allow EBDA */
23884 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
23885 + return 1;
23886 +#else
23887 + if (!pagenr)
23888 + return 1;
23889 +#ifdef CONFIG_VM86
23890 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
23891 + return 1;
23892 +#endif
23893 +#endif
23894 +
23895 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
23896 + return 1;
23897 +#ifdef CONFIG_GRKERNSEC_KMEM
23898 + /* throw out everything else below 1MB */
23899 if (pagenr <= 256)
23900 - return 1;
23901 + return 0;
23902 +#endif
23903 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
23904 return 0;
23905 if (!page_is_ram(pagenr))
23906 @@ -374,6 +396,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
23907
23908 void free_initmem(void)
23909 {
23910 +
23911 +#ifdef CONFIG_PAX_KERNEXEC
23912 +#ifdef CONFIG_X86_32
23913 + /* PaX: limit KERNEL_CS to actual size */
23914 + unsigned long addr, limit;
23915 + struct desc_struct d;
23916 + int cpu;
23917 +
23918 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
23919 + limit = (limit - 1UL) >> PAGE_SHIFT;
23920 +
23921 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
23922 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
23923 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
23924 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
23925 + }
23926 +
23927 + /* PaX: make KERNEL_CS read-only */
23928 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
23929 + if (!paravirt_enabled())
23930 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
23931 +/*
23932 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
23933 + pgd = pgd_offset_k(addr);
23934 + pud = pud_offset(pgd, addr);
23935 + pmd = pmd_offset(pud, addr);
23936 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23937 + }
23938 +*/
23939 +#ifdef CONFIG_X86_PAE
23940 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
23941 +/*
23942 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
23943 + pgd = pgd_offset_k(addr);
23944 + pud = pud_offset(pgd, addr);
23945 + pmd = pmd_offset(pud, addr);
23946 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
23947 + }
23948 +*/
23949 +#endif
23950 +
23951 +#ifdef CONFIG_MODULES
23952 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
23953 +#endif
23954 +
23955 +#else
23956 + pgd_t *pgd;
23957 + pud_t *pud;
23958 + pmd_t *pmd;
23959 + unsigned long addr, end;
23960 +
23961 + /* PaX: make kernel code/rodata read-only, rest non-executable */
23962 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
23963 + pgd = pgd_offset_k(addr);
23964 + pud = pud_offset(pgd, addr);
23965 + pmd = pmd_offset(pud, addr);
23966 + if (!pmd_present(*pmd))
23967 + continue;
23968 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
23969 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23970 + else
23971 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
23972 + }
23973 +
23974 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
23975 + end = addr + KERNEL_IMAGE_SIZE;
23976 + for (; addr < end; addr += PMD_SIZE) {
23977 + pgd = pgd_offset_k(addr);
23978 + pud = pud_offset(pgd, addr);
23979 + pmd = pmd_offset(pud, addr);
23980 + if (!pmd_present(*pmd))
23981 + continue;
23982 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
23983 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23984 + }
23985 +#endif
23986 +
23987 + flush_tlb_all();
23988 +#endif
23989 +
23990 free_init_pages("unused kernel memory",
23991 (unsigned long)(&__init_begin),
23992 (unsigned long)(&__init_end));
23993 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
23994 index 8663f6c..829ae76 100644
23995 --- a/arch/x86/mm/init_32.c
23996 +++ b/arch/x86/mm/init_32.c
23997 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
23998 }
23999
24000 /*
24001 - * Creates a middle page table and puts a pointer to it in the
24002 - * given global directory entry. This only returns the gd entry
24003 - * in non-PAE compilation mode, since the middle layer is folded.
24004 - */
24005 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24006 -{
24007 - pud_t *pud;
24008 - pmd_t *pmd_table;
24009 -
24010 -#ifdef CONFIG_X86_PAE
24011 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24012 - if (after_bootmem)
24013 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24014 - else
24015 - pmd_table = (pmd_t *)alloc_low_page();
24016 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24017 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24018 - pud = pud_offset(pgd, 0);
24019 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24020 -
24021 - return pmd_table;
24022 - }
24023 -#endif
24024 - pud = pud_offset(pgd, 0);
24025 - pmd_table = pmd_offset(pud, 0);
24026 -
24027 - return pmd_table;
24028 -}
24029 -
24030 -/*
24031 * Create a page table and place a pointer to it in a middle page
24032 * directory entry:
24033 */
24034 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24035 page_table = (pte_t *)alloc_low_page();
24036
24037 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24038 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24039 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24040 +#else
24041 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24042 +#endif
24043 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24044 }
24045
24046 return pte_offset_kernel(pmd, 0);
24047 }
24048
24049 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24050 +{
24051 + pud_t *pud;
24052 + pmd_t *pmd_table;
24053 +
24054 + pud = pud_offset(pgd, 0);
24055 + pmd_table = pmd_offset(pud, 0);
24056 +
24057 + return pmd_table;
24058 +}
24059 +
24060 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24061 {
24062 int pgd_idx = pgd_index(vaddr);
24063 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24064 int pgd_idx, pmd_idx;
24065 unsigned long vaddr;
24066 pgd_t *pgd;
24067 + pud_t *pud;
24068 pmd_t *pmd;
24069 pte_t *pte = NULL;
24070
24071 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24072 pgd = pgd_base + pgd_idx;
24073
24074 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24075 - pmd = one_md_table_init(pgd);
24076 - pmd = pmd + pmd_index(vaddr);
24077 + pud = pud_offset(pgd, vaddr);
24078 + pmd = pmd_offset(pud, vaddr);
24079 +
24080 +#ifdef CONFIG_X86_PAE
24081 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24082 +#endif
24083 +
24084 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24085 pmd++, pmd_idx++) {
24086 pte = page_table_kmap_check(one_page_table_init(pmd),
24087 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24088 }
24089 }
24090
24091 -static inline int is_kernel_text(unsigned long addr)
24092 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24093 {
24094 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24095 - return 1;
24096 - return 0;
24097 + if ((start > ktla_ktva((unsigned long)_etext) ||
24098 + end <= ktla_ktva((unsigned long)_stext)) &&
24099 + (start > ktla_ktva((unsigned long)_einittext) ||
24100 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24101 +
24102 +#ifdef CONFIG_ACPI_SLEEP
24103 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24104 +#endif
24105 +
24106 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24107 + return 0;
24108 + return 1;
24109 }
24110
24111 /*
24112 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24113 unsigned long last_map_addr = end;
24114 unsigned long start_pfn, end_pfn;
24115 pgd_t *pgd_base = swapper_pg_dir;
24116 - int pgd_idx, pmd_idx, pte_ofs;
24117 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24118 unsigned long pfn;
24119 pgd_t *pgd;
24120 + pud_t *pud;
24121 pmd_t *pmd;
24122 pte_t *pte;
24123 unsigned pages_2m, pages_4k;
24124 @@ -281,8 +282,13 @@ repeat:
24125 pfn = start_pfn;
24126 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24127 pgd = pgd_base + pgd_idx;
24128 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24129 - pmd = one_md_table_init(pgd);
24130 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24131 + pud = pud_offset(pgd, 0);
24132 + pmd = pmd_offset(pud, 0);
24133 +
24134 +#ifdef CONFIG_X86_PAE
24135 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24136 +#endif
24137
24138 if (pfn >= end_pfn)
24139 continue;
24140 @@ -294,14 +300,13 @@ repeat:
24141 #endif
24142 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24143 pmd++, pmd_idx++) {
24144 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24145 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24146
24147 /*
24148 * Map with big pages if possible, otherwise
24149 * create normal page tables:
24150 */
24151 if (use_pse) {
24152 - unsigned int addr2;
24153 pgprot_t prot = PAGE_KERNEL_LARGE;
24154 /*
24155 * first pass will use the same initial
24156 @@ -311,11 +316,7 @@ repeat:
24157 __pgprot(PTE_IDENT_ATTR |
24158 _PAGE_PSE);
24159
24160 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24161 - PAGE_OFFSET + PAGE_SIZE-1;
24162 -
24163 - if (is_kernel_text(addr) ||
24164 - is_kernel_text(addr2))
24165 + if (is_kernel_text(address, address + PMD_SIZE))
24166 prot = PAGE_KERNEL_LARGE_EXEC;
24167
24168 pages_2m++;
24169 @@ -332,7 +333,7 @@ repeat:
24170 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24171 pte += pte_ofs;
24172 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24173 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24174 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24175 pgprot_t prot = PAGE_KERNEL;
24176 /*
24177 * first pass will use the same initial
24178 @@ -340,7 +341,7 @@ repeat:
24179 */
24180 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24181
24182 - if (is_kernel_text(addr))
24183 + if (is_kernel_text(address, address + PAGE_SIZE))
24184 prot = PAGE_KERNEL_EXEC;
24185
24186 pages_4k++;
24187 @@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24188
24189 pud = pud_offset(pgd, va);
24190 pmd = pmd_offset(pud, va);
24191 - if (!pmd_present(*pmd))
24192 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24193 break;
24194
24195 pte = pte_offset_kernel(pmd, va);
24196 @@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
24197
24198 static void __init pagetable_init(void)
24199 {
24200 - pgd_t *pgd_base = swapper_pg_dir;
24201 -
24202 - permanent_kmaps_init(pgd_base);
24203 + permanent_kmaps_init(swapper_pg_dir);
24204 }
24205
24206 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24207 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24208 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24209
24210 /* user-defined highmem size */
24211 @@ -735,6 +734,12 @@ void __init mem_init(void)
24212
24213 pci_iommu_alloc();
24214
24215 +#ifdef CONFIG_PAX_PER_CPU_PGD
24216 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24217 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24218 + KERNEL_PGD_PTRS);
24219 +#endif
24220 +
24221 #ifdef CONFIG_FLATMEM
24222 BUG_ON(!mem_map);
24223 #endif
24224 @@ -761,7 +766,7 @@ void __init mem_init(void)
24225 reservedpages++;
24226
24227 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24228 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24229 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24230 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24231
24232 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24233 @@ -802,10 +807,10 @@ void __init mem_init(void)
24234 ((unsigned long)&__init_end -
24235 (unsigned long)&__init_begin) >> 10,
24236
24237 - (unsigned long)&_etext, (unsigned long)&_edata,
24238 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24239 + (unsigned long)&_sdata, (unsigned long)&_edata,
24240 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24241
24242 - (unsigned long)&_text, (unsigned long)&_etext,
24243 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24244 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24245
24246 /*
24247 @@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
24248 if (!kernel_set_to_readonly)
24249 return;
24250
24251 + start = ktla_ktva(start);
24252 pr_debug("Set kernel text: %lx - %lx for read write\n",
24253 start, start+size);
24254
24255 @@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
24256 if (!kernel_set_to_readonly)
24257 return;
24258
24259 + start = ktla_ktva(start);
24260 pr_debug("Set kernel text: %lx - %lx for read only\n",
24261 start, start+size);
24262
24263 @@ -925,6 +932,7 @@ void mark_rodata_ro(void)
24264 unsigned long start = PFN_ALIGN(_text);
24265 unsigned long size = PFN_ALIGN(_etext) - start;
24266
24267 + start = ktla_ktva(start);
24268 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24269 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24270 size >> 10);
24271 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24272 index 436a030..b8596b9 100644
24273 --- a/arch/x86/mm/init_64.c
24274 +++ b/arch/x86/mm/init_64.c
24275 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24276 * around without checking the pgd every time.
24277 */
24278
24279 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24280 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24281 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24282
24283 int force_personality32;
24284 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24285
24286 for (address = start; address <= end; address += PGDIR_SIZE) {
24287 const pgd_t *pgd_ref = pgd_offset_k(address);
24288 +
24289 +#ifdef CONFIG_PAX_PER_CPU_PGD
24290 + unsigned long cpu;
24291 +#else
24292 struct page *page;
24293 +#endif
24294
24295 if (pgd_none(*pgd_ref))
24296 continue;
24297
24298 spin_lock(&pgd_lock);
24299 +
24300 +#ifdef CONFIG_PAX_PER_CPU_PGD
24301 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24302 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24303 +#else
24304 list_for_each_entry(page, &pgd_list, lru) {
24305 pgd_t *pgd;
24306 spinlock_t *pgt_lock;
24307 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24308 /* the pgt_lock only for Xen */
24309 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24310 spin_lock(pgt_lock);
24311 +#endif
24312
24313 if (pgd_none(*pgd))
24314 set_pgd(pgd, *pgd_ref);
24315 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24316 BUG_ON(pgd_page_vaddr(*pgd)
24317 != pgd_page_vaddr(*pgd_ref));
24318
24319 +#ifndef CONFIG_PAX_PER_CPU_PGD
24320 spin_unlock(pgt_lock);
24321 +#endif
24322 +
24323 }
24324 spin_unlock(&pgd_lock);
24325 }
24326 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24327 pmd = fill_pmd(pud, vaddr);
24328 pte = fill_pte(pmd, vaddr);
24329
24330 + pax_open_kernel();
24331 set_pte(pte, new_pte);
24332 + pax_close_kernel();
24333
24334 /*
24335 * It's enough to flush this one mapping.
24336 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24337 pgd = pgd_offset_k((unsigned long)__va(phys));
24338 if (pgd_none(*pgd)) {
24339 pud = (pud_t *) spp_getpage();
24340 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24341 - _PAGE_USER));
24342 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24343 }
24344 pud = pud_offset(pgd, (unsigned long)__va(phys));
24345 if (pud_none(*pud)) {
24346 pmd = (pmd_t *) spp_getpage();
24347 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24348 - _PAGE_USER));
24349 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24350 }
24351 pmd = pmd_offset(pud, phys);
24352 BUG_ON(!pmd_none(*pmd));
24353 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24354 if (pfn >= pgt_buf_top)
24355 panic("alloc_low_page: ran out of memory");
24356
24357 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24358 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24359 clear_page(adr);
24360 *phys = pfn * PAGE_SIZE;
24361 return adr;
24362 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
24363
24364 phys = __pa(virt);
24365 left = phys & (PAGE_SIZE - 1);
24366 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24367 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24368 adr = (void *)(((unsigned long)adr) | left);
24369
24370 return adr;
24371 @@ -684,6 +698,12 @@ void __init mem_init(void)
24372
24373 pci_iommu_alloc();
24374
24375 +#ifdef CONFIG_PAX_PER_CPU_PGD
24376 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24377 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24378 + KERNEL_PGD_PTRS);
24379 +#endif
24380 +
24381 /* clear_bss() already clear the empty_zero_page */
24382
24383 reservedpages = 0;
24384 @@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
24385 static struct vm_area_struct gate_vma = {
24386 .vm_start = VSYSCALL_START,
24387 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24388 - .vm_page_prot = PAGE_READONLY_EXEC,
24389 - .vm_flags = VM_READ | VM_EXEC
24390 + .vm_page_prot = PAGE_READONLY,
24391 + .vm_flags = VM_READ
24392 };
24393
24394 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24395 @@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
24396
24397 const char *arch_vma_name(struct vm_area_struct *vma)
24398 {
24399 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24400 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24401 return "[vdso]";
24402 if (vma == &gate_vma)
24403 return "[vsyscall]";
24404 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24405 index 7b179b4..6bd1777 100644
24406 --- a/arch/x86/mm/iomap_32.c
24407 +++ b/arch/x86/mm/iomap_32.c
24408 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24409 type = kmap_atomic_idx_push();
24410 idx = type + KM_TYPE_NR * smp_processor_id();
24411 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24412 +
24413 + pax_open_kernel();
24414 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24415 + pax_close_kernel();
24416 +
24417 arch_flush_lazy_mmu_mode();
24418
24419 return (void *)vaddr;
24420 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24421 index be1ef57..55f0160 100644
24422 --- a/arch/x86/mm/ioremap.c
24423 +++ b/arch/x86/mm/ioremap.c
24424 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24425 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24426 int is_ram = page_is_ram(pfn);
24427
24428 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24429 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24430 return NULL;
24431 WARN_ON_ONCE(is_ram);
24432 }
24433 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24434
24435 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24436 if (page_is_ram(start >> PAGE_SHIFT))
24437 +#ifdef CONFIG_HIGHMEM
24438 + if ((start >> PAGE_SHIFT) < max_low_pfn)
24439 +#endif
24440 return __va(phys);
24441
24442 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24443 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24444 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24445
24446 static __initdata int after_paging_init;
24447 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24448 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24449
24450 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24451 {
24452 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24453 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24454
24455 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
24456 - memset(bm_pte, 0, sizeof(bm_pte));
24457 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
24458 + pmd_populate_user(&init_mm, pmd, bm_pte);
24459
24460 /*
24461 * The boot-ioremap range spans multiple pmds, for which
24462 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
24463 index d87dd6d..bf3fa66 100644
24464 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
24465 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
24466 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
24467 * memory (e.g. tracked pages)? For now, we need this to avoid
24468 * invoking kmemcheck for PnP BIOS calls.
24469 */
24470 - if (regs->flags & X86_VM_MASK)
24471 + if (v8086_mode(regs))
24472 return false;
24473 - if (regs->cs != __KERNEL_CS)
24474 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
24475 return false;
24476
24477 pte = kmemcheck_pte_lookup(address);
24478 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
24479 index 845df68..1d8d29f 100644
24480 --- a/arch/x86/mm/mmap.c
24481 +++ b/arch/x86/mm/mmap.c
24482 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
24483 * Leave an at least ~128 MB hole with possible stack randomization.
24484 */
24485 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
24486 -#define MAX_GAP (TASK_SIZE/6*5)
24487 +#define MAX_GAP (pax_task_size/6*5)
24488
24489 static int mmap_is_legacy(void)
24490 {
24491 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
24492 return rnd << PAGE_SHIFT;
24493 }
24494
24495 -static unsigned long mmap_base(void)
24496 +static unsigned long mmap_base(struct mm_struct *mm)
24497 {
24498 unsigned long gap = rlimit(RLIMIT_STACK);
24499 + unsigned long pax_task_size = TASK_SIZE;
24500 +
24501 +#ifdef CONFIG_PAX_SEGMEXEC
24502 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24503 + pax_task_size = SEGMEXEC_TASK_SIZE;
24504 +#endif
24505
24506 if (gap < MIN_GAP)
24507 gap = MIN_GAP;
24508 else if (gap > MAX_GAP)
24509 gap = MAX_GAP;
24510
24511 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
24512 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
24513 }
24514
24515 /*
24516 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
24517 * does, but not when emulating X86_32
24518 */
24519 -static unsigned long mmap_legacy_base(void)
24520 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
24521 {
24522 - if (mmap_is_ia32())
24523 + if (mmap_is_ia32()) {
24524 +
24525 +#ifdef CONFIG_PAX_SEGMEXEC
24526 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24527 + return SEGMEXEC_TASK_UNMAPPED_BASE;
24528 + else
24529 +#endif
24530 +
24531 return TASK_UNMAPPED_BASE;
24532 - else
24533 + } else
24534 return TASK_UNMAPPED_BASE + mmap_rnd();
24535 }
24536
24537 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
24538 void arch_pick_mmap_layout(struct mm_struct *mm)
24539 {
24540 if (mmap_is_legacy()) {
24541 - mm->mmap_base = mmap_legacy_base();
24542 + mm->mmap_base = mmap_legacy_base(mm);
24543 +
24544 +#ifdef CONFIG_PAX_RANDMMAP
24545 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24546 + mm->mmap_base += mm->delta_mmap;
24547 +#endif
24548 +
24549 mm->get_unmapped_area = arch_get_unmapped_area;
24550 mm->unmap_area = arch_unmap_area;
24551 } else {
24552 - mm->mmap_base = mmap_base();
24553 + mm->mmap_base = mmap_base(mm);
24554 +
24555 +#ifdef CONFIG_PAX_RANDMMAP
24556 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24557 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
24558 +#endif
24559 +
24560 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
24561 mm->unmap_area = arch_unmap_area_topdown;
24562 }
24563 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
24564 index dc0b727..dc9d71a 100644
24565 --- a/arch/x86/mm/mmio-mod.c
24566 +++ b/arch/x86/mm/mmio-mod.c
24567 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
24568 break;
24569 default:
24570 {
24571 - unsigned char *ip = (unsigned char *)instptr;
24572 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
24573 my_trace->opcode = MMIO_UNKNOWN_OP;
24574 my_trace->width = 0;
24575 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
24576 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
24577 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
24578 void __iomem *addr)
24579 {
24580 - static atomic_t next_id;
24581 + static atomic_unchecked_t next_id;
24582 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
24583 /* These are page-unaligned. */
24584 struct mmiotrace_map map = {
24585 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
24586 .private = trace
24587 },
24588 .phys = offset,
24589 - .id = atomic_inc_return(&next_id)
24590 + .id = atomic_inc_return_unchecked(&next_id)
24591 };
24592 map.map_id = trace->id;
24593
24594 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
24595 index b008656..773eac2 100644
24596 --- a/arch/x86/mm/pageattr-test.c
24597 +++ b/arch/x86/mm/pageattr-test.c
24598 @@ -36,7 +36,7 @@ enum {
24599
24600 static int pte_testbit(pte_t pte)
24601 {
24602 - return pte_flags(pte) & _PAGE_UNUSED1;
24603 + return pte_flags(pte) & _PAGE_CPA_TEST;
24604 }
24605
24606 struct split_state {
24607 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
24608 index e1ebde3..b1e1db38 100644
24609 --- a/arch/x86/mm/pageattr.c
24610 +++ b/arch/x86/mm/pageattr.c
24611 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24612 */
24613 #ifdef CONFIG_PCI_BIOS
24614 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
24615 - pgprot_val(forbidden) |= _PAGE_NX;
24616 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24617 #endif
24618
24619 /*
24620 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24621 * Does not cover __inittext since that is gone later on. On
24622 * 64bit we do not enforce !NX on the low mapping
24623 */
24624 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
24625 - pgprot_val(forbidden) |= _PAGE_NX;
24626 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
24627 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24628
24629 +#ifdef CONFIG_DEBUG_RODATA
24630 /*
24631 * The .rodata section needs to be read-only. Using the pfn
24632 * catches all aliases.
24633 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24634 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
24635 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
24636 pgprot_val(forbidden) |= _PAGE_RW;
24637 +#endif
24638
24639 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
24640 /*
24641 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24642 }
24643 #endif
24644
24645 +#ifdef CONFIG_PAX_KERNEXEC
24646 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
24647 + pgprot_val(forbidden) |= _PAGE_RW;
24648 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24649 + }
24650 +#endif
24651 +
24652 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
24653
24654 return prot;
24655 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
24656 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
24657 {
24658 /* change init_mm */
24659 + pax_open_kernel();
24660 set_pte_atomic(kpte, pte);
24661 +
24662 #ifdef CONFIG_X86_32
24663 if (!SHARED_KERNEL_PMD) {
24664 +
24665 +#ifdef CONFIG_PAX_PER_CPU_PGD
24666 + unsigned long cpu;
24667 +#else
24668 struct page *page;
24669 +#endif
24670
24671 +#ifdef CONFIG_PAX_PER_CPU_PGD
24672 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24673 + pgd_t *pgd = get_cpu_pgd(cpu);
24674 +#else
24675 list_for_each_entry(page, &pgd_list, lru) {
24676 - pgd_t *pgd;
24677 + pgd_t *pgd = (pgd_t *)page_address(page);
24678 +#endif
24679 +
24680 pud_t *pud;
24681 pmd_t *pmd;
24682
24683 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
24684 + pgd += pgd_index(address);
24685 pud = pud_offset(pgd, address);
24686 pmd = pmd_offset(pud, address);
24687 set_pte_atomic((pte_t *)pmd, pte);
24688 }
24689 }
24690 #endif
24691 + pax_close_kernel();
24692 }
24693
24694 static int
24695 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
24696 index f6ff57b..481690f 100644
24697 --- a/arch/x86/mm/pat.c
24698 +++ b/arch/x86/mm/pat.c
24699 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
24700
24701 if (!entry) {
24702 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
24703 - current->comm, current->pid, start, end);
24704 + current->comm, task_pid_nr(current), start, end);
24705 return -EINVAL;
24706 }
24707
24708 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
24709 while (cursor < to) {
24710 if (!devmem_is_allowed(pfn)) {
24711 printk(KERN_INFO
24712 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
24713 - current->comm, from, to);
24714 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
24715 + current->comm, from, to, cursor);
24716 return 0;
24717 }
24718 cursor += PAGE_SIZE;
24719 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
24720 printk(KERN_INFO
24721 "%s:%d ioremap_change_attr failed %s "
24722 "for %Lx-%Lx\n",
24723 - current->comm, current->pid,
24724 + current->comm, task_pid_nr(current),
24725 cattr_name(flags),
24726 base, (unsigned long long)(base + size));
24727 return -EINVAL;
24728 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
24729 if (want_flags != flags) {
24730 printk(KERN_WARNING
24731 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
24732 - current->comm, current->pid,
24733 + current->comm, task_pid_nr(current),
24734 cattr_name(want_flags),
24735 (unsigned long long)paddr,
24736 (unsigned long long)(paddr + size),
24737 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
24738 free_memtype(paddr, paddr + size);
24739 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
24740 " for %Lx-%Lx, got %s\n",
24741 - current->comm, current->pid,
24742 + current->comm, task_pid_nr(current),
24743 cattr_name(want_flags),
24744 (unsigned long long)paddr,
24745 (unsigned long long)(paddr + size),
24746 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
24747 index 9f0614d..92ae64a 100644
24748 --- a/arch/x86/mm/pf_in.c
24749 +++ b/arch/x86/mm/pf_in.c
24750 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
24751 int i;
24752 enum reason_type rv = OTHERS;
24753
24754 - p = (unsigned char *)ins_addr;
24755 + p = (unsigned char *)ktla_ktva(ins_addr);
24756 p += skip_prefix(p, &prf);
24757 p += get_opcode(p, &opcode);
24758
24759 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
24760 struct prefix_bits prf;
24761 int i;
24762
24763 - p = (unsigned char *)ins_addr;
24764 + p = (unsigned char *)ktla_ktva(ins_addr);
24765 p += skip_prefix(p, &prf);
24766 p += get_opcode(p, &opcode);
24767
24768 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
24769 struct prefix_bits prf;
24770 int i;
24771
24772 - p = (unsigned char *)ins_addr;
24773 + p = (unsigned char *)ktla_ktva(ins_addr);
24774 p += skip_prefix(p, &prf);
24775 p += get_opcode(p, &opcode);
24776
24777 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
24778 struct prefix_bits prf;
24779 int i;
24780
24781 - p = (unsigned char *)ins_addr;
24782 + p = (unsigned char *)ktla_ktva(ins_addr);
24783 p += skip_prefix(p, &prf);
24784 p += get_opcode(p, &opcode);
24785 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
24786 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
24787 struct prefix_bits prf;
24788 int i;
24789
24790 - p = (unsigned char *)ins_addr;
24791 + p = (unsigned char *)ktla_ktva(ins_addr);
24792 p += skip_prefix(p, &prf);
24793 p += get_opcode(p, &opcode);
24794 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
24795 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
24796 index 8573b83..c3b1a30 100644
24797 --- a/arch/x86/mm/pgtable.c
24798 +++ b/arch/x86/mm/pgtable.c
24799 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
24800 list_del(&page->lru);
24801 }
24802
24803 -#define UNSHARED_PTRS_PER_PGD \
24804 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
24805 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24806 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
24807
24808 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
24809 +{
24810 + while (count--)
24811 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
24812 +}
24813 +#endif
24814
24815 +#ifdef CONFIG_PAX_PER_CPU_PGD
24816 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
24817 +{
24818 + while (count--)
24819 +
24820 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24821 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
24822 +#else
24823 + *dst++ = *src++;
24824 +#endif
24825 +
24826 +}
24827 +#endif
24828 +
24829 +#ifdef CONFIG_X86_64
24830 +#define pxd_t pud_t
24831 +#define pyd_t pgd_t
24832 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
24833 +#define pxd_free(mm, pud) pud_free((mm), (pud))
24834 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
24835 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
24836 +#define PYD_SIZE PGDIR_SIZE
24837 +#else
24838 +#define pxd_t pmd_t
24839 +#define pyd_t pud_t
24840 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
24841 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
24842 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
24843 +#define pyd_offset(mm, address) pud_offset((mm), (address))
24844 +#define PYD_SIZE PUD_SIZE
24845 +#endif
24846 +
24847 +#ifdef CONFIG_PAX_PER_CPU_PGD
24848 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
24849 +static inline void pgd_dtor(pgd_t *pgd) {}
24850 +#else
24851 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
24852 {
24853 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
24854 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
24855 pgd_list_del(pgd);
24856 spin_unlock(&pgd_lock);
24857 }
24858 +#endif
24859
24860 /*
24861 * List of all pgd's needed for non-PAE so it can invalidate entries
24862 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
24863 * -- wli
24864 */
24865
24866 -#ifdef CONFIG_X86_PAE
24867 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24868 /*
24869 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
24870 * updating the top-level pagetable entries to guarantee the
24871 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
24872 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
24873 * and initialize the kernel pmds here.
24874 */
24875 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
24876 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
24877
24878 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
24879 {
24880 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
24881 */
24882 flush_tlb_mm(mm);
24883 }
24884 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
24885 +#define PREALLOCATED_PXDS USER_PGD_PTRS
24886 #else /* !CONFIG_X86_PAE */
24887
24888 /* No need to prepopulate any pagetable entries in non-PAE modes. */
24889 -#define PREALLOCATED_PMDS 0
24890 +#define PREALLOCATED_PXDS 0
24891
24892 #endif /* CONFIG_X86_PAE */
24893
24894 -static void free_pmds(pmd_t *pmds[])
24895 +static void free_pxds(pxd_t *pxds[])
24896 {
24897 int i;
24898
24899 - for(i = 0; i < PREALLOCATED_PMDS; i++)
24900 - if (pmds[i])
24901 - free_page((unsigned long)pmds[i]);
24902 + for(i = 0; i < PREALLOCATED_PXDS; i++)
24903 + if (pxds[i])
24904 + free_page((unsigned long)pxds[i]);
24905 }
24906
24907 -static int preallocate_pmds(pmd_t *pmds[])
24908 +static int preallocate_pxds(pxd_t *pxds[])
24909 {
24910 int i;
24911 bool failed = false;
24912
24913 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
24914 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
24915 - if (pmd == NULL)
24916 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
24917 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
24918 + if (pxd == NULL)
24919 failed = true;
24920 - pmds[i] = pmd;
24921 + pxds[i] = pxd;
24922 }
24923
24924 if (failed) {
24925 - free_pmds(pmds);
24926 + free_pxds(pxds);
24927 return -ENOMEM;
24928 }
24929
24930 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
24931 * preallocate which never got a corresponding vma will need to be
24932 * freed manually.
24933 */
24934 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
24935 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
24936 {
24937 int i;
24938
24939 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
24940 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
24941 pgd_t pgd = pgdp[i];
24942
24943 if (pgd_val(pgd) != 0) {
24944 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
24945 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
24946
24947 - pgdp[i] = native_make_pgd(0);
24948 + set_pgd(pgdp + i, native_make_pgd(0));
24949
24950 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
24951 - pmd_free(mm, pmd);
24952 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
24953 + pxd_free(mm, pxd);
24954 }
24955 }
24956 }
24957
24958 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
24959 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
24960 {
24961 - pud_t *pud;
24962 + pyd_t *pyd;
24963 unsigned long addr;
24964 int i;
24965
24966 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
24967 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
24968 return;
24969
24970 - pud = pud_offset(pgd, 0);
24971 +#ifdef CONFIG_X86_64
24972 + pyd = pyd_offset(mm, 0L);
24973 +#else
24974 + pyd = pyd_offset(pgd, 0L);
24975 +#endif
24976
24977 - for (addr = i = 0; i < PREALLOCATED_PMDS;
24978 - i++, pud++, addr += PUD_SIZE) {
24979 - pmd_t *pmd = pmds[i];
24980 + for (addr = i = 0; i < PREALLOCATED_PXDS;
24981 + i++, pyd++, addr += PYD_SIZE) {
24982 + pxd_t *pxd = pxds[i];
24983
24984 if (i >= KERNEL_PGD_BOUNDARY)
24985 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
24986 - sizeof(pmd_t) * PTRS_PER_PMD);
24987 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
24988 + sizeof(pxd_t) * PTRS_PER_PMD);
24989
24990 - pud_populate(mm, pud, pmd);
24991 + pyd_populate(mm, pyd, pxd);
24992 }
24993 }
24994
24995 pgd_t *pgd_alloc(struct mm_struct *mm)
24996 {
24997 pgd_t *pgd;
24998 - pmd_t *pmds[PREALLOCATED_PMDS];
24999 + pxd_t *pxds[PREALLOCATED_PXDS];
25000
25001 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25002
25003 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25004
25005 mm->pgd = pgd;
25006
25007 - if (preallocate_pmds(pmds) != 0)
25008 + if (preallocate_pxds(pxds) != 0)
25009 goto out_free_pgd;
25010
25011 if (paravirt_pgd_alloc(mm) != 0)
25012 - goto out_free_pmds;
25013 + goto out_free_pxds;
25014
25015 /*
25016 * Make sure that pre-populating the pmds is atomic with
25017 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25018 spin_lock(&pgd_lock);
25019
25020 pgd_ctor(mm, pgd);
25021 - pgd_prepopulate_pmd(mm, pgd, pmds);
25022 + pgd_prepopulate_pxd(mm, pgd, pxds);
25023
25024 spin_unlock(&pgd_lock);
25025
25026 return pgd;
25027
25028 -out_free_pmds:
25029 - free_pmds(pmds);
25030 +out_free_pxds:
25031 + free_pxds(pxds);
25032 out_free_pgd:
25033 free_page((unsigned long)pgd);
25034 out:
25035 @@ -295,7 +344,7 @@ out:
25036
25037 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25038 {
25039 - pgd_mop_up_pmds(mm, pgd);
25040 + pgd_mop_up_pxds(mm, pgd);
25041 pgd_dtor(pgd);
25042 paravirt_pgd_free(mm, pgd);
25043 free_page((unsigned long)pgd);
25044 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25045 index cac7184..09a39fa 100644
25046 --- a/arch/x86/mm/pgtable_32.c
25047 +++ b/arch/x86/mm/pgtable_32.c
25048 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25049 return;
25050 }
25051 pte = pte_offset_kernel(pmd, vaddr);
25052 +
25053 + pax_open_kernel();
25054 if (pte_val(pteval))
25055 set_pte_at(&init_mm, vaddr, pte, pteval);
25056 else
25057 pte_clear(&init_mm, vaddr, pte);
25058 + pax_close_kernel();
25059
25060 /*
25061 * It's enough to flush this one mapping.
25062 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25063 index 410531d..0f16030 100644
25064 --- a/arch/x86/mm/setup_nx.c
25065 +++ b/arch/x86/mm/setup_nx.c
25066 @@ -5,8 +5,10 @@
25067 #include <asm/pgtable.h>
25068 #include <asm/proto.h>
25069
25070 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25071 static int disable_nx __cpuinitdata;
25072
25073 +#ifndef CONFIG_PAX_PAGEEXEC
25074 /*
25075 * noexec = on|off
25076 *
25077 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25078 return 0;
25079 }
25080 early_param("noexec", noexec_setup);
25081 +#endif
25082 +
25083 +#endif
25084
25085 void __cpuinit x86_configure_nx(void)
25086 {
25087 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25088 if (cpu_has_nx && !disable_nx)
25089 __supported_pte_mask |= _PAGE_NX;
25090 else
25091 +#endif
25092 __supported_pte_mask &= ~_PAGE_NX;
25093 }
25094
25095 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25096 index d6c0418..06a0ad5 100644
25097 --- a/arch/x86/mm/tlb.c
25098 +++ b/arch/x86/mm/tlb.c
25099 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25100 BUG();
25101 cpumask_clear_cpu(cpu,
25102 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25103 +
25104 +#ifndef CONFIG_PAX_PER_CPU_PGD
25105 load_cr3(swapper_pg_dir);
25106 +#endif
25107 +
25108 }
25109 EXPORT_SYMBOL_GPL(leave_mm);
25110
25111 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25112 index 6687022..ceabcfa 100644
25113 --- a/arch/x86/net/bpf_jit.S
25114 +++ b/arch/x86/net/bpf_jit.S
25115 @@ -9,6 +9,7 @@
25116 */
25117 #include <linux/linkage.h>
25118 #include <asm/dwarf2.h>
25119 +#include <asm/alternative-asm.h>
25120
25121 /*
25122 * Calling convention :
25123 @@ -35,6 +36,7 @@ sk_load_word:
25124 jle bpf_slow_path_word
25125 mov (SKBDATA,%rsi),%eax
25126 bswap %eax /* ntohl() */
25127 + pax_force_retaddr
25128 ret
25129
25130
25131 @@ -53,6 +55,7 @@ sk_load_half:
25132 jle bpf_slow_path_half
25133 movzwl (SKBDATA,%rsi),%eax
25134 rol $8,%ax # ntohs()
25135 + pax_force_retaddr
25136 ret
25137
25138 sk_load_byte_ind:
25139 @@ -66,6 +69,7 @@ sk_load_byte:
25140 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25141 jle bpf_slow_path_byte
25142 movzbl (SKBDATA,%rsi),%eax
25143 + pax_force_retaddr
25144 ret
25145
25146 /**
25147 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
25148 movzbl (SKBDATA,%rsi),%ebx
25149 and $15,%bl
25150 shl $2,%bl
25151 + pax_force_retaddr
25152 ret
25153 CFI_ENDPROC
25154 ENDPROC(sk_load_byte_msh)
25155 @@ -91,6 +96,7 @@ bpf_error:
25156 xor %eax,%eax
25157 mov -8(%rbp),%rbx
25158 leaveq
25159 + pax_force_retaddr
25160 ret
25161
25162 /* rsi contains offset and can be scratched */
25163 @@ -113,6 +119,7 @@ bpf_slow_path_word:
25164 js bpf_error
25165 mov -12(%rbp),%eax
25166 bswap %eax
25167 + pax_force_retaddr
25168 ret
25169
25170 bpf_slow_path_half:
25171 @@ -121,12 +128,14 @@ bpf_slow_path_half:
25172 mov -12(%rbp),%ax
25173 rol $8,%ax
25174 movzwl %ax,%eax
25175 + pax_force_retaddr
25176 ret
25177
25178 bpf_slow_path_byte:
25179 bpf_slow_path_common(1)
25180 js bpf_error
25181 movzbl -12(%rbp),%eax
25182 + pax_force_retaddr
25183 ret
25184
25185 bpf_slow_path_byte_msh:
25186 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
25187 and $15,%al
25188 shl $2,%al
25189 xchg %eax,%ebx
25190 + pax_force_retaddr
25191 ret
25192 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25193 index 5671752..6838cd1 100644
25194 --- a/arch/x86/net/bpf_jit_comp.c
25195 +++ b/arch/x86/net/bpf_jit_comp.c
25196 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
25197 set_fs(old_fs);
25198 }
25199
25200 +struct bpf_jit_work {
25201 + struct work_struct work;
25202 + void *image;
25203 +};
25204
25205 void bpf_jit_compile(struct sk_filter *fp)
25206 {
25207 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25208 if (addrs == NULL)
25209 return;
25210
25211 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25212 + if (!fp->work)
25213 + goto out;
25214 +
25215 /* Before first pass, make a rough estimation of addrs[]
25216 * each bpf instruction is translated to less than 64 bytes
25217 */
25218 @@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25219 common_load: seen |= SEEN_DATAREF;
25220 if ((int)K < 0) {
25221 /* Abort the JIT because __load_pointer() is needed. */
25222 - goto out;
25223 + goto error;
25224 }
25225 t_offset = func - (image + addrs[i]);
25226 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25227 @@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
25228 case BPF_S_LDX_B_MSH:
25229 if ((int)K < 0) {
25230 /* Abort the JIT because __load_pointer() is needed. */
25231 - goto out;
25232 + goto error;
25233 }
25234 seen |= SEEN_DATAREF | SEEN_XREG;
25235 t_offset = sk_load_byte_msh - (image + addrs[i]);
25236 @@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25237 break;
25238 default:
25239 /* hmm, too complex filter, give up with jit compiler */
25240 - goto out;
25241 + goto error;
25242 }
25243 ilen = prog - temp;
25244 if (image) {
25245 if (unlikely(proglen + ilen > oldproglen)) {
25246 pr_err("bpb_jit_compile fatal error\n");
25247 - kfree(addrs);
25248 - module_free(NULL, image);
25249 - return;
25250 + module_free_exec(NULL, image);
25251 + goto error;
25252 }
25253 + pax_open_kernel();
25254 memcpy(image + proglen, temp, ilen);
25255 + pax_close_kernel();
25256 }
25257 proglen += ilen;
25258 addrs[i] = proglen;
25259 @@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25260 break;
25261 }
25262 if (proglen == oldproglen) {
25263 - image = module_alloc(max_t(unsigned int,
25264 - proglen,
25265 - sizeof(struct work_struct)));
25266 + image = module_alloc_exec(proglen);
25267 if (!image)
25268 - goto out;
25269 + goto error;
25270 }
25271 oldproglen = proglen;
25272 }
25273 @@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25274 bpf_flush_icache(image, image + proglen);
25275
25276 fp->bpf_func = (void *)image;
25277 - }
25278 + } else
25279 +error:
25280 + kfree(fp->work);
25281 +
25282 out:
25283 kfree(addrs);
25284 return;
25285 @@ -641,18 +651,20 @@ out:
25286
25287 static void jit_free_defer(struct work_struct *arg)
25288 {
25289 - module_free(NULL, arg);
25290 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25291 + kfree(arg);
25292 }
25293
25294 /* run from softirq, we must use a work_struct to call
25295 - * module_free() from process context
25296 + * module_free_exec() from process context
25297 */
25298 void bpf_jit_free(struct sk_filter *fp)
25299 {
25300 if (fp->bpf_func != sk_run_filter) {
25301 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25302 + struct work_struct *work = &fp->work->work;
25303
25304 INIT_WORK(work, jit_free_defer);
25305 + fp->work->image = fp->bpf_func;
25306 schedule_work(work);
25307 }
25308 }
25309 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25310 index bff89df..377758a 100644
25311 --- a/arch/x86/oprofile/backtrace.c
25312 +++ b/arch/x86/oprofile/backtrace.c
25313 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25314 struct stack_frame_ia32 *fp;
25315 unsigned long bytes;
25316
25317 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25318 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25319 if (bytes != sizeof(bufhead))
25320 return NULL;
25321
25322 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25323 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25324
25325 oprofile_add_trace(bufhead[0].return_address);
25326
25327 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25328 struct stack_frame bufhead[2];
25329 unsigned long bytes;
25330
25331 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25332 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25333 if (bytes != sizeof(bufhead))
25334 return NULL;
25335
25336 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25337 {
25338 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25339
25340 - if (!user_mode_vm(regs)) {
25341 + if (!user_mode(regs)) {
25342 unsigned long stack = kernel_stack_pointer(regs);
25343 if (depth)
25344 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25345 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25346 index cb29191..036766d 100644
25347 --- a/arch/x86/pci/mrst.c
25348 +++ b/arch/x86/pci/mrst.c
25349 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
25350 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
25351 pci_mmcfg_late_init();
25352 pcibios_enable_irq = mrst_pci_irq_enable;
25353 - pci_root_ops = pci_mrst_ops;
25354 + pax_open_kernel();
25355 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25356 + pax_close_kernel();
25357 /* Continue with standard init */
25358 return 1;
25359 }
25360 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25361 index da8fe05..7ee6704 100644
25362 --- a/arch/x86/pci/pcbios.c
25363 +++ b/arch/x86/pci/pcbios.c
25364 @@ -79,50 +79,93 @@ union bios32 {
25365 static struct {
25366 unsigned long address;
25367 unsigned short segment;
25368 -} bios32_indirect = { 0, __KERNEL_CS };
25369 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25370
25371 /*
25372 * Returns the entry point for the given service, NULL on error
25373 */
25374
25375 -static unsigned long bios32_service(unsigned long service)
25376 +static unsigned long __devinit bios32_service(unsigned long service)
25377 {
25378 unsigned char return_code; /* %al */
25379 unsigned long address; /* %ebx */
25380 unsigned long length; /* %ecx */
25381 unsigned long entry; /* %edx */
25382 unsigned long flags;
25383 + struct desc_struct d, *gdt;
25384
25385 local_irq_save(flags);
25386 - __asm__("lcall *(%%edi); cld"
25387 +
25388 + gdt = get_cpu_gdt_table(smp_processor_id());
25389 +
25390 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25391 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25392 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25393 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25394 +
25395 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25396 : "=a" (return_code),
25397 "=b" (address),
25398 "=c" (length),
25399 "=d" (entry)
25400 : "0" (service),
25401 "1" (0),
25402 - "D" (&bios32_indirect));
25403 + "D" (&bios32_indirect),
25404 + "r"(__PCIBIOS_DS)
25405 + : "memory");
25406 +
25407 + pax_open_kernel();
25408 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25409 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25410 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25411 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25412 + pax_close_kernel();
25413 +
25414 local_irq_restore(flags);
25415
25416 switch (return_code) {
25417 - case 0:
25418 - return address + entry;
25419 - case 0x80: /* Not present */
25420 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25421 - return 0;
25422 - default: /* Shouldn't happen */
25423 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25424 - service, return_code);
25425 + case 0: {
25426 + int cpu;
25427 + unsigned char flags;
25428 +
25429 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
25430 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
25431 + printk(KERN_WARNING "bios32_service: not valid\n");
25432 return 0;
25433 + }
25434 + address = address + PAGE_OFFSET;
25435 + length += 16UL; /* some BIOSs underreport this... */
25436 + flags = 4;
25437 + if (length >= 64*1024*1024) {
25438 + length >>= PAGE_SHIFT;
25439 + flags |= 8;
25440 + }
25441 +
25442 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25443 + gdt = get_cpu_gdt_table(cpu);
25444 + pack_descriptor(&d, address, length, 0x9b, flags);
25445 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25446 + pack_descriptor(&d, address, length, 0x93, flags);
25447 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25448 + }
25449 + return entry;
25450 + }
25451 + case 0x80: /* Not present */
25452 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25453 + return 0;
25454 + default: /* Shouldn't happen */
25455 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25456 + service, return_code);
25457 + return 0;
25458 }
25459 }
25460
25461 static struct {
25462 unsigned long address;
25463 unsigned short segment;
25464 -} pci_indirect = { 0, __KERNEL_CS };
25465 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
25466
25467 -static int pci_bios_present;
25468 +static int pci_bios_present __read_only;
25469
25470 static int __devinit check_pcibios(void)
25471 {
25472 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
25473 unsigned long flags, pcibios_entry;
25474
25475 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
25476 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
25477 + pci_indirect.address = pcibios_entry;
25478
25479 local_irq_save(flags);
25480 - __asm__(
25481 - "lcall *(%%edi); cld\n\t"
25482 + __asm__("movw %w6, %%ds\n\t"
25483 + "lcall *%%ss:(%%edi); cld\n\t"
25484 + "push %%ss\n\t"
25485 + "pop %%ds\n\t"
25486 "jc 1f\n\t"
25487 "xor %%ah, %%ah\n"
25488 "1:"
25489 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
25490 "=b" (ebx),
25491 "=c" (ecx)
25492 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
25493 - "D" (&pci_indirect)
25494 + "D" (&pci_indirect),
25495 + "r" (__PCIBIOS_DS)
25496 : "memory");
25497 local_irq_restore(flags);
25498
25499 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25500
25501 switch (len) {
25502 case 1:
25503 - __asm__("lcall *(%%esi); cld\n\t"
25504 + __asm__("movw %w6, %%ds\n\t"
25505 + "lcall *%%ss:(%%esi); cld\n\t"
25506 + "push %%ss\n\t"
25507 + "pop %%ds\n\t"
25508 "jc 1f\n\t"
25509 "xor %%ah, %%ah\n"
25510 "1:"
25511 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25512 : "1" (PCIBIOS_READ_CONFIG_BYTE),
25513 "b" (bx),
25514 "D" ((long)reg),
25515 - "S" (&pci_indirect));
25516 + "S" (&pci_indirect),
25517 + "r" (__PCIBIOS_DS));
25518 /*
25519 * Zero-extend the result beyond 8 bits, do not trust the
25520 * BIOS having done it:
25521 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25522 *value &= 0xff;
25523 break;
25524 case 2:
25525 - __asm__("lcall *(%%esi); cld\n\t"
25526 + __asm__("movw %w6, %%ds\n\t"
25527 + "lcall *%%ss:(%%esi); cld\n\t"
25528 + "push %%ss\n\t"
25529 + "pop %%ds\n\t"
25530 "jc 1f\n\t"
25531 "xor %%ah, %%ah\n"
25532 "1:"
25533 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25534 : "1" (PCIBIOS_READ_CONFIG_WORD),
25535 "b" (bx),
25536 "D" ((long)reg),
25537 - "S" (&pci_indirect));
25538 + "S" (&pci_indirect),
25539 + "r" (__PCIBIOS_DS));
25540 /*
25541 * Zero-extend the result beyond 16 bits, do not trust the
25542 * BIOS having done it:
25543 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25544 *value &= 0xffff;
25545 break;
25546 case 4:
25547 - __asm__("lcall *(%%esi); cld\n\t"
25548 + __asm__("movw %w6, %%ds\n\t"
25549 + "lcall *%%ss:(%%esi); cld\n\t"
25550 + "push %%ss\n\t"
25551 + "pop %%ds\n\t"
25552 "jc 1f\n\t"
25553 "xor %%ah, %%ah\n"
25554 "1:"
25555 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25556 : "1" (PCIBIOS_READ_CONFIG_DWORD),
25557 "b" (bx),
25558 "D" ((long)reg),
25559 - "S" (&pci_indirect));
25560 + "S" (&pci_indirect),
25561 + "r" (__PCIBIOS_DS));
25562 break;
25563 }
25564
25565 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25566
25567 switch (len) {
25568 case 1:
25569 - __asm__("lcall *(%%esi); cld\n\t"
25570 + __asm__("movw %w6, %%ds\n\t"
25571 + "lcall *%%ss:(%%esi); cld\n\t"
25572 + "push %%ss\n\t"
25573 + "pop %%ds\n\t"
25574 "jc 1f\n\t"
25575 "xor %%ah, %%ah\n"
25576 "1:"
25577 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25578 "c" (value),
25579 "b" (bx),
25580 "D" ((long)reg),
25581 - "S" (&pci_indirect));
25582 + "S" (&pci_indirect),
25583 + "r" (__PCIBIOS_DS));
25584 break;
25585 case 2:
25586 - __asm__("lcall *(%%esi); cld\n\t"
25587 + __asm__("movw %w6, %%ds\n\t"
25588 + "lcall *%%ss:(%%esi); cld\n\t"
25589 + "push %%ss\n\t"
25590 + "pop %%ds\n\t"
25591 "jc 1f\n\t"
25592 "xor %%ah, %%ah\n"
25593 "1:"
25594 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25595 "c" (value),
25596 "b" (bx),
25597 "D" ((long)reg),
25598 - "S" (&pci_indirect));
25599 + "S" (&pci_indirect),
25600 + "r" (__PCIBIOS_DS));
25601 break;
25602 case 4:
25603 - __asm__("lcall *(%%esi); cld\n\t"
25604 + __asm__("movw %w6, %%ds\n\t"
25605 + "lcall *%%ss:(%%esi); cld\n\t"
25606 + "push %%ss\n\t"
25607 + "pop %%ds\n\t"
25608 "jc 1f\n\t"
25609 "xor %%ah, %%ah\n"
25610 "1:"
25611 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25612 "c" (value),
25613 "b" (bx),
25614 "D" ((long)reg),
25615 - "S" (&pci_indirect));
25616 + "S" (&pci_indirect),
25617 + "r" (__PCIBIOS_DS));
25618 break;
25619 }
25620
25621 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
25622
25623 DBG("PCI: Fetching IRQ routing table... ");
25624 __asm__("push %%es\n\t"
25625 + "movw %w8, %%ds\n\t"
25626 "push %%ds\n\t"
25627 "pop %%es\n\t"
25628 - "lcall *(%%esi); cld\n\t"
25629 + "lcall *%%ss:(%%esi); cld\n\t"
25630 "pop %%es\n\t"
25631 + "push %%ss\n\t"
25632 + "pop %%ds\n"
25633 "jc 1f\n\t"
25634 "xor %%ah, %%ah\n"
25635 "1:"
25636 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
25637 "1" (0),
25638 "D" ((long) &opt),
25639 "S" (&pci_indirect),
25640 - "m" (opt)
25641 + "m" (opt),
25642 + "r" (__PCIBIOS_DS)
25643 : "memory");
25644 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
25645 if (ret & 0xff00)
25646 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
25647 {
25648 int ret;
25649
25650 - __asm__("lcall *(%%esi); cld\n\t"
25651 + __asm__("movw %w5, %%ds\n\t"
25652 + "lcall *%%ss:(%%esi); cld\n\t"
25653 + "push %%ss\n\t"
25654 + "pop %%ds\n"
25655 "jc 1f\n\t"
25656 "xor %%ah, %%ah\n"
25657 "1:"
25658 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
25659 : "0" (PCIBIOS_SET_PCI_HW_INT),
25660 "b" ((dev->bus->number << 8) | dev->devfn),
25661 "c" ((irq << 8) | (pin + 10)),
25662 - "S" (&pci_indirect));
25663 + "S" (&pci_indirect),
25664 + "r" (__PCIBIOS_DS));
25665 return !(ret & 0xff00);
25666 }
25667 EXPORT_SYMBOL(pcibios_set_irq_routing);
25668 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
25669 index 40e4469..1ab536e 100644
25670 --- a/arch/x86/platform/efi/efi_32.c
25671 +++ b/arch/x86/platform/efi/efi_32.c
25672 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
25673 {
25674 struct desc_ptr gdt_descr;
25675
25676 +#ifdef CONFIG_PAX_KERNEXEC
25677 + struct desc_struct d;
25678 +#endif
25679 +
25680 local_irq_save(efi_rt_eflags);
25681
25682 load_cr3(initial_page_table);
25683 __flush_tlb_all();
25684
25685 +#ifdef CONFIG_PAX_KERNEXEC
25686 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
25687 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
25688 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
25689 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
25690 +#endif
25691 +
25692 gdt_descr.address = __pa(get_cpu_gdt_table(0));
25693 gdt_descr.size = GDT_SIZE - 1;
25694 load_gdt(&gdt_descr);
25695 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
25696 {
25697 struct desc_ptr gdt_descr;
25698
25699 +#ifdef CONFIG_PAX_KERNEXEC
25700 + struct desc_struct d;
25701 +
25702 + memset(&d, 0, sizeof d);
25703 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
25704 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
25705 +#endif
25706 +
25707 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
25708 gdt_descr.size = GDT_SIZE - 1;
25709 load_gdt(&gdt_descr);
25710 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
25711 index fbe66e6..c5c0dd2 100644
25712 --- a/arch/x86/platform/efi/efi_stub_32.S
25713 +++ b/arch/x86/platform/efi/efi_stub_32.S
25714 @@ -6,7 +6,9 @@
25715 */
25716
25717 #include <linux/linkage.h>
25718 +#include <linux/init.h>
25719 #include <asm/page_types.h>
25720 +#include <asm/segment.h>
25721
25722 /*
25723 * efi_call_phys(void *, ...) is a function with variable parameters.
25724 @@ -20,7 +22,7 @@
25725 * service functions will comply with gcc calling convention, too.
25726 */
25727
25728 -.text
25729 +__INIT
25730 ENTRY(efi_call_phys)
25731 /*
25732 * 0. The function can only be called in Linux kernel. So CS has been
25733 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
25734 * The mapping of lower virtual memory has been created in prelog and
25735 * epilog.
25736 */
25737 - movl $1f, %edx
25738 - subl $__PAGE_OFFSET, %edx
25739 - jmp *%edx
25740 + movl $(__KERNEXEC_EFI_DS), %edx
25741 + mov %edx, %ds
25742 + mov %edx, %es
25743 + mov %edx, %ss
25744 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
25745 1:
25746
25747 /*
25748 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
25749 * parameter 2, ..., param n. To make things easy, we save the return
25750 * address of efi_call_phys in a global variable.
25751 */
25752 - popl %edx
25753 - movl %edx, saved_return_addr
25754 - /* get the function pointer into ECX*/
25755 - popl %ecx
25756 - movl %ecx, efi_rt_function_ptr
25757 - movl $2f, %edx
25758 - subl $__PAGE_OFFSET, %edx
25759 - pushl %edx
25760 + popl (saved_return_addr)
25761 + popl (efi_rt_function_ptr)
25762
25763 /*
25764 * 3. Clear PG bit in %CR0.
25765 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
25766 /*
25767 * 5. Call the physical function.
25768 */
25769 - jmp *%ecx
25770 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
25771
25772 -2:
25773 /*
25774 * 6. After EFI runtime service returns, control will return to
25775 * following instruction. We'd better readjust stack pointer first.
25776 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
25777 movl %cr0, %edx
25778 orl $0x80000000, %edx
25779 movl %edx, %cr0
25780 - jmp 1f
25781 -1:
25782 +
25783 /*
25784 * 8. Now restore the virtual mode from flat mode by
25785 * adding EIP with PAGE_OFFSET.
25786 */
25787 - movl $1f, %edx
25788 - jmp *%edx
25789 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
25790 1:
25791 + movl $(__KERNEL_DS), %edx
25792 + mov %edx, %ds
25793 + mov %edx, %es
25794 + mov %edx, %ss
25795
25796 /*
25797 * 9. Balance the stack. And because EAX contain the return value,
25798 * we'd better not clobber it.
25799 */
25800 - leal efi_rt_function_ptr, %edx
25801 - movl (%edx), %ecx
25802 - pushl %ecx
25803 + pushl (efi_rt_function_ptr)
25804
25805 /*
25806 - * 10. Push the saved return address onto the stack and return.
25807 + * 10. Return to the saved return address.
25808 */
25809 - leal saved_return_addr, %edx
25810 - movl (%edx), %ecx
25811 - pushl %ecx
25812 - ret
25813 + jmpl *(saved_return_addr)
25814 ENDPROC(efi_call_phys)
25815 .previous
25816
25817 -.data
25818 +__INITDATA
25819 saved_return_addr:
25820 .long 0
25821 efi_rt_function_ptr:
25822 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
25823 index 4c07cca..2c8427d 100644
25824 --- a/arch/x86/platform/efi/efi_stub_64.S
25825 +++ b/arch/x86/platform/efi/efi_stub_64.S
25826 @@ -7,6 +7,7 @@
25827 */
25828
25829 #include <linux/linkage.h>
25830 +#include <asm/alternative-asm.h>
25831
25832 #define SAVE_XMM \
25833 mov %rsp, %rax; \
25834 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
25835 call *%rdi
25836 addq $32, %rsp
25837 RESTORE_XMM
25838 + pax_force_retaddr 0, 1
25839 ret
25840 ENDPROC(efi_call0)
25841
25842 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
25843 call *%rdi
25844 addq $32, %rsp
25845 RESTORE_XMM
25846 + pax_force_retaddr 0, 1
25847 ret
25848 ENDPROC(efi_call1)
25849
25850 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
25851 call *%rdi
25852 addq $32, %rsp
25853 RESTORE_XMM
25854 + pax_force_retaddr 0, 1
25855 ret
25856 ENDPROC(efi_call2)
25857
25858 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
25859 call *%rdi
25860 addq $32, %rsp
25861 RESTORE_XMM
25862 + pax_force_retaddr 0, 1
25863 ret
25864 ENDPROC(efi_call3)
25865
25866 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
25867 call *%rdi
25868 addq $32, %rsp
25869 RESTORE_XMM
25870 + pax_force_retaddr 0, 1
25871 ret
25872 ENDPROC(efi_call4)
25873
25874 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
25875 call *%rdi
25876 addq $48, %rsp
25877 RESTORE_XMM
25878 + pax_force_retaddr 0, 1
25879 ret
25880 ENDPROC(efi_call5)
25881
25882 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
25883 call *%rdi
25884 addq $48, %rsp
25885 RESTORE_XMM
25886 + pax_force_retaddr 0, 1
25887 ret
25888 ENDPROC(efi_call6)
25889 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
25890 index 475e2cd..1b8e708 100644
25891 --- a/arch/x86/platform/mrst/mrst.c
25892 +++ b/arch/x86/platform/mrst/mrst.c
25893 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
25894 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
25895 int sfi_mrtc_num;
25896
25897 -static void mrst_power_off(void)
25898 +static __noreturn void mrst_power_off(void)
25899 {
25900 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
25901 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
25902 + BUG();
25903 }
25904
25905 -static void mrst_reboot(void)
25906 +static __noreturn void mrst_reboot(void)
25907 {
25908 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
25909 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
25910 else
25911 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
25912 + BUG();
25913 }
25914
25915 /* parse all the mtimer info to a static mtimer array */
25916 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
25917 index f10c0af..3ec1f95 100644
25918 --- a/arch/x86/power/cpu.c
25919 +++ b/arch/x86/power/cpu.c
25920 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
25921 static void fix_processor_context(void)
25922 {
25923 int cpu = smp_processor_id();
25924 - struct tss_struct *t = &per_cpu(init_tss, cpu);
25925 + struct tss_struct *t = init_tss + cpu;
25926
25927 set_tss_desc(cpu, t); /*
25928 * This just modifies memory; should not be
25929 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
25930 */
25931
25932 #ifdef CONFIG_X86_64
25933 + pax_open_kernel();
25934 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
25935 + pax_close_kernel();
25936
25937 syscall_init(); /* This sets MSR_*STAR and related */
25938 #endif
25939 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
25940 index 5d17950..2253fc9 100644
25941 --- a/arch/x86/vdso/Makefile
25942 +++ b/arch/x86/vdso/Makefile
25943 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
25944 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
25945 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
25946
25947 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
25948 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
25949 GCOV_PROFILE := n
25950
25951 #
25952 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
25953 index 468d591..8e80a0a 100644
25954 --- a/arch/x86/vdso/vdso32-setup.c
25955 +++ b/arch/x86/vdso/vdso32-setup.c
25956 @@ -25,6 +25,7 @@
25957 #include <asm/tlbflush.h>
25958 #include <asm/vdso.h>
25959 #include <asm/proto.h>
25960 +#include <asm/mman.h>
25961
25962 enum {
25963 VDSO_DISABLED = 0,
25964 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
25965 void enable_sep_cpu(void)
25966 {
25967 int cpu = get_cpu();
25968 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
25969 + struct tss_struct *tss = init_tss + cpu;
25970
25971 if (!boot_cpu_has(X86_FEATURE_SEP)) {
25972 put_cpu();
25973 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
25974 gate_vma.vm_start = FIXADDR_USER_START;
25975 gate_vma.vm_end = FIXADDR_USER_END;
25976 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
25977 - gate_vma.vm_page_prot = __P101;
25978 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
25979 /*
25980 * Make sure the vDSO gets into every core dump.
25981 * Dumping its contents makes post-mortem fully interpretable later
25982 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
25983 if (compat)
25984 addr = VDSO_HIGH_BASE;
25985 else {
25986 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
25987 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
25988 if (IS_ERR_VALUE(addr)) {
25989 ret = addr;
25990 goto up_fail;
25991 }
25992 }
25993
25994 - current->mm->context.vdso = (void *)addr;
25995 + current->mm->context.vdso = addr;
25996
25997 if (compat_uses_vma || !compat) {
25998 /*
25999 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26000 }
26001
26002 current_thread_info()->sysenter_return =
26003 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26004 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26005
26006 up_fail:
26007 if (ret)
26008 - current->mm->context.vdso = NULL;
26009 + current->mm->context.vdso = 0;
26010
26011 up_write(&mm->mmap_sem);
26012
26013 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26014
26015 const char *arch_vma_name(struct vm_area_struct *vma)
26016 {
26017 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26018 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26019 return "[vdso]";
26020 +
26021 +#ifdef CONFIG_PAX_SEGMEXEC
26022 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26023 + return "[vdso]";
26024 +#endif
26025 +
26026 return NULL;
26027 }
26028
26029 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26030 * Check to see if the corresponding task was created in compat vdso
26031 * mode.
26032 */
26033 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26034 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26035 return &gate_vma;
26036 return NULL;
26037 }
26038 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26039 index 153407c..611cba9 100644
26040 --- a/arch/x86/vdso/vma.c
26041 +++ b/arch/x86/vdso/vma.c
26042 @@ -16,8 +16,6 @@
26043 #include <asm/vdso.h>
26044 #include <asm/page.h>
26045
26046 -unsigned int __read_mostly vdso_enabled = 1;
26047 -
26048 extern char vdso_start[], vdso_end[];
26049 extern unsigned short vdso_sync_cpuid;
26050
26051 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26052 * unaligned here as a result of stack start randomization.
26053 */
26054 addr = PAGE_ALIGN(addr);
26055 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26056
26057 return addr;
26058 }
26059 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26060 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26061 {
26062 struct mm_struct *mm = current->mm;
26063 - unsigned long addr;
26064 + unsigned long addr = 0;
26065 int ret;
26066
26067 - if (!vdso_enabled)
26068 - return 0;
26069 -
26070 down_write(&mm->mmap_sem);
26071 +
26072 +#ifdef CONFIG_PAX_RANDMMAP
26073 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26074 +#endif
26075 +
26076 addr = vdso_addr(mm->start_stack, vdso_size);
26077 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26078 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26079 if (IS_ERR_VALUE(addr)) {
26080 ret = addr;
26081 goto up_fail;
26082 }
26083
26084 - current->mm->context.vdso = (void *)addr;
26085 + mm->context.vdso = addr;
26086
26087 ret = install_special_mapping(mm, addr, vdso_size,
26088 VM_READ|VM_EXEC|
26089 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
26090 VM_ALWAYSDUMP,
26091 vdso_pages);
26092 - if (ret) {
26093 - current->mm->context.vdso = NULL;
26094 - goto up_fail;
26095 - }
26096 +
26097 + if (ret)
26098 + mm->context.vdso = 0;
26099
26100 up_fail:
26101 up_write(&mm->mmap_sem);
26102 return ret;
26103 }
26104 -
26105 -static __init int vdso_setup(char *s)
26106 -{
26107 - vdso_enabled = simple_strtoul(s, NULL, 0);
26108 - return 0;
26109 -}
26110 -__setup("vdso=", vdso_setup);
26111 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26112 index 4172af8..2c8ed7f 100644
26113 --- a/arch/x86/xen/enlighten.c
26114 +++ b/arch/x86/xen/enlighten.c
26115 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26116
26117 struct shared_info xen_dummy_shared_info;
26118
26119 -void *xen_initial_gdt;
26120 -
26121 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
26122 __read_mostly int xen_have_vector_callback;
26123 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
26124 @@ -1029,30 +1027,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
26125 #endif
26126 };
26127
26128 -static void xen_reboot(int reason)
26129 +static __noreturn void xen_reboot(int reason)
26130 {
26131 struct sched_shutdown r = { .reason = reason };
26132
26133 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
26134 - BUG();
26135 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
26136 + BUG();
26137 }
26138
26139 -static void xen_restart(char *msg)
26140 +static __noreturn void xen_restart(char *msg)
26141 {
26142 xen_reboot(SHUTDOWN_reboot);
26143 }
26144
26145 -static void xen_emergency_restart(void)
26146 +static __noreturn void xen_emergency_restart(void)
26147 {
26148 xen_reboot(SHUTDOWN_reboot);
26149 }
26150
26151 -static void xen_machine_halt(void)
26152 +static __noreturn void xen_machine_halt(void)
26153 {
26154 xen_reboot(SHUTDOWN_poweroff);
26155 }
26156
26157 -static void xen_machine_power_off(void)
26158 +static __noreturn void xen_machine_power_off(void)
26159 {
26160 if (pm_power_off)
26161 pm_power_off();
26162 @@ -1155,7 +1153,17 @@ asmlinkage void __init xen_start_kernel(void)
26163 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26164
26165 /* Work out if we support NX */
26166 - x86_configure_nx();
26167 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26168 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26169 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26170 + unsigned l, h;
26171 +
26172 + __supported_pte_mask |= _PAGE_NX;
26173 + rdmsr(MSR_EFER, l, h);
26174 + l |= EFER_NX;
26175 + wrmsr(MSR_EFER, l, h);
26176 + }
26177 +#endif
26178
26179 xen_setup_features();
26180
26181 @@ -1186,13 +1194,6 @@ asmlinkage void __init xen_start_kernel(void)
26182
26183 machine_ops = xen_machine_ops;
26184
26185 - /*
26186 - * The only reliable way to retain the initial address of the
26187 - * percpu gdt_page is to remember it here, so we can go and
26188 - * mark it RW later, when the initial percpu area is freed.
26189 - */
26190 - xen_initial_gdt = &per_cpu(gdt_page, 0);
26191 -
26192 xen_smp_init();
26193
26194 #ifdef CONFIG_ACPI_NUMA
26195 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26196 index 95c1cf6..4bfa5be 100644
26197 --- a/arch/x86/xen/mmu.c
26198 +++ b/arch/x86/xen/mmu.c
26199 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26200 convert_pfn_mfn(init_level4_pgt);
26201 convert_pfn_mfn(level3_ident_pgt);
26202 convert_pfn_mfn(level3_kernel_pgt);
26203 + convert_pfn_mfn(level3_vmalloc_start_pgt);
26204 + convert_pfn_mfn(level3_vmalloc_end_pgt);
26205 + convert_pfn_mfn(level3_vmemmap_pgt);
26206
26207 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26208 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26209 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26210 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26211 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26212 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26213 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26214 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26215 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26216 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26217 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26218 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26219 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26220
26221 @@ -1958,6 +1965,7 @@ static void __init xen_post_allocator_init(void)
26222 pv_mmu_ops.set_pud = xen_set_pud;
26223 #if PAGETABLE_LEVELS == 4
26224 pv_mmu_ops.set_pgd = xen_set_pgd;
26225 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26226 #endif
26227
26228 /* This will work as long as patching hasn't happened yet
26229 @@ -2039,6 +2047,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
26230 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26231 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26232 .set_pgd = xen_set_pgd_hyper,
26233 + .set_pgd_batched = xen_set_pgd_hyper,
26234
26235 .alloc_pud = xen_alloc_pmd_init,
26236 .release_pud = xen_release_pmd_init,
26237 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26238 index 501d4e0..e877605 100644
26239 --- a/arch/x86/xen/smp.c
26240 +++ b/arch/x86/xen/smp.c
26241 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26242 {
26243 BUG_ON(smp_processor_id() != 0);
26244 native_smp_prepare_boot_cpu();
26245 -
26246 - /* We've switched to the "real" per-cpu gdt, so make sure the
26247 - old memory can be recycled */
26248 - make_lowmem_page_readwrite(xen_initial_gdt);
26249 -
26250 xen_filter_cpu_maps();
26251 xen_setup_vcpu_info_placement();
26252 }
26253 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26254 gdt = get_cpu_gdt_table(cpu);
26255
26256 ctxt->flags = VGCF_IN_KERNEL;
26257 - ctxt->user_regs.ds = __USER_DS;
26258 - ctxt->user_regs.es = __USER_DS;
26259 + ctxt->user_regs.ds = __KERNEL_DS;
26260 + ctxt->user_regs.es = __KERNEL_DS;
26261 ctxt->user_regs.ss = __KERNEL_DS;
26262 #ifdef CONFIG_X86_32
26263 ctxt->user_regs.fs = __KERNEL_PERCPU;
26264 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26265 + savesegment(gs, ctxt->user_regs.gs);
26266 #else
26267 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26268 #endif
26269 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26270 int rc;
26271
26272 per_cpu(current_task, cpu) = idle;
26273 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26274 #ifdef CONFIG_X86_32
26275 irq_ctx_init(cpu);
26276 #else
26277 clear_tsk_thread_flag(idle, TIF_FORK);
26278 - per_cpu(kernel_stack, cpu) =
26279 - (unsigned long)task_stack_page(idle) -
26280 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26281 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26282 #endif
26283 xen_setup_runstate_info(cpu);
26284 xen_setup_timer(cpu);
26285 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26286 index b040b0e..8cc4fe0 100644
26287 --- a/arch/x86/xen/xen-asm_32.S
26288 +++ b/arch/x86/xen/xen-asm_32.S
26289 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
26290 ESP_OFFSET=4 # bytes pushed onto stack
26291
26292 /*
26293 - * Store vcpu_info pointer for easy access. Do it this way to
26294 - * avoid having to reload %fs
26295 + * Store vcpu_info pointer for easy access.
26296 */
26297 #ifdef CONFIG_SMP
26298 - GET_THREAD_INFO(%eax)
26299 - movl TI_cpu(%eax), %eax
26300 - movl __per_cpu_offset(,%eax,4), %eax
26301 - mov xen_vcpu(%eax), %eax
26302 + push %fs
26303 + mov $(__KERNEL_PERCPU), %eax
26304 + mov %eax, %fs
26305 + mov PER_CPU_VAR(xen_vcpu), %eax
26306 + pop %fs
26307 #else
26308 movl xen_vcpu, %eax
26309 #endif
26310 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
26311 index aaa7291..3f77960 100644
26312 --- a/arch/x86/xen/xen-head.S
26313 +++ b/arch/x86/xen/xen-head.S
26314 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
26315 #ifdef CONFIG_X86_32
26316 mov %esi,xen_start_info
26317 mov $init_thread_union+THREAD_SIZE,%esp
26318 +#ifdef CONFIG_SMP
26319 + movl $cpu_gdt_table,%edi
26320 + movl $__per_cpu_load,%eax
26321 + movw %ax,__KERNEL_PERCPU + 2(%edi)
26322 + rorl $16,%eax
26323 + movb %al,__KERNEL_PERCPU + 4(%edi)
26324 + movb %ah,__KERNEL_PERCPU + 7(%edi)
26325 + movl $__per_cpu_end - 1,%eax
26326 + subl $__per_cpu_start,%eax
26327 + movw %ax,__KERNEL_PERCPU + 0(%edi)
26328 +#endif
26329 #else
26330 mov %rsi,xen_start_info
26331 mov $init_thread_union+THREAD_SIZE,%rsp
26332 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
26333 index b095739..8c17bcd 100644
26334 --- a/arch/x86/xen/xen-ops.h
26335 +++ b/arch/x86/xen/xen-ops.h
26336 @@ -10,8 +10,6 @@
26337 extern const char xen_hypervisor_callback[];
26338 extern const char xen_failsafe_callback[];
26339
26340 -extern void *xen_initial_gdt;
26341 -
26342 struct trap_info;
26343 void xen_copy_trap_info(struct trap_info *traps);
26344
26345 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
26346 index 525bd3d..ef888b1 100644
26347 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
26348 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
26349 @@ -119,9 +119,9 @@
26350 ----------------------------------------------------------------------*/
26351
26352 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
26353 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
26354 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
26355 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
26356 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26357
26358 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
26359 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
26360 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
26361 index 2f33760..835e50a 100644
26362 --- a/arch/xtensa/variants/fsf/include/variant/core.h
26363 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
26364 @@ -11,6 +11,7 @@
26365 #ifndef _XTENSA_CORE_H
26366 #define _XTENSA_CORE_H
26367
26368 +#include <linux/const.h>
26369
26370 /****************************************************************************
26371 Parameters Useful for Any Code, USER or PRIVILEGED
26372 @@ -112,9 +113,9 @@
26373 ----------------------------------------------------------------------*/
26374
26375 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26376 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26377 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26378 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26379 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26380
26381 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
26382 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
26383 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
26384 index af00795..2bb8105 100644
26385 --- a/arch/xtensa/variants/s6000/include/variant/core.h
26386 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
26387 @@ -11,6 +11,7 @@
26388 #ifndef _XTENSA_CORE_CONFIGURATION_H
26389 #define _XTENSA_CORE_CONFIGURATION_H
26390
26391 +#include <linux/const.h>
26392
26393 /****************************************************************************
26394 Parameters Useful for Any Code, USER or PRIVILEGED
26395 @@ -118,9 +119,9 @@
26396 ----------------------------------------------------------------------*/
26397
26398 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26399 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26400 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26401 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26402 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26403
26404 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
26405 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
26406 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
26407 index 58916af..9cb880b 100644
26408 --- a/block/blk-iopoll.c
26409 +++ b/block/blk-iopoll.c
26410 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
26411 }
26412 EXPORT_SYMBOL(blk_iopoll_complete);
26413
26414 -static void blk_iopoll_softirq(struct softirq_action *h)
26415 +static void blk_iopoll_softirq(void)
26416 {
26417 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
26418 int rearm = 0, budget = blk_iopoll_budget;
26419 diff --git a/block/blk-map.c b/block/blk-map.c
26420 index 623e1cd..ca1e109 100644
26421 --- a/block/blk-map.c
26422 +++ b/block/blk-map.c
26423 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
26424 if (!len || !kbuf)
26425 return -EINVAL;
26426
26427 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
26428 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
26429 if (do_copy)
26430 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
26431 else
26432 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
26433 index 1366a89..e17f54b 100644
26434 --- a/block/blk-softirq.c
26435 +++ b/block/blk-softirq.c
26436 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
26437 * Softirq action handler - move entries to local list and loop over them
26438 * while passing them to the queue registered handler.
26439 */
26440 -static void blk_done_softirq(struct softirq_action *h)
26441 +static void blk_done_softirq(void)
26442 {
26443 struct list_head *cpu_list, local_list;
26444
26445 diff --git a/block/bsg.c b/block/bsg.c
26446 index ff64ae3..593560c 100644
26447 --- a/block/bsg.c
26448 +++ b/block/bsg.c
26449 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
26450 struct sg_io_v4 *hdr, struct bsg_device *bd,
26451 fmode_t has_write_perm)
26452 {
26453 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26454 + unsigned char *cmdptr;
26455 +
26456 if (hdr->request_len > BLK_MAX_CDB) {
26457 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
26458 if (!rq->cmd)
26459 return -ENOMEM;
26460 - }
26461 + cmdptr = rq->cmd;
26462 + } else
26463 + cmdptr = tmpcmd;
26464
26465 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
26466 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
26467 hdr->request_len))
26468 return -EFAULT;
26469
26470 + if (cmdptr != rq->cmd)
26471 + memcpy(rq->cmd, cmdptr, hdr->request_len);
26472 +
26473 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
26474 if (blk_verify_command(rq->cmd, has_write_perm))
26475 return -EPERM;
26476 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
26477 index 7c668c8..db3521c 100644
26478 --- a/block/compat_ioctl.c
26479 +++ b/block/compat_ioctl.c
26480 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
26481 err |= __get_user(f->spec1, &uf->spec1);
26482 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
26483 err |= __get_user(name, &uf->name);
26484 - f->name = compat_ptr(name);
26485 + f->name = (void __force_kernel *)compat_ptr(name);
26486 if (err) {
26487 err = -EFAULT;
26488 goto out;
26489 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
26490 index 6296b40..417c00f 100644
26491 --- a/block/partitions/efi.c
26492 +++ b/block/partitions/efi.c
26493 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
26494 if (!gpt)
26495 return NULL;
26496
26497 + if (!le32_to_cpu(gpt->num_partition_entries))
26498 + return NULL;
26499 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
26500 + if (!pte)
26501 + return NULL;
26502 +
26503 count = le32_to_cpu(gpt->num_partition_entries) *
26504 le32_to_cpu(gpt->sizeof_partition_entry);
26505 - if (!count)
26506 - return NULL;
26507 - pte = kzalloc(count, GFP_KERNEL);
26508 - if (!pte)
26509 - return NULL;
26510 -
26511 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
26512 (u8 *) pte,
26513 count) < count) {
26514 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
26515 index 260fa80..e8f3caf 100644
26516 --- a/block/scsi_ioctl.c
26517 +++ b/block/scsi_ioctl.c
26518 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
26519 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
26520 struct sg_io_hdr *hdr, fmode_t mode)
26521 {
26522 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
26523 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26524 + unsigned char *cmdptr;
26525 +
26526 + if (rq->cmd != rq->__cmd)
26527 + cmdptr = rq->cmd;
26528 + else
26529 + cmdptr = tmpcmd;
26530 +
26531 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
26532 return -EFAULT;
26533 +
26534 + if (cmdptr != rq->cmd)
26535 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
26536 +
26537 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
26538 return -EPERM;
26539
26540 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
26541 int err;
26542 unsigned int in_len, out_len, bytes, opcode, cmdlen;
26543 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
26544 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26545 + unsigned char *cmdptr;
26546
26547 if (!sic)
26548 return -EINVAL;
26549 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
26550 */
26551 err = -EFAULT;
26552 rq->cmd_len = cmdlen;
26553 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
26554 +
26555 + if (rq->cmd != rq->__cmd)
26556 + cmdptr = rq->cmd;
26557 + else
26558 + cmdptr = tmpcmd;
26559 +
26560 + if (copy_from_user(cmdptr, sic->data, cmdlen))
26561 goto error;
26562
26563 + if (rq->cmd != cmdptr)
26564 + memcpy(rq->cmd, cmdptr, cmdlen);
26565 +
26566 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
26567 goto error;
26568
26569 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
26570 index 671d4d6..5f24030 100644
26571 --- a/crypto/cryptd.c
26572 +++ b/crypto/cryptd.c
26573 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
26574
26575 struct cryptd_blkcipher_request_ctx {
26576 crypto_completion_t complete;
26577 -};
26578 +} __no_const;
26579
26580 struct cryptd_hash_ctx {
26581 struct crypto_shash *child;
26582 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
26583
26584 struct cryptd_aead_request_ctx {
26585 crypto_completion_t complete;
26586 -};
26587 +} __no_const;
26588
26589 static void cryptd_queue_worker(struct work_struct *work);
26590
26591 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
26592 index 5d41894..22021e4 100644
26593 --- a/drivers/acpi/apei/cper.c
26594 +++ b/drivers/acpi/apei/cper.c
26595 @@ -38,12 +38,12 @@
26596 */
26597 u64 cper_next_record_id(void)
26598 {
26599 - static atomic64_t seq;
26600 + static atomic64_unchecked_t seq;
26601
26602 - if (!atomic64_read(&seq))
26603 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
26604 + if (!atomic64_read_unchecked(&seq))
26605 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
26606
26607 - return atomic64_inc_return(&seq);
26608 + return atomic64_inc_return_unchecked(&seq);
26609 }
26610 EXPORT_SYMBOL_GPL(cper_next_record_id);
26611
26612 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
26613 index b258cab..3fb7da7 100644
26614 --- a/drivers/acpi/ec_sys.c
26615 +++ b/drivers/acpi/ec_sys.c
26616 @@ -12,6 +12,7 @@
26617 #include <linux/acpi.h>
26618 #include <linux/debugfs.h>
26619 #include <linux/module.h>
26620 +#include <linux/uaccess.h>
26621 #include "internal.h"
26622
26623 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
26624 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
26625 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
26626 */
26627 unsigned int size = EC_SPACE_SIZE;
26628 - u8 *data = (u8 *) buf;
26629 + u8 data;
26630 loff_t init_off = *off;
26631 int err = 0;
26632
26633 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
26634 size = count;
26635
26636 while (size) {
26637 - err = ec_read(*off, &data[*off - init_off]);
26638 + err = ec_read(*off, &data);
26639 if (err)
26640 return err;
26641 + if (put_user(data, &buf[*off - init_off]))
26642 + return -EFAULT;
26643 *off += 1;
26644 size--;
26645 }
26646 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
26647
26648 unsigned int size = count;
26649 loff_t init_off = *off;
26650 - u8 *data = (u8 *) buf;
26651 int err = 0;
26652
26653 if (*off >= EC_SPACE_SIZE)
26654 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
26655 }
26656
26657 while (size) {
26658 - u8 byte_write = data[*off - init_off];
26659 + u8 byte_write;
26660 + if (get_user(byte_write, &buf[*off - init_off]))
26661 + return -EFAULT;
26662 err = ec_write(*off, byte_write);
26663 if (err)
26664 return err;
26665 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
26666 index 251c7b62..000462d 100644
26667 --- a/drivers/acpi/proc.c
26668 +++ b/drivers/acpi/proc.c
26669 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
26670 size_t count, loff_t * ppos)
26671 {
26672 struct list_head *node, *next;
26673 - char strbuf[5];
26674 - char str[5] = "";
26675 - unsigned int len = count;
26676 + char strbuf[5] = {0};
26677
26678 - if (len > 4)
26679 - len = 4;
26680 - if (len < 0)
26681 + if (count > 4)
26682 + count = 4;
26683 + if (copy_from_user(strbuf, buffer, count))
26684 return -EFAULT;
26685 -
26686 - if (copy_from_user(strbuf, buffer, len))
26687 - return -EFAULT;
26688 - strbuf[len] = '\0';
26689 - sscanf(strbuf, "%s", str);
26690 + strbuf[count] = '\0';
26691
26692 mutex_lock(&acpi_device_lock);
26693 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
26694 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
26695 if (!dev->wakeup.flags.valid)
26696 continue;
26697
26698 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
26699 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
26700 if (device_can_wakeup(&dev->dev)) {
26701 bool enable = !device_may_wakeup(&dev->dev);
26702 device_set_wakeup_enable(&dev->dev, enable);
26703 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
26704 index 8ae05ce..7dbbed9 100644
26705 --- a/drivers/acpi/processor_driver.c
26706 +++ b/drivers/acpi/processor_driver.c
26707 @@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
26708 return 0;
26709 #endif
26710
26711 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
26712 + BUG_ON(pr->id >= nr_cpu_ids);
26713
26714 /*
26715 * Buggy BIOS check
26716 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
26717 index c06e0ec..a2c06ba 100644
26718 --- a/drivers/ata/libata-core.c
26719 +++ b/drivers/ata/libata-core.c
26720 @@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
26721 struct ata_port *ap;
26722 unsigned int tag;
26723
26724 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26725 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26726 ap = qc->ap;
26727
26728 qc->flags = 0;
26729 @@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
26730 struct ata_port *ap;
26731 struct ata_link *link;
26732
26733 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26734 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26735 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
26736 ap = qc->ap;
26737 link = qc->dev->link;
26738 @@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
26739 return;
26740
26741 spin_lock(&lock);
26742 + pax_open_kernel();
26743
26744 for (cur = ops->inherits; cur; cur = cur->inherits) {
26745 void **inherit = (void **)cur;
26746 @@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
26747 if (IS_ERR(*pp))
26748 *pp = NULL;
26749
26750 - ops->inherits = NULL;
26751 + *(struct ata_port_operations **)&ops->inherits = NULL;
26752
26753 + pax_close_kernel();
26754 spin_unlock(&lock);
26755 }
26756
26757 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
26758 index 048589f..4002b98 100644
26759 --- a/drivers/ata/pata_arasan_cf.c
26760 +++ b/drivers/ata/pata_arasan_cf.c
26761 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
26762 /* Handle platform specific quirks */
26763 if (pdata->quirk) {
26764 if (pdata->quirk & CF_BROKEN_PIO) {
26765 - ap->ops->set_piomode = NULL;
26766 + pax_open_kernel();
26767 + *(void **)&ap->ops->set_piomode = NULL;
26768 + pax_close_kernel();
26769 ap->pio_mask = 0;
26770 }
26771 if (pdata->quirk & CF_BROKEN_MWDMA)
26772 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
26773 index f9b983a..887b9d8 100644
26774 --- a/drivers/atm/adummy.c
26775 +++ b/drivers/atm/adummy.c
26776 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
26777 vcc->pop(vcc, skb);
26778 else
26779 dev_kfree_skb_any(skb);
26780 - atomic_inc(&vcc->stats->tx);
26781 + atomic_inc_unchecked(&vcc->stats->tx);
26782
26783 return 0;
26784 }
26785 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
26786 index f8f41e0..1f987dd 100644
26787 --- a/drivers/atm/ambassador.c
26788 +++ b/drivers/atm/ambassador.c
26789 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
26790 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26791
26792 // VC layer stats
26793 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26794 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26795
26796 // free the descriptor
26797 kfree (tx_descr);
26798 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
26799 dump_skb ("<<<", vc, skb);
26800
26801 // VC layer stats
26802 - atomic_inc(&atm_vcc->stats->rx);
26803 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26804 __net_timestamp(skb);
26805 // end of our responsibility
26806 atm_vcc->push (atm_vcc, skb);
26807 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
26808 } else {
26809 PRINTK (KERN_INFO, "dropped over-size frame");
26810 // should we count this?
26811 - atomic_inc(&atm_vcc->stats->rx_drop);
26812 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26813 }
26814
26815 } else {
26816 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
26817 }
26818
26819 if (check_area (skb->data, skb->len)) {
26820 - atomic_inc(&atm_vcc->stats->tx_err);
26821 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26822 return -ENOMEM; // ?
26823 }
26824
26825 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
26826 index b22d71c..d6e1049 100644
26827 --- a/drivers/atm/atmtcp.c
26828 +++ b/drivers/atm/atmtcp.c
26829 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26830 if (vcc->pop) vcc->pop(vcc,skb);
26831 else dev_kfree_skb(skb);
26832 if (dev_data) return 0;
26833 - atomic_inc(&vcc->stats->tx_err);
26834 + atomic_inc_unchecked(&vcc->stats->tx_err);
26835 return -ENOLINK;
26836 }
26837 size = skb->len+sizeof(struct atmtcp_hdr);
26838 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26839 if (!new_skb) {
26840 if (vcc->pop) vcc->pop(vcc,skb);
26841 else dev_kfree_skb(skb);
26842 - atomic_inc(&vcc->stats->tx_err);
26843 + atomic_inc_unchecked(&vcc->stats->tx_err);
26844 return -ENOBUFS;
26845 }
26846 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26847 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26848 if (vcc->pop) vcc->pop(vcc,skb);
26849 else dev_kfree_skb(skb);
26850 out_vcc->push(out_vcc,new_skb);
26851 - atomic_inc(&vcc->stats->tx);
26852 - atomic_inc(&out_vcc->stats->rx);
26853 + atomic_inc_unchecked(&vcc->stats->tx);
26854 + atomic_inc_unchecked(&out_vcc->stats->rx);
26855 return 0;
26856 }
26857
26858 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
26859 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26860 read_unlock(&vcc_sklist_lock);
26861 if (!out_vcc) {
26862 - atomic_inc(&vcc->stats->tx_err);
26863 + atomic_inc_unchecked(&vcc->stats->tx_err);
26864 goto done;
26865 }
26866 skb_pull(skb,sizeof(struct atmtcp_hdr));
26867 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
26868 __net_timestamp(new_skb);
26869 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26870 out_vcc->push(out_vcc,new_skb);
26871 - atomic_inc(&vcc->stats->tx);
26872 - atomic_inc(&out_vcc->stats->rx);
26873 + atomic_inc_unchecked(&vcc->stats->tx);
26874 + atomic_inc_unchecked(&out_vcc->stats->rx);
26875 done:
26876 if (vcc->pop) vcc->pop(vcc,skb);
26877 else dev_kfree_skb(skb);
26878 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
26879 index 956e9ac..133516d 100644
26880 --- a/drivers/atm/eni.c
26881 +++ b/drivers/atm/eni.c
26882 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26883 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26884 vcc->dev->number);
26885 length = 0;
26886 - atomic_inc(&vcc->stats->rx_err);
26887 + atomic_inc_unchecked(&vcc->stats->rx_err);
26888 }
26889 else {
26890 length = ATM_CELL_SIZE-1; /* no HEC */
26891 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26892 size);
26893 }
26894 eff = length = 0;
26895 - atomic_inc(&vcc->stats->rx_err);
26896 + atomic_inc_unchecked(&vcc->stats->rx_err);
26897 }
26898 else {
26899 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26900 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26901 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26902 vcc->dev->number,vcc->vci,length,size << 2,descr);
26903 length = eff = 0;
26904 - atomic_inc(&vcc->stats->rx_err);
26905 + atomic_inc_unchecked(&vcc->stats->rx_err);
26906 }
26907 }
26908 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26909 @@ -771,7 +771,7 @@ rx_dequeued++;
26910 vcc->push(vcc,skb);
26911 pushed++;
26912 }
26913 - atomic_inc(&vcc->stats->rx);
26914 + atomic_inc_unchecked(&vcc->stats->rx);
26915 }
26916 wake_up(&eni_dev->rx_wait);
26917 }
26918 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
26919 PCI_DMA_TODEVICE);
26920 if (vcc->pop) vcc->pop(vcc,skb);
26921 else dev_kfree_skb_irq(skb);
26922 - atomic_inc(&vcc->stats->tx);
26923 + atomic_inc_unchecked(&vcc->stats->tx);
26924 wake_up(&eni_dev->tx_wait);
26925 dma_complete++;
26926 }
26927 @@ -1569,7 +1569,7 @@ tx_complete++;
26928 /*--------------------------------- entries ---------------------------------*/
26929
26930
26931 -static const char *media_name[] __devinitdata = {
26932 +static const char *media_name[] __devinitconst = {
26933 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
26934 "UTP", "05?", "06?", "07?", /* 4- 7 */
26935 "TAXI","09?", "10?", "11?", /* 8-11 */
26936 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
26937 index 5072f8a..fa52520d 100644
26938 --- a/drivers/atm/firestream.c
26939 +++ b/drivers/atm/firestream.c
26940 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
26941 }
26942 }
26943
26944 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26945 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26946
26947 fs_dprintk (FS_DEBUG_TXMEM, "i");
26948 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26949 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
26950 #endif
26951 skb_put (skb, qe->p1 & 0xffff);
26952 ATM_SKB(skb)->vcc = atm_vcc;
26953 - atomic_inc(&atm_vcc->stats->rx);
26954 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26955 __net_timestamp(skb);
26956 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26957 atm_vcc->push (atm_vcc, skb);
26958 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
26959 kfree (pe);
26960 }
26961 if (atm_vcc)
26962 - atomic_inc(&atm_vcc->stats->rx_drop);
26963 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26964 break;
26965 case 0x1f: /* Reassembly abort: no buffers. */
26966 /* Silently increment error counter. */
26967 if (atm_vcc)
26968 - atomic_inc(&atm_vcc->stats->rx_drop);
26969 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26970 break;
26971 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26972 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26973 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
26974 index 361f5ae..7fc552d 100644
26975 --- a/drivers/atm/fore200e.c
26976 +++ b/drivers/atm/fore200e.c
26977 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
26978 #endif
26979 /* check error condition */
26980 if (*entry->status & STATUS_ERROR)
26981 - atomic_inc(&vcc->stats->tx_err);
26982 + atomic_inc_unchecked(&vcc->stats->tx_err);
26983 else
26984 - atomic_inc(&vcc->stats->tx);
26985 + atomic_inc_unchecked(&vcc->stats->tx);
26986 }
26987 }
26988
26989 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
26990 if (skb == NULL) {
26991 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26992
26993 - atomic_inc(&vcc->stats->rx_drop);
26994 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26995 return -ENOMEM;
26996 }
26997
26998 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
26999
27000 dev_kfree_skb_any(skb);
27001
27002 - atomic_inc(&vcc->stats->rx_drop);
27003 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27004 return -ENOMEM;
27005 }
27006
27007 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27008
27009 vcc->push(vcc, skb);
27010 - atomic_inc(&vcc->stats->rx);
27011 + atomic_inc_unchecked(&vcc->stats->rx);
27012
27013 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27014
27015 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27016 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27017 fore200e->atm_dev->number,
27018 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27019 - atomic_inc(&vcc->stats->rx_err);
27020 + atomic_inc_unchecked(&vcc->stats->rx_err);
27021 }
27022 }
27023
27024 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27025 goto retry_here;
27026 }
27027
27028 - atomic_inc(&vcc->stats->tx_err);
27029 + atomic_inc_unchecked(&vcc->stats->tx_err);
27030
27031 fore200e->tx_sat++;
27032 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27033 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27034 index b182c2f..1c6fa8a 100644
27035 --- a/drivers/atm/he.c
27036 +++ b/drivers/atm/he.c
27037 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27038
27039 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27040 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27041 - atomic_inc(&vcc->stats->rx_drop);
27042 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27043 goto return_host_buffers;
27044 }
27045
27046 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27047 RBRQ_LEN_ERR(he_dev->rbrq_head)
27048 ? "LEN_ERR" : "",
27049 vcc->vpi, vcc->vci);
27050 - atomic_inc(&vcc->stats->rx_err);
27051 + atomic_inc_unchecked(&vcc->stats->rx_err);
27052 goto return_host_buffers;
27053 }
27054
27055 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27056 vcc->push(vcc, skb);
27057 spin_lock(&he_dev->global_lock);
27058
27059 - atomic_inc(&vcc->stats->rx);
27060 + atomic_inc_unchecked(&vcc->stats->rx);
27061
27062 return_host_buffers:
27063 ++pdus_assembled;
27064 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27065 tpd->vcc->pop(tpd->vcc, tpd->skb);
27066 else
27067 dev_kfree_skb_any(tpd->skb);
27068 - atomic_inc(&tpd->vcc->stats->tx_err);
27069 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27070 }
27071 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27072 return;
27073 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27074 vcc->pop(vcc, skb);
27075 else
27076 dev_kfree_skb_any(skb);
27077 - atomic_inc(&vcc->stats->tx_err);
27078 + atomic_inc_unchecked(&vcc->stats->tx_err);
27079 return -EINVAL;
27080 }
27081
27082 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27083 vcc->pop(vcc, skb);
27084 else
27085 dev_kfree_skb_any(skb);
27086 - atomic_inc(&vcc->stats->tx_err);
27087 + atomic_inc_unchecked(&vcc->stats->tx_err);
27088 return -EINVAL;
27089 }
27090 #endif
27091 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27092 vcc->pop(vcc, skb);
27093 else
27094 dev_kfree_skb_any(skb);
27095 - atomic_inc(&vcc->stats->tx_err);
27096 + atomic_inc_unchecked(&vcc->stats->tx_err);
27097 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27098 return -ENOMEM;
27099 }
27100 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27101 vcc->pop(vcc, skb);
27102 else
27103 dev_kfree_skb_any(skb);
27104 - atomic_inc(&vcc->stats->tx_err);
27105 + atomic_inc_unchecked(&vcc->stats->tx_err);
27106 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27107 return -ENOMEM;
27108 }
27109 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27110 __enqueue_tpd(he_dev, tpd, cid);
27111 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27112
27113 - atomic_inc(&vcc->stats->tx);
27114 + atomic_inc_unchecked(&vcc->stats->tx);
27115
27116 return 0;
27117 }
27118 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
27119 index b812103..e391a49 100644
27120 --- a/drivers/atm/horizon.c
27121 +++ b/drivers/atm/horizon.c
27122 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
27123 {
27124 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27125 // VC layer stats
27126 - atomic_inc(&vcc->stats->rx);
27127 + atomic_inc_unchecked(&vcc->stats->rx);
27128 __net_timestamp(skb);
27129 // end of our responsibility
27130 vcc->push (vcc, skb);
27131 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
27132 dev->tx_iovec = NULL;
27133
27134 // VC layer stats
27135 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27136 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27137
27138 // free the skb
27139 hrz_kfree_skb (skb);
27140 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
27141 index 1c05212..c28e200 100644
27142 --- a/drivers/atm/idt77252.c
27143 +++ b/drivers/atm/idt77252.c
27144 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
27145 else
27146 dev_kfree_skb(skb);
27147
27148 - atomic_inc(&vcc->stats->tx);
27149 + atomic_inc_unchecked(&vcc->stats->tx);
27150 }
27151
27152 atomic_dec(&scq->used);
27153 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27154 if ((sb = dev_alloc_skb(64)) == NULL) {
27155 printk("%s: Can't allocate buffers for aal0.\n",
27156 card->name);
27157 - atomic_add(i, &vcc->stats->rx_drop);
27158 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27159 break;
27160 }
27161 if (!atm_charge(vcc, sb->truesize)) {
27162 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
27163 card->name);
27164 - atomic_add(i - 1, &vcc->stats->rx_drop);
27165 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
27166 dev_kfree_skb(sb);
27167 break;
27168 }
27169 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27170 ATM_SKB(sb)->vcc = vcc;
27171 __net_timestamp(sb);
27172 vcc->push(vcc, sb);
27173 - atomic_inc(&vcc->stats->rx);
27174 + atomic_inc_unchecked(&vcc->stats->rx);
27175
27176 cell += ATM_CELL_PAYLOAD;
27177 }
27178 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27179 "(CDC: %08x)\n",
27180 card->name, len, rpp->len, readl(SAR_REG_CDC));
27181 recycle_rx_pool_skb(card, rpp);
27182 - atomic_inc(&vcc->stats->rx_err);
27183 + atomic_inc_unchecked(&vcc->stats->rx_err);
27184 return;
27185 }
27186 if (stat & SAR_RSQE_CRC) {
27187 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
27188 recycle_rx_pool_skb(card, rpp);
27189 - atomic_inc(&vcc->stats->rx_err);
27190 + atomic_inc_unchecked(&vcc->stats->rx_err);
27191 return;
27192 }
27193 if (skb_queue_len(&rpp->queue) > 1) {
27194 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27195 RXPRINTK("%s: Can't alloc RX skb.\n",
27196 card->name);
27197 recycle_rx_pool_skb(card, rpp);
27198 - atomic_inc(&vcc->stats->rx_err);
27199 + atomic_inc_unchecked(&vcc->stats->rx_err);
27200 return;
27201 }
27202 if (!atm_charge(vcc, skb->truesize)) {
27203 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27204 __net_timestamp(skb);
27205
27206 vcc->push(vcc, skb);
27207 - atomic_inc(&vcc->stats->rx);
27208 + atomic_inc_unchecked(&vcc->stats->rx);
27209
27210 return;
27211 }
27212 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27213 __net_timestamp(skb);
27214
27215 vcc->push(vcc, skb);
27216 - atomic_inc(&vcc->stats->rx);
27217 + atomic_inc_unchecked(&vcc->stats->rx);
27218
27219 if (skb->truesize > SAR_FB_SIZE_3)
27220 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
27221 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
27222 if (vcc->qos.aal != ATM_AAL0) {
27223 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
27224 card->name, vpi, vci);
27225 - atomic_inc(&vcc->stats->rx_drop);
27226 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27227 goto drop;
27228 }
27229
27230 if ((sb = dev_alloc_skb(64)) == NULL) {
27231 printk("%s: Can't allocate buffers for AAL0.\n",
27232 card->name);
27233 - atomic_inc(&vcc->stats->rx_err);
27234 + atomic_inc_unchecked(&vcc->stats->rx_err);
27235 goto drop;
27236 }
27237
27238 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
27239 ATM_SKB(sb)->vcc = vcc;
27240 __net_timestamp(sb);
27241 vcc->push(vcc, sb);
27242 - atomic_inc(&vcc->stats->rx);
27243 + atomic_inc_unchecked(&vcc->stats->rx);
27244
27245 drop:
27246 skb_pull(queue, 64);
27247 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27248
27249 if (vc == NULL) {
27250 printk("%s: NULL connection in send().\n", card->name);
27251 - atomic_inc(&vcc->stats->tx_err);
27252 + atomic_inc_unchecked(&vcc->stats->tx_err);
27253 dev_kfree_skb(skb);
27254 return -EINVAL;
27255 }
27256 if (!test_bit(VCF_TX, &vc->flags)) {
27257 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
27258 - atomic_inc(&vcc->stats->tx_err);
27259 + atomic_inc_unchecked(&vcc->stats->tx_err);
27260 dev_kfree_skb(skb);
27261 return -EINVAL;
27262 }
27263 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27264 break;
27265 default:
27266 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27267 - atomic_inc(&vcc->stats->tx_err);
27268 + atomic_inc_unchecked(&vcc->stats->tx_err);
27269 dev_kfree_skb(skb);
27270 return -EINVAL;
27271 }
27272
27273 if (skb_shinfo(skb)->nr_frags != 0) {
27274 printk("%s: No scatter-gather yet.\n", card->name);
27275 - atomic_inc(&vcc->stats->tx_err);
27276 + atomic_inc_unchecked(&vcc->stats->tx_err);
27277 dev_kfree_skb(skb);
27278 return -EINVAL;
27279 }
27280 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27281
27282 err = queue_skb(card, vc, skb, oam);
27283 if (err) {
27284 - atomic_inc(&vcc->stats->tx_err);
27285 + atomic_inc_unchecked(&vcc->stats->tx_err);
27286 dev_kfree_skb(skb);
27287 return err;
27288 }
27289 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
27290 skb = dev_alloc_skb(64);
27291 if (!skb) {
27292 printk("%s: Out of memory in send_oam().\n", card->name);
27293 - atomic_inc(&vcc->stats->tx_err);
27294 + atomic_inc_unchecked(&vcc->stats->tx_err);
27295 return -ENOMEM;
27296 }
27297 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27298 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
27299 index 9e373ba..cf93727 100644
27300 --- a/drivers/atm/iphase.c
27301 +++ b/drivers/atm/iphase.c
27302 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
27303 status = (u_short) (buf_desc_ptr->desc_mode);
27304 if (status & (RX_CER | RX_PTE | RX_OFL))
27305 {
27306 - atomic_inc(&vcc->stats->rx_err);
27307 + atomic_inc_unchecked(&vcc->stats->rx_err);
27308 IF_ERR(printk("IA: bad packet, dropping it");)
27309 if (status & RX_CER) {
27310 IF_ERR(printk(" cause: packet CRC error\n");)
27311 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
27312 len = dma_addr - buf_addr;
27313 if (len > iadev->rx_buf_sz) {
27314 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27315 - atomic_inc(&vcc->stats->rx_err);
27316 + atomic_inc_unchecked(&vcc->stats->rx_err);
27317 goto out_free_desc;
27318 }
27319
27320 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27321 ia_vcc = INPH_IA_VCC(vcc);
27322 if (ia_vcc == NULL)
27323 {
27324 - atomic_inc(&vcc->stats->rx_err);
27325 + atomic_inc_unchecked(&vcc->stats->rx_err);
27326 atm_return(vcc, skb->truesize);
27327 dev_kfree_skb_any(skb);
27328 goto INCR_DLE;
27329 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27330 if ((length > iadev->rx_buf_sz) || (length >
27331 (skb->len - sizeof(struct cpcs_trailer))))
27332 {
27333 - atomic_inc(&vcc->stats->rx_err);
27334 + atomic_inc_unchecked(&vcc->stats->rx_err);
27335 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27336 length, skb->len);)
27337 atm_return(vcc, skb->truesize);
27338 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27339
27340 IF_RX(printk("rx_dle_intr: skb push");)
27341 vcc->push(vcc,skb);
27342 - atomic_inc(&vcc->stats->rx);
27343 + atomic_inc_unchecked(&vcc->stats->rx);
27344 iadev->rx_pkt_cnt++;
27345 }
27346 INCR_DLE:
27347 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
27348 {
27349 struct k_sonet_stats *stats;
27350 stats = &PRIV(_ia_dev[board])->sonet_stats;
27351 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27352 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27353 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27354 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27355 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27356 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27357 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27358 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27359 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27360 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27361 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27362 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27363 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27364 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27365 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27366 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27367 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27368 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
27369 }
27370 ia_cmds.status = 0;
27371 break;
27372 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27373 if ((desc == 0) || (desc > iadev->num_tx_desc))
27374 {
27375 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
27376 - atomic_inc(&vcc->stats->tx);
27377 + atomic_inc_unchecked(&vcc->stats->tx);
27378 if (vcc->pop)
27379 vcc->pop(vcc, skb);
27380 else
27381 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27382 ATM_DESC(skb) = vcc->vci;
27383 skb_queue_tail(&iadev->tx_dma_q, skb);
27384
27385 - atomic_inc(&vcc->stats->tx);
27386 + atomic_inc_unchecked(&vcc->stats->tx);
27387 iadev->tx_pkt_cnt++;
27388 /* Increment transaction counter */
27389 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
27390
27391 #if 0
27392 /* add flow control logic */
27393 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27394 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27395 if (iavcc->vc_desc_cnt > 10) {
27396 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27397 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27398 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
27399 index f556969..0da15eb 100644
27400 --- a/drivers/atm/lanai.c
27401 +++ b/drivers/atm/lanai.c
27402 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
27403 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27404 lanai_endtx(lanai, lvcc);
27405 lanai_free_skb(lvcc->tx.atmvcc, skb);
27406 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
27407 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
27408 }
27409
27410 /* Try to fill the buffer - don't call unless there is backlog */
27411 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
27412 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
27413 __net_timestamp(skb);
27414 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
27415 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
27416 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
27417 out:
27418 lvcc->rx.buf.ptr = end;
27419 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
27420 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27421 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27422 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27423 lanai->stats.service_rxnotaal5++;
27424 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27425 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27426 return 0;
27427 }
27428 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27429 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27430 int bytes;
27431 read_unlock(&vcc_sklist_lock);
27432 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27433 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27434 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27435 lvcc->stats.x.aal5.service_trash++;
27436 bytes = (SERVICE_GET_END(s) * 16) -
27437 (((unsigned long) lvcc->rx.buf.ptr) -
27438 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27439 }
27440 if (s & SERVICE_STREAM) {
27441 read_unlock(&vcc_sklist_lock);
27442 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27443 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27444 lvcc->stats.x.aal5.service_stream++;
27445 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27446 "PDU on VCI %d!\n", lanai->number, vci);
27447 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27448 return 0;
27449 }
27450 DPRINTK("got rx crc error on vci %d\n", vci);
27451 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27452 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27453 lvcc->stats.x.aal5.service_rxcrc++;
27454 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27455 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27456 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
27457 index 1c70c45..300718d 100644
27458 --- a/drivers/atm/nicstar.c
27459 +++ b/drivers/atm/nicstar.c
27460 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27461 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
27462 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
27463 card->index);
27464 - atomic_inc(&vcc->stats->tx_err);
27465 + atomic_inc_unchecked(&vcc->stats->tx_err);
27466 dev_kfree_skb_any(skb);
27467 return -EINVAL;
27468 }
27469 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27470 if (!vc->tx) {
27471 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
27472 card->index);
27473 - atomic_inc(&vcc->stats->tx_err);
27474 + atomic_inc_unchecked(&vcc->stats->tx_err);
27475 dev_kfree_skb_any(skb);
27476 return -EINVAL;
27477 }
27478 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27479 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
27480 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
27481 card->index);
27482 - atomic_inc(&vcc->stats->tx_err);
27483 + atomic_inc_unchecked(&vcc->stats->tx_err);
27484 dev_kfree_skb_any(skb);
27485 return -EINVAL;
27486 }
27487
27488 if (skb_shinfo(skb)->nr_frags != 0) {
27489 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27490 - atomic_inc(&vcc->stats->tx_err);
27491 + atomic_inc_unchecked(&vcc->stats->tx_err);
27492 dev_kfree_skb_any(skb);
27493 return -EINVAL;
27494 }
27495 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27496 }
27497
27498 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
27499 - atomic_inc(&vcc->stats->tx_err);
27500 + atomic_inc_unchecked(&vcc->stats->tx_err);
27501 dev_kfree_skb_any(skb);
27502 return -EIO;
27503 }
27504 - atomic_inc(&vcc->stats->tx);
27505 + atomic_inc_unchecked(&vcc->stats->tx);
27506
27507 return 0;
27508 }
27509 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27510 printk
27511 ("nicstar%d: Can't allocate buffers for aal0.\n",
27512 card->index);
27513 - atomic_add(i, &vcc->stats->rx_drop);
27514 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27515 break;
27516 }
27517 if (!atm_charge(vcc, sb->truesize)) {
27518 RXPRINTK
27519 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
27520 card->index);
27521 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27522 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27523 dev_kfree_skb_any(sb);
27524 break;
27525 }
27526 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27527 ATM_SKB(sb)->vcc = vcc;
27528 __net_timestamp(sb);
27529 vcc->push(vcc, sb);
27530 - atomic_inc(&vcc->stats->rx);
27531 + atomic_inc_unchecked(&vcc->stats->rx);
27532 cell += ATM_CELL_PAYLOAD;
27533 }
27534
27535 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27536 if (iovb == NULL) {
27537 printk("nicstar%d: Out of iovec buffers.\n",
27538 card->index);
27539 - atomic_inc(&vcc->stats->rx_drop);
27540 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27541 recycle_rx_buf(card, skb);
27542 return;
27543 }
27544 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27545 small or large buffer itself. */
27546 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
27547 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
27548 - atomic_inc(&vcc->stats->rx_err);
27549 + atomic_inc_unchecked(&vcc->stats->rx_err);
27550 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27551 NS_MAX_IOVECS);
27552 NS_PRV_IOVCNT(iovb) = 0;
27553 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27554 ("nicstar%d: Expected a small buffer, and this is not one.\n",
27555 card->index);
27556 which_list(card, skb);
27557 - atomic_inc(&vcc->stats->rx_err);
27558 + atomic_inc_unchecked(&vcc->stats->rx_err);
27559 recycle_rx_buf(card, skb);
27560 vc->rx_iov = NULL;
27561 recycle_iov_buf(card, iovb);
27562 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27563 ("nicstar%d: Expected a large buffer, and this is not one.\n",
27564 card->index);
27565 which_list(card, skb);
27566 - atomic_inc(&vcc->stats->rx_err);
27567 + atomic_inc_unchecked(&vcc->stats->rx_err);
27568 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27569 NS_PRV_IOVCNT(iovb));
27570 vc->rx_iov = NULL;
27571 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27572 printk(" - PDU size mismatch.\n");
27573 else
27574 printk(".\n");
27575 - atomic_inc(&vcc->stats->rx_err);
27576 + atomic_inc_unchecked(&vcc->stats->rx_err);
27577 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27578 NS_PRV_IOVCNT(iovb));
27579 vc->rx_iov = NULL;
27580 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27581 /* skb points to a small buffer */
27582 if (!atm_charge(vcc, skb->truesize)) {
27583 push_rxbufs(card, skb);
27584 - atomic_inc(&vcc->stats->rx_drop);
27585 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27586 } else {
27587 skb_put(skb, len);
27588 dequeue_sm_buf(card, skb);
27589 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27590 ATM_SKB(skb)->vcc = vcc;
27591 __net_timestamp(skb);
27592 vcc->push(vcc, skb);
27593 - atomic_inc(&vcc->stats->rx);
27594 + atomic_inc_unchecked(&vcc->stats->rx);
27595 }
27596 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
27597 struct sk_buff *sb;
27598 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27599 if (len <= NS_SMBUFSIZE) {
27600 if (!atm_charge(vcc, sb->truesize)) {
27601 push_rxbufs(card, sb);
27602 - atomic_inc(&vcc->stats->rx_drop);
27603 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27604 } else {
27605 skb_put(sb, len);
27606 dequeue_sm_buf(card, sb);
27607 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27608 ATM_SKB(sb)->vcc = vcc;
27609 __net_timestamp(sb);
27610 vcc->push(vcc, sb);
27611 - atomic_inc(&vcc->stats->rx);
27612 + atomic_inc_unchecked(&vcc->stats->rx);
27613 }
27614
27615 push_rxbufs(card, skb);
27616 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27617
27618 if (!atm_charge(vcc, skb->truesize)) {
27619 push_rxbufs(card, skb);
27620 - atomic_inc(&vcc->stats->rx_drop);
27621 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27622 } else {
27623 dequeue_lg_buf(card, skb);
27624 #ifdef NS_USE_DESTRUCTORS
27625 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27626 ATM_SKB(skb)->vcc = vcc;
27627 __net_timestamp(skb);
27628 vcc->push(vcc, skb);
27629 - atomic_inc(&vcc->stats->rx);
27630 + atomic_inc_unchecked(&vcc->stats->rx);
27631 }
27632
27633 push_rxbufs(card, sb);
27634 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27635 printk
27636 ("nicstar%d: Out of huge buffers.\n",
27637 card->index);
27638 - atomic_inc(&vcc->stats->rx_drop);
27639 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27640 recycle_iovec_rx_bufs(card,
27641 (struct iovec *)
27642 iovb->data,
27643 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27644 card->hbpool.count++;
27645 } else
27646 dev_kfree_skb_any(hb);
27647 - atomic_inc(&vcc->stats->rx_drop);
27648 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27649 } else {
27650 /* Copy the small buffer to the huge buffer */
27651 sb = (struct sk_buff *)iov->iov_base;
27652 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27653 #endif /* NS_USE_DESTRUCTORS */
27654 __net_timestamp(hb);
27655 vcc->push(vcc, hb);
27656 - atomic_inc(&vcc->stats->rx);
27657 + atomic_inc_unchecked(&vcc->stats->rx);
27658 }
27659 }
27660
27661 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
27662 index e8cd652..bbbd1fc 100644
27663 --- a/drivers/atm/solos-pci.c
27664 +++ b/drivers/atm/solos-pci.c
27665 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
27666 }
27667 atm_charge(vcc, skb->truesize);
27668 vcc->push(vcc, skb);
27669 - atomic_inc(&vcc->stats->rx);
27670 + atomic_inc_unchecked(&vcc->stats->rx);
27671 break;
27672
27673 case PKT_STATUS:
27674 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
27675 vcc = SKB_CB(oldskb)->vcc;
27676
27677 if (vcc) {
27678 - atomic_inc(&vcc->stats->tx);
27679 + atomic_inc_unchecked(&vcc->stats->tx);
27680 solos_pop(vcc, oldskb);
27681 } else
27682 dev_kfree_skb_irq(oldskb);
27683 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
27684 index 90f1ccc..04c4a1e 100644
27685 --- a/drivers/atm/suni.c
27686 +++ b/drivers/atm/suni.c
27687 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
27688
27689
27690 #define ADD_LIMITED(s,v) \
27691 - atomic_add((v),&stats->s); \
27692 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
27693 + atomic_add_unchecked((v),&stats->s); \
27694 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
27695
27696
27697 static void suni_hz(unsigned long from_timer)
27698 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
27699 index 5120a96..e2572bd 100644
27700 --- a/drivers/atm/uPD98402.c
27701 +++ b/drivers/atm/uPD98402.c
27702 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
27703 struct sonet_stats tmp;
27704 int error = 0;
27705
27706 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27707 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27708 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
27709 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
27710 if (zero && !error) {
27711 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
27712
27713
27714 #define ADD_LIMITED(s,v) \
27715 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
27716 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
27717 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27718 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
27719 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
27720 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27721
27722
27723 static void stat_event(struct atm_dev *dev)
27724 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
27725 if (reason & uPD98402_INT_PFM) stat_event(dev);
27726 if (reason & uPD98402_INT_PCO) {
27727 (void) GET(PCOCR); /* clear interrupt cause */
27728 - atomic_add(GET(HECCT),
27729 + atomic_add_unchecked(GET(HECCT),
27730 &PRIV(dev)->sonet_stats.uncorr_hcs);
27731 }
27732 if ((reason & uPD98402_INT_RFO) &&
27733 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
27734 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
27735 uPD98402_INT_LOS),PIMR); /* enable them */
27736 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
27737 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27738 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
27739 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
27740 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27741 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
27742 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
27743 return 0;
27744 }
27745
27746 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
27747 index d889f56..17eb71e 100644
27748 --- a/drivers/atm/zatm.c
27749 +++ b/drivers/atm/zatm.c
27750 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
27751 }
27752 if (!size) {
27753 dev_kfree_skb_irq(skb);
27754 - if (vcc) atomic_inc(&vcc->stats->rx_err);
27755 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
27756 continue;
27757 }
27758 if (!atm_charge(vcc,skb->truesize)) {
27759 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
27760 skb->len = size;
27761 ATM_SKB(skb)->vcc = vcc;
27762 vcc->push(vcc,skb);
27763 - atomic_inc(&vcc->stats->rx);
27764 + atomic_inc_unchecked(&vcc->stats->rx);
27765 }
27766 zout(pos & 0xffff,MTA(mbx));
27767 #if 0 /* probably a stupid idea */
27768 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
27769 skb_queue_head(&zatm_vcc->backlog,skb);
27770 break;
27771 }
27772 - atomic_inc(&vcc->stats->tx);
27773 + atomic_inc_unchecked(&vcc->stats->tx);
27774 wake_up(&zatm_vcc->tx_wait);
27775 }
27776
27777 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
27778 index 8493536..31adee0 100644
27779 --- a/drivers/base/devtmpfs.c
27780 +++ b/drivers/base/devtmpfs.c
27781 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
27782 if (!thread)
27783 return 0;
27784
27785 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
27786 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
27787 if (err)
27788 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
27789 else
27790 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
27791 index caf995f..6f76697 100644
27792 --- a/drivers/base/power/wakeup.c
27793 +++ b/drivers/base/power/wakeup.c
27794 @@ -30,14 +30,14 @@ bool events_check_enabled;
27795 * They need to be modified together atomically, so it's better to use one
27796 * atomic variable to hold them both.
27797 */
27798 -static atomic_t combined_event_count = ATOMIC_INIT(0);
27799 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
27800
27801 #define IN_PROGRESS_BITS (sizeof(int) * 4)
27802 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
27803
27804 static void split_counters(unsigned int *cnt, unsigned int *inpr)
27805 {
27806 - unsigned int comb = atomic_read(&combined_event_count);
27807 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
27808
27809 *cnt = (comb >> IN_PROGRESS_BITS);
27810 *inpr = comb & MAX_IN_PROGRESS;
27811 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
27812 ws->last_time = ktime_get();
27813
27814 /* Increment the counter of events in progress. */
27815 - atomic_inc(&combined_event_count);
27816 + atomic_inc_unchecked(&combined_event_count);
27817 }
27818
27819 /**
27820 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
27821 * Increment the counter of registered wakeup events and decrement the
27822 * couter of wakeup events in progress simultaneously.
27823 */
27824 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
27825 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
27826 }
27827
27828 /**
27829 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
27830 index b0f553b..77b928b 100644
27831 --- a/drivers/block/cciss.c
27832 +++ b/drivers/block/cciss.c
27833 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
27834 int err;
27835 u32 cp;
27836
27837 + memset(&arg64, 0, sizeof(arg64));
27838 +
27839 err = 0;
27840 err |=
27841 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27842 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
27843 while (!list_empty(&h->reqQ)) {
27844 c = list_entry(h->reqQ.next, CommandList_struct, list);
27845 /* can't do anything if fifo is full */
27846 - if ((h->access.fifo_full(h))) {
27847 + if ((h->access->fifo_full(h))) {
27848 dev_warn(&h->pdev->dev, "fifo full\n");
27849 break;
27850 }
27851 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
27852 h->Qdepth--;
27853
27854 /* Tell the controller execute command */
27855 - h->access.submit_command(h, c);
27856 + h->access->submit_command(h, c);
27857
27858 /* Put job onto the completed Q */
27859 addQ(&h->cmpQ, c);
27860 @@ -3443,17 +3445,17 @@ startio:
27861
27862 static inline unsigned long get_next_completion(ctlr_info_t *h)
27863 {
27864 - return h->access.command_completed(h);
27865 + return h->access->command_completed(h);
27866 }
27867
27868 static inline int interrupt_pending(ctlr_info_t *h)
27869 {
27870 - return h->access.intr_pending(h);
27871 + return h->access->intr_pending(h);
27872 }
27873
27874 static inline long interrupt_not_for_us(ctlr_info_t *h)
27875 {
27876 - return ((h->access.intr_pending(h) == 0) ||
27877 + return ((h->access->intr_pending(h) == 0) ||
27878 (h->interrupts_enabled == 0));
27879 }
27880
27881 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
27882 u32 a;
27883
27884 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
27885 - return h->access.command_completed(h);
27886 + return h->access->command_completed(h);
27887
27888 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
27889 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
27890 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
27891 trans_support & CFGTBL_Trans_use_short_tags);
27892
27893 /* Change the access methods to the performant access methods */
27894 - h->access = SA5_performant_access;
27895 + h->access = &SA5_performant_access;
27896 h->transMethod = CFGTBL_Trans_Performant;
27897
27898 return;
27899 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
27900 if (prod_index < 0)
27901 return -ENODEV;
27902 h->product_name = products[prod_index].product_name;
27903 - h->access = *(products[prod_index].access);
27904 + h->access = products[prod_index].access;
27905
27906 if (cciss_board_disabled(h)) {
27907 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
27908 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
27909 }
27910
27911 /* make sure the board interrupts are off */
27912 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27913 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27914 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
27915 if (rc)
27916 goto clean2;
27917 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
27918 * fake ones to scoop up any residual completions.
27919 */
27920 spin_lock_irqsave(&h->lock, flags);
27921 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27922 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27923 spin_unlock_irqrestore(&h->lock, flags);
27924 free_irq(h->intr[h->intr_mode], h);
27925 rc = cciss_request_irq(h, cciss_msix_discard_completions,
27926 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
27927 dev_info(&h->pdev->dev, "Board READY.\n");
27928 dev_info(&h->pdev->dev,
27929 "Waiting for stale completions to drain.\n");
27930 - h->access.set_intr_mask(h, CCISS_INTR_ON);
27931 + h->access->set_intr_mask(h, CCISS_INTR_ON);
27932 msleep(10000);
27933 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27934 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27935
27936 rc = controller_reset_failed(h->cfgtable);
27937 if (rc)
27938 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
27939 cciss_scsi_setup(h);
27940
27941 /* Turn the interrupts on so we can service requests */
27942 - h->access.set_intr_mask(h, CCISS_INTR_ON);
27943 + h->access->set_intr_mask(h, CCISS_INTR_ON);
27944
27945 /* Get the firmware version */
27946 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
27947 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
27948 kfree(flush_buf);
27949 if (return_code != IO_OK)
27950 dev_warn(&h->pdev->dev, "Error flushing cache\n");
27951 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27952 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27953 free_irq(h->intr[h->intr_mode], h);
27954 }
27955
27956 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
27957 index 7fda30e..eb5dfe0 100644
27958 --- a/drivers/block/cciss.h
27959 +++ b/drivers/block/cciss.h
27960 @@ -101,7 +101,7 @@ struct ctlr_info
27961 /* information about each logical volume */
27962 drive_info_struct *drv[CISS_MAX_LUN];
27963
27964 - struct access_method access;
27965 + struct access_method *access;
27966
27967 /* queue and queue Info */
27968 struct list_head reqQ;
27969 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
27970 index 9125bbe..eede5c8 100644
27971 --- a/drivers/block/cpqarray.c
27972 +++ b/drivers/block/cpqarray.c
27973 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
27974 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
27975 goto Enomem4;
27976 }
27977 - hba[i]->access.set_intr_mask(hba[i], 0);
27978 + hba[i]->access->set_intr_mask(hba[i], 0);
27979 if (request_irq(hba[i]->intr, do_ida_intr,
27980 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
27981 {
27982 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
27983 add_timer(&hba[i]->timer);
27984
27985 /* Enable IRQ now that spinlock and rate limit timer are set up */
27986 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27987 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27988
27989 for(j=0; j<NWD; j++) {
27990 struct gendisk *disk = ida_gendisk[i][j];
27991 @@ -694,7 +694,7 @@ DBGINFO(
27992 for(i=0; i<NR_PRODUCTS; i++) {
27993 if (board_id == products[i].board_id) {
27994 c->product_name = products[i].product_name;
27995 - c->access = *(products[i].access);
27996 + c->access = products[i].access;
27997 break;
27998 }
27999 }
28000 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28001 hba[ctlr]->intr = intr;
28002 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28003 hba[ctlr]->product_name = products[j].product_name;
28004 - hba[ctlr]->access = *(products[j].access);
28005 + hba[ctlr]->access = products[j].access;
28006 hba[ctlr]->ctlr = ctlr;
28007 hba[ctlr]->board_id = board_id;
28008 hba[ctlr]->pci_dev = NULL; /* not PCI */
28009 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28010
28011 while((c = h->reqQ) != NULL) {
28012 /* Can't do anything if we're busy */
28013 - if (h->access.fifo_full(h) == 0)
28014 + if (h->access->fifo_full(h) == 0)
28015 return;
28016
28017 /* Get the first entry from the request Q */
28018 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28019 h->Qdepth--;
28020
28021 /* Tell the controller to do our bidding */
28022 - h->access.submit_command(h, c);
28023 + h->access->submit_command(h, c);
28024
28025 /* Get onto the completion Q */
28026 addQ(&h->cmpQ, c);
28027 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28028 unsigned long flags;
28029 __u32 a,a1;
28030
28031 - istat = h->access.intr_pending(h);
28032 + istat = h->access->intr_pending(h);
28033 /* Is this interrupt for us? */
28034 if (istat == 0)
28035 return IRQ_NONE;
28036 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28037 */
28038 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28039 if (istat & FIFO_NOT_EMPTY) {
28040 - while((a = h->access.command_completed(h))) {
28041 + while((a = h->access->command_completed(h))) {
28042 a1 = a; a &= ~3;
28043 if ((c = h->cmpQ) == NULL)
28044 {
28045 @@ -1449,11 +1449,11 @@ static int sendcmd(
28046 /*
28047 * Disable interrupt
28048 */
28049 - info_p->access.set_intr_mask(info_p, 0);
28050 + info_p->access->set_intr_mask(info_p, 0);
28051 /* Make sure there is room in the command FIFO */
28052 /* Actually it should be completely empty at this time. */
28053 for (i = 200000; i > 0; i--) {
28054 - temp = info_p->access.fifo_full(info_p);
28055 + temp = info_p->access->fifo_full(info_p);
28056 if (temp != 0) {
28057 break;
28058 }
28059 @@ -1466,7 +1466,7 @@ DBG(
28060 /*
28061 * Send the cmd
28062 */
28063 - info_p->access.submit_command(info_p, c);
28064 + info_p->access->submit_command(info_p, c);
28065 complete = pollcomplete(ctlr);
28066
28067 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28068 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28069 * we check the new geometry. Then turn interrupts back on when
28070 * we're done.
28071 */
28072 - host->access.set_intr_mask(host, 0);
28073 + host->access->set_intr_mask(host, 0);
28074 getgeometry(ctlr);
28075 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28076 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28077
28078 for(i=0; i<NWD; i++) {
28079 struct gendisk *disk = ida_gendisk[ctlr][i];
28080 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28081 /* Wait (up to 2 seconds) for a command to complete */
28082
28083 for (i = 200000; i > 0; i--) {
28084 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28085 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28086 if (done == 0) {
28087 udelay(10); /* a short fixed delay */
28088 } else
28089 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28090 index be73e9d..7fbf140 100644
28091 --- a/drivers/block/cpqarray.h
28092 +++ b/drivers/block/cpqarray.h
28093 @@ -99,7 +99,7 @@ struct ctlr_info {
28094 drv_info_t drv[NWD];
28095 struct proc_dir_entry *proc;
28096
28097 - struct access_method access;
28098 + struct access_method *access;
28099
28100 cmdlist_t *reqQ;
28101 cmdlist_t *cmpQ;
28102 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28103 index 8d68056..e67050f 100644
28104 --- a/drivers/block/drbd/drbd_int.h
28105 +++ b/drivers/block/drbd/drbd_int.h
28106 @@ -736,7 +736,7 @@ struct drbd_request;
28107 struct drbd_epoch {
28108 struct list_head list;
28109 unsigned int barrier_nr;
28110 - atomic_t epoch_size; /* increased on every request added. */
28111 + atomic_unchecked_t epoch_size; /* increased on every request added. */
28112 atomic_t active; /* increased on every req. added, and dec on every finished. */
28113 unsigned long flags;
28114 };
28115 @@ -1108,7 +1108,7 @@ struct drbd_conf {
28116 void *int_dig_in;
28117 void *int_dig_vv;
28118 wait_queue_head_t seq_wait;
28119 - atomic_t packet_seq;
28120 + atomic_unchecked_t packet_seq;
28121 unsigned int peer_seq;
28122 spinlock_t peer_seq_lock;
28123 unsigned int minor;
28124 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
28125
28126 static inline void drbd_tcp_cork(struct socket *sock)
28127 {
28128 - int __user val = 1;
28129 + int val = 1;
28130 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28131 - (char __user *)&val, sizeof(val));
28132 + (char __force_user *)&val, sizeof(val));
28133 }
28134
28135 static inline void drbd_tcp_uncork(struct socket *sock)
28136 {
28137 - int __user val = 0;
28138 + int val = 0;
28139 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28140 - (char __user *)&val, sizeof(val));
28141 + (char __force_user *)&val, sizeof(val));
28142 }
28143
28144 static inline void drbd_tcp_nodelay(struct socket *sock)
28145 {
28146 - int __user val = 1;
28147 + int val = 1;
28148 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
28149 - (char __user *)&val, sizeof(val));
28150 + (char __force_user *)&val, sizeof(val));
28151 }
28152
28153 static inline void drbd_tcp_quickack(struct socket *sock)
28154 {
28155 - int __user val = 2;
28156 + int val = 2;
28157 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
28158 - (char __user *)&val, sizeof(val));
28159 + (char __force_user *)&val, sizeof(val));
28160 }
28161
28162 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
28163 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
28164 index 211fc44..c5116f1 100644
28165 --- a/drivers/block/drbd/drbd_main.c
28166 +++ b/drivers/block/drbd/drbd_main.c
28167 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
28168 p.sector = sector;
28169 p.block_id = block_id;
28170 p.blksize = blksize;
28171 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
28172 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
28173
28174 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
28175 return false;
28176 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
28177 p.sector = cpu_to_be64(req->sector);
28178 p.block_id = (unsigned long)req;
28179 p.seq_num = cpu_to_be32(req->seq_num =
28180 - atomic_add_return(1, &mdev->packet_seq));
28181 + atomic_add_return_unchecked(1, &mdev->packet_seq));
28182
28183 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
28184
28185 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
28186 atomic_set(&mdev->unacked_cnt, 0);
28187 atomic_set(&mdev->local_cnt, 0);
28188 atomic_set(&mdev->net_cnt, 0);
28189 - atomic_set(&mdev->packet_seq, 0);
28190 + atomic_set_unchecked(&mdev->packet_seq, 0);
28191 atomic_set(&mdev->pp_in_use, 0);
28192 atomic_set(&mdev->pp_in_use_by_net, 0);
28193 atomic_set(&mdev->rs_sect_in, 0);
28194 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
28195 mdev->receiver.t_state);
28196
28197 /* no need to lock it, I'm the only thread alive */
28198 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
28199 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
28200 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
28201 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
28202 mdev->al_writ_cnt =
28203 mdev->bm_writ_cnt =
28204 mdev->read_cnt =
28205 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
28206 index af2a250..219c74b 100644
28207 --- a/drivers/block/drbd/drbd_nl.c
28208 +++ b/drivers/block/drbd/drbd_nl.c
28209 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
28210 module_put(THIS_MODULE);
28211 }
28212
28213 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28214 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28215
28216 static unsigned short *
28217 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
28218 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
28219 cn_reply->id.idx = CN_IDX_DRBD;
28220 cn_reply->id.val = CN_VAL_DRBD;
28221
28222 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28223 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28224 cn_reply->ack = 0; /* not used here. */
28225 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28226 (int)((char *)tl - (char *)reply->tag_list);
28227 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
28228 cn_reply->id.idx = CN_IDX_DRBD;
28229 cn_reply->id.val = CN_VAL_DRBD;
28230
28231 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28232 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28233 cn_reply->ack = 0; /* not used here. */
28234 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28235 (int)((char *)tl - (char *)reply->tag_list);
28236 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
28237 cn_reply->id.idx = CN_IDX_DRBD;
28238 cn_reply->id.val = CN_VAL_DRBD;
28239
28240 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
28241 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
28242 cn_reply->ack = 0; // not used here.
28243 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28244 (int)((char*)tl - (char*)reply->tag_list);
28245 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
28246 cn_reply->id.idx = CN_IDX_DRBD;
28247 cn_reply->id.val = CN_VAL_DRBD;
28248
28249 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28250 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28251 cn_reply->ack = 0; /* not used here. */
28252 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28253 (int)((char *)tl - (char *)reply->tag_list);
28254 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
28255 index 43beaca..4a5b1dd 100644
28256 --- a/drivers/block/drbd/drbd_receiver.c
28257 +++ b/drivers/block/drbd/drbd_receiver.c
28258 @@ -894,7 +894,7 @@ retry:
28259 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
28260 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
28261
28262 - atomic_set(&mdev->packet_seq, 0);
28263 + atomic_set_unchecked(&mdev->packet_seq, 0);
28264 mdev->peer_seq = 0;
28265
28266 drbd_thread_start(&mdev->asender);
28267 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28268 do {
28269 next_epoch = NULL;
28270
28271 - epoch_size = atomic_read(&epoch->epoch_size);
28272 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
28273
28274 switch (ev & ~EV_CLEANUP) {
28275 case EV_PUT:
28276 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28277 rv = FE_DESTROYED;
28278 } else {
28279 epoch->flags = 0;
28280 - atomic_set(&epoch->epoch_size, 0);
28281 + atomic_set_unchecked(&epoch->epoch_size, 0);
28282 /* atomic_set(&epoch->active, 0); is already zero */
28283 if (rv == FE_STILL_LIVE)
28284 rv = FE_RECYCLED;
28285 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28286 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
28287 drbd_flush(mdev);
28288
28289 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28290 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28291 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
28292 if (epoch)
28293 break;
28294 }
28295
28296 epoch = mdev->current_epoch;
28297 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
28298 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
28299
28300 D_ASSERT(atomic_read(&epoch->active) == 0);
28301 D_ASSERT(epoch->flags == 0);
28302 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28303 }
28304
28305 epoch->flags = 0;
28306 - atomic_set(&epoch->epoch_size, 0);
28307 + atomic_set_unchecked(&epoch->epoch_size, 0);
28308 atomic_set(&epoch->active, 0);
28309
28310 spin_lock(&mdev->epoch_lock);
28311 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28312 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28313 list_add(&epoch->list, &mdev->current_epoch->list);
28314 mdev->current_epoch = epoch;
28315 mdev->epochs++;
28316 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28317 spin_unlock(&mdev->peer_seq_lock);
28318
28319 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
28320 - atomic_inc(&mdev->current_epoch->epoch_size);
28321 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
28322 return drbd_drain_block(mdev, data_size);
28323 }
28324
28325 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28326
28327 spin_lock(&mdev->epoch_lock);
28328 e->epoch = mdev->current_epoch;
28329 - atomic_inc(&e->epoch->epoch_size);
28330 + atomic_inc_unchecked(&e->epoch->epoch_size);
28331 atomic_inc(&e->epoch->active);
28332 spin_unlock(&mdev->epoch_lock);
28333
28334 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
28335 D_ASSERT(list_empty(&mdev->done_ee));
28336
28337 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
28338 - atomic_set(&mdev->current_epoch->epoch_size, 0);
28339 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
28340 D_ASSERT(list_empty(&mdev->current_epoch->list));
28341 }
28342
28343 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
28344 index cd50435..ba1ffb5 100644
28345 --- a/drivers/block/loop.c
28346 +++ b/drivers/block/loop.c
28347 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
28348 mm_segment_t old_fs = get_fs();
28349
28350 set_fs(get_ds());
28351 - bw = file->f_op->write(file, buf, len, &pos);
28352 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
28353 set_fs(old_fs);
28354 if (likely(bw == len))
28355 return 0;
28356 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
28357 index 4364303..9adf4ee 100644
28358 --- a/drivers/char/Kconfig
28359 +++ b/drivers/char/Kconfig
28360 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28361
28362 config DEVKMEM
28363 bool "/dev/kmem virtual device support"
28364 - default y
28365 + default n
28366 + depends on !GRKERNSEC_KMEM
28367 help
28368 Say Y here if you want to support the /dev/kmem device. The
28369 /dev/kmem device is rarely used, but can be used for certain
28370 @@ -596,6 +597,7 @@ config DEVPORT
28371 bool
28372 depends on !M68K
28373 depends on ISA || PCI
28374 + depends on !GRKERNSEC_KMEM
28375 default y
28376
28377 source "drivers/s390/char/Kconfig"
28378 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
28379 index 2e04433..22afc64 100644
28380 --- a/drivers/char/agp/frontend.c
28381 +++ b/drivers/char/agp/frontend.c
28382 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
28383 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
28384 return -EFAULT;
28385
28386 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
28387 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
28388 return -EFAULT;
28389
28390 client = agp_find_client_by_pid(reserve.pid);
28391 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
28392 index 095ab90..afad0a4 100644
28393 --- a/drivers/char/briq_panel.c
28394 +++ b/drivers/char/briq_panel.c
28395 @@ -9,6 +9,7 @@
28396 #include <linux/types.h>
28397 #include <linux/errno.h>
28398 #include <linux/tty.h>
28399 +#include <linux/mutex.h>
28400 #include <linux/timer.h>
28401 #include <linux/kernel.h>
28402 #include <linux/wait.h>
28403 @@ -34,6 +35,7 @@ static int vfd_is_open;
28404 static unsigned char vfd[40];
28405 static int vfd_cursor;
28406 static unsigned char ledpb, led;
28407 +static DEFINE_MUTEX(vfd_mutex);
28408
28409 static void update_vfd(void)
28410 {
28411 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
28412 if (!vfd_is_open)
28413 return -EBUSY;
28414
28415 + mutex_lock(&vfd_mutex);
28416 for (;;) {
28417 char c;
28418 if (!indx)
28419 break;
28420 - if (get_user(c, buf))
28421 + if (get_user(c, buf)) {
28422 + mutex_unlock(&vfd_mutex);
28423 return -EFAULT;
28424 + }
28425 if (esc) {
28426 set_led(c);
28427 esc = 0;
28428 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
28429 buf++;
28430 }
28431 update_vfd();
28432 + mutex_unlock(&vfd_mutex);
28433
28434 return len;
28435 }
28436 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
28437 index f773a9d..65cd683 100644
28438 --- a/drivers/char/genrtc.c
28439 +++ b/drivers/char/genrtc.c
28440 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
28441 switch (cmd) {
28442
28443 case RTC_PLL_GET:
28444 + memset(&pll, 0, sizeof(pll));
28445 if (get_rtc_pll(&pll))
28446 return -EINVAL;
28447 else
28448 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
28449 index 0833896..cccce52 100644
28450 --- a/drivers/char/hpet.c
28451 +++ b/drivers/char/hpet.c
28452 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
28453 }
28454
28455 static int
28456 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
28457 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
28458 struct hpet_info *info)
28459 {
28460 struct hpet_timer __iomem *timer;
28461 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
28462 index 58c0e63..46c16bf 100644
28463 --- a/drivers/char/ipmi/ipmi_msghandler.c
28464 +++ b/drivers/char/ipmi/ipmi_msghandler.c
28465 @@ -415,7 +415,7 @@ struct ipmi_smi {
28466 struct proc_dir_entry *proc_dir;
28467 char proc_dir_name[10];
28468
28469 - atomic_t stats[IPMI_NUM_STATS];
28470 + atomic_unchecked_t stats[IPMI_NUM_STATS];
28471
28472 /*
28473 * run_to_completion duplicate of smb_info, smi_info
28474 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
28475
28476
28477 #define ipmi_inc_stat(intf, stat) \
28478 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
28479 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
28480 #define ipmi_get_stat(intf, stat) \
28481 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
28482 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
28483
28484 static int is_lan_addr(struct ipmi_addr *addr)
28485 {
28486 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
28487 INIT_LIST_HEAD(&intf->cmd_rcvrs);
28488 init_waitqueue_head(&intf->waitq);
28489 for (i = 0; i < IPMI_NUM_STATS; i++)
28490 - atomic_set(&intf->stats[i], 0);
28491 + atomic_set_unchecked(&intf->stats[i], 0);
28492
28493 intf->proc_dir = NULL;
28494
28495 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
28496 index 50fcf9c..91b5528 100644
28497 --- a/drivers/char/ipmi/ipmi_si_intf.c
28498 +++ b/drivers/char/ipmi/ipmi_si_intf.c
28499 @@ -277,7 +277,7 @@ struct smi_info {
28500 unsigned char slave_addr;
28501
28502 /* Counters and things for the proc filesystem. */
28503 - atomic_t stats[SI_NUM_STATS];
28504 + atomic_unchecked_t stats[SI_NUM_STATS];
28505
28506 struct task_struct *thread;
28507
28508 @@ -286,9 +286,9 @@ struct smi_info {
28509 };
28510
28511 #define smi_inc_stat(smi, stat) \
28512 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
28513 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
28514 #define smi_get_stat(smi, stat) \
28515 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
28516 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
28517
28518 #define SI_MAX_PARMS 4
28519
28520 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
28521 atomic_set(&new_smi->req_events, 0);
28522 new_smi->run_to_completion = 0;
28523 for (i = 0; i < SI_NUM_STATS; i++)
28524 - atomic_set(&new_smi->stats[i], 0);
28525 + atomic_set_unchecked(&new_smi->stats[i], 0);
28526
28527 new_smi->interrupt_disabled = 1;
28528 atomic_set(&new_smi->stop_operation, 0);
28529 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
28530 index 1aeaaba..e018570 100644
28531 --- a/drivers/char/mbcs.c
28532 +++ b/drivers/char/mbcs.c
28533 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
28534 return 0;
28535 }
28536
28537 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
28538 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
28539 {
28540 .part_num = MBCS_PART_NUM,
28541 .mfg_num = MBCS_MFG_NUM,
28542 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
28543 index d6e9d08..4493e89 100644
28544 --- a/drivers/char/mem.c
28545 +++ b/drivers/char/mem.c
28546 @@ -18,6 +18,7 @@
28547 #include <linux/raw.h>
28548 #include <linux/tty.h>
28549 #include <linux/capability.h>
28550 +#include <linux/security.h>
28551 #include <linux/ptrace.h>
28552 #include <linux/device.h>
28553 #include <linux/highmem.h>
28554 @@ -35,6 +36,10 @@
28555 # include <linux/efi.h>
28556 #endif
28557
28558 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28559 +extern const struct file_operations grsec_fops;
28560 +#endif
28561 +
28562 static inline unsigned long size_inside_page(unsigned long start,
28563 unsigned long size)
28564 {
28565 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28566
28567 while (cursor < to) {
28568 if (!devmem_is_allowed(pfn)) {
28569 +#ifdef CONFIG_GRKERNSEC_KMEM
28570 + gr_handle_mem_readwrite(from, to);
28571 +#else
28572 printk(KERN_INFO
28573 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
28574 current->comm, from, to);
28575 +#endif
28576 return 0;
28577 }
28578 cursor += PAGE_SIZE;
28579 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28580 }
28581 return 1;
28582 }
28583 +#elif defined(CONFIG_GRKERNSEC_KMEM)
28584 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28585 +{
28586 + return 0;
28587 +}
28588 #else
28589 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28590 {
28591 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
28592
28593 while (count > 0) {
28594 unsigned long remaining;
28595 + char *temp;
28596
28597 sz = size_inside_page(p, count);
28598
28599 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
28600 if (!ptr)
28601 return -EFAULT;
28602
28603 - remaining = copy_to_user(buf, ptr, sz);
28604 +#ifdef CONFIG_PAX_USERCOPY
28605 + temp = kmalloc(sz, GFP_KERNEL);
28606 + if (!temp) {
28607 + unxlate_dev_mem_ptr(p, ptr);
28608 + return -ENOMEM;
28609 + }
28610 + memcpy(temp, ptr, sz);
28611 +#else
28612 + temp = ptr;
28613 +#endif
28614 +
28615 + remaining = copy_to_user(buf, temp, sz);
28616 +
28617 +#ifdef CONFIG_PAX_USERCOPY
28618 + kfree(temp);
28619 +#endif
28620 +
28621 unxlate_dev_mem_ptr(p, ptr);
28622 if (remaining)
28623 return -EFAULT;
28624 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28625 size_t count, loff_t *ppos)
28626 {
28627 unsigned long p = *ppos;
28628 - ssize_t low_count, read, sz;
28629 + ssize_t low_count, read, sz, err = 0;
28630 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28631 - int err = 0;
28632
28633 read = 0;
28634 if (p < (unsigned long) high_memory) {
28635 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28636 }
28637 #endif
28638 while (low_count > 0) {
28639 + char *temp;
28640 +
28641 sz = size_inside_page(p, low_count);
28642
28643 /*
28644 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28645 */
28646 kbuf = xlate_dev_kmem_ptr((char *)p);
28647
28648 - if (copy_to_user(buf, kbuf, sz))
28649 +#ifdef CONFIG_PAX_USERCOPY
28650 + temp = kmalloc(sz, GFP_KERNEL);
28651 + if (!temp)
28652 + return -ENOMEM;
28653 + memcpy(temp, kbuf, sz);
28654 +#else
28655 + temp = kbuf;
28656 +#endif
28657 +
28658 + err = copy_to_user(buf, temp, sz);
28659 +
28660 +#ifdef CONFIG_PAX_USERCOPY
28661 + kfree(temp);
28662 +#endif
28663 +
28664 + if (err)
28665 return -EFAULT;
28666 buf += sz;
28667 p += sz;
28668 @@ -867,6 +914,9 @@ static const struct memdev {
28669 #ifdef CONFIG_CRASH_DUMP
28670 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28671 #endif
28672 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28673 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28674 +#endif
28675 };
28676
28677 static int memory_open(struct inode *inode, struct file *filp)
28678 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
28679 index da3cfee..a5a6606 100644
28680 --- a/drivers/char/nvram.c
28681 +++ b/drivers/char/nvram.c
28682 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
28683
28684 spin_unlock_irq(&rtc_lock);
28685
28686 - if (copy_to_user(buf, contents, tmp - contents))
28687 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
28688 return -EFAULT;
28689
28690 *ppos = i;
28691 diff --git a/drivers/char/random.c b/drivers/char/random.c
28692 index 54ca8b2..d58cb51 100644
28693 --- a/drivers/char/random.c
28694 +++ b/drivers/char/random.c
28695 @@ -261,8 +261,13 @@
28696 /*
28697 * Configuration information
28698 */
28699 +#ifdef CONFIG_GRKERNSEC_RANDNET
28700 +#define INPUT_POOL_WORDS 512
28701 +#define OUTPUT_POOL_WORDS 128
28702 +#else
28703 #define INPUT_POOL_WORDS 128
28704 #define OUTPUT_POOL_WORDS 32
28705 +#endif
28706 #define SEC_XFER_SIZE 512
28707 #define EXTRACT_SIZE 10
28708
28709 @@ -300,10 +305,17 @@ static struct poolinfo {
28710 int poolwords;
28711 int tap1, tap2, tap3, tap4, tap5;
28712 } poolinfo_table[] = {
28713 +#ifdef CONFIG_GRKERNSEC_RANDNET
28714 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28715 + { 512, 411, 308, 208, 104, 1 },
28716 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28717 + { 128, 103, 76, 51, 25, 1 },
28718 +#else
28719 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28720 { 128, 103, 76, 51, 25, 1 },
28721 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28722 { 32, 26, 20, 14, 7, 1 },
28723 +#endif
28724 #if 0
28725 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28726 { 2048, 1638, 1231, 819, 411, 1 },
28727 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
28728
28729 extract_buf(r, tmp);
28730 i = min_t(int, nbytes, EXTRACT_SIZE);
28731 - if (copy_to_user(buf, tmp, i)) {
28732 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
28733 ret = -EFAULT;
28734 break;
28735 }
28736 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28737 #include <linux/sysctl.h>
28738
28739 static int min_read_thresh = 8, min_write_thresh;
28740 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
28741 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28742 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28743 static char sysctl_bootid[16];
28744
28745 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
28746 index 1ee8ce7..b778bef 100644
28747 --- a/drivers/char/sonypi.c
28748 +++ b/drivers/char/sonypi.c
28749 @@ -55,6 +55,7 @@
28750 #include <asm/uaccess.h>
28751 #include <asm/io.h>
28752 #include <asm/system.h>
28753 +#include <asm/local.h>
28754
28755 #include <linux/sonypi.h>
28756
28757 @@ -491,7 +492,7 @@ static struct sonypi_device {
28758 spinlock_t fifo_lock;
28759 wait_queue_head_t fifo_proc_list;
28760 struct fasync_struct *fifo_async;
28761 - int open_count;
28762 + local_t open_count;
28763 int model;
28764 struct input_dev *input_jog_dev;
28765 struct input_dev *input_key_dev;
28766 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
28767 static int sonypi_misc_release(struct inode *inode, struct file *file)
28768 {
28769 mutex_lock(&sonypi_device.lock);
28770 - sonypi_device.open_count--;
28771 + local_dec(&sonypi_device.open_count);
28772 mutex_unlock(&sonypi_device.lock);
28773 return 0;
28774 }
28775 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
28776 {
28777 mutex_lock(&sonypi_device.lock);
28778 /* Flush input queue on first open */
28779 - if (!sonypi_device.open_count)
28780 + if (!local_read(&sonypi_device.open_count))
28781 kfifo_reset(&sonypi_device.fifo);
28782 - sonypi_device.open_count++;
28783 + local_inc(&sonypi_device.open_count);
28784 mutex_unlock(&sonypi_device.lock);
28785
28786 return 0;
28787 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
28788 index ad7c732..5aa8054 100644
28789 --- a/drivers/char/tpm/tpm.c
28790 +++ b/drivers/char/tpm/tpm.c
28791 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
28792 chip->vendor.req_complete_val)
28793 goto out_recv;
28794
28795 - if ((status == chip->vendor.req_canceled)) {
28796 + if (status == chip->vendor.req_canceled) {
28797 dev_err(chip->dev, "Operation Canceled\n");
28798 rc = -ECANCELED;
28799 goto out;
28800 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
28801 index 0636520..169c1d0 100644
28802 --- a/drivers/char/tpm/tpm_bios.c
28803 +++ b/drivers/char/tpm/tpm_bios.c
28804 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
28805 event = addr;
28806
28807 if ((event->event_type == 0 && event->event_size == 0) ||
28808 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28809 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28810 return NULL;
28811
28812 return addr;
28813 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
28814 return NULL;
28815
28816 if ((event->event_type == 0 && event->event_size == 0) ||
28817 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28818 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28819 return NULL;
28820
28821 (*pos)++;
28822 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
28823 int i;
28824
28825 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28826 - seq_putc(m, data[i]);
28827 + if (!seq_putc(m, data[i]))
28828 + return -EFAULT;
28829
28830 return 0;
28831 }
28832 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
28833 log->bios_event_log_end = log->bios_event_log + len;
28834
28835 virt = acpi_os_map_memory(start, len);
28836 + if (!virt) {
28837 + kfree(log->bios_event_log);
28838 + log->bios_event_log = NULL;
28839 + return -EFAULT;
28840 + }
28841
28842 - memcpy(log->bios_event_log, virt, len);
28843 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
28844
28845 acpi_os_unmap_memory(virt, len);
28846 return 0;
28847 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
28848 index b58b561..c9088c8 100644
28849 --- a/drivers/char/virtio_console.c
28850 +++ b/drivers/char/virtio_console.c
28851 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
28852 if (to_user) {
28853 ssize_t ret;
28854
28855 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
28856 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
28857 if (ret)
28858 return -EFAULT;
28859 } else {
28860 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
28861 if (!port_has_data(port) && !port->host_connected)
28862 return 0;
28863
28864 - return fill_readbuf(port, ubuf, count, true);
28865 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
28866 }
28867
28868 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
28869 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
28870 index c9eee6d..f9d5280 100644
28871 --- a/drivers/edac/amd64_edac.c
28872 +++ b/drivers/edac/amd64_edac.c
28873 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
28874 * PCI core identifies what devices are on a system during boot, and then
28875 * inquiry this table to see if this driver is for a given device found.
28876 */
28877 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
28878 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
28879 {
28880 .vendor = PCI_VENDOR_ID_AMD,
28881 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
28882 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
28883 index e47e73b..348e0bd 100644
28884 --- a/drivers/edac/amd76x_edac.c
28885 +++ b/drivers/edac/amd76x_edac.c
28886 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
28887 edac_mc_free(mci);
28888 }
28889
28890 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
28891 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
28892 {
28893 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28894 AMD762},
28895 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
28896 index 1af531a..3a8ff27 100644
28897 --- a/drivers/edac/e752x_edac.c
28898 +++ b/drivers/edac/e752x_edac.c
28899 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
28900 edac_mc_free(mci);
28901 }
28902
28903 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
28904 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
28905 {
28906 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28907 E7520},
28908 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
28909 index 6ffb6d2..383d8d7 100644
28910 --- a/drivers/edac/e7xxx_edac.c
28911 +++ b/drivers/edac/e7xxx_edac.c
28912 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
28913 edac_mc_free(mci);
28914 }
28915
28916 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
28917 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
28918 {
28919 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28920 E7205},
28921 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
28922 index 97f5064..202b6e6 100644
28923 --- a/drivers/edac/edac_pci_sysfs.c
28924 +++ b/drivers/edac/edac_pci_sysfs.c
28925 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
28926 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28927 static int edac_pci_poll_msec = 1000; /* one second workq period */
28928
28929 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
28930 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28931 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28932 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28933
28934 static struct kobject *edac_pci_top_main_kobj;
28935 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28936 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28937 edac_printk(KERN_CRIT, EDAC_PCI,
28938 "Signaled System Error on %s\n",
28939 pci_name(dev));
28940 - atomic_inc(&pci_nonparity_count);
28941 + atomic_inc_unchecked(&pci_nonparity_count);
28942 }
28943
28944 if (status & (PCI_STATUS_PARITY)) {
28945 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28946 "Master Data Parity Error on %s\n",
28947 pci_name(dev));
28948
28949 - atomic_inc(&pci_parity_count);
28950 + atomic_inc_unchecked(&pci_parity_count);
28951 }
28952
28953 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28954 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28955 "Detected Parity Error on %s\n",
28956 pci_name(dev));
28957
28958 - atomic_inc(&pci_parity_count);
28959 + atomic_inc_unchecked(&pci_parity_count);
28960 }
28961 }
28962
28963 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28964 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28965 "Signaled System Error on %s\n",
28966 pci_name(dev));
28967 - atomic_inc(&pci_nonparity_count);
28968 + atomic_inc_unchecked(&pci_nonparity_count);
28969 }
28970
28971 if (status & (PCI_STATUS_PARITY)) {
28972 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28973 "Master Data Parity Error on "
28974 "%s\n", pci_name(dev));
28975
28976 - atomic_inc(&pci_parity_count);
28977 + atomic_inc_unchecked(&pci_parity_count);
28978 }
28979
28980 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28981 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28982 "Detected Parity Error on %s\n",
28983 pci_name(dev));
28984
28985 - atomic_inc(&pci_parity_count);
28986 + atomic_inc_unchecked(&pci_parity_count);
28987 }
28988 }
28989 }
28990 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
28991 if (!check_pci_errors)
28992 return;
28993
28994 - before_count = atomic_read(&pci_parity_count);
28995 + before_count = atomic_read_unchecked(&pci_parity_count);
28996
28997 /* scan all PCI devices looking for a Parity Error on devices and
28998 * bridges.
28999 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29000 /* Only if operator has selected panic on PCI Error */
29001 if (edac_pci_get_panic_on_pe()) {
29002 /* If the count is different 'after' from 'before' */
29003 - if (before_count != atomic_read(&pci_parity_count))
29004 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29005 panic("EDAC: PCI Parity Error");
29006 }
29007 }
29008 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29009 index c0510b3..6e2a954 100644
29010 --- a/drivers/edac/i3000_edac.c
29011 +++ b/drivers/edac/i3000_edac.c
29012 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29013 edac_mc_free(mci);
29014 }
29015
29016 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29017 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29018 {
29019 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29020 I3000},
29021 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29022 index 73f55e200..5faaf59 100644
29023 --- a/drivers/edac/i3200_edac.c
29024 +++ b/drivers/edac/i3200_edac.c
29025 @@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29026 edac_mc_free(mci);
29027 }
29028
29029 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29030 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29031 {
29032 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29033 I3200},
29034 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29035 index 4dc3ac2..67d05a6 100644
29036 --- a/drivers/edac/i5000_edac.c
29037 +++ b/drivers/edac/i5000_edac.c
29038 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29039 *
29040 * The "E500P" device is the first device supported.
29041 */
29042 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29043 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
29044 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
29045 .driver_data = I5000P},
29046
29047 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
29048 index bcbdeec..9886d16 100644
29049 --- a/drivers/edac/i5100_edac.c
29050 +++ b/drivers/edac/i5100_edac.c
29051 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
29052 edac_mc_free(mci);
29053 }
29054
29055 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
29056 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
29057 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
29058 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
29059 { 0, }
29060 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
29061 index 74d6ec34..baff517 100644
29062 --- a/drivers/edac/i5400_edac.c
29063 +++ b/drivers/edac/i5400_edac.c
29064 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
29065 *
29066 * The "E500P" device is the first device supported.
29067 */
29068 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
29069 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
29070 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
29071 {0,} /* 0 terminated list. */
29072 };
29073 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
29074 index 6104dba..e7ea8e1 100644
29075 --- a/drivers/edac/i7300_edac.c
29076 +++ b/drivers/edac/i7300_edac.c
29077 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
29078 *
29079 * Has only 8086:360c PCI ID
29080 */
29081 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
29082 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
29083 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
29084 {0,} /* 0 terminated list. */
29085 };
29086 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
29087 index 8568d9b..42b2fa8 100644
29088 --- a/drivers/edac/i7core_edac.c
29089 +++ b/drivers/edac/i7core_edac.c
29090 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
29091 /*
29092 * pci_device_id table for which devices we are looking for
29093 */
29094 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
29095 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
29096 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
29097 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
29098 {0,} /* 0 terminated list. */
29099 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
29100 index 4329d39..f3022ef 100644
29101 --- a/drivers/edac/i82443bxgx_edac.c
29102 +++ b/drivers/edac/i82443bxgx_edac.c
29103 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
29104
29105 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
29106
29107 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
29108 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
29109 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
29110 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
29111 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
29112 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
29113 index 931a057..fd28340 100644
29114 --- a/drivers/edac/i82860_edac.c
29115 +++ b/drivers/edac/i82860_edac.c
29116 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
29117 edac_mc_free(mci);
29118 }
29119
29120 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
29121 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
29122 {
29123 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29124 I82860},
29125 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
29126 index 33864c6..01edc61 100644
29127 --- a/drivers/edac/i82875p_edac.c
29128 +++ b/drivers/edac/i82875p_edac.c
29129 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
29130 edac_mc_free(mci);
29131 }
29132
29133 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
29134 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
29135 {
29136 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29137 I82875P},
29138 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
29139 index 4184e01..dcb2cd3 100644
29140 --- a/drivers/edac/i82975x_edac.c
29141 +++ b/drivers/edac/i82975x_edac.c
29142 @@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
29143 edac_mc_free(mci);
29144 }
29145
29146 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
29147 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
29148 {
29149 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29150 I82975X
29151 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29152 index 0106747..0b40417 100644
29153 --- a/drivers/edac/mce_amd.h
29154 +++ b/drivers/edac/mce_amd.h
29155 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
29156 bool (*dc_mce)(u16, u8);
29157 bool (*ic_mce)(u16, u8);
29158 bool (*nb_mce)(u16, u8);
29159 -};
29160 +} __no_const;
29161
29162 void amd_report_gart_errors(bool);
29163 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29164 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
29165 index e294e1b..a41b05b 100644
29166 --- a/drivers/edac/r82600_edac.c
29167 +++ b/drivers/edac/r82600_edac.c
29168 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
29169 edac_mc_free(mci);
29170 }
29171
29172 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
29173 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
29174 {
29175 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
29176 },
29177 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
29178 index 1dc118d..8c68af9 100644
29179 --- a/drivers/edac/sb_edac.c
29180 +++ b/drivers/edac/sb_edac.c
29181 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
29182 /*
29183 * pci_device_id table for which devices we are looking for
29184 */
29185 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
29186 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
29187 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
29188 {0,} /* 0 terminated list. */
29189 };
29190 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
29191 index b6f47de..c5acf3a 100644
29192 --- a/drivers/edac/x38_edac.c
29193 +++ b/drivers/edac/x38_edac.c
29194 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
29195 edac_mc_free(mci);
29196 }
29197
29198 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
29199 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
29200 {
29201 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29202 X38},
29203 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29204 index 85661b0..c784559a 100644
29205 --- a/drivers/firewire/core-card.c
29206 +++ b/drivers/firewire/core-card.c
29207 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
29208
29209 void fw_core_remove_card(struct fw_card *card)
29210 {
29211 - struct fw_card_driver dummy_driver = dummy_driver_template;
29212 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29213
29214 card->driver->update_phy_reg(card, 4,
29215 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29216 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29217 index 4799393..37bd3ab 100644
29218 --- a/drivers/firewire/core-cdev.c
29219 +++ b/drivers/firewire/core-cdev.c
29220 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
29221 int ret;
29222
29223 if ((request->channels == 0 && request->bandwidth == 0) ||
29224 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29225 - request->bandwidth < 0)
29226 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29227 return -EINVAL;
29228
29229 r = kmalloc(sizeof(*r), GFP_KERNEL);
29230 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29231 index 855ab3f..11f4bbd 100644
29232 --- a/drivers/firewire/core-transaction.c
29233 +++ b/drivers/firewire/core-transaction.c
29234 @@ -37,6 +37,7 @@
29235 #include <linux/timer.h>
29236 #include <linux/types.h>
29237 #include <linux/workqueue.h>
29238 +#include <linux/sched.h>
29239
29240 #include <asm/byteorder.h>
29241
29242 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29243 index b45be57..5fad18b 100644
29244 --- a/drivers/firewire/core.h
29245 +++ b/drivers/firewire/core.h
29246 @@ -101,6 +101,7 @@ struct fw_card_driver {
29247
29248 int (*stop_iso)(struct fw_iso_context *ctx);
29249 };
29250 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29251
29252 void fw_card_initialize(struct fw_card *card,
29253 const struct fw_card_driver *driver, struct device *device);
29254 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29255 index 153980b..4b4d046 100644
29256 --- a/drivers/firmware/dmi_scan.c
29257 +++ b/drivers/firmware/dmi_scan.c
29258 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29259 }
29260 }
29261 else {
29262 - /*
29263 - * no iounmap() for that ioremap(); it would be a no-op, but
29264 - * it's so early in setup that sucker gets confused into doing
29265 - * what it shouldn't if we actually call it.
29266 - */
29267 p = dmi_ioremap(0xF0000, 0x10000);
29268 if (p == NULL)
29269 goto error;
29270 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29271 if (buf == NULL)
29272 return -1;
29273
29274 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29275 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29276
29277 iounmap(buf);
29278 return 0;
29279 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29280 index 82d5c20..44a7177 100644
29281 --- a/drivers/gpio/gpio-vr41xx.c
29282 +++ b/drivers/gpio/gpio-vr41xx.c
29283 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29284 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29285 maskl, pendl, maskh, pendh);
29286
29287 - atomic_inc(&irq_err_count);
29288 + atomic_inc_unchecked(&irq_err_count);
29289
29290 return -EINVAL;
29291 }
29292 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29293 index 84a4a80..ce0306e 100644
29294 --- a/drivers/gpu/drm/drm_crtc_helper.c
29295 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29296 @@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29297 struct drm_crtc *tmp;
29298 int crtc_mask = 1;
29299
29300 - WARN(!crtc, "checking null crtc?\n");
29301 + BUG_ON(!crtc);
29302
29303 dev = crtc->dev;
29304
29305 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
29306 index ebf7d3f..d64c436 100644
29307 --- a/drivers/gpu/drm/drm_drv.c
29308 +++ b/drivers/gpu/drm/drm_drv.c
29309 @@ -312,7 +312,7 @@ module_exit(drm_core_exit);
29310 /**
29311 * Copy and IOCTL return string to user space
29312 */
29313 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
29314 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
29315 {
29316 int len;
29317
29318 @@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
29319
29320 dev = file_priv->minor->dev;
29321 atomic_inc(&dev->ioctl_count);
29322 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
29323 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
29324 ++file_priv->ioctl_count;
29325
29326 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
29327 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
29328 index 6263b01..7987f55 100644
29329 --- a/drivers/gpu/drm/drm_fops.c
29330 +++ b/drivers/gpu/drm/drm_fops.c
29331 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
29332 }
29333
29334 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
29335 - atomic_set(&dev->counts[i], 0);
29336 + atomic_set_unchecked(&dev->counts[i], 0);
29337
29338 dev->sigdata.lock = NULL;
29339
29340 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
29341
29342 retcode = drm_open_helper(inode, filp, dev);
29343 if (!retcode) {
29344 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
29345 - if (!dev->open_count++)
29346 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
29347 + if (local_inc_return(&dev->open_count) == 1)
29348 retcode = drm_setup(dev);
29349 }
29350 if (!retcode) {
29351 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
29352
29353 mutex_lock(&drm_global_mutex);
29354
29355 - DRM_DEBUG("open_count = %d\n", dev->open_count);
29356 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
29357
29358 if (dev->driver->preclose)
29359 dev->driver->preclose(dev, file_priv);
29360 @@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
29361 * Begin inline drm_release
29362 */
29363
29364 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
29365 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
29366 task_pid_nr(current),
29367 (long)old_encode_dev(file_priv->minor->device),
29368 - dev->open_count);
29369 + local_read(&dev->open_count));
29370
29371 /* Release any auth tokens that might point to this file_priv,
29372 (do that under the drm_global_mutex) */
29373 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
29374 * End inline drm_release
29375 */
29376
29377 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
29378 - if (!--dev->open_count) {
29379 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
29380 + if (local_dec_and_test(&dev->open_count)) {
29381 if (atomic_read(&dev->ioctl_count)) {
29382 DRM_ERROR("Device busy: %d\n",
29383 atomic_read(&dev->ioctl_count));
29384 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
29385 index c87dc96..326055d 100644
29386 --- a/drivers/gpu/drm/drm_global.c
29387 +++ b/drivers/gpu/drm/drm_global.c
29388 @@ -36,7 +36,7 @@
29389 struct drm_global_item {
29390 struct mutex mutex;
29391 void *object;
29392 - int refcount;
29393 + atomic_t refcount;
29394 };
29395
29396 static struct drm_global_item glob[DRM_GLOBAL_NUM];
29397 @@ -49,7 +49,7 @@ void drm_global_init(void)
29398 struct drm_global_item *item = &glob[i];
29399 mutex_init(&item->mutex);
29400 item->object = NULL;
29401 - item->refcount = 0;
29402 + atomic_set(&item->refcount, 0);
29403 }
29404 }
29405
29406 @@ -59,7 +59,7 @@ void drm_global_release(void)
29407 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
29408 struct drm_global_item *item = &glob[i];
29409 BUG_ON(item->object != NULL);
29410 - BUG_ON(item->refcount != 0);
29411 + BUG_ON(atomic_read(&item->refcount) != 0);
29412 }
29413 }
29414
29415 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
29416 void *object;
29417
29418 mutex_lock(&item->mutex);
29419 - if (item->refcount == 0) {
29420 + if (atomic_read(&item->refcount) == 0) {
29421 item->object = kzalloc(ref->size, GFP_KERNEL);
29422 if (unlikely(item->object == NULL)) {
29423 ret = -ENOMEM;
29424 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
29425 goto out_err;
29426
29427 }
29428 - ++item->refcount;
29429 + atomic_inc(&item->refcount);
29430 ref->object = item->object;
29431 object = item->object;
29432 mutex_unlock(&item->mutex);
29433 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
29434 struct drm_global_item *item = &glob[ref->global_type];
29435
29436 mutex_lock(&item->mutex);
29437 - BUG_ON(item->refcount == 0);
29438 + BUG_ON(atomic_read(&item->refcount) == 0);
29439 BUG_ON(ref->object != item->object);
29440 - if (--item->refcount == 0) {
29441 + if (atomic_dec_and_test(&item->refcount)) {
29442 ref->release(ref);
29443 item->object = NULL;
29444 }
29445 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
29446 index ab1162d..42587b2 100644
29447 --- a/drivers/gpu/drm/drm_info.c
29448 +++ b/drivers/gpu/drm/drm_info.c
29449 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
29450 struct drm_local_map *map;
29451 struct drm_map_list *r_list;
29452
29453 - /* Hardcoded from _DRM_FRAME_BUFFER,
29454 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
29455 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
29456 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
29457 + static const char * const types[] = {
29458 + [_DRM_FRAME_BUFFER] = "FB",
29459 + [_DRM_REGISTERS] = "REG",
29460 + [_DRM_SHM] = "SHM",
29461 + [_DRM_AGP] = "AGP",
29462 + [_DRM_SCATTER_GATHER] = "SG",
29463 + [_DRM_CONSISTENT] = "PCI",
29464 + [_DRM_GEM] = "GEM" };
29465 const char *type;
29466 int i;
29467
29468 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
29469 map = r_list->map;
29470 if (!map)
29471 continue;
29472 - if (map->type < 0 || map->type > 5)
29473 + if (map->type >= ARRAY_SIZE(types))
29474 type = "??";
29475 else
29476 type = types[map->type];
29477 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
29478 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
29479 vma->vm_flags & VM_LOCKED ? 'l' : '-',
29480 vma->vm_flags & VM_IO ? 'i' : '-',
29481 +#ifdef CONFIG_GRKERNSEC_HIDESYM
29482 + 0);
29483 +#else
29484 vma->vm_pgoff);
29485 +#endif
29486
29487 #if defined(__i386__)
29488 pgprot = pgprot_val(vma->vm_page_prot);
29489 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
29490 index 637fcc3..e890b33 100644
29491 --- a/drivers/gpu/drm/drm_ioc32.c
29492 +++ b/drivers/gpu/drm/drm_ioc32.c
29493 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
29494 request = compat_alloc_user_space(nbytes);
29495 if (!access_ok(VERIFY_WRITE, request, nbytes))
29496 return -EFAULT;
29497 - list = (struct drm_buf_desc *) (request + 1);
29498 + list = (struct drm_buf_desc __user *) (request + 1);
29499
29500 if (__put_user(count, &request->count)
29501 || __put_user(list, &request->list))
29502 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
29503 request = compat_alloc_user_space(nbytes);
29504 if (!access_ok(VERIFY_WRITE, request, nbytes))
29505 return -EFAULT;
29506 - list = (struct drm_buf_pub *) (request + 1);
29507 + list = (struct drm_buf_pub __user *) (request + 1);
29508
29509 if (__put_user(count, &request->count)
29510 || __put_user(list, &request->list))
29511 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
29512 index 956fd38..e52167a 100644
29513 --- a/drivers/gpu/drm/drm_ioctl.c
29514 +++ b/drivers/gpu/drm/drm_ioctl.c
29515 @@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
29516 stats->data[i].value =
29517 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
29518 else
29519 - stats->data[i].value = atomic_read(&dev->counts[i]);
29520 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
29521 stats->data[i].type = dev->types[i];
29522 }
29523
29524 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
29525 index c79c713..2048588 100644
29526 --- a/drivers/gpu/drm/drm_lock.c
29527 +++ b/drivers/gpu/drm/drm_lock.c
29528 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
29529 if (drm_lock_take(&master->lock, lock->context)) {
29530 master->lock.file_priv = file_priv;
29531 master->lock.lock_time = jiffies;
29532 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
29533 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
29534 break; /* Got lock */
29535 }
29536
29537 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
29538 return -EINVAL;
29539 }
29540
29541 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
29542 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
29543
29544 if (drm_lock_free(&master->lock, lock->context)) {
29545 /* FIXME: Should really bail out here. */
29546 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
29547 index 7f4b4e1..bf4def2 100644
29548 --- a/drivers/gpu/drm/i810/i810_dma.c
29549 +++ b/drivers/gpu/drm/i810/i810_dma.c
29550 @@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
29551 dma->buflist[vertex->idx],
29552 vertex->discard, vertex->used);
29553
29554 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29555 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29556 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29557 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29558 sarea_priv->last_enqueue = dev_priv->counter - 1;
29559 sarea_priv->last_dispatch = (int)hw_status[5];
29560
29561 @@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
29562 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
29563 mc->last_render);
29564
29565 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29566 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29567 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29568 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29569 sarea_priv->last_enqueue = dev_priv->counter - 1;
29570 sarea_priv->last_dispatch = (int)hw_status[5];
29571
29572 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
29573 index c9339f4..f5e1b9d 100644
29574 --- a/drivers/gpu/drm/i810/i810_drv.h
29575 +++ b/drivers/gpu/drm/i810/i810_drv.h
29576 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
29577 int page_flipping;
29578
29579 wait_queue_head_t irq_queue;
29580 - atomic_t irq_received;
29581 - atomic_t irq_emitted;
29582 + atomic_unchecked_t irq_received;
29583 + atomic_unchecked_t irq_emitted;
29584
29585 int front_offset;
29586 } drm_i810_private_t;
29587 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
29588 index deaa657..e0fd296 100644
29589 --- a/drivers/gpu/drm/i915/i915_debugfs.c
29590 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
29591 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
29592 I915_READ(GTIMR));
29593 }
29594 seq_printf(m, "Interrupts received: %d\n",
29595 - atomic_read(&dev_priv->irq_received));
29596 + atomic_read_unchecked(&dev_priv->irq_received));
29597 for (i = 0; i < I915_NUM_RINGS; i++) {
29598 if (IS_GEN6(dev) || IS_GEN7(dev)) {
29599 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
29600 @@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
29601 return ret;
29602
29603 if (opregion->header)
29604 - seq_write(m, opregion->header, OPREGION_SIZE);
29605 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
29606
29607 mutex_unlock(&dev->struct_mutex);
29608
29609 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
29610 index ddfe3d9..f6e6b21 100644
29611 --- a/drivers/gpu/drm/i915/i915_dma.c
29612 +++ b/drivers/gpu/drm/i915/i915_dma.c
29613 @@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
29614 bool can_switch;
29615
29616 spin_lock(&dev->count_lock);
29617 - can_switch = (dev->open_count == 0);
29618 + can_switch = (local_read(&dev->open_count) == 0);
29619 spin_unlock(&dev->count_lock);
29620 return can_switch;
29621 }
29622 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
29623 index 9689ca3..294f9c1 100644
29624 --- a/drivers/gpu/drm/i915/i915_drv.h
29625 +++ b/drivers/gpu/drm/i915/i915_drv.h
29626 @@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
29627 /* render clock increase/decrease */
29628 /* display clock increase/decrease */
29629 /* pll clock increase/decrease */
29630 -};
29631 +} __no_const;
29632
29633 struct intel_device_info {
29634 u8 gen;
29635 @@ -320,7 +320,7 @@ typedef struct drm_i915_private {
29636 int current_page;
29637 int page_flipping;
29638
29639 - atomic_t irq_received;
29640 + atomic_unchecked_t irq_received;
29641
29642 /* protects the irq masks */
29643 spinlock_t irq_lock;
29644 @@ -896,7 +896,7 @@ struct drm_i915_gem_object {
29645 * will be page flipped away on the next vblank. When it
29646 * reaches 0, dev_priv->pending_flip_queue will be woken up.
29647 */
29648 - atomic_t pending_flip;
29649 + atomic_unchecked_t pending_flip;
29650 };
29651
29652 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
29653 @@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
29654 extern void intel_teardown_gmbus(struct drm_device *dev);
29655 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
29656 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
29657 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29658 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29659 {
29660 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
29661 }
29662 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29663 index 65e1f00..a30ef00 100644
29664 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29665 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29666 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
29667 i915_gem_clflush_object(obj);
29668
29669 if (obj->base.pending_write_domain)
29670 - cd->flips |= atomic_read(&obj->pending_flip);
29671 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
29672
29673 /* The actual obj->write_domain will be updated with
29674 * pending_write_domain after we emit the accumulated flush for all
29675 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
29676
29677 static int
29678 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
29679 - int count)
29680 + unsigned int count)
29681 {
29682 - int i;
29683 + unsigned int i;
29684
29685 for (i = 0; i < count; i++) {
29686 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
29687 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
29688 index 5bd4361..0241a42 100644
29689 --- a/drivers/gpu/drm/i915/i915_irq.c
29690 +++ b/drivers/gpu/drm/i915/i915_irq.c
29691 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
29692 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
29693 struct drm_i915_master_private *master_priv;
29694
29695 - atomic_inc(&dev_priv->irq_received);
29696 + atomic_inc_unchecked(&dev_priv->irq_received);
29697
29698 /* disable master interrupt before clearing iir */
29699 de_ier = I915_READ(DEIER);
29700 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
29701 struct drm_i915_master_private *master_priv;
29702 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
29703
29704 - atomic_inc(&dev_priv->irq_received);
29705 + atomic_inc_unchecked(&dev_priv->irq_received);
29706
29707 if (IS_GEN6(dev))
29708 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
29709 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
29710 int ret = IRQ_NONE, pipe;
29711 bool blc_event = false;
29712
29713 - atomic_inc(&dev_priv->irq_received);
29714 + atomic_inc_unchecked(&dev_priv->irq_received);
29715
29716 iir = I915_READ(IIR);
29717
29718 @@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
29719 {
29720 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29721
29722 - atomic_set(&dev_priv->irq_received, 0);
29723 + atomic_set_unchecked(&dev_priv->irq_received, 0);
29724
29725 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29726 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29727 @@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
29728 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29729 int pipe;
29730
29731 - atomic_set(&dev_priv->irq_received, 0);
29732 + atomic_set_unchecked(&dev_priv->irq_received, 0);
29733
29734 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29735 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29736 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
29737 index 397087c..9178d0d 100644
29738 --- a/drivers/gpu/drm/i915/intel_display.c
29739 +++ b/drivers/gpu/drm/i915/intel_display.c
29740 @@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
29741
29742 wait_event(dev_priv->pending_flip_queue,
29743 atomic_read(&dev_priv->mm.wedged) ||
29744 - atomic_read(&obj->pending_flip) == 0);
29745 + atomic_read_unchecked(&obj->pending_flip) == 0);
29746
29747 /* Big Hammer, we also need to ensure that any pending
29748 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
29749 @@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
29750 obj = to_intel_framebuffer(crtc->fb)->obj;
29751 dev_priv = crtc->dev->dev_private;
29752 wait_event(dev_priv->pending_flip_queue,
29753 - atomic_read(&obj->pending_flip) == 0);
29754 + atomic_read_unchecked(&obj->pending_flip) == 0);
29755 }
29756
29757 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
29758 @@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
29759
29760 atomic_clear_mask(1 << intel_crtc->plane,
29761 &obj->pending_flip.counter);
29762 - if (atomic_read(&obj->pending_flip) == 0)
29763 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
29764 wake_up(&dev_priv->pending_flip_queue);
29765
29766 schedule_work(&work->work);
29767 @@ -7461,7 +7461,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
29768 /* Block clients from rendering to the new back buffer until
29769 * the flip occurs and the object is no longer visible.
29770 */
29771 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29772 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29773
29774 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
29775 if (ret)
29776 @@ -7475,7 +7475,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
29777 return 0;
29778
29779 cleanup_pending:
29780 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29781 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29782 drm_gem_object_unreference(&work->old_fb_obj->base);
29783 drm_gem_object_unreference(&obj->base);
29784 mutex_unlock(&dev->struct_mutex);
29785 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
29786 index 54558a0..2d97005 100644
29787 --- a/drivers/gpu/drm/mga/mga_drv.h
29788 +++ b/drivers/gpu/drm/mga/mga_drv.h
29789 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29790 u32 clear_cmd;
29791 u32 maccess;
29792
29793 - atomic_t vbl_received; /**< Number of vblanks received. */
29794 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29795 wait_queue_head_t fence_queue;
29796 - atomic_t last_fence_retired;
29797 + atomic_unchecked_t last_fence_retired;
29798 u32 next_fence_to_post;
29799
29800 unsigned int fb_cpp;
29801 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
29802 index 2581202..f230a8d9 100644
29803 --- a/drivers/gpu/drm/mga/mga_irq.c
29804 +++ b/drivers/gpu/drm/mga/mga_irq.c
29805 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
29806 if (crtc != 0)
29807 return 0;
29808
29809 - return atomic_read(&dev_priv->vbl_received);
29810 + return atomic_read_unchecked(&dev_priv->vbl_received);
29811 }
29812
29813
29814 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
29815 /* VBLANK interrupt */
29816 if (status & MGA_VLINEPEN) {
29817 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29818 - atomic_inc(&dev_priv->vbl_received);
29819 + atomic_inc_unchecked(&dev_priv->vbl_received);
29820 drm_handle_vblank(dev, 0);
29821 handled = 1;
29822 }
29823 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
29824 if ((prim_start & ~0x03) != (prim_end & ~0x03))
29825 MGA_WRITE(MGA_PRIMEND, prim_end);
29826
29827 - atomic_inc(&dev_priv->last_fence_retired);
29828 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
29829 DRM_WAKEUP(&dev_priv->fence_queue);
29830 handled = 1;
29831 }
29832 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
29833 * using fences.
29834 */
29835 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29836 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29837 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29838 - *sequence) <= (1 << 23)));
29839
29840 *sequence = cur_fence;
29841 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
29842 index e5cbead..6c354a3 100644
29843 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
29844 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
29845 @@ -199,7 +199,7 @@ struct methods {
29846 const char desc[8];
29847 void (*loadbios)(struct drm_device *, uint8_t *);
29848 const bool rw;
29849 -};
29850 +} __do_const;
29851
29852 static struct methods shadow_methods[] = {
29853 { "PRAMIN", load_vbios_pramin, true },
29854 @@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
29855 struct bit_table {
29856 const char id;
29857 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
29858 -};
29859 +} __no_const;
29860
29861 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
29862
29863 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
29864 index b827098..c31a797 100644
29865 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
29866 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
29867 @@ -242,7 +242,7 @@ struct nouveau_channel {
29868 struct list_head pending;
29869 uint32_t sequence;
29870 uint32_t sequence_ack;
29871 - atomic_t last_sequence_irq;
29872 + atomic_unchecked_t last_sequence_irq;
29873 struct nouveau_vma vma;
29874 } fence;
29875
29876 @@ -323,7 +323,7 @@ struct nouveau_exec_engine {
29877 u32 handle, u16 class);
29878 void (*set_tile_region)(struct drm_device *dev, int i);
29879 void (*tlb_flush)(struct drm_device *, int engine);
29880 -};
29881 +} __no_const;
29882
29883 struct nouveau_instmem_engine {
29884 void *priv;
29885 @@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
29886 struct nouveau_mc_engine {
29887 int (*init)(struct drm_device *dev);
29888 void (*takedown)(struct drm_device *dev);
29889 -};
29890 +} __no_const;
29891
29892 struct nouveau_timer_engine {
29893 int (*init)(struct drm_device *dev);
29894 void (*takedown)(struct drm_device *dev);
29895 uint64_t (*read)(struct drm_device *dev);
29896 -};
29897 +} __no_const;
29898
29899 struct nouveau_fb_engine {
29900 int num_tiles;
29901 @@ -566,7 +566,7 @@ struct nouveau_vram_engine {
29902 void (*put)(struct drm_device *, struct nouveau_mem **);
29903
29904 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
29905 -};
29906 +} __no_const;
29907
29908 struct nouveau_engine {
29909 struct nouveau_instmem_engine instmem;
29910 @@ -714,7 +714,7 @@ struct drm_nouveau_private {
29911 struct drm_global_reference mem_global_ref;
29912 struct ttm_bo_global_ref bo_global_ref;
29913 struct ttm_bo_device bdev;
29914 - atomic_t validate_sequence;
29915 + atomic_unchecked_t validate_sequence;
29916 } ttm;
29917
29918 struct {
29919 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
29920 index 2f6daae..c9d7b9e 100644
29921 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
29922 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
29923 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
29924 if (USE_REFCNT(dev))
29925 sequence = nvchan_rd32(chan, 0x48);
29926 else
29927 - sequence = atomic_read(&chan->fence.last_sequence_irq);
29928 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
29929
29930 if (chan->fence.sequence_ack == sequence)
29931 goto out;
29932 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
29933 return ret;
29934 }
29935
29936 - atomic_set(&chan->fence.last_sequence_irq, 0);
29937 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
29938 return 0;
29939 }
29940
29941 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
29942 index 7ce3fde..cb3ea04 100644
29943 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
29944 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
29945 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
29946 int trycnt = 0;
29947 int ret, i;
29948
29949 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
29950 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
29951 retry:
29952 if (++trycnt > 100000) {
29953 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
29954 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
29955 index f80c5e0..936baa7 100644
29956 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
29957 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
29958 @@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
29959 bool can_switch;
29960
29961 spin_lock(&dev->count_lock);
29962 - can_switch = (dev->open_count == 0);
29963 + can_switch = (local_read(&dev->open_count) == 0);
29964 spin_unlock(&dev->count_lock);
29965 return can_switch;
29966 }
29967 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
29968 index dbdea8e..cd6eeeb 100644
29969 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
29970 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
29971 @@ -554,7 +554,7 @@ static int
29972 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
29973 u32 class, u32 mthd, u32 data)
29974 {
29975 - atomic_set(&chan->fence.last_sequence_irq, data);
29976 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
29977 return 0;
29978 }
29979
29980 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
29981 index bcac90b..53bfc76 100644
29982 --- a/drivers/gpu/drm/r128/r128_cce.c
29983 +++ b/drivers/gpu/drm/r128/r128_cce.c
29984 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
29985
29986 /* GH: Simple idle check.
29987 */
29988 - atomic_set(&dev_priv->idle_count, 0);
29989 + atomic_set_unchecked(&dev_priv->idle_count, 0);
29990
29991 /* We don't support anything other than bus-mastering ring mode,
29992 * but the ring can be in either AGP or PCI space for the ring
29993 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
29994 index 930c71b..499aded 100644
29995 --- a/drivers/gpu/drm/r128/r128_drv.h
29996 +++ b/drivers/gpu/drm/r128/r128_drv.h
29997 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29998 int is_pci;
29999 unsigned long cce_buffers_offset;
30000
30001 - atomic_t idle_count;
30002 + atomic_unchecked_t idle_count;
30003
30004 int page_flipping;
30005 int current_page;
30006 u32 crtc_offset;
30007 u32 crtc_offset_cntl;
30008
30009 - atomic_t vbl_received;
30010 + atomic_unchecked_t vbl_received;
30011
30012 u32 color_fmt;
30013 unsigned int front_offset;
30014 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30015 index 429d5a0..7e899ed 100644
30016 --- a/drivers/gpu/drm/r128/r128_irq.c
30017 +++ b/drivers/gpu/drm/r128/r128_irq.c
30018 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30019 if (crtc != 0)
30020 return 0;
30021
30022 - return atomic_read(&dev_priv->vbl_received);
30023 + return atomic_read_unchecked(&dev_priv->vbl_received);
30024 }
30025
30026 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30027 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30028 /* VBLANK interrupt */
30029 if (status & R128_CRTC_VBLANK_INT) {
30030 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30031 - atomic_inc(&dev_priv->vbl_received);
30032 + atomic_inc_unchecked(&dev_priv->vbl_received);
30033 drm_handle_vblank(dev, 0);
30034 return IRQ_HANDLED;
30035 }
30036 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30037 index a9e33ce..09edd4b 100644
30038 --- a/drivers/gpu/drm/r128/r128_state.c
30039 +++ b/drivers/gpu/drm/r128/r128_state.c
30040 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30041
30042 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30043 {
30044 - if (atomic_read(&dev_priv->idle_count) == 0)
30045 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30046 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30047 else
30048 - atomic_set(&dev_priv->idle_count, 0);
30049 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30050 }
30051
30052 #endif
30053 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30054 index 5a82b6b..9e69c73 100644
30055 --- a/drivers/gpu/drm/radeon/mkregtable.c
30056 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30057 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30058 regex_t mask_rex;
30059 regmatch_t match[4];
30060 char buf[1024];
30061 - size_t end;
30062 + long end;
30063 int len;
30064 int done = 0;
30065 int r;
30066 unsigned o;
30067 struct offset *offset;
30068 char last_reg_s[10];
30069 - int last_reg;
30070 + unsigned long last_reg;
30071
30072 if (regcomp
30073 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30074 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30075 index 1668ec1..30ebdab 100644
30076 --- a/drivers/gpu/drm/radeon/radeon.h
30077 +++ b/drivers/gpu/drm/radeon/radeon.h
30078 @@ -250,7 +250,7 @@ struct radeon_fence_driver {
30079 uint32_t scratch_reg;
30080 uint64_t gpu_addr;
30081 volatile uint32_t *cpu_addr;
30082 - atomic_t seq;
30083 + atomic_unchecked_t seq;
30084 uint32_t last_seq;
30085 unsigned long last_jiffies;
30086 unsigned long last_timeout;
30087 @@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
30088 int x2, int y2);
30089 void (*draw_auto)(struct radeon_device *rdev);
30090 void (*set_default_state)(struct radeon_device *rdev);
30091 -};
30092 +} __no_const;
30093
30094 struct r600_blit {
30095 struct mutex mutex;
30096 @@ -1201,7 +1201,7 @@ struct radeon_asic {
30097 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
30098 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30099 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30100 -};
30101 +} __no_const;
30102
30103 /*
30104 * Asic structures
30105 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30106 index 49f7cb7..2fcb48f 100644
30107 --- a/drivers/gpu/drm/radeon/radeon_device.c
30108 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30109 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30110 bool can_switch;
30111
30112 spin_lock(&dev->count_lock);
30113 - can_switch = (dev->open_count == 0);
30114 + can_switch = (local_read(&dev->open_count) == 0);
30115 spin_unlock(&dev->count_lock);
30116 return can_switch;
30117 }
30118 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30119 index a1b59ca..86f2d44 100644
30120 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30121 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30122 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30123
30124 /* SW interrupt */
30125 wait_queue_head_t swi_queue;
30126 - atomic_t swi_emitted;
30127 + atomic_unchecked_t swi_emitted;
30128 int vblank_crtc;
30129 uint32_t irq_enable_reg;
30130 uint32_t r500_disp_irq_reg;
30131 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30132 index 4bd36a3..e66fe9c 100644
30133 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30134 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30135 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30136 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30137 return 0;
30138 }
30139 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30140 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30141 if (!rdev->ring[fence->ring].ready)
30142 /* FIXME: cp is not running assume everythings is done right
30143 * away
30144 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30145 }
30146 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30147 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30148 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30149 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30150 rdev->fence_drv[ring].initialized = true;
30151 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30152 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30153 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30154 rdev->fence_drv[ring].scratch_reg = -1;
30155 rdev->fence_drv[ring].cpu_addr = NULL;
30156 rdev->fence_drv[ring].gpu_addr = 0;
30157 - atomic_set(&rdev->fence_drv[ring].seq, 0);
30158 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30159 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30160 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30161 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30162 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30163 index 48b7cea..342236f 100644
30164 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30165 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30166 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30167 request = compat_alloc_user_space(sizeof(*request));
30168 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30169 || __put_user(req32.param, &request->param)
30170 - || __put_user((void __user *)(unsigned long)req32.value,
30171 + || __put_user((unsigned long)req32.value,
30172 &request->value))
30173 return -EFAULT;
30174
30175 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30176 index 00da384..32f972d 100644
30177 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30178 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30179 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30180 unsigned int ret;
30181 RING_LOCALS;
30182
30183 - atomic_inc(&dev_priv->swi_emitted);
30184 - ret = atomic_read(&dev_priv->swi_emitted);
30185 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30186 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30187
30188 BEGIN_RING(4);
30189 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30190 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30191 drm_radeon_private_t *dev_priv =
30192 (drm_radeon_private_t *) dev->dev_private;
30193
30194 - atomic_set(&dev_priv->swi_emitted, 0);
30195 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30196 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30197
30198 dev->max_vblank_count = 0x001fffff;
30199 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30200 index e8422ae..d22d4a8 100644
30201 --- a/drivers/gpu/drm/radeon/radeon_state.c
30202 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30203 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30204 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30205 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30206
30207 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30208 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30209 sarea_priv->nbox * sizeof(depth_boxes[0])))
30210 return -EFAULT;
30211
30212 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30213 {
30214 drm_radeon_private_t *dev_priv = dev->dev_private;
30215 drm_radeon_getparam_t *param = data;
30216 - int value;
30217 + int value = 0;
30218
30219 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30220
30221 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30222 index c421e77..e6bf2e8 100644
30223 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30224 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30225 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30226 }
30227 if (unlikely(ttm_vm_ops == NULL)) {
30228 ttm_vm_ops = vma->vm_ops;
30229 - radeon_ttm_vm_ops = *ttm_vm_ops;
30230 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30231 + pax_open_kernel();
30232 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30233 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30234 + pax_close_kernel();
30235 }
30236 vma->vm_ops = &radeon_ttm_vm_ops;
30237 return 0;
30238 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30239 index f68dff2..8df955c 100644
30240 --- a/drivers/gpu/drm/radeon/rs690.c
30241 +++ b/drivers/gpu/drm/radeon/rs690.c
30242 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30243 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30244 rdev->pm.sideport_bandwidth.full)
30245 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30246 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30247 + read_delay_latency.full = dfixed_const(800 * 1000);
30248 read_delay_latency.full = dfixed_div(read_delay_latency,
30249 rdev->pm.igp_sideport_mclk);
30250 + a.full = dfixed_const(370);
30251 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30252 } else {
30253 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30254 rdev->pm.k8_bandwidth.full)
30255 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30256 index 499debd..66fce72 100644
30257 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30258 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30259 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
30260 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30261 struct shrink_control *sc)
30262 {
30263 - static atomic_t start_pool = ATOMIC_INIT(0);
30264 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30265 unsigned i;
30266 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30267 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30268 struct ttm_page_pool *pool;
30269 int shrink_pages = sc->nr_to_scan;
30270
30271 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30272 index 88edacc..1e5412b 100644
30273 --- a/drivers/gpu/drm/via/via_drv.h
30274 +++ b/drivers/gpu/drm/via/via_drv.h
30275 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30276 typedef uint32_t maskarray_t[5];
30277
30278 typedef struct drm_via_irq {
30279 - atomic_t irq_received;
30280 + atomic_unchecked_t irq_received;
30281 uint32_t pending_mask;
30282 uint32_t enable_mask;
30283 wait_queue_head_t irq_queue;
30284 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30285 struct timeval last_vblank;
30286 int last_vblank_valid;
30287 unsigned usec_per_vblank;
30288 - atomic_t vbl_received;
30289 + atomic_unchecked_t vbl_received;
30290 drm_via_state_t hc_state;
30291 char pci_buf[VIA_PCI_BUF_SIZE];
30292 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30293 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30294 index d391f48..10c8ca3 100644
30295 --- a/drivers/gpu/drm/via/via_irq.c
30296 +++ b/drivers/gpu/drm/via/via_irq.c
30297 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30298 if (crtc != 0)
30299 return 0;
30300
30301 - return atomic_read(&dev_priv->vbl_received);
30302 + return atomic_read_unchecked(&dev_priv->vbl_received);
30303 }
30304
30305 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30306 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30307
30308 status = VIA_READ(VIA_REG_INTERRUPT);
30309 if (status & VIA_IRQ_VBLANK_PENDING) {
30310 - atomic_inc(&dev_priv->vbl_received);
30311 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30312 + atomic_inc_unchecked(&dev_priv->vbl_received);
30313 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30314 do_gettimeofday(&cur_vblank);
30315 if (dev_priv->last_vblank_valid) {
30316 dev_priv->usec_per_vblank =
30317 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30318 dev_priv->last_vblank = cur_vblank;
30319 dev_priv->last_vblank_valid = 1;
30320 }
30321 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30322 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30323 DRM_DEBUG("US per vblank is: %u\n",
30324 dev_priv->usec_per_vblank);
30325 }
30326 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30327
30328 for (i = 0; i < dev_priv->num_irqs; ++i) {
30329 if (status & cur_irq->pending_mask) {
30330 - atomic_inc(&cur_irq->irq_received);
30331 + atomic_inc_unchecked(&cur_irq->irq_received);
30332 DRM_WAKEUP(&cur_irq->irq_queue);
30333 handled = 1;
30334 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
30335 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
30336 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30337 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
30338 masks[irq][4]));
30339 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
30340 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
30341 } else {
30342 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30343 (((cur_irq_sequence =
30344 - atomic_read(&cur_irq->irq_received)) -
30345 + atomic_read_unchecked(&cur_irq->irq_received)) -
30346 *sequence) <= (1 << 23)));
30347 }
30348 *sequence = cur_irq_sequence;
30349 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
30350 }
30351
30352 for (i = 0; i < dev_priv->num_irqs; ++i) {
30353 - atomic_set(&cur_irq->irq_received, 0);
30354 + atomic_set_unchecked(&cur_irq->irq_received, 0);
30355 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
30356 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
30357 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
30358 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
30359 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
30360 case VIA_IRQ_RELATIVE:
30361 irqwait->request.sequence +=
30362 - atomic_read(&cur_irq->irq_received);
30363 + atomic_read_unchecked(&cur_irq->irq_received);
30364 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
30365 case VIA_IRQ_ABSOLUTE:
30366 break;
30367 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30368 index dc27970..f18b008 100644
30369 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30370 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30371 @@ -260,7 +260,7 @@ struct vmw_private {
30372 * Fencing and IRQs.
30373 */
30374
30375 - atomic_t marker_seq;
30376 + atomic_unchecked_t marker_seq;
30377 wait_queue_head_t fence_queue;
30378 wait_queue_head_t fifo_queue;
30379 int fence_queue_waiters; /* Protected by hw_mutex */
30380 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30381 index a0c2f12..68ae6cb 100644
30382 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30383 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30384 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
30385 (unsigned int) min,
30386 (unsigned int) fifo->capabilities);
30387
30388 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
30389 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
30390 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
30391 vmw_marker_queue_init(&fifo->marker_queue);
30392 return vmw_fifo_send_fence(dev_priv, &dummy);
30393 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
30394 if (reserveable)
30395 iowrite32(bytes, fifo_mem +
30396 SVGA_FIFO_RESERVED);
30397 - return fifo_mem + (next_cmd >> 2);
30398 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
30399 } else {
30400 need_bounce = true;
30401 }
30402 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
30403
30404 fm = vmw_fifo_reserve(dev_priv, bytes);
30405 if (unlikely(fm == NULL)) {
30406 - *seqno = atomic_read(&dev_priv->marker_seq);
30407 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
30408 ret = -ENOMEM;
30409 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
30410 false, 3*HZ);
30411 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
30412 }
30413
30414 do {
30415 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
30416 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
30417 } while (*seqno == 0);
30418
30419 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
30420 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30421 index cabc95f..14b3d77 100644
30422 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30423 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30424 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
30425 * emitted. Then the fence is stale and signaled.
30426 */
30427
30428 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
30429 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
30430 > VMW_FENCE_WRAP);
30431
30432 return ret;
30433 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
30434
30435 if (fifo_idle)
30436 down_read(&fifo_state->rwsem);
30437 - signal_seq = atomic_read(&dev_priv->marker_seq);
30438 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
30439 ret = 0;
30440
30441 for (;;) {
30442 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30443 index 8a8725c..afed796 100644
30444 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30445 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30446 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
30447 while (!vmw_lag_lt(queue, us)) {
30448 spin_lock(&queue->lock);
30449 if (list_empty(&queue->head))
30450 - seqno = atomic_read(&dev_priv->marker_seq);
30451 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
30452 else {
30453 marker = list_first_entry(&queue->head,
30454 struct vmw_marker, head);
30455 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
30456 index 75dbe34..f9204a8 100644
30457 --- a/drivers/hid/hid-core.c
30458 +++ b/drivers/hid/hid-core.c
30459 @@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
30460
30461 int hid_add_device(struct hid_device *hdev)
30462 {
30463 - static atomic_t id = ATOMIC_INIT(0);
30464 + static atomic_unchecked_t id = ATOMIC_INIT(0);
30465 int ret;
30466
30467 if (WARN_ON(hdev->status & HID_STAT_ADDED))
30468 @@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
30469 /* XXX hack, any other cleaner solution after the driver core
30470 * is converted to allow more than 20 bytes as the device name? */
30471 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
30472 - hdev->vendor, hdev->product, atomic_inc_return(&id));
30473 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
30474
30475 hid_debug_register(hdev, dev_name(&hdev->dev));
30476 ret = device_add(&hdev->dev);
30477 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
30478 index b1ec0e2..c295a61 100644
30479 --- a/drivers/hid/usbhid/hiddev.c
30480 +++ b/drivers/hid/usbhid/hiddev.c
30481 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
30482 break;
30483
30484 case HIDIOCAPPLICATION:
30485 - if (arg < 0 || arg >= hid->maxapplication)
30486 + if (arg >= hid->maxapplication)
30487 break;
30488
30489 for (i = 0; i < hid->maxcollection; i++)
30490 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
30491 index 4065374..10ed7dc 100644
30492 --- a/drivers/hv/channel.c
30493 +++ b/drivers/hv/channel.c
30494 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
30495 int ret = 0;
30496 int t;
30497
30498 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
30499 - atomic_inc(&vmbus_connection.next_gpadl_handle);
30500 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
30501 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
30502
30503 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
30504 if (ret)
30505 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
30506 index 12aa97f..c0679f7 100644
30507 --- a/drivers/hv/hv.c
30508 +++ b/drivers/hv/hv.c
30509 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
30510 u64 output_address = (output) ? virt_to_phys(output) : 0;
30511 u32 output_address_hi = output_address >> 32;
30512 u32 output_address_lo = output_address & 0xFFFFFFFF;
30513 - void *hypercall_page = hv_context.hypercall_page;
30514 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
30515
30516 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
30517 "=a"(hv_status_lo) : "d" (control_hi),
30518 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
30519 index 6d7d286..92b0873 100644
30520 --- a/drivers/hv/hyperv_vmbus.h
30521 +++ b/drivers/hv/hyperv_vmbus.h
30522 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
30523 struct vmbus_connection {
30524 enum vmbus_connect_state conn_state;
30525
30526 - atomic_t next_gpadl_handle;
30527 + atomic_unchecked_t next_gpadl_handle;
30528
30529 /*
30530 * Represents channel interrupts. Each bit position represents a
30531 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
30532 index a220e57..428f54d 100644
30533 --- a/drivers/hv/vmbus_drv.c
30534 +++ b/drivers/hv/vmbus_drv.c
30535 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
30536 {
30537 int ret = 0;
30538
30539 - static atomic_t device_num = ATOMIC_INIT(0);
30540 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
30541
30542 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
30543 - atomic_inc_return(&device_num));
30544 + atomic_inc_return_unchecked(&device_num));
30545
30546 child_device_obj->device.bus = &hv_bus;
30547 child_device_obj->device.parent = &hv_acpi_dev->dev;
30548 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
30549 index 554f046..f8b4729 100644
30550 --- a/drivers/hwmon/acpi_power_meter.c
30551 +++ b/drivers/hwmon/acpi_power_meter.c
30552 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
30553 return res;
30554
30555 temp /= 1000;
30556 - if (temp < 0)
30557 - return -EINVAL;
30558
30559 mutex_lock(&resource->lock);
30560 resource->trip[attr->index - 7] = temp;
30561 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
30562 index 91fdd1f..b66a686 100644
30563 --- a/drivers/hwmon/sht15.c
30564 +++ b/drivers/hwmon/sht15.c
30565 @@ -166,7 +166,7 @@ struct sht15_data {
30566 int supply_uV;
30567 bool supply_uV_valid;
30568 struct work_struct update_supply_work;
30569 - atomic_t interrupt_handled;
30570 + atomic_unchecked_t interrupt_handled;
30571 };
30572
30573 /**
30574 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
30575 return ret;
30576
30577 gpio_direction_input(data->pdata->gpio_data);
30578 - atomic_set(&data->interrupt_handled, 0);
30579 + atomic_set_unchecked(&data->interrupt_handled, 0);
30580
30581 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30582 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30583 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30584 /* Only relevant if the interrupt hasn't occurred. */
30585 - if (!atomic_read(&data->interrupt_handled))
30586 + if (!atomic_read_unchecked(&data->interrupt_handled))
30587 schedule_work(&data->read_work);
30588 }
30589 ret = wait_event_timeout(data->wait_queue,
30590 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
30591
30592 /* First disable the interrupt */
30593 disable_irq_nosync(irq);
30594 - atomic_inc(&data->interrupt_handled);
30595 + atomic_inc_unchecked(&data->interrupt_handled);
30596 /* Then schedule a reading work struct */
30597 if (data->state != SHT15_READING_NOTHING)
30598 schedule_work(&data->read_work);
30599 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
30600 * If not, then start the interrupt again - care here as could
30601 * have gone low in meantime so verify it hasn't!
30602 */
30603 - atomic_set(&data->interrupt_handled, 0);
30604 + atomic_set_unchecked(&data->interrupt_handled, 0);
30605 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30606 /* If still not occurred or another handler has been scheduled */
30607 if (gpio_get_value(data->pdata->gpio_data)
30608 - || atomic_read(&data->interrupt_handled))
30609 + || atomic_read_unchecked(&data->interrupt_handled))
30610 return;
30611 }
30612
30613 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
30614 index 378fcb5..5e91fa8 100644
30615 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
30616 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
30617 @@ -43,7 +43,7 @@
30618 extern struct i2c_adapter amd756_smbus;
30619
30620 static struct i2c_adapter *s4882_adapter;
30621 -static struct i2c_algorithm *s4882_algo;
30622 +static i2c_algorithm_no_const *s4882_algo;
30623
30624 /* Wrapper access functions for multiplexed SMBus */
30625 static DEFINE_MUTEX(amd756_lock);
30626 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
30627 index 29015eb..af2d8e9 100644
30628 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
30629 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
30630 @@ -41,7 +41,7 @@
30631 extern struct i2c_adapter *nforce2_smbus;
30632
30633 static struct i2c_adapter *s4985_adapter;
30634 -static struct i2c_algorithm *s4985_algo;
30635 +static i2c_algorithm_no_const *s4985_algo;
30636
30637 /* Wrapper access functions for multiplexed SMBus */
30638 static DEFINE_MUTEX(nforce2_lock);
30639 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
30640 index d7a4833..7fae376 100644
30641 --- a/drivers/i2c/i2c-mux.c
30642 +++ b/drivers/i2c/i2c-mux.c
30643 @@ -28,7 +28,7 @@
30644 /* multiplexer per channel data */
30645 struct i2c_mux_priv {
30646 struct i2c_adapter adap;
30647 - struct i2c_algorithm algo;
30648 + i2c_algorithm_no_const algo;
30649
30650 struct i2c_adapter *parent;
30651 void *mux_dev; /* the mux chip/device */
30652 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
30653 index 57d00ca..0145194 100644
30654 --- a/drivers/ide/aec62xx.c
30655 +++ b/drivers/ide/aec62xx.c
30656 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
30657 .cable_detect = atp86x_cable_detect,
30658 };
30659
30660 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
30661 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
30662 { /* 0: AEC6210 */
30663 .name = DRV_NAME,
30664 .init_chipset = init_chipset_aec62xx,
30665 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
30666 index 2c8016a..911a27c 100644
30667 --- a/drivers/ide/alim15x3.c
30668 +++ b/drivers/ide/alim15x3.c
30669 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
30670 .dma_sff_read_status = ide_dma_sff_read_status,
30671 };
30672
30673 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
30674 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
30675 .name = DRV_NAME,
30676 .init_chipset = init_chipset_ali15x3,
30677 .init_hwif = init_hwif_ali15x3,
30678 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
30679 index 3747b25..56fc995 100644
30680 --- a/drivers/ide/amd74xx.c
30681 +++ b/drivers/ide/amd74xx.c
30682 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
30683 .udma_mask = udma, \
30684 }
30685
30686 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
30687 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
30688 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
30689 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
30690 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
30691 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
30692 index 15f0ead..cb43480 100644
30693 --- a/drivers/ide/atiixp.c
30694 +++ b/drivers/ide/atiixp.c
30695 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
30696 .cable_detect = atiixp_cable_detect,
30697 };
30698
30699 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
30700 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
30701 { /* 0: IXP200/300/400/700 */
30702 .name = DRV_NAME,
30703 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
30704 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
30705 index 5f80312..d1fc438 100644
30706 --- a/drivers/ide/cmd64x.c
30707 +++ b/drivers/ide/cmd64x.c
30708 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
30709 .dma_sff_read_status = ide_dma_sff_read_status,
30710 };
30711
30712 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
30713 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
30714 { /* 0: CMD643 */
30715 .name = DRV_NAME,
30716 .init_chipset = init_chipset_cmd64x,
30717 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
30718 index 2c1e5f7..1444762 100644
30719 --- a/drivers/ide/cs5520.c
30720 +++ b/drivers/ide/cs5520.c
30721 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
30722 .set_dma_mode = cs5520_set_dma_mode,
30723 };
30724
30725 -static const struct ide_port_info cyrix_chipset __devinitdata = {
30726 +static const struct ide_port_info cyrix_chipset __devinitconst = {
30727 .name = DRV_NAME,
30728 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
30729 .port_ops = &cs5520_port_ops,
30730 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
30731 index 4dc4eb9..49b40ad 100644
30732 --- a/drivers/ide/cs5530.c
30733 +++ b/drivers/ide/cs5530.c
30734 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
30735 .udma_filter = cs5530_udma_filter,
30736 };
30737
30738 -static const struct ide_port_info cs5530_chipset __devinitdata = {
30739 +static const struct ide_port_info cs5530_chipset __devinitconst = {
30740 .name = DRV_NAME,
30741 .init_chipset = init_chipset_cs5530,
30742 .init_hwif = init_hwif_cs5530,
30743 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
30744 index 5059faf..18d4c85 100644
30745 --- a/drivers/ide/cs5535.c
30746 +++ b/drivers/ide/cs5535.c
30747 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
30748 .cable_detect = cs5535_cable_detect,
30749 };
30750
30751 -static const struct ide_port_info cs5535_chipset __devinitdata = {
30752 +static const struct ide_port_info cs5535_chipset __devinitconst = {
30753 .name = DRV_NAME,
30754 .port_ops = &cs5535_port_ops,
30755 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
30756 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
30757 index 847553f..3ffb49d 100644
30758 --- a/drivers/ide/cy82c693.c
30759 +++ b/drivers/ide/cy82c693.c
30760 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
30761 .set_dma_mode = cy82c693_set_dma_mode,
30762 };
30763
30764 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
30765 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
30766 .name = DRV_NAME,
30767 .init_iops = init_iops_cy82c693,
30768 .port_ops = &cy82c693_port_ops,
30769 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
30770 index 58c51cd..4aec3b8 100644
30771 --- a/drivers/ide/hpt366.c
30772 +++ b/drivers/ide/hpt366.c
30773 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
30774 }
30775 };
30776
30777 -static const struct hpt_info hpt36x __devinitdata = {
30778 +static const struct hpt_info hpt36x __devinitconst = {
30779 .chip_name = "HPT36x",
30780 .chip_type = HPT36x,
30781 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
30782 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
30783 .timings = &hpt36x_timings
30784 };
30785
30786 -static const struct hpt_info hpt370 __devinitdata = {
30787 +static const struct hpt_info hpt370 __devinitconst = {
30788 .chip_name = "HPT370",
30789 .chip_type = HPT370,
30790 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
30791 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
30792 .timings = &hpt37x_timings
30793 };
30794
30795 -static const struct hpt_info hpt370a __devinitdata = {
30796 +static const struct hpt_info hpt370a __devinitconst = {
30797 .chip_name = "HPT370A",
30798 .chip_type = HPT370A,
30799 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
30800 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
30801 .timings = &hpt37x_timings
30802 };
30803
30804 -static const struct hpt_info hpt374 __devinitdata = {
30805 +static const struct hpt_info hpt374 __devinitconst = {
30806 .chip_name = "HPT374",
30807 .chip_type = HPT374,
30808 .udma_mask = ATA_UDMA5,
30809 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
30810 .timings = &hpt37x_timings
30811 };
30812
30813 -static const struct hpt_info hpt372 __devinitdata = {
30814 +static const struct hpt_info hpt372 __devinitconst = {
30815 .chip_name = "HPT372",
30816 .chip_type = HPT372,
30817 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30818 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
30819 .timings = &hpt37x_timings
30820 };
30821
30822 -static const struct hpt_info hpt372a __devinitdata = {
30823 +static const struct hpt_info hpt372a __devinitconst = {
30824 .chip_name = "HPT372A",
30825 .chip_type = HPT372A,
30826 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30827 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
30828 .timings = &hpt37x_timings
30829 };
30830
30831 -static const struct hpt_info hpt302 __devinitdata = {
30832 +static const struct hpt_info hpt302 __devinitconst = {
30833 .chip_name = "HPT302",
30834 .chip_type = HPT302,
30835 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30836 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
30837 .timings = &hpt37x_timings
30838 };
30839
30840 -static const struct hpt_info hpt371 __devinitdata = {
30841 +static const struct hpt_info hpt371 __devinitconst = {
30842 .chip_name = "HPT371",
30843 .chip_type = HPT371,
30844 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30845 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
30846 .timings = &hpt37x_timings
30847 };
30848
30849 -static const struct hpt_info hpt372n __devinitdata = {
30850 +static const struct hpt_info hpt372n __devinitconst = {
30851 .chip_name = "HPT372N",
30852 .chip_type = HPT372N,
30853 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30854 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
30855 .timings = &hpt37x_timings
30856 };
30857
30858 -static const struct hpt_info hpt302n __devinitdata = {
30859 +static const struct hpt_info hpt302n __devinitconst = {
30860 .chip_name = "HPT302N",
30861 .chip_type = HPT302N,
30862 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30863 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
30864 .timings = &hpt37x_timings
30865 };
30866
30867 -static const struct hpt_info hpt371n __devinitdata = {
30868 +static const struct hpt_info hpt371n __devinitconst = {
30869 .chip_name = "HPT371N",
30870 .chip_type = HPT371N,
30871 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30872 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
30873 .dma_sff_read_status = ide_dma_sff_read_status,
30874 };
30875
30876 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
30877 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
30878 { /* 0: HPT36x */
30879 .name = DRV_NAME,
30880 .init_chipset = init_chipset_hpt366,
30881 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
30882 index 8126824..55a2798 100644
30883 --- a/drivers/ide/ide-cd.c
30884 +++ b/drivers/ide/ide-cd.c
30885 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
30886 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30887 if ((unsigned long)buf & alignment
30888 || blk_rq_bytes(rq) & q->dma_pad_mask
30889 - || object_is_on_stack(buf))
30890 + || object_starts_on_stack(buf))
30891 drive->dma = 0;
30892 }
30893 }
30894 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
30895 index 7f56b73..dab5b67 100644
30896 --- a/drivers/ide/ide-pci-generic.c
30897 +++ b/drivers/ide/ide-pci-generic.c
30898 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
30899 .udma_mask = ATA_UDMA6, \
30900 }
30901
30902 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
30903 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
30904 /* 0: Unknown */
30905 DECLARE_GENERIC_PCI_DEV(0),
30906
30907 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
30908 index 560e66d..d5dd180 100644
30909 --- a/drivers/ide/it8172.c
30910 +++ b/drivers/ide/it8172.c
30911 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
30912 .set_dma_mode = it8172_set_dma_mode,
30913 };
30914
30915 -static const struct ide_port_info it8172_port_info __devinitdata = {
30916 +static const struct ide_port_info it8172_port_info __devinitconst = {
30917 .name = DRV_NAME,
30918 .port_ops = &it8172_port_ops,
30919 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
30920 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
30921 index 46816ba..1847aeb 100644
30922 --- a/drivers/ide/it8213.c
30923 +++ b/drivers/ide/it8213.c
30924 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
30925 .cable_detect = it8213_cable_detect,
30926 };
30927
30928 -static const struct ide_port_info it8213_chipset __devinitdata = {
30929 +static const struct ide_port_info it8213_chipset __devinitconst = {
30930 .name = DRV_NAME,
30931 .enablebits = { {0x41, 0x80, 0x80} },
30932 .port_ops = &it8213_port_ops,
30933 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
30934 index 2e3169f..c5611db 100644
30935 --- a/drivers/ide/it821x.c
30936 +++ b/drivers/ide/it821x.c
30937 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
30938 .cable_detect = it821x_cable_detect,
30939 };
30940
30941 -static const struct ide_port_info it821x_chipset __devinitdata = {
30942 +static const struct ide_port_info it821x_chipset __devinitconst = {
30943 .name = DRV_NAME,
30944 .init_chipset = init_chipset_it821x,
30945 .init_hwif = init_hwif_it821x,
30946 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
30947 index 74c2c4a..efddd7d 100644
30948 --- a/drivers/ide/jmicron.c
30949 +++ b/drivers/ide/jmicron.c
30950 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
30951 .cable_detect = jmicron_cable_detect,
30952 };
30953
30954 -static const struct ide_port_info jmicron_chipset __devinitdata = {
30955 +static const struct ide_port_info jmicron_chipset __devinitconst = {
30956 .name = DRV_NAME,
30957 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
30958 .port_ops = &jmicron_port_ops,
30959 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
30960 index 95327a2..73f78d8 100644
30961 --- a/drivers/ide/ns87415.c
30962 +++ b/drivers/ide/ns87415.c
30963 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
30964 .dma_sff_read_status = superio_dma_sff_read_status,
30965 };
30966
30967 -static const struct ide_port_info ns87415_chipset __devinitdata = {
30968 +static const struct ide_port_info ns87415_chipset __devinitconst = {
30969 .name = DRV_NAME,
30970 .init_hwif = init_hwif_ns87415,
30971 .tp_ops = &ns87415_tp_ops,
30972 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
30973 index 1a53a4c..39edc66 100644
30974 --- a/drivers/ide/opti621.c
30975 +++ b/drivers/ide/opti621.c
30976 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
30977 .set_pio_mode = opti621_set_pio_mode,
30978 };
30979
30980 -static const struct ide_port_info opti621_chipset __devinitdata = {
30981 +static const struct ide_port_info opti621_chipset __devinitconst = {
30982 .name = DRV_NAME,
30983 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
30984 .port_ops = &opti621_port_ops,
30985 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
30986 index 9546fe2..2e5ceb6 100644
30987 --- a/drivers/ide/pdc202xx_new.c
30988 +++ b/drivers/ide/pdc202xx_new.c
30989 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
30990 .udma_mask = udma, \
30991 }
30992
30993 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
30994 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
30995 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
30996 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
30997 };
30998 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
30999 index 3a35ec6..5634510 100644
31000 --- a/drivers/ide/pdc202xx_old.c
31001 +++ b/drivers/ide/pdc202xx_old.c
31002 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31003 .max_sectors = sectors, \
31004 }
31005
31006 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31007 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31008 { /* 0: PDC20246 */
31009 .name = DRV_NAME,
31010 .init_chipset = init_chipset_pdc202xx,
31011 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31012 index 1892e81..fe0fd60 100644
31013 --- a/drivers/ide/piix.c
31014 +++ b/drivers/ide/piix.c
31015 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31016 .udma_mask = udma, \
31017 }
31018
31019 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31020 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31021 /* 0: MPIIX */
31022 { /*
31023 * MPIIX actually has only a single IDE channel mapped to
31024 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31025 index a6414a8..c04173e 100644
31026 --- a/drivers/ide/rz1000.c
31027 +++ b/drivers/ide/rz1000.c
31028 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31029 }
31030 }
31031
31032 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31033 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31034 .name = DRV_NAME,
31035 .host_flags = IDE_HFLAG_NO_DMA,
31036 };
31037 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31038 index 356b9b5..d4758eb 100644
31039 --- a/drivers/ide/sc1200.c
31040 +++ b/drivers/ide/sc1200.c
31041 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31042 .dma_sff_read_status = ide_dma_sff_read_status,
31043 };
31044
31045 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31046 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31047 .name = DRV_NAME,
31048 .port_ops = &sc1200_port_ops,
31049 .dma_ops = &sc1200_dma_ops,
31050 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31051 index b7f5b0c..9701038 100644
31052 --- a/drivers/ide/scc_pata.c
31053 +++ b/drivers/ide/scc_pata.c
31054 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31055 .dma_sff_read_status = scc_dma_sff_read_status,
31056 };
31057
31058 -static const struct ide_port_info scc_chipset __devinitdata = {
31059 +static const struct ide_port_info scc_chipset __devinitconst = {
31060 .name = "sccIDE",
31061 .init_iops = init_iops_scc,
31062 .init_dma = scc_init_dma,
31063 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31064 index 35fb8da..24d72ef 100644
31065 --- a/drivers/ide/serverworks.c
31066 +++ b/drivers/ide/serverworks.c
31067 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31068 .cable_detect = svwks_cable_detect,
31069 };
31070
31071 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31072 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31073 { /* 0: OSB4 */
31074 .name = DRV_NAME,
31075 .init_chipset = init_chipset_svwks,
31076 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31077 index ddeda44..46f7e30 100644
31078 --- a/drivers/ide/siimage.c
31079 +++ b/drivers/ide/siimage.c
31080 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31081 .udma_mask = ATA_UDMA6, \
31082 }
31083
31084 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31085 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31086 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31087 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31088 };
31089 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31090 index 4a00225..09e61b4 100644
31091 --- a/drivers/ide/sis5513.c
31092 +++ b/drivers/ide/sis5513.c
31093 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31094 .cable_detect = sis_cable_detect,
31095 };
31096
31097 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31098 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31099 .name = DRV_NAME,
31100 .init_chipset = init_chipset_sis5513,
31101 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31102 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31103 index f21dc2a..d051cd2 100644
31104 --- a/drivers/ide/sl82c105.c
31105 +++ b/drivers/ide/sl82c105.c
31106 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31107 .dma_sff_read_status = ide_dma_sff_read_status,
31108 };
31109
31110 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31111 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31112 .name = DRV_NAME,
31113 .init_chipset = init_chipset_sl82c105,
31114 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31115 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31116 index 864ffe0..863a5e9 100644
31117 --- a/drivers/ide/slc90e66.c
31118 +++ b/drivers/ide/slc90e66.c
31119 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31120 .cable_detect = slc90e66_cable_detect,
31121 };
31122
31123 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31124 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31125 .name = DRV_NAME,
31126 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31127 .port_ops = &slc90e66_port_ops,
31128 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31129 index 4799d5c..1794678 100644
31130 --- a/drivers/ide/tc86c001.c
31131 +++ b/drivers/ide/tc86c001.c
31132 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31133 .dma_sff_read_status = ide_dma_sff_read_status,
31134 };
31135
31136 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31137 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31138 .name = DRV_NAME,
31139 .init_hwif = init_hwif_tc86c001,
31140 .port_ops = &tc86c001_port_ops,
31141 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31142 index 281c914..55ce1b8 100644
31143 --- a/drivers/ide/triflex.c
31144 +++ b/drivers/ide/triflex.c
31145 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31146 .set_dma_mode = triflex_set_mode,
31147 };
31148
31149 -static const struct ide_port_info triflex_device __devinitdata = {
31150 +static const struct ide_port_info triflex_device __devinitconst = {
31151 .name = DRV_NAME,
31152 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31153 .port_ops = &triflex_port_ops,
31154 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31155 index 4b42ca0..e494a98 100644
31156 --- a/drivers/ide/trm290.c
31157 +++ b/drivers/ide/trm290.c
31158 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31159 .dma_check = trm290_dma_check,
31160 };
31161
31162 -static const struct ide_port_info trm290_chipset __devinitdata = {
31163 +static const struct ide_port_info trm290_chipset __devinitconst = {
31164 .name = DRV_NAME,
31165 .init_hwif = init_hwif_trm290,
31166 .tp_ops = &trm290_tp_ops,
31167 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31168 index f46f49c..eb77678 100644
31169 --- a/drivers/ide/via82cxxx.c
31170 +++ b/drivers/ide/via82cxxx.c
31171 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31172 .cable_detect = via82cxxx_cable_detect,
31173 };
31174
31175 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31176 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31177 .name = DRV_NAME,
31178 .init_chipset = init_chipset_via82cxxx,
31179 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31180 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31181 index 73d4531..c90cd2d 100644
31182 --- a/drivers/ieee802154/fakehard.c
31183 +++ b/drivers/ieee802154/fakehard.c
31184 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31185 phy->transmit_power = 0xbf;
31186
31187 dev->netdev_ops = &fake_ops;
31188 - dev->ml_priv = &fake_mlme;
31189 + dev->ml_priv = (void *)&fake_mlme;
31190
31191 priv = netdev_priv(dev);
31192 priv->phy = phy;
31193 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31194 index c889aae..6cf5aa7 100644
31195 --- a/drivers/infiniband/core/cm.c
31196 +++ b/drivers/infiniband/core/cm.c
31197 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31198
31199 struct cm_counter_group {
31200 struct kobject obj;
31201 - atomic_long_t counter[CM_ATTR_COUNT];
31202 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31203 };
31204
31205 struct cm_counter_attribute {
31206 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31207 struct ib_mad_send_buf *msg = NULL;
31208 int ret;
31209
31210 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31211 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31212 counter[CM_REQ_COUNTER]);
31213
31214 /* Quick state check to discard duplicate REQs. */
31215 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31216 if (!cm_id_priv)
31217 return;
31218
31219 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31220 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31221 counter[CM_REP_COUNTER]);
31222 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31223 if (ret)
31224 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31225 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31226 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31227 spin_unlock_irq(&cm_id_priv->lock);
31228 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31229 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31230 counter[CM_RTU_COUNTER]);
31231 goto out;
31232 }
31233 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31234 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31235 dreq_msg->local_comm_id);
31236 if (!cm_id_priv) {
31237 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31238 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31239 counter[CM_DREQ_COUNTER]);
31240 cm_issue_drep(work->port, work->mad_recv_wc);
31241 return -EINVAL;
31242 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31243 case IB_CM_MRA_REP_RCVD:
31244 break;
31245 case IB_CM_TIMEWAIT:
31246 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31247 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31248 counter[CM_DREQ_COUNTER]);
31249 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31250 goto unlock;
31251 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31252 cm_free_msg(msg);
31253 goto deref;
31254 case IB_CM_DREQ_RCVD:
31255 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31256 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31257 counter[CM_DREQ_COUNTER]);
31258 goto unlock;
31259 default:
31260 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31261 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31262 cm_id_priv->msg, timeout)) {
31263 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31264 - atomic_long_inc(&work->port->
31265 + atomic_long_inc_unchecked(&work->port->
31266 counter_group[CM_RECV_DUPLICATES].
31267 counter[CM_MRA_COUNTER]);
31268 goto out;
31269 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31270 break;
31271 case IB_CM_MRA_REQ_RCVD:
31272 case IB_CM_MRA_REP_RCVD:
31273 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31274 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31275 counter[CM_MRA_COUNTER]);
31276 /* fall through */
31277 default:
31278 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31279 case IB_CM_LAP_IDLE:
31280 break;
31281 case IB_CM_MRA_LAP_SENT:
31282 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31283 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31284 counter[CM_LAP_COUNTER]);
31285 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31286 goto unlock;
31287 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31288 cm_free_msg(msg);
31289 goto deref;
31290 case IB_CM_LAP_RCVD:
31291 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31292 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31293 counter[CM_LAP_COUNTER]);
31294 goto unlock;
31295 default:
31296 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31297 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31298 if (cur_cm_id_priv) {
31299 spin_unlock_irq(&cm.lock);
31300 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31301 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31302 counter[CM_SIDR_REQ_COUNTER]);
31303 goto out; /* Duplicate message. */
31304 }
31305 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
31306 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31307 msg->retries = 1;
31308
31309 - atomic_long_add(1 + msg->retries,
31310 + atomic_long_add_unchecked(1 + msg->retries,
31311 &port->counter_group[CM_XMIT].counter[attr_index]);
31312 if (msg->retries)
31313 - atomic_long_add(msg->retries,
31314 + atomic_long_add_unchecked(msg->retries,
31315 &port->counter_group[CM_XMIT_RETRIES].
31316 counter[attr_index]);
31317
31318 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
31319 }
31320
31321 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
31322 - atomic_long_inc(&port->counter_group[CM_RECV].
31323 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
31324 counter[attr_id - CM_ATTR_ID_OFFSET]);
31325
31326 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
31327 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
31328 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
31329
31330 return sprintf(buf, "%ld\n",
31331 - atomic_long_read(&group->counter[cm_attr->index]));
31332 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
31333 }
31334
31335 static const struct sysfs_ops cm_counter_ops = {
31336 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
31337 index 176c8f9..2627b62 100644
31338 --- a/drivers/infiniband/core/fmr_pool.c
31339 +++ b/drivers/infiniband/core/fmr_pool.c
31340 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
31341
31342 struct task_struct *thread;
31343
31344 - atomic_t req_ser;
31345 - atomic_t flush_ser;
31346 + atomic_unchecked_t req_ser;
31347 + atomic_unchecked_t flush_ser;
31348
31349 wait_queue_head_t force_wait;
31350 };
31351 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31352 struct ib_fmr_pool *pool = pool_ptr;
31353
31354 do {
31355 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
31356 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
31357 ib_fmr_batch_release(pool);
31358
31359 - atomic_inc(&pool->flush_ser);
31360 + atomic_inc_unchecked(&pool->flush_ser);
31361 wake_up_interruptible(&pool->force_wait);
31362
31363 if (pool->flush_function)
31364 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31365 }
31366
31367 set_current_state(TASK_INTERRUPTIBLE);
31368 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
31369 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
31370 !kthread_should_stop())
31371 schedule();
31372 __set_current_state(TASK_RUNNING);
31373 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
31374 pool->dirty_watermark = params->dirty_watermark;
31375 pool->dirty_len = 0;
31376 spin_lock_init(&pool->pool_lock);
31377 - atomic_set(&pool->req_ser, 0);
31378 - atomic_set(&pool->flush_ser, 0);
31379 + atomic_set_unchecked(&pool->req_ser, 0);
31380 + atomic_set_unchecked(&pool->flush_ser, 0);
31381 init_waitqueue_head(&pool->force_wait);
31382
31383 pool->thread = kthread_run(ib_fmr_cleanup_thread,
31384 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
31385 }
31386 spin_unlock_irq(&pool->pool_lock);
31387
31388 - serial = atomic_inc_return(&pool->req_ser);
31389 + serial = atomic_inc_return_unchecked(&pool->req_ser);
31390 wake_up_process(pool->thread);
31391
31392 if (wait_event_interruptible(pool->force_wait,
31393 - atomic_read(&pool->flush_ser) - serial >= 0))
31394 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
31395 return -EINTR;
31396
31397 return 0;
31398 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
31399 } else {
31400 list_add_tail(&fmr->list, &pool->dirty_list);
31401 if (++pool->dirty_len >= pool->dirty_watermark) {
31402 - atomic_inc(&pool->req_ser);
31403 + atomic_inc_unchecked(&pool->req_ser);
31404 wake_up_process(pool->thread);
31405 }
31406 }
31407 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
31408 index 40c8353..946b0e4 100644
31409 --- a/drivers/infiniband/hw/cxgb4/mem.c
31410 +++ b/drivers/infiniband/hw/cxgb4/mem.c
31411 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
31412 int err;
31413 struct fw_ri_tpte tpt;
31414 u32 stag_idx;
31415 - static atomic_t key;
31416 + static atomic_unchecked_t key;
31417
31418 if (c4iw_fatal_error(rdev))
31419 return -EIO;
31420 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
31421 &rdev->resource.tpt_fifo_lock);
31422 if (!stag_idx)
31423 return -ENOMEM;
31424 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
31425 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
31426 }
31427 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
31428 __func__, stag_state, type, pdid, stag_idx);
31429 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
31430 index 79b3dbc..96e5fcc 100644
31431 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
31432 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
31433 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
31434 struct ib_atomic_eth *ateth;
31435 struct ipath_ack_entry *e;
31436 u64 vaddr;
31437 - atomic64_t *maddr;
31438 + atomic64_unchecked_t *maddr;
31439 u64 sdata;
31440 u32 rkey;
31441 u8 next;
31442 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
31443 IB_ACCESS_REMOTE_ATOMIC)))
31444 goto nack_acc_unlck;
31445 /* Perform atomic OP and save result. */
31446 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
31447 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
31448 sdata = be64_to_cpu(ateth->swap_data);
31449 e = &qp->s_ack_queue[qp->r_head_ack_queue];
31450 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
31451 - (u64) atomic64_add_return(sdata, maddr) - sdata :
31452 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
31453 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
31454 be64_to_cpu(ateth->compare_data),
31455 sdata);
31456 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
31457 index 1f95bba..9530f87 100644
31458 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
31459 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
31460 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
31461 unsigned long flags;
31462 struct ib_wc wc;
31463 u64 sdata;
31464 - atomic64_t *maddr;
31465 + atomic64_unchecked_t *maddr;
31466 enum ib_wc_status send_status;
31467
31468 /*
31469 @@ -382,11 +382,11 @@ again:
31470 IB_ACCESS_REMOTE_ATOMIC)))
31471 goto acc_err;
31472 /* Perform atomic OP and save result. */
31473 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
31474 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
31475 sdata = wqe->wr.wr.atomic.compare_add;
31476 *(u64 *) sqp->s_sge.sge.vaddr =
31477 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
31478 - (u64) atomic64_add_return(sdata, maddr) - sdata :
31479 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
31480 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
31481 sdata, wqe->wr.wr.atomic.swap);
31482 goto send_comp;
31483 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
31484 index 7140199..da60063 100644
31485 --- a/drivers/infiniband/hw/nes/nes.c
31486 +++ b/drivers/infiniband/hw/nes/nes.c
31487 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
31488 LIST_HEAD(nes_adapter_list);
31489 static LIST_HEAD(nes_dev_list);
31490
31491 -atomic_t qps_destroyed;
31492 +atomic_unchecked_t qps_destroyed;
31493
31494 static unsigned int ee_flsh_adapter;
31495 static unsigned int sysfs_nonidx_addr;
31496 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
31497 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
31498 struct nes_adapter *nesadapter = nesdev->nesadapter;
31499
31500 - atomic_inc(&qps_destroyed);
31501 + atomic_inc_unchecked(&qps_destroyed);
31502
31503 /* Free the control structures */
31504
31505 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
31506 index c438e46..ca30356 100644
31507 --- a/drivers/infiniband/hw/nes/nes.h
31508 +++ b/drivers/infiniband/hw/nes/nes.h
31509 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
31510 extern unsigned int wqm_quanta;
31511 extern struct list_head nes_adapter_list;
31512
31513 -extern atomic_t cm_connects;
31514 -extern atomic_t cm_accepts;
31515 -extern atomic_t cm_disconnects;
31516 -extern atomic_t cm_closes;
31517 -extern atomic_t cm_connecteds;
31518 -extern atomic_t cm_connect_reqs;
31519 -extern atomic_t cm_rejects;
31520 -extern atomic_t mod_qp_timouts;
31521 -extern atomic_t qps_created;
31522 -extern atomic_t qps_destroyed;
31523 -extern atomic_t sw_qps_destroyed;
31524 +extern atomic_unchecked_t cm_connects;
31525 +extern atomic_unchecked_t cm_accepts;
31526 +extern atomic_unchecked_t cm_disconnects;
31527 +extern atomic_unchecked_t cm_closes;
31528 +extern atomic_unchecked_t cm_connecteds;
31529 +extern atomic_unchecked_t cm_connect_reqs;
31530 +extern atomic_unchecked_t cm_rejects;
31531 +extern atomic_unchecked_t mod_qp_timouts;
31532 +extern atomic_unchecked_t qps_created;
31533 +extern atomic_unchecked_t qps_destroyed;
31534 +extern atomic_unchecked_t sw_qps_destroyed;
31535 extern u32 mh_detected;
31536 extern u32 mh_pauses_sent;
31537 extern u32 cm_packets_sent;
31538 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
31539 extern u32 cm_packets_received;
31540 extern u32 cm_packets_dropped;
31541 extern u32 cm_packets_retrans;
31542 -extern atomic_t cm_listens_created;
31543 -extern atomic_t cm_listens_destroyed;
31544 +extern atomic_unchecked_t cm_listens_created;
31545 +extern atomic_unchecked_t cm_listens_destroyed;
31546 extern u32 cm_backlog_drops;
31547 -extern atomic_t cm_loopbacks;
31548 -extern atomic_t cm_nodes_created;
31549 -extern atomic_t cm_nodes_destroyed;
31550 -extern atomic_t cm_accel_dropped_pkts;
31551 -extern atomic_t cm_resets_recvd;
31552 -extern atomic_t pau_qps_created;
31553 -extern atomic_t pau_qps_destroyed;
31554 +extern atomic_unchecked_t cm_loopbacks;
31555 +extern atomic_unchecked_t cm_nodes_created;
31556 +extern atomic_unchecked_t cm_nodes_destroyed;
31557 +extern atomic_unchecked_t cm_accel_dropped_pkts;
31558 +extern atomic_unchecked_t cm_resets_recvd;
31559 +extern atomic_unchecked_t pau_qps_created;
31560 +extern atomic_unchecked_t pau_qps_destroyed;
31561
31562 extern u32 int_mod_timer_init;
31563 extern u32 int_mod_cq_depth_256;
31564 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
31565 index a4972ab..1bcfc31 100644
31566 --- a/drivers/infiniband/hw/nes/nes_cm.c
31567 +++ b/drivers/infiniband/hw/nes/nes_cm.c
31568 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
31569 u32 cm_packets_retrans;
31570 u32 cm_packets_created;
31571 u32 cm_packets_received;
31572 -atomic_t cm_listens_created;
31573 -atomic_t cm_listens_destroyed;
31574 +atomic_unchecked_t cm_listens_created;
31575 +atomic_unchecked_t cm_listens_destroyed;
31576 u32 cm_backlog_drops;
31577 -atomic_t cm_loopbacks;
31578 -atomic_t cm_nodes_created;
31579 -atomic_t cm_nodes_destroyed;
31580 -atomic_t cm_accel_dropped_pkts;
31581 -atomic_t cm_resets_recvd;
31582 +atomic_unchecked_t cm_loopbacks;
31583 +atomic_unchecked_t cm_nodes_created;
31584 +atomic_unchecked_t cm_nodes_destroyed;
31585 +atomic_unchecked_t cm_accel_dropped_pkts;
31586 +atomic_unchecked_t cm_resets_recvd;
31587
31588 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
31589 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
31590 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
31591
31592 static struct nes_cm_core *g_cm_core;
31593
31594 -atomic_t cm_connects;
31595 -atomic_t cm_accepts;
31596 -atomic_t cm_disconnects;
31597 -atomic_t cm_closes;
31598 -atomic_t cm_connecteds;
31599 -atomic_t cm_connect_reqs;
31600 -atomic_t cm_rejects;
31601 +atomic_unchecked_t cm_connects;
31602 +atomic_unchecked_t cm_accepts;
31603 +atomic_unchecked_t cm_disconnects;
31604 +atomic_unchecked_t cm_closes;
31605 +atomic_unchecked_t cm_connecteds;
31606 +atomic_unchecked_t cm_connect_reqs;
31607 +atomic_unchecked_t cm_rejects;
31608
31609 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
31610 {
31611 @@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
31612 kfree(listener);
31613 listener = NULL;
31614 ret = 0;
31615 - atomic_inc(&cm_listens_destroyed);
31616 + atomic_inc_unchecked(&cm_listens_destroyed);
31617 } else {
31618 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
31619 }
31620 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
31621 cm_node->rem_mac);
31622
31623 add_hte_node(cm_core, cm_node);
31624 - atomic_inc(&cm_nodes_created);
31625 + atomic_inc_unchecked(&cm_nodes_created);
31626
31627 return cm_node;
31628 }
31629 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
31630 }
31631
31632 atomic_dec(&cm_core->node_cnt);
31633 - atomic_inc(&cm_nodes_destroyed);
31634 + atomic_inc_unchecked(&cm_nodes_destroyed);
31635 nesqp = cm_node->nesqp;
31636 if (nesqp) {
31637 nesqp->cm_node = NULL;
31638 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
31639
31640 static void drop_packet(struct sk_buff *skb)
31641 {
31642 - atomic_inc(&cm_accel_dropped_pkts);
31643 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
31644 dev_kfree_skb_any(skb);
31645 }
31646
31647 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
31648 {
31649
31650 int reset = 0; /* whether to send reset in case of err.. */
31651 - atomic_inc(&cm_resets_recvd);
31652 + atomic_inc_unchecked(&cm_resets_recvd);
31653 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
31654 " refcnt=%d\n", cm_node, cm_node->state,
31655 atomic_read(&cm_node->ref_count));
31656 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
31657 rem_ref_cm_node(cm_node->cm_core, cm_node);
31658 return NULL;
31659 }
31660 - atomic_inc(&cm_loopbacks);
31661 + atomic_inc_unchecked(&cm_loopbacks);
31662 loopbackremotenode->loopbackpartner = cm_node;
31663 loopbackremotenode->tcp_cntxt.rcv_wscale =
31664 NES_CM_DEFAULT_RCV_WND_SCALE;
31665 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
31666 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
31667 else {
31668 rem_ref_cm_node(cm_core, cm_node);
31669 - atomic_inc(&cm_accel_dropped_pkts);
31670 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
31671 dev_kfree_skb_any(skb);
31672 }
31673 break;
31674 @@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
31675
31676 if ((cm_id) && (cm_id->event_handler)) {
31677 if (issue_disconn) {
31678 - atomic_inc(&cm_disconnects);
31679 + atomic_inc_unchecked(&cm_disconnects);
31680 cm_event.event = IW_CM_EVENT_DISCONNECT;
31681 cm_event.status = disconn_status;
31682 cm_event.local_addr = cm_id->local_addr;
31683 @@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
31684 }
31685
31686 if (issue_close) {
31687 - atomic_inc(&cm_closes);
31688 + atomic_inc_unchecked(&cm_closes);
31689 nes_disconnect(nesqp, 1);
31690
31691 cm_id->provider_data = nesqp;
31692 @@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
31693
31694 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
31695 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
31696 - atomic_inc(&cm_accepts);
31697 + atomic_inc_unchecked(&cm_accepts);
31698
31699 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
31700 netdev_refcnt_read(nesvnic->netdev));
31701 @@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
31702 struct nes_cm_core *cm_core;
31703 u8 *start_buff;
31704
31705 - atomic_inc(&cm_rejects);
31706 + atomic_inc_unchecked(&cm_rejects);
31707 cm_node = (struct nes_cm_node *)cm_id->provider_data;
31708 loopback = cm_node->loopbackpartner;
31709 cm_core = cm_node->cm_core;
31710 @@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
31711 ntohl(cm_id->local_addr.sin_addr.s_addr),
31712 ntohs(cm_id->local_addr.sin_port));
31713
31714 - atomic_inc(&cm_connects);
31715 + atomic_inc_unchecked(&cm_connects);
31716 nesqp->active_conn = 1;
31717
31718 /* cache the cm_id in the qp */
31719 @@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
31720 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
31721 return err;
31722 }
31723 - atomic_inc(&cm_listens_created);
31724 + atomic_inc_unchecked(&cm_listens_created);
31725 }
31726
31727 cm_id->add_ref(cm_id);
31728 @@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
31729
31730 if (nesqp->destroyed)
31731 return;
31732 - atomic_inc(&cm_connecteds);
31733 + atomic_inc_unchecked(&cm_connecteds);
31734 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
31735 " local port 0x%04X. jiffies = %lu.\n",
31736 nesqp->hwqp.qp_id,
31737 @@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
31738
31739 cm_id->add_ref(cm_id);
31740 ret = cm_id->event_handler(cm_id, &cm_event);
31741 - atomic_inc(&cm_closes);
31742 + atomic_inc_unchecked(&cm_closes);
31743 cm_event.event = IW_CM_EVENT_CLOSE;
31744 cm_event.status = 0;
31745 cm_event.provider_data = cm_id->provider_data;
31746 @@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
31747 return;
31748 cm_id = cm_node->cm_id;
31749
31750 - atomic_inc(&cm_connect_reqs);
31751 + atomic_inc_unchecked(&cm_connect_reqs);
31752 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31753 cm_node, cm_id, jiffies);
31754
31755 @@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
31756 return;
31757 cm_id = cm_node->cm_id;
31758
31759 - atomic_inc(&cm_connect_reqs);
31760 + atomic_inc_unchecked(&cm_connect_reqs);
31761 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31762 cm_node, cm_id, jiffies);
31763
31764 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
31765 index 3ba7be3..c81f6ff 100644
31766 --- a/drivers/infiniband/hw/nes/nes_mgt.c
31767 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
31768 @@ -40,8 +40,8 @@
31769 #include "nes.h"
31770 #include "nes_mgt.h"
31771
31772 -atomic_t pau_qps_created;
31773 -atomic_t pau_qps_destroyed;
31774 +atomic_unchecked_t pau_qps_created;
31775 +atomic_unchecked_t pau_qps_destroyed;
31776
31777 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
31778 {
31779 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
31780 {
31781 struct sk_buff *skb;
31782 unsigned long flags;
31783 - atomic_inc(&pau_qps_destroyed);
31784 + atomic_inc_unchecked(&pau_qps_destroyed);
31785
31786 /* Free packets that have not yet been forwarded */
31787 /* Lock is acquired by skb_dequeue when removing the skb */
31788 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
31789 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
31790 skb_queue_head_init(&nesqp->pau_list);
31791 spin_lock_init(&nesqp->pau_lock);
31792 - atomic_inc(&pau_qps_created);
31793 + atomic_inc_unchecked(&pau_qps_created);
31794 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
31795 }
31796
31797 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
31798 index f3a3ecf..57d311d 100644
31799 --- a/drivers/infiniband/hw/nes/nes_nic.c
31800 +++ b/drivers/infiniband/hw/nes/nes_nic.c
31801 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
31802 target_stat_values[++index] = mh_detected;
31803 target_stat_values[++index] = mh_pauses_sent;
31804 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
31805 - target_stat_values[++index] = atomic_read(&cm_connects);
31806 - target_stat_values[++index] = atomic_read(&cm_accepts);
31807 - target_stat_values[++index] = atomic_read(&cm_disconnects);
31808 - target_stat_values[++index] = atomic_read(&cm_connecteds);
31809 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
31810 - target_stat_values[++index] = atomic_read(&cm_rejects);
31811 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
31812 - target_stat_values[++index] = atomic_read(&qps_created);
31813 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
31814 - target_stat_values[++index] = atomic_read(&qps_destroyed);
31815 - target_stat_values[++index] = atomic_read(&cm_closes);
31816 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
31817 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
31818 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
31819 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
31820 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
31821 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
31822 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
31823 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
31824 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
31825 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
31826 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
31827 target_stat_values[++index] = cm_packets_sent;
31828 target_stat_values[++index] = cm_packets_bounced;
31829 target_stat_values[++index] = cm_packets_created;
31830 target_stat_values[++index] = cm_packets_received;
31831 target_stat_values[++index] = cm_packets_dropped;
31832 target_stat_values[++index] = cm_packets_retrans;
31833 - target_stat_values[++index] = atomic_read(&cm_listens_created);
31834 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
31835 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
31836 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
31837 target_stat_values[++index] = cm_backlog_drops;
31838 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
31839 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
31840 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
31841 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
31842 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
31843 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
31844 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
31845 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
31846 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
31847 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
31848 target_stat_values[++index] = nesadapter->free_4kpbl;
31849 target_stat_values[++index] = nesadapter->free_256pbl;
31850 target_stat_values[++index] = int_mod_timer_init;
31851 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
31852 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
31853 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
31854 - target_stat_values[++index] = atomic_read(&pau_qps_created);
31855 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
31856 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
31857 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
31858 }
31859
31860 /**
31861 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
31862 index 0927b5c..ed67986 100644
31863 --- a/drivers/infiniband/hw/nes/nes_verbs.c
31864 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
31865 @@ -46,9 +46,9 @@
31866
31867 #include <rdma/ib_umem.h>
31868
31869 -atomic_t mod_qp_timouts;
31870 -atomic_t qps_created;
31871 -atomic_t sw_qps_destroyed;
31872 +atomic_unchecked_t mod_qp_timouts;
31873 +atomic_unchecked_t qps_created;
31874 +atomic_unchecked_t sw_qps_destroyed;
31875
31876 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
31877
31878 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
31879 if (init_attr->create_flags)
31880 return ERR_PTR(-EINVAL);
31881
31882 - atomic_inc(&qps_created);
31883 + atomic_inc_unchecked(&qps_created);
31884 switch (init_attr->qp_type) {
31885 case IB_QPT_RC:
31886 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
31887 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
31888 struct iw_cm_event cm_event;
31889 int ret = 0;
31890
31891 - atomic_inc(&sw_qps_destroyed);
31892 + atomic_inc_unchecked(&sw_qps_destroyed);
31893 nesqp->destroyed = 1;
31894
31895 /* Blow away the connection if it exists. */
31896 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
31897 index b881bdc..c2e360c 100644
31898 --- a/drivers/infiniband/hw/qib/qib.h
31899 +++ b/drivers/infiniband/hw/qib/qib.h
31900 @@ -51,6 +51,7 @@
31901 #include <linux/completion.h>
31902 #include <linux/kref.h>
31903 #include <linux/sched.h>
31904 +#include <linux/slab.h>
31905
31906 #include "qib_common.h"
31907 #include "qib_verbs.h"
31908 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
31909 index c351aa4..e6967c2 100644
31910 --- a/drivers/input/gameport/gameport.c
31911 +++ b/drivers/input/gameport/gameport.c
31912 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
31913 */
31914 static void gameport_init_port(struct gameport *gameport)
31915 {
31916 - static atomic_t gameport_no = ATOMIC_INIT(0);
31917 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
31918
31919 __module_get(THIS_MODULE);
31920
31921 mutex_init(&gameport->drv_mutex);
31922 device_initialize(&gameport->dev);
31923 dev_set_name(&gameport->dev, "gameport%lu",
31924 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
31925 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
31926 gameport->dev.bus = &gameport_bus;
31927 gameport->dev.release = gameport_release_port;
31928 if (gameport->parent)
31929 diff --git a/drivers/input/input.c b/drivers/input/input.c
31930 index 1f78c95..3cddc6c 100644
31931 --- a/drivers/input/input.c
31932 +++ b/drivers/input/input.c
31933 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
31934 */
31935 int input_register_device(struct input_dev *dev)
31936 {
31937 - static atomic_t input_no = ATOMIC_INIT(0);
31938 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
31939 struct input_handler *handler;
31940 const char *path;
31941 int error;
31942 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
31943 dev->setkeycode = input_default_setkeycode;
31944
31945 dev_set_name(&dev->dev, "input%ld",
31946 - (unsigned long) atomic_inc_return(&input_no) - 1);
31947 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
31948
31949 error = device_add(&dev->dev);
31950 if (error)
31951 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
31952 index b8d8611..7a4a04b 100644
31953 --- a/drivers/input/joystick/sidewinder.c
31954 +++ b/drivers/input/joystick/sidewinder.c
31955 @@ -30,6 +30,7 @@
31956 #include <linux/kernel.h>
31957 #include <linux/module.h>
31958 #include <linux/slab.h>
31959 +#include <linux/sched.h>
31960 #include <linux/init.h>
31961 #include <linux/input.h>
31962 #include <linux/gameport.h>
31963 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
31964 index fd7a0d5..a4af10c 100644
31965 --- a/drivers/input/joystick/xpad.c
31966 +++ b/drivers/input/joystick/xpad.c
31967 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
31968
31969 static int xpad_led_probe(struct usb_xpad *xpad)
31970 {
31971 - static atomic_t led_seq = ATOMIC_INIT(0);
31972 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31973 long led_no;
31974 struct xpad_led *led;
31975 struct led_classdev *led_cdev;
31976 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
31977 if (!led)
31978 return -ENOMEM;
31979
31980 - led_no = (long)atomic_inc_return(&led_seq) - 1;
31981 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31982
31983 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31984 led->xpad = xpad;
31985 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
31986 index 0110b5a..d3ad144 100644
31987 --- a/drivers/input/mousedev.c
31988 +++ b/drivers/input/mousedev.c
31989 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
31990
31991 spin_unlock_irq(&client->packet_lock);
31992
31993 - if (copy_to_user(buffer, data, count))
31994 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
31995 return -EFAULT;
31996
31997 return count;
31998 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
31999 index ba70058..571d25d 100644
32000 --- a/drivers/input/serio/serio.c
32001 +++ b/drivers/input/serio/serio.c
32002 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32003 */
32004 static void serio_init_port(struct serio *serio)
32005 {
32006 - static atomic_t serio_no = ATOMIC_INIT(0);
32007 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32008
32009 __module_get(THIS_MODULE);
32010
32011 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32012 mutex_init(&serio->drv_mutex);
32013 device_initialize(&serio->dev);
32014 dev_set_name(&serio->dev, "serio%ld",
32015 - (long)atomic_inc_return(&serio_no) - 1);
32016 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32017 serio->dev.bus = &serio_bus;
32018 serio->dev.release = serio_release_port;
32019 serio->dev.groups = serio_device_attr_groups;
32020 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32021 index e44933d..9ba484a 100644
32022 --- a/drivers/isdn/capi/capi.c
32023 +++ b/drivers/isdn/capi/capi.c
32024 @@ -83,8 +83,8 @@ struct capiminor {
32025
32026 struct capi20_appl *ap;
32027 u32 ncci;
32028 - atomic_t datahandle;
32029 - atomic_t msgid;
32030 + atomic_unchecked_t datahandle;
32031 + atomic_unchecked_t msgid;
32032
32033 struct tty_port port;
32034 int ttyinstop;
32035 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32036 capimsg_setu16(s, 2, mp->ap->applid);
32037 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32038 capimsg_setu8 (s, 5, CAPI_RESP);
32039 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32040 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32041 capimsg_setu32(s, 8, mp->ncci);
32042 capimsg_setu16(s, 12, datahandle);
32043 }
32044 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32045 mp->outbytes -= len;
32046 spin_unlock_bh(&mp->outlock);
32047
32048 - datahandle = atomic_inc_return(&mp->datahandle);
32049 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32050 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32051 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32052 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32053 capimsg_setu16(skb->data, 2, mp->ap->applid);
32054 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32055 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32056 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32057 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32058 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32059 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32060 capimsg_setu16(skb->data, 16, len); /* Data length */
32061 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
32062 index db621db..825ea1a 100644
32063 --- a/drivers/isdn/gigaset/common.c
32064 +++ b/drivers/isdn/gigaset/common.c
32065 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
32066 cs->commands_pending = 0;
32067 cs->cur_at_seq = 0;
32068 cs->gotfwver = -1;
32069 - cs->open_count = 0;
32070 + local_set(&cs->open_count, 0);
32071 cs->dev = NULL;
32072 cs->tty = NULL;
32073 cs->tty_dev = NULL;
32074 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
32075 index 212efaf..f187c6b 100644
32076 --- a/drivers/isdn/gigaset/gigaset.h
32077 +++ b/drivers/isdn/gigaset/gigaset.h
32078 @@ -35,6 +35,7 @@
32079 #include <linux/tty_driver.h>
32080 #include <linux/list.h>
32081 #include <linux/atomic.h>
32082 +#include <asm/local.h>
32083
32084 #define GIG_VERSION {0, 5, 0, 0}
32085 #define GIG_COMPAT {0, 4, 0, 0}
32086 @@ -433,7 +434,7 @@ struct cardstate {
32087 spinlock_t cmdlock;
32088 unsigned curlen, cmdbytes;
32089
32090 - unsigned open_count;
32091 + local_t open_count;
32092 struct tty_struct *tty;
32093 struct tasklet_struct if_wake_tasklet;
32094 unsigned control_state;
32095 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32096 index ee0a549..a7c9798 100644
32097 --- a/drivers/isdn/gigaset/interface.c
32098 +++ b/drivers/isdn/gigaset/interface.c
32099 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32100 }
32101 tty->driver_data = cs;
32102
32103 - ++cs->open_count;
32104 -
32105 - if (cs->open_count == 1) {
32106 + if (local_inc_return(&cs->open_count) == 1) {
32107 spin_lock_irqsave(&cs->lock, flags);
32108 cs->tty = tty;
32109 spin_unlock_irqrestore(&cs->lock, flags);
32110 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32111
32112 if (!cs->connected)
32113 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32114 - else if (!cs->open_count)
32115 + else if (!local_read(&cs->open_count))
32116 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32117 else {
32118 - if (!--cs->open_count) {
32119 + if (!local_dec_return(&cs->open_count)) {
32120 spin_lock_irqsave(&cs->lock, flags);
32121 cs->tty = NULL;
32122 spin_unlock_irqrestore(&cs->lock, flags);
32123 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
32124 if (!cs->connected) {
32125 gig_dbg(DEBUG_IF, "not connected");
32126 retval = -ENODEV;
32127 - } else if (!cs->open_count)
32128 + } else if (!local_read(&cs->open_count))
32129 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32130 else {
32131 retval = 0;
32132 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
32133 retval = -ENODEV;
32134 goto done;
32135 }
32136 - if (!cs->open_count) {
32137 + if (!local_read(&cs->open_count)) {
32138 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32139 retval = -ENODEV;
32140 goto done;
32141 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
32142 if (!cs->connected) {
32143 gig_dbg(DEBUG_IF, "not connected");
32144 retval = -ENODEV;
32145 - } else if (!cs->open_count)
32146 + } else if (!local_read(&cs->open_count))
32147 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32148 else if (cs->mstate != MS_LOCKED) {
32149 dev_warn(cs->dev, "can't write to unlocked device\n");
32150 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
32151
32152 if (!cs->connected)
32153 gig_dbg(DEBUG_IF, "not connected");
32154 - else if (!cs->open_count)
32155 + else if (!local_read(&cs->open_count))
32156 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32157 else if (cs->mstate != MS_LOCKED)
32158 dev_warn(cs->dev, "can't write to unlocked device\n");
32159 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
32160
32161 if (!cs->connected)
32162 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32163 - else if (!cs->open_count)
32164 + else if (!local_read(&cs->open_count))
32165 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32166 else
32167 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32168 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
32169
32170 if (!cs->connected)
32171 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32172 - else if (!cs->open_count)
32173 + else if (!local_read(&cs->open_count))
32174 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32175 else
32176 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32177 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
32178 goto out;
32179 }
32180
32181 - if (!cs->open_count) {
32182 + if (!local_read(&cs->open_count)) {
32183 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32184 goto out;
32185 }
32186 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32187 index 2a57da59..e7a12ed 100644
32188 --- a/drivers/isdn/hardware/avm/b1.c
32189 +++ b/drivers/isdn/hardware/avm/b1.c
32190 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
32191 }
32192 if (left) {
32193 if (t4file->user) {
32194 - if (copy_from_user(buf, dp, left))
32195 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32196 return -EFAULT;
32197 } else {
32198 memcpy(buf, dp, left);
32199 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
32200 }
32201 if (left) {
32202 if (config->user) {
32203 - if (copy_from_user(buf, dp, left))
32204 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32205 return -EFAULT;
32206 } else {
32207 memcpy(buf, dp, left);
32208 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32209 index 85784a7..a19ca98 100644
32210 --- a/drivers/isdn/hardware/eicon/divasync.h
32211 +++ b/drivers/isdn/hardware/eicon/divasync.h
32212 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32213 } diva_didd_add_adapter_t;
32214 typedef struct _diva_didd_remove_adapter {
32215 IDI_CALL p_request;
32216 -} diva_didd_remove_adapter_t;
32217 +} __no_const diva_didd_remove_adapter_t;
32218 typedef struct _diva_didd_read_adapter_array {
32219 void * buffer;
32220 dword length;
32221 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32222 index a3bd163..8956575 100644
32223 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32224 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32225 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32226 typedef struct _diva_os_idi_adapter_interface {
32227 diva_init_card_proc_t cleanup_adapter_proc;
32228 diva_cmd_card_proc_t cmd_proc;
32229 -} diva_os_idi_adapter_interface_t;
32230 +} __no_const diva_os_idi_adapter_interface_t;
32231
32232 typedef struct _diva_os_xdi_adapter {
32233 struct list_head link;
32234 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32235 index 1f355bb..43f1fea 100644
32236 --- a/drivers/isdn/icn/icn.c
32237 +++ b/drivers/isdn/icn/icn.c
32238 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
32239 if (count > len)
32240 count = len;
32241 if (user) {
32242 - if (copy_from_user(msg, buf, count))
32243 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32244 return -EFAULT;
32245 } else
32246 memcpy(msg, buf, count);
32247 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32248 index b5fdcb7..5b6c59f 100644
32249 --- a/drivers/lguest/core.c
32250 +++ b/drivers/lguest/core.c
32251 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32252 * it's worked so far. The end address needs +1 because __get_vm_area
32253 * allocates an extra guard page, so we need space for that.
32254 */
32255 +
32256 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32257 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32258 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32259 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32260 +#else
32261 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32262 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32263 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32264 +#endif
32265 +
32266 if (!switcher_vma) {
32267 err = -ENOMEM;
32268 printk("lguest: could not map switcher pages high\n");
32269 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32270 * Now the Switcher is mapped at the right address, we can't fail!
32271 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32272 */
32273 - memcpy(switcher_vma->addr, start_switcher_text,
32274 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32275 end_switcher_text - start_switcher_text);
32276
32277 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32278 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32279 index 3980903..ce25c5e 100644
32280 --- a/drivers/lguest/x86/core.c
32281 +++ b/drivers/lguest/x86/core.c
32282 @@ -59,7 +59,7 @@ static struct {
32283 /* Offset from where switcher.S was compiled to where we've copied it */
32284 static unsigned long switcher_offset(void)
32285 {
32286 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32287 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32288 }
32289
32290 /* This cpu's struct lguest_pages. */
32291 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32292 * These copies are pretty cheap, so we do them unconditionally: */
32293 /* Save the current Host top-level page directory.
32294 */
32295 +
32296 +#ifdef CONFIG_PAX_PER_CPU_PGD
32297 + pages->state.host_cr3 = read_cr3();
32298 +#else
32299 pages->state.host_cr3 = __pa(current->mm->pgd);
32300 +#endif
32301 +
32302 /*
32303 * Set up the Guest's page tables to see this CPU's pages (and no
32304 * other CPU's pages).
32305 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32306 * compiled-in switcher code and the high-mapped copy we just made.
32307 */
32308 for (i = 0; i < IDT_ENTRIES; i++)
32309 - default_idt_entries[i] += switcher_offset();
32310 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32311
32312 /*
32313 * Set up the Switcher's per-cpu areas.
32314 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32315 * it will be undisturbed when we switch. To change %cs and jump we
32316 * need this structure to feed to Intel's "lcall" instruction.
32317 */
32318 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32319 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32320 lguest_entry.segment = LGUEST_CS;
32321
32322 /*
32323 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32324 index 40634b0..4f5855e 100644
32325 --- a/drivers/lguest/x86/switcher_32.S
32326 +++ b/drivers/lguest/x86/switcher_32.S
32327 @@ -87,6 +87,7 @@
32328 #include <asm/page.h>
32329 #include <asm/segment.h>
32330 #include <asm/lguest.h>
32331 +#include <asm/processor-flags.h>
32332
32333 // We mark the start of the code to copy
32334 // It's placed in .text tho it's never run here
32335 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
32336 // Changes type when we load it: damn Intel!
32337 // For after we switch over our page tables
32338 // That entry will be read-only: we'd crash.
32339 +
32340 +#ifdef CONFIG_PAX_KERNEXEC
32341 + mov %cr0, %edx
32342 + xor $X86_CR0_WP, %edx
32343 + mov %edx, %cr0
32344 +#endif
32345 +
32346 movl $(GDT_ENTRY_TSS*8), %edx
32347 ltr %dx
32348
32349 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
32350 // Let's clear it again for our return.
32351 // The GDT descriptor of the Host
32352 // Points to the table after two "size" bytes
32353 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
32354 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
32355 // Clear "used" from type field (byte 5, bit 2)
32356 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
32357 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
32358 +
32359 +#ifdef CONFIG_PAX_KERNEXEC
32360 + mov %cr0, %eax
32361 + xor $X86_CR0_WP, %eax
32362 + mov %eax, %cr0
32363 +#endif
32364
32365 // Once our page table's switched, the Guest is live!
32366 // The Host fades as we run this final step.
32367 @@ -295,13 +309,12 @@ deliver_to_host:
32368 // I consulted gcc, and it gave
32369 // These instructions, which I gladly credit:
32370 leal (%edx,%ebx,8), %eax
32371 - movzwl (%eax),%edx
32372 - movl 4(%eax), %eax
32373 - xorw %ax, %ax
32374 - orl %eax, %edx
32375 + movl 4(%eax), %edx
32376 + movw (%eax), %dx
32377 // Now the address of the handler's in %edx
32378 // We call it now: its "iret" drops us home.
32379 - jmp *%edx
32380 + ljmp $__KERNEL_CS, $1f
32381 +1: jmp *%edx
32382
32383 // Every interrupt can come to us here
32384 // But we must truly tell each apart.
32385 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
32386 index 4daf9e5..b8d1d0f 100644
32387 --- a/drivers/macintosh/macio_asic.c
32388 +++ b/drivers/macintosh/macio_asic.c
32389 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
32390 * MacIO is matched against any Apple ID, it's probe() function
32391 * will then decide wether it applies or not
32392 */
32393 -static const struct pci_device_id __devinitdata pci_ids [] = { {
32394 +static const struct pci_device_id __devinitconst pci_ids [] = { {
32395 .vendor = PCI_VENDOR_ID_APPLE,
32396 .device = PCI_ANY_ID,
32397 .subvendor = PCI_ANY_ID,
32398 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
32399 index 1ce84ed..0fdd40a 100644
32400 --- a/drivers/md/dm-ioctl.c
32401 +++ b/drivers/md/dm-ioctl.c
32402 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
32403 cmd == DM_LIST_VERSIONS_CMD)
32404 return 0;
32405
32406 - if ((cmd == DM_DEV_CREATE_CMD)) {
32407 + if (cmd == DM_DEV_CREATE_CMD) {
32408 if (!*param->name) {
32409 DMWARN("name not supplied when creating device");
32410 return -EINVAL;
32411 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
32412 index 9bfd057..01180bc 100644
32413 --- a/drivers/md/dm-raid1.c
32414 +++ b/drivers/md/dm-raid1.c
32415 @@ -40,7 +40,7 @@ enum dm_raid1_error {
32416
32417 struct mirror {
32418 struct mirror_set *ms;
32419 - atomic_t error_count;
32420 + atomic_unchecked_t error_count;
32421 unsigned long error_type;
32422 struct dm_dev *dev;
32423 sector_t offset;
32424 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
32425 struct mirror *m;
32426
32427 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
32428 - if (!atomic_read(&m->error_count))
32429 + if (!atomic_read_unchecked(&m->error_count))
32430 return m;
32431
32432 return NULL;
32433 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
32434 * simple way to tell if a device has encountered
32435 * errors.
32436 */
32437 - atomic_inc(&m->error_count);
32438 + atomic_inc_unchecked(&m->error_count);
32439
32440 if (test_and_set_bit(error_type, &m->error_type))
32441 return;
32442 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
32443 struct mirror *m = get_default_mirror(ms);
32444
32445 do {
32446 - if (likely(!atomic_read(&m->error_count)))
32447 + if (likely(!atomic_read_unchecked(&m->error_count)))
32448 return m;
32449
32450 if (m-- == ms->mirror)
32451 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
32452 {
32453 struct mirror *default_mirror = get_default_mirror(m->ms);
32454
32455 - return !atomic_read(&default_mirror->error_count);
32456 + return !atomic_read_unchecked(&default_mirror->error_count);
32457 }
32458
32459 static int mirror_available(struct mirror_set *ms, struct bio *bio)
32460 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
32461 */
32462 if (likely(region_in_sync(ms, region, 1)))
32463 m = choose_mirror(ms, bio->bi_sector);
32464 - else if (m && atomic_read(&m->error_count))
32465 + else if (m && atomic_read_unchecked(&m->error_count))
32466 m = NULL;
32467
32468 if (likely(m))
32469 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
32470 }
32471
32472 ms->mirror[mirror].ms = ms;
32473 - atomic_set(&(ms->mirror[mirror].error_count), 0);
32474 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
32475 ms->mirror[mirror].error_type = 0;
32476 ms->mirror[mirror].offset = offset;
32477
32478 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
32479 */
32480 static char device_status_char(struct mirror *m)
32481 {
32482 - if (!atomic_read(&(m->error_count)))
32483 + if (!atomic_read_unchecked(&(m->error_count)))
32484 return 'A';
32485
32486 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
32487 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
32488 index 3d80cf0..b77cc47 100644
32489 --- a/drivers/md/dm-stripe.c
32490 +++ b/drivers/md/dm-stripe.c
32491 @@ -20,7 +20,7 @@ struct stripe {
32492 struct dm_dev *dev;
32493 sector_t physical_start;
32494
32495 - atomic_t error_count;
32496 + atomic_unchecked_t error_count;
32497 };
32498
32499 struct stripe_c {
32500 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
32501 kfree(sc);
32502 return r;
32503 }
32504 - atomic_set(&(sc->stripe[i].error_count), 0);
32505 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
32506 }
32507
32508 ti->private = sc;
32509 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
32510 DMEMIT("%d ", sc->stripes);
32511 for (i = 0; i < sc->stripes; i++) {
32512 DMEMIT("%s ", sc->stripe[i].dev->name);
32513 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
32514 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
32515 'D' : 'A';
32516 }
32517 buffer[i] = '\0';
32518 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
32519 */
32520 for (i = 0; i < sc->stripes; i++)
32521 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
32522 - atomic_inc(&(sc->stripe[i].error_count));
32523 - if (atomic_read(&(sc->stripe[i].error_count)) <
32524 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
32525 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
32526 DM_IO_ERROR_THRESHOLD)
32527 schedule_work(&sc->trigger_event);
32528 }
32529 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
32530 index 63cc542..8d45caf3 100644
32531 --- a/drivers/md/dm-table.c
32532 +++ b/drivers/md/dm-table.c
32533 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
32534 if (!dev_size)
32535 return 0;
32536
32537 - if ((start >= dev_size) || (start + len > dev_size)) {
32538 + if ((start >= dev_size) || (len > dev_size - start)) {
32539 DMWARN("%s: %s too small for target: "
32540 "start=%llu, len=%llu, dev_size=%llu",
32541 dm_device_name(ti->table->md), bdevname(bdev, b),
32542 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
32543 index 237571a..fb6d19b 100644
32544 --- a/drivers/md/dm-thin-metadata.c
32545 +++ b/drivers/md/dm-thin-metadata.c
32546 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
32547
32548 pmd->info.tm = tm;
32549 pmd->info.levels = 2;
32550 - pmd->info.value_type.context = pmd->data_sm;
32551 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
32552 pmd->info.value_type.size = sizeof(__le64);
32553 pmd->info.value_type.inc = data_block_inc;
32554 pmd->info.value_type.dec = data_block_dec;
32555 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
32556
32557 pmd->bl_info.tm = tm;
32558 pmd->bl_info.levels = 1;
32559 - pmd->bl_info.value_type.context = pmd->data_sm;
32560 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
32561 pmd->bl_info.value_type.size = sizeof(__le64);
32562 pmd->bl_info.value_type.inc = data_block_inc;
32563 pmd->bl_info.value_type.dec = data_block_dec;
32564 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
32565 index b89c548..2af3ce4 100644
32566 --- a/drivers/md/dm.c
32567 +++ b/drivers/md/dm.c
32568 @@ -176,9 +176,9 @@ struct mapped_device {
32569 /*
32570 * Event handling.
32571 */
32572 - atomic_t event_nr;
32573 + atomic_unchecked_t event_nr;
32574 wait_queue_head_t eventq;
32575 - atomic_t uevent_seq;
32576 + atomic_unchecked_t uevent_seq;
32577 struct list_head uevent_list;
32578 spinlock_t uevent_lock; /* Protect access to uevent_list */
32579
32580 @@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
32581 rwlock_init(&md->map_lock);
32582 atomic_set(&md->holders, 1);
32583 atomic_set(&md->open_count, 0);
32584 - atomic_set(&md->event_nr, 0);
32585 - atomic_set(&md->uevent_seq, 0);
32586 + atomic_set_unchecked(&md->event_nr, 0);
32587 + atomic_set_unchecked(&md->uevent_seq, 0);
32588 INIT_LIST_HEAD(&md->uevent_list);
32589 spin_lock_init(&md->uevent_lock);
32590
32591 @@ -1979,7 +1979,7 @@ static void event_callback(void *context)
32592
32593 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
32594
32595 - atomic_inc(&md->event_nr);
32596 + atomic_inc_unchecked(&md->event_nr);
32597 wake_up(&md->eventq);
32598 }
32599
32600 @@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
32601
32602 uint32_t dm_next_uevent_seq(struct mapped_device *md)
32603 {
32604 - return atomic_add_return(1, &md->uevent_seq);
32605 + return atomic_add_return_unchecked(1, &md->uevent_seq);
32606 }
32607
32608 uint32_t dm_get_event_nr(struct mapped_device *md)
32609 {
32610 - return atomic_read(&md->event_nr);
32611 + return atomic_read_unchecked(&md->event_nr);
32612 }
32613
32614 int dm_wait_event(struct mapped_device *md, int event_nr)
32615 {
32616 return wait_event_interruptible(md->eventq,
32617 - (event_nr != atomic_read(&md->event_nr)));
32618 + (event_nr != atomic_read_unchecked(&md->event_nr)));
32619 }
32620
32621 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
32622 diff --git a/drivers/md/md.c b/drivers/md/md.c
32623 index 6acc846..80a6b96 100644
32624 --- a/drivers/md/md.c
32625 +++ b/drivers/md/md.c
32626 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
32627 * start build, activate spare
32628 */
32629 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
32630 -static atomic_t md_event_count;
32631 +static atomic_unchecked_t md_event_count;
32632 void md_new_event(struct mddev *mddev)
32633 {
32634 - atomic_inc(&md_event_count);
32635 + atomic_inc_unchecked(&md_event_count);
32636 wake_up(&md_event_waiters);
32637 }
32638 EXPORT_SYMBOL_GPL(md_new_event);
32639 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
32640 */
32641 static void md_new_event_inintr(struct mddev *mddev)
32642 {
32643 - atomic_inc(&md_event_count);
32644 + atomic_inc_unchecked(&md_event_count);
32645 wake_up(&md_event_waiters);
32646 }
32647
32648 @@ -1524,7 +1524,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
32649
32650 rdev->preferred_minor = 0xffff;
32651 rdev->data_offset = le64_to_cpu(sb->data_offset);
32652 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32653 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32654
32655 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
32656 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
32657 @@ -1743,7 +1743,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
32658 else
32659 sb->resync_offset = cpu_to_le64(0);
32660
32661 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
32662 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
32663
32664 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
32665 sb->size = cpu_to_le64(mddev->dev_sectors);
32666 @@ -2689,7 +2689,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
32667 static ssize_t
32668 errors_show(struct md_rdev *rdev, char *page)
32669 {
32670 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
32671 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
32672 }
32673
32674 static ssize_t
32675 @@ -2698,7 +2698,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
32676 char *e;
32677 unsigned long n = simple_strtoul(buf, &e, 10);
32678 if (*buf && (*e == 0 || *e == '\n')) {
32679 - atomic_set(&rdev->corrected_errors, n);
32680 + atomic_set_unchecked(&rdev->corrected_errors, n);
32681 return len;
32682 }
32683 return -EINVAL;
32684 @@ -3084,8 +3084,8 @@ int md_rdev_init(struct md_rdev *rdev)
32685 rdev->sb_loaded = 0;
32686 rdev->bb_page = NULL;
32687 atomic_set(&rdev->nr_pending, 0);
32688 - atomic_set(&rdev->read_errors, 0);
32689 - atomic_set(&rdev->corrected_errors, 0);
32690 + atomic_set_unchecked(&rdev->read_errors, 0);
32691 + atomic_set_unchecked(&rdev->corrected_errors, 0);
32692
32693 INIT_LIST_HEAD(&rdev->same_set);
32694 init_waitqueue_head(&rdev->blocked_wait);
32695 @@ -6736,7 +6736,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
32696
32697 spin_unlock(&pers_lock);
32698 seq_printf(seq, "\n");
32699 - seq->poll_event = atomic_read(&md_event_count);
32700 + seq->poll_event = atomic_read_unchecked(&md_event_count);
32701 return 0;
32702 }
32703 if (v == (void*)2) {
32704 @@ -6828,7 +6828,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
32705 chunk_kb ? "KB" : "B");
32706 if (bitmap->file) {
32707 seq_printf(seq, ", file: ");
32708 - seq_path(seq, &bitmap->file->f_path, " \t\n");
32709 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
32710 }
32711
32712 seq_printf(seq, "\n");
32713 @@ -6859,7 +6859,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
32714 return error;
32715
32716 seq = file->private_data;
32717 - seq->poll_event = atomic_read(&md_event_count);
32718 + seq->poll_event = atomic_read_unchecked(&md_event_count);
32719 return error;
32720 }
32721
32722 @@ -6873,7 +6873,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
32723 /* always allow read */
32724 mask = POLLIN | POLLRDNORM;
32725
32726 - if (seq->poll_event != atomic_read(&md_event_count))
32727 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
32728 mask |= POLLERR | POLLPRI;
32729 return mask;
32730 }
32731 @@ -6917,7 +6917,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
32732 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
32733 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
32734 (int)part_stat_read(&disk->part0, sectors[1]) -
32735 - atomic_read(&disk->sync_io);
32736 + atomic_read_unchecked(&disk->sync_io);
32737 /* sync IO will cause sync_io to increase before the disk_stats
32738 * as sync_io is counted when a request starts, and
32739 * disk_stats is counted when it completes.
32740 diff --git a/drivers/md/md.h b/drivers/md/md.h
32741 index 44c63df..b795d1a 100644
32742 --- a/drivers/md/md.h
32743 +++ b/drivers/md/md.h
32744 @@ -93,13 +93,13 @@ struct md_rdev {
32745 * only maintained for arrays that
32746 * support hot removal
32747 */
32748 - atomic_t read_errors; /* number of consecutive read errors that
32749 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
32750 * we have tried to ignore.
32751 */
32752 struct timespec last_read_error; /* monotonic time since our
32753 * last read error
32754 */
32755 - atomic_t corrected_errors; /* number of corrected read errors,
32756 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32757 * for reporting to userspace and storing
32758 * in superblock.
32759 */
32760 @@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
32761
32762 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32763 {
32764 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32765 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32766 }
32767
32768 struct md_personality
32769 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
32770 index 50ed53b..4f29d7d 100644
32771 --- a/drivers/md/persistent-data/dm-space-map-checker.c
32772 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
32773 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
32774 /*----------------------------------------------------------------*/
32775
32776 struct sm_checker {
32777 - struct dm_space_map sm;
32778 + dm_space_map_no_const sm;
32779
32780 struct count_array old_counts;
32781 struct count_array counts;
32782 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
32783 index fc469ba..2d91555 100644
32784 --- a/drivers/md/persistent-data/dm-space-map-disk.c
32785 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
32786 @@ -23,7 +23,7 @@
32787 * Space map interface.
32788 */
32789 struct sm_disk {
32790 - struct dm_space_map sm;
32791 + dm_space_map_no_const sm;
32792
32793 struct ll_disk ll;
32794 struct ll_disk old_ll;
32795 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
32796 index e89ae5e..062e4c2 100644
32797 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
32798 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
32799 @@ -43,7 +43,7 @@ struct block_op {
32800 };
32801
32802 struct sm_metadata {
32803 - struct dm_space_map sm;
32804 + dm_space_map_no_const sm;
32805
32806 struct ll_disk ll;
32807 struct ll_disk old_ll;
32808 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
32809 index 1cbfc6b..56e1dbb 100644
32810 --- a/drivers/md/persistent-data/dm-space-map.h
32811 +++ b/drivers/md/persistent-data/dm-space-map.h
32812 @@ -60,6 +60,7 @@ struct dm_space_map {
32813 int (*root_size)(struct dm_space_map *sm, size_t *result);
32814 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
32815 };
32816 +typedef struct dm_space_map __no_const dm_space_map_no_const;
32817
32818 /*----------------------------------------------------------------*/
32819
32820 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
32821 index 118e0f6..210c4d7 100644
32822 --- a/drivers/md/raid1.c
32823 +++ b/drivers/md/raid1.c
32824 @@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
32825 if (r1_sync_page_io(rdev, sect, s,
32826 bio->bi_io_vec[idx].bv_page,
32827 READ) != 0)
32828 - atomic_add(s, &rdev->corrected_errors);
32829 + atomic_add_unchecked(s, &rdev->corrected_errors);
32830 }
32831 sectors -= s;
32832 sect += s;
32833 @@ -1858,7 +1858,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
32834 test_bit(In_sync, &rdev->flags)) {
32835 if (r1_sync_page_io(rdev, sect, s,
32836 conf->tmppage, READ)) {
32837 - atomic_add(s, &rdev->corrected_errors);
32838 + atomic_add_unchecked(s, &rdev->corrected_errors);
32839 printk(KERN_INFO
32840 "md/raid1:%s: read error corrected "
32841 "(%d sectors at %llu on %s)\n",
32842 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
32843 index be7101d..f23ba30 100644
32844 --- a/drivers/md/raid10.c
32845 +++ b/drivers/md/raid10.c
32846 @@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
32847 /* The write handler will notice the lack of
32848 * R10BIO_Uptodate and record any errors etc
32849 */
32850 - atomic_add(r10_bio->sectors,
32851 + atomic_add_unchecked(r10_bio->sectors,
32852 &conf->mirrors[d].rdev->corrected_errors);
32853
32854 /* for reconstruct, we always reschedule after a read.
32855 @@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
32856 {
32857 struct timespec cur_time_mon;
32858 unsigned long hours_since_last;
32859 - unsigned int read_errors = atomic_read(&rdev->read_errors);
32860 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
32861
32862 ktime_get_ts(&cur_time_mon);
32863
32864 @@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
32865 * overflowing the shift of read_errors by hours_since_last.
32866 */
32867 if (hours_since_last >= 8 * sizeof(read_errors))
32868 - atomic_set(&rdev->read_errors, 0);
32869 + atomic_set_unchecked(&rdev->read_errors, 0);
32870 else
32871 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
32872 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
32873 }
32874
32875 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
32876 @@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32877 return;
32878
32879 check_decay_read_errors(mddev, rdev);
32880 - atomic_inc(&rdev->read_errors);
32881 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
32882 + atomic_inc_unchecked(&rdev->read_errors);
32883 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
32884 char b[BDEVNAME_SIZE];
32885 bdevname(rdev->bdev, b);
32886
32887 @@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32888 "md/raid10:%s: %s: Raid device exceeded "
32889 "read_error threshold [cur %d:max %d]\n",
32890 mdname(mddev), b,
32891 - atomic_read(&rdev->read_errors), max_read_errors);
32892 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
32893 printk(KERN_NOTICE
32894 "md/raid10:%s: %s: Failing raid device\n",
32895 mdname(mddev), b);
32896 @@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32897 (unsigned long long)(
32898 sect + rdev->data_offset),
32899 bdevname(rdev->bdev, b));
32900 - atomic_add(s, &rdev->corrected_errors);
32901 + atomic_add_unchecked(s, &rdev->corrected_errors);
32902 }
32903
32904 rdev_dec_pending(rdev, mddev);
32905 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
32906 index 360f2b9..08b5382 100644
32907 --- a/drivers/md/raid5.c
32908 +++ b/drivers/md/raid5.c
32909 @@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
32910 (unsigned long long)(sh->sector
32911 + rdev->data_offset),
32912 bdevname(rdev->bdev, b));
32913 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
32914 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
32915 clear_bit(R5_ReadError, &sh->dev[i].flags);
32916 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32917 }
32918 - if (atomic_read(&rdev->read_errors))
32919 - atomic_set(&rdev->read_errors, 0);
32920 + if (atomic_read_unchecked(&rdev->read_errors))
32921 + atomic_set_unchecked(&rdev->read_errors, 0);
32922 } else {
32923 const char *bdn = bdevname(rdev->bdev, b);
32924 int retry = 0;
32925
32926 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32927 - atomic_inc(&rdev->read_errors);
32928 + atomic_inc_unchecked(&rdev->read_errors);
32929 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
32930 printk_ratelimited(
32931 KERN_WARNING
32932 @@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
32933 (unsigned long long)(sh->sector
32934 + rdev->data_offset),
32935 bdn);
32936 - else if (atomic_read(&rdev->read_errors)
32937 + else if (atomic_read_unchecked(&rdev->read_errors)
32938 > conf->max_nr_stripes)
32939 printk(KERN_WARNING
32940 "md/raid:%s: Too many read errors, failing device %s.\n",
32941 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
32942 index ce4f858..7bcfb46 100644
32943 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
32944 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
32945 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
32946 .subvendor = _subvend, .subdevice = _subdev, \
32947 .driver_data = (unsigned long)&_driverdata }
32948
32949 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
32950 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
32951 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
32952 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
32953 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
32954 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
32955 index a7d876f..8c21b61 100644
32956 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
32957 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
32958 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
32959 union {
32960 dmx_ts_cb ts;
32961 dmx_section_cb sec;
32962 - } cb;
32963 + } __no_const cb;
32964
32965 struct dvb_demux *demux;
32966 void *priv;
32967 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
32968 index 00a6732..70a682e 100644
32969 --- a/drivers/media/dvb/dvb-core/dvbdev.c
32970 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
32971 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
32972 const struct dvb_device *template, void *priv, int type)
32973 {
32974 struct dvb_device *dvbdev;
32975 - struct file_operations *dvbdevfops;
32976 + file_operations_no_const *dvbdevfops;
32977 struct device *clsdev;
32978 int minor;
32979 int id;
32980 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
32981 index 3940bb0..fb3952a 100644
32982 --- a/drivers/media/dvb/dvb-usb/cxusb.c
32983 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
32984 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
32985
32986 struct dib0700_adapter_state {
32987 int (*set_param_save) (struct dvb_frontend *);
32988 -};
32989 +} __no_const;
32990
32991 static int dib7070_set_param_override(struct dvb_frontend *fe)
32992 {
32993 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
32994 index 451c5a7..649f711 100644
32995 --- a/drivers/media/dvb/dvb-usb/dw2102.c
32996 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
32997 @@ -95,7 +95,7 @@ struct su3000_state {
32998
32999 struct s6x0_state {
33000 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33001 -};
33002 +} __no_const;
33003
33004 /* debug */
33005 static int dvb_usb_dw2102_debug;
33006 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33007 index 404f63a..4796533 100644
33008 --- a/drivers/media/dvb/frontends/dib3000.h
33009 +++ b/drivers/media/dvb/frontends/dib3000.h
33010 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33011 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33012 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33013 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33014 -};
33015 +} __no_const;
33016
33017 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33018 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33019 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33020 index 8418c02..8555013 100644
33021 --- a/drivers/media/dvb/ngene/ngene-cards.c
33022 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33023 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
33024
33025 /****************************************************************************/
33026
33027 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33028 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33029 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33030 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33031 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33032 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33033 index 16a089f..ab1667d 100644
33034 --- a/drivers/media/radio/radio-cadet.c
33035 +++ b/drivers/media/radio/radio-cadet.c
33036 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33037 unsigned char readbuf[RDS_BUFFER];
33038 int i = 0;
33039
33040 + if (count > RDS_BUFFER)
33041 + return -EFAULT;
33042 mutex_lock(&dev->lock);
33043 if (dev->rdsstat == 0) {
33044 dev->rdsstat = 1;
33045 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33046 index 9cde353..8c6a1c3 100644
33047 --- a/drivers/media/video/au0828/au0828.h
33048 +++ b/drivers/media/video/au0828/au0828.h
33049 @@ -191,7 +191,7 @@ struct au0828_dev {
33050
33051 /* I2C */
33052 struct i2c_adapter i2c_adap;
33053 - struct i2c_algorithm i2c_algo;
33054 + i2c_algorithm_no_const i2c_algo;
33055 struct i2c_client i2c_client;
33056 u32 i2c_rc;
33057
33058 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33059 index 04bf662..e0ac026 100644
33060 --- a/drivers/media/video/cx88/cx88-alsa.c
33061 +++ b/drivers/media/video/cx88/cx88-alsa.c
33062 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33063 * Only boards with eeprom and byte 1 at eeprom=1 have it
33064 */
33065
33066 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33067 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33068 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33069 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33070 {0, }
33071 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33072 index 1fb7d5b..3901e77 100644
33073 --- a/drivers/media/video/omap/omap_vout.c
33074 +++ b/drivers/media/video/omap/omap_vout.c
33075 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33076 OMAP_VIDEO2,
33077 };
33078
33079 -static struct videobuf_queue_ops video_vbq_ops;
33080 /* Variables configurable through module params*/
33081 static u32 video1_numbuffers = 3;
33082 static u32 video2_numbuffers = 3;
33083 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33084 {
33085 struct videobuf_queue *q;
33086 struct omap_vout_device *vout = NULL;
33087 + static struct videobuf_queue_ops video_vbq_ops = {
33088 + .buf_setup = omap_vout_buffer_setup,
33089 + .buf_prepare = omap_vout_buffer_prepare,
33090 + .buf_release = omap_vout_buffer_release,
33091 + .buf_queue = omap_vout_buffer_queue,
33092 + };
33093
33094 vout = video_drvdata(file);
33095 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33096 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33097 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33098
33099 q = &vout->vbq;
33100 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33101 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33102 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33103 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33104 spin_lock_init(&vout->vbq_lock);
33105
33106 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33107 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33108 index 305e6aa..0143317 100644
33109 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33110 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33111 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33112
33113 /* I2C stuff */
33114 struct i2c_adapter i2c_adap;
33115 - struct i2c_algorithm i2c_algo;
33116 + i2c_algorithm_no_const i2c_algo;
33117 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33118 int i2c_cx25840_hack_state;
33119 int i2c_linked;
33120 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33121 index 4ed1c7c2..8f15e13 100644
33122 --- a/drivers/media/video/timblogiw.c
33123 +++ b/drivers/media/video/timblogiw.c
33124 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33125
33126 /* Platform device functions */
33127
33128 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33129 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33130 .vidioc_querycap = timblogiw_querycap,
33131 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33132 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33133 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33134 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33135 };
33136
33137 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33138 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33139 .owner = THIS_MODULE,
33140 .open = timblogiw_open,
33141 .release = timblogiw_close,
33142 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33143 index a7dc467..a55c423 100644
33144 --- a/drivers/message/fusion/mptbase.c
33145 +++ b/drivers/message/fusion/mptbase.c
33146 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33147 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33148 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33149
33150 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33151 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33152 +#else
33153 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33154 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33155 +#endif
33156 +
33157 /*
33158 * Rounding UP to nearest 4-kB boundary here...
33159 */
33160 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33161 index 551262e..7551198 100644
33162 --- a/drivers/message/fusion/mptsas.c
33163 +++ b/drivers/message/fusion/mptsas.c
33164 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33165 return 0;
33166 }
33167
33168 +static inline void
33169 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33170 +{
33171 + if (phy_info->port_details) {
33172 + phy_info->port_details->rphy = rphy;
33173 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33174 + ioc->name, rphy));
33175 + }
33176 +
33177 + if (rphy) {
33178 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33179 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33180 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33181 + ioc->name, rphy, rphy->dev.release));
33182 + }
33183 +}
33184 +
33185 /* no mutex */
33186 static void
33187 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33188 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33189 return NULL;
33190 }
33191
33192 -static inline void
33193 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33194 -{
33195 - if (phy_info->port_details) {
33196 - phy_info->port_details->rphy = rphy;
33197 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33198 - ioc->name, rphy));
33199 - }
33200 -
33201 - if (rphy) {
33202 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33203 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33204 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33205 - ioc->name, rphy, rphy->dev.release));
33206 - }
33207 -}
33208 -
33209 static inline struct sas_port *
33210 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33211 {
33212 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33213 index 0c3ced7..1fe34ec 100644
33214 --- a/drivers/message/fusion/mptscsih.c
33215 +++ b/drivers/message/fusion/mptscsih.c
33216 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33217
33218 h = shost_priv(SChost);
33219
33220 - if (h) {
33221 - if (h->info_kbuf == NULL)
33222 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33223 - return h->info_kbuf;
33224 - h->info_kbuf[0] = '\0';
33225 + if (!h)
33226 + return NULL;
33227
33228 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33229 - h->info_kbuf[size-1] = '\0';
33230 - }
33231 + if (h->info_kbuf == NULL)
33232 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33233 + return h->info_kbuf;
33234 + h->info_kbuf[0] = '\0';
33235 +
33236 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33237 + h->info_kbuf[size-1] = '\0';
33238
33239 return h->info_kbuf;
33240 }
33241 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33242 index 6d115c7..58ff7fd 100644
33243 --- a/drivers/message/i2o/i2o_proc.c
33244 +++ b/drivers/message/i2o/i2o_proc.c
33245 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33246 "Array Controller Device"
33247 };
33248
33249 -static char *chtostr(u8 * chars, int n)
33250 -{
33251 - char tmp[256];
33252 - tmp[0] = 0;
33253 - return strncat(tmp, (char *)chars, n);
33254 -}
33255 -
33256 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33257 char *group)
33258 {
33259 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33260
33261 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33262 seq_printf(seq, "%-#8x", ddm_table.module_id);
33263 - seq_printf(seq, "%-29s",
33264 - chtostr(ddm_table.module_name_version, 28));
33265 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33266 seq_printf(seq, "%9d ", ddm_table.data_size);
33267 seq_printf(seq, "%8d", ddm_table.code_size);
33268
33269 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33270
33271 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33272 seq_printf(seq, "%-#8x", dst->module_id);
33273 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33274 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33275 + seq_printf(seq, "%-.28s", dst->module_name_version);
33276 + seq_printf(seq, "%-.8s", dst->date);
33277 seq_printf(seq, "%8d ", dst->module_size);
33278 seq_printf(seq, "%8d ", dst->mpb_size);
33279 seq_printf(seq, "0x%04x", dst->module_flags);
33280 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33281 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33282 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33283 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33284 - seq_printf(seq, "Vendor info : %s\n",
33285 - chtostr((u8 *) (work32 + 2), 16));
33286 - seq_printf(seq, "Product info : %s\n",
33287 - chtostr((u8 *) (work32 + 6), 16));
33288 - seq_printf(seq, "Description : %s\n",
33289 - chtostr((u8 *) (work32 + 10), 16));
33290 - seq_printf(seq, "Product rev. : %s\n",
33291 - chtostr((u8 *) (work32 + 14), 8));
33292 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33293 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33294 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33295 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33296
33297 seq_printf(seq, "Serial number : ");
33298 print_serial_number(seq, (u8 *) (work32 + 16),
33299 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33300 }
33301
33302 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33303 - seq_printf(seq, "Module name : %s\n",
33304 - chtostr(result.module_name, 24));
33305 - seq_printf(seq, "Module revision : %s\n",
33306 - chtostr(result.module_rev, 8));
33307 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
33308 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33309
33310 seq_printf(seq, "Serial number : ");
33311 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33312 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
33313 return 0;
33314 }
33315
33316 - seq_printf(seq, "Device name : %s\n",
33317 - chtostr(result.device_name, 64));
33318 - seq_printf(seq, "Service name : %s\n",
33319 - chtostr(result.service_name, 64));
33320 - seq_printf(seq, "Physical name : %s\n",
33321 - chtostr(result.physical_location, 64));
33322 - seq_printf(seq, "Instance number : %s\n",
33323 - chtostr(result.instance_number, 4));
33324 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
33325 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
33326 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33327 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33328
33329 return 0;
33330 }
33331 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
33332 index a8c08f3..155fe3d 100644
33333 --- a/drivers/message/i2o/iop.c
33334 +++ b/drivers/message/i2o/iop.c
33335 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
33336
33337 spin_lock_irqsave(&c->context_list_lock, flags);
33338
33339 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33340 - atomic_inc(&c->context_list_counter);
33341 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33342 + atomic_inc_unchecked(&c->context_list_counter);
33343
33344 - entry->context = atomic_read(&c->context_list_counter);
33345 + entry->context = atomic_read_unchecked(&c->context_list_counter);
33346
33347 list_add(&entry->list, &c->context_list);
33348
33349 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
33350
33351 #if BITS_PER_LONG == 64
33352 spin_lock_init(&c->context_list_lock);
33353 - atomic_set(&c->context_list_counter, 0);
33354 + atomic_set_unchecked(&c->context_list_counter, 0);
33355 INIT_LIST_HEAD(&c->context_list);
33356 #endif
33357
33358 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
33359 index 7ce65f4..e66e9bc 100644
33360 --- a/drivers/mfd/abx500-core.c
33361 +++ b/drivers/mfd/abx500-core.c
33362 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
33363
33364 struct abx500_device_entry {
33365 struct list_head list;
33366 - struct abx500_ops ops;
33367 + abx500_ops_no_const ops;
33368 struct device *dev;
33369 };
33370
33371 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
33372 index a9223ed..4127b13 100644
33373 --- a/drivers/mfd/janz-cmodio.c
33374 +++ b/drivers/mfd/janz-cmodio.c
33375 @@ -13,6 +13,7 @@
33376
33377 #include <linux/kernel.h>
33378 #include <linux/module.h>
33379 +#include <linux/slab.h>
33380 #include <linux/init.h>
33381 #include <linux/pci.h>
33382 #include <linux/interrupt.h>
33383 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
33384 index a981e2a..5ca0c8b 100644
33385 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
33386 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
33387 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
33388 * the lid is closed. This leads to interrupts as soon as a little move
33389 * is done.
33390 */
33391 - atomic_inc(&lis3->count);
33392 + atomic_inc_unchecked(&lis3->count);
33393
33394 wake_up_interruptible(&lis3->misc_wait);
33395 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
33396 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
33397 if (lis3->pm_dev)
33398 pm_runtime_get_sync(lis3->pm_dev);
33399
33400 - atomic_set(&lis3->count, 0);
33401 + atomic_set_unchecked(&lis3->count, 0);
33402 return 0;
33403 }
33404
33405 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
33406 add_wait_queue(&lis3->misc_wait, &wait);
33407 while (true) {
33408 set_current_state(TASK_INTERRUPTIBLE);
33409 - data = atomic_xchg(&lis3->count, 0);
33410 + data = atomic_xchg_unchecked(&lis3->count, 0);
33411 if (data)
33412 break;
33413
33414 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33415 struct lis3lv02d, miscdev);
33416
33417 poll_wait(file, &lis3->misc_wait, wait);
33418 - if (atomic_read(&lis3->count))
33419 + if (atomic_read_unchecked(&lis3->count))
33420 return POLLIN | POLLRDNORM;
33421 return 0;
33422 }
33423 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
33424 index 2b1482a..5d33616 100644
33425 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
33426 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
33427 @@ -266,7 +266,7 @@ struct lis3lv02d {
33428 struct input_polled_dev *idev; /* input device */
33429 struct platform_device *pdev; /* platform device */
33430 struct regulator_bulk_data regulators[2];
33431 - atomic_t count; /* interrupt count after last read */
33432 + atomic_unchecked_t count; /* interrupt count after last read */
33433 union axis_conversion ac; /* hw -> logical axis */
33434 int mapped_btns[3];
33435
33436 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
33437 index 2f30bad..c4c13d0 100644
33438 --- a/drivers/misc/sgi-gru/gruhandles.c
33439 +++ b/drivers/misc/sgi-gru/gruhandles.c
33440 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
33441 unsigned long nsec;
33442
33443 nsec = CLKS2NSEC(clks);
33444 - atomic_long_inc(&mcs_op_statistics[op].count);
33445 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
33446 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33447 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
33448 if (mcs_op_statistics[op].max < nsec)
33449 mcs_op_statistics[op].max = nsec;
33450 }
33451 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
33452 index 950dbe9..eeef0f8 100644
33453 --- a/drivers/misc/sgi-gru/gruprocfs.c
33454 +++ b/drivers/misc/sgi-gru/gruprocfs.c
33455 @@ -32,9 +32,9 @@
33456
33457 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33458
33459 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33460 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33461 {
33462 - unsigned long val = atomic_long_read(v);
33463 + unsigned long val = atomic_long_read_unchecked(v);
33464
33465 seq_printf(s, "%16lu %s\n", val, id);
33466 }
33467 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
33468
33469 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
33470 for (op = 0; op < mcsop_last; op++) {
33471 - count = atomic_long_read(&mcs_op_statistics[op].count);
33472 - total = atomic_long_read(&mcs_op_statistics[op].total);
33473 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33474 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33475 max = mcs_op_statistics[op].max;
33476 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33477 count ? total / count : 0, max);
33478 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
33479 index 5c3ce24..4915ccb 100644
33480 --- a/drivers/misc/sgi-gru/grutables.h
33481 +++ b/drivers/misc/sgi-gru/grutables.h
33482 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
33483 * GRU statistics.
33484 */
33485 struct gru_stats_s {
33486 - atomic_long_t vdata_alloc;
33487 - atomic_long_t vdata_free;
33488 - atomic_long_t gts_alloc;
33489 - atomic_long_t gts_free;
33490 - atomic_long_t gms_alloc;
33491 - atomic_long_t gms_free;
33492 - atomic_long_t gts_double_allocate;
33493 - atomic_long_t assign_context;
33494 - atomic_long_t assign_context_failed;
33495 - atomic_long_t free_context;
33496 - atomic_long_t load_user_context;
33497 - atomic_long_t load_kernel_context;
33498 - atomic_long_t lock_kernel_context;
33499 - atomic_long_t unlock_kernel_context;
33500 - atomic_long_t steal_user_context;
33501 - atomic_long_t steal_kernel_context;
33502 - atomic_long_t steal_context_failed;
33503 - atomic_long_t nopfn;
33504 - atomic_long_t asid_new;
33505 - atomic_long_t asid_next;
33506 - atomic_long_t asid_wrap;
33507 - atomic_long_t asid_reuse;
33508 - atomic_long_t intr;
33509 - atomic_long_t intr_cbr;
33510 - atomic_long_t intr_tfh;
33511 - atomic_long_t intr_spurious;
33512 - atomic_long_t intr_mm_lock_failed;
33513 - atomic_long_t call_os;
33514 - atomic_long_t call_os_wait_queue;
33515 - atomic_long_t user_flush_tlb;
33516 - atomic_long_t user_unload_context;
33517 - atomic_long_t user_exception;
33518 - atomic_long_t set_context_option;
33519 - atomic_long_t check_context_retarget_intr;
33520 - atomic_long_t check_context_unload;
33521 - atomic_long_t tlb_dropin;
33522 - atomic_long_t tlb_preload_page;
33523 - atomic_long_t tlb_dropin_fail_no_asid;
33524 - atomic_long_t tlb_dropin_fail_upm;
33525 - atomic_long_t tlb_dropin_fail_invalid;
33526 - atomic_long_t tlb_dropin_fail_range_active;
33527 - atomic_long_t tlb_dropin_fail_idle;
33528 - atomic_long_t tlb_dropin_fail_fmm;
33529 - atomic_long_t tlb_dropin_fail_no_exception;
33530 - atomic_long_t tfh_stale_on_fault;
33531 - atomic_long_t mmu_invalidate_range;
33532 - atomic_long_t mmu_invalidate_page;
33533 - atomic_long_t flush_tlb;
33534 - atomic_long_t flush_tlb_gru;
33535 - atomic_long_t flush_tlb_gru_tgh;
33536 - atomic_long_t flush_tlb_gru_zero_asid;
33537 + atomic_long_unchecked_t vdata_alloc;
33538 + atomic_long_unchecked_t vdata_free;
33539 + atomic_long_unchecked_t gts_alloc;
33540 + atomic_long_unchecked_t gts_free;
33541 + atomic_long_unchecked_t gms_alloc;
33542 + atomic_long_unchecked_t gms_free;
33543 + atomic_long_unchecked_t gts_double_allocate;
33544 + atomic_long_unchecked_t assign_context;
33545 + atomic_long_unchecked_t assign_context_failed;
33546 + atomic_long_unchecked_t free_context;
33547 + atomic_long_unchecked_t load_user_context;
33548 + atomic_long_unchecked_t load_kernel_context;
33549 + atomic_long_unchecked_t lock_kernel_context;
33550 + atomic_long_unchecked_t unlock_kernel_context;
33551 + atomic_long_unchecked_t steal_user_context;
33552 + atomic_long_unchecked_t steal_kernel_context;
33553 + atomic_long_unchecked_t steal_context_failed;
33554 + atomic_long_unchecked_t nopfn;
33555 + atomic_long_unchecked_t asid_new;
33556 + atomic_long_unchecked_t asid_next;
33557 + atomic_long_unchecked_t asid_wrap;
33558 + atomic_long_unchecked_t asid_reuse;
33559 + atomic_long_unchecked_t intr;
33560 + atomic_long_unchecked_t intr_cbr;
33561 + atomic_long_unchecked_t intr_tfh;
33562 + atomic_long_unchecked_t intr_spurious;
33563 + atomic_long_unchecked_t intr_mm_lock_failed;
33564 + atomic_long_unchecked_t call_os;
33565 + atomic_long_unchecked_t call_os_wait_queue;
33566 + atomic_long_unchecked_t user_flush_tlb;
33567 + atomic_long_unchecked_t user_unload_context;
33568 + atomic_long_unchecked_t user_exception;
33569 + atomic_long_unchecked_t set_context_option;
33570 + atomic_long_unchecked_t check_context_retarget_intr;
33571 + atomic_long_unchecked_t check_context_unload;
33572 + atomic_long_unchecked_t tlb_dropin;
33573 + atomic_long_unchecked_t tlb_preload_page;
33574 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33575 + atomic_long_unchecked_t tlb_dropin_fail_upm;
33576 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
33577 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
33578 + atomic_long_unchecked_t tlb_dropin_fail_idle;
33579 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
33580 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33581 + atomic_long_unchecked_t tfh_stale_on_fault;
33582 + atomic_long_unchecked_t mmu_invalidate_range;
33583 + atomic_long_unchecked_t mmu_invalidate_page;
33584 + atomic_long_unchecked_t flush_tlb;
33585 + atomic_long_unchecked_t flush_tlb_gru;
33586 + atomic_long_unchecked_t flush_tlb_gru_tgh;
33587 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33588
33589 - atomic_long_t copy_gpa;
33590 - atomic_long_t read_gpa;
33591 + atomic_long_unchecked_t copy_gpa;
33592 + atomic_long_unchecked_t read_gpa;
33593
33594 - atomic_long_t mesq_receive;
33595 - atomic_long_t mesq_receive_none;
33596 - atomic_long_t mesq_send;
33597 - atomic_long_t mesq_send_failed;
33598 - atomic_long_t mesq_noop;
33599 - atomic_long_t mesq_send_unexpected_error;
33600 - atomic_long_t mesq_send_lb_overflow;
33601 - atomic_long_t mesq_send_qlimit_reached;
33602 - atomic_long_t mesq_send_amo_nacked;
33603 - atomic_long_t mesq_send_put_nacked;
33604 - atomic_long_t mesq_page_overflow;
33605 - atomic_long_t mesq_qf_locked;
33606 - atomic_long_t mesq_qf_noop_not_full;
33607 - atomic_long_t mesq_qf_switch_head_failed;
33608 - atomic_long_t mesq_qf_unexpected_error;
33609 - atomic_long_t mesq_noop_unexpected_error;
33610 - atomic_long_t mesq_noop_lb_overflow;
33611 - atomic_long_t mesq_noop_qlimit_reached;
33612 - atomic_long_t mesq_noop_amo_nacked;
33613 - atomic_long_t mesq_noop_put_nacked;
33614 - atomic_long_t mesq_noop_page_overflow;
33615 + atomic_long_unchecked_t mesq_receive;
33616 + atomic_long_unchecked_t mesq_receive_none;
33617 + atomic_long_unchecked_t mesq_send;
33618 + atomic_long_unchecked_t mesq_send_failed;
33619 + atomic_long_unchecked_t mesq_noop;
33620 + atomic_long_unchecked_t mesq_send_unexpected_error;
33621 + atomic_long_unchecked_t mesq_send_lb_overflow;
33622 + atomic_long_unchecked_t mesq_send_qlimit_reached;
33623 + atomic_long_unchecked_t mesq_send_amo_nacked;
33624 + atomic_long_unchecked_t mesq_send_put_nacked;
33625 + atomic_long_unchecked_t mesq_page_overflow;
33626 + atomic_long_unchecked_t mesq_qf_locked;
33627 + atomic_long_unchecked_t mesq_qf_noop_not_full;
33628 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
33629 + atomic_long_unchecked_t mesq_qf_unexpected_error;
33630 + atomic_long_unchecked_t mesq_noop_unexpected_error;
33631 + atomic_long_unchecked_t mesq_noop_lb_overflow;
33632 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
33633 + atomic_long_unchecked_t mesq_noop_amo_nacked;
33634 + atomic_long_unchecked_t mesq_noop_put_nacked;
33635 + atomic_long_unchecked_t mesq_noop_page_overflow;
33636
33637 };
33638
33639 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
33640 tghop_invalidate, mcsop_last};
33641
33642 struct mcs_op_statistic {
33643 - atomic_long_t count;
33644 - atomic_long_t total;
33645 + atomic_long_unchecked_t count;
33646 + atomic_long_unchecked_t total;
33647 unsigned long max;
33648 };
33649
33650 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
33651
33652 #define STAT(id) do { \
33653 if (gru_options & OPT_STATS) \
33654 - atomic_long_inc(&gru_stats.id); \
33655 + atomic_long_inc_unchecked(&gru_stats.id); \
33656 } while (0)
33657
33658 #ifdef CONFIG_SGI_GRU_DEBUG
33659 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
33660 index 851b2f2..a4ec097 100644
33661 --- a/drivers/misc/sgi-xp/xp.h
33662 +++ b/drivers/misc/sgi-xp/xp.h
33663 @@ -289,7 +289,7 @@ struct xpc_interface {
33664 xpc_notify_func, void *);
33665 void (*received) (short, int, void *);
33666 enum xp_retval (*partid_to_nasids) (short, void *);
33667 -};
33668 +} __no_const;
33669
33670 extern struct xpc_interface xpc_interface;
33671
33672 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
33673 index b94d5f7..7f494c5 100644
33674 --- a/drivers/misc/sgi-xp/xpc.h
33675 +++ b/drivers/misc/sgi-xp/xpc.h
33676 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
33677 void (*received_payload) (struct xpc_channel *, void *);
33678 void (*notify_senders_of_disconnect) (struct xpc_channel *);
33679 };
33680 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
33681
33682 /* struct xpc_partition act_state values (for XPC HB) */
33683
33684 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
33685 /* found in xpc_main.c */
33686 extern struct device *xpc_part;
33687 extern struct device *xpc_chan;
33688 -extern struct xpc_arch_operations xpc_arch_ops;
33689 +extern xpc_arch_operations_no_const xpc_arch_ops;
33690 extern int xpc_disengage_timelimit;
33691 extern int xpc_disengage_timedout;
33692 extern int xpc_activate_IRQ_rcvd;
33693 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
33694 index 8d082b4..aa749ae 100644
33695 --- a/drivers/misc/sgi-xp/xpc_main.c
33696 +++ b/drivers/misc/sgi-xp/xpc_main.c
33697 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
33698 .notifier_call = xpc_system_die,
33699 };
33700
33701 -struct xpc_arch_operations xpc_arch_ops;
33702 +xpc_arch_operations_no_const xpc_arch_ops;
33703
33704 /*
33705 * Timer function to enforce the timelimit on the partition disengage.
33706 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
33707 index 6ebdc40..9edf5d8 100644
33708 --- a/drivers/mmc/host/sdhci-pci.c
33709 +++ b/drivers/mmc/host/sdhci-pci.c
33710 @@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
33711 .probe = via_probe,
33712 };
33713
33714 -static const struct pci_device_id pci_ids[] __devinitdata = {
33715 +static const struct pci_device_id pci_ids[] __devinitconst = {
33716 {
33717 .vendor = PCI_VENDOR_ID_RICOH,
33718 .device = PCI_DEVICE_ID_RICOH_R5C822,
33719 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
33720 index b1cdf64..ce6e438 100644
33721 --- a/drivers/mtd/devices/doc2000.c
33722 +++ b/drivers/mtd/devices/doc2000.c
33723 @@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
33724
33725 /* The ECC will not be calculated correctly if less than 512 is written */
33726 /* DBB-
33727 - if (len != 0x200 && eccbuf)
33728 + if (len != 0x200)
33729 printk(KERN_WARNING
33730 "ECC needs a full sector write (adr: %lx size %lx)\n",
33731 (long) to, (long) len);
33732 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
33733 index 7543b98..7069947 100644
33734 --- a/drivers/mtd/devices/doc2001.c
33735 +++ b/drivers/mtd/devices/doc2001.c
33736 @@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
33737 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
33738
33739 /* Don't allow read past end of device */
33740 - if (from >= this->totlen)
33741 + if (from >= this->totlen || !len)
33742 return -EINVAL;
33743
33744 /* Don't allow a single read to cross a 512-byte block boundary */
33745 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
33746 index 3984d48..28aa897 100644
33747 --- a/drivers/mtd/nand/denali.c
33748 +++ b/drivers/mtd/nand/denali.c
33749 @@ -26,6 +26,7 @@
33750 #include <linux/pci.h>
33751 #include <linux/mtd/mtd.h>
33752 #include <linux/module.h>
33753 +#include <linux/slab.h>
33754
33755 #include "denali.h"
33756
33757 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
33758 index 51b9d6a..52af9a7 100644
33759 --- a/drivers/mtd/nftlmount.c
33760 +++ b/drivers/mtd/nftlmount.c
33761 @@ -24,6 +24,7 @@
33762 #include <asm/errno.h>
33763 #include <linux/delay.h>
33764 #include <linux/slab.h>
33765 +#include <linux/sched.h>
33766 #include <linux/mtd/mtd.h>
33767 #include <linux/mtd/nand.h>
33768 #include <linux/mtd/nftl.h>
33769 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
33770 index 115749f..3021f01 100644
33771 --- a/drivers/mtd/ubi/build.c
33772 +++ b/drivers/mtd/ubi/build.c
33773 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
33774 static int __init bytes_str_to_int(const char *str)
33775 {
33776 char *endp;
33777 - unsigned long result;
33778 + unsigned long result, scale = 1;
33779
33780 result = simple_strtoul(str, &endp, 0);
33781 if (str == endp || result >= INT_MAX) {
33782 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
33783
33784 switch (*endp) {
33785 case 'G':
33786 - result *= 1024;
33787 + scale *= 1024;
33788 case 'M':
33789 - result *= 1024;
33790 + scale *= 1024;
33791 case 'K':
33792 - result *= 1024;
33793 + scale *= 1024;
33794 if (endp[1] == 'i' && endp[2] == 'B')
33795 endp += 2;
33796 case '\0':
33797 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
33798 return -EINVAL;
33799 }
33800
33801 - return result;
33802 + if ((intoverflow_t)result*scale >= INT_MAX) {
33803 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
33804 + str);
33805 + return -EINVAL;
33806 + }
33807 +
33808 + return result*scale;
33809 }
33810
33811 /**
33812 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
33813 index 071f4c8..440862e 100644
33814 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
33815 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
33816 @@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
33817 */
33818
33819 #define ATL2_PARAM(X, desc) \
33820 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33821 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33822 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
33823 MODULE_PARM_DESC(X, desc);
33824 #else
33825 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33826 index 66da39f..5dc436d 100644
33827 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33828 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33829 @@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
33830
33831 int (*wait_comp)(struct bnx2x *bp,
33832 struct bnx2x_rx_mode_ramrod_params *p);
33833 -};
33834 +} __no_const;
33835
33836 /********************** Set multicast group ***********************************/
33837
33838 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
33839 index aea8f72..fcebf75 100644
33840 --- a/drivers/net/ethernet/broadcom/tg3.h
33841 +++ b/drivers/net/ethernet/broadcom/tg3.h
33842 @@ -140,6 +140,7 @@
33843 #define CHIPREV_ID_5750_A0 0x4000
33844 #define CHIPREV_ID_5750_A1 0x4001
33845 #define CHIPREV_ID_5750_A3 0x4003
33846 +#define CHIPREV_ID_5750_C1 0x4201
33847 #define CHIPREV_ID_5750_C2 0x4202
33848 #define CHIPREV_ID_5752_A0_HW 0x5000
33849 #define CHIPREV_ID_5752_A0 0x6000
33850 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
33851 index c4e8643..0979484 100644
33852 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
33853 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
33854 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
33855 */
33856 struct l2t_skb_cb {
33857 arp_failure_handler_func arp_failure_handler;
33858 -};
33859 +} __no_const;
33860
33861 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
33862
33863 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
33864 index 4d71f5a..8004440 100644
33865 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
33866 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
33867 @@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
33868 for (i=0; i<ETH_ALEN; i++) {
33869 tmp.addr[i] = dev->dev_addr[i];
33870 }
33871 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
33872 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
33873 break;
33874
33875 case DE4X5_SET_HWADDR: /* Set the hardware address */
33876 @@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
33877 spin_lock_irqsave(&lp->lock, flags);
33878 memcpy(&statbuf, &lp->pktStats, ioc->len);
33879 spin_unlock_irqrestore(&lp->lock, flags);
33880 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
33881 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
33882 return -EFAULT;
33883 break;
33884 }
33885 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
33886 index 14d5b61..1398636 100644
33887 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
33888 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
33889 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
33890 {NULL}};
33891
33892
33893 -static const char *block_name[] __devinitdata = {
33894 +static const char *block_name[] __devinitconst = {
33895 "21140 non-MII",
33896 "21140 MII PHY",
33897 "21142 Serial PHY",
33898 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
33899 index 52da7b2..4ddfe1c 100644
33900 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
33901 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
33902 @@ -236,7 +236,7 @@ struct pci_id_info {
33903 int drv_flags; /* Driver use, intended as capability flags. */
33904 };
33905
33906 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
33907 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
33908 { /* Sometime a Level-One switch card. */
33909 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
33910 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
33911 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
33912 index 28a3a9b..d96cb63 100644
33913 --- a/drivers/net/ethernet/dlink/sundance.c
33914 +++ b/drivers/net/ethernet/dlink/sundance.c
33915 @@ -218,7 +218,7 @@ enum {
33916 struct pci_id_info {
33917 const char *name;
33918 };
33919 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
33920 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
33921 {"D-Link DFE-550TX FAST Ethernet Adapter"},
33922 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
33923 {"D-Link DFE-580TX 4 port Server Adapter"},
33924 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
33925 index e703d64..d62ecf9 100644
33926 --- a/drivers/net/ethernet/emulex/benet/be_main.c
33927 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
33928 @@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
33929
33930 if (wrapped)
33931 newacc += 65536;
33932 - ACCESS_ONCE(*acc) = newacc;
33933 + ACCESS_ONCE_RW(*acc) = newacc;
33934 }
33935
33936 void be_parse_stats(struct be_adapter *adapter)
33937 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
33938 index 47f85c3..82ab6c4 100644
33939 --- a/drivers/net/ethernet/faraday/ftgmac100.c
33940 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
33941 @@ -31,6 +31,8 @@
33942 #include <linux/netdevice.h>
33943 #include <linux/phy.h>
33944 #include <linux/platform_device.h>
33945 +#include <linux/interrupt.h>
33946 +#include <linux/irqreturn.h>
33947 #include <net/ip.h>
33948
33949 #include "ftgmac100.h"
33950 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
33951 index bb336a0..4b472da 100644
33952 --- a/drivers/net/ethernet/faraday/ftmac100.c
33953 +++ b/drivers/net/ethernet/faraday/ftmac100.c
33954 @@ -31,6 +31,8 @@
33955 #include <linux/module.h>
33956 #include <linux/netdevice.h>
33957 #include <linux/platform_device.h>
33958 +#include <linux/interrupt.h>
33959 +#include <linux/irqreturn.h>
33960
33961 #include "ftmac100.h"
33962
33963 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
33964 index c82d444..0007fb4 100644
33965 --- a/drivers/net/ethernet/fealnx.c
33966 +++ b/drivers/net/ethernet/fealnx.c
33967 @@ -150,7 +150,7 @@ struct chip_info {
33968 int flags;
33969 };
33970
33971 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
33972 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
33973 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33974 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
33975 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33976 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
33977 index e1159e5..e18684d 100644
33978 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
33979 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
33980 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
33981 {
33982 struct e1000_hw *hw = &adapter->hw;
33983 struct e1000_mac_info *mac = &hw->mac;
33984 - struct e1000_mac_operations *func = &mac->ops;
33985 + e1000_mac_operations_no_const *func = &mac->ops;
33986
33987 /* Set media type */
33988 switch (adapter->pdev->device) {
33989 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
33990 index a3e65fd..f451444 100644
33991 --- a/drivers/net/ethernet/intel/e1000e/82571.c
33992 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
33993 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
33994 {
33995 struct e1000_hw *hw = &adapter->hw;
33996 struct e1000_mac_info *mac = &hw->mac;
33997 - struct e1000_mac_operations *func = &mac->ops;
33998 + e1000_mac_operations_no_const *func = &mac->ops;
33999 u32 swsm = 0;
34000 u32 swsm2 = 0;
34001 bool force_clear_smbi = false;
34002 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34003 index 2967039..ca8c40c 100644
34004 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34005 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34006 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
34007 void (*write_vfta)(struct e1000_hw *, u32, u32);
34008 s32 (*read_mac_addr)(struct e1000_hw *);
34009 };
34010 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34011
34012 /*
34013 * When to use various PHY register access functions:
34014 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
34015 void (*power_up)(struct e1000_hw *);
34016 void (*power_down)(struct e1000_hw *);
34017 };
34018 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34019
34020 /* Function pointers for the NVM. */
34021 struct e1000_nvm_operations {
34022 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
34023 s32 (*validate)(struct e1000_hw *);
34024 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34025 };
34026 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34027
34028 struct e1000_mac_info {
34029 - struct e1000_mac_operations ops;
34030 + e1000_mac_operations_no_const ops;
34031 u8 addr[ETH_ALEN];
34032 u8 perm_addr[ETH_ALEN];
34033
34034 @@ -872,7 +875,7 @@ struct e1000_mac_info {
34035 };
34036
34037 struct e1000_phy_info {
34038 - struct e1000_phy_operations ops;
34039 + e1000_phy_operations_no_const ops;
34040
34041 enum e1000_phy_type type;
34042
34043 @@ -906,7 +909,7 @@ struct e1000_phy_info {
34044 };
34045
34046 struct e1000_nvm_info {
34047 - struct e1000_nvm_operations ops;
34048 + e1000_nvm_operations_no_const ops;
34049
34050 enum e1000_nvm_type type;
34051 enum e1000_nvm_override override;
34052 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34053 index f67cbd3..cef9e3d 100644
34054 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34055 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34056 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34057 s32 (*read_mac_addr)(struct e1000_hw *);
34058 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34059 };
34060 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34061
34062 struct e1000_phy_operations {
34063 s32 (*acquire)(struct e1000_hw *);
34064 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34065 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34066 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34067 };
34068 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34069
34070 struct e1000_nvm_operations {
34071 s32 (*acquire)(struct e1000_hw *);
34072 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34073 s32 (*update)(struct e1000_hw *);
34074 s32 (*validate)(struct e1000_hw *);
34075 };
34076 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34077
34078 struct e1000_info {
34079 s32 (*get_invariants)(struct e1000_hw *);
34080 @@ -350,7 +353,7 @@ struct e1000_info {
34081 extern const struct e1000_info e1000_82575_info;
34082
34083 struct e1000_mac_info {
34084 - struct e1000_mac_operations ops;
34085 + e1000_mac_operations_no_const ops;
34086
34087 u8 addr[6];
34088 u8 perm_addr[6];
34089 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34090 };
34091
34092 struct e1000_phy_info {
34093 - struct e1000_phy_operations ops;
34094 + e1000_phy_operations_no_const ops;
34095
34096 enum e1000_phy_type type;
34097
34098 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34099 };
34100
34101 struct e1000_nvm_info {
34102 - struct e1000_nvm_operations ops;
34103 + e1000_nvm_operations_no_const ops;
34104 enum e1000_nvm_type type;
34105 enum e1000_nvm_override override;
34106
34107 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34108 s32 (*check_for_ack)(struct e1000_hw *, u16);
34109 s32 (*check_for_rst)(struct e1000_hw *, u16);
34110 };
34111 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34112
34113 struct e1000_mbx_stats {
34114 u32 msgs_tx;
34115 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34116 };
34117
34118 struct e1000_mbx_info {
34119 - struct e1000_mbx_operations ops;
34120 + e1000_mbx_operations_no_const ops;
34121 struct e1000_mbx_stats stats;
34122 u32 timeout;
34123 u32 usec_delay;
34124 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34125 index 57db3c6..aa825fc 100644
34126 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34127 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34128 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34129 s32 (*read_mac_addr)(struct e1000_hw *);
34130 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34131 };
34132 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34133
34134 struct e1000_mac_info {
34135 - struct e1000_mac_operations ops;
34136 + e1000_mac_operations_no_const ops;
34137 u8 addr[6];
34138 u8 perm_addr[6];
34139
34140 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34141 s32 (*check_for_ack)(struct e1000_hw *);
34142 s32 (*check_for_rst)(struct e1000_hw *);
34143 };
34144 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34145
34146 struct e1000_mbx_stats {
34147 u32 msgs_tx;
34148 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34149 };
34150
34151 struct e1000_mbx_info {
34152 - struct e1000_mbx_operations ops;
34153 + e1000_mbx_operations_no_const ops;
34154 struct e1000_mbx_stats stats;
34155 u32 timeout;
34156 u32 usec_delay;
34157 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34158 index 9b95bef..7e254ee 100644
34159 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34160 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34161 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
34162 s32 (*update_checksum)(struct ixgbe_hw *);
34163 u16 (*calc_checksum)(struct ixgbe_hw *);
34164 };
34165 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34166
34167 struct ixgbe_mac_operations {
34168 s32 (*init_hw)(struct ixgbe_hw *);
34169 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
34170 /* Manageability interface */
34171 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
34172 };
34173 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34174
34175 struct ixgbe_phy_operations {
34176 s32 (*identify)(struct ixgbe_hw *);
34177 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
34178 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34179 s32 (*check_overtemp)(struct ixgbe_hw *);
34180 };
34181 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34182
34183 struct ixgbe_eeprom_info {
34184 - struct ixgbe_eeprom_operations ops;
34185 + ixgbe_eeprom_operations_no_const ops;
34186 enum ixgbe_eeprom_type type;
34187 u32 semaphore_delay;
34188 u16 word_size;
34189 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
34190
34191 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34192 struct ixgbe_mac_info {
34193 - struct ixgbe_mac_operations ops;
34194 + ixgbe_mac_operations_no_const ops;
34195 enum ixgbe_mac_type type;
34196 u8 addr[ETH_ALEN];
34197 u8 perm_addr[ETH_ALEN];
34198 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
34199 };
34200
34201 struct ixgbe_phy_info {
34202 - struct ixgbe_phy_operations ops;
34203 + ixgbe_phy_operations_no_const ops;
34204 struct mdio_if_info mdio;
34205 enum ixgbe_phy_type type;
34206 u32 id;
34207 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
34208 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34209 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34210 };
34211 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34212
34213 struct ixgbe_mbx_stats {
34214 u32 msgs_tx;
34215 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
34216 };
34217
34218 struct ixgbe_mbx_info {
34219 - struct ixgbe_mbx_operations ops;
34220 + ixgbe_mbx_operations_no_const ops;
34221 struct ixgbe_mbx_stats stats;
34222 u32 timeout;
34223 u32 usec_delay;
34224 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34225 index 25c951d..cc7cf33 100644
34226 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34227 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34228 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34229 s32 (*clear_vfta)(struct ixgbe_hw *);
34230 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34231 };
34232 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34233
34234 enum ixgbe_mac_type {
34235 ixgbe_mac_unknown = 0,
34236 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34237 };
34238
34239 struct ixgbe_mac_info {
34240 - struct ixgbe_mac_operations ops;
34241 + ixgbe_mac_operations_no_const ops;
34242 u8 addr[6];
34243 u8 perm_addr[6];
34244
34245 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34246 s32 (*check_for_ack)(struct ixgbe_hw *);
34247 s32 (*check_for_rst)(struct ixgbe_hw *);
34248 };
34249 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34250
34251 struct ixgbe_mbx_stats {
34252 u32 msgs_tx;
34253 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34254 };
34255
34256 struct ixgbe_mbx_info {
34257 - struct ixgbe_mbx_operations ops;
34258 + ixgbe_mbx_operations_no_const ops;
34259 struct ixgbe_mbx_stats stats;
34260 u32 timeout;
34261 u32 udelay;
34262 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34263 index 8bf22b6..7f5baaa 100644
34264 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
34265 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34266 @@ -41,6 +41,7 @@
34267 #include <linux/slab.h>
34268 #include <linux/io-mapping.h>
34269 #include <linux/delay.h>
34270 +#include <linux/sched.h>
34271
34272 #include <linux/mlx4/device.h>
34273 #include <linux/mlx4/doorbell.h>
34274 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34275 index 5046a64..71ca936 100644
34276 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34277 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34278 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34279 void (*link_down)(struct __vxge_hw_device *devh);
34280 void (*crit_err)(struct __vxge_hw_device *devh,
34281 enum vxge_hw_event type, u64 ext_data);
34282 -};
34283 +} __no_const;
34284
34285 /*
34286 * struct __vxge_hw_blockpool_entry - Block private data structure
34287 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34288 index 4a518a3..936b334 100644
34289 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34290 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34291 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34292 struct vxge_hw_mempool_dma *dma_object,
34293 u32 index,
34294 u32 is_last);
34295 -};
34296 +} __no_const;
34297
34298 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34299 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34300 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34301 index bbacb37..d60887d 100644
34302 --- a/drivers/net/ethernet/realtek/r8169.c
34303 +++ b/drivers/net/ethernet/realtek/r8169.c
34304 @@ -695,17 +695,17 @@ struct rtl8169_private {
34305 struct mdio_ops {
34306 void (*write)(void __iomem *, int, int);
34307 int (*read)(void __iomem *, int);
34308 - } mdio_ops;
34309 + } __no_const mdio_ops;
34310
34311 struct pll_power_ops {
34312 void (*down)(struct rtl8169_private *);
34313 void (*up)(struct rtl8169_private *);
34314 - } pll_power_ops;
34315 + } __no_const pll_power_ops;
34316
34317 struct jumbo_ops {
34318 void (*enable)(struct rtl8169_private *);
34319 void (*disable)(struct rtl8169_private *);
34320 - } jumbo_ops;
34321 + } __no_const jumbo_ops;
34322
34323 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34324 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34325 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
34326 index 5b118cd..858b523 100644
34327 --- a/drivers/net/ethernet/sis/sis190.c
34328 +++ b/drivers/net/ethernet/sis/sis190.c
34329 @@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34330 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34331 struct net_device *dev)
34332 {
34333 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34334 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34335 struct sis190_private *tp = netdev_priv(dev);
34336 struct pci_dev *isa_bridge;
34337 u8 reg, tmp8;
34338 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34339 index c07cfe9..81cbf7e 100644
34340 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34341 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34342 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
34343
34344 writel(value, ioaddr + MMC_CNTRL);
34345
34346 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34347 - MMC_CNTRL, value);
34348 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34349 +// MMC_CNTRL, value);
34350 }
34351
34352 /* To mask all all interrupts.*/
34353 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
34354 index dec5836..6d4db7d 100644
34355 --- a/drivers/net/hyperv/hyperv_net.h
34356 +++ b/drivers/net/hyperv/hyperv_net.h
34357 @@ -97,7 +97,7 @@ struct rndis_device {
34358
34359 enum rndis_device_state state;
34360 bool link_state;
34361 - atomic_t new_req_id;
34362 + atomic_unchecked_t new_req_id;
34363
34364 spinlock_t request_lock;
34365 struct list_head req_list;
34366 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
34367 index 133b7fb..d58c559 100644
34368 --- a/drivers/net/hyperv/rndis_filter.c
34369 +++ b/drivers/net/hyperv/rndis_filter.c
34370 @@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
34371 * template
34372 */
34373 set = &rndis_msg->msg.set_req;
34374 - set->req_id = atomic_inc_return(&dev->new_req_id);
34375 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
34376
34377 /* Add to the request list */
34378 spin_lock_irqsave(&dev->request_lock, flags);
34379 @@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
34380
34381 /* Setup the rndis set */
34382 halt = &request->request_msg.msg.halt_req;
34383 - halt->req_id = atomic_inc_return(&dev->new_req_id);
34384 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
34385
34386 /* Ignore return since this msg is optional. */
34387 rndis_filter_send_request(dev, request);
34388 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
34389 index 486b404..0d6677d 100644
34390 --- a/drivers/net/ppp/ppp_generic.c
34391 +++ b/drivers/net/ppp/ppp_generic.c
34392 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34393 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
34394 struct ppp_stats stats;
34395 struct ppp_comp_stats cstats;
34396 - char *vers;
34397
34398 switch (cmd) {
34399 case SIOCGPPPSTATS:
34400 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34401 break;
34402
34403 case SIOCGPPPVER:
34404 - vers = PPP_VERSION;
34405 - if (copy_to_user(addr, vers, strlen(vers) + 1))
34406 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
34407 break;
34408 err = 0;
34409 break;
34410 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
34411 index 515f122..41dd273 100644
34412 --- a/drivers/net/tokenring/abyss.c
34413 +++ b/drivers/net/tokenring/abyss.c
34414 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
34415
34416 static int __init abyss_init (void)
34417 {
34418 - abyss_netdev_ops = tms380tr_netdev_ops;
34419 + pax_open_kernel();
34420 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34421
34422 - abyss_netdev_ops.ndo_open = abyss_open;
34423 - abyss_netdev_ops.ndo_stop = abyss_close;
34424 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
34425 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
34426 + pax_close_kernel();
34427
34428 return pci_register_driver(&abyss_driver);
34429 }
34430 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
34431 index 6153cfd..cf69c1c 100644
34432 --- a/drivers/net/tokenring/madgemc.c
34433 +++ b/drivers/net/tokenring/madgemc.c
34434 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
34435
34436 static int __init madgemc_init (void)
34437 {
34438 - madgemc_netdev_ops = tms380tr_netdev_ops;
34439 - madgemc_netdev_ops.ndo_open = madgemc_open;
34440 - madgemc_netdev_ops.ndo_stop = madgemc_close;
34441 + pax_open_kernel();
34442 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34443 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
34444 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
34445 + pax_close_kernel();
34446
34447 return mca_register_driver (&madgemc_driver);
34448 }
34449 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
34450 index 8d362e6..f91cc52 100644
34451 --- a/drivers/net/tokenring/proteon.c
34452 +++ b/drivers/net/tokenring/proteon.c
34453 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
34454 struct platform_device *pdev;
34455 int i, num = 0, err = 0;
34456
34457 - proteon_netdev_ops = tms380tr_netdev_ops;
34458 - proteon_netdev_ops.ndo_open = proteon_open;
34459 - proteon_netdev_ops.ndo_stop = tms380tr_close;
34460 + pax_open_kernel();
34461 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34462 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
34463 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
34464 + pax_close_kernel();
34465
34466 err = platform_driver_register(&proteon_driver);
34467 if (err)
34468 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
34469 index 46db5c5..37c1536 100644
34470 --- a/drivers/net/tokenring/skisa.c
34471 +++ b/drivers/net/tokenring/skisa.c
34472 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
34473 struct platform_device *pdev;
34474 int i, num = 0, err = 0;
34475
34476 - sk_isa_netdev_ops = tms380tr_netdev_ops;
34477 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
34478 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34479 + pax_open_kernel();
34480 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34481 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
34482 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34483 + pax_close_kernel();
34484
34485 err = platform_driver_register(&sk_isa_driver);
34486 if (err)
34487 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
34488 index e1324b4..e1b0041 100644
34489 --- a/drivers/net/usb/hso.c
34490 +++ b/drivers/net/usb/hso.c
34491 @@ -71,7 +71,7 @@
34492 #include <asm/byteorder.h>
34493 #include <linux/serial_core.h>
34494 #include <linux/serial.h>
34495 -
34496 +#include <asm/local.h>
34497
34498 #define MOD_AUTHOR "Option Wireless"
34499 #define MOD_DESCRIPTION "USB High Speed Option driver"
34500 @@ -257,7 +257,7 @@ struct hso_serial {
34501
34502 /* from usb_serial_port */
34503 struct tty_struct *tty;
34504 - int open_count;
34505 + local_t open_count;
34506 spinlock_t serial_lock;
34507
34508 int (*write_data) (struct hso_serial *serial);
34509 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
34510 struct urb *urb;
34511
34512 urb = serial->rx_urb[0];
34513 - if (serial->open_count > 0) {
34514 + if (local_read(&serial->open_count) > 0) {
34515 count = put_rxbuf_data(urb, serial);
34516 if (count == -1)
34517 return;
34518 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
34519 DUMP1(urb->transfer_buffer, urb->actual_length);
34520
34521 /* Anyone listening? */
34522 - if (serial->open_count == 0)
34523 + if (local_read(&serial->open_count) == 0)
34524 return;
34525
34526 if (status == 0) {
34527 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34528 spin_unlock_irq(&serial->serial_lock);
34529
34530 /* check for port already opened, if not set the termios */
34531 - serial->open_count++;
34532 - if (serial->open_count == 1) {
34533 + if (local_inc_return(&serial->open_count) == 1) {
34534 serial->rx_state = RX_IDLE;
34535 /* Force default termio settings */
34536 _hso_serial_set_termios(tty, NULL);
34537 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34538 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
34539 if (result) {
34540 hso_stop_serial_device(serial->parent);
34541 - serial->open_count--;
34542 + local_dec(&serial->open_count);
34543 kref_put(&serial->parent->ref, hso_serial_ref_free);
34544 }
34545 } else {
34546 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
34547
34548 /* reset the rts and dtr */
34549 /* do the actual close */
34550 - serial->open_count--;
34551 + local_dec(&serial->open_count);
34552
34553 - if (serial->open_count <= 0) {
34554 - serial->open_count = 0;
34555 + if (local_read(&serial->open_count) <= 0) {
34556 + local_set(&serial->open_count, 0);
34557 spin_lock_irq(&serial->serial_lock);
34558 if (serial->tty == tty) {
34559 serial->tty->driver_data = NULL;
34560 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
34561
34562 /* the actual setup */
34563 spin_lock_irqsave(&serial->serial_lock, flags);
34564 - if (serial->open_count)
34565 + if (local_read(&serial->open_count))
34566 _hso_serial_set_termios(tty, old);
34567 else
34568 tty->termios = old;
34569 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
34570 D1("Pending read interrupt on port %d\n", i);
34571 spin_lock(&serial->serial_lock);
34572 if (serial->rx_state == RX_IDLE &&
34573 - serial->open_count > 0) {
34574 + local_read(&serial->open_count) > 0) {
34575 /* Setup and send a ctrl req read on
34576 * port i */
34577 if (!serial->rx_urb_filled[0]) {
34578 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
34579 /* Start all serial ports */
34580 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
34581 if (serial_table[i] && (serial_table[i]->interface == iface)) {
34582 - if (dev2ser(serial_table[i])->open_count) {
34583 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
34584 result =
34585 hso_start_serial_device(serial_table[i], GFP_NOIO);
34586 hso_kick_transmit(dev2ser(serial_table[i]));
34587 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
34588 index efc0111..79c8f5b 100644
34589 --- a/drivers/net/wireless/ath/ath.h
34590 +++ b/drivers/net/wireless/ath/ath.h
34591 @@ -119,6 +119,7 @@ struct ath_ops {
34592 void (*write_flush) (void *);
34593 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
34594 };
34595 +typedef struct ath_ops __no_const ath_ops_no_const;
34596
34597 struct ath_common;
34598 struct ath_bus_ops;
34599 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34600 index 7b6417b..ab5db98 100644
34601 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34602 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34603 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34604 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
34605 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
34606
34607 - ACCESS_ONCE(ads->ds_link) = i->link;
34608 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
34609 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
34610 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
34611
34612 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
34613 ctl6 = SM(i->keytype, AR_EncrType);
34614 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34615
34616 if ((i->is_first || i->is_last) &&
34617 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
34618 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
34619 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
34620 | set11nTries(i->rates, 1)
34621 | set11nTries(i->rates, 2)
34622 | set11nTries(i->rates, 3)
34623 | (i->dur_update ? AR_DurUpdateEna : 0)
34624 | SM(0, AR_BurstDur);
34625
34626 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
34627 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
34628 | set11nRate(i->rates, 1)
34629 | set11nRate(i->rates, 2)
34630 | set11nRate(i->rates, 3);
34631 } else {
34632 - ACCESS_ONCE(ads->ds_ctl2) = 0;
34633 - ACCESS_ONCE(ads->ds_ctl3) = 0;
34634 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
34635 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
34636 }
34637
34638 if (!i->is_first) {
34639 - ACCESS_ONCE(ads->ds_ctl0) = 0;
34640 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
34641 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
34642 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
34643 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
34644 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
34645 return;
34646 }
34647
34648 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34649 break;
34650 }
34651
34652 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
34653 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
34654 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
34655 | SM(i->txpower, AR_XmitPower)
34656 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
34657 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34658 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
34659 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
34660
34661 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
34662 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
34663 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
34664 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
34665
34666 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
34667 return;
34668
34669 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
34670 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
34671 | set11nPktDurRTSCTS(i->rates, 1);
34672
34673 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
34674 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
34675 | set11nPktDurRTSCTS(i->rates, 3);
34676
34677 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
34678 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
34679 | set11nRateFlags(i->rates, 1)
34680 | set11nRateFlags(i->rates, 2)
34681 | set11nRateFlags(i->rates, 3)
34682 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34683 index 09b8c9d..905339e 100644
34684 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34685 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34686 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34687 (i->qcu << AR_TxQcuNum_S) | 0x17;
34688
34689 checksum += val;
34690 - ACCESS_ONCE(ads->info) = val;
34691 + ACCESS_ONCE_RW(ads->info) = val;
34692
34693 checksum += i->link;
34694 - ACCESS_ONCE(ads->link) = i->link;
34695 + ACCESS_ONCE_RW(ads->link) = i->link;
34696
34697 checksum += i->buf_addr[0];
34698 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
34699 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
34700 checksum += i->buf_addr[1];
34701 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
34702 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
34703 checksum += i->buf_addr[2];
34704 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
34705 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
34706 checksum += i->buf_addr[3];
34707 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
34708 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
34709
34710 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
34711 - ACCESS_ONCE(ads->ctl3) = val;
34712 + ACCESS_ONCE_RW(ads->ctl3) = val;
34713 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
34714 - ACCESS_ONCE(ads->ctl5) = val;
34715 + ACCESS_ONCE_RW(ads->ctl5) = val;
34716 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
34717 - ACCESS_ONCE(ads->ctl7) = val;
34718 + ACCESS_ONCE_RW(ads->ctl7) = val;
34719 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
34720 - ACCESS_ONCE(ads->ctl9) = val;
34721 + ACCESS_ONCE_RW(ads->ctl9) = val;
34722
34723 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
34724 - ACCESS_ONCE(ads->ctl10) = checksum;
34725 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
34726
34727 if (i->is_first || i->is_last) {
34728 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
34729 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
34730 | set11nTries(i->rates, 1)
34731 | set11nTries(i->rates, 2)
34732 | set11nTries(i->rates, 3)
34733 | (i->dur_update ? AR_DurUpdateEna : 0)
34734 | SM(0, AR_BurstDur);
34735
34736 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
34737 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
34738 | set11nRate(i->rates, 1)
34739 | set11nRate(i->rates, 2)
34740 | set11nRate(i->rates, 3);
34741 } else {
34742 - ACCESS_ONCE(ads->ctl13) = 0;
34743 - ACCESS_ONCE(ads->ctl14) = 0;
34744 + ACCESS_ONCE_RW(ads->ctl13) = 0;
34745 + ACCESS_ONCE_RW(ads->ctl14) = 0;
34746 }
34747
34748 ads->ctl20 = 0;
34749 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34750
34751 ctl17 = SM(i->keytype, AR_EncrType);
34752 if (!i->is_first) {
34753 - ACCESS_ONCE(ads->ctl11) = 0;
34754 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
34755 - ACCESS_ONCE(ads->ctl15) = 0;
34756 - ACCESS_ONCE(ads->ctl16) = 0;
34757 - ACCESS_ONCE(ads->ctl17) = ctl17;
34758 - ACCESS_ONCE(ads->ctl18) = 0;
34759 - ACCESS_ONCE(ads->ctl19) = 0;
34760 + ACCESS_ONCE_RW(ads->ctl11) = 0;
34761 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
34762 + ACCESS_ONCE_RW(ads->ctl15) = 0;
34763 + ACCESS_ONCE_RW(ads->ctl16) = 0;
34764 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
34765 + ACCESS_ONCE_RW(ads->ctl18) = 0;
34766 + ACCESS_ONCE_RW(ads->ctl19) = 0;
34767 return;
34768 }
34769
34770 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
34771 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
34772 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
34773 | SM(i->txpower, AR_XmitPower)
34774 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
34775 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34776 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
34777 ctl12 |= SM(val, AR_PAPRDChainMask);
34778
34779 - ACCESS_ONCE(ads->ctl12) = ctl12;
34780 - ACCESS_ONCE(ads->ctl17) = ctl17;
34781 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
34782 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
34783
34784 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
34785 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
34786 | set11nPktDurRTSCTS(i->rates, 1);
34787
34788 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
34789 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
34790 | set11nPktDurRTSCTS(i->rates, 3);
34791
34792 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
34793 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
34794 | set11nRateFlags(i->rates, 1)
34795 | set11nRateFlags(i->rates, 2)
34796 | set11nRateFlags(i->rates, 3)
34797 | SM(i->rtscts_rate, AR_RTSCTSRate);
34798
34799 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
34800 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
34801 }
34802
34803 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
34804 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
34805 index c8261d4..8d88929 100644
34806 --- a/drivers/net/wireless/ath/ath9k/hw.h
34807 +++ b/drivers/net/wireless/ath/ath9k/hw.h
34808 @@ -773,7 +773,7 @@ struct ath_hw_private_ops {
34809
34810 /* ANI */
34811 void (*ani_cache_ini_regs)(struct ath_hw *ah);
34812 -};
34813 +} __no_const;
34814
34815 /**
34816 * struct ath_hw_ops - callbacks used by hardware code and driver code
34817 @@ -803,7 +803,7 @@ struct ath_hw_ops {
34818 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
34819 struct ath_hw_antcomb_conf *antconf);
34820
34821 -};
34822 +} __no_const;
34823
34824 struct ath_nf_limits {
34825 s16 max;
34826 @@ -823,7 +823,7 @@ enum ath_cal_list {
34827 #define AH_FASTCC 0x4
34828
34829 struct ath_hw {
34830 - struct ath_ops reg_ops;
34831 + ath_ops_no_const reg_ops;
34832
34833 struct ieee80211_hw *hw;
34834 struct ath_common common;
34835 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34836 index af00e2c..ab04d34 100644
34837 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34838 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34839 @@ -545,7 +545,7 @@ struct phy_func_ptr {
34840 void (*carrsuppr)(struct brcms_phy *);
34841 s32 (*rxsigpwr)(struct brcms_phy *, s32);
34842 void (*detach)(struct brcms_phy *);
34843 -};
34844 +} __no_const;
34845
34846 struct brcms_phy {
34847 struct brcms_phy_pub pubpi_ro;
34848 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
34849 index a7dfba8..e28eacd 100644
34850 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
34851 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
34852 @@ -3647,7 +3647,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
34853 */
34854 if (il3945_mod_params.disable_hw_scan) {
34855 D_INFO("Disabling hw_scan\n");
34856 - il3945_hw_ops.hw_scan = NULL;
34857 + pax_open_kernel();
34858 + *(void **)&il3945_hw_ops.hw_scan = NULL;
34859 + pax_close_kernel();
34860 }
34861
34862 D_INFO("*** LOAD DRIVER ***\n");
34863 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
34864 index f8fc239..8cade22 100644
34865 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
34866 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
34867 @@ -86,8 +86,8 @@ do { \
34868 } while (0)
34869
34870 #else
34871 -#define IWL_DEBUG(m, level, fmt, args...)
34872 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
34873 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
34874 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
34875 #define iwl_print_hex_dump(m, level, p, len)
34876 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
34877 do { \
34878 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
34879 index 4b9e730..7603659 100644
34880 --- a/drivers/net/wireless/mac80211_hwsim.c
34881 +++ b/drivers/net/wireless/mac80211_hwsim.c
34882 @@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
34883 return -EINVAL;
34884
34885 if (fake_hw_scan) {
34886 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
34887 - mac80211_hwsim_ops.sw_scan_start = NULL;
34888 - mac80211_hwsim_ops.sw_scan_complete = NULL;
34889 + pax_open_kernel();
34890 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
34891 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
34892 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
34893 + pax_close_kernel();
34894 }
34895
34896 spin_lock_init(&hwsim_radio_lock);
34897 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
34898 index 3186aa4..b35b09f 100644
34899 --- a/drivers/net/wireless/mwifiex/main.h
34900 +++ b/drivers/net/wireless/mwifiex/main.h
34901 @@ -536,7 +536,7 @@ struct mwifiex_if_ops {
34902 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
34903 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
34904 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
34905 -};
34906 +} __no_const;
34907
34908 struct mwifiex_adapter {
34909 u8 iface_type;
34910 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
34911 index a330c69..a81540f 100644
34912 --- a/drivers/net/wireless/rndis_wlan.c
34913 +++ b/drivers/net/wireless/rndis_wlan.c
34914 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
34915
34916 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
34917
34918 - if (rts_threshold < 0 || rts_threshold > 2347)
34919 + if (rts_threshold > 2347)
34920 rts_threshold = 2347;
34921
34922 tmp = cpu_to_le32(rts_threshold);
34923 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
34924 index a77f1bb..c608b2b 100644
34925 --- a/drivers/net/wireless/wl1251/wl1251.h
34926 +++ b/drivers/net/wireless/wl1251/wl1251.h
34927 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
34928 void (*reset)(struct wl1251 *wl);
34929 void (*enable_irq)(struct wl1251 *wl);
34930 void (*disable_irq)(struct wl1251 *wl);
34931 -};
34932 +} __no_const;
34933
34934 struct wl1251 {
34935 struct ieee80211_hw *hw;
34936 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
34937 index f34b5b2..b5abb9f 100644
34938 --- a/drivers/oprofile/buffer_sync.c
34939 +++ b/drivers/oprofile/buffer_sync.c
34940 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
34941 if (cookie == NO_COOKIE)
34942 offset = pc;
34943 if (cookie == INVALID_COOKIE) {
34944 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
34945 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
34946 offset = pc;
34947 }
34948 if (cookie != last_cookie) {
34949 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
34950 /* add userspace sample */
34951
34952 if (!mm) {
34953 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
34954 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
34955 return 0;
34956 }
34957
34958 cookie = lookup_dcookie(mm, s->eip, &offset);
34959
34960 if (cookie == INVALID_COOKIE) {
34961 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
34962 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
34963 return 0;
34964 }
34965
34966 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
34967 /* ignore backtraces if failed to add a sample */
34968 if (state == sb_bt_start) {
34969 state = sb_bt_ignore;
34970 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
34971 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
34972 }
34973 }
34974 release_mm(mm);
34975 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
34976 index c0cc4e7..44d4e54 100644
34977 --- a/drivers/oprofile/event_buffer.c
34978 +++ b/drivers/oprofile/event_buffer.c
34979 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
34980 }
34981
34982 if (buffer_pos == buffer_size) {
34983 - atomic_inc(&oprofile_stats.event_lost_overflow);
34984 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
34985 return;
34986 }
34987
34988 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
34989 index ed2c3ec..deda85a 100644
34990 --- a/drivers/oprofile/oprof.c
34991 +++ b/drivers/oprofile/oprof.c
34992 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
34993 if (oprofile_ops.switch_events())
34994 return;
34995
34996 - atomic_inc(&oprofile_stats.multiplex_counter);
34997 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
34998 start_switch_worker();
34999 }
35000
35001 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35002 index 917d28e..d62d981 100644
35003 --- a/drivers/oprofile/oprofile_stats.c
35004 +++ b/drivers/oprofile/oprofile_stats.c
35005 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35006 cpu_buf->sample_invalid_eip = 0;
35007 }
35008
35009 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35010 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35011 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35012 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35013 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35014 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35015 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35016 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35017 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35018 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35019 }
35020
35021
35022 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35023 index 38b6fc0..b5cbfce 100644
35024 --- a/drivers/oprofile/oprofile_stats.h
35025 +++ b/drivers/oprofile/oprofile_stats.h
35026 @@ -13,11 +13,11 @@
35027 #include <linux/atomic.h>
35028
35029 struct oprofile_stat_struct {
35030 - atomic_t sample_lost_no_mm;
35031 - atomic_t sample_lost_no_mapping;
35032 - atomic_t bt_lost_no_mapping;
35033 - atomic_t event_lost_overflow;
35034 - atomic_t multiplex_counter;
35035 + atomic_unchecked_t sample_lost_no_mm;
35036 + atomic_unchecked_t sample_lost_no_mapping;
35037 + atomic_unchecked_t bt_lost_no_mapping;
35038 + atomic_unchecked_t event_lost_overflow;
35039 + atomic_unchecked_t multiplex_counter;
35040 };
35041
35042 extern struct oprofile_stat_struct oprofile_stats;
35043 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35044 index 2f0aa0f..90fab02 100644
35045 --- a/drivers/oprofile/oprofilefs.c
35046 +++ b/drivers/oprofile/oprofilefs.c
35047 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
35048
35049
35050 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35051 - char const *name, atomic_t *val)
35052 + char const *name, atomic_unchecked_t *val)
35053 {
35054 return __oprofilefs_create_file(sb, root, name,
35055 &atomic_ro_fops, 0444, val);
35056 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35057 index 3f56bc0..707d642 100644
35058 --- a/drivers/parport/procfs.c
35059 +++ b/drivers/parport/procfs.c
35060 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35061
35062 *ppos += len;
35063
35064 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35065 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35066 }
35067
35068 #ifdef CONFIG_PARPORT_1284
35069 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35070
35071 *ppos += len;
35072
35073 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35074 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35075 }
35076 #endif /* IEEE1284.3 support. */
35077
35078 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35079 index 9fff878..ad0ad53 100644
35080 --- a/drivers/pci/hotplug/cpci_hotplug.h
35081 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35082 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35083 int (*hardware_test) (struct slot* slot, u32 value);
35084 u8 (*get_power) (struct slot* slot);
35085 int (*set_power) (struct slot* slot, int value);
35086 -};
35087 +} __no_const;
35088
35089 struct cpci_hp_controller {
35090 unsigned int irq;
35091 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35092 index 76ba8a1..20ca857 100644
35093 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35094 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35095 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35096
35097 void compaq_nvram_init (void __iomem *rom_start)
35098 {
35099 +
35100 +#ifndef CONFIG_PAX_KERNEXEC
35101 if (rom_start) {
35102 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35103 }
35104 +#endif
35105 +
35106 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35107
35108 /* initialize our int15 lock */
35109 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35110 index 2275162..95f1a92 100644
35111 --- a/drivers/pci/pcie/aspm.c
35112 +++ b/drivers/pci/pcie/aspm.c
35113 @@ -27,9 +27,9 @@
35114 #define MODULE_PARAM_PREFIX "pcie_aspm."
35115
35116 /* Note: those are not register definitions */
35117 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35118 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35119 -#define ASPM_STATE_L1 (4) /* L1 state */
35120 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35121 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35122 +#define ASPM_STATE_L1 (4U) /* L1 state */
35123 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35124 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35125
35126 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35127 index 71eac9c..2de27ef 100644
35128 --- a/drivers/pci/probe.c
35129 +++ b/drivers/pci/probe.c
35130 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35131 u32 l, sz, mask;
35132 u16 orig_cmd;
35133
35134 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35135 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35136
35137 if (!dev->mmio_always_on) {
35138 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35139 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35140 index 27911b5..5b6db88 100644
35141 --- a/drivers/pci/proc.c
35142 +++ b/drivers/pci/proc.c
35143 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35144 static int __init pci_proc_init(void)
35145 {
35146 struct pci_dev *dev = NULL;
35147 +
35148 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35149 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35150 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35151 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35152 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35153 +#endif
35154 +#else
35155 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35156 +#endif
35157 proc_create("devices", 0, proc_bus_pci_dir,
35158 &proc_bus_pci_dev_operations);
35159 proc_initialized = 1;
35160 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35161 index ea0c607..58c4628 100644
35162 --- a/drivers/platform/x86/thinkpad_acpi.c
35163 +++ b/drivers/platform/x86/thinkpad_acpi.c
35164 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35165 return 0;
35166 }
35167
35168 -void static hotkey_mask_warn_incomplete_mask(void)
35169 +static void hotkey_mask_warn_incomplete_mask(void)
35170 {
35171 /* log only what the user can fix... */
35172 const u32 wantedmask = hotkey_driver_mask &
35173 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35174 }
35175 }
35176
35177 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35178 - struct tp_nvram_state *newn,
35179 - const u32 event_mask)
35180 -{
35181 -
35182 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35183 do { \
35184 if ((event_mask & (1 << __scancode)) && \
35185 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35186 tpacpi_hotkey_send_key(__scancode); \
35187 } while (0)
35188
35189 - void issue_volchange(const unsigned int oldvol,
35190 - const unsigned int newvol)
35191 - {
35192 - unsigned int i = oldvol;
35193 +static void issue_volchange(const unsigned int oldvol,
35194 + const unsigned int newvol,
35195 + const u32 event_mask)
35196 +{
35197 + unsigned int i = oldvol;
35198
35199 - while (i > newvol) {
35200 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35201 - i--;
35202 - }
35203 - while (i < newvol) {
35204 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35205 - i++;
35206 - }
35207 + while (i > newvol) {
35208 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35209 + i--;
35210 }
35211 + while (i < newvol) {
35212 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35213 + i++;
35214 + }
35215 +}
35216
35217 - void issue_brightnesschange(const unsigned int oldbrt,
35218 - const unsigned int newbrt)
35219 - {
35220 - unsigned int i = oldbrt;
35221 +static void issue_brightnesschange(const unsigned int oldbrt,
35222 + const unsigned int newbrt,
35223 + const u32 event_mask)
35224 +{
35225 + unsigned int i = oldbrt;
35226
35227 - while (i > newbrt) {
35228 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35229 - i--;
35230 - }
35231 - while (i < newbrt) {
35232 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35233 - i++;
35234 - }
35235 + while (i > newbrt) {
35236 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35237 + i--;
35238 + }
35239 + while (i < newbrt) {
35240 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35241 + i++;
35242 }
35243 +}
35244
35245 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35246 + struct tp_nvram_state *newn,
35247 + const u32 event_mask)
35248 +{
35249 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35250 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35251 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35252 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35253 oldn->volume_level != newn->volume_level) {
35254 /* recently muted, or repeated mute keypress, or
35255 * multiple presses ending in mute */
35256 - issue_volchange(oldn->volume_level, newn->volume_level);
35257 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35258 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35259 }
35260 } else {
35261 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35262 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35263 }
35264 if (oldn->volume_level != newn->volume_level) {
35265 - issue_volchange(oldn->volume_level, newn->volume_level);
35266 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35267 } else if (oldn->volume_toggle != newn->volume_toggle) {
35268 /* repeated vol up/down keypress at end of scale ? */
35269 if (newn->volume_level == 0)
35270 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35271 /* handle brightness */
35272 if (oldn->brightness_level != newn->brightness_level) {
35273 issue_brightnesschange(oldn->brightness_level,
35274 - newn->brightness_level);
35275 + newn->brightness_level,
35276 + event_mask);
35277 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35278 /* repeated key presses that didn't change state */
35279 if (newn->brightness_level == 0)
35280 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35281 && !tp_features.bright_unkfw)
35282 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35283 }
35284 +}
35285
35286 #undef TPACPI_COMPARE_KEY
35287 #undef TPACPI_MAY_SEND_KEY
35288 -}
35289
35290 /*
35291 * Polling driver
35292 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35293 index b859d16..5cc6b1a 100644
35294 --- a/drivers/pnp/pnpbios/bioscalls.c
35295 +++ b/drivers/pnp/pnpbios/bioscalls.c
35296 @@ -59,7 +59,7 @@ do { \
35297 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35298 } while(0)
35299
35300 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35301 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35302 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35303
35304 /*
35305 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35306
35307 cpu = get_cpu();
35308 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35309 +
35310 + pax_open_kernel();
35311 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35312 + pax_close_kernel();
35313
35314 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35315 spin_lock_irqsave(&pnp_bios_lock, flags);
35316 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35317 :"memory");
35318 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35319
35320 + pax_open_kernel();
35321 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35322 + pax_close_kernel();
35323 +
35324 put_cpu();
35325
35326 /* If we get here and this is set then the PnP BIOS faulted on us. */
35327 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35328 return status;
35329 }
35330
35331 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
35332 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35333 {
35334 int i;
35335
35336 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35337 pnp_bios_callpoint.offset = header->fields.pm16offset;
35338 pnp_bios_callpoint.segment = PNP_CS16;
35339
35340 + pax_open_kernel();
35341 +
35342 for_each_possible_cpu(i) {
35343 struct desc_struct *gdt = get_cpu_gdt_table(i);
35344 if (!gdt)
35345 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35346 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35347 (unsigned long)__va(header->fields.pm16dseg));
35348 }
35349 +
35350 + pax_close_kernel();
35351 }
35352 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35353 index b0ecacb..7c9da2e 100644
35354 --- a/drivers/pnp/resource.c
35355 +++ b/drivers/pnp/resource.c
35356 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35357 return 1;
35358
35359 /* check if the resource is valid */
35360 - if (*irq < 0 || *irq > 15)
35361 + if (*irq > 15)
35362 return 0;
35363
35364 /* check if the resource is reserved */
35365 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35366 return 1;
35367
35368 /* check if the resource is valid */
35369 - if (*dma < 0 || *dma == 4 || *dma > 7)
35370 + if (*dma == 4 || *dma > 7)
35371 return 0;
35372
35373 /* check if the resource is reserved */
35374 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
35375 index 1ed6ea0..77c0bd2 100644
35376 --- a/drivers/power/bq27x00_battery.c
35377 +++ b/drivers/power/bq27x00_battery.c
35378 @@ -72,7 +72,7 @@
35379 struct bq27x00_device_info;
35380 struct bq27x00_access_methods {
35381 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
35382 -};
35383 +} __no_const;
35384
35385 enum bq27x00_chip { BQ27000, BQ27500 };
35386
35387 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
35388 index a838e66..a9e1665 100644
35389 --- a/drivers/regulator/max8660.c
35390 +++ b/drivers/regulator/max8660.c
35391 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
35392 max8660->shadow_regs[MAX8660_OVER1] = 5;
35393 } else {
35394 /* Otherwise devices can be toggled via software */
35395 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
35396 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
35397 + pax_open_kernel();
35398 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
35399 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
35400 + pax_close_kernel();
35401 }
35402
35403 /*
35404 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
35405 index e8cfc99..072aee2 100644
35406 --- a/drivers/regulator/mc13892-regulator.c
35407 +++ b/drivers/regulator/mc13892-regulator.c
35408 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
35409 }
35410 mc13xxx_unlock(mc13892);
35411
35412 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35413 + pax_open_kernel();
35414 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35415 = mc13892_vcam_set_mode;
35416 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35417 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35418 = mc13892_vcam_get_mode;
35419 + pax_close_kernel();
35420
35421 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
35422 ARRAY_SIZE(mc13892_regulators));
35423 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
35424 index cace6d3..f623fda 100644
35425 --- a/drivers/rtc/rtc-dev.c
35426 +++ b/drivers/rtc/rtc-dev.c
35427 @@ -14,6 +14,7 @@
35428 #include <linux/module.h>
35429 #include <linux/rtc.h>
35430 #include <linux/sched.h>
35431 +#include <linux/grsecurity.h>
35432 #include "rtc-core.h"
35433
35434 static dev_t rtc_devt;
35435 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
35436 if (copy_from_user(&tm, uarg, sizeof(tm)))
35437 return -EFAULT;
35438
35439 + gr_log_timechange();
35440 +
35441 return rtc_set_time(rtc, &tm);
35442
35443 case RTC_PIE_ON:
35444 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
35445 index ffb5878..e6d785c 100644
35446 --- a/drivers/scsi/aacraid/aacraid.h
35447 +++ b/drivers/scsi/aacraid/aacraid.h
35448 @@ -492,7 +492,7 @@ struct adapter_ops
35449 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
35450 /* Administrative operations */
35451 int (*adapter_comm)(struct aac_dev * dev, int comm);
35452 -};
35453 +} __no_const;
35454
35455 /*
35456 * Define which interrupt handler needs to be installed
35457 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
35458 index 705e13e..91c873c 100644
35459 --- a/drivers/scsi/aacraid/linit.c
35460 +++ b/drivers/scsi/aacraid/linit.c
35461 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
35462 #elif defined(__devinitconst)
35463 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35464 #else
35465 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
35466 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35467 #endif
35468 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
35469 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
35470 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
35471 index d5ff142..49c0ebb 100644
35472 --- a/drivers/scsi/aic94xx/aic94xx_init.c
35473 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
35474 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
35475 .lldd_control_phy = asd_control_phy,
35476 };
35477
35478 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
35479 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
35480 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
35481 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
35482 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
35483 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
35484 index a796de9..1ef20e1 100644
35485 --- a/drivers/scsi/bfa/bfa.h
35486 +++ b/drivers/scsi/bfa/bfa.h
35487 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
35488 u32 *end);
35489 int cpe_vec_q0;
35490 int rme_vec_q0;
35491 -};
35492 +} __no_const;
35493 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
35494
35495 struct bfa_faa_cbfn_s {
35496 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
35497 index f0f80e2..8ec946b 100644
35498 --- a/drivers/scsi/bfa/bfa_fcpim.c
35499 +++ b/drivers/scsi/bfa/bfa_fcpim.c
35500 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
35501
35502 bfa_iotag_attach(fcp);
35503
35504 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
35505 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
35506 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
35507 (fcp->num_itns * sizeof(struct bfa_itn_s));
35508 memset(fcp->itn_arr, 0,
35509 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35510 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
35511 {
35512 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
35513 - struct bfa_itn_s *itn;
35514 + bfa_itn_s_no_const *itn;
35515
35516 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
35517 itn->isr = isr;
35518 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
35519 index 36f26da..38a34a8 100644
35520 --- a/drivers/scsi/bfa/bfa_fcpim.h
35521 +++ b/drivers/scsi/bfa/bfa_fcpim.h
35522 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
35523 struct bfa_itn_s {
35524 bfa_isr_func_t isr;
35525 };
35526 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
35527
35528 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35529 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
35530 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
35531 struct list_head iotag_tio_free_q; /* free IO resources */
35532 struct list_head iotag_unused_q; /* unused IO resources*/
35533 struct bfa_iotag_s *iotag_arr;
35534 - struct bfa_itn_s *itn_arr;
35535 + bfa_itn_s_no_const *itn_arr;
35536 int num_ioim_reqs;
35537 int num_fwtio_reqs;
35538 int num_itns;
35539 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
35540 index 546d46b..642fa5b 100644
35541 --- a/drivers/scsi/bfa/bfa_ioc.h
35542 +++ b/drivers/scsi/bfa/bfa_ioc.h
35543 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
35544 bfa_ioc_disable_cbfn_t disable_cbfn;
35545 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
35546 bfa_ioc_reset_cbfn_t reset_cbfn;
35547 -};
35548 +} __no_const;
35549
35550 /*
35551 * IOC event notification mechanism.
35552 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
35553 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
35554 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
35555 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
35556 -};
35557 +} __no_const;
35558
35559 /*
35560 * Queue element to wait for room in request queue. FIFO order is
35561 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
35562 index 351dc0b..951dc32 100644
35563 --- a/drivers/scsi/hosts.c
35564 +++ b/drivers/scsi/hosts.c
35565 @@ -42,7 +42,7 @@
35566 #include "scsi_logging.h"
35567
35568
35569 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
35570 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
35571
35572
35573 static void scsi_host_cls_release(struct device *dev)
35574 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
35575 * subtract one because we increment first then return, but we need to
35576 * know what the next host number was before increment
35577 */
35578 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
35579 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
35580 shost->dma_channel = 0xff;
35581
35582 /* These three are default values which can be overridden */
35583 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
35584 index b96962c..0c82ec2 100644
35585 --- a/drivers/scsi/hpsa.c
35586 +++ b/drivers/scsi/hpsa.c
35587 @@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
35588 u32 a;
35589
35590 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35591 - return h->access.command_completed(h);
35592 + return h->access->command_completed(h);
35593
35594 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
35595 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
35596 @@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
35597 while (!list_empty(&h->reqQ)) {
35598 c = list_entry(h->reqQ.next, struct CommandList, list);
35599 /* can't do anything if fifo is full */
35600 - if ((h->access.fifo_full(h))) {
35601 + if ((h->access->fifo_full(h))) {
35602 dev_warn(&h->pdev->dev, "fifo full\n");
35603 break;
35604 }
35605 @@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
35606 h->Qdepth--;
35607
35608 /* Tell the controller execute command */
35609 - h->access.submit_command(h, c);
35610 + h->access->submit_command(h, c);
35611
35612 /* Put job onto the completed Q */
35613 addQ(&h->cmpQ, c);
35614 @@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
35615
35616 static inline unsigned long get_next_completion(struct ctlr_info *h)
35617 {
35618 - return h->access.command_completed(h);
35619 + return h->access->command_completed(h);
35620 }
35621
35622 static inline bool interrupt_pending(struct ctlr_info *h)
35623 {
35624 - return h->access.intr_pending(h);
35625 + return h->access->intr_pending(h);
35626 }
35627
35628 static inline long interrupt_not_for_us(struct ctlr_info *h)
35629 {
35630 - return (h->access.intr_pending(h) == 0) ||
35631 + return (h->access->intr_pending(h) == 0) ||
35632 (h->interrupts_enabled == 0);
35633 }
35634
35635 @@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
35636 if (prod_index < 0)
35637 return -ENODEV;
35638 h->product_name = products[prod_index].product_name;
35639 - h->access = *(products[prod_index].access);
35640 + h->access = products[prod_index].access;
35641
35642 if (hpsa_board_disabled(h->pdev)) {
35643 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
35644 @@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
35645
35646 assert_spin_locked(&lockup_detector_lock);
35647 remove_ctlr_from_lockup_detector_list(h);
35648 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35649 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35650 spin_lock_irqsave(&h->lock, flags);
35651 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
35652 spin_unlock_irqrestore(&h->lock, flags);
35653 @@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
35654 }
35655
35656 /* make sure the board interrupts are off */
35657 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35658 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35659
35660 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
35661 goto clean2;
35662 @@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
35663 * fake ones to scoop up any residual completions.
35664 */
35665 spin_lock_irqsave(&h->lock, flags);
35666 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35667 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35668 spin_unlock_irqrestore(&h->lock, flags);
35669 free_irq(h->intr[h->intr_mode], h);
35670 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
35671 @@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
35672 dev_info(&h->pdev->dev, "Board READY.\n");
35673 dev_info(&h->pdev->dev,
35674 "Waiting for stale completions to drain.\n");
35675 - h->access.set_intr_mask(h, HPSA_INTR_ON);
35676 + h->access->set_intr_mask(h, HPSA_INTR_ON);
35677 msleep(10000);
35678 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35679 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35680
35681 rc = controller_reset_failed(h->cfgtable);
35682 if (rc)
35683 @@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
35684 }
35685
35686 /* Turn the interrupts on so we can service requests */
35687 - h->access.set_intr_mask(h, HPSA_INTR_ON);
35688 + h->access->set_intr_mask(h, HPSA_INTR_ON);
35689
35690 hpsa_hba_inquiry(h);
35691 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
35692 @@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
35693 * To write all data in the battery backed cache to disks
35694 */
35695 hpsa_flush_cache(h);
35696 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35697 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35698 free_irq(h->intr[h->intr_mode], h);
35699 #ifdef CONFIG_PCI_MSI
35700 if (h->msix_vector)
35701 @@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
35702 return;
35703 }
35704 /* Change the access methods to the performant access methods */
35705 - h->access = SA5_performant_access;
35706 + h->access = &SA5_performant_access;
35707 h->transMethod = CFGTBL_Trans_Performant;
35708 }
35709
35710 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
35711 index 91edafb..a9b88ec 100644
35712 --- a/drivers/scsi/hpsa.h
35713 +++ b/drivers/scsi/hpsa.h
35714 @@ -73,7 +73,7 @@ struct ctlr_info {
35715 unsigned int msix_vector;
35716 unsigned int msi_vector;
35717 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
35718 - struct access_method access;
35719 + struct access_method *access;
35720
35721 /* queue and queue Info */
35722 struct list_head reqQ;
35723 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
35724 index f2df059..a3a9930 100644
35725 --- a/drivers/scsi/ips.h
35726 +++ b/drivers/scsi/ips.h
35727 @@ -1027,7 +1027,7 @@ typedef struct {
35728 int (*intr)(struct ips_ha *);
35729 void (*enableint)(struct ips_ha *);
35730 uint32_t (*statupd)(struct ips_ha *);
35731 -} ips_hw_func_t;
35732 +} __no_const ips_hw_func_t;
35733
35734 typedef struct ips_ha {
35735 uint8_t ha_id[IPS_MAX_CHANNELS+1];
35736 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
35737 index 4d70d96..84d0573 100644
35738 --- a/drivers/scsi/libfc/fc_exch.c
35739 +++ b/drivers/scsi/libfc/fc_exch.c
35740 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
35741 * all together if not used XXX
35742 */
35743 struct {
35744 - atomic_t no_free_exch;
35745 - atomic_t no_free_exch_xid;
35746 - atomic_t xid_not_found;
35747 - atomic_t xid_busy;
35748 - atomic_t seq_not_found;
35749 - atomic_t non_bls_resp;
35750 + atomic_unchecked_t no_free_exch;
35751 + atomic_unchecked_t no_free_exch_xid;
35752 + atomic_unchecked_t xid_not_found;
35753 + atomic_unchecked_t xid_busy;
35754 + atomic_unchecked_t seq_not_found;
35755 + atomic_unchecked_t non_bls_resp;
35756 } stats;
35757 };
35758
35759 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
35760 /* allocate memory for exchange */
35761 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
35762 if (!ep) {
35763 - atomic_inc(&mp->stats.no_free_exch);
35764 + atomic_inc_unchecked(&mp->stats.no_free_exch);
35765 goto out;
35766 }
35767 memset(ep, 0, sizeof(*ep));
35768 @@ -780,7 +780,7 @@ out:
35769 return ep;
35770 err:
35771 spin_unlock_bh(&pool->lock);
35772 - atomic_inc(&mp->stats.no_free_exch_xid);
35773 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
35774 mempool_free(ep, mp->ep_pool);
35775 return NULL;
35776 }
35777 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35778 xid = ntohs(fh->fh_ox_id); /* we originated exch */
35779 ep = fc_exch_find(mp, xid);
35780 if (!ep) {
35781 - atomic_inc(&mp->stats.xid_not_found);
35782 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35783 reject = FC_RJT_OX_ID;
35784 goto out;
35785 }
35786 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35787 ep = fc_exch_find(mp, xid);
35788 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
35789 if (ep) {
35790 - atomic_inc(&mp->stats.xid_busy);
35791 + atomic_inc_unchecked(&mp->stats.xid_busy);
35792 reject = FC_RJT_RX_ID;
35793 goto rel;
35794 }
35795 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35796 }
35797 xid = ep->xid; /* get our XID */
35798 } else if (!ep) {
35799 - atomic_inc(&mp->stats.xid_not_found);
35800 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35801 reject = FC_RJT_RX_ID; /* XID not found */
35802 goto out;
35803 }
35804 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35805 } else {
35806 sp = &ep->seq;
35807 if (sp->id != fh->fh_seq_id) {
35808 - atomic_inc(&mp->stats.seq_not_found);
35809 + atomic_inc_unchecked(&mp->stats.seq_not_found);
35810 if (f_ctl & FC_FC_END_SEQ) {
35811 /*
35812 * Update sequence_id based on incoming last
35813 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35814
35815 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
35816 if (!ep) {
35817 - atomic_inc(&mp->stats.xid_not_found);
35818 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35819 goto out;
35820 }
35821 if (ep->esb_stat & ESB_ST_COMPLETE) {
35822 - atomic_inc(&mp->stats.xid_not_found);
35823 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35824 goto rel;
35825 }
35826 if (ep->rxid == FC_XID_UNKNOWN)
35827 ep->rxid = ntohs(fh->fh_rx_id);
35828 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
35829 - atomic_inc(&mp->stats.xid_not_found);
35830 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35831 goto rel;
35832 }
35833 if (ep->did != ntoh24(fh->fh_s_id) &&
35834 ep->did != FC_FID_FLOGI) {
35835 - atomic_inc(&mp->stats.xid_not_found);
35836 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35837 goto rel;
35838 }
35839 sof = fr_sof(fp);
35840 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35841 sp->ssb_stat |= SSB_ST_RESP;
35842 sp->id = fh->fh_seq_id;
35843 } else if (sp->id != fh->fh_seq_id) {
35844 - atomic_inc(&mp->stats.seq_not_found);
35845 + atomic_inc_unchecked(&mp->stats.seq_not_found);
35846 goto rel;
35847 }
35848
35849 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35850 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
35851
35852 if (!sp)
35853 - atomic_inc(&mp->stats.xid_not_found);
35854 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35855 else
35856 - atomic_inc(&mp->stats.non_bls_resp);
35857 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
35858
35859 fc_frame_free(fp);
35860 }
35861 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
35862 index db9238f..4378ed2 100644
35863 --- a/drivers/scsi/libsas/sas_ata.c
35864 +++ b/drivers/scsi/libsas/sas_ata.c
35865 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
35866 .postreset = ata_std_postreset,
35867 .error_handler = ata_std_error_handler,
35868 .post_internal_cmd = sas_ata_post_internal,
35869 - .qc_defer = ata_std_qc_defer,
35870 + .qc_defer = ata_std_qc_defer,
35871 .qc_prep = ata_noop_qc_prep,
35872 .qc_issue = sas_ata_qc_issue,
35873 .qc_fill_rtf = sas_ata_qc_fill_rtf,
35874 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
35875 index 825f930..ce42672 100644
35876 --- a/drivers/scsi/lpfc/lpfc.h
35877 +++ b/drivers/scsi/lpfc/lpfc.h
35878 @@ -413,7 +413,7 @@ struct lpfc_vport {
35879 struct dentry *debug_nodelist;
35880 struct dentry *vport_debugfs_root;
35881 struct lpfc_debugfs_trc *disc_trc;
35882 - atomic_t disc_trc_cnt;
35883 + atomic_unchecked_t disc_trc_cnt;
35884 #endif
35885 uint8_t stat_data_enabled;
35886 uint8_t stat_data_blocked;
35887 @@ -821,8 +821,8 @@ struct lpfc_hba {
35888 struct timer_list fabric_block_timer;
35889 unsigned long bit_flags;
35890 #define FABRIC_COMANDS_BLOCKED 0
35891 - atomic_t num_rsrc_err;
35892 - atomic_t num_cmd_success;
35893 + atomic_unchecked_t num_rsrc_err;
35894 + atomic_unchecked_t num_cmd_success;
35895 unsigned long last_rsrc_error_time;
35896 unsigned long last_ramp_down_time;
35897 unsigned long last_ramp_up_time;
35898 @@ -852,7 +852,7 @@ struct lpfc_hba {
35899
35900 struct dentry *debug_slow_ring_trc;
35901 struct lpfc_debugfs_trc *slow_ring_trc;
35902 - atomic_t slow_ring_trc_cnt;
35903 + atomic_unchecked_t slow_ring_trc_cnt;
35904 /* iDiag debugfs sub-directory */
35905 struct dentry *idiag_root;
35906 struct dentry *idiag_pci_cfg;
35907 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
35908 index 3587a3f..d45b81b 100644
35909 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
35910 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
35911 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
35912
35913 #include <linux/debugfs.h>
35914
35915 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
35916 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
35917 static unsigned long lpfc_debugfs_start_time = 0L;
35918
35919 /* iDiag */
35920 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
35921 lpfc_debugfs_enable = 0;
35922
35923 len = 0;
35924 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
35925 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
35926 (lpfc_debugfs_max_disc_trc - 1);
35927 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
35928 dtp = vport->disc_trc + i;
35929 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
35930 lpfc_debugfs_enable = 0;
35931
35932 len = 0;
35933 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
35934 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
35935 (lpfc_debugfs_max_slow_ring_trc - 1);
35936 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
35937 dtp = phba->slow_ring_trc + i;
35938 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
35939 !vport || !vport->disc_trc)
35940 return;
35941
35942 - index = atomic_inc_return(&vport->disc_trc_cnt) &
35943 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
35944 (lpfc_debugfs_max_disc_trc - 1);
35945 dtp = vport->disc_trc + index;
35946 dtp->fmt = fmt;
35947 dtp->data1 = data1;
35948 dtp->data2 = data2;
35949 dtp->data3 = data3;
35950 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
35951 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
35952 dtp->jif = jiffies;
35953 #endif
35954 return;
35955 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
35956 !phba || !phba->slow_ring_trc)
35957 return;
35958
35959 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
35960 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
35961 (lpfc_debugfs_max_slow_ring_trc - 1);
35962 dtp = phba->slow_ring_trc + index;
35963 dtp->fmt = fmt;
35964 dtp->data1 = data1;
35965 dtp->data2 = data2;
35966 dtp->data3 = data3;
35967 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
35968 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
35969 dtp->jif = jiffies;
35970 #endif
35971 return;
35972 @@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
35973 "slow_ring buffer\n");
35974 goto debug_failed;
35975 }
35976 - atomic_set(&phba->slow_ring_trc_cnt, 0);
35977 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
35978 memset(phba->slow_ring_trc, 0,
35979 (sizeof(struct lpfc_debugfs_trc) *
35980 lpfc_debugfs_max_slow_ring_trc));
35981 @@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
35982 "buffer\n");
35983 goto debug_failed;
35984 }
35985 - atomic_set(&vport->disc_trc_cnt, 0);
35986 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
35987
35988 snprintf(name, sizeof(name), "discovery_trace");
35989 vport->debug_disc_trc =
35990 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
35991 index dfea2da..8e17227 100644
35992 --- a/drivers/scsi/lpfc/lpfc_init.c
35993 +++ b/drivers/scsi/lpfc/lpfc_init.c
35994 @@ -10145,8 +10145,10 @@ lpfc_init(void)
35995 printk(LPFC_COPYRIGHT "\n");
35996
35997 if (lpfc_enable_npiv) {
35998 - lpfc_transport_functions.vport_create = lpfc_vport_create;
35999 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36000 + pax_open_kernel();
36001 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36002 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36003 + pax_close_kernel();
36004 }
36005 lpfc_transport_template =
36006 fc_attach_transport(&lpfc_transport_functions);
36007 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36008 index c60f5d0..751535c 100644
36009 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36010 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36011 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36012 uint32_t evt_posted;
36013
36014 spin_lock_irqsave(&phba->hbalock, flags);
36015 - atomic_inc(&phba->num_rsrc_err);
36016 + atomic_inc_unchecked(&phba->num_rsrc_err);
36017 phba->last_rsrc_error_time = jiffies;
36018
36019 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36020 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36021 unsigned long flags;
36022 struct lpfc_hba *phba = vport->phba;
36023 uint32_t evt_posted;
36024 - atomic_inc(&phba->num_cmd_success);
36025 + atomic_inc_unchecked(&phba->num_cmd_success);
36026
36027 if (vport->cfg_lun_queue_depth <= queue_depth)
36028 return;
36029 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36030 unsigned long num_rsrc_err, num_cmd_success;
36031 int i;
36032
36033 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36034 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36035 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36036 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36037
36038 vports = lpfc_create_vport_work_array(phba);
36039 if (vports != NULL)
36040 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36041 }
36042 }
36043 lpfc_destroy_vport_work_array(phba, vports);
36044 - atomic_set(&phba->num_rsrc_err, 0);
36045 - atomic_set(&phba->num_cmd_success, 0);
36046 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36047 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36048 }
36049
36050 /**
36051 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36052 }
36053 }
36054 lpfc_destroy_vport_work_array(phba, vports);
36055 - atomic_set(&phba->num_rsrc_err, 0);
36056 - atomic_set(&phba->num_cmd_success, 0);
36057 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36058 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36059 }
36060
36061 /**
36062 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36063 index ea8a0b4..812a124 100644
36064 --- a/drivers/scsi/pmcraid.c
36065 +++ b/drivers/scsi/pmcraid.c
36066 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36067 res->scsi_dev = scsi_dev;
36068 scsi_dev->hostdata = res;
36069 res->change_detected = 0;
36070 - atomic_set(&res->read_failures, 0);
36071 - atomic_set(&res->write_failures, 0);
36072 + atomic_set_unchecked(&res->read_failures, 0);
36073 + atomic_set_unchecked(&res->write_failures, 0);
36074 rc = 0;
36075 }
36076 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36077 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36078
36079 /* If this was a SCSI read/write command keep count of errors */
36080 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36081 - atomic_inc(&res->read_failures);
36082 + atomic_inc_unchecked(&res->read_failures);
36083 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36084 - atomic_inc(&res->write_failures);
36085 + atomic_inc_unchecked(&res->write_failures);
36086
36087 if (!RES_IS_GSCSI(res->cfg_entry) &&
36088 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36089 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36090 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36091 * hrrq_id assigned here in queuecommand
36092 */
36093 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36094 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36095 pinstance->num_hrrq;
36096 cmd->cmd_done = pmcraid_io_done;
36097
36098 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36099 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36100 * hrrq_id assigned here in queuecommand
36101 */
36102 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36103 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36104 pinstance->num_hrrq;
36105
36106 if (request_size) {
36107 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36108
36109 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36110 /* add resources only after host is added into system */
36111 - if (!atomic_read(&pinstance->expose_resources))
36112 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36113 return;
36114
36115 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36116 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36117 init_waitqueue_head(&pinstance->reset_wait_q);
36118
36119 atomic_set(&pinstance->outstanding_cmds, 0);
36120 - atomic_set(&pinstance->last_message_id, 0);
36121 - atomic_set(&pinstance->expose_resources, 0);
36122 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36123 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36124
36125 INIT_LIST_HEAD(&pinstance->free_res_q);
36126 INIT_LIST_HEAD(&pinstance->used_res_q);
36127 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36128 /* Schedule worker thread to handle CCN and take care of adding and
36129 * removing devices to OS
36130 */
36131 - atomic_set(&pinstance->expose_resources, 1);
36132 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36133 schedule_work(&pinstance->worker_q);
36134 return rc;
36135
36136 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36137 index ca496c7..9c791d5 100644
36138 --- a/drivers/scsi/pmcraid.h
36139 +++ b/drivers/scsi/pmcraid.h
36140 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36141 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36142
36143 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36144 - atomic_t last_message_id;
36145 + atomic_unchecked_t last_message_id;
36146
36147 /* configuration table */
36148 struct pmcraid_config_table *cfg_table;
36149 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36150 atomic_t outstanding_cmds;
36151
36152 /* should add/delete resources to mid-layer now ?*/
36153 - atomic_t expose_resources;
36154 + atomic_unchecked_t expose_resources;
36155
36156
36157
36158 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36159 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36160 };
36161 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36162 - atomic_t read_failures; /* count of failed READ commands */
36163 - atomic_t write_failures; /* count of failed WRITE commands */
36164 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36165 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36166
36167 /* To indicate add/delete/modify during CCN */
36168 u8 change_detected;
36169 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36170 index af1003f..be55a75 100644
36171 --- a/drivers/scsi/qla2xxx/qla_def.h
36172 +++ b/drivers/scsi/qla2xxx/qla_def.h
36173 @@ -2247,7 +2247,7 @@ struct isp_operations {
36174 int (*start_scsi) (srb_t *);
36175 int (*abort_isp) (struct scsi_qla_host *);
36176 int (*iospace_config)(struct qla_hw_data*);
36177 -};
36178 +} __no_const;
36179
36180 /* MSI-X Support *************************************************************/
36181
36182 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36183 index bfe6854..ceac088 100644
36184 --- a/drivers/scsi/qla4xxx/ql4_def.h
36185 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36186 @@ -261,7 +261,7 @@ struct ddb_entry {
36187 * (4000 only) */
36188 atomic_t relogin_timer; /* Max Time to wait for
36189 * relogin to complete */
36190 - atomic_t relogin_retry_count; /* Num of times relogin has been
36191 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36192 * retried */
36193 uint32_t default_time2wait; /* Default Min time between
36194 * relogins (+aens) */
36195 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36196 index ce6d3b7..73fac54 100644
36197 --- a/drivers/scsi/qla4xxx/ql4_os.c
36198 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36199 @@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36200 */
36201 if (!iscsi_is_session_online(cls_sess)) {
36202 /* Reset retry relogin timer */
36203 - atomic_inc(&ddb_entry->relogin_retry_count);
36204 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36205 DEBUG2(ql4_printk(KERN_INFO, ha,
36206 "%s: index[%d] relogin timed out-retrying"
36207 " relogin (%d), retry (%d)\n", __func__,
36208 ddb_entry->fw_ddb_index,
36209 - atomic_read(&ddb_entry->relogin_retry_count),
36210 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36211 ddb_entry->default_time2wait + 4));
36212 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36213 atomic_set(&ddb_entry->retry_relogin_timer,
36214 @@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36215
36216 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36217 atomic_set(&ddb_entry->relogin_timer, 0);
36218 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36219 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36220 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36221 ddb_entry->default_relogin_timeout =
36222 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36223 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36224 index 2aeb2e9..46e3925 100644
36225 --- a/drivers/scsi/scsi.c
36226 +++ b/drivers/scsi/scsi.c
36227 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36228 unsigned long timeout;
36229 int rtn = 0;
36230
36231 - atomic_inc(&cmd->device->iorequest_cnt);
36232 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36233
36234 /* check if the device is still usable */
36235 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36236 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36237 index b2c95db..227d74e 100644
36238 --- a/drivers/scsi/scsi_lib.c
36239 +++ b/drivers/scsi/scsi_lib.c
36240 @@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36241 shost = sdev->host;
36242 scsi_init_cmd_errh(cmd);
36243 cmd->result = DID_NO_CONNECT << 16;
36244 - atomic_inc(&cmd->device->iorequest_cnt);
36245 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36246
36247 /*
36248 * SCSI request completion path will do scsi_device_unbusy(),
36249 @@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
36250
36251 INIT_LIST_HEAD(&cmd->eh_entry);
36252
36253 - atomic_inc(&cmd->device->iodone_cnt);
36254 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36255 if (cmd->result)
36256 - atomic_inc(&cmd->device->ioerr_cnt);
36257 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36258
36259 disposition = scsi_decide_disposition(cmd);
36260 if (disposition != SUCCESS &&
36261 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36262 index 04c2a27..9d8bd66 100644
36263 --- a/drivers/scsi/scsi_sysfs.c
36264 +++ b/drivers/scsi/scsi_sysfs.c
36265 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36266 char *buf) \
36267 { \
36268 struct scsi_device *sdev = to_scsi_device(dev); \
36269 - unsigned long long count = atomic_read(&sdev->field); \
36270 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36271 return snprintf(buf, 20, "0x%llx\n", count); \
36272 } \
36273 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36274 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36275 index 84a1fdf..693b0d6 100644
36276 --- a/drivers/scsi/scsi_tgt_lib.c
36277 +++ b/drivers/scsi/scsi_tgt_lib.c
36278 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36279 int err;
36280
36281 dprintk("%lx %u\n", uaddr, len);
36282 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36283 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36284 if (err) {
36285 /*
36286 * TODO: need to fixup sg_tablesize, max_segment_size,
36287 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36288 index f59d4a0..1d89407 100644
36289 --- a/drivers/scsi/scsi_transport_fc.c
36290 +++ b/drivers/scsi/scsi_transport_fc.c
36291 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36292 * Netlink Infrastructure
36293 */
36294
36295 -static atomic_t fc_event_seq;
36296 +static atomic_unchecked_t fc_event_seq;
36297
36298 /**
36299 * fc_get_event_number - Obtain the next sequential FC event number
36300 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
36301 u32
36302 fc_get_event_number(void)
36303 {
36304 - return atomic_add_return(1, &fc_event_seq);
36305 + return atomic_add_return_unchecked(1, &fc_event_seq);
36306 }
36307 EXPORT_SYMBOL(fc_get_event_number);
36308
36309 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
36310 {
36311 int error;
36312
36313 - atomic_set(&fc_event_seq, 0);
36314 + atomic_set_unchecked(&fc_event_seq, 0);
36315
36316 error = transport_class_register(&fc_host_class);
36317 if (error)
36318 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36319 char *cp;
36320
36321 *val = simple_strtoul(buf, &cp, 0);
36322 - if ((*cp && (*cp != '\n')) || (*val < 0))
36323 + if (*cp && (*cp != '\n'))
36324 return -EINVAL;
36325 /*
36326 * Check for overflow; dev_loss_tmo is u32
36327 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36328 index e3e3c7d..ebdab62 100644
36329 --- a/drivers/scsi/scsi_transport_iscsi.c
36330 +++ b/drivers/scsi/scsi_transport_iscsi.c
36331 @@ -79,7 +79,7 @@ struct iscsi_internal {
36332 struct transport_container session_cont;
36333 };
36334
36335 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
36336 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
36337 static struct workqueue_struct *iscsi_eh_timer_workq;
36338
36339 static DEFINE_IDA(iscsi_sess_ida);
36340 @@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
36341 int err;
36342
36343 ihost = shost->shost_data;
36344 - session->sid = atomic_add_return(1, &iscsi_session_nr);
36345 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
36346
36347 if (target_id == ISCSI_MAX_TARGET) {
36348 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
36349 @@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
36350 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
36351 ISCSI_TRANSPORT_VERSION);
36352
36353 - atomic_set(&iscsi_session_nr, 0);
36354 + atomic_set_unchecked(&iscsi_session_nr, 0);
36355
36356 err = class_register(&iscsi_transport_class);
36357 if (err)
36358 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
36359 index 21a045e..ec89e03 100644
36360 --- a/drivers/scsi/scsi_transport_srp.c
36361 +++ b/drivers/scsi/scsi_transport_srp.c
36362 @@ -33,7 +33,7 @@
36363 #include "scsi_transport_srp_internal.h"
36364
36365 struct srp_host_attrs {
36366 - atomic_t next_port_id;
36367 + atomic_unchecked_t next_port_id;
36368 };
36369 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
36370
36371 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
36372 struct Scsi_Host *shost = dev_to_shost(dev);
36373 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
36374
36375 - atomic_set(&srp_host->next_port_id, 0);
36376 + atomic_set_unchecked(&srp_host->next_port_id, 0);
36377 return 0;
36378 }
36379
36380 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
36381 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
36382 rport->roles = ids->roles;
36383
36384 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
36385 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
36386 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
36387
36388 transport_setup_device(&rport->dev);
36389 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
36390 index eacd46b..e3f4d62 100644
36391 --- a/drivers/scsi/sg.c
36392 +++ b/drivers/scsi/sg.c
36393 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
36394 sdp->disk->disk_name,
36395 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
36396 NULL,
36397 - (char *)arg);
36398 + (char __user *)arg);
36399 case BLKTRACESTART:
36400 return blk_trace_startstop(sdp->device->request_queue, 1);
36401 case BLKTRACESTOP:
36402 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
36403 const struct file_operations * fops;
36404 };
36405
36406 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
36407 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
36408 {"allow_dio", &adio_fops},
36409 {"debug", &debug_fops},
36410 {"def_reserved_size", &dressz_fops},
36411 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
36412 if (!sg_proc_sgp)
36413 return 1;
36414 for (k = 0; k < num_leaves; ++k) {
36415 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
36416 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
36417 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
36418 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
36419 }
36420 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
36421 index f64250e..1ee3049 100644
36422 --- a/drivers/spi/spi-dw-pci.c
36423 +++ b/drivers/spi/spi-dw-pci.c
36424 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
36425 #define spi_resume NULL
36426 #endif
36427
36428 -static const struct pci_device_id pci_ids[] __devinitdata = {
36429 +static const struct pci_device_id pci_ids[] __devinitconst = {
36430 /* Intel MID platform SPI controller 0 */
36431 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
36432 {},
36433 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
36434 index b2ccdea..84cde75 100644
36435 --- a/drivers/spi/spi.c
36436 +++ b/drivers/spi/spi.c
36437 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
36438 EXPORT_SYMBOL_GPL(spi_bus_unlock);
36439
36440 /* portable code must never pass more than 32 bytes */
36441 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
36442 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
36443
36444 static u8 *buf;
36445
36446 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
36447 index 400df8c..065d4f4 100644
36448 --- a/drivers/staging/octeon/ethernet-rx.c
36449 +++ b/drivers/staging/octeon/ethernet-rx.c
36450 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
36451 /* Increment RX stats for virtual ports */
36452 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
36453 #ifdef CONFIG_64BIT
36454 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
36455 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
36456 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
36457 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
36458 #else
36459 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
36460 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
36461 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
36462 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
36463 #endif
36464 }
36465 netif_receive_skb(skb);
36466 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
36467 dev->name);
36468 */
36469 #ifdef CONFIG_64BIT
36470 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
36471 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
36472 #else
36473 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
36474 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
36475 #endif
36476 dev_kfree_skb_irq(skb);
36477 }
36478 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
36479 index 9112cd8..92f8d51 100644
36480 --- a/drivers/staging/octeon/ethernet.c
36481 +++ b/drivers/staging/octeon/ethernet.c
36482 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
36483 * since the RX tasklet also increments it.
36484 */
36485 #ifdef CONFIG_64BIT
36486 - atomic64_add(rx_status.dropped_packets,
36487 - (atomic64_t *)&priv->stats.rx_dropped);
36488 + atomic64_add_unchecked(rx_status.dropped_packets,
36489 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
36490 #else
36491 - atomic_add(rx_status.dropped_packets,
36492 - (atomic_t *)&priv->stats.rx_dropped);
36493 + atomic_add_unchecked(rx_status.dropped_packets,
36494 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
36495 #endif
36496 }
36497
36498 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
36499 index 86308a0..feaa925 100644
36500 --- a/drivers/staging/rtl8712/rtl871x_io.h
36501 +++ b/drivers/staging/rtl8712/rtl871x_io.h
36502 @@ -108,7 +108,7 @@ struct _io_ops {
36503 u8 *pmem);
36504 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
36505 u8 *pmem);
36506 -};
36507 +} __no_const;
36508
36509 struct io_req {
36510 struct list_head list;
36511 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
36512 index c7b5e8b..783d6cb 100644
36513 --- a/drivers/staging/sbe-2t3e3/netdev.c
36514 +++ b/drivers/staging/sbe-2t3e3/netdev.c
36515 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36516 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
36517
36518 if (rlen)
36519 - if (copy_to_user(data, &resp, rlen))
36520 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
36521 return -EFAULT;
36522
36523 return 0;
36524 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
36525 index 42cdafe..2769103 100644
36526 --- a/drivers/staging/speakup/speakup_soft.c
36527 +++ b/drivers/staging/speakup/speakup_soft.c
36528 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
36529 break;
36530 } else if (!initialized) {
36531 if (*init) {
36532 - ch = *init;
36533 init++;
36534 } else {
36535 initialized = 1;
36536 }
36537 + ch = *init;
36538 } else {
36539 ch = synth_buffer_getc();
36540 }
36541 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
36542 index b8f8c48..1fc5025 100644
36543 --- a/drivers/staging/usbip/usbip_common.h
36544 +++ b/drivers/staging/usbip/usbip_common.h
36545 @@ -289,7 +289,7 @@ struct usbip_device {
36546 void (*shutdown)(struct usbip_device *);
36547 void (*reset)(struct usbip_device *);
36548 void (*unusable)(struct usbip_device *);
36549 - } eh_ops;
36550 + } __no_const eh_ops;
36551 };
36552
36553 /* usbip_common.c */
36554 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
36555 index 88b3298..3783eee 100644
36556 --- a/drivers/staging/usbip/vhci.h
36557 +++ b/drivers/staging/usbip/vhci.h
36558 @@ -88,7 +88,7 @@ struct vhci_hcd {
36559 unsigned resuming:1;
36560 unsigned long re_timeout;
36561
36562 - atomic_t seqnum;
36563 + atomic_unchecked_t seqnum;
36564
36565 /*
36566 * NOTE:
36567 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
36568 index 2ee97e2..0420b86 100644
36569 --- a/drivers/staging/usbip/vhci_hcd.c
36570 +++ b/drivers/staging/usbip/vhci_hcd.c
36571 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
36572 return;
36573 }
36574
36575 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
36576 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
36577 if (priv->seqnum == 0xffff)
36578 dev_info(&urb->dev->dev, "seqnum max\n");
36579
36580 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
36581 return -ENOMEM;
36582 }
36583
36584 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
36585 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
36586 if (unlink->seqnum == 0xffff)
36587 pr_info("seqnum max\n");
36588
36589 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
36590 vdev->rhport = rhport;
36591 }
36592
36593 - atomic_set(&vhci->seqnum, 0);
36594 + atomic_set_unchecked(&vhci->seqnum, 0);
36595 spin_lock_init(&vhci->lock);
36596
36597 hcd->power_budget = 0; /* no limit */
36598 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
36599 index 3f511b4..d3dbc1e 100644
36600 --- a/drivers/staging/usbip/vhci_rx.c
36601 +++ b/drivers/staging/usbip/vhci_rx.c
36602 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
36603 if (!urb) {
36604 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
36605 pr_info("max seqnum %d\n",
36606 - atomic_read(&the_controller->seqnum));
36607 + atomic_read_unchecked(&the_controller->seqnum));
36608 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
36609 return;
36610 }
36611 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
36612 index 7735027..30eed13 100644
36613 --- a/drivers/staging/vt6655/hostap.c
36614 +++ b/drivers/staging/vt6655/hostap.c
36615 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
36616 *
36617 */
36618
36619 +static net_device_ops_no_const apdev_netdev_ops;
36620 +
36621 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36622 {
36623 PSDevice apdev_priv;
36624 struct net_device *dev = pDevice->dev;
36625 int ret;
36626 - const struct net_device_ops apdev_netdev_ops = {
36627 - .ndo_start_xmit = pDevice->tx_80211,
36628 - };
36629
36630 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
36631
36632 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36633 *apdev_priv = *pDevice;
36634 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
36635
36636 + /* only half broken now */
36637 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
36638 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
36639
36640 pDevice->apdev->type = ARPHRD_IEEE80211;
36641 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
36642 index 51b5adf..098e320 100644
36643 --- a/drivers/staging/vt6656/hostap.c
36644 +++ b/drivers/staging/vt6656/hostap.c
36645 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
36646 *
36647 */
36648
36649 +static net_device_ops_no_const apdev_netdev_ops;
36650 +
36651 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36652 {
36653 PSDevice apdev_priv;
36654 struct net_device *dev = pDevice->dev;
36655 int ret;
36656 - const struct net_device_ops apdev_netdev_ops = {
36657 - .ndo_start_xmit = pDevice->tx_80211,
36658 - };
36659
36660 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
36661
36662 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36663 *apdev_priv = *pDevice;
36664 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
36665
36666 + /* only half broken now */
36667 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
36668 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
36669
36670 pDevice->apdev->type = ARPHRD_IEEE80211;
36671 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
36672 index 7843dfd..3db105f 100644
36673 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
36674 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
36675 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
36676
36677 struct usbctlx_completor {
36678 int (*complete) (struct usbctlx_completor *);
36679 -};
36680 +} __no_const;
36681
36682 static int
36683 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
36684 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
36685 index 1ca66ea..76f1343 100644
36686 --- a/drivers/staging/zcache/tmem.c
36687 +++ b/drivers/staging/zcache/tmem.c
36688 @@ -39,7 +39,7 @@
36689 * A tmem host implementation must use this function to register callbacks
36690 * for memory allocation.
36691 */
36692 -static struct tmem_hostops tmem_hostops;
36693 +static tmem_hostops_no_const tmem_hostops;
36694
36695 static void tmem_objnode_tree_init(void);
36696
36697 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
36698 * A tmem host implementation must use this function to register
36699 * callbacks for a page-accessible memory (PAM) implementation
36700 */
36701 -static struct tmem_pamops tmem_pamops;
36702 +static tmem_pamops_no_const tmem_pamops;
36703
36704 void tmem_register_pamops(struct tmem_pamops *m)
36705 {
36706 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
36707 index ed147c4..94fc3c6 100644
36708 --- a/drivers/staging/zcache/tmem.h
36709 +++ b/drivers/staging/zcache/tmem.h
36710 @@ -180,6 +180,7 @@ struct tmem_pamops {
36711 void (*new_obj)(struct tmem_obj *);
36712 int (*replace_in_obj)(void *, struct tmem_obj *);
36713 };
36714 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
36715 extern void tmem_register_pamops(struct tmem_pamops *m);
36716
36717 /* memory allocation methods provided by the host implementation */
36718 @@ -189,6 +190,7 @@ struct tmem_hostops {
36719 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
36720 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
36721 };
36722 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
36723 extern void tmem_register_hostops(struct tmem_hostops *m);
36724
36725 /* core tmem accessor functions */
36726 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
36727 index 97c74ee..7f6d77d 100644
36728 --- a/drivers/target/iscsi/iscsi_target.c
36729 +++ b/drivers/target/iscsi/iscsi_target.c
36730 @@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
36731 * outstanding_r2ts reaches zero, go ahead and send the delayed
36732 * TASK_ABORTED status.
36733 */
36734 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
36735 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
36736 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
36737 if (--cmd->outstanding_r2ts < 1) {
36738 iscsit_stop_dataout_timer(cmd);
36739 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
36740 index dcb0618..97e3d85 100644
36741 --- a/drivers/target/target_core_tmr.c
36742 +++ b/drivers/target/target_core_tmr.c
36743 @@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
36744 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
36745 cmd->t_task_list_num,
36746 atomic_read(&cmd->t_task_cdbs_left),
36747 - atomic_read(&cmd->t_task_cdbs_sent),
36748 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
36749 atomic_read(&cmd->t_transport_active),
36750 atomic_read(&cmd->t_transport_stop),
36751 atomic_read(&cmd->t_transport_sent));
36752 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
36753 pr_debug("LUN_RESET: got t_transport_active = 1 for"
36754 " task: %p, t_fe_count: %d dev: %p\n", task,
36755 fe_count, dev);
36756 - atomic_set(&cmd->t_transport_aborted, 1);
36757 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
36758 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36759
36760 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
36761 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
36762 }
36763 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
36764 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
36765 - atomic_set(&cmd->t_transport_aborted, 1);
36766 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
36767 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36768
36769 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
36770 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
36771 index cd5cd95..5249d30 100644
36772 --- a/drivers/target/target_core_transport.c
36773 +++ b/drivers/target/target_core_transport.c
36774 @@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
36775 spin_lock_init(&dev->se_port_lock);
36776 spin_lock_init(&dev->se_tmr_lock);
36777 spin_lock_init(&dev->qf_cmd_lock);
36778 - atomic_set(&dev->dev_ordered_id, 0);
36779 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
36780
36781 se_dev_set_default_attribs(dev, dev_limits);
36782
36783 @@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
36784 * Used to determine when ORDERED commands should go from
36785 * Dormant to Active status.
36786 */
36787 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
36788 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
36789 smp_mb__after_atomic_inc();
36790 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
36791 cmd->se_ordered_id, cmd->sam_task_attr,
36792 @@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
36793 " t_transport_active: %d t_transport_stop: %d"
36794 " t_transport_sent: %d\n", cmd->t_task_list_num,
36795 atomic_read(&cmd->t_task_cdbs_left),
36796 - atomic_read(&cmd->t_task_cdbs_sent),
36797 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
36798 atomic_read(&cmd->t_task_cdbs_ex_left),
36799 atomic_read(&cmd->t_transport_active),
36800 atomic_read(&cmd->t_transport_stop),
36801 @@ -2121,9 +2121,9 @@ check_depth:
36802 cmd = task->task_se_cmd;
36803 spin_lock_irqsave(&cmd->t_state_lock, flags);
36804 task->task_flags |= (TF_ACTIVE | TF_SENT);
36805 - atomic_inc(&cmd->t_task_cdbs_sent);
36806 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
36807
36808 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
36809 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
36810 cmd->t_task_list_num)
36811 atomic_set(&cmd->t_transport_sent, 1);
36812
36813 @@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
36814 atomic_set(&cmd->transport_lun_stop, 0);
36815 }
36816 if (!atomic_read(&cmd->t_transport_active) ||
36817 - atomic_read(&cmd->t_transport_aborted)) {
36818 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
36819 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36820 return false;
36821 }
36822 @@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
36823 {
36824 int ret = 0;
36825
36826 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
36827 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
36828 if (!send_status ||
36829 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
36830 return 1;
36831 @@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
36832 */
36833 if (cmd->data_direction == DMA_TO_DEVICE) {
36834 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
36835 - atomic_inc(&cmd->t_transport_aborted);
36836 + atomic_inc_unchecked(&cmd->t_transport_aborted);
36837 smp_mb__after_atomic_inc();
36838 }
36839 }
36840 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
36841 index b9040be..e3f5aab 100644
36842 --- a/drivers/tty/hvc/hvcs.c
36843 +++ b/drivers/tty/hvc/hvcs.c
36844 @@ -83,6 +83,7 @@
36845 #include <asm/hvcserver.h>
36846 #include <asm/uaccess.h>
36847 #include <asm/vio.h>
36848 +#include <asm/local.h>
36849
36850 /*
36851 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
36852 @@ -270,7 +271,7 @@ struct hvcs_struct {
36853 unsigned int index;
36854
36855 struct tty_struct *tty;
36856 - int open_count;
36857 + local_t open_count;
36858
36859 /*
36860 * Used to tell the driver kernel_thread what operations need to take
36861 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
36862
36863 spin_lock_irqsave(&hvcsd->lock, flags);
36864
36865 - if (hvcsd->open_count > 0) {
36866 + if (local_read(&hvcsd->open_count) > 0) {
36867 spin_unlock_irqrestore(&hvcsd->lock, flags);
36868 printk(KERN_INFO "HVCS: vterm state unchanged. "
36869 "The hvcs device node is still in use.\n");
36870 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
36871 if ((retval = hvcs_partner_connect(hvcsd)))
36872 goto error_release;
36873
36874 - hvcsd->open_count = 1;
36875 + local_set(&hvcsd->open_count, 1);
36876 hvcsd->tty = tty;
36877 tty->driver_data = hvcsd;
36878
36879 @@ -1179,7 +1180,7 @@ fast_open:
36880
36881 spin_lock_irqsave(&hvcsd->lock, flags);
36882 kref_get(&hvcsd->kref);
36883 - hvcsd->open_count++;
36884 + local_inc(&hvcsd->open_count);
36885 hvcsd->todo_mask |= HVCS_SCHED_READ;
36886 spin_unlock_irqrestore(&hvcsd->lock, flags);
36887
36888 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
36889 hvcsd = tty->driver_data;
36890
36891 spin_lock_irqsave(&hvcsd->lock, flags);
36892 - if (--hvcsd->open_count == 0) {
36893 + if (local_dec_and_test(&hvcsd->open_count)) {
36894
36895 vio_disable_interrupts(hvcsd->vdev);
36896
36897 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
36898 free_irq(irq, hvcsd);
36899 kref_put(&hvcsd->kref, destroy_hvcs_struct);
36900 return;
36901 - } else if (hvcsd->open_count < 0) {
36902 + } else if (local_read(&hvcsd->open_count) < 0) {
36903 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
36904 " is missmanaged.\n",
36905 - hvcsd->vdev->unit_address, hvcsd->open_count);
36906 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
36907 }
36908
36909 spin_unlock_irqrestore(&hvcsd->lock, flags);
36910 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
36911
36912 spin_lock_irqsave(&hvcsd->lock, flags);
36913 /* Preserve this so that we know how many kref refs to put */
36914 - temp_open_count = hvcsd->open_count;
36915 + temp_open_count = local_read(&hvcsd->open_count);
36916
36917 /*
36918 * Don't kref put inside the spinlock because the destruction
36919 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
36920 hvcsd->tty->driver_data = NULL;
36921 hvcsd->tty = NULL;
36922
36923 - hvcsd->open_count = 0;
36924 + local_set(&hvcsd->open_count, 0);
36925
36926 /* This will drop any buffered data on the floor which is OK in a hangup
36927 * scenario. */
36928 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
36929 * the middle of a write operation? This is a crummy place to do this
36930 * but we want to keep it all in the spinlock.
36931 */
36932 - if (hvcsd->open_count <= 0) {
36933 + if (local_read(&hvcsd->open_count) <= 0) {
36934 spin_unlock_irqrestore(&hvcsd->lock, flags);
36935 return -ENODEV;
36936 }
36937 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
36938 {
36939 struct hvcs_struct *hvcsd = tty->driver_data;
36940
36941 - if (!hvcsd || hvcsd->open_count <= 0)
36942 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
36943 return 0;
36944
36945 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
36946 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
36947 index ef92869..f4ebd88 100644
36948 --- a/drivers/tty/ipwireless/tty.c
36949 +++ b/drivers/tty/ipwireless/tty.c
36950 @@ -29,6 +29,7 @@
36951 #include <linux/tty_driver.h>
36952 #include <linux/tty_flip.h>
36953 #include <linux/uaccess.h>
36954 +#include <asm/local.h>
36955
36956 #include "tty.h"
36957 #include "network.h"
36958 @@ -51,7 +52,7 @@ struct ipw_tty {
36959 int tty_type;
36960 struct ipw_network *network;
36961 struct tty_struct *linux_tty;
36962 - int open_count;
36963 + local_t open_count;
36964 unsigned int control_lines;
36965 struct mutex ipw_tty_mutex;
36966 int tx_bytes_queued;
36967 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
36968 mutex_unlock(&tty->ipw_tty_mutex);
36969 return -ENODEV;
36970 }
36971 - if (tty->open_count == 0)
36972 + if (local_read(&tty->open_count) == 0)
36973 tty->tx_bytes_queued = 0;
36974
36975 - tty->open_count++;
36976 + local_inc(&tty->open_count);
36977
36978 tty->linux_tty = linux_tty;
36979 linux_tty->driver_data = tty;
36980 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
36981
36982 static void do_ipw_close(struct ipw_tty *tty)
36983 {
36984 - tty->open_count--;
36985 -
36986 - if (tty->open_count == 0) {
36987 + if (local_dec_return(&tty->open_count) == 0) {
36988 struct tty_struct *linux_tty = tty->linux_tty;
36989
36990 if (linux_tty != NULL) {
36991 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
36992 return;
36993
36994 mutex_lock(&tty->ipw_tty_mutex);
36995 - if (tty->open_count == 0) {
36996 + if (local_read(&tty->open_count) == 0) {
36997 mutex_unlock(&tty->ipw_tty_mutex);
36998 return;
36999 }
37000 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37001 return;
37002 }
37003
37004 - if (!tty->open_count) {
37005 + if (!local_read(&tty->open_count)) {
37006 mutex_unlock(&tty->ipw_tty_mutex);
37007 return;
37008 }
37009 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37010 return -ENODEV;
37011
37012 mutex_lock(&tty->ipw_tty_mutex);
37013 - if (!tty->open_count) {
37014 + if (!local_read(&tty->open_count)) {
37015 mutex_unlock(&tty->ipw_tty_mutex);
37016 return -EINVAL;
37017 }
37018 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37019 if (!tty)
37020 return -ENODEV;
37021
37022 - if (!tty->open_count)
37023 + if (!local_read(&tty->open_count))
37024 return -EINVAL;
37025
37026 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37027 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37028 if (!tty)
37029 return 0;
37030
37031 - if (!tty->open_count)
37032 + if (!local_read(&tty->open_count))
37033 return 0;
37034
37035 return tty->tx_bytes_queued;
37036 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37037 if (!tty)
37038 return -ENODEV;
37039
37040 - if (!tty->open_count)
37041 + if (!local_read(&tty->open_count))
37042 return -EINVAL;
37043
37044 return get_control_lines(tty);
37045 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37046 if (!tty)
37047 return -ENODEV;
37048
37049 - if (!tty->open_count)
37050 + if (!local_read(&tty->open_count))
37051 return -EINVAL;
37052
37053 return set_control_lines(tty, set, clear);
37054 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37055 if (!tty)
37056 return -ENODEV;
37057
37058 - if (!tty->open_count)
37059 + if (!local_read(&tty->open_count))
37060 return -EINVAL;
37061
37062 /* FIXME: Exactly how is the tty object locked here .. */
37063 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37064 against a parallel ioctl etc */
37065 mutex_lock(&ttyj->ipw_tty_mutex);
37066 }
37067 - while (ttyj->open_count)
37068 + while (local_read(&ttyj->open_count))
37069 do_ipw_close(ttyj);
37070 ipwireless_disassociate_network_ttys(network,
37071 ttyj->channel_idx);
37072 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37073 index fc7bbba..9527e93 100644
37074 --- a/drivers/tty/n_gsm.c
37075 +++ b/drivers/tty/n_gsm.c
37076 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37077 kref_init(&dlci->ref);
37078 mutex_init(&dlci->mutex);
37079 dlci->fifo = &dlci->_fifo;
37080 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37081 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37082 kfree(dlci);
37083 return NULL;
37084 }
37085 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37086 index d2256d0..97476fa 100644
37087 --- a/drivers/tty/n_tty.c
37088 +++ b/drivers/tty/n_tty.c
37089 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37090 {
37091 *ops = tty_ldisc_N_TTY;
37092 ops->owner = NULL;
37093 - ops->refcount = ops->flags = 0;
37094 + atomic_set(&ops->refcount, 0);
37095 + ops->flags = 0;
37096 }
37097 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37098 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37099 index d8653ab..f8afd9d 100644
37100 --- a/drivers/tty/pty.c
37101 +++ b/drivers/tty/pty.c
37102 @@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
37103 register_sysctl_table(pty_root_table);
37104
37105 /* Now create the /dev/ptmx special device */
37106 + pax_open_kernel();
37107 tty_default_fops(&ptmx_fops);
37108 - ptmx_fops.open = ptmx_open;
37109 + *(void **)&ptmx_fops.open = ptmx_open;
37110 + pax_close_kernel();
37111
37112 cdev_init(&ptmx_cdev, &ptmx_fops);
37113 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37114 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37115 index 2b42a01..32a2ed3 100644
37116 --- a/drivers/tty/serial/kgdboc.c
37117 +++ b/drivers/tty/serial/kgdboc.c
37118 @@ -24,8 +24,9 @@
37119 #define MAX_CONFIG_LEN 40
37120
37121 static struct kgdb_io kgdboc_io_ops;
37122 +static struct kgdb_io kgdboc_io_ops_console;
37123
37124 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37125 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37126 static int configured = -1;
37127
37128 static char config[MAX_CONFIG_LEN];
37129 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37130 kgdboc_unregister_kbd();
37131 if (configured == 1)
37132 kgdb_unregister_io_module(&kgdboc_io_ops);
37133 + else if (configured == 2)
37134 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37135 }
37136
37137 static int configure_kgdboc(void)
37138 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37139 int err;
37140 char *cptr = config;
37141 struct console *cons;
37142 + int is_console = 0;
37143
37144 err = kgdboc_option_setup(config);
37145 if (err || !strlen(config) || isspace(config[0]))
37146 goto noconfig;
37147
37148 err = -ENODEV;
37149 - kgdboc_io_ops.is_console = 0;
37150 kgdb_tty_driver = NULL;
37151
37152 kgdboc_use_kms = 0;
37153 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37154 int idx;
37155 if (cons->device && cons->device(cons, &idx) == p &&
37156 idx == tty_line) {
37157 - kgdboc_io_ops.is_console = 1;
37158 + is_console = 1;
37159 break;
37160 }
37161 cons = cons->next;
37162 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37163 kgdb_tty_line = tty_line;
37164
37165 do_register:
37166 - err = kgdb_register_io_module(&kgdboc_io_ops);
37167 + if (is_console) {
37168 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37169 + configured = 2;
37170 + } else {
37171 + err = kgdb_register_io_module(&kgdboc_io_ops);
37172 + configured = 1;
37173 + }
37174 if (err)
37175 goto noconfig;
37176
37177 - configured = 1;
37178 -
37179 return 0;
37180
37181 noconfig:
37182 @@ -213,7 +220,7 @@ noconfig:
37183 static int __init init_kgdboc(void)
37184 {
37185 /* Already configured? */
37186 - if (configured == 1)
37187 + if (configured >= 1)
37188 return 0;
37189
37190 return configure_kgdboc();
37191 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37192 if (config[len - 1] == '\n')
37193 config[len - 1] = '\0';
37194
37195 - if (configured == 1)
37196 + if (configured >= 1)
37197 cleanup_kgdboc();
37198
37199 /* Go and configure with the new params. */
37200 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37201 .post_exception = kgdboc_post_exp_handler,
37202 };
37203
37204 +static struct kgdb_io kgdboc_io_ops_console = {
37205 + .name = "kgdboc",
37206 + .read_char = kgdboc_get_char,
37207 + .write_char = kgdboc_put_char,
37208 + .pre_exception = kgdboc_pre_exp_handler,
37209 + .post_exception = kgdboc_post_exp_handler,
37210 + .is_console = 1
37211 +};
37212 +
37213 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37214 /* This is only available if kgdboc is a built in for early debugging */
37215 static int __init kgdboc_early_init(char *opt)
37216 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37217 index e41b9bb..84002fb 100644
37218 --- a/drivers/tty/tty_io.c
37219 +++ b/drivers/tty/tty_io.c
37220 @@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
37221
37222 void tty_default_fops(struct file_operations *fops)
37223 {
37224 - *fops = tty_fops;
37225 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
37226 }
37227
37228 /*
37229 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
37230 index 24b95db..9c078d0 100644
37231 --- a/drivers/tty/tty_ldisc.c
37232 +++ b/drivers/tty/tty_ldisc.c
37233 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
37234 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
37235 struct tty_ldisc_ops *ldo = ld->ops;
37236
37237 - ldo->refcount--;
37238 + atomic_dec(&ldo->refcount);
37239 module_put(ldo->owner);
37240 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37241
37242 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
37243 spin_lock_irqsave(&tty_ldisc_lock, flags);
37244 tty_ldiscs[disc] = new_ldisc;
37245 new_ldisc->num = disc;
37246 - new_ldisc->refcount = 0;
37247 + atomic_set(&new_ldisc->refcount, 0);
37248 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37249
37250 return ret;
37251 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
37252 return -EINVAL;
37253
37254 spin_lock_irqsave(&tty_ldisc_lock, flags);
37255 - if (tty_ldiscs[disc]->refcount)
37256 + if (atomic_read(&tty_ldiscs[disc]->refcount))
37257 ret = -EBUSY;
37258 else
37259 tty_ldiscs[disc] = NULL;
37260 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
37261 if (ldops) {
37262 ret = ERR_PTR(-EAGAIN);
37263 if (try_module_get(ldops->owner)) {
37264 - ldops->refcount++;
37265 + atomic_inc(&ldops->refcount);
37266 ret = ldops;
37267 }
37268 }
37269 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
37270 unsigned long flags;
37271
37272 spin_lock_irqsave(&tty_ldisc_lock, flags);
37273 - ldops->refcount--;
37274 + atomic_dec(&ldops->refcount);
37275 module_put(ldops->owner);
37276 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37277 }
37278 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
37279 index a605549..6bd3c96 100644
37280 --- a/drivers/tty/vt/keyboard.c
37281 +++ b/drivers/tty/vt/keyboard.c
37282 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
37283 kbd->kbdmode == VC_OFF) &&
37284 value != KVAL(K_SAK))
37285 return; /* SAK is allowed even in raw mode */
37286 +
37287 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
37288 + {
37289 + void *func = fn_handler[value];
37290 + if (func == fn_show_state || func == fn_show_ptregs ||
37291 + func == fn_show_mem)
37292 + return;
37293 + }
37294 +#endif
37295 +
37296 fn_handler[value](vc);
37297 }
37298
37299 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
37300 index 65447c5..0526f0a 100644
37301 --- a/drivers/tty/vt/vt_ioctl.c
37302 +++ b/drivers/tty/vt/vt_ioctl.c
37303 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
37304 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
37305 return -EFAULT;
37306
37307 - if (!capable(CAP_SYS_TTY_CONFIG))
37308 - perm = 0;
37309 -
37310 switch (cmd) {
37311 case KDGKBENT:
37312 key_map = key_maps[s];
37313 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
37314 val = (i ? K_HOLE : K_NOSUCHMAP);
37315 return put_user(val, &user_kbe->kb_value);
37316 case KDSKBENT:
37317 + if (!capable(CAP_SYS_TTY_CONFIG))
37318 + perm = 0;
37319 +
37320 if (!perm)
37321 return -EPERM;
37322 if (!i && v == K_NOSUCHMAP) {
37323 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37324 int i, j, k;
37325 int ret;
37326
37327 - if (!capable(CAP_SYS_TTY_CONFIG))
37328 - perm = 0;
37329 -
37330 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
37331 if (!kbs) {
37332 ret = -ENOMEM;
37333 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37334 kfree(kbs);
37335 return ((p && *p) ? -EOVERFLOW : 0);
37336 case KDSKBSENT:
37337 + if (!capable(CAP_SYS_TTY_CONFIG))
37338 + perm = 0;
37339 +
37340 if (!perm) {
37341 ret = -EPERM;
37342 goto reterr;
37343 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
37344 index a783d53..cb30d94 100644
37345 --- a/drivers/uio/uio.c
37346 +++ b/drivers/uio/uio.c
37347 @@ -25,6 +25,7 @@
37348 #include <linux/kobject.h>
37349 #include <linux/cdev.h>
37350 #include <linux/uio_driver.h>
37351 +#include <asm/local.h>
37352
37353 #define UIO_MAX_DEVICES (1U << MINORBITS)
37354
37355 @@ -32,10 +33,10 @@ struct uio_device {
37356 struct module *owner;
37357 struct device *dev;
37358 int minor;
37359 - atomic_t event;
37360 + atomic_unchecked_t event;
37361 struct fasync_struct *async_queue;
37362 wait_queue_head_t wait;
37363 - int vma_count;
37364 + local_t vma_count;
37365 struct uio_info *info;
37366 struct kobject *map_dir;
37367 struct kobject *portio_dir;
37368 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
37369 struct device_attribute *attr, char *buf)
37370 {
37371 struct uio_device *idev = dev_get_drvdata(dev);
37372 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
37373 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
37374 }
37375
37376 static struct device_attribute uio_class_attributes[] = {
37377 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
37378 {
37379 struct uio_device *idev = info->uio_dev;
37380
37381 - atomic_inc(&idev->event);
37382 + atomic_inc_unchecked(&idev->event);
37383 wake_up_interruptible(&idev->wait);
37384 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
37385 }
37386 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
37387 }
37388
37389 listener->dev = idev;
37390 - listener->event_count = atomic_read(&idev->event);
37391 + listener->event_count = atomic_read_unchecked(&idev->event);
37392 filep->private_data = listener;
37393
37394 if (idev->info->open) {
37395 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
37396 return -EIO;
37397
37398 poll_wait(filep, &idev->wait, wait);
37399 - if (listener->event_count != atomic_read(&idev->event))
37400 + if (listener->event_count != atomic_read_unchecked(&idev->event))
37401 return POLLIN | POLLRDNORM;
37402 return 0;
37403 }
37404 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
37405 do {
37406 set_current_state(TASK_INTERRUPTIBLE);
37407
37408 - event_count = atomic_read(&idev->event);
37409 + event_count = atomic_read_unchecked(&idev->event);
37410 if (event_count != listener->event_count) {
37411 if (copy_to_user(buf, &event_count, count))
37412 retval = -EFAULT;
37413 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
37414 static void uio_vma_open(struct vm_area_struct *vma)
37415 {
37416 struct uio_device *idev = vma->vm_private_data;
37417 - idev->vma_count++;
37418 + local_inc(&idev->vma_count);
37419 }
37420
37421 static void uio_vma_close(struct vm_area_struct *vma)
37422 {
37423 struct uio_device *idev = vma->vm_private_data;
37424 - idev->vma_count--;
37425 + local_dec(&idev->vma_count);
37426 }
37427
37428 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
37429 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
37430 idev->owner = owner;
37431 idev->info = info;
37432 init_waitqueue_head(&idev->wait);
37433 - atomic_set(&idev->event, 0);
37434 + atomic_set_unchecked(&idev->event, 0);
37435
37436 ret = uio_get_minor(idev);
37437 if (ret)
37438 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
37439 index 98b89fe..aff824e 100644
37440 --- a/drivers/usb/atm/cxacru.c
37441 +++ b/drivers/usb/atm/cxacru.c
37442 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
37443 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
37444 if (ret < 2)
37445 return -EINVAL;
37446 - if (index < 0 || index > 0x7f)
37447 + if (index > 0x7f)
37448 return -EINVAL;
37449 pos += tmp;
37450
37451 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
37452 index d3448ca..d2864ca 100644
37453 --- a/drivers/usb/atm/usbatm.c
37454 +++ b/drivers/usb/atm/usbatm.c
37455 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37456 if (printk_ratelimit())
37457 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
37458 __func__, vpi, vci);
37459 - atomic_inc(&vcc->stats->rx_err);
37460 + atomic_inc_unchecked(&vcc->stats->rx_err);
37461 return;
37462 }
37463
37464 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37465 if (length > ATM_MAX_AAL5_PDU) {
37466 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
37467 __func__, length, vcc);
37468 - atomic_inc(&vcc->stats->rx_err);
37469 + atomic_inc_unchecked(&vcc->stats->rx_err);
37470 goto out;
37471 }
37472
37473 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37474 if (sarb->len < pdu_length) {
37475 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
37476 __func__, pdu_length, sarb->len, vcc);
37477 - atomic_inc(&vcc->stats->rx_err);
37478 + atomic_inc_unchecked(&vcc->stats->rx_err);
37479 goto out;
37480 }
37481
37482 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
37483 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
37484 __func__, vcc);
37485 - atomic_inc(&vcc->stats->rx_err);
37486 + atomic_inc_unchecked(&vcc->stats->rx_err);
37487 goto out;
37488 }
37489
37490 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37491 if (printk_ratelimit())
37492 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
37493 __func__, length);
37494 - atomic_inc(&vcc->stats->rx_drop);
37495 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37496 goto out;
37497 }
37498
37499 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37500
37501 vcc->push(vcc, skb);
37502
37503 - atomic_inc(&vcc->stats->rx);
37504 + atomic_inc_unchecked(&vcc->stats->rx);
37505 out:
37506 skb_trim(sarb, 0);
37507 }
37508 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
37509 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
37510
37511 usbatm_pop(vcc, skb);
37512 - atomic_inc(&vcc->stats->tx);
37513 + atomic_inc_unchecked(&vcc->stats->tx);
37514
37515 skb = skb_dequeue(&instance->sndqueue);
37516 }
37517 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
37518 if (!left--)
37519 return sprintf(page,
37520 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
37521 - atomic_read(&atm_dev->stats.aal5.tx),
37522 - atomic_read(&atm_dev->stats.aal5.tx_err),
37523 - atomic_read(&atm_dev->stats.aal5.rx),
37524 - atomic_read(&atm_dev->stats.aal5.rx_err),
37525 - atomic_read(&atm_dev->stats.aal5.rx_drop));
37526 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
37527 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
37528 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
37529 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
37530 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
37531
37532 if (!left--) {
37533 if (instance->disconnected)
37534 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
37535 index d956965..4179a77 100644
37536 --- a/drivers/usb/core/devices.c
37537 +++ b/drivers/usb/core/devices.c
37538 @@ -126,7 +126,7 @@ static const char format_endpt[] =
37539 * time it gets called.
37540 */
37541 static struct device_connect_event {
37542 - atomic_t count;
37543 + atomic_unchecked_t count;
37544 wait_queue_head_t wait;
37545 } device_event = {
37546 .count = ATOMIC_INIT(1),
37547 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
37548
37549 void usbfs_conn_disc_event(void)
37550 {
37551 - atomic_add(2, &device_event.count);
37552 + atomic_add_unchecked(2, &device_event.count);
37553 wake_up(&device_event.wait);
37554 }
37555
37556 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
37557
37558 poll_wait(file, &device_event.wait, wait);
37559
37560 - event_count = atomic_read(&device_event.count);
37561 + event_count = atomic_read_unchecked(&device_event.count);
37562 if (file->f_version != event_count) {
37563 file->f_version = event_count;
37564 return POLLIN | POLLRDNORM;
37565 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
37566 index b3bdfed..a9460e0 100644
37567 --- a/drivers/usb/core/message.c
37568 +++ b/drivers/usb/core/message.c
37569 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
37570 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
37571 if (buf) {
37572 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
37573 - if (len > 0) {
37574 - smallbuf = kmalloc(++len, GFP_NOIO);
37575 + if (len++ > 0) {
37576 + smallbuf = kmalloc(len, GFP_NOIO);
37577 if (!smallbuf)
37578 return buf;
37579 memcpy(smallbuf, buf, len);
37580 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
37581 index 1fc8f12..20647c1 100644
37582 --- a/drivers/usb/early/ehci-dbgp.c
37583 +++ b/drivers/usb/early/ehci-dbgp.c
37584 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
37585
37586 #ifdef CONFIG_KGDB
37587 static struct kgdb_io kgdbdbgp_io_ops;
37588 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
37589 +static struct kgdb_io kgdbdbgp_io_ops_console;
37590 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
37591 #else
37592 #define dbgp_kgdb_mode (0)
37593 #endif
37594 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
37595 .write_char = kgdbdbgp_write_char,
37596 };
37597
37598 +static struct kgdb_io kgdbdbgp_io_ops_console = {
37599 + .name = "kgdbdbgp",
37600 + .read_char = kgdbdbgp_read_char,
37601 + .write_char = kgdbdbgp_write_char,
37602 + .is_console = 1
37603 +};
37604 +
37605 static int kgdbdbgp_wait_time;
37606
37607 static int __init kgdbdbgp_parse_config(char *str)
37608 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
37609 ptr++;
37610 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
37611 }
37612 - kgdb_register_io_module(&kgdbdbgp_io_ops);
37613 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
37614 + if (early_dbgp_console.index != -1)
37615 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
37616 + else
37617 + kgdb_register_io_module(&kgdbdbgp_io_ops);
37618
37619 return 0;
37620 }
37621 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
37622 index d6bea3e..60b250e 100644
37623 --- a/drivers/usb/wusbcore/wa-hc.h
37624 +++ b/drivers/usb/wusbcore/wa-hc.h
37625 @@ -192,7 +192,7 @@ struct wahc {
37626 struct list_head xfer_delayed_list;
37627 spinlock_t xfer_list_lock;
37628 struct work_struct xfer_work;
37629 - atomic_t xfer_id_count;
37630 + atomic_unchecked_t xfer_id_count;
37631 };
37632
37633
37634 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
37635 INIT_LIST_HEAD(&wa->xfer_delayed_list);
37636 spin_lock_init(&wa->xfer_list_lock);
37637 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
37638 - atomic_set(&wa->xfer_id_count, 1);
37639 + atomic_set_unchecked(&wa->xfer_id_count, 1);
37640 }
37641
37642 /**
37643 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
37644 index 57c01ab..8a05959 100644
37645 --- a/drivers/usb/wusbcore/wa-xfer.c
37646 +++ b/drivers/usb/wusbcore/wa-xfer.c
37647 @@ -296,7 +296,7 @@ out:
37648 */
37649 static void wa_xfer_id_init(struct wa_xfer *xfer)
37650 {
37651 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
37652 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
37653 }
37654
37655 /*
37656 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
37657 index c14c42b..f955cc2 100644
37658 --- a/drivers/vhost/vhost.c
37659 +++ b/drivers/vhost/vhost.c
37660 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
37661 return 0;
37662 }
37663
37664 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
37665 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
37666 {
37667 struct file *eventfp, *filep = NULL,
37668 *pollstart = NULL, *pollstop = NULL;
37669 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
37670 index b0b2ac3..89a4399 100644
37671 --- a/drivers/video/aty/aty128fb.c
37672 +++ b/drivers/video/aty/aty128fb.c
37673 @@ -148,7 +148,7 @@ enum {
37674 };
37675
37676 /* Must match above enum */
37677 -static const char *r128_family[] __devinitdata = {
37678 +static const char *r128_family[] __devinitconst = {
37679 "AGP",
37680 "PCI",
37681 "PRO AGP",
37682 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
37683 index 5c3960d..15cf8fc 100644
37684 --- a/drivers/video/fbcmap.c
37685 +++ b/drivers/video/fbcmap.c
37686 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
37687 rc = -ENODEV;
37688 goto out;
37689 }
37690 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
37691 - !info->fbops->fb_setcmap)) {
37692 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
37693 rc = -EINVAL;
37694 goto out1;
37695 }
37696 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
37697 index c6ce416..3b9b642 100644
37698 --- a/drivers/video/fbmem.c
37699 +++ b/drivers/video/fbmem.c
37700 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
37701 image->dx += image->width + 8;
37702 }
37703 } else if (rotate == FB_ROTATE_UD) {
37704 - for (x = 0; x < num && image->dx >= 0; x++) {
37705 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
37706 info->fbops->fb_imageblit(info, image);
37707 image->dx -= image->width + 8;
37708 }
37709 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
37710 image->dy += image->height + 8;
37711 }
37712 } else if (rotate == FB_ROTATE_CCW) {
37713 - for (x = 0; x < num && image->dy >= 0; x++) {
37714 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
37715 info->fbops->fb_imageblit(info, image);
37716 image->dy -= image->height + 8;
37717 }
37718 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
37719 return -EFAULT;
37720 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
37721 return -EINVAL;
37722 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
37723 + if (con2fb.framebuffer >= FB_MAX)
37724 return -EINVAL;
37725 if (!registered_fb[con2fb.framebuffer])
37726 request_module("fb%d", con2fb.framebuffer);
37727 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
37728 index 5a5d092..265c5ed 100644
37729 --- a/drivers/video/geode/gx1fb_core.c
37730 +++ b/drivers/video/geode/gx1fb_core.c
37731 @@ -29,7 +29,7 @@ static int crt_option = 1;
37732 static char panel_option[32] = "";
37733
37734 /* Modes relevant to the GX1 (taken from modedb.c) */
37735 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
37736 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
37737 /* 640x480-60 VESA */
37738 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
37739 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
37740 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
37741 index 0fad23f..0e9afa4 100644
37742 --- a/drivers/video/gxt4500.c
37743 +++ b/drivers/video/gxt4500.c
37744 @@ -156,7 +156,7 @@ struct gxt4500_par {
37745 static char *mode_option;
37746
37747 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
37748 -static const struct fb_videomode defaultmode __devinitdata = {
37749 +static const struct fb_videomode defaultmode __devinitconst = {
37750 .refresh = 60,
37751 .xres = 1280,
37752 .yres = 1024,
37753 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
37754 return 0;
37755 }
37756
37757 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
37758 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
37759 .id = "IBM GXT4500P",
37760 .type = FB_TYPE_PACKED_PIXELS,
37761 .visual = FB_VISUAL_PSEUDOCOLOR,
37762 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
37763 index 7672d2e..b56437f 100644
37764 --- a/drivers/video/i810/i810_accel.c
37765 +++ b/drivers/video/i810/i810_accel.c
37766 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
37767 }
37768 }
37769 printk("ringbuffer lockup!!!\n");
37770 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
37771 i810_report_error(mmio);
37772 par->dev_flags |= LOCKUP;
37773 info->pixmap.scan_align = 1;
37774 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
37775 index b83f361..2b05a91 100644
37776 --- a/drivers/video/i810/i810_main.c
37777 +++ b/drivers/video/i810/i810_main.c
37778 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
37779 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
37780
37781 /* PCI */
37782 -static const char *i810_pci_list[] __devinitdata = {
37783 +static const char *i810_pci_list[] __devinitconst = {
37784 "Intel(R) 810 Framebuffer Device" ,
37785 "Intel(R) 810-DC100 Framebuffer Device" ,
37786 "Intel(R) 810E Framebuffer Device" ,
37787 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
37788 index de36693..3c63fc2 100644
37789 --- a/drivers/video/jz4740_fb.c
37790 +++ b/drivers/video/jz4740_fb.c
37791 @@ -136,7 +136,7 @@ struct jzfb {
37792 uint32_t pseudo_palette[16];
37793 };
37794
37795 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
37796 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
37797 .id = "JZ4740 FB",
37798 .type = FB_TYPE_PACKED_PIXELS,
37799 .visual = FB_VISUAL_TRUECOLOR,
37800 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
37801 index 3c14e43..eafa544 100644
37802 --- a/drivers/video/logo/logo_linux_clut224.ppm
37803 +++ b/drivers/video/logo/logo_linux_clut224.ppm
37804 @@ -1,1604 +1,1123 @@
37805 P3
37806 -# Standard 224-color Linux logo
37807 80 80
37808 255
37809 - 0 0 0 0 0 0 0 0 0 0 0 0
37810 - 0 0 0 0 0 0 0 0 0 0 0 0
37811 - 0 0 0 0 0 0 0 0 0 0 0 0
37812 - 0 0 0 0 0 0 0 0 0 0 0 0
37813 - 0 0 0 0 0 0 0 0 0 0 0 0
37814 - 0 0 0 0 0 0 0 0 0 0 0 0
37815 - 0 0 0 0 0 0 0 0 0 0 0 0
37816 - 0 0 0 0 0 0 0 0 0 0 0 0
37817 - 0 0 0 0 0 0 0 0 0 0 0 0
37818 - 6 6 6 6 6 6 10 10 10 10 10 10
37819 - 10 10 10 6 6 6 6 6 6 6 6 6
37820 - 0 0 0 0 0 0 0 0 0 0 0 0
37821 - 0 0 0 0 0 0 0 0 0 0 0 0
37822 - 0 0 0 0 0 0 0 0 0 0 0 0
37823 - 0 0 0 0 0 0 0 0 0 0 0 0
37824 - 0 0 0 0 0 0 0 0 0 0 0 0
37825 - 0 0 0 0 0 0 0 0 0 0 0 0
37826 - 0 0 0 0 0 0 0 0 0 0 0 0
37827 - 0 0 0 0 0 0 0 0 0 0 0 0
37828 - 0 0 0 0 0 0 0 0 0 0 0 0
37829 - 0 0 0 0 0 0 0 0 0 0 0 0
37830 - 0 0 0 0 0 0 0 0 0 0 0 0
37831 - 0 0 0 0 0 0 0 0 0 0 0 0
37832 - 0 0 0 0 0 0 0 0 0 0 0 0
37833 - 0 0 0 0 0 0 0 0 0 0 0 0
37834 - 0 0 0 0 0 0 0 0 0 0 0 0
37835 - 0 0 0 0 0 0 0 0 0 0 0 0
37836 - 0 0 0 0 0 0 0 0 0 0 0 0
37837 - 0 0 0 6 6 6 10 10 10 14 14 14
37838 - 22 22 22 26 26 26 30 30 30 34 34 34
37839 - 30 30 30 30 30 30 26 26 26 18 18 18
37840 - 14 14 14 10 10 10 6 6 6 0 0 0
37841 - 0 0 0 0 0 0 0 0 0 0 0 0
37842 - 0 0 0 0 0 0 0 0 0 0 0 0
37843 - 0 0 0 0 0 0 0 0 0 0 0 0
37844 - 0 0 0 0 0 0 0 0 0 0 0 0
37845 - 0 0 0 0 0 0 0 0 0 0 0 0
37846 - 0 0 0 0 0 0 0 0 0 0 0 0
37847 - 0 0 0 0 0 0 0 0 0 0 0 0
37848 - 0 0 0 0 0 0 0 0 0 0 0 0
37849 - 0 0 0 0 0 0 0 0 0 0 0 0
37850 - 0 0 0 0 0 1 0 0 1 0 0 0
37851 - 0 0 0 0 0 0 0 0 0 0 0 0
37852 - 0 0 0 0 0 0 0 0 0 0 0 0
37853 - 0 0 0 0 0 0 0 0 0 0 0 0
37854 - 0 0 0 0 0 0 0 0 0 0 0 0
37855 - 0 0 0 0 0 0 0 0 0 0 0 0
37856 - 0 0 0 0 0 0 0 0 0 0 0 0
37857 - 6 6 6 14 14 14 26 26 26 42 42 42
37858 - 54 54 54 66 66 66 78 78 78 78 78 78
37859 - 78 78 78 74 74 74 66 66 66 54 54 54
37860 - 42 42 42 26 26 26 18 18 18 10 10 10
37861 - 6 6 6 0 0 0 0 0 0 0 0 0
37862 - 0 0 0 0 0 0 0 0 0 0 0 0
37863 - 0 0 0 0 0 0 0 0 0 0 0 0
37864 - 0 0 0 0 0 0 0 0 0 0 0 0
37865 - 0 0 0 0 0 0 0 0 0 0 0 0
37866 - 0 0 0 0 0 0 0 0 0 0 0 0
37867 - 0 0 0 0 0 0 0 0 0 0 0 0
37868 - 0 0 0 0 0 0 0 0 0 0 0 0
37869 - 0 0 0 0 0 0 0 0 0 0 0 0
37870 - 0 0 1 0 0 0 0 0 0 0 0 0
37871 - 0 0 0 0 0 0 0 0 0 0 0 0
37872 - 0 0 0 0 0 0 0 0 0 0 0 0
37873 - 0 0 0 0 0 0 0 0 0 0 0 0
37874 - 0 0 0 0 0 0 0 0 0 0 0 0
37875 - 0 0 0 0 0 0 0 0 0 0 0 0
37876 - 0 0 0 0 0 0 0 0 0 10 10 10
37877 - 22 22 22 42 42 42 66 66 66 86 86 86
37878 - 66 66 66 38 38 38 38 38 38 22 22 22
37879 - 26 26 26 34 34 34 54 54 54 66 66 66
37880 - 86 86 86 70 70 70 46 46 46 26 26 26
37881 - 14 14 14 6 6 6 0 0 0 0 0 0
37882 - 0 0 0 0 0 0 0 0 0 0 0 0
37883 - 0 0 0 0 0 0 0 0 0 0 0 0
37884 - 0 0 0 0 0 0 0 0 0 0 0 0
37885 - 0 0 0 0 0 0 0 0 0 0 0 0
37886 - 0 0 0 0 0 0 0 0 0 0 0 0
37887 - 0 0 0 0 0 0 0 0 0 0 0 0
37888 - 0 0 0 0 0 0 0 0 0 0 0 0
37889 - 0 0 0 0 0 0 0 0 0 0 0 0
37890 - 0 0 1 0 0 1 0 0 1 0 0 0
37891 - 0 0 0 0 0 0 0 0 0 0 0 0
37892 - 0 0 0 0 0 0 0 0 0 0 0 0
37893 - 0 0 0 0 0 0 0 0 0 0 0 0
37894 - 0 0 0 0 0 0 0 0 0 0 0 0
37895 - 0 0 0 0 0 0 0 0 0 0 0 0
37896 - 0 0 0 0 0 0 10 10 10 26 26 26
37897 - 50 50 50 82 82 82 58 58 58 6 6 6
37898 - 2 2 6 2 2 6 2 2 6 2 2 6
37899 - 2 2 6 2 2 6 2 2 6 2 2 6
37900 - 6 6 6 54 54 54 86 86 86 66 66 66
37901 - 38 38 38 18 18 18 6 6 6 0 0 0
37902 - 0 0 0 0 0 0 0 0 0 0 0 0
37903 - 0 0 0 0 0 0 0 0 0 0 0 0
37904 - 0 0 0 0 0 0 0 0 0 0 0 0
37905 - 0 0 0 0 0 0 0 0 0 0 0 0
37906 - 0 0 0 0 0 0 0 0 0 0 0 0
37907 - 0 0 0 0 0 0 0 0 0 0 0 0
37908 - 0 0 0 0 0 0 0 0 0 0 0 0
37909 - 0 0 0 0 0 0 0 0 0 0 0 0
37910 - 0 0 0 0 0 0 0 0 0 0 0 0
37911 - 0 0 0 0 0 0 0 0 0 0 0 0
37912 - 0 0 0 0 0 0 0 0 0 0 0 0
37913 - 0 0 0 0 0 0 0 0 0 0 0 0
37914 - 0 0 0 0 0 0 0 0 0 0 0 0
37915 - 0 0 0 0 0 0 0 0 0 0 0 0
37916 - 0 0 0 6 6 6 22 22 22 50 50 50
37917 - 78 78 78 34 34 34 2 2 6 2 2 6
37918 - 2 2 6 2 2 6 2 2 6 2 2 6
37919 - 2 2 6 2 2 6 2 2 6 2 2 6
37920 - 2 2 6 2 2 6 6 6 6 70 70 70
37921 - 78 78 78 46 46 46 22 22 22 6 6 6
37922 - 0 0 0 0 0 0 0 0 0 0 0 0
37923 - 0 0 0 0 0 0 0 0 0 0 0 0
37924 - 0 0 0 0 0 0 0 0 0 0 0 0
37925 - 0 0 0 0 0 0 0 0 0 0 0 0
37926 - 0 0 0 0 0 0 0 0 0 0 0 0
37927 - 0 0 0 0 0 0 0 0 0 0 0 0
37928 - 0 0 0 0 0 0 0 0 0 0 0 0
37929 - 0 0 0 0 0 0 0 0 0 0 0 0
37930 - 0 0 1 0 0 1 0 0 1 0 0 0
37931 - 0 0 0 0 0 0 0 0 0 0 0 0
37932 - 0 0 0 0 0 0 0 0 0 0 0 0
37933 - 0 0 0 0 0 0 0 0 0 0 0 0
37934 - 0 0 0 0 0 0 0 0 0 0 0 0
37935 - 0 0 0 0 0 0 0 0 0 0 0 0
37936 - 6 6 6 18 18 18 42 42 42 82 82 82
37937 - 26 26 26 2 2 6 2 2 6 2 2 6
37938 - 2 2 6 2 2 6 2 2 6 2 2 6
37939 - 2 2 6 2 2 6 2 2 6 14 14 14
37940 - 46 46 46 34 34 34 6 6 6 2 2 6
37941 - 42 42 42 78 78 78 42 42 42 18 18 18
37942 - 6 6 6 0 0 0 0 0 0 0 0 0
37943 - 0 0 0 0 0 0 0 0 0 0 0 0
37944 - 0 0 0 0 0 0 0 0 0 0 0 0
37945 - 0 0 0 0 0 0 0 0 0 0 0 0
37946 - 0 0 0 0 0 0 0 0 0 0 0 0
37947 - 0 0 0 0 0 0 0 0 0 0 0 0
37948 - 0 0 0 0 0 0 0 0 0 0 0 0
37949 - 0 0 0 0 0 0 0 0 0 0 0 0
37950 - 0 0 1 0 0 0 0 0 1 0 0 0
37951 - 0 0 0 0 0 0 0 0 0 0 0 0
37952 - 0 0 0 0 0 0 0 0 0 0 0 0
37953 - 0 0 0 0 0 0 0 0 0 0 0 0
37954 - 0 0 0 0 0 0 0 0 0 0 0 0
37955 - 0 0 0 0 0 0 0 0 0 0 0 0
37956 - 10 10 10 30 30 30 66 66 66 58 58 58
37957 - 2 2 6 2 2 6 2 2 6 2 2 6
37958 - 2 2 6 2 2 6 2 2 6 2 2 6
37959 - 2 2 6 2 2 6 2 2 6 26 26 26
37960 - 86 86 86 101 101 101 46 46 46 10 10 10
37961 - 2 2 6 58 58 58 70 70 70 34 34 34
37962 - 10 10 10 0 0 0 0 0 0 0 0 0
37963 - 0 0 0 0 0 0 0 0 0 0 0 0
37964 - 0 0 0 0 0 0 0 0 0 0 0 0
37965 - 0 0 0 0 0 0 0 0 0 0 0 0
37966 - 0 0 0 0 0 0 0 0 0 0 0 0
37967 - 0 0 0 0 0 0 0 0 0 0 0 0
37968 - 0 0 0 0 0 0 0 0 0 0 0 0
37969 - 0 0 0 0 0 0 0 0 0 0 0 0
37970 - 0 0 1 0 0 1 0 0 1 0 0 0
37971 - 0 0 0 0 0 0 0 0 0 0 0 0
37972 - 0 0 0 0 0 0 0 0 0 0 0 0
37973 - 0 0 0 0 0 0 0 0 0 0 0 0
37974 - 0 0 0 0 0 0 0 0 0 0 0 0
37975 - 0 0 0 0 0 0 0 0 0 0 0 0
37976 - 14 14 14 42 42 42 86 86 86 10 10 10
37977 - 2 2 6 2 2 6 2 2 6 2 2 6
37978 - 2 2 6 2 2 6 2 2 6 2 2 6
37979 - 2 2 6 2 2 6 2 2 6 30 30 30
37980 - 94 94 94 94 94 94 58 58 58 26 26 26
37981 - 2 2 6 6 6 6 78 78 78 54 54 54
37982 - 22 22 22 6 6 6 0 0 0 0 0 0
37983 - 0 0 0 0 0 0 0 0 0 0 0 0
37984 - 0 0 0 0 0 0 0 0 0 0 0 0
37985 - 0 0 0 0 0 0 0 0 0 0 0 0
37986 - 0 0 0 0 0 0 0 0 0 0 0 0
37987 - 0 0 0 0 0 0 0 0 0 0 0 0
37988 - 0 0 0 0 0 0 0 0 0 0 0 0
37989 - 0 0 0 0 0 0 0 0 0 0 0 0
37990 - 0 0 0 0 0 0 0 0 0 0 0 0
37991 - 0 0 0 0 0 0 0 0 0 0 0 0
37992 - 0 0 0 0 0 0 0 0 0 0 0 0
37993 - 0 0 0 0 0 0 0 0 0 0 0 0
37994 - 0 0 0 0 0 0 0 0 0 0 0 0
37995 - 0 0 0 0 0 0 0 0 0 6 6 6
37996 - 22 22 22 62 62 62 62 62 62 2 2 6
37997 - 2 2 6 2 2 6 2 2 6 2 2 6
37998 - 2 2 6 2 2 6 2 2 6 2 2 6
37999 - 2 2 6 2 2 6 2 2 6 26 26 26
38000 - 54 54 54 38 38 38 18 18 18 10 10 10
38001 - 2 2 6 2 2 6 34 34 34 82 82 82
38002 - 38 38 38 14 14 14 0 0 0 0 0 0
38003 - 0 0 0 0 0 0 0 0 0 0 0 0
38004 - 0 0 0 0 0 0 0 0 0 0 0 0
38005 - 0 0 0 0 0 0 0 0 0 0 0 0
38006 - 0 0 0 0 0 0 0 0 0 0 0 0
38007 - 0 0 0 0 0 0 0 0 0 0 0 0
38008 - 0 0 0 0 0 0 0 0 0 0 0 0
38009 - 0 0 0 0 0 0 0 0 0 0 0 0
38010 - 0 0 0 0 0 1 0 0 1 0 0 0
38011 - 0 0 0 0 0 0 0 0 0 0 0 0
38012 - 0 0 0 0 0 0 0 0 0 0 0 0
38013 - 0 0 0 0 0 0 0 0 0 0 0 0
38014 - 0 0 0 0 0 0 0 0 0 0 0 0
38015 - 0 0 0 0 0 0 0 0 0 6 6 6
38016 - 30 30 30 78 78 78 30 30 30 2 2 6
38017 - 2 2 6 2 2 6 2 2 6 2 2 6
38018 - 2 2 6 2 2 6 2 2 6 2 2 6
38019 - 2 2 6 2 2 6 2 2 6 10 10 10
38020 - 10 10 10 2 2 6 2 2 6 2 2 6
38021 - 2 2 6 2 2 6 2 2 6 78 78 78
38022 - 50 50 50 18 18 18 6 6 6 0 0 0
38023 - 0 0 0 0 0 0 0 0 0 0 0 0
38024 - 0 0 0 0 0 0 0 0 0 0 0 0
38025 - 0 0 0 0 0 0 0 0 0 0 0 0
38026 - 0 0 0 0 0 0 0 0 0 0 0 0
38027 - 0 0 0 0 0 0 0 0 0 0 0 0
38028 - 0 0 0 0 0 0 0 0 0 0 0 0
38029 - 0 0 0 0 0 0 0 0 0 0 0 0
38030 - 0 0 1 0 0 0 0 0 0 0 0 0
38031 - 0 0 0 0 0 0 0 0 0 0 0 0
38032 - 0 0 0 0 0 0 0 0 0 0 0 0
38033 - 0 0 0 0 0 0 0 0 0 0 0 0
38034 - 0 0 0 0 0 0 0 0 0 0 0 0
38035 - 0 0 0 0 0 0 0 0 0 10 10 10
38036 - 38 38 38 86 86 86 14 14 14 2 2 6
38037 - 2 2 6 2 2 6 2 2 6 2 2 6
38038 - 2 2 6 2 2 6 2 2 6 2 2 6
38039 - 2 2 6 2 2 6 2 2 6 2 2 6
38040 - 2 2 6 2 2 6 2 2 6 2 2 6
38041 - 2 2 6 2 2 6 2 2 6 54 54 54
38042 - 66 66 66 26 26 26 6 6 6 0 0 0
38043 - 0 0 0 0 0 0 0 0 0 0 0 0
38044 - 0 0 0 0 0 0 0 0 0 0 0 0
38045 - 0 0 0 0 0 0 0 0 0 0 0 0
38046 - 0 0 0 0 0 0 0 0 0 0 0 0
38047 - 0 0 0 0 0 0 0 0 0 0 0 0
38048 - 0 0 0 0 0 0 0 0 0 0 0 0
38049 - 0 0 0 0 0 0 0 0 0 0 0 0
38050 - 0 0 0 0 0 1 0 0 1 0 0 0
38051 - 0 0 0 0 0 0 0 0 0 0 0 0
38052 - 0 0 0 0 0 0 0 0 0 0 0 0
38053 - 0 0 0 0 0 0 0 0 0 0 0 0
38054 - 0 0 0 0 0 0 0 0 0 0 0 0
38055 - 0 0 0 0 0 0 0 0 0 14 14 14
38056 - 42 42 42 82 82 82 2 2 6 2 2 6
38057 - 2 2 6 6 6 6 10 10 10 2 2 6
38058 - 2 2 6 2 2 6 2 2 6 2 2 6
38059 - 2 2 6 2 2 6 2 2 6 6 6 6
38060 - 14 14 14 10 10 10 2 2 6 2 2 6
38061 - 2 2 6 2 2 6 2 2 6 18 18 18
38062 - 82 82 82 34 34 34 10 10 10 0 0 0
38063 - 0 0 0 0 0 0 0 0 0 0 0 0
38064 - 0 0 0 0 0 0 0 0 0 0 0 0
38065 - 0 0 0 0 0 0 0 0 0 0 0 0
38066 - 0 0 0 0 0 0 0 0 0 0 0 0
38067 - 0 0 0 0 0 0 0 0 0 0 0 0
38068 - 0 0 0 0 0 0 0 0 0 0 0 0
38069 - 0 0 0 0 0 0 0 0 0 0 0 0
38070 - 0 0 1 0 0 0 0 0 0 0 0 0
38071 - 0 0 0 0 0 0 0 0 0 0 0 0
38072 - 0 0 0 0 0 0 0 0 0 0 0 0
38073 - 0 0 0 0 0 0 0 0 0 0 0 0
38074 - 0 0 0 0 0 0 0 0 0 0 0 0
38075 - 0 0 0 0 0 0 0 0 0 14 14 14
38076 - 46 46 46 86 86 86 2 2 6 2 2 6
38077 - 6 6 6 6 6 6 22 22 22 34 34 34
38078 - 6 6 6 2 2 6 2 2 6 2 2 6
38079 - 2 2 6 2 2 6 18 18 18 34 34 34
38080 - 10 10 10 50 50 50 22 22 22 2 2 6
38081 - 2 2 6 2 2 6 2 2 6 10 10 10
38082 - 86 86 86 42 42 42 14 14 14 0 0 0
38083 - 0 0 0 0 0 0 0 0 0 0 0 0
38084 - 0 0 0 0 0 0 0 0 0 0 0 0
38085 - 0 0 0 0 0 0 0 0 0 0 0 0
38086 - 0 0 0 0 0 0 0 0 0 0 0 0
38087 - 0 0 0 0 0 0 0 0 0 0 0 0
38088 - 0 0 0 0 0 0 0 0 0 0 0 0
38089 - 0 0 0 0 0 0 0 0 0 0 0 0
38090 - 0 0 1 0 0 1 0 0 1 0 0 0
38091 - 0 0 0 0 0 0 0 0 0 0 0 0
38092 - 0 0 0 0 0 0 0 0 0 0 0 0
38093 - 0 0 0 0 0 0 0 0 0 0 0 0
38094 - 0 0 0 0 0 0 0 0 0 0 0 0
38095 - 0 0 0 0 0 0 0 0 0 14 14 14
38096 - 46 46 46 86 86 86 2 2 6 2 2 6
38097 - 38 38 38 116 116 116 94 94 94 22 22 22
38098 - 22 22 22 2 2 6 2 2 6 2 2 6
38099 - 14 14 14 86 86 86 138 138 138 162 162 162
38100 -154 154 154 38 38 38 26 26 26 6 6 6
38101 - 2 2 6 2 2 6 2 2 6 2 2 6
38102 - 86 86 86 46 46 46 14 14 14 0 0 0
38103 - 0 0 0 0 0 0 0 0 0 0 0 0
38104 - 0 0 0 0 0 0 0 0 0 0 0 0
38105 - 0 0 0 0 0 0 0 0 0 0 0 0
38106 - 0 0 0 0 0 0 0 0 0 0 0 0
38107 - 0 0 0 0 0 0 0 0 0 0 0 0
38108 - 0 0 0 0 0 0 0 0 0 0 0 0
38109 - 0 0 0 0 0 0 0 0 0 0 0 0
38110 - 0 0 0 0 0 0 0 0 0 0 0 0
38111 - 0 0 0 0 0 0 0 0 0 0 0 0
38112 - 0 0 0 0 0 0 0 0 0 0 0 0
38113 - 0 0 0 0 0 0 0 0 0 0 0 0
38114 - 0 0 0 0 0 0 0 0 0 0 0 0
38115 - 0 0 0 0 0 0 0 0 0 14 14 14
38116 - 46 46 46 86 86 86 2 2 6 14 14 14
38117 -134 134 134 198 198 198 195 195 195 116 116 116
38118 - 10 10 10 2 2 6 2 2 6 6 6 6
38119 -101 98 89 187 187 187 210 210 210 218 218 218
38120 -214 214 214 134 134 134 14 14 14 6 6 6
38121 - 2 2 6 2 2 6 2 2 6 2 2 6
38122 - 86 86 86 50 50 50 18 18 18 6 6 6
38123 - 0 0 0 0 0 0 0 0 0 0 0 0
38124 - 0 0 0 0 0 0 0 0 0 0 0 0
38125 - 0 0 0 0 0 0 0 0 0 0 0 0
38126 - 0 0 0 0 0 0 0 0 0 0 0 0
38127 - 0 0 0 0 0 0 0 0 0 0 0 0
38128 - 0 0 0 0 0 0 0 0 0 0 0 0
38129 - 0 0 0 0 0 0 0 0 1 0 0 0
38130 - 0 0 1 0 0 1 0 0 1 0 0 0
38131 - 0 0 0 0 0 0 0 0 0 0 0 0
38132 - 0 0 0 0 0 0 0 0 0 0 0 0
38133 - 0 0 0 0 0 0 0 0 0 0 0 0
38134 - 0 0 0 0 0 0 0 0 0 0 0 0
38135 - 0 0 0 0 0 0 0 0 0 14 14 14
38136 - 46 46 46 86 86 86 2 2 6 54 54 54
38137 -218 218 218 195 195 195 226 226 226 246 246 246
38138 - 58 58 58 2 2 6 2 2 6 30 30 30
38139 -210 210 210 253 253 253 174 174 174 123 123 123
38140 -221 221 221 234 234 234 74 74 74 2 2 6
38141 - 2 2 6 2 2 6 2 2 6 2 2 6
38142 - 70 70 70 58 58 58 22 22 22 6 6 6
38143 - 0 0 0 0 0 0 0 0 0 0 0 0
38144 - 0 0 0 0 0 0 0 0 0 0 0 0
38145 - 0 0 0 0 0 0 0 0 0 0 0 0
38146 - 0 0 0 0 0 0 0 0 0 0 0 0
38147 - 0 0 0 0 0 0 0 0 0 0 0 0
38148 - 0 0 0 0 0 0 0 0 0 0 0 0
38149 - 0 0 0 0 0 0 0 0 0 0 0 0
38150 - 0 0 0 0 0 0 0 0 0 0 0 0
38151 - 0 0 0 0 0 0 0 0 0 0 0 0
38152 - 0 0 0 0 0 0 0 0 0 0 0 0
38153 - 0 0 0 0 0 0 0 0 0 0 0 0
38154 - 0 0 0 0 0 0 0 0 0 0 0 0
38155 - 0 0 0 0 0 0 0 0 0 14 14 14
38156 - 46 46 46 82 82 82 2 2 6 106 106 106
38157 -170 170 170 26 26 26 86 86 86 226 226 226
38158 -123 123 123 10 10 10 14 14 14 46 46 46
38159 -231 231 231 190 190 190 6 6 6 70 70 70
38160 - 90 90 90 238 238 238 158 158 158 2 2 6
38161 - 2 2 6 2 2 6 2 2 6 2 2 6
38162 - 70 70 70 58 58 58 22 22 22 6 6 6
38163 - 0 0 0 0 0 0 0 0 0 0 0 0
38164 - 0 0 0 0 0 0 0 0 0 0 0 0
38165 - 0 0 0 0 0 0 0 0 0 0 0 0
38166 - 0 0 0 0 0 0 0 0 0 0 0 0
38167 - 0 0 0 0 0 0 0 0 0 0 0 0
38168 - 0 0 0 0 0 0 0 0 0 0 0 0
38169 - 0 0 0 0 0 0 0 0 1 0 0 0
38170 - 0 0 1 0 0 1 0 0 1 0 0 0
38171 - 0 0 0 0 0 0 0 0 0 0 0 0
38172 - 0 0 0 0 0 0 0 0 0 0 0 0
38173 - 0 0 0 0 0 0 0 0 0 0 0 0
38174 - 0 0 0 0 0 0 0 0 0 0 0 0
38175 - 0 0 0 0 0 0 0 0 0 14 14 14
38176 - 42 42 42 86 86 86 6 6 6 116 116 116
38177 -106 106 106 6 6 6 70 70 70 149 149 149
38178 -128 128 128 18 18 18 38 38 38 54 54 54
38179 -221 221 221 106 106 106 2 2 6 14 14 14
38180 - 46 46 46 190 190 190 198 198 198 2 2 6
38181 - 2 2 6 2 2 6 2 2 6 2 2 6
38182 - 74 74 74 62 62 62 22 22 22 6 6 6
38183 - 0 0 0 0 0 0 0 0 0 0 0 0
38184 - 0 0 0 0 0 0 0 0 0 0 0 0
38185 - 0 0 0 0 0 0 0 0 0 0 0 0
38186 - 0 0 0 0 0 0 0 0 0 0 0 0
38187 - 0 0 0 0 0 0 0 0 0 0 0 0
38188 - 0 0 0 0 0 0 0 0 0 0 0 0
38189 - 0 0 0 0 0 0 0 0 1 0 0 0
38190 - 0 0 1 0 0 0 0 0 1 0 0 0
38191 - 0 0 0 0 0 0 0 0 0 0 0 0
38192 - 0 0 0 0 0 0 0 0 0 0 0 0
38193 - 0 0 0 0 0 0 0 0 0 0 0 0
38194 - 0 0 0 0 0 0 0 0 0 0 0 0
38195 - 0 0 0 0 0 0 0 0 0 14 14 14
38196 - 42 42 42 94 94 94 14 14 14 101 101 101
38197 -128 128 128 2 2 6 18 18 18 116 116 116
38198 -118 98 46 121 92 8 121 92 8 98 78 10
38199 -162 162 162 106 106 106 2 2 6 2 2 6
38200 - 2 2 6 195 195 195 195 195 195 6 6 6
38201 - 2 2 6 2 2 6 2 2 6 2 2 6
38202 - 74 74 74 62 62 62 22 22 22 6 6 6
38203 - 0 0 0 0 0 0 0 0 0 0 0 0
38204 - 0 0 0 0 0 0 0 0 0 0 0 0
38205 - 0 0 0 0 0 0 0 0 0 0 0 0
38206 - 0 0 0 0 0 0 0 0 0 0 0 0
38207 - 0 0 0 0 0 0 0 0 0 0 0 0
38208 - 0 0 0 0 0 0 0 0 0 0 0 0
38209 - 0 0 0 0 0 0 0 0 1 0 0 1
38210 - 0 0 1 0 0 0 0 0 1 0 0 0
38211 - 0 0 0 0 0 0 0 0 0 0 0 0
38212 - 0 0 0 0 0 0 0 0 0 0 0 0
38213 - 0 0 0 0 0 0 0 0 0 0 0 0
38214 - 0 0 0 0 0 0 0 0 0 0 0 0
38215 - 0 0 0 0 0 0 0 0 0 10 10 10
38216 - 38 38 38 90 90 90 14 14 14 58 58 58
38217 -210 210 210 26 26 26 54 38 6 154 114 10
38218 -226 170 11 236 186 11 225 175 15 184 144 12
38219 -215 174 15 175 146 61 37 26 9 2 2 6
38220 - 70 70 70 246 246 246 138 138 138 2 2 6
38221 - 2 2 6 2 2 6 2 2 6 2 2 6
38222 - 70 70 70 66 66 66 26 26 26 6 6 6
38223 - 0 0 0 0 0 0 0 0 0 0 0 0
38224 - 0 0 0 0 0 0 0 0 0 0 0 0
38225 - 0 0 0 0 0 0 0 0 0 0 0 0
38226 - 0 0 0 0 0 0 0 0 0 0 0 0
38227 - 0 0 0 0 0 0 0 0 0 0 0 0
38228 - 0 0 0 0 0 0 0 0 0 0 0 0
38229 - 0 0 0 0 0 0 0 0 0 0 0 0
38230 - 0 0 0 0 0 0 0 0 0 0 0 0
38231 - 0 0 0 0 0 0 0 0 0 0 0 0
38232 - 0 0 0 0 0 0 0 0 0 0 0 0
38233 - 0 0 0 0 0 0 0 0 0 0 0 0
38234 - 0 0 0 0 0 0 0 0 0 0 0 0
38235 - 0 0 0 0 0 0 0 0 0 10 10 10
38236 - 38 38 38 86 86 86 14 14 14 10 10 10
38237 -195 195 195 188 164 115 192 133 9 225 175 15
38238 -239 182 13 234 190 10 232 195 16 232 200 30
38239 -245 207 45 241 208 19 232 195 16 184 144 12
38240 -218 194 134 211 206 186 42 42 42 2 2 6
38241 - 2 2 6 2 2 6 2 2 6 2 2 6
38242 - 50 50 50 74 74 74 30 30 30 6 6 6
38243 - 0 0 0 0 0 0 0 0 0 0 0 0
38244 - 0 0 0 0 0 0 0 0 0 0 0 0
38245 - 0 0 0 0 0 0 0 0 0 0 0 0
38246 - 0 0 0 0 0 0 0 0 0 0 0 0
38247 - 0 0 0 0 0 0 0 0 0 0 0 0
38248 - 0 0 0 0 0 0 0 0 0 0 0 0
38249 - 0 0 0 0 0 0 0 0 0 0 0 0
38250 - 0 0 0 0 0 0 0 0 0 0 0 0
38251 - 0 0 0 0 0 0 0 0 0 0 0 0
38252 - 0 0 0 0 0 0 0 0 0 0 0 0
38253 - 0 0 0 0 0 0 0 0 0 0 0 0
38254 - 0 0 0 0 0 0 0 0 0 0 0 0
38255 - 0 0 0 0 0 0 0 0 0 10 10 10
38256 - 34 34 34 86 86 86 14 14 14 2 2 6
38257 -121 87 25 192 133 9 219 162 10 239 182 13
38258 -236 186 11 232 195 16 241 208 19 244 214 54
38259 -246 218 60 246 218 38 246 215 20 241 208 19
38260 -241 208 19 226 184 13 121 87 25 2 2 6
38261 - 2 2 6 2 2 6 2 2 6 2 2 6
38262 - 50 50 50 82 82 82 34 34 34 10 10 10
38263 - 0 0 0 0 0 0 0 0 0 0 0 0
38264 - 0 0 0 0 0 0 0 0 0 0 0 0
38265 - 0 0 0 0 0 0 0 0 0 0 0 0
38266 - 0 0 0 0 0 0 0 0 0 0 0 0
38267 - 0 0 0 0 0 0 0 0 0 0 0 0
38268 - 0 0 0 0 0 0 0 0 0 0 0 0
38269 - 0 0 0 0 0 0 0 0 0 0 0 0
38270 - 0 0 0 0 0 0 0 0 0 0 0 0
38271 - 0 0 0 0 0 0 0 0 0 0 0 0
38272 - 0 0 0 0 0 0 0 0 0 0 0 0
38273 - 0 0 0 0 0 0 0 0 0 0 0 0
38274 - 0 0 0 0 0 0 0 0 0 0 0 0
38275 - 0 0 0 0 0 0 0 0 0 10 10 10
38276 - 34 34 34 82 82 82 30 30 30 61 42 6
38277 -180 123 7 206 145 10 230 174 11 239 182 13
38278 -234 190 10 238 202 15 241 208 19 246 218 74
38279 -246 218 38 246 215 20 246 215 20 246 215 20
38280 -226 184 13 215 174 15 184 144 12 6 6 6
38281 - 2 2 6 2 2 6 2 2 6 2 2 6
38282 - 26 26 26 94 94 94 42 42 42 14 14 14
38283 - 0 0 0 0 0 0 0 0 0 0 0 0
38284 - 0 0 0 0 0 0 0 0 0 0 0 0
38285 - 0 0 0 0 0 0 0 0 0 0 0 0
38286 - 0 0 0 0 0 0 0 0 0 0 0 0
38287 - 0 0 0 0 0 0 0 0 0 0 0 0
38288 - 0 0 0 0 0 0 0 0 0 0 0 0
38289 - 0 0 0 0 0 0 0 0 0 0 0 0
38290 - 0 0 0 0 0 0 0 0 0 0 0 0
38291 - 0 0 0 0 0 0 0 0 0 0 0 0
38292 - 0 0 0 0 0 0 0 0 0 0 0 0
38293 - 0 0 0 0 0 0 0 0 0 0 0 0
38294 - 0 0 0 0 0 0 0 0 0 0 0 0
38295 - 0 0 0 0 0 0 0 0 0 10 10 10
38296 - 30 30 30 78 78 78 50 50 50 104 69 6
38297 -192 133 9 216 158 10 236 178 12 236 186 11
38298 -232 195 16 241 208 19 244 214 54 245 215 43
38299 -246 215 20 246 215 20 241 208 19 198 155 10
38300 -200 144 11 216 158 10 156 118 10 2 2 6
38301 - 2 2 6 2 2 6 2 2 6 2 2 6
38302 - 6 6 6 90 90 90 54 54 54 18 18 18
38303 - 6 6 6 0 0 0 0 0 0 0 0 0
38304 - 0 0 0 0 0 0 0 0 0 0 0 0
38305 - 0 0 0 0 0 0 0 0 0 0 0 0
38306 - 0 0 0 0 0 0 0 0 0 0 0 0
38307 - 0 0 0 0 0 0 0 0 0 0 0 0
38308 - 0 0 0 0 0 0 0 0 0 0 0 0
38309 - 0 0 0 0 0 0 0 0 0 0 0 0
38310 - 0 0 0 0 0 0 0 0 0 0 0 0
38311 - 0 0 0 0 0 0 0 0 0 0 0 0
38312 - 0 0 0 0 0 0 0 0 0 0 0 0
38313 - 0 0 0 0 0 0 0 0 0 0 0 0
38314 - 0 0 0 0 0 0 0 0 0 0 0 0
38315 - 0 0 0 0 0 0 0 0 0 10 10 10
38316 - 30 30 30 78 78 78 46 46 46 22 22 22
38317 -137 92 6 210 162 10 239 182 13 238 190 10
38318 -238 202 15 241 208 19 246 215 20 246 215 20
38319 -241 208 19 203 166 17 185 133 11 210 150 10
38320 -216 158 10 210 150 10 102 78 10 2 2 6
38321 - 6 6 6 54 54 54 14 14 14 2 2 6
38322 - 2 2 6 62 62 62 74 74 74 30 30 30
38323 - 10 10 10 0 0 0 0 0 0 0 0 0
38324 - 0 0 0 0 0 0 0 0 0 0 0 0
38325 - 0 0 0 0 0 0 0 0 0 0 0 0
38326 - 0 0 0 0 0 0 0 0 0 0 0 0
38327 - 0 0 0 0 0 0 0 0 0 0 0 0
38328 - 0 0 0 0 0 0 0 0 0 0 0 0
38329 - 0 0 0 0 0 0 0 0 0 0 0 0
38330 - 0 0 0 0 0 0 0 0 0 0 0 0
38331 - 0 0 0 0 0 0 0 0 0 0 0 0
38332 - 0 0 0 0 0 0 0 0 0 0 0 0
38333 - 0 0 0 0 0 0 0 0 0 0 0 0
38334 - 0 0 0 0 0 0 0 0 0 0 0 0
38335 - 0 0 0 0 0 0 0 0 0 10 10 10
38336 - 34 34 34 78 78 78 50 50 50 6 6 6
38337 - 94 70 30 139 102 15 190 146 13 226 184 13
38338 -232 200 30 232 195 16 215 174 15 190 146 13
38339 -168 122 10 192 133 9 210 150 10 213 154 11
38340 -202 150 34 182 157 106 101 98 89 2 2 6
38341 - 2 2 6 78 78 78 116 116 116 58 58 58
38342 - 2 2 6 22 22 22 90 90 90 46 46 46
38343 - 18 18 18 6 6 6 0 0 0 0 0 0
38344 - 0 0 0 0 0 0 0 0 0 0 0 0
38345 - 0 0 0 0 0 0 0 0 0 0 0 0
38346 - 0 0 0 0 0 0 0 0 0 0 0 0
38347 - 0 0 0 0 0 0 0 0 0 0 0 0
38348 - 0 0 0 0 0 0 0 0 0 0 0 0
38349 - 0 0 0 0 0 0 0 0 0 0 0 0
38350 - 0 0 0 0 0 0 0 0 0 0 0 0
38351 - 0 0 0 0 0 0 0 0 0 0 0 0
38352 - 0 0 0 0 0 0 0 0 0 0 0 0
38353 - 0 0 0 0 0 0 0 0 0 0 0 0
38354 - 0 0 0 0 0 0 0 0 0 0 0 0
38355 - 0 0 0 0 0 0 0 0 0 10 10 10
38356 - 38 38 38 86 86 86 50 50 50 6 6 6
38357 -128 128 128 174 154 114 156 107 11 168 122 10
38358 -198 155 10 184 144 12 197 138 11 200 144 11
38359 -206 145 10 206 145 10 197 138 11 188 164 115
38360 -195 195 195 198 198 198 174 174 174 14 14 14
38361 - 2 2 6 22 22 22 116 116 116 116 116 116
38362 - 22 22 22 2 2 6 74 74 74 70 70 70
38363 - 30 30 30 10 10 10 0 0 0 0 0 0
38364 - 0 0 0 0 0 0 0 0 0 0 0 0
38365 - 0 0 0 0 0 0 0 0 0 0 0 0
38366 - 0 0 0 0 0 0 0 0 0 0 0 0
38367 - 0 0 0 0 0 0 0 0 0 0 0 0
38368 - 0 0 0 0 0 0 0 0 0 0 0 0
38369 - 0 0 0 0 0 0 0 0 0 0 0 0
38370 - 0 0 0 0 0 0 0 0 0 0 0 0
38371 - 0 0 0 0 0 0 0 0 0 0 0 0
38372 - 0 0 0 0 0 0 0 0 0 0 0 0
38373 - 0 0 0 0 0 0 0 0 0 0 0 0
38374 - 0 0 0 0 0 0 0 0 0 0 0 0
38375 - 0 0 0 0 0 0 6 6 6 18 18 18
38376 - 50 50 50 101 101 101 26 26 26 10 10 10
38377 -138 138 138 190 190 190 174 154 114 156 107 11
38378 -197 138 11 200 144 11 197 138 11 192 133 9
38379 -180 123 7 190 142 34 190 178 144 187 187 187
38380 -202 202 202 221 221 221 214 214 214 66 66 66
38381 - 2 2 6 2 2 6 50 50 50 62 62 62
38382 - 6 6 6 2 2 6 10 10 10 90 90 90
38383 - 50 50 50 18 18 18 6 6 6 0 0 0
38384 - 0 0 0 0 0 0 0 0 0 0 0 0
38385 - 0 0 0 0 0 0 0 0 0 0 0 0
38386 - 0 0 0 0 0 0 0 0 0 0 0 0
38387 - 0 0 0 0 0 0 0 0 0 0 0 0
38388 - 0 0 0 0 0 0 0 0 0 0 0 0
38389 - 0 0 0 0 0 0 0 0 0 0 0 0
38390 - 0 0 0 0 0 0 0 0 0 0 0 0
38391 - 0 0 0 0 0 0 0 0 0 0 0 0
38392 - 0 0 0 0 0 0 0 0 0 0 0 0
38393 - 0 0 0 0 0 0 0 0 0 0 0 0
38394 - 0 0 0 0 0 0 0 0 0 0 0 0
38395 - 0 0 0 0 0 0 10 10 10 34 34 34
38396 - 74 74 74 74 74 74 2 2 6 6 6 6
38397 -144 144 144 198 198 198 190 190 190 178 166 146
38398 -154 121 60 156 107 11 156 107 11 168 124 44
38399 -174 154 114 187 187 187 190 190 190 210 210 210
38400 -246 246 246 253 253 253 253 253 253 182 182 182
38401 - 6 6 6 2 2 6 2 2 6 2 2 6
38402 - 2 2 6 2 2 6 2 2 6 62 62 62
38403 - 74 74 74 34 34 34 14 14 14 0 0 0
38404 - 0 0 0 0 0 0 0 0 0 0 0 0
38405 - 0 0 0 0 0 0 0 0 0 0 0 0
38406 - 0 0 0 0 0 0 0 0 0 0 0 0
38407 - 0 0 0 0 0 0 0 0 0 0 0 0
38408 - 0 0 0 0 0 0 0 0 0 0 0 0
38409 - 0 0 0 0 0 0 0 0 0 0 0 0
38410 - 0 0 0 0 0 0 0 0 0 0 0 0
38411 - 0 0 0 0 0 0 0 0 0 0 0 0
38412 - 0 0 0 0 0 0 0 0 0 0 0 0
38413 - 0 0 0 0 0 0 0 0 0 0 0 0
38414 - 0 0 0 0 0 0 0 0 0 0 0 0
38415 - 0 0 0 10 10 10 22 22 22 54 54 54
38416 - 94 94 94 18 18 18 2 2 6 46 46 46
38417 -234 234 234 221 221 221 190 190 190 190 190 190
38418 -190 190 190 187 187 187 187 187 187 190 190 190
38419 -190 190 190 195 195 195 214 214 214 242 242 242
38420 -253 253 253 253 253 253 253 253 253 253 253 253
38421 - 82 82 82 2 2 6 2 2 6 2 2 6
38422 - 2 2 6 2 2 6 2 2 6 14 14 14
38423 - 86 86 86 54 54 54 22 22 22 6 6 6
38424 - 0 0 0 0 0 0 0 0 0 0 0 0
38425 - 0 0 0 0 0 0 0 0 0 0 0 0
38426 - 0 0 0 0 0 0 0 0 0 0 0 0
38427 - 0 0 0 0 0 0 0 0 0 0 0 0
38428 - 0 0 0 0 0 0 0 0 0 0 0 0
38429 - 0 0 0 0 0 0 0 0 0 0 0 0
38430 - 0 0 0 0 0 0 0 0 0 0 0 0
38431 - 0 0 0 0 0 0 0 0 0 0 0 0
38432 - 0 0 0 0 0 0 0 0 0 0 0 0
38433 - 0 0 0 0 0 0 0 0 0 0 0 0
38434 - 0 0 0 0 0 0 0 0 0 0 0 0
38435 - 6 6 6 18 18 18 46 46 46 90 90 90
38436 - 46 46 46 18 18 18 6 6 6 182 182 182
38437 -253 253 253 246 246 246 206 206 206 190 190 190
38438 -190 190 190 190 190 190 190 190 190 190 190 190
38439 -206 206 206 231 231 231 250 250 250 253 253 253
38440 -253 253 253 253 253 253 253 253 253 253 253 253
38441 -202 202 202 14 14 14 2 2 6 2 2 6
38442 - 2 2 6 2 2 6 2 2 6 2 2 6
38443 - 42 42 42 86 86 86 42 42 42 18 18 18
38444 - 6 6 6 0 0 0 0 0 0 0 0 0
38445 - 0 0 0 0 0 0 0 0 0 0 0 0
38446 - 0 0 0 0 0 0 0 0 0 0 0 0
38447 - 0 0 0 0 0 0 0 0 0 0 0 0
38448 - 0 0 0 0 0 0 0 0 0 0 0 0
38449 - 0 0 0 0 0 0 0 0 0 0 0 0
38450 - 0 0 0 0 0 0 0 0 0 0 0 0
38451 - 0 0 0 0 0 0 0 0 0 0 0 0
38452 - 0 0 0 0 0 0 0 0 0 0 0 0
38453 - 0 0 0 0 0 0 0 0 0 0 0 0
38454 - 0 0 0 0 0 0 0 0 0 6 6 6
38455 - 14 14 14 38 38 38 74 74 74 66 66 66
38456 - 2 2 6 6 6 6 90 90 90 250 250 250
38457 -253 253 253 253 253 253 238 238 238 198 198 198
38458 -190 190 190 190 190 190 195 195 195 221 221 221
38459 -246 246 246 253 253 253 253 253 253 253 253 253
38460 -253 253 253 253 253 253 253 253 253 253 253 253
38461 -253 253 253 82 82 82 2 2 6 2 2 6
38462 - 2 2 6 2 2 6 2 2 6 2 2 6
38463 - 2 2 6 78 78 78 70 70 70 34 34 34
38464 - 14 14 14 6 6 6 0 0 0 0 0 0
38465 - 0 0 0 0 0 0 0 0 0 0 0 0
38466 - 0 0 0 0 0 0 0 0 0 0 0 0
38467 - 0 0 0 0 0 0 0 0 0 0 0 0
38468 - 0 0 0 0 0 0 0 0 0 0 0 0
38469 - 0 0 0 0 0 0 0 0 0 0 0 0
38470 - 0 0 0 0 0 0 0 0 0 0 0 0
38471 - 0 0 0 0 0 0 0 0 0 0 0 0
38472 - 0 0 0 0 0 0 0 0 0 0 0 0
38473 - 0 0 0 0 0 0 0 0 0 0 0 0
38474 - 0 0 0 0 0 0 0 0 0 14 14 14
38475 - 34 34 34 66 66 66 78 78 78 6 6 6
38476 - 2 2 6 18 18 18 218 218 218 253 253 253
38477 -253 253 253 253 253 253 253 253 253 246 246 246
38478 -226 226 226 231 231 231 246 246 246 253 253 253
38479 -253 253 253 253 253 253 253 253 253 253 253 253
38480 -253 253 253 253 253 253 253 253 253 253 253 253
38481 -253 253 253 178 178 178 2 2 6 2 2 6
38482 - 2 2 6 2 2 6 2 2 6 2 2 6
38483 - 2 2 6 18 18 18 90 90 90 62 62 62
38484 - 30 30 30 10 10 10 0 0 0 0 0 0
38485 - 0 0 0 0 0 0 0 0 0 0 0 0
38486 - 0 0 0 0 0 0 0 0 0 0 0 0
38487 - 0 0 0 0 0 0 0 0 0 0 0 0
38488 - 0 0 0 0 0 0 0 0 0 0 0 0
38489 - 0 0 0 0 0 0 0 0 0 0 0 0
38490 - 0 0 0 0 0 0 0 0 0 0 0 0
38491 - 0 0 0 0 0 0 0 0 0 0 0 0
38492 - 0 0 0 0 0 0 0 0 0 0 0 0
38493 - 0 0 0 0 0 0 0 0 0 0 0 0
38494 - 0 0 0 0 0 0 10 10 10 26 26 26
38495 - 58 58 58 90 90 90 18 18 18 2 2 6
38496 - 2 2 6 110 110 110 253 253 253 253 253 253
38497 -253 253 253 253 253 253 253 253 253 253 253 253
38498 -250 250 250 253 253 253 253 253 253 253 253 253
38499 -253 253 253 253 253 253 253 253 253 253 253 253
38500 -253 253 253 253 253 253 253 253 253 253 253 253
38501 -253 253 253 231 231 231 18 18 18 2 2 6
38502 - 2 2 6 2 2 6 2 2 6 2 2 6
38503 - 2 2 6 2 2 6 18 18 18 94 94 94
38504 - 54 54 54 26 26 26 10 10 10 0 0 0
38505 - 0 0 0 0 0 0 0 0 0 0 0 0
38506 - 0 0 0 0 0 0 0 0 0 0 0 0
38507 - 0 0 0 0 0 0 0 0 0 0 0 0
38508 - 0 0 0 0 0 0 0 0 0 0 0 0
38509 - 0 0 0 0 0 0 0 0 0 0 0 0
38510 - 0 0 0 0 0 0 0 0 0 0 0 0
38511 - 0 0 0 0 0 0 0 0 0 0 0 0
38512 - 0 0 0 0 0 0 0 0 0 0 0 0
38513 - 0 0 0 0 0 0 0 0 0 0 0 0
38514 - 0 0 0 6 6 6 22 22 22 50 50 50
38515 - 90 90 90 26 26 26 2 2 6 2 2 6
38516 - 14 14 14 195 195 195 250 250 250 253 253 253
38517 -253 253 253 253 253 253 253 253 253 253 253 253
38518 -253 253 253 253 253 253 253 253 253 253 253 253
38519 -253 253 253 253 253 253 253 253 253 253 253 253
38520 -253 253 253 253 253 253 253 253 253 253 253 253
38521 -250 250 250 242 242 242 54 54 54 2 2 6
38522 - 2 2 6 2 2 6 2 2 6 2 2 6
38523 - 2 2 6 2 2 6 2 2 6 38 38 38
38524 - 86 86 86 50 50 50 22 22 22 6 6 6
38525 - 0 0 0 0 0 0 0 0 0 0 0 0
38526 - 0 0 0 0 0 0 0 0 0 0 0 0
38527 - 0 0 0 0 0 0 0 0 0 0 0 0
38528 - 0 0 0 0 0 0 0 0 0 0 0 0
38529 - 0 0 0 0 0 0 0 0 0 0 0 0
38530 - 0 0 0 0 0 0 0 0 0 0 0 0
38531 - 0 0 0 0 0 0 0 0 0 0 0 0
38532 - 0 0 0 0 0 0 0 0 0 0 0 0
38533 - 0 0 0 0 0 0 0 0 0 0 0 0
38534 - 6 6 6 14 14 14 38 38 38 82 82 82
38535 - 34 34 34 2 2 6 2 2 6 2 2 6
38536 - 42 42 42 195 195 195 246 246 246 253 253 253
38537 -253 253 253 253 253 253 253 253 253 250 250 250
38538 -242 242 242 242 242 242 250 250 250 253 253 253
38539 -253 253 253 253 253 253 253 253 253 253 253 253
38540 -253 253 253 250 250 250 246 246 246 238 238 238
38541 -226 226 226 231 231 231 101 101 101 6 6 6
38542 - 2 2 6 2 2 6 2 2 6 2 2 6
38543 - 2 2 6 2 2 6 2 2 6 2 2 6
38544 - 38 38 38 82 82 82 42 42 42 14 14 14
38545 - 6 6 6 0 0 0 0 0 0 0 0 0
38546 - 0 0 0 0 0 0 0 0 0 0 0 0
38547 - 0 0 0 0 0 0 0 0 0 0 0 0
38548 - 0 0 0 0 0 0 0 0 0 0 0 0
38549 - 0 0 0 0 0 0 0 0 0 0 0 0
38550 - 0 0 0 0 0 0 0 0 0 0 0 0
38551 - 0 0 0 0 0 0 0 0 0 0 0 0
38552 - 0 0 0 0 0 0 0 0 0 0 0 0
38553 - 0 0 0 0 0 0 0 0 0 0 0 0
38554 - 10 10 10 26 26 26 62 62 62 66 66 66
38555 - 2 2 6 2 2 6 2 2 6 6 6 6
38556 - 70 70 70 170 170 170 206 206 206 234 234 234
38557 -246 246 246 250 250 250 250 250 250 238 238 238
38558 -226 226 226 231 231 231 238 238 238 250 250 250
38559 -250 250 250 250 250 250 246 246 246 231 231 231
38560 -214 214 214 206 206 206 202 202 202 202 202 202
38561 -198 198 198 202 202 202 182 182 182 18 18 18
38562 - 2 2 6 2 2 6 2 2 6 2 2 6
38563 - 2 2 6 2 2 6 2 2 6 2 2 6
38564 - 2 2 6 62 62 62 66 66 66 30 30 30
38565 - 10 10 10 0 0 0 0 0 0 0 0 0
38566 - 0 0 0 0 0 0 0 0 0 0 0 0
38567 - 0 0 0 0 0 0 0 0 0 0 0 0
38568 - 0 0 0 0 0 0 0 0 0 0 0 0
38569 - 0 0 0 0 0 0 0 0 0 0 0 0
38570 - 0 0 0 0 0 0 0 0 0 0 0 0
38571 - 0 0 0 0 0 0 0 0 0 0 0 0
38572 - 0 0 0 0 0 0 0 0 0 0 0 0
38573 - 0 0 0 0 0 0 0 0 0 0 0 0
38574 - 14 14 14 42 42 42 82 82 82 18 18 18
38575 - 2 2 6 2 2 6 2 2 6 10 10 10
38576 - 94 94 94 182 182 182 218 218 218 242 242 242
38577 -250 250 250 253 253 253 253 253 253 250 250 250
38578 -234 234 234 253 253 253 253 253 253 253 253 253
38579 -253 253 253 253 253 253 253 253 253 246 246 246
38580 -238 238 238 226 226 226 210 210 210 202 202 202
38581 -195 195 195 195 195 195 210 210 210 158 158 158
38582 - 6 6 6 14 14 14 50 50 50 14 14 14
38583 - 2 2 6 2 2 6 2 2 6 2 2 6
38584 - 2 2 6 6 6 6 86 86 86 46 46 46
38585 - 18 18 18 6 6 6 0 0 0 0 0 0
38586 - 0 0 0 0 0 0 0 0 0 0 0 0
38587 - 0 0 0 0 0 0 0 0 0 0 0 0
38588 - 0 0 0 0 0 0 0 0 0 0 0 0
38589 - 0 0 0 0 0 0 0 0 0 0 0 0
38590 - 0 0 0 0 0 0 0 0 0 0 0 0
38591 - 0 0 0 0 0 0 0 0 0 0 0 0
38592 - 0 0 0 0 0 0 0 0 0 0 0 0
38593 - 0 0 0 0 0 0 0 0 0 6 6 6
38594 - 22 22 22 54 54 54 70 70 70 2 2 6
38595 - 2 2 6 10 10 10 2 2 6 22 22 22
38596 -166 166 166 231 231 231 250 250 250 253 253 253
38597 -253 253 253 253 253 253 253 253 253 250 250 250
38598 -242 242 242 253 253 253 253 253 253 253 253 253
38599 -253 253 253 253 253 253 253 253 253 253 253 253
38600 -253 253 253 253 253 253 253 253 253 246 246 246
38601 -231 231 231 206 206 206 198 198 198 226 226 226
38602 - 94 94 94 2 2 6 6 6 6 38 38 38
38603 - 30 30 30 2 2 6 2 2 6 2 2 6
38604 - 2 2 6 2 2 6 62 62 62 66 66 66
38605 - 26 26 26 10 10 10 0 0 0 0 0 0
38606 - 0 0 0 0 0 0 0 0 0 0 0 0
38607 - 0 0 0 0 0 0 0 0 0 0 0 0
38608 - 0 0 0 0 0 0 0 0 0 0 0 0
38609 - 0 0 0 0 0 0 0 0 0 0 0 0
38610 - 0 0 0 0 0 0 0 0 0 0 0 0
38611 - 0 0 0 0 0 0 0 0 0 0 0 0
38612 - 0 0 0 0 0 0 0 0 0 0 0 0
38613 - 0 0 0 0 0 0 0 0 0 10 10 10
38614 - 30 30 30 74 74 74 50 50 50 2 2 6
38615 - 26 26 26 26 26 26 2 2 6 106 106 106
38616 -238 238 238 253 253 253 253 253 253 253 253 253
38617 -253 253 253 253 253 253 253 253 253 253 253 253
38618 -253 253 253 253 253 253 253 253 253 253 253 253
38619 -253 253 253 253 253 253 253 253 253 253 253 253
38620 -253 253 253 253 253 253 253 253 253 253 253 253
38621 -253 253 253 246 246 246 218 218 218 202 202 202
38622 -210 210 210 14 14 14 2 2 6 2 2 6
38623 - 30 30 30 22 22 22 2 2 6 2 2 6
38624 - 2 2 6 2 2 6 18 18 18 86 86 86
38625 - 42 42 42 14 14 14 0 0 0 0 0 0
38626 - 0 0 0 0 0 0 0 0 0 0 0 0
38627 - 0 0 0 0 0 0 0 0 0 0 0 0
38628 - 0 0 0 0 0 0 0 0 0 0 0 0
38629 - 0 0 0 0 0 0 0 0 0 0 0 0
38630 - 0 0 0 0 0 0 0 0 0 0 0 0
38631 - 0 0 0 0 0 0 0 0 0 0 0 0
38632 - 0 0 0 0 0 0 0 0 0 0 0 0
38633 - 0 0 0 0 0 0 0 0 0 14 14 14
38634 - 42 42 42 90 90 90 22 22 22 2 2 6
38635 - 42 42 42 2 2 6 18 18 18 218 218 218
38636 -253 253 253 253 253 253 253 253 253 253 253 253
38637 -253 253 253 253 253 253 253 253 253 253 253 253
38638 -253 253 253 253 253 253 253 253 253 253 253 253
38639 -253 253 253 253 253 253 253 253 253 253 253 253
38640 -253 253 253 253 253 253 253 253 253 253 253 253
38641 -253 253 253 253 253 253 250 250 250 221 221 221
38642 -218 218 218 101 101 101 2 2 6 14 14 14
38643 - 18 18 18 38 38 38 10 10 10 2 2 6
38644 - 2 2 6 2 2 6 2 2 6 78 78 78
38645 - 58 58 58 22 22 22 6 6 6 0 0 0
38646 - 0 0 0 0 0 0 0 0 0 0 0 0
38647 - 0 0 0 0 0 0 0 0 0 0 0 0
38648 - 0 0 0 0 0 0 0 0 0 0 0 0
38649 - 0 0 0 0 0 0 0 0 0 0 0 0
38650 - 0 0 0 0 0 0 0 0 0 0 0 0
38651 - 0 0 0 0 0 0 0 0 0 0 0 0
38652 - 0 0 0 0 0 0 0 0 0 0 0 0
38653 - 0 0 0 0 0 0 6 6 6 18 18 18
38654 - 54 54 54 82 82 82 2 2 6 26 26 26
38655 - 22 22 22 2 2 6 123 123 123 253 253 253
38656 -253 253 253 253 253 253 253 253 253 253 253 253
38657 -253 253 253 253 253 253 253 253 253 253 253 253
38658 -253 253 253 253 253 253 253 253 253 253 253 253
38659 -253 253 253 253 253 253 253 253 253 253 253 253
38660 -253 253 253 253 253 253 253 253 253 253 253 253
38661 -253 253 253 253 253 253 253 253 253 250 250 250
38662 -238 238 238 198 198 198 6 6 6 38 38 38
38663 - 58 58 58 26 26 26 38 38 38 2 2 6
38664 - 2 2 6 2 2 6 2 2 6 46 46 46
38665 - 78 78 78 30 30 30 10 10 10 0 0 0
38666 - 0 0 0 0 0 0 0 0 0 0 0 0
38667 - 0 0 0 0 0 0 0 0 0 0 0 0
38668 - 0 0 0 0 0 0 0 0 0 0 0 0
38669 - 0 0 0 0 0 0 0 0 0 0 0 0
38670 - 0 0 0 0 0 0 0 0 0 0 0 0
38671 - 0 0 0 0 0 0 0 0 0 0 0 0
38672 - 0 0 0 0 0 0 0 0 0 0 0 0
38673 - 0 0 0 0 0 0 10 10 10 30 30 30
38674 - 74 74 74 58 58 58 2 2 6 42 42 42
38675 - 2 2 6 22 22 22 231 231 231 253 253 253
38676 -253 253 253 253 253 253 253 253 253 253 253 253
38677 -253 253 253 253 253 253 253 253 253 250 250 250
38678 -253 253 253 253 253 253 253 253 253 253 253 253
38679 -253 253 253 253 253 253 253 253 253 253 253 253
38680 -253 253 253 253 253 253 253 253 253 253 253 253
38681 -253 253 253 253 253 253 253 253 253 253 253 253
38682 -253 253 253 246 246 246 46 46 46 38 38 38
38683 - 42 42 42 14 14 14 38 38 38 14 14 14
38684 - 2 2 6 2 2 6 2 2 6 6 6 6
38685 - 86 86 86 46 46 46 14 14 14 0 0 0
38686 - 0 0 0 0 0 0 0 0 0 0 0 0
38687 - 0 0 0 0 0 0 0 0 0 0 0 0
38688 - 0 0 0 0 0 0 0 0 0 0 0 0
38689 - 0 0 0 0 0 0 0 0 0 0 0 0
38690 - 0 0 0 0 0 0 0 0 0 0 0 0
38691 - 0 0 0 0 0 0 0 0 0 0 0 0
38692 - 0 0 0 0 0 0 0 0 0 0 0 0
38693 - 0 0 0 6 6 6 14 14 14 42 42 42
38694 - 90 90 90 18 18 18 18 18 18 26 26 26
38695 - 2 2 6 116 116 116 253 253 253 253 253 253
38696 -253 253 253 253 253 253 253 253 253 253 253 253
38697 -253 253 253 253 253 253 250 250 250 238 238 238
38698 -253 253 253 253 253 253 253 253 253 253 253 253
38699 -253 253 253 253 253 253 253 253 253 253 253 253
38700 -253 253 253 253 253 253 253 253 253 253 253 253
38701 -253 253 253 253 253 253 253 253 253 253 253 253
38702 -253 253 253 253 253 253 94 94 94 6 6 6
38703 - 2 2 6 2 2 6 10 10 10 34 34 34
38704 - 2 2 6 2 2 6 2 2 6 2 2 6
38705 - 74 74 74 58 58 58 22 22 22 6 6 6
38706 - 0 0 0 0 0 0 0 0 0 0 0 0
38707 - 0 0 0 0 0 0 0 0 0 0 0 0
38708 - 0 0 0 0 0 0 0 0 0 0 0 0
38709 - 0 0 0 0 0 0 0 0 0 0 0 0
38710 - 0 0 0 0 0 0 0 0 0 0 0 0
38711 - 0 0 0 0 0 0 0 0 0 0 0 0
38712 - 0 0 0 0 0 0 0 0 0 0 0 0
38713 - 0 0 0 10 10 10 26 26 26 66 66 66
38714 - 82 82 82 2 2 6 38 38 38 6 6 6
38715 - 14 14 14 210 210 210 253 253 253 253 253 253
38716 -253 253 253 253 253 253 253 253 253 253 253 253
38717 -253 253 253 253 253 253 246 246 246 242 242 242
38718 -253 253 253 253 253 253 253 253 253 253 253 253
38719 -253 253 253 253 253 253 253 253 253 253 253 253
38720 -253 253 253 253 253 253 253 253 253 253 253 253
38721 -253 253 253 253 253 253 253 253 253 253 253 253
38722 -253 253 253 253 253 253 144 144 144 2 2 6
38723 - 2 2 6 2 2 6 2 2 6 46 46 46
38724 - 2 2 6 2 2 6 2 2 6 2 2 6
38725 - 42 42 42 74 74 74 30 30 30 10 10 10
38726 - 0 0 0 0 0 0 0 0 0 0 0 0
38727 - 0 0 0 0 0 0 0 0 0 0 0 0
38728 - 0 0 0 0 0 0 0 0 0 0 0 0
38729 - 0 0 0 0 0 0 0 0 0 0 0 0
38730 - 0 0 0 0 0 0 0 0 0 0 0 0
38731 - 0 0 0 0 0 0 0 0 0 0 0 0
38732 - 0 0 0 0 0 0 0 0 0 0 0 0
38733 - 6 6 6 14 14 14 42 42 42 90 90 90
38734 - 26 26 26 6 6 6 42 42 42 2 2 6
38735 - 74 74 74 250 250 250 253 253 253 253 253 253
38736 -253 253 253 253 253 253 253 253 253 253 253 253
38737 -253 253 253 253 253 253 242 242 242 242 242 242
38738 -253 253 253 253 253 253 253 253 253 253 253 253
38739 -253 253 253 253 253 253 253 253 253 253 253 253
38740 -253 253 253 253 253 253 253 253 253 253 253 253
38741 -253 253 253 253 253 253 253 253 253 253 253 253
38742 -253 253 253 253 253 253 182 182 182 2 2 6
38743 - 2 2 6 2 2 6 2 2 6 46 46 46
38744 - 2 2 6 2 2 6 2 2 6 2 2 6
38745 - 10 10 10 86 86 86 38 38 38 10 10 10
38746 - 0 0 0 0 0 0 0 0 0 0 0 0
38747 - 0 0 0 0 0 0 0 0 0 0 0 0
38748 - 0 0 0 0 0 0 0 0 0 0 0 0
38749 - 0 0 0 0 0 0 0 0 0 0 0 0
38750 - 0 0 0 0 0 0 0 0 0 0 0 0
38751 - 0 0 0 0 0 0 0 0 0 0 0 0
38752 - 0 0 0 0 0 0 0 0 0 0 0 0
38753 - 10 10 10 26 26 26 66 66 66 82 82 82
38754 - 2 2 6 22 22 22 18 18 18 2 2 6
38755 -149 149 149 253 253 253 253 253 253 253 253 253
38756 -253 253 253 253 253 253 253 253 253 253 253 253
38757 -253 253 253 253 253 253 234 234 234 242 242 242
38758 -253 253 253 253 253 253 253 253 253 253 253 253
38759 -253 253 253 253 253 253 253 253 253 253 253 253
38760 -253 253 253 253 253 253 253 253 253 253 253 253
38761 -253 253 253 253 253 253 253 253 253 253 253 253
38762 -253 253 253 253 253 253 206 206 206 2 2 6
38763 - 2 2 6 2 2 6 2 2 6 38 38 38
38764 - 2 2 6 2 2 6 2 2 6 2 2 6
38765 - 6 6 6 86 86 86 46 46 46 14 14 14
38766 - 0 0 0 0 0 0 0 0 0 0 0 0
38767 - 0 0 0 0 0 0 0 0 0 0 0 0
38768 - 0 0 0 0 0 0 0 0 0 0 0 0
38769 - 0 0 0 0 0 0 0 0 0 0 0 0
38770 - 0 0 0 0 0 0 0 0 0 0 0 0
38771 - 0 0 0 0 0 0 0 0 0 0 0 0
38772 - 0 0 0 0 0 0 0 0 0 6 6 6
38773 - 18 18 18 46 46 46 86 86 86 18 18 18
38774 - 2 2 6 34 34 34 10 10 10 6 6 6
38775 -210 210 210 253 253 253 253 253 253 253 253 253
38776 -253 253 253 253 253 253 253 253 253 253 253 253
38777 -253 253 253 253 253 253 234 234 234 242 242 242
38778 -253 253 253 253 253 253 253 253 253 253 253 253
38779 -253 253 253 253 253 253 253 253 253 253 253 253
38780 -253 253 253 253 253 253 253 253 253 253 253 253
38781 -253 253 253 253 253 253 253 253 253 253 253 253
38782 -253 253 253 253 253 253 221 221 221 6 6 6
38783 - 2 2 6 2 2 6 6 6 6 30 30 30
38784 - 2 2 6 2 2 6 2 2 6 2 2 6
38785 - 2 2 6 82 82 82 54 54 54 18 18 18
38786 - 6 6 6 0 0 0 0 0 0 0 0 0
38787 - 0 0 0 0 0 0 0 0 0 0 0 0
38788 - 0 0 0 0 0 0 0 0 0 0 0 0
38789 - 0 0 0 0 0 0 0 0 0 0 0 0
38790 - 0 0 0 0 0 0 0 0 0 0 0 0
38791 - 0 0 0 0 0 0 0 0 0 0 0 0
38792 - 0 0 0 0 0 0 0 0 0 10 10 10
38793 - 26 26 26 66 66 66 62 62 62 2 2 6
38794 - 2 2 6 38 38 38 10 10 10 26 26 26
38795 -238 238 238 253 253 253 253 253 253 253 253 253
38796 -253 253 253 253 253 253 253 253 253 253 253 253
38797 -253 253 253 253 253 253 231 231 231 238 238 238
38798 -253 253 253 253 253 253 253 253 253 253 253 253
38799 -253 253 253 253 253 253 253 253 253 253 253 253
38800 -253 253 253 253 253 253 253 253 253 253 253 253
38801 -253 253 253 253 253 253 253 253 253 253 253 253
38802 -253 253 253 253 253 253 231 231 231 6 6 6
38803 - 2 2 6 2 2 6 10 10 10 30 30 30
38804 - 2 2 6 2 2 6 2 2 6 2 2 6
38805 - 2 2 6 66 66 66 58 58 58 22 22 22
38806 - 6 6 6 0 0 0 0 0 0 0 0 0
38807 - 0 0 0 0 0 0 0 0 0 0 0 0
38808 - 0 0 0 0 0 0 0 0 0 0 0 0
38809 - 0 0 0 0 0 0 0 0 0 0 0 0
38810 - 0 0 0 0 0 0 0 0 0 0 0 0
38811 - 0 0 0 0 0 0 0 0 0 0 0 0
38812 - 0 0 0 0 0 0 0 0 0 10 10 10
38813 - 38 38 38 78 78 78 6 6 6 2 2 6
38814 - 2 2 6 46 46 46 14 14 14 42 42 42
38815 -246 246 246 253 253 253 253 253 253 253 253 253
38816 -253 253 253 253 253 253 253 253 253 253 253 253
38817 -253 253 253 253 253 253 231 231 231 242 242 242
38818 -253 253 253 253 253 253 253 253 253 253 253 253
38819 -253 253 253 253 253 253 253 253 253 253 253 253
38820 -253 253 253 253 253 253 253 253 253 253 253 253
38821 -253 253 253 253 253 253 253 253 253 253 253 253
38822 -253 253 253 253 253 253 234 234 234 10 10 10
38823 - 2 2 6 2 2 6 22 22 22 14 14 14
38824 - 2 2 6 2 2 6 2 2 6 2 2 6
38825 - 2 2 6 66 66 66 62 62 62 22 22 22
38826 - 6 6 6 0 0 0 0 0 0 0 0 0
38827 - 0 0 0 0 0 0 0 0 0 0 0 0
38828 - 0 0 0 0 0 0 0 0 0 0 0 0
38829 - 0 0 0 0 0 0 0 0 0 0 0 0
38830 - 0 0 0 0 0 0 0 0 0 0 0 0
38831 - 0 0 0 0 0 0 0 0 0 0 0 0
38832 - 0 0 0 0 0 0 6 6 6 18 18 18
38833 - 50 50 50 74 74 74 2 2 6 2 2 6
38834 - 14 14 14 70 70 70 34 34 34 62 62 62
38835 -250 250 250 253 253 253 253 253 253 253 253 253
38836 -253 253 253 253 253 253 253 253 253 253 253 253
38837 -253 253 253 253 253 253 231 231 231 246 246 246
38838 -253 253 253 253 253 253 253 253 253 253 253 253
38839 -253 253 253 253 253 253 253 253 253 253 253 253
38840 -253 253 253 253 253 253 253 253 253 253 253 253
38841 -253 253 253 253 253 253 253 253 253 253 253 253
38842 -253 253 253 253 253 253 234 234 234 14 14 14
38843 - 2 2 6 2 2 6 30 30 30 2 2 6
38844 - 2 2 6 2 2 6 2 2 6 2 2 6
38845 - 2 2 6 66 66 66 62 62 62 22 22 22
38846 - 6 6 6 0 0 0 0 0 0 0 0 0
38847 - 0 0 0 0 0 0 0 0 0 0 0 0
38848 - 0 0 0 0 0 0 0 0 0 0 0 0
38849 - 0 0 0 0 0 0 0 0 0 0 0 0
38850 - 0 0 0 0 0 0 0 0 0 0 0 0
38851 - 0 0 0 0 0 0 0 0 0 0 0 0
38852 - 0 0 0 0 0 0 6 6 6 18 18 18
38853 - 54 54 54 62 62 62 2 2 6 2 2 6
38854 - 2 2 6 30 30 30 46 46 46 70 70 70
38855 -250 250 250 253 253 253 253 253 253 253 253 253
38856 -253 253 253 253 253 253 253 253 253 253 253 253
38857 -253 253 253 253 253 253 231 231 231 246 246 246
38858 -253 253 253 253 253 253 253 253 253 253 253 253
38859 -253 253 253 253 253 253 253 253 253 253 253 253
38860 -253 253 253 253 253 253 253 253 253 253 253 253
38861 -253 253 253 253 253 253 253 253 253 253 253 253
38862 -253 253 253 253 253 253 226 226 226 10 10 10
38863 - 2 2 6 6 6 6 30 30 30 2 2 6
38864 - 2 2 6 2 2 6 2 2 6 2 2 6
38865 - 2 2 6 66 66 66 58 58 58 22 22 22
38866 - 6 6 6 0 0 0 0 0 0 0 0 0
38867 - 0 0 0 0 0 0 0 0 0 0 0 0
38868 - 0 0 0 0 0 0 0 0 0 0 0 0
38869 - 0 0 0 0 0 0 0 0 0 0 0 0
38870 - 0 0 0 0 0 0 0 0 0 0 0 0
38871 - 0 0 0 0 0 0 0 0 0 0 0 0
38872 - 0 0 0 0 0 0 6 6 6 22 22 22
38873 - 58 58 58 62 62 62 2 2 6 2 2 6
38874 - 2 2 6 2 2 6 30 30 30 78 78 78
38875 -250 250 250 253 253 253 253 253 253 253 253 253
38876 -253 253 253 253 253 253 253 253 253 253 253 253
38877 -253 253 253 253 253 253 231 231 231 246 246 246
38878 -253 253 253 253 253 253 253 253 253 253 253 253
38879 -253 253 253 253 253 253 253 253 253 253 253 253
38880 -253 253 253 253 253 253 253 253 253 253 253 253
38881 -253 253 253 253 253 253 253 253 253 253 253 253
38882 -253 253 253 253 253 253 206 206 206 2 2 6
38883 - 22 22 22 34 34 34 18 14 6 22 22 22
38884 - 26 26 26 18 18 18 6 6 6 2 2 6
38885 - 2 2 6 82 82 82 54 54 54 18 18 18
38886 - 6 6 6 0 0 0 0 0 0 0 0 0
38887 - 0 0 0 0 0 0 0 0 0 0 0 0
38888 - 0 0 0 0 0 0 0 0 0 0 0 0
38889 - 0 0 0 0 0 0 0 0 0 0 0 0
38890 - 0 0 0 0 0 0 0 0 0 0 0 0
38891 - 0 0 0 0 0 0 0 0 0 0 0 0
38892 - 0 0 0 0 0 0 6 6 6 26 26 26
38893 - 62 62 62 106 106 106 74 54 14 185 133 11
38894 -210 162 10 121 92 8 6 6 6 62 62 62
38895 -238 238 238 253 253 253 253 253 253 253 253 253
38896 -253 253 253 253 253 253 253 253 253 253 253 253
38897 -253 253 253 253 253 253 231 231 231 246 246 246
38898 -253 253 253 253 253 253 253 253 253 253 253 253
38899 -253 253 253 253 253 253 253 253 253 253 253 253
38900 -253 253 253 253 253 253 253 253 253 253 253 253
38901 -253 253 253 253 253 253 253 253 253 253 253 253
38902 -253 253 253 253 253 253 158 158 158 18 18 18
38903 - 14 14 14 2 2 6 2 2 6 2 2 6
38904 - 6 6 6 18 18 18 66 66 66 38 38 38
38905 - 6 6 6 94 94 94 50 50 50 18 18 18
38906 - 6 6 6 0 0 0 0 0 0 0 0 0
38907 - 0 0 0 0 0 0 0 0 0 0 0 0
38908 - 0 0 0 0 0 0 0 0 0 0 0 0
38909 - 0 0 0 0 0 0 0 0 0 0 0 0
38910 - 0 0 0 0 0 0 0 0 0 0 0 0
38911 - 0 0 0 0 0 0 0 0 0 6 6 6
38912 - 10 10 10 10 10 10 18 18 18 38 38 38
38913 - 78 78 78 142 134 106 216 158 10 242 186 14
38914 -246 190 14 246 190 14 156 118 10 10 10 10
38915 - 90 90 90 238 238 238 253 253 253 253 253 253
38916 -253 253 253 253 253 253 253 253 253 253 253 253
38917 -253 253 253 253 253 253 231 231 231 250 250 250
38918 -253 253 253 253 253 253 253 253 253 253 253 253
38919 -253 253 253 253 253 253 253 253 253 253 253 253
38920 -253 253 253 253 253 253 253 253 253 253 253 253
38921 -253 253 253 253 253 253 253 253 253 246 230 190
38922 -238 204 91 238 204 91 181 142 44 37 26 9
38923 - 2 2 6 2 2 6 2 2 6 2 2 6
38924 - 2 2 6 2 2 6 38 38 38 46 46 46
38925 - 26 26 26 106 106 106 54 54 54 18 18 18
38926 - 6 6 6 0 0 0 0 0 0 0 0 0
38927 - 0 0 0 0 0 0 0 0 0 0 0 0
38928 - 0 0 0 0 0 0 0 0 0 0 0 0
38929 - 0 0 0 0 0 0 0 0 0 0 0 0
38930 - 0 0 0 0 0 0 0 0 0 0 0 0
38931 - 0 0 0 6 6 6 14 14 14 22 22 22
38932 - 30 30 30 38 38 38 50 50 50 70 70 70
38933 -106 106 106 190 142 34 226 170 11 242 186 14
38934 -246 190 14 246 190 14 246 190 14 154 114 10
38935 - 6 6 6 74 74 74 226 226 226 253 253 253
38936 -253 253 253 253 253 253 253 253 253 253 253 253
38937 -253 253 253 253 253 253 231 231 231 250 250 250
38938 -253 253 253 253 253 253 253 253 253 253 253 253
38939 -253 253 253 253 253 253 253 253 253 253 253 253
38940 -253 253 253 253 253 253 253 253 253 253 253 253
38941 -253 253 253 253 253 253 253 253 253 228 184 62
38942 -241 196 14 241 208 19 232 195 16 38 30 10
38943 - 2 2 6 2 2 6 2 2 6 2 2 6
38944 - 2 2 6 6 6 6 30 30 30 26 26 26
38945 -203 166 17 154 142 90 66 66 66 26 26 26
38946 - 6 6 6 0 0 0 0 0 0 0 0 0
38947 - 0 0 0 0 0 0 0 0 0 0 0 0
38948 - 0 0 0 0 0 0 0 0 0 0 0 0
38949 - 0 0 0 0 0 0 0 0 0 0 0 0
38950 - 0 0 0 0 0 0 0 0 0 0 0 0
38951 - 6 6 6 18 18 18 38 38 38 58 58 58
38952 - 78 78 78 86 86 86 101 101 101 123 123 123
38953 -175 146 61 210 150 10 234 174 13 246 186 14
38954 -246 190 14 246 190 14 246 190 14 238 190 10
38955 -102 78 10 2 2 6 46 46 46 198 198 198
38956 -253 253 253 253 253 253 253 253 253 253 253 253
38957 -253 253 253 253 253 253 234 234 234 242 242 242
38958 -253 253 253 253 253 253 253 253 253 253 253 253
38959 -253 253 253 253 253 253 253 253 253 253 253 253
38960 -253 253 253 253 253 253 253 253 253 253 253 253
38961 -253 253 253 253 253 253 253 253 253 224 178 62
38962 -242 186 14 241 196 14 210 166 10 22 18 6
38963 - 2 2 6 2 2 6 2 2 6 2 2 6
38964 - 2 2 6 2 2 6 6 6 6 121 92 8
38965 -238 202 15 232 195 16 82 82 82 34 34 34
38966 - 10 10 10 0 0 0 0 0 0 0 0 0
38967 - 0 0 0 0 0 0 0 0 0 0 0 0
38968 - 0 0 0 0 0 0 0 0 0 0 0 0
38969 - 0 0 0 0 0 0 0 0 0 0 0 0
38970 - 0 0 0 0 0 0 0 0 0 0 0 0
38971 - 14 14 14 38 38 38 70 70 70 154 122 46
38972 -190 142 34 200 144 11 197 138 11 197 138 11
38973 -213 154 11 226 170 11 242 186 14 246 190 14
38974 -246 190 14 246 190 14 246 190 14 246 190 14
38975 -225 175 15 46 32 6 2 2 6 22 22 22
38976 -158 158 158 250 250 250 253 253 253 253 253 253
38977 -253 253 253 253 253 253 253 253 253 253 253 253
38978 -253 253 253 253 253 253 253 253 253 253 253 253
38979 -253 253 253 253 253 253 253 253 253 253 253 253
38980 -253 253 253 253 253 253 253 253 253 253 253 253
38981 -253 253 253 250 250 250 242 242 242 224 178 62
38982 -239 182 13 236 186 11 213 154 11 46 32 6
38983 - 2 2 6 2 2 6 2 2 6 2 2 6
38984 - 2 2 6 2 2 6 61 42 6 225 175 15
38985 -238 190 10 236 186 11 112 100 78 42 42 42
38986 - 14 14 14 0 0 0 0 0 0 0 0 0
38987 - 0 0 0 0 0 0 0 0 0 0 0 0
38988 - 0 0 0 0 0 0 0 0 0 0 0 0
38989 - 0 0 0 0 0 0 0 0 0 0 0 0
38990 - 0 0 0 0 0 0 0 0 0 6 6 6
38991 - 22 22 22 54 54 54 154 122 46 213 154 11
38992 -226 170 11 230 174 11 226 170 11 226 170 11
38993 -236 178 12 242 186 14 246 190 14 246 190 14
38994 -246 190 14 246 190 14 246 190 14 246 190 14
38995 -241 196 14 184 144 12 10 10 10 2 2 6
38996 - 6 6 6 116 116 116 242 242 242 253 253 253
38997 -253 253 253 253 253 253 253 253 253 253 253 253
38998 -253 253 253 253 253 253 253 253 253 253 253 253
38999 -253 253 253 253 253 253 253 253 253 253 253 253
39000 -253 253 253 253 253 253 253 253 253 253 253 253
39001 -253 253 253 231 231 231 198 198 198 214 170 54
39002 -236 178 12 236 178 12 210 150 10 137 92 6
39003 - 18 14 6 2 2 6 2 2 6 2 2 6
39004 - 6 6 6 70 47 6 200 144 11 236 178 12
39005 -239 182 13 239 182 13 124 112 88 58 58 58
39006 - 22 22 22 6 6 6 0 0 0 0 0 0
39007 - 0 0 0 0 0 0 0 0 0 0 0 0
39008 - 0 0 0 0 0 0 0 0 0 0 0 0
39009 - 0 0 0 0 0 0 0 0 0 0 0 0
39010 - 0 0 0 0 0 0 0 0 0 10 10 10
39011 - 30 30 30 70 70 70 180 133 36 226 170 11
39012 -239 182 13 242 186 14 242 186 14 246 186 14
39013 -246 190 14 246 190 14 246 190 14 246 190 14
39014 -246 190 14 246 190 14 246 190 14 246 190 14
39015 -246 190 14 232 195 16 98 70 6 2 2 6
39016 - 2 2 6 2 2 6 66 66 66 221 221 221
39017 -253 253 253 253 253 253 253 253 253 253 253 253
39018 -253 253 253 253 253 253 253 253 253 253 253 253
39019 -253 253 253 253 253 253 253 253 253 253 253 253
39020 -253 253 253 253 253 253 253 253 253 253 253 253
39021 -253 253 253 206 206 206 198 198 198 214 166 58
39022 -230 174 11 230 174 11 216 158 10 192 133 9
39023 -163 110 8 116 81 8 102 78 10 116 81 8
39024 -167 114 7 197 138 11 226 170 11 239 182 13
39025 -242 186 14 242 186 14 162 146 94 78 78 78
39026 - 34 34 34 14 14 14 6 6 6 0 0 0
39027 - 0 0 0 0 0 0 0 0 0 0 0 0
39028 - 0 0 0 0 0 0 0 0 0 0 0 0
39029 - 0 0 0 0 0 0 0 0 0 0 0 0
39030 - 0 0 0 0 0 0 0 0 0 6 6 6
39031 - 30 30 30 78 78 78 190 142 34 226 170 11
39032 -239 182 13 246 190 14 246 190 14 246 190 14
39033 -246 190 14 246 190 14 246 190 14 246 190 14
39034 -246 190 14 246 190 14 246 190 14 246 190 14
39035 -246 190 14 241 196 14 203 166 17 22 18 6
39036 - 2 2 6 2 2 6 2 2 6 38 38 38
39037 -218 218 218 253 253 253 253 253 253 253 253 253
39038 -253 253 253 253 253 253 253 253 253 253 253 253
39039 -253 253 253 253 253 253 253 253 253 253 253 253
39040 -253 253 253 253 253 253 253 253 253 253 253 253
39041 -250 250 250 206 206 206 198 198 198 202 162 69
39042 -226 170 11 236 178 12 224 166 10 210 150 10
39043 -200 144 11 197 138 11 192 133 9 197 138 11
39044 -210 150 10 226 170 11 242 186 14 246 190 14
39045 -246 190 14 246 186 14 225 175 15 124 112 88
39046 - 62 62 62 30 30 30 14 14 14 6 6 6
39047 - 0 0 0 0 0 0 0 0 0 0 0 0
39048 - 0 0 0 0 0 0 0 0 0 0 0 0
39049 - 0 0 0 0 0 0 0 0 0 0 0 0
39050 - 0 0 0 0 0 0 0 0 0 10 10 10
39051 - 30 30 30 78 78 78 174 135 50 224 166 10
39052 -239 182 13 246 190 14 246 190 14 246 190 14
39053 -246 190 14 246 190 14 246 190 14 246 190 14
39054 -246 190 14 246 190 14 246 190 14 246 190 14
39055 -246 190 14 246 190 14 241 196 14 139 102 15
39056 - 2 2 6 2 2 6 2 2 6 2 2 6
39057 - 78 78 78 250 250 250 253 253 253 253 253 253
39058 -253 253 253 253 253 253 253 253 253 253 253 253
39059 -253 253 253 253 253 253 253 253 253 253 253 253
39060 -253 253 253 253 253 253 253 253 253 253 253 253
39061 -250 250 250 214 214 214 198 198 198 190 150 46
39062 -219 162 10 236 178 12 234 174 13 224 166 10
39063 -216 158 10 213 154 11 213 154 11 216 158 10
39064 -226 170 11 239 182 13 246 190 14 246 190 14
39065 -246 190 14 246 190 14 242 186 14 206 162 42
39066 -101 101 101 58 58 58 30 30 30 14 14 14
39067 - 6 6 6 0 0 0 0 0 0 0 0 0
39068 - 0 0 0 0 0 0 0 0 0 0 0 0
39069 - 0 0 0 0 0 0 0 0 0 0 0 0
39070 - 0 0 0 0 0 0 0 0 0 10 10 10
39071 - 30 30 30 74 74 74 174 135 50 216 158 10
39072 -236 178 12 246 190 14 246 190 14 246 190 14
39073 -246 190 14 246 190 14 246 190 14 246 190 14
39074 -246 190 14 246 190 14 246 190 14 246 190 14
39075 -246 190 14 246 190 14 241 196 14 226 184 13
39076 - 61 42 6 2 2 6 2 2 6 2 2 6
39077 - 22 22 22 238 238 238 253 253 253 253 253 253
39078 -253 253 253 253 253 253 253 253 253 253 253 253
39079 -253 253 253 253 253 253 253 253 253 253 253 253
39080 -253 253 253 253 253 253 253 253 253 253 253 253
39081 -253 253 253 226 226 226 187 187 187 180 133 36
39082 -216 158 10 236 178 12 239 182 13 236 178 12
39083 -230 174 11 226 170 11 226 170 11 230 174 11
39084 -236 178 12 242 186 14 246 190 14 246 190 14
39085 -246 190 14 246 190 14 246 186 14 239 182 13
39086 -206 162 42 106 106 106 66 66 66 34 34 34
39087 - 14 14 14 6 6 6 0 0 0 0 0 0
39088 - 0 0 0 0 0 0 0 0 0 0 0 0
39089 - 0 0 0 0 0 0 0 0 0 0 0 0
39090 - 0 0 0 0 0 0 0 0 0 6 6 6
39091 - 26 26 26 70 70 70 163 133 67 213 154 11
39092 -236 178 12 246 190 14 246 190 14 246 190 14
39093 -246 190 14 246 190 14 246 190 14 246 190 14
39094 -246 190 14 246 190 14 246 190 14 246 190 14
39095 -246 190 14 246 190 14 246 190 14 241 196 14
39096 -190 146 13 18 14 6 2 2 6 2 2 6
39097 - 46 46 46 246 246 246 253 253 253 253 253 253
39098 -253 253 253 253 253 253 253 253 253 253 253 253
39099 -253 253 253 253 253 253 253 253 253 253 253 253
39100 -253 253 253 253 253 253 253 253 253 253 253 253
39101 -253 253 253 221 221 221 86 86 86 156 107 11
39102 -216 158 10 236 178 12 242 186 14 246 186 14
39103 -242 186 14 239 182 13 239 182 13 242 186 14
39104 -242 186 14 246 186 14 246 190 14 246 190 14
39105 -246 190 14 246 190 14 246 190 14 246 190 14
39106 -242 186 14 225 175 15 142 122 72 66 66 66
39107 - 30 30 30 10 10 10 0 0 0 0 0 0
39108 - 0 0 0 0 0 0 0 0 0 0 0 0
39109 - 0 0 0 0 0 0 0 0 0 0 0 0
39110 - 0 0 0 0 0 0 0 0 0 6 6 6
39111 - 26 26 26 70 70 70 163 133 67 210 150 10
39112 -236 178 12 246 190 14 246 190 14 246 190 14
39113 -246 190 14 246 190 14 246 190 14 246 190 14
39114 -246 190 14 246 190 14 246 190 14 246 190 14
39115 -246 190 14 246 190 14 246 190 14 246 190 14
39116 -232 195 16 121 92 8 34 34 34 106 106 106
39117 -221 221 221 253 253 253 253 253 253 253 253 253
39118 -253 253 253 253 253 253 253 253 253 253 253 253
39119 -253 253 253 253 253 253 253 253 253 253 253 253
39120 -253 253 253 253 253 253 253 253 253 253 253 253
39121 -242 242 242 82 82 82 18 14 6 163 110 8
39122 -216 158 10 236 178 12 242 186 14 246 190 14
39123 -246 190 14 246 190 14 246 190 14 246 190 14
39124 -246 190 14 246 190 14 246 190 14 246 190 14
39125 -246 190 14 246 190 14 246 190 14 246 190 14
39126 -246 190 14 246 190 14 242 186 14 163 133 67
39127 - 46 46 46 18 18 18 6 6 6 0 0 0
39128 - 0 0 0 0 0 0 0 0 0 0 0 0
39129 - 0 0 0 0 0 0 0 0 0 0 0 0
39130 - 0 0 0 0 0 0 0 0 0 10 10 10
39131 - 30 30 30 78 78 78 163 133 67 210 150 10
39132 -236 178 12 246 186 14 246 190 14 246 190 14
39133 -246 190 14 246 190 14 246 190 14 246 190 14
39134 -246 190 14 246 190 14 246 190 14 246 190 14
39135 -246 190 14 246 190 14 246 190 14 246 190 14
39136 -241 196 14 215 174 15 190 178 144 253 253 253
39137 -253 253 253 253 253 253 253 253 253 253 253 253
39138 -253 253 253 253 253 253 253 253 253 253 253 253
39139 -253 253 253 253 253 253 253 253 253 253 253 253
39140 -253 253 253 253 253 253 253 253 253 218 218 218
39141 - 58 58 58 2 2 6 22 18 6 167 114 7
39142 -216 158 10 236 178 12 246 186 14 246 190 14
39143 -246 190 14 246 190 14 246 190 14 246 190 14
39144 -246 190 14 246 190 14 246 190 14 246 190 14
39145 -246 190 14 246 190 14 246 190 14 246 190 14
39146 -246 190 14 246 186 14 242 186 14 190 150 46
39147 - 54 54 54 22 22 22 6 6 6 0 0 0
39148 - 0 0 0 0 0 0 0 0 0 0 0 0
39149 - 0 0 0 0 0 0 0 0 0 0 0 0
39150 - 0 0 0 0 0 0 0 0 0 14 14 14
39151 - 38 38 38 86 86 86 180 133 36 213 154 11
39152 -236 178 12 246 186 14 246 190 14 246 190 14
39153 -246 190 14 246 190 14 246 190 14 246 190 14
39154 -246 190 14 246 190 14 246 190 14 246 190 14
39155 -246 190 14 246 190 14 246 190 14 246 190 14
39156 -246 190 14 232 195 16 190 146 13 214 214 214
39157 -253 253 253 253 253 253 253 253 253 253 253 253
39158 -253 253 253 253 253 253 253 253 253 253 253 253
39159 -253 253 253 253 253 253 253 253 253 253 253 253
39160 -253 253 253 250 250 250 170 170 170 26 26 26
39161 - 2 2 6 2 2 6 37 26 9 163 110 8
39162 -219 162 10 239 182 13 246 186 14 246 190 14
39163 -246 190 14 246 190 14 246 190 14 246 190 14
39164 -246 190 14 246 190 14 246 190 14 246 190 14
39165 -246 190 14 246 190 14 246 190 14 246 190 14
39166 -246 186 14 236 178 12 224 166 10 142 122 72
39167 - 46 46 46 18 18 18 6 6 6 0 0 0
39168 - 0 0 0 0 0 0 0 0 0 0 0 0
39169 - 0 0 0 0 0 0 0 0 0 0 0 0
39170 - 0 0 0 0 0 0 6 6 6 18 18 18
39171 - 50 50 50 109 106 95 192 133 9 224 166 10
39172 -242 186 14 246 190 14 246 190 14 246 190 14
39173 -246 190 14 246 190 14 246 190 14 246 190 14
39174 -246 190 14 246 190 14 246 190 14 246 190 14
39175 -246 190 14 246 190 14 246 190 14 246 190 14
39176 -242 186 14 226 184 13 210 162 10 142 110 46
39177 -226 226 226 253 253 253 253 253 253 253 253 253
39178 -253 253 253 253 253 253 253 253 253 253 253 253
39179 -253 253 253 253 253 253 253 253 253 253 253 253
39180 -198 198 198 66 66 66 2 2 6 2 2 6
39181 - 2 2 6 2 2 6 50 34 6 156 107 11
39182 -219 162 10 239 182 13 246 186 14 246 190 14
39183 -246 190 14 246 190 14 246 190 14 246 190 14
39184 -246 190 14 246 190 14 246 190 14 246 190 14
39185 -246 190 14 246 190 14 246 190 14 242 186 14
39186 -234 174 13 213 154 11 154 122 46 66 66 66
39187 - 30 30 30 10 10 10 0 0 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 0 0 0 0
39189 - 0 0 0 0 0 0 0 0 0 0 0 0
39190 - 0 0 0 0 0 0 6 6 6 22 22 22
39191 - 58 58 58 154 121 60 206 145 10 234 174 13
39192 -242 186 14 246 186 14 246 190 14 246 190 14
39193 -246 190 14 246 190 14 246 190 14 246 190 14
39194 -246 190 14 246 190 14 246 190 14 246 190 14
39195 -246 190 14 246 190 14 246 190 14 246 190 14
39196 -246 186 14 236 178 12 210 162 10 163 110 8
39197 - 61 42 6 138 138 138 218 218 218 250 250 250
39198 -253 253 253 253 253 253 253 253 253 250 250 250
39199 -242 242 242 210 210 210 144 144 144 66 66 66
39200 - 6 6 6 2 2 6 2 2 6 2 2 6
39201 - 2 2 6 2 2 6 61 42 6 163 110 8
39202 -216 158 10 236 178 12 246 190 14 246 190 14
39203 -246 190 14 246 190 14 246 190 14 246 190 14
39204 -246 190 14 246 190 14 246 190 14 246 190 14
39205 -246 190 14 239 182 13 230 174 11 216 158 10
39206 -190 142 34 124 112 88 70 70 70 38 38 38
39207 - 18 18 18 6 6 6 0 0 0 0 0 0
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 0 0 0
39210 - 0 0 0 0 0 0 6 6 6 22 22 22
39211 - 62 62 62 168 124 44 206 145 10 224 166 10
39212 -236 178 12 239 182 13 242 186 14 242 186 14
39213 -246 186 14 246 190 14 246 190 14 246 190 14
39214 -246 190 14 246 190 14 246 190 14 246 190 14
39215 -246 190 14 246 190 14 246 190 14 246 190 14
39216 -246 190 14 236 178 12 216 158 10 175 118 6
39217 - 80 54 7 2 2 6 6 6 6 30 30 30
39218 - 54 54 54 62 62 62 50 50 50 38 38 38
39219 - 14 14 14 2 2 6 2 2 6 2 2 6
39220 - 2 2 6 2 2 6 2 2 6 2 2 6
39221 - 2 2 6 6 6 6 80 54 7 167 114 7
39222 -213 154 11 236 178 12 246 190 14 246 190 14
39223 -246 190 14 246 190 14 246 190 14 246 190 14
39224 -246 190 14 242 186 14 239 182 13 239 182 13
39225 -230 174 11 210 150 10 174 135 50 124 112 88
39226 - 82 82 82 54 54 54 34 34 34 18 18 18
39227 - 6 6 6 0 0 0 0 0 0 0 0 0
39228 - 0 0 0 0 0 0 0 0 0 0 0 0
39229 - 0 0 0 0 0 0 0 0 0 0 0 0
39230 - 0 0 0 0 0 0 6 6 6 18 18 18
39231 - 50 50 50 158 118 36 192 133 9 200 144 11
39232 -216 158 10 219 162 10 224 166 10 226 170 11
39233 -230 174 11 236 178 12 239 182 13 239 182 13
39234 -242 186 14 246 186 14 246 190 14 246 190 14
39235 -246 190 14 246 190 14 246 190 14 246 190 14
39236 -246 186 14 230 174 11 210 150 10 163 110 8
39237 -104 69 6 10 10 10 2 2 6 2 2 6
39238 - 2 2 6 2 2 6 2 2 6 2 2 6
39239 - 2 2 6 2 2 6 2 2 6 2 2 6
39240 - 2 2 6 2 2 6 2 2 6 2 2 6
39241 - 2 2 6 6 6 6 91 60 6 167 114 7
39242 -206 145 10 230 174 11 242 186 14 246 190 14
39243 -246 190 14 246 190 14 246 186 14 242 186 14
39244 -239 182 13 230 174 11 224 166 10 213 154 11
39245 -180 133 36 124 112 88 86 86 86 58 58 58
39246 - 38 38 38 22 22 22 10 10 10 6 6 6
39247 - 0 0 0 0 0 0 0 0 0 0 0 0
39248 - 0 0 0 0 0 0 0 0 0 0 0 0
39249 - 0 0 0 0 0 0 0 0 0 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 14 14 14
39251 - 34 34 34 70 70 70 138 110 50 158 118 36
39252 -167 114 7 180 123 7 192 133 9 197 138 11
39253 -200 144 11 206 145 10 213 154 11 219 162 10
39254 -224 166 10 230 174 11 239 182 13 242 186 14
39255 -246 186 14 246 186 14 246 186 14 246 186 14
39256 -239 182 13 216 158 10 185 133 11 152 99 6
39257 -104 69 6 18 14 6 2 2 6 2 2 6
39258 - 2 2 6 2 2 6 2 2 6 2 2 6
39259 - 2 2 6 2 2 6 2 2 6 2 2 6
39260 - 2 2 6 2 2 6 2 2 6 2 2 6
39261 - 2 2 6 6 6 6 80 54 7 152 99 6
39262 -192 133 9 219 162 10 236 178 12 239 182 13
39263 -246 186 14 242 186 14 239 182 13 236 178 12
39264 -224 166 10 206 145 10 192 133 9 154 121 60
39265 - 94 94 94 62 62 62 42 42 42 22 22 22
39266 - 14 14 14 6 6 6 0 0 0 0 0 0
39267 - 0 0 0 0 0 0 0 0 0 0 0 0
39268 - 0 0 0 0 0 0 0 0 0 0 0 0
39269 - 0 0 0 0 0 0 0 0 0 0 0 0
39270 - 0 0 0 0 0 0 0 0 0 6 6 6
39271 - 18 18 18 34 34 34 58 58 58 78 78 78
39272 -101 98 89 124 112 88 142 110 46 156 107 11
39273 -163 110 8 167 114 7 175 118 6 180 123 7
39274 -185 133 11 197 138 11 210 150 10 219 162 10
39275 -226 170 11 236 178 12 236 178 12 234 174 13
39276 -219 162 10 197 138 11 163 110 8 130 83 6
39277 - 91 60 6 10 10 10 2 2 6 2 2 6
39278 - 18 18 18 38 38 38 38 38 38 38 38 38
39279 - 38 38 38 38 38 38 38 38 38 38 38 38
39280 - 38 38 38 38 38 38 26 26 26 2 2 6
39281 - 2 2 6 6 6 6 70 47 6 137 92 6
39282 -175 118 6 200 144 11 219 162 10 230 174 11
39283 -234 174 13 230 174 11 219 162 10 210 150 10
39284 -192 133 9 163 110 8 124 112 88 82 82 82
39285 - 50 50 50 30 30 30 14 14 14 6 6 6
39286 - 0 0 0 0 0 0 0 0 0 0 0 0
39287 - 0 0 0 0 0 0 0 0 0 0 0 0
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 0 0 0
39290 - 0 0 0 0 0 0 0 0 0 0 0 0
39291 - 6 6 6 14 14 14 22 22 22 34 34 34
39292 - 42 42 42 58 58 58 74 74 74 86 86 86
39293 -101 98 89 122 102 70 130 98 46 121 87 25
39294 -137 92 6 152 99 6 163 110 8 180 123 7
39295 -185 133 11 197 138 11 206 145 10 200 144 11
39296 -180 123 7 156 107 11 130 83 6 104 69 6
39297 - 50 34 6 54 54 54 110 110 110 101 98 89
39298 - 86 86 86 82 82 82 78 78 78 78 78 78
39299 - 78 78 78 78 78 78 78 78 78 78 78 78
39300 - 78 78 78 82 82 82 86 86 86 94 94 94
39301 -106 106 106 101 101 101 86 66 34 124 80 6
39302 -156 107 11 180 123 7 192 133 9 200 144 11
39303 -206 145 10 200 144 11 192 133 9 175 118 6
39304 -139 102 15 109 106 95 70 70 70 42 42 42
39305 - 22 22 22 10 10 10 0 0 0 0 0 0
39306 - 0 0 0 0 0 0 0 0 0 0 0 0
39307 - 0 0 0 0 0 0 0 0 0 0 0 0
39308 - 0 0 0 0 0 0 0 0 0 0 0 0
39309 - 0 0 0 0 0 0 0 0 0 0 0 0
39310 - 0 0 0 0 0 0 0 0 0 0 0 0
39311 - 0 0 0 0 0 0 6 6 6 10 10 10
39312 - 14 14 14 22 22 22 30 30 30 38 38 38
39313 - 50 50 50 62 62 62 74 74 74 90 90 90
39314 -101 98 89 112 100 78 121 87 25 124 80 6
39315 -137 92 6 152 99 6 152 99 6 152 99 6
39316 -138 86 6 124 80 6 98 70 6 86 66 30
39317 -101 98 89 82 82 82 58 58 58 46 46 46
39318 - 38 38 38 34 34 34 34 34 34 34 34 34
39319 - 34 34 34 34 34 34 34 34 34 34 34 34
39320 - 34 34 34 34 34 34 38 38 38 42 42 42
39321 - 54 54 54 82 82 82 94 86 76 91 60 6
39322 -134 86 6 156 107 11 167 114 7 175 118 6
39323 -175 118 6 167 114 7 152 99 6 121 87 25
39324 -101 98 89 62 62 62 34 34 34 18 18 18
39325 - 6 6 6 0 0 0 0 0 0 0 0 0
39326 - 0 0 0 0 0 0 0 0 0 0 0 0
39327 - 0 0 0 0 0 0 0 0 0 0 0 0
39328 - 0 0 0 0 0 0 0 0 0 0 0 0
39329 - 0 0 0 0 0 0 0 0 0 0 0 0
39330 - 0 0 0 0 0 0 0 0 0 0 0 0
39331 - 0 0 0 0 0 0 0 0 0 0 0 0
39332 - 0 0 0 6 6 6 6 6 6 10 10 10
39333 - 18 18 18 22 22 22 30 30 30 42 42 42
39334 - 50 50 50 66 66 66 86 86 86 101 98 89
39335 -106 86 58 98 70 6 104 69 6 104 69 6
39336 -104 69 6 91 60 6 82 62 34 90 90 90
39337 - 62 62 62 38 38 38 22 22 22 14 14 14
39338 - 10 10 10 10 10 10 10 10 10 10 10 10
39339 - 10 10 10 10 10 10 6 6 6 10 10 10
39340 - 10 10 10 10 10 10 10 10 10 14 14 14
39341 - 22 22 22 42 42 42 70 70 70 89 81 66
39342 - 80 54 7 104 69 6 124 80 6 137 92 6
39343 -134 86 6 116 81 8 100 82 52 86 86 86
39344 - 58 58 58 30 30 30 14 14 14 6 6 6
39345 - 0 0 0 0 0 0 0 0 0 0 0 0
39346 - 0 0 0 0 0 0 0 0 0 0 0 0
39347 - 0 0 0 0 0 0 0 0 0 0 0 0
39348 - 0 0 0 0 0 0 0 0 0 0 0 0
39349 - 0 0 0 0 0 0 0 0 0 0 0 0
39350 - 0 0 0 0 0 0 0 0 0 0 0 0
39351 - 0 0 0 0 0 0 0 0 0 0 0 0
39352 - 0 0 0 0 0 0 0 0 0 0 0 0
39353 - 0 0 0 6 6 6 10 10 10 14 14 14
39354 - 18 18 18 26 26 26 38 38 38 54 54 54
39355 - 70 70 70 86 86 86 94 86 76 89 81 66
39356 - 89 81 66 86 86 86 74 74 74 50 50 50
39357 - 30 30 30 14 14 14 6 6 6 0 0 0
39358 - 0 0 0 0 0 0 0 0 0 0 0 0
39359 - 0 0 0 0 0 0 0 0 0 0 0 0
39360 - 0 0 0 0 0 0 0 0 0 0 0 0
39361 - 6 6 6 18 18 18 34 34 34 58 58 58
39362 - 82 82 82 89 81 66 89 81 66 89 81 66
39363 - 94 86 66 94 86 76 74 74 74 50 50 50
39364 - 26 26 26 14 14 14 6 6 6 0 0 0
39365 - 0 0 0 0 0 0 0 0 0 0 0 0
39366 - 0 0 0 0 0 0 0 0 0 0 0 0
39367 - 0 0 0 0 0 0 0 0 0 0 0 0
39368 - 0 0 0 0 0 0 0 0 0 0 0 0
39369 - 0 0 0 0 0 0 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 0 0 0
39371 - 0 0 0 0 0 0 0 0 0 0 0 0
39372 - 0 0 0 0 0 0 0 0 0 0 0 0
39373 - 0 0 0 0 0 0 0 0 0 0 0 0
39374 - 6 6 6 6 6 6 14 14 14 18 18 18
39375 - 30 30 30 38 38 38 46 46 46 54 54 54
39376 - 50 50 50 42 42 42 30 30 30 18 18 18
39377 - 10 10 10 0 0 0 0 0 0 0 0 0
39378 - 0 0 0 0 0 0 0 0 0 0 0 0
39379 - 0 0 0 0 0 0 0 0 0 0 0 0
39380 - 0 0 0 0 0 0 0 0 0 0 0 0
39381 - 0 0 0 6 6 6 14 14 14 26 26 26
39382 - 38 38 38 50 50 50 58 58 58 58 58 58
39383 - 54 54 54 42 42 42 30 30 30 18 18 18
39384 - 10 10 10 0 0 0 0 0 0 0 0 0
39385 - 0 0 0 0 0 0 0 0 0 0 0 0
39386 - 0 0 0 0 0 0 0 0 0 0 0 0
39387 - 0 0 0 0 0 0 0 0 0 0 0 0
39388 - 0 0 0 0 0 0 0 0 0 0 0 0
39389 - 0 0 0 0 0 0 0 0 0 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 0 0 0
39391 - 0 0 0 0 0 0 0 0 0 0 0 0
39392 - 0 0 0 0 0 0 0 0 0 0 0 0
39393 - 0 0 0 0 0 0 0 0 0 0 0 0
39394 - 0 0 0 0 0 0 0 0 0 6 6 6
39395 - 6 6 6 10 10 10 14 14 14 18 18 18
39396 - 18 18 18 14 14 14 10 10 10 6 6 6
39397 - 0 0 0 0 0 0 0 0 0 0 0 0
39398 - 0 0 0 0 0 0 0 0 0 0 0 0
39399 - 0 0 0 0 0 0 0 0 0 0 0 0
39400 - 0 0 0 0 0 0 0 0 0 0 0 0
39401 - 0 0 0 0 0 0 0 0 0 6 6 6
39402 - 14 14 14 18 18 18 22 22 22 22 22 22
39403 - 18 18 18 14 14 14 10 10 10 6 6 6
39404 - 0 0 0 0 0 0 0 0 0 0 0 0
39405 - 0 0 0 0 0 0 0 0 0 0 0 0
39406 - 0 0 0 0 0 0 0 0 0 0 0 0
39407 - 0 0 0 0 0 0 0 0 0 0 0 0
39408 - 0 0 0 0 0 0 0 0 0 0 0 0
39409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39422 +4 4 4 4 4 4
39423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39436 +4 4 4 4 4 4
39437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39450 +4 4 4 4 4 4
39451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39464 +4 4 4 4 4 4
39465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39478 +4 4 4 4 4 4
39479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39492 +4 4 4 4 4 4
39493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39497 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
39498 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
39499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39502 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
39503 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39504 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
39505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39506 +4 4 4 4 4 4
39507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39511 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
39512 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
39513 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39516 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
39517 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
39518 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
39519 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39520 +4 4 4 4 4 4
39521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39525 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
39526 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
39527 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39530 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
39531 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
39532 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
39533 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
39534 +4 4 4 4 4 4
39535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39538 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
39539 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
39540 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
39541 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
39542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39543 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
39544 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
39545 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
39546 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
39547 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
39548 +4 4 4 4 4 4
39549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39552 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
39553 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
39554 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
39555 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
39556 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
39557 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
39558 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
39559 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
39560 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
39561 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
39562 +4 4 4 4 4 4
39563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39566 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
39567 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
39568 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
39569 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
39570 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
39571 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
39572 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
39573 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
39574 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
39575 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
39576 +4 4 4 4 4 4
39577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39579 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
39580 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
39581 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
39582 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
39583 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
39584 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
39585 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
39586 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
39587 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
39588 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
39589 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
39590 +4 4 4 4 4 4
39591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39593 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
39594 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
39595 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
39596 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
39597 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
39598 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
39599 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
39600 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
39601 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
39602 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
39603 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
39604 +4 4 4 4 4 4
39605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39607 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
39608 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
39609 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
39610 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
39611 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
39612 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
39613 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
39614 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
39615 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
39616 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
39617 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39618 +4 4 4 4 4 4
39619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39621 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
39622 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
39623 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
39624 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
39625 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
39626 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
39627 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
39628 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
39629 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
39630 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
39631 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
39632 +4 4 4 4 4 4
39633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39634 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
39635 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
39636 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
39637 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
39638 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
39639 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
39640 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
39641 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
39642 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
39643 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
39644 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
39645 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
39646 +4 4 4 4 4 4
39647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39648 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
39649 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
39650 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
39651 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
39652 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
39653 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
39654 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
39655 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
39656 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
39657 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
39658 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
39659 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
39660 +0 0 0 4 4 4
39661 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
39662 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
39663 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
39664 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
39665 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
39666 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
39667 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
39668 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
39669 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
39670 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
39671 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
39672 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
39673 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
39674 +2 0 0 0 0 0
39675 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
39676 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
39677 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
39678 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
39679 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
39680 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
39681 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
39682 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
39683 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
39684 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
39685 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
39686 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
39687 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
39688 +37 38 37 0 0 0
39689 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
39690 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
39691 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
39692 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
39693 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
39694 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
39695 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
39696 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
39697 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
39698 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
39699 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
39700 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
39701 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
39702 +85 115 134 4 0 0
39703 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
39704 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
39705 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
39706 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
39707 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
39708 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
39709 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
39710 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
39711 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
39712 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
39713 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
39714 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
39715 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
39716 +60 73 81 4 0 0
39717 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
39718 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
39719 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
39720 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
39721 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
39722 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
39723 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
39724 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
39725 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
39726 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
39727 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
39728 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
39729 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
39730 +16 19 21 4 0 0
39731 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
39732 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
39733 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
39734 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
39735 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
39736 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
39737 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
39738 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
39739 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
39740 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
39741 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
39742 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
39743 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
39744 +4 0 0 4 3 3
39745 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
39746 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
39747 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
39748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
39749 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
39750 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
39751 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
39752 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
39753 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
39754 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
39755 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
39756 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
39757 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
39758 +3 2 2 4 4 4
39759 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
39760 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
39761 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
39762 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
39763 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
39764 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
39765 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
39766 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
39767 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
39768 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
39769 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
39770 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
39771 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
39772 +4 4 4 4 4 4
39773 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
39774 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
39775 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
39776 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
39777 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
39778 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
39779 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
39780 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
39781 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
39782 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
39783 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
39784 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
39785 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
39786 +4 4 4 4 4 4
39787 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
39788 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
39789 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
39790 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
39791 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
39792 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
39793 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
39794 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
39795 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
39796 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
39797 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
39798 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
39799 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
39800 +5 5 5 5 5 5
39801 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
39802 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
39803 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
39804 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
39805 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
39806 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39807 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
39808 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
39809 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
39810 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
39811 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
39812 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
39813 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
39814 +5 5 5 4 4 4
39815 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
39816 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
39817 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
39818 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
39819 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
39820 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
39821 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
39822 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
39823 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
39824 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
39825 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
39826 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
39827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39828 +4 4 4 4 4 4
39829 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
39830 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
39831 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
39832 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
39833 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
39834 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39835 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39836 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
39837 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
39838 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
39839 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
39840 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
39841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39842 +4 4 4 4 4 4
39843 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
39844 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
39845 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
39846 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
39847 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
39848 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
39849 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
39850 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
39851 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
39852 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
39853 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
39854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39856 +4 4 4 4 4 4
39857 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
39858 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
39859 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
39860 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
39861 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
39862 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39863 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39864 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
39865 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
39866 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
39867 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
39868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39870 +4 4 4 4 4 4
39871 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
39872 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
39873 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
39874 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
39875 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
39876 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
39877 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
39878 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
39879 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
39880 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
39881 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39884 +4 4 4 4 4 4
39885 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
39886 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
39887 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
39888 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
39889 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
39890 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
39891 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
39892 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
39893 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
39894 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
39895 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
39896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39898 +4 4 4 4 4 4
39899 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
39900 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
39901 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
39902 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
39903 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
39904 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
39905 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
39906 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
39907 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
39908 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
39909 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
39910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39912 +4 4 4 4 4 4
39913 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
39914 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
39915 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
39916 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
39917 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
39918 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
39919 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
39920 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
39921 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
39922 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
39923 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39926 +4 4 4 4 4 4
39927 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
39928 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
39929 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
39930 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
39931 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39932 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
39933 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
39934 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
39935 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
39936 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
39937 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39940 +4 4 4 4 4 4
39941 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
39942 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
39943 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
39944 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
39945 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39946 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
39947 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
39948 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
39949 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
39950 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
39951 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39954 +4 4 4 4 4 4
39955 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
39956 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
39957 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
39958 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
39959 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39960 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
39961 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
39962 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
39963 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
39964 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39965 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39968 +4 4 4 4 4 4
39969 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
39970 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
39971 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
39972 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
39973 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
39974 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
39975 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
39976 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
39977 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
39978 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39979 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39982 +4 4 4 4 4 4
39983 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
39984 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
39985 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
39986 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
39987 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39988 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
39989 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
39990 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
39991 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
39992 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39993 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39996 +4 4 4 4 4 4
39997 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
39998 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
39999 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40000 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40001 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40002 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40003 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40004 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40005 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40006 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40007 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40010 +4 4 4 4 4 4
40011 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40012 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40013 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40014 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40015 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40016 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40017 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40018 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40019 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40020 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40021 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40024 +4 4 4 4 4 4
40025 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40026 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40027 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40028 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40029 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40030 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40031 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40032 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40033 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40034 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40035 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40038 +4 4 4 4 4 4
40039 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40040 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40041 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40042 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40043 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40044 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40045 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40046 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40047 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
40048 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40049 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40052 +4 4 4 4 4 4
40053 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40054 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40055 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40056 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40057 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40058 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
40059 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
40060 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
40061 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40062 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40063 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40066 +4 4 4 4 4 4
40067 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40068 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
40069 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40070 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
40071 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
40072 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
40073 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
40074 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
40075 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40076 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40077 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40080 +4 4 4 4 4 4
40081 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40082 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
40083 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
40084 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
40085 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
40086 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
40087 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40088 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
40089 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40090 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40091 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40094 +4 4 4 4 4 4
40095 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40096 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
40097 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
40098 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40099 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
40100 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
40101 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40102 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40103 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40104 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40105 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40108 +4 4 4 4 4 4
40109 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40110 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40111 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40112 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40113 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40114 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40115 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40116 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40117 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40118 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40119 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40122 +4 4 4 4 4 4
40123 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40124 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40125 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40126 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40127 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40128 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40129 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40130 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40131 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40132 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40133 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40136 +4 4 4 4 4 4
40137 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40138 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40139 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40140 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40141 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40142 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40143 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40144 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40145 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40146 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40147 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40150 +4 4 4 4 4 4
40151 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40152 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40153 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40154 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40155 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40156 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40157 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40158 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40159 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40160 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40161 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40164 +4 4 4 4 4 4
40165 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40166 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40167 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40168 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40169 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40170 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40171 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40172 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40173 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40174 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40175 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40178 +4 4 4 4 4 4
40179 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40180 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40181 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40182 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40183 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40184 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40185 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40186 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40187 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40188 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40189 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40192 +4 4 4 4 4 4
40193 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40194 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40195 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40196 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40197 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40198 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40199 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40200 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40201 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40202 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40203 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40206 +4 4 4 4 4 4
40207 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40208 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40209 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40210 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40211 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40212 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40213 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40214 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40215 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40216 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40217 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40220 +4 4 4 4 4 4
40221 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40222 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40223 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40224 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40225 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40226 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40227 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40228 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40229 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40230 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
40231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40234 +4 4 4 4 4 4
40235 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40236 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40237 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40238 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
40239 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
40240 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
40241 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
40242 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
40243 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
40244 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40248 +4 4 4 4 4 4
40249 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
40250 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
40251 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
40252 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
40253 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
40254 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
40255 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
40256 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
40257 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
40258 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40262 +4 4 4 4 4 4
40263 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
40264 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
40265 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
40266 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
40267 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
40268 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
40269 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
40270 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
40271 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40272 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40276 +4 4 4 4 4 4
40277 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
40278 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40279 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
40280 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40281 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
40282 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
40283 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
40284 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
40285 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
40286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40290 +4 4 4 4 4 4
40291 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
40292 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
40293 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
40294 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
40295 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
40296 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
40297 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
40298 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
40299 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
40300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40304 +4 4 4 4 4 4
40305 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40306 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
40307 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
40308 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
40309 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
40310 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
40311 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
40312 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
40313 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40318 +4 4 4 4 4 4
40319 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
40320 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
40321 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40322 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
40323 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
40324 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
40325 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
40326 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
40327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40332 +4 4 4 4 4 4
40333 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40334 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
40335 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
40336 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
40337 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
40338 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
40339 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
40340 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40346 +4 4 4 4 4 4
40347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40348 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
40349 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40350 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
40351 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
40352 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
40353 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
40354 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
40355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40360 +4 4 4 4 4 4
40361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40362 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
40363 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
40364 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
40365 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
40366 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
40367 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
40368 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
40369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40374 +4 4 4 4 4 4
40375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40376 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40377 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
40378 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40379 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
40380 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
40381 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
40382 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40388 +4 4 4 4 4 4
40389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40391 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40392 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
40393 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
40394 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
40395 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
40396 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40402 +4 4 4 4 4 4
40403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40406 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40407 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
40408 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
40409 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
40410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40416 +4 4 4 4 4 4
40417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40420 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40421 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40422 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
40423 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
40424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40430 +4 4 4 4 4 4
40431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40434 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40435 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40436 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40437 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
40438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40444 +4 4 4 4 4 4
40445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40448 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
40449 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
40450 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
40451 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
40452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40458 +4 4 4 4 4 4
40459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40463 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
40464 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40465 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40472 +4 4 4 4 4 4
40473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40477 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
40478 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
40479 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40486 +4 4 4 4 4 4
40487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40491 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
40492 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
40493 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40500 +4 4 4 4 4 4
40501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40505 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
40506 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
40507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40514 +4 4 4 4 4 4
40515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40519 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40520 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
40521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40528 +4 4 4 4 4 4
40529 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
40530 index a40c05e..785c583 100644
40531 --- a/drivers/video/udlfb.c
40532 +++ b/drivers/video/udlfb.c
40533 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
40534 dlfb_urb_completion(urb);
40535
40536 error:
40537 - atomic_add(bytes_sent, &dev->bytes_sent);
40538 - atomic_add(bytes_identical, &dev->bytes_identical);
40539 - atomic_add(width*height*2, &dev->bytes_rendered);
40540 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
40541 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
40542 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
40543 end_cycles = get_cycles();
40544 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
40545 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
40546 >> 10)), /* Kcycles */
40547 &dev->cpu_kcycles_used);
40548
40549 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
40550 dlfb_urb_completion(urb);
40551
40552 error:
40553 - atomic_add(bytes_sent, &dev->bytes_sent);
40554 - atomic_add(bytes_identical, &dev->bytes_identical);
40555 - atomic_add(bytes_rendered, &dev->bytes_rendered);
40556 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
40557 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
40558 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
40559 end_cycles = get_cycles();
40560 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
40561 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
40562 >> 10)), /* Kcycles */
40563 &dev->cpu_kcycles_used);
40564 }
40565 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
40566 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40567 struct dlfb_data *dev = fb_info->par;
40568 return snprintf(buf, PAGE_SIZE, "%u\n",
40569 - atomic_read(&dev->bytes_rendered));
40570 + atomic_read_unchecked(&dev->bytes_rendered));
40571 }
40572
40573 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
40574 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
40575 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40576 struct dlfb_data *dev = fb_info->par;
40577 return snprintf(buf, PAGE_SIZE, "%u\n",
40578 - atomic_read(&dev->bytes_identical));
40579 + atomic_read_unchecked(&dev->bytes_identical));
40580 }
40581
40582 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
40583 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
40584 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40585 struct dlfb_data *dev = fb_info->par;
40586 return snprintf(buf, PAGE_SIZE, "%u\n",
40587 - atomic_read(&dev->bytes_sent));
40588 + atomic_read_unchecked(&dev->bytes_sent));
40589 }
40590
40591 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
40592 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
40593 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40594 struct dlfb_data *dev = fb_info->par;
40595 return snprintf(buf, PAGE_SIZE, "%u\n",
40596 - atomic_read(&dev->cpu_kcycles_used));
40597 + atomic_read_unchecked(&dev->cpu_kcycles_used));
40598 }
40599
40600 static ssize_t edid_show(
40601 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
40602 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40603 struct dlfb_data *dev = fb_info->par;
40604
40605 - atomic_set(&dev->bytes_rendered, 0);
40606 - atomic_set(&dev->bytes_identical, 0);
40607 - atomic_set(&dev->bytes_sent, 0);
40608 - atomic_set(&dev->cpu_kcycles_used, 0);
40609 + atomic_set_unchecked(&dev->bytes_rendered, 0);
40610 + atomic_set_unchecked(&dev->bytes_identical, 0);
40611 + atomic_set_unchecked(&dev->bytes_sent, 0);
40612 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
40613
40614 return count;
40615 }
40616 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
40617 index e7f69ef..83af4fd 100644
40618 --- a/drivers/video/uvesafb.c
40619 +++ b/drivers/video/uvesafb.c
40620 @@ -19,6 +19,7 @@
40621 #include <linux/io.h>
40622 #include <linux/mutex.h>
40623 #include <linux/slab.h>
40624 +#include <linux/moduleloader.h>
40625 #include <video/edid.h>
40626 #include <video/uvesafb.h>
40627 #ifdef CONFIG_X86
40628 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
40629 NULL,
40630 };
40631
40632 - return call_usermodehelper(v86d_path, argv, envp, 1);
40633 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
40634 }
40635
40636 /*
40637 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
40638 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
40639 par->pmi_setpal = par->ypan = 0;
40640 } else {
40641 +
40642 +#ifdef CONFIG_PAX_KERNEXEC
40643 +#ifdef CONFIG_MODULES
40644 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
40645 +#endif
40646 + if (!par->pmi_code) {
40647 + par->pmi_setpal = par->ypan = 0;
40648 + return 0;
40649 + }
40650 +#endif
40651 +
40652 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
40653 + task->t.regs.edi);
40654 +
40655 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40656 + pax_open_kernel();
40657 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
40658 + pax_close_kernel();
40659 +
40660 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
40661 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
40662 +#else
40663 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
40664 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
40665 +#endif
40666 +
40667 printk(KERN_INFO "uvesafb: protected mode interface info at "
40668 "%04x:%04x\n",
40669 (u16)task->t.regs.es, (u16)task->t.regs.edi);
40670 @@ -1821,6 +1844,11 @@ out:
40671 if (par->vbe_modes)
40672 kfree(par->vbe_modes);
40673
40674 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40675 + if (par->pmi_code)
40676 + module_free_exec(NULL, par->pmi_code);
40677 +#endif
40678 +
40679 framebuffer_release(info);
40680 return err;
40681 }
40682 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
40683 kfree(par->vbe_state_orig);
40684 if (par->vbe_state_saved)
40685 kfree(par->vbe_state_saved);
40686 +
40687 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40688 + if (par->pmi_code)
40689 + module_free_exec(NULL, par->pmi_code);
40690 +#endif
40691 +
40692 }
40693
40694 framebuffer_release(info);
40695 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
40696 index 501b340..86bd4cf 100644
40697 --- a/drivers/video/vesafb.c
40698 +++ b/drivers/video/vesafb.c
40699 @@ -9,6 +9,7 @@
40700 */
40701
40702 #include <linux/module.h>
40703 +#include <linux/moduleloader.h>
40704 #include <linux/kernel.h>
40705 #include <linux/errno.h>
40706 #include <linux/string.h>
40707 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
40708 static int vram_total __initdata; /* Set total amount of memory */
40709 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
40710 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
40711 -static void (*pmi_start)(void) __read_mostly;
40712 -static void (*pmi_pal) (void) __read_mostly;
40713 +static void (*pmi_start)(void) __read_only;
40714 +static void (*pmi_pal) (void) __read_only;
40715 static int depth __read_mostly;
40716 static int vga_compat __read_mostly;
40717 /* --------------------------------------------------------------------- */
40718 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
40719 unsigned int size_vmode;
40720 unsigned int size_remap;
40721 unsigned int size_total;
40722 + void *pmi_code = NULL;
40723
40724 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
40725 return -ENODEV;
40726 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
40727 size_remap = size_total;
40728 vesafb_fix.smem_len = size_remap;
40729
40730 -#ifndef __i386__
40731 - screen_info.vesapm_seg = 0;
40732 -#endif
40733 -
40734 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
40735 printk(KERN_WARNING
40736 "vesafb: cannot reserve video memory at 0x%lx\n",
40737 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
40738 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
40739 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
40740
40741 +#ifdef __i386__
40742 +
40743 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40744 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
40745 + if (!pmi_code)
40746 +#elif !defined(CONFIG_PAX_KERNEXEC)
40747 + if (0)
40748 +#endif
40749 +
40750 +#endif
40751 + screen_info.vesapm_seg = 0;
40752 +
40753 if (screen_info.vesapm_seg) {
40754 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
40755 - screen_info.vesapm_seg,screen_info.vesapm_off);
40756 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
40757 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
40758 }
40759
40760 if (screen_info.vesapm_seg < 0xc000)
40761 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
40762
40763 if (ypan || pmi_setpal) {
40764 unsigned short *pmi_base;
40765 +
40766 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
40767 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
40768 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
40769 +
40770 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40771 + pax_open_kernel();
40772 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
40773 +#else
40774 + pmi_code = pmi_base;
40775 +#endif
40776 +
40777 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
40778 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
40779 +
40780 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40781 + pmi_start = ktva_ktla(pmi_start);
40782 + pmi_pal = ktva_ktla(pmi_pal);
40783 + pax_close_kernel();
40784 +#endif
40785 +
40786 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
40787 if (pmi_base[3]) {
40788 printk(KERN_INFO "vesafb: pmi: ports = ");
40789 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
40790 info->node, info->fix.id);
40791 return 0;
40792 err:
40793 +
40794 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40795 + module_free_exec(NULL, pmi_code);
40796 +#endif
40797 +
40798 if (info->screen_base)
40799 iounmap(info->screen_base);
40800 framebuffer_release(info);
40801 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
40802 index 88714ae..16c2e11 100644
40803 --- a/drivers/video/via/via_clock.h
40804 +++ b/drivers/video/via/via_clock.h
40805 @@ -56,7 +56,7 @@ struct via_clock {
40806
40807 void (*set_engine_pll_state)(u8 state);
40808 void (*set_engine_pll)(struct via_pll_config config);
40809 -};
40810 +} __no_const;
40811
40812
40813 static inline u32 get_pll_internal_frequency(u32 ref_freq,
40814 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
40815 index e56c934..fc22f4b 100644
40816 --- a/drivers/xen/xen-pciback/conf_space.h
40817 +++ b/drivers/xen/xen-pciback/conf_space.h
40818 @@ -44,15 +44,15 @@ struct config_field {
40819 struct {
40820 conf_dword_write write;
40821 conf_dword_read read;
40822 - } dw;
40823 + } __no_const dw;
40824 struct {
40825 conf_word_write write;
40826 conf_word_read read;
40827 - } w;
40828 + } __no_const w;
40829 struct {
40830 conf_byte_write write;
40831 conf_byte_read read;
40832 - } b;
40833 + } __no_const b;
40834 } u;
40835 struct list_head list;
40836 };
40837 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
40838 index 014c8dd..6f3dfe6 100644
40839 --- a/fs/9p/vfs_inode.c
40840 +++ b/fs/9p/vfs_inode.c
40841 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
40842 void
40843 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
40844 {
40845 - char *s = nd_get_link(nd);
40846 + const char *s = nd_get_link(nd);
40847
40848 p9_debug(P9_DEBUG_VFS, " %s %s\n",
40849 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
40850 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
40851 index e95d1b6..3454244 100644
40852 --- a/fs/Kconfig.binfmt
40853 +++ b/fs/Kconfig.binfmt
40854 @@ -89,7 +89,7 @@ config HAVE_AOUT
40855
40856 config BINFMT_AOUT
40857 tristate "Kernel support for a.out and ECOFF binaries"
40858 - depends on HAVE_AOUT
40859 + depends on HAVE_AOUT && BROKEN
40860 ---help---
40861 A.out (Assembler.OUTput) is a set of formats for libraries and
40862 executables used in the earliest versions of UNIX. Linux used
40863 diff --git a/fs/aio.c b/fs/aio.c
40864 index b9d64d8..86cb1d5 100644
40865 --- a/fs/aio.c
40866 +++ b/fs/aio.c
40867 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
40868 size += sizeof(struct io_event) * nr_events;
40869 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
40870
40871 - if (nr_pages < 0)
40872 + if (nr_pages <= 0)
40873 return -EINVAL;
40874
40875 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
40876 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
40877 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
40878 {
40879 ssize_t ret;
40880 + struct iovec iovstack;
40881
40882 #ifdef CONFIG_COMPAT
40883 if (compat)
40884 ret = compat_rw_copy_check_uvector(type,
40885 (struct compat_iovec __user *)kiocb->ki_buf,
40886 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
40887 + kiocb->ki_nbytes, 1, &iovstack,
40888 &kiocb->ki_iovec, 1);
40889 else
40890 #endif
40891 ret = rw_copy_check_uvector(type,
40892 (struct iovec __user *)kiocb->ki_buf,
40893 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
40894 + kiocb->ki_nbytes, 1, &iovstack,
40895 &kiocb->ki_iovec, 1);
40896 if (ret < 0)
40897 goto out;
40898
40899 + if (kiocb->ki_iovec == &iovstack) {
40900 + kiocb->ki_inline_vec = iovstack;
40901 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
40902 + }
40903 kiocb->ki_nr_segs = kiocb->ki_nbytes;
40904 kiocb->ki_cur_seg = 0;
40905 /* ki_nbytes/left now reflect bytes instead of segs */
40906 diff --git a/fs/attr.c b/fs/attr.c
40907 index 95053ad..2cc93ca 100644
40908 --- a/fs/attr.c
40909 +++ b/fs/attr.c
40910 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
40911 unsigned long limit;
40912
40913 limit = rlimit(RLIMIT_FSIZE);
40914 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
40915 if (limit != RLIM_INFINITY && offset > limit)
40916 goto out_sig;
40917 if (offset > inode->i_sb->s_maxbytes)
40918 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
40919 index 9c098db..c755da5 100644
40920 --- a/fs/autofs4/waitq.c
40921 +++ b/fs/autofs4/waitq.c
40922 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
40923 {
40924 unsigned long sigpipe, flags;
40925 mm_segment_t fs;
40926 - const char *data = (const char *)addr;
40927 + const char __user *data = (const char __force_user *)addr;
40928 ssize_t wr = 0;
40929
40930 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
40931 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
40932 index 6e6d536..457113a 100644
40933 --- a/fs/befs/linuxvfs.c
40934 +++ b/fs/befs/linuxvfs.c
40935 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
40936 {
40937 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
40938 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
40939 - char *link = nd_get_link(nd);
40940 + const char *link = nd_get_link(nd);
40941 if (!IS_ERR(link))
40942 kfree(link);
40943 }
40944 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
40945 index 1ff9405..f1e376a 100644
40946 --- a/fs/binfmt_aout.c
40947 +++ b/fs/binfmt_aout.c
40948 @@ -16,6 +16,7 @@
40949 #include <linux/string.h>
40950 #include <linux/fs.h>
40951 #include <linux/file.h>
40952 +#include <linux/security.h>
40953 #include <linux/stat.h>
40954 #include <linux/fcntl.h>
40955 #include <linux/ptrace.h>
40956 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
40957 #endif
40958 # define START_STACK(u) ((void __user *)u.start_stack)
40959
40960 + memset(&dump, 0, sizeof(dump));
40961 +
40962 fs = get_fs();
40963 set_fs(KERNEL_DS);
40964 has_dumped = 1;
40965 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
40966
40967 /* If the size of the dump file exceeds the rlimit, then see what would happen
40968 if we wrote the stack, but not the data area. */
40969 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
40970 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
40971 dump.u_dsize = 0;
40972
40973 /* Make sure we have enough room to write the stack and data areas. */
40974 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
40975 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
40976 dump.u_ssize = 0;
40977
40978 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
40979 rlim = rlimit(RLIMIT_DATA);
40980 if (rlim >= RLIM_INFINITY)
40981 rlim = ~0;
40982 +
40983 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
40984 if (ex.a_data + ex.a_bss > rlim)
40985 return -ENOMEM;
40986
40987 @@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
40988 install_exec_creds(bprm);
40989 current->flags &= ~PF_FORKNOEXEC;
40990
40991 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
40992 + current->mm->pax_flags = 0UL;
40993 +#endif
40994 +
40995 +#ifdef CONFIG_PAX_PAGEEXEC
40996 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
40997 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
40998 +
40999 +#ifdef CONFIG_PAX_EMUTRAMP
41000 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41001 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41002 +#endif
41003 +
41004 +#ifdef CONFIG_PAX_MPROTECT
41005 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41006 + current->mm->pax_flags |= MF_PAX_MPROTECT;
41007 +#endif
41008 +
41009 + }
41010 +#endif
41011 +
41012 if (N_MAGIC(ex) == OMAGIC) {
41013 unsigned long text_addr, map_size;
41014 loff_t pos;
41015 @@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41016
41017 down_write(&current->mm->mmap_sem);
41018 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41019 - PROT_READ | PROT_WRITE | PROT_EXEC,
41020 + PROT_READ | PROT_WRITE,
41021 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41022 fd_offset + ex.a_text);
41023 up_write(&current->mm->mmap_sem);
41024 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41025 index 07d096c..5e2a0b3 100644
41026 --- a/fs/binfmt_elf.c
41027 +++ b/fs/binfmt_elf.c
41028 @@ -32,6 +32,7 @@
41029 #include <linux/elf.h>
41030 #include <linux/utsname.h>
41031 #include <linux/coredump.h>
41032 +#include <linux/xattr.h>
41033 #include <asm/uaccess.h>
41034 #include <asm/param.h>
41035 #include <asm/page.h>
41036 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
41037 #define elf_core_dump NULL
41038 #endif
41039
41040 +#ifdef CONFIG_PAX_MPROTECT
41041 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
41042 +#endif
41043 +
41044 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
41045 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
41046 #else
41047 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
41048 .load_binary = load_elf_binary,
41049 .load_shlib = load_elf_library,
41050 .core_dump = elf_core_dump,
41051 +
41052 +#ifdef CONFIG_PAX_MPROTECT
41053 + .handle_mprotect= elf_handle_mprotect,
41054 +#endif
41055 +
41056 .min_coredump = ELF_EXEC_PAGESIZE,
41057 };
41058
41059 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
41060
41061 static int set_brk(unsigned long start, unsigned long end)
41062 {
41063 + unsigned long e = end;
41064 +
41065 start = ELF_PAGEALIGN(start);
41066 end = ELF_PAGEALIGN(end);
41067 if (end > start) {
41068 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
41069 if (BAD_ADDR(addr))
41070 return addr;
41071 }
41072 - current->mm->start_brk = current->mm->brk = end;
41073 + current->mm->start_brk = current->mm->brk = e;
41074 return 0;
41075 }
41076
41077 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41078 elf_addr_t __user *u_rand_bytes;
41079 const char *k_platform = ELF_PLATFORM;
41080 const char *k_base_platform = ELF_BASE_PLATFORM;
41081 - unsigned char k_rand_bytes[16];
41082 + u32 k_rand_bytes[4];
41083 int items;
41084 elf_addr_t *elf_info;
41085 int ei_index = 0;
41086 const struct cred *cred = current_cred();
41087 struct vm_area_struct *vma;
41088 + unsigned long saved_auxv[AT_VECTOR_SIZE];
41089
41090 /*
41091 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41092 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41093 * Generate 16 random bytes for userspace PRNG seeding.
41094 */
41095 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41096 - u_rand_bytes = (elf_addr_t __user *)
41097 - STACK_ALLOC(p, sizeof(k_rand_bytes));
41098 + srandom32(k_rand_bytes[0] ^ random32());
41099 + srandom32(k_rand_bytes[1] ^ random32());
41100 + srandom32(k_rand_bytes[2] ^ random32());
41101 + srandom32(k_rand_bytes[3] ^ random32());
41102 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
41103 + u_rand_bytes = (elf_addr_t __user *) p;
41104 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41105 return -EFAULT;
41106
41107 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41108 return -EFAULT;
41109 current->mm->env_end = p;
41110
41111 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41112 +
41113 /* Put the elf_info on the stack in the right place. */
41114 sp = (elf_addr_t __user *)envp + 1;
41115 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41116 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41117 return -EFAULT;
41118 return 0;
41119 }
41120 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41121 {
41122 struct elf_phdr *elf_phdata;
41123 struct elf_phdr *eppnt;
41124 - unsigned long load_addr = 0;
41125 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41126 int load_addr_set = 0;
41127 unsigned long last_bss = 0, elf_bss = 0;
41128 - unsigned long error = ~0UL;
41129 + unsigned long error = -EINVAL;
41130 unsigned long total_size;
41131 int retval, i, size;
41132
41133 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41134 goto out_close;
41135 }
41136
41137 +#ifdef CONFIG_PAX_SEGMEXEC
41138 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41139 + pax_task_size = SEGMEXEC_TASK_SIZE;
41140 +#endif
41141 +
41142 eppnt = elf_phdata;
41143 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41144 if (eppnt->p_type == PT_LOAD) {
41145 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41146 k = load_addr + eppnt->p_vaddr;
41147 if (BAD_ADDR(k) ||
41148 eppnt->p_filesz > eppnt->p_memsz ||
41149 - eppnt->p_memsz > TASK_SIZE ||
41150 - TASK_SIZE - eppnt->p_memsz < k) {
41151 + eppnt->p_memsz > pax_task_size ||
41152 + pax_task_size - eppnt->p_memsz < k) {
41153 error = -ENOMEM;
41154 goto out_close;
41155 }
41156 @@ -528,6 +552,351 @@ out:
41157 return error;
41158 }
41159
41160 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41161 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41162 +{
41163 + unsigned long pax_flags = 0UL;
41164 +
41165 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41166 +
41167 +#ifdef CONFIG_PAX_PAGEEXEC
41168 + if (elf_phdata->p_flags & PF_PAGEEXEC)
41169 + pax_flags |= MF_PAX_PAGEEXEC;
41170 +#endif
41171 +
41172 +#ifdef CONFIG_PAX_SEGMEXEC
41173 + if (elf_phdata->p_flags & PF_SEGMEXEC)
41174 + pax_flags |= MF_PAX_SEGMEXEC;
41175 +#endif
41176 +
41177 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41178 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41179 + if ((__supported_pte_mask & _PAGE_NX))
41180 + pax_flags &= ~MF_PAX_SEGMEXEC;
41181 + else
41182 + pax_flags &= ~MF_PAX_PAGEEXEC;
41183 + }
41184 +#endif
41185 +
41186 +#ifdef CONFIG_PAX_EMUTRAMP
41187 + if (elf_phdata->p_flags & PF_EMUTRAMP)
41188 + pax_flags |= MF_PAX_EMUTRAMP;
41189 +#endif
41190 +
41191 +#ifdef CONFIG_PAX_MPROTECT
41192 + if (elf_phdata->p_flags & PF_MPROTECT)
41193 + pax_flags |= MF_PAX_MPROTECT;
41194 +#endif
41195 +
41196 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41197 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41198 + pax_flags |= MF_PAX_RANDMMAP;
41199 +#endif
41200 +
41201 +#endif
41202 +
41203 + return pax_flags;
41204 +}
41205 +
41206 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41207 +{
41208 + unsigned long pax_flags = 0UL;
41209 +
41210 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41211 +
41212 +#ifdef CONFIG_PAX_PAGEEXEC
41213 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41214 + pax_flags |= MF_PAX_PAGEEXEC;
41215 +#endif
41216 +
41217 +#ifdef CONFIG_PAX_SEGMEXEC
41218 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41219 + pax_flags |= MF_PAX_SEGMEXEC;
41220 +#endif
41221 +
41222 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41223 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41224 + if ((__supported_pte_mask & _PAGE_NX))
41225 + pax_flags &= ~MF_PAX_SEGMEXEC;
41226 + else
41227 + pax_flags &= ~MF_PAX_PAGEEXEC;
41228 + }
41229 +#endif
41230 +
41231 +#ifdef CONFIG_PAX_EMUTRAMP
41232 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
41233 + pax_flags |= MF_PAX_EMUTRAMP;
41234 +#endif
41235 +
41236 +#ifdef CONFIG_PAX_MPROTECT
41237 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
41238 + pax_flags |= MF_PAX_MPROTECT;
41239 +#endif
41240 +
41241 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41242 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
41243 + pax_flags |= MF_PAX_RANDMMAP;
41244 +#endif
41245 +
41246 +#endif
41247 +
41248 + return pax_flags;
41249 +}
41250 +
41251 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
41252 +{
41253 + unsigned long pax_flags = 0UL;
41254 +
41255 +#ifdef CONFIG_PAX_EI_PAX
41256 +
41257 +#ifdef CONFIG_PAX_PAGEEXEC
41258 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
41259 + pax_flags |= MF_PAX_PAGEEXEC;
41260 +#endif
41261 +
41262 +#ifdef CONFIG_PAX_SEGMEXEC
41263 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
41264 + pax_flags |= MF_PAX_SEGMEXEC;
41265 +#endif
41266 +
41267 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41268 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41269 + if ((__supported_pte_mask & _PAGE_NX))
41270 + pax_flags &= ~MF_PAX_SEGMEXEC;
41271 + else
41272 + pax_flags &= ~MF_PAX_PAGEEXEC;
41273 + }
41274 +#endif
41275 +
41276 +#ifdef CONFIG_PAX_EMUTRAMP
41277 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
41278 + pax_flags |= MF_PAX_EMUTRAMP;
41279 +#endif
41280 +
41281 +#ifdef CONFIG_PAX_MPROTECT
41282 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
41283 + pax_flags |= MF_PAX_MPROTECT;
41284 +#endif
41285 +
41286 +#ifdef CONFIG_PAX_ASLR
41287 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
41288 + pax_flags |= MF_PAX_RANDMMAP;
41289 +#endif
41290 +
41291 +#else
41292 +
41293 +#ifdef CONFIG_PAX_PAGEEXEC
41294 + pax_flags |= MF_PAX_PAGEEXEC;
41295 +#endif
41296 +
41297 +#ifdef CONFIG_PAX_MPROTECT
41298 + pax_flags |= MF_PAX_MPROTECT;
41299 +#endif
41300 +
41301 +#ifdef CONFIG_PAX_RANDMMAP
41302 + pax_flags |= MF_PAX_RANDMMAP;
41303 +#endif
41304 +
41305 +#ifdef CONFIG_PAX_SEGMEXEC
41306 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
41307 + pax_flags &= ~MF_PAX_PAGEEXEC;
41308 + pax_flags |= MF_PAX_SEGMEXEC;
41309 + }
41310 +#endif
41311 +
41312 +#endif
41313 +
41314 + return pax_flags;
41315 +}
41316 +
41317 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
41318 +{
41319 +
41320 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41321 + unsigned long i;
41322 +
41323 + for (i = 0UL; i < elf_ex->e_phnum; i++)
41324 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
41325 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
41326 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
41327 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
41328 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
41329 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
41330 + return ~0UL;
41331 +
41332 +#ifdef CONFIG_PAX_SOFTMODE
41333 + if (pax_softmode)
41334 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
41335 + else
41336 +#endif
41337 +
41338 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
41339 + break;
41340 + }
41341 +#endif
41342 +
41343 + return ~0UL;
41344 +}
41345 +
41346 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41347 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
41348 +{
41349 + unsigned long pax_flags = 0UL;
41350 +
41351 +#ifdef CONFIG_PAX_PAGEEXEC
41352 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
41353 + pax_flags |= MF_PAX_PAGEEXEC;
41354 +#endif
41355 +
41356 +#ifdef CONFIG_PAX_SEGMEXEC
41357 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
41358 + pax_flags |= MF_PAX_SEGMEXEC;
41359 +#endif
41360 +
41361 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41362 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41363 + if ((__supported_pte_mask & _PAGE_NX))
41364 + pax_flags &= ~MF_PAX_SEGMEXEC;
41365 + else
41366 + pax_flags &= ~MF_PAX_PAGEEXEC;
41367 + }
41368 +#endif
41369 +
41370 +#ifdef CONFIG_PAX_EMUTRAMP
41371 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
41372 + pax_flags |= MF_PAX_EMUTRAMP;
41373 +#endif
41374 +
41375 +#ifdef CONFIG_PAX_MPROTECT
41376 + if (pax_flags_softmode & MF_PAX_MPROTECT)
41377 + pax_flags |= MF_PAX_MPROTECT;
41378 +#endif
41379 +
41380 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41381 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
41382 + pax_flags |= MF_PAX_RANDMMAP;
41383 +#endif
41384 +
41385 + return pax_flags;
41386 +}
41387 +
41388 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
41389 +{
41390 + unsigned long pax_flags = 0UL;
41391 +
41392 +#ifdef CONFIG_PAX_PAGEEXEC
41393 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
41394 + pax_flags |= MF_PAX_PAGEEXEC;
41395 +#endif
41396 +
41397 +#ifdef CONFIG_PAX_SEGMEXEC
41398 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
41399 + pax_flags |= MF_PAX_SEGMEXEC;
41400 +#endif
41401 +
41402 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41403 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41404 + if ((__supported_pte_mask & _PAGE_NX))
41405 + pax_flags &= ~MF_PAX_SEGMEXEC;
41406 + else
41407 + pax_flags &= ~MF_PAX_PAGEEXEC;
41408 + }
41409 +#endif
41410 +
41411 +#ifdef CONFIG_PAX_EMUTRAMP
41412 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
41413 + pax_flags |= MF_PAX_EMUTRAMP;
41414 +#endif
41415 +
41416 +#ifdef CONFIG_PAX_MPROTECT
41417 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
41418 + pax_flags |= MF_PAX_MPROTECT;
41419 +#endif
41420 +
41421 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41422 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
41423 + pax_flags |= MF_PAX_RANDMMAP;
41424 +#endif
41425 +
41426 + return pax_flags;
41427 +}
41428 +#endif
41429 +
41430 +static unsigned long pax_parse_xattr_pax(struct file * const file)
41431 +{
41432 +
41433 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41434 + ssize_t xattr_size, i;
41435 + unsigned char xattr_value[5];
41436 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
41437 +
41438 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
41439 + if (xattr_size <= 0)
41440 + return ~0UL;
41441 +
41442 + for (i = 0; i < xattr_size; i++)
41443 + switch (xattr_value[i]) {
41444 + default:
41445 + return ~0UL;
41446 +
41447 +#define parse_flag(option1, option2, flag) \
41448 + case option1: \
41449 + pax_flags_hardmode |= MF_PAX_##flag; \
41450 + break; \
41451 + case option2: \
41452 + pax_flags_softmode |= MF_PAX_##flag; \
41453 + break;
41454 +
41455 + parse_flag('p', 'P', PAGEEXEC);
41456 + parse_flag('e', 'E', EMUTRAMP);
41457 + parse_flag('m', 'M', MPROTECT);
41458 + parse_flag('r', 'R', RANDMMAP);
41459 + parse_flag('s', 'S', SEGMEXEC);
41460 +
41461 +#undef parse_flag
41462 + }
41463 +
41464 + if (pax_flags_hardmode & pax_flags_softmode)
41465 + return ~0UL;
41466 +
41467 +#ifdef CONFIG_PAX_SOFTMODE
41468 + if (pax_softmode)
41469 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
41470 + else
41471 +#endif
41472 +
41473 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
41474 +#else
41475 + return ~0UL;
41476 +#endif
41477 +
41478 +}
41479 +
41480 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
41481 +{
41482 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
41483 +
41484 + pax_flags = pax_parse_ei_pax(elf_ex);
41485 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
41486 + xattr_pax_flags = pax_parse_xattr_pax(file);
41487 +
41488 + if (pt_pax_flags == ~0UL)
41489 + pt_pax_flags = xattr_pax_flags;
41490 + else if (xattr_pax_flags == ~0UL)
41491 + xattr_pax_flags = pt_pax_flags;
41492 + if (pt_pax_flags != xattr_pax_flags)
41493 + return -EINVAL;
41494 + if (pt_pax_flags != ~0UL)
41495 + pax_flags = pt_pax_flags;
41496 +
41497 + if (0 > pax_check_flags(&pax_flags))
41498 + return -EINVAL;
41499 +
41500 + current->mm->pax_flags = pax_flags;
41501 + return 0;
41502 +}
41503 +#endif
41504 +
41505 /*
41506 * These are the functions used to load ELF style executables and shared
41507 * libraries. There is no binary dependent code anywhere else.
41508 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
41509 {
41510 unsigned int random_variable = 0;
41511
41512 +#ifdef CONFIG_PAX_RANDUSTACK
41513 + if (randomize_va_space)
41514 + return stack_top - current->mm->delta_stack;
41515 +#endif
41516 +
41517 if ((current->flags & PF_RANDOMIZE) &&
41518 !(current->personality & ADDR_NO_RANDOMIZE)) {
41519 random_variable = get_random_int() & STACK_RND_MASK;
41520 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41521 unsigned long load_addr = 0, load_bias = 0;
41522 int load_addr_set = 0;
41523 char * elf_interpreter = NULL;
41524 - unsigned long error;
41525 + unsigned long error = 0;
41526 struct elf_phdr *elf_ppnt, *elf_phdata;
41527 unsigned long elf_bss, elf_brk;
41528 int retval, i;
41529 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41530 unsigned long start_code, end_code, start_data, end_data;
41531 unsigned long reloc_func_desc __maybe_unused = 0;
41532 int executable_stack = EXSTACK_DEFAULT;
41533 - unsigned long def_flags = 0;
41534 struct {
41535 struct elfhdr elf_ex;
41536 struct elfhdr interp_elf_ex;
41537 } *loc;
41538 + unsigned long pax_task_size = TASK_SIZE;
41539
41540 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
41541 if (!loc) {
41542 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41543
41544 /* OK, This is the point of no return */
41545 current->flags &= ~PF_FORKNOEXEC;
41546 - current->mm->def_flags = def_flags;
41547 +
41548 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41549 + current->mm->pax_flags = 0UL;
41550 +#endif
41551 +
41552 +#ifdef CONFIG_PAX_DLRESOLVE
41553 + current->mm->call_dl_resolve = 0UL;
41554 +#endif
41555 +
41556 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
41557 + current->mm->call_syscall = 0UL;
41558 +#endif
41559 +
41560 +#ifdef CONFIG_PAX_ASLR
41561 + current->mm->delta_mmap = 0UL;
41562 + current->mm->delta_stack = 0UL;
41563 +#endif
41564 +
41565 + current->mm->def_flags = 0;
41566 +
41567 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41568 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
41569 + send_sig(SIGKILL, current, 0);
41570 + goto out_free_dentry;
41571 + }
41572 +#endif
41573 +
41574 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
41575 + pax_set_initial_flags(bprm);
41576 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
41577 + if (pax_set_initial_flags_func)
41578 + (pax_set_initial_flags_func)(bprm);
41579 +#endif
41580 +
41581 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
41582 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
41583 + current->mm->context.user_cs_limit = PAGE_SIZE;
41584 + current->mm->def_flags |= VM_PAGEEXEC;
41585 + }
41586 +#endif
41587 +
41588 +#ifdef CONFIG_PAX_SEGMEXEC
41589 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
41590 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
41591 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
41592 + pax_task_size = SEGMEXEC_TASK_SIZE;
41593 + current->mm->def_flags |= VM_NOHUGEPAGE;
41594 + }
41595 +#endif
41596 +
41597 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
41598 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41599 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
41600 + put_cpu();
41601 + }
41602 +#endif
41603
41604 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
41605 may depend on the personality. */
41606 SET_PERSONALITY(loc->elf_ex);
41607 +
41608 +#ifdef CONFIG_PAX_ASLR
41609 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
41610 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
41611 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
41612 + }
41613 +#endif
41614 +
41615 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41616 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41617 + executable_stack = EXSTACK_DISABLE_X;
41618 + current->personality &= ~READ_IMPLIES_EXEC;
41619 + } else
41620 +#endif
41621 +
41622 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
41623 current->personality |= READ_IMPLIES_EXEC;
41624
41625 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41626 #else
41627 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
41628 #endif
41629 +
41630 +#ifdef CONFIG_PAX_RANDMMAP
41631 + /* PaX: randomize base address at the default exe base if requested */
41632 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
41633 +#ifdef CONFIG_SPARC64
41634 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
41635 +#else
41636 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
41637 +#endif
41638 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
41639 + elf_flags |= MAP_FIXED;
41640 + }
41641 +#endif
41642 +
41643 }
41644
41645 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
41646 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41647 * allowed task size. Note that p_filesz must always be
41648 * <= p_memsz so it is only necessary to check p_memsz.
41649 */
41650 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
41651 - elf_ppnt->p_memsz > TASK_SIZE ||
41652 - TASK_SIZE - elf_ppnt->p_memsz < k) {
41653 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
41654 + elf_ppnt->p_memsz > pax_task_size ||
41655 + pax_task_size - elf_ppnt->p_memsz < k) {
41656 /* set_brk can never work. Avoid overflows. */
41657 send_sig(SIGKILL, current, 0);
41658 retval = -EINVAL;
41659 @@ -881,11 +1339,35 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41660 goto out_free_dentry;
41661 }
41662 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
41663 - send_sig(SIGSEGV, current, 0);
41664 - retval = -EFAULT; /* Nobody gets to see this, but.. */
41665 - goto out_free_dentry;
41666 + /*
41667 + * This bss-zeroing can fail if the ELF
41668 + * file specifies odd protections. So
41669 + * we don't check the return value
41670 + */
41671 }
41672
41673 +#ifdef CONFIG_PAX_RANDMMAP
41674 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
41675 + unsigned long start, size;
41676 +
41677 + start = ELF_PAGEALIGN(elf_brk);
41678 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
41679 + down_write(&current->mm->mmap_sem);
41680 + retval = -ENOMEM;
41681 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
41682 + start = do_mmap(NULL, start, size, PROT_NONE, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
41683 + retval = IS_ERR_VALUE(start) ? start : 0;
41684 + }
41685 + up_write(&current->mm->mmap_sem);
41686 + if (retval == 0)
41687 + retval = set_brk(start + size, start + size + PAGE_SIZE);
41688 + if (retval < 0) {
41689 + send_sig(SIGKILL, current, 0);
41690 + goto out_free_dentry;
41691 + }
41692 + }
41693 +#endif
41694 +
41695 if (elf_interpreter) {
41696 unsigned long uninitialized_var(interp_map_addr);
41697
41698 @@ -1098,7 +1580,7 @@ out:
41699 * Decide what to dump of a segment, part, all or none.
41700 */
41701 static unsigned long vma_dump_size(struct vm_area_struct *vma,
41702 - unsigned long mm_flags)
41703 + unsigned long mm_flags, long signr)
41704 {
41705 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
41706
41707 @@ -1132,7 +1614,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
41708 if (vma->vm_file == NULL)
41709 return 0;
41710
41711 - if (FILTER(MAPPED_PRIVATE))
41712 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
41713 goto whole;
41714
41715 /*
41716 @@ -1354,9 +1836,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
41717 {
41718 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
41719 int i = 0;
41720 - do
41721 + do {
41722 i += 2;
41723 - while (auxv[i - 2] != AT_NULL);
41724 + } while (auxv[i - 2] != AT_NULL);
41725 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
41726 }
41727
41728 @@ -1862,14 +2344,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
41729 }
41730
41731 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
41732 - unsigned long mm_flags)
41733 + struct coredump_params *cprm)
41734 {
41735 struct vm_area_struct *vma;
41736 size_t size = 0;
41737
41738 for (vma = first_vma(current, gate_vma); vma != NULL;
41739 vma = next_vma(vma, gate_vma))
41740 - size += vma_dump_size(vma, mm_flags);
41741 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41742 return size;
41743 }
41744
41745 @@ -1963,7 +2445,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41746
41747 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
41748
41749 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
41750 + offset += elf_core_vma_data_size(gate_vma, cprm);
41751 offset += elf_core_extra_data_size();
41752 e_shoff = offset;
41753
41754 @@ -1977,10 +2459,12 @@ static int elf_core_dump(struct coredump_params *cprm)
41755 offset = dataoff;
41756
41757 size += sizeof(*elf);
41758 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
41759 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
41760 goto end_coredump;
41761
41762 size += sizeof(*phdr4note);
41763 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
41764 if (size > cprm->limit
41765 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
41766 goto end_coredump;
41767 @@ -1994,7 +2478,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41768 phdr.p_offset = offset;
41769 phdr.p_vaddr = vma->vm_start;
41770 phdr.p_paddr = 0;
41771 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
41772 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41773 phdr.p_memsz = vma->vm_end - vma->vm_start;
41774 offset += phdr.p_filesz;
41775 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
41776 @@ -2005,6 +2489,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41777 phdr.p_align = ELF_EXEC_PAGESIZE;
41778
41779 size += sizeof(phdr);
41780 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
41781 if (size > cprm->limit
41782 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
41783 goto end_coredump;
41784 @@ -2029,7 +2514,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41785 unsigned long addr;
41786 unsigned long end;
41787
41788 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
41789 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41790
41791 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
41792 struct page *page;
41793 @@ -2038,6 +2523,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41794 page = get_dump_page(addr);
41795 if (page) {
41796 void *kaddr = kmap(page);
41797 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
41798 stop = ((size += PAGE_SIZE) > cprm->limit) ||
41799 !dump_write(cprm->file, kaddr,
41800 PAGE_SIZE);
41801 @@ -2055,6 +2541,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41802
41803 if (e_phnum == PN_XNUM) {
41804 size += sizeof(*shdr4extnum);
41805 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
41806 if (size > cprm->limit
41807 || !dump_write(cprm->file, shdr4extnum,
41808 sizeof(*shdr4extnum)))
41809 @@ -2075,6 +2562,97 @@ out:
41810
41811 #endif /* CONFIG_ELF_CORE */
41812
41813 +#ifdef CONFIG_PAX_MPROTECT
41814 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
41815 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
41816 + * we'll remove VM_MAYWRITE for good on RELRO segments.
41817 + *
41818 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
41819 + * basis because we want to allow the common case and not the special ones.
41820 + */
41821 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
41822 +{
41823 + struct elfhdr elf_h;
41824 + struct elf_phdr elf_p;
41825 + unsigned long i;
41826 + unsigned long oldflags;
41827 + bool is_textrel_rw, is_textrel_rx, is_relro;
41828 +
41829 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
41830 + return;
41831 +
41832 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
41833 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
41834 +
41835 +#ifdef CONFIG_PAX_ELFRELOCS
41836 + /* possible TEXTREL */
41837 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
41838 + 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);
41839 +#else
41840 + is_textrel_rw = false;
41841 + is_textrel_rx = false;
41842 +#endif
41843 +
41844 + /* possible RELRO */
41845 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
41846 +
41847 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
41848 + return;
41849 +
41850 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
41851 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
41852 +
41853 +#ifdef CONFIG_PAX_ETEXECRELOCS
41854 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
41855 +#else
41856 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
41857 +#endif
41858 +
41859 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
41860 + !elf_check_arch(&elf_h) ||
41861 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
41862 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
41863 + return;
41864 +
41865 + for (i = 0UL; i < elf_h.e_phnum; i++) {
41866 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
41867 + return;
41868 + switch (elf_p.p_type) {
41869 + case PT_DYNAMIC:
41870 + if (!is_textrel_rw && !is_textrel_rx)
41871 + continue;
41872 + i = 0UL;
41873 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
41874 + elf_dyn dyn;
41875 +
41876 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
41877 + return;
41878 + if (dyn.d_tag == DT_NULL)
41879 + return;
41880 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
41881 + gr_log_textrel(vma);
41882 + if (is_textrel_rw)
41883 + vma->vm_flags |= VM_MAYWRITE;
41884 + else
41885 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
41886 + vma->vm_flags &= ~VM_MAYWRITE;
41887 + return;
41888 + }
41889 + i++;
41890 + }
41891 + return;
41892 +
41893 + case PT_GNU_RELRO:
41894 + if (!is_relro)
41895 + continue;
41896 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
41897 + vma->vm_flags &= ~VM_MAYWRITE;
41898 + return;
41899 + }
41900 + }
41901 +}
41902 +#endif
41903 +
41904 static int __init init_elf_binfmt(void)
41905 {
41906 return register_binfmt(&elf_format);
41907 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
41908 index 1bffbe0..c8c283e 100644
41909 --- a/fs/binfmt_flat.c
41910 +++ b/fs/binfmt_flat.c
41911 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
41912 realdatastart = (unsigned long) -ENOMEM;
41913 printk("Unable to allocate RAM for process data, errno %d\n",
41914 (int)-realdatastart);
41915 + down_write(&current->mm->mmap_sem);
41916 do_munmap(current->mm, textpos, text_len);
41917 + up_write(&current->mm->mmap_sem);
41918 ret = realdatastart;
41919 goto err;
41920 }
41921 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
41922 }
41923 if (IS_ERR_VALUE(result)) {
41924 printk("Unable to read data+bss, errno %d\n", (int)-result);
41925 + down_write(&current->mm->mmap_sem);
41926 do_munmap(current->mm, textpos, text_len);
41927 do_munmap(current->mm, realdatastart, len);
41928 + up_write(&current->mm->mmap_sem);
41929 ret = result;
41930 goto err;
41931 }
41932 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
41933 }
41934 if (IS_ERR_VALUE(result)) {
41935 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
41936 + down_write(&current->mm->mmap_sem);
41937 do_munmap(current->mm, textpos, text_len + data_len + extra +
41938 MAX_SHARED_LIBS * sizeof(unsigned long));
41939 + up_write(&current->mm->mmap_sem);
41940 ret = result;
41941 goto err;
41942 }
41943 diff --git a/fs/bio.c b/fs/bio.c
41944 index b980ecd..74800bf 100644
41945 --- a/fs/bio.c
41946 +++ b/fs/bio.c
41947 @@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
41948 /*
41949 * Overflow, abort
41950 */
41951 - if (end < start)
41952 + if (end < start || end - start > INT_MAX - nr_pages)
41953 return ERR_PTR(-EINVAL);
41954
41955 nr_pages += end - start;
41956 @@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
41957 const int read = bio_data_dir(bio) == READ;
41958 struct bio_map_data *bmd = bio->bi_private;
41959 int i;
41960 - char *p = bmd->sgvecs[0].iov_base;
41961 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
41962
41963 __bio_for_each_segment(bvec, bio, i, 0) {
41964 char *addr = page_address(bvec->bv_page);
41965 diff --git a/fs/block_dev.c b/fs/block_dev.c
41966 index 5e9f198..6bf9b1c 100644
41967 --- a/fs/block_dev.c
41968 +++ b/fs/block_dev.c
41969 @@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
41970 else if (bdev->bd_contains == bdev)
41971 return true; /* is a whole device which isn't held */
41972
41973 - else if (whole->bd_holder == bd_may_claim)
41974 + else if (whole->bd_holder == (void *)bd_may_claim)
41975 return true; /* is a partition of a device that is being partitioned */
41976 else if (whole->bd_holder != NULL)
41977 return false; /* is a partition of a held device */
41978 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
41979 index d986824..af1befd 100644
41980 --- a/fs/btrfs/check-integrity.c
41981 +++ b/fs/btrfs/check-integrity.c
41982 @@ -157,7 +157,7 @@ struct btrfsic_block {
41983 union {
41984 bio_end_io_t *bio;
41985 bh_end_io_t *bh;
41986 - } orig_bio_bh_end_io;
41987 + } __no_const orig_bio_bh_end_io;
41988 int submit_bio_bh_rw;
41989 u64 flush_gen; /* only valid if !never_written */
41990 };
41991 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
41992 index 0639a55..7d9e07f 100644
41993 --- a/fs/btrfs/ctree.c
41994 +++ b/fs/btrfs/ctree.c
41995 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
41996 free_extent_buffer(buf);
41997 add_root_to_dirty_list(root);
41998 } else {
41999 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42000 - parent_start = parent->start;
42001 - else
42002 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42003 + if (parent)
42004 + parent_start = parent->start;
42005 + else
42006 + parent_start = 0;
42007 + } else
42008 parent_start = 0;
42009
42010 WARN_ON(trans->transid != btrfs_header_generation(parent));
42011 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42012 index 892b347..b3db246 100644
42013 --- a/fs/btrfs/inode.c
42014 +++ b/fs/btrfs/inode.c
42015 @@ -6930,7 +6930,7 @@ fail:
42016 return -ENOMEM;
42017 }
42018
42019 -static int btrfs_getattr(struct vfsmount *mnt,
42020 +int btrfs_getattr(struct vfsmount *mnt,
42021 struct dentry *dentry, struct kstat *stat)
42022 {
42023 struct inode *inode = dentry->d_inode;
42024 @@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42025 return 0;
42026 }
42027
42028 +EXPORT_SYMBOL(btrfs_getattr);
42029 +
42030 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
42031 +{
42032 + return BTRFS_I(inode)->root->anon_dev;
42033 +}
42034 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42035 +
42036 /*
42037 * If a file is moved, it will inherit the cow and compression flags of the new
42038 * directory.
42039 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42040 index d8b5471..e5463d7 100644
42041 --- a/fs/btrfs/ioctl.c
42042 +++ b/fs/btrfs/ioctl.c
42043 @@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42044 for (i = 0; i < num_types; i++) {
42045 struct btrfs_space_info *tmp;
42046
42047 + /* Don't copy in more than we allocated */
42048 if (!slot_count)
42049 break;
42050
42051 + slot_count--;
42052 +
42053 info = NULL;
42054 rcu_read_lock();
42055 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42056 @@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42057 memcpy(dest, &space, sizeof(space));
42058 dest++;
42059 space_args.total_spaces++;
42060 - slot_count--;
42061 }
42062 - if (!slot_count)
42063 - break;
42064 }
42065 up_read(&info->groups_sem);
42066 }
42067
42068 - user_dest = (struct btrfs_ioctl_space_info *)
42069 + user_dest = (struct btrfs_ioctl_space_info __user *)
42070 (arg + sizeof(struct btrfs_ioctl_space_args));
42071
42072 if (copy_to_user(user_dest, dest_orig, alloc_size))
42073 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
42074 index 8c1aae2..1e46446 100644
42075 --- a/fs/btrfs/relocation.c
42076 +++ b/fs/btrfs/relocation.c
42077 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
42078 }
42079 spin_unlock(&rc->reloc_root_tree.lock);
42080
42081 - BUG_ON((struct btrfs_root *)node->data != root);
42082 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
42083
42084 if (!del) {
42085 spin_lock(&rc->reloc_root_tree.lock);
42086 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
42087 index 622f469..e8d2d55 100644
42088 --- a/fs/cachefiles/bind.c
42089 +++ b/fs/cachefiles/bind.c
42090 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
42091 args);
42092
42093 /* start by checking things over */
42094 - ASSERT(cache->fstop_percent >= 0 &&
42095 - cache->fstop_percent < cache->fcull_percent &&
42096 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
42097 cache->fcull_percent < cache->frun_percent &&
42098 cache->frun_percent < 100);
42099
42100 - ASSERT(cache->bstop_percent >= 0 &&
42101 - cache->bstop_percent < cache->bcull_percent &&
42102 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
42103 cache->bcull_percent < cache->brun_percent &&
42104 cache->brun_percent < 100);
42105
42106 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42107 index 0a1467b..6a53245 100644
42108 --- a/fs/cachefiles/daemon.c
42109 +++ b/fs/cachefiles/daemon.c
42110 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42111 if (n > buflen)
42112 return -EMSGSIZE;
42113
42114 - if (copy_to_user(_buffer, buffer, n) != 0)
42115 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42116 return -EFAULT;
42117
42118 return n;
42119 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42120 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42121 return -EIO;
42122
42123 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
42124 + if (datalen > PAGE_SIZE - 1)
42125 return -EOPNOTSUPP;
42126
42127 /* drag the command string into the kernel so we can parse it */
42128 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42129 if (args[0] != '%' || args[1] != '\0')
42130 return -EINVAL;
42131
42132 - if (fstop < 0 || fstop >= cache->fcull_percent)
42133 + if (fstop >= cache->fcull_percent)
42134 return cachefiles_daemon_range_error(cache, args);
42135
42136 cache->fstop_percent = fstop;
42137 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42138 if (args[0] != '%' || args[1] != '\0')
42139 return -EINVAL;
42140
42141 - if (bstop < 0 || bstop >= cache->bcull_percent)
42142 + if (bstop >= cache->bcull_percent)
42143 return cachefiles_daemon_range_error(cache, args);
42144
42145 cache->bstop_percent = bstop;
42146 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42147 index bd6bc1b..b627b53 100644
42148 --- a/fs/cachefiles/internal.h
42149 +++ b/fs/cachefiles/internal.h
42150 @@ -57,7 +57,7 @@ struct cachefiles_cache {
42151 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42152 struct rb_root active_nodes; /* active nodes (can't be culled) */
42153 rwlock_t active_lock; /* lock for active_nodes */
42154 - atomic_t gravecounter; /* graveyard uniquifier */
42155 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42156 unsigned frun_percent; /* when to stop culling (% files) */
42157 unsigned fcull_percent; /* when to start culling (% files) */
42158 unsigned fstop_percent; /* when to stop allocating (% files) */
42159 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42160 * proc.c
42161 */
42162 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42163 -extern atomic_t cachefiles_lookup_histogram[HZ];
42164 -extern atomic_t cachefiles_mkdir_histogram[HZ];
42165 -extern atomic_t cachefiles_create_histogram[HZ];
42166 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42167 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42168 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42169
42170 extern int __init cachefiles_proc_init(void);
42171 extern void cachefiles_proc_cleanup(void);
42172 static inline
42173 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42174 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42175 {
42176 unsigned long jif = jiffies - start_jif;
42177 if (jif >= HZ)
42178 jif = HZ - 1;
42179 - atomic_inc(&histogram[jif]);
42180 + atomic_inc_unchecked(&histogram[jif]);
42181 }
42182
42183 #else
42184 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42185 index a0358c2..d6137f2 100644
42186 --- a/fs/cachefiles/namei.c
42187 +++ b/fs/cachefiles/namei.c
42188 @@ -318,7 +318,7 @@ try_again:
42189 /* first step is to make up a grave dentry in the graveyard */
42190 sprintf(nbuffer, "%08x%08x",
42191 (uint32_t) get_seconds(),
42192 - (uint32_t) atomic_inc_return(&cache->gravecounter));
42193 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42194
42195 /* do the multiway lock magic */
42196 trap = lock_rename(cache->graveyard, dir);
42197 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42198 index eccd339..4c1d995 100644
42199 --- a/fs/cachefiles/proc.c
42200 +++ b/fs/cachefiles/proc.c
42201 @@ -14,9 +14,9 @@
42202 #include <linux/seq_file.h>
42203 #include "internal.h"
42204
42205 -atomic_t cachefiles_lookup_histogram[HZ];
42206 -atomic_t cachefiles_mkdir_histogram[HZ];
42207 -atomic_t cachefiles_create_histogram[HZ];
42208 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42209 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42210 +atomic_unchecked_t cachefiles_create_histogram[HZ];
42211
42212 /*
42213 * display the latency histogram
42214 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42215 return 0;
42216 default:
42217 index = (unsigned long) v - 3;
42218 - x = atomic_read(&cachefiles_lookup_histogram[index]);
42219 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
42220 - z = atomic_read(&cachefiles_create_histogram[index]);
42221 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42222 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42223 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42224 if (x == 0 && y == 0 && z == 0)
42225 return 0;
42226
42227 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
42228 index 0e3c092..818480e 100644
42229 --- a/fs/cachefiles/rdwr.c
42230 +++ b/fs/cachefiles/rdwr.c
42231 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
42232 old_fs = get_fs();
42233 set_fs(KERNEL_DS);
42234 ret = file->f_op->write(
42235 - file, (const void __user *) data, len, &pos);
42236 + file, (const void __force_user *) data, len, &pos);
42237 set_fs(old_fs);
42238 kunmap(page);
42239 if (ret != len)
42240 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
42241 index 3e8094b..cb3ff3d 100644
42242 --- a/fs/ceph/dir.c
42243 +++ b/fs/ceph/dir.c
42244 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
42245 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
42246 struct ceph_mds_client *mdsc = fsc->mdsc;
42247 unsigned frag = fpos_frag(filp->f_pos);
42248 - int off = fpos_off(filp->f_pos);
42249 + unsigned int off = fpos_off(filp->f_pos);
42250 int err;
42251 u32 ftype;
42252 struct ceph_mds_reply_info_parsed *rinfo;
42253 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
42254 if (nd &&
42255 (nd->flags & LOOKUP_OPEN) &&
42256 !(nd->intent.open.flags & O_CREAT)) {
42257 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
42258 + int mode = nd->intent.open.create_mode & ~current_umask();
42259 return ceph_lookup_open(dir, dentry, nd, mode, 1);
42260 }
42261
42262 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
42263 index 24b3dfc..3cd5454 100644
42264 --- a/fs/cifs/cifs_debug.c
42265 +++ b/fs/cifs/cifs_debug.c
42266 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42267
42268 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
42269 #ifdef CONFIG_CIFS_STATS2
42270 - atomic_set(&totBufAllocCount, 0);
42271 - atomic_set(&totSmBufAllocCount, 0);
42272 + atomic_set_unchecked(&totBufAllocCount, 0);
42273 + atomic_set_unchecked(&totSmBufAllocCount, 0);
42274 #endif /* CONFIG_CIFS_STATS2 */
42275 spin_lock(&cifs_tcp_ses_lock);
42276 list_for_each(tmp1, &cifs_tcp_ses_list) {
42277 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42278 tcon = list_entry(tmp3,
42279 struct cifs_tcon,
42280 tcon_list);
42281 - atomic_set(&tcon->num_smbs_sent, 0);
42282 - atomic_set(&tcon->num_writes, 0);
42283 - atomic_set(&tcon->num_reads, 0);
42284 - atomic_set(&tcon->num_oplock_brks, 0);
42285 - atomic_set(&tcon->num_opens, 0);
42286 - atomic_set(&tcon->num_posixopens, 0);
42287 - atomic_set(&tcon->num_posixmkdirs, 0);
42288 - atomic_set(&tcon->num_closes, 0);
42289 - atomic_set(&tcon->num_deletes, 0);
42290 - atomic_set(&tcon->num_mkdirs, 0);
42291 - atomic_set(&tcon->num_rmdirs, 0);
42292 - atomic_set(&tcon->num_renames, 0);
42293 - atomic_set(&tcon->num_t2renames, 0);
42294 - atomic_set(&tcon->num_ffirst, 0);
42295 - atomic_set(&tcon->num_fnext, 0);
42296 - atomic_set(&tcon->num_fclose, 0);
42297 - atomic_set(&tcon->num_hardlinks, 0);
42298 - atomic_set(&tcon->num_symlinks, 0);
42299 - atomic_set(&tcon->num_locks, 0);
42300 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
42301 + atomic_set_unchecked(&tcon->num_writes, 0);
42302 + atomic_set_unchecked(&tcon->num_reads, 0);
42303 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
42304 + atomic_set_unchecked(&tcon->num_opens, 0);
42305 + atomic_set_unchecked(&tcon->num_posixopens, 0);
42306 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
42307 + atomic_set_unchecked(&tcon->num_closes, 0);
42308 + atomic_set_unchecked(&tcon->num_deletes, 0);
42309 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
42310 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
42311 + atomic_set_unchecked(&tcon->num_renames, 0);
42312 + atomic_set_unchecked(&tcon->num_t2renames, 0);
42313 + atomic_set_unchecked(&tcon->num_ffirst, 0);
42314 + atomic_set_unchecked(&tcon->num_fnext, 0);
42315 + atomic_set_unchecked(&tcon->num_fclose, 0);
42316 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
42317 + atomic_set_unchecked(&tcon->num_symlinks, 0);
42318 + atomic_set_unchecked(&tcon->num_locks, 0);
42319 }
42320 }
42321 }
42322 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42323 smBufAllocCount.counter, cifs_min_small);
42324 #ifdef CONFIG_CIFS_STATS2
42325 seq_printf(m, "Total Large %d Small %d Allocations\n",
42326 - atomic_read(&totBufAllocCount),
42327 - atomic_read(&totSmBufAllocCount));
42328 + atomic_read_unchecked(&totBufAllocCount),
42329 + atomic_read_unchecked(&totSmBufAllocCount));
42330 #endif /* CONFIG_CIFS_STATS2 */
42331
42332 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
42333 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42334 if (tcon->need_reconnect)
42335 seq_puts(m, "\tDISCONNECTED ");
42336 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
42337 - atomic_read(&tcon->num_smbs_sent),
42338 - atomic_read(&tcon->num_oplock_brks));
42339 + atomic_read_unchecked(&tcon->num_smbs_sent),
42340 + atomic_read_unchecked(&tcon->num_oplock_brks));
42341 seq_printf(m, "\nReads: %d Bytes: %lld",
42342 - atomic_read(&tcon->num_reads),
42343 + atomic_read_unchecked(&tcon->num_reads),
42344 (long long)(tcon->bytes_read));
42345 seq_printf(m, "\nWrites: %d Bytes: %lld",
42346 - atomic_read(&tcon->num_writes),
42347 + atomic_read_unchecked(&tcon->num_writes),
42348 (long long)(tcon->bytes_written));
42349 seq_printf(m, "\nFlushes: %d",
42350 - atomic_read(&tcon->num_flushes));
42351 + atomic_read_unchecked(&tcon->num_flushes));
42352 seq_printf(m, "\nLocks: %d HardLinks: %d "
42353 "Symlinks: %d",
42354 - atomic_read(&tcon->num_locks),
42355 - atomic_read(&tcon->num_hardlinks),
42356 - atomic_read(&tcon->num_symlinks));
42357 + atomic_read_unchecked(&tcon->num_locks),
42358 + atomic_read_unchecked(&tcon->num_hardlinks),
42359 + atomic_read_unchecked(&tcon->num_symlinks));
42360 seq_printf(m, "\nOpens: %d Closes: %d "
42361 "Deletes: %d",
42362 - atomic_read(&tcon->num_opens),
42363 - atomic_read(&tcon->num_closes),
42364 - atomic_read(&tcon->num_deletes));
42365 + atomic_read_unchecked(&tcon->num_opens),
42366 + atomic_read_unchecked(&tcon->num_closes),
42367 + atomic_read_unchecked(&tcon->num_deletes));
42368 seq_printf(m, "\nPosix Opens: %d "
42369 "Posix Mkdirs: %d",
42370 - atomic_read(&tcon->num_posixopens),
42371 - atomic_read(&tcon->num_posixmkdirs));
42372 + atomic_read_unchecked(&tcon->num_posixopens),
42373 + atomic_read_unchecked(&tcon->num_posixmkdirs));
42374 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
42375 - atomic_read(&tcon->num_mkdirs),
42376 - atomic_read(&tcon->num_rmdirs));
42377 + atomic_read_unchecked(&tcon->num_mkdirs),
42378 + atomic_read_unchecked(&tcon->num_rmdirs));
42379 seq_printf(m, "\nRenames: %d T2 Renames %d",
42380 - atomic_read(&tcon->num_renames),
42381 - atomic_read(&tcon->num_t2renames));
42382 + atomic_read_unchecked(&tcon->num_renames),
42383 + atomic_read_unchecked(&tcon->num_t2renames));
42384 seq_printf(m, "\nFindFirst: %d FNext %d "
42385 "FClose %d",
42386 - atomic_read(&tcon->num_ffirst),
42387 - atomic_read(&tcon->num_fnext),
42388 - atomic_read(&tcon->num_fclose));
42389 + atomic_read_unchecked(&tcon->num_ffirst),
42390 + atomic_read_unchecked(&tcon->num_fnext),
42391 + atomic_read_unchecked(&tcon->num_fclose));
42392 }
42393 }
42394 }
42395 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
42396 index 6ee1cb4..8443157 100644
42397 --- a/fs/cifs/cifsfs.c
42398 +++ b/fs/cifs/cifsfs.c
42399 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
42400 cifs_req_cachep = kmem_cache_create("cifs_request",
42401 CIFSMaxBufSize +
42402 MAX_CIFS_HDR_SIZE, 0,
42403 - SLAB_HWCACHE_ALIGN, NULL);
42404 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
42405 if (cifs_req_cachep == NULL)
42406 return -ENOMEM;
42407
42408 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
42409 efficient to alloc 1 per page off the slab compared to 17K (5page)
42410 alloc of large cifs buffers even when page debugging is on */
42411 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
42412 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
42413 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
42414 NULL);
42415 if (cifs_sm_req_cachep == NULL) {
42416 mempool_destroy(cifs_req_poolp);
42417 @@ -1101,8 +1101,8 @@ init_cifs(void)
42418 atomic_set(&bufAllocCount, 0);
42419 atomic_set(&smBufAllocCount, 0);
42420 #ifdef CONFIG_CIFS_STATS2
42421 - atomic_set(&totBufAllocCount, 0);
42422 - atomic_set(&totSmBufAllocCount, 0);
42423 + atomic_set_unchecked(&totBufAllocCount, 0);
42424 + atomic_set_unchecked(&totSmBufAllocCount, 0);
42425 #endif /* CONFIG_CIFS_STATS2 */
42426
42427 atomic_set(&midCount, 0);
42428 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
42429 index d47d20a..77e8b33 100644
42430 --- a/fs/cifs/cifsglob.h
42431 +++ b/fs/cifs/cifsglob.h
42432 @@ -388,28 +388,28 @@ struct cifs_tcon {
42433 __u16 Flags; /* optional support bits */
42434 enum statusEnum tidStatus;
42435 #ifdef CONFIG_CIFS_STATS
42436 - atomic_t num_smbs_sent;
42437 - atomic_t num_writes;
42438 - atomic_t num_reads;
42439 - atomic_t num_flushes;
42440 - atomic_t num_oplock_brks;
42441 - atomic_t num_opens;
42442 - atomic_t num_closes;
42443 - atomic_t num_deletes;
42444 - atomic_t num_mkdirs;
42445 - atomic_t num_posixopens;
42446 - atomic_t num_posixmkdirs;
42447 - atomic_t num_rmdirs;
42448 - atomic_t num_renames;
42449 - atomic_t num_t2renames;
42450 - atomic_t num_ffirst;
42451 - atomic_t num_fnext;
42452 - atomic_t num_fclose;
42453 - atomic_t num_hardlinks;
42454 - atomic_t num_symlinks;
42455 - atomic_t num_locks;
42456 - atomic_t num_acl_get;
42457 - atomic_t num_acl_set;
42458 + atomic_unchecked_t num_smbs_sent;
42459 + atomic_unchecked_t num_writes;
42460 + atomic_unchecked_t num_reads;
42461 + atomic_unchecked_t num_flushes;
42462 + atomic_unchecked_t num_oplock_brks;
42463 + atomic_unchecked_t num_opens;
42464 + atomic_unchecked_t num_closes;
42465 + atomic_unchecked_t num_deletes;
42466 + atomic_unchecked_t num_mkdirs;
42467 + atomic_unchecked_t num_posixopens;
42468 + atomic_unchecked_t num_posixmkdirs;
42469 + atomic_unchecked_t num_rmdirs;
42470 + atomic_unchecked_t num_renames;
42471 + atomic_unchecked_t num_t2renames;
42472 + atomic_unchecked_t num_ffirst;
42473 + atomic_unchecked_t num_fnext;
42474 + atomic_unchecked_t num_fclose;
42475 + atomic_unchecked_t num_hardlinks;
42476 + atomic_unchecked_t num_symlinks;
42477 + atomic_unchecked_t num_locks;
42478 + atomic_unchecked_t num_acl_get;
42479 + atomic_unchecked_t num_acl_set;
42480 #ifdef CONFIG_CIFS_STATS2
42481 unsigned long long time_writes;
42482 unsigned long long time_reads;
42483 @@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
42484 }
42485
42486 #ifdef CONFIG_CIFS_STATS
42487 -#define cifs_stats_inc atomic_inc
42488 +#define cifs_stats_inc atomic_inc_unchecked
42489
42490 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
42491 unsigned int bytes)
42492 @@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
42493 /* Various Debug counters */
42494 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
42495 #ifdef CONFIG_CIFS_STATS2
42496 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
42497 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
42498 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
42499 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
42500 #endif
42501 GLOBAL_EXTERN atomic_t smBufAllocCount;
42502 GLOBAL_EXTERN atomic_t midCount;
42503 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
42504 index 6b0e064..94e6c3c 100644
42505 --- a/fs/cifs/link.c
42506 +++ b/fs/cifs/link.c
42507 @@ -600,7 +600,7 @@ symlink_exit:
42508
42509 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
42510 {
42511 - char *p = nd_get_link(nd);
42512 + const char *p = nd_get_link(nd);
42513 if (!IS_ERR(p))
42514 kfree(p);
42515 }
42516 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
42517 index 703ef5c..2a44ed5 100644
42518 --- a/fs/cifs/misc.c
42519 +++ b/fs/cifs/misc.c
42520 @@ -156,7 +156,7 @@ cifs_buf_get(void)
42521 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
42522 atomic_inc(&bufAllocCount);
42523 #ifdef CONFIG_CIFS_STATS2
42524 - atomic_inc(&totBufAllocCount);
42525 + atomic_inc_unchecked(&totBufAllocCount);
42526 #endif /* CONFIG_CIFS_STATS2 */
42527 }
42528
42529 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
42530 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
42531 atomic_inc(&smBufAllocCount);
42532 #ifdef CONFIG_CIFS_STATS2
42533 - atomic_inc(&totSmBufAllocCount);
42534 + atomic_inc_unchecked(&totSmBufAllocCount);
42535 #endif /* CONFIG_CIFS_STATS2 */
42536
42537 }
42538 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
42539 index 6901578..d402eb5 100644
42540 --- a/fs/coda/cache.c
42541 +++ b/fs/coda/cache.c
42542 @@ -24,7 +24,7 @@
42543 #include "coda_linux.h"
42544 #include "coda_cache.h"
42545
42546 -static atomic_t permission_epoch = ATOMIC_INIT(0);
42547 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
42548
42549 /* replace or extend an acl cache hit */
42550 void coda_cache_enter(struct inode *inode, int mask)
42551 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
42552 struct coda_inode_info *cii = ITOC(inode);
42553
42554 spin_lock(&cii->c_lock);
42555 - cii->c_cached_epoch = atomic_read(&permission_epoch);
42556 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
42557 if (cii->c_uid != current_fsuid()) {
42558 cii->c_uid = current_fsuid();
42559 cii->c_cached_perm = mask;
42560 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
42561 {
42562 struct coda_inode_info *cii = ITOC(inode);
42563 spin_lock(&cii->c_lock);
42564 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
42565 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
42566 spin_unlock(&cii->c_lock);
42567 }
42568
42569 /* remove all acl caches */
42570 void coda_cache_clear_all(struct super_block *sb)
42571 {
42572 - atomic_inc(&permission_epoch);
42573 + atomic_inc_unchecked(&permission_epoch);
42574 }
42575
42576
42577 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
42578 spin_lock(&cii->c_lock);
42579 hit = (mask & cii->c_cached_perm) == mask &&
42580 cii->c_uid == current_fsuid() &&
42581 - cii->c_cached_epoch == atomic_read(&permission_epoch);
42582 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
42583 spin_unlock(&cii->c_lock);
42584
42585 return hit;
42586 diff --git a/fs/compat.c b/fs/compat.c
42587 index 07880ba..3fb2862 100644
42588 --- a/fs/compat.c
42589 +++ b/fs/compat.c
42590 @@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
42591
42592 set_fs(KERNEL_DS);
42593 /* The __user pointer cast is valid because of the set_fs() */
42594 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
42595 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
42596 set_fs(oldfs);
42597 /* truncating is ok because it's a user address */
42598 if (!ret)
42599 @@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
42600 goto out;
42601
42602 ret = -EINVAL;
42603 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
42604 + if (nr_segs > UIO_MAXIOV)
42605 goto out;
42606 if (nr_segs > fast_segs) {
42607 ret = -ENOMEM;
42608 @@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
42609
42610 struct compat_readdir_callback {
42611 struct compat_old_linux_dirent __user *dirent;
42612 + struct file * file;
42613 int result;
42614 };
42615
42616 @@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
42617 buf->result = -EOVERFLOW;
42618 return -EOVERFLOW;
42619 }
42620 +
42621 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42622 + return 0;
42623 +
42624 buf->result++;
42625 dirent = buf->dirent;
42626 if (!access_ok(VERIFY_WRITE, dirent,
42627 @@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
42628
42629 buf.result = 0;
42630 buf.dirent = dirent;
42631 + buf.file = file;
42632
42633 error = vfs_readdir(file, compat_fillonedir, &buf);
42634 if (buf.result)
42635 @@ -901,6 +907,7 @@ struct compat_linux_dirent {
42636 struct compat_getdents_callback {
42637 struct compat_linux_dirent __user *current_dir;
42638 struct compat_linux_dirent __user *previous;
42639 + struct file * file;
42640 int count;
42641 int error;
42642 };
42643 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
42644 buf->error = -EOVERFLOW;
42645 return -EOVERFLOW;
42646 }
42647 +
42648 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42649 + return 0;
42650 +
42651 dirent = buf->previous;
42652 if (dirent) {
42653 if (__put_user(offset, &dirent->d_off))
42654 @@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
42655 buf.previous = NULL;
42656 buf.count = count;
42657 buf.error = 0;
42658 + buf.file = file;
42659
42660 error = vfs_readdir(file, compat_filldir, &buf);
42661 if (error >= 0)
42662 @@ -990,6 +1002,7 @@ out:
42663 struct compat_getdents_callback64 {
42664 struct linux_dirent64 __user *current_dir;
42665 struct linux_dirent64 __user *previous;
42666 + struct file * file;
42667 int count;
42668 int error;
42669 };
42670 @@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
42671 buf->error = -EINVAL; /* only used if we fail.. */
42672 if (reclen > buf->count)
42673 return -EINVAL;
42674 +
42675 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42676 + return 0;
42677 +
42678 dirent = buf->previous;
42679
42680 if (dirent) {
42681 @@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
42682 buf.previous = NULL;
42683 buf.count = count;
42684 buf.error = 0;
42685 + buf.file = file;
42686
42687 error = vfs_readdir(file, compat_filldir64, &buf);
42688 if (error >= 0)
42689 error = buf.error;
42690 lastdirent = buf.previous;
42691 if (lastdirent) {
42692 - typeof(lastdirent->d_off) d_off = file->f_pos;
42693 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
42694 if (__put_user_unaligned(d_off, &lastdirent->d_off))
42695 error = -EFAULT;
42696 else
42697 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
42698 index 112e45a..b59845b 100644
42699 --- a/fs/compat_binfmt_elf.c
42700 +++ b/fs/compat_binfmt_elf.c
42701 @@ -30,11 +30,13 @@
42702 #undef elf_phdr
42703 #undef elf_shdr
42704 #undef elf_note
42705 +#undef elf_dyn
42706 #undef elf_addr_t
42707 #define elfhdr elf32_hdr
42708 #define elf_phdr elf32_phdr
42709 #define elf_shdr elf32_shdr
42710 #define elf_note elf32_note
42711 +#define elf_dyn Elf32_Dyn
42712 #define elf_addr_t Elf32_Addr
42713
42714 /*
42715 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
42716 index a26bea1..ae23e72 100644
42717 --- a/fs/compat_ioctl.c
42718 +++ b/fs/compat_ioctl.c
42719 @@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
42720
42721 err = get_user(palp, &up->palette);
42722 err |= get_user(length, &up->length);
42723 + if (err)
42724 + return -EFAULT;
42725
42726 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
42727 err = put_user(compat_ptr(palp), &up_native->palette);
42728 @@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
42729 return -EFAULT;
42730 if (__get_user(udata, &ss32->iomem_base))
42731 return -EFAULT;
42732 - ss.iomem_base = compat_ptr(udata);
42733 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
42734 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
42735 __get_user(ss.port_high, &ss32->port_high))
42736 return -EFAULT;
42737 @@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
42738 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
42739 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
42740 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
42741 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
42742 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
42743 return -EFAULT;
42744
42745 return ioctl_preallocate(file, p);
42746 @@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
42747 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
42748 {
42749 unsigned int a, b;
42750 - a = *(unsigned int *)p;
42751 - b = *(unsigned int *)q;
42752 + a = *(const unsigned int *)p;
42753 + b = *(const unsigned int *)q;
42754 if (a > b)
42755 return 1;
42756 if (a < b)
42757 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
42758 index 5ddd7eb..c18bf04 100644
42759 --- a/fs/configfs/dir.c
42760 +++ b/fs/configfs/dir.c
42761 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
42762 }
42763 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
42764 struct configfs_dirent *next;
42765 - const char * name;
42766 + const unsigned char * name;
42767 + char d_name[sizeof(next->s_dentry->d_iname)];
42768 int len;
42769 struct inode *inode = NULL;
42770
42771 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
42772 continue;
42773
42774 name = configfs_get_name(next);
42775 - len = strlen(name);
42776 + if (next->s_dentry && name == next->s_dentry->d_iname) {
42777 + len = next->s_dentry->d_name.len;
42778 + memcpy(d_name, name, len);
42779 + name = d_name;
42780 + } else
42781 + len = strlen(name);
42782
42783 /*
42784 * We'll have a dentry and an inode for
42785 diff --git a/fs/dcache.c b/fs/dcache.c
42786 index 2576d14..0cec38d 100644
42787 --- a/fs/dcache.c
42788 +++ b/fs/dcache.c
42789 @@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
42790 static struct hlist_bl_head *dentry_hashtable __read_mostly;
42791
42792 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
42793 - unsigned long hash)
42794 + unsigned int hash)
42795 {
42796 - hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
42797 - hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
42798 + hash += (unsigned long) parent / L1_CACHE_BYTES;
42799 + hash = hash + (hash >> D_HASHBITS);
42800 return dentry_hashtable + (hash & D_HASHMASK);
42801 }
42802
42803 @@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
42804 mempages -= reserve;
42805
42806 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
42807 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
42808 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
42809
42810 dcache_init();
42811 inode_init();
42812 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
42813 index 956d5dd..e755e04 100644
42814 --- a/fs/debugfs/inode.c
42815 +++ b/fs/debugfs/inode.c
42816 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
42817 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
42818 {
42819 return debugfs_create_file(name,
42820 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
42821 + S_IFDIR | S_IRWXU,
42822 +#else
42823 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
42824 +#endif
42825 parent, NULL, NULL);
42826 }
42827 EXPORT_SYMBOL_GPL(debugfs_create_dir);
42828 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
42829 index ab35b11..b30af66 100644
42830 --- a/fs/ecryptfs/inode.c
42831 +++ b/fs/ecryptfs/inode.c
42832 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
42833 old_fs = get_fs();
42834 set_fs(get_ds());
42835 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
42836 - (char __user *)lower_buf,
42837 + (char __force_user *)lower_buf,
42838 lower_bufsiz);
42839 set_fs(old_fs);
42840 if (rc < 0)
42841 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42842 }
42843 old_fs = get_fs();
42844 set_fs(get_ds());
42845 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
42846 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
42847 set_fs(old_fs);
42848 if (rc < 0) {
42849 kfree(buf);
42850 @@ -733,7 +733,7 @@ out:
42851 static void
42852 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
42853 {
42854 - char *buf = nd_get_link(nd);
42855 + const char *buf = nd_get_link(nd);
42856 if (!IS_ERR(buf)) {
42857 /* Free the char* */
42858 kfree(buf);
42859 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
42860 index 3a06f40..f7af544 100644
42861 --- a/fs/ecryptfs/miscdev.c
42862 +++ b/fs/ecryptfs/miscdev.c
42863 @@ -345,7 +345,7 @@ check_list:
42864 goto out_unlock_msg_ctx;
42865 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
42866 if (msg_ctx->msg) {
42867 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
42868 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
42869 goto out_unlock_msg_ctx;
42870 i += packet_length_size;
42871 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
42872 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
42873 index b2a34a1..162fa69 100644
42874 --- a/fs/ecryptfs/read_write.c
42875 +++ b/fs/ecryptfs/read_write.c
42876 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
42877 return -EIO;
42878 fs_save = get_fs();
42879 set_fs(get_ds());
42880 - rc = vfs_write(lower_file, data, size, &offset);
42881 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
42882 set_fs(fs_save);
42883 mark_inode_dirty_sync(ecryptfs_inode);
42884 return rc;
42885 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
42886 return -EIO;
42887 fs_save = get_fs();
42888 set_fs(get_ds());
42889 - rc = vfs_read(lower_file, data, size, &offset);
42890 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
42891 set_fs(fs_save);
42892 return rc;
42893 }
42894 diff --git a/fs/exec.c b/fs/exec.c
42895 index 153dee1..8ee97ba 100644
42896 --- a/fs/exec.c
42897 +++ b/fs/exec.c
42898 @@ -55,6 +55,13 @@
42899 #include <linux/pipe_fs_i.h>
42900 #include <linux/oom.h>
42901 #include <linux/compat.h>
42902 +#include <linux/random.h>
42903 +#include <linux/seq_file.h>
42904 +
42905 +#ifdef CONFIG_PAX_REFCOUNT
42906 +#include <linux/kallsyms.h>
42907 +#include <linux/kdebug.h>
42908 +#endif
42909
42910 #include <asm/uaccess.h>
42911 #include <asm/mmu_context.h>
42912 @@ -63,6 +70,15 @@
42913 #include <trace/events/task.h>
42914 #include "internal.h"
42915
42916 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
42917 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
42918 +#endif
42919 +
42920 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
42921 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
42922 +EXPORT_SYMBOL(pax_set_initial_flags_func);
42923 +#endif
42924 +
42925 int core_uses_pid;
42926 char core_pattern[CORENAME_MAX_SIZE] = "core";
42927 unsigned int core_pipe_limit;
42928 @@ -72,7 +88,7 @@ struct core_name {
42929 char *corename;
42930 int used, size;
42931 };
42932 -static atomic_t call_count = ATOMIC_INIT(1);
42933 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
42934
42935 /* The maximal length of core_pattern is also specified in sysctl.c */
42936
42937 @@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
42938 int write)
42939 {
42940 struct page *page;
42941 - int ret;
42942
42943 -#ifdef CONFIG_STACK_GROWSUP
42944 - if (write) {
42945 - ret = expand_downwards(bprm->vma, pos);
42946 - if (ret < 0)
42947 - return NULL;
42948 - }
42949 -#endif
42950 - ret = get_user_pages(current, bprm->mm, pos,
42951 - 1, write, 1, &page, NULL);
42952 - if (ret <= 0)
42953 + if (0 > expand_downwards(bprm->vma, pos))
42954 + return NULL;
42955 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
42956 return NULL;
42957
42958 if (write) {
42959 @@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
42960 if (size <= ARG_MAX)
42961 return page;
42962
42963 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42964 + // only allow 512KB for argv+env on suid/sgid binaries
42965 + // to prevent easy ASLR exhaustion
42966 + if (((bprm->cred->euid != current_euid()) ||
42967 + (bprm->cred->egid != current_egid())) &&
42968 + (size > (512 * 1024))) {
42969 + put_page(page);
42970 + return NULL;
42971 + }
42972 +#endif
42973 +
42974 /*
42975 * Limit to 1/4-th the stack size for the argv+env strings.
42976 * This ensures that:
42977 @@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
42978 vma->vm_end = STACK_TOP_MAX;
42979 vma->vm_start = vma->vm_end - PAGE_SIZE;
42980 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
42981 +
42982 +#ifdef CONFIG_PAX_SEGMEXEC
42983 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
42984 +#endif
42985 +
42986 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
42987 INIT_LIST_HEAD(&vma->anon_vma_chain);
42988
42989 @@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
42990 mm->stack_vm = mm->total_vm = 1;
42991 up_write(&mm->mmap_sem);
42992 bprm->p = vma->vm_end - sizeof(void *);
42993 +
42994 +#ifdef CONFIG_PAX_RANDUSTACK
42995 + if (randomize_va_space)
42996 + bprm->p ^= random32() & ~PAGE_MASK;
42997 +#endif
42998 +
42999 return 0;
43000 err:
43001 up_write(&mm->mmap_sem);
43002 @@ -398,19 +428,7 @@ err:
43003 return err;
43004 }
43005
43006 -struct user_arg_ptr {
43007 -#ifdef CONFIG_COMPAT
43008 - bool is_compat;
43009 -#endif
43010 - union {
43011 - const char __user *const __user *native;
43012 -#ifdef CONFIG_COMPAT
43013 - compat_uptr_t __user *compat;
43014 -#endif
43015 - } ptr;
43016 -};
43017 -
43018 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43019 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43020 {
43021 const char __user *native;
43022
43023 @@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43024 compat_uptr_t compat;
43025
43026 if (get_user(compat, argv.ptr.compat + nr))
43027 - return ERR_PTR(-EFAULT);
43028 + return (const char __force_user *)ERR_PTR(-EFAULT);
43029
43030 return compat_ptr(compat);
43031 }
43032 #endif
43033
43034 if (get_user(native, argv.ptr.native + nr))
43035 - return ERR_PTR(-EFAULT);
43036 + return (const char __force_user *)ERR_PTR(-EFAULT);
43037
43038 return native;
43039 }
43040 @@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
43041 if (!p)
43042 break;
43043
43044 - if (IS_ERR(p))
43045 + if (IS_ERR((const char __force_kernel *)p))
43046 return -EFAULT;
43047
43048 if (i++ >= max)
43049 @@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43050
43051 ret = -EFAULT;
43052 str = get_user_arg_ptr(argv, argc);
43053 - if (IS_ERR(str))
43054 + if (IS_ERR((const char __force_kernel *)str))
43055 goto out;
43056
43057 len = strnlen_user(str, MAX_ARG_STRLEN);
43058 @@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43059 int r;
43060 mm_segment_t oldfs = get_fs();
43061 struct user_arg_ptr argv = {
43062 - .ptr.native = (const char __user *const __user *)__argv,
43063 + .ptr.native = (const char __force_user *const __force_user *)__argv,
43064 };
43065
43066 set_fs(KERNEL_DS);
43067 @@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43068 unsigned long new_end = old_end - shift;
43069 struct mmu_gather tlb;
43070
43071 - BUG_ON(new_start > new_end);
43072 + if (new_start >= new_end || new_start < mmap_min_addr)
43073 + return -ENOMEM;
43074
43075 /*
43076 * ensure there are no vmas between where we want to go
43077 @@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43078 if (vma != find_vma(mm, new_start))
43079 return -EFAULT;
43080
43081 +#ifdef CONFIG_PAX_SEGMEXEC
43082 + BUG_ON(pax_find_mirror_vma(vma));
43083 +#endif
43084 +
43085 /*
43086 * cover the whole range: [new_start, old_end)
43087 */
43088 @@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43089 stack_top = arch_align_stack(stack_top);
43090 stack_top = PAGE_ALIGN(stack_top);
43091
43092 - if (unlikely(stack_top < mmap_min_addr) ||
43093 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43094 - return -ENOMEM;
43095 -
43096 stack_shift = vma->vm_end - stack_top;
43097
43098 bprm->p -= stack_shift;
43099 @@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43100 bprm->exec -= stack_shift;
43101
43102 down_write(&mm->mmap_sem);
43103 +
43104 + /* Move stack pages down in memory. */
43105 + if (stack_shift) {
43106 + ret = shift_arg_pages(vma, stack_shift);
43107 + if (ret)
43108 + goto out_unlock;
43109 + }
43110 +
43111 vm_flags = VM_STACK_FLAGS;
43112
43113 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43114 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43115 + vm_flags &= ~VM_EXEC;
43116 +
43117 +#ifdef CONFIG_PAX_MPROTECT
43118 + if (mm->pax_flags & MF_PAX_MPROTECT)
43119 + vm_flags &= ~VM_MAYEXEC;
43120 +#endif
43121 +
43122 + }
43123 +#endif
43124 +
43125 /*
43126 * Adjust stack execute permissions; explicitly enable for
43127 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43128 @@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43129 goto out_unlock;
43130 BUG_ON(prev != vma);
43131
43132 - /* Move stack pages down in memory. */
43133 - if (stack_shift) {
43134 - ret = shift_arg_pages(vma, stack_shift);
43135 - if (ret)
43136 - goto out_unlock;
43137 - }
43138 -
43139 /* mprotect_fixup is overkill to remove the temporary stack flags */
43140 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43141
43142 @@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
43143 old_fs = get_fs();
43144 set_fs(get_ds());
43145 /* The cast to a user pointer is valid due to the set_fs() */
43146 - result = vfs_read(file, (void __user *)addr, count, &pos);
43147 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
43148 set_fs(old_fs);
43149 return result;
43150 }
43151 @@ -1252,7 +1284,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
43152 }
43153 rcu_read_unlock();
43154
43155 - if (p->fs->users > n_fs) {
43156 + if (atomic_read(&p->fs->users) > n_fs) {
43157 bprm->unsafe |= LSM_UNSAFE_SHARE;
43158 } else {
43159 res = -EAGAIN;
43160 @@ -1447,6 +1479,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43161
43162 EXPORT_SYMBOL(search_binary_handler);
43163
43164 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43165 +static DEFINE_PER_CPU(u64, exec_counter);
43166 +static int __init init_exec_counters(void)
43167 +{
43168 + unsigned int cpu;
43169 +
43170 + for_each_possible_cpu(cpu) {
43171 + per_cpu(exec_counter, cpu) = (u64)cpu;
43172 + }
43173 +
43174 + return 0;
43175 +}
43176 +early_initcall(init_exec_counters);
43177 +static inline void increment_exec_counter(void)
43178 +{
43179 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
43180 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43181 +}
43182 +#else
43183 +static inline void increment_exec_counter(void) {}
43184 +#endif
43185 +
43186 /*
43187 * sys_execve() executes a new program.
43188 */
43189 @@ -1455,6 +1509,11 @@ static int do_execve_common(const char *filename,
43190 struct user_arg_ptr envp,
43191 struct pt_regs *regs)
43192 {
43193 +#ifdef CONFIG_GRKERNSEC
43194 + struct file *old_exec_file;
43195 + struct acl_subject_label *old_acl;
43196 + struct rlimit old_rlim[RLIM_NLIMITS];
43197 +#endif
43198 struct linux_binprm *bprm;
43199 struct file *file;
43200 struct files_struct *displaced;
43201 @@ -1462,6 +1521,8 @@ static int do_execve_common(const char *filename,
43202 int retval;
43203 const struct cred *cred = current_cred();
43204
43205 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43206 +
43207 /*
43208 * We move the actual failure in case of RLIMIT_NPROC excess from
43209 * set*uid() to execve() because too many poorly written programs
43210 @@ -1502,12 +1563,27 @@ static int do_execve_common(const char *filename,
43211 if (IS_ERR(file))
43212 goto out_unmark;
43213
43214 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
43215 + retval = -EPERM;
43216 + goto out_file;
43217 + }
43218 +
43219 sched_exec();
43220
43221 bprm->file = file;
43222 bprm->filename = filename;
43223 bprm->interp = filename;
43224
43225 + if (gr_process_user_ban()) {
43226 + retval = -EPERM;
43227 + goto out_file;
43228 + }
43229 +
43230 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
43231 + retval = -EACCES;
43232 + goto out_file;
43233 + }
43234 +
43235 retval = bprm_mm_init(bprm);
43236 if (retval)
43237 goto out_file;
43238 @@ -1524,24 +1600,65 @@ static int do_execve_common(const char *filename,
43239 if (retval < 0)
43240 goto out;
43241
43242 +#ifdef CONFIG_GRKERNSEC
43243 + old_acl = current->acl;
43244 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
43245 + old_exec_file = current->exec_file;
43246 + get_file(file);
43247 + current->exec_file = file;
43248 +#endif
43249 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43250 + /* limit suid stack to 8MB
43251 + we saved the old limits above and will restore them if this exec fails
43252 + */
43253 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
43254 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
43255 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
43256 +#endif
43257 +
43258 + if (!gr_tpe_allow(file)) {
43259 + retval = -EACCES;
43260 + goto out_fail;
43261 + }
43262 +
43263 + if (gr_check_crash_exec(file)) {
43264 + retval = -EACCES;
43265 + goto out_fail;
43266 + }
43267 +
43268 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
43269 + bprm->unsafe);
43270 + if (retval < 0)
43271 + goto out_fail;
43272 +
43273 retval = copy_strings_kernel(1, &bprm->filename, bprm);
43274 if (retval < 0)
43275 - goto out;
43276 + goto out_fail;
43277
43278 bprm->exec = bprm->p;
43279 retval = copy_strings(bprm->envc, envp, bprm);
43280 if (retval < 0)
43281 - goto out;
43282 + goto out_fail;
43283
43284 retval = copy_strings(bprm->argc, argv, bprm);
43285 if (retval < 0)
43286 - goto out;
43287 + goto out_fail;
43288 +
43289 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
43290 +
43291 + gr_handle_exec_args(bprm, argv);
43292
43293 retval = search_binary_handler(bprm,regs);
43294 if (retval < 0)
43295 - goto out;
43296 + goto out_fail;
43297 +#ifdef CONFIG_GRKERNSEC
43298 + if (old_exec_file)
43299 + fput(old_exec_file);
43300 +#endif
43301
43302 /* execve succeeded */
43303 +
43304 + increment_exec_counter();
43305 current->fs->in_exec = 0;
43306 current->in_execve = 0;
43307 acct_update_integrals(current);
43308 @@ -1550,6 +1667,14 @@ static int do_execve_common(const char *filename,
43309 put_files_struct(displaced);
43310 return retval;
43311
43312 +out_fail:
43313 +#ifdef CONFIG_GRKERNSEC
43314 + current->acl = old_acl;
43315 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
43316 + fput(current->exec_file);
43317 + current->exec_file = old_exec_file;
43318 +#endif
43319 +
43320 out:
43321 if (bprm->mm) {
43322 acct_arg_size(bprm, 0);
43323 @@ -1623,7 +1748,7 @@ static int expand_corename(struct core_name *cn)
43324 {
43325 char *old_corename = cn->corename;
43326
43327 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
43328 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
43329 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
43330
43331 if (!cn->corename) {
43332 @@ -1720,7 +1845,7 @@ static int format_corename(struct core_name *cn, long signr)
43333 int pid_in_pattern = 0;
43334 int err = 0;
43335
43336 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
43337 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
43338 cn->corename = kmalloc(cn->size, GFP_KERNEL);
43339 cn->used = 0;
43340
43341 @@ -1817,6 +1942,218 @@ out:
43342 return ispipe;
43343 }
43344
43345 +int pax_check_flags(unsigned long *flags)
43346 +{
43347 + int retval = 0;
43348 +
43349 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
43350 + if (*flags & MF_PAX_SEGMEXEC)
43351 + {
43352 + *flags &= ~MF_PAX_SEGMEXEC;
43353 + retval = -EINVAL;
43354 + }
43355 +#endif
43356 +
43357 + if ((*flags & MF_PAX_PAGEEXEC)
43358 +
43359 +#ifdef CONFIG_PAX_PAGEEXEC
43360 + && (*flags & MF_PAX_SEGMEXEC)
43361 +#endif
43362 +
43363 + )
43364 + {
43365 + *flags &= ~MF_PAX_PAGEEXEC;
43366 + retval = -EINVAL;
43367 + }
43368 +
43369 + if ((*flags & MF_PAX_MPROTECT)
43370 +
43371 +#ifdef CONFIG_PAX_MPROTECT
43372 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43373 +#endif
43374 +
43375 + )
43376 + {
43377 + *flags &= ~MF_PAX_MPROTECT;
43378 + retval = -EINVAL;
43379 + }
43380 +
43381 + if ((*flags & MF_PAX_EMUTRAMP)
43382 +
43383 +#ifdef CONFIG_PAX_EMUTRAMP
43384 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43385 +#endif
43386 +
43387 + )
43388 + {
43389 + *flags &= ~MF_PAX_EMUTRAMP;
43390 + retval = -EINVAL;
43391 + }
43392 +
43393 + return retval;
43394 +}
43395 +
43396 +EXPORT_SYMBOL(pax_check_flags);
43397 +
43398 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43399 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
43400 +{
43401 + struct task_struct *tsk = current;
43402 + struct mm_struct *mm = current->mm;
43403 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
43404 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
43405 + char *path_exec = NULL;
43406 + char *path_fault = NULL;
43407 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
43408 +
43409 + if (buffer_exec && buffer_fault) {
43410 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
43411 +
43412 + down_read(&mm->mmap_sem);
43413 + vma = mm->mmap;
43414 + while (vma && (!vma_exec || !vma_fault)) {
43415 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
43416 + vma_exec = vma;
43417 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
43418 + vma_fault = vma;
43419 + vma = vma->vm_next;
43420 + }
43421 + if (vma_exec) {
43422 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
43423 + if (IS_ERR(path_exec))
43424 + path_exec = "<path too long>";
43425 + else {
43426 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
43427 + if (path_exec) {
43428 + *path_exec = 0;
43429 + path_exec = buffer_exec;
43430 + } else
43431 + path_exec = "<path too long>";
43432 + }
43433 + }
43434 + if (vma_fault) {
43435 + start = vma_fault->vm_start;
43436 + end = vma_fault->vm_end;
43437 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
43438 + if (vma_fault->vm_file) {
43439 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
43440 + if (IS_ERR(path_fault))
43441 + path_fault = "<path too long>";
43442 + else {
43443 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
43444 + if (path_fault) {
43445 + *path_fault = 0;
43446 + path_fault = buffer_fault;
43447 + } else
43448 + path_fault = "<path too long>";
43449 + }
43450 + } else
43451 + path_fault = "<anonymous mapping>";
43452 + }
43453 + up_read(&mm->mmap_sem);
43454 + }
43455 + if (tsk->signal->curr_ip)
43456 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
43457 + else
43458 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
43459 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
43460 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
43461 + task_uid(tsk), task_euid(tsk), pc, sp);
43462 + free_page((unsigned long)buffer_exec);
43463 + free_page((unsigned long)buffer_fault);
43464 + pax_report_insns(regs, pc, sp);
43465 + do_coredump(SIGKILL, SIGKILL, regs);
43466 +}
43467 +#endif
43468 +
43469 +#ifdef CONFIG_PAX_REFCOUNT
43470 +void pax_report_refcount_overflow(struct pt_regs *regs)
43471 +{
43472 + if (current->signal->curr_ip)
43473 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
43474 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
43475 + else
43476 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
43477 + current->comm, task_pid_nr(current), current_uid(), current_euid());
43478 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
43479 + show_regs(regs);
43480 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
43481 +}
43482 +#endif
43483 +
43484 +#ifdef CONFIG_PAX_USERCOPY
43485 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
43486 +int object_is_on_stack(const void *obj, unsigned long len)
43487 +{
43488 + const void * const stack = task_stack_page(current);
43489 + const void * const stackend = stack + THREAD_SIZE;
43490 +
43491 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
43492 + const void *frame = NULL;
43493 + const void *oldframe;
43494 +#endif
43495 +
43496 + if (obj + len < obj)
43497 + return -1;
43498 +
43499 + if (obj + len <= stack || stackend <= obj)
43500 + return 0;
43501 +
43502 + if (obj < stack || stackend < obj + len)
43503 + return -1;
43504 +
43505 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
43506 + oldframe = __builtin_frame_address(1);
43507 + if (oldframe)
43508 + frame = __builtin_frame_address(2);
43509 + /*
43510 + low ----------------------------------------------> high
43511 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
43512 + ^----------------^
43513 + allow copies only within here
43514 + */
43515 + while (stack <= frame && frame < stackend) {
43516 + /* if obj + len extends past the last frame, this
43517 + check won't pass and the next frame will be 0,
43518 + causing us to bail out and correctly report
43519 + the copy as invalid
43520 + */
43521 + if (obj + len <= frame)
43522 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
43523 + oldframe = frame;
43524 + frame = *(const void * const *)frame;
43525 + }
43526 + return -1;
43527 +#else
43528 + return 1;
43529 +#endif
43530 +}
43531 +
43532 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
43533 +{
43534 + if (current->signal->curr_ip)
43535 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
43536 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
43537 + else
43538 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
43539 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
43540 + dump_stack();
43541 + gr_handle_kernel_exploit();
43542 + do_group_exit(SIGKILL);
43543 +}
43544 +#endif
43545 +
43546 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
43547 +void pax_track_stack(void)
43548 +{
43549 + unsigned long sp = (unsigned long)&sp;
43550 + if (sp < current_thread_info()->lowest_stack &&
43551 + sp > (unsigned long)task_stack_page(current))
43552 + current_thread_info()->lowest_stack = sp;
43553 +}
43554 +EXPORT_SYMBOL(pax_track_stack);
43555 +#endif
43556 +
43557 static int zap_process(struct task_struct *start, int exit_code)
43558 {
43559 struct task_struct *t;
43560 @@ -2014,17 +2351,17 @@ static void wait_for_dump_helpers(struct file *file)
43561 pipe = file->f_path.dentry->d_inode->i_pipe;
43562
43563 pipe_lock(pipe);
43564 - pipe->readers++;
43565 - pipe->writers--;
43566 + atomic_inc(&pipe->readers);
43567 + atomic_dec(&pipe->writers);
43568
43569 - while ((pipe->readers > 1) && (!signal_pending(current))) {
43570 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
43571 wake_up_interruptible_sync(&pipe->wait);
43572 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
43573 pipe_wait(pipe);
43574 }
43575
43576 - pipe->readers--;
43577 - pipe->writers++;
43578 + atomic_dec(&pipe->readers);
43579 + atomic_inc(&pipe->writers);
43580 pipe_unlock(pipe);
43581
43582 }
43583 @@ -2085,7 +2422,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43584 int retval = 0;
43585 int flag = 0;
43586 int ispipe;
43587 - static atomic_t core_dump_count = ATOMIC_INIT(0);
43588 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
43589 struct coredump_params cprm = {
43590 .signr = signr,
43591 .regs = regs,
43592 @@ -2100,6 +2437,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43593
43594 audit_core_dumps(signr);
43595
43596 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
43597 + gr_handle_brute_attach(current, cprm.mm_flags);
43598 +
43599 binfmt = mm->binfmt;
43600 if (!binfmt || !binfmt->core_dump)
43601 goto fail;
43602 @@ -2167,7 +2507,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43603 }
43604 cprm.limit = RLIM_INFINITY;
43605
43606 - dump_count = atomic_inc_return(&core_dump_count);
43607 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
43608 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
43609 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
43610 task_tgid_vnr(current), current->comm);
43611 @@ -2194,6 +2534,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43612 } else {
43613 struct inode *inode;
43614
43615 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
43616 +
43617 if (cprm.limit < binfmt->min_coredump)
43618 goto fail_unlock;
43619
43620 @@ -2237,7 +2579,7 @@ close_fail:
43621 filp_close(cprm.file, NULL);
43622 fail_dropcount:
43623 if (ispipe)
43624 - atomic_dec(&core_dump_count);
43625 + atomic_dec_unchecked(&core_dump_count);
43626 fail_unlock:
43627 kfree(cn.corename);
43628 fail_corename:
43629 @@ -2256,7 +2598,7 @@ fail:
43630 */
43631 int dump_write(struct file *file, const void *addr, int nr)
43632 {
43633 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
43634 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
43635 }
43636 EXPORT_SYMBOL(dump_write);
43637
43638 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
43639 index a8cbe1b..fed04cb 100644
43640 --- a/fs/ext2/balloc.c
43641 +++ b/fs/ext2/balloc.c
43642 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
43643
43644 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
43645 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
43646 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
43647 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
43648 sbi->s_resuid != current_fsuid() &&
43649 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
43650 return 0;
43651 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
43652 index a203892..4e64db5 100644
43653 --- a/fs/ext3/balloc.c
43654 +++ b/fs/ext3/balloc.c
43655 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
43656
43657 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
43658 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
43659 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
43660 + if (free_blocks < root_blocks + 1 &&
43661 !use_reservation && sbi->s_resuid != current_fsuid() &&
43662 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
43663 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
43664 + !capable_nolog(CAP_SYS_RESOURCE)) {
43665 return 0;
43666 }
43667 return 1;
43668 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
43669 index f9e2cd8..bfdc476 100644
43670 --- a/fs/ext4/balloc.c
43671 +++ b/fs/ext4/balloc.c
43672 @@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
43673 /* Hm, nope. Are (enough) root reserved clusters available? */
43674 if (sbi->s_resuid == current_fsuid() ||
43675 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
43676 - capable(CAP_SYS_RESOURCE) ||
43677 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
43678 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
43679 + capable_nolog(CAP_SYS_RESOURCE)) {
43680
43681 if (free_clusters >= (nclusters + dirty_clusters))
43682 return 1;
43683 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
43684 index 3ce6a0c..0311fe5 100644
43685 --- a/fs/ext4/ext4.h
43686 +++ b/fs/ext4/ext4.h
43687 @@ -1220,19 +1220,19 @@ struct ext4_sb_info {
43688 unsigned long s_mb_last_start;
43689
43690 /* stats for buddy allocator */
43691 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
43692 - atomic_t s_bal_success; /* we found long enough chunks */
43693 - atomic_t s_bal_allocated; /* in blocks */
43694 - atomic_t s_bal_ex_scanned; /* total extents scanned */
43695 - atomic_t s_bal_goals; /* goal hits */
43696 - atomic_t s_bal_breaks; /* too long searches */
43697 - atomic_t s_bal_2orders; /* 2^order hits */
43698 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
43699 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
43700 + atomic_unchecked_t s_bal_allocated; /* in blocks */
43701 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
43702 + atomic_unchecked_t s_bal_goals; /* goal hits */
43703 + atomic_unchecked_t s_bal_breaks; /* too long searches */
43704 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
43705 spinlock_t s_bal_lock;
43706 unsigned long s_mb_buddies_generated;
43707 unsigned long long s_mb_generation_time;
43708 - atomic_t s_mb_lost_chunks;
43709 - atomic_t s_mb_preallocated;
43710 - atomic_t s_mb_discarded;
43711 + atomic_unchecked_t s_mb_lost_chunks;
43712 + atomic_unchecked_t s_mb_preallocated;
43713 + atomic_unchecked_t s_mb_discarded;
43714 atomic_t s_lock_busy;
43715
43716 /* locality groups */
43717 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
43718 index cb990b2..4820141 100644
43719 --- a/fs/ext4/mballoc.c
43720 +++ b/fs/ext4/mballoc.c
43721 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
43722 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
43723
43724 if (EXT4_SB(sb)->s_mb_stats)
43725 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
43726 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
43727
43728 break;
43729 }
43730 @@ -2088,7 +2088,7 @@ repeat:
43731 ac->ac_status = AC_STATUS_CONTINUE;
43732 ac->ac_flags |= EXT4_MB_HINT_FIRST;
43733 cr = 3;
43734 - atomic_inc(&sbi->s_mb_lost_chunks);
43735 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
43736 goto repeat;
43737 }
43738 }
43739 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
43740 if (sbi->s_mb_stats) {
43741 ext4_msg(sb, KERN_INFO,
43742 "mballoc: %u blocks %u reqs (%u success)",
43743 - atomic_read(&sbi->s_bal_allocated),
43744 - atomic_read(&sbi->s_bal_reqs),
43745 - atomic_read(&sbi->s_bal_success));
43746 + atomic_read_unchecked(&sbi->s_bal_allocated),
43747 + atomic_read_unchecked(&sbi->s_bal_reqs),
43748 + atomic_read_unchecked(&sbi->s_bal_success));
43749 ext4_msg(sb, KERN_INFO,
43750 "mballoc: %u extents scanned, %u goal hits, "
43751 "%u 2^N hits, %u breaks, %u lost",
43752 - atomic_read(&sbi->s_bal_ex_scanned),
43753 - atomic_read(&sbi->s_bal_goals),
43754 - atomic_read(&sbi->s_bal_2orders),
43755 - atomic_read(&sbi->s_bal_breaks),
43756 - atomic_read(&sbi->s_mb_lost_chunks));
43757 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
43758 + atomic_read_unchecked(&sbi->s_bal_goals),
43759 + atomic_read_unchecked(&sbi->s_bal_2orders),
43760 + atomic_read_unchecked(&sbi->s_bal_breaks),
43761 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
43762 ext4_msg(sb, KERN_INFO,
43763 "mballoc: %lu generated and it took %Lu",
43764 sbi->s_mb_buddies_generated,
43765 sbi->s_mb_generation_time);
43766 ext4_msg(sb, KERN_INFO,
43767 "mballoc: %u preallocated, %u discarded",
43768 - atomic_read(&sbi->s_mb_preallocated),
43769 - atomic_read(&sbi->s_mb_discarded));
43770 + atomic_read_unchecked(&sbi->s_mb_preallocated),
43771 + atomic_read_unchecked(&sbi->s_mb_discarded));
43772 }
43773
43774 free_percpu(sbi->s_locality_groups);
43775 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
43776 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
43777
43778 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
43779 - atomic_inc(&sbi->s_bal_reqs);
43780 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
43781 + atomic_inc_unchecked(&sbi->s_bal_reqs);
43782 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
43783 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
43784 - atomic_inc(&sbi->s_bal_success);
43785 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
43786 + atomic_inc_unchecked(&sbi->s_bal_success);
43787 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
43788 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
43789 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
43790 - atomic_inc(&sbi->s_bal_goals);
43791 + atomic_inc_unchecked(&sbi->s_bal_goals);
43792 if (ac->ac_found > sbi->s_mb_max_to_scan)
43793 - atomic_inc(&sbi->s_bal_breaks);
43794 + atomic_inc_unchecked(&sbi->s_bal_breaks);
43795 }
43796
43797 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
43798 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
43799 trace_ext4_mb_new_inode_pa(ac, pa);
43800
43801 ext4_mb_use_inode_pa(ac, pa);
43802 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
43803 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
43804
43805 ei = EXT4_I(ac->ac_inode);
43806 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
43807 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
43808 trace_ext4_mb_new_group_pa(ac, pa);
43809
43810 ext4_mb_use_group_pa(ac, pa);
43811 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
43812 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
43813
43814 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
43815 lg = ac->ac_lg;
43816 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
43817 * from the bitmap and continue.
43818 */
43819 }
43820 - atomic_add(free, &sbi->s_mb_discarded);
43821 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
43822
43823 return err;
43824 }
43825 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
43826 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
43827 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
43828 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
43829 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
43830 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
43831 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
43832
43833 return 0;
43834 diff --git a/fs/fcntl.c b/fs/fcntl.c
43835 index 22764c7..86372c9 100644
43836 --- a/fs/fcntl.c
43837 +++ b/fs/fcntl.c
43838 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
43839 if (err)
43840 return err;
43841
43842 + if (gr_handle_chroot_fowner(pid, type))
43843 + return -ENOENT;
43844 + if (gr_check_protected_task_fowner(pid, type))
43845 + return -EACCES;
43846 +
43847 f_modown(filp, pid, type, force);
43848 return 0;
43849 }
43850 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
43851
43852 static int f_setown_ex(struct file *filp, unsigned long arg)
43853 {
43854 - struct f_owner_ex * __user owner_p = (void * __user)arg;
43855 + struct f_owner_ex __user *owner_p = (void __user *)arg;
43856 struct f_owner_ex owner;
43857 struct pid *pid;
43858 int type;
43859 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
43860
43861 static int f_getown_ex(struct file *filp, unsigned long arg)
43862 {
43863 - struct f_owner_ex * __user owner_p = (void * __user)arg;
43864 + struct f_owner_ex __user *owner_p = (void __user *)arg;
43865 struct f_owner_ex owner;
43866 int ret = 0;
43867
43868 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
43869 switch (cmd) {
43870 case F_DUPFD:
43871 case F_DUPFD_CLOEXEC:
43872 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
43873 if (arg >= rlimit(RLIMIT_NOFILE))
43874 break;
43875 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
43876 diff --git a/fs/fifo.c b/fs/fifo.c
43877 index b1a524d..4ee270e 100644
43878 --- a/fs/fifo.c
43879 +++ b/fs/fifo.c
43880 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
43881 */
43882 filp->f_op = &read_pipefifo_fops;
43883 pipe->r_counter++;
43884 - if (pipe->readers++ == 0)
43885 + if (atomic_inc_return(&pipe->readers) == 1)
43886 wake_up_partner(inode);
43887
43888 - if (!pipe->writers) {
43889 + if (!atomic_read(&pipe->writers)) {
43890 if ((filp->f_flags & O_NONBLOCK)) {
43891 /* suppress POLLHUP until we have
43892 * seen a writer */
43893 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
43894 * errno=ENXIO when there is no process reading the FIFO.
43895 */
43896 ret = -ENXIO;
43897 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
43898 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
43899 goto err;
43900
43901 filp->f_op = &write_pipefifo_fops;
43902 pipe->w_counter++;
43903 - if (!pipe->writers++)
43904 + if (atomic_inc_return(&pipe->writers) == 1)
43905 wake_up_partner(inode);
43906
43907 - if (!pipe->readers) {
43908 + if (!atomic_read(&pipe->readers)) {
43909 wait_for_partner(inode, &pipe->r_counter);
43910 if (signal_pending(current))
43911 goto err_wr;
43912 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
43913 */
43914 filp->f_op = &rdwr_pipefifo_fops;
43915
43916 - pipe->readers++;
43917 - pipe->writers++;
43918 + atomic_inc(&pipe->readers);
43919 + atomic_inc(&pipe->writers);
43920 pipe->r_counter++;
43921 pipe->w_counter++;
43922 - if (pipe->readers == 1 || pipe->writers == 1)
43923 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
43924 wake_up_partner(inode);
43925 break;
43926
43927 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
43928 return 0;
43929
43930 err_rd:
43931 - if (!--pipe->readers)
43932 + if (atomic_dec_and_test(&pipe->readers))
43933 wake_up_interruptible(&pipe->wait);
43934 ret = -ERESTARTSYS;
43935 goto err;
43936
43937 err_wr:
43938 - if (!--pipe->writers)
43939 + if (atomic_dec_and_test(&pipe->writers))
43940 wake_up_interruptible(&pipe->wait);
43941 ret = -ERESTARTSYS;
43942 goto err;
43943
43944 err:
43945 - if (!pipe->readers && !pipe->writers)
43946 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
43947 free_pipe_info(inode);
43948
43949 err_nocleanup:
43950 diff --git a/fs/file.c b/fs/file.c
43951 index 4c6992d..104cdea 100644
43952 --- a/fs/file.c
43953 +++ b/fs/file.c
43954 @@ -15,6 +15,7 @@
43955 #include <linux/slab.h>
43956 #include <linux/vmalloc.h>
43957 #include <linux/file.h>
43958 +#include <linux/security.h>
43959 #include <linux/fdtable.h>
43960 #include <linux/bitops.h>
43961 #include <linux/interrupt.h>
43962 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
43963 * N.B. For clone tasks sharing a files structure, this test
43964 * will limit the total number of files that can be opened.
43965 */
43966 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
43967 if (nr >= rlimit(RLIMIT_NOFILE))
43968 return -EMFILE;
43969
43970 diff --git a/fs/filesystems.c b/fs/filesystems.c
43971 index 96f2428..f5eeb8e 100644
43972 --- a/fs/filesystems.c
43973 +++ b/fs/filesystems.c
43974 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
43975 int len = dot ? dot - name : strlen(name);
43976
43977 fs = __get_fs_type(name, len);
43978 +
43979 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
43980 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
43981 +#else
43982 if (!fs && (request_module("%.*s", len, name) == 0))
43983 +#endif
43984 fs = __get_fs_type(name, len);
43985
43986 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
43987 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
43988 index 78b519c..a8b4979 100644
43989 --- a/fs/fs_struct.c
43990 +++ b/fs/fs_struct.c
43991 @@ -4,6 +4,7 @@
43992 #include <linux/path.h>
43993 #include <linux/slab.h>
43994 #include <linux/fs_struct.h>
43995 +#include <linux/grsecurity.h>
43996 #include "internal.h"
43997
43998 static inline void path_get_longterm(struct path *path)
43999 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44000 old_root = fs->root;
44001 fs->root = *path;
44002 path_get_longterm(path);
44003 + gr_set_chroot_entries(current, path);
44004 write_seqcount_end(&fs->seq);
44005 spin_unlock(&fs->lock);
44006 if (old_root.dentry)
44007 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44008 && fs->root.mnt == old_root->mnt) {
44009 path_get_longterm(new_root);
44010 fs->root = *new_root;
44011 + gr_set_chroot_entries(p, new_root);
44012 count++;
44013 }
44014 if (fs->pwd.dentry == old_root->dentry
44015 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
44016 spin_lock(&fs->lock);
44017 write_seqcount_begin(&fs->seq);
44018 tsk->fs = NULL;
44019 - kill = !--fs->users;
44020 + gr_clear_chroot_entries(tsk);
44021 + kill = !atomic_dec_return(&fs->users);
44022 write_seqcount_end(&fs->seq);
44023 spin_unlock(&fs->lock);
44024 task_unlock(tsk);
44025 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44026 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44027 /* We don't need to lock fs - think why ;-) */
44028 if (fs) {
44029 - fs->users = 1;
44030 + atomic_set(&fs->users, 1);
44031 fs->in_exec = 0;
44032 spin_lock_init(&fs->lock);
44033 seqcount_init(&fs->seq);
44034 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44035 spin_lock(&old->lock);
44036 fs->root = old->root;
44037 path_get_longterm(&fs->root);
44038 + /* instead of calling gr_set_chroot_entries here,
44039 + we call it from every caller of this function
44040 + */
44041 fs->pwd = old->pwd;
44042 path_get_longterm(&fs->pwd);
44043 spin_unlock(&old->lock);
44044 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
44045
44046 task_lock(current);
44047 spin_lock(&fs->lock);
44048 - kill = !--fs->users;
44049 + kill = !atomic_dec_return(&fs->users);
44050 current->fs = new_fs;
44051 + gr_set_chroot_entries(current, &new_fs->root);
44052 spin_unlock(&fs->lock);
44053 task_unlock(current);
44054
44055 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44056
44057 int current_umask(void)
44058 {
44059 - return current->fs->umask;
44060 + return current->fs->umask | gr_acl_umask();
44061 }
44062 EXPORT_SYMBOL(current_umask);
44063
44064 /* to be mentioned only in INIT_TASK */
44065 struct fs_struct init_fs = {
44066 - .users = 1,
44067 + .users = ATOMIC_INIT(1),
44068 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44069 .seq = SEQCNT_ZERO,
44070 .umask = 0022,
44071 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
44072 task_lock(current);
44073
44074 spin_lock(&init_fs.lock);
44075 - init_fs.users++;
44076 + atomic_inc(&init_fs.users);
44077 spin_unlock(&init_fs.lock);
44078
44079 spin_lock(&fs->lock);
44080 current->fs = &init_fs;
44081 - kill = !--fs->users;
44082 + gr_set_chroot_entries(current, &current->fs->root);
44083 + kill = !atomic_dec_return(&fs->users);
44084 spin_unlock(&fs->lock);
44085
44086 task_unlock(current);
44087 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44088 index 9905350..02eaec4 100644
44089 --- a/fs/fscache/cookie.c
44090 +++ b/fs/fscache/cookie.c
44091 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44092 parent ? (char *) parent->def->name : "<no-parent>",
44093 def->name, netfs_data);
44094
44095 - fscache_stat(&fscache_n_acquires);
44096 + fscache_stat_unchecked(&fscache_n_acquires);
44097
44098 /* if there's no parent cookie, then we don't create one here either */
44099 if (!parent) {
44100 - fscache_stat(&fscache_n_acquires_null);
44101 + fscache_stat_unchecked(&fscache_n_acquires_null);
44102 _leave(" [no parent]");
44103 return NULL;
44104 }
44105 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44106 /* allocate and initialise a cookie */
44107 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44108 if (!cookie) {
44109 - fscache_stat(&fscache_n_acquires_oom);
44110 + fscache_stat_unchecked(&fscache_n_acquires_oom);
44111 _leave(" [ENOMEM]");
44112 return NULL;
44113 }
44114 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44115
44116 switch (cookie->def->type) {
44117 case FSCACHE_COOKIE_TYPE_INDEX:
44118 - fscache_stat(&fscache_n_cookie_index);
44119 + fscache_stat_unchecked(&fscache_n_cookie_index);
44120 break;
44121 case FSCACHE_COOKIE_TYPE_DATAFILE:
44122 - fscache_stat(&fscache_n_cookie_data);
44123 + fscache_stat_unchecked(&fscache_n_cookie_data);
44124 break;
44125 default:
44126 - fscache_stat(&fscache_n_cookie_special);
44127 + fscache_stat_unchecked(&fscache_n_cookie_special);
44128 break;
44129 }
44130
44131 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44132 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44133 atomic_dec(&parent->n_children);
44134 __fscache_cookie_put(cookie);
44135 - fscache_stat(&fscache_n_acquires_nobufs);
44136 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44137 _leave(" = NULL");
44138 return NULL;
44139 }
44140 }
44141
44142 - fscache_stat(&fscache_n_acquires_ok);
44143 + fscache_stat_unchecked(&fscache_n_acquires_ok);
44144 _leave(" = %p", cookie);
44145 return cookie;
44146 }
44147 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44148 cache = fscache_select_cache_for_object(cookie->parent);
44149 if (!cache) {
44150 up_read(&fscache_addremove_sem);
44151 - fscache_stat(&fscache_n_acquires_no_cache);
44152 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44153 _leave(" = -ENOMEDIUM [no cache]");
44154 return -ENOMEDIUM;
44155 }
44156 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44157 object = cache->ops->alloc_object(cache, cookie);
44158 fscache_stat_d(&fscache_n_cop_alloc_object);
44159 if (IS_ERR(object)) {
44160 - fscache_stat(&fscache_n_object_no_alloc);
44161 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
44162 ret = PTR_ERR(object);
44163 goto error;
44164 }
44165
44166 - fscache_stat(&fscache_n_object_alloc);
44167 + fscache_stat_unchecked(&fscache_n_object_alloc);
44168
44169 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
44170
44171 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
44172 struct fscache_object *object;
44173 struct hlist_node *_p;
44174
44175 - fscache_stat(&fscache_n_updates);
44176 + fscache_stat_unchecked(&fscache_n_updates);
44177
44178 if (!cookie) {
44179 - fscache_stat(&fscache_n_updates_null);
44180 + fscache_stat_unchecked(&fscache_n_updates_null);
44181 _leave(" [no cookie]");
44182 return;
44183 }
44184 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44185 struct fscache_object *object;
44186 unsigned long event;
44187
44188 - fscache_stat(&fscache_n_relinquishes);
44189 + fscache_stat_unchecked(&fscache_n_relinquishes);
44190 if (retire)
44191 - fscache_stat(&fscache_n_relinquishes_retire);
44192 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
44193
44194 if (!cookie) {
44195 - fscache_stat(&fscache_n_relinquishes_null);
44196 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
44197 _leave(" [no cookie]");
44198 return;
44199 }
44200 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44201
44202 /* wait for the cookie to finish being instantiated (or to fail) */
44203 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
44204 - fscache_stat(&fscache_n_relinquishes_waitcrt);
44205 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
44206 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
44207 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
44208 }
44209 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
44210 index f6aad48..88dcf26 100644
44211 --- a/fs/fscache/internal.h
44212 +++ b/fs/fscache/internal.h
44213 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
44214 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
44215 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
44216
44217 -extern atomic_t fscache_n_op_pend;
44218 -extern atomic_t fscache_n_op_run;
44219 -extern atomic_t fscache_n_op_enqueue;
44220 -extern atomic_t fscache_n_op_deferred_release;
44221 -extern atomic_t fscache_n_op_release;
44222 -extern atomic_t fscache_n_op_gc;
44223 -extern atomic_t fscache_n_op_cancelled;
44224 -extern atomic_t fscache_n_op_rejected;
44225 +extern atomic_unchecked_t fscache_n_op_pend;
44226 +extern atomic_unchecked_t fscache_n_op_run;
44227 +extern atomic_unchecked_t fscache_n_op_enqueue;
44228 +extern atomic_unchecked_t fscache_n_op_deferred_release;
44229 +extern atomic_unchecked_t fscache_n_op_release;
44230 +extern atomic_unchecked_t fscache_n_op_gc;
44231 +extern atomic_unchecked_t fscache_n_op_cancelled;
44232 +extern atomic_unchecked_t fscache_n_op_rejected;
44233
44234 -extern atomic_t fscache_n_attr_changed;
44235 -extern atomic_t fscache_n_attr_changed_ok;
44236 -extern atomic_t fscache_n_attr_changed_nobufs;
44237 -extern atomic_t fscache_n_attr_changed_nomem;
44238 -extern atomic_t fscache_n_attr_changed_calls;
44239 +extern atomic_unchecked_t fscache_n_attr_changed;
44240 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
44241 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
44242 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
44243 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
44244
44245 -extern atomic_t fscache_n_allocs;
44246 -extern atomic_t fscache_n_allocs_ok;
44247 -extern atomic_t fscache_n_allocs_wait;
44248 -extern atomic_t fscache_n_allocs_nobufs;
44249 -extern atomic_t fscache_n_allocs_intr;
44250 -extern atomic_t fscache_n_allocs_object_dead;
44251 -extern atomic_t fscache_n_alloc_ops;
44252 -extern atomic_t fscache_n_alloc_op_waits;
44253 +extern atomic_unchecked_t fscache_n_allocs;
44254 +extern atomic_unchecked_t fscache_n_allocs_ok;
44255 +extern atomic_unchecked_t fscache_n_allocs_wait;
44256 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
44257 +extern atomic_unchecked_t fscache_n_allocs_intr;
44258 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
44259 +extern atomic_unchecked_t fscache_n_alloc_ops;
44260 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
44261
44262 -extern atomic_t fscache_n_retrievals;
44263 -extern atomic_t fscache_n_retrievals_ok;
44264 -extern atomic_t fscache_n_retrievals_wait;
44265 -extern atomic_t fscache_n_retrievals_nodata;
44266 -extern atomic_t fscache_n_retrievals_nobufs;
44267 -extern atomic_t fscache_n_retrievals_intr;
44268 -extern atomic_t fscache_n_retrievals_nomem;
44269 -extern atomic_t fscache_n_retrievals_object_dead;
44270 -extern atomic_t fscache_n_retrieval_ops;
44271 -extern atomic_t fscache_n_retrieval_op_waits;
44272 +extern atomic_unchecked_t fscache_n_retrievals;
44273 +extern atomic_unchecked_t fscache_n_retrievals_ok;
44274 +extern atomic_unchecked_t fscache_n_retrievals_wait;
44275 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
44276 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
44277 +extern atomic_unchecked_t fscache_n_retrievals_intr;
44278 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
44279 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
44280 +extern atomic_unchecked_t fscache_n_retrieval_ops;
44281 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
44282
44283 -extern atomic_t fscache_n_stores;
44284 -extern atomic_t fscache_n_stores_ok;
44285 -extern atomic_t fscache_n_stores_again;
44286 -extern atomic_t fscache_n_stores_nobufs;
44287 -extern atomic_t fscache_n_stores_oom;
44288 -extern atomic_t fscache_n_store_ops;
44289 -extern atomic_t fscache_n_store_calls;
44290 -extern atomic_t fscache_n_store_pages;
44291 -extern atomic_t fscache_n_store_radix_deletes;
44292 -extern atomic_t fscache_n_store_pages_over_limit;
44293 +extern atomic_unchecked_t fscache_n_stores;
44294 +extern atomic_unchecked_t fscache_n_stores_ok;
44295 +extern atomic_unchecked_t fscache_n_stores_again;
44296 +extern atomic_unchecked_t fscache_n_stores_nobufs;
44297 +extern atomic_unchecked_t fscache_n_stores_oom;
44298 +extern atomic_unchecked_t fscache_n_store_ops;
44299 +extern atomic_unchecked_t fscache_n_store_calls;
44300 +extern atomic_unchecked_t fscache_n_store_pages;
44301 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
44302 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
44303
44304 -extern atomic_t fscache_n_store_vmscan_not_storing;
44305 -extern atomic_t fscache_n_store_vmscan_gone;
44306 -extern atomic_t fscache_n_store_vmscan_busy;
44307 -extern atomic_t fscache_n_store_vmscan_cancelled;
44308 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
44309 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
44310 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
44311 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
44312
44313 -extern atomic_t fscache_n_marks;
44314 -extern atomic_t fscache_n_uncaches;
44315 +extern atomic_unchecked_t fscache_n_marks;
44316 +extern atomic_unchecked_t fscache_n_uncaches;
44317
44318 -extern atomic_t fscache_n_acquires;
44319 -extern atomic_t fscache_n_acquires_null;
44320 -extern atomic_t fscache_n_acquires_no_cache;
44321 -extern atomic_t fscache_n_acquires_ok;
44322 -extern atomic_t fscache_n_acquires_nobufs;
44323 -extern atomic_t fscache_n_acquires_oom;
44324 +extern atomic_unchecked_t fscache_n_acquires;
44325 +extern atomic_unchecked_t fscache_n_acquires_null;
44326 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
44327 +extern atomic_unchecked_t fscache_n_acquires_ok;
44328 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
44329 +extern atomic_unchecked_t fscache_n_acquires_oom;
44330
44331 -extern atomic_t fscache_n_updates;
44332 -extern atomic_t fscache_n_updates_null;
44333 -extern atomic_t fscache_n_updates_run;
44334 +extern atomic_unchecked_t fscache_n_updates;
44335 +extern atomic_unchecked_t fscache_n_updates_null;
44336 +extern atomic_unchecked_t fscache_n_updates_run;
44337
44338 -extern atomic_t fscache_n_relinquishes;
44339 -extern atomic_t fscache_n_relinquishes_null;
44340 -extern atomic_t fscache_n_relinquishes_waitcrt;
44341 -extern atomic_t fscache_n_relinquishes_retire;
44342 +extern atomic_unchecked_t fscache_n_relinquishes;
44343 +extern atomic_unchecked_t fscache_n_relinquishes_null;
44344 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
44345 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
44346
44347 -extern atomic_t fscache_n_cookie_index;
44348 -extern atomic_t fscache_n_cookie_data;
44349 -extern atomic_t fscache_n_cookie_special;
44350 +extern atomic_unchecked_t fscache_n_cookie_index;
44351 +extern atomic_unchecked_t fscache_n_cookie_data;
44352 +extern atomic_unchecked_t fscache_n_cookie_special;
44353
44354 -extern atomic_t fscache_n_object_alloc;
44355 -extern atomic_t fscache_n_object_no_alloc;
44356 -extern atomic_t fscache_n_object_lookups;
44357 -extern atomic_t fscache_n_object_lookups_negative;
44358 -extern atomic_t fscache_n_object_lookups_positive;
44359 -extern atomic_t fscache_n_object_lookups_timed_out;
44360 -extern atomic_t fscache_n_object_created;
44361 -extern atomic_t fscache_n_object_avail;
44362 -extern atomic_t fscache_n_object_dead;
44363 +extern atomic_unchecked_t fscache_n_object_alloc;
44364 +extern atomic_unchecked_t fscache_n_object_no_alloc;
44365 +extern atomic_unchecked_t fscache_n_object_lookups;
44366 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
44367 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
44368 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
44369 +extern atomic_unchecked_t fscache_n_object_created;
44370 +extern atomic_unchecked_t fscache_n_object_avail;
44371 +extern atomic_unchecked_t fscache_n_object_dead;
44372
44373 -extern atomic_t fscache_n_checkaux_none;
44374 -extern atomic_t fscache_n_checkaux_okay;
44375 -extern atomic_t fscache_n_checkaux_update;
44376 -extern atomic_t fscache_n_checkaux_obsolete;
44377 +extern atomic_unchecked_t fscache_n_checkaux_none;
44378 +extern atomic_unchecked_t fscache_n_checkaux_okay;
44379 +extern atomic_unchecked_t fscache_n_checkaux_update;
44380 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
44381
44382 extern atomic_t fscache_n_cop_alloc_object;
44383 extern atomic_t fscache_n_cop_lookup_object;
44384 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
44385 atomic_inc(stat);
44386 }
44387
44388 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
44389 +{
44390 + atomic_inc_unchecked(stat);
44391 +}
44392 +
44393 static inline void fscache_stat_d(atomic_t *stat)
44394 {
44395 atomic_dec(stat);
44396 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
44397
44398 #define __fscache_stat(stat) (NULL)
44399 #define fscache_stat(stat) do {} while (0)
44400 +#define fscache_stat_unchecked(stat) do {} while (0)
44401 #define fscache_stat_d(stat) do {} while (0)
44402 #endif
44403
44404 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
44405 index b6b897c..0ffff9c 100644
44406 --- a/fs/fscache/object.c
44407 +++ b/fs/fscache/object.c
44408 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44409 /* update the object metadata on disk */
44410 case FSCACHE_OBJECT_UPDATING:
44411 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
44412 - fscache_stat(&fscache_n_updates_run);
44413 + fscache_stat_unchecked(&fscache_n_updates_run);
44414 fscache_stat(&fscache_n_cop_update_object);
44415 object->cache->ops->update_object(object);
44416 fscache_stat_d(&fscache_n_cop_update_object);
44417 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44418 spin_lock(&object->lock);
44419 object->state = FSCACHE_OBJECT_DEAD;
44420 spin_unlock(&object->lock);
44421 - fscache_stat(&fscache_n_object_dead);
44422 + fscache_stat_unchecked(&fscache_n_object_dead);
44423 goto terminal_transit;
44424
44425 /* handle the parent cache of this object being withdrawn from
44426 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44427 spin_lock(&object->lock);
44428 object->state = FSCACHE_OBJECT_DEAD;
44429 spin_unlock(&object->lock);
44430 - fscache_stat(&fscache_n_object_dead);
44431 + fscache_stat_unchecked(&fscache_n_object_dead);
44432 goto terminal_transit;
44433
44434 /* complain about the object being woken up once it is
44435 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
44436 parent->cookie->def->name, cookie->def->name,
44437 object->cache->tag->name);
44438
44439 - fscache_stat(&fscache_n_object_lookups);
44440 + fscache_stat_unchecked(&fscache_n_object_lookups);
44441 fscache_stat(&fscache_n_cop_lookup_object);
44442 ret = object->cache->ops->lookup_object(object);
44443 fscache_stat_d(&fscache_n_cop_lookup_object);
44444 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
44445 if (ret == -ETIMEDOUT) {
44446 /* probably stuck behind another object, so move this one to
44447 * the back of the queue */
44448 - fscache_stat(&fscache_n_object_lookups_timed_out);
44449 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
44450 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
44451 }
44452
44453 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
44454
44455 spin_lock(&object->lock);
44456 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
44457 - fscache_stat(&fscache_n_object_lookups_negative);
44458 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
44459
44460 /* transit here to allow write requests to begin stacking up
44461 * and read requests to begin returning ENODATA */
44462 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
44463 * result, in which case there may be data available */
44464 spin_lock(&object->lock);
44465 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
44466 - fscache_stat(&fscache_n_object_lookups_positive);
44467 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
44468
44469 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
44470
44471 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
44472 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
44473 } else {
44474 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
44475 - fscache_stat(&fscache_n_object_created);
44476 + fscache_stat_unchecked(&fscache_n_object_created);
44477
44478 object->state = FSCACHE_OBJECT_AVAILABLE;
44479 spin_unlock(&object->lock);
44480 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
44481 fscache_enqueue_dependents(object);
44482
44483 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
44484 - fscache_stat(&fscache_n_object_avail);
44485 + fscache_stat_unchecked(&fscache_n_object_avail);
44486
44487 _leave("");
44488 }
44489 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
44490 enum fscache_checkaux result;
44491
44492 if (!object->cookie->def->check_aux) {
44493 - fscache_stat(&fscache_n_checkaux_none);
44494 + fscache_stat_unchecked(&fscache_n_checkaux_none);
44495 return FSCACHE_CHECKAUX_OKAY;
44496 }
44497
44498 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
44499 switch (result) {
44500 /* entry okay as is */
44501 case FSCACHE_CHECKAUX_OKAY:
44502 - fscache_stat(&fscache_n_checkaux_okay);
44503 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
44504 break;
44505
44506 /* entry requires update */
44507 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
44508 - fscache_stat(&fscache_n_checkaux_update);
44509 + fscache_stat_unchecked(&fscache_n_checkaux_update);
44510 break;
44511
44512 /* entry requires deletion */
44513 case FSCACHE_CHECKAUX_OBSOLETE:
44514 - fscache_stat(&fscache_n_checkaux_obsolete);
44515 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
44516 break;
44517
44518 default:
44519 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
44520 index 30afdfa..2256596 100644
44521 --- a/fs/fscache/operation.c
44522 +++ b/fs/fscache/operation.c
44523 @@ -17,7 +17,7 @@
44524 #include <linux/slab.h>
44525 #include "internal.h"
44526
44527 -atomic_t fscache_op_debug_id;
44528 +atomic_unchecked_t fscache_op_debug_id;
44529 EXPORT_SYMBOL(fscache_op_debug_id);
44530
44531 /**
44532 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
44533 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
44534 ASSERTCMP(atomic_read(&op->usage), >, 0);
44535
44536 - fscache_stat(&fscache_n_op_enqueue);
44537 + fscache_stat_unchecked(&fscache_n_op_enqueue);
44538 switch (op->flags & FSCACHE_OP_TYPE) {
44539 case FSCACHE_OP_ASYNC:
44540 _debug("queue async");
44541 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
44542 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
44543 if (op->processor)
44544 fscache_enqueue_operation(op);
44545 - fscache_stat(&fscache_n_op_run);
44546 + fscache_stat_unchecked(&fscache_n_op_run);
44547 }
44548
44549 /*
44550 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
44551 if (object->n_ops > 1) {
44552 atomic_inc(&op->usage);
44553 list_add_tail(&op->pend_link, &object->pending_ops);
44554 - fscache_stat(&fscache_n_op_pend);
44555 + fscache_stat_unchecked(&fscache_n_op_pend);
44556 } else if (!list_empty(&object->pending_ops)) {
44557 atomic_inc(&op->usage);
44558 list_add_tail(&op->pend_link, &object->pending_ops);
44559 - fscache_stat(&fscache_n_op_pend);
44560 + fscache_stat_unchecked(&fscache_n_op_pend);
44561 fscache_start_operations(object);
44562 } else {
44563 ASSERTCMP(object->n_in_progress, ==, 0);
44564 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
44565 object->n_exclusive++; /* reads and writes must wait */
44566 atomic_inc(&op->usage);
44567 list_add_tail(&op->pend_link, &object->pending_ops);
44568 - fscache_stat(&fscache_n_op_pend);
44569 + fscache_stat_unchecked(&fscache_n_op_pend);
44570 ret = 0;
44571 } else {
44572 /* not allowed to submit ops in any other state */
44573 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
44574 if (object->n_exclusive > 0) {
44575 atomic_inc(&op->usage);
44576 list_add_tail(&op->pend_link, &object->pending_ops);
44577 - fscache_stat(&fscache_n_op_pend);
44578 + fscache_stat_unchecked(&fscache_n_op_pend);
44579 } else if (!list_empty(&object->pending_ops)) {
44580 atomic_inc(&op->usage);
44581 list_add_tail(&op->pend_link, &object->pending_ops);
44582 - fscache_stat(&fscache_n_op_pend);
44583 + fscache_stat_unchecked(&fscache_n_op_pend);
44584 fscache_start_operations(object);
44585 } else {
44586 ASSERTCMP(object->n_exclusive, ==, 0);
44587 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
44588 object->n_ops++;
44589 atomic_inc(&op->usage);
44590 list_add_tail(&op->pend_link, &object->pending_ops);
44591 - fscache_stat(&fscache_n_op_pend);
44592 + fscache_stat_unchecked(&fscache_n_op_pend);
44593 ret = 0;
44594 } else if (object->state == FSCACHE_OBJECT_DYING ||
44595 object->state == FSCACHE_OBJECT_LC_DYING ||
44596 object->state == FSCACHE_OBJECT_WITHDRAWING) {
44597 - fscache_stat(&fscache_n_op_rejected);
44598 + fscache_stat_unchecked(&fscache_n_op_rejected);
44599 ret = -ENOBUFS;
44600 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
44601 fscache_report_unexpected_submission(object, op, ostate);
44602 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
44603
44604 ret = -EBUSY;
44605 if (!list_empty(&op->pend_link)) {
44606 - fscache_stat(&fscache_n_op_cancelled);
44607 + fscache_stat_unchecked(&fscache_n_op_cancelled);
44608 list_del_init(&op->pend_link);
44609 object->n_ops--;
44610 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
44611 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
44612 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
44613 BUG();
44614
44615 - fscache_stat(&fscache_n_op_release);
44616 + fscache_stat_unchecked(&fscache_n_op_release);
44617
44618 if (op->release) {
44619 op->release(op);
44620 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
44621 * lock, and defer it otherwise */
44622 if (!spin_trylock(&object->lock)) {
44623 _debug("defer put");
44624 - fscache_stat(&fscache_n_op_deferred_release);
44625 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
44626
44627 cache = object->cache;
44628 spin_lock(&cache->op_gc_list_lock);
44629 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
44630
44631 _debug("GC DEFERRED REL OBJ%x OP%x",
44632 object->debug_id, op->debug_id);
44633 - fscache_stat(&fscache_n_op_gc);
44634 + fscache_stat_unchecked(&fscache_n_op_gc);
44635
44636 ASSERTCMP(atomic_read(&op->usage), ==, 0);
44637
44638 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
44639 index 3f7a59b..cf196cc 100644
44640 --- a/fs/fscache/page.c
44641 +++ b/fs/fscache/page.c
44642 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
44643 val = radix_tree_lookup(&cookie->stores, page->index);
44644 if (!val) {
44645 rcu_read_unlock();
44646 - fscache_stat(&fscache_n_store_vmscan_not_storing);
44647 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
44648 __fscache_uncache_page(cookie, page);
44649 return true;
44650 }
44651 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
44652 spin_unlock(&cookie->stores_lock);
44653
44654 if (xpage) {
44655 - fscache_stat(&fscache_n_store_vmscan_cancelled);
44656 - fscache_stat(&fscache_n_store_radix_deletes);
44657 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
44658 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
44659 ASSERTCMP(xpage, ==, page);
44660 } else {
44661 - fscache_stat(&fscache_n_store_vmscan_gone);
44662 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
44663 }
44664
44665 wake_up_bit(&cookie->flags, 0);
44666 @@ -107,7 +107,7 @@ page_busy:
44667 /* we might want to wait here, but that could deadlock the allocator as
44668 * the work threads writing to the cache may all end up sleeping
44669 * on memory allocation */
44670 - fscache_stat(&fscache_n_store_vmscan_busy);
44671 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
44672 return false;
44673 }
44674 EXPORT_SYMBOL(__fscache_maybe_release_page);
44675 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
44676 FSCACHE_COOKIE_STORING_TAG);
44677 if (!radix_tree_tag_get(&cookie->stores, page->index,
44678 FSCACHE_COOKIE_PENDING_TAG)) {
44679 - fscache_stat(&fscache_n_store_radix_deletes);
44680 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
44681 xpage = radix_tree_delete(&cookie->stores, page->index);
44682 }
44683 spin_unlock(&cookie->stores_lock);
44684 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
44685
44686 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
44687
44688 - fscache_stat(&fscache_n_attr_changed_calls);
44689 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
44690
44691 if (fscache_object_is_active(object)) {
44692 fscache_stat(&fscache_n_cop_attr_changed);
44693 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44694
44695 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
44696
44697 - fscache_stat(&fscache_n_attr_changed);
44698 + fscache_stat_unchecked(&fscache_n_attr_changed);
44699
44700 op = kzalloc(sizeof(*op), GFP_KERNEL);
44701 if (!op) {
44702 - fscache_stat(&fscache_n_attr_changed_nomem);
44703 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
44704 _leave(" = -ENOMEM");
44705 return -ENOMEM;
44706 }
44707 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44708 if (fscache_submit_exclusive_op(object, op) < 0)
44709 goto nobufs;
44710 spin_unlock(&cookie->lock);
44711 - fscache_stat(&fscache_n_attr_changed_ok);
44712 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
44713 fscache_put_operation(op);
44714 _leave(" = 0");
44715 return 0;
44716 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44717 nobufs:
44718 spin_unlock(&cookie->lock);
44719 kfree(op);
44720 - fscache_stat(&fscache_n_attr_changed_nobufs);
44721 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
44722 _leave(" = %d", -ENOBUFS);
44723 return -ENOBUFS;
44724 }
44725 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
44726 /* allocate a retrieval operation and attempt to submit it */
44727 op = kzalloc(sizeof(*op), GFP_NOIO);
44728 if (!op) {
44729 - fscache_stat(&fscache_n_retrievals_nomem);
44730 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
44731 return NULL;
44732 }
44733
44734 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
44735 return 0;
44736 }
44737
44738 - fscache_stat(&fscache_n_retrievals_wait);
44739 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
44740
44741 jif = jiffies;
44742 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
44743 fscache_wait_bit_interruptible,
44744 TASK_INTERRUPTIBLE) != 0) {
44745 - fscache_stat(&fscache_n_retrievals_intr);
44746 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
44747 _leave(" = -ERESTARTSYS");
44748 return -ERESTARTSYS;
44749 }
44750 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
44751 */
44752 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
44753 struct fscache_retrieval *op,
44754 - atomic_t *stat_op_waits,
44755 - atomic_t *stat_object_dead)
44756 + atomic_unchecked_t *stat_op_waits,
44757 + atomic_unchecked_t *stat_object_dead)
44758 {
44759 int ret;
44760
44761 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
44762 goto check_if_dead;
44763
44764 _debug(">>> WT");
44765 - fscache_stat(stat_op_waits);
44766 + fscache_stat_unchecked(stat_op_waits);
44767 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
44768 fscache_wait_bit_interruptible,
44769 TASK_INTERRUPTIBLE) < 0) {
44770 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
44771
44772 check_if_dead:
44773 if (unlikely(fscache_object_is_dead(object))) {
44774 - fscache_stat(stat_object_dead);
44775 + fscache_stat_unchecked(stat_object_dead);
44776 return -ENOBUFS;
44777 }
44778 return 0;
44779 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
44780
44781 _enter("%p,%p,,,", cookie, page);
44782
44783 - fscache_stat(&fscache_n_retrievals);
44784 + fscache_stat_unchecked(&fscache_n_retrievals);
44785
44786 if (hlist_empty(&cookie->backing_objects))
44787 goto nobufs;
44788 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
44789 goto nobufs_unlock;
44790 spin_unlock(&cookie->lock);
44791
44792 - fscache_stat(&fscache_n_retrieval_ops);
44793 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
44794
44795 /* pin the netfs read context in case we need to do the actual netfs
44796 * read because we've encountered a cache read failure */
44797 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
44798
44799 error:
44800 if (ret == -ENOMEM)
44801 - fscache_stat(&fscache_n_retrievals_nomem);
44802 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
44803 else if (ret == -ERESTARTSYS)
44804 - fscache_stat(&fscache_n_retrievals_intr);
44805 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
44806 else if (ret == -ENODATA)
44807 - fscache_stat(&fscache_n_retrievals_nodata);
44808 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
44809 else if (ret < 0)
44810 - fscache_stat(&fscache_n_retrievals_nobufs);
44811 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44812 else
44813 - fscache_stat(&fscache_n_retrievals_ok);
44814 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
44815
44816 fscache_put_retrieval(op);
44817 _leave(" = %d", ret);
44818 @@ -429,7 +429,7 @@ nobufs_unlock:
44819 spin_unlock(&cookie->lock);
44820 kfree(op);
44821 nobufs:
44822 - fscache_stat(&fscache_n_retrievals_nobufs);
44823 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44824 _leave(" = -ENOBUFS");
44825 return -ENOBUFS;
44826 }
44827 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
44828
44829 _enter("%p,,%d,,,", cookie, *nr_pages);
44830
44831 - fscache_stat(&fscache_n_retrievals);
44832 + fscache_stat_unchecked(&fscache_n_retrievals);
44833
44834 if (hlist_empty(&cookie->backing_objects))
44835 goto nobufs;
44836 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
44837 goto nobufs_unlock;
44838 spin_unlock(&cookie->lock);
44839
44840 - fscache_stat(&fscache_n_retrieval_ops);
44841 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
44842
44843 /* pin the netfs read context in case we need to do the actual netfs
44844 * read because we've encountered a cache read failure */
44845 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
44846
44847 error:
44848 if (ret == -ENOMEM)
44849 - fscache_stat(&fscache_n_retrievals_nomem);
44850 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
44851 else if (ret == -ERESTARTSYS)
44852 - fscache_stat(&fscache_n_retrievals_intr);
44853 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
44854 else if (ret == -ENODATA)
44855 - fscache_stat(&fscache_n_retrievals_nodata);
44856 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
44857 else if (ret < 0)
44858 - fscache_stat(&fscache_n_retrievals_nobufs);
44859 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44860 else
44861 - fscache_stat(&fscache_n_retrievals_ok);
44862 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
44863
44864 fscache_put_retrieval(op);
44865 _leave(" = %d", ret);
44866 @@ -545,7 +545,7 @@ nobufs_unlock:
44867 spin_unlock(&cookie->lock);
44868 kfree(op);
44869 nobufs:
44870 - fscache_stat(&fscache_n_retrievals_nobufs);
44871 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44872 _leave(" = -ENOBUFS");
44873 return -ENOBUFS;
44874 }
44875 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
44876
44877 _enter("%p,%p,,,", cookie, page);
44878
44879 - fscache_stat(&fscache_n_allocs);
44880 + fscache_stat_unchecked(&fscache_n_allocs);
44881
44882 if (hlist_empty(&cookie->backing_objects))
44883 goto nobufs;
44884 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
44885 goto nobufs_unlock;
44886 spin_unlock(&cookie->lock);
44887
44888 - fscache_stat(&fscache_n_alloc_ops);
44889 + fscache_stat_unchecked(&fscache_n_alloc_ops);
44890
44891 ret = fscache_wait_for_retrieval_activation(
44892 object, op,
44893 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
44894
44895 error:
44896 if (ret == -ERESTARTSYS)
44897 - fscache_stat(&fscache_n_allocs_intr);
44898 + fscache_stat_unchecked(&fscache_n_allocs_intr);
44899 else if (ret < 0)
44900 - fscache_stat(&fscache_n_allocs_nobufs);
44901 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
44902 else
44903 - fscache_stat(&fscache_n_allocs_ok);
44904 + fscache_stat_unchecked(&fscache_n_allocs_ok);
44905
44906 fscache_put_retrieval(op);
44907 _leave(" = %d", ret);
44908 @@ -625,7 +625,7 @@ nobufs_unlock:
44909 spin_unlock(&cookie->lock);
44910 kfree(op);
44911 nobufs:
44912 - fscache_stat(&fscache_n_allocs_nobufs);
44913 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
44914 _leave(" = -ENOBUFS");
44915 return -ENOBUFS;
44916 }
44917 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
44918
44919 spin_lock(&cookie->stores_lock);
44920
44921 - fscache_stat(&fscache_n_store_calls);
44922 + fscache_stat_unchecked(&fscache_n_store_calls);
44923
44924 /* find a page to store */
44925 page = NULL;
44926 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
44927 page = results[0];
44928 _debug("gang %d [%lx]", n, page->index);
44929 if (page->index > op->store_limit) {
44930 - fscache_stat(&fscache_n_store_pages_over_limit);
44931 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
44932 goto superseded;
44933 }
44934
44935 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
44936 spin_unlock(&cookie->stores_lock);
44937 spin_unlock(&object->lock);
44938
44939 - fscache_stat(&fscache_n_store_pages);
44940 + fscache_stat_unchecked(&fscache_n_store_pages);
44941 fscache_stat(&fscache_n_cop_write_page);
44942 ret = object->cache->ops->write_page(op, page);
44943 fscache_stat_d(&fscache_n_cop_write_page);
44944 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44945 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
44946 ASSERT(PageFsCache(page));
44947
44948 - fscache_stat(&fscache_n_stores);
44949 + fscache_stat_unchecked(&fscache_n_stores);
44950
44951 op = kzalloc(sizeof(*op), GFP_NOIO);
44952 if (!op)
44953 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44954 spin_unlock(&cookie->stores_lock);
44955 spin_unlock(&object->lock);
44956
44957 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
44958 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
44959 op->store_limit = object->store_limit;
44960
44961 if (fscache_submit_op(object, &op->op) < 0)
44962 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44963
44964 spin_unlock(&cookie->lock);
44965 radix_tree_preload_end();
44966 - fscache_stat(&fscache_n_store_ops);
44967 - fscache_stat(&fscache_n_stores_ok);
44968 + fscache_stat_unchecked(&fscache_n_store_ops);
44969 + fscache_stat_unchecked(&fscache_n_stores_ok);
44970
44971 /* the work queue now carries its own ref on the object */
44972 fscache_put_operation(&op->op);
44973 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44974 return 0;
44975
44976 already_queued:
44977 - fscache_stat(&fscache_n_stores_again);
44978 + fscache_stat_unchecked(&fscache_n_stores_again);
44979 already_pending:
44980 spin_unlock(&cookie->stores_lock);
44981 spin_unlock(&object->lock);
44982 spin_unlock(&cookie->lock);
44983 radix_tree_preload_end();
44984 kfree(op);
44985 - fscache_stat(&fscache_n_stores_ok);
44986 + fscache_stat_unchecked(&fscache_n_stores_ok);
44987 _leave(" = 0");
44988 return 0;
44989
44990 @@ -851,14 +851,14 @@ nobufs:
44991 spin_unlock(&cookie->lock);
44992 radix_tree_preload_end();
44993 kfree(op);
44994 - fscache_stat(&fscache_n_stores_nobufs);
44995 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
44996 _leave(" = -ENOBUFS");
44997 return -ENOBUFS;
44998
44999 nomem_free:
45000 kfree(op);
45001 nomem:
45002 - fscache_stat(&fscache_n_stores_oom);
45003 + fscache_stat_unchecked(&fscache_n_stores_oom);
45004 _leave(" = -ENOMEM");
45005 return -ENOMEM;
45006 }
45007 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45008 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45009 ASSERTCMP(page, !=, NULL);
45010
45011 - fscache_stat(&fscache_n_uncaches);
45012 + fscache_stat_unchecked(&fscache_n_uncaches);
45013
45014 /* cache withdrawal may beat us to it */
45015 if (!PageFsCache(page))
45016 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45017 unsigned long loop;
45018
45019 #ifdef CONFIG_FSCACHE_STATS
45020 - atomic_add(pagevec->nr, &fscache_n_marks);
45021 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45022 #endif
45023
45024 for (loop = 0; loop < pagevec->nr; loop++) {
45025 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45026 index 4765190..2a067f2 100644
45027 --- a/fs/fscache/stats.c
45028 +++ b/fs/fscache/stats.c
45029 @@ -18,95 +18,95 @@
45030 /*
45031 * operation counters
45032 */
45033 -atomic_t fscache_n_op_pend;
45034 -atomic_t fscache_n_op_run;
45035 -atomic_t fscache_n_op_enqueue;
45036 -atomic_t fscache_n_op_requeue;
45037 -atomic_t fscache_n_op_deferred_release;
45038 -atomic_t fscache_n_op_release;
45039 -atomic_t fscache_n_op_gc;
45040 -atomic_t fscache_n_op_cancelled;
45041 -atomic_t fscache_n_op_rejected;
45042 +atomic_unchecked_t fscache_n_op_pend;
45043 +atomic_unchecked_t fscache_n_op_run;
45044 +atomic_unchecked_t fscache_n_op_enqueue;
45045 +atomic_unchecked_t fscache_n_op_requeue;
45046 +atomic_unchecked_t fscache_n_op_deferred_release;
45047 +atomic_unchecked_t fscache_n_op_release;
45048 +atomic_unchecked_t fscache_n_op_gc;
45049 +atomic_unchecked_t fscache_n_op_cancelled;
45050 +atomic_unchecked_t fscache_n_op_rejected;
45051
45052 -atomic_t fscache_n_attr_changed;
45053 -atomic_t fscache_n_attr_changed_ok;
45054 -atomic_t fscache_n_attr_changed_nobufs;
45055 -atomic_t fscache_n_attr_changed_nomem;
45056 -atomic_t fscache_n_attr_changed_calls;
45057 +atomic_unchecked_t fscache_n_attr_changed;
45058 +atomic_unchecked_t fscache_n_attr_changed_ok;
45059 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
45060 +atomic_unchecked_t fscache_n_attr_changed_nomem;
45061 +atomic_unchecked_t fscache_n_attr_changed_calls;
45062
45063 -atomic_t fscache_n_allocs;
45064 -atomic_t fscache_n_allocs_ok;
45065 -atomic_t fscache_n_allocs_wait;
45066 -atomic_t fscache_n_allocs_nobufs;
45067 -atomic_t fscache_n_allocs_intr;
45068 -atomic_t fscache_n_allocs_object_dead;
45069 -atomic_t fscache_n_alloc_ops;
45070 -atomic_t fscache_n_alloc_op_waits;
45071 +atomic_unchecked_t fscache_n_allocs;
45072 +atomic_unchecked_t fscache_n_allocs_ok;
45073 +atomic_unchecked_t fscache_n_allocs_wait;
45074 +atomic_unchecked_t fscache_n_allocs_nobufs;
45075 +atomic_unchecked_t fscache_n_allocs_intr;
45076 +atomic_unchecked_t fscache_n_allocs_object_dead;
45077 +atomic_unchecked_t fscache_n_alloc_ops;
45078 +atomic_unchecked_t fscache_n_alloc_op_waits;
45079
45080 -atomic_t fscache_n_retrievals;
45081 -atomic_t fscache_n_retrievals_ok;
45082 -atomic_t fscache_n_retrievals_wait;
45083 -atomic_t fscache_n_retrievals_nodata;
45084 -atomic_t fscache_n_retrievals_nobufs;
45085 -atomic_t fscache_n_retrievals_intr;
45086 -atomic_t fscache_n_retrievals_nomem;
45087 -atomic_t fscache_n_retrievals_object_dead;
45088 -atomic_t fscache_n_retrieval_ops;
45089 -atomic_t fscache_n_retrieval_op_waits;
45090 +atomic_unchecked_t fscache_n_retrievals;
45091 +atomic_unchecked_t fscache_n_retrievals_ok;
45092 +atomic_unchecked_t fscache_n_retrievals_wait;
45093 +atomic_unchecked_t fscache_n_retrievals_nodata;
45094 +atomic_unchecked_t fscache_n_retrievals_nobufs;
45095 +atomic_unchecked_t fscache_n_retrievals_intr;
45096 +atomic_unchecked_t fscache_n_retrievals_nomem;
45097 +atomic_unchecked_t fscache_n_retrievals_object_dead;
45098 +atomic_unchecked_t fscache_n_retrieval_ops;
45099 +atomic_unchecked_t fscache_n_retrieval_op_waits;
45100
45101 -atomic_t fscache_n_stores;
45102 -atomic_t fscache_n_stores_ok;
45103 -atomic_t fscache_n_stores_again;
45104 -atomic_t fscache_n_stores_nobufs;
45105 -atomic_t fscache_n_stores_oom;
45106 -atomic_t fscache_n_store_ops;
45107 -atomic_t fscache_n_store_calls;
45108 -atomic_t fscache_n_store_pages;
45109 -atomic_t fscache_n_store_radix_deletes;
45110 -atomic_t fscache_n_store_pages_over_limit;
45111 +atomic_unchecked_t fscache_n_stores;
45112 +atomic_unchecked_t fscache_n_stores_ok;
45113 +atomic_unchecked_t fscache_n_stores_again;
45114 +atomic_unchecked_t fscache_n_stores_nobufs;
45115 +atomic_unchecked_t fscache_n_stores_oom;
45116 +atomic_unchecked_t fscache_n_store_ops;
45117 +atomic_unchecked_t fscache_n_store_calls;
45118 +atomic_unchecked_t fscache_n_store_pages;
45119 +atomic_unchecked_t fscache_n_store_radix_deletes;
45120 +atomic_unchecked_t fscache_n_store_pages_over_limit;
45121
45122 -atomic_t fscache_n_store_vmscan_not_storing;
45123 -atomic_t fscache_n_store_vmscan_gone;
45124 -atomic_t fscache_n_store_vmscan_busy;
45125 -atomic_t fscache_n_store_vmscan_cancelled;
45126 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45127 +atomic_unchecked_t fscache_n_store_vmscan_gone;
45128 +atomic_unchecked_t fscache_n_store_vmscan_busy;
45129 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45130
45131 -atomic_t fscache_n_marks;
45132 -atomic_t fscache_n_uncaches;
45133 +atomic_unchecked_t fscache_n_marks;
45134 +atomic_unchecked_t fscache_n_uncaches;
45135
45136 -atomic_t fscache_n_acquires;
45137 -atomic_t fscache_n_acquires_null;
45138 -atomic_t fscache_n_acquires_no_cache;
45139 -atomic_t fscache_n_acquires_ok;
45140 -atomic_t fscache_n_acquires_nobufs;
45141 -atomic_t fscache_n_acquires_oom;
45142 +atomic_unchecked_t fscache_n_acquires;
45143 +atomic_unchecked_t fscache_n_acquires_null;
45144 +atomic_unchecked_t fscache_n_acquires_no_cache;
45145 +atomic_unchecked_t fscache_n_acquires_ok;
45146 +atomic_unchecked_t fscache_n_acquires_nobufs;
45147 +atomic_unchecked_t fscache_n_acquires_oom;
45148
45149 -atomic_t fscache_n_updates;
45150 -atomic_t fscache_n_updates_null;
45151 -atomic_t fscache_n_updates_run;
45152 +atomic_unchecked_t fscache_n_updates;
45153 +atomic_unchecked_t fscache_n_updates_null;
45154 +atomic_unchecked_t fscache_n_updates_run;
45155
45156 -atomic_t fscache_n_relinquishes;
45157 -atomic_t fscache_n_relinquishes_null;
45158 -atomic_t fscache_n_relinquishes_waitcrt;
45159 -atomic_t fscache_n_relinquishes_retire;
45160 +atomic_unchecked_t fscache_n_relinquishes;
45161 +atomic_unchecked_t fscache_n_relinquishes_null;
45162 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45163 +atomic_unchecked_t fscache_n_relinquishes_retire;
45164
45165 -atomic_t fscache_n_cookie_index;
45166 -atomic_t fscache_n_cookie_data;
45167 -atomic_t fscache_n_cookie_special;
45168 +atomic_unchecked_t fscache_n_cookie_index;
45169 +atomic_unchecked_t fscache_n_cookie_data;
45170 +atomic_unchecked_t fscache_n_cookie_special;
45171
45172 -atomic_t fscache_n_object_alloc;
45173 -atomic_t fscache_n_object_no_alloc;
45174 -atomic_t fscache_n_object_lookups;
45175 -atomic_t fscache_n_object_lookups_negative;
45176 -atomic_t fscache_n_object_lookups_positive;
45177 -atomic_t fscache_n_object_lookups_timed_out;
45178 -atomic_t fscache_n_object_created;
45179 -atomic_t fscache_n_object_avail;
45180 -atomic_t fscache_n_object_dead;
45181 +atomic_unchecked_t fscache_n_object_alloc;
45182 +atomic_unchecked_t fscache_n_object_no_alloc;
45183 +atomic_unchecked_t fscache_n_object_lookups;
45184 +atomic_unchecked_t fscache_n_object_lookups_negative;
45185 +atomic_unchecked_t fscache_n_object_lookups_positive;
45186 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
45187 +atomic_unchecked_t fscache_n_object_created;
45188 +atomic_unchecked_t fscache_n_object_avail;
45189 +atomic_unchecked_t fscache_n_object_dead;
45190
45191 -atomic_t fscache_n_checkaux_none;
45192 -atomic_t fscache_n_checkaux_okay;
45193 -atomic_t fscache_n_checkaux_update;
45194 -atomic_t fscache_n_checkaux_obsolete;
45195 +atomic_unchecked_t fscache_n_checkaux_none;
45196 +atomic_unchecked_t fscache_n_checkaux_okay;
45197 +atomic_unchecked_t fscache_n_checkaux_update;
45198 +atomic_unchecked_t fscache_n_checkaux_obsolete;
45199
45200 atomic_t fscache_n_cop_alloc_object;
45201 atomic_t fscache_n_cop_lookup_object;
45202 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
45203 seq_puts(m, "FS-Cache statistics\n");
45204
45205 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
45206 - atomic_read(&fscache_n_cookie_index),
45207 - atomic_read(&fscache_n_cookie_data),
45208 - atomic_read(&fscache_n_cookie_special));
45209 + atomic_read_unchecked(&fscache_n_cookie_index),
45210 + atomic_read_unchecked(&fscache_n_cookie_data),
45211 + atomic_read_unchecked(&fscache_n_cookie_special));
45212
45213 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
45214 - atomic_read(&fscache_n_object_alloc),
45215 - atomic_read(&fscache_n_object_no_alloc),
45216 - atomic_read(&fscache_n_object_avail),
45217 - atomic_read(&fscache_n_object_dead));
45218 + atomic_read_unchecked(&fscache_n_object_alloc),
45219 + atomic_read_unchecked(&fscache_n_object_no_alloc),
45220 + atomic_read_unchecked(&fscache_n_object_avail),
45221 + atomic_read_unchecked(&fscache_n_object_dead));
45222 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
45223 - atomic_read(&fscache_n_checkaux_none),
45224 - atomic_read(&fscache_n_checkaux_okay),
45225 - atomic_read(&fscache_n_checkaux_update),
45226 - atomic_read(&fscache_n_checkaux_obsolete));
45227 + atomic_read_unchecked(&fscache_n_checkaux_none),
45228 + atomic_read_unchecked(&fscache_n_checkaux_okay),
45229 + atomic_read_unchecked(&fscache_n_checkaux_update),
45230 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
45231
45232 seq_printf(m, "Pages : mrk=%u unc=%u\n",
45233 - atomic_read(&fscache_n_marks),
45234 - atomic_read(&fscache_n_uncaches));
45235 + atomic_read_unchecked(&fscache_n_marks),
45236 + atomic_read_unchecked(&fscache_n_uncaches));
45237
45238 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
45239 " oom=%u\n",
45240 - atomic_read(&fscache_n_acquires),
45241 - atomic_read(&fscache_n_acquires_null),
45242 - atomic_read(&fscache_n_acquires_no_cache),
45243 - atomic_read(&fscache_n_acquires_ok),
45244 - atomic_read(&fscache_n_acquires_nobufs),
45245 - atomic_read(&fscache_n_acquires_oom));
45246 + atomic_read_unchecked(&fscache_n_acquires),
45247 + atomic_read_unchecked(&fscache_n_acquires_null),
45248 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
45249 + atomic_read_unchecked(&fscache_n_acquires_ok),
45250 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
45251 + atomic_read_unchecked(&fscache_n_acquires_oom));
45252
45253 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
45254 - atomic_read(&fscache_n_object_lookups),
45255 - atomic_read(&fscache_n_object_lookups_negative),
45256 - atomic_read(&fscache_n_object_lookups_positive),
45257 - atomic_read(&fscache_n_object_created),
45258 - atomic_read(&fscache_n_object_lookups_timed_out));
45259 + atomic_read_unchecked(&fscache_n_object_lookups),
45260 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
45261 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
45262 + atomic_read_unchecked(&fscache_n_object_created),
45263 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
45264
45265 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
45266 - atomic_read(&fscache_n_updates),
45267 - atomic_read(&fscache_n_updates_null),
45268 - atomic_read(&fscache_n_updates_run));
45269 + atomic_read_unchecked(&fscache_n_updates),
45270 + atomic_read_unchecked(&fscache_n_updates_null),
45271 + atomic_read_unchecked(&fscache_n_updates_run));
45272
45273 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
45274 - atomic_read(&fscache_n_relinquishes),
45275 - atomic_read(&fscache_n_relinquishes_null),
45276 - atomic_read(&fscache_n_relinquishes_waitcrt),
45277 - atomic_read(&fscache_n_relinquishes_retire));
45278 + atomic_read_unchecked(&fscache_n_relinquishes),
45279 + atomic_read_unchecked(&fscache_n_relinquishes_null),
45280 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
45281 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
45282
45283 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
45284 - atomic_read(&fscache_n_attr_changed),
45285 - atomic_read(&fscache_n_attr_changed_ok),
45286 - atomic_read(&fscache_n_attr_changed_nobufs),
45287 - atomic_read(&fscache_n_attr_changed_nomem),
45288 - atomic_read(&fscache_n_attr_changed_calls));
45289 + atomic_read_unchecked(&fscache_n_attr_changed),
45290 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
45291 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
45292 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
45293 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
45294
45295 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
45296 - atomic_read(&fscache_n_allocs),
45297 - atomic_read(&fscache_n_allocs_ok),
45298 - atomic_read(&fscache_n_allocs_wait),
45299 - atomic_read(&fscache_n_allocs_nobufs),
45300 - atomic_read(&fscache_n_allocs_intr));
45301 + atomic_read_unchecked(&fscache_n_allocs),
45302 + atomic_read_unchecked(&fscache_n_allocs_ok),
45303 + atomic_read_unchecked(&fscache_n_allocs_wait),
45304 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
45305 + atomic_read_unchecked(&fscache_n_allocs_intr));
45306 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
45307 - atomic_read(&fscache_n_alloc_ops),
45308 - atomic_read(&fscache_n_alloc_op_waits),
45309 - atomic_read(&fscache_n_allocs_object_dead));
45310 + atomic_read_unchecked(&fscache_n_alloc_ops),
45311 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
45312 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
45313
45314 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
45315 " int=%u oom=%u\n",
45316 - atomic_read(&fscache_n_retrievals),
45317 - atomic_read(&fscache_n_retrievals_ok),
45318 - atomic_read(&fscache_n_retrievals_wait),
45319 - atomic_read(&fscache_n_retrievals_nodata),
45320 - atomic_read(&fscache_n_retrievals_nobufs),
45321 - atomic_read(&fscache_n_retrievals_intr),
45322 - atomic_read(&fscache_n_retrievals_nomem));
45323 + atomic_read_unchecked(&fscache_n_retrievals),
45324 + atomic_read_unchecked(&fscache_n_retrievals_ok),
45325 + atomic_read_unchecked(&fscache_n_retrievals_wait),
45326 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
45327 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
45328 + atomic_read_unchecked(&fscache_n_retrievals_intr),
45329 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
45330 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
45331 - atomic_read(&fscache_n_retrieval_ops),
45332 - atomic_read(&fscache_n_retrieval_op_waits),
45333 - atomic_read(&fscache_n_retrievals_object_dead));
45334 + atomic_read_unchecked(&fscache_n_retrieval_ops),
45335 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
45336 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
45337
45338 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
45339 - atomic_read(&fscache_n_stores),
45340 - atomic_read(&fscache_n_stores_ok),
45341 - atomic_read(&fscache_n_stores_again),
45342 - atomic_read(&fscache_n_stores_nobufs),
45343 - atomic_read(&fscache_n_stores_oom));
45344 + atomic_read_unchecked(&fscache_n_stores),
45345 + atomic_read_unchecked(&fscache_n_stores_ok),
45346 + atomic_read_unchecked(&fscache_n_stores_again),
45347 + atomic_read_unchecked(&fscache_n_stores_nobufs),
45348 + atomic_read_unchecked(&fscache_n_stores_oom));
45349 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
45350 - atomic_read(&fscache_n_store_ops),
45351 - atomic_read(&fscache_n_store_calls),
45352 - atomic_read(&fscache_n_store_pages),
45353 - atomic_read(&fscache_n_store_radix_deletes),
45354 - atomic_read(&fscache_n_store_pages_over_limit));
45355 + atomic_read_unchecked(&fscache_n_store_ops),
45356 + atomic_read_unchecked(&fscache_n_store_calls),
45357 + atomic_read_unchecked(&fscache_n_store_pages),
45358 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
45359 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
45360
45361 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
45362 - atomic_read(&fscache_n_store_vmscan_not_storing),
45363 - atomic_read(&fscache_n_store_vmscan_gone),
45364 - atomic_read(&fscache_n_store_vmscan_busy),
45365 - atomic_read(&fscache_n_store_vmscan_cancelled));
45366 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
45367 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
45368 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
45369 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
45370
45371 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
45372 - atomic_read(&fscache_n_op_pend),
45373 - atomic_read(&fscache_n_op_run),
45374 - atomic_read(&fscache_n_op_enqueue),
45375 - atomic_read(&fscache_n_op_cancelled),
45376 - atomic_read(&fscache_n_op_rejected));
45377 + atomic_read_unchecked(&fscache_n_op_pend),
45378 + atomic_read_unchecked(&fscache_n_op_run),
45379 + atomic_read_unchecked(&fscache_n_op_enqueue),
45380 + atomic_read_unchecked(&fscache_n_op_cancelled),
45381 + atomic_read_unchecked(&fscache_n_op_rejected));
45382 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
45383 - atomic_read(&fscache_n_op_deferred_release),
45384 - atomic_read(&fscache_n_op_release),
45385 - atomic_read(&fscache_n_op_gc));
45386 + atomic_read_unchecked(&fscache_n_op_deferred_release),
45387 + atomic_read_unchecked(&fscache_n_op_release),
45388 + atomic_read_unchecked(&fscache_n_op_gc));
45389
45390 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
45391 atomic_read(&fscache_n_cop_alloc_object),
45392 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
45393 index 3426521..3b75162 100644
45394 --- a/fs/fuse/cuse.c
45395 +++ b/fs/fuse/cuse.c
45396 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
45397 INIT_LIST_HEAD(&cuse_conntbl[i]);
45398
45399 /* inherit and extend fuse_dev_operations */
45400 - cuse_channel_fops = fuse_dev_operations;
45401 - cuse_channel_fops.owner = THIS_MODULE;
45402 - cuse_channel_fops.open = cuse_channel_open;
45403 - cuse_channel_fops.release = cuse_channel_release;
45404 + pax_open_kernel();
45405 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
45406 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
45407 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
45408 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
45409 + pax_close_kernel();
45410
45411 cuse_class = class_create(THIS_MODULE, "cuse");
45412 if (IS_ERR(cuse_class))
45413 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
45414 index 5f3368a..8306426 100644
45415 --- a/fs/fuse/dev.c
45416 +++ b/fs/fuse/dev.c
45417 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
45418 ret = 0;
45419 pipe_lock(pipe);
45420
45421 - if (!pipe->readers) {
45422 + if (!atomic_read(&pipe->readers)) {
45423 send_sig(SIGPIPE, current, 0);
45424 if (!ret)
45425 ret = -EPIPE;
45426 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
45427 index 2066328..f5add3b 100644
45428 --- a/fs/fuse/dir.c
45429 +++ b/fs/fuse/dir.c
45430 @@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
45431 return link;
45432 }
45433
45434 -static void free_link(char *link)
45435 +static void free_link(const char *link)
45436 {
45437 if (!IS_ERR(link))
45438 free_page((unsigned long) link);
45439 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
45440 index 5698746..6086012 100644
45441 --- a/fs/gfs2/inode.c
45442 +++ b/fs/gfs2/inode.c
45443 @@ -1487,7 +1487,7 @@ out:
45444
45445 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45446 {
45447 - char *s = nd_get_link(nd);
45448 + const char *s = nd_get_link(nd);
45449 if (!IS_ERR(s))
45450 kfree(s);
45451 }
45452 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
45453 index 3645cd3..786809c 100644
45454 --- a/fs/hugetlbfs/inode.c
45455 +++ b/fs/hugetlbfs/inode.c
45456 @@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs_fs_type = {
45457 .kill_sb = kill_litter_super,
45458 };
45459
45460 -static struct vfsmount *hugetlbfs_vfsmount;
45461 +struct vfsmount *hugetlbfs_vfsmount;
45462
45463 static int can_do_hugetlb_shm(void)
45464 {
45465 diff --git a/fs/inode.c b/fs/inode.c
45466 index 83ab215..8842101 100644
45467 --- a/fs/inode.c
45468 +++ b/fs/inode.c
45469 @@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
45470
45471 #ifdef CONFIG_SMP
45472 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
45473 - static atomic_t shared_last_ino;
45474 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
45475 + static atomic_unchecked_t shared_last_ino;
45476 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
45477
45478 res = next - LAST_INO_BATCH;
45479 }
45480 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
45481 index eafb8d3..f423d37 100644
45482 --- a/fs/jffs2/erase.c
45483 +++ b/fs/jffs2/erase.c
45484 @@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
45485 struct jffs2_unknown_node marker = {
45486 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
45487 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
45488 - .totlen = cpu_to_je32(c->cleanmarker_size)
45489 + .totlen = cpu_to_je32(c->cleanmarker_size),
45490 + .hdr_crc = cpu_to_je32(0)
45491 };
45492
45493 jffs2_prealloc_raw_node_refs(c, jeb, 1);
45494 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
45495 index 30e8f47..21f600c 100644
45496 --- a/fs/jffs2/wbuf.c
45497 +++ b/fs/jffs2/wbuf.c
45498 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
45499 {
45500 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
45501 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
45502 - .totlen = constant_cpu_to_je32(8)
45503 + .totlen = constant_cpu_to_je32(8),
45504 + .hdr_crc = constant_cpu_to_je32(0)
45505 };
45506
45507 /*
45508 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
45509 index 682bca6..86b8e6e 100644
45510 --- a/fs/jfs/super.c
45511 +++ b/fs/jfs/super.c
45512 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
45513
45514 jfs_inode_cachep =
45515 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
45516 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
45517 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
45518 init_once);
45519 if (jfs_inode_cachep == NULL)
45520 return -ENOMEM;
45521 diff --git a/fs/libfs.c b/fs/libfs.c
45522 index 5b2dbb3..7442d54 100644
45523 --- a/fs/libfs.c
45524 +++ b/fs/libfs.c
45525 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
45526
45527 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
45528 struct dentry *next;
45529 + char d_name[sizeof(next->d_iname)];
45530 + const unsigned char *name;
45531 +
45532 next = list_entry(p, struct dentry, d_u.d_child);
45533 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
45534 if (!simple_positive(next)) {
45535 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
45536
45537 spin_unlock(&next->d_lock);
45538 spin_unlock(&dentry->d_lock);
45539 - if (filldir(dirent, next->d_name.name,
45540 + name = next->d_name.name;
45541 + if (name == next->d_iname) {
45542 + memcpy(d_name, name, next->d_name.len);
45543 + name = d_name;
45544 + }
45545 + if (filldir(dirent, name,
45546 next->d_name.len, filp->f_pos,
45547 next->d_inode->i_ino,
45548 dt_type(next->d_inode)) < 0)
45549 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
45550 index 8392cb8..80d6193 100644
45551 --- a/fs/lockd/clntproc.c
45552 +++ b/fs/lockd/clntproc.c
45553 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
45554 /*
45555 * Cookie counter for NLM requests
45556 */
45557 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
45558 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
45559
45560 void nlmclnt_next_cookie(struct nlm_cookie *c)
45561 {
45562 - u32 cookie = atomic_inc_return(&nlm_cookie);
45563 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
45564
45565 memcpy(c->data, &cookie, 4);
45566 c->len=4;
45567 diff --git a/fs/locks.c b/fs/locks.c
45568 index 637694b..f84a121 100644
45569 --- a/fs/locks.c
45570 +++ b/fs/locks.c
45571 @@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
45572 return;
45573
45574 if (filp->f_op && filp->f_op->flock) {
45575 - struct file_lock fl = {
45576 + struct file_lock flock = {
45577 .fl_pid = current->tgid,
45578 .fl_file = filp,
45579 .fl_flags = FL_FLOCK,
45580 .fl_type = F_UNLCK,
45581 .fl_end = OFFSET_MAX,
45582 };
45583 - filp->f_op->flock(filp, F_SETLKW, &fl);
45584 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
45585 - fl.fl_ops->fl_release_private(&fl);
45586 + filp->f_op->flock(filp, F_SETLKW, &flock);
45587 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
45588 + flock.fl_ops->fl_release_private(&flock);
45589 }
45590
45591 lock_flocks();
45592 diff --git a/fs/namei.c b/fs/namei.c
45593 index 46ea9cc..c7cf3a3 100644
45594 --- a/fs/namei.c
45595 +++ b/fs/namei.c
45596 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
45597 if (ret != -EACCES)
45598 return ret;
45599
45600 +#ifdef CONFIG_GRKERNSEC
45601 + /* we'll block if we have to log due to a denied capability use */
45602 + if (mask & MAY_NOT_BLOCK)
45603 + return -ECHILD;
45604 +#endif
45605 +
45606 if (S_ISDIR(inode->i_mode)) {
45607 /* DACs are overridable for directories */
45608 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45609 - return 0;
45610 if (!(mask & MAY_WRITE))
45611 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45612 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
45613 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45614 return 0;
45615 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45616 + return 0;
45617 return -EACCES;
45618 }
45619 /*
45620 + * Searching includes executable on directories, else just read.
45621 + */
45622 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
45623 + if (mask == MAY_READ)
45624 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
45625 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45626 + return 0;
45627 +
45628 + /*
45629 * Read/write DACs are always overridable.
45630 * Executable DACs are overridable when there is
45631 * at least one exec bit set.
45632 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
45633 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45634 return 0;
45635
45636 - /*
45637 - * Searching includes executable on directories, else just read.
45638 - */
45639 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
45640 - if (mask == MAY_READ)
45641 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45642 - return 0;
45643 -
45644 return -EACCES;
45645 }
45646
45647 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
45648 return error;
45649 }
45650
45651 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
45652 + dentry->d_inode, dentry, nd->path.mnt)) {
45653 + error = -EACCES;
45654 + *p = ERR_PTR(error); /* no ->put_link(), please */
45655 + path_put(&nd->path);
45656 + return error;
45657 + }
45658 +
45659 nd->last_type = LAST_BIND;
45660 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
45661 error = PTR_ERR(*p);
45662 if (!IS_ERR(*p)) {
45663 - char *s = nd_get_link(nd);
45664 + const char *s = nd_get_link(nd);
45665 error = 0;
45666 if (s)
45667 error = __vfs_follow_link(nd, s);
45668 @@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
45669 if (!err)
45670 err = complete_walk(nd);
45671
45672 + if (!(nd->flags & LOOKUP_PARENT)) {
45673 +#ifdef CONFIG_GRKERNSEC
45674 + if (flags & LOOKUP_RCU) {
45675 + if (!err)
45676 + path_put(&nd->path);
45677 + err = -ECHILD;
45678 + } else
45679 +#endif
45680 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45681 + if (!err)
45682 + path_put(&nd->path);
45683 + err = -ENOENT;
45684 + }
45685 + }
45686 +
45687 if (!err && nd->flags & LOOKUP_DIRECTORY) {
45688 if (!nd->inode->i_op->lookup) {
45689 path_put(&nd->path);
45690 @@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
45691 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
45692
45693 if (likely(!retval)) {
45694 + if (*name != '/' && nd->path.dentry && nd->inode) {
45695 +#ifdef CONFIG_GRKERNSEC
45696 + if (flags & LOOKUP_RCU)
45697 + return -ECHILD;
45698 +#endif
45699 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
45700 + return -ENOENT;
45701 + }
45702 +
45703 if (unlikely(!audit_dummy_context())) {
45704 if (nd->path.dentry && nd->inode)
45705 audit_inode(name, nd->path.dentry);
45706 @@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
45707 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
45708 return -EPERM;
45709
45710 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
45711 + return -EPERM;
45712 + if (gr_handle_rawio(inode))
45713 + return -EPERM;
45714 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
45715 + return -EACCES;
45716 +
45717 return 0;
45718 }
45719
45720 @@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45721 error = complete_walk(nd);
45722 if (error)
45723 return ERR_PTR(error);
45724 +#ifdef CONFIG_GRKERNSEC
45725 + if (nd->flags & LOOKUP_RCU) {
45726 + error = -ECHILD;
45727 + goto exit;
45728 + }
45729 +#endif
45730 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45731 + error = -ENOENT;
45732 + goto exit;
45733 + }
45734 audit_inode(pathname, nd->path.dentry);
45735 if (open_flag & O_CREAT) {
45736 error = -EISDIR;
45737 @@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45738 error = complete_walk(nd);
45739 if (error)
45740 return ERR_PTR(error);
45741 +#ifdef CONFIG_GRKERNSEC
45742 + if (nd->flags & LOOKUP_RCU) {
45743 + error = -ECHILD;
45744 + goto exit;
45745 + }
45746 +#endif
45747 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
45748 + error = -ENOENT;
45749 + goto exit;
45750 + }
45751 audit_inode(pathname, dir);
45752 goto ok;
45753 }
45754 @@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45755 error = complete_walk(nd);
45756 if (error)
45757 return ERR_PTR(error);
45758 +#ifdef CONFIG_GRKERNSEC
45759 + if (nd->flags & LOOKUP_RCU) {
45760 + error = -ECHILD;
45761 + goto exit;
45762 + }
45763 +#endif
45764 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45765 + error = -ENOENT;
45766 + goto exit;
45767 + }
45768
45769 error = -ENOTDIR;
45770 if (nd->flags & LOOKUP_DIRECTORY) {
45771 @@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45772 /* Negative dentry, just create the file */
45773 if (!dentry->d_inode) {
45774 umode_t mode = op->mode;
45775 +
45776 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
45777 + error = -EACCES;
45778 + goto exit_mutex_unlock;
45779 + }
45780 +
45781 if (!IS_POSIXACL(dir->d_inode))
45782 mode &= ~current_umask();
45783 /*
45784 @@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45785 error = vfs_create(dir->d_inode, dentry, mode, nd);
45786 if (error)
45787 goto exit_mutex_unlock;
45788 + else
45789 + gr_handle_create(path->dentry, path->mnt);
45790 mutex_unlock(&dir->d_inode->i_mutex);
45791 dput(nd->path.dentry);
45792 nd->path.dentry = dentry;
45793 @@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45794 /*
45795 * It already exists.
45796 */
45797 +
45798 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
45799 + error = -ENOENT;
45800 + goto exit_mutex_unlock;
45801 + }
45802 +
45803 + /* only check if O_CREAT is specified, all other checks need to go
45804 + into may_open */
45805 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
45806 + error = -EACCES;
45807 + goto exit_mutex_unlock;
45808 + }
45809 +
45810 mutex_unlock(&dir->d_inode->i_mutex);
45811 audit_inode(pathname, path->dentry);
45812
45813 @@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
45814 *path = nd.path;
45815 return dentry;
45816 eexist:
45817 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
45818 + dput(dentry);
45819 + dentry = ERR_PTR(-ENOENT);
45820 + goto fail;
45821 + }
45822 dput(dentry);
45823 dentry = ERR_PTR(-EEXIST);
45824 fail:
45825 @@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
45826 }
45827 EXPORT_SYMBOL(user_path_create);
45828
45829 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
45830 +{
45831 + char *tmp = getname(pathname);
45832 + struct dentry *res;
45833 + if (IS_ERR(tmp))
45834 + return ERR_CAST(tmp);
45835 + res = kern_path_create(dfd, tmp, path, is_dir);
45836 + if (IS_ERR(res))
45837 + putname(tmp);
45838 + else
45839 + *to = tmp;
45840 + return res;
45841 +}
45842 +
45843 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
45844 {
45845 int error = may_create(dir, dentry);
45846 @@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
45847 error = mnt_want_write(path.mnt);
45848 if (error)
45849 goto out_dput;
45850 +
45851 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
45852 + error = -EPERM;
45853 + goto out_drop_write;
45854 + }
45855 +
45856 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
45857 + error = -EACCES;
45858 + goto out_drop_write;
45859 + }
45860 +
45861 error = security_path_mknod(&path, dentry, mode, dev);
45862 if (error)
45863 goto out_drop_write;
45864 @@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
45865 }
45866 out_drop_write:
45867 mnt_drop_write(path.mnt);
45868 +
45869 + if (!error)
45870 + gr_handle_create(dentry, path.mnt);
45871 out_dput:
45872 dput(dentry);
45873 mutex_unlock(&path.dentry->d_inode->i_mutex);
45874 @@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
45875 error = mnt_want_write(path.mnt);
45876 if (error)
45877 goto out_dput;
45878 +
45879 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
45880 + error = -EACCES;
45881 + goto out_drop_write;
45882 + }
45883 +
45884 error = security_path_mkdir(&path, dentry, mode);
45885 if (error)
45886 goto out_drop_write;
45887 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
45888 out_drop_write:
45889 mnt_drop_write(path.mnt);
45890 +
45891 + if (!error)
45892 + gr_handle_create(dentry, path.mnt);
45893 out_dput:
45894 dput(dentry);
45895 mutex_unlock(&path.dentry->d_inode->i_mutex);
45896 @@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
45897 char * name;
45898 struct dentry *dentry;
45899 struct nameidata nd;
45900 + ino_t saved_ino = 0;
45901 + dev_t saved_dev = 0;
45902
45903 error = user_path_parent(dfd, pathname, &nd, &name);
45904 if (error)
45905 @@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
45906 error = -ENOENT;
45907 goto exit3;
45908 }
45909 +
45910 + saved_ino = dentry->d_inode->i_ino;
45911 + saved_dev = gr_get_dev_from_dentry(dentry);
45912 +
45913 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
45914 + error = -EACCES;
45915 + goto exit3;
45916 + }
45917 +
45918 error = mnt_want_write(nd.path.mnt);
45919 if (error)
45920 goto exit3;
45921 @@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
45922 if (error)
45923 goto exit4;
45924 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
45925 + if (!error && (saved_dev || saved_ino))
45926 + gr_handle_delete(saved_ino, saved_dev);
45927 exit4:
45928 mnt_drop_write(nd.path.mnt);
45929 exit3:
45930 @@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
45931 struct dentry *dentry;
45932 struct nameidata nd;
45933 struct inode *inode = NULL;
45934 + ino_t saved_ino = 0;
45935 + dev_t saved_dev = 0;
45936
45937 error = user_path_parent(dfd, pathname, &nd, &name);
45938 if (error)
45939 @@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
45940 if (!inode)
45941 goto slashes;
45942 ihold(inode);
45943 +
45944 + if (inode->i_nlink <= 1) {
45945 + saved_ino = inode->i_ino;
45946 + saved_dev = gr_get_dev_from_dentry(dentry);
45947 + }
45948 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
45949 + error = -EACCES;
45950 + goto exit2;
45951 + }
45952 +
45953 error = mnt_want_write(nd.path.mnt);
45954 if (error)
45955 goto exit2;
45956 @@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
45957 if (error)
45958 goto exit3;
45959 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
45960 + if (!error && (saved_ino || saved_dev))
45961 + gr_handle_delete(saved_ino, saved_dev);
45962 exit3:
45963 mnt_drop_write(nd.path.mnt);
45964 exit2:
45965 @@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
45966 error = mnt_want_write(path.mnt);
45967 if (error)
45968 goto out_dput;
45969 +
45970 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
45971 + error = -EACCES;
45972 + goto out_drop_write;
45973 + }
45974 +
45975 error = security_path_symlink(&path, dentry, from);
45976 if (error)
45977 goto out_drop_write;
45978 error = vfs_symlink(path.dentry->d_inode, dentry, from);
45979 + if (!error)
45980 + gr_handle_create(dentry, path.mnt);
45981 out_drop_write:
45982 mnt_drop_write(path.mnt);
45983 out_dput:
45984 @@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
45985 {
45986 struct dentry *new_dentry;
45987 struct path old_path, new_path;
45988 + char *to = NULL;
45989 int how = 0;
45990 int error;
45991
45992 @@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
45993 if (error)
45994 return error;
45995
45996 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
45997 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
45998 error = PTR_ERR(new_dentry);
45999 if (IS_ERR(new_dentry))
46000 goto out;
46001 @@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46002 error = mnt_want_write(new_path.mnt);
46003 if (error)
46004 goto out_dput;
46005 +
46006 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
46007 + old_path.dentry->d_inode,
46008 + old_path.dentry->d_inode->i_mode, to)) {
46009 + error = -EACCES;
46010 + goto out_drop_write;
46011 + }
46012 +
46013 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
46014 + old_path.dentry, old_path.mnt, to)) {
46015 + error = -EACCES;
46016 + goto out_drop_write;
46017 + }
46018 +
46019 error = security_path_link(old_path.dentry, &new_path, new_dentry);
46020 if (error)
46021 goto out_drop_write;
46022 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
46023 + if (!error)
46024 + gr_handle_create(new_dentry, new_path.mnt);
46025 out_drop_write:
46026 mnt_drop_write(new_path.mnt);
46027 out_dput:
46028 + putname(to);
46029 dput(new_dentry);
46030 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
46031 path_put(&new_path);
46032 @@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46033 if (new_dentry == trap)
46034 goto exit5;
46035
46036 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
46037 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
46038 + to);
46039 + if (error)
46040 + goto exit5;
46041 +
46042 error = mnt_want_write(oldnd.path.mnt);
46043 if (error)
46044 goto exit5;
46045 @@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46046 goto exit6;
46047 error = vfs_rename(old_dir->d_inode, old_dentry,
46048 new_dir->d_inode, new_dentry);
46049 + if (!error)
46050 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
46051 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
46052 exit6:
46053 mnt_drop_write(oldnd.path.mnt);
46054 exit5:
46055 @@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46056
46057 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46058 {
46059 + char tmpbuf[64];
46060 + const char *newlink;
46061 int len;
46062
46063 len = PTR_ERR(link);
46064 @@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46065 len = strlen(link);
46066 if (len > (unsigned) buflen)
46067 len = buflen;
46068 - if (copy_to_user(buffer, link, len))
46069 +
46070 + if (len < sizeof(tmpbuf)) {
46071 + memcpy(tmpbuf, link, len);
46072 + newlink = tmpbuf;
46073 + } else
46074 + newlink = link;
46075 +
46076 + if (copy_to_user(buffer, newlink, len))
46077 len = -EFAULT;
46078 out:
46079 return len;
46080 diff --git a/fs/namespace.c b/fs/namespace.c
46081 index e608199..9609cb9 100644
46082 --- a/fs/namespace.c
46083 +++ b/fs/namespace.c
46084 @@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
46085 if (!(sb->s_flags & MS_RDONLY))
46086 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46087 up_write(&sb->s_umount);
46088 +
46089 + gr_log_remount(mnt->mnt_devname, retval);
46090 +
46091 return retval;
46092 }
46093
46094 @@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
46095 br_write_unlock(vfsmount_lock);
46096 up_write(&namespace_sem);
46097 release_mounts(&umount_list);
46098 +
46099 + gr_log_unmount(mnt->mnt_devname, retval);
46100 +
46101 return retval;
46102 }
46103
46104 @@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46105 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
46106 MS_STRICTATIME);
46107
46108 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
46109 + retval = -EPERM;
46110 + goto dput_out;
46111 + }
46112 +
46113 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
46114 + retval = -EPERM;
46115 + goto dput_out;
46116 + }
46117 +
46118 if (flags & MS_REMOUNT)
46119 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
46120 data_page);
46121 @@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46122 dev_name, data_page);
46123 dput_out:
46124 path_put(&path);
46125 +
46126 + gr_log_mount(dev_name, dir_name, retval);
46127 +
46128 return retval;
46129 }
46130
46131 @@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
46132 if (error)
46133 goto out2;
46134
46135 + if (gr_handle_chroot_pivot()) {
46136 + error = -EPERM;
46137 + goto out2;
46138 + }
46139 +
46140 get_fs_root(current->fs, &root);
46141 error = lock_mount(&old);
46142 if (error)
46143 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
46144 index f649fba..236bf92 100644
46145 --- a/fs/nfs/inode.c
46146 +++ b/fs/nfs/inode.c
46147 @@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
46148 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
46149 nfsi->attrtimeo_timestamp = jiffies;
46150
46151 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
46152 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
46153 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
46154 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
46155 else
46156 @@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
46157 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
46158 }
46159
46160 -static atomic_long_t nfs_attr_generation_counter;
46161 +static atomic_long_unchecked_t nfs_attr_generation_counter;
46162
46163 static unsigned long nfs_read_attr_generation_counter(void)
46164 {
46165 - return atomic_long_read(&nfs_attr_generation_counter);
46166 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
46167 }
46168
46169 unsigned long nfs_inc_attr_generation_counter(void)
46170 {
46171 - return atomic_long_inc_return(&nfs_attr_generation_counter);
46172 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
46173 }
46174
46175 void nfs_fattr_init(struct nfs_fattr *fattr)
46176 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
46177 index edf6d3e..bdd1da7 100644
46178 --- a/fs/nfsd/vfs.c
46179 +++ b/fs/nfsd/vfs.c
46180 @@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46181 } else {
46182 oldfs = get_fs();
46183 set_fs(KERNEL_DS);
46184 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
46185 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
46186 set_fs(oldfs);
46187 }
46188
46189 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46190
46191 /* Write the data. */
46192 oldfs = get_fs(); set_fs(KERNEL_DS);
46193 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
46194 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
46195 set_fs(oldfs);
46196 if (host_err < 0)
46197 goto out_nfserr;
46198 @@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
46199 */
46200
46201 oldfs = get_fs(); set_fs(KERNEL_DS);
46202 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
46203 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
46204 set_fs(oldfs);
46205
46206 if (host_err < 0)
46207 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
46208 index 3568c8a..e0240d8 100644
46209 --- a/fs/notify/fanotify/fanotify_user.c
46210 +++ b/fs/notify/fanotify/fanotify_user.c
46211 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
46212 goto out_close_fd;
46213
46214 ret = -EFAULT;
46215 - if (copy_to_user(buf, &fanotify_event_metadata,
46216 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
46217 + copy_to_user(buf, &fanotify_event_metadata,
46218 fanotify_event_metadata.event_len))
46219 goto out_kill_access_response;
46220
46221 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
46222 index ee18815..7aa5d01 100644
46223 --- a/fs/notify/notification.c
46224 +++ b/fs/notify/notification.c
46225 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
46226 * get set to 0 so it will never get 'freed'
46227 */
46228 static struct fsnotify_event *q_overflow_event;
46229 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46230 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46231
46232 /**
46233 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
46234 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46235 */
46236 u32 fsnotify_get_cookie(void)
46237 {
46238 - return atomic_inc_return(&fsnotify_sync_cookie);
46239 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
46240 }
46241 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
46242
46243 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
46244 index 99e3610..02c1068 100644
46245 --- a/fs/ntfs/dir.c
46246 +++ b/fs/ntfs/dir.c
46247 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
46248 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
46249 ~(s64)(ndir->itype.index.block_size - 1)));
46250 /* Bounds checks. */
46251 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46252 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46253 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
46254 "inode 0x%lx or driver bug.", vdir->i_ino);
46255 goto err_out;
46256 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
46257 index c587e2d..3641eaa 100644
46258 --- a/fs/ntfs/file.c
46259 +++ b/fs/ntfs/file.c
46260 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
46261 #endif /* NTFS_RW */
46262 };
46263
46264 -const struct file_operations ntfs_empty_file_ops = {};
46265 +const struct file_operations ntfs_empty_file_ops __read_only;
46266
46267 -const struct inode_operations ntfs_empty_inode_ops = {};
46268 +const struct inode_operations ntfs_empty_inode_ops __read_only;
46269 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
46270 index 210c352..a174f83 100644
46271 --- a/fs/ocfs2/localalloc.c
46272 +++ b/fs/ocfs2/localalloc.c
46273 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
46274 goto bail;
46275 }
46276
46277 - atomic_inc(&osb->alloc_stats.moves);
46278 + atomic_inc_unchecked(&osb->alloc_stats.moves);
46279
46280 bail:
46281 if (handle)
46282 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
46283 index d355e6e..578d905 100644
46284 --- a/fs/ocfs2/ocfs2.h
46285 +++ b/fs/ocfs2/ocfs2.h
46286 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
46287
46288 struct ocfs2_alloc_stats
46289 {
46290 - atomic_t moves;
46291 - atomic_t local_data;
46292 - atomic_t bitmap_data;
46293 - atomic_t bg_allocs;
46294 - atomic_t bg_extends;
46295 + atomic_unchecked_t moves;
46296 + atomic_unchecked_t local_data;
46297 + atomic_unchecked_t bitmap_data;
46298 + atomic_unchecked_t bg_allocs;
46299 + atomic_unchecked_t bg_extends;
46300 };
46301
46302 enum ocfs2_local_alloc_state
46303 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
46304 index ba5d97e..c77db25 100644
46305 --- a/fs/ocfs2/suballoc.c
46306 +++ b/fs/ocfs2/suballoc.c
46307 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
46308 mlog_errno(status);
46309 goto bail;
46310 }
46311 - atomic_inc(&osb->alloc_stats.bg_extends);
46312 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
46313
46314 /* You should never ask for this much metadata */
46315 BUG_ON(bits_wanted >
46316 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
46317 mlog_errno(status);
46318 goto bail;
46319 }
46320 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46321 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46322
46323 *suballoc_loc = res.sr_bg_blkno;
46324 *suballoc_bit_start = res.sr_bit_offset;
46325 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
46326 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
46327 res->sr_bits);
46328
46329 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46330 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46331
46332 BUG_ON(res->sr_bits != 1);
46333
46334 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
46335 mlog_errno(status);
46336 goto bail;
46337 }
46338 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46339 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46340
46341 BUG_ON(res.sr_bits != 1);
46342
46343 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46344 cluster_start,
46345 num_clusters);
46346 if (!status)
46347 - atomic_inc(&osb->alloc_stats.local_data);
46348 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
46349 } else {
46350 if (min_clusters > (osb->bitmap_cpg - 1)) {
46351 /* The only paths asking for contiguousness
46352 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46353 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
46354 res.sr_bg_blkno,
46355 res.sr_bit_offset);
46356 - atomic_inc(&osb->alloc_stats.bitmap_data);
46357 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
46358 *num_clusters = res.sr_bits;
46359 }
46360 }
46361 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
46362 index 604e12c..8426483 100644
46363 --- a/fs/ocfs2/super.c
46364 +++ b/fs/ocfs2/super.c
46365 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
46366 "%10s => GlobalAllocs: %d LocalAllocs: %d "
46367 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
46368 "Stats",
46369 - atomic_read(&osb->alloc_stats.bitmap_data),
46370 - atomic_read(&osb->alloc_stats.local_data),
46371 - atomic_read(&osb->alloc_stats.bg_allocs),
46372 - atomic_read(&osb->alloc_stats.moves),
46373 - atomic_read(&osb->alloc_stats.bg_extends));
46374 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
46375 + atomic_read_unchecked(&osb->alloc_stats.local_data),
46376 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
46377 + atomic_read_unchecked(&osb->alloc_stats.moves),
46378 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
46379
46380 out += snprintf(buf + out, len - out,
46381 "%10s => State: %u Descriptor: %llu Size: %u bits "
46382 @@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
46383 spin_lock_init(&osb->osb_xattr_lock);
46384 ocfs2_init_steal_slots(osb);
46385
46386 - atomic_set(&osb->alloc_stats.moves, 0);
46387 - atomic_set(&osb->alloc_stats.local_data, 0);
46388 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
46389 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
46390 - atomic_set(&osb->alloc_stats.bg_extends, 0);
46391 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
46392 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
46393 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
46394 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
46395 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
46396
46397 /* Copy the blockcheck stats from the superblock probe */
46398 osb->osb_ecc_stats = *stats;
46399 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
46400 index 5d22872..523db20 100644
46401 --- a/fs/ocfs2/symlink.c
46402 +++ b/fs/ocfs2/symlink.c
46403 @@ -142,7 +142,7 @@ bail:
46404
46405 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
46406 {
46407 - char *link = nd_get_link(nd);
46408 + const char *link = nd_get_link(nd);
46409 if (!IS_ERR(link))
46410 kfree(link);
46411 }
46412 diff --git a/fs/open.c b/fs/open.c
46413 index 77becc0..aad7bd9 100644
46414 --- a/fs/open.c
46415 +++ b/fs/open.c
46416 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
46417 error = locks_verify_truncate(inode, NULL, length);
46418 if (!error)
46419 error = security_path_truncate(&path);
46420 +
46421 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
46422 + error = -EACCES;
46423 +
46424 if (!error)
46425 error = do_truncate(path.dentry, length, 0, NULL);
46426
46427 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
46428 if (__mnt_is_readonly(path.mnt))
46429 res = -EROFS;
46430
46431 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
46432 + res = -EACCES;
46433 +
46434 out_path_release:
46435 path_put(&path);
46436 out:
46437 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
46438 if (error)
46439 goto dput_and_out;
46440
46441 + gr_log_chdir(path.dentry, path.mnt);
46442 +
46443 set_fs_pwd(current->fs, &path);
46444
46445 dput_and_out:
46446 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
46447 goto out_putf;
46448
46449 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
46450 +
46451 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
46452 + error = -EPERM;
46453 +
46454 + if (!error)
46455 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
46456 +
46457 if (!error)
46458 set_fs_pwd(current->fs, &file->f_path);
46459 out_putf:
46460 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
46461 if (error)
46462 goto dput_and_out;
46463
46464 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
46465 + goto dput_and_out;
46466 +
46467 set_fs_root(current->fs, &path);
46468 +
46469 + gr_handle_chroot_chdir(&path);
46470 +
46471 error = 0;
46472 dput_and_out:
46473 path_put(&path);
46474 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
46475 if (error)
46476 return error;
46477 mutex_lock(&inode->i_mutex);
46478 +
46479 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
46480 + error = -EACCES;
46481 + goto out_unlock;
46482 + }
46483 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
46484 + error = -EACCES;
46485 + goto out_unlock;
46486 + }
46487 +
46488 error = security_path_chmod(path, mode);
46489 if (error)
46490 goto out_unlock;
46491 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
46492 int error;
46493 struct iattr newattrs;
46494
46495 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
46496 + return -EACCES;
46497 +
46498 newattrs.ia_valid = ATTR_CTIME;
46499 if (user != (uid_t) -1) {
46500 newattrs.ia_valid |= ATTR_UID;
46501 diff --git a/fs/pipe.c b/fs/pipe.c
46502 index a932ced..6495412 100644
46503 --- a/fs/pipe.c
46504 +++ b/fs/pipe.c
46505 @@ -420,9 +420,9 @@ redo:
46506 }
46507 if (bufs) /* More to do? */
46508 continue;
46509 - if (!pipe->writers)
46510 + if (!atomic_read(&pipe->writers))
46511 break;
46512 - if (!pipe->waiting_writers) {
46513 + if (!atomic_read(&pipe->waiting_writers)) {
46514 /* syscall merging: Usually we must not sleep
46515 * if O_NONBLOCK is set, or if we got some data.
46516 * But if a writer sleeps in kernel space, then
46517 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
46518 mutex_lock(&inode->i_mutex);
46519 pipe = inode->i_pipe;
46520
46521 - if (!pipe->readers) {
46522 + if (!atomic_read(&pipe->readers)) {
46523 send_sig(SIGPIPE, current, 0);
46524 ret = -EPIPE;
46525 goto out;
46526 @@ -530,7 +530,7 @@ redo1:
46527 for (;;) {
46528 int bufs;
46529
46530 - if (!pipe->readers) {
46531 + if (!atomic_read(&pipe->readers)) {
46532 send_sig(SIGPIPE, current, 0);
46533 if (!ret)
46534 ret = -EPIPE;
46535 @@ -616,9 +616,9 @@ redo2:
46536 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46537 do_wakeup = 0;
46538 }
46539 - pipe->waiting_writers++;
46540 + atomic_inc(&pipe->waiting_writers);
46541 pipe_wait(pipe);
46542 - pipe->waiting_writers--;
46543 + atomic_dec(&pipe->waiting_writers);
46544 }
46545 out:
46546 mutex_unlock(&inode->i_mutex);
46547 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
46548 mask = 0;
46549 if (filp->f_mode & FMODE_READ) {
46550 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
46551 - if (!pipe->writers && filp->f_version != pipe->w_counter)
46552 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
46553 mask |= POLLHUP;
46554 }
46555
46556 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
46557 * Most Unices do not set POLLERR for FIFOs but on Linux they
46558 * behave exactly like pipes for poll().
46559 */
46560 - if (!pipe->readers)
46561 + if (!atomic_read(&pipe->readers))
46562 mask |= POLLERR;
46563 }
46564
46565 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
46566
46567 mutex_lock(&inode->i_mutex);
46568 pipe = inode->i_pipe;
46569 - pipe->readers -= decr;
46570 - pipe->writers -= decw;
46571 + atomic_sub(decr, &pipe->readers);
46572 + atomic_sub(decw, &pipe->writers);
46573
46574 - if (!pipe->readers && !pipe->writers) {
46575 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
46576 free_pipe_info(inode);
46577 } else {
46578 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
46579 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
46580
46581 if (inode->i_pipe) {
46582 ret = 0;
46583 - inode->i_pipe->readers++;
46584 + atomic_inc(&inode->i_pipe->readers);
46585 }
46586
46587 mutex_unlock(&inode->i_mutex);
46588 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
46589
46590 if (inode->i_pipe) {
46591 ret = 0;
46592 - inode->i_pipe->writers++;
46593 + atomic_inc(&inode->i_pipe->writers);
46594 }
46595
46596 mutex_unlock(&inode->i_mutex);
46597 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
46598 if (inode->i_pipe) {
46599 ret = 0;
46600 if (filp->f_mode & FMODE_READ)
46601 - inode->i_pipe->readers++;
46602 + atomic_inc(&inode->i_pipe->readers);
46603 if (filp->f_mode & FMODE_WRITE)
46604 - inode->i_pipe->writers++;
46605 + atomic_inc(&inode->i_pipe->writers);
46606 }
46607
46608 mutex_unlock(&inode->i_mutex);
46609 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
46610 inode->i_pipe = NULL;
46611 }
46612
46613 -static struct vfsmount *pipe_mnt __read_mostly;
46614 +struct vfsmount *pipe_mnt __read_mostly;
46615
46616 /*
46617 * pipefs_dname() is called from d_path().
46618 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
46619 goto fail_iput;
46620 inode->i_pipe = pipe;
46621
46622 - pipe->readers = pipe->writers = 1;
46623 + atomic_set(&pipe->readers, 1);
46624 + atomic_set(&pipe->writers, 1);
46625 inode->i_fop = &rdwr_pipefifo_fops;
46626
46627 /*
46628 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
46629 index 15af622..0e9f4467 100644
46630 --- a/fs/proc/Kconfig
46631 +++ b/fs/proc/Kconfig
46632 @@ -30,12 +30,12 @@ config PROC_FS
46633
46634 config PROC_KCORE
46635 bool "/proc/kcore support" if !ARM
46636 - depends on PROC_FS && MMU
46637 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
46638
46639 config PROC_VMCORE
46640 bool "/proc/vmcore support"
46641 - depends on PROC_FS && CRASH_DUMP
46642 - default y
46643 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
46644 + default n
46645 help
46646 Exports the dump image of crashed kernel in ELF format.
46647
46648 @@ -59,8 +59,8 @@ config PROC_SYSCTL
46649 limited in memory.
46650
46651 config PROC_PAGE_MONITOR
46652 - default y
46653 - depends on PROC_FS && MMU
46654 + default n
46655 + depends on PROC_FS && MMU && !GRKERNSEC
46656 bool "Enable /proc page monitoring" if EXPERT
46657 help
46658 Various /proc files exist to monitor process memory utilization:
46659 diff --git a/fs/proc/array.c b/fs/proc/array.c
46660 index c602b8d..a7de642 100644
46661 --- a/fs/proc/array.c
46662 +++ b/fs/proc/array.c
46663 @@ -60,6 +60,7 @@
46664 #include <linux/tty.h>
46665 #include <linux/string.h>
46666 #include <linux/mman.h>
46667 +#include <linux/grsecurity.h>
46668 #include <linux/proc_fs.h>
46669 #include <linux/ioport.h>
46670 #include <linux/uaccess.h>
46671 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
46672 seq_putc(m, '\n');
46673 }
46674
46675 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46676 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
46677 +{
46678 + if (p->mm)
46679 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
46680 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
46681 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
46682 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
46683 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
46684 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
46685 + else
46686 + seq_printf(m, "PaX:\t-----\n");
46687 +}
46688 +#endif
46689 +
46690 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46691 struct pid *pid, struct task_struct *task)
46692 {
46693 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46694 task_cpus_allowed(m, task);
46695 cpuset_task_status_allowed(m, task);
46696 task_context_switch_counts(m, task);
46697 +
46698 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46699 + task_pax(m, task);
46700 +#endif
46701 +
46702 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
46703 + task_grsec_rbac(m, task);
46704 +#endif
46705 +
46706 return 0;
46707 }
46708
46709 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46710 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46711 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
46712 + _mm->pax_flags & MF_PAX_SEGMEXEC))
46713 +#endif
46714 +
46715 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46716 struct pid *pid, struct task_struct *task, int whole)
46717 {
46718 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46719 char tcomm[sizeof(task->comm)];
46720 unsigned long flags;
46721
46722 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46723 + if (current->exec_id != m->exec_id) {
46724 + gr_log_badprocpid("stat");
46725 + return 0;
46726 + }
46727 +#endif
46728 +
46729 state = *get_task_state(task);
46730 vsize = eip = esp = 0;
46731 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
46732 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46733 gtime = task->gtime;
46734 }
46735
46736 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46737 + if (PAX_RAND_FLAGS(mm)) {
46738 + eip = 0;
46739 + esp = 0;
46740 + wchan = 0;
46741 + }
46742 +#endif
46743 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46744 + wchan = 0;
46745 + eip =0;
46746 + esp =0;
46747 +#endif
46748 +
46749 /* scale priority and nice values from timeslices to -20..20 */
46750 /* to make it look like a "normal" Unix priority/nice value */
46751 priority = task_prio(task);
46752 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46753 vsize,
46754 mm ? get_mm_rss(mm) : 0,
46755 rsslim,
46756 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46757 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
46758 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
46759 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
46760 +#else
46761 mm ? (permitted ? mm->start_code : 1) : 0,
46762 mm ? (permitted ? mm->end_code : 1) : 0,
46763 (permitted && mm) ? mm->start_stack : 0,
46764 +#endif
46765 esp,
46766 eip,
46767 /* The signal information here is obsolete.
46768 @@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46769 struct pid *pid, struct task_struct *task)
46770 {
46771 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
46772 - struct mm_struct *mm = get_task_mm(task);
46773 + struct mm_struct *mm;
46774
46775 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46776 + if (current->exec_id != m->exec_id) {
46777 + gr_log_badprocpid("statm");
46778 + return 0;
46779 + }
46780 +#endif
46781 + mm = get_task_mm(task);
46782 if (mm) {
46783 size = task_statm(mm, &shared, &text, &data, &resident);
46784 mmput(mm);
46785 @@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46786
46787 return 0;
46788 }
46789 +
46790 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
46791 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
46792 +{
46793 + u32 curr_ip = 0;
46794 + unsigned long flags;
46795 +
46796 + if (lock_task_sighand(task, &flags)) {
46797 + curr_ip = task->signal->curr_ip;
46798 + unlock_task_sighand(task, &flags);
46799 + }
46800 +
46801 + return sprintf(buffer, "%pI4\n", &curr_ip);
46802 +}
46803 +#endif
46804 diff --git a/fs/proc/base.c b/fs/proc/base.c
46805 index d4548dd..d101f84 100644
46806 --- a/fs/proc/base.c
46807 +++ b/fs/proc/base.c
46808 @@ -109,6 +109,14 @@ struct pid_entry {
46809 union proc_op op;
46810 };
46811
46812 +struct getdents_callback {
46813 + struct linux_dirent __user * current_dir;
46814 + struct linux_dirent __user * previous;
46815 + struct file * file;
46816 + int count;
46817 + int error;
46818 +};
46819 +
46820 #define NOD(NAME, MODE, IOP, FOP, OP) { \
46821 .name = (NAME), \
46822 .len = sizeof(NAME) - 1, \
46823 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
46824 if (!mm->arg_end)
46825 goto out_mm; /* Shh! No looking before we're done */
46826
46827 + if (gr_acl_handle_procpidmem(task))
46828 + goto out_mm;
46829 +
46830 len = mm->arg_end - mm->arg_start;
46831
46832 if (len > PAGE_SIZE)
46833 @@ -240,12 +251,28 @@ out:
46834 return res;
46835 }
46836
46837 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46838 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46839 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
46840 + _mm->pax_flags & MF_PAX_SEGMEXEC))
46841 +#endif
46842 +
46843 static int proc_pid_auxv(struct task_struct *task, char *buffer)
46844 {
46845 struct mm_struct *mm = mm_for_maps(task);
46846 int res = PTR_ERR(mm);
46847 if (mm && !IS_ERR(mm)) {
46848 unsigned int nwords = 0;
46849 +
46850 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46851 + /* allow if we're currently ptracing this task */
46852 + if (PAX_RAND_FLAGS(mm) &&
46853 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
46854 + mmput(mm);
46855 + return 0;
46856 + }
46857 +#endif
46858 +
46859 do {
46860 nwords += 2;
46861 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
46862 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
46863 }
46864
46865
46866 -#ifdef CONFIG_KALLSYMS
46867 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46868 /*
46869 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
46870 * Returns the resolved symbol. If that fails, simply return the address.
46871 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
46872 mutex_unlock(&task->signal->cred_guard_mutex);
46873 }
46874
46875 -#ifdef CONFIG_STACKTRACE
46876 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46877
46878 #define MAX_STACK_TRACE_DEPTH 64
46879
46880 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
46881 return count;
46882 }
46883
46884 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
46885 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
46886 static int proc_pid_syscall(struct task_struct *task, char *buffer)
46887 {
46888 long nr;
46889 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
46890 /************************************************************************/
46891
46892 /* permission checks */
46893 -static int proc_fd_access_allowed(struct inode *inode)
46894 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
46895 {
46896 struct task_struct *task;
46897 int allowed = 0;
46898 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
46899 */
46900 task = get_proc_task(inode);
46901 if (task) {
46902 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
46903 + if (log)
46904 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
46905 + else
46906 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
46907 put_task_struct(task);
46908 }
46909 return allowed;
46910 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
46911 struct task_struct *task,
46912 int hide_pid_min)
46913 {
46914 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
46915 + return false;
46916 +
46917 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46918 + rcu_read_lock();
46919 + {
46920 + const struct cred *tmpcred = current_cred();
46921 + const struct cred *cred = __task_cred(task);
46922 +
46923 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
46924 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46925 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
46926 +#endif
46927 + ) {
46928 + rcu_read_unlock();
46929 + return true;
46930 + }
46931 + }
46932 + rcu_read_unlock();
46933 +
46934 + if (!pid->hide_pid)
46935 + return false;
46936 +#endif
46937 +
46938 if (pid->hide_pid < hide_pid_min)
46939 return true;
46940 if (in_group_p(pid->pid_gid))
46941 return true;
46942 +
46943 return ptrace_may_access(task, PTRACE_MODE_READ);
46944 }
46945
46946 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
46947 put_task_struct(task);
46948
46949 if (!has_perms) {
46950 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46951 + {
46952 +#else
46953 if (pid->hide_pid == 2) {
46954 +#endif
46955 /*
46956 * Let's make getdents(), stat(), and open()
46957 * consistent with each other. If a process
46958 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
46959 file->f_mode |= FMODE_UNSIGNED_OFFSET;
46960 file->private_data = mm;
46961
46962 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46963 + file->f_version = current->exec_id;
46964 +#endif
46965 +
46966 return 0;
46967 }
46968
46969 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
46970 ssize_t copied;
46971 char *page;
46972
46973 +#ifdef CONFIG_GRKERNSEC
46974 + if (write)
46975 + return -EPERM;
46976 +#endif
46977 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46978 + if (file->f_version != current->exec_id) {
46979 + gr_log_badprocpid("mem");
46980 + return 0;
46981 + }
46982 +#endif
46983 +
46984 if (!mm)
46985 return 0;
46986
46987 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
46988 if (!task)
46989 goto out_no_task;
46990
46991 + if (gr_acl_handle_procpidmem(task))
46992 + goto out;
46993 +
46994 ret = -ENOMEM;
46995 page = (char *)__get_free_page(GFP_TEMPORARY);
46996 if (!page)
46997 @@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
46998 path_put(&nd->path);
46999
47000 /* Are we allowed to snoop on the tasks file descriptors? */
47001 - if (!proc_fd_access_allowed(inode))
47002 + if (!proc_fd_access_allowed(inode, 0))
47003 goto out;
47004
47005 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
47006 @@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
47007 struct path path;
47008
47009 /* Are we allowed to snoop on the tasks file descriptors? */
47010 - if (!proc_fd_access_allowed(inode))
47011 - goto out;
47012 + /* logging this is needed for learning on chromium to work properly,
47013 + but we don't want to flood the logs from 'ps' which does a readlink
47014 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
47015 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
47016 + */
47017 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
47018 + if (!proc_fd_access_allowed(inode,0))
47019 + goto out;
47020 + } else {
47021 + if (!proc_fd_access_allowed(inode,1))
47022 + goto out;
47023 + }
47024
47025 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
47026 if (error)
47027 @@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
47028 rcu_read_lock();
47029 cred = __task_cred(task);
47030 inode->i_uid = cred->euid;
47031 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47032 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47033 +#else
47034 inode->i_gid = cred->egid;
47035 +#endif
47036 rcu_read_unlock();
47037 }
47038 security_task_to_inode(task, inode);
47039 @@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47040 return -ENOENT;
47041 }
47042 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47043 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47044 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47045 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47046 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47047 +#endif
47048 task_dumpable(task)) {
47049 cred = __task_cred(task);
47050 stat->uid = cred->euid;
47051 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47052 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
47053 +#else
47054 stat->gid = cred->egid;
47055 +#endif
47056 }
47057 }
47058 rcu_read_unlock();
47059 @@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
47060
47061 if (task) {
47062 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47063 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47064 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47065 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47066 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47067 +#endif
47068 task_dumpable(task)) {
47069 rcu_read_lock();
47070 cred = __task_cred(task);
47071 inode->i_uid = cred->euid;
47072 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47073 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47074 +#else
47075 inode->i_gid = cred->egid;
47076 +#endif
47077 rcu_read_unlock();
47078 } else {
47079 inode->i_uid = 0;
47080 @@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
47081 int fd = proc_fd(inode);
47082
47083 if (task) {
47084 - files = get_files_struct(task);
47085 + if (!gr_acl_handle_procpidmem(task))
47086 + files = get_files_struct(task);
47087 put_task_struct(task);
47088 }
47089 if (files) {
47090 @@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
47091 */
47092 static int proc_fd_permission(struct inode *inode, int mask)
47093 {
47094 + struct task_struct *task;
47095 int rv = generic_permission(inode, mask);
47096 - if (rv == 0)
47097 - return 0;
47098 +
47099 if (task_pid(current) == proc_pid(inode))
47100 rv = 0;
47101 +
47102 + task = get_proc_task(inode);
47103 + if (task == NULL)
47104 + return rv;
47105 +
47106 + if (gr_acl_handle_procpidmem(task))
47107 + rv = -EACCES;
47108 +
47109 + put_task_struct(task);
47110 +
47111 return rv;
47112 }
47113
47114 @@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
47115 if (!task)
47116 goto out_no_task;
47117
47118 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47119 + goto out;
47120 +
47121 /*
47122 * Yes, it does not scale. And it should not. Don't add
47123 * new entries into /proc/<tgid>/ without very good reasons.
47124 @@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
47125 if (!task)
47126 goto out_no_task;
47127
47128 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47129 + goto out;
47130 +
47131 ret = 0;
47132 i = filp->f_pos;
47133 switch (i) {
47134 @@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
47135 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
47136 void *cookie)
47137 {
47138 - char *s = nd_get_link(nd);
47139 + const char *s = nd_get_link(nd);
47140 if (!IS_ERR(s))
47141 __putname(s);
47142 }
47143 @@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
47144 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
47145 #endif
47146 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47147 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47148 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47149 INF("syscall", S_IRUGO, proc_pid_syscall),
47150 #endif
47151 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47152 @@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
47153 #ifdef CONFIG_SECURITY
47154 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47155 #endif
47156 -#ifdef CONFIG_KALLSYMS
47157 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47158 INF("wchan", S_IRUGO, proc_pid_wchan),
47159 #endif
47160 -#ifdef CONFIG_STACKTRACE
47161 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47162 ONE("stack", S_IRUGO, proc_pid_stack),
47163 #endif
47164 #ifdef CONFIG_SCHEDSTATS
47165 @@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
47166 #ifdef CONFIG_HARDWALL
47167 INF("hardwall", S_IRUGO, proc_pid_hardwall),
47168 #endif
47169 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47170 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
47171 +#endif
47172 };
47173
47174 static int proc_tgid_base_readdir(struct file * filp,
47175 @@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
47176 if (!inode)
47177 goto out;
47178
47179 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47180 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
47181 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47182 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47183 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
47184 +#else
47185 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
47186 +#endif
47187 inode->i_op = &proc_tgid_base_inode_operations;
47188 inode->i_fop = &proc_tgid_base_operations;
47189 inode->i_flags|=S_IMMUTABLE;
47190 @@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
47191 if (!task)
47192 goto out;
47193
47194 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47195 + goto out_put_task;
47196 +
47197 result = proc_pid_instantiate(dir, dentry, task, NULL);
47198 +out_put_task:
47199 put_task_struct(task);
47200 out:
47201 return result;
47202 @@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
47203 static int fake_filldir(void *buf, const char *name, int namelen,
47204 loff_t offset, u64 ino, unsigned d_type)
47205 {
47206 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
47207 + __buf->error = -EINVAL;
47208 return 0;
47209 }
47210
47211 @@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
47212 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
47213 #endif
47214 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47215 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47216 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47217 INF("syscall", S_IRUGO, proc_pid_syscall),
47218 #endif
47219 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47220 @@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
47221 #ifdef CONFIG_SECURITY
47222 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47223 #endif
47224 -#ifdef CONFIG_KALLSYMS
47225 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47226 INF("wchan", S_IRUGO, proc_pid_wchan),
47227 #endif
47228 -#ifdef CONFIG_STACKTRACE
47229 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47230 ONE("stack", S_IRUGO, proc_pid_stack),
47231 #endif
47232 #ifdef CONFIG_SCHEDSTATS
47233 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
47234 index 82676e3..5f8518a 100644
47235 --- a/fs/proc/cmdline.c
47236 +++ b/fs/proc/cmdline.c
47237 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
47238
47239 static int __init proc_cmdline_init(void)
47240 {
47241 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47242 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
47243 +#else
47244 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
47245 +#endif
47246 return 0;
47247 }
47248 module_init(proc_cmdline_init);
47249 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
47250 index b143471..bb105e5 100644
47251 --- a/fs/proc/devices.c
47252 +++ b/fs/proc/devices.c
47253 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
47254
47255 static int __init proc_devices_init(void)
47256 {
47257 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47258 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
47259 +#else
47260 proc_create("devices", 0, NULL, &proc_devinfo_operations);
47261 +#endif
47262 return 0;
47263 }
47264 module_init(proc_devices_init);
47265 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
47266 index 84fd323..f698a32 100644
47267 --- a/fs/proc/inode.c
47268 +++ b/fs/proc/inode.c
47269 @@ -21,12 +21,18 @@
47270 #include <linux/seq_file.h>
47271 #include <linux/slab.h>
47272 #include <linux/mount.h>
47273 +#include <linux/grsecurity.h>
47274
47275 #include <asm/system.h>
47276 #include <asm/uaccess.h>
47277
47278 #include "internal.h"
47279
47280 +#ifdef CONFIG_PROC_SYSCTL
47281 +extern const struct inode_operations proc_sys_inode_operations;
47282 +extern const struct inode_operations proc_sys_dir_operations;
47283 +#endif
47284 +
47285 static void proc_evict_inode(struct inode *inode)
47286 {
47287 struct proc_dir_entry *de;
47288 @@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
47289 ns_ops = PROC_I(inode)->ns_ops;
47290 if (ns_ops && ns_ops->put)
47291 ns_ops->put(PROC_I(inode)->ns);
47292 +
47293 +#ifdef CONFIG_PROC_SYSCTL
47294 + if (inode->i_op == &proc_sys_inode_operations ||
47295 + inode->i_op == &proc_sys_dir_operations)
47296 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
47297 +#endif
47298 +
47299 }
47300
47301 static struct kmem_cache * proc_inode_cachep;
47302 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
47303 if (de->mode) {
47304 inode->i_mode = de->mode;
47305 inode->i_uid = de->uid;
47306 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47307 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47308 +#else
47309 inode->i_gid = de->gid;
47310 +#endif
47311 }
47312 if (de->size)
47313 inode->i_size = de->size;
47314 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
47315 index 2925775..4f08fae 100644
47316 --- a/fs/proc/internal.h
47317 +++ b/fs/proc/internal.h
47318 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47319 struct pid *pid, struct task_struct *task);
47320 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47321 struct pid *pid, struct task_struct *task);
47322 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47323 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
47324 +#endif
47325 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
47326
47327 extern const struct file_operations proc_maps_operations;
47328 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
47329 index d245cb2..f4e8498 100644
47330 --- a/fs/proc/kcore.c
47331 +++ b/fs/proc/kcore.c
47332 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47333 * the addresses in the elf_phdr on our list.
47334 */
47335 start = kc_offset_to_vaddr(*fpos - elf_buflen);
47336 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
47337 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
47338 + if (tsz > buflen)
47339 tsz = buflen;
47340 -
47341 +
47342 while (buflen) {
47343 struct kcore_list *m;
47344
47345 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47346 kfree(elf_buf);
47347 } else {
47348 if (kern_addr_valid(start)) {
47349 - unsigned long n;
47350 + char *elf_buf;
47351 + mm_segment_t oldfs;
47352
47353 - n = copy_to_user(buffer, (char *)start, tsz);
47354 - /*
47355 - * We cannot distingush between fault on source
47356 - * and fault on destination. When this happens
47357 - * we clear too and hope it will trigger the
47358 - * EFAULT again.
47359 - */
47360 - if (n) {
47361 - if (clear_user(buffer + tsz - n,
47362 - n))
47363 + elf_buf = kmalloc(tsz, GFP_KERNEL);
47364 + if (!elf_buf)
47365 + return -ENOMEM;
47366 + oldfs = get_fs();
47367 + set_fs(KERNEL_DS);
47368 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
47369 + set_fs(oldfs);
47370 + if (copy_to_user(buffer, elf_buf, tsz)) {
47371 + kfree(elf_buf);
47372 return -EFAULT;
47373 + }
47374 }
47375 + set_fs(oldfs);
47376 + kfree(elf_buf);
47377 } else {
47378 if (clear_user(buffer, tsz))
47379 return -EFAULT;
47380 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47381
47382 static int open_kcore(struct inode *inode, struct file *filp)
47383 {
47384 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
47385 + return -EPERM;
47386 +#endif
47387 if (!capable(CAP_SYS_RAWIO))
47388 return -EPERM;
47389 if (kcore_need_update)
47390 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
47391 index 80e4645..53e5fcf 100644
47392 --- a/fs/proc/meminfo.c
47393 +++ b/fs/proc/meminfo.c
47394 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
47395 vmi.used >> 10,
47396 vmi.largest_chunk >> 10
47397 #ifdef CONFIG_MEMORY_FAILURE
47398 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
47399 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
47400 #endif
47401 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
47402 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
47403 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
47404 index b1822dd..df622cb 100644
47405 --- a/fs/proc/nommu.c
47406 +++ b/fs/proc/nommu.c
47407 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
47408 if (len < 1)
47409 len = 1;
47410 seq_printf(m, "%*c", len, ' ');
47411 - seq_path(m, &file->f_path, "");
47412 + seq_path(m, &file->f_path, "\n\\");
47413 }
47414
47415 seq_putc(m, '\n');
47416 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
47417 index 06e1cc1..177cd98 100644
47418 --- a/fs/proc/proc_net.c
47419 +++ b/fs/proc/proc_net.c
47420 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
47421 struct task_struct *task;
47422 struct nsproxy *ns;
47423 struct net *net = NULL;
47424 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47425 + const struct cred *cred = current_cred();
47426 +#endif
47427 +
47428 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47429 + if (cred->fsuid)
47430 + return net;
47431 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47432 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
47433 + return net;
47434 +#endif
47435
47436 rcu_read_lock();
47437 task = pid_task(proc_pid(dir), PIDTYPE_PID);
47438 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
47439 index 53c3bce..10ad159 100644
47440 --- a/fs/proc/proc_sysctl.c
47441 +++ b/fs/proc/proc_sysctl.c
47442 @@ -9,11 +9,13 @@
47443 #include <linux/namei.h>
47444 #include "internal.h"
47445
47446 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
47447 +
47448 static const struct dentry_operations proc_sys_dentry_operations;
47449 static const struct file_operations proc_sys_file_operations;
47450 -static const struct inode_operations proc_sys_inode_operations;
47451 +const struct inode_operations proc_sys_inode_operations;
47452 static const struct file_operations proc_sys_dir_file_operations;
47453 -static const struct inode_operations proc_sys_dir_operations;
47454 +const struct inode_operations proc_sys_dir_operations;
47455
47456 void proc_sys_poll_notify(struct ctl_table_poll *poll)
47457 {
47458 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
47459
47460 err = NULL;
47461 d_set_d_op(dentry, &proc_sys_dentry_operations);
47462 +
47463 + gr_handle_proc_create(dentry, inode);
47464 +
47465 d_add(dentry, inode);
47466
47467 + if (gr_handle_sysctl(p, MAY_EXEC))
47468 + err = ERR_PTR(-ENOENT);
47469 +
47470 out:
47471 sysctl_head_finish(head);
47472 return err;
47473 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
47474 if (!table->proc_handler)
47475 goto out;
47476
47477 +#ifdef CONFIG_GRKERNSEC
47478 + error = -EPERM;
47479 + if (write && !capable(CAP_SYS_ADMIN))
47480 + goto out;
47481 +#endif
47482 +
47483 /* careful: calling conventions are nasty here */
47484 res = count;
47485 error = table->proc_handler(table, write, buf, &res, ppos);
47486 @@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
47487 return -ENOMEM;
47488 } else {
47489 d_set_d_op(child, &proc_sys_dentry_operations);
47490 +
47491 + gr_handle_proc_create(child, inode);
47492 +
47493 d_add(child, inode);
47494 }
47495 } else {
47496 @@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
47497 if (*pos < file->f_pos)
47498 continue;
47499
47500 + if (gr_handle_sysctl(table, 0))
47501 + continue;
47502 +
47503 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
47504 if (res)
47505 return res;
47506 @@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
47507 if (IS_ERR(head))
47508 return PTR_ERR(head);
47509
47510 + if (table && gr_handle_sysctl(table, MAY_EXEC))
47511 + return -ENOENT;
47512 +
47513 generic_fillattr(inode, stat);
47514 if (table)
47515 stat->mode = (stat->mode & S_IFMT) | table->mode;
47516 @@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
47517 .llseek = generic_file_llseek,
47518 };
47519
47520 -static const struct inode_operations proc_sys_inode_operations = {
47521 +const struct inode_operations proc_sys_inode_operations = {
47522 .permission = proc_sys_permission,
47523 .setattr = proc_sys_setattr,
47524 .getattr = proc_sys_getattr,
47525 };
47526
47527 -static const struct inode_operations proc_sys_dir_operations = {
47528 +const struct inode_operations proc_sys_dir_operations = {
47529 .lookup = proc_sys_lookup,
47530 .permission = proc_sys_permission,
47531 .setattr = proc_sys_setattr,
47532 diff --git a/fs/proc/root.c b/fs/proc/root.c
47533 index 46a15d8..335631a 100644
47534 --- a/fs/proc/root.c
47535 +++ b/fs/proc/root.c
47536 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
47537 #ifdef CONFIG_PROC_DEVICETREE
47538 proc_device_tree_init();
47539 #endif
47540 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47541 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47542 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
47543 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47544 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47545 +#endif
47546 +#else
47547 proc_mkdir("bus", NULL);
47548 +#endif
47549 proc_sys_init();
47550 }
47551
47552 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
47553 index 3efa725..23c925b 100644
47554 --- a/fs/proc/task_mmu.c
47555 +++ b/fs/proc/task_mmu.c
47556 @@ -11,6 +11,7 @@
47557 #include <linux/rmap.h>
47558 #include <linux/swap.h>
47559 #include <linux/swapops.h>
47560 +#include <linux/grsecurity.h>
47561
47562 #include <asm/elf.h>
47563 #include <asm/uaccess.h>
47564 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47565 "VmExe:\t%8lu kB\n"
47566 "VmLib:\t%8lu kB\n"
47567 "VmPTE:\t%8lu kB\n"
47568 - "VmSwap:\t%8lu kB\n",
47569 - hiwater_vm << (PAGE_SHIFT-10),
47570 + "VmSwap:\t%8lu kB\n"
47571 +
47572 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47573 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
47574 +#endif
47575 +
47576 + ,hiwater_vm << (PAGE_SHIFT-10),
47577 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
47578 mm->locked_vm << (PAGE_SHIFT-10),
47579 mm->pinned_vm << (PAGE_SHIFT-10),
47580 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47581 data << (PAGE_SHIFT-10),
47582 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
47583 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
47584 - swap << (PAGE_SHIFT-10));
47585 + swap << (PAGE_SHIFT-10)
47586 +
47587 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47588 + , mm->context.user_cs_base, mm->context.user_cs_limit
47589 +#endif
47590 +
47591 + );
47592 }
47593
47594 unsigned long task_vsize(struct mm_struct *mm)
47595 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
47596 return ret;
47597 }
47598
47599 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47600 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47601 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47602 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47603 +#endif
47604 +
47605 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47606 {
47607 struct mm_struct *mm = vma->vm_mm;
47608 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47609 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
47610 }
47611
47612 - /* We don't show the stack guard page in /proc/maps */
47613 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47614 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
47615 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
47616 +#else
47617 start = vma->vm_start;
47618 - if (stack_guard_page_start(vma, start))
47619 - start += PAGE_SIZE;
47620 end = vma->vm_end;
47621 - if (stack_guard_page_end(vma, end))
47622 - end -= PAGE_SIZE;
47623 +#endif
47624
47625 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
47626 start,
47627 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47628 flags & VM_WRITE ? 'w' : '-',
47629 flags & VM_EXEC ? 'x' : '-',
47630 flags & VM_MAYSHARE ? 's' : 'p',
47631 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47632 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
47633 +#else
47634 pgoff,
47635 +#endif
47636 MAJOR(dev), MINOR(dev), ino, &len);
47637
47638 /*
47639 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47640 */
47641 if (file) {
47642 pad_len_spaces(m, len);
47643 - seq_path(m, &file->f_path, "\n");
47644 + seq_path(m, &file->f_path, "\n\\");
47645 } else {
47646 const char *name = arch_vma_name(vma);
47647 if (!name) {
47648 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47649 if (vma->vm_start <= mm->brk &&
47650 vma->vm_end >= mm->start_brk) {
47651 name = "[heap]";
47652 - } else if (vma->vm_start <= mm->start_stack &&
47653 - vma->vm_end >= mm->start_stack) {
47654 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
47655 + (vma->vm_start <= mm->start_stack &&
47656 + vma->vm_end >= mm->start_stack)) {
47657 name = "[stack]";
47658 }
47659 } else {
47660 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
47661 struct proc_maps_private *priv = m->private;
47662 struct task_struct *task = priv->task;
47663
47664 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47665 + if (current->exec_id != m->exec_id) {
47666 + gr_log_badprocpid("maps");
47667 + return 0;
47668 + }
47669 +#endif
47670 +
47671 show_map_vma(m, vma);
47672
47673 if (m->count < m->size) /* vma is copied successfully */
47674 @@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
47675 .private = &mss,
47676 };
47677
47678 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47679 + if (current->exec_id != m->exec_id) {
47680 + gr_log_badprocpid("smaps");
47681 + return 0;
47682 + }
47683 +#endif
47684 memset(&mss, 0, sizeof mss);
47685 - mss.vma = vma;
47686 - /* mmap_sem is held in m_start */
47687 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
47688 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
47689 -
47690 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47691 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
47692 +#endif
47693 + mss.vma = vma;
47694 + /* mmap_sem is held in m_start */
47695 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
47696 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
47697 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47698 + }
47699 +#endif
47700 show_map_vma(m, vma);
47701
47702 seq_printf(m,
47703 @@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
47704 "KernelPageSize: %8lu kB\n"
47705 "MMUPageSize: %8lu kB\n"
47706 "Locked: %8lu kB\n",
47707 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47708 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
47709 +#else
47710 (vma->vm_end - vma->vm_start) >> 10,
47711 +#endif
47712 mss.resident >> 10,
47713 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
47714 mss.shared_clean >> 10,
47715 @@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
47716 int n;
47717 char buffer[50];
47718
47719 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47720 + if (current->exec_id != m->exec_id) {
47721 + gr_log_badprocpid("numa_maps");
47722 + return 0;
47723 + }
47724 +#endif
47725 +
47726 if (!mm)
47727 return 0;
47728
47729 @@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
47730 mpol_to_str(buffer, sizeof(buffer), pol, 0);
47731 mpol_cond_put(pol);
47732
47733 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47734 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
47735 +#else
47736 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
47737 +#endif
47738
47739 if (file) {
47740 seq_printf(m, " file=");
47741 - seq_path(m, &file->f_path, "\n\t= ");
47742 + seq_path(m, &file->f_path, "\n\t\\= ");
47743 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
47744 seq_printf(m, " heap");
47745 } else if (vma->vm_start <= mm->start_stack &&
47746 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
47747 index 980de54..2a4db5f 100644
47748 --- a/fs/proc/task_nommu.c
47749 +++ b/fs/proc/task_nommu.c
47750 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47751 else
47752 bytes += kobjsize(mm);
47753
47754 - if (current->fs && current->fs->users > 1)
47755 + if (current->fs && atomic_read(&current->fs->users) > 1)
47756 sbytes += kobjsize(current->fs);
47757 else
47758 bytes += kobjsize(current->fs);
47759 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
47760
47761 if (file) {
47762 pad_len_spaces(m, len);
47763 - seq_path(m, &file->f_path, "");
47764 + seq_path(m, &file->f_path, "\n\\");
47765 } else if (mm) {
47766 if (vma->vm_start <= mm->start_stack &&
47767 vma->vm_end >= mm->start_stack) {
47768 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
47769 index d67908b..d13f6a6 100644
47770 --- a/fs/quota/netlink.c
47771 +++ b/fs/quota/netlink.c
47772 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
47773 void quota_send_warning(short type, unsigned int id, dev_t dev,
47774 const char warntype)
47775 {
47776 - static atomic_t seq;
47777 + static atomic_unchecked_t seq;
47778 struct sk_buff *skb;
47779 void *msg_head;
47780 int ret;
47781 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
47782 "VFS: Not enough memory to send quota warning.\n");
47783 return;
47784 }
47785 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
47786 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
47787 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
47788 if (!msg_head) {
47789 printk(KERN_ERR
47790 diff --git a/fs/readdir.c b/fs/readdir.c
47791 index 356f715..c918d38 100644
47792 --- a/fs/readdir.c
47793 +++ b/fs/readdir.c
47794 @@ -17,6 +17,7 @@
47795 #include <linux/security.h>
47796 #include <linux/syscalls.h>
47797 #include <linux/unistd.h>
47798 +#include <linux/namei.h>
47799
47800 #include <asm/uaccess.h>
47801
47802 @@ -67,6 +68,7 @@ struct old_linux_dirent {
47803
47804 struct readdir_callback {
47805 struct old_linux_dirent __user * dirent;
47806 + struct file * file;
47807 int result;
47808 };
47809
47810 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
47811 buf->result = -EOVERFLOW;
47812 return -EOVERFLOW;
47813 }
47814 +
47815 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47816 + return 0;
47817 +
47818 buf->result++;
47819 dirent = buf->dirent;
47820 if (!access_ok(VERIFY_WRITE, dirent,
47821 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
47822
47823 buf.result = 0;
47824 buf.dirent = dirent;
47825 + buf.file = file;
47826
47827 error = vfs_readdir(file, fillonedir, &buf);
47828 if (buf.result)
47829 @@ -142,6 +149,7 @@ struct linux_dirent {
47830 struct getdents_callback {
47831 struct linux_dirent __user * current_dir;
47832 struct linux_dirent __user * previous;
47833 + struct file * file;
47834 int count;
47835 int error;
47836 };
47837 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
47838 buf->error = -EOVERFLOW;
47839 return -EOVERFLOW;
47840 }
47841 +
47842 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47843 + return 0;
47844 +
47845 dirent = buf->previous;
47846 if (dirent) {
47847 if (__put_user(offset, &dirent->d_off))
47848 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
47849 buf.previous = NULL;
47850 buf.count = count;
47851 buf.error = 0;
47852 + buf.file = file;
47853
47854 error = vfs_readdir(file, filldir, &buf);
47855 if (error >= 0)
47856 @@ -229,6 +242,7 @@ out:
47857 struct getdents_callback64 {
47858 struct linux_dirent64 __user * current_dir;
47859 struct linux_dirent64 __user * previous;
47860 + struct file *file;
47861 int count;
47862 int error;
47863 };
47864 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
47865 buf->error = -EINVAL; /* only used if we fail.. */
47866 if (reclen > buf->count)
47867 return -EINVAL;
47868 +
47869 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47870 + return 0;
47871 +
47872 dirent = buf->previous;
47873 if (dirent) {
47874 if (__put_user(offset, &dirent->d_off))
47875 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
47876
47877 buf.current_dir = dirent;
47878 buf.previous = NULL;
47879 + buf.file = file;
47880 buf.count = count;
47881 buf.error = 0;
47882
47883 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
47884 error = buf.error;
47885 lastdirent = buf.previous;
47886 if (lastdirent) {
47887 - typeof(lastdirent->d_off) d_off = file->f_pos;
47888 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
47889 if (__put_user(d_off, &lastdirent->d_off))
47890 error = -EFAULT;
47891 else
47892 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
47893 index 60c0804..d814f98 100644
47894 --- a/fs/reiserfs/do_balan.c
47895 +++ b/fs/reiserfs/do_balan.c
47896 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
47897 return;
47898 }
47899
47900 - atomic_inc(&(fs_generation(tb->tb_sb)));
47901 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
47902 do_balance_starts(tb);
47903
47904 /* balance leaf returns 0 except if combining L R and S into
47905 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
47906 index 7a99811..a7c96c4 100644
47907 --- a/fs/reiserfs/procfs.c
47908 +++ b/fs/reiserfs/procfs.c
47909 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
47910 "SMALL_TAILS " : "NO_TAILS ",
47911 replay_only(sb) ? "REPLAY_ONLY " : "",
47912 convert_reiserfs(sb) ? "CONV " : "",
47913 - atomic_read(&r->s_generation_counter),
47914 + atomic_read_unchecked(&r->s_generation_counter),
47915 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
47916 SF(s_do_balance), SF(s_unneeded_left_neighbor),
47917 SF(s_good_search_by_key_reada), SF(s_bmaps),
47918 diff --git a/fs/select.c b/fs/select.c
47919 index e782258..3b4b44c 100644
47920 --- a/fs/select.c
47921 +++ b/fs/select.c
47922 @@ -20,6 +20,7 @@
47923 #include <linux/module.h>
47924 #include <linux/slab.h>
47925 #include <linux/poll.h>
47926 +#include <linux/security.h>
47927 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
47928 #include <linux/file.h>
47929 #include <linux/fdtable.h>
47930 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
47931 struct poll_list *walk = head;
47932 unsigned long todo = nfds;
47933
47934 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
47935 if (nfds > rlimit(RLIMIT_NOFILE))
47936 return -EINVAL;
47937
47938 diff --git a/fs/seq_file.c b/fs/seq_file.c
47939 index 4023d6b..53b39c5 100644
47940 --- a/fs/seq_file.c
47941 +++ b/fs/seq_file.c
47942 @@ -9,6 +9,7 @@
47943 #include <linux/module.h>
47944 #include <linux/seq_file.h>
47945 #include <linux/slab.h>
47946 +#include <linux/sched.h>
47947
47948 #include <asm/uaccess.h>
47949 #include <asm/page.h>
47950 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
47951 memset(p, 0, sizeof(*p));
47952 mutex_init(&p->lock);
47953 p->op = op;
47954 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47955 + p->exec_id = current->exec_id;
47956 +#endif
47957
47958 /*
47959 * Wrappers around seq_open(e.g. swaps_open) need to be
47960 @@ -76,7 +80,8 @@ static int traverse(struct seq_file *m, loff_t offset)
47961 return 0;
47962 }
47963 if (!m->buf) {
47964 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
47965 + m->size = PAGE_SIZE;
47966 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
47967 if (!m->buf)
47968 return -ENOMEM;
47969 }
47970 @@ -116,7 +121,8 @@ static int traverse(struct seq_file *m, loff_t offset)
47971 Eoverflow:
47972 m->op->stop(m, p);
47973 kfree(m->buf);
47974 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
47975 + m->size <<= 1;
47976 + m->buf = kmalloc(m->size, GFP_KERNEL);
47977 return !m->buf ? -ENOMEM : -EAGAIN;
47978 }
47979
47980 @@ -169,7 +175,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
47981 m->version = file->f_version;
47982 /* grab buffer if we didn't have one */
47983 if (!m->buf) {
47984 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
47985 + m->size = PAGE_SIZE;
47986 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
47987 if (!m->buf)
47988 goto Enomem;
47989 }
47990 @@ -210,7 +217,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
47991 goto Fill;
47992 m->op->stop(m, p);
47993 kfree(m->buf);
47994 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
47995 + m->size <<= 1;
47996 + m->buf = kmalloc(m->size, GFP_KERNEL);
47997 if (!m->buf)
47998 goto Enomem;
47999 m->count = 0;
48000 @@ -549,7 +557,7 @@ static void single_stop(struct seq_file *p, void *v)
48001 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48002 void *data)
48003 {
48004 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48005 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48006 int res = -ENOMEM;
48007
48008 if (op) {
48009 diff --git a/fs/splice.c b/fs/splice.c
48010 index 1ec0493..d6ab5c2 100644
48011 --- a/fs/splice.c
48012 +++ b/fs/splice.c
48013 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48014 pipe_lock(pipe);
48015
48016 for (;;) {
48017 - if (!pipe->readers) {
48018 + if (!atomic_read(&pipe->readers)) {
48019 send_sig(SIGPIPE, current, 0);
48020 if (!ret)
48021 ret = -EPIPE;
48022 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48023 do_wakeup = 0;
48024 }
48025
48026 - pipe->waiting_writers++;
48027 + atomic_inc(&pipe->waiting_writers);
48028 pipe_wait(pipe);
48029 - pipe->waiting_writers--;
48030 + atomic_dec(&pipe->waiting_writers);
48031 }
48032
48033 pipe_unlock(pipe);
48034 @@ -559,7 +559,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
48035 old_fs = get_fs();
48036 set_fs(get_ds());
48037 /* The cast to a user pointer is valid due to the set_fs() */
48038 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
48039 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
48040 set_fs(old_fs);
48041
48042 return res;
48043 @@ -574,7 +574,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
48044 old_fs = get_fs();
48045 set_fs(get_ds());
48046 /* The cast to a user pointer is valid due to the set_fs() */
48047 - res = vfs_write(file, (const char __user *)buf, count, &pos);
48048 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
48049 set_fs(old_fs);
48050
48051 return res;
48052 @@ -625,7 +625,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
48053 goto err;
48054
48055 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
48056 - vec[i].iov_base = (void __user *) page_address(page);
48057 + vec[i].iov_base = (void __force_user *) page_address(page);
48058 vec[i].iov_len = this_len;
48059 spd.pages[i] = page;
48060 spd.nr_pages++;
48061 @@ -845,10 +845,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
48062 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
48063 {
48064 while (!pipe->nrbufs) {
48065 - if (!pipe->writers)
48066 + if (!atomic_read(&pipe->writers))
48067 return 0;
48068
48069 - if (!pipe->waiting_writers && sd->num_spliced)
48070 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
48071 return 0;
48072
48073 if (sd->flags & SPLICE_F_NONBLOCK)
48074 @@ -1181,7 +1181,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
48075 * out of the pipe right after the splice_to_pipe(). So set
48076 * PIPE_READERS appropriately.
48077 */
48078 - pipe->readers = 1;
48079 + atomic_set(&pipe->readers, 1);
48080
48081 current->splice_pipe = pipe;
48082 }
48083 @@ -1733,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48084 ret = -ERESTARTSYS;
48085 break;
48086 }
48087 - if (!pipe->writers)
48088 + if (!atomic_read(&pipe->writers))
48089 break;
48090 - if (!pipe->waiting_writers) {
48091 + if (!atomic_read(&pipe->waiting_writers)) {
48092 if (flags & SPLICE_F_NONBLOCK) {
48093 ret = -EAGAIN;
48094 break;
48095 @@ -1767,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48096 pipe_lock(pipe);
48097
48098 while (pipe->nrbufs >= pipe->buffers) {
48099 - if (!pipe->readers) {
48100 + if (!atomic_read(&pipe->readers)) {
48101 send_sig(SIGPIPE, current, 0);
48102 ret = -EPIPE;
48103 break;
48104 @@ -1780,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48105 ret = -ERESTARTSYS;
48106 break;
48107 }
48108 - pipe->waiting_writers++;
48109 + atomic_inc(&pipe->waiting_writers);
48110 pipe_wait(pipe);
48111 - pipe->waiting_writers--;
48112 + atomic_dec(&pipe->waiting_writers);
48113 }
48114
48115 pipe_unlock(pipe);
48116 @@ -1818,14 +1818,14 @@ retry:
48117 pipe_double_lock(ipipe, opipe);
48118
48119 do {
48120 - if (!opipe->readers) {
48121 + if (!atomic_read(&opipe->readers)) {
48122 send_sig(SIGPIPE, current, 0);
48123 if (!ret)
48124 ret = -EPIPE;
48125 break;
48126 }
48127
48128 - if (!ipipe->nrbufs && !ipipe->writers)
48129 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
48130 break;
48131
48132 /*
48133 @@ -1922,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48134 pipe_double_lock(ipipe, opipe);
48135
48136 do {
48137 - if (!opipe->readers) {
48138 + if (!atomic_read(&opipe->readers)) {
48139 send_sig(SIGPIPE, current, 0);
48140 if (!ret)
48141 ret = -EPIPE;
48142 @@ -1967,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48143 * return EAGAIN if we have the potential of some data in the
48144 * future, otherwise just return 0
48145 */
48146 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
48147 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
48148 ret = -EAGAIN;
48149
48150 pipe_unlock(ipipe);
48151 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
48152 index 7fdf6a7..e6cd8ad 100644
48153 --- a/fs/sysfs/dir.c
48154 +++ b/fs/sysfs/dir.c
48155 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
48156 struct sysfs_dirent *sd;
48157 int rc;
48158
48159 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
48160 + const char *parent_name = parent_sd->s_name;
48161 +
48162 + mode = S_IFDIR | S_IRWXU;
48163 +
48164 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
48165 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
48166 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
48167 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
48168 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
48169 +#endif
48170 +
48171 /* allocate */
48172 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
48173 if (!sd)
48174 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
48175 index 00012e3..8392349 100644
48176 --- a/fs/sysfs/file.c
48177 +++ b/fs/sysfs/file.c
48178 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
48179
48180 struct sysfs_open_dirent {
48181 atomic_t refcnt;
48182 - atomic_t event;
48183 + atomic_unchecked_t event;
48184 wait_queue_head_t poll;
48185 struct list_head buffers; /* goes through sysfs_buffer.list */
48186 };
48187 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
48188 if (!sysfs_get_active(attr_sd))
48189 return -ENODEV;
48190
48191 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
48192 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
48193 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
48194
48195 sysfs_put_active(attr_sd);
48196 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
48197 return -ENOMEM;
48198
48199 atomic_set(&new_od->refcnt, 0);
48200 - atomic_set(&new_od->event, 1);
48201 + atomic_set_unchecked(&new_od->event, 1);
48202 init_waitqueue_head(&new_od->poll);
48203 INIT_LIST_HEAD(&new_od->buffers);
48204 goto retry;
48205 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
48206
48207 sysfs_put_active(attr_sd);
48208
48209 - if (buffer->event != atomic_read(&od->event))
48210 + if (buffer->event != atomic_read_unchecked(&od->event))
48211 goto trigger;
48212
48213 return DEFAULT_POLLMASK;
48214 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
48215
48216 od = sd->s_attr.open;
48217 if (od) {
48218 - atomic_inc(&od->event);
48219 + atomic_inc_unchecked(&od->event);
48220 wake_up_interruptible(&od->poll);
48221 }
48222
48223 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
48224 index a7ac78f..02158e1 100644
48225 --- a/fs/sysfs/symlink.c
48226 +++ b/fs/sysfs/symlink.c
48227 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48228
48229 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
48230 {
48231 - char *page = nd_get_link(nd);
48232 + const char *page = nd_get_link(nd);
48233 if (!IS_ERR(page))
48234 free_page((unsigned long)page);
48235 }
48236 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
48237 index c175b4d..8f36a16 100644
48238 --- a/fs/udf/misc.c
48239 +++ b/fs/udf/misc.c
48240 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
48241
48242 u8 udf_tag_checksum(const struct tag *t)
48243 {
48244 - u8 *data = (u8 *)t;
48245 + const u8 *data = (const u8 *)t;
48246 u8 checksum = 0;
48247 int i;
48248 for (i = 0; i < sizeof(struct tag); ++i)
48249 diff --git a/fs/utimes.c b/fs/utimes.c
48250 index ba653f3..06ea4b1 100644
48251 --- a/fs/utimes.c
48252 +++ b/fs/utimes.c
48253 @@ -1,6 +1,7 @@
48254 #include <linux/compiler.h>
48255 #include <linux/file.h>
48256 #include <linux/fs.h>
48257 +#include <linux/security.h>
48258 #include <linux/linkage.h>
48259 #include <linux/mount.h>
48260 #include <linux/namei.h>
48261 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
48262 goto mnt_drop_write_and_out;
48263 }
48264 }
48265 +
48266 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
48267 + error = -EACCES;
48268 + goto mnt_drop_write_and_out;
48269 + }
48270 +
48271 mutex_lock(&inode->i_mutex);
48272 error = notify_change(path->dentry, &newattrs);
48273 mutex_unlock(&inode->i_mutex);
48274 diff --git a/fs/xattr.c b/fs/xattr.c
48275 index 82f4337..236473c 100644
48276 --- a/fs/xattr.c
48277 +++ b/fs/xattr.c
48278 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
48279 * Extended attribute SET operations
48280 */
48281 static long
48282 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
48283 +setxattr(struct path *path, const char __user *name, const void __user *value,
48284 size_t size, int flags)
48285 {
48286 int error;
48287 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
48288 return PTR_ERR(kvalue);
48289 }
48290
48291 - error = vfs_setxattr(d, kname, kvalue, size, flags);
48292 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
48293 + error = -EACCES;
48294 + goto out;
48295 + }
48296 +
48297 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
48298 +out:
48299 kfree(kvalue);
48300 return error;
48301 }
48302 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
48303 return error;
48304 error = mnt_want_write(path.mnt);
48305 if (!error) {
48306 - error = setxattr(path.dentry, name, value, size, flags);
48307 + error = setxattr(&path, name, value, size, flags);
48308 mnt_drop_write(path.mnt);
48309 }
48310 path_put(&path);
48311 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
48312 return error;
48313 error = mnt_want_write(path.mnt);
48314 if (!error) {
48315 - error = setxattr(path.dentry, name, value, size, flags);
48316 + error = setxattr(&path, name, value, size, flags);
48317 mnt_drop_write(path.mnt);
48318 }
48319 path_put(&path);
48320 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
48321 const void __user *,value, size_t, size, int, flags)
48322 {
48323 struct file *f;
48324 - struct dentry *dentry;
48325 int error = -EBADF;
48326
48327 f = fget(fd);
48328 if (!f)
48329 return error;
48330 - dentry = f->f_path.dentry;
48331 - audit_inode(NULL, dentry);
48332 + audit_inode(NULL, f->f_path.dentry);
48333 error = mnt_want_write_file(f);
48334 if (!error) {
48335 - error = setxattr(dentry, name, value, size, flags);
48336 + error = setxattr(&f->f_path, name, value, size, flags);
48337 mnt_drop_write_file(f);
48338 }
48339 fput(f);
48340 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
48341 index 8d5a506..7f62712 100644
48342 --- a/fs/xattr_acl.c
48343 +++ b/fs/xattr_acl.c
48344 @@ -17,8 +17,8 @@
48345 struct posix_acl *
48346 posix_acl_from_xattr(const void *value, size_t size)
48347 {
48348 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
48349 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
48350 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
48351 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
48352 int count;
48353 struct posix_acl *acl;
48354 struct posix_acl_entry *acl_e;
48355 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
48356 index 188ef2f..adcf864 100644
48357 --- a/fs/xfs/xfs_bmap.c
48358 +++ b/fs/xfs/xfs_bmap.c
48359 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
48360 int nmap,
48361 int ret_nmap);
48362 #else
48363 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
48364 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
48365 #endif /* DEBUG */
48366
48367 STATIC int
48368 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
48369 index 79d05e8..e3e5861 100644
48370 --- a/fs/xfs/xfs_dir2_sf.c
48371 +++ b/fs/xfs/xfs_dir2_sf.c
48372 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
48373 }
48374
48375 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
48376 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
48377 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
48378 + char name[sfep->namelen];
48379 + memcpy(name, sfep->name, sfep->namelen);
48380 + if (filldir(dirent, name, sfep->namelen,
48381 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
48382 + *offset = off & 0x7fffffff;
48383 + return 0;
48384 + }
48385 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
48386 off & 0x7fffffff, ino, DT_UNKNOWN)) {
48387 *offset = off & 0x7fffffff;
48388 return 0;
48389 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
48390 index 76f3ca5..f57f712 100644
48391 --- a/fs/xfs/xfs_ioctl.c
48392 +++ b/fs/xfs/xfs_ioctl.c
48393 @@ -128,7 +128,7 @@ xfs_find_handle(
48394 }
48395
48396 error = -EFAULT;
48397 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
48398 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
48399 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
48400 goto out_put;
48401
48402 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
48403 index ab30253..4d86958 100644
48404 --- a/fs/xfs/xfs_iops.c
48405 +++ b/fs/xfs/xfs_iops.c
48406 @@ -447,7 +447,7 @@ xfs_vn_put_link(
48407 struct nameidata *nd,
48408 void *p)
48409 {
48410 - char *s = nd_get_link(nd);
48411 + const char *s = nd_get_link(nd);
48412
48413 if (!IS_ERR(s))
48414 kfree(s);
48415 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
48416 new file mode 100644
48417 index 0000000..4089e05
48418 --- /dev/null
48419 +++ b/grsecurity/Kconfig
48420 @@ -0,0 +1,1078 @@
48421 +#
48422 +# grecurity configuration
48423 +#
48424 +
48425 +menu "Grsecurity"
48426 +
48427 +config GRKERNSEC
48428 + bool "Grsecurity"
48429 + select CRYPTO
48430 + select CRYPTO_SHA256
48431 + help
48432 + If you say Y here, you will be able to configure many features
48433 + that will enhance the security of your system. It is highly
48434 + recommended that you say Y here and read through the help
48435 + for each option so that you fully understand the features and
48436 + can evaluate their usefulness for your machine.
48437 +
48438 +choice
48439 + prompt "Security Level"
48440 + depends on GRKERNSEC
48441 + default GRKERNSEC_CUSTOM
48442 +
48443 +config GRKERNSEC_LOW
48444 + bool "Low"
48445 + select GRKERNSEC_LINK
48446 + select GRKERNSEC_FIFO
48447 + select GRKERNSEC_RANDNET
48448 + select GRKERNSEC_DMESG
48449 + select GRKERNSEC_CHROOT
48450 + select GRKERNSEC_CHROOT_CHDIR
48451 +
48452 + help
48453 + If you choose this option, several of the grsecurity options will
48454 + be enabled that will give you greater protection against a number
48455 + of attacks, while assuring that none of your software will have any
48456 + conflicts with the additional security measures. If you run a lot
48457 + of unusual software, or you are having problems with the higher
48458 + security levels, you should say Y here. With this option, the
48459 + following features are enabled:
48460 +
48461 + - Linking restrictions
48462 + - FIFO restrictions
48463 + - Restricted dmesg
48464 + - Enforced chdir("/") on chroot
48465 + - Runtime module disabling
48466 +
48467 +config GRKERNSEC_MEDIUM
48468 + bool "Medium"
48469 + select PAX
48470 + select PAX_EI_PAX
48471 + select PAX_PT_PAX_FLAGS
48472 + select PAX_HAVE_ACL_FLAGS
48473 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
48474 + select GRKERNSEC_CHROOT
48475 + select GRKERNSEC_CHROOT_SYSCTL
48476 + select GRKERNSEC_LINK
48477 + select GRKERNSEC_FIFO
48478 + select GRKERNSEC_DMESG
48479 + select GRKERNSEC_RANDNET
48480 + select GRKERNSEC_FORKFAIL
48481 + select GRKERNSEC_TIME
48482 + select GRKERNSEC_SIGNAL
48483 + select GRKERNSEC_CHROOT
48484 + select GRKERNSEC_CHROOT_UNIX
48485 + select GRKERNSEC_CHROOT_MOUNT
48486 + select GRKERNSEC_CHROOT_PIVOT
48487 + select GRKERNSEC_CHROOT_DOUBLE
48488 + select GRKERNSEC_CHROOT_CHDIR
48489 + select GRKERNSEC_CHROOT_MKNOD
48490 + select GRKERNSEC_PROC
48491 + select GRKERNSEC_PROC_USERGROUP
48492 + select PAX_RANDUSTACK
48493 + select PAX_ASLR
48494 + select PAX_RANDMMAP
48495 + select PAX_REFCOUNT if (X86 || SPARC64)
48496 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
48497 +
48498 + help
48499 + If you say Y here, several features in addition to those included
48500 + in the low additional security level will be enabled. These
48501 + features provide even more security to your system, though in rare
48502 + cases they may be incompatible with very old or poorly written
48503 + software. If you enable this option, make sure that your auth
48504 + service (identd) is running as gid 1001. With this option,
48505 + the following features (in addition to those provided in the
48506 + low additional security level) will be enabled:
48507 +
48508 + - Failed fork logging
48509 + - Time change logging
48510 + - Signal logging
48511 + - Deny mounts in chroot
48512 + - Deny double chrooting
48513 + - Deny sysctl writes in chroot
48514 + - Deny mknod in chroot
48515 + - Deny access to abstract AF_UNIX sockets out of chroot
48516 + - Deny pivot_root in chroot
48517 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
48518 + - /proc restrictions with special GID set to 10 (usually wheel)
48519 + - Address Space Layout Randomization (ASLR)
48520 + - Prevent exploitation of most refcount overflows
48521 + - Bounds checking of copying between the kernel and userland
48522 +
48523 +config GRKERNSEC_HIGH
48524 + bool "High"
48525 + select GRKERNSEC_LINK
48526 + select GRKERNSEC_FIFO
48527 + select GRKERNSEC_DMESG
48528 + select GRKERNSEC_FORKFAIL
48529 + select GRKERNSEC_TIME
48530 + select GRKERNSEC_SIGNAL
48531 + select GRKERNSEC_CHROOT
48532 + select GRKERNSEC_CHROOT_SHMAT
48533 + select GRKERNSEC_CHROOT_UNIX
48534 + select GRKERNSEC_CHROOT_MOUNT
48535 + select GRKERNSEC_CHROOT_FCHDIR
48536 + select GRKERNSEC_CHROOT_PIVOT
48537 + select GRKERNSEC_CHROOT_DOUBLE
48538 + select GRKERNSEC_CHROOT_CHDIR
48539 + select GRKERNSEC_CHROOT_MKNOD
48540 + select GRKERNSEC_CHROOT_CAPS
48541 + select GRKERNSEC_CHROOT_SYSCTL
48542 + select GRKERNSEC_CHROOT_FINDTASK
48543 + select GRKERNSEC_SYSFS_RESTRICT
48544 + select GRKERNSEC_PROC
48545 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
48546 + select GRKERNSEC_HIDESYM
48547 + select GRKERNSEC_BRUTE
48548 + select GRKERNSEC_PROC_USERGROUP
48549 + select GRKERNSEC_KMEM
48550 + select GRKERNSEC_RESLOG
48551 + select GRKERNSEC_RANDNET
48552 + select GRKERNSEC_PROC_ADD
48553 + select GRKERNSEC_CHROOT_CHMOD
48554 + select GRKERNSEC_CHROOT_NICE
48555 + select GRKERNSEC_SETXID
48556 + select GRKERNSEC_AUDIT_MOUNT
48557 + select GRKERNSEC_MODHARDEN if (MODULES)
48558 + select GRKERNSEC_HARDEN_PTRACE
48559 + select GRKERNSEC_PTRACE_READEXEC
48560 + select GRKERNSEC_VM86 if (X86_32)
48561 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
48562 + select PAX
48563 + select PAX_RANDUSTACK
48564 + select PAX_ASLR
48565 + select PAX_RANDMMAP
48566 + select PAX_NOEXEC
48567 + select PAX_MPROTECT
48568 + select PAX_EI_PAX
48569 + select PAX_PT_PAX_FLAGS
48570 + select PAX_HAVE_ACL_FLAGS
48571 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
48572 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
48573 + select PAX_RANDKSTACK if (X86_TSC && X86)
48574 + select PAX_SEGMEXEC if (X86_32)
48575 + select PAX_PAGEEXEC
48576 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
48577 + select PAX_EMUTRAMP if (PARISC)
48578 + select PAX_EMUSIGRT if (PARISC)
48579 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
48580 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
48581 + select PAX_REFCOUNT if (X86 || SPARC64)
48582 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
48583 + help
48584 + If you say Y here, many of the features of grsecurity will be
48585 + enabled, which will protect you against many kinds of attacks
48586 + against your system. The heightened security comes at a cost
48587 + of an increased chance of incompatibilities with rare software
48588 + on your machine. Since this security level enables PaX, you should
48589 + view <http://pax.grsecurity.net> and read about the PaX
48590 + project. While you are there, download chpax and run it on
48591 + binaries that cause problems with PaX. Also remember that
48592 + since the /proc restrictions are enabled, you must run your
48593 + identd as gid 1001. This security level enables the following
48594 + features in addition to those listed in the low and medium
48595 + security levels:
48596 +
48597 + - Additional /proc restrictions
48598 + - Chmod restrictions in chroot
48599 + - No signals, ptrace, or viewing of processes outside of chroot
48600 + - Capability restrictions in chroot
48601 + - Deny fchdir out of chroot
48602 + - Priority restrictions in chroot
48603 + - Segmentation-based implementation of PaX
48604 + - Mprotect restrictions
48605 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
48606 + - Kernel stack randomization
48607 + - Mount/unmount/remount logging
48608 + - Kernel symbol hiding
48609 + - Hardening of module auto-loading
48610 + - Ptrace restrictions
48611 + - Restricted vm86 mode
48612 + - Restricted sysfs/debugfs
48613 + - Active kernel exploit response
48614 +
48615 +config GRKERNSEC_CUSTOM
48616 + bool "Custom"
48617 + help
48618 + If you say Y here, you will be able to configure every grsecurity
48619 + option, which allows you to enable many more features that aren't
48620 + covered in the basic security levels. These additional features
48621 + include TPE, socket restrictions, and the sysctl system for
48622 + grsecurity. It is advised that you read through the help for
48623 + each option to determine its usefulness in your situation.
48624 +
48625 +endchoice
48626 +
48627 +menu "Memory Protections"
48628 +depends on GRKERNSEC
48629 +
48630 +config GRKERNSEC_KMEM
48631 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
48632 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
48633 + help
48634 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
48635 + be written to or read from to modify or leak the contents of the running
48636 + kernel. /dev/port will also not be allowed to be opened. If you have module
48637 + support disabled, enabling this will close up four ways that are
48638 + currently used to insert malicious code into the running kernel.
48639 + Even with all these features enabled, we still highly recommend that
48640 + you use the RBAC system, as it is still possible for an attacker to
48641 + modify the running kernel through privileged I/O granted by ioperm/iopl.
48642 + If you are not using XFree86, you may be able to stop this additional
48643 + case by enabling the 'Disable privileged I/O' option. Though nothing
48644 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
48645 + but only to video memory, which is the only writing we allow in this
48646 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
48647 + not be allowed to mprotect it with PROT_WRITE later.
48648 + It is highly recommended that you say Y here if you meet all the
48649 + conditions above.
48650 +
48651 +config GRKERNSEC_VM86
48652 + bool "Restrict VM86 mode"
48653 + depends on X86_32
48654 +
48655 + help
48656 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
48657 + make use of a special execution mode on 32bit x86 processors called
48658 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
48659 + video cards and will still work with this option enabled. The purpose
48660 + of the option is to prevent exploitation of emulation errors in
48661 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
48662 + Nearly all users should be able to enable this option.
48663 +
48664 +config GRKERNSEC_IO
48665 + bool "Disable privileged I/O"
48666 + depends on X86
48667 + select RTC_CLASS
48668 + select RTC_INTF_DEV
48669 + select RTC_DRV_CMOS
48670 +
48671 + help
48672 + If you say Y here, all ioperm and iopl calls will return an error.
48673 + Ioperm and iopl can be used to modify the running kernel.
48674 + Unfortunately, some programs need this access to operate properly,
48675 + the most notable of which are XFree86 and hwclock. hwclock can be
48676 + remedied by having RTC support in the kernel, so real-time
48677 + clock support is enabled if this option is enabled, to ensure
48678 + that hwclock operates correctly. XFree86 still will not
48679 + operate correctly with this option enabled, so DO NOT CHOOSE Y
48680 + IF YOU USE XFree86. If you use XFree86 and you still want to
48681 + protect your kernel against modification, use the RBAC system.
48682 +
48683 +config GRKERNSEC_PROC_MEMMAP
48684 + bool "Harden ASLR against information leaks and entropy reduction"
48685 + default y if (PAX_NOEXEC || PAX_ASLR)
48686 + depends on PAX_NOEXEC || PAX_ASLR
48687 + help
48688 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
48689 + give no information about the addresses of its mappings if
48690 + PaX features that rely on random addresses are enabled on the task.
48691 + In addition to sanitizing this information and disabling other
48692 + dangerous sources of information, this option causes reads of sensitive
48693 + /proc/<pid> entries where the file descriptor was opened in a different
48694 + task than the one performing the read. Such attempts are logged.
48695 + This option also limits argv/env strings for suid/sgid binaries
48696 + to 512KB to prevent a complete exhaustion of the stack entropy provided
48697 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
48698 + binaries to prevent alternative mmap layouts from being abused.
48699 +
48700 + If you use PaX it is essential that you say Y here as it closes up
48701 + several holes that make full ASLR useless locally.
48702 +
48703 +config GRKERNSEC_BRUTE
48704 + bool "Deter exploit bruteforcing"
48705 + help
48706 + If you say Y here, attempts to bruteforce exploits against forking
48707 + daemons such as apache or sshd, as well as against suid/sgid binaries
48708 + will be deterred. When a child of a forking daemon is killed by PaX
48709 + or crashes due to an illegal instruction or other suspicious signal,
48710 + the parent process will be delayed 30 seconds upon every subsequent
48711 + fork until the administrator is able to assess the situation and
48712 + restart the daemon.
48713 + In the suid/sgid case, the attempt is logged, the user has all their
48714 + processes terminated, and they are prevented from executing any further
48715 + processes for 15 minutes.
48716 + It is recommended that you also enable signal logging in the auditing
48717 + section so that logs are generated when a process triggers a suspicious
48718 + signal.
48719 + If the sysctl option is enabled, a sysctl option with name
48720 + "deter_bruteforce" is created.
48721 +
48722 +
48723 +config GRKERNSEC_MODHARDEN
48724 + bool "Harden module auto-loading"
48725 + depends on MODULES
48726 + help
48727 + If you say Y here, module auto-loading in response to use of some
48728 + feature implemented by an unloaded module will be restricted to
48729 + root users. Enabling this option helps defend against attacks
48730 + by unprivileged users who abuse the auto-loading behavior to
48731 + cause a vulnerable module to load that is then exploited.
48732 +
48733 + If this option prevents a legitimate use of auto-loading for a
48734 + non-root user, the administrator can execute modprobe manually
48735 + with the exact name of the module mentioned in the alert log.
48736 + Alternatively, the administrator can add the module to the list
48737 + of modules loaded at boot by modifying init scripts.
48738 +
48739 + Modification of init scripts will most likely be needed on
48740 + Ubuntu servers with encrypted home directory support enabled,
48741 + as the first non-root user logging in will cause the ecb(aes),
48742 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
48743 +
48744 +config GRKERNSEC_HIDESYM
48745 + bool "Hide kernel symbols"
48746 + help
48747 + If you say Y here, getting information on loaded modules, and
48748 + displaying all kernel symbols through a syscall will be restricted
48749 + to users with CAP_SYS_MODULE. For software compatibility reasons,
48750 + /proc/kallsyms will be restricted to the root user. The RBAC
48751 + system can hide that entry even from root.
48752 +
48753 + This option also prevents leaking of kernel addresses through
48754 + several /proc entries.
48755 +
48756 + Note that this option is only effective provided the following
48757 + conditions are met:
48758 + 1) The kernel using grsecurity is not precompiled by some distribution
48759 + 2) You have also enabled GRKERNSEC_DMESG
48760 + 3) You are using the RBAC system and hiding other files such as your
48761 + kernel image and System.map. Alternatively, enabling this option
48762 + causes the permissions on /boot, /lib/modules, and the kernel
48763 + source directory to change at compile time to prevent
48764 + reading by non-root users.
48765 + If the above conditions are met, this option will aid in providing a
48766 + useful protection against local kernel exploitation of overflows
48767 + and arbitrary read/write vulnerabilities.
48768 +
48769 +config GRKERNSEC_KERN_LOCKOUT
48770 + bool "Active kernel exploit response"
48771 + depends on X86 || ARM || PPC || SPARC
48772 + help
48773 + If you say Y here, when a PaX alert is triggered due to suspicious
48774 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
48775 + or an OOPs occurs due to bad memory accesses, instead of just
48776 + terminating the offending process (and potentially allowing
48777 + a subsequent exploit from the same user), we will take one of two
48778 + actions:
48779 + If the user was root, we will panic the system
48780 + If the user was non-root, we will log the attempt, terminate
48781 + all processes owned by the user, then prevent them from creating
48782 + any new processes until the system is restarted
48783 + This deters repeated kernel exploitation/bruteforcing attempts
48784 + and is useful for later forensics.
48785 +
48786 +endmenu
48787 +menu "Role Based Access Control Options"
48788 +depends on GRKERNSEC
48789 +
48790 +config GRKERNSEC_RBAC_DEBUG
48791 + bool
48792 +
48793 +config GRKERNSEC_NO_RBAC
48794 + bool "Disable RBAC system"
48795 + help
48796 + If you say Y here, the /dev/grsec device will be removed from the kernel,
48797 + preventing the RBAC system from being enabled. You should only say Y
48798 + here if you have no intention of using the RBAC system, so as to prevent
48799 + an attacker with root access from misusing the RBAC system to hide files
48800 + and processes when loadable module support and /dev/[k]mem have been
48801 + locked down.
48802 +
48803 +config GRKERNSEC_ACL_HIDEKERN
48804 + bool "Hide kernel processes"
48805 + help
48806 + If you say Y here, all kernel threads will be hidden to all
48807 + processes but those whose subject has the "view hidden processes"
48808 + flag.
48809 +
48810 +config GRKERNSEC_ACL_MAXTRIES
48811 + int "Maximum tries before password lockout"
48812 + default 3
48813 + help
48814 + This option enforces the maximum number of times a user can attempt
48815 + to authorize themselves with the grsecurity RBAC system before being
48816 + denied the ability to attempt authorization again for a specified time.
48817 + The lower the number, the harder it will be to brute-force a password.
48818 +
48819 +config GRKERNSEC_ACL_TIMEOUT
48820 + int "Time to wait after max password tries, in seconds"
48821 + default 30
48822 + help
48823 + This option specifies the time the user must wait after attempting to
48824 + authorize to the RBAC system with the maximum number of invalid
48825 + passwords. The higher the number, the harder it will be to brute-force
48826 + a password.
48827 +
48828 +endmenu
48829 +menu "Filesystem Protections"
48830 +depends on GRKERNSEC
48831 +
48832 +config GRKERNSEC_PROC
48833 + bool "Proc restrictions"
48834 + help
48835 + If you say Y here, the permissions of the /proc filesystem
48836 + will be altered to enhance system security and privacy. You MUST
48837 + choose either a user only restriction or a user and group restriction.
48838 + Depending upon the option you choose, you can either restrict users to
48839 + see only the processes they themselves run, or choose a group that can
48840 + view all processes and files normally restricted to root if you choose
48841 + the "restrict to user only" option. NOTE: If you're running identd or
48842 + ntpd as a non-root user, you will have to run it as the group you
48843 + specify here.
48844 +
48845 +config GRKERNSEC_PROC_USER
48846 + bool "Restrict /proc to user only"
48847 + depends on GRKERNSEC_PROC
48848 + help
48849 + If you say Y here, non-root users will only be able to view their own
48850 + processes, and restricts them from viewing network-related information,
48851 + and viewing kernel symbol and module information.
48852 +
48853 +config GRKERNSEC_PROC_USERGROUP
48854 + bool "Allow special group"
48855 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
48856 + help
48857 + If you say Y here, you will be able to select a group that will be
48858 + able to view all processes and network-related information. If you've
48859 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
48860 + remain hidden. This option is useful if you want to run identd as
48861 + a non-root user.
48862 +
48863 +config GRKERNSEC_PROC_GID
48864 + int "GID for special group"
48865 + depends on GRKERNSEC_PROC_USERGROUP
48866 + default 1001
48867 +
48868 +config GRKERNSEC_PROC_ADD
48869 + bool "Additional restrictions"
48870 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
48871 + help
48872 + If you say Y here, additional restrictions will be placed on
48873 + /proc that keep normal users from viewing device information and
48874 + slabinfo information that could be useful for exploits.
48875 +
48876 +config GRKERNSEC_LINK
48877 + bool "Linking restrictions"
48878 + help
48879 + If you say Y here, /tmp race exploits will be prevented, since users
48880 + will no longer be able to follow symlinks owned by other users in
48881 + world-writable +t directories (e.g. /tmp), unless the owner of the
48882 + symlink is the owner of the directory. users will also not be
48883 + able to hardlink to files they do not own. If the sysctl option is
48884 + enabled, a sysctl option with name "linking_restrictions" is created.
48885 +
48886 +config GRKERNSEC_FIFO
48887 + bool "FIFO restrictions"
48888 + help
48889 + If you say Y here, users will not be able to write to FIFOs they don't
48890 + own in world-writable +t directories (e.g. /tmp), unless the owner of
48891 + the FIFO is the same owner of the directory it's held in. If the sysctl
48892 + option is enabled, a sysctl option with name "fifo_restrictions" is
48893 + created.
48894 +
48895 +config GRKERNSEC_SYSFS_RESTRICT
48896 + bool "Sysfs/debugfs restriction"
48897 + depends on SYSFS
48898 + help
48899 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
48900 + any filesystem normally mounted under it (e.g. debugfs) will be
48901 + mostly accessible only by root. These filesystems generally provide access
48902 + to hardware and debug information that isn't appropriate for unprivileged
48903 + users of the system. Sysfs and debugfs have also become a large source
48904 + of new vulnerabilities, ranging from infoleaks to local compromise.
48905 + There has been very little oversight with an eye toward security involved
48906 + in adding new exporters of information to these filesystems, so their
48907 + use is discouraged.
48908 + For reasons of compatibility, a few directories have been whitelisted
48909 + for access by non-root users:
48910 + /sys/fs/selinux
48911 + /sys/fs/fuse
48912 + /sys/devices/system/cpu
48913 +
48914 +config GRKERNSEC_ROFS
48915 + bool "Runtime read-only mount protection"
48916 + help
48917 + If you say Y here, a sysctl option with name "romount_protect" will
48918 + be created. By setting this option to 1 at runtime, filesystems
48919 + will be protected in the following ways:
48920 + * No new writable mounts will be allowed
48921 + * Existing read-only mounts won't be able to be remounted read/write
48922 + * Write operations will be denied on all block devices
48923 + This option acts independently of grsec_lock: once it is set to 1,
48924 + it cannot be turned off. Therefore, please be mindful of the resulting
48925 + behavior if this option is enabled in an init script on a read-only
48926 + filesystem. This feature is mainly intended for secure embedded systems.
48927 +
48928 +config GRKERNSEC_CHROOT
48929 + bool "Chroot jail restrictions"
48930 + help
48931 + If you say Y here, you will be able to choose several options that will
48932 + make breaking out of a chrooted jail much more difficult. If you
48933 + encounter no software incompatibilities with the following options, it
48934 + is recommended that you enable each one.
48935 +
48936 +config GRKERNSEC_CHROOT_MOUNT
48937 + bool "Deny mounts"
48938 + depends on GRKERNSEC_CHROOT
48939 + help
48940 + If you say Y here, processes inside a chroot will not be able to
48941 + mount or remount filesystems. If the sysctl option is enabled, a
48942 + sysctl option with name "chroot_deny_mount" is created.
48943 +
48944 +config GRKERNSEC_CHROOT_DOUBLE
48945 + bool "Deny double-chroots"
48946 + depends on GRKERNSEC_CHROOT
48947 + help
48948 + If you say Y here, processes inside a chroot will not be able to chroot
48949 + again outside the chroot. This is a widely used method of breaking
48950 + out of a chroot jail and should not be allowed. If the sysctl
48951 + option is enabled, a sysctl option with name
48952 + "chroot_deny_chroot" is created.
48953 +
48954 +config GRKERNSEC_CHROOT_PIVOT
48955 + bool "Deny pivot_root in chroot"
48956 + depends on GRKERNSEC_CHROOT
48957 + help
48958 + If you say Y here, processes inside a chroot will not be able to use
48959 + a function called pivot_root() that was introduced in Linux 2.3.41. It
48960 + works similar to chroot in that it changes the root filesystem. This
48961 + function could be misused in a chrooted process to attempt to break out
48962 + of the chroot, and therefore should not be allowed. If the sysctl
48963 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
48964 + created.
48965 +
48966 +config GRKERNSEC_CHROOT_CHDIR
48967 + bool "Enforce chdir(\"/\") on all chroots"
48968 + depends on GRKERNSEC_CHROOT
48969 + help
48970 + If you say Y here, the current working directory of all newly-chrooted
48971 + applications will be set to the the root directory of the chroot.
48972 + The man page on chroot(2) states:
48973 + Note that this call does not change the current working
48974 + directory, so that `.' can be outside the tree rooted at
48975 + `/'. In particular, the super-user can escape from a
48976 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
48977 +
48978 + It is recommended that you say Y here, since it's not known to break
48979 + any software. If the sysctl option is enabled, a sysctl option with
48980 + name "chroot_enforce_chdir" is created.
48981 +
48982 +config GRKERNSEC_CHROOT_CHMOD
48983 + bool "Deny (f)chmod +s"
48984 + depends on GRKERNSEC_CHROOT
48985 + help
48986 + If you say Y here, processes inside a chroot will not be able to chmod
48987 + or fchmod files to make them have suid or sgid bits. This protects
48988 + against another published method of breaking a chroot. If the sysctl
48989 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
48990 + created.
48991 +
48992 +config GRKERNSEC_CHROOT_FCHDIR
48993 + bool "Deny fchdir out of chroot"
48994 + depends on GRKERNSEC_CHROOT
48995 + help
48996 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
48997 + to a file descriptor of the chrooting process that points to a directory
48998 + outside the filesystem will be stopped. If the sysctl option
48999 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49000 +
49001 +config GRKERNSEC_CHROOT_MKNOD
49002 + bool "Deny mknod"
49003 + depends on GRKERNSEC_CHROOT
49004 + help
49005 + If you say Y here, processes inside a chroot will not be allowed to
49006 + mknod. The problem with using mknod inside a chroot is that it
49007 + would allow an attacker to create a device entry that is the same
49008 + as one on the physical root of your system, which could range from
49009 + anything from the console device to a device for your harddrive (which
49010 + they could then use to wipe the drive or steal data). It is recommended
49011 + that you say Y here, unless you run into software incompatibilities.
49012 + If the sysctl option is enabled, a sysctl option with name
49013 + "chroot_deny_mknod" is created.
49014 +
49015 +config GRKERNSEC_CHROOT_SHMAT
49016 + bool "Deny shmat() out of chroot"
49017 + depends on GRKERNSEC_CHROOT
49018 + help
49019 + If you say Y here, processes inside a chroot will not be able to attach
49020 + to shared memory segments that were created outside of the chroot jail.
49021 + It is recommended that you say Y here. If the sysctl option is enabled,
49022 + a sysctl option with name "chroot_deny_shmat" is created.
49023 +
49024 +config GRKERNSEC_CHROOT_UNIX
49025 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
49026 + depends on GRKERNSEC_CHROOT
49027 + help
49028 + If you say Y here, processes inside a chroot will not be able to
49029 + connect to abstract (meaning not belonging to a filesystem) Unix
49030 + domain sockets that were bound outside of a chroot. It is recommended
49031 + that you say Y here. If the sysctl option is enabled, a sysctl option
49032 + with name "chroot_deny_unix" is created.
49033 +
49034 +config GRKERNSEC_CHROOT_FINDTASK
49035 + bool "Protect outside processes"
49036 + depends on GRKERNSEC_CHROOT
49037 + help
49038 + If you say Y here, processes inside a chroot will not be able to
49039 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
49040 + getsid, or view any process outside of the chroot. If the sysctl
49041 + option is enabled, a sysctl option with name "chroot_findtask" is
49042 + created.
49043 +
49044 +config GRKERNSEC_CHROOT_NICE
49045 + bool "Restrict priority changes"
49046 + depends on GRKERNSEC_CHROOT
49047 + help
49048 + If you say Y here, processes inside a chroot will not be able to raise
49049 + the priority of processes in the chroot, or alter the priority of
49050 + processes outside the chroot. This provides more security than simply
49051 + removing CAP_SYS_NICE from the process' capability set. If the
49052 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
49053 + is created.
49054 +
49055 +config GRKERNSEC_CHROOT_SYSCTL
49056 + bool "Deny sysctl writes"
49057 + depends on GRKERNSEC_CHROOT
49058 + help
49059 + If you say Y here, an attacker in a chroot will not be able to
49060 + write to sysctl entries, either by sysctl(2) or through a /proc
49061 + interface. It is strongly recommended that you say Y here. If the
49062 + sysctl option is enabled, a sysctl option with name
49063 + "chroot_deny_sysctl" is created.
49064 +
49065 +config GRKERNSEC_CHROOT_CAPS
49066 + bool "Capability restrictions"
49067 + depends on GRKERNSEC_CHROOT
49068 + help
49069 + If you say Y here, the capabilities on all processes within a
49070 + chroot jail will be lowered to stop module insertion, raw i/o,
49071 + system and net admin tasks, rebooting the system, modifying immutable
49072 + files, modifying IPC owned by another, and changing the system time.
49073 + This is left an option because it can break some apps. Disable this
49074 + if your chrooted apps are having problems performing those kinds of
49075 + tasks. If the sysctl option is enabled, a sysctl option with
49076 + name "chroot_caps" is created.
49077 +
49078 +endmenu
49079 +menu "Kernel Auditing"
49080 +depends on GRKERNSEC
49081 +
49082 +config GRKERNSEC_AUDIT_GROUP
49083 + bool "Single group for auditing"
49084 + help
49085 + If you say Y here, the exec, chdir, and (un)mount logging features
49086 + will only operate on a group you specify. This option is recommended
49087 + if you only want to watch certain users instead of having a large
49088 + amount of logs from the entire system. If the sysctl option is enabled,
49089 + a sysctl option with name "audit_group" is created.
49090 +
49091 +config GRKERNSEC_AUDIT_GID
49092 + int "GID for auditing"
49093 + depends on GRKERNSEC_AUDIT_GROUP
49094 + default 1007
49095 +
49096 +config GRKERNSEC_EXECLOG
49097 + bool "Exec logging"
49098 + help
49099 + If you say Y here, all execve() calls will be logged (since the
49100 + other exec*() calls are frontends to execve(), all execution
49101 + will be logged). Useful for shell-servers that like to keep track
49102 + of their users. If the sysctl option is enabled, a sysctl option with
49103 + name "exec_logging" is created.
49104 + WARNING: This option when enabled will produce a LOT of logs, especially
49105 + on an active system.
49106 +
49107 +config GRKERNSEC_RESLOG
49108 + bool "Resource logging"
49109 + help
49110 + If you say Y here, all attempts to overstep resource limits will
49111 + be logged with the resource name, the requested size, and the current
49112 + limit. It is highly recommended that you say Y here. If the sysctl
49113 + option is enabled, a sysctl option with name "resource_logging" is
49114 + created. If the RBAC system is enabled, the sysctl value is ignored.
49115 +
49116 +config GRKERNSEC_CHROOT_EXECLOG
49117 + bool "Log execs within chroot"
49118 + help
49119 + If you say Y here, all executions inside a chroot jail will be logged
49120 + to syslog. This can cause a large amount of logs if certain
49121 + applications (eg. djb's daemontools) are installed on the system, and
49122 + is therefore left as an option. If the sysctl option is enabled, a
49123 + sysctl option with name "chroot_execlog" is created.
49124 +
49125 +config GRKERNSEC_AUDIT_PTRACE
49126 + bool "Ptrace logging"
49127 + help
49128 + If you say Y here, all attempts to attach to a process via ptrace
49129 + will be logged. If the sysctl option is enabled, a sysctl option
49130 + with name "audit_ptrace" is created.
49131 +
49132 +config GRKERNSEC_AUDIT_CHDIR
49133 + bool "Chdir logging"
49134 + help
49135 + If you say Y here, all chdir() calls will be logged. If the sysctl
49136 + option is enabled, a sysctl option with name "audit_chdir" is created.
49137 +
49138 +config GRKERNSEC_AUDIT_MOUNT
49139 + bool "(Un)Mount logging"
49140 + help
49141 + If you say Y here, all mounts and unmounts will be logged. If the
49142 + sysctl option is enabled, a sysctl option with name "audit_mount" is
49143 + created.
49144 +
49145 +config GRKERNSEC_SIGNAL
49146 + bool "Signal logging"
49147 + help
49148 + If you say Y here, certain important signals will be logged, such as
49149 + SIGSEGV, which will as a result inform you of when a error in a program
49150 + occurred, which in some cases could mean a possible exploit attempt.
49151 + If the sysctl option is enabled, a sysctl option with name
49152 + "signal_logging" is created.
49153 +
49154 +config GRKERNSEC_FORKFAIL
49155 + bool "Fork failure logging"
49156 + help
49157 + If you say Y here, all failed fork() attempts will be logged.
49158 + This could suggest a fork bomb, or someone attempting to overstep
49159 + their process limit. If the sysctl option is enabled, a sysctl option
49160 + with name "forkfail_logging" is created.
49161 +
49162 +config GRKERNSEC_TIME
49163 + bool "Time change logging"
49164 + help
49165 + If you say Y here, any changes of the system clock will be logged.
49166 + If the sysctl option is enabled, a sysctl option with name
49167 + "timechange_logging" is created.
49168 +
49169 +config GRKERNSEC_PROC_IPADDR
49170 + bool "/proc/<pid>/ipaddr support"
49171 + help
49172 + If you say Y here, a new entry will be added to each /proc/<pid>
49173 + directory that contains the IP address of the person using the task.
49174 + The IP is carried across local TCP and AF_UNIX stream sockets.
49175 + This information can be useful for IDS/IPSes to perform remote response
49176 + to a local attack. The entry is readable by only the owner of the
49177 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
49178 + the RBAC system), and thus does not create privacy concerns.
49179 +
49180 +config GRKERNSEC_RWXMAP_LOG
49181 + bool 'Denied RWX mmap/mprotect logging'
49182 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
49183 + help
49184 + If you say Y here, calls to mmap() and mprotect() with explicit
49185 + usage of PROT_WRITE and PROT_EXEC together will be logged when
49186 + denied by the PAX_MPROTECT feature. If the sysctl option is
49187 + enabled, a sysctl option with name "rwxmap_logging" is created.
49188 +
49189 +config GRKERNSEC_AUDIT_TEXTREL
49190 + bool 'ELF text relocations logging (READ HELP)'
49191 + depends on PAX_MPROTECT
49192 + help
49193 + If you say Y here, text relocations will be logged with the filename
49194 + of the offending library or binary. The purpose of the feature is
49195 + to help Linux distribution developers get rid of libraries and
49196 + binaries that need text relocations which hinder the future progress
49197 + of PaX. Only Linux distribution developers should say Y here, and
49198 + never on a production machine, as this option creates an information
49199 + leak that could aid an attacker in defeating the randomization of
49200 + a single memory region. If the sysctl option is enabled, a sysctl
49201 + option with name "audit_textrel" is created.
49202 +
49203 +endmenu
49204 +
49205 +menu "Executable Protections"
49206 +depends on GRKERNSEC
49207 +
49208 +config GRKERNSEC_DMESG
49209 + bool "Dmesg(8) restriction"
49210 + help
49211 + If you say Y here, non-root users will not be able to use dmesg(8)
49212 + to view up to the last 4kb of messages in the kernel's log buffer.
49213 + The kernel's log buffer often contains kernel addresses and other
49214 + identifying information useful to an attacker in fingerprinting a
49215 + system for a targeted exploit.
49216 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
49217 + created.
49218 +
49219 +config GRKERNSEC_HARDEN_PTRACE
49220 + bool "Deter ptrace-based process snooping"
49221 + help
49222 + If you say Y here, TTY sniffers and other malicious monitoring
49223 + programs implemented through ptrace will be defeated. If you
49224 + have been using the RBAC system, this option has already been
49225 + enabled for several years for all users, with the ability to make
49226 + fine-grained exceptions.
49227 +
49228 + This option only affects the ability of non-root users to ptrace
49229 + processes that are not a descendent of the ptracing process.
49230 + This means that strace ./binary and gdb ./binary will still work,
49231 + but attaching to arbitrary processes will not. If the sysctl
49232 + option is enabled, a sysctl option with name "harden_ptrace" is
49233 + created.
49234 +
49235 +config GRKERNSEC_PTRACE_READEXEC
49236 + bool "Require read access to ptrace sensitive binaries"
49237 + help
49238 + If you say Y here, unprivileged users will not be able to ptrace unreadable
49239 + binaries. This option is useful in environments that
49240 + remove the read bits (e.g. file mode 4711) from suid binaries to
49241 + prevent infoleaking of their contents. This option adds
49242 + consistency to the use of that file mode, as the binary could normally
49243 + be read out when run without privileges while ptracing.
49244 +
49245 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
49246 + is created.
49247 +
49248 +config GRKERNSEC_SETXID
49249 + bool "Enforce consistent multithreaded privileges"
49250 + help
49251 + If you say Y here, a change from a root uid to a non-root uid
49252 + in a multithreaded application will cause the resulting uids,
49253 + gids, supplementary groups, and capabilities in that thread
49254 + to be propagated to the other threads of the process. In most
49255 + cases this is unnecessary, as glibc will emulate this behavior
49256 + on behalf of the application. Other libcs do not act in the
49257 + same way, allowing the other threads of the process to continue
49258 + running with root privileges. If the sysctl option is enabled,
49259 + a sysctl option with name "consistent_setxid" is created.
49260 +
49261 +config GRKERNSEC_TPE
49262 + bool "Trusted Path Execution (TPE)"
49263 + help
49264 + If you say Y here, you will be able to choose a gid to add to the
49265 + supplementary groups of users you want to mark as "untrusted."
49266 + These users will not be able to execute any files that are not in
49267 + root-owned directories writable only by root. If the sysctl option
49268 + is enabled, a sysctl option with name "tpe" is created.
49269 +
49270 +config GRKERNSEC_TPE_ALL
49271 + bool "Partially restrict all non-root users"
49272 + depends on GRKERNSEC_TPE
49273 + help
49274 + If you say Y here, all non-root users will be covered under
49275 + a weaker TPE restriction. This is separate from, and in addition to,
49276 + the main TPE options that you have selected elsewhere. Thus, if a
49277 + "trusted" GID is chosen, this restriction applies to even that GID.
49278 + Under this restriction, all non-root users will only be allowed to
49279 + execute files in directories they own that are not group or
49280 + world-writable, or in directories owned by root and writable only by
49281 + root. If the sysctl option is enabled, a sysctl option with name
49282 + "tpe_restrict_all" is created.
49283 +
49284 +config GRKERNSEC_TPE_INVERT
49285 + bool "Invert GID option"
49286 + depends on GRKERNSEC_TPE
49287 + help
49288 + If you say Y here, the group you specify in the TPE configuration will
49289 + decide what group TPE restrictions will be *disabled* for. This
49290 + option is useful if you want TPE restrictions to be applied to most
49291 + users on the system. If the sysctl option is enabled, a sysctl option
49292 + with name "tpe_invert" is created. Unlike other sysctl options, this
49293 + entry will default to on for backward-compatibility.
49294 +
49295 +config GRKERNSEC_TPE_GID
49296 + int "GID for untrusted users"
49297 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
49298 + default 1005
49299 + help
49300 + Setting this GID determines what group TPE restrictions will be
49301 + *enabled* for. If the sysctl option is enabled, a sysctl option
49302 + with name "tpe_gid" is created.
49303 +
49304 +config GRKERNSEC_TPE_GID
49305 + int "GID for trusted users"
49306 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
49307 + default 1005
49308 + help
49309 + Setting this GID determines what group TPE restrictions will be
49310 + *disabled* for. If the sysctl option is enabled, a sysctl option
49311 + with name "tpe_gid" is created.
49312 +
49313 +endmenu
49314 +menu "Network Protections"
49315 +depends on GRKERNSEC
49316 +
49317 +config GRKERNSEC_RANDNET
49318 + bool "Larger entropy pools"
49319 + help
49320 + If you say Y here, the entropy pools used for many features of Linux
49321 + and grsecurity will be doubled in size. Since several grsecurity
49322 + features use additional randomness, it is recommended that you say Y
49323 + here. Saying Y here has a similar effect as modifying
49324 + /proc/sys/kernel/random/poolsize.
49325 +
49326 +config GRKERNSEC_BLACKHOLE
49327 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
49328 + depends on NET
49329 + help
49330 + If you say Y here, neither TCP resets nor ICMP
49331 + destination-unreachable packets will be sent in response to packets
49332 + sent to ports for which no associated listening process exists.
49333 + This feature supports both IPV4 and IPV6 and exempts the
49334 + loopback interface from blackholing. Enabling this feature
49335 + makes a host more resilient to DoS attacks and reduces network
49336 + visibility against scanners.
49337 +
49338 + The blackhole feature as-implemented is equivalent to the FreeBSD
49339 + blackhole feature, as it prevents RST responses to all packets, not
49340 + just SYNs. Under most application behavior this causes no
49341 + problems, but applications (like haproxy) may not close certain
49342 + connections in a way that cleanly terminates them on the remote
49343 + end, leaving the remote host in LAST_ACK state. Because of this
49344 + side-effect and to prevent intentional LAST_ACK DoSes, this
49345 + feature also adds automatic mitigation against such attacks.
49346 + The mitigation drastically reduces the amount of time a socket
49347 + can spend in LAST_ACK state. If you're using haproxy and not
49348 + all servers it connects to have this option enabled, consider
49349 + disabling this feature on the haproxy host.
49350 +
49351 + If the sysctl option is enabled, two sysctl options with names
49352 + "ip_blackhole" and "lastack_retries" will be created.
49353 + While "ip_blackhole" takes the standard zero/non-zero on/off
49354 + toggle, "lastack_retries" uses the same kinds of values as
49355 + "tcp_retries1" and "tcp_retries2". The default value of 4
49356 + prevents a socket from lasting more than 45 seconds in LAST_ACK
49357 + state.
49358 +
49359 +config GRKERNSEC_SOCKET
49360 + bool "Socket restrictions"
49361 + depends on NET
49362 + help
49363 + If you say Y here, you will be able to choose from several options.
49364 + If you assign a GID on your system and add it to the supplementary
49365 + groups of users you want to restrict socket access to, this patch
49366 + will perform up to three things, based on the option(s) you choose.
49367 +
49368 +config GRKERNSEC_SOCKET_ALL
49369 + bool "Deny any sockets to group"
49370 + depends on GRKERNSEC_SOCKET
49371 + help
49372 + If you say Y here, you will be able to choose a GID of whose users will
49373 + be unable to connect to other hosts from your machine or run server
49374 + applications from your machine. If the sysctl option is enabled, a
49375 + sysctl option with name "socket_all" is created.
49376 +
49377 +config GRKERNSEC_SOCKET_ALL_GID
49378 + int "GID to deny all sockets for"
49379 + depends on GRKERNSEC_SOCKET_ALL
49380 + default 1004
49381 + help
49382 + Here you can choose the GID to disable socket access for. Remember to
49383 + add the users you want socket access disabled for to the GID
49384 + specified here. If the sysctl option is enabled, a sysctl option
49385 + with name "socket_all_gid" is created.
49386 +
49387 +config GRKERNSEC_SOCKET_CLIENT
49388 + bool "Deny client sockets to group"
49389 + depends on GRKERNSEC_SOCKET
49390 + help
49391 + If you say Y here, you will be able to choose a GID of whose users will
49392 + be unable to connect to other hosts from your machine, but will be
49393 + able to run servers. If this option is enabled, all users in the group
49394 + you specify will have to use passive mode when initiating ftp transfers
49395 + from the shell on your machine. If the sysctl option is enabled, a
49396 + sysctl option with name "socket_client" is created.
49397 +
49398 +config GRKERNSEC_SOCKET_CLIENT_GID
49399 + int "GID to deny client sockets for"
49400 + depends on GRKERNSEC_SOCKET_CLIENT
49401 + default 1003
49402 + help
49403 + Here you can choose the GID to disable client socket access for.
49404 + Remember to add the users you want client socket access disabled for to
49405 + the GID specified here. If the sysctl option is enabled, a sysctl
49406 + option with name "socket_client_gid" is created.
49407 +
49408 +config GRKERNSEC_SOCKET_SERVER
49409 + bool "Deny server sockets to group"
49410 + depends on GRKERNSEC_SOCKET
49411 + help
49412 + If you say Y here, you will be able to choose a GID of whose users will
49413 + be unable to run server applications from your machine. If the sysctl
49414 + option is enabled, a sysctl option with name "socket_server" is created.
49415 +
49416 +config GRKERNSEC_SOCKET_SERVER_GID
49417 + int "GID to deny server sockets for"
49418 + depends on GRKERNSEC_SOCKET_SERVER
49419 + default 1002
49420 + help
49421 + Here you can choose the GID to disable server socket access for.
49422 + Remember to add the users you want server socket access disabled for to
49423 + the GID specified here. If the sysctl option is enabled, a sysctl
49424 + option with name "socket_server_gid" is created.
49425 +
49426 +endmenu
49427 +menu "Sysctl support"
49428 +depends on GRKERNSEC && SYSCTL
49429 +
49430 +config GRKERNSEC_SYSCTL
49431 + bool "Sysctl support"
49432 + help
49433 + If you say Y here, you will be able to change the options that
49434 + grsecurity runs with at bootup, without having to recompile your
49435 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
49436 + to enable (1) or disable (0) various features. All the sysctl entries
49437 + are mutable until the "grsec_lock" entry is set to a non-zero value.
49438 + All features enabled in the kernel configuration are disabled at boot
49439 + if you do not say Y to the "Turn on features by default" option.
49440 + All options should be set at startup, and the grsec_lock entry should
49441 + be set to a non-zero value after all the options are set.
49442 + *THIS IS EXTREMELY IMPORTANT*
49443 +
49444 +config GRKERNSEC_SYSCTL_DISTRO
49445 + bool "Extra sysctl support for distro makers (READ HELP)"
49446 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
49447 + help
49448 + If you say Y here, additional sysctl options will be created
49449 + for features that affect processes running as root. Therefore,
49450 + it is critical when using this option that the grsec_lock entry be
49451 + enabled after boot. Only distros with prebuilt kernel packages
49452 + with this option enabled that can ensure grsec_lock is enabled
49453 + after boot should use this option.
49454 + *Failure to set grsec_lock after boot makes all grsec features
49455 + this option covers useless*
49456 +
49457 + Currently this option creates the following sysctl entries:
49458 + "Disable Privileged I/O": "disable_priv_io"
49459 +
49460 +config GRKERNSEC_SYSCTL_ON
49461 + bool "Turn on features by default"
49462 + depends on GRKERNSEC_SYSCTL
49463 + help
49464 + If you say Y here, instead of having all features enabled in the
49465 + kernel configuration disabled at boot time, the features will be
49466 + enabled at boot time. It is recommended you say Y here unless
49467 + there is some reason you would want all sysctl-tunable features to
49468 + be disabled by default. As mentioned elsewhere, it is important
49469 + to enable the grsec_lock entry once you have finished modifying
49470 + the sysctl entries.
49471 +
49472 +endmenu
49473 +menu "Logging Options"
49474 +depends on GRKERNSEC
49475 +
49476 +config GRKERNSEC_FLOODTIME
49477 + int "Seconds in between log messages (minimum)"
49478 + default 10
49479 + help
49480 + This option allows you to enforce the number of seconds between
49481 + grsecurity log messages. The default should be suitable for most
49482 + people, however, if you choose to change it, choose a value small enough
49483 + to allow informative logs to be produced, but large enough to
49484 + prevent flooding.
49485 +
49486 +config GRKERNSEC_FLOODBURST
49487 + int "Number of messages in a burst (maximum)"
49488 + default 6
49489 + help
49490 + This option allows you to choose the maximum number of messages allowed
49491 + within the flood time interval you chose in a separate option. The
49492 + default should be suitable for most people, however if you find that
49493 + many of your logs are being interpreted as flooding, you may want to
49494 + raise this value.
49495 +
49496 +endmenu
49497 +
49498 +endmenu
49499 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
49500 new file mode 100644
49501 index 0000000..1b9afa9
49502 --- /dev/null
49503 +++ b/grsecurity/Makefile
49504 @@ -0,0 +1,38 @@
49505 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
49506 +# during 2001-2009 it has been completely redesigned by Brad Spengler
49507 +# into an RBAC system
49508 +#
49509 +# All code in this directory and various hooks inserted throughout the kernel
49510 +# are copyright Brad Spengler - Open Source Security, Inc., and released
49511 +# under the GPL v2 or higher
49512 +
49513 +KBUILD_CFLAGS += -Werror
49514 +
49515 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
49516 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
49517 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
49518 +
49519 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
49520 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
49521 + gracl_learn.o grsec_log.o
49522 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
49523 +
49524 +ifdef CONFIG_NET
49525 +obj-y += grsec_sock.o
49526 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
49527 +endif
49528 +
49529 +ifndef CONFIG_GRKERNSEC
49530 +obj-y += grsec_disabled.o
49531 +endif
49532 +
49533 +ifdef CONFIG_GRKERNSEC_HIDESYM
49534 +extra-y := grsec_hidesym.o
49535 +$(obj)/grsec_hidesym.o:
49536 + @-chmod -f 500 /boot
49537 + @-chmod -f 500 /lib/modules
49538 + @-chmod -f 500 /lib64/modules
49539 + @-chmod -f 500 /lib32/modules
49540 + @-chmod -f 700 .
49541 + @echo ' grsec: protected kernel image paths'
49542 +endif
49543 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
49544 new file mode 100644
49545 index 0000000..e8c5d41
49546 --- /dev/null
49547 +++ b/grsecurity/gracl.c
49548 @@ -0,0 +1,4179 @@
49549 +#include <linux/kernel.h>
49550 +#include <linux/module.h>
49551 +#include <linux/sched.h>
49552 +#include <linux/mm.h>
49553 +#include <linux/file.h>
49554 +#include <linux/fs.h>
49555 +#include <linux/namei.h>
49556 +#include <linux/mount.h>
49557 +#include <linux/tty.h>
49558 +#include <linux/proc_fs.h>
49559 +#include <linux/lglock.h>
49560 +#include <linux/slab.h>
49561 +#include <linux/vmalloc.h>
49562 +#include <linux/types.h>
49563 +#include <linux/sysctl.h>
49564 +#include <linux/netdevice.h>
49565 +#include <linux/ptrace.h>
49566 +#include <linux/gracl.h>
49567 +#include <linux/gralloc.h>
49568 +#include <linux/security.h>
49569 +#include <linux/grinternal.h>
49570 +#include <linux/pid_namespace.h>
49571 +#include <linux/fdtable.h>
49572 +#include <linux/percpu.h>
49573 +#include "../fs/mount.h"
49574 +
49575 +#include <asm/uaccess.h>
49576 +#include <asm/errno.h>
49577 +#include <asm/mman.h>
49578 +
49579 +static struct acl_role_db acl_role_set;
49580 +static struct name_db name_set;
49581 +static struct inodev_db inodev_set;
49582 +
49583 +/* for keeping track of userspace pointers used for subjects, so we
49584 + can share references in the kernel as well
49585 +*/
49586 +
49587 +static struct path real_root;
49588 +
49589 +static struct acl_subj_map_db subj_map_set;
49590 +
49591 +static struct acl_role_label *default_role;
49592 +
49593 +static struct acl_role_label *role_list;
49594 +
49595 +static u16 acl_sp_role_value;
49596 +
49597 +extern char *gr_shared_page[4];
49598 +static DEFINE_MUTEX(gr_dev_mutex);
49599 +DEFINE_RWLOCK(gr_inode_lock);
49600 +
49601 +struct gr_arg *gr_usermode;
49602 +
49603 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
49604 +
49605 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
49606 +extern void gr_clear_learn_entries(void);
49607 +
49608 +#ifdef CONFIG_GRKERNSEC_RESLOG
49609 +extern void gr_log_resource(const struct task_struct *task,
49610 + const int res, const unsigned long wanted, const int gt);
49611 +#endif
49612 +
49613 +unsigned char *gr_system_salt;
49614 +unsigned char *gr_system_sum;
49615 +
49616 +static struct sprole_pw **acl_special_roles = NULL;
49617 +static __u16 num_sprole_pws = 0;
49618 +
49619 +static struct acl_role_label *kernel_role = NULL;
49620 +
49621 +static unsigned int gr_auth_attempts = 0;
49622 +static unsigned long gr_auth_expires = 0UL;
49623 +
49624 +#ifdef CONFIG_NET
49625 +extern struct vfsmount *sock_mnt;
49626 +#endif
49627 +
49628 +extern struct vfsmount *pipe_mnt;
49629 +extern struct vfsmount *shm_mnt;
49630 +#ifdef CONFIG_HUGETLBFS
49631 +extern struct vfsmount *hugetlbfs_vfsmount;
49632 +#endif
49633 +
49634 +static struct acl_object_label *fakefs_obj_rw;
49635 +static struct acl_object_label *fakefs_obj_rwx;
49636 +
49637 +extern int gr_init_uidset(void);
49638 +extern void gr_free_uidset(void);
49639 +extern void gr_remove_uid(uid_t uid);
49640 +extern int gr_find_uid(uid_t uid);
49641 +
49642 +DECLARE_BRLOCK(vfsmount_lock);
49643 +
49644 +__inline__ int
49645 +gr_acl_is_enabled(void)
49646 +{
49647 + return (gr_status & GR_READY);
49648 +}
49649 +
49650 +#ifdef CONFIG_BTRFS_FS
49651 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
49652 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
49653 +#endif
49654 +
49655 +static inline dev_t __get_dev(const struct dentry *dentry)
49656 +{
49657 +#ifdef CONFIG_BTRFS_FS
49658 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
49659 + return get_btrfs_dev_from_inode(dentry->d_inode);
49660 + else
49661 +#endif
49662 + return dentry->d_inode->i_sb->s_dev;
49663 +}
49664 +
49665 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
49666 +{
49667 + return __get_dev(dentry);
49668 +}
49669 +
49670 +static char gr_task_roletype_to_char(struct task_struct *task)
49671 +{
49672 + switch (task->role->roletype &
49673 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
49674 + GR_ROLE_SPECIAL)) {
49675 + case GR_ROLE_DEFAULT:
49676 + return 'D';
49677 + case GR_ROLE_USER:
49678 + return 'U';
49679 + case GR_ROLE_GROUP:
49680 + return 'G';
49681 + case GR_ROLE_SPECIAL:
49682 + return 'S';
49683 + }
49684 +
49685 + return 'X';
49686 +}
49687 +
49688 +char gr_roletype_to_char(void)
49689 +{
49690 + return gr_task_roletype_to_char(current);
49691 +}
49692 +
49693 +__inline__ int
49694 +gr_acl_tpe_check(void)
49695 +{
49696 + if (unlikely(!(gr_status & GR_READY)))
49697 + return 0;
49698 + if (current->role->roletype & GR_ROLE_TPE)
49699 + return 1;
49700 + else
49701 + return 0;
49702 +}
49703 +
49704 +int
49705 +gr_handle_rawio(const struct inode *inode)
49706 +{
49707 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
49708 + if (inode && S_ISBLK(inode->i_mode) &&
49709 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
49710 + !capable(CAP_SYS_RAWIO))
49711 + return 1;
49712 +#endif
49713 + return 0;
49714 +}
49715 +
49716 +static int
49717 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
49718 +{
49719 + if (likely(lena != lenb))
49720 + return 0;
49721 +
49722 + return !memcmp(a, b, lena);
49723 +}
49724 +
49725 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
49726 +{
49727 + *buflen -= namelen;
49728 + if (*buflen < 0)
49729 + return -ENAMETOOLONG;
49730 + *buffer -= namelen;
49731 + memcpy(*buffer, str, namelen);
49732 + return 0;
49733 +}
49734 +
49735 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
49736 +{
49737 + return prepend(buffer, buflen, name->name, name->len);
49738 +}
49739 +
49740 +static int prepend_path(const struct path *path, struct path *root,
49741 + char **buffer, int *buflen)
49742 +{
49743 + struct dentry *dentry = path->dentry;
49744 + struct vfsmount *vfsmnt = path->mnt;
49745 + struct mount *mnt = real_mount(vfsmnt);
49746 + bool slash = false;
49747 + int error = 0;
49748 +
49749 + while (dentry != root->dentry || vfsmnt != root->mnt) {
49750 + struct dentry * parent;
49751 +
49752 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
49753 + /* Global root? */
49754 + if (!mnt_has_parent(mnt)) {
49755 + goto out;
49756 + }
49757 + dentry = mnt->mnt_mountpoint;
49758 + mnt = mnt->mnt_parent;
49759 + vfsmnt = &mnt->mnt;
49760 + continue;
49761 + }
49762 + parent = dentry->d_parent;
49763 + prefetch(parent);
49764 + spin_lock(&dentry->d_lock);
49765 + error = prepend_name(buffer, buflen, &dentry->d_name);
49766 + spin_unlock(&dentry->d_lock);
49767 + if (!error)
49768 + error = prepend(buffer, buflen, "/", 1);
49769 + if (error)
49770 + break;
49771 +
49772 + slash = true;
49773 + dentry = parent;
49774 + }
49775 +
49776 +out:
49777 + if (!error && !slash)
49778 + error = prepend(buffer, buflen, "/", 1);
49779 +
49780 + return error;
49781 +}
49782 +
49783 +/* this must be called with vfsmount_lock and rename_lock held */
49784 +
49785 +static char *__our_d_path(const struct path *path, struct path *root,
49786 + char *buf, int buflen)
49787 +{
49788 + char *res = buf + buflen;
49789 + int error;
49790 +
49791 + prepend(&res, &buflen, "\0", 1);
49792 + error = prepend_path(path, root, &res, &buflen);
49793 + if (error)
49794 + return ERR_PTR(error);
49795 +
49796 + return res;
49797 +}
49798 +
49799 +static char *
49800 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
49801 +{
49802 + char *retval;
49803 +
49804 + retval = __our_d_path(path, root, buf, buflen);
49805 + if (unlikely(IS_ERR(retval)))
49806 + retval = strcpy(buf, "<path too long>");
49807 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
49808 + retval[1] = '\0';
49809 +
49810 + return retval;
49811 +}
49812 +
49813 +static char *
49814 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
49815 + char *buf, int buflen)
49816 +{
49817 + struct path path;
49818 + char *res;
49819 +
49820 + path.dentry = (struct dentry *)dentry;
49821 + path.mnt = (struct vfsmount *)vfsmnt;
49822 +
49823 + /* we can use real_root.dentry, real_root.mnt, because this is only called
49824 + by the RBAC system */
49825 + res = gen_full_path(&path, &real_root, buf, buflen);
49826 +
49827 + return res;
49828 +}
49829 +
49830 +static char *
49831 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
49832 + char *buf, int buflen)
49833 +{
49834 + char *res;
49835 + struct path path;
49836 + struct path root;
49837 + struct task_struct *reaper = &init_task;
49838 +
49839 + path.dentry = (struct dentry *)dentry;
49840 + path.mnt = (struct vfsmount *)vfsmnt;
49841 +
49842 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
49843 + get_fs_root(reaper->fs, &root);
49844 +
49845 + write_seqlock(&rename_lock);
49846 + br_read_lock(vfsmount_lock);
49847 + res = gen_full_path(&path, &root, buf, buflen);
49848 + br_read_unlock(vfsmount_lock);
49849 + write_sequnlock(&rename_lock);
49850 +
49851 + path_put(&root);
49852 + return res;
49853 +}
49854 +
49855 +static char *
49856 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
49857 +{
49858 + char *ret;
49859 + write_seqlock(&rename_lock);
49860 + br_read_lock(vfsmount_lock);
49861 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
49862 + PAGE_SIZE);
49863 + br_read_unlock(vfsmount_lock);
49864 + write_sequnlock(&rename_lock);
49865 + return ret;
49866 +}
49867 +
49868 +static char *
49869 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
49870 +{
49871 + char *ret;
49872 + char *buf;
49873 + int buflen;
49874 +
49875 + write_seqlock(&rename_lock);
49876 + br_read_lock(vfsmount_lock);
49877 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
49878 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
49879 + buflen = (int)(ret - buf);
49880 + if (buflen >= 5)
49881 + prepend(&ret, &buflen, "/proc", 5);
49882 + else
49883 + ret = strcpy(buf, "<path too long>");
49884 + br_read_unlock(vfsmount_lock);
49885 + write_sequnlock(&rename_lock);
49886 + return ret;
49887 +}
49888 +
49889 +char *
49890 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
49891 +{
49892 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
49893 + PAGE_SIZE);
49894 +}
49895 +
49896 +char *
49897 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
49898 +{
49899 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
49900 + PAGE_SIZE);
49901 +}
49902 +
49903 +char *
49904 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
49905 +{
49906 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
49907 + PAGE_SIZE);
49908 +}
49909 +
49910 +char *
49911 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
49912 +{
49913 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
49914 + PAGE_SIZE);
49915 +}
49916 +
49917 +char *
49918 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
49919 +{
49920 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
49921 + PAGE_SIZE);
49922 +}
49923 +
49924 +__inline__ __u32
49925 +to_gr_audit(const __u32 reqmode)
49926 +{
49927 + /* masks off auditable permission flags, then shifts them to create
49928 + auditing flags, and adds the special case of append auditing if
49929 + we're requesting write */
49930 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
49931 +}
49932 +
49933 +struct acl_subject_label *
49934 +lookup_subject_map(const struct acl_subject_label *userp)
49935 +{
49936 + unsigned int index = shash(userp, subj_map_set.s_size);
49937 + struct subject_map *match;
49938 +
49939 + match = subj_map_set.s_hash[index];
49940 +
49941 + while (match && match->user != userp)
49942 + match = match->next;
49943 +
49944 + if (match != NULL)
49945 + return match->kernel;
49946 + else
49947 + return NULL;
49948 +}
49949 +
49950 +static void
49951 +insert_subj_map_entry(struct subject_map *subjmap)
49952 +{
49953 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
49954 + struct subject_map **curr;
49955 +
49956 + subjmap->prev = NULL;
49957 +
49958 + curr = &subj_map_set.s_hash[index];
49959 + if (*curr != NULL)
49960 + (*curr)->prev = subjmap;
49961 +
49962 + subjmap->next = *curr;
49963 + *curr = subjmap;
49964 +
49965 + return;
49966 +}
49967 +
49968 +static struct acl_role_label *
49969 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
49970 + const gid_t gid)
49971 +{
49972 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
49973 + struct acl_role_label *match;
49974 + struct role_allowed_ip *ipp;
49975 + unsigned int x;
49976 + u32 curr_ip = task->signal->curr_ip;
49977 +
49978 + task->signal->saved_ip = curr_ip;
49979 +
49980 + match = acl_role_set.r_hash[index];
49981 +
49982 + while (match) {
49983 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
49984 + for (x = 0; x < match->domain_child_num; x++) {
49985 + if (match->domain_children[x] == uid)
49986 + goto found;
49987 + }
49988 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
49989 + break;
49990 + match = match->next;
49991 + }
49992 +found:
49993 + if (match == NULL) {
49994 + try_group:
49995 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
49996 + match = acl_role_set.r_hash[index];
49997 +
49998 + while (match) {
49999 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50000 + for (x = 0; x < match->domain_child_num; x++) {
50001 + if (match->domain_children[x] == gid)
50002 + goto found2;
50003 + }
50004 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50005 + break;
50006 + match = match->next;
50007 + }
50008 +found2:
50009 + if (match == NULL)
50010 + match = default_role;
50011 + if (match->allowed_ips == NULL)
50012 + return match;
50013 + else {
50014 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50015 + if (likely
50016 + ((ntohl(curr_ip) & ipp->netmask) ==
50017 + (ntohl(ipp->addr) & ipp->netmask)))
50018 + return match;
50019 + }
50020 + match = default_role;
50021 + }
50022 + } else if (match->allowed_ips == NULL) {
50023 + return match;
50024 + } else {
50025 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50026 + if (likely
50027 + ((ntohl(curr_ip) & ipp->netmask) ==
50028 + (ntohl(ipp->addr) & ipp->netmask)))
50029 + return match;
50030 + }
50031 + goto try_group;
50032 + }
50033 +
50034 + return match;
50035 +}
50036 +
50037 +struct acl_subject_label *
50038 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
50039 + const struct acl_role_label *role)
50040 +{
50041 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50042 + struct acl_subject_label *match;
50043 +
50044 + match = role->subj_hash[index];
50045 +
50046 + while (match && (match->inode != ino || match->device != dev ||
50047 + (match->mode & GR_DELETED))) {
50048 + match = match->next;
50049 + }
50050 +
50051 + if (match && !(match->mode & GR_DELETED))
50052 + return match;
50053 + else
50054 + return NULL;
50055 +}
50056 +
50057 +struct acl_subject_label *
50058 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
50059 + const struct acl_role_label *role)
50060 +{
50061 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50062 + struct acl_subject_label *match;
50063 +
50064 + match = role->subj_hash[index];
50065 +
50066 + while (match && (match->inode != ino || match->device != dev ||
50067 + !(match->mode & GR_DELETED))) {
50068 + match = match->next;
50069 + }
50070 +
50071 + if (match && (match->mode & GR_DELETED))
50072 + return match;
50073 + else
50074 + return NULL;
50075 +}
50076 +
50077 +static struct acl_object_label *
50078 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
50079 + const struct acl_subject_label *subj)
50080 +{
50081 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50082 + struct acl_object_label *match;
50083 +
50084 + match = subj->obj_hash[index];
50085 +
50086 + while (match && (match->inode != ino || match->device != dev ||
50087 + (match->mode & GR_DELETED))) {
50088 + match = match->next;
50089 + }
50090 +
50091 + if (match && !(match->mode & GR_DELETED))
50092 + return match;
50093 + else
50094 + return NULL;
50095 +}
50096 +
50097 +static struct acl_object_label *
50098 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
50099 + const struct acl_subject_label *subj)
50100 +{
50101 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50102 + struct acl_object_label *match;
50103 +
50104 + match = subj->obj_hash[index];
50105 +
50106 + while (match && (match->inode != ino || match->device != dev ||
50107 + !(match->mode & GR_DELETED))) {
50108 + match = match->next;
50109 + }
50110 +
50111 + if (match && (match->mode & GR_DELETED))
50112 + return match;
50113 +
50114 + match = subj->obj_hash[index];
50115 +
50116 + while (match && (match->inode != ino || match->device != dev ||
50117 + (match->mode & GR_DELETED))) {
50118 + match = match->next;
50119 + }
50120 +
50121 + if (match && !(match->mode & GR_DELETED))
50122 + return match;
50123 + else
50124 + return NULL;
50125 +}
50126 +
50127 +static struct name_entry *
50128 +lookup_name_entry(const char *name)
50129 +{
50130 + unsigned int len = strlen(name);
50131 + unsigned int key = full_name_hash(name, len);
50132 + unsigned int index = key % name_set.n_size;
50133 + struct name_entry *match;
50134 +
50135 + match = name_set.n_hash[index];
50136 +
50137 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
50138 + match = match->next;
50139 +
50140 + return match;
50141 +}
50142 +
50143 +static struct name_entry *
50144 +lookup_name_entry_create(const char *name)
50145 +{
50146 + unsigned int len = strlen(name);
50147 + unsigned int key = full_name_hash(name, len);
50148 + unsigned int index = key % name_set.n_size;
50149 + struct name_entry *match;
50150 +
50151 + match = name_set.n_hash[index];
50152 +
50153 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50154 + !match->deleted))
50155 + match = match->next;
50156 +
50157 + if (match && match->deleted)
50158 + return match;
50159 +
50160 + match = name_set.n_hash[index];
50161 +
50162 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50163 + match->deleted))
50164 + match = match->next;
50165 +
50166 + if (match && !match->deleted)
50167 + return match;
50168 + else
50169 + return NULL;
50170 +}
50171 +
50172 +static struct inodev_entry *
50173 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
50174 +{
50175 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
50176 + struct inodev_entry *match;
50177 +
50178 + match = inodev_set.i_hash[index];
50179 +
50180 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
50181 + match = match->next;
50182 +
50183 + return match;
50184 +}
50185 +
50186 +static void
50187 +insert_inodev_entry(struct inodev_entry *entry)
50188 +{
50189 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
50190 + inodev_set.i_size);
50191 + struct inodev_entry **curr;
50192 +
50193 + entry->prev = NULL;
50194 +
50195 + curr = &inodev_set.i_hash[index];
50196 + if (*curr != NULL)
50197 + (*curr)->prev = entry;
50198 +
50199 + entry->next = *curr;
50200 + *curr = entry;
50201 +
50202 + return;
50203 +}
50204 +
50205 +static void
50206 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
50207 +{
50208 + unsigned int index =
50209 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
50210 + struct acl_role_label **curr;
50211 + struct acl_role_label *tmp, *tmp2;
50212 +
50213 + curr = &acl_role_set.r_hash[index];
50214 +
50215 + /* simple case, slot is empty, just set it to our role */
50216 + if (*curr == NULL) {
50217 + *curr = role;
50218 + } else {
50219 + /* example:
50220 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
50221 + 2 -> 3
50222 + */
50223 + /* first check to see if we can already be reached via this slot */
50224 + tmp = *curr;
50225 + while (tmp && tmp != role)
50226 + tmp = tmp->next;
50227 + if (tmp == role) {
50228 + /* we don't need to add ourselves to this slot's chain */
50229 + return;
50230 + }
50231 + /* we need to add ourselves to this chain, two cases */
50232 + if (role->next == NULL) {
50233 + /* simple case, append the current chain to our role */
50234 + role->next = *curr;
50235 + *curr = role;
50236 + } else {
50237 + /* 1 -> 2 -> 3 -> 4
50238 + 2 -> 3 -> 4
50239 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
50240 + */
50241 + /* trickier case: walk our role's chain until we find
50242 + the role for the start of the current slot's chain */
50243 + tmp = role;
50244 + tmp2 = *curr;
50245 + while (tmp->next && tmp->next != tmp2)
50246 + tmp = tmp->next;
50247 + if (tmp->next == tmp2) {
50248 + /* from example above, we found 3, so just
50249 + replace this slot's chain with ours */
50250 + *curr = role;
50251 + } else {
50252 + /* we didn't find a subset of our role's chain
50253 + in the current slot's chain, so append their
50254 + chain to ours, and set us as the first role in
50255 + the slot's chain
50256 +
50257 + we could fold this case with the case above,
50258 + but making it explicit for clarity
50259 + */
50260 + tmp->next = tmp2;
50261 + *curr = role;
50262 + }
50263 + }
50264 + }
50265 +
50266 + return;
50267 +}
50268 +
50269 +static void
50270 +insert_acl_role_label(struct acl_role_label *role)
50271 +{
50272 + int i;
50273 +
50274 + if (role_list == NULL) {
50275 + role_list = role;
50276 + role->prev = NULL;
50277 + } else {
50278 + role->prev = role_list;
50279 + role_list = role;
50280 + }
50281 +
50282 + /* used for hash chains */
50283 + role->next = NULL;
50284 +
50285 + if (role->roletype & GR_ROLE_DOMAIN) {
50286 + for (i = 0; i < role->domain_child_num; i++)
50287 + __insert_acl_role_label(role, role->domain_children[i]);
50288 + } else
50289 + __insert_acl_role_label(role, role->uidgid);
50290 +}
50291 +
50292 +static int
50293 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
50294 +{
50295 + struct name_entry **curr, *nentry;
50296 + struct inodev_entry *ientry;
50297 + unsigned int len = strlen(name);
50298 + unsigned int key = full_name_hash(name, len);
50299 + unsigned int index = key % name_set.n_size;
50300 +
50301 + curr = &name_set.n_hash[index];
50302 +
50303 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
50304 + curr = &((*curr)->next);
50305 +
50306 + if (*curr != NULL)
50307 + return 1;
50308 +
50309 + nentry = acl_alloc(sizeof (struct name_entry));
50310 + if (nentry == NULL)
50311 + return 0;
50312 + ientry = acl_alloc(sizeof (struct inodev_entry));
50313 + if (ientry == NULL)
50314 + return 0;
50315 + ientry->nentry = nentry;
50316 +
50317 + nentry->key = key;
50318 + nentry->name = name;
50319 + nentry->inode = inode;
50320 + nentry->device = device;
50321 + nentry->len = len;
50322 + nentry->deleted = deleted;
50323 +
50324 + nentry->prev = NULL;
50325 + curr = &name_set.n_hash[index];
50326 + if (*curr != NULL)
50327 + (*curr)->prev = nentry;
50328 + nentry->next = *curr;
50329 + *curr = nentry;
50330 +
50331 + /* insert us into the table searchable by inode/dev */
50332 + insert_inodev_entry(ientry);
50333 +
50334 + return 1;
50335 +}
50336 +
50337 +static void
50338 +insert_acl_obj_label(struct acl_object_label *obj,
50339 + struct acl_subject_label *subj)
50340 +{
50341 + unsigned int index =
50342 + fhash(obj->inode, obj->device, subj->obj_hash_size);
50343 + struct acl_object_label **curr;
50344 +
50345 +
50346 + obj->prev = NULL;
50347 +
50348 + curr = &subj->obj_hash[index];
50349 + if (*curr != NULL)
50350 + (*curr)->prev = obj;
50351 +
50352 + obj->next = *curr;
50353 + *curr = obj;
50354 +
50355 + return;
50356 +}
50357 +
50358 +static void
50359 +insert_acl_subj_label(struct acl_subject_label *obj,
50360 + struct acl_role_label *role)
50361 +{
50362 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
50363 + struct acl_subject_label **curr;
50364 +
50365 + obj->prev = NULL;
50366 +
50367 + curr = &role->subj_hash[index];
50368 + if (*curr != NULL)
50369 + (*curr)->prev = obj;
50370 +
50371 + obj->next = *curr;
50372 + *curr = obj;
50373 +
50374 + return;
50375 +}
50376 +
50377 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
50378 +
50379 +static void *
50380 +create_table(__u32 * len, int elementsize)
50381 +{
50382 + unsigned int table_sizes[] = {
50383 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
50384 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
50385 + 4194301, 8388593, 16777213, 33554393, 67108859
50386 + };
50387 + void *newtable = NULL;
50388 + unsigned int pwr = 0;
50389 +
50390 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
50391 + table_sizes[pwr] <= *len)
50392 + pwr++;
50393 +
50394 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
50395 + return newtable;
50396 +
50397 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
50398 + newtable =
50399 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
50400 + else
50401 + newtable = vmalloc(table_sizes[pwr] * elementsize);
50402 +
50403 + *len = table_sizes[pwr];
50404 +
50405 + return newtable;
50406 +}
50407 +
50408 +static int
50409 +init_variables(const struct gr_arg *arg)
50410 +{
50411 + struct task_struct *reaper = &init_task;
50412 + unsigned int stacksize;
50413 +
50414 + subj_map_set.s_size = arg->role_db.num_subjects;
50415 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
50416 + name_set.n_size = arg->role_db.num_objects;
50417 + inodev_set.i_size = arg->role_db.num_objects;
50418 +
50419 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
50420 + !name_set.n_size || !inodev_set.i_size)
50421 + return 1;
50422 +
50423 + if (!gr_init_uidset())
50424 + return 1;
50425 +
50426 + /* set up the stack that holds allocation info */
50427 +
50428 + stacksize = arg->role_db.num_pointers + 5;
50429 +
50430 + if (!acl_alloc_stack_init(stacksize))
50431 + return 1;
50432 +
50433 + /* grab reference for the real root dentry and vfsmount */
50434 + get_fs_root(reaper->fs, &real_root);
50435 +
50436 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50437 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
50438 +#endif
50439 +
50440 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
50441 + if (fakefs_obj_rw == NULL)
50442 + return 1;
50443 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
50444 +
50445 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
50446 + if (fakefs_obj_rwx == NULL)
50447 + return 1;
50448 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
50449 +
50450 + subj_map_set.s_hash =
50451 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
50452 + acl_role_set.r_hash =
50453 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
50454 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
50455 + inodev_set.i_hash =
50456 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
50457 +
50458 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
50459 + !name_set.n_hash || !inodev_set.i_hash)
50460 + return 1;
50461 +
50462 + memset(subj_map_set.s_hash, 0,
50463 + sizeof(struct subject_map *) * subj_map_set.s_size);
50464 + memset(acl_role_set.r_hash, 0,
50465 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
50466 + memset(name_set.n_hash, 0,
50467 + sizeof (struct name_entry *) * name_set.n_size);
50468 + memset(inodev_set.i_hash, 0,
50469 + sizeof (struct inodev_entry *) * inodev_set.i_size);
50470 +
50471 + return 0;
50472 +}
50473 +
50474 +/* free information not needed after startup
50475 + currently contains user->kernel pointer mappings for subjects
50476 +*/
50477 +
50478 +static void
50479 +free_init_variables(void)
50480 +{
50481 + __u32 i;
50482 +
50483 + if (subj_map_set.s_hash) {
50484 + for (i = 0; i < subj_map_set.s_size; i++) {
50485 + if (subj_map_set.s_hash[i]) {
50486 + kfree(subj_map_set.s_hash[i]);
50487 + subj_map_set.s_hash[i] = NULL;
50488 + }
50489 + }
50490 +
50491 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
50492 + PAGE_SIZE)
50493 + kfree(subj_map_set.s_hash);
50494 + else
50495 + vfree(subj_map_set.s_hash);
50496 + }
50497 +
50498 + return;
50499 +}
50500 +
50501 +static void
50502 +free_variables(void)
50503 +{
50504 + struct acl_subject_label *s;
50505 + struct acl_role_label *r;
50506 + struct task_struct *task, *task2;
50507 + unsigned int x;
50508 +
50509 + gr_clear_learn_entries();
50510 +
50511 + read_lock(&tasklist_lock);
50512 + do_each_thread(task2, task) {
50513 + task->acl_sp_role = 0;
50514 + task->acl_role_id = 0;
50515 + task->acl = NULL;
50516 + task->role = NULL;
50517 + } while_each_thread(task2, task);
50518 + read_unlock(&tasklist_lock);
50519 +
50520 + /* release the reference to the real root dentry and vfsmount */
50521 + path_put(&real_root);
50522 + memset(&real_root, 0, sizeof(real_root));
50523 +
50524 + /* free all object hash tables */
50525 +
50526 + FOR_EACH_ROLE_START(r)
50527 + if (r->subj_hash == NULL)
50528 + goto next_role;
50529 + FOR_EACH_SUBJECT_START(r, s, x)
50530 + if (s->obj_hash == NULL)
50531 + break;
50532 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
50533 + kfree(s->obj_hash);
50534 + else
50535 + vfree(s->obj_hash);
50536 + FOR_EACH_SUBJECT_END(s, x)
50537 + FOR_EACH_NESTED_SUBJECT_START(r, s)
50538 + if (s->obj_hash == NULL)
50539 + break;
50540 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
50541 + kfree(s->obj_hash);
50542 + else
50543 + vfree(s->obj_hash);
50544 + FOR_EACH_NESTED_SUBJECT_END(s)
50545 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
50546 + kfree(r->subj_hash);
50547 + else
50548 + vfree(r->subj_hash);
50549 + r->subj_hash = NULL;
50550 +next_role:
50551 + FOR_EACH_ROLE_END(r)
50552 +
50553 + acl_free_all();
50554 +
50555 + if (acl_role_set.r_hash) {
50556 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
50557 + PAGE_SIZE)
50558 + kfree(acl_role_set.r_hash);
50559 + else
50560 + vfree(acl_role_set.r_hash);
50561 + }
50562 + if (name_set.n_hash) {
50563 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
50564 + PAGE_SIZE)
50565 + kfree(name_set.n_hash);
50566 + else
50567 + vfree(name_set.n_hash);
50568 + }
50569 +
50570 + if (inodev_set.i_hash) {
50571 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
50572 + PAGE_SIZE)
50573 + kfree(inodev_set.i_hash);
50574 + else
50575 + vfree(inodev_set.i_hash);
50576 + }
50577 +
50578 + gr_free_uidset();
50579 +
50580 + memset(&name_set, 0, sizeof (struct name_db));
50581 + memset(&inodev_set, 0, sizeof (struct inodev_db));
50582 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
50583 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
50584 +
50585 + default_role = NULL;
50586 + kernel_role = NULL;
50587 + role_list = NULL;
50588 +
50589 + return;
50590 +}
50591 +
50592 +static __u32
50593 +count_user_objs(struct acl_object_label *userp)
50594 +{
50595 + struct acl_object_label o_tmp;
50596 + __u32 num = 0;
50597 +
50598 + while (userp) {
50599 + if (copy_from_user(&o_tmp, userp,
50600 + sizeof (struct acl_object_label)))
50601 + break;
50602 +
50603 + userp = o_tmp.prev;
50604 + num++;
50605 + }
50606 +
50607 + return num;
50608 +}
50609 +
50610 +static struct acl_subject_label *
50611 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
50612 +
50613 +static int
50614 +copy_user_glob(struct acl_object_label *obj)
50615 +{
50616 + struct acl_object_label *g_tmp, **guser;
50617 + unsigned int len;
50618 + char *tmp;
50619 +
50620 + if (obj->globbed == NULL)
50621 + return 0;
50622 +
50623 + guser = &obj->globbed;
50624 + while (*guser) {
50625 + g_tmp = (struct acl_object_label *)
50626 + acl_alloc(sizeof (struct acl_object_label));
50627 + if (g_tmp == NULL)
50628 + return -ENOMEM;
50629 +
50630 + if (copy_from_user(g_tmp, *guser,
50631 + sizeof (struct acl_object_label)))
50632 + return -EFAULT;
50633 +
50634 + len = strnlen_user(g_tmp->filename, PATH_MAX);
50635 +
50636 + if (!len || len >= PATH_MAX)
50637 + return -EINVAL;
50638 +
50639 + if ((tmp = (char *) acl_alloc(len)) == NULL)
50640 + return -ENOMEM;
50641 +
50642 + if (copy_from_user(tmp, g_tmp->filename, len))
50643 + return -EFAULT;
50644 + tmp[len-1] = '\0';
50645 + g_tmp->filename = tmp;
50646 +
50647 + *guser = g_tmp;
50648 + guser = &(g_tmp->next);
50649 + }
50650 +
50651 + return 0;
50652 +}
50653 +
50654 +static int
50655 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
50656 + struct acl_role_label *role)
50657 +{
50658 + struct acl_object_label *o_tmp;
50659 + unsigned int len;
50660 + int ret;
50661 + char *tmp;
50662 +
50663 + while (userp) {
50664 + if ((o_tmp = (struct acl_object_label *)
50665 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
50666 + return -ENOMEM;
50667 +
50668 + if (copy_from_user(o_tmp, userp,
50669 + sizeof (struct acl_object_label)))
50670 + return -EFAULT;
50671 +
50672 + userp = o_tmp->prev;
50673 +
50674 + len = strnlen_user(o_tmp->filename, PATH_MAX);
50675 +
50676 + if (!len || len >= PATH_MAX)
50677 + return -EINVAL;
50678 +
50679 + if ((tmp = (char *) acl_alloc(len)) == NULL)
50680 + return -ENOMEM;
50681 +
50682 + if (copy_from_user(tmp, o_tmp->filename, len))
50683 + return -EFAULT;
50684 + tmp[len-1] = '\0';
50685 + o_tmp->filename = tmp;
50686 +
50687 + insert_acl_obj_label(o_tmp, subj);
50688 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
50689 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
50690 + return -ENOMEM;
50691 +
50692 + ret = copy_user_glob(o_tmp);
50693 + if (ret)
50694 + return ret;
50695 +
50696 + if (o_tmp->nested) {
50697 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
50698 + if (IS_ERR(o_tmp->nested))
50699 + return PTR_ERR(o_tmp->nested);
50700 +
50701 + /* insert into nested subject list */
50702 + o_tmp->nested->next = role->hash->first;
50703 + role->hash->first = o_tmp->nested;
50704 + }
50705 + }
50706 +
50707 + return 0;
50708 +}
50709 +
50710 +static __u32
50711 +count_user_subjs(struct acl_subject_label *userp)
50712 +{
50713 + struct acl_subject_label s_tmp;
50714 + __u32 num = 0;
50715 +
50716 + while (userp) {
50717 + if (copy_from_user(&s_tmp, userp,
50718 + sizeof (struct acl_subject_label)))
50719 + break;
50720 +
50721 + userp = s_tmp.prev;
50722 + /* do not count nested subjects against this count, since
50723 + they are not included in the hash table, but are
50724 + attached to objects. We have already counted
50725 + the subjects in userspace for the allocation
50726 + stack
50727 + */
50728 + if (!(s_tmp.mode & GR_NESTED))
50729 + num++;
50730 + }
50731 +
50732 + return num;
50733 +}
50734 +
50735 +static int
50736 +copy_user_allowedips(struct acl_role_label *rolep)
50737 +{
50738 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
50739 +
50740 + ruserip = rolep->allowed_ips;
50741 +
50742 + while (ruserip) {
50743 + rlast = rtmp;
50744 +
50745 + if ((rtmp = (struct role_allowed_ip *)
50746 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
50747 + return -ENOMEM;
50748 +
50749 + if (copy_from_user(rtmp, ruserip,
50750 + sizeof (struct role_allowed_ip)))
50751 + return -EFAULT;
50752 +
50753 + ruserip = rtmp->prev;
50754 +
50755 + if (!rlast) {
50756 + rtmp->prev = NULL;
50757 + rolep->allowed_ips = rtmp;
50758 + } else {
50759 + rlast->next = rtmp;
50760 + rtmp->prev = rlast;
50761 + }
50762 +
50763 + if (!ruserip)
50764 + rtmp->next = NULL;
50765 + }
50766 +
50767 + return 0;
50768 +}
50769 +
50770 +static int
50771 +copy_user_transitions(struct acl_role_label *rolep)
50772 +{
50773 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
50774 +
50775 + unsigned int len;
50776 + char *tmp;
50777 +
50778 + rusertp = rolep->transitions;
50779 +
50780 + while (rusertp) {
50781 + rlast = rtmp;
50782 +
50783 + if ((rtmp = (struct role_transition *)
50784 + acl_alloc(sizeof (struct role_transition))) == NULL)
50785 + return -ENOMEM;
50786 +
50787 + if (copy_from_user(rtmp, rusertp,
50788 + sizeof (struct role_transition)))
50789 + return -EFAULT;
50790 +
50791 + rusertp = rtmp->prev;
50792 +
50793 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
50794 +
50795 + if (!len || len >= GR_SPROLE_LEN)
50796 + return -EINVAL;
50797 +
50798 + if ((tmp = (char *) acl_alloc(len)) == NULL)
50799 + return -ENOMEM;
50800 +
50801 + if (copy_from_user(tmp, rtmp->rolename, len))
50802 + return -EFAULT;
50803 + tmp[len-1] = '\0';
50804 + rtmp->rolename = tmp;
50805 +
50806 + if (!rlast) {
50807 + rtmp->prev = NULL;
50808 + rolep->transitions = rtmp;
50809 + } else {
50810 + rlast->next = rtmp;
50811 + rtmp->prev = rlast;
50812 + }
50813 +
50814 + if (!rusertp)
50815 + rtmp->next = NULL;
50816 + }
50817 +
50818 + return 0;
50819 +}
50820 +
50821 +static struct acl_subject_label *
50822 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
50823 +{
50824 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
50825 + unsigned int len;
50826 + char *tmp;
50827 + __u32 num_objs;
50828 + struct acl_ip_label **i_tmp, *i_utmp2;
50829 + struct gr_hash_struct ghash;
50830 + struct subject_map *subjmap;
50831 + unsigned int i_num;
50832 + int err;
50833 +
50834 + s_tmp = lookup_subject_map(userp);
50835 +
50836 + /* we've already copied this subject into the kernel, just return
50837 + the reference to it, and don't copy it over again
50838 + */
50839 + if (s_tmp)
50840 + return(s_tmp);
50841 +
50842 + if ((s_tmp = (struct acl_subject_label *)
50843 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
50844 + return ERR_PTR(-ENOMEM);
50845 +
50846 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
50847 + if (subjmap == NULL)
50848 + return ERR_PTR(-ENOMEM);
50849 +
50850 + subjmap->user = userp;
50851 + subjmap->kernel = s_tmp;
50852 + insert_subj_map_entry(subjmap);
50853 +
50854 + if (copy_from_user(s_tmp, userp,
50855 + sizeof (struct acl_subject_label)))
50856 + return ERR_PTR(-EFAULT);
50857 +
50858 + len = strnlen_user(s_tmp->filename, PATH_MAX);
50859 +
50860 + if (!len || len >= PATH_MAX)
50861 + return ERR_PTR(-EINVAL);
50862 +
50863 + if ((tmp = (char *) acl_alloc(len)) == NULL)
50864 + return ERR_PTR(-ENOMEM);
50865 +
50866 + if (copy_from_user(tmp, s_tmp->filename, len))
50867 + return ERR_PTR(-EFAULT);
50868 + tmp[len-1] = '\0';
50869 + s_tmp->filename = tmp;
50870 +
50871 + if (!strcmp(s_tmp->filename, "/"))
50872 + role->root_label = s_tmp;
50873 +
50874 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
50875 + return ERR_PTR(-EFAULT);
50876 +
50877 + /* copy user and group transition tables */
50878 +
50879 + if (s_tmp->user_trans_num) {
50880 + uid_t *uidlist;
50881 +
50882 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
50883 + if (uidlist == NULL)
50884 + return ERR_PTR(-ENOMEM);
50885 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
50886 + return ERR_PTR(-EFAULT);
50887 +
50888 + s_tmp->user_transitions = uidlist;
50889 + }
50890 +
50891 + if (s_tmp->group_trans_num) {
50892 + gid_t *gidlist;
50893 +
50894 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
50895 + if (gidlist == NULL)
50896 + return ERR_PTR(-ENOMEM);
50897 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
50898 + return ERR_PTR(-EFAULT);
50899 +
50900 + s_tmp->group_transitions = gidlist;
50901 + }
50902 +
50903 + /* set up object hash table */
50904 + num_objs = count_user_objs(ghash.first);
50905 +
50906 + s_tmp->obj_hash_size = num_objs;
50907 + s_tmp->obj_hash =
50908 + (struct acl_object_label **)
50909 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
50910 +
50911 + if (!s_tmp->obj_hash)
50912 + return ERR_PTR(-ENOMEM);
50913 +
50914 + memset(s_tmp->obj_hash, 0,
50915 + s_tmp->obj_hash_size *
50916 + sizeof (struct acl_object_label *));
50917 +
50918 + /* add in objects */
50919 + err = copy_user_objs(ghash.first, s_tmp, role);
50920 +
50921 + if (err)
50922 + return ERR_PTR(err);
50923 +
50924 + /* set pointer for parent subject */
50925 + if (s_tmp->parent_subject) {
50926 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
50927 +
50928 + if (IS_ERR(s_tmp2))
50929 + return s_tmp2;
50930 +
50931 + s_tmp->parent_subject = s_tmp2;
50932 + }
50933 +
50934 + /* add in ip acls */
50935 +
50936 + if (!s_tmp->ip_num) {
50937 + s_tmp->ips = NULL;
50938 + goto insert;
50939 + }
50940 +
50941 + i_tmp =
50942 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
50943 + sizeof (struct acl_ip_label *));
50944 +
50945 + if (!i_tmp)
50946 + return ERR_PTR(-ENOMEM);
50947 +
50948 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
50949 + *(i_tmp + i_num) =
50950 + (struct acl_ip_label *)
50951 + acl_alloc(sizeof (struct acl_ip_label));
50952 + if (!*(i_tmp + i_num))
50953 + return ERR_PTR(-ENOMEM);
50954 +
50955 + if (copy_from_user
50956 + (&i_utmp2, s_tmp->ips + i_num,
50957 + sizeof (struct acl_ip_label *)))
50958 + return ERR_PTR(-EFAULT);
50959 +
50960 + if (copy_from_user
50961 + (*(i_tmp + i_num), i_utmp2,
50962 + sizeof (struct acl_ip_label)))
50963 + return ERR_PTR(-EFAULT);
50964 +
50965 + if ((*(i_tmp + i_num))->iface == NULL)
50966 + continue;
50967 +
50968 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
50969 + if (!len || len >= IFNAMSIZ)
50970 + return ERR_PTR(-EINVAL);
50971 + tmp = acl_alloc(len);
50972 + if (tmp == NULL)
50973 + return ERR_PTR(-ENOMEM);
50974 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
50975 + return ERR_PTR(-EFAULT);
50976 + (*(i_tmp + i_num))->iface = tmp;
50977 + }
50978 +
50979 + s_tmp->ips = i_tmp;
50980 +
50981 +insert:
50982 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
50983 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
50984 + return ERR_PTR(-ENOMEM);
50985 +
50986 + return s_tmp;
50987 +}
50988 +
50989 +static int
50990 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
50991 +{
50992 + struct acl_subject_label s_pre;
50993 + struct acl_subject_label * ret;
50994 + int err;
50995 +
50996 + while (userp) {
50997 + if (copy_from_user(&s_pre, userp,
50998 + sizeof (struct acl_subject_label)))
50999 + return -EFAULT;
51000 +
51001 + /* do not add nested subjects here, add
51002 + while parsing objects
51003 + */
51004 +
51005 + if (s_pre.mode & GR_NESTED) {
51006 + userp = s_pre.prev;
51007 + continue;
51008 + }
51009 +
51010 + ret = do_copy_user_subj(userp, role);
51011 +
51012 + err = PTR_ERR(ret);
51013 + if (IS_ERR(ret))
51014 + return err;
51015 +
51016 + insert_acl_subj_label(ret, role);
51017 +
51018 + userp = s_pre.prev;
51019 + }
51020 +
51021 + return 0;
51022 +}
51023 +
51024 +static int
51025 +copy_user_acl(struct gr_arg *arg)
51026 +{
51027 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
51028 + struct sprole_pw *sptmp;
51029 + struct gr_hash_struct *ghash;
51030 + uid_t *domainlist;
51031 + unsigned int r_num;
51032 + unsigned int len;
51033 + char *tmp;
51034 + int err = 0;
51035 + __u16 i;
51036 + __u32 num_subjs;
51037 +
51038 + /* we need a default and kernel role */
51039 + if (arg->role_db.num_roles < 2)
51040 + return -EINVAL;
51041 +
51042 + /* copy special role authentication info from userspace */
51043 +
51044 + num_sprole_pws = arg->num_sprole_pws;
51045 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
51046 +
51047 + if (!acl_special_roles && num_sprole_pws)
51048 + return -ENOMEM;
51049 +
51050 + for (i = 0; i < num_sprole_pws; i++) {
51051 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
51052 + if (!sptmp)
51053 + return -ENOMEM;
51054 + if (copy_from_user(sptmp, arg->sprole_pws + i,
51055 + sizeof (struct sprole_pw)))
51056 + return -EFAULT;
51057 +
51058 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
51059 +
51060 + if (!len || len >= GR_SPROLE_LEN)
51061 + return -EINVAL;
51062 +
51063 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51064 + return -ENOMEM;
51065 +
51066 + if (copy_from_user(tmp, sptmp->rolename, len))
51067 + return -EFAULT;
51068 +
51069 + tmp[len-1] = '\0';
51070 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51071 + printk(KERN_ALERT "Copying special role %s\n", tmp);
51072 +#endif
51073 + sptmp->rolename = tmp;
51074 + acl_special_roles[i] = sptmp;
51075 + }
51076 +
51077 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
51078 +
51079 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
51080 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
51081 +
51082 + if (!r_tmp)
51083 + return -ENOMEM;
51084 +
51085 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
51086 + sizeof (struct acl_role_label *)))
51087 + return -EFAULT;
51088 +
51089 + if (copy_from_user(r_tmp, r_utmp2,
51090 + sizeof (struct acl_role_label)))
51091 + return -EFAULT;
51092 +
51093 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
51094 +
51095 + if (!len || len >= PATH_MAX)
51096 + return -EINVAL;
51097 +
51098 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51099 + return -ENOMEM;
51100 +
51101 + if (copy_from_user(tmp, r_tmp->rolename, len))
51102 + return -EFAULT;
51103 +
51104 + tmp[len-1] = '\0';
51105 + r_tmp->rolename = tmp;
51106 +
51107 + if (!strcmp(r_tmp->rolename, "default")
51108 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
51109 + default_role = r_tmp;
51110 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
51111 + kernel_role = r_tmp;
51112 + }
51113 +
51114 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
51115 + return -ENOMEM;
51116 +
51117 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
51118 + return -EFAULT;
51119 +
51120 + r_tmp->hash = ghash;
51121 +
51122 + num_subjs = count_user_subjs(r_tmp->hash->first);
51123 +
51124 + r_tmp->subj_hash_size = num_subjs;
51125 + r_tmp->subj_hash =
51126 + (struct acl_subject_label **)
51127 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
51128 +
51129 + if (!r_tmp->subj_hash)
51130 + return -ENOMEM;
51131 +
51132 + err = copy_user_allowedips(r_tmp);
51133 + if (err)
51134 + return err;
51135 +
51136 + /* copy domain info */
51137 + if (r_tmp->domain_children != NULL) {
51138 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
51139 + if (domainlist == NULL)
51140 + return -ENOMEM;
51141 +
51142 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
51143 + return -EFAULT;
51144 +
51145 + r_tmp->domain_children = domainlist;
51146 + }
51147 +
51148 + err = copy_user_transitions(r_tmp);
51149 + if (err)
51150 + return err;
51151 +
51152 + memset(r_tmp->subj_hash, 0,
51153 + r_tmp->subj_hash_size *
51154 + sizeof (struct acl_subject_label *));
51155 +
51156 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
51157 +
51158 + if (err)
51159 + return err;
51160 +
51161 + /* set nested subject list to null */
51162 + r_tmp->hash->first = NULL;
51163 +
51164 + insert_acl_role_label(r_tmp);
51165 + }
51166 +
51167 + if (default_role == NULL || kernel_role == NULL)
51168 + return -EINVAL;
51169 +
51170 + return err;
51171 +}
51172 +
51173 +static int
51174 +gracl_init(struct gr_arg *args)
51175 +{
51176 + int error = 0;
51177 +
51178 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
51179 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
51180 +
51181 + if (init_variables(args)) {
51182 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
51183 + error = -ENOMEM;
51184 + free_variables();
51185 + goto out;
51186 + }
51187 +
51188 + error = copy_user_acl(args);
51189 + free_init_variables();
51190 + if (error) {
51191 + free_variables();
51192 + goto out;
51193 + }
51194 +
51195 + if ((error = gr_set_acls(0))) {
51196 + free_variables();
51197 + goto out;
51198 + }
51199 +
51200 + pax_open_kernel();
51201 + gr_status |= GR_READY;
51202 + pax_close_kernel();
51203 +
51204 + out:
51205 + return error;
51206 +}
51207 +
51208 +/* derived from glibc fnmatch() 0: match, 1: no match*/
51209 +
51210 +static int
51211 +glob_match(const char *p, const char *n)
51212 +{
51213 + char c;
51214 +
51215 + while ((c = *p++) != '\0') {
51216 + switch (c) {
51217 + case '?':
51218 + if (*n == '\0')
51219 + return 1;
51220 + else if (*n == '/')
51221 + return 1;
51222 + break;
51223 + case '\\':
51224 + if (*n != c)
51225 + return 1;
51226 + break;
51227 + case '*':
51228 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
51229 + if (*n == '/')
51230 + return 1;
51231 + else if (c == '?') {
51232 + if (*n == '\0')
51233 + return 1;
51234 + else
51235 + ++n;
51236 + }
51237 + }
51238 + if (c == '\0') {
51239 + return 0;
51240 + } else {
51241 + const char *endp;
51242 +
51243 + if ((endp = strchr(n, '/')) == NULL)
51244 + endp = n + strlen(n);
51245 +
51246 + if (c == '[') {
51247 + for (--p; n < endp; ++n)
51248 + if (!glob_match(p, n))
51249 + return 0;
51250 + } else if (c == '/') {
51251 + while (*n != '\0' && *n != '/')
51252 + ++n;
51253 + if (*n == '/' && !glob_match(p, n + 1))
51254 + return 0;
51255 + } else {
51256 + for (--p; n < endp; ++n)
51257 + if (*n == c && !glob_match(p, n))
51258 + return 0;
51259 + }
51260 +
51261 + return 1;
51262 + }
51263 + case '[':
51264 + {
51265 + int not;
51266 + char cold;
51267 +
51268 + if (*n == '\0' || *n == '/')
51269 + return 1;
51270 +
51271 + not = (*p == '!' || *p == '^');
51272 + if (not)
51273 + ++p;
51274 +
51275 + c = *p++;
51276 + for (;;) {
51277 + unsigned char fn = (unsigned char)*n;
51278 +
51279 + if (c == '\0')
51280 + return 1;
51281 + else {
51282 + if (c == fn)
51283 + goto matched;
51284 + cold = c;
51285 + c = *p++;
51286 +
51287 + if (c == '-' && *p != ']') {
51288 + unsigned char cend = *p++;
51289 +
51290 + if (cend == '\0')
51291 + return 1;
51292 +
51293 + if (cold <= fn && fn <= cend)
51294 + goto matched;
51295 +
51296 + c = *p++;
51297 + }
51298 + }
51299 +
51300 + if (c == ']')
51301 + break;
51302 + }
51303 + if (!not)
51304 + return 1;
51305 + break;
51306 + matched:
51307 + while (c != ']') {
51308 + if (c == '\0')
51309 + return 1;
51310 +
51311 + c = *p++;
51312 + }
51313 + if (not)
51314 + return 1;
51315 + }
51316 + break;
51317 + default:
51318 + if (c != *n)
51319 + return 1;
51320 + }
51321 +
51322 + ++n;
51323 + }
51324 +
51325 + if (*n == '\0')
51326 + return 0;
51327 +
51328 + if (*n == '/')
51329 + return 0;
51330 +
51331 + return 1;
51332 +}
51333 +
51334 +static struct acl_object_label *
51335 +chk_glob_label(struct acl_object_label *globbed,
51336 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
51337 +{
51338 + struct acl_object_label *tmp;
51339 +
51340 + if (*path == NULL)
51341 + *path = gr_to_filename_nolock(dentry, mnt);
51342 +
51343 + tmp = globbed;
51344 +
51345 + while (tmp) {
51346 + if (!glob_match(tmp->filename, *path))
51347 + return tmp;
51348 + tmp = tmp->next;
51349 + }
51350 +
51351 + return NULL;
51352 +}
51353 +
51354 +static struct acl_object_label *
51355 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51356 + const ino_t curr_ino, const dev_t curr_dev,
51357 + const struct acl_subject_label *subj, char **path, const int checkglob)
51358 +{
51359 + struct acl_subject_label *tmpsubj;
51360 + struct acl_object_label *retval;
51361 + struct acl_object_label *retval2;
51362 +
51363 + tmpsubj = (struct acl_subject_label *) subj;
51364 + read_lock(&gr_inode_lock);
51365 + do {
51366 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
51367 + if (retval) {
51368 + if (checkglob && retval->globbed) {
51369 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
51370 + if (retval2)
51371 + retval = retval2;
51372 + }
51373 + break;
51374 + }
51375 + } while ((tmpsubj = tmpsubj->parent_subject));
51376 + read_unlock(&gr_inode_lock);
51377 +
51378 + return retval;
51379 +}
51380 +
51381 +static __inline__ struct acl_object_label *
51382 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51383 + struct dentry *curr_dentry,
51384 + const struct acl_subject_label *subj, char **path, const int checkglob)
51385 +{
51386 + int newglob = checkglob;
51387 + ino_t inode;
51388 + dev_t device;
51389 +
51390 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
51391 + as we don't want a / * rule to match instead of the / object
51392 + don't do this for create lookups that call this function though, since they're looking up
51393 + on the parent and thus need globbing checks on all paths
51394 + */
51395 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
51396 + newglob = GR_NO_GLOB;
51397 +
51398 + spin_lock(&curr_dentry->d_lock);
51399 + inode = curr_dentry->d_inode->i_ino;
51400 + device = __get_dev(curr_dentry);
51401 + spin_unlock(&curr_dentry->d_lock);
51402 +
51403 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
51404 +}
51405 +
51406 +static struct acl_object_label *
51407 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51408 + const struct acl_subject_label *subj, char *path, const int checkglob)
51409 +{
51410 + struct dentry *dentry = (struct dentry *) l_dentry;
51411 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
51412 + struct mount *real_mnt = real_mount(mnt);
51413 + struct acl_object_label *retval;
51414 + struct dentry *parent;
51415 +
51416 + write_seqlock(&rename_lock);
51417 + br_read_lock(vfsmount_lock);
51418 +
51419 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
51420 +#ifdef CONFIG_NET
51421 + mnt == sock_mnt ||
51422 +#endif
51423 +#ifdef CONFIG_HUGETLBFS
51424 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
51425 +#endif
51426 + /* ignore Eric Biederman */
51427 + IS_PRIVATE(l_dentry->d_inode))) {
51428 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
51429 + goto out;
51430 + }
51431 +
51432 + for (;;) {
51433 + if (dentry == real_root.dentry && mnt == real_root.mnt)
51434 + break;
51435 +
51436 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
51437 + if (!mnt_has_parent(real_mnt))
51438 + break;
51439 +
51440 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51441 + if (retval != NULL)
51442 + goto out;
51443 +
51444 + dentry = real_mnt->mnt_mountpoint;
51445 + real_mnt = real_mnt->mnt_parent;
51446 + mnt = &real_mnt->mnt;
51447 + continue;
51448 + }
51449 +
51450 + parent = dentry->d_parent;
51451 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51452 + if (retval != NULL)
51453 + goto out;
51454 +
51455 + dentry = parent;
51456 + }
51457 +
51458 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51459 +
51460 + /* real_root is pinned so we don't have to hold a reference */
51461 + if (retval == NULL)
51462 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
51463 +out:
51464 + br_read_unlock(vfsmount_lock);
51465 + write_sequnlock(&rename_lock);
51466 +
51467 + BUG_ON(retval == NULL);
51468 +
51469 + return retval;
51470 +}
51471 +
51472 +static __inline__ struct acl_object_label *
51473 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51474 + const struct acl_subject_label *subj)
51475 +{
51476 + char *path = NULL;
51477 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
51478 +}
51479 +
51480 +static __inline__ struct acl_object_label *
51481 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51482 + const struct acl_subject_label *subj)
51483 +{
51484 + char *path = NULL;
51485 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
51486 +}
51487 +
51488 +static __inline__ struct acl_object_label *
51489 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51490 + const struct acl_subject_label *subj, char *path)
51491 +{
51492 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
51493 +}
51494 +
51495 +static struct acl_subject_label *
51496 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51497 + const struct acl_role_label *role)
51498 +{
51499 + struct dentry *dentry = (struct dentry *) l_dentry;
51500 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
51501 + struct mount *real_mnt = real_mount(mnt);
51502 + struct acl_subject_label *retval;
51503 + struct dentry *parent;
51504 +
51505 + write_seqlock(&rename_lock);
51506 + br_read_lock(vfsmount_lock);
51507 +
51508 + for (;;) {
51509 + if (dentry == real_root.dentry && mnt == real_root.mnt)
51510 + break;
51511 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
51512 + if (!mnt_has_parent(real_mnt))
51513 + break;
51514 +
51515 + spin_lock(&dentry->d_lock);
51516 + read_lock(&gr_inode_lock);
51517 + retval =
51518 + lookup_acl_subj_label(dentry->d_inode->i_ino,
51519 + __get_dev(dentry), role);
51520 + read_unlock(&gr_inode_lock);
51521 + spin_unlock(&dentry->d_lock);
51522 + if (retval != NULL)
51523 + goto out;
51524 +
51525 + dentry = real_mnt->mnt_mountpoint;
51526 + real_mnt = real_mnt->mnt_parent;
51527 + mnt = &real_mnt->mnt;
51528 + continue;
51529 + }
51530 +
51531 + spin_lock(&dentry->d_lock);
51532 + read_lock(&gr_inode_lock);
51533 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
51534 + __get_dev(dentry), role);
51535 + read_unlock(&gr_inode_lock);
51536 + parent = dentry->d_parent;
51537 + spin_unlock(&dentry->d_lock);
51538 +
51539 + if (retval != NULL)
51540 + goto out;
51541 +
51542 + dentry = parent;
51543 + }
51544 +
51545 + spin_lock(&dentry->d_lock);
51546 + read_lock(&gr_inode_lock);
51547 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
51548 + __get_dev(dentry), role);
51549 + read_unlock(&gr_inode_lock);
51550 + spin_unlock(&dentry->d_lock);
51551 +
51552 + if (unlikely(retval == NULL)) {
51553 + /* real_root is pinned, we don't need to hold a reference */
51554 + read_lock(&gr_inode_lock);
51555 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
51556 + __get_dev(real_root.dentry), role);
51557 + read_unlock(&gr_inode_lock);
51558 + }
51559 +out:
51560 + br_read_unlock(vfsmount_lock);
51561 + write_sequnlock(&rename_lock);
51562 +
51563 + BUG_ON(retval == NULL);
51564 +
51565 + return retval;
51566 +}
51567 +
51568 +static void
51569 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
51570 +{
51571 + struct task_struct *task = current;
51572 + const struct cred *cred = current_cred();
51573 +
51574 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
51575 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51576 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51577 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
51578 +
51579 + return;
51580 +}
51581 +
51582 +static void
51583 +gr_log_learn_sysctl(const char *path, const __u32 mode)
51584 +{
51585 + struct task_struct *task = current;
51586 + const struct cred *cred = current_cred();
51587 +
51588 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
51589 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51590 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51591 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
51592 +
51593 + return;
51594 +}
51595 +
51596 +static void
51597 +gr_log_learn_id_change(const char type, const unsigned int real,
51598 + const unsigned int effective, const unsigned int fs)
51599 +{
51600 + struct task_struct *task = current;
51601 + const struct cred *cred = current_cred();
51602 +
51603 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
51604 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51605 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51606 + type, real, effective, fs, &task->signal->saved_ip);
51607 +
51608 + return;
51609 +}
51610 +
51611 +__u32
51612 +gr_search_file(const struct dentry * dentry, const __u32 mode,
51613 + const struct vfsmount * mnt)
51614 +{
51615 + __u32 retval = mode;
51616 + struct acl_subject_label *curracl;
51617 + struct acl_object_label *currobj;
51618 +
51619 + if (unlikely(!(gr_status & GR_READY)))
51620 + return (mode & ~GR_AUDITS);
51621 +
51622 + curracl = current->acl;
51623 +
51624 + currobj = chk_obj_label(dentry, mnt, curracl);
51625 + retval = currobj->mode & mode;
51626 +
51627 + /* if we're opening a specified transfer file for writing
51628 + (e.g. /dev/initctl), then transfer our role to init
51629 + */
51630 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
51631 + current->role->roletype & GR_ROLE_PERSIST)) {
51632 + struct task_struct *task = init_pid_ns.child_reaper;
51633 +
51634 + if (task->role != current->role) {
51635 + task->acl_sp_role = 0;
51636 + task->acl_role_id = current->acl_role_id;
51637 + task->role = current->role;
51638 + rcu_read_lock();
51639 + read_lock(&grsec_exec_file_lock);
51640 + gr_apply_subject_to_task(task);
51641 + read_unlock(&grsec_exec_file_lock);
51642 + rcu_read_unlock();
51643 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
51644 + }
51645 + }
51646 +
51647 + if (unlikely
51648 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
51649 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
51650 + __u32 new_mode = mode;
51651 +
51652 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
51653 +
51654 + retval = new_mode;
51655 +
51656 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
51657 + new_mode |= GR_INHERIT;
51658 +
51659 + if (!(mode & GR_NOLEARN))
51660 + gr_log_learn(dentry, mnt, new_mode);
51661 + }
51662 +
51663 + return retval;
51664 +}
51665 +
51666 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
51667 + const struct dentry *parent,
51668 + const struct vfsmount *mnt)
51669 +{
51670 + struct name_entry *match;
51671 + struct acl_object_label *matchpo;
51672 + struct acl_subject_label *curracl;
51673 + char *path;
51674 +
51675 + if (unlikely(!(gr_status & GR_READY)))
51676 + return NULL;
51677 +
51678 + preempt_disable();
51679 + path = gr_to_filename_rbac(new_dentry, mnt);
51680 + match = lookup_name_entry_create(path);
51681 +
51682 + curracl = current->acl;
51683 +
51684 + if (match) {
51685 + read_lock(&gr_inode_lock);
51686 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
51687 + read_unlock(&gr_inode_lock);
51688 +
51689 + if (matchpo) {
51690 + preempt_enable();
51691 + return matchpo;
51692 + }
51693 + }
51694 +
51695 + // lookup parent
51696 +
51697 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
51698 +
51699 + preempt_enable();
51700 + return matchpo;
51701 +}
51702 +
51703 +__u32
51704 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
51705 + const struct vfsmount * mnt, const __u32 mode)
51706 +{
51707 + struct acl_object_label *matchpo;
51708 + __u32 retval;
51709 +
51710 + if (unlikely(!(gr_status & GR_READY)))
51711 + return (mode & ~GR_AUDITS);
51712 +
51713 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
51714 +
51715 + retval = matchpo->mode & mode;
51716 +
51717 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
51718 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
51719 + __u32 new_mode = mode;
51720 +
51721 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
51722 +
51723 + gr_log_learn(new_dentry, mnt, new_mode);
51724 + return new_mode;
51725 + }
51726 +
51727 + return retval;
51728 +}
51729 +
51730 +__u32
51731 +gr_check_link(const struct dentry * new_dentry,
51732 + const struct dentry * parent_dentry,
51733 + const struct vfsmount * parent_mnt,
51734 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
51735 +{
51736 + struct acl_object_label *obj;
51737 + __u32 oldmode, newmode;
51738 + __u32 needmode;
51739 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
51740 + GR_DELETE | GR_INHERIT;
51741 +
51742 + if (unlikely(!(gr_status & GR_READY)))
51743 + return (GR_CREATE | GR_LINK);
51744 +
51745 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
51746 + oldmode = obj->mode;
51747 +
51748 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
51749 + newmode = obj->mode;
51750 +
51751 + needmode = newmode & checkmodes;
51752 +
51753 + // old name for hardlink must have at least the permissions of the new name
51754 + if ((oldmode & needmode) != needmode)
51755 + goto bad;
51756 +
51757 + // if old name had restrictions/auditing, make sure the new name does as well
51758 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
51759 +
51760 + // don't allow hardlinking of suid/sgid files without permission
51761 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
51762 + needmode |= GR_SETID;
51763 +
51764 + if ((newmode & needmode) != needmode)
51765 + goto bad;
51766 +
51767 + // enforce minimum permissions
51768 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
51769 + return newmode;
51770 +bad:
51771 + needmode = oldmode;
51772 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
51773 + needmode |= GR_SETID;
51774 +
51775 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
51776 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
51777 + return (GR_CREATE | GR_LINK);
51778 + } else if (newmode & GR_SUPPRESS)
51779 + return GR_SUPPRESS;
51780 + else
51781 + return 0;
51782 +}
51783 +
51784 +int
51785 +gr_check_hidden_task(const struct task_struct *task)
51786 +{
51787 + if (unlikely(!(gr_status & GR_READY)))
51788 + return 0;
51789 +
51790 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
51791 + return 1;
51792 +
51793 + return 0;
51794 +}
51795 +
51796 +int
51797 +gr_check_protected_task(const struct task_struct *task)
51798 +{
51799 + if (unlikely(!(gr_status & GR_READY) || !task))
51800 + return 0;
51801 +
51802 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
51803 + task->acl != current->acl)
51804 + return 1;
51805 +
51806 + return 0;
51807 +}
51808 +
51809 +int
51810 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
51811 +{
51812 + struct task_struct *p;
51813 + int ret = 0;
51814 +
51815 + if (unlikely(!(gr_status & GR_READY) || !pid))
51816 + return ret;
51817 +
51818 + read_lock(&tasklist_lock);
51819 + do_each_pid_task(pid, type, p) {
51820 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
51821 + p->acl != current->acl) {
51822 + ret = 1;
51823 + goto out;
51824 + }
51825 + } while_each_pid_task(pid, type, p);
51826 +out:
51827 + read_unlock(&tasklist_lock);
51828 +
51829 + return ret;
51830 +}
51831 +
51832 +void
51833 +gr_copy_label(struct task_struct *tsk)
51834 +{
51835 + /* plain copying of fields is already done by dup_task_struct */
51836 + tsk->signal->used_accept = 0;
51837 + tsk->acl_sp_role = 0;
51838 + //tsk->acl_role_id = current->acl_role_id;
51839 + //tsk->acl = current->acl;
51840 + //tsk->role = current->role;
51841 + tsk->signal->curr_ip = current->signal->curr_ip;
51842 + tsk->signal->saved_ip = current->signal->saved_ip;
51843 + if (current->exec_file)
51844 + get_file(current->exec_file);
51845 + //tsk->exec_file = current->exec_file;
51846 + //tsk->is_writable = current->is_writable;
51847 + if (unlikely(current->signal->used_accept)) {
51848 + current->signal->curr_ip = 0;
51849 + current->signal->saved_ip = 0;
51850 + }
51851 +
51852 + return;
51853 +}
51854 +
51855 +static void
51856 +gr_set_proc_res(struct task_struct *task)
51857 +{
51858 + struct acl_subject_label *proc;
51859 + unsigned short i;
51860 +
51861 + proc = task->acl;
51862 +
51863 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
51864 + return;
51865 +
51866 + for (i = 0; i < RLIM_NLIMITS; i++) {
51867 + if (!(proc->resmask & (1 << i)))
51868 + continue;
51869 +
51870 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
51871 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
51872 + }
51873 +
51874 + return;
51875 +}
51876 +
51877 +extern int __gr_process_user_ban(struct user_struct *user);
51878 +
51879 +int
51880 +gr_check_user_change(int real, int effective, int fs)
51881 +{
51882 + unsigned int i;
51883 + __u16 num;
51884 + uid_t *uidlist;
51885 + int curuid;
51886 + int realok = 0;
51887 + int effectiveok = 0;
51888 + int fsok = 0;
51889 +
51890 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
51891 + struct user_struct *user;
51892 +
51893 + if (real == -1)
51894 + goto skipit;
51895 +
51896 + user = find_user(real);
51897 + if (user == NULL)
51898 + goto skipit;
51899 +
51900 + if (__gr_process_user_ban(user)) {
51901 + /* for find_user */
51902 + free_uid(user);
51903 + return 1;
51904 + }
51905 +
51906 + /* for find_user */
51907 + free_uid(user);
51908 +
51909 +skipit:
51910 +#endif
51911 +
51912 + if (unlikely(!(gr_status & GR_READY)))
51913 + return 0;
51914 +
51915 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
51916 + gr_log_learn_id_change('u', real, effective, fs);
51917 +
51918 + num = current->acl->user_trans_num;
51919 + uidlist = current->acl->user_transitions;
51920 +
51921 + if (uidlist == NULL)
51922 + return 0;
51923 +
51924 + if (real == -1)
51925 + realok = 1;
51926 + if (effective == -1)
51927 + effectiveok = 1;
51928 + if (fs == -1)
51929 + fsok = 1;
51930 +
51931 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
51932 + for (i = 0; i < num; i++) {
51933 + curuid = (int)uidlist[i];
51934 + if (real == curuid)
51935 + realok = 1;
51936 + if (effective == curuid)
51937 + effectiveok = 1;
51938 + if (fs == curuid)
51939 + fsok = 1;
51940 + }
51941 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
51942 + for (i = 0; i < num; i++) {
51943 + curuid = (int)uidlist[i];
51944 + if (real == curuid)
51945 + break;
51946 + if (effective == curuid)
51947 + break;
51948 + if (fs == curuid)
51949 + break;
51950 + }
51951 + /* not in deny list */
51952 + if (i == num) {
51953 + realok = 1;
51954 + effectiveok = 1;
51955 + fsok = 1;
51956 + }
51957 + }
51958 +
51959 + if (realok && effectiveok && fsok)
51960 + return 0;
51961 + else {
51962 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
51963 + return 1;
51964 + }
51965 +}
51966 +
51967 +int
51968 +gr_check_group_change(int real, int effective, int fs)
51969 +{
51970 + unsigned int i;
51971 + __u16 num;
51972 + gid_t *gidlist;
51973 + int curgid;
51974 + int realok = 0;
51975 + int effectiveok = 0;
51976 + int fsok = 0;
51977 +
51978 + if (unlikely(!(gr_status & GR_READY)))
51979 + return 0;
51980 +
51981 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
51982 + gr_log_learn_id_change('g', real, effective, fs);
51983 +
51984 + num = current->acl->group_trans_num;
51985 + gidlist = current->acl->group_transitions;
51986 +
51987 + if (gidlist == NULL)
51988 + return 0;
51989 +
51990 + if (real == -1)
51991 + realok = 1;
51992 + if (effective == -1)
51993 + effectiveok = 1;
51994 + if (fs == -1)
51995 + fsok = 1;
51996 +
51997 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
51998 + for (i = 0; i < num; i++) {
51999 + curgid = (int)gidlist[i];
52000 + if (real == curgid)
52001 + realok = 1;
52002 + if (effective == curgid)
52003 + effectiveok = 1;
52004 + if (fs == curgid)
52005 + fsok = 1;
52006 + }
52007 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
52008 + for (i = 0; i < num; i++) {
52009 + curgid = (int)gidlist[i];
52010 + if (real == curgid)
52011 + break;
52012 + if (effective == curgid)
52013 + break;
52014 + if (fs == curgid)
52015 + break;
52016 + }
52017 + /* not in deny list */
52018 + if (i == num) {
52019 + realok = 1;
52020 + effectiveok = 1;
52021 + fsok = 1;
52022 + }
52023 + }
52024 +
52025 + if (realok && effectiveok && fsok)
52026 + return 0;
52027 + else {
52028 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52029 + return 1;
52030 + }
52031 +}
52032 +
52033 +extern int gr_acl_is_capable(const int cap);
52034 +
52035 +void
52036 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
52037 +{
52038 + struct acl_role_label *role = task->role;
52039 + struct acl_subject_label *subj = NULL;
52040 + struct acl_object_label *obj;
52041 + struct file *filp;
52042 +
52043 + if (unlikely(!(gr_status & GR_READY)))
52044 + return;
52045 +
52046 + filp = task->exec_file;
52047 +
52048 + /* kernel process, we'll give them the kernel role */
52049 + if (unlikely(!filp)) {
52050 + task->role = kernel_role;
52051 + task->acl = kernel_role->root_label;
52052 + return;
52053 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
52054 + role = lookup_acl_role_label(task, uid, gid);
52055 +
52056 + /* don't change the role if we're not a privileged process */
52057 + if (role && task->role != role &&
52058 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
52059 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
52060 + return;
52061 +
52062 + /* perform subject lookup in possibly new role
52063 + we can use this result below in the case where role == task->role
52064 + */
52065 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
52066 +
52067 + /* if we changed uid/gid, but result in the same role
52068 + and are using inheritance, don't lose the inherited subject
52069 + if current subject is other than what normal lookup
52070 + would result in, we arrived via inheritance, don't
52071 + lose subject
52072 + */
52073 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
52074 + (subj == task->acl)))
52075 + task->acl = subj;
52076 +
52077 + task->role = role;
52078 +
52079 + task->is_writable = 0;
52080 +
52081 + /* ignore additional mmap checks for processes that are writable
52082 + by the default ACL */
52083 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52084 + if (unlikely(obj->mode & GR_WRITE))
52085 + task->is_writable = 1;
52086 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52087 + if (unlikely(obj->mode & GR_WRITE))
52088 + task->is_writable = 1;
52089 +
52090 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52091 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52092 +#endif
52093 +
52094 + gr_set_proc_res(task);
52095 +
52096 + return;
52097 +}
52098 +
52099 +int
52100 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
52101 + const int unsafe_flags)
52102 +{
52103 + struct task_struct *task = current;
52104 + struct acl_subject_label *newacl;
52105 + struct acl_object_label *obj;
52106 + __u32 retmode;
52107 +
52108 + if (unlikely(!(gr_status & GR_READY)))
52109 + return 0;
52110 +
52111 + newacl = chk_subj_label(dentry, mnt, task->role);
52112 +
52113 + task_lock(task);
52114 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
52115 + !(task->role->roletype & GR_ROLE_GOD) &&
52116 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
52117 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52118 + task_unlock(task);
52119 + if (unsafe_flags & LSM_UNSAFE_SHARE)
52120 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
52121 + else
52122 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
52123 + return -EACCES;
52124 + }
52125 + task_unlock(task);
52126 +
52127 + obj = chk_obj_label(dentry, mnt, task->acl);
52128 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
52129 +
52130 + if (!(task->acl->mode & GR_INHERITLEARN) &&
52131 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
52132 + if (obj->nested)
52133 + task->acl = obj->nested;
52134 + else
52135 + task->acl = newacl;
52136 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
52137 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
52138 +
52139 + task->is_writable = 0;
52140 +
52141 + /* ignore additional mmap checks for processes that are writable
52142 + by the default ACL */
52143 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
52144 + if (unlikely(obj->mode & GR_WRITE))
52145 + task->is_writable = 1;
52146 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
52147 + if (unlikely(obj->mode & GR_WRITE))
52148 + task->is_writable = 1;
52149 +
52150 + gr_set_proc_res(task);
52151 +
52152 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52153 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52154 +#endif
52155 + return 0;
52156 +}
52157 +
52158 +/* always called with valid inodev ptr */
52159 +static void
52160 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
52161 +{
52162 + struct acl_object_label *matchpo;
52163 + struct acl_subject_label *matchps;
52164 + struct acl_subject_label *subj;
52165 + struct acl_role_label *role;
52166 + unsigned int x;
52167 +
52168 + FOR_EACH_ROLE_START(role)
52169 + FOR_EACH_SUBJECT_START(role, subj, x)
52170 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
52171 + matchpo->mode |= GR_DELETED;
52172 + FOR_EACH_SUBJECT_END(subj,x)
52173 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52174 + if (subj->inode == ino && subj->device == dev)
52175 + subj->mode |= GR_DELETED;
52176 + FOR_EACH_NESTED_SUBJECT_END(subj)
52177 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
52178 + matchps->mode |= GR_DELETED;
52179 + FOR_EACH_ROLE_END(role)
52180 +
52181 + inodev->nentry->deleted = 1;
52182 +
52183 + return;
52184 +}
52185 +
52186 +void
52187 +gr_handle_delete(const ino_t ino, const dev_t dev)
52188 +{
52189 + struct inodev_entry *inodev;
52190 +
52191 + if (unlikely(!(gr_status & GR_READY)))
52192 + return;
52193 +
52194 + write_lock(&gr_inode_lock);
52195 + inodev = lookup_inodev_entry(ino, dev);
52196 + if (inodev != NULL)
52197 + do_handle_delete(inodev, ino, dev);
52198 + write_unlock(&gr_inode_lock);
52199 +
52200 + return;
52201 +}
52202 +
52203 +static void
52204 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
52205 + const ino_t newinode, const dev_t newdevice,
52206 + struct acl_subject_label *subj)
52207 +{
52208 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
52209 + struct acl_object_label *match;
52210 +
52211 + match = subj->obj_hash[index];
52212 +
52213 + while (match && (match->inode != oldinode ||
52214 + match->device != olddevice ||
52215 + !(match->mode & GR_DELETED)))
52216 + match = match->next;
52217 +
52218 + if (match && (match->inode == oldinode)
52219 + && (match->device == olddevice)
52220 + && (match->mode & GR_DELETED)) {
52221 + if (match->prev == NULL) {
52222 + subj->obj_hash[index] = match->next;
52223 + if (match->next != NULL)
52224 + match->next->prev = NULL;
52225 + } else {
52226 + match->prev->next = match->next;
52227 + if (match->next != NULL)
52228 + match->next->prev = match->prev;
52229 + }
52230 + match->prev = NULL;
52231 + match->next = NULL;
52232 + match->inode = newinode;
52233 + match->device = newdevice;
52234 + match->mode &= ~GR_DELETED;
52235 +
52236 + insert_acl_obj_label(match, subj);
52237 + }
52238 +
52239 + return;
52240 +}
52241 +
52242 +static void
52243 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
52244 + const ino_t newinode, const dev_t newdevice,
52245 + struct acl_role_label *role)
52246 +{
52247 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
52248 + struct acl_subject_label *match;
52249 +
52250 + match = role->subj_hash[index];
52251 +
52252 + while (match && (match->inode != oldinode ||
52253 + match->device != olddevice ||
52254 + !(match->mode & GR_DELETED)))
52255 + match = match->next;
52256 +
52257 + if (match && (match->inode == oldinode)
52258 + && (match->device == olddevice)
52259 + && (match->mode & GR_DELETED)) {
52260 + if (match->prev == NULL) {
52261 + role->subj_hash[index] = match->next;
52262 + if (match->next != NULL)
52263 + match->next->prev = NULL;
52264 + } else {
52265 + match->prev->next = match->next;
52266 + if (match->next != NULL)
52267 + match->next->prev = match->prev;
52268 + }
52269 + match->prev = NULL;
52270 + match->next = NULL;
52271 + match->inode = newinode;
52272 + match->device = newdevice;
52273 + match->mode &= ~GR_DELETED;
52274 +
52275 + insert_acl_subj_label(match, role);
52276 + }
52277 +
52278 + return;
52279 +}
52280 +
52281 +static void
52282 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
52283 + const ino_t newinode, const dev_t newdevice)
52284 +{
52285 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
52286 + struct inodev_entry *match;
52287 +
52288 + match = inodev_set.i_hash[index];
52289 +
52290 + while (match && (match->nentry->inode != oldinode ||
52291 + match->nentry->device != olddevice || !match->nentry->deleted))
52292 + match = match->next;
52293 +
52294 + if (match && (match->nentry->inode == oldinode)
52295 + && (match->nentry->device == olddevice) &&
52296 + match->nentry->deleted) {
52297 + if (match->prev == NULL) {
52298 + inodev_set.i_hash[index] = match->next;
52299 + if (match->next != NULL)
52300 + match->next->prev = NULL;
52301 + } else {
52302 + match->prev->next = match->next;
52303 + if (match->next != NULL)
52304 + match->next->prev = match->prev;
52305 + }
52306 + match->prev = NULL;
52307 + match->next = NULL;
52308 + match->nentry->inode = newinode;
52309 + match->nentry->device = newdevice;
52310 + match->nentry->deleted = 0;
52311 +
52312 + insert_inodev_entry(match);
52313 + }
52314 +
52315 + return;
52316 +}
52317 +
52318 +static void
52319 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
52320 +{
52321 + struct acl_subject_label *subj;
52322 + struct acl_role_label *role;
52323 + unsigned int x;
52324 +
52325 + FOR_EACH_ROLE_START(role)
52326 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
52327 +
52328 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52329 + if ((subj->inode == ino) && (subj->device == dev)) {
52330 + subj->inode = ino;
52331 + subj->device = dev;
52332 + }
52333 + FOR_EACH_NESTED_SUBJECT_END(subj)
52334 + FOR_EACH_SUBJECT_START(role, subj, x)
52335 + update_acl_obj_label(matchn->inode, matchn->device,
52336 + ino, dev, subj);
52337 + FOR_EACH_SUBJECT_END(subj,x)
52338 + FOR_EACH_ROLE_END(role)
52339 +
52340 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
52341 +
52342 + return;
52343 +}
52344 +
52345 +static void
52346 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
52347 + const struct vfsmount *mnt)
52348 +{
52349 + ino_t ino = dentry->d_inode->i_ino;
52350 + dev_t dev = __get_dev(dentry);
52351 +
52352 + __do_handle_create(matchn, ino, dev);
52353 +
52354 + return;
52355 +}
52356 +
52357 +void
52358 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
52359 +{
52360 + struct name_entry *matchn;
52361 +
52362 + if (unlikely(!(gr_status & GR_READY)))
52363 + return;
52364 +
52365 + preempt_disable();
52366 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
52367 +
52368 + if (unlikely((unsigned long)matchn)) {
52369 + write_lock(&gr_inode_lock);
52370 + do_handle_create(matchn, dentry, mnt);
52371 + write_unlock(&gr_inode_lock);
52372 + }
52373 + preempt_enable();
52374 +
52375 + return;
52376 +}
52377 +
52378 +void
52379 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
52380 +{
52381 + struct name_entry *matchn;
52382 +
52383 + if (unlikely(!(gr_status & GR_READY)))
52384 + return;
52385 +
52386 + preempt_disable();
52387 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
52388 +
52389 + if (unlikely((unsigned long)matchn)) {
52390 + write_lock(&gr_inode_lock);
52391 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
52392 + write_unlock(&gr_inode_lock);
52393 + }
52394 + preempt_enable();
52395 +
52396 + return;
52397 +}
52398 +
52399 +void
52400 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
52401 + struct dentry *old_dentry,
52402 + struct dentry *new_dentry,
52403 + struct vfsmount *mnt, const __u8 replace)
52404 +{
52405 + struct name_entry *matchn;
52406 + struct inodev_entry *inodev;
52407 + struct inode *inode = new_dentry->d_inode;
52408 + ino_t old_ino = old_dentry->d_inode->i_ino;
52409 + dev_t old_dev = __get_dev(old_dentry);
52410 +
52411 + /* vfs_rename swaps the name and parent link for old_dentry and
52412 + new_dentry
52413 + at this point, old_dentry has the new name, parent link, and inode
52414 + for the renamed file
52415 + if a file is being replaced by a rename, new_dentry has the inode
52416 + and name for the replaced file
52417 + */
52418 +
52419 + if (unlikely(!(gr_status & GR_READY)))
52420 + return;
52421 +
52422 + preempt_disable();
52423 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
52424 +
52425 + /* we wouldn't have to check d_inode if it weren't for
52426 + NFS silly-renaming
52427 + */
52428 +
52429 + write_lock(&gr_inode_lock);
52430 + if (unlikely(replace && inode)) {
52431 + ino_t new_ino = inode->i_ino;
52432 + dev_t new_dev = __get_dev(new_dentry);
52433 +
52434 + inodev = lookup_inodev_entry(new_ino, new_dev);
52435 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
52436 + do_handle_delete(inodev, new_ino, new_dev);
52437 + }
52438 +
52439 + inodev = lookup_inodev_entry(old_ino, old_dev);
52440 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
52441 + do_handle_delete(inodev, old_ino, old_dev);
52442 +
52443 + if (unlikely((unsigned long)matchn))
52444 + do_handle_create(matchn, old_dentry, mnt);
52445 +
52446 + write_unlock(&gr_inode_lock);
52447 + preempt_enable();
52448 +
52449 + return;
52450 +}
52451 +
52452 +static int
52453 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
52454 + unsigned char **sum)
52455 +{
52456 + struct acl_role_label *r;
52457 + struct role_allowed_ip *ipp;
52458 + struct role_transition *trans;
52459 + unsigned int i;
52460 + int found = 0;
52461 + u32 curr_ip = current->signal->curr_ip;
52462 +
52463 + current->signal->saved_ip = curr_ip;
52464 +
52465 + /* check transition table */
52466 +
52467 + for (trans = current->role->transitions; trans; trans = trans->next) {
52468 + if (!strcmp(rolename, trans->rolename)) {
52469 + found = 1;
52470 + break;
52471 + }
52472 + }
52473 +
52474 + if (!found)
52475 + return 0;
52476 +
52477 + /* handle special roles that do not require authentication
52478 + and check ip */
52479 +
52480 + FOR_EACH_ROLE_START(r)
52481 + if (!strcmp(rolename, r->rolename) &&
52482 + (r->roletype & GR_ROLE_SPECIAL)) {
52483 + found = 0;
52484 + if (r->allowed_ips != NULL) {
52485 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
52486 + if ((ntohl(curr_ip) & ipp->netmask) ==
52487 + (ntohl(ipp->addr) & ipp->netmask))
52488 + found = 1;
52489 + }
52490 + } else
52491 + found = 2;
52492 + if (!found)
52493 + return 0;
52494 +
52495 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
52496 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
52497 + *salt = NULL;
52498 + *sum = NULL;
52499 + return 1;
52500 + }
52501 + }
52502 + FOR_EACH_ROLE_END(r)
52503 +
52504 + for (i = 0; i < num_sprole_pws; i++) {
52505 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
52506 + *salt = acl_special_roles[i]->salt;
52507 + *sum = acl_special_roles[i]->sum;
52508 + return 1;
52509 + }
52510 + }
52511 +
52512 + return 0;
52513 +}
52514 +
52515 +static void
52516 +assign_special_role(char *rolename)
52517 +{
52518 + struct acl_object_label *obj;
52519 + struct acl_role_label *r;
52520 + struct acl_role_label *assigned = NULL;
52521 + struct task_struct *tsk;
52522 + struct file *filp;
52523 +
52524 + FOR_EACH_ROLE_START(r)
52525 + if (!strcmp(rolename, r->rolename) &&
52526 + (r->roletype & GR_ROLE_SPECIAL)) {
52527 + assigned = r;
52528 + break;
52529 + }
52530 + FOR_EACH_ROLE_END(r)
52531 +
52532 + if (!assigned)
52533 + return;
52534 +
52535 + read_lock(&tasklist_lock);
52536 + read_lock(&grsec_exec_file_lock);
52537 +
52538 + tsk = current->real_parent;
52539 + if (tsk == NULL)
52540 + goto out_unlock;
52541 +
52542 + filp = tsk->exec_file;
52543 + if (filp == NULL)
52544 + goto out_unlock;
52545 +
52546 + tsk->is_writable = 0;
52547 +
52548 + tsk->acl_sp_role = 1;
52549 + tsk->acl_role_id = ++acl_sp_role_value;
52550 + tsk->role = assigned;
52551 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
52552 +
52553 + /* ignore additional mmap checks for processes that are writable
52554 + by the default ACL */
52555 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52556 + if (unlikely(obj->mode & GR_WRITE))
52557 + tsk->is_writable = 1;
52558 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
52559 + if (unlikely(obj->mode & GR_WRITE))
52560 + tsk->is_writable = 1;
52561 +
52562 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52563 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
52564 +#endif
52565 +
52566 +out_unlock:
52567 + read_unlock(&grsec_exec_file_lock);
52568 + read_unlock(&tasklist_lock);
52569 + return;
52570 +}
52571 +
52572 +int gr_check_secure_terminal(struct task_struct *task)
52573 +{
52574 + struct task_struct *p, *p2, *p3;
52575 + struct files_struct *files;
52576 + struct fdtable *fdt;
52577 + struct file *our_file = NULL, *file;
52578 + int i;
52579 +
52580 + if (task->signal->tty == NULL)
52581 + return 1;
52582 +
52583 + files = get_files_struct(task);
52584 + if (files != NULL) {
52585 + rcu_read_lock();
52586 + fdt = files_fdtable(files);
52587 + for (i=0; i < fdt->max_fds; i++) {
52588 + file = fcheck_files(files, i);
52589 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
52590 + get_file(file);
52591 + our_file = file;
52592 + }
52593 + }
52594 + rcu_read_unlock();
52595 + put_files_struct(files);
52596 + }
52597 +
52598 + if (our_file == NULL)
52599 + return 1;
52600 +
52601 + read_lock(&tasklist_lock);
52602 + do_each_thread(p2, p) {
52603 + files = get_files_struct(p);
52604 + if (files == NULL ||
52605 + (p->signal && p->signal->tty == task->signal->tty)) {
52606 + if (files != NULL)
52607 + put_files_struct(files);
52608 + continue;
52609 + }
52610 + rcu_read_lock();
52611 + fdt = files_fdtable(files);
52612 + for (i=0; i < fdt->max_fds; i++) {
52613 + file = fcheck_files(files, i);
52614 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
52615 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
52616 + p3 = task;
52617 + while (p3->pid > 0) {
52618 + if (p3 == p)
52619 + break;
52620 + p3 = p3->real_parent;
52621 + }
52622 + if (p3 == p)
52623 + break;
52624 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
52625 + gr_handle_alertkill(p);
52626 + rcu_read_unlock();
52627 + put_files_struct(files);
52628 + read_unlock(&tasklist_lock);
52629 + fput(our_file);
52630 + return 0;
52631 + }
52632 + }
52633 + rcu_read_unlock();
52634 + put_files_struct(files);
52635 + } while_each_thread(p2, p);
52636 + read_unlock(&tasklist_lock);
52637 +
52638 + fput(our_file);
52639 + return 1;
52640 +}
52641 +
52642 +ssize_t
52643 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
52644 +{
52645 + struct gr_arg_wrapper uwrap;
52646 + unsigned char *sprole_salt = NULL;
52647 + unsigned char *sprole_sum = NULL;
52648 + int error = sizeof (struct gr_arg_wrapper);
52649 + int error2 = 0;
52650 +
52651 + mutex_lock(&gr_dev_mutex);
52652 +
52653 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
52654 + error = -EPERM;
52655 + goto out;
52656 + }
52657 +
52658 + if (count != sizeof (struct gr_arg_wrapper)) {
52659 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
52660 + error = -EINVAL;
52661 + goto out;
52662 + }
52663 +
52664 +
52665 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
52666 + gr_auth_expires = 0;
52667 + gr_auth_attempts = 0;
52668 + }
52669 +
52670 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
52671 + error = -EFAULT;
52672 + goto out;
52673 + }
52674 +
52675 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
52676 + error = -EINVAL;
52677 + goto out;
52678 + }
52679 +
52680 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
52681 + error = -EFAULT;
52682 + goto out;
52683 + }
52684 +
52685 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
52686 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
52687 + time_after(gr_auth_expires, get_seconds())) {
52688 + error = -EBUSY;
52689 + goto out;
52690 + }
52691 +
52692 + /* if non-root trying to do anything other than use a special role,
52693 + do not attempt authentication, do not count towards authentication
52694 + locking
52695 + */
52696 +
52697 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
52698 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
52699 + current_uid()) {
52700 + error = -EPERM;
52701 + goto out;
52702 + }
52703 +
52704 + /* ensure pw and special role name are null terminated */
52705 +
52706 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
52707 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
52708 +
52709 + /* Okay.
52710 + * We have our enough of the argument structure..(we have yet
52711 + * to copy_from_user the tables themselves) . Copy the tables
52712 + * only if we need them, i.e. for loading operations. */
52713 +
52714 + switch (gr_usermode->mode) {
52715 + case GR_STATUS:
52716 + if (gr_status & GR_READY) {
52717 + error = 1;
52718 + if (!gr_check_secure_terminal(current))
52719 + error = 3;
52720 + } else
52721 + error = 2;
52722 + goto out;
52723 + case GR_SHUTDOWN:
52724 + if ((gr_status & GR_READY)
52725 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
52726 + pax_open_kernel();
52727 + gr_status &= ~GR_READY;
52728 + pax_close_kernel();
52729 +
52730 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
52731 + free_variables();
52732 + memset(gr_usermode, 0, sizeof (struct gr_arg));
52733 + memset(gr_system_salt, 0, GR_SALT_LEN);
52734 + memset(gr_system_sum, 0, GR_SHA_LEN);
52735 + } else if (gr_status & GR_READY) {
52736 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
52737 + error = -EPERM;
52738 + } else {
52739 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
52740 + error = -EAGAIN;
52741 + }
52742 + break;
52743 + case GR_ENABLE:
52744 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
52745 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
52746 + else {
52747 + if (gr_status & GR_READY)
52748 + error = -EAGAIN;
52749 + else
52750 + error = error2;
52751 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
52752 + }
52753 + break;
52754 + case GR_RELOAD:
52755 + if (!(gr_status & GR_READY)) {
52756 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
52757 + error = -EAGAIN;
52758 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
52759 + preempt_disable();
52760 +
52761 + pax_open_kernel();
52762 + gr_status &= ~GR_READY;
52763 + pax_close_kernel();
52764 +
52765 + free_variables();
52766 + if (!(error2 = gracl_init(gr_usermode))) {
52767 + preempt_enable();
52768 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
52769 + } else {
52770 + preempt_enable();
52771 + error = error2;
52772 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
52773 + }
52774 + } else {
52775 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
52776 + error = -EPERM;
52777 + }
52778 + break;
52779 + case GR_SEGVMOD:
52780 + if (unlikely(!(gr_status & GR_READY))) {
52781 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
52782 + error = -EAGAIN;
52783 + break;
52784 + }
52785 +
52786 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
52787 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
52788 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
52789 + struct acl_subject_label *segvacl;
52790 + segvacl =
52791 + lookup_acl_subj_label(gr_usermode->segv_inode,
52792 + gr_usermode->segv_device,
52793 + current->role);
52794 + if (segvacl) {
52795 + segvacl->crashes = 0;
52796 + segvacl->expires = 0;
52797 + }
52798 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
52799 + gr_remove_uid(gr_usermode->segv_uid);
52800 + }
52801 + } else {
52802 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
52803 + error = -EPERM;
52804 + }
52805 + break;
52806 + case GR_SPROLE:
52807 + case GR_SPROLEPAM:
52808 + if (unlikely(!(gr_status & GR_READY))) {
52809 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
52810 + error = -EAGAIN;
52811 + break;
52812 + }
52813 +
52814 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
52815 + current->role->expires = 0;
52816 + current->role->auth_attempts = 0;
52817 + }
52818 +
52819 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
52820 + time_after(current->role->expires, get_seconds())) {
52821 + error = -EBUSY;
52822 + goto out;
52823 + }
52824 +
52825 + if (lookup_special_role_auth
52826 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
52827 + && ((!sprole_salt && !sprole_sum)
52828 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
52829 + char *p = "";
52830 + assign_special_role(gr_usermode->sp_role);
52831 + read_lock(&tasklist_lock);
52832 + if (current->real_parent)
52833 + p = current->real_parent->role->rolename;
52834 + read_unlock(&tasklist_lock);
52835 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
52836 + p, acl_sp_role_value);
52837 + } else {
52838 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
52839 + error = -EPERM;
52840 + if(!(current->role->auth_attempts++))
52841 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
52842 +
52843 + goto out;
52844 + }
52845 + break;
52846 + case GR_UNSPROLE:
52847 + if (unlikely(!(gr_status & GR_READY))) {
52848 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
52849 + error = -EAGAIN;
52850 + break;
52851 + }
52852 +
52853 + if (current->role->roletype & GR_ROLE_SPECIAL) {
52854 + char *p = "";
52855 + int i = 0;
52856 +
52857 + read_lock(&tasklist_lock);
52858 + if (current->real_parent) {
52859 + p = current->real_parent->role->rolename;
52860 + i = current->real_parent->acl_role_id;
52861 + }
52862 + read_unlock(&tasklist_lock);
52863 +
52864 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
52865 + gr_set_acls(1);
52866 + } else {
52867 + error = -EPERM;
52868 + goto out;
52869 + }
52870 + break;
52871 + default:
52872 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
52873 + error = -EINVAL;
52874 + break;
52875 + }
52876 +
52877 + if (error != -EPERM)
52878 + goto out;
52879 +
52880 + if(!(gr_auth_attempts++))
52881 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
52882 +
52883 + out:
52884 + mutex_unlock(&gr_dev_mutex);
52885 + return error;
52886 +}
52887 +
52888 +/* must be called with
52889 + rcu_read_lock();
52890 + read_lock(&tasklist_lock);
52891 + read_lock(&grsec_exec_file_lock);
52892 +*/
52893 +int gr_apply_subject_to_task(struct task_struct *task)
52894 +{
52895 + struct acl_object_label *obj;
52896 + char *tmpname;
52897 + struct acl_subject_label *tmpsubj;
52898 + struct file *filp;
52899 + struct name_entry *nmatch;
52900 +
52901 + filp = task->exec_file;
52902 + if (filp == NULL)
52903 + return 0;
52904 +
52905 + /* the following is to apply the correct subject
52906 + on binaries running when the RBAC system
52907 + is enabled, when the binaries have been
52908 + replaced or deleted since their execution
52909 + -----
52910 + when the RBAC system starts, the inode/dev
52911 + from exec_file will be one the RBAC system
52912 + is unaware of. It only knows the inode/dev
52913 + of the present file on disk, or the absence
52914 + of it.
52915 + */
52916 + preempt_disable();
52917 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
52918 +
52919 + nmatch = lookup_name_entry(tmpname);
52920 + preempt_enable();
52921 + tmpsubj = NULL;
52922 + if (nmatch) {
52923 + if (nmatch->deleted)
52924 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
52925 + else
52926 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
52927 + if (tmpsubj != NULL)
52928 + task->acl = tmpsubj;
52929 + }
52930 + if (tmpsubj == NULL)
52931 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
52932 + task->role);
52933 + if (task->acl) {
52934 + task->is_writable = 0;
52935 + /* ignore additional mmap checks for processes that are writable
52936 + by the default ACL */
52937 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52938 + if (unlikely(obj->mode & GR_WRITE))
52939 + task->is_writable = 1;
52940 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52941 + if (unlikely(obj->mode & GR_WRITE))
52942 + task->is_writable = 1;
52943 +
52944 + gr_set_proc_res(task);
52945 +
52946 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52947 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52948 +#endif
52949 + } else {
52950 + return 1;
52951 + }
52952 +
52953 + return 0;
52954 +}
52955 +
52956 +int
52957 +gr_set_acls(const int type)
52958 +{
52959 + struct task_struct *task, *task2;
52960 + struct acl_role_label *role = current->role;
52961 + __u16 acl_role_id = current->acl_role_id;
52962 + const struct cred *cred;
52963 + int ret;
52964 +
52965 + rcu_read_lock();
52966 + read_lock(&tasklist_lock);
52967 + read_lock(&grsec_exec_file_lock);
52968 + do_each_thread(task2, task) {
52969 + /* check to see if we're called from the exit handler,
52970 + if so, only replace ACLs that have inherited the admin
52971 + ACL */
52972 +
52973 + if (type && (task->role != role ||
52974 + task->acl_role_id != acl_role_id))
52975 + continue;
52976 +
52977 + task->acl_role_id = 0;
52978 + task->acl_sp_role = 0;
52979 +
52980 + if (task->exec_file) {
52981 + cred = __task_cred(task);
52982 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
52983 + ret = gr_apply_subject_to_task(task);
52984 + if (ret) {
52985 + read_unlock(&grsec_exec_file_lock);
52986 + read_unlock(&tasklist_lock);
52987 + rcu_read_unlock();
52988 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
52989 + return ret;
52990 + }
52991 + } else {
52992 + // it's a kernel process
52993 + task->role = kernel_role;
52994 + task->acl = kernel_role->root_label;
52995 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
52996 + task->acl->mode &= ~GR_PROCFIND;
52997 +#endif
52998 + }
52999 + } while_each_thread(task2, task);
53000 + read_unlock(&grsec_exec_file_lock);
53001 + read_unlock(&tasklist_lock);
53002 + rcu_read_unlock();
53003 +
53004 + return 0;
53005 +}
53006 +
53007 +void
53008 +gr_learn_resource(const struct task_struct *task,
53009 + const int res, const unsigned long wanted, const int gt)
53010 +{
53011 + struct acl_subject_label *acl;
53012 + const struct cred *cred;
53013 +
53014 + if (unlikely((gr_status & GR_READY) &&
53015 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
53016 + goto skip_reslog;
53017 +
53018 +#ifdef CONFIG_GRKERNSEC_RESLOG
53019 + gr_log_resource(task, res, wanted, gt);
53020 +#endif
53021 + skip_reslog:
53022 +
53023 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
53024 + return;
53025 +
53026 + acl = task->acl;
53027 +
53028 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
53029 + !(acl->resmask & (1 << (unsigned short) res))))
53030 + return;
53031 +
53032 + if (wanted >= acl->res[res].rlim_cur) {
53033 + unsigned long res_add;
53034 +
53035 + res_add = wanted;
53036 + switch (res) {
53037 + case RLIMIT_CPU:
53038 + res_add += GR_RLIM_CPU_BUMP;
53039 + break;
53040 + case RLIMIT_FSIZE:
53041 + res_add += GR_RLIM_FSIZE_BUMP;
53042 + break;
53043 + case RLIMIT_DATA:
53044 + res_add += GR_RLIM_DATA_BUMP;
53045 + break;
53046 + case RLIMIT_STACK:
53047 + res_add += GR_RLIM_STACK_BUMP;
53048 + break;
53049 + case RLIMIT_CORE:
53050 + res_add += GR_RLIM_CORE_BUMP;
53051 + break;
53052 + case RLIMIT_RSS:
53053 + res_add += GR_RLIM_RSS_BUMP;
53054 + break;
53055 + case RLIMIT_NPROC:
53056 + res_add += GR_RLIM_NPROC_BUMP;
53057 + break;
53058 + case RLIMIT_NOFILE:
53059 + res_add += GR_RLIM_NOFILE_BUMP;
53060 + break;
53061 + case RLIMIT_MEMLOCK:
53062 + res_add += GR_RLIM_MEMLOCK_BUMP;
53063 + break;
53064 + case RLIMIT_AS:
53065 + res_add += GR_RLIM_AS_BUMP;
53066 + break;
53067 + case RLIMIT_LOCKS:
53068 + res_add += GR_RLIM_LOCKS_BUMP;
53069 + break;
53070 + case RLIMIT_SIGPENDING:
53071 + res_add += GR_RLIM_SIGPENDING_BUMP;
53072 + break;
53073 + case RLIMIT_MSGQUEUE:
53074 + res_add += GR_RLIM_MSGQUEUE_BUMP;
53075 + break;
53076 + case RLIMIT_NICE:
53077 + res_add += GR_RLIM_NICE_BUMP;
53078 + break;
53079 + case RLIMIT_RTPRIO:
53080 + res_add += GR_RLIM_RTPRIO_BUMP;
53081 + break;
53082 + case RLIMIT_RTTIME:
53083 + res_add += GR_RLIM_RTTIME_BUMP;
53084 + break;
53085 + }
53086 +
53087 + acl->res[res].rlim_cur = res_add;
53088 +
53089 + if (wanted > acl->res[res].rlim_max)
53090 + acl->res[res].rlim_max = res_add;
53091 +
53092 + /* only log the subject filename, since resource logging is supported for
53093 + single-subject learning only */
53094 + rcu_read_lock();
53095 + cred = __task_cred(task);
53096 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53097 + task->role->roletype, cred->uid, cred->gid, acl->filename,
53098 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
53099 + "", (unsigned long) res, &task->signal->saved_ip);
53100 + rcu_read_unlock();
53101 + }
53102 +
53103 + return;
53104 +}
53105 +
53106 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
53107 +void
53108 +pax_set_initial_flags(struct linux_binprm *bprm)
53109 +{
53110 + struct task_struct *task = current;
53111 + struct acl_subject_label *proc;
53112 + unsigned long flags;
53113 +
53114 + if (unlikely(!(gr_status & GR_READY)))
53115 + return;
53116 +
53117 + flags = pax_get_flags(task);
53118 +
53119 + proc = task->acl;
53120 +
53121 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
53122 + flags &= ~MF_PAX_PAGEEXEC;
53123 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
53124 + flags &= ~MF_PAX_SEGMEXEC;
53125 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
53126 + flags &= ~MF_PAX_RANDMMAP;
53127 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
53128 + flags &= ~MF_PAX_EMUTRAMP;
53129 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
53130 + flags &= ~MF_PAX_MPROTECT;
53131 +
53132 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
53133 + flags |= MF_PAX_PAGEEXEC;
53134 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
53135 + flags |= MF_PAX_SEGMEXEC;
53136 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
53137 + flags |= MF_PAX_RANDMMAP;
53138 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
53139 + flags |= MF_PAX_EMUTRAMP;
53140 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
53141 + flags |= MF_PAX_MPROTECT;
53142 +
53143 + pax_set_flags(task, flags);
53144 +
53145 + return;
53146 +}
53147 +#endif
53148 +
53149 +#ifdef CONFIG_SYSCTL
53150 +/* Eric Biederman likes breaking userland ABI and every inode-based security
53151 + system to save 35kb of memory */
53152 +
53153 +/* we modify the passed in filename, but adjust it back before returning */
53154 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
53155 +{
53156 + struct name_entry *nmatch;
53157 + char *p, *lastp = NULL;
53158 + struct acl_object_label *obj = NULL, *tmp;
53159 + struct acl_subject_label *tmpsubj;
53160 + char c = '\0';
53161 +
53162 + read_lock(&gr_inode_lock);
53163 +
53164 + p = name + len - 1;
53165 + do {
53166 + nmatch = lookup_name_entry(name);
53167 + if (lastp != NULL)
53168 + *lastp = c;
53169 +
53170 + if (nmatch == NULL)
53171 + goto next_component;
53172 + tmpsubj = current->acl;
53173 + do {
53174 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
53175 + if (obj != NULL) {
53176 + tmp = obj->globbed;
53177 + while (tmp) {
53178 + if (!glob_match(tmp->filename, name)) {
53179 + obj = tmp;
53180 + goto found_obj;
53181 + }
53182 + tmp = tmp->next;
53183 + }
53184 + goto found_obj;
53185 + }
53186 + } while ((tmpsubj = tmpsubj->parent_subject));
53187 +next_component:
53188 + /* end case */
53189 + if (p == name)
53190 + break;
53191 +
53192 + while (*p != '/')
53193 + p--;
53194 + if (p == name)
53195 + lastp = p + 1;
53196 + else {
53197 + lastp = p;
53198 + p--;
53199 + }
53200 + c = *lastp;
53201 + *lastp = '\0';
53202 + } while (1);
53203 +found_obj:
53204 + read_unlock(&gr_inode_lock);
53205 + /* obj returned will always be non-null */
53206 + return obj;
53207 +}
53208 +
53209 +/* returns 0 when allowing, non-zero on error
53210 + op of 0 is used for readdir, so we don't log the names of hidden files
53211 +*/
53212 +__u32
53213 +gr_handle_sysctl(const struct ctl_table *table, const int op)
53214 +{
53215 + struct ctl_table *tmp;
53216 + const char *proc_sys = "/proc/sys";
53217 + char *path;
53218 + struct acl_object_label *obj;
53219 + unsigned short len = 0, pos = 0, depth = 0, i;
53220 + __u32 err = 0;
53221 + __u32 mode = 0;
53222 +
53223 + if (unlikely(!(gr_status & GR_READY)))
53224 + return 0;
53225 +
53226 + /* for now, ignore operations on non-sysctl entries if it's not a
53227 + readdir*/
53228 + if (table->child != NULL && op != 0)
53229 + return 0;
53230 +
53231 + mode |= GR_FIND;
53232 + /* it's only a read if it's an entry, read on dirs is for readdir */
53233 + if (op & MAY_READ)
53234 + mode |= GR_READ;
53235 + if (op & MAY_WRITE)
53236 + mode |= GR_WRITE;
53237 +
53238 + preempt_disable();
53239 +
53240 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53241 +
53242 + /* it's only a read/write if it's an actual entry, not a dir
53243 + (which are opened for readdir)
53244 + */
53245 +
53246 + /* convert the requested sysctl entry into a pathname */
53247 +
53248 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
53249 + len += strlen(tmp->procname);
53250 + len++;
53251 + depth++;
53252 + }
53253 +
53254 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
53255 + /* deny */
53256 + goto out;
53257 + }
53258 +
53259 + memset(path, 0, PAGE_SIZE);
53260 +
53261 + memcpy(path, proc_sys, strlen(proc_sys));
53262 +
53263 + pos += strlen(proc_sys);
53264 +
53265 + for (; depth > 0; depth--) {
53266 + path[pos] = '/';
53267 + pos++;
53268 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
53269 + if (depth == i) {
53270 + memcpy(path + pos, tmp->procname,
53271 + strlen(tmp->procname));
53272 + pos += strlen(tmp->procname);
53273 + }
53274 + i++;
53275 + }
53276 + }
53277 +
53278 + obj = gr_lookup_by_name(path, pos);
53279 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
53280 +
53281 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
53282 + ((err & mode) != mode))) {
53283 + __u32 new_mode = mode;
53284 +
53285 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53286 +
53287 + err = 0;
53288 + gr_log_learn_sysctl(path, new_mode);
53289 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
53290 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
53291 + err = -ENOENT;
53292 + } else if (!(err & GR_FIND)) {
53293 + err = -ENOENT;
53294 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
53295 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
53296 + path, (mode & GR_READ) ? " reading" : "",
53297 + (mode & GR_WRITE) ? " writing" : "");
53298 + err = -EACCES;
53299 + } else if ((err & mode) != mode) {
53300 + err = -EACCES;
53301 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
53302 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
53303 + path, (mode & GR_READ) ? " reading" : "",
53304 + (mode & GR_WRITE) ? " writing" : "");
53305 + err = 0;
53306 + } else
53307 + err = 0;
53308 +
53309 + out:
53310 + preempt_enable();
53311 +
53312 + return err;
53313 +}
53314 +#endif
53315 +
53316 +int
53317 +gr_handle_proc_ptrace(struct task_struct *task)
53318 +{
53319 + struct file *filp;
53320 + struct task_struct *tmp = task;
53321 + struct task_struct *curtemp = current;
53322 + __u32 retmode;
53323 +
53324 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53325 + if (unlikely(!(gr_status & GR_READY)))
53326 + return 0;
53327 +#endif
53328 +
53329 + read_lock(&tasklist_lock);
53330 + read_lock(&grsec_exec_file_lock);
53331 + filp = task->exec_file;
53332 +
53333 + while (tmp->pid > 0) {
53334 + if (tmp == curtemp)
53335 + break;
53336 + tmp = tmp->real_parent;
53337 + }
53338 +
53339 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53340 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
53341 + read_unlock(&grsec_exec_file_lock);
53342 + read_unlock(&tasklist_lock);
53343 + return 1;
53344 + }
53345 +
53346 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53347 + if (!(gr_status & GR_READY)) {
53348 + read_unlock(&grsec_exec_file_lock);
53349 + read_unlock(&tasklist_lock);
53350 + return 0;
53351 + }
53352 +#endif
53353 +
53354 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
53355 + read_unlock(&grsec_exec_file_lock);
53356 + read_unlock(&tasklist_lock);
53357 +
53358 + if (retmode & GR_NOPTRACE)
53359 + return 1;
53360 +
53361 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
53362 + && (current->acl != task->acl || (current->acl != current->role->root_label
53363 + && current->pid != task->pid)))
53364 + return 1;
53365 +
53366 + return 0;
53367 +}
53368 +
53369 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
53370 +{
53371 + if (unlikely(!(gr_status & GR_READY)))
53372 + return;
53373 +
53374 + if (!(current->role->roletype & GR_ROLE_GOD))
53375 + return;
53376 +
53377 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
53378 + p->role->rolename, gr_task_roletype_to_char(p),
53379 + p->acl->filename);
53380 +}
53381 +
53382 +int
53383 +gr_handle_ptrace(struct task_struct *task, const long request)
53384 +{
53385 + struct task_struct *tmp = task;
53386 + struct task_struct *curtemp = current;
53387 + __u32 retmode;
53388 +
53389 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53390 + if (unlikely(!(gr_status & GR_READY)))
53391 + return 0;
53392 +#endif
53393 +
53394 + read_lock(&tasklist_lock);
53395 + while (tmp->pid > 0) {
53396 + if (tmp == curtemp)
53397 + break;
53398 + tmp = tmp->real_parent;
53399 + }
53400 +
53401 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53402 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
53403 + read_unlock(&tasklist_lock);
53404 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53405 + return 1;
53406 + }
53407 + read_unlock(&tasklist_lock);
53408 +
53409 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53410 + if (!(gr_status & GR_READY))
53411 + return 0;
53412 +#endif
53413 +
53414 + read_lock(&grsec_exec_file_lock);
53415 + if (unlikely(!task->exec_file)) {
53416 + read_unlock(&grsec_exec_file_lock);
53417 + return 0;
53418 + }
53419 +
53420 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
53421 + read_unlock(&grsec_exec_file_lock);
53422 +
53423 + if (retmode & GR_NOPTRACE) {
53424 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53425 + return 1;
53426 + }
53427 +
53428 + if (retmode & GR_PTRACERD) {
53429 + switch (request) {
53430 + case PTRACE_SEIZE:
53431 + case PTRACE_POKETEXT:
53432 + case PTRACE_POKEDATA:
53433 + case PTRACE_POKEUSR:
53434 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
53435 + case PTRACE_SETREGS:
53436 + case PTRACE_SETFPREGS:
53437 +#endif
53438 +#ifdef CONFIG_X86
53439 + case PTRACE_SETFPXREGS:
53440 +#endif
53441 +#ifdef CONFIG_ALTIVEC
53442 + case PTRACE_SETVRREGS:
53443 +#endif
53444 + return 1;
53445 + default:
53446 + return 0;
53447 + }
53448 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
53449 + !(current->role->roletype & GR_ROLE_GOD) &&
53450 + (current->acl != task->acl)) {
53451 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53452 + return 1;
53453 + }
53454 +
53455 + return 0;
53456 +}
53457 +
53458 +static int is_writable_mmap(const struct file *filp)
53459 +{
53460 + struct task_struct *task = current;
53461 + struct acl_object_label *obj, *obj2;
53462 +
53463 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
53464 + !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))) {
53465 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53466 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
53467 + task->role->root_label);
53468 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
53469 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
53470 + return 1;
53471 + }
53472 + }
53473 + return 0;
53474 +}
53475 +
53476 +int
53477 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
53478 +{
53479 + __u32 mode;
53480 +
53481 + if (unlikely(!file || !(prot & PROT_EXEC)))
53482 + return 1;
53483 +
53484 + if (is_writable_mmap(file))
53485 + return 0;
53486 +
53487 + mode =
53488 + gr_search_file(file->f_path.dentry,
53489 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53490 + file->f_path.mnt);
53491 +
53492 + if (!gr_tpe_allow(file))
53493 + return 0;
53494 +
53495 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53496 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53497 + return 0;
53498 + } else if (unlikely(!(mode & GR_EXEC))) {
53499 + return 0;
53500 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53501 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53502 + return 1;
53503 + }
53504 +
53505 + return 1;
53506 +}
53507 +
53508 +int
53509 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
53510 +{
53511 + __u32 mode;
53512 +
53513 + if (unlikely(!file || !(prot & PROT_EXEC)))
53514 + return 1;
53515 +
53516 + if (is_writable_mmap(file))
53517 + return 0;
53518 +
53519 + mode =
53520 + gr_search_file(file->f_path.dentry,
53521 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53522 + file->f_path.mnt);
53523 +
53524 + if (!gr_tpe_allow(file))
53525 + return 0;
53526 +
53527 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53528 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53529 + return 0;
53530 + } else if (unlikely(!(mode & GR_EXEC))) {
53531 + return 0;
53532 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53533 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53534 + return 1;
53535 + }
53536 +
53537 + return 1;
53538 +}
53539 +
53540 +void
53541 +gr_acl_handle_psacct(struct task_struct *task, const long code)
53542 +{
53543 + unsigned long runtime;
53544 + unsigned long cputime;
53545 + unsigned int wday, cday;
53546 + __u8 whr, chr;
53547 + __u8 wmin, cmin;
53548 + __u8 wsec, csec;
53549 + struct timespec timeval;
53550 +
53551 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
53552 + !(task->acl->mode & GR_PROCACCT)))
53553 + return;
53554 +
53555 + do_posix_clock_monotonic_gettime(&timeval);
53556 + runtime = timeval.tv_sec - task->start_time.tv_sec;
53557 + wday = runtime / (3600 * 24);
53558 + runtime -= wday * (3600 * 24);
53559 + whr = runtime / 3600;
53560 + runtime -= whr * 3600;
53561 + wmin = runtime / 60;
53562 + runtime -= wmin * 60;
53563 + wsec = runtime;
53564 +
53565 + cputime = (task->utime + task->stime) / HZ;
53566 + cday = cputime / (3600 * 24);
53567 + cputime -= cday * (3600 * 24);
53568 + chr = cputime / 3600;
53569 + cputime -= chr * 3600;
53570 + cmin = cputime / 60;
53571 + cputime -= cmin * 60;
53572 + csec = cputime;
53573 +
53574 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
53575 +
53576 + return;
53577 +}
53578 +
53579 +void gr_set_kernel_label(struct task_struct *task)
53580 +{
53581 + if (gr_status & GR_READY) {
53582 + task->role = kernel_role;
53583 + task->acl = kernel_role->root_label;
53584 + }
53585 + return;
53586 +}
53587 +
53588 +#ifdef CONFIG_TASKSTATS
53589 +int gr_is_taskstats_denied(int pid)
53590 +{
53591 + struct task_struct *task;
53592 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53593 + const struct cred *cred;
53594 +#endif
53595 + int ret = 0;
53596 +
53597 + /* restrict taskstats viewing to un-chrooted root users
53598 + who have the 'view' subject flag if the RBAC system is enabled
53599 + */
53600 +
53601 + rcu_read_lock();
53602 + read_lock(&tasklist_lock);
53603 + task = find_task_by_vpid(pid);
53604 + if (task) {
53605 +#ifdef CONFIG_GRKERNSEC_CHROOT
53606 + if (proc_is_chrooted(task))
53607 + ret = -EACCES;
53608 +#endif
53609 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53610 + cred = __task_cred(task);
53611 +#ifdef CONFIG_GRKERNSEC_PROC_USER
53612 + if (cred->uid != 0)
53613 + ret = -EACCES;
53614 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53615 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
53616 + ret = -EACCES;
53617 +#endif
53618 +#endif
53619 + if (gr_status & GR_READY) {
53620 + if (!(task->acl->mode & GR_VIEW))
53621 + ret = -EACCES;
53622 + }
53623 + } else
53624 + ret = -ENOENT;
53625 +
53626 + read_unlock(&tasklist_lock);
53627 + rcu_read_unlock();
53628 +
53629 + return ret;
53630 +}
53631 +#endif
53632 +
53633 +/* AUXV entries are filled via a descendant of search_binary_handler
53634 + after we've already applied the subject for the target
53635 +*/
53636 +int gr_acl_enable_at_secure(void)
53637 +{
53638 + if (unlikely(!(gr_status & GR_READY)))
53639 + return 0;
53640 +
53641 + if (current->acl->mode & GR_ATSECURE)
53642 + return 1;
53643 +
53644 + return 0;
53645 +}
53646 +
53647 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
53648 +{
53649 + struct task_struct *task = current;
53650 + struct dentry *dentry = file->f_path.dentry;
53651 + struct vfsmount *mnt = file->f_path.mnt;
53652 + struct acl_object_label *obj, *tmp;
53653 + struct acl_subject_label *subj;
53654 + unsigned int bufsize;
53655 + int is_not_root;
53656 + char *path;
53657 + dev_t dev = __get_dev(dentry);
53658 +
53659 + if (unlikely(!(gr_status & GR_READY)))
53660 + return 1;
53661 +
53662 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53663 + return 1;
53664 +
53665 + /* ignore Eric Biederman */
53666 + if (IS_PRIVATE(dentry->d_inode))
53667 + return 1;
53668 +
53669 + subj = task->acl;
53670 + do {
53671 + obj = lookup_acl_obj_label(ino, dev, subj);
53672 + if (obj != NULL)
53673 + return (obj->mode & GR_FIND) ? 1 : 0;
53674 + } while ((subj = subj->parent_subject));
53675 +
53676 + /* this is purely an optimization since we're looking for an object
53677 + for the directory we're doing a readdir on
53678 + if it's possible for any globbed object to match the entry we're
53679 + filling into the directory, then the object we find here will be
53680 + an anchor point with attached globbed objects
53681 + */
53682 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
53683 + if (obj->globbed == NULL)
53684 + return (obj->mode & GR_FIND) ? 1 : 0;
53685 +
53686 + is_not_root = ((obj->filename[0] == '/') &&
53687 + (obj->filename[1] == '\0')) ? 0 : 1;
53688 + bufsize = PAGE_SIZE - namelen - is_not_root;
53689 +
53690 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
53691 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
53692 + return 1;
53693 +
53694 + preempt_disable();
53695 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53696 + bufsize);
53697 +
53698 + bufsize = strlen(path);
53699 +
53700 + /* if base is "/", don't append an additional slash */
53701 + if (is_not_root)
53702 + *(path + bufsize) = '/';
53703 + memcpy(path + bufsize + is_not_root, name, namelen);
53704 + *(path + bufsize + namelen + is_not_root) = '\0';
53705 +
53706 + tmp = obj->globbed;
53707 + while (tmp) {
53708 + if (!glob_match(tmp->filename, path)) {
53709 + preempt_enable();
53710 + return (tmp->mode & GR_FIND) ? 1 : 0;
53711 + }
53712 + tmp = tmp->next;
53713 + }
53714 + preempt_enable();
53715 + return (obj->mode & GR_FIND) ? 1 : 0;
53716 +}
53717 +
53718 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
53719 +EXPORT_SYMBOL(gr_acl_is_enabled);
53720 +#endif
53721 +EXPORT_SYMBOL(gr_learn_resource);
53722 +EXPORT_SYMBOL(gr_set_kernel_label);
53723 +#ifdef CONFIG_SECURITY
53724 +EXPORT_SYMBOL(gr_check_user_change);
53725 +EXPORT_SYMBOL(gr_check_group_change);
53726 +#endif
53727 +
53728 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
53729 new file mode 100644
53730 index 0000000..34fefda
53731 --- /dev/null
53732 +++ b/grsecurity/gracl_alloc.c
53733 @@ -0,0 +1,105 @@
53734 +#include <linux/kernel.h>
53735 +#include <linux/mm.h>
53736 +#include <linux/slab.h>
53737 +#include <linux/vmalloc.h>
53738 +#include <linux/gracl.h>
53739 +#include <linux/grsecurity.h>
53740 +
53741 +static unsigned long alloc_stack_next = 1;
53742 +static unsigned long alloc_stack_size = 1;
53743 +static void **alloc_stack;
53744 +
53745 +static __inline__ int
53746 +alloc_pop(void)
53747 +{
53748 + if (alloc_stack_next == 1)
53749 + return 0;
53750 +
53751 + kfree(alloc_stack[alloc_stack_next - 2]);
53752 +
53753 + alloc_stack_next--;
53754 +
53755 + return 1;
53756 +}
53757 +
53758 +static __inline__ int
53759 +alloc_push(void *buf)
53760 +{
53761 + if (alloc_stack_next >= alloc_stack_size)
53762 + return 1;
53763 +
53764 + alloc_stack[alloc_stack_next - 1] = buf;
53765 +
53766 + alloc_stack_next++;
53767 +
53768 + return 0;
53769 +}
53770 +
53771 +void *
53772 +acl_alloc(unsigned long len)
53773 +{
53774 + void *ret = NULL;
53775 +
53776 + if (!len || len > PAGE_SIZE)
53777 + goto out;
53778 +
53779 + ret = kmalloc(len, GFP_KERNEL);
53780 +
53781 + if (ret) {
53782 + if (alloc_push(ret)) {
53783 + kfree(ret);
53784 + ret = NULL;
53785 + }
53786 + }
53787 +
53788 +out:
53789 + return ret;
53790 +}
53791 +
53792 +void *
53793 +acl_alloc_num(unsigned long num, unsigned long len)
53794 +{
53795 + if (!len || (num > (PAGE_SIZE / len)))
53796 + return NULL;
53797 +
53798 + return acl_alloc(num * len);
53799 +}
53800 +
53801 +void
53802 +acl_free_all(void)
53803 +{
53804 + if (gr_acl_is_enabled() || !alloc_stack)
53805 + return;
53806 +
53807 + while (alloc_pop()) ;
53808 +
53809 + if (alloc_stack) {
53810 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
53811 + kfree(alloc_stack);
53812 + else
53813 + vfree(alloc_stack);
53814 + }
53815 +
53816 + alloc_stack = NULL;
53817 + alloc_stack_size = 1;
53818 + alloc_stack_next = 1;
53819 +
53820 + return;
53821 +}
53822 +
53823 +int
53824 +acl_alloc_stack_init(unsigned long size)
53825 +{
53826 + if ((size * sizeof (void *)) <= PAGE_SIZE)
53827 + alloc_stack =
53828 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
53829 + else
53830 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
53831 +
53832 + alloc_stack_size = size;
53833 +
53834 + if (!alloc_stack)
53835 + return 0;
53836 + else
53837 + return 1;
53838 +}
53839 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
53840 new file mode 100644
53841 index 0000000..6d21049
53842 --- /dev/null
53843 +++ b/grsecurity/gracl_cap.c
53844 @@ -0,0 +1,110 @@
53845 +#include <linux/kernel.h>
53846 +#include <linux/module.h>
53847 +#include <linux/sched.h>
53848 +#include <linux/gracl.h>
53849 +#include <linux/grsecurity.h>
53850 +#include <linux/grinternal.h>
53851 +
53852 +extern const char *captab_log[];
53853 +extern int captab_log_entries;
53854 +
53855 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
53856 +{
53857 + struct acl_subject_label *curracl;
53858 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
53859 + kernel_cap_t cap_audit = __cap_empty_set;
53860 +
53861 + if (!gr_acl_is_enabled())
53862 + return 1;
53863 +
53864 + curracl = task->acl;
53865 +
53866 + cap_drop = curracl->cap_lower;
53867 + cap_mask = curracl->cap_mask;
53868 + cap_audit = curracl->cap_invert_audit;
53869 +
53870 + while ((curracl = curracl->parent_subject)) {
53871 + /* if the cap isn't specified in the current computed mask but is specified in the
53872 + current level subject, and is lowered in the current level subject, then add
53873 + it to the set of dropped capabilities
53874 + otherwise, add the current level subject's mask to the current computed mask
53875 + */
53876 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
53877 + cap_raise(cap_mask, cap);
53878 + if (cap_raised(curracl->cap_lower, cap))
53879 + cap_raise(cap_drop, cap);
53880 + if (cap_raised(curracl->cap_invert_audit, cap))
53881 + cap_raise(cap_audit, cap);
53882 + }
53883 + }
53884 +
53885 + if (!cap_raised(cap_drop, cap)) {
53886 + if (cap_raised(cap_audit, cap))
53887 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
53888 + return 1;
53889 + }
53890 +
53891 + curracl = task->acl;
53892 +
53893 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
53894 + && cap_raised(cred->cap_effective, cap)) {
53895 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53896 + task->role->roletype, cred->uid,
53897 + cred->gid, task->exec_file ?
53898 + gr_to_filename(task->exec_file->f_path.dentry,
53899 + task->exec_file->f_path.mnt) : curracl->filename,
53900 + curracl->filename, 0UL,
53901 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
53902 + return 1;
53903 + }
53904 +
53905 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
53906 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
53907 +
53908 + return 0;
53909 +}
53910 +
53911 +int
53912 +gr_acl_is_capable(const int cap)
53913 +{
53914 + return gr_task_acl_is_capable(current, current_cred(), cap);
53915 +}
53916 +
53917 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
53918 +{
53919 + struct acl_subject_label *curracl;
53920 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
53921 +
53922 + if (!gr_acl_is_enabled())
53923 + return 1;
53924 +
53925 + curracl = task->acl;
53926 +
53927 + cap_drop = curracl->cap_lower;
53928 + cap_mask = curracl->cap_mask;
53929 +
53930 + while ((curracl = curracl->parent_subject)) {
53931 + /* if the cap isn't specified in the current computed mask but is specified in the
53932 + current level subject, and is lowered in the current level subject, then add
53933 + it to the set of dropped capabilities
53934 + otherwise, add the current level subject's mask to the current computed mask
53935 + */
53936 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
53937 + cap_raise(cap_mask, cap);
53938 + if (cap_raised(curracl->cap_lower, cap))
53939 + cap_raise(cap_drop, cap);
53940 + }
53941 + }
53942 +
53943 + if (!cap_raised(cap_drop, cap))
53944 + return 1;
53945 +
53946 + return 0;
53947 +}
53948 +
53949 +int
53950 +gr_acl_is_capable_nolog(const int cap)
53951 +{
53952 + return gr_task_acl_is_capable_nolog(current, cap);
53953 +}
53954 +
53955 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
53956 new file mode 100644
53957 index 0000000..88d0e87
53958 --- /dev/null
53959 +++ b/grsecurity/gracl_fs.c
53960 @@ -0,0 +1,435 @@
53961 +#include <linux/kernel.h>
53962 +#include <linux/sched.h>
53963 +#include <linux/types.h>
53964 +#include <linux/fs.h>
53965 +#include <linux/file.h>
53966 +#include <linux/stat.h>
53967 +#include <linux/grsecurity.h>
53968 +#include <linux/grinternal.h>
53969 +#include <linux/gracl.h>
53970 +
53971 +umode_t
53972 +gr_acl_umask(void)
53973 +{
53974 + if (unlikely(!gr_acl_is_enabled()))
53975 + return 0;
53976 +
53977 + return current->role->umask;
53978 +}
53979 +
53980 +__u32
53981 +gr_acl_handle_hidden_file(const struct dentry * dentry,
53982 + const struct vfsmount * mnt)
53983 +{
53984 + __u32 mode;
53985 +
53986 + if (unlikely(!dentry->d_inode))
53987 + return GR_FIND;
53988 +
53989 + mode =
53990 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
53991 +
53992 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
53993 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
53994 + return mode;
53995 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
53996 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
53997 + return 0;
53998 + } else if (unlikely(!(mode & GR_FIND)))
53999 + return 0;
54000 +
54001 + return GR_FIND;
54002 +}
54003 +
54004 +__u32
54005 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54006 + int acc_mode)
54007 +{
54008 + __u32 reqmode = GR_FIND;
54009 + __u32 mode;
54010 +
54011 + if (unlikely(!dentry->d_inode))
54012 + return reqmode;
54013 +
54014 + if (acc_mode & MAY_APPEND)
54015 + reqmode |= GR_APPEND;
54016 + else if (acc_mode & MAY_WRITE)
54017 + reqmode |= GR_WRITE;
54018 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54019 + reqmode |= GR_READ;
54020 +
54021 + mode =
54022 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54023 + mnt);
54024 +
54025 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54026 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54027 + reqmode & GR_READ ? " reading" : "",
54028 + reqmode & GR_WRITE ? " writing" : reqmode &
54029 + GR_APPEND ? " appending" : "");
54030 + return reqmode;
54031 + } else
54032 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54033 + {
54034 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54035 + reqmode & GR_READ ? " reading" : "",
54036 + reqmode & GR_WRITE ? " writing" : reqmode &
54037 + GR_APPEND ? " appending" : "");
54038 + return 0;
54039 + } else if (unlikely((mode & reqmode) != reqmode))
54040 + return 0;
54041 +
54042 + return reqmode;
54043 +}
54044 +
54045 +__u32
54046 +gr_acl_handle_creat(const struct dentry * dentry,
54047 + const struct dentry * p_dentry,
54048 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54049 + const int imode)
54050 +{
54051 + __u32 reqmode = GR_WRITE | GR_CREATE;
54052 + __u32 mode;
54053 +
54054 + if (acc_mode & MAY_APPEND)
54055 + reqmode |= GR_APPEND;
54056 + // if a directory was required or the directory already exists, then
54057 + // don't count this open as a read
54058 + if ((acc_mode & MAY_READ) &&
54059 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54060 + reqmode |= GR_READ;
54061 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54062 + reqmode |= GR_SETID;
54063 +
54064 + mode =
54065 + gr_check_create(dentry, p_dentry, p_mnt,
54066 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54067 +
54068 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54069 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54070 + reqmode & GR_READ ? " reading" : "",
54071 + reqmode & GR_WRITE ? " writing" : reqmode &
54072 + GR_APPEND ? " appending" : "");
54073 + return reqmode;
54074 + } else
54075 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54076 + {
54077 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54078 + reqmode & GR_READ ? " reading" : "",
54079 + reqmode & GR_WRITE ? " writing" : reqmode &
54080 + GR_APPEND ? " appending" : "");
54081 + return 0;
54082 + } else if (unlikely((mode & reqmode) != reqmode))
54083 + return 0;
54084 +
54085 + return reqmode;
54086 +}
54087 +
54088 +__u32
54089 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54090 + const int fmode)
54091 +{
54092 + __u32 mode, reqmode = GR_FIND;
54093 +
54094 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54095 + reqmode |= GR_EXEC;
54096 + if (fmode & S_IWOTH)
54097 + reqmode |= GR_WRITE;
54098 + if (fmode & S_IROTH)
54099 + reqmode |= GR_READ;
54100 +
54101 + mode =
54102 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54103 + mnt);
54104 +
54105 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54106 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54107 + reqmode & GR_READ ? " reading" : "",
54108 + reqmode & GR_WRITE ? " writing" : "",
54109 + reqmode & GR_EXEC ? " executing" : "");
54110 + return reqmode;
54111 + } else
54112 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54113 + {
54114 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54115 + reqmode & GR_READ ? " reading" : "",
54116 + reqmode & GR_WRITE ? " writing" : "",
54117 + reqmode & GR_EXEC ? " executing" : "");
54118 + return 0;
54119 + } else if (unlikely((mode & reqmode) != reqmode))
54120 + return 0;
54121 +
54122 + return reqmode;
54123 +}
54124 +
54125 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
54126 +{
54127 + __u32 mode;
54128 +
54129 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
54130 +
54131 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54132 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
54133 + return mode;
54134 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54135 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
54136 + return 0;
54137 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54138 + return 0;
54139 +
54140 + return (reqmode);
54141 +}
54142 +
54143 +__u32
54144 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54145 +{
54146 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
54147 +}
54148 +
54149 +__u32
54150 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
54151 +{
54152 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
54153 +}
54154 +
54155 +__u32
54156 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
54157 +{
54158 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
54159 +}
54160 +
54161 +__u32
54162 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
54163 +{
54164 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
54165 +}
54166 +
54167 +__u32
54168 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
54169 + umode_t *modeptr)
54170 +{
54171 + umode_t mode;
54172 +
54173 + *modeptr &= ~gr_acl_umask();
54174 + mode = *modeptr;
54175 +
54176 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
54177 + return 1;
54178 +
54179 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
54180 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
54181 + GR_CHMOD_ACL_MSG);
54182 + } else {
54183 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
54184 + }
54185 +}
54186 +
54187 +__u32
54188 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
54189 +{
54190 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
54191 +}
54192 +
54193 +__u32
54194 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
54195 +{
54196 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
54197 +}
54198 +
54199 +__u32
54200 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
54201 +{
54202 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
54203 +}
54204 +
54205 +__u32
54206 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
54207 +{
54208 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
54209 + GR_UNIXCONNECT_ACL_MSG);
54210 +}
54211 +
54212 +/* hardlinks require at minimum create and link permission,
54213 + any additional privilege required is based on the
54214 + privilege of the file being linked to
54215 +*/
54216 +__u32
54217 +gr_acl_handle_link(const struct dentry * new_dentry,
54218 + const struct dentry * parent_dentry,
54219 + const struct vfsmount * parent_mnt,
54220 + const struct dentry * old_dentry,
54221 + const struct vfsmount * old_mnt, const char *to)
54222 +{
54223 + __u32 mode;
54224 + __u32 needmode = GR_CREATE | GR_LINK;
54225 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
54226 +
54227 + mode =
54228 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
54229 + old_mnt);
54230 +
54231 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
54232 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54233 + return mode;
54234 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54235 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54236 + return 0;
54237 + } else if (unlikely((mode & needmode) != needmode))
54238 + return 0;
54239 +
54240 + return 1;
54241 +}
54242 +
54243 +__u32
54244 +gr_acl_handle_symlink(const struct dentry * new_dentry,
54245 + const struct dentry * parent_dentry,
54246 + const struct vfsmount * parent_mnt, const char *from)
54247 +{
54248 + __u32 needmode = GR_WRITE | GR_CREATE;
54249 + __u32 mode;
54250 +
54251 + mode =
54252 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
54253 + GR_CREATE | GR_AUDIT_CREATE |
54254 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
54255 +
54256 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
54257 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54258 + return mode;
54259 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54260 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54261 + return 0;
54262 + } else if (unlikely((mode & needmode) != needmode))
54263 + return 0;
54264 +
54265 + return (GR_WRITE | GR_CREATE);
54266 +}
54267 +
54268 +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)
54269 +{
54270 + __u32 mode;
54271 +
54272 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54273 +
54274 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54275 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
54276 + return mode;
54277 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54278 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
54279 + return 0;
54280 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54281 + return 0;
54282 +
54283 + return (reqmode);
54284 +}
54285 +
54286 +__u32
54287 +gr_acl_handle_mknod(const struct dentry * new_dentry,
54288 + const struct dentry * parent_dentry,
54289 + const struct vfsmount * parent_mnt,
54290 + const int mode)
54291 +{
54292 + __u32 reqmode = GR_WRITE | GR_CREATE;
54293 + if (unlikely(mode & (S_ISUID | S_ISGID)))
54294 + reqmode |= GR_SETID;
54295 +
54296 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54297 + reqmode, GR_MKNOD_ACL_MSG);
54298 +}
54299 +
54300 +__u32
54301 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
54302 + const struct dentry *parent_dentry,
54303 + const struct vfsmount *parent_mnt)
54304 +{
54305 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54306 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
54307 +}
54308 +
54309 +#define RENAME_CHECK_SUCCESS(old, new) \
54310 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
54311 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
54312 +
54313 +int
54314 +gr_acl_handle_rename(struct dentry *new_dentry,
54315 + struct dentry *parent_dentry,
54316 + const struct vfsmount *parent_mnt,
54317 + struct dentry *old_dentry,
54318 + struct inode *old_parent_inode,
54319 + struct vfsmount *old_mnt, const char *newname)
54320 +{
54321 + __u32 comp1, comp2;
54322 + int error = 0;
54323 +
54324 + if (unlikely(!gr_acl_is_enabled()))
54325 + return 0;
54326 +
54327 + if (!new_dentry->d_inode) {
54328 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
54329 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
54330 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
54331 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
54332 + GR_DELETE | GR_AUDIT_DELETE |
54333 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54334 + GR_SUPPRESS, old_mnt);
54335 + } else {
54336 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
54337 + GR_CREATE | GR_DELETE |
54338 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
54339 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54340 + GR_SUPPRESS, parent_mnt);
54341 + comp2 =
54342 + gr_search_file(old_dentry,
54343 + GR_READ | GR_WRITE | GR_AUDIT_READ |
54344 + GR_DELETE | GR_AUDIT_DELETE |
54345 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
54346 + }
54347 +
54348 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
54349 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
54350 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54351 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
54352 + && !(comp2 & GR_SUPPRESS)) {
54353 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54354 + error = -EACCES;
54355 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
54356 + error = -EACCES;
54357 +
54358 + return error;
54359 +}
54360 +
54361 +void
54362 +gr_acl_handle_exit(void)
54363 +{
54364 + u16 id;
54365 + char *rolename;
54366 + struct file *exec_file;
54367 +
54368 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
54369 + !(current->role->roletype & GR_ROLE_PERSIST))) {
54370 + id = current->acl_role_id;
54371 + rolename = current->role->rolename;
54372 + gr_set_acls(1);
54373 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
54374 + }
54375 +
54376 + write_lock(&grsec_exec_file_lock);
54377 + exec_file = current->exec_file;
54378 + current->exec_file = NULL;
54379 + write_unlock(&grsec_exec_file_lock);
54380 +
54381 + if (exec_file)
54382 + fput(exec_file);
54383 +}
54384 +
54385 +int
54386 +gr_acl_handle_procpidmem(const struct task_struct *task)
54387 +{
54388 + if (unlikely(!gr_acl_is_enabled()))
54389 + return 0;
54390 +
54391 + if (task != current && task->acl->mode & GR_PROTPROCFD)
54392 + return -EACCES;
54393 +
54394 + return 0;
54395 +}
54396 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
54397 new file mode 100644
54398 index 0000000..17050ca
54399 --- /dev/null
54400 +++ b/grsecurity/gracl_ip.c
54401 @@ -0,0 +1,381 @@
54402 +#include <linux/kernel.h>
54403 +#include <asm/uaccess.h>
54404 +#include <asm/errno.h>
54405 +#include <net/sock.h>
54406 +#include <linux/file.h>
54407 +#include <linux/fs.h>
54408 +#include <linux/net.h>
54409 +#include <linux/in.h>
54410 +#include <linux/skbuff.h>
54411 +#include <linux/ip.h>
54412 +#include <linux/udp.h>
54413 +#include <linux/types.h>
54414 +#include <linux/sched.h>
54415 +#include <linux/netdevice.h>
54416 +#include <linux/inetdevice.h>
54417 +#include <linux/gracl.h>
54418 +#include <linux/grsecurity.h>
54419 +#include <linux/grinternal.h>
54420 +
54421 +#define GR_BIND 0x01
54422 +#define GR_CONNECT 0x02
54423 +#define GR_INVERT 0x04
54424 +#define GR_BINDOVERRIDE 0x08
54425 +#define GR_CONNECTOVERRIDE 0x10
54426 +#define GR_SOCK_FAMILY 0x20
54427 +
54428 +static const char * gr_protocols[IPPROTO_MAX] = {
54429 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
54430 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
54431 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
54432 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
54433 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
54434 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
54435 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
54436 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
54437 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
54438 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
54439 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
54440 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
54441 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
54442 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
54443 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
54444 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
54445 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
54446 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
54447 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
54448 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
54449 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
54450 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
54451 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
54452 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
54453 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
54454 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
54455 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
54456 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
54457 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
54458 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
54459 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
54460 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
54461 + };
54462 +
54463 +static const char * gr_socktypes[SOCK_MAX] = {
54464 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
54465 + "unknown:7", "unknown:8", "unknown:9", "packet"
54466 + };
54467 +
54468 +static const char * gr_sockfamilies[AF_MAX+1] = {
54469 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
54470 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
54471 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
54472 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
54473 + };
54474 +
54475 +const char *
54476 +gr_proto_to_name(unsigned char proto)
54477 +{
54478 + return gr_protocols[proto];
54479 +}
54480 +
54481 +const char *
54482 +gr_socktype_to_name(unsigned char type)
54483 +{
54484 + return gr_socktypes[type];
54485 +}
54486 +
54487 +const char *
54488 +gr_sockfamily_to_name(unsigned char family)
54489 +{
54490 + return gr_sockfamilies[family];
54491 +}
54492 +
54493 +int
54494 +gr_search_socket(const int domain, const int type, const int protocol)
54495 +{
54496 + struct acl_subject_label *curr;
54497 + const struct cred *cred = current_cred();
54498 +
54499 + if (unlikely(!gr_acl_is_enabled()))
54500 + goto exit;
54501 +
54502 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
54503 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
54504 + goto exit; // let the kernel handle it
54505 +
54506 + curr = current->acl;
54507 +
54508 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
54509 + /* the family is allowed, if this is PF_INET allow it only if
54510 + the extra sock type/protocol checks pass */
54511 + if (domain == PF_INET)
54512 + goto inet_check;
54513 + goto exit;
54514 + } else {
54515 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54516 + __u32 fakeip = 0;
54517 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54518 + current->role->roletype, cred->uid,
54519 + cred->gid, current->exec_file ?
54520 + gr_to_filename(current->exec_file->f_path.dentry,
54521 + current->exec_file->f_path.mnt) :
54522 + curr->filename, curr->filename,
54523 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
54524 + &current->signal->saved_ip);
54525 + goto exit;
54526 + }
54527 + goto exit_fail;
54528 + }
54529 +
54530 +inet_check:
54531 + /* the rest of this checking is for IPv4 only */
54532 + if (!curr->ips)
54533 + goto exit;
54534 +
54535 + if ((curr->ip_type & (1 << type)) &&
54536 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
54537 + goto exit;
54538 +
54539 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54540 + /* we don't place acls on raw sockets , and sometimes
54541 + dgram/ip sockets are opened for ioctl and not
54542 + bind/connect, so we'll fake a bind learn log */
54543 + if (type == SOCK_RAW || type == SOCK_PACKET) {
54544 + __u32 fakeip = 0;
54545 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54546 + current->role->roletype, cred->uid,
54547 + cred->gid, current->exec_file ?
54548 + gr_to_filename(current->exec_file->f_path.dentry,
54549 + current->exec_file->f_path.mnt) :
54550 + curr->filename, curr->filename,
54551 + &fakeip, 0, type,
54552 + protocol, GR_CONNECT, &current->signal->saved_ip);
54553 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
54554 + __u32 fakeip = 0;
54555 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54556 + current->role->roletype, cred->uid,
54557 + cred->gid, current->exec_file ?
54558 + gr_to_filename(current->exec_file->f_path.dentry,
54559 + current->exec_file->f_path.mnt) :
54560 + curr->filename, curr->filename,
54561 + &fakeip, 0, type,
54562 + protocol, GR_BIND, &current->signal->saved_ip);
54563 + }
54564 + /* we'll log when they use connect or bind */
54565 + goto exit;
54566 + }
54567 +
54568 +exit_fail:
54569 + if (domain == PF_INET)
54570 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
54571 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
54572 + else
54573 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
54574 + gr_socktype_to_name(type), protocol);
54575 +
54576 + return 0;
54577 +exit:
54578 + return 1;
54579 +}
54580 +
54581 +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)
54582 +{
54583 + if ((ip->mode & mode) &&
54584 + (ip_port >= ip->low) &&
54585 + (ip_port <= ip->high) &&
54586 + ((ntohl(ip_addr) & our_netmask) ==
54587 + (ntohl(our_addr) & our_netmask))
54588 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
54589 + && (ip->type & (1 << type))) {
54590 + if (ip->mode & GR_INVERT)
54591 + return 2; // specifically denied
54592 + else
54593 + return 1; // allowed
54594 + }
54595 +
54596 + return 0; // not specifically allowed, may continue parsing
54597 +}
54598 +
54599 +static int
54600 +gr_search_connectbind(const int full_mode, struct sock *sk,
54601 + struct sockaddr_in *addr, const int type)
54602 +{
54603 + char iface[IFNAMSIZ] = {0};
54604 + struct acl_subject_label *curr;
54605 + struct acl_ip_label *ip;
54606 + struct inet_sock *isk;
54607 + struct net_device *dev;
54608 + struct in_device *idev;
54609 + unsigned long i;
54610 + int ret;
54611 + int mode = full_mode & (GR_BIND | GR_CONNECT);
54612 + __u32 ip_addr = 0;
54613 + __u32 our_addr;
54614 + __u32 our_netmask;
54615 + char *p;
54616 + __u16 ip_port = 0;
54617 + const struct cred *cred = current_cred();
54618 +
54619 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
54620 + return 0;
54621 +
54622 + curr = current->acl;
54623 + isk = inet_sk(sk);
54624 +
54625 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
54626 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
54627 + addr->sin_addr.s_addr = curr->inaddr_any_override;
54628 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
54629 + struct sockaddr_in saddr;
54630 + int err;
54631 +
54632 + saddr.sin_family = AF_INET;
54633 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
54634 + saddr.sin_port = isk->inet_sport;
54635 +
54636 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
54637 + if (err)
54638 + return err;
54639 +
54640 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
54641 + if (err)
54642 + return err;
54643 + }
54644 +
54645 + if (!curr->ips)
54646 + return 0;
54647 +
54648 + ip_addr = addr->sin_addr.s_addr;
54649 + ip_port = ntohs(addr->sin_port);
54650 +
54651 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54652 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54653 + current->role->roletype, cred->uid,
54654 + cred->gid, current->exec_file ?
54655 + gr_to_filename(current->exec_file->f_path.dentry,
54656 + current->exec_file->f_path.mnt) :
54657 + curr->filename, curr->filename,
54658 + &ip_addr, ip_port, type,
54659 + sk->sk_protocol, mode, &current->signal->saved_ip);
54660 + return 0;
54661 + }
54662 +
54663 + for (i = 0; i < curr->ip_num; i++) {
54664 + ip = *(curr->ips + i);
54665 + if (ip->iface != NULL) {
54666 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
54667 + p = strchr(iface, ':');
54668 + if (p != NULL)
54669 + *p = '\0';
54670 + dev = dev_get_by_name(sock_net(sk), iface);
54671 + if (dev == NULL)
54672 + continue;
54673 + idev = in_dev_get(dev);
54674 + if (idev == NULL) {
54675 + dev_put(dev);
54676 + continue;
54677 + }
54678 + rcu_read_lock();
54679 + for_ifa(idev) {
54680 + if (!strcmp(ip->iface, ifa->ifa_label)) {
54681 + our_addr = ifa->ifa_address;
54682 + our_netmask = 0xffffffff;
54683 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
54684 + if (ret == 1) {
54685 + rcu_read_unlock();
54686 + in_dev_put(idev);
54687 + dev_put(dev);
54688 + return 0;
54689 + } else if (ret == 2) {
54690 + rcu_read_unlock();
54691 + in_dev_put(idev);
54692 + dev_put(dev);
54693 + goto denied;
54694 + }
54695 + }
54696 + } endfor_ifa(idev);
54697 + rcu_read_unlock();
54698 + in_dev_put(idev);
54699 + dev_put(dev);
54700 + } else {
54701 + our_addr = ip->addr;
54702 + our_netmask = ip->netmask;
54703 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
54704 + if (ret == 1)
54705 + return 0;
54706 + else if (ret == 2)
54707 + goto denied;
54708 + }
54709 + }
54710 +
54711 +denied:
54712 + if (mode == GR_BIND)
54713 + 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));
54714 + else if (mode == GR_CONNECT)
54715 + 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));
54716 +
54717 + return -EACCES;
54718 +}
54719 +
54720 +int
54721 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
54722 +{
54723 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
54724 +}
54725 +
54726 +int
54727 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
54728 +{
54729 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
54730 +}
54731 +
54732 +int gr_search_listen(struct socket *sock)
54733 +{
54734 + struct sock *sk = sock->sk;
54735 + struct sockaddr_in addr;
54736 +
54737 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
54738 + addr.sin_port = inet_sk(sk)->inet_sport;
54739 +
54740 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
54741 +}
54742 +
54743 +int gr_search_accept(struct socket *sock)
54744 +{
54745 + struct sock *sk = sock->sk;
54746 + struct sockaddr_in addr;
54747 +
54748 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
54749 + addr.sin_port = inet_sk(sk)->inet_sport;
54750 +
54751 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
54752 +}
54753 +
54754 +int
54755 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
54756 +{
54757 + if (addr)
54758 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
54759 + else {
54760 + struct sockaddr_in sin;
54761 + const struct inet_sock *inet = inet_sk(sk);
54762 +
54763 + sin.sin_addr.s_addr = inet->inet_daddr;
54764 + sin.sin_port = inet->inet_dport;
54765 +
54766 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
54767 + }
54768 +}
54769 +
54770 +int
54771 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
54772 +{
54773 + struct sockaddr_in sin;
54774 +
54775 + if (unlikely(skb->len < sizeof (struct udphdr)))
54776 + return 0; // skip this packet
54777 +
54778 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
54779 + sin.sin_port = udp_hdr(skb)->source;
54780 +
54781 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
54782 +}
54783 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
54784 new file mode 100644
54785 index 0000000..25f54ef
54786 --- /dev/null
54787 +++ b/grsecurity/gracl_learn.c
54788 @@ -0,0 +1,207 @@
54789 +#include <linux/kernel.h>
54790 +#include <linux/mm.h>
54791 +#include <linux/sched.h>
54792 +#include <linux/poll.h>
54793 +#include <linux/string.h>
54794 +#include <linux/file.h>
54795 +#include <linux/types.h>
54796 +#include <linux/vmalloc.h>
54797 +#include <linux/grinternal.h>
54798 +
54799 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
54800 + size_t count, loff_t *ppos);
54801 +extern int gr_acl_is_enabled(void);
54802 +
54803 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
54804 +static int gr_learn_attached;
54805 +
54806 +/* use a 512k buffer */
54807 +#define LEARN_BUFFER_SIZE (512 * 1024)
54808 +
54809 +static DEFINE_SPINLOCK(gr_learn_lock);
54810 +static DEFINE_MUTEX(gr_learn_user_mutex);
54811 +
54812 +/* we need to maintain two buffers, so that the kernel context of grlearn
54813 + uses a semaphore around the userspace copying, and the other kernel contexts
54814 + use a spinlock when copying into the buffer, since they cannot sleep
54815 +*/
54816 +static char *learn_buffer;
54817 +static char *learn_buffer_user;
54818 +static int learn_buffer_len;
54819 +static int learn_buffer_user_len;
54820 +
54821 +static ssize_t
54822 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
54823 +{
54824 + DECLARE_WAITQUEUE(wait, current);
54825 + ssize_t retval = 0;
54826 +
54827 + add_wait_queue(&learn_wait, &wait);
54828 + set_current_state(TASK_INTERRUPTIBLE);
54829 + do {
54830 + mutex_lock(&gr_learn_user_mutex);
54831 + spin_lock(&gr_learn_lock);
54832 + if (learn_buffer_len)
54833 + break;
54834 + spin_unlock(&gr_learn_lock);
54835 + mutex_unlock(&gr_learn_user_mutex);
54836 + if (file->f_flags & O_NONBLOCK) {
54837 + retval = -EAGAIN;
54838 + goto out;
54839 + }
54840 + if (signal_pending(current)) {
54841 + retval = -ERESTARTSYS;
54842 + goto out;
54843 + }
54844 +
54845 + schedule();
54846 + } while (1);
54847 +
54848 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
54849 + learn_buffer_user_len = learn_buffer_len;
54850 + retval = learn_buffer_len;
54851 + learn_buffer_len = 0;
54852 +
54853 + spin_unlock(&gr_learn_lock);
54854 +
54855 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
54856 + retval = -EFAULT;
54857 +
54858 + mutex_unlock(&gr_learn_user_mutex);
54859 +out:
54860 + set_current_state(TASK_RUNNING);
54861 + remove_wait_queue(&learn_wait, &wait);
54862 + return retval;
54863 +}
54864 +
54865 +static unsigned int
54866 +poll_learn(struct file * file, poll_table * wait)
54867 +{
54868 + poll_wait(file, &learn_wait, wait);
54869 +
54870 + if (learn_buffer_len)
54871 + return (POLLIN | POLLRDNORM);
54872 +
54873 + return 0;
54874 +}
54875 +
54876 +void
54877 +gr_clear_learn_entries(void)
54878 +{
54879 + char *tmp;
54880 +
54881 + mutex_lock(&gr_learn_user_mutex);
54882 + spin_lock(&gr_learn_lock);
54883 + tmp = learn_buffer;
54884 + learn_buffer = NULL;
54885 + spin_unlock(&gr_learn_lock);
54886 + if (tmp)
54887 + vfree(tmp);
54888 + if (learn_buffer_user != NULL) {
54889 + vfree(learn_buffer_user);
54890 + learn_buffer_user = NULL;
54891 + }
54892 + learn_buffer_len = 0;
54893 + mutex_unlock(&gr_learn_user_mutex);
54894 +
54895 + return;
54896 +}
54897 +
54898 +void
54899 +gr_add_learn_entry(const char *fmt, ...)
54900 +{
54901 + va_list args;
54902 + unsigned int len;
54903 +
54904 + if (!gr_learn_attached)
54905 + return;
54906 +
54907 + spin_lock(&gr_learn_lock);
54908 +
54909 + /* leave a gap at the end so we know when it's "full" but don't have to
54910 + compute the exact length of the string we're trying to append
54911 + */
54912 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
54913 + spin_unlock(&gr_learn_lock);
54914 + wake_up_interruptible(&learn_wait);
54915 + return;
54916 + }
54917 + if (learn_buffer == NULL) {
54918 + spin_unlock(&gr_learn_lock);
54919 + return;
54920 + }
54921 +
54922 + va_start(args, fmt);
54923 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
54924 + va_end(args);
54925 +
54926 + learn_buffer_len += len + 1;
54927 +
54928 + spin_unlock(&gr_learn_lock);
54929 + wake_up_interruptible(&learn_wait);
54930 +
54931 + return;
54932 +}
54933 +
54934 +static int
54935 +open_learn(struct inode *inode, struct file *file)
54936 +{
54937 + if (file->f_mode & FMODE_READ && gr_learn_attached)
54938 + return -EBUSY;
54939 + if (file->f_mode & FMODE_READ) {
54940 + int retval = 0;
54941 + mutex_lock(&gr_learn_user_mutex);
54942 + if (learn_buffer == NULL)
54943 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
54944 + if (learn_buffer_user == NULL)
54945 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
54946 + if (learn_buffer == NULL) {
54947 + retval = -ENOMEM;
54948 + goto out_error;
54949 + }
54950 + if (learn_buffer_user == NULL) {
54951 + retval = -ENOMEM;
54952 + goto out_error;
54953 + }
54954 + learn_buffer_len = 0;
54955 + learn_buffer_user_len = 0;
54956 + gr_learn_attached = 1;
54957 +out_error:
54958 + mutex_unlock(&gr_learn_user_mutex);
54959 + return retval;
54960 + }
54961 + return 0;
54962 +}
54963 +
54964 +static int
54965 +close_learn(struct inode *inode, struct file *file)
54966 +{
54967 + if (file->f_mode & FMODE_READ) {
54968 + char *tmp = NULL;
54969 + mutex_lock(&gr_learn_user_mutex);
54970 + spin_lock(&gr_learn_lock);
54971 + tmp = learn_buffer;
54972 + learn_buffer = NULL;
54973 + spin_unlock(&gr_learn_lock);
54974 + if (tmp)
54975 + vfree(tmp);
54976 + if (learn_buffer_user != NULL) {
54977 + vfree(learn_buffer_user);
54978 + learn_buffer_user = NULL;
54979 + }
54980 + learn_buffer_len = 0;
54981 + learn_buffer_user_len = 0;
54982 + gr_learn_attached = 0;
54983 + mutex_unlock(&gr_learn_user_mutex);
54984 + }
54985 +
54986 + return 0;
54987 +}
54988 +
54989 +const struct file_operations grsec_fops = {
54990 + .read = read_learn,
54991 + .write = write_grsec_handler,
54992 + .open = open_learn,
54993 + .release = close_learn,
54994 + .poll = poll_learn,
54995 +};
54996 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
54997 new file mode 100644
54998 index 0000000..39645c9
54999 --- /dev/null
55000 +++ b/grsecurity/gracl_res.c
55001 @@ -0,0 +1,68 @@
55002 +#include <linux/kernel.h>
55003 +#include <linux/sched.h>
55004 +#include <linux/gracl.h>
55005 +#include <linux/grinternal.h>
55006 +
55007 +static const char *restab_log[] = {
55008 + [RLIMIT_CPU] = "RLIMIT_CPU",
55009 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55010 + [RLIMIT_DATA] = "RLIMIT_DATA",
55011 + [RLIMIT_STACK] = "RLIMIT_STACK",
55012 + [RLIMIT_CORE] = "RLIMIT_CORE",
55013 + [RLIMIT_RSS] = "RLIMIT_RSS",
55014 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
55015 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55016 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55017 + [RLIMIT_AS] = "RLIMIT_AS",
55018 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55019 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55020 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55021 + [RLIMIT_NICE] = "RLIMIT_NICE",
55022 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55023 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55024 + [GR_CRASH_RES] = "RLIMIT_CRASH"
55025 +};
55026 +
55027 +void
55028 +gr_log_resource(const struct task_struct *task,
55029 + const int res, const unsigned long wanted, const int gt)
55030 +{
55031 + const struct cred *cred;
55032 + unsigned long rlim;
55033 +
55034 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
55035 + return;
55036 +
55037 + // not yet supported resource
55038 + if (unlikely(!restab_log[res]))
55039 + return;
55040 +
55041 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55042 + rlim = task_rlimit_max(task, res);
55043 + else
55044 + rlim = task_rlimit(task, res);
55045 +
55046 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55047 + return;
55048 +
55049 + rcu_read_lock();
55050 + cred = __task_cred(task);
55051 +
55052 + if (res == RLIMIT_NPROC &&
55053 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55054 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55055 + goto out_rcu_unlock;
55056 + else if (res == RLIMIT_MEMLOCK &&
55057 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55058 + goto out_rcu_unlock;
55059 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55060 + goto out_rcu_unlock;
55061 + rcu_read_unlock();
55062 +
55063 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55064 +
55065 + return;
55066 +out_rcu_unlock:
55067 + rcu_read_unlock();
55068 + return;
55069 +}
55070 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55071 new file mode 100644
55072 index 0000000..5556be3
55073 --- /dev/null
55074 +++ b/grsecurity/gracl_segv.c
55075 @@ -0,0 +1,299 @@
55076 +#include <linux/kernel.h>
55077 +#include <linux/mm.h>
55078 +#include <asm/uaccess.h>
55079 +#include <asm/errno.h>
55080 +#include <asm/mman.h>
55081 +#include <net/sock.h>
55082 +#include <linux/file.h>
55083 +#include <linux/fs.h>
55084 +#include <linux/net.h>
55085 +#include <linux/in.h>
55086 +#include <linux/slab.h>
55087 +#include <linux/types.h>
55088 +#include <linux/sched.h>
55089 +#include <linux/timer.h>
55090 +#include <linux/gracl.h>
55091 +#include <linux/grsecurity.h>
55092 +#include <linux/grinternal.h>
55093 +
55094 +static struct crash_uid *uid_set;
55095 +static unsigned short uid_used;
55096 +static DEFINE_SPINLOCK(gr_uid_lock);
55097 +extern rwlock_t gr_inode_lock;
55098 +extern struct acl_subject_label *
55099 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55100 + struct acl_role_label *role);
55101 +
55102 +#ifdef CONFIG_BTRFS_FS
55103 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55104 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55105 +#endif
55106 +
55107 +static inline dev_t __get_dev(const struct dentry *dentry)
55108 +{
55109 +#ifdef CONFIG_BTRFS_FS
55110 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55111 + return get_btrfs_dev_from_inode(dentry->d_inode);
55112 + else
55113 +#endif
55114 + return dentry->d_inode->i_sb->s_dev;
55115 +}
55116 +
55117 +int
55118 +gr_init_uidset(void)
55119 +{
55120 + uid_set =
55121 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
55122 + uid_used = 0;
55123 +
55124 + return uid_set ? 1 : 0;
55125 +}
55126 +
55127 +void
55128 +gr_free_uidset(void)
55129 +{
55130 + if (uid_set)
55131 + kfree(uid_set);
55132 +
55133 + return;
55134 +}
55135 +
55136 +int
55137 +gr_find_uid(const uid_t uid)
55138 +{
55139 + struct crash_uid *tmp = uid_set;
55140 + uid_t buid;
55141 + int low = 0, high = uid_used - 1, mid;
55142 +
55143 + while (high >= low) {
55144 + mid = (low + high) >> 1;
55145 + buid = tmp[mid].uid;
55146 + if (buid == uid)
55147 + return mid;
55148 + if (buid > uid)
55149 + high = mid - 1;
55150 + if (buid < uid)
55151 + low = mid + 1;
55152 + }
55153 +
55154 + return -1;
55155 +}
55156 +
55157 +static __inline__ void
55158 +gr_insertsort(void)
55159 +{
55160 + unsigned short i, j;
55161 + struct crash_uid index;
55162 +
55163 + for (i = 1; i < uid_used; i++) {
55164 + index = uid_set[i];
55165 + j = i;
55166 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
55167 + uid_set[j] = uid_set[j - 1];
55168 + j--;
55169 + }
55170 + uid_set[j] = index;
55171 + }
55172 +
55173 + return;
55174 +}
55175 +
55176 +static __inline__ void
55177 +gr_insert_uid(const uid_t uid, const unsigned long expires)
55178 +{
55179 + int loc;
55180 +
55181 + if (uid_used == GR_UIDTABLE_MAX)
55182 + return;
55183 +
55184 + loc = gr_find_uid(uid);
55185 +
55186 + if (loc >= 0) {
55187 + uid_set[loc].expires = expires;
55188 + return;
55189 + }
55190 +
55191 + uid_set[uid_used].uid = uid;
55192 + uid_set[uid_used].expires = expires;
55193 + uid_used++;
55194 +
55195 + gr_insertsort();
55196 +
55197 + return;
55198 +}
55199 +
55200 +void
55201 +gr_remove_uid(const unsigned short loc)
55202 +{
55203 + unsigned short i;
55204 +
55205 + for (i = loc + 1; i < uid_used; i++)
55206 + uid_set[i - 1] = uid_set[i];
55207 +
55208 + uid_used--;
55209 +
55210 + return;
55211 +}
55212 +
55213 +int
55214 +gr_check_crash_uid(const uid_t uid)
55215 +{
55216 + int loc;
55217 + int ret = 0;
55218 +
55219 + if (unlikely(!gr_acl_is_enabled()))
55220 + return 0;
55221 +
55222 + spin_lock(&gr_uid_lock);
55223 + loc = gr_find_uid(uid);
55224 +
55225 + if (loc < 0)
55226 + goto out_unlock;
55227 +
55228 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
55229 + gr_remove_uid(loc);
55230 + else
55231 + ret = 1;
55232 +
55233 +out_unlock:
55234 + spin_unlock(&gr_uid_lock);
55235 + return ret;
55236 +}
55237 +
55238 +static __inline__ int
55239 +proc_is_setxid(const struct cred *cred)
55240 +{
55241 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
55242 + cred->uid != cred->fsuid)
55243 + return 1;
55244 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
55245 + cred->gid != cred->fsgid)
55246 + return 1;
55247 +
55248 + return 0;
55249 +}
55250 +
55251 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
55252 +
55253 +void
55254 +gr_handle_crash(struct task_struct *task, const int sig)
55255 +{
55256 + struct acl_subject_label *curr;
55257 + struct task_struct *tsk, *tsk2;
55258 + const struct cred *cred;
55259 + const struct cred *cred2;
55260 +
55261 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
55262 + return;
55263 +
55264 + if (unlikely(!gr_acl_is_enabled()))
55265 + return;
55266 +
55267 + curr = task->acl;
55268 +
55269 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
55270 + return;
55271 +
55272 + if (time_before_eq(curr->expires, get_seconds())) {
55273 + curr->expires = 0;
55274 + curr->crashes = 0;
55275 + }
55276 +
55277 + curr->crashes++;
55278 +
55279 + if (!curr->expires)
55280 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
55281 +
55282 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55283 + time_after(curr->expires, get_seconds())) {
55284 + rcu_read_lock();
55285 + cred = __task_cred(task);
55286 + if (cred->uid && proc_is_setxid(cred)) {
55287 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55288 + spin_lock(&gr_uid_lock);
55289 + gr_insert_uid(cred->uid, curr->expires);
55290 + spin_unlock(&gr_uid_lock);
55291 + curr->expires = 0;
55292 + curr->crashes = 0;
55293 + read_lock(&tasklist_lock);
55294 + do_each_thread(tsk2, tsk) {
55295 + cred2 = __task_cred(tsk);
55296 + if (tsk != task && cred2->uid == cred->uid)
55297 + gr_fake_force_sig(SIGKILL, tsk);
55298 + } while_each_thread(tsk2, tsk);
55299 + read_unlock(&tasklist_lock);
55300 + } else {
55301 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55302 + read_lock(&tasklist_lock);
55303 + read_lock(&grsec_exec_file_lock);
55304 + do_each_thread(tsk2, tsk) {
55305 + if (likely(tsk != task)) {
55306 + // if this thread has the same subject as the one that triggered
55307 + // RES_CRASH and it's the same binary, kill it
55308 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
55309 + gr_fake_force_sig(SIGKILL, tsk);
55310 + }
55311 + } while_each_thread(tsk2, tsk);
55312 + read_unlock(&grsec_exec_file_lock);
55313 + read_unlock(&tasklist_lock);
55314 + }
55315 + rcu_read_unlock();
55316 + }
55317 +
55318 + return;
55319 +}
55320 +
55321 +int
55322 +gr_check_crash_exec(const struct file *filp)
55323 +{
55324 + struct acl_subject_label *curr;
55325 +
55326 + if (unlikely(!gr_acl_is_enabled()))
55327 + return 0;
55328 +
55329 + read_lock(&gr_inode_lock);
55330 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
55331 + __get_dev(filp->f_path.dentry),
55332 + current->role);
55333 + read_unlock(&gr_inode_lock);
55334 +
55335 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
55336 + (!curr->crashes && !curr->expires))
55337 + return 0;
55338 +
55339 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55340 + time_after(curr->expires, get_seconds()))
55341 + return 1;
55342 + else if (time_before_eq(curr->expires, get_seconds())) {
55343 + curr->crashes = 0;
55344 + curr->expires = 0;
55345 + }
55346 +
55347 + return 0;
55348 +}
55349 +
55350 +void
55351 +gr_handle_alertkill(struct task_struct *task)
55352 +{
55353 + struct acl_subject_label *curracl;
55354 + __u32 curr_ip;
55355 + struct task_struct *p, *p2;
55356 +
55357 + if (unlikely(!gr_acl_is_enabled()))
55358 + return;
55359 +
55360 + curracl = task->acl;
55361 + curr_ip = task->signal->curr_ip;
55362 +
55363 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
55364 + read_lock(&tasklist_lock);
55365 + do_each_thread(p2, p) {
55366 + if (p->signal->curr_ip == curr_ip)
55367 + gr_fake_force_sig(SIGKILL, p);
55368 + } while_each_thread(p2, p);
55369 + read_unlock(&tasklist_lock);
55370 + } else if (curracl->mode & GR_KILLPROC)
55371 + gr_fake_force_sig(SIGKILL, task);
55372 +
55373 + return;
55374 +}
55375 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
55376 new file mode 100644
55377 index 0000000..9d83a69
55378 --- /dev/null
55379 +++ b/grsecurity/gracl_shm.c
55380 @@ -0,0 +1,40 @@
55381 +#include <linux/kernel.h>
55382 +#include <linux/mm.h>
55383 +#include <linux/sched.h>
55384 +#include <linux/file.h>
55385 +#include <linux/ipc.h>
55386 +#include <linux/gracl.h>
55387 +#include <linux/grsecurity.h>
55388 +#include <linux/grinternal.h>
55389 +
55390 +int
55391 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55392 + const time_t shm_createtime, const uid_t cuid, const int shmid)
55393 +{
55394 + struct task_struct *task;
55395 +
55396 + if (!gr_acl_is_enabled())
55397 + return 1;
55398 +
55399 + rcu_read_lock();
55400 + read_lock(&tasklist_lock);
55401 +
55402 + task = find_task_by_vpid(shm_cprid);
55403 +
55404 + if (unlikely(!task))
55405 + task = find_task_by_vpid(shm_lapid);
55406 +
55407 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
55408 + (task->pid == shm_lapid)) &&
55409 + (task->acl->mode & GR_PROTSHM) &&
55410 + (task->acl != current->acl))) {
55411 + read_unlock(&tasklist_lock);
55412 + rcu_read_unlock();
55413 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
55414 + return 0;
55415 + }
55416 + read_unlock(&tasklist_lock);
55417 + rcu_read_unlock();
55418 +
55419 + return 1;
55420 +}
55421 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
55422 new file mode 100644
55423 index 0000000..bc0be01
55424 --- /dev/null
55425 +++ b/grsecurity/grsec_chdir.c
55426 @@ -0,0 +1,19 @@
55427 +#include <linux/kernel.h>
55428 +#include <linux/sched.h>
55429 +#include <linux/fs.h>
55430 +#include <linux/file.h>
55431 +#include <linux/grsecurity.h>
55432 +#include <linux/grinternal.h>
55433 +
55434 +void
55435 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
55436 +{
55437 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55438 + if ((grsec_enable_chdir && grsec_enable_group &&
55439 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
55440 + !grsec_enable_group)) {
55441 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
55442 + }
55443 +#endif
55444 + return;
55445 +}
55446 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
55447 new file mode 100644
55448 index 0000000..9807ee2
55449 --- /dev/null
55450 +++ b/grsecurity/grsec_chroot.c
55451 @@ -0,0 +1,368 @@
55452 +#include <linux/kernel.h>
55453 +#include <linux/module.h>
55454 +#include <linux/sched.h>
55455 +#include <linux/file.h>
55456 +#include <linux/fs.h>
55457 +#include <linux/mount.h>
55458 +#include <linux/types.h>
55459 +#include "../fs/mount.h"
55460 +#include <linux/grsecurity.h>
55461 +#include <linux/grinternal.h>
55462 +
55463 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
55464 +{
55465 +#ifdef CONFIG_GRKERNSEC
55466 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
55467 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
55468 + task->gr_is_chrooted = 1;
55469 + else
55470 + task->gr_is_chrooted = 0;
55471 +
55472 + task->gr_chroot_dentry = path->dentry;
55473 +#endif
55474 + return;
55475 +}
55476 +
55477 +void gr_clear_chroot_entries(struct task_struct *task)
55478 +{
55479 +#ifdef CONFIG_GRKERNSEC
55480 + task->gr_is_chrooted = 0;
55481 + task->gr_chroot_dentry = NULL;
55482 +#endif
55483 + return;
55484 +}
55485 +
55486 +int
55487 +gr_handle_chroot_unix(const pid_t pid)
55488 +{
55489 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55490 + struct task_struct *p;
55491 +
55492 + if (unlikely(!grsec_enable_chroot_unix))
55493 + return 1;
55494 +
55495 + if (likely(!proc_is_chrooted(current)))
55496 + return 1;
55497 +
55498 + rcu_read_lock();
55499 + read_lock(&tasklist_lock);
55500 + p = find_task_by_vpid_unrestricted(pid);
55501 + if (unlikely(p && !have_same_root(current, p))) {
55502 + read_unlock(&tasklist_lock);
55503 + rcu_read_unlock();
55504 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
55505 + return 0;
55506 + }
55507 + read_unlock(&tasklist_lock);
55508 + rcu_read_unlock();
55509 +#endif
55510 + return 1;
55511 +}
55512 +
55513 +int
55514 +gr_handle_chroot_nice(void)
55515 +{
55516 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55517 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
55518 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
55519 + return -EPERM;
55520 + }
55521 +#endif
55522 + return 0;
55523 +}
55524 +
55525 +int
55526 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
55527 +{
55528 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55529 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
55530 + && proc_is_chrooted(current)) {
55531 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
55532 + return -EACCES;
55533 + }
55534 +#endif
55535 + return 0;
55536 +}
55537 +
55538 +int
55539 +gr_handle_chroot_rawio(const struct inode *inode)
55540 +{
55541 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55542 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55543 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
55544 + return 1;
55545 +#endif
55546 + return 0;
55547 +}
55548 +
55549 +int
55550 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
55551 +{
55552 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55553 + struct task_struct *p;
55554 + int ret = 0;
55555 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
55556 + return ret;
55557 +
55558 + read_lock(&tasklist_lock);
55559 + do_each_pid_task(pid, type, p) {
55560 + if (!have_same_root(current, p)) {
55561 + ret = 1;
55562 + goto out;
55563 + }
55564 + } while_each_pid_task(pid, type, p);
55565 +out:
55566 + read_unlock(&tasklist_lock);
55567 + return ret;
55568 +#endif
55569 + return 0;
55570 +}
55571 +
55572 +int
55573 +gr_pid_is_chrooted(struct task_struct *p)
55574 +{
55575 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55576 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
55577 + return 0;
55578 +
55579 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
55580 + !have_same_root(current, p)) {
55581 + return 1;
55582 + }
55583 +#endif
55584 + return 0;
55585 +}
55586 +
55587 +EXPORT_SYMBOL(gr_pid_is_chrooted);
55588 +
55589 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
55590 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
55591 +{
55592 + struct path path, currentroot;
55593 + int ret = 0;
55594 +
55595 + path.dentry = (struct dentry *)u_dentry;
55596 + path.mnt = (struct vfsmount *)u_mnt;
55597 + get_fs_root(current->fs, &currentroot);
55598 + if (path_is_under(&path, &currentroot))
55599 + ret = 1;
55600 + path_put(&currentroot);
55601 +
55602 + return ret;
55603 +}
55604 +#endif
55605 +
55606 +int
55607 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
55608 +{
55609 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55610 + if (!grsec_enable_chroot_fchdir)
55611 + return 1;
55612 +
55613 + if (!proc_is_chrooted(current))
55614 + return 1;
55615 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
55616 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
55617 + return 0;
55618 + }
55619 +#endif
55620 + return 1;
55621 +}
55622 +
55623 +int
55624 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55625 + const time_t shm_createtime)
55626 +{
55627 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55628 + struct task_struct *p;
55629 + time_t starttime;
55630 +
55631 + if (unlikely(!grsec_enable_chroot_shmat))
55632 + return 1;
55633 +
55634 + if (likely(!proc_is_chrooted(current)))
55635 + return 1;
55636 +
55637 + rcu_read_lock();
55638 + read_lock(&tasklist_lock);
55639 +
55640 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
55641 + starttime = p->start_time.tv_sec;
55642 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
55643 + if (have_same_root(current, p)) {
55644 + goto allow;
55645 + } else {
55646 + read_unlock(&tasklist_lock);
55647 + rcu_read_unlock();
55648 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
55649 + return 0;
55650 + }
55651 + }
55652 + /* creator exited, pid reuse, fall through to next check */
55653 + }
55654 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
55655 + if (unlikely(!have_same_root(current, p))) {
55656 + read_unlock(&tasklist_lock);
55657 + rcu_read_unlock();
55658 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
55659 + return 0;
55660 + }
55661 + }
55662 +
55663 +allow:
55664 + read_unlock(&tasklist_lock);
55665 + rcu_read_unlock();
55666 +#endif
55667 + return 1;
55668 +}
55669 +
55670 +void
55671 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
55672 +{
55673 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
55674 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
55675 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
55676 +#endif
55677 + return;
55678 +}
55679 +
55680 +int
55681 +gr_handle_chroot_mknod(const struct dentry *dentry,
55682 + const struct vfsmount *mnt, const int mode)
55683 +{
55684 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
55685 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
55686 + proc_is_chrooted(current)) {
55687 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
55688 + return -EPERM;
55689 + }
55690 +#endif
55691 + return 0;
55692 +}
55693 +
55694 +int
55695 +gr_handle_chroot_mount(const struct dentry *dentry,
55696 + const struct vfsmount *mnt, const char *dev_name)
55697 +{
55698 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
55699 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
55700 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
55701 + return -EPERM;
55702 + }
55703 +#endif
55704 + return 0;
55705 +}
55706 +
55707 +int
55708 +gr_handle_chroot_pivot(void)
55709 +{
55710 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
55711 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
55712 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
55713 + return -EPERM;
55714 + }
55715 +#endif
55716 + return 0;
55717 +}
55718 +
55719 +int
55720 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
55721 +{
55722 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
55723 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
55724 + !gr_is_outside_chroot(dentry, mnt)) {
55725 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
55726 + return -EPERM;
55727 + }
55728 +#endif
55729 + return 0;
55730 +}
55731 +
55732 +extern const char *captab_log[];
55733 +extern int captab_log_entries;
55734 +
55735 +int
55736 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55737 +{
55738 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55739 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
55740 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
55741 + if (cap_raised(chroot_caps, cap)) {
55742 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
55743 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
55744 + }
55745 + return 0;
55746 + }
55747 + }
55748 +#endif
55749 + return 1;
55750 +}
55751 +
55752 +int
55753 +gr_chroot_is_capable(const int cap)
55754 +{
55755 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55756 + return gr_task_chroot_is_capable(current, current_cred(), cap);
55757 +#endif
55758 + return 1;
55759 +}
55760 +
55761 +int
55762 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
55763 +{
55764 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55765 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
55766 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
55767 + if (cap_raised(chroot_caps, cap)) {
55768 + return 0;
55769 + }
55770 + }
55771 +#endif
55772 + return 1;
55773 +}
55774 +
55775 +int
55776 +gr_chroot_is_capable_nolog(const int cap)
55777 +{
55778 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55779 + return gr_task_chroot_is_capable_nolog(current, cap);
55780 +#endif
55781 + return 1;
55782 +}
55783 +
55784 +int
55785 +gr_handle_chroot_sysctl(const int op)
55786 +{
55787 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
55788 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
55789 + proc_is_chrooted(current))
55790 + return -EACCES;
55791 +#endif
55792 + return 0;
55793 +}
55794 +
55795 +void
55796 +gr_handle_chroot_chdir(struct path *path)
55797 +{
55798 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
55799 + if (grsec_enable_chroot_chdir)
55800 + set_fs_pwd(current->fs, path);
55801 +#endif
55802 + return;
55803 +}
55804 +
55805 +int
55806 +gr_handle_chroot_chmod(const struct dentry *dentry,
55807 + const struct vfsmount *mnt, const int mode)
55808 +{
55809 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
55810 + /* allow chmod +s on directories, but not files */
55811 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
55812 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
55813 + proc_is_chrooted(current)) {
55814 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
55815 + return -EPERM;
55816 + }
55817 +#endif
55818 + return 0;
55819 +}
55820 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
55821 new file mode 100644
55822 index 0000000..213ad8b
55823 --- /dev/null
55824 +++ b/grsecurity/grsec_disabled.c
55825 @@ -0,0 +1,437 @@
55826 +#include <linux/kernel.h>
55827 +#include <linux/module.h>
55828 +#include <linux/sched.h>
55829 +#include <linux/file.h>
55830 +#include <linux/fs.h>
55831 +#include <linux/kdev_t.h>
55832 +#include <linux/net.h>
55833 +#include <linux/in.h>
55834 +#include <linux/ip.h>
55835 +#include <linux/skbuff.h>
55836 +#include <linux/sysctl.h>
55837 +
55838 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55839 +void
55840 +pax_set_initial_flags(struct linux_binprm *bprm)
55841 +{
55842 + return;
55843 +}
55844 +#endif
55845 +
55846 +#ifdef CONFIG_SYSCTL
55847 +__u32
55848 +gr_handle_sysctl(const struct ctl_table * table, const int op)
55849 +{
55850 + return 0;
55851 +}
55852 +#endif
55853 +
55854 +#ifdef CONFIG_TASKSTATS
55855 +int gr_is_taskstats_denied(int pid)
55856 +{
55857 + return 0;
55858 +}
55859 +#endif
55860 +
55861 +int
55862 +gr_acl_is_enabled(void)
55863 +{
55864 + return 0;
55865 +}
55866 +
55867 +void
55868 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
55869 +{
55870 + return;
55871 +}
55872 +
55873 +int
55874 +gr_handle_rawio(const struct inode *inode)
55875 +{
55876 + return 0;
55877 +}
55878 +
55879 +void
55880 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55881 +{
55882 + return;
55883 +}
55884 +
55885 +int
55886 +gr_handle_ptrace(struct task_struct *task, const long request)
55887 +{
55888 + return 0;
55889 +}
55890 +
55891 +int
55892 +gr_handle_proc_ptrace(struct task_struct *task)
55893 +{
55894 + return 0;
55895 +}
55896 +
55897 +void
55898 +gr_learn_resource(const struct task_struct *task,
55899 + const int res, const unsigned long wanted, const int gt)
55900 +{
55901 + return;
55902 +}
55903 +
55904 +int
55905 +gr_set_acls(const int type)
55906 +{
55907 + return 0;
55908 +}
55909 +
55910 +int
55911 +gr_check_hidden_task(const struct task_struct *tsk)
55912 +{
55913 + return 0;
55914 +}
55915 +
55916 +int
55917 +gr_check_protected_task(const struct task_struct *task)
55918 +{
55919 + return 0;
55920 +}
55921 +
55922 +int
55923 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55924 +{
55925 + return 0;
55926 +}
55927 +
55928 +void
55929 +gr_copy_label(struct task_struct *tsk)
55930 +{
55931 + return;
55932 +}
55933 +
55934 +void
55935 +gr_set_pax_flags(struct task_struct *task)
55936 +{
55937 + return;
55938 +}
55939 +
55940 +int
55941 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
55942 + const int unsafe_share)
55943 +{
55944 + return 0;
55945 +}
55946 +
55947 +void
55948 +gr_handle_delete(const ino_t ino, const dev_t dev)
55949 +{
55950 + return;
55951 +}
55952 +
55953 +void
55954 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
55955 +{
55956 + return;
55957 +}
55958 +
55959 +void
55960 +gr_handle_crash(struct task_struct *task, const int sig)
55961 +{
55962 + return;
55963 +}
55964 +
55965 +int
55966 +gr_check_crash_exec(const struct file *filp)
55967 +{
55968 + return 0;
55969 +}
55970 +
55971 +int
55972 +gr_check_crash_uid(const uid_t uid)
55973 +{
55974 + return 0;
55975 +}
55976 +
55977 +void
55978 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55979 + struct dentry *old_dentry,
55980 + struct dentry *new_dentry,
55981 + struct vfsmount *mnt, const __u8 replace)
55982 +{
55983 + return;
55984 +}
55985 +
55986 +int
55987 +gr_search_socket(const int family, const int type, const int protocol)
55988 +{
55989 + return 1;
55990 +}
55991 +
55992 +int
55993 +gr_search_connectbind(const int mode, const struct socket *sock,
55994 + const struct sockaddr_in *addr)
55995 +{
55996 + return 0;
55997 +}
55998 +
55999 +void
56000 +gr_handle_alertkill(struct task_struct *task)
56001 +{
56002 + return;
56003 +}
56004 +
56005 +__u32
56006 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56007 +{
56008 + return 1;
56009 +}
56010 +
56011 +__u32
56012 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56013 + const struct vfsmount * mnt)
56014 +{
56015 + return 1;
56016 +}
56017 +
56018 +__u32
56019 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56020 + int acc_mode)
56021 +{
56022 + return 1;
56023 +}
56024 +
56025 +__u32
56026 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56027 +{
56028 + return 1;
56029 +}
56030 +
56031 +__u32
56032 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56033 +{
56034 + return 1;
56035 +}
56036 +
56037 +int
56038 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56039 + unsigned int *vm_flags)
56040 +{
56041 + return 1;
56042 +}
56043 +
56044 +__u32
56045 +gr_acl_handle_truncate(const struct dentry * dentry,
56046 + const struct vfsmount * mnt)
56047 +{
56048 + return 1;
56049 +}
56050 +
56051 +__u32
56052 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56053 +{
56054 + return 1;
56055 +}
56056 +
56057 +__u32
56058 +gr_acl_handle_access(const struct dentry * dentry,
56059 + const struct vfsmount * mnt, const int fmode)
56060 +{
56061 + return 1;
56062 +}
56063 +
56064 +__u32
56065 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56066 + umode_t *mode)
56067 +{
56068 + return 1;
56069 +}
56070 +
56071 +__u32
56072 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56073 +{
56074 + return 1;
56075 +}
56076 +
56077 +__u32
56078 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56079 +{
56080 + return 1;
56081 +}
56082 +
56083 +void
56084 +grsecurity_init(void)
56085 +{
56086 + return;
56087 +}
56088 +
56089 +umode_t gr_acl_umask(void)
56090 +{
56091 + return 0;
56092 +}
56093 +
56094 +__u32
56095 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56096 + const struct dentry * parent_dentry,
56097 + const struct vfsmount * parent_mnt,
56098 + const int mode)
56099 +{
56100 + return 1;
56101 +}
56102 +
56103 +__u32
56104 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
56105 + const struct dentry * parent_dentry,
56106 + const struct vfsmount * parent_mnt)
56107 +{
56108 + return 1;
56109 +}
56110 +
56111 +__u32
56112 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56113 + const struct dentry * parent_dentry,
56114 + const struct vfsmount * parent_mnt, const char *from)
56115 +{
56116 + return 1;
56117 +}
56118 +
56119 +__u32
56120 +gr_acl_handle_link(const struct dentry * new_dentry,
56121 + const struct dentry * parent_dentry,
56122 + const struct vfsmount * parent_mnt,
56123 + const struct dentry * old_dentry,
56124 + const struct vfsmount * old_mnt, const char *to)
56125 +{
56126 + return 1;
56127 +}
56128 +
56129 +int
56130 +gr_acl_handle_rename(const struct dentry *new_dentry,
56131 + const struct dentry *parent_dentry,
56132 + const struct vfsmount *parent_mnt,
56133 + const struct dentry *old_dentry,
56134 + const struct inode *old_parent_inode,
56135 + const struct vfsmount *old_mnt, const char *newname)
56136 +{
56137 + return 0;
56138 +}
56139 +
56140 +int
56141 +gr_acl_handle_filldir(const struct file *file, const char *name,
56142 + const int namelen, const ino_t ino)
56143 +{
56144 + return 1;
56145 +}
56146 +
56147 +int
56148 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56149 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56150 +{
56151 + return 1;
56152 +}
56153 +
56154 +int
56155 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
56156 +{
56157 + return 0;
56158 +}
56159 +
56160 +int
56161 +gr_search_accept(const struct socket *sock)
56162 +{
56163 + return 0;
56164 +}
56165 +
56166 +int
56167 +gr_search_listen(const struct socket *sock)
56168 +{
56169 + return 0;
56170 +}
56171 +
56172 +int
56173 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
56174 +{
56175 + return 0;
56176 +}
56177 +
56178 +__u32
56179 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
56180 +{
56181 + return 1;
56182 +}
56183 +
56184 +__u32
56185 +gr_acl_handle_creat(const struct dentry * dentry,
56186 + const struct dentry * p_dentry,
56187 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56188 + const int imode)
56189 +{
56190 + return 1;
56191 +}
56192 +
56193 +void
56194 +gr_acl_handle_exit(void)
56195 +{
56196 + return;
56197 +}
56198 +
56199 +int
56200 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56201 +{
56202 + return 1;
56203 +}
56204 +
56205 +void
56206 +gr_set_role_label(const uid_t uid, const gid_t gid)
56207 +{
56208 + return;
56209 +}
56210 +
56211 +int
56212 +gr_acl_handle_procpidmem(const struct task_struct *task)
56213 +{
56214 + return 0;
56215 +}
56216 +
56217 +int
56218 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
56219 +{
56220 + return 0;
56221 +}
56222 +
56223 +int
56224 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
56225 +{
56226 + return 0;
56227 +}
56228 +
56229 +void
56230 +gr_set_kernel_label(struct task_struct *task)
56231 +{
56232 + return;
56233 +}
56234 +
56235 +int
56236 +gr_check_user_change(int real, int effective, int fs)
56237 +{
56238 + return 0;
56239 +}
56240 +
56241 +int
56242 +gr_check_group_change(int real, int effective, int fs)
56243 +{
56244 + return 0;
56245 +}
56246 +
56247 +int gr_acl_enable_at_secure(void)
56248 +{
56249 + return 0;
56250 +}
56251 +
56252 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56253 +{
56254 + return dentry->d_inode->i_sb->s_dev;
56255 +}
56256 +
56257 +EXPORT_SYMBOL(gr_learn_resource);
56258 +EXPORT_SYMBOL(gr_set_kernel_label);
56259 +#ifdef CONFIG_SECURITY
56260 +EXPORT_SYMBOL(gr_check_user_change);
56261 +EXPORT_SYMBOL(gr_check_group_change);
56262 +#endif
56263 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
56264 new file mode 100644
56265 index 0000000..abfa971
56266 --- /dev/null
56267 +++ b/grsecurity/grsec_exec.c
56268 @@ -0,0 +1,174 @@
56269 +#include <linux/kernel.h>
56270 +#include <linux/sched.h>
56271 +#include <linux/file.h>
56272 +#include <linux/binfmts.h>
56273 +#include <linux/fs.h>
56274 +#include <linux/types.h>
56275 +#include <linux/grdefs.h>
56276 +#include <linux/grsecurity.h>
56277 +#include <linux/grinternal.h>
56278 +#include <linux/capability.h>
56279 +#include <linux/module.h>
56280 +
56281 +#include <asm/uaccess.h>
56282 +
56283 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56284 +static char gr_exec_arg_buf[132];
56285 +static DEFINE_MUTEX(gr_exec_arg_mutex);
56286 +#endif
56287 +
56288 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
56289 +
56290 +void
56291 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
56292 +{
56293 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56294 + char *grarg = gr_exec_arg_buf;
56295 + unsigned int i, x, execlen = 0;
56296 + char c;
56297 +
56298 + if (!((grsec_enable_execlog && grsec_enable_group &&
56299 + in_group_p(grsec_audit_gid))
56300 + || (grsec_enable_execlog && !grsec_enable_group)))
56301 + return;
56302 +
56303 + mutex_lock(&gr_exec_arg_mutex);
56304 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
56305 +
56306 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
56307 + const char __user *p;
56308 + unsigned int len;
56309 +
56310 + p = get_user_arg_ptr(argv, i);
56311 + if (IS_ERR(p))
56312 + goto log;
56313 +
56314 + len = strnlen_user(p, 128 - execlen);
56315 + if (len > 128 - execlen)
56316 + len = 128 - execlen;
56317 + else if (len > 0)
56318 + len--;
56319 + if (copy_from_user(grarg + execlen, p, len))
56320 + goto log;
56321 +
56322 + /* rewrite unprintable characters */
56323 + for (x = 0; x < len; x++) {
56324 + c = *(grarg + execlen + x);
56325 + if (c < 32 || c > 126)
56326 + *(grarg + execlen + x) = ' ';
56327 + }
56328 +
56329 + execlen += len;
56330 + *(grarg + execlen) = ' ';
56331 + *(grarg + execlen + 1) = '\0';
56332 + execlen++;
56333 + }
56334 +
56335 + log:
56336 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
56337 + bprm->file->f_path.mnt, grarg);
56338 + mutex_unlock(&gr_exec_arg_mutex);
56339 +#endif
56340 + return;
56341 +}
56342 +
56343 +#ifdef CONFIG_GRKERNSEC
56344 +extern int gr_acl_is_capable(const int cap);
56345 +extern int gr_acl_is_capable_nolog(const int cap);
56346 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56347 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
56348 +extern int gr_chroot_is_capable(const int cap);
56349 +extern int gr_chroot_is_capable_nolog(const int cap);
56350 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56351 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
56352 +#endif
56353 +
56354 +const char *captab_log[] = {
56355 + "CAP_CHOWN",
56356 + "CAP_DAC_OVERRIDE",
56357 + "CAP_DAC_READ_SEARCH",
56358 + "CAP_FOWNER",
56359 + "CAP_FSETID",
56360 + "CAP_KILL",
56361 + "CAP_SETGID",
56362 + "CAP_SETUID",
56363 + "CAP_SETPCAP",
56364 + "CAP_LINUX_IMMUTABLE",
56365 + "CAP_NET_BIND_SERVICE",
56366 + "CAP_NET_BROADCAST",
56367 + "CAP_NET_ADMIN",
56368 + "CAP_NET_RAW",
56369 + "CAP_IPC_LOCK",
56370 + "CAP_IPC_OWNER",
56371 + "CAP_SYS_MODULE",
56372 + "CAP_SYS_RAWIO",
56373 + "CAP_SYS_CHROOT",
56374 + "CAP_SYS_PTRACE",
56375 + "CAP_SYS_PACCT",
56376 + "CAP_SYS_ADMIN",
56377 + "CAP_SYS_BOOT",
56378 + "CAP_SYS_NICE",
56379 + "CAP_SYS_RESOURCE",
56380 + "CAP_SYS_TIME",
56381 + "CAP_SYS_TTY_CONFIG",
56382 + "CAP_MKNOD",
56383 + "CAP_LEASE",
56384 + "CAP_AUDIT_WRITE",
56385 + "CAP_AUDIT_CONTROL",
56386 + "CAP_SETFCAP",
56387 + "CAP_MAC_OVERRIDE",
56388 + "CAP_MAC_ADMIN",
56389 + "CAP_SYSLOG",
56390 + "CAP_WAKE_ALARM"
56391 +};
56392 +
56393 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
56394 +
56395 +int gr_is_capable(const int cap)
56396 +{
56397 +#ifdef CONFIG_GRKERNSEC
56398 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
56399 + return 1;
56400 + return 0;
56401 +#else
56402 + return 1;
56403 +#endif
56404 +}
56405 +
56406 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56407 +{
56408 +#ifdef CONFIG_GRKERNSEC
56409 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
56410 + return 1;
56411 + return 0;
56412 +#else
56413 + return 1;
56414 +#endif
56415 +}
56416 +
56417 +int gr_is_capable_nolog(const int cap)
56418 +{
56419 +#ifdef CONFIG_GRKERNSEC
56420 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
56421 + return 1;
56422 + return 0;
56423 +#else
56424 + return 1;
56425 +#endif
56426 +}
56427 +
56428 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
56429 +{
56430 +#ifdef CONFIG_GRKERNSEC
56431 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
56432 + return 1;
56433 + return 0;
56434 +#else
56435 + return 1;
56436 +#endif
56437 +}
56438 +
56439 +EXPORT_SYMBOL(gr_is_capable);
56440 +EXPORT_SYMBOL(gr_is_capable_nolog);
56441 +EXPORT_SYMBOL(gr_task_is_capable);
56442 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
56443 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
56444 new file mode 100644
56445 index 0000000..d3ee748
56446 --- /dev/null
56447 +++ b/grsecurity/grsec_fifo.c
56448 @@ -0,0 +1,24 @@
56449 +#include <linux/kernel.h>
56450 +#include <linux/sched.h>
56451 +#include <linux/fs.h>
56452 +#include <linux/file.h>
56453 +#include <linux/grinternal.h>
56454 +
56455 +int
56456 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
56457 + const struct dentry *dir, const int flag, const int acc_mode)
56458 +{
56459 +#ifdef CONFIG_GRKERNSEC_FIFO
56460 + const struct cred *cred = current_cred();
56461 +
56462 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
56463 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
56464 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
56465 + (cred->fsuid != dentry->d_inode->i_uid)) {
56466 + if (!inode_permission(dentry->d_inode, acc_mode))
56467 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
56468 + return -EACCES;
56469 + }
56470 +#endif
56471 + return 0;
56472 +}
56473 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
56474 new file mode 100644
56475 index 0000000..8ca18bf
56476 --- /dev/null
56477 +++ b/grsecurity/grsec_fork.c
56478 @@ -0,0 +1,23 @@
56479 +#include <linux/kernel.h>
56480 +#include <linux/sched.h>
56481 +#include <linux/grsecurity.h>
56482 +#include <linux/grinternal.h>
56483 +#include <linux/errno.h>
56484 +
56485 +void
56486 +gr_log_forkfail(const int retval)
56487 +{
56488 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56489 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
56490 + switch (retval) {
56491 + case -EAGAIN:
56492 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
56493 + break;
56494 + case -ENOMEM:
56495 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
56496 + break;
56497 + }
56498 + }
56499 +#endif
56500 + return;
56501 +}
56502 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
56503 new file mode 100644
56504 index 0000000..01ddde4
56505 --- /dev/null
56506 +++ b/grsecurity/grsec_init.c
56507 @@ -0,0 +1,277 @@
56508 +#include <linux/kernel.h>
56509 +#include <linux/sched.h>
56510 +#include <linux/mm.h>
56511 +#include <linux/gracl.h>
56512 +#include <linux/slab.h>
56513 +#include <linux/vmalloc.h>
56514 +#include <linux/percpu.h>
56515 +#include <linux/module.h>
56516 +
56517 +int grsec_enable_ptrace_readexec;
56518 +int grsec_enable_setxid;
56519 +int grsec_enable_brute;
56520 +int grsec_enable_link;
56521 +int grsec_enable_dmesg;
56522 +int grsec_enable_harden_ptrace;
56523 +int grsec_enable_fifo;
56524 +int grsec_enable_execlog;
56525 +int grsec_enable_signal;
56526 +int grsec_enable_forkfail;
56527 +int grsec_enable_audit_ptrace;
56528 +int grsec_enable_time;
56529 +int grsec_enable_audit_textrel;
56530 +int grsec_enable_group;
56531 +int grsec_audit_gid;
56532 +int grsec_enable_chdir;
56533 +int grsec_enable_mount;
56534 +int grsec_enable_rofs;
56535 +int grsec_enable_chroot_findtask;
56536 +int grsec_enable_chroot_mount;
56537 +int grsec_enable_chroot_shmat;
56538 +int grsec_enable_chroot_fchdir;
56539 +int grsec_enable_chroot_double;
56540 +int grsec_enable_chroot_pivot;
56541 +int grsec_enable_chroot_chdir;
56542 +int grsec_enable_chroot_chmod;
56543 +int grsec_enable_chroot_mknod;
56544 +int grsec_enable_chroot_nice;
56545 +int grsec_enable_chroot_execlog;
56546 +int grsec_enable_chroot_caps;
56547 +int grsec_enable_chroot_sysctl;
56548 +int grsec_enable_chroot_unix;
56549 +int grsec_enable_tpe;
56550 +int grsec_tpe_gid;
56551 +int grsec_enable_blackhole;
56552 +#ifdef CONFIG_IPV6_MODULE
56553 +EXPORT_SYMBOL(grsec_enable_blackhole);
56554 +#endif
56555 +int grsec_lastack_retries;
56556 +int grsec_enable_tpe_all;
56557 +int grsec_enable_tpe_invert;
56558 +int grsec_enable_socket_all;
56559 +int grsec_socket_all_gid;
56560 +int grsec_enable_socket_client;
56561 +int grsec_socket_client_gid;
56562 +int grsec_enable_socket_server;
56563 +int grsec_socket_server_gid;
56564 +int grsec_resource_logging;
56565 +int grsec_disable_privio;
56566 +int grsec_enable_log_rwxmaps;
56567 +int grsec_lock;
56568 +
56569 +DEFINE_SPINLOCK(grsec_alert_lock);
56570 +unsigned long grsec_alert_wtime = 0;
56571 +unsigned long grsec_alert_fyet = 0;
56572 +
56573 +DEFINE_SPINLOCK(grsec_audit_lock);
56574 +
56575 +DEFINE_RWLOCK(grsec_exec_file_lock);
56576 +
56577 +char *gr_shared_page[4];
56578 +
56579 +char *gr_alert_log_fmt;
56580 +char *gr_audit_log_fmt;
56581 +char *gr_alert_log_buf;
56582 +char *gr_audit_log_buf;
56583 +
56584 +extern struct gr_arg *gr_usermode;
56585 +extern unsigned char *gr_system_salt;
56586 +extern unsigned char *gr_system_sum;
56587 +
56588 +void __init
56589 +grsecurity_init(void)
56590 +{
56591 + int j;
56592 + /* create the per-cpu shared pages */
56593 +
56594 +#ifdef CONFIG_X86
56595 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
56596 +#endif
56597 +
56598 + for (j = 0; j < 4; j++) {
56599 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
56600 + if (gr_shared_page[j] == NULL) {
56601 + panic("Unable to allocate grsecurity shared page");
56602 + return;
56603 + }
56604 + }
56605 +
56606 + /* allocate log buffers */
56607 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
56608 + if (!gr_alert_log_fmt) {
56609 + panic("Unable to allocate grsecurity alert log format buffer");
56610 + return;
56611 + }
56612 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
56613 + if (!gr_audit_log_fmt) {
56614 + panic("Unable to allocate grsecurity audit log format buffer");
56615 + return;
56616 + }
56617 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
56618 + if (!gr_alert_log_buf) {
56619 + panic("Unable to allocate grsecurity alert log buffer");
56620 + return;
56621 + }
56622 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
56623 + if (!gr_audit_log_buf) {
56624 + panic("Unable to allocate grsecurity audit log buffer");
56625 + return;
56626 + }
56627 +
56628 + /* allocate memory for authentication structure */
56629 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
56630 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
56631 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
56632 +
56633 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
56634 + panic("Unable to allocate grsecurity authentication structure");
56635 + return;
56636 + }
56637 +
56638 +
56639 +#ifdef CONFIG_GRKERNSEC_IO
56640 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
56641 + grsec_disable_privio = 1;
56642 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
56643 + grsec_disable_privio = 1;
56644 +#else
56645 + grsec_disable_privio = 0;
56646 +#endif
56647 +#endif
56648 +
56649 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
56650 + /* for backward compatibility, tpe_invert always defaults to on if
56651 + enabled in the kernel
56652 + */
56653 + grsec_enable_tpe_invert = 1;
56654 +#endif
56655 +
56656 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
56657 +#ifndef CONFIG_GRKERNSEC_SYSCTL
56658 + grsec_lock = 1;
56659 +#endif
56660 +
56661 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
56662 + grsec_enable_audit_textrel = 1;
56663 +#endif
56664 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56665 + grsec_enable_log_rwxmaps = 1;
56666 +#endif
56667 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
56668 + grsec_enable_group = 1;
56669 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
56670 +#endif
56671 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56672 + grsec_enable_ptrace_readexec = 1;
56673 +#endif
56674 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56675 + grsec_enable_chdir = 1;
56676 +#endif
56677 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56678 + grsec_enable_harden_ptrace = 1;
56679 +#endif
56680 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56681 + grsec_enable_mount = 1;
56682 +#endif
56683 +#ifdef CONFIG_GRKERNSEC_LINK
56684 + grsec_enable_link = 1;
56685 +#endif
56686 +#ifdef CONFIG_GRKERNSEC_BRUTE
56687 + grsec_enable_brute = 1;
56688 +#endif
56689 +#ifdef CONFIG_GRKERNSEC_DMESG
56690 + grsec_enable_dmesg = 1;
56691 +#endif
56692 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56693 + grsec_enable_blackhole = 1;
56694 + grsec_lastack_retries = 4;
56695 +#endif
56696 +#ifdef CONFIG_GRKERNSEC_FIFO
56697 + grsec_enable_fifo = 1;
56698 +#endif
56699 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56700 + grsec_enable_execlog = 1;
56701 +#endif
56702 +#ifdef CONFIG_GRKERNSEC_SETXID
56703 + grsec_enable_setxid = 1;
56704 +#endif
56705 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56706 + grsec_enable_signal = 1;
56707 +#endif
56708 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56709 + grsec_enable_forkfail = 1;
56710 +#endif
56711 +#ifdef CONFIG_GRKERNSEC_TIME
56712 + grsec_enable_time = 1;
56713 +#endif
56714 +#ifdef CONFIG_GRKERNSEC_RESLOG
56715 + grsec_resource_logging = 1;
56716 +#endif
56717 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56718 + grsec_enable_chroot_findtask = 1;
56719 +#endif
56720 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56721 + grsec_enable_chroot_unix = 1;
56722 +#endif
56723 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56724 + grsec_enable_chroot_mount = 1;
56725 +#endif
56726 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56727 + grsec_enable_chroot_fchdir = 1;
56728 +#endif
56729 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56730 + grsec_enable_chroot_shmat = 1;
56731 +#endif
56732 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
56733 + grsec_enable_audit_ptrace = 1;
56734 +#endif
56735 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56736 + grsec_enable_chroot_double = 1;
56737 +#endif
56738 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56739 + grsec_enable_chroot_pivot = 1;
56740 +#endif
56741 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56742 + grsec_enable_chroot_chdir = 1;
56743 +#endif
56744 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56745 + grsec_enable_chroot_chmod = 1;
56746 +#endif
56747 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56748 + grsec_enable_chroot_mknod = 1;
56749 +#endif
56750 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56751 + grsec_enable_chroot_nice = 1;
56752 +#endif
56753 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56754 + grsec_enable_chroot_execlog = 1;
56755 +#endif
56756 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56757 + grsec_enable_chroot_caps = 1;
56758 +#endif
56759 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56760 + grsec_enable_chroot_sysctl = 1;
56761 +#endif
56762 +#ifdef CONFIG_GRKERNSEC_TPE
56763 + grsec_enable_tpe = 1;
56764 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
56765 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
56766 + grsec_enable_tpe_all = 1;
56767 +#endif
56768 +#endif
56769 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56770 + grsec_enable_socket_all = 1;
56771 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
56772 +#endif
56773 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56774 + grsec_enable_socket_client = 1;
56775 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
56776 +#endif
56777 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56778 + grsec_enable_socket_server = 1;
56779 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
56780 +#endif
56781 +#endif
56782 +
56783 + return;
56784 +}
56785 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
56786 new file mode 100644
56787 index 0000000..3efe141
56788 --- /dev/null
56789 +++ b/grsecurity/grsec_link.c
56790 @@ -0,0 +1,43 @@
56791 +#include <linux/kernel.h>
56792 +#include <linux/sched.h>
56793 +#include <linux/fs.h>
56794 +#include <linux/file.h>
56795 +#include <linux/grinternal.h>
56796 +
56797 +int
56798 +gr_handle_follow_link(const struct inode *parent,
56799 + const struct inode *inode,
56800 + const struct dentry *dentry, const struct vfsmount *mnt)
56801 +{
56802 +#ifdef CONFIG_GRKERNSEC_LINK
56803 + const struct cred *cred = current_cred();
56804 +
56805 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
56806 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
56807 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
56808 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
56809 + return -EACCES;
56810 + }
56811 +#endif
56812 + return 0;
56813 +}
56814 +
56815 +int
56816 +gr_handle_hardlink(const struct dentry *dentry,
56817 + const struct vfsmount *mnt,
56818 + struct inode *inode, const int mode, const char *to)
56819 +{
56820 +#ifdef CONFIG_GRKERNSEC_LINK
56821 + const struct cred *cred = current_cred();
56822 +
56823 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
56824 + (!S_ISREG(mode) || (mode & S_ISUID) ||
56825 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
56826 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
56827 + !capable(CAP_FOWNER) && cred->uid) {
56828 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
56829 + return -EPERM;
56830 + }
56831 +#endif
56832 + return 0;
56833 +}
56834 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
56835 new file mode 100644
56836 index 0000000..a45d2e9
56837 --- /dev/null
56838 +++ b/grsecurity/grsec_log.c
56839 @@ -0,0 +1,322 @@
56840 +#include <linux/kernel.h>
56841 +#include <linux/sched.h>
56842 +#include <linux/file.h>
56843 +#include <linux/tty.h>
56844 +#include <linux/fs.h>
56845 +#include <linux/grinternal.h>
56846 +
56847 +#ifdef CONFIG_TREE_PREEMPT_RCU
56848 +#define DISABLE_PREEMPT() preempt_disable()
56849 +#define ENABLE_PREEMPT() preempt_enable()
56850 +#else
56851 +#define DISABLE_PREEMPT()
56852 +#define ENABLE_PREEMPT()
56853 +#endif
56854 +
56855 +#define BEGIN_LOCKS(x) \
56856 + DISABLE_PREEMPT(); \
56857 + rcu_read_lock(); \
56858 + read_lock(&tasklist_lock); \
56859 + read_lock(&grsec_exec_file_lock); \
56860 + if (x != GR_DO_AUDIT) \
56861 + spin_lock(&grsec_alert_lock); \
56862 + else \
56863 + spin_lock(&grsec_audit_lock)
56864 +
56865 +#define END_LOCKS(x) \
56866 + if (x != GR_DO_AUDIT) \
56867 + spin_unlock(&grsec_alert_lock); \
56868 + else \
56869 + spin_unlock(&grsec_audit_lock); \
56870 + read_unlock(&grsec_exec_file_lock); \
56871 + read_unlock(&tasklist_lock); \
56872 + rcu_read_unlock(); \
56873 + ENABLE_PREEMPT(); \
56874 + if (x == GR_DONT_AUDIT) \
56875 + gr_handle_alertkill(current)
56876 +
56877 +enum {
56878 + FLOODING,
56879 + NO_FLOODING
56880 +};
56881 +
56882 +extern char *gr_alert_log_fmt;
56883 +extern char *gr_audit_log_fmt;
56884 +extern char *gr_alert_log_buf;
56885 +extern char *gr_audit_log_buf;
56886 +
56887 +static int gr_log_start(int audit)
56888 +{
56889 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
56890 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
56891 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56892 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
56893 + unsigned long curr_secs = get_seconds();
56894 +
56895 + if (audit == GR_DO_AUDIT)
56896 + goto set_fmt;
56897 +
56898 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
56899 + grsec_alert_wtime = curr_secs;
56900 + grsec_alert_fyet = 0;
56901 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
56902 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
56903 + grsec_alert_fyet++;
56904 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
56905 + grsec_alert_wtime = curr_secs;
56906 + grsec_alert_fyet++;
56907 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
56908 + return FLOODING;
56909 + }
56910 + else return FLOODING;
56911 +
56912 +set_fmt:
56913 +#endif
56914 + memset(buf, 0, PAGE_SIZE);
56915 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
56916 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
56917 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
56918 + } else if (current->signal->curr_ip) {
56919 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
56920 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
56921 + } else if (gr_acl_is_enabled()) {
56922 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
56923 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
56924 + } else {
56925 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
56926 + strcpy(buf, fmt);
56927 + }
56928 +
56929 + return NO_FLOODING;
56930 +}
56931 +
56932 +static void gr_log_middle(int audit, const char *msg, va_list ap)
56933 + __attribute__ ((format (printf, 2, 0)));
56934 +
56935 +static void gr_log_middle(int audit, const char *msg, va_list ap)
56936 +{
56937 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56938 + unsigned int len = strlen(buf);
56939 +
56940 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
56941 +
56942 + return;
56943 +}
56944 +
56945 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
56946 + __attribute__ ((format (printf, 2, 3)));
56947 +
56948 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
56949 +{
56950 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56951 + unsigned int len = strlen(buf);
56952 + va_list ap;
56953 +
56954 + va_start(ap, msg);
56955 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
56956 + va_end(ap);
56957 +
56958 + return;
56959 +}
56960 +
56961 +static void gr_log_end(int audit, int append_default)
56962 +{
56963 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56964 +
56965 + if (append_default) {
56966 + unsigned int len = strlen(buf);
56967 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
56968 + }
56969 +
56970 + printk("%s\n", buf);
56971 +
56972 + return;
56973 +}
56974 +
56975 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
56976 +{
56977 + int logtype;
56978 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
56979 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
56980 + void *voidptr = NULL;
56981 + int num1 = 0, num2 = 0;
56982 + unsigned long ulong1 = 0, ulong2 = 0;
56983 + struct dentry *dentry = NULL;
56984 + struct vfsmount *mnt = NULL;
56985 + struct file *file = NULL;
56986 + struct task_struct *task = NULL;
56987 + const struct cred *cred, *pcred;
56988 + va_list ap;
56989 +
56990 + BEGIN_LOCKS(audit);
56991 + logtype = gr_log_start(audit);
56992 + if (logtype == FLOODING) {
56993 + END_LOCKS(audit);
56994 + return;
56995 + }
56996 + va_start(ap, argtypes);
56997 + switch (argtypes) {
56998 + case GR_TTYSNIFF:
56999 + task = va_arg(ap, struct task_struct *);
57000 + 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);
57001 + break;
57002 + case GR_SYSCTL_HIDDEN:
57003 + str1 = va_arg(ap, char *);
57004 + gr_log_middle_varargs(audit, msg, result, str1);
57005 + break;
57006 + case GR_RBAC:
57007 + dentry = va_arg(ap, struct dentry *);
57008 + mnt = va_arg(ap, struct vfsmount *);
57009 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
57010 + break;
57011 + case GR_RBAC_STR:
57012 + dentry = va_arg(ap, struct dentry *);
57013 + mnt = va_arg(ap, struct vfsmount *);
57014 + str1 = va_arg(ap, char *);
57015 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
57016 + break;
57017 + case GR_STR_RBAC:
57018 + str1 = va_arg(ap, char *);
57019 + dentry = va_arg(ap, struct dentry *);
57020 + mnt = va_arg(ap, struct vfsmount *);
57021 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57022 + break;
57023 + case GR_RBAC_MODE2:
57024 + dentry = va_arg(ap, struct dentry *);
57025 + mnt = va_arg(ap, struct vfsmount *);
57026 + str1 = va_arg(ap, char *);
57027 + str2 = va_arg(ap, char *);
57028 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57029 + break;
57030 + case GR_RBAC_MODE3:
57031 + dentry = va_arg(ap, struct dentry *);
57032 + mnt = va_arg(ap, struct vfsmount *);
57033 + str1 = va_arg(ap, char *);
57034 + str2 = va_arg(ap, char *);
57035 + str3 = va_arg(ap, char *);
57036 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57037 + break;
57038 + case GR_FILENAME:
57039 + dentry = va_arg(ap, struct dentry *);
57040 + mnt = va_arg(ap, struct vfsmount *);
57041 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57042 + break;
57043 + case GR_STR_FILENAME:
57044 + str1 = va_arg(ap, char *);
57045 + dentry = va_arg(ap, struct dentry *);
57046 + mnt = va_arg(ap, struct vfsmount *);
57047 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57048 + break;
57049 + case GR_FILENAME_STR:
57050 + dentry = va_arg(ap, struct dentry *);
57051 + mnt = va_arg(ap, struct vfsmount *);
57052 + str1 = va_arg(ap, char *);
57053 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57054 + break;
57055 + case GR_FILENAME_TWO_INT:
57056 + dentry = va_arg(ap, struct dentry *);
57057 + mnt = va_arg(ap, struct vfsmount *);
57058 + num1 = va_arg(ap, int);
57059 + num2 = va_arg(ap, int);
57060 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57061 + break;
57062 + case GR_FILENAME_TWO_INT_STR:
57063 + dentry = va_arg(ap, struct dentry *);
57064 + mnt = va_arg(ap, struct vfsmount *);
57065 + num1 = va_arg(ap, int);
57066 + num2 = va_arg(ap, int);
57067 + str1 = va_arg(ap, char *);
57068 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57069 + break;
57070 + case GR_TEXTREL:
57071 + file = va_arg(ap, struct file *);
57072 + ulong1 = va_arg(ap, unsigned long);
57073 + ulong2 = va_arg(ap, unsigned long);
57074 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57075 + break;
57076 + case GR_PTRACE:
57077 + task = va_arg(ap, struct task_struct *);
57078 + 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);
57079 + break;
57080 + case GR_RESOURCE:
57081 + task = va_arg(ap, struct task_struct *);
57082 + cred = __task_cred(task);
57083 + pcred = __task_cred(task->real_parent);
57084 + ulong1 = va_arg(ap, unsigned long);
57085 + str1 = va_arg(ap, char *);
57086 + ulong2 = va_arg(ap, unsigned long);
57087 + 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);
57088 + break;
57089 + case GR_CAP:
57090 + task = va_arg(ap, struct task_struct *);
57091 + cred = __task_cred(task);
57092 + pcred = __task_cred(task->real_parent);
57093 + str1 = va_arg(ap, char *);
57094 + 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);
57095 + break;
57096 + case GR_SIG:
57097 + str1 = va_arg(ap, char *);
57098 + voidptr = va_arg(ap, void *);
57099 + gr_log_middle_varargs(audit, msg, str1, voidptr);
57100 + break;
57101 + case GR_SIG2:
57102 + task = va_arg(ap, struct task_struct *);
57103 + cred = __task_cred(task);
57104 + pcred = __task_cred(task->real_parent);
57105 + num1 = va_arg(ap, int);
57106 + 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);
57107 + break;
57108 + case GR_CRASH1:
57109 + task = va_arg(ap, struct task_struct *);
57110 + cred = __task_cred(task);
57111 + pcred = __task_cred(task->real_parent);
57112 + ulong1 = va_arg(ap, unsigned long);
57113 + 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);
57114 + break;
57115 + case GR_CRASH2:
57116 + task = va_arg(ap, struct task_struct *);
57117 + cred = __task_cred(task);
57118 + pcred = __task_cred(task->real_parent);
57119 + ulong1 = va_arg(ap, unsigned long);
57120 + 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);
57121 + break;
57122 + case GR_RWXMAP:
57123 + file = va_arg(ap, struct file *);
57124 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
57125 + break;
57126 + case GR_PSACCT:
57127 + {
57128 + unsigned int wday, cday;
57129 + __u8 whr, chr;
57130 + __u8 wmin, cmin;
57131 + __u8 wsec, csec;
57132 + char cur_tty[64] = { 0 };
57133 + char parent_tty[64] = { 0 };
57134 +
57135 + task = va_arg(ap, struct task_struct *);
57136 + wday = va_arg(ap, unsigned int);
57137 + cday = va_arg(ap, unsigned int);
57138 + whr = va_arg(ap, int);
57139 + chr = va_arg(ap, int);
57140 + wmin = va_arg(ap, int);
57141 + cmin = va_arg(ap, int);
57142 + wsec = va_arg(ap, int);
57143 + csec = va_arg(ap, int);
57144 + ulong1 = va_arg(ap, unsigned long);
57145 + cred = __task_cred(task);
57146 + pcred = __task_cred(task->real_parent);
57147 +
57148 + 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);
57149 + }
57150 + break;
57151 + default:
57152 + gr_log_middle(audit, msg, ap);
57153 + }
57154 + va_end(ap);
57155 + // these don't need DEFAULTSECARGS printed on the end
57156 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
57157 + gr_log_end(audit, 0);
57158 + else
57159 + gr_log_end(audit, 1);
57160 + END_LOCKS(audit);
57161 +}
57162 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
57163 new file mode 100644
57164 index 0000000..f536303
57165 --- /dev/null
57166 +++ b/grsecurity/grsec_mem.c
57167 @@ -0,0 +1,40 @@
57168 +#include <linux/kernel.h>
57169 +#include <linux/sched.h>
57170 +#include <linux/mm.h>
57171 +#include <linux/mman.h>
57172 +#include <linux/grinternal.h>
57173 +
57174 +void
57175 +gr_handle_ioperm(void)
57176 +{
57177 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
57178 + return;
57179 +}
57180 +
57181 +void
57182 +gr_handle_iopl(void)
57183 +{
57184 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
57185 + return;
57186 +}
57187 +
57188 +void
57189 +gr_handle_mem_readwrite(u64 from, u64 to)
57190 +{
57191 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
57192 + return;
57193 +}
57194 +
57195 +void
57196 +gr_handle_vm86(void)
57197 +{
57198 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
57199 + return;
57200 +}
57201 +
57202 +void
57203 +gr_log_badprocpid(const char *entry)
57204 +{
57205 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
57206 + return;
57207 +}
57208 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
57209 new file mode 100644
57210 index 0000000..2131422
57211 --- /dev/null
57212 +++ b/grsecurity/grsec_mount.c
57213 @@ -0,0 +1,62 @@
57214 +#include <linux/kernel.h>
57215 +#include <linux/sched.h>
57216 +#include <linux/mount.h>
57217 +#include <linux/grsecurity.h>
57218 +#include <linux/grinternal.h>
57219 +
57220 +void
57221 +gr_log_remount(const char *devname, const int retval)
57222 +{
57223 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57224 + if (grsec_enable_mount && (retval >= 0))
57225 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
57226 +#endif
57227 + return;
57228 +}
57229 +
57230 +void
57231 +gr_log_unmount(const char *devname, const int retval)
57232 +{
57233 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57234 + if (grsec_enable_mount && (retval >= 0))
57235 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
57236 +#endif
57237 + return;
57238 +}
57239 +
57240 +void
57241 +gr_log_mount(const char *from, const char *to, const int retval)
57242 +{
57243 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57244 + if (grsec_enable_mount && (retval >= 0))
57245 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
57246 +#endif
57247 + return;
57248 +}
57249 +
57250 +int
57251 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
57252 +{
57253 +#ifdef CONFIG_GRKERNSEC_ROFS
57254 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
57255 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
57256 + return -EPERM;
57257 + } else
57258 + return 0;
57259 +#endif
57260 + return 0;
57261 +}
57262 +
57263 +int
57264 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
57265 +{
57266 +#ifdef CONFIG_GRKERNSEC_ROFS
57267 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
57268 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
57269 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
57270 + return -EPERM;
57271 + } else
57272 + return 0;
57273 +#endif
57274 + return 0;
57275 +}
57276 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
57277 new file mode 100644
57278 index 0000000..a3b12a0
57279 --- /dev/null
57280 +++ b/grsecurity/grsec_pax.c
57281 @@ -0,0 +1,36 @@
57282 +#include <linux/kernel.h>
57283 +#include <linux/sched.h>
57284 +#include <linux/mm.h>
57285 +#include <linux/file.h>
57286 +#include <linux/grinternal.h>
57287 +#include <linux/grsecurity.h>
57288 +
57289 +void
57290 +gr_log_textrel(struct vm_area_struct * vma)
57291 +{
57292 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57293 + if (grsec_enable_audit_textrel)
57294 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
57295 +#endif
57296 + return;
57297 +}
57298 +
57299 +void
57300 +gr_log_rwxmmap(struct file *file)
57301 +{
57302 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57303 + if (grsec_enable_log_rwxmaps)
57304 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
57305 +#endif
57306 + return;
57307 +}
57308 +
57309 +void
57310 +gr_log_rwxmprotect(struct file *file)
57311 +{
57312 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57313 + if (grsec_enable_log_rwxmaps)
57314 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
57315 +#endif
57316 + return;
57317 +}
57318 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
57319 new file mode 100644
57320 index 0000000..f7f29aa
57321 --- /dev/null
57322 +++ b/grsecurity/grsec_ptrace.c
57323 @@ -0,0 +1,30 @@
57324 +#include <linux/kernel.h>
57325 +#include <linux/sched.h>
57326 +#include <linux/grinternal.h>
57327 +#include <linux/security.h>
57328 +
57329 +void
57330 +gr_audit_ptrace(struct task_struct *task)
57331 +{
57332 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57333 + if (grsec_enable_audit_ptrace)
57334 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
57335 +#endif
57336 + return;
57337 +}
57338 +
57339 +int
57340 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
57341 +{
57342 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57343 + const struct dentry *dentry = file->f_path.dentry;
57344 + const struct vfsmount *mnt = file->f_path.mnt;
57345 +
57346 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
57347 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
57348 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
57349 + return -EACCES;
57350 + }
57351 +#endif
57352 + return 0;
57353 +}
57354 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
57355 new file mode 100644
57356 index 0000000..7a5b2de
57357 --- /dev/null
57358 +++ b/grsecurity/grsec_sig.c
57359 @@ -0,0 +1,207 @@
57360 +#include <linux/kernel.h>
57361 +#include <linux/sched.h>
57362 +#include <linux/delay.h>
57363 +#include <linux/grsecurity.h>
57364 +#include <linux/grinternal.h>
57365 +#include <linux/hardirq.h>
57366 +
57367 +char *signames[] = {
57368 + [SIGSEGV] = "Segmentation fault",
57369 + [SIGILL] = "Illegal instruction",
57370 + [SIGABRT] = "Abort",
57371 + [SIGBUS] = "Invalid alignment/Bus error"
57372 +};
57373 +
57374 +void
57375 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
57376 +{
57377 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57378 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
57379 + (sig == SIGABRT) || (sig == SIGBUS))) {
57380 + if (t->pid == current->pid) {
57381 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
57382 + } else {
57383 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
57384 + }
57385 + }
57386 +#endif
57387 + return;
57388 +}
57389 +
57390 +int
57391 +gr_handle_signal(const struct task_struct *p, const int sig)
57392 +{
57393 +#ifdef CONFIG_GRKERNSEC
57394 + /* ignore the 0 signal for protected task checks */
57395 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
57396 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
57397 + return -EPERM;
57398 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
57399 + return -EPERM;
57400 + }
57401 +#endif
57402 + return 0;
57403 +}
57404 +
57405 +#ifdef CONFIG_GRKERNSEC
57406 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
57407 +
57408 +int gr_fake_force_sig(int sig, struct task_struct *t)
57409 +{
57410 + unsigned long int flags;
57411 + int ret, blocked, ignored;
57412 + struct k_sigaction *action;
57413 +
57414 + spin_lock_irqsave(&t->sighand->siglock, flags);
57415 + action = &t->sighand->action[sig-1];
57416 + ignored = action->sa.sa_handler == SIG_IGN;
57417 + blocked = sigismember(&t->blocked, sig);
57418 + if (blocked || ignored) {
57419 + action->sa.sa_handler = SIG_DFL;
57420 + if (blocked) {
57421 + sigdelset(&t->blocked, sig);
57422 + recalc_sigpending_and_wake(t);
57423 + }
57424 + }
57425 + if (action->sa.sa_handler == SIG_DFL)
57426 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
57427 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
57428 +
57429 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
57430 +
57431 + return ret;
57432 +}
57433 +#endif
57434 +
57435 +#ifdef CONFIG_GRKERNSEC_BRUTE
57436 +#define GR_USER_BAN_TIME (15 * 60)
57437 +
57438 +static int __get_dumpable(unsigned long mm_flags)
57439 +{
57440 + int ret;
57441 +
57442 + ret = mm_flags & MMF_DUMPABLE_MASK;
57443 + return (ret >= 2) ? 2 : ret;
57444 +}
57445 +#endif
57446 +
57447 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
57448 +{
57449 +#ifdef CONFIG_GRKERNSEC_BRUTE
57450 + uid_t uid = 0;
57451 +
57452 + if (!grsec_enable_brute)
57453 + return;
57454 +
57455 + rcu_read_lock();
57456 + read_lock(&tasklist_lock);
57457 + read_lock(&grsec_exec_file_lock);
57458 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
57459 + p->real_parent->brute = 1;
57460 + else {
57461 + const struct cred *cred = __task_cred(p), *cred2;
57462 + struct task_struct *tsk, *tsk2;
57463 +
57464 + if (!__get_dumpable(mm_flags) && cred->uid) {
57465 + struct user_struct *user;
57466 +
57467 + uid = cred->uid;
57468 +
57469 + /* this is put upon execution past expiration */
57470 + user = find_user(uid);
57471 + if (user == NULL)
57472 + goto unlock;
57473 + user->banned = 1;
57474 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
57475 + if (user->ban_expires == ~0UL)
57476 + user->ban_expires--;
57477 +
57478 + do_each_thread(tsk2, tsk) {
57479 + cred2 = __task_cred(tsk);
57480 + if (tsk != p && cred2->uid == uid)
57481 + gr_fake_force_sig(SIGKILL, tsk);
57482 + } while_each_thread(tsk2, tsk);
57483 + }
57484 + }
57485 +unlock:
57486 + read_unlock(&grsec_exec_file_lock);
57487 + read_unlock(&tasklist_lock);
57488 + rcu_read_unlock();
57489 +
57490 + if (uid)
57491 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
57492 +
57493 +#endif
57494 + return;
57495 +}
57496 +
57497 +void gr_handle_brute_check(void)
57498 +{
57499 +#ifdef CONFIG_GRKERNSEC_BRUTE
57500 + if (current->brute)
57501 + msleep(30 * 1000);
57502 +#endif
57503 + return;
57504 +}
57505 +
57506 +void gr_handle_kernel_exploit(void)
57507 +{
57508 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
57509 + const struct cred *cred;
57510 + struct task_struct *tsk, *tsk2;
57511 + struct user_struct *user;
57512 + uid_t uid;
57513 +
57514 + if (in_irq() || in_serving_softirq() || in_nmi())
57515 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
57516 +
57517 + uid = current_uid();
57518 +
57519 + if (uid == 0)
57520 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
57521 + else {
57522 + /* kill all the processes of this user, hold a reference
57523 + to their creds struct, and prevent them from creating
57524 + another process until system reset
57525 + */
57526 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
57527 + /* we intentionally leak this ref */
57528 + user = get_uid(current->cred->user);
57529 + if (user) {
57530 + user->banned = 1;
57531 + user->ban_expires = ~0UL;
57532 + }
57533 +
57534 + read_lock(&tasklist_lock);
57535 + do_each_thread(tsk2, tsk) {
57536 + cred = __task_cred(tsk);
57537 + if (cred->uid == uid)
57538 + gr_fake_force_sig(SIGKILL, tsk);
57539 + } while_each_thread(tsk2, tsk);
57540 + read_unlock(&tasklist_lock);
57541 + }
57542 +#endif
57543 +}
57544 +
57545 +int __gr_process_user_ban(struct user_struct *user)
57546 +{
57547 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57548 + if (unlikely(user->banned)) {
57549 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
57550 + user->banned = 0;
57551 + user->ban_expires = 0;
57552 + free_uid(user);
57553 + } else
57554 + return -EPERM;
57555 + }
57556 +#endif
57557 + return 0;
57558 +}
57559 +
57560 +int gr_process_user_ban(void)
57561 +{
57562 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57563 + return __gr_process_user_ban(current->cred->user);
57564 +#endif
57565 + return 0;
57566 +}
57567 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
57568 new file mode 100644
57569 index 0000000..4030d57
57570 --- /dev/null
57571 +++ b/grsecurity/grsec_sock.c
57572 @@ -0,0 +1,244 @@
57573 +#include <linux/kernel.h>
57574 +#include <linux/module.h>
57575 +#include <linux/sched.h>
57576 +#include <linux/file.h>
57577 +#include <linux/net.h>
57578 +#include <linux/in.h>
57579 +#include <linux/ip.h>
57580 +#include <net/sock.h>
57581 +#include <net/inet_sock.h>
57582 +#include <linux/grsecurity.h>
57583 +#include <linux/grinternal.h>
57584 +#include <linux/gracl.h>
57585 +
57586 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
57587 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
57588 +
57589 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
57590 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
57591 +
57592 +#ifdef CONFIG_UNIX_MODULE
57593 +EXPORT_SYMBOL(gr_acl_handle_unix);
57594 +EXPORT_SYMBOL(gr_acl_handle_mknod);
57595 +EXPORT_SYMBOL(gr_handle_chroot_unix);
57596 +EXPORT_SYMBOL(gr_handle_create);
57597 +#endif
57598 +
57599 +#ifdef CONFIG_GRKERNSEC
57600 +#define gr_conn_table_size 32749
57601 +struct conn_table_entry {
57602 + struct conn_table_entry *next;
57603 + struct signal_struct *sig;
57604 +};
57605 +
57606 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
57607 +DEFINE_SPINLOCK(gr_conn_table_lock);
57608 +
57609 +extern const char * gr_socktype_to_name(unsigned char type);
57610 +extern const char * gr_proto_to_name(unsigned char proto);
57611 +extern const char * gr_sockfamily_to_name(unsigned char family);
57612 +
57613 +static __inline__ int
57614 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
57615 +{
57616 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
57617 +}
57618 +
57619 +static __inline__ int
57620 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
57621 + __u16 sport, __u16 dport)
57622 +{
57623 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
57624 + sig->gr_sport == sport && sig->gr_dport == dport))
57625 + return 1;
57626 + else
57627 + return 0;
57628 +}
57629 +
57630 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
57631 +{
57632 + struct conn_table_entry **match;
57633 + unsigned int index;
57634 +
57635 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
57636 + sig->gr_sport, sig->gr_dport,
57637 + gr_conn_table_size);
57638 +
57639 + newent->sig = sig;
57640 +
57641 + match = &gr_conn_table[index];
57642 + newent->next = *match;
57643 + *match = newent;
57644 +
57645 + return;
57646 +}
57647 +
57648 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
57649 +{
57650 + struct conn_table_entry *match, *last = NULL;
57651 + unsigned int index;
57652 +
57653 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
57654 + sig->gr_sport, sig->gr_dport,
57655 + gr_conn_table_size);
57656 +
57657 + match = gr_conn_table[index];
57658 + while (match && !conn_match(match->sig,
57659 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
57660 + sig->gr_dport)) {
57661 + last = match;
57662 + match = match->next;
57663 + }
57664 +
57665 + if (match) {
57666 + if (last)
57667 + last->next = match->next;
57668 + else
57669 + gr_conn_table[index] = NULL;
57670 + kfree(match);
57671 + }
57672 +
57673 + return;
57674 +}
57675 +
57676 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
57677 + __u16 sport, __u16 dport)
57678 +{
57679 + struct conn_table_entry *match;
57680 + unsigned int index;
57681 +
57682 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
57683 +
57684 + match = gr_conn_table[index];
57685 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
57686 + match = match->next;
57687 +
57688 + if (match)
57689 + return match->sig;
57690 + else
57691 + return NULL;
57692 +}
57693 +
57694 +#endif
57695 +
57696 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
57697 +{
57698 +#ifdef CONFIG_GRKERNSEC
57699 + struct signal_struct *sig = task->signal;
57700 + struct conn_table_entry *newent;
57701 +
57702 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
57703 + if (newent == NULL)
57704 + return;
57705 + /* no bh lock needed since we are called with bh disabled */
57706 + spin_lock(&gr_conn_table_lock);
57707 + gr_del_task_from_ip_table_nolock(sig);
57708 + sig->gr_saddr = inet->inet_rcv_saddr;
57709 + sig->gr_daddr = inet->inet_daddr;
57710 + sig->gr_sport = inet->inet_sport;
57711 + sig->gr_dport = inet->inet_dport;
57712 + gr_add_to_task_ip_table_nolock(sig, newent);
57713 + spin_unlock(&gr_conn_table_lock);
57714 +#endif
57715 + return;
57716 +}
57717 +
57718 +void gr_del_task_from_ip_table(struct task_struct *task)
57719 +{
57720 +#ifdef CONFIG_GRKERNSEC
57721 + spin_lock_bh(&gr_conn_table_lock);
57722 + gr_del_task_from_ip_table_nolock(task->signal);
57723 + spin_unlock_bh(&gr_conn_table_lock);
57724 +#endif
57725 + return;
57726 +}
57727 +
57728 +void
57729 +gr_attach_curr_ip(const struct sock *sk)
57730 +{
57731 +#ifdef CONFIG_GRKERNSEC
57732 + struct signal_struct *p, *set;
57733 + const struct inet_sock *inet = inet_sk(sk);
57734 +
57735 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
57736 + return;
57737 +
57738 + set = current->signal;
57739 +
57740 + spin_lock_bh(&gr_conn_table_lock);
57741 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
57742 + inet->inet_dport, inet->inet_sport);
57743 + if (unlikely(p != NULL)) {
57744 + set->curr_ip = p->curr_ip;
57745 + set->used_accept = 1;
57746 + gr_del_task_from_ip_table_nolock(p);
57747 + spin_unlock_bh(&gr_conn_table_lock);
57748 + return;
57749 + }
57750 + spin_unlock_bh(&gr_conn_table_lock);
57751 +
57752 + set->curr_ip = inet->inet_daddr;
57753 + set->used_accept = 1;
57754 +#endif
57755 + return;
57756 +}
57757 +
57758 +int
57759 +gr_handle_sock_all(const int family, const int type, const int protocol)
57760 +{
57761 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57762 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
57763 + (family != AF_UNIX)) {
57764 + if (family == AF_INET)
57765 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
57766 + else
57767 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
57768 + return -EACCES;
57769 + }
57770 +#endif
57771 + return 0;
57772 +}
57773 +
57774 +int
57775 +gr_handle_sock_server(const struct sockaddr *sck)
57776 +{
57777 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57778 + if (grsec_enable_socket_server &&
57779 + in_group_p(grsec_socket_server_gid) &&
57780 + sck && (sck->sa_family != AF_UNIX) &&
57781 + (sck->sa_family != AF_LOCAL)) {
57782 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
57783 + return -EACCES;
57784 + }
57785 +#endif
57786 + return 0;
57787 +}
57788 +
57789 +int
57790 +gr_handle_sock_server_other(const struct sock *sck)
57791 +{
57792 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57793 + if (grsec_enable_socket_server &&
57794 + in_group_p(grsec_socket_server_gid) &&
57795 + sck && (sck->sk_family != AF_UNIX) &&
57796 + (sck->sk_family != AF_LOCAL)) {
57797 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
57798 + return -EACCES;
57799 + }
57800 +#endif
57801 + return 0;
57802 +}
57803 +
57804 +int
57805 +gr_handle_sock_client(const struct sockaddr *sck)
57806 +{
57807 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57808 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
57809 + sck && (sck->sa_family != AF_UNIX) &&
57810 + (sck->sa_family != AF_LOCAL)) {
57811 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
57812 + return -EACCES;
57813 + }
57814 +#endif
57815 + return 0;
57816 +}
57817 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
57818 new file mode 100644
57819 index 0000000..a1aedd7
57820 --- /dev/null
57821 +++ b/grsecurity/grsec_sysctl.c
57822 @@ -0,0 +1,451 @@
57823 +#include <linux/kernel.h>
57824 +#include <linux/sched.h>
57825 +#include <linux/sysctl.h>
57826 +#include <linux/grsecurity.h>
57827 +#include <linux/grinternal.h>
57828 +
57829 +int
57830 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
57831 +{
57832 +#ifdef CONFIG_GRKERNSEC_SYSCTL
57833 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
57834 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
57835 + return -EACCES;
57836 + }
57837 +#endif
57838 + return 0;
57839 +}
57840 +
57841 +#ifdef CONFIG_GRKERNSEC_ROFS
57842 +static int __maybe_unused one = 1;
57843 +#endif
57844 +
57845 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
57846 +struct ctl_table grsecurity_table[] = {
57847 +#ifdef CONFIG_GRKERNSEC_SYSCTL
57848 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
57849 +#ifdef CONFIG_GRKERNSEC_IO
57850 + {
57851 + .procname = "disable_priv_io",
57852 + .data = &grsec_disable_privio,
57853 + .maxlen = sizeof(int),
57854 + .mode = 0600,
57855 + .proc_handler = &proc_dointvec,
57856 + },
57857 +#endif
57858 +#endif
57859 +#ifdef CONFIG_GRKERNSEC_LINK
57860 + {
57861 + .procname = "linking_restrictions",
57862 + .data = &grsec_enable_link,
57863 + .maxlen = sizeof(int),
57864 + .mode = 0600,
57865 + .proc_handler = &proc_dointvec,
57866 + },
57867 +#endif
57868 +#ifdef CONFIG_GRKERNSEC_BRUTE
57869 + {
57870 + .procname = "deter_bruteforce",
57871 + .data = &grsec_enable_brute,
57872 + .maxlen = sizeof(int),
57873 + .mode = 0600,
57874 + .proc_handler = &proc_dointvec,
57875 + },
57876 +#endif
57877 +#ifdef CONFIG_GRKERNSEC_FIFO
57878 + {
57879 + .procname = "fifo_restrictions",
57880 + .data = &grsec_enable_fifo,
57881 + .maxlen = sizeof(int),
57882 + .mode = 0600,
57883 + .proc_handler = &proc_dointvec,
57884 + },
57885 +#endif
57886 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57887 + {
57888 + .procname = "ptrace_readexec",
57889 + .data = &grsec_enable_ptrace_readexec,
57890 + .maxlen = sizeof(int),
57891 + .mode = 0600,
57892 + .proc_handler = &proc_dointvec,
57893 + },
57894 +#endif
57895 +#ifdef CONFIG_GRKERNSEC_SETXID
57896 + {
57897 + .procname = "consistent_setxid",
57898 + .data = &grsec_enable_setxid,
57899 + .maxlen = sizeof(int),
57900 + .mode = 0600,
57901 + .proc_handler = &proc_dointvec,
57902 + },
57903 +#endif
57904 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57905 + {
57906 + .procname = "ip_blackhole",
57907 + .data = &grsec_enable_blackhole,
57908 + .maxlen = sizeof(int),
57909 + .mode = 0600,
57910 + .proc_handler = &proc_dointvec,
57911 + },
57912 + {
57913 + .procname = "lastack_retries",
57914 + .data = &grsec_lastack_retries,
57915 + .maxlen = sizeof(int),
57916 + .mode = 0600,
57917 + .proc_handler = &proc_dointvec,
57918 + },
57919 +#endif
57920 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57921 + {
57922 + .procname = "exec_logging",
57923 + .data = &grsec_enable_execlog,
57924 + .maxlen = sizeof(int),
57925 + .mode = 0600,
57926 + .proc_handler = &proc_dointvec,
57927 + },
57928 +#endif
57929 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57930 + {
57931 + .procname = "rwxmap_logging",
57932 + .data = &grsec_enable_log_rwxmaps,
57933 + .maxlen = sizeof(int),
57934 + .mode = 0600,
57935 + .proc_handler = &proc_dointvec,
57936 + },
57937 +#endif
57938 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57939 + {
57940 + .procname = "signal_logging",
57941 + .data = &grsec_enable_signal,
57942 + .maxlen = sizeof(int),
57943 + .mode = 0600,
57944 + .proc_handler = &proc_dointvec,
57945 + },
57946 +#endif
57947 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57948 + {
57949 + .procname = "forkfail_logging",
57950 + .data = &grsec_enable_forkfail,
57951 + .maxlen = sizeof(int),
57952 + .mode = 0600,
57953 + .proc_handler = &proc_dointvec,
57954 + },
57955 +#endif
57956 +#ifdef CONFIG_GRKERNSEC_TIME
57957 + {
57958 + .procname = "timechange_logging",
57959 + .data = &grsec_enable_time,
57960 + .maxlen = sizeof(int),
57961 + .mode = 0600,
57962 + .proc_handler = &proc_dointvec,
57963 + },
57964 +#endif
57965 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57966 + {
57967 + .procname = "chroot_deny_shmat",
57968 + .data = &grsec_enable_chroot_shmat,
57969 + .maxlen = sizeof(int),
57970 + .mode = 0600,
57971 + .proc_handler = &proc_dointvec,
57972 + },
57973 +#endif
57974 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57975 + {
57976 + .procname = "chroot_deny_unix",
57977 + .data = &grsec_enable_chroot_unix,
57978 + .maxlen = sizeof(int),
57979 + .mode = 0600,
57980 + .proc_handler = &proc_dointvec,
57981 + },
57982 +#endif
57983 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57984 + {
57985 + .procname = "chroot_deny_mount",
57986 + .data = &grsec_enable_chroot_mount,
57987 + .maxlen = sizeof(int),
57988 + .mode = 0600,
57989 + .proc_handler = &proc_dointvec,
57990 + },
57991 +#endif
57992 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57993 + {
57994 + .procname = "chroot_deny_fchdir",
57995 + .data = &grsec_enable_chroot_fchdir,
57996 + .maxlen = sizeof(int),
57997 + .mode = 0600,
57998 + .proc_handler = &proc_dointvec,
57999 + },
58000 +#endif
58001 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58002 + {
58003 + .procname = "chroot_deny_chroot",
58004 + .data = &grsec_enable_chroot_double,
58005 + .maxlen = sizeof(int),
58006 + .mode = 0600,
58007 + .proc_handler = &proc_dointvec,
58008 + },
58009 +#endif
58010 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58011 + {
58012 + .procname = "chroot_deny_pivot",
58013 + .data = &grsec_enable_chroot_pivot,
58014 + .maxlen = sizeof(int),
58015 + .mode = 0600,
58016 + .proc_handler = &proc_dointvec,
58017 + },
58018 +#endif
58019 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58020 + {
58021 + .procname = "chroot_enforce_chdir",
58022 + .data = &grsec_enable_chroot_chdir,
58023 + .maxlen = sizeof(int),
58024 + .mode = 0600,
58025 + .proc_handler = &proc_dointvec,
58026 + },
58027 +#endif
58028 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58029 + {
58030 + .procname = "chroot_deny_chmod",
58031 + .data = &grsec_enable_chroot_chmod,
58032 + .maxlen = sizeof(int),
58033 + .mode = 0600,
58034 + .proc_handler = &proc_dointvec,
58035 + },
58036 +#endif
58037 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58038 + {
58039 + .procname = "chroot_deny_mknod",
58040 + .data = &grsec_enable_chroot_mknod,
58041 + .maxlen = sizeof(int),
58042 + .mode = 0600,
58043 + .proc_handler = &proc_dointvec,
58044 + },
58045 +#endif
58046 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58047 + {
58048 + .procname = "chroot_restrict_nice",
58049 + .data = &grsec_enable_chroot_nice,
58050 + .maxlen = sizeof(int),
58051 + .mode = 0600,
58052 + .proc_handler = &proc_dointvec,
58053 + },
58054 +#endif
58055 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58056 + {
58057 + .procname = "chroot_execlog",
58058 + .data = &grsec_enable_chroot_execlog,
58059 + .maxlen = sizeof(int),
58060 + .mode = 0600,
58061 + .proc_handler = &proc_dointvec,
58062 + },
58063 +#endif
58064 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58065 + {
58066 + .procname = "chroot_caps",
58067 + .data = &grsec_enable_chroot_caps,
58068 + .maxlen = sizeof(int),
58069 + .mode = 0600,
58070 + .proc_handler = &proc_dointvec,
58071 + },
58072 +#endif
58073 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58074 + {
58075 + .procname = "chroot_deny_sysctl",
58076 + .data = &grsec_enable_chroot_sysctl,
58077 + .maxlen = sizeof(int),
58078 + .mode = 0600,
58079 + .proc_handler = &proc_dointvec,
58080 + },
58081 +#endif
58082 +#ifdef CONFIG_GRKERNSEC_TPE
58083 + {
58084 + .procname = "tpe",
58085 + .data = &grsec_enable_tpe,
58086 + .maxlen = sizeof(int),
58087 + .mode = 0600,
58088 + .proc_handler = &proc_dointvec,
58089 + },
58090 + {
58091 + .procname = "tpe_gid",
58092 + .data = &grsec_tpe_gid,
58093 + .maxlen = sizeof(int),
58094 + .mode = 0600,
58095 + .proc_handler = &proc_dointvec,
58096 + },
58097 +#endif
58098 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58099 + {
58100 + .procname = "tpe_invert",
58101 + .data = &grsec_enable_tpe_invert,
58102 + .maxlen = sizeof(int),
58103 + .mode = 0600,
58104 + .proc_handler = &proc_dointvec,
58105 + },
58106 +#endif
58107 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58108 + {
58109 + .procname = "tpe_restrict_all",
58110 + .data = &grsec_enable_tpe_all,
58111 + .maxlen = sizeof(int),
58112 + .mode = 0600,
58113 + .proc_handler = &proc_dointvec,
58114 + },
58115 +#endif
58116 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58117 + {
58118 + .procname = "socket_all",
58119 + .data = &grsec_enable_socket_all,
58120 + .maxlen = sizeof(int),
58121 + .mode = 0600,
58122 + .proc_handler = &proc_dointvec,
58123 + },
58124 + {
58125 + .procname = "socket_all_gid",
58126 + .data = &grsec_socket_all_gid,
58127 + .maxlen = sizeof(int),
58128 + .mode = 0600,
58129 + .proc_handler = &proc_dointvec,
58130 + },
58131 +#endif
58132 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58133 + {
58134 + .procname = "socket_client",
58135 + .data = &grsec_enable_socket_client,
58136 + .maxlen = sizeof(int),
58137 + .mode = 0600,
58138 + .proc_handler = &proc_dointvec,
58139 + },
58140 + {
58141 + .procname = "socket_client_gid",
58142 + .data = &grsec_socket_client_gid,
58143 + .maxlen = sizeof(int),
58144 + .mode = 0600,
58145 + .proc_handler = &proc_dointvec,
58146 + },
58147 +#endif
58148 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58149 + {
58150 + .procname = "socket_server",
58151 + .data = &grsec_enable_socket_server,
58152 + .maxlen = sizeof(int),
58153 + .mode = 0600,
58154 + .proc_handler = &proc_dointvec,
58155 + },
58156 + {
58157 + .procname = "socket_server_gid",
58158 + .data = &grsec_socket_server_gid,
58159 + .maxlen = sizeof(int),
58160 + .mode = 0600,
58161 + .proc_handler = &proc_dointvec,
58162 + },
58163 +#endif
58164 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58165 + {
58166 + .procname = "audit_group",
58167 + .data = &grsec_enable_group,
58168 + .maxlen = sizeof(int),
58169 + .mode = 0600,
58170 + .proc_handler = &proc_dointvec,
58171 + },
58172 + {
58173 + .procname = "audit_gid",
58174 + .data = &grsec_audit_gid,
58175 + .maxlen = sizeof(int),
58176 + .mode = 0600,
58177 + .proc_handler = &proc_dointvec,
58178 + },
58179 +#endif
58180 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58181 + {
58182 + .procname = "audit_chdir",
58183 + .data = &grsec_enable_chdir,
58184 + .maxlen = sizeof(int),
58185 + .mode = 0600,
58186 + .proc_handler = &proc_dointvec,
58187 + },
58188 +#endif
58189 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58190 + {
58191 + .procname = "audit_mount",
58192 + .data = &grsec_enable_mount,
58193 + .maxlen = sizeof(int),
58194 + .mode = 0600,
58195 + .proc_handler = &proc_dointvec,
58196 + },
58197 +#endif
58198 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58199 + {
58200 + .procname = "audit_textrel",
58201 + .data = &grsec_enable_audit_textrel,
58202 + .maxlen = sizeof(int),
58203 + .mode = 0600,
58204 + .proc_handler = &proc_dointvec,
58205 + },
58206 +#endif
58207 +#ifdef CONFIG_GRKERNSEC_DMESG
58208 + {
58209 + .procname = "dmesg",
58210 + .data = &grsec_enable_dmesg,
58211 + .maxlen = sizeof(int),
58212 + .mode = 0600,
58213 + .proc_handler = &proc_dointvec,
58214 + },
58215 +#endif
58216 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58217 + {
58218 + .procname = "chroot_findtask",
58219 + .data = &grsec_enable_chroot_findtask,
58220 + .maxlen = sizeof(int),
58221 + .mode = 0600,
58222 + .proc_handler = &proc_dointvec,
58223 + },
58224 +#endif
58225 +#ifdef CONFIG_GRKERNSEC_RESLOG
58226 + {
58227 + .procname = "resource_logging",
58228 + .data = &grsec_resource_logging,
58229 + .maxlen = sizeof(int),
58230 + .mode = 0600,
58231 + .proc_handler = &proc_dointvec,
58232 + },
58233 +#endif
58234 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58235 + {
58236 + .procname = "audit_ptrace",
58237 + .data = &grsec_enable_audit_ptrace,
58238 + .maxlen = sizeof(int),
58239 + .mode = 0600,
58240 + .proc_handler = &proc_dointvec,
58241 + },
58242 +#endif
58243 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58244 + {
58245 + .procname = "harden_ptrace",
58246 + .data = &grsec_enable_harden_ptrace,
58247 + .maxlen = sizeof(int),
58248 + .mode = 0600,
58249 + .proc_handler = &proc_dointvec,
58250 + },
58251 +#endif
58252 + {
58253 + .procname = "grsec_lock",
58254 + .data = &grsec_lock,
58255 + .maxlen = sizeof(int),
58256 + .mode = 0600,
58257 + .proc_handler = &proc_dointvec,
58258 + },
58259 +#endif
58260 +#ifdef CONFIG_GRKERNSEC_ROFS
58261 + {
58262 + .procname = "romount_protect",
58263 + .data = &grsec_enable_rofs,
58264 + .maxlen = sizeof(int),
58265 + .mode = 0600,
58266 + .proc_handler = &proc_dointvec_minmax,
58267 + .extra1 = &one,
58268 + .extra2 = &one,
58269 + },
58270 +#endif
58271 + { }
58272 +};
58273 +#endif
58274 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
58275 new file mode 100644
58276 index 0000000..0dc13c3
58277 --- /dev/null
58278 +++ b/grsecurity/grsec_time.c
58279 @@ -0,0 +1,16 @@
58280 +#include <linux/kernel.h>
58281 +#include <linux/sched.h>
58282 +#include <linux/grinternal.h>
58283 +#include <linux/module.h>
58284 +
58285 +void
58286 +gr_log_timechange(void)
58287 +{
58288 +#ifdef CONFIG_GRKERNSEC_TIME
58289 + if (grsec_enable_time)
58290 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
58291 +#endif
58292 + return;
58293 +}
58294 +
58295 +EXPORT_SYMBOL(gr_log_timechange);
58296 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
58297 new file mode 100644
58298 index 0000000..07e0dc0
58299 --- /dev/null
58300 +++ b/grsecurity/grsec_tpe.c
58301 @@ -0,0 +1,73 @@
58302 +#include <linux/kernel.h>
58303 +#include <linux/sched.h>
58304 +#include <linux/file.h>
58305 +#include <linux/fs.h>
58306 +#include <linux/grinternal.h>
58307 +
58308 +extern int gr_acl_tpe_check(void);
58309 +
58310 +int
58311 +gr_tpe_allow(const struct file *file)
58312 +{
58313 +#ifdef CONFIG_GRKERNSEC
58314 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
58315 + const struct cred *cred = current_cred();
58316 + char *msg = NULL;
58317 + char *msg2 = NULL;
58318 +
58319 + // never restrict root
58320 + if (!cred->uid)
58321 + return 1;
58322 +
58323 + if (grsec_enable_tpe) {
58324 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58325 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
58326 + msg = "not being in trusted group";
58327 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
58328 + msg = "being in untrusted group";
58329 +#else
58330 + if (in_group_p(grsec_tpe_gid))
58331 + msg = "being in untrusted group";
58332 +#endif
58333 + }
58334 + if (!msg && gr_acl_tpe_check())
58335 + msg = "being in untrusted role";
58336 +
58337 + // not in any affected group/role
58338 + if (!msg)
58339 + goto next_check;
58340 +
58341 + if (inode->i_uid)
58342 + msg2 = "file in non-root-owned directory";
58343 + else if (inode->i_mode & S_IWOTH)
58344 + msg2 = "file in world-writable directory";
58345 + else if (inode->i_mode & S_IWGRP)
58346 + msg2 = "file in group-writable directory";
58347 +
58348 + if (msg && msg2) {
58349 + char fullmsg[70] = {0};
58350 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
58351 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
58352 + return 0;
58353 + }
58354 + msg = NULL;
58355 +next_check:
58356 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58357 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
58358 + return 1;
58359 +
58360 + if (inode->i_uid && (inode->i_uid != cred->uid))
58361 + msg = "directory not owned by user";
58362 + else if (inode->i_mode & S_IWOTH)
58363 + msg = "file in world-writable directory";
58364 + else if (inode->i_mode & S_IWGRP)
58365 + msg = "file in group-writable directory";
58366 +
58367 + if (msg) {
58368 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
58369 + return 0;
58370 + }
58371 +#endif
58372 +#endif
58373 + return 1;
58374 +}
58375 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
58376 new file mode 100644
58377 index 0000000..9f7b1ac
58378 --- /dev/null
58379 +++ b/grsecurity/grsum.c
58380 @@ -0,0 +1,61 @@
58381 +#include <linux/err.h>
58382 +#include <linux/kernel.h>
58383 +#include <linux/sched.h>
58384 +#include <linux/mm.h>
58385 +#include <linux/scatterlist.h>
58386 +#include <linux/crypto.h>
58387 +#include <linux/gracl.h>
58388 +
58389 +
58390 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
58391 +#error "crypto and sha256 must be built into the kernel"
58392 +#endif
58393 +
58394 +int
58395 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
58396 +{
58397 + char *p;
58398 + struct crypto_hash *tfm;
58399 + struct hash_desc desc;
58400 + struct scatterlist sg;
58401 + unsigned char temp_sum[GR_SHA_LEN];
58402 + volatile int retval = 0;
58403 + volatile int dummy = 0;
58404 + unsigned int i;
58405 +
58406 + sg_init_table(&sg, 1);
58407 +
58408 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
58409 + if (IS_ERR(tfm)) {
58410 + /* should never happen, since sha256 should be built in */
58411 + return 1;
58412 + }
58413 +
58414 + desc.tfm = tfm;
58415 + desc.flags = 0;
58416 +
58417 + crypto_hash_init(&desc);
58418 +
58419 + p = salt;
58420 + sg_set_buf(&sg, p, GR_SALT_LEN);
58421 + crypto_hash_update(&desc, &sg, sg.length);
58422 +
58423 + p = entry->pw;
58424 + sg_set_buf(&sg, p, strlen(p));
58425 +
58426 + crypto_hash_update(&desc, &sg, sg.length);
58427 +
58428 + crypto_hash_final(&desc, temp_sum);
58429 +
58430 + memset(entry->pw, 0, GR_PW_LEN);
58431 +
58432 + for (i = 0; i < GR_SHA_LEN; i++)
58433 + if (sum[i] != temp_sum[i])
58434 + retval = 1;
58435 + else
58436 + dummy = 1; // waste a cycle
58437 +
58438 + crypto_free_hash(tfm);
58439 +
58440 + return retval;
58441 +}
58442 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
58443 index 6cd5b64..f620d2d 100644
58444 --- a/include/acpi/acpi_bus.h
58445 +++ b/include/acpi/acpi_bus.h
58446 @@ -107,7 +107,7 @@ struct acpi_device_ops {
58447 acpi_op_bind bind;
58448 acpi_op_unbind unbind;
58449 acpi_op_notify notify;
58450 -};
58451 +} __no_const;
58452
58453 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
58454
58455 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
58456 index b7babf0..71e4e74 100644
58457 --- a/include/asm-generic/atomic-long.h
58458 +++ b/include/asm-generic/atomic-long.h
58459 @@ -22,6 +22,12 @@
58460
58461 typedef atomic64_t atomic_long_t;
58462
58463 +#ifdef CONFIG_PAX_REFCOUNT
58464 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
58465 +#else
58466 +typedef atomic64_t atomic_long_unchecked_t;
58467 +#endif
58468 +
58469 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
58470
58471 static inline long atomic_long_read(atomic_long_t *l)
58472 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58473 return (long)atomic64_read(v);
58474 }
58475
58476 +#ifdef CONFIG_PAX_REFCOUNT
58477 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58478 +{
58479 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58480 +
58481 + return (long)atomic64_read_unchecked(v);
58482 +}
58483 +#endif
58484 +
58485 static inline void atomic_long_set(atomic_long_t *l, long i)
58486 {
58487 atomic64_t *v = (atomic64_t *)l;
58488 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58489 atomic64_set(v, i);
58490 }
58491
58492 +#ifdef CONFIG_PAX_REFCOUNT
58493 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58494 +{
58495 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58496 +
58497 + atomic64_set_unchecked(v, i);
58498 +}
58499 +#endif
58500 +
58501 static inline void atomic_long_inc(atomic_long_t *l)
58502 {
58503 atomic64_t *v = (atomic64_t *)l;
58504 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58505 atomic64_inc(v);
58506 }
58507
58508 +#ifdef CONFIG_PAX_REFCOUNT
58509 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58510 +{
58511 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58512 +
58513 + atomic64_inc_unchecked(v);
58514 +}
58515 +#endif
58516 +
58517 static inline void atomic_long_dec(atomic_long_t *l)
58518 {
58519 atomic64_t *v = (atomic64_t *)l;
58520 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58521 atomic64_dec(v);
58522 }
58523
58524 +#ifdef CONFIG_PAX_REFCOUNT
58525 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58526 +{
58527 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58528 +
58529 + atomic64_dec_unchecked(v);
58530 +}
58531 +#endif
58532 +
58533 static inline void atomic_long_add(long i, atomic_long_t *l)
58534 {
58535 atomic64_t *v = (atomic64_t *)l;
58536 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
58537 atomic64_add(i, v);
58538 }
58539
58540 +#ifdef CONFIG_PAX_REFCOUNT
58541 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
58542 +{
58543 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58544 +
58545 + atomic64_add_unchecked(i, v);
58546 +}
58547 +#endif
58548 +
58549 static inline void atomic_long_sub(long i, atomic_long_t *l)
58550 {
58551 atomic64_t *v = (atomic64_t *)l;
58552 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
58553 atomic64_sub(i, v);
58554 }
58555
58556 +#ifdef CONFIG_PAX_REFCOUNT
58557 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
58558 +{
58559 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58560 +
58561 + atomic64_sub_unchecked(i, v);
58562 +}
58563 +#endif
58564 +
58565 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
58566 {
58567 atomic64_t *v = (atomic64_t *)l;
58568 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
58569 return (long)atomic64_inc_return(v);
58570 }
58571
58572 +#ifdef CONFIG_PAX_REFCOUNT
58573 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
58574 +{
58575 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58576 +
58577 + return (long)atomic64_inc_return_unchecked(v);
58578 +}
58579 +#endif
58580 +
58581 static inline long atomic_long_dec_return(atomic_long_t *l)
58582 {
58583 atomic64_t *v = (atomic64_t *)l;
58584 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
58585
58586 typedef atomic_t atomic_long_t;
58587
58588 +#ifdef CONFIG_PAX_REFCOUNT
58589 +typedef atomic_unchecked_t atomic_long_unchecked_t;
58590 +#else
58591 +typedef atomic_t atomic_long_unchecked_t;
58592 +#endif
58593 +
58594 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
58595 static inline long atomic_long_read(atomic_long_t *l)
58596 {
58597 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58598 return (long)atomic_read(v);
58599 }
58600
58601 +#ifdef CONFIG_PAX_REFCOUNT
58602 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58603 +{
58604 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58605 +
58606 + return (long)atomic_read_unchecked(v);
58607 +}
58608 +#endif
58609 +
58610 static inline void atomic_long_set(atomic_long_t *l, long i)
58611 {
58612 atomic_t *v = (atomic_t *)l;
58613 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58614 atomic_set(v, i);
58615 }
58616
58617 +#ifdef CONFIG_PAX_REFCOUNT
58618 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58619 +{
58620 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58621 +
58622 + atomic_set_unchecked(v, i);
58623 +}
58624 +#endif
58625 +
58626 static inline void atomic_long_inc(atomic_long_t *l)
58627 {
58628 atomic_t *v = (atomic_t *)l;
58629 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58630 atomic_inc(v);
58631 }
58632
58633 +#ifdef CONFIG_PAX_REFCOUNT
58634 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58635 +{
58636 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58637 +
58638 + atomic_inc_unchecked(v);
58639 +}
58640 +#endif
58641 +
58642 static inline void atomic_long_dec(atomic_long_t *l)
58643 {
58644 atomic_t *v = (atomic_t *)l;
58645 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58646 atomic_dec(v);
58647 }
58648
58649 +#ifdef CONFIG_PAX_REFCOUNT
58650 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58651 +{
58652 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58653 +
58654 + atomic_dec_unchecked(v);
58655 +}
58656 +#endif
58657 +
58658 static inline void atomic_long_add(long i, atomic_long_t *l)
58659 {
58660 atomic_t *v = (atomic_t *)l;
58661 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
58662 atomic_add(i, v);
58663 }
58664
58665 +#ifdef CONFIG_PAX_REFCOUNT
58666 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
58667 +{
58668 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58669 +
58670 + atomic_add_unchecked(i, v);
58671 +}
58672 +#endif
58673 +
58674 static inline void atomic_long_sub(long i, atomic_long_t *l)
58675 {
58676 atomic_t *v = (atomic_t *)l;
58677 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
58678 atomic_sub(i, v);
58679 }
58680
58681 +#ifdef CONFIG_PAX_REFCOUNT
58682 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
58683 +{
58684 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58685 +
58686 + atomic_sub_unchecked(i, v);
58687 +}
58688 +#endif
58689 +
58690 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
58691 {
58692 atomic_t *v = (atomic_t *)l;
58693 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
58694 return (long)atomic_inc_return(v);
58695 }
58696
58697 +#ifdef CONFIG_PAX_REFCOUNT
58698 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
58699 +{
58700 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58701 +
58702 + return (long)atomic_inc_return_unchecked(v);
58703 +}
58704 +#endif
58705 +
58706 static inline long atomic_long_dec_return(atomic_long_t *l)
58707 {
58708 atomic_t *v = (atomic_t *)l;
58709 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
58710
58711 #endif /* BITS_PER_LONG == 64 */
58712
58713 +#ifdef CONFIG_PAX_REFCOUNT
58714 +static inline void pax_refcount_needs_these_functions(void)
58715 +{
58716 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
58717 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
58718 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
58719 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
58720 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
58721 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
58722 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
58723 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
58724 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
58725 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
58726 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
58727 +
58728 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
58729 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
58730 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
58731 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
58732 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
58733 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
58734 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
58735 +}
58736 +#else
58737 +#define atomic_read_unchecked(v) atomic_read(v)
58738 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
58739 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
58740 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
58741 +#define atomic_inc_unchecked(v) atomic_inc(v)
58742 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
58743 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
58744 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
58745 +#define atomic_dec_unchecked(v) atomic_dec(v)
58746 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
58747 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
58748 +
58749 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
58750 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
58751 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
58752 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
58753 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
58754 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
58755 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
58756 +#endif
58757 +
58758 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
58759 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
58760 index b18ce4f..2ee2843 100644
58761 --- a/include/asm-generic/atomic64.h
58762 +++ b/include/asm-generic/atomic64.h
58763 @@ -16,6 +16,8 @@ typedef struct {
58764 long long counter;
58765 } atomic64_t;
58766
58767 +typedef atomic64_t atomic64_unchecked_t;
58768 +
58769 #define ATOMIC64_INIT(i) { (i) }
58770
58771 extern long long atomic64_read(const atomic64_t *v);
58772 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
58773 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
58774 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
58775
58776 +#define atomic64_read_unchecked(v) atomic64_read(v)
58777 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
58778 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
58779 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
58780 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
58781 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
58782 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
58783 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
58784 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
58785 +
58786 #endif /* _ASM_GENERIC_ATOMIC64_H */
58787 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
58788 index 1bfcfe5..e04c5c9 100644
58789 --- a/include/asm-generic/cache.h
58790 +++ b/include/asm-generic/cache.h
58791 @@ -6,7 +6,7 @@
58792 * cache lines need to provide their own cache.h.
58793 */
58794
58795 -#define L1_CACHE_SHIFT 5
58796 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
58797 +#define L1_CACHE_SHIFT 5UL
58798 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
58799
58800 #endif /* __ASM_GENERIC_CACHE_H */
58801 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
58802 index 0d68a1e..b74a761 100644
58803 --- a/include/asm-generic/emergency-restart.h
58804 +++ b/include/asm-generic/emergency-restart.h
58805 @@ -1,7 +1,7 @@
58806 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
58807 #define _ASM_GENERIC_EMERGENCY_RESTART_H
58808
58809 -static inline void machine_emergency_restart(void)
58810 +static inline __noreturn void machine_emergency_restart(void)
58811 {
58812 machine_restart(NULL);
58813 }
58814 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
58815 index 1ca3efc..e3dc852 100644
58816 --- a/include/asm-generic/int-l64.h
58817 +++ b/include/asm-generic/int-l64.h
58818 @@ -46,6 +46,8 @@ typedef unsigned int u32;
58819 typedef signed long s64;
58820 typedef unsigned long u64;
58821
58822 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
58823 +
58824 #define S8_C(x) x
58825 #define U8_C(x) x ## U
58826 #define S16_C(x) x
58827 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
58828 index f394147..b6152b9 100644
58829 --- a/include/asm-generic/int-ll64.h
58830 +++ b/include/asm-generic/int-ll64.h
58831 @@ -51,6 +51,8 @@ typedef unsigned int u32;
58832 typedef signed long long s64;
58833 typedef unsigned long long u64;
58834
58835 +typedef unsigned long long intoverflow_t;
58836 +
58837 #define S8_C(x) x
58838 #define U8_C(x) x ## U
58839 #define S16_C(x) x
58840 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
58841 index 0232ccb..13d9165 100644
58842 --- a/include/asm-generic/kmap_types.h
58843 +++ b/include/asm-generic/kmap_types.h
58844 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
58845 KMAP_D(17) KM_NMI,
58846 KMAP_D(18) KM_NMI_PTE,
58847 KMAP_D(19) KM_KDB,
58848 +KMAP_D(20) KM_CLEARPAGE,
58849 /*
58850 * Remember to update debug_kmap_atomic() when adding new kmap types!
58851 */
58852 -KMAP_D(20) KM_TYPE_NR
58853 +KMAP_D(21) KM_TYPE_NR
58854 };
58855
58856 #undef KMAP_D
58857 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
58858 index 9ceb03b..2efbcbd 100644
58859 --- a/include/asm-generic/local.h
58860 +++ b/include/asm-generic/local.h
58861 @@ -39,6 +39,7 @@ typedef struct
58862 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
58863 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
58864 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
58865 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
58866
58867 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
58868 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
58869 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
58870 index 725612b..9cc513a 100644
58871 --- a/include/asm-generic/pgtable-nopmd.h
58872 +++ b/include/asm-generic/pgtable-nopmd.h
58873 @@ -1,14 +1,19 @@
58874 #ifndef _PGTABLE_NOPMD_H
58875 #define _PGTABLE_NOPMD_H
58876
58877 -#ifndef __ASSEMBLY__
58878 -
58879 #include <asm-generic/pgtable-nopud.h>
58880
58881 -struct mm_struct;
58882 -
58883 #define __PAGETABLE_PMD_FOLDED
58884
58885 +#define PMD_SHIFT PUD_SHIFT
58886 +#define PTRS_PER_PMD 1
58887 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
58888 +#define PMD_MASK (~(PMD_SIZE-1))
58889 +
58890 +#ifndef __ASSEMBLY__
58891 +
58892 +struct mm_struct;
58893 +
58894 /*
58895 * Having the pmd type consist of a pud gets the size right, and allows
58896 * us to conceptually access the pud entry that this pmd is folded into
58897 @@ -16,11 +21,6 @@ struct mm_struct;
58898 */
58899 typedef struct { pud_t pud; } pmd_t;
58900
58901 -#define PMD_SHIFT PUD_SHIFT
58902 -#define PTRS_PER_PMD 1
58903 -#define PMD_SIZE (1UL << PMD_SHIFT)
58904 -#define PMD_MASK (~(PMD_SIZE-1))
58905 -
58906 /*
58907 * The "pud_xxx()" functions here are trivial for a folded two-level
58908 * setup: the pmd is never bad, and a pmd always exists (as it's folded
58909 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
58910 index 810431d..ccc3638 100644
58911 --- a/include/asm-generic/pgtable-nopud.h
58912 +++ b/include/asm-generic/pgtable-nopud.h
58913 @@ -1,10 +1,15 @@
58914 #ifndef _PGTABLE_NOPUD_H
58915 #define _PGTABLE_NOPUD_H
58916
58917 -#ifndef __ASSEMBLY__
58918 -
58919 #define __PAGETABLE_PUD_FOLDED
58920
58921 +#define PUD_SHIFT PGDIR_SHIFT
58922 +#define PTRS_PER_PUD 1
58923 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
58924 +#define PUD_MASK (~(PUD_SIZE-1))
58925 +
58926 +#ifndef __ASSEMBLY__
58927 +
58928 /*
58929 * Having the pud type consist of a pgd gets the size right, and allows
58930 * us to conceptually access the pgd entry that this pud is folded into
58931 @@ -12,11 +17,6 @@
58932 */
58933 typedef struct { pgd_t pgd; } pud_t;
58934
58935 -#define PUD_SHIFT PGDIR_SHIFT
58936 -#define PTRS_PER_PUD 1
58937 -#define PUD_SIZE (1UL << PUD_SHIFT)
58938 -#define PUD_MASK (~(PUD_SIZE-1))
58939 -
58940 /*
58941 * The "pgd_xxx()" functions here are trivial for a folded two-level
58942 * setup: the pud is never bad, and a pud always exists (as it's folded
58943 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
58944 index a03c098..9624b83 100644
58945 --- a/include/asm-generic/pgtable.h
58946 +++ b/include/asm-generic/pgtable.h
58947 @@ -504,6 +504,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
58948
58949 #endif /* CONFIG_MMU */
58950
58951 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
58952 +static inline unsigned long pax_open_kernel(void) { return 0; }
58953 +#endif
58954 +
58955 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
58956 +static inline unsigned long pax_close_kernel(void) { return 0; }
58957 +#endif
58958 +
58959 #endif /* !__ASSEMBLY__ */
58960
58961 #endif /* _ASM_GENERIC_PGTABLE_H */
58962 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
58963 index b5e2e4c..6a5373e 100644
58964 --- a/include/asm-generic/vmlinux.lds.h
58965 +++ b/include/asm-generic/vmlinux.lds.h
58966 @@ -217,6 +217,7 @@
58967 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
58968 VMLINUX_SYMBOL(__start_rodata) = .; \
58969 *(.rodata) *(.rodata.*) \
58970 + *(.data..read_only) \
58971 *(__vermagic) /* Kernel version magic */ \
58972 . = ALIGN(8); \
58973 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
58974 @@ -722,17 +723,18 @@
58975 * section in the linker script will go there too. @phdr should have
58976 * a leading colon.
58977 *
58978 - * Note that this macros defines __per_cpu_load as an absolute symbol.
58979 + * Note that this macros defines per_cpu_load as an absolute symbol.
58980 * If there is no need to put the percpu section at a predetermined
58981 * address, use PERCPU_SECTION.
58982 */
58983 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
58984 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
58985 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
58986 + per_cpu_load = .; \
58987 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
58988 - LOAD_OFFSET) { \
58989 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
58990 PERCPU_INPUT(cacheline) \
58991 } phdr \
58992 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
58993 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
58994
58995 /**
58996 * PERCPU_SECTION - define output section for percpu area, simple version
58997 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
58998 index 92f0981..d44a37c 100644
58999 --- a/include/drm/drmP.h
59000 +++ b/include/drm/drmP.h
59001 @@ -72,6 +72,7 @@
59002 #include <linux/workqueue.h>
59003 #include <linux/poll.h>
59004 #include <asm/pgalloc.h>
59005 +#include <asm/local.h>
59006 #include "drm.h"
59007
59008 #include <linux/idr.h>
59009 @@ -1038,7 +1039,7 @@ struct drm_device {
59010
59011 /** \name Usage Counters */
59012 /*@{ */
59013 - int open_count; /**< Outstanding files open */
59014 + local_t open_count; /**< Outstanding files open */
59015 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
59016 atomic_t vma_count; /**< Outstanding vma areas open */
59017 int buf_use; /**< Buffers in use -- cannot alloc */
59018 @@ -1049,7 +1050,7 @@ struct drm_device {
59019 /*@{ */
59020 unsigned long counters;
59021 enum drm_stat_type types[15];
59022 - atomic_t counts[15];
59023 + atomic_unchecked_t counts[15];
59024 /*@} */
59025
59026 struct list_head filelist;
59027 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
59028 index 37515d1..34fa8b0 100644
59029 --- a/include/drm/drm_crtc_helper.h
59030 +++ b/include/drm/drm_crtc_helper.h
59031 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
59032
59033 /* disable crtc when not in use - more explicit than dpms off */
59034 void (*disable)(struct drm_crtc *crtc);
59035 -};
59036 +} __no_const;
59037
59038 struct drm_encoder_helper_funcs {
59039 void (*dpms)(struct drm_encoder *encoder, int mode);
59040 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59041 struct drm_connector *connector);
59042 /* disable encoder when not in use - more explicit than dpms off */
59043 void (*disable)(struct drm_encoder *encoder);
59044 -};
59045 +} __no_const;
59046
59047 struct drm_connector_helper_funcs {
59048 int (*get_modes)(struct drm_connector *connector);
59049 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59050 index 26c1f78..6722682 100644
59051 --- a/include/drm/ttm/ttm_memory.h
59052 +++ b/include/drm/ttm/ttm_memory.h
59053 @@ -47,7 +47,7 @@
59054
59055 struct ttm_mem_shrink {
59056 int (*do_shrink) (struct ttm_mem_shrink *);
59057 -};
59058 +} __no_const;
59059
59060 /**
59061 * struct ttm_mem_global - Global memory accounting structure.
59062 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59063 index e86dfca..40cc55f 100644
59064 --- a/include/linux/a.out.h
59065 +++ b/include/linux/a.out.h
59066 @@ -39,6 +39,14 @@ enum machine_type {
59067 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59068 };
59069
59070 +/* Constants for the N_FLAGS field */
59071 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59072 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59073 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59074 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59075 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59076 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59077 +
59078 #if !defined (N_MAGIC)
59079 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
59080 #endif
59081 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
59082 index f4ff882..84b53a6 100644
59083 --- a/include/linux/atmdev.h
59084 +++ b/include/linux/atmdev.h
59085 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
59086 #endif
59087
59088 struct k_atm_aal_stats {
59089 -#define __HANDLE_ITEM(i) atomic_t i
59090 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
59091 __AAL_STAT_ITEMS
59092 #undef __HANDLE_ITEM
59093 };
59094 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
59095 index 0092102..8a801b4 100644
59096 --- a/include/linux/binfmts.h
59097 +++ b/include/linux/binfmts.h
59098 @@ -89,6 +89,7 @@ struct linux_binfmt {
59099 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
59100 int (*load_shlib)(struct file *);
59101 int (*core_dump)(struct coredump_params *cprm);
59102 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
59103 unsigned long min_coredump; /* minimal dump size */
59104 };
59105
59106 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
59107 index 606cf33..b72c577 100644
59108 --- a/include/linux/blkdev.h
59109 +++ b/include/linux/blkdev.h
59110 @@ -1379,7 +1379,7 @@ struct block_device_operations {
59111 /* this callback is with swap_lock and sometimes page table lock held */
59112 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
59113 struct module *owner;
59114 -};
59115 +} __do_const;
59116
59117 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
59118 unsigned long);
59119 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
59120 index 4d1a074..88f929a 100644
59121 --- a/include/linux/blktrace_api.h
59122 +++ b/include/linux/blktrace_api.h
59123 @@ -162,7 +162,7 @@ struct blk_trace {
59124 struct dentry *dir;
59125 struct dentry *dropped_file;
59126 struct dentry *msg_file;
59127 - atomic_t dropped;
59128 + atomic_unchecked_t dropped;
59129 };
59130
59131 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
59132 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
59133 index 83195fb..0b0f77d 100644
59134 --- a/include/linux/byteorder/little_endian.h
59135 +++ b/include/linux/byteorder/little_endian.h
59136 @@ -42,51 +42,51 @@
59137
59138 static inline __le64 __cpu_to_le64p(const __u64 *p)
59139 {
59140 - return (__force __le64)*p;
59141 + return (__force const __le64)*p;
59142 }
59143 static inline __u64 __le64_to_cpup(const __le64 *p)
59144 {
59145 - return (__force __u64)*p;
59146 + return (__force const __u64)*p;
59147 }
59148 static inline __le32 __cpu_to_le32p(const __u32 *p)
59149 {
59150 - return (__force __le32)*p;
59151 + return (__force const __le32)*p;
59152 }
59153 static inline __u32 __le32_to_cpup(const __le32 *p)
59154 {
59155 - return (__force __u32)*p;
59156 + return (__force const __u32)*p;
59157 }
59158 static inline __le16 __cpu_to_le16p(const __u16 *p)
59159 {
59160 - return (__force __le16)*p;
59161 + return (__force const __le16)*p;
59162 }
59163 static inline __u16 __le16_to_cpup(const __le16 *p)
59164 {
59165 - return (__force __u16)*p;
59166 + return (__force const __u16)*p;
59167 }
59168 static inline __be64 __cpu_to_be64p(const __u64 *p)
59169 {
59170 - return (__force __be64)__swab64p(p);
59171 + return (__force const __be64)__swab64p(p);
59172 }
59173 static inline __u64 __be64_to_cpup(const __be64 *p)
59174 {
59175 - return __swab64p((__u64 *)p);
59176 + return __swab64p((const __u64 *)p);
59177 }
59178 static inline __be32 __cpu_to_be32p(const __u32 *p)
59179 {
59180 - return (__force __be32)__swab32p(p);
59181 + return (__force const __be32)__swab32p(p);
59182 }
59183 static inline __u32 __be32_to_cpup(const __be32 *p)
59184 {
59185 - return __swab32p((__u32 *)p);
59186 + return __swab32p((const __u32 *)p);
59187 }
59188 static inline __be16 __cpu_to_be16p(const __u16 *p)
59189 {
59190 - return (__force __be16)__swab16p(p);
59191 + return (__force const __be16)__swab16p(p);
59192 }
59193 static inline __u16 __be16_to_cpup(const __be16 *p)
59194 {
59195 - return __swab16p((__u16 *)p);
59196 + return __swab16p((const __u16 *)p);
59197 }
59198 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
59199 #define __le64_to_cpus(x) do { (void)(x); } while (0)
59200 diff --git a/include/linux/cache.h b/include/linux/cache.h
59201 index 4c57065..4307975 100644
59202 --- a/include/linux/cache.h
59203 +++ b/include/linux/cache.h
59204 @@ -16,6 +16,10 @@
59205 #define __read_mostly
59206 #endif
59207
59208 +#ifndef __read_only
59209 +#define __read_only __read_mostly
59210 +#endif
59211 +
59212 #ifndef ____cacheline_aligned
59213 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
59214 #endif
59215 diff --git a/include/linux/capability.h b/include/linux/capability.h
59216 index 12d52de..b5f7fa7 100644
59217 --- a/include/linux/capability.h
59218 +++ b/include/linux/capability.h
59219 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
59220 extern bool capable(int cap);
59221 extern bool ns_capable(struct user_namespace *ns, int cap);
59222 extern bool nsown_capable(int cap);
59223 +extern bool capable_nolog(int cap);
59224 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
59225
59226 /* audit system wants to get cap info from files as well */
59227 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
59228 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
59229 index 04ffb2e..6799180 100644
59230 --- a/include/linux/cleancache.h
59231 +++ b/include/linux/cleancache.h
59232 @@ -31,7 +31,7 @@ struct cleancache_ops {
59233 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
59234 void (*flush_inode)(int, struct cleancache_filekey);
59235 void (*flush_fs)(int);
59236 -};
59237 +} __no_const;
59238
59239 extern struct cleancache_ops
59240 cleancache_register_ops(struct cleancache_ops *ops);
59241 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
59242 index 2f40791..89a56fd 100644
59243 --- a/include/linux/compiler-gcc4.h
59244 +++ b/include/linux/compiler-gcc4.h
59245 @@ -32,6 +32,12 @@
59246 #define __linktime_error(message) __attribute__((__error__(message)))
59247
59248 #if __GNUC_MINOR__ >= 5
59249 +
59250 +#ifdef CONSTIFY_PLUGIN
59251 +#define __no_const __attribute__((no_const))
59252 +#define __do_const __attribute__((do_const))
59253 +#endif
59254 +
59255 /*
59256 * Mark a position in code as unreachable. This can be used to
59257 * suppress control flow warnings after asm blocks that transfer
59258 @@ -47,6 +53,11 @@
59259 #define __noclone __attribute__((__noclone__))
59260
59261 #endif
59262 +
59263 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
59264 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
59265 +#define __bos0(ptr) __bos((ptr), 0)
59266 +#define __bos1(ptr) __bos((ptr), 1)
59267 #endif
59268
59269 #if __GNUC_MINOR__ > 0
59270 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
59271 index 4a24354..9570c1b 100644
59272 --- a/include/linux/compiler.h
59273 +++ b/include/linux/compiler.h
59274 @@ -5,31 +5,62 @@
59275
59276 #ifdef __CHECKER__
59277 # define __user __attribute__((noderef, address_space(1)))
59278 +# define __force_user __force __user
59279 # define __kernel __attribute__((address_space(0)))
59280 +# define __force_kernel __force __kernel
59281 # define __safe __attribute__((safe))
59282 # define __force __attribute__((force))
59283 # define __nocast __attribute__((nocast))
59284 # define __iomem __attribute__((noderef, address_space(2)))
59285 +# define __force_iomem __force __iomem
59286 # define __acquires(x) __attribute__((context(x,0,1)))
59287 # define __releases(x) __attribute__((context(x,1,0)))
59288 # define __acquire(x) __context__(x,1)
59289 # define __release(x) __context__(x,-1)
59290 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
59291 # define __percpu __attribute__((noderef, address_space(3)))
59292 +# define __force_percpu __force __percpu
59293 #ifdef CONFIG_SPARSE_RCU_POINTER
59294 # define __rcu __attribute__((noderef, address_space(4)))
59295 +# define __force_rcu __force __rcu
59296 #else
59297 # define __rcu
59298 +# define __force_rcu
59299 #endif
59300 extern void __chk_user_ptr(const volatile void __user *);
59301 extern void __chk_io_ptr(const volatile void __iomem *);
59302 +#elif defined(CHECKER_PLUGIN)
59303 +//# define __user
59304 +//# define __force_user
59305 +//# define __kernel
59306 +//# define __force_kernel
59307 +# define __safe
59308 +# define __force
59309 +# define __nocast
59310 +# define __iomem
59311 +# define __force_iomem
59312 +# define __chk_user_ptr(x) (void)0
59313 +# define __chk_io_ptr(x) (void)0
59314 +# define __builtin_warning(x, y...) (1)
59315 +# define __acquires(x)
59316 +# define __releases(x)
59317 +# define __acquire(x) (void)0
59318 +# define __release(x) (void)0
59319 +# define __cond_lock(x,c) (c)
59320 +# define __percpu
59321 +# define __force_percpu
59322 +# define __rcu
59323 +# define __force_rcu
59324 #else
59325 # define __user
59326 +# define __force_user
59327 # define __kernel
59328 +# define __force_kernel
59329 # define __safe
59330 # define __force
59331 # define __nocast
59332 # define __iomem
59333 +# define __force_iomem
59334 # define __chk_user_ptr(x) (void)0
59335 # define __chk_io_ptr(x) (void)0
59336 # define __builtin_warning(x, y...) (1)
59337 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59338 # define __release(x) (void)0
59339 # define __cond_lock(x,c) (c)
59340 # define __percpu
59341 +# define __force_percpu
59342 # define __rcu
59343 +# define __force_rcu
59344 #endif
59345
59346 #ifdef __KERNEL__
59347 @@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59348 # define __attribute_const__ /* unimplemented */
59349 #endif
59350
59351 +#ifndef __no_const
59352 +# define __no_const
59353 +#endif
59354 +
59355 +#ifndef __do_const
59356 +# define __do_const
59357 +#endif
59358 +
59359 /*
59360 * Tell gcc if a function is cold. The compiler will assume any path
59361 * directly leading to the call is unlikely.
59362 @@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59363 #define __cold
59364 #endif
59365
59366 +#ifndef __alloc_size
59367 +#define __alloc_size(...)
59368 +#endif
59369 +
59370 +#ifndef __bos
59371 +#define __bos(ptr, arg)
59372 +#endif
59373 +
59374 +#ifndef __bos0
59375 +#define __bos0(ptr)
59376 +#endif
59377 +
59378 +#ifndef __bos1
59379 +#define __bos1(ptr)
59380 +#endif
59381 +
59382 /* Simple shorthand for a section definition */
59383 #ifndef __section
59384 # define __section(S) __attribute__ ((__section__(#S)))
59385 @@ -308,6 +365,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59386 * use is to mediate communication between process-level code and irq/NMI
59387 * handlers, all running on the same CPU.
59388 */
59389 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
59390 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
59391 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
59392
59393 #endif /* __LINUX_COMPILER_H */
59394 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
59395 index e9eaec5..bfeb9bb 100644
59396 --- a/include/linux/cpuset.h
59397 +++ b/include/linux/cpuset.h
59398 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
59399 * nodemask.
59400 */
59401 smp_mb();
59402 - --ACCESS_ONCE(current->mems_allowed_change_disable);
59403 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
59404 }
59405
59406 static inline void set_mems_allowed(nodemask_t nodemask)
59407 diff --git a/include/linux/cred.h b/include/linux/cred.h
59408 index adadf71..6af5560 100644
59409 --- a/include/linux/cred.h
59410 +++ b/include/linux/cred.h
59411 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
59412 static inline void validate_process_creds(void)
59413 {
59414 }
59415 +static inline void validate_task_creds(struct task_struct *task)
59416 +{
59417 +}
59418 #endif
59419
59420 /**
59421 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
59422 index 8a94217..15d49e3 100644
59423 --- a/include/linux/crypto.h
59424 +++ b/include/linux/crypto.h
59425 @@ -365,7 +365,7 @@ struct cipher_tfm {
59426 const u8 *key, unsigned int keylen);
59427 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59428 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59429 -};
59430 +} __no_const;
59431
59432 struct hash_tfm {
59433 int (*init)(struct hash_desc *desc);
59434 @@ -386,13 +386,13 @@ struct compress_tfm {
59435 int (*cot_decompress)(struct crypto_tfm *tfm,
59436 const u8 *src, unsigned int slen,
59437 u8 *dst, unsigned int *dlen);
59438 -};
59439 +} __no_const;
59440
59441 struct rng_tfm {
59442 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
59443 unsigned int dlen);
59444 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
59445 -};
59446 +} __no_const;
59447
59448 #define crt_ablkcipher crt_u.ablkcipher
59449 #define crt_aead crt_u.aead
59450 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
59451 index 7925bf0..d5143d2 100644
59452 --- a/include/linux/decompress/mm.h
59453 +++ b/include/linux/decompress/mm.h
59454 @@ -77,7 +77,7 @@ static void free(void *where)
59455 * warnings when not needed (indeed large_malloc / large_free are not
59456 * needed by inflate */
59457
59458 -#define malloc(a) kmalloc(a, GFP_KERNEL)
59459 +#define malloc(a) kmalloc((a), GFP_KERNEL)
59460 #define free(a) kfree(a)
59461
59462 #define large_malloc(a) vmalloc(a)
59463 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
59464 index e13117c..e9fc938 100644
59465 --- a/include/linux/dma-mapping.h
59466 +++ b/include/linux/dma-mapping.h
59467 @@ -46,7 +46,7 @@ struct dma_map_ops {
59468 u64 (*get_required_mask)(struct device *dev);
59469 #endif
59470 int is_phys;
59471 -};
59472 +} __do_const;
59473
59474 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
59475
59476 diff --git a/include/linux/efi.h b/include/linux/efi.h
59477 index 37c3007..92ab679 100644
59478 --- a/include/linux/efi.h
59479 +++ b/include/linux/efi.h
59480 @@ -580,7 +580,7 @@ struct efivar_operations {
59481 efi_get_variable_t *get_variable;
59482 efi_get_next_variable_t *get_next_variable;
59483 efi_set_variable_t *set_variable;
59484 -};
59485 +} __no_const;
59486
59487 struct efivars {
59488 /*
59489 diff --git a/include/linux/elf.h b/include/linux/elf.h
59490 index 999b4f5..57753b4 100644
59491 --- a/include/linux/elf.h
59492 +++ b/include/linux/elf.h
59493 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
59494 #define PT_GNU_EH_FRAME 0x6474e550
59495
59496 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
59497 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
59498 +
59499 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
59500 +
59501 +/* Constants for the e_flags field */
59502 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59503 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
59504 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
59505 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
59506 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59507 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59508
59509 /*
59510 * Extended Numbering
59511 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
59512 #define DT_DEBUG 21
59513 #define DT_TEXTREL 22
59514 #define DT_JMPREL 23
59515 +#define DT_FLAGS 30
59516 + #define DF_TEXTREL 0x00000004
59517 #define DT_ENCODING 32
59518 #define OLD_DT_LOOS 0x60000000
59519 #define DT_LOOS 0x6000000d
59520 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
59521 #define PF_W 0x2
59522 #define PF_X 0x1
59523
59524 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
59525 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
59526 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
59527 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
59528 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
59529 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
59530 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
59531 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
59532 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
59533 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
59534 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
59535 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
59536 +
59537 typedef struct elf32_phdr{
59538 Elf32_Word p_type;
59539 Elf32_Off p_offset;
59540 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
59541 #define EI_OSABI 7
59542 #define EI_PAD 8
59543
59544 +#define EI_PAX 14
59545 +
59546 #define ELFMAG0 0x7f /* EI_MAG */
59547 #define ELFMAG1 'E'
59548 #define ELFMAG2 'L'
59549 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
59550 #define elf_note elf32_note
59551 #define elf_addr_t Elf32_Off
59552 #define Elf_Half Elf32_Half
59553 +#define elf_dyn Elf32_Dyn
59554
59555 #else
59556
59557 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
59558 #define elf_note elf64_note
59559 #define elf_addr_t Elf64_Off
59560 #define Elf_Half Elf64_Half
59561 +#define elf_dyn Elf64_Dyn
59562
59563 #endif
59564
59565 diff --git a/include/linux/filter.h b/include/linux/filter.h
59566 index 8eeb205..d59bfa2 100644
59567 --- a/include/linux/filter.h
59568 +++ b/include/linux/filter.h
59569 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
59570
59571 struct sk_buff;
59572 struct sock;
59573 +struct bpf_jit_work;
59574
59575 struct sk_filter
59576 {
59577 @@ -141,6 +142,9 @@ struct sk_filter
59578 unsigned int len; /* Number of filter blocks */
59579 unsigned int (*bpf_func)(const struct sk_buff *skb,
59580 const struct sock_filter *filter);
59581 +#ifdef CONFIG_BPF_JIT
59582 + struct bpf_jit_work *work;
59583 +#endif
59584 struct rcu_head rcu;
59585 struct sock_filter insns[0];
59586 };
59587 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
59588 index 84ccf8e..2e9b14c 100644
59589 --- a/include/linux/firewire.h
59590 +++ b/include/linux/firewire.h
59591 @@ -428,7 +428,7 @@ struct fw_iso_context {
59592 union {
59593 fw_iso_callback_t sc;
59594 fw_iso_mc_callback_t mc;
59595 - } callback;
59596 + } __no_const callback;
59597 void *callback_data;
59598 };
59599
59600 diff --git a/include/linux/fs.h b/include/linux/fs.h
59601 index 69cd5bb..58425c2 100644
59602 --- a/include/linux/fs.h
59603 +++ b/include/linux/fs.h
59604 @@ -1623,7 +1623,8 @@ struct file_operations {
59605 int (*setlease)(struct file *, long, struct file_lock **);
59606 long (*fallocate)(struct file *file, int mode, loff_t offset,
59607 loff_t len);
59608 -};
59609 +} __do_const;
59610 +typedef struct file_operations __no_const file_operations_no_const;
59611
59612 struct inode_operations {
59613 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
59614 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
59615 index 003dc0f..3c4ea97 100644
59616 --- a/include/linux/fs_struct.h
59617 +++ b/include/linux/fs_struct.h
59618 @@ -6,7 +6,7 @@
59619 #include <linux/seqlock.h>
59620
59621 struct fs_struct {
59622 - int users;
59623 + atomic_t users;
59624 spinlock_t lock;
59625 seqcount_t seq;
59626 int umask;
59627 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
59628 index ce31408..b1ad003 100644
59629 --- a/include/linux/fscache-cache.h
59630 +++ b/include/linux/fscache-cache.h
59631 @@ -102,7 +102,7 @@ struct fscache_operation {
59632 fscache_operation_release_t release;
59633 };
59634
59635 -extern atomic_t fscache_op_debug_id;
59636 +extern atomic_unchecked_t fscache_op_debug_id;
59637 extern void fscache_op_work_func(struct work_struct *work);
59638
59639 extern void fscache_enqueue_operation(struct fscache_operation *);
59640 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
59641 {
59642 INIT_WORK(&op->work, fscache_op_work_func);
59643 atomic_set(&op->usage, 1);
59644 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59645 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59646 op->processor = processor;
59647 op->release = release;
59648 INIT_LIST_HEAD(&op->pend_link);
59649 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
59650 index 2a53f10..0187fdf 100644
59651 --- a/include/linux/fsnotify.h
59652 +++ b/include/linux/fsnotify.h
59653 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
59654 */
59655 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
59656 {
59657 - return kstrdup(name, GFP_KERNEL);
59658 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
59659 }
59660
59661 /*
59662 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
59663 index 91d0e0a3..035666b 100644
59664 --- a/include/linux/fsnotify_backend.h
59665 +++ b/include/linux/fsnotify_backend.h
59666 @@ -105,6 +105,7 @@ struct fsnotify_ops {
59667 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
59668 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
59669 };
59670 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
59671
59672 /*
59673 * A group is a "thing" that wants to receive notification about filesystem
59674 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
59675 index c3da42d..c70e0df 100644
59676 --- a/include/linux/ftrace_event.h
59677 +++ b/include/linux/ftrace_event.h
59678 @@ -97,7 +97,7 @@ struct trace_event_functions {
59679 trace_print_func raw;
59680 trace_print_func hex;
59681 trace_print_func binary;
59682 -};
59683 +} __no_const;
59684
59685 struct trace_event {
59686 struct hlist_node node;
59687 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
59688 extern int trace_add_event_call(struct ftrace_event_call *call);
59689 extern void trace_remove_event_call(struct ftrace_event_call *call);
59690
59691 -#define is_signed_type(type) (((type)(-1)) < 0)
59692 +#define is_signed_type(type) (((type)(-1)) < (type)1)
59693
59694 int trace_set_clr_event(const char *system, const char *event, int set);
59695
59696 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
59697 index e61d319..0da8505 100644
59698 --- a/include/linux/genhd.h
59699 +++ b/include/linux/genhd.h
59700 @@ -185,7 +185,7 @@ struct gendisk {
59701 struct kobject *slave_dir;
59702
59703 struct timer_rand_state *random;
59704 - atomic_t sync_io; /* RAID */
59705 + atomic_unchecked_t sync_io; /* RAID */
59706 struct disk_events *ev;
59707 #ifdef CONFIG_BLK_DEV_INTEGRITY
59708 struct blk_integrity *integrity;
59709 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
59710 new file mode 100644
59711 index 0000000..8a130b6
59712 --- /dev/null
59713 +++ b/include/linux/gracl.h
59714 @@ -0,0 +1,319 @@
59715 +#ifndef GR_ACL_H
59716 +#define GR_ACL_H
59717 +
59718 +#include <linux/grdefs.h>
59719 +#include <linux/resource.h>
59720 +#include <linux/capability.h>
59721 +#include <linux/dcache.h>
59722 +#include <asm/resource.h>
59723 +
59724 +/* Major status information */
59725 +
59726 +#define GR_VERSION "grsecurity 2.9"
59727 +#define GRSECURITY_VERSION 0x2900
59728 +
59729 +enum {
59730 + GR_SHUTDOWN = 0,
59731 + GR_ENABLE = 1,
59732 + GR_SPROLE = 2,
59733 + GR_RELOAD = 3,
59734 + GR_SEGVMOD = 4,
59735 + GR_STATUS = 5,
59736 + GR_UNSPROLE = 6,
59737 + GR_PASSSET = 7,
59738 + GR_SPROLEPAM = 8,
59739 +};
59740 +
59741 +/* Password setup definitions
59742 + * kernel/grhash.c */
59743 +enum {
59744 + GR_PW_LEN = 128,
59745 + GR_SALT_LEN = 16,
59746 + GR_SHA_LEN = 32,
59747 +};
59748 +
59749 +enum {
59750 + GR_SPROLE_LEN = 64,
59751 +};
59752 +
59753 +enum {
59754 + GR_NO_GLOB = 0,
59755 + GR_REG_GLOB,
59756 + GR_CREATE_GLOB
59757 +};
59758 +
59759 +#define GR_NLIMITS 32
59760 +
59761 +/* Begin Data Structures */
59762 +
59763 +struct sprole_pw {
59764 + unsigned char *rolename;
59765 + unsigned char salt[GR_SALT_LEN];
59766 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
59767 +};
59768 +
59769 +struct name_entry {
59770 + __u32 key;
59771 + ino_t inode;
59772 + dev_t device;
59773 + char *name;
59774 + __u16 len;
59775 + __u8 deleted;
59776 + struct name_entry *prev;
59777 + struct name_entry *next;
59778 +};
59779 +
59780 +struct inodev_entry {
59781 + struct name_entry *nentry;
59782 + struct inodev_entry *prev;
59783 + struct inodev_entry *next;
59784 +};
59785 +
59786 +struct acl_role_db {
59787 + struct acl_role_label **r_hash;
59788 + __u32 r_size;
59789 +};
59790 +
59791 +struct inodev_db {
59792 + struct inodev_entry **i_hash;
59793 + __u32 i_size;
59794 +};
59795 +
59796 +struct name_db {
59797 + struct name_entry **n_hash;
59798 + __u32 n_size;
59799 +};
59800 +
59801 +struct crash_uid {
59802 + uid_t uid;
59803 + unsigned long expires;
59804 +};
59805 +
59806 +struct gr_hash_struct {
59807 + void **table;
59808 + void **nametable;
59809 + void *first;
59810 + __u32 table_size;
59811 + __u32 used_size;
59812 + int type;
59813 +};
59814 +
59815 +/* Userspace Grsecurity ACL data structures */
59816 +
59817 +struct acl_subject_label {
59818 + char *filename;
59819 + ino_t inode;
59820 + dev_t device;
59821 + __u32 mode;
59822 + kernel_cap_t cap_mask;
59823 + kernel_cap_t cap_lower;
59824 + kernel_cap_t cap_invert_audit;
59825 +
59826 + struct rlimit res[GR_NLIMITS];
59827 + __u32 resmask;
59828 +
59829 + __u8 user_trans_type;
59830 + __u8 group_trans_type;
59831 + uid_t *user_transitions;
59832 + gid_t *group_transitions;
59833 + __u16 user_trans_num;
59834 + __u16 group_trans_num;
59835 +
59836 + __u32 sock_families[2];
59837 + __u32 ip_proto[8];
59838 + __u32 ip_type;
59839 + struct acl_ip_label **ips;
59840 + __u32 ip_num;
59841 + __u32 inaddr_any_override;
59842 +
59843 + __u32 crashes;
59844 + unsigned long expires;
59845 +
59846 + struct acl_subject_label *parent_subject;
59847 + struct gr_hash_struct *hash;
59848 + struct acl_subject_label *prev;
59849 + struct acl_subject_label *next;
59850 +
59851 + struct acl_object_label **obj_hash;
59852 + __u32 obj_hash_size;
59853 + __u16 pax_flags;
59854 +};
59855 +
59856 +struct role_allowed_ip {
59857 + __u32 addr;
59858 + __u32 netmask;
59859 +
59860 + struct role_allowed_ip *prev;
59861 + struct role_allowed_ip *next;
59862 +};
59863 +
59864 +struct role_transition {
59865 + char *rolename;
59866 +
59867 + struct role_transition *prev;
59868 + struct role_transition *next;
59869 +};
59870 +
59871 +struct acl_role_label {
59872 + char *rolename;
59873 + uid_t uidgid;
59874 + __u16 roletype;
59875 +
59876 + __u16 auth_attempts;
59877 + unsigned long expires;
59878 +
59879 + struct acl_subject_label *root_label;
59880 + struct gr_hash_struct *hash;
59881 +
59882 + struct acl_role_label *prev;
59883 + struct acl_role_label *next;
59884 +
59885 + struct role_transition *transitions;
59886 + struct role_allowed_ip *allowed_ips;
59887 + uid_t *domain_children;
59888 + __u16 domain_child_num;
59889 +
59890 + umode_t umask;
59891 +
59892 + struct acl_subject_label **subj_hash;
59893 + __u32 subj_hash_size;
59894 +};
59895 +
59896 +struct user_acl_role_db {
59897 + struct acl_role_label **r_table;
59898 + __u32 num_pointers; /* Number of allocations to track */
59899 + __u32 num_roles; /* Number of roles */
59900 + __u32 num_domain_children; /* Number of domain children */
59901 + __u32 num_subjects; /* Number of subjects */
59902 + __u32 num_objects; /* Number of objects */
59903 +};
59904 +
59905 +struct acl_object_label {
59906 + char *filename;
59907 + ino_t inode;
59908 + dev_t device;
59909 + __u32 mode;
59910 +
59911 + struct acl_subject_label *nested;
59912 + struct acl_object_label *globbed;
59913 +
59914 + /* next two structures not used */
59915 +
59916 + struct acl_object_label *prev;
59917 + struct acl_object_label *next;
59918 +};
59919 +
59920 +struct acl_ip_label {
59921 + char *iface;
59922 + __u32 addr;
59923 + __u32 netmask;
59924 + __u16 low, high;
59925 + __u8 mode;
59926 + __u32 type;
59927 + __u32 proto[8];
59928 +
59929 + /* next two structures not used */
59930 +
59931 + struct acl_ip_label *prev;
59932 + struct acl_ip_label *next;
59933 +};
59934 +
59935 +struct gr_arg {
59936 + struct user_acl_role_db role_db;
59937 + unsigned char pw[GR_PW_LEN];
59938 + unsigned char salt[GR_SALT_LEN];
59939 + unsigned char sum[GR_SHA_LEN];
59940 + unsigned char sp_role[GR_SPROLE_LEN];
59941 + struct sprole_pw *sprole_pws;
59942 + dev_t segv_device;
59943 + ino_t segv_inode;
59944 + uid_t segv_uid;
59945 + __u16 num_sprole_pws;
59946 + __u16 mode;
59947 +};
59948 +
59949 +struct gr_arg_wrapper {
59950 + struct gr_arg *arg;
59951 + __u32 version;
59952 + __u32 size;
59953 +};
59954 +
59955 +struct subject_map {
59956 + struct acl_subject_label *user;
59957 + struct acl_subject_label *kernel;
59958 + struct subject_map *prev;
59959 + struct subject_map *next;
59960 +};
59961 +
59962 +struct acl_subj_map_db {
59963 + struct subject_map **s_hash;
59964 + __u32 s_size;
59965 +};
59966 +
59967 +/* End Data Structures Section */
59968 +
59969 +/* Hash functions generated by empirical testing by Brad Spengler
59970 + Makes good use of the low bits of the inode. Generally 0-1 times
59971 + in loop for successful match. 0-3 for unsuccessful match.
59972 + Shift/add algorithm with modulus of table size and an XOR*/
59973 +
59974 +static __inline__ unsigned int
59975 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
59976 +{
59977 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
59978 +}
59979 +
59980 + static __inline__ unsigned int
59981 +shash(const struct acl_subject_label *userp, const unsigned int sz)
59982 +{
59983 + return ((const unsigned long)userp % sz);
59984 +}
59985 +
59986 +static __inline__ unsigned int
59987 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
59988 +{
59989 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
59990 +}
59991 +
59992 +static __inline__ unsigned int
59993 +nhash(const char *name, const __u16 len, const unsigned int sz)
59994 +{
59995 + return full_name_hash((const unsigned char *)name, len) % sz;
59996 +}
59997 +
59998 +#define FOR_EACH_ROLE_START(role) \
59999 + role = role_list; \
60000 + while (role) {
60001 +
60002 +#define FOR_EACH_ROLE_END(role) \
60003 + role = role->prev; \
60004 + }
60005 +
60006 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
60007 + subj = NULL; \
60008 + iter = 0; \
60009 + while (iter < role->subj_hash_size) { \
60010 + if (subj == NULL) \
60011 + subj = role->subj_hash[iter]; \
60012 + if (subj == NULL) { \
60013 + iter++; \
60014 + continue; \
60015 + }
60016 +
60017 +#define FOR_EACH_SUBJECT_END(subj,iter) \
60018 + subj = subj->next; \
60019 + if (subj == NULL) \
60020 + iter++; \
60021 + }
60022 +
60023 +
60024 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60025 + subj = role->hash->first; \
60026 + while (subj != NULL) {
60027 +
60028 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60029 + subj = subj->next; \
60030 + }
60031 +
60032 +#endif
60033 +
60034 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
60035 new file mode 100644
60036 index 0000000..323ecf2
60037 --- /dev/null
60038 +++ b/include/linux/gralloc.h
60039 @@ -0,0 +1,9 @@
60040 +#ifndef __GRALLOC_H
60041 +#define __GRALLOC_H
60042 +
60043 +void acl_free_all(void);
60044 +int acl_alloc_stack_init(unsigned long size);
60045 +void *acl_alloc(unsigned long len);
60046 +void *acl_alloc_num(unsigned long num, unsigned long len);
60047 +
60048 +#endif
60049 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
60050 new file mode 100644
60051 index 0000000..b30e9bc
60052 --- /dev/null
60053 +++ b/include/linux/grdefs.h
60054 @@ -0,0 +1,140 @@
60055 +#ifndef GRDEFS_H
60056 +#define GRDEFS_H
60057 +
60058 +/* Begin grsecurity status declarations */
60059 +
60060 +enum {
60061 + GR_READY = 0x01,
60062 + GR_STATUS_INIT = 0x00 // disabled state
60063 +};
60064 +
60065 +/* Begin ACL declarations */
60066 +
60067 +/* Role flags */
60068 +
60069 +enum {
60070 + GR_ROLE_USER = 0x0001,
60071 + GR_ROLE_GROUP = 0x0002,
60072 + GR_ROLE_DEFAULT = 0x0004,
60073 + GR_ROLE_SPECIAL = 0x0008,
60074 + GR_ROLE_AUTH = 0x0010,
60075 + GR_ROLE_NOPW = 0x0020,
60076 + GR_ROLE_GOD = 0x0040,
60077 + GR_ROLE_LEARN = 0x0080,
60078 + GR_ROLE_TPE = 0x0100,
60079 + GR_ROLE_DOMAIN = 0x0200,
60080 + GR_ROLE_PAM = 0x0400,
60081 + GR_ROLE_PERSIST = 0x0800
60082 +};
60083 +
60084 +/* ACL Subject and Object mode flags */
60085 +enum {
60086 + GR_DELETED = 0x80000000
60087 +};
60088 +
60089 +/* ACL Object-only mode flags */
60090 +enum {
60091 + GR_READ = 0x00000001,
60092 + GR_APPEND = 0x00000002,
60093 + GR_WRITE = 0x00000004,
60094 + GR_EXEC = 0x00000008,
60095 + GR_FIND = 0x00000010,
60096 + GR_INHERIT = 0x00000020,
60097 + GR_SETID = 0x00000040,
60098 + GR_CREATE = 0x00000080,
60099 + GR_DELETE = 0x00000100,
60100 + GR_LINK = 0x00000200,
60101 + GR_AUDIT_READ = 0x00000400,
60102 + GR_AUDIT_APPEND = 0x00000800,
60103 + GR_AUDIT_WRITE = 0x00001000,
60104 + GR_AUDIT_EXEC = 0x00002000,
60105 + GR_AUDIT_FIND = 0x00004000,
60106 + GR_AUDIT_INHERIT= 0x00008000,
60107 + GR_AUDIT_SETID = 0x00010000,
60108 + GR_AUDIT_CREATE = 0x00020000,
60109 + GR_AUDIT_DELETE = 0x00040000,
60110 + GR_AUDIT_LINK = 0x00080000,
60111 + GR_PTRACERD = 0x00100000,
60112 + GR_NOPTRACE = 0x00200000,
60113 + GR_SUPPRESS = 0x00400000,
60114 + GR_NOLEARN = 0x00800000,
60115 + GR_INIT_TRANSFER= 0x01000000
60116 +};
60117 +
60118 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
60119 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
60120 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
60121 +
60122 +/* ACL subject-only mode flags */
60123 +enum {
60124 + GR_KILL = 0x00000001,
60125 + GR_VIEW = 0x00000002,
60126 + GR_PROTECTED = 0x00000004,
60127 + GR_LEARN = 0x00000008,
60128 + GR_OVERRIDE = 0x00000010,
60129 + /* just a placeholder, this mode is only used in userspace */
60130 + GR_DUMMY = 0x00000020,
60131 + GR_PROTSHM = 0x00000040,
60132 + GR_KILLPROC = 0x00000080,
60133 + GR_KILLIPPROC = 0x00000100,
60134 + /* just a placeholder, this mode is only used in userspace */
60135 + GR_NOTROJAN = 0x00000200,
60136 + GR_PROTPROCFD = 0x00000400,
60137 + GR_PROCACCT = 0x00000800,
60138 + GR_RELAXPTRACE = 0x00001000,
60139 + GR_NESTED = 0x00002000,
60140 + GR_INHERITLEARN = 0x00004000,
60141 + GR_PROCFIND = 0x00008000,
60142 + GR_POVERRIDE = 0x00010000,
60143 + GR_KERNELAUTH = 0x00020000,
60144 + GR_ATSECURE = 0x00040000,
60145 + GR_SHMEXEC = 0x00080000
60146 +};
60147 +
60148 +enum {
60149 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
60150 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
60151 + GR_PAX_ENABLE_MPROTECT = 0x0004,
60152 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
60153 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
60154 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
60155 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
60156 + GR_PAX_DISABLE_MPROTECT = 0x0400,
60157 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
60158 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
60159 +};
60160 +
60161 +enum {
60162 + GR_ID_USER = 0x01,
60163 + GR_ID_GROUP = 0x02,
60164 +};
60165 +
60166 +enum {
60167 + GR_ID_ALLOW = 0x01,
60168 + GR_ID_DENY = 0x02,
60169 +};
60170 +
60171 +#define GR_CRASH_RES 31
60172 +#define GR_UIDTABLE_MAX 500
60173 +
60174 +/* begin resource learning section */
60175 +enum {
60176 + GR_RLIM_CPU_BUMP = 60,
60177 + GR_RLIM_FSIZE_BUMP = 50000,
60178 + GR_RLIM_DATA_BUMP = 10000,
60179 + GR_RLIM_STACK_BUMP = 1000,
60180 + GR_RLIM_CORE_BUMP = 10000,
60181 + GR_RLIM_RSS_BUMP = 500000,
60182 + GR_RLIM_NPROC_BUMP = 1,
60183 + GR_RLIM_NOFILE_BUMP = 5,
60184 + GR_RLIM_MEMLOCK_BUMP = 50000,
60185 + GR_RLIM_AS_BUMP = 500000,
60186 + GR_RLIM_LOCKS_BUMP = 2,
60187 + GR_RLIM_SIGPENDING_BUMP = 5,
60188 + GR_RLIM_MSGQUEUE_BUMP = 10000,
60189 + GR_RLIM_NICE_BUMP = 1,
60190 + GR_RLIM_RTPRIO_BUMP = 1,
60191 + GR_RLIM_RTTIME_BUMP = 1000000
60192 +};
60193 +
60194 +#endif
60195 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
60196 new file mode 100644
60197 index 0000000..da390f1
60198 --- /dev/null
60199 +++ b/include/linux/grinternal.h
60200 @@ -0,0 +1,221 @@
60201 +#ifndef __GRINTERNAL_H
60202 +#define __GRINTERNAL_H
60203 +
60204 +#ifdef CONFIG_GRKERNSEC
60205 +
60206 +#include <linux/fs.h>
60207 +#include <linux/mnt_namespace.h>
60208 +#include <linux/nsproxy.h>
60209 +#include <linux/gracl.h>
60210 +#include <linux/grdefs.h>
60211 +#include <linux/grmsg.h>
60212 +
60213 +void gr_add_learn_entry(const char *fmt, ...)
60214 + __attribute__ ((format (printf, 1, 2)));
60215 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
60216 + const struct vfsmount *mnt);
60217 +__u32 gr_check_create(const struct dentry *new_dentry,
60218 + const struct dentry *parent,
60219 + const struct vfsmount *mnt, const __u32 mode);
60220 +int gr_check_protected_task(const struct task_struct *task);
60221 +__u32 to_gr_audit(const __u32 reqmode);
60222 +int gr_set_acls(const int type);
60223 +int gr_apply_subject_to_task(struct task_struct *task);
60224 +int gr_acl_is_enabled(void);
60225 +char gr_roletype_to_char(void);
60226 +
60227 +void gr_handle_alertkill(struct task_struct *task);
60228 +char *gr_to_filename(const struct dentry *dentry,
60229 + const struct vfsmount *mnt);
60230 +char *gr_to_filename1(const struct dentry *dentry,
60231 + const struct vfsmount *mnt);
60232 +char *gr_to_filename2(const struct dentry *dentry,
60233 + const struct vfsmount *mnt);
60234 +char *gr_to_filename3(const struct dentry *dentry,
60235 + const struct vfsmount *mnt);
60236 +
60237 +extern int grsec_enable_ptrace_readexec;
60238 +extern int grsec_enable_harden_ptrace;
60239 +extern int grsec_enable_link;
60240 +extern int grsec_enable_fifo;
60241 +extern int grsec_enable_execve;
60242 +extern int grsec_enable_shm;
60243 +extern int grsec_enable_execlog;
60244 +extern int grsec_enable_signal;
60245 +extern int grsec_enable_audit_ptrace;
60246 +extern int grsec_enable_forkfail;
60247 +extern int grsec_enable_time;
60248 +extern int grsec_enable_rofs;
60249 +extern int grsec_enable_chroot_shmat;
60250 +extern int grsec_enable_chroot_mount;
60251 +extern int grsec_enable_chroot_double;
60252 +extern int grsec_enable_chroot_pivot;
60253 +extern int grsec_enable_chroot_chdir;
60254 +extern int grsec_enable_chroot_chmod;
60255 +extern int grsec_enable_chroot_mknod;
60256 +extern int grsec_enable_chroot_fchdir;
60257 +extern int grsec_enable_chroot_nice;
60258 +extern int grsec_enable_chroot_execlog;
60259 +extern int grsec_enable_chroot_caps;
60260 +extern int grsec_enable_chroot_sysctl;
60261 +extern int grsec_enable_chroot_unix;
60262 +extern int grsec_enable_tpe;
60263 +extern int grsec_tpe_gid;
60264 +extern int grsec_enable_tpe_all;
60265 +extern int grsec_enable_tpe_invert;
60266 +extern int grsec_enable_socket_all;
60267 +extern int grsec_socket_all_gid;
60268 +extern int grsec_enable_socket_client;
60269 +extern int grsec_socket_client_gid;
60270 +extern int grsec_enable_socket_server;
60271 +extern int grsec_socket_server_gid;
60272 +extern int grsec_audit_gid;
60273 +extern int grsec_enable_group;
60274 +extern int grsec_enable_audit_textrel;
60275 +extern int grsec_enable_log_rwxmaps;
60276 +extern int grsec_enable_mount;
60277 +extern int grsec_enable_chdir;
60278 +extern int grsec_resource_logging;
60279 +extern int grsec_enable_blackhole;
60280 +extern int grsec_lastack_retries;
60281 +extern int grsec_enable_brute;
60282 +extern int grsec_lock;
60283 +
60284 +extern spinlock_t grsec_alert_lock;
60285 +extern unsigned long grsec_alert_wtime;
60286 +extern unsigned long grsec_alert_fyet;
60287 +
60288 +extern spinlock_t grsec_audit_lock;
60289 +
60290 +extern rwlock_t grsec_exec_file_lock;
60291 +
60292 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
60293 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
60294 + (tsk)->exec_file->f_vfsmnt) : "/")
60295 +
60296 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
60297 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
60298 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60299 +
60300 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
60301 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
60302 + (tsk)->exec_file->f_vfsmnt) : "/")
60303 +
60304 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
60305 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
60306 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60307 +
60308 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
60309 +
60310 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
60311 +
60312 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
60313 + (task)->pid, (cred)->uid, \
60314 + (cred)->euid, (cred)->gid, (cred)->egid, \
60315 + gr_parent_task_fullpath(task), \
60316 + (task)->real_parent->comm, (task)->real_parent->pid, \
60317 + (pcred)->uid, (pcred)->euid, \
60318 + (pcred)->gid, (pcred)->egid
60319 +
60320 +#define GR_CHROOT_CAPS {{ \
60321 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
60322 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
60323 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
60324 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
60325 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
60326 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
60327 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
60328 +
60329 +#define security_learn(normal_msg,args...) \
60330 +({ \
60331 + read_lock(&grsec_exec_file_lock); \
60332 + gr_add_learn_entry(normal_msg "\n", ## args); \
60333 + read_unlock(&grsec_exec_file_lock); \
60334 +})
60335 +
60336 +enum {
60337 + GR_DO_AUDIT,
60338 + GR_DONT_AUDIT,
60339 + /* used for non-audit messages that we shouldn't kill the task on */
60340 + GR_DONT_AUDIT_GOOD
60341 +};
60342 +
60343 +enum {
60344 + GR_TTYSNIFF,
60345 + GR_RBAC,
60346 + GR_RBAC_STR,
60347 + GR_STR_RBAC,
60348 + GR_RBAC_MODE2,
60349 + GR_RBAC_MODE3,
60350 + GR_FILENAME,
60351 + GR_SYSCTL_HIDDEN,
60352 + GR_NOARGS,
60353 + GR_ONE_INT,
60354 + GR_ONE_INT_TWO_STR,
60355 + GR_ONE_STR,
60356 + GR_STR_INT,
60357 + GR_TWO_STR_INT,
60358 + GR_TWO_INT,
60359 + GR_TWO_U64,
60360 + GR_THREE_INT,
60361 + GR_FIVE_INT_TWO_STR,
60362 + GR_TWO_STR,
60363 + GR_THREE_STR,
60364 + GR_FOUR_STR,
60365 + GR_STR_FILENAME,
60366 + GR_FILENAME_STR,
60367 + GR_FILENAME_TWO_INT,
60368 + GR_FILENAME_TWO_INT_STR,
60369 + GR_TEXTREL,
60370 + GR_PTRACE,
60371 + GR_RESOURCE,
60372 + GR_CAP,
60373 + GR_SIG,
60374 + GR_SIG2,
60375 + GR_CRASH1,
60376 + GR_CRASH2,
60377 + GR_PSACCT,
60378 + GR_RWXMAP
60379 +};
60380 +
60381 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
60382 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
60383 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
60384 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
60385 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
60386 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
60387 +#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)
60388 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
60389 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
60390 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
60391 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
60392 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
60393 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
60394 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
60395 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
60396 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
60397 +#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)
60398 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
60399 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
60400 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
60401 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
60402 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
60403 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
60404 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
60405 +#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)
60406 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
60407 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
60408 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
60409 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
60410 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
60411 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
60412 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
60413 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
60414 +#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)
60415 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
60416 +
60417 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
60418 +
60419 +#endif
60420 +
60421 +#endif
60422 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
60423 new file mode 100644
60424 index 0000000..ae576a1
60425 --- /dev/null
60426 +++ b/include/linux/grmsg.h
60427 @@ -0,0 +1,109 @@
60428 +#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"
60429 +#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"
60430 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
60431 +#define GR_STOPMOD_MSG "denied modification of module state by "
60432 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
60433 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
60434 +#define GR_IOPERM_MSG "denied use of ioperm() by "
60435 +#define GR_IOPL_MSG "denied use of iopl() by "
60436 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
60437 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
60438 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
60439 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
60440 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
60441 +#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"
60442 +#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"
60443 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
60444 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
60445 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
60446 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
60447 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
60448 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
60449 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
60450 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
60451 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
60452 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
60453 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
60454 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
60455 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
60456 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
60457 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
60458 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
60459 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
60460 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
60461 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
60462 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
60463 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
60464 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
60465 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
60466 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
60467 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
60468 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
60469 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
60470 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
60471 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
60472 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
60473 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
60474 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
60475 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
60476 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
60477 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
60478 +#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"
60479 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
60480 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
60481 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
60482 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
60483 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
60484 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
60485 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
60486 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
60487 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
60488 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
60489 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
60490 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
60491 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
60492 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
60493 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
60494 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
60495 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
60496 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
60497 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
60498 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
60499 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
60500 +#define GR_NICE_CHROOT_MSG "denied priority change by "
60501 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
60502 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
60503 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
60504 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
60505 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
60506 +#define GR_TIME_MSG "time set by "
60507 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
60508 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
60509 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
60510 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
60511 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
60512 +#define GR_BIND_MSG "denied bind() by "
60513 +#define GR_CONNECT_MSG "denied connect() by "
60514 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
60515 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
60516 +#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"
60517 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
60518 +#define GR_CAP_ACL_MSG "use of %s denied for "
60519 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
60520 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
60521 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
60522 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
60523 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
60524 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
60525 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
60526 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
60527 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
60528 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
60529 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
60530 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
60531 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
60532 +#define GR_VM86_MSG "denied use of vm86 by "
60533 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
60534 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
60535 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
60536 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
60537 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
60538 new file mode 100644
60539 index 0000000..acd05db
60540 --- /dev/null
60541 +++ b/include/linux/grsecurity.h
60542 @@ -0,0 +1,232 @@
60543 +#ifndef GR_SECURITY_H
60544 +#define GR_SECURITY_H
60545 +#include <linux/fs.h>
60546 +#include <linux/fs_struct.h>
60547 +#include <linux/binfmts.h>
60548 +#include <linux/gracl.h>
60549 +
60550 +/* notify of brain-dead configs */
60551 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60552 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
60553 +#endif
60554 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
60555 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
60556 +#endif
60557 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
60558 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
60559 +#endif
60560 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
60561 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
60562 +#endif
60563 +
60564 +#include <linux/compat.h>
60565 +
60566 +struct user_arg_ptr {
60567 +#ifdef CONFIG_COMPAT
60568 + bool is_compat;
60569 +#endif
60570 + union {
60571 + const char __user *const __user *native;
60572 +#ifdef CONFIG_COMPAT
60573 + compat_uptr_t __user *compat;
60574 +#endif
60575 + } ptr;
60576 +};
60577 +
60578 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
60579 +void gr_handle_brute_check(void);
60580 +void gr_handle_kernel_exploit(void);
60581 +int gr_process_user_ban(void);
60582 +
60583 +char gr_roletype_to_char(void);
60584 +
60585 +int gr_acl_enable_at_secure(void);
60586 +
60587 +int gr_check_user_change(int real, int effective, int fs);
60588 +int gr_check_group_change(int real, int effective, int fs);
60589 +
60590 +void gr_del_task_from_ip_table(struct task_struct *p);
60591 +
60592 +int gr_pid_is_chrooted(struct task_struct *p);
60593 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
60594 +int gr_handle_chroot_nice(void);
60595 +int gr_handle_chroot_sysctl(const int op);
60596 +int gr_handle_chroot_setpriority(struct task_struct *p,
60597 + const int niceval);
60598 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
60599 +int gr_handle_chroot_chroot(const struct dentry *dentry,
60600 + const struct vfsmount *mnt);
60601 +void gr_handle_chroot_chdir(struct path *path);
60602 +int gr_handle_chroot_chmod(const struct dentry *dentry,
60603 + const struct vfsmount *mnt, const int mode);
60604 +int gr_handle_chroot_mknod(const struct dentry *dentry,
60605 + const struct vfsmount *mnt, const int mode);
60606 +int gr_handle_chroot_mount(const struct dentry *dentry,
60607 + const struct vfsmount *mnt,
60608 + const char *dev_name);
60609 +int gr_handle_chroot_pivot(void);
60610 +int gr_handle_chroot_unix(const pid_t pid);
60611 +
60612 +int gr_handle_rawio(const struct inode *inode);
60613 +
60614 +void gr_handle_ioperm(void);
60615 +void gr_handle_iopl(void);
60616 +
60617 +umode_t gr_acl_umask(void);
60618 +
60619 +int gr_tpe_allow(const struct file *file);
60620 +
60621 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
60622 +void gr_clear_chroot_entries(struct task_struct *task);
60623 +
60624 +void gr_log_forkfail(const int retval);
60625 +void gr_log_timechange(void);
60626 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
60627 +void gr_log_chdir(const struct dentry *dentry,
60628 + const struct vfsmount *mnt);
60629 +void gr_log_chroot_exec(const struct dentry *dentry,
60630 + const struct vfsmount *mnt);
60631 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
60632 +void gr_log_remount(const char *devname, const int retval);
60633 +void gr_log_unmount(const char *devname, const int retval);
60634 +void gr_log_mount(const char *from, const char *to, const int retval);
60635 +void gr_log_textrel(struct vm_area_struct *vma);
60636 +void gr_log_rwxmmap(struct file *file);
60637 +void gr_log_rwxmprotect(struct file *file);
60638 +
60639 +int gr_handle_follow_link(const struct inode *parent,
60640 + const struct inode *inode,
60641 + const struct dentry *dentry,
60642 + const struct vfsmount *mnt);
60643 +int gr_handle_fifo(const struct dentry *dentry,
60644 + const struct vfsmount *mnt,
60645 + const struct dentry *dir, const int flag,
60646 + const int acc_mode);
60647 +int gr_handle_hardlink(const struct dentry *dentry,
60648 + const struct vfsmount *mnt,
60649 + struct inode *inode,
60650 + const int mode, const char *to);
60651 +
60652 +int gr_is_capable(const int cap);
60653 +int gr_is_capable_nolog(const int cap);
60654 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60655 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
60656 +
60657 +void gr_learn_resource(const struct task_struct *task, const int limit,
60658 + const unsigned long wanted, const int gt);
60659 +void gr_copy_label(struct task_struct *tsk);
60660 +void gr_handle_crash(struct task_struct *task, const int sig);
60661 +int gr_handle_signal(const struct task_struct *p, const int sig);
60662 +int gr_check_crash_uid(const uid_t uid);
60663 +int gr_check_protected_task(const struct task_struct *task);
60664 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
60665 +int gr_acl_handle_mmap(const struct file *file,
60666 + const unsigned long prot);
60667 +int gr_acl_handle_mprotect(const struct file *file,
60668 + const unsigned long prot);
60669 +int gr_check_hidden_task(const struct task_struct *tsk);
60670 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
60671 + const struct vfsmount *mnt);
60672 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
60673 + const struct vfsmount *mnt);
60674 +__u32 gr_acl_handle_access(const struct dentry *dentry,
60675 + const struct vfsmount *mnt, const int fmode);
60676 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
60677 + const struct vfsmount *mnt, umode_t *mode);
60678 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
60679 + const struct vfsmount *mnt);
60680 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
60681 + const struct vfsmount *mnt);
60682 +int gr_handle_ptrace(struct task_struct *task, const long request);
60683 +int gr_handle_proc_ptrace(struct task_struct *task);
60684 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
60685 + const struct vfsmount *mnt);
60686 +int gr_check_crash_exec(const struct file *filp);
60687 +int gr_acl_is_enabled(void);
60688 +void gr_set_kernel_label(struct task_struct *task);
60689 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
60690 + const gid_t gid);
60691 +int gr_set_proc_label(const struct dentry *dentry,
60692 + const struct vfsmount *mnt,
60693 + const int unsafe_flags);
60694 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
60695 + const struct vfsmount *mnt);
60696 +__u32 gr_acl_handle_open(const struct dentry *dentry,
60697 + const struct vfsmount *mnt, int acc_mode);
60698 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
60699 + const struct dentry *p_dentry,
60700 + const struct vfsmount *p_mnt,
60701 + int open_flags, int acc_mode, const int imode);
60702 +void gr_handle_create(const struct dentry *dentry,
60703 + const struct vfsmount *mnt);
60704 +void gr_handle_proc_create(const struct dentry *dentry,
60705 + const struct inode *inode);
60706 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
60707 + const struct dentry *parent_dentry,
60708 + const struct vfsmount *parent_mnt,
60709 + const int mode);
60710 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
60711 + const struct dentry *parent_dentry,
60712 + const struct vfsmount *parent_mnt);
60713 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
60714 + const struct vfsmount *mnt);
60715 +void gr_handle_delete(const ino_t ino, const dev_t dev);
60716 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
60717 + const struct vfsmount *mnt);
60718 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
60719 + const struct dentry *parent_dentry,
60720 + const struct vfsmount *parent_mnt,
60721 + const char *from);
60722 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
60723 + const struct dentry *parent_dentry,
60724 + const struct vfsmount *parent_mnt,
60725 + const struct dentry *old_dentry,
60726 + const struct vfsmount *old_mnt, const char *to);
60727 +int gr_acl_handle_rename(struct dentry *new_dentry,
60728 + struct dentry *parent_dentry,
60729 + const struct vfsmount *parent_mnt,
60730 + struct dentry *old_dentry,
60731 + struct inode *old_parent_inode,
60732 + struct vfsmount *old_mnt, const char *newname);
60733 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60734 + struct dentry *old_dentry,
60735 + struct dentry *new_dentry,
60736 + struct vfsmount *mnt, const __u8 replace);
60737 +__u32 gr_check_link(const struct dentry *new_dentry,
60738 + const struct dentry *parent_dentry,
60739 + const struct vfsmount *parent_mnt,
60740 + const struct dentry *old_dentry,
60741 + const struct vfsmount *old_mnt);
60742 +int gr_acl_handle_filldir(const struct file *file, const char *name,
60743 + const unsigned int namelen, const ino_t ino);
60744 +
60745 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
60746 + const struct vfsmount *mnt);
60747 +void gr_acl_handle_exit(void);
60748 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
60749 +int gr_acl_handle_procpidmem(const struct task_struct *task);
60750 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
60751 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
60752 +void gr_audit_ptrace(struct task_struct *task);
60753 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
60754 +
60755 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
60756 +
60757 +#ifdef CONFIG_GRKERNSEC
60758 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
60759 +void gr_handle_vm86(void);
60760 +void gr_handle_mem_readwrite(u64 from, u64 to);
60761 +
60762 +void gr_log_badprocpid(const char *entry);
60763 +
60764 +extern int grsec_enable_dmesg;
60765 +extern int grsec_disable_privio;
60766 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60767 +extern int grsec_enable_chroot_findtask;
60768 +#endif
60769 +#ifdef CONFIG_GRKERNSEC_SETXID
60770 +extern int grsec_enable_setxid;
60771 +#endif
60772 +#endif
60773 +
60774 +#endif
60775 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
60776 new file mode 100644
60777 index 0000000..e7ffaaf
60778 --- /dev/null
60779 +++ b/include/linux/grsock.h
60780 @@ -0,0 +1,19 @@
60781 +#ifndef __GRSOCK_H
60782 +#define __GRSOCK_H
60783 +
60784 +extern void gr_attach_curr_ip(const struct sock *sk);
60785 +extern int gr_handle_sock_all(const int family, const int type,
60786 + const int protocol);
60787 +extern int gr_handle_sock_server(const struct sockaddr *sck);
60788 +extern int gr_handle_sock_server_other(const struct sock *sck);
60789 +extern int gr_handle_sock_client(const struct sockaddr *sck);
60790 +extern int gr_search_connect(struct socket * sock,
60791 + struct sockaddr_in * addr);
60792 +extern int gr_search_bind(struct socket * sock,
60793 + struct sockaddr_in * addr);
60794 +extern int gr_search_listen(struct socket * sock);
60795 +extern int gr_search_accept(struct socket * sock);
60796 +extern int gr_search_socket(const int domain, const int type,
60797 + const int protocol);
60798 +
60799 +#endif
60800 diff --git a/include/linux/hid.h b/include/linux/hid.h
60801 index 3a95da6..51986f1 100644
60802 --- a/include/linux/hid.h
60803 +++ b/include/linux/hid.h
60804 @@ -696,7 +696,7 @@ struct hid_ll_driver {
60805 unsigned int code, int value);
60806
60807 int (*parse)(struct hid_device *hdev);
60808 -};
60809 +} __no_const;
60810
60811 #define PM_HINT_FULLON 1<<5
60812 #define PM_HINT_NORMAL 1<<1
60813 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
60814 index 3a93f73..b19d0b3 100644
60815 --- a/include/linux/highmem.h
60816 +++ b/include/linux/highmem.h
60817 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
60818 kunmap_atomic(kaddr, KM_USER0);
60819 }
60820
60821 +static inline void sanitize_highpage(struct page *page)
60822 +{
60823 + void *kaddr;
60824 + unsigned long flags;
60825 +
60826 + local_irq_save(flags);
60827 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
60828 + clear_page(kaddr);
60829 + kunmap_atomic(kaddr, KM_CLEARPAGE);
60830 + local_irq_restore(flags);
60831 +}
60832 +
60833 static inline void zero_user_segments(struct page *page,
60834 unsigned start1, unsigned end1,
60835 unsigned start2, unsigned end2)
60836 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
60837 index 8e25a91..551b161 100644
60838 --- a/include/linux/i2c.h
60839 +++ b/include/linux/i2c.h
60840 @@ -364,6 +364,7 @@ struct i2c_algorithm {
60841 /* To determine what the adapter supports */
60842 u32 (*functionality) (struct i2c_adapter *);
60843 };
60844 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
60845
60846 /*
60847 * i2c_adapter is the structure used to identify a physical i2c bus along
60848 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
60849 index a6deef4..c56a7f2 100644
60850 --- a/include/linux/i2o.h
60851 +++ b/include/linux/i2o.h
60852 @@ -564,7 +564,7 @@ struct i2o_controller {
60853 struct i2o_device *exec; /* Executive */
60854 #if BITS_PER_LONG == 64
60855 spinlock_t context_list_lock; /* lock for context_list */
60856 - atomic_t context_list_counter; /* needed for unique contexts */
60857 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
60858 struct list_head context_list; /* list of context id's
60859 and pointers */
60860 #endif
60861 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
60862 index 58404b0..439ed95 100644
60863 --- a/include/linux/if_team.h
60864 +++ b/include/linux/if_team.h
60865 @@ -64,6 +64,7 @@ struct team_mode_ops {
60866 void (*port_leave)(struct team *team, struct team_port *port);
60867 void (*port_change_mac)(struct team *team, struct team_port *port);
60868 };
60869 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
60870
60871 enum team_option_type {
60872 TEAM_OPTION_TYPE_U32,
60873 @@ -112,7 +113,7 @@ struct team {
60874 struct list_head option_list;
60875
60876 const struct team_mode *mode;
60877 - struct team_mode_ops ops;
60878 + team_mode_ops_no_const ops;
60879 long mode_priv[TEAM_MODE_PRIV_LONGS];
60880 };
60881
60882 diff --git a/include/linux/init.h b/include/linux/init.h
60883 index 6b95109..4aca62c 100644
60884 --- a/include/linux/init.h
60885 +++ b/include/linux/init.h
60886 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
60887
60888 /* Each module must use one module_init(). */
60889 #define module_init(initfn) \
60890 - static inline initcall_t __inittest(void) \
60891 + static inline __used initcall_t __inittest(void) \
60892 { return initfn; } \
60893 int init_module(void) __attribute__((alias(#initfn)));
60894
60895 /* This is only required if you want to be unloadable. */
60896 #define module_exit(exitfn) \
60897 - static inline exitcall_t __exittest(void) \
60898 + static inline __used exitcall_t __exittest(void) \
60899 { return exitfn; } \
60900 void cleanup_module(void) __attribute__((alias(#exitfn)));
60901
60902 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
60903 index 9c66b1a..a3fdded 100644
60904 --- a/include/linux/init_task.h
60905 +++ b/include/linux/init_task.h
60906 @@ -127,6 +127,12 @@ extern struct cred init_cred;
60907
60908 #define INIT_TASK_COMM "swapper"
60909
60910 +#ifdef CONFIG_X86
60911 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
60912 +#else
60913 +#define INIT_TASK_THREAD_INFO
60914 +#endif
60915 +
60916 /*
60917 * INIT_TASK is used to set up the first task table, touch at
60918 * your own risk!. Base=0, limit=0x1fffff (=2MB)
60919 @@ -165,6 +171,7 @@ extern struct cred init_cred;
60920 RCU_INIT_POINTER(.cred, &init_cred), \
60921 .comm = INIT_TASK_COMM, \
60922 .thread = INIT_THREAD, \
60923 + INIT_TASK_THREAD_INFO \
60924 .fs = &init_fs, \
60925 .files = &init_files, \
60926 .signal = &init_signals, \
60927 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
60928 index e6ca56d..8583707 100644
60929 --- a/include/linux/intel-iommu.h
60930 +++ b/include/linux/intel-iommu.h
60931 @@ -296,7 +296,7 @@ struct iommu_flush {
60932 u8 fm, u64 type);
60933 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
60934 unsigned int size_order, u64 type);
60935 -};
60936 +} __no_const;
60937
60938 enum {
60939 SR_DMAR_FECTL_REG,
60940 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
60941 index a64b00e..464d8bc 100644
60942 --- a/include/linux/interrupt.h
60943 +++ b/include/linux/interrupt.h
60944 @@ -441,7 +441,7 @@ enum
60945 /* map softirq index to softirq name. update 'softirq_to_name' in
60946 * kernel/softirq.c when adding a new softirq.
60947 */
60948 -extern char *softirq_to_name[NR_SOFTIRQS];
60949 +extern const char * const softirq_to_name[NR_SOFTIRQS];
60950
60951 /* softirq mask and active fields moved to irq_cpustat_t in
60952 * asm/hardirq.h to get better cache usage. KAO
60953 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
60954
60955 struct softirq_action
60956 {
60957 - void (*action)(struct softirq_action *);
60958 + void (*action)(void);
60959 };
60960
60961 asmlinkage void do_softirq(void);
60962 asmlinkage void __do_softirq(void);
60963 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
60964 +extern void open_softirq(int nr, void (*action)(void));
60965 extern void softirq_init(void);
60966 static inline void __raise_softirq_irqoff(unsigned int nr)
60967 {
60968 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
60969 index 3875719..4cd454c 100644
60970 --- a/include/linux/kallsyms.h
60971 +++ b/include/linux/kallsyms.h
60972 @@ -15,7 +15,8 @@
60973
60974 struct module;
60975
60976 -#ifdef CONFIG_KALLSYMS
60977 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
60978 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60979 /* Lookup the address for a symbol. Returns 0 if not found. */
60980 unsigned long kallsyms_lookup_name(const char *name);
60981
60982 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
60983 /* Stupid that this does nothing, but I didn't create this mess. */
60984 #define __print_symbol(fmt, addr)
60985 #endif /*CONFIG_KALLSYMS*/
60986 +#else /* when included by kallsyms.c, vsnprintf.c, or
60987 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
60988 +extern void __print_symbol(const char *fmt, unsigned long address);
60989 +extern int sprint_backtrace(char *buffer, unsigned long address);
60990 +extern int sprint_symbol(char *buffer, unsigned long address);
60991 +const char *kallsyms_lookup(unsigned long addr,
60992 + unsigned long *symbolsize,
60993 + unsigned long *offset,
60994 + char **modname, char *namebuf);
60995 +#endif
60996
60997 /* This macro allows us to keep printk typechecking */
60998 static __printf(1, 2)
60999 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
61000 index fa39183..40160be 100644
61001 --- a/include/linux/kgdb.h
61002 +++ b/include/linux/kgdb.h
61003 @@ -53,7 +53,7 @@ extern int kgdb_connected;
61004 extern int kgdb_io_module_registered;
61005
61006 extern atomic_t kgdb_setting_breakpoint;
61007 -extern atomic_t kgdb_cpu_doing_single_step;
61008 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
61009
61010 extern struct task_struct *kgdb_usethread;
61011 extern struct task_struct *kgdb_contthread;
61012 @@ -251,7 +251,7 @@ struct kgdb_arch {
61013 void (*disable_hw_break)(struct pt_regs *regs);
61014 void (*remove_all_hw_break)(void);
61015 void (*correct_hw_break)(void);
61016 -};
61017 +} __do_const;
61018
61019 /**
61020 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
61021 @@ -276,7 +276,7 @@ struct kgdb_io {
61022 void (*pre_exception) (void);
61023 void (*post_exception) (void);
61024 int is_console;
61025 -};
61026 +} __do_const;
61027
61028 extern struct kgdb_arch arch_kgdb_ops;
61029
61030 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
61031 index 722f477..eef2a27 100644
61032 --- a/include/linux/kmod.h
61033 +++ b/include/linux/kmod.h
61034 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
61035 * usually useless though. */
61036 extern __printf(2, 3)
61037 int __request_module(bool wait, const char *name, ...);
61038 +extern __printf(3, 4)
61039 +int ___request_module(bool wait, char *param_name, const char *name, ...);
61040 #define request_module(mod...) __request_module(true, mod)
61041 #define request_module_nowait(mod...) __request_module(false, mod)
61042 #define try_then_request_module(x, mod...) \
61043 diff --git a/include/linux/kref.h b/include/linux/kref.h
61044 index 9c07dce..a92fa71 100644
61045 --- a/include/linux/kref.h
61046 +++ b/include/linux/kref.h
61047 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
61048 static inline int kref_sub(struct kref *kref, unsigned int count,
61049 void (*release)(struct kref *kref))
61050 {
61051 - WARN_ON(release == NULL);
61052 + BUG_ON(release == NULL);
61053
61054 if (atomic_sub_and_test((int) count, &kref->refcount)) {
61055 release(kref);
61056 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
61057 index 900c763..43260cf 100644
61058 --- a/include/linux/kvm_host.h
61059 +++ b/include/linux/kvm_host.h
61060 @@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
61061 void vcpu_load(struct kvm_vcpu *vcpu);
61062 void vcpu_put(struct kvm_vcpu *vcpu);
61063
61064 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61065 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61066 struct module *module);
61067 void kvm_exit(void);
61068
61069 @@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
61070 struct kvm_guest_debug *dbg);
61071 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
61072
61073 -int kvm_arch_init(void *opaque);
61074 +int kvm_arch_init(const void *opaque);
61075 void kvm_arch_exit(void);
61076
61077 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
61078 diff --git a/include/linux/libata.h b/include/linux/libata.h
61079 index cafc09a..d7e7829 100644
61080 --- a/include/linux/libata.h
61081 +++ b/include/linux/libata.h
61082 @@ -909,7 +909,7 @@ struct ata_port_operations {
61083 * fields must be pointers.
61084 */
61085 const struct ata_port_operations *inherits;
61086 -};
61087 +} __do_const;
61088
61089 struct ata_port_info {
61090 unsigned long flags;
61091 diff --git a/include/linux/mca.h b/include/linux/mca.h
61092 index 3797270..7765ede 100644
61093 --- a/include/linux/mca.h
61094 +++ b/include/linux/mca.h
61095 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
61096 int region);
61097 void * (*mca_transform_memory)(struct mca_device *,
61098 void *memory);
61099 -};
61100 +} __no_const;
61101
61102 struct mca_bus {
61103 u64 default_dma_mask;
61104 diff --git a/include/linux/memory.h b/include/linux/memory.h
61105 index 1ac7f6e..a5794d0 100644
61106 --- a/include/linux/memory.h
61107 +++ b/include/linux/memory.h
61108 @@ -143,7 +143,7 @@ struct memory_accessor {
61109 size_t count);
61110 ssize_t (*write)(struct memory_accessor *, const char *buf,
61111 off_t offset, size_t count);
61112 -};
61113 +} __no_const;
61114
61115 /*
61116 * Kernel text modification mutex, used for code patching. Users of this lock
61117 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
61118 index 9970337..9444122 100644
61119 --- a/include/linux/mfd/abx500.h
61120 +++ b/include/linux/mfd/abx500.h
61121 @@ -188,6 +188,7 @@ struct abx500_ops {
61122 int (*event_registers_startup_state_get) (struct device *, u8 *);
61123 int (*startup_irq_enabled) (struct device *, unsigned int);
61124 };
61125 +typedef struct abx500_ops __no_const abx500_ops_no_const;
61126
61127 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
61128 void abx500_remove_ops(struct device *dev);
61129 diff --git a/include/linux/mm.h b/include/linux/mm.h
61130 index 17b27cd..467ba2f 100644
61131 --- a/include/linux/mm.h
61132 +++ b/include/linux/mm.h
61133 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
61134
61135 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
61136 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
61137 +
61138 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
61139 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
61140 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
61141 +#else
61142 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
61143 +#endif
61144 +
61145 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
61146 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
61147
61148 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
61149 int set_page_dirty_lock(struct page *page);
61150 int clear_page_dirty_for_io(struct page *page);
61151
61152 -/* Is the vma a continuation of the stack vma above it? */
61153 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
61154 -{
61155 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
61156 -}
61157 -
61158 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
61159 - unsigned long addr)
61160 -{
61161 - return (vma->vm_flags & VM_GROWSDOWN) &&
61162 - (vma->vm_start == addr) &&
61163 - !vma_growsdown(vma->vm_prev, addr);
61164 -}
61165 -
61166 -/* Is the vma a continuation of the stack vma below it? */
61167 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
61168 -{
61169 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
61170 -}
61171 -
61172 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
61173 - unsigned long addr)
61174 -{
61175 - return (vma->vm_flags & VM_GROWSUP) &&
61176 - (vma->vm_end == addr) &&
61177 - !vma_growsup(vma->vm_next, addr);
61178 -}
61179 -
61180 extern unsigned long move_page_tables(struct vm_area_struct *vma,
61181 unsigned long old_addr, struct vm_area_struct *new_vma,
61182 unsigned long new_addr, unsigned long len);
61183 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
61184 }
61185 #endif
61186
61187 +#ifdef CONFIG_MMU
61188 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
61189 +#else
61190 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
61191 +{
61192 + return __pgprot(0);
61193 +}
61194 +#endif
61195 +
61196 int vma_wants_writenotify(struct vm_area_struct *vma);
61197
61198 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
61199 @@ -1409,6 +1397,7 @@ out:
61200 }
61201
61202 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
61203 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
61204
61205 extern unsigned long do_brk(unsigned long, unsigned long);
61206
61207 @@ -1466,6 +1455,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
61208 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
61209 struct vm_area_struct **pprev);
61210
61211 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
61212 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
61213 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
61214 +
61215 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
61216 NULL if none. Assume start_addr < end_addr. */
61217 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
61218 @@ -1494,15 +1487,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
61219 return vma;
61220 }
61221
61222 -#ifdef CONFIG_MMU
61223 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
61224 -#else
61225 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
61226 -{
61227 - return __pgprot(0);
61228 -}
61229 -#endif
61230 -
61231 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
61232 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
61233 unsigned long pfn, unsigned long size, pgprot_t);
61234 @@ -1606,7 +1590,7 @@ extern int unpoison_memory(unsigned long pfn);
61235 extern int sysctl_memory_failure_early_kill;
61236 extern int sysctl_memory_failure_recovery;
61237 extern void shake_page(struct page *p, int access);
61238 -extern atomic_long_t mce_bad_pages;
61239 +extern atomic_long_unchecked_t mce_bad_pages;
61240 extern int soft_offline_page(struct page *page, int flags);
61241
61242 extern void dump_page(struct page *page);
61243 @@ -1637,5 +1621,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
61244 static inline bool page_is_guard(struct page *page) { return false; }
61245 #endif /* CONFIG_DEBUG_PAGEALLOC */
61246
61247 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61248 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
61249 +#else
61250 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
61251 +#endif
61252 +
61253 #endif /* __KERNEL__ */
61254 #endif /* _LINUX_MM_H */
61255 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
61256 index 3cc3062..8947a82 100644
61257 --- a/include/linux/mm_types.h
61258 +++ b/include/linux/mm_types.h
61259 @@ -252,6 +252,8 @@ struct vm_area_struct {
61260 #ifdef CONFIG_NUMA
61261 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
61262 #endif
61263 +
61264 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
61265 };
61266
61267 struct core_thread {
61268 @@ -388,6 +390,24 @@ struct mm_struct {
61269 #ifdef CONFIG_CPUMASK_OFFSTACK
61270 struct cpumask cpumask_allocation;
61271 #endif
61272 +
61273 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61274 + unsigned long pax_flags;
61275 +#endif
61276 +
61277 +#ifdef CONFIG_PAX_DLRESOLVE
61278 + unsigned long call_dl_resolve;
61279 +#endif
61280 +
61281 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
61282 + unsigned long call_syscall;
61283 +#endif
61284 +
61285 +#ifdef CONFIG_PAX_ASLR
61286 + unsigned long delta_mmap; /* randomized offset */
61287 + unsigned long delta_stack; /* randomized offset */
61288 +#endif
61289 +
61290 };
61291
61292 static inline void mm_init_cpumask(struct mm_struct *mm)
61293 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
61294 index 1d1b1e1..2a13c78 100644
61295 --- a/include/linux/mmu_notifier.h
61296 +++ b/include/linux/mmu_notifier.h
61297 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
61298 */
61299 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
61300 ({ \
61301 - pte_t __pte; \
61302 + pte_t ___pte; \
61303 struct vm_area_struct *___vma = __vma; \
61304 unsigned long ___address = __address; \
61305 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
61306 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
61307 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
61308 - __pte; \
61309 + ___pte; \
61310 })
61311
61312 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
61313 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
61314 index 650ba2f..af0a58c 100644
61315 --- a/include/linux/mmzone.h
61316 +++ b/include/linux/mmzone.h
61317 @@ -379,7 +379,7 @@ struct zone {
61318 unsigned long flags; /* zone flags, see below */
61319
61320 /* Zone statistics */
61321 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61322 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61323
61324 /*
61325 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
61326 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
61327 index 83ac071..2656e0e 100644
61328 --- a/include/linux/mod_devicetable.h
61329 +++ b/include/linux/mod_devicetable.h
61330 @@ -12,7 +12,7 @@
61331 typedef unsigned long kernel_ulong_t;
61332 #endif
61333
61334 -#define PCI_ANY_ID (~0)
61335 +#define PCI_ANY_ID ((__u16)~0)
61336
61337 struct pci_device_id {
61338 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
61339 @@ -131,7 +131,7 @@ struct usb_device_id {
61340 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
61341 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
61342
61343 -#define HID_ANY_ID (~0)
61344 +#define HID_ANY_ID (~0U)
61345
61346 struct hid_device_id {
61347 __u16 bus;
61348 diff --git a/include/linux/module.h b/include/linux/module.h
61349 index 4598bf0..e069d7f 100644
61350 --- a/include/linux/module.h
61351 +++ b/include/linux/module.h
61352 @@ -17,6 +17,7 @@
61353 #include <linux/moduleparam.h>
61354 #include <linux/tracepoint.h>
61355 #include <linux/export.h>
61356 +#include <linux/fs.h>
61357
61358 #include <linux/percpu.h>
61359 #include <asm/module.h>
61360 @@ -275,19 +276,16 @@ struct module
61361 int (*init)(void);
61362
61363 /* If this is non-NULL, vfree after init() returns */
61364 - void *module_init;
61365 + void *module_init_rx, *module_init_rw;
61366
61367 /* Here is the actual code + data, vfree'd on unload. */
61368 - void *module_core;
61369 + void *module_core_rx, *module_core_rw;
61370
61371 /* Here are the sizes of the init and core sections */
61372 - unsigned int init_size, core_size;
61373 + unsigned int init_size_rw, core_size_rw;
61374
61375 /* The size of the executable code in each section. */
61376 - unsigned int init_text_size, core_text_size;
61377 -
61378 - /* Size of RO sections of the module (text+rodata) */
61379 - unsigned int init_ro_size, core_ro_size;
61380 + unsigned int init_size_rx, core_size_rx;
61381
61382 /* Arch-specific module values */
61383 struct mod_arch_specific arch;
61384 @@ -343,6 +341,10 @@ struct module
61385 #ifdef CONFIG_EVENT_TRACING
61386 struct ftrace_event_call **trace_events;
61387 unsigned int num_trace_events;
61388 + struct file_operations trace_id;
61389 + struct file_operations trace_enable;
61390 + struct file_operations trace_format;
61391 + struct file_operations trace_filter;
61392 #endif
61393 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
61394 unsigned int num_ftrace_callsites;
61395 @@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
61396 bool is_module_percpu_address(unsigned long addr);
61397 bool is_module_text_address(unsigned long addr);
61398
61399 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
61400 +{
61401 +
61402 +#ifdef CONFIG_PAX_KERNEXEC
61403 + if (ktla_ktva(addr) >= (unsigned long)start &&
61404 + ktla_ktva(addr) < (unsigned long)start + size)
61405 + return 1;
61406 +#endif
61407 +
61408 + return ((void *)addr >= start && (void *)addr < start + size);
61409 +}
61410 +
61411 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
61412 +{
61413 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
61414 +}
61415 +
61416 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
61417 +{
61418 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
61419 +}
61420 +
61421 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
61422 +{
61423 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
61424 +}
61425 +
61426 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
61427 +{
61428 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
61429 +}
61430 +
61431 static inline int within_module_core(unsigned long addr, struct module *mod)
61432 {
61433 - return (unsigned long)mod->module_core <= addr &&
61434 - addr < (unsigned long)mod->module_core + mod->core_size;
61435 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
61436 }
61437
61438 static inline int within_module_init(unsigned long addr, struct module *mod)
61439 {
61440 - return (unsigned long)mod->module_init <= addr &&
61441 - addr < (unsigned long)mod->module_init + mod->init_size;
61442 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
61443 }
61444
61445 /* Search for module by name: must hold module_mutex. */
61446 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
61447 index b2be02e..6a9fdb1 100644
61448 --- a/include/linux/moduleloader.h
61449 +++ b/include/linux/moduleloader.h
61450 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
61451 sections. Returns NULL on failure. */
61452 void *module_alloc(unsigned long size);
61453
61454 +#ifdef CONFIG_PAX_KERNEXEC
61455 +void *module_alloc_exec(unsigned long size);
61456 +#else
61457 +#define module_alloc_exec(x) module_alloc(x)
61458 +#endif
61459 +
61460 /* Free memory returned from module_alloc. */
61461 void module_free(struct module *mod, void *module_region);
61462
61463 +#ifdef CONFIG_PAX_KERNEXEC
61464 +void module_free_exec(struct module *mod, void *module_region);
61465 +#else
61466 +#define module_free_exec(x, y) module_free((x), (y))
61467 +#endif
61468 +
61469 /* Apply the given relocation to the (simplified) ELF. Return -error
61470 or 0. */
61471 int apply_relocate(Elf_Shdr *sechdrs,
61472 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
61473 index c47f4d6..23f9bdb 100644
61474 --- a/include/linux/moduleparam.h
61475 +++ b/include/linux/moduleparam.h
61476 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
61477 * @len is usually just sizeof(string).
61478 */
61479 #define module_param_string(name, string, len, perm) \
61480 - static const struct kparam_string __param_string_##name \
61481 + static const struct kparam_string __param_string_##name __used \
61482 = { len, string }; \
61483 __module_param_call(MODULE_PARAM_PREFIX, name, \
61484 &param_ops_string, \
61485 @@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
61486 */
61487 #define module_param_array_named(name, array, type, nump, perm) \
61488 param_check_##type(name, &(array)[0]); \
61489 - static const struct kparam_array __param_arr_##name \
61490 + static const struct kparam_array __param_arr_##name __used \
61491 = { .max = ARRAY_SIZE(array), .num = nump, \
61492 .ops = &param_ops_##type, \
61493 .elemsize = sizeof(array[0]), .elem = array }; \
61494 diff --git a/include/linux/namei.h b/include/linux/namei.h
61495 index ffc0213..2c1f2cb 100644
61496 --- a/include/linux/namei.h
61497 +++ b/include/linux/namei.h
61498 @@ -24,7 +24,7 @@ struct nameidata {
61499 unsigned seq;
61500 int last_type;
61501 unsigned depth;
61502 - char *saved_names[MAX_NESTED_LINKS + 1];
61503 + const char *saved_names[MAX_NESTED_LINKS + 1];
61504
61505 /* Intent data */
61506 union {
61507 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
61508 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
61509 extern void unlock_rename(struct dentry *, struct dentry *);
61510
61511 -static inline void nd_set_link(struct nameidata *nd, char *path)
61512 +static inline void nd_set_link(struct nameidata *nd, const char *path)
61513 {
61514 nd->saved_names[nd->depth] = path;
61515 }
61516
61517 -static inline char *nd_get_link(struct nameidata *nd)
61518 +static inline const char *nd_get_link(const struct nameidata *nd)
61519 {
61520 return nd->saved_names[nd->depth];
61521 }
61522 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
61523 index 0eac07c..a59f6a8 100644
61524 --- a/include/linux/netdevice.h
61525 +++ b/include/linux/netdevice.h
61526 @@ -1002,6 +1002,7 @@ struct net_device_ops {
61527 int (*ndo_neigh_construct)(struct neighbour *n);
61528 void (*ndo_neigh_destroy)(struct neighbour *n);
61529 };
61530 +typedef struct net_device_ops __no_const net_device_ops_no_const;
61531
61532 /*
61533 * The DEVICE structure.
61534 @@ -1063,7 +1064,7 @@ struct net_device {
61535 int iflink;
61536
61537 struct net_device_stats stats;
61538 - atomic_long_t rx_dropped; /* dropped packets by core network
61539 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
61540 * Do not use this in drivers.
61541 */
61542
61543 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
61544 new file mode 100644
61545 index 0000000..33f4af8
61546 --- /dev/null
61547 +++ b/include/linux/netfilter/xt_gradm.h
61548 @@ -0,0 +1,9 @@
61549 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
61550 +#define _LINUX_NETFILTER_XT_GRADM_H 1
61551 +
61552 +struct xt_gradm_mtinfo {
61553 + __u16 flags;
61554 + __u16 invflags;
61555 +};
61556 +
61557 +#endif
61558 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
61559 index c65a18a..0c05f3a 100644
61560 --- a/include/linux/of_pdt.h
61561 +++ b/include/linux/of_pdt.h
61562 @@ -32,7 +32,7 @@ struct of_pdt_ops {
61563
61564 /* return 0 on success; fill in 'len' with number of bytes in path */
61565 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
61566 -};
61567 +} __no_const;
61568
61569 extern void *prom_early_alloc(unsigned long size);
61570
61571 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
61572 index a4c5624..79d6d88 100644
61573 --- a/include/linux/oprofile.h
61574 +++ b/include/linux/oprofile.h
61575 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
61576 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
61577 char const * name, ulong * val);
61578
61579 -/** Create a file for read-only access to an atomic_t. */
61580 +/** Create a file for read-only access to an atomic_unchecked_t. */
61581 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
61582 - char const * name, atomic_t * val);
61583 + char const * name, atomic_unchecked_t * val);
61584
61585 /** create a directory */
61586 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
61587 diff --git a/include/linux/padata.h b/include/linux/padata.h
61588 index 4633b2f..988bc08 100644
61589 --- a/include/linux/padata.h
61590 +++ b/include/linux/padata.h
61591 @@ -129,7 +129,7 @@ struct parallel_data {
61592 struct padata_instance *pinst;
61593 struct padata_parallel_queue __percpu *pqueue;
61594 struct padata_serial_queue __percpu *squeue;
61595 - atomic_t seq_nr;
61596 + atomic_unchecked_t seq_nr;
61597 atomic_t reorder_objects;
61598 atomic_t refcnt;
61599 unsigned int max_seq_nr;
61600 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
61601 index abb2776..d8b8e15 100644
61602 --- a/include/linux/perf_event.h
61603 +++ b/include/linux/perf_event.h
61604 @@ -750,8 +750,8 @@ struct perf_event {
61605
61606 enum perf_event_active_state state;
61607 unsigned int attach_state;
61608 - local64_t count;
61609 - atomic64_t child_count;
61610 + local64_t count; /* PaX: fix it one day */
61611 + atomic64_unchecked_t child_count;
61612
61613 /*
61614 * These are the total time in nanoseconds that the event
61615 @@ -802,8 +802,8 @@ struct perf_event {
61616 * These accumulate total time (in nanoseconds) that children
61617 * events have been enabled and running, respectively.
61618 */
61619 - atomic64_t child_total_time_enabled;
61620 - atomic64_t child_total_time_running;
61621 + atomic64_unchecked_t child_total_time_enabled;
61622 + atomic64_unchecked_t child_total_time_running;
61623
61624 /*
61625 * Protect attach/detach and child_list:
61626 diff --git a/include/linux/personality.h b/include/linux/personality.h
61627 index 8fc7dd1a..c19d89e 100644
61628 --- a/include/linux/personality.h
61629 +++ b/include/linux/personality.h
61630 @@ -44,6 +44,7 @@ enum {
61631 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
61632 ADDR_NO_RANDOMIZE | \
61633 ADDR_COMPAT_LAYOUT | \
61634 + ADDR_LIMIT_3GB | \
61635 MMAP_PAGE_ZERO)
61636
61637 /*
61638 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
61639 index 77257c9..51d473a 100644
61640 --- a/include/linux/pipe_fs_i.h
61641 +++ b/include/linux/pipe_fs_i.h
61642 @@ -46,9 +46,9 @@ struct pipe_buffer {
61643 struct pipe_inode_info {
61644 wait_queue_head_t wait;
61645 unsigned int nrbufs, curbuf, buffers;
61646 - unsigned int readers;
61647 - unsigned int writers;
61648 - unsigned int waiting_writers;
61649 + atomic_t readers;
61650 + atomic_t writers;
61651 + atomic_t waiting_writers;
61652 unsigned int r_counter;
61653 unsigned int w_counter;
61654 struct page *tmp_page;
61655 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
61656 index 609daae..5392427 100644
61657 --- a/include/linux/pm_runtime.h
61658 +++ b/include/linux/pm_runtime.h
61659 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
61660
61661 static inline void pm_runtime_mark_last_busy(struct device *dev)
61662 {
61663 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
61664 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
61665 }
61666
61667 #else /* !CONFIG_PM_RUNTIME */
61668 diff --git a/include/linux/poison.h b/include/linux/poison.h
61669 index 2110a81..13a11bb 100644
61670 --- a/include/linux/poison.h
61671 +++ b/include/linux/poison.h
61672 @@ -19,8 +19,8 @@
61673 * under normal circumstances, used to verify that nobody uses
61674 * non-initialized list entries.
61675 */
61676 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
61677 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
61678 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
61679 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
61680
61681 /********** include/linux/timer.h **********/
61682 /*
61683 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
61684 index 58969b2..ead129b 100644
61685 --- a/include/linux/preempt.h
61686 +++ b/include/linux/preempt.h
61687 @@ -123,7 +123,7 @@ struct preempt_ops {
61688 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
61689 void (*sched_out)(struct preempt_notifier *notifier,
61690 struct task_struct *next);
61691 -};
61692 +} __no_const;
61693
61694 /**
61695 * preempt_notifier - key for installing preemption notifiers
61696 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
61697 index 85c5073..51fac8b 100644
61698 --- a/include/linux/proc_fs.h
61699 +++ b/include/linux/proc_fs.h
61700 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
61701 return proc_create_data(name, mode, parent, proc_fops, NULL);
61702 }
61703
61704 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
61705 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
61706 +{
61707 +#ifdef CONFIG_GRKERNSEC_PROC_USER
61708 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
61709 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61710 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
61711 +#else
61712 + return proc_create_data(name, mode, parent, proc_fops, NULL);
61713 +#endif
61714 +}
61715 +
61716 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
61717 umode_t mode, struct proc_dir_entry *base,
61718 read_proc_t *read_proc, void * data)
61719 @@ -258,7 +270,7 @@ union proc_op {
61720 int (*proc_show)(struct seq_file *m,
61721 struct pid_namespace *ns, struct pid *pid,
61722 struct task_struct *task);
61723 -};
61724 +} __no_const;
61725
61726 struct ctl_table_header;
61727 struct ctl_table;
61728 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
61729 index c2f1f6a..6fdb196 100644
61730 --- a/include/linux/ptrace.h
61731 +++ b/include/linux/ptrace.h
61732 @@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
61733 if (unlikely(ptrace_event_enabled(current, event))) {
61734 current->ptrace_message = message;
61735 ptrace_notify((event << 8) | SIGTRAP);
61736 - } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
61737 + } else if (event == PTRACE_EVENT_EXEC) {
61738 /* legacy EXEC report via SIGTRAP */
61739 - send_sig(SIGTRAP, current, 0);
61740 + if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
61741 + send_sig(SIGTRAP, current, 0);
61742 }
61743 }
61744
61745 diff --git a/include/linux/random.h b/include/linux/random.h
61746 index 8f74538..02a1012 100644
61747 --- a/include/linux/random.h
61748 +++ b/include/linux/random.h
61749 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
61750
61751 u32 prandom32(struct rnd_state *);
61752
61753 +static inline unsigned long pax_get_random_long(void)
61754 +{
61755 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
61756 +}
61757 +
61758 /*
61759 * Handle minimum values for seeds
61760 */
61761 static inline u32 __seed(u32 x, u32 m)
61762 {
61763 - return (x < m) ? x + m : x;
61764 + return (x <= m) ? x + m + 1 : x;
61765 }
61766
61767 /**
61768 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
61769 index e0879a7..a12f962 100644
61770 --- a/include/linux/reboot.h
61771 +++ b/include/linux/reboot.h
61772 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
61773 * Architecture-specific implementations of sys_reboot commands.
61774 */
61775
61776 -extern void machine_restart(char *cmd);
61777 -extern void machine_halt(void);
61778 -extern void machine_power_off(void);
61779 +extern void machine_restart(char *cmd) __noreturn;
61780 +extern void machine_halt(void) __noreturn;
61781 +extern void machine_power_off(void) __noreturn;
61782
61783 extern void machine_shutdown(void);
61784 struct pt_regs;
61785 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
61786 */
61787
61788 extern void kernel_restart_prepare(char *cmd);
61789 -extern void kernel_restart(char *cmd);
61790 -extern void kernel_halt(void);
61791 -extern void kernel_power_off(void);
61792 +extern void kernel_restart(char *cmd) __noreturn;
61793 +extern void kernel_halt(void) __noreturn;
61794 +extern void kernel_power_off(void) __noreturn;
61795
61796 extern int C_A_D; /* for sysctl */
61797 void ctrl_alt_del(void);
61798 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
61799 * Emergency restart, callable from an interrupt handler.
61800 */
61801
61802 -extern void emergency_restart(void);
61803 +extern void emergency_restart(void) __noreturn;
61804 #include <asm/emergency-restart.h>
61805
61806 #endif
61807 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
61808 index 2213ddc..650212a 100644
61809 --- a/include/linux/reiserfs_fs.h
61810 +++ b/include/linux/reiserfs_fs.h
61811 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
61812 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
61813
61814 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
61815 -#define get_generation(s) atomic_read (&fs_generation(s))
61816 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
61817 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
61818 #define __fs_changed(gen,s) (gen != get_generation (s))
61819 #define fs_changed(gen,s) \
61820 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
61821 index 8c9e85c..1698e9a 100644
61822 --- a/include/linux/reiserfs_fs_sb.h
61823 +++ b/include/linux/reiserfs_fs_sb.h
61824 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
61825 /* Comment? -Hans */
61826 wait_queue_head_t s_wait;
61827 /* To be obsoleted soon by per buffer seals.. -Hans */
61828 - atomic_t s_generation_counter; // increased by one every time the
61829 + atomic_unchecked_t s_generation_counter; // increased by one every time the
61830 // tree gets re-balanced
61831 unsigned long s_properties; /* File system properties. Currently holds
61832 on-disk FS format */
61833 diff --git a/include/linux/relay.h b/include/linux/relay.h
61834 index a822fd7..62b70f6 100644
61835 --- a/include/linux/relay.h
61836 +++ b/include/linux/relay.h
61837 @@ -159,7 +159,7 @@ struct rchan_callbacks
61838 * The callback should return 0 if successful, negative if not.
61839 */
61840 int (*remove_buf_file)(struct dentry *dentry);
61841 -};
61842 +} __no_const;
61843
61844 /*
61845 * CONFIG_RELAY kernel API, kernel/relay.c
61846 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
61847 index c6c6084..5bf1212 100644
61848 --- a/include/linux/rfkill.h
61849 +++ b/include/linux/rfkill.h
61850 @@ -147,6 +147,7 @@ struct rfkill_ops {
61851 void (*query)(struct rfkill *rfkill, void *data);
61852 int (*set_block)(void *data, bool blocked);
61853 };
61854 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
61855
61856 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
61857 /**
61858 diff --git a/include/linux/rio.h b/include/linux/rio.h
61859 index 4d50611..c6858a2 100644
61860 --- a/include/linux/rio.h
61861 +++ b/include/linux/rio.h
61862 @@ -315,7 +315,7 @@ struct rio_ops {
61863 int mbox, void *buffer, size_t len);
61864 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
61865 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
61866 -};
61867 +} __no_const;
61868
61869 #define RIO_RESOURCE_MEM 0x00000100
61870 #define RIO_RESOURCE_DOORBELL 0x00000200
61871 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
61872 index 1cdd62a..e399f0d 100644
61873 --- a/include/linux/rmap.h
61874 +++ b/include/linux/rmap.h
61875 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
61876 void anon_vma_init(void); /* create anon_vma_cachep */
61877 int anon_vma_prepare(struct vm_area_struct *);
61878 void unlink_anon_vmas(struct vm_area_struct *);
61879 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
61880 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
61881 void anon_vma_moveto_tail(struct vm_area_struct *);
61882 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
61883 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
61884 void __anon_vma_link(struct vm_area_struct *);
61885
61886 static inline void anon_vma_merge(struct vm_area_struct *vma,
61887 diff --git a/include/linux/sched.h b/include/linux/sched.h
61888 index 0657368..765f70f 100644
61889 --- a/include/linux/sched.h
61890 +++ b/include/linux/sched.h
61891 @@ -101,6 +101,7 @@ struct bio_list;
61892 struct fs_struct;
61893 struct perf_event_context;
61894 struct blk_plug;
61895 +struct linux_binprm;
61896
61897 /*
61898 * List of flags we want to share for kernel threads,
61899 @@ -382,10 +383,13 @@ struct user_namespace;
61900 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
61901
61902 extern int sysctl_max_map_count;
61903 +extern unsigned long sysctl_heap_stack_gap;
61904
61905 #include <linux/aio.h>
61906
61907 #ifdef CONFIG_MMU
61908 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
61909 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
61910 extern void arch_pick_mmap_layout(struct mm_struct *mm);
61911 extern unsigned long
61912 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
61913 @@ -631,6 +635,17 @@ struct signal_struct {
61914 #ifdef CONFIG_TASKSTATS
61915 struct taskstats *stats;
61916 #endif
61917 +
61918 +#ifdef CONFIG_GRKERNSEC
61919 + u32 curr_ip;
61920 + u32 saved_ip;
61921 + u32 gr_saddr;
61922 + u32 gr_daddr;
61923 + u16 gr_sport;
61924 + u16 gr_dport;
61925 + u8 used_accept:1;
61926 +#endif
61927 +
61928 #ifdef CONFIG_AUDIT
61929 unsigned audit_tty;
61930 struct tty_audit_buf *tty_audit_buf;
61931 @@ -714,6 +729,11 @@ struct user_struct {
61932 struct key *session_keyring; /* UID's default session keyring */
61933 #endif
61934
61935 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61936 + unsigned int banned;
61937 + unsigned long ban_expires;
61938 +#endif
61939 +
61940 /* Hash table maintenance information */
61941 struct hlist_node uidhash_node;
61942 uid_t uid;
61943 @@ -1354,8 +1374,8 @@ struct task_struct {
61944 struct list_head thread_group;
61945
61946 struct completion *vfork_done; /* for vfork() */
61947 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
61948 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
61949 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
61950 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
61951
61952 cputime_t utime, stime, utimescaled, stimescaled;
61953 cputime_t gtime;
61954 @@ -1371,13 +1391,6 @@ struct task_struct {
61955 struct task_cputime cputime_expires;
61956 struct list_head cpu_timers[3];
61957
61958 -/* process credentials */
61959 - const struct cred __rcu *real_cred; /* objective and real subjective task
61960 - * credentials (COW) */
61961 - const struct cred __rcu *cred; /* effective (overridable) subjective task
61962 - * credentials (COW) */
61963 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
61964 -
61965 char comm[TASK_COMM_LEN]; /* executable name excluding path
61966 - access with [gs]et_task_comm (which lock
61967 it with task_lock())
61968 @@ -1394,8 +1407,16 @@ struct task_struct {
61969 #endif
61970 /* CPU-specific state of this task */
61971 struct thread_struct thread;
61972 +/* thread_info moved to task_struct */
61973 +#ifdef CONFIG_X86
61974 + struct thread_info tinfo;
61975 +#endif
61976 /* filesystem information */
61977 struct fs_struct *fs;
61978 +
61979 + const struct cred __rcu *cred; /* effective (overridable) subjective task
61980 + * credentials (COW) */
61981 +
61982 /* open file information */
61983 struct files_struct *files;
61984 /* namespaces */
61985 @@ -1442,6 +1463,11 @@ struct task_struct {
61986 struct rt_mutex_waiter *pi_blocked_on;
61987 #endif
61988
61989 +/* process credentials */
61990 + const struct cred __rcu *real_cred; /* objective and real subjective task
61991 + * credentials (COW) */
61992 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
61993 +
61994 #ifdef CONFIG_DEBUG_MUTEXES
61995 /* mutex deadlock detection */
61996 struct mutex_waiter *blocked_on;
61997 @@ -1558,6 +1584,27 @@ struct task_struct {
61998 unsigned long default_timer_slack_ns;
61999
62000 struct list_head *scm_work_list;
62001 +
62002 +#ifdef CONFIG_GRKERNSEC
62003 + /* grsecurity */
62004 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62005 + u64 exec_id;
62006 +#endif
62007 +#ifdef CONFIG_GRKERNSEC_SETXID
62008 + const struct cred *delayed_cred;
62009 +#endif
62010 + struct dentry *gr_chroot_dentry;
62011 + struct acl_subject_label *acl;
62012 + struct acl_role_label *role;
62013 + struct file *exec_file;
62014 + u16 acl_role_id;
62015 + /* is this the task that authenticated to the special role */
62016 + u8 acl_sp_role;
62017 + u8 is_writable;
62018 + u8 brute;
62019 + u8 gr_is_chrooted;
62020 +#endif
62021 +
62022 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
62023 /* Index of current stored address in ret_stack */
62024 int curr_ret_stack;
62025 @@ -1592,6 +1639,51 @@ struct task_struct {
62026 #endif
62027 };
62028
62029 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
62030 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
62031 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
62032 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
62033 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
62034 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
62035 +
62036 +#ifdef CONFIG_PAX_SOFTMODE
62037 +extern int pax_softmode;
62038 +#endif
62039 +
62040 +extern int pax_check_flags(unsigned long *);
62041 +
62042 +/* if tsk != current then task_lock must be held on it */
62043 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62044 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
62045 +{
62046 + if (likely(tsk->mm))
62047 + return tsk->mm->pax_flags;
62048 + else
62049 + return 0UL;
62050 +}
62051 +
62052 +/* if tsk != current then task_lock must be held on it */
62053 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
62054 +{
62055 + if (likely(tsk->mm)) {
62056 + tsk->mm->pax_flags = flags;
62057 + return 0;
62058 + }
62059 + return -EINVAL;
62060 +}
62061 +#endif
62062 +
62063 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62064 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
62065 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62066 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62067 +#endif
62068 +
62069 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
62070 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
62071 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
62072 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
62073 +
62074 /* Future-safe accessor for struct task_struct's cpus_allowed. */
62075 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
62076
62077 @@ -2104,7 +2196,9 @@ void yield(void);
62078 extern struct exec_domain default_exec_domain;
62079
62080 union thread_union {
62081 +#ifndef CONFIG_X86
62082 struct thread_info thread_info;
62083 +#endif
62084 unsigned long stack[THREAD_SIZE/sizeof(long)];
62085 };
62086
62087 @@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
62088 */
62089
62090 extern struct task_struct *find_task_by_vpid(pid_t nr);
62091 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
62092 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
62093 struct pid_namespace *ns);
62094
62095 @@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
62096 extern void exit_itimers(struct signal_struct *);
62097 extern void flush_itimer_signals(void);
62098
62099 -extern void do_group_exit(int);
62100 +extern __noreturn void do_group_exit(int);
62101
62102 extern void daemonize(const char *, ...);
62103 extern int allow_signal(int);
62104 @@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
62105
62106 #endif
62107
62108 -static inline int object_is_on_stack(void *obj)
62109 +static inline int object_starts_on_stack(void *obj)
62110 {
62111 - void *stack = task_stack_page(current);
62112 + const void *stack = task_stack_page(current);
62113
62114 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
62115 }
62116
62117 +#ifdef CONFIG_PAX_USERCOPY
62118 +extern int object_is_on_stack(const void *obj, unsigned long len);
62119 +#endif
62120 +
62121 extern void thread_info_cache_init(void);
62122
62123 #ifdef CONFIG_DEBUG_STACK_USAGE
62124 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
62125 index 899fbb4..1cb4138 100644
62126 --- a/include/linux/screen_info.h
62127 +++ b/include/linux/screen_info.h
62128 @@ -43,7 +43,8 @@ struct screen_info {
62129 __u16 pages; /* 0x32 */
62130 __u16 vesa_attributes; /* 0x34 */
62131 __u32 capabilities; /* 0x36 */
62132 - __u8 _reserved[6]; /* 0x3a */
62133 + __u16 vesapm_size; /* 0x3a */
62134 + __u8 _reserved[4]; /* 0x3c */
62135 } __attribute__((packed));
62136
62137 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
62138 diff --git a/include/linux/security.h b/include/linux/security.h
62139 index 83c18e8..2d98860 100644
62140 --- a/include/linux/security.h
62141 +++ b/include/linux/security.h
62142 @@ -37,6 +37,7 @@
62143 #include <linux/xfrm.h>
62144 #include <linux/slab.h>
62145 #include <linux/xattr.h>
62146 +#include <linux/grsecurity.h>
62147 #include <net/flow.h>
62148
62149 /* Maximum number of letters for an LSM name string */
62150 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
62151 index 44f1514..2bbf6c1 100644
62152 --- a/include/linux/seq_file.h
62153 +++ b/include/linux/seq_file.h
62154 @@ -24,6 +24,9 @@ struct seq_file {
62155 struct mutex lock;
62156 const struct seq_operations *op;
62157 int poll_event;
62158 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62159 + u64 exec_id;
62160 +#endif
62161 void *private;
62162 };
62163
62164 @@ -33,6 +36,7 @@ struct seq_operations {
62165 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
62166 int (*show) (struct seq_file *m, void *v);
62167 };
62168 +typedef struct seq_operations __no_const seq_operations_no_const;
62169
62170 #define SEQ_SKIP 1
62171
62172 diff --git a/include/linux/shm.h b/include/linux/shm.h
62173 index 92808b8..c28cac4 100644
62174 --- a/include/linux/shm.h
62175 +++ b/include/linux/shm.h
62176 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
62177
62178 /* The task created the shm object. NULL if the task is dead. */
62179 struct task_struct *shm_creator;
62180 +#ifdef CONFIG_GRKERNSEC
62181 + time_t shm_createtime;
62182 + pid_t shm_lapid;
62183 +#endif
62184 };
62185
62186 /* shm_mode upper byte flags */
62187 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
62188 index ae86ade..2b51468 100644
62189 --- a/include/linux/skbuff.h
62190 +++ b/include/linux/skbuff.h
62191 @@ -654,7 +654,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
62192 */
62193 static inline int skb_queue_empty(const struct sk_buff_head *list)
62194 {
62195 - return list->next == (struct sk_buff *)list;
62196 + return list->next == (const struct sk_buff *)list;
62197 }
62198
62199 /**
62200 @@ -667,7 +667,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
62201 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62202 const struct sk_buff *skb)
62203 {
62204 - return skb->next == (struct sk_buff *)list;
62205 + return skb->next == (const struct sk_buff *)list;
62206 }
62207
62208 /**
62209 @@ -680,7 +680,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62210 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
62211 const struct sk_buff *skb)
62212 {
62213 - return skb->prev == (struct sk_buff *)list;
62214 + return skb->prev == (const struct sk_buff *)list;
62215 }
62216
62217 /**
62218 @@ -1545,7 +1545,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
62219 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
62220 */
62221 #ifndef NET_SKB_PAD
62222 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
62223 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
62224 #endif
62225
62226 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
62227 diff --git a/include/linux/slab.h b/include/linux/slab.h
62228 index 573c809..e84c132 100644
62229 --- a/include/linux/slab.h
62230 +++ b/include/linux/slab.h
62231 @@ -11,12 +11,20 @@
62232
62233 #include <linux/gfp.h>
62234 #include <linux/types.h>
62235 +#include <linux/err.h>
62236
62237 /*
62238 * Flags to pass to kmem_cache_create().
62239 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
62240 */
62241 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
62242 +
62243 +#ifdef CONFIG_PAX_USERCOPY
62244 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
62245 +#else
62246 +#define SLAB_USERCOPY 0x00000000UL
62247 +#endif
62248 +
62249 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
62250 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
62251 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
62252 @@ -87,10 +95,13 @@
62253 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
62254 * Both make kfree a no-op.
62255 */
62256 -#define ZERO_SIZE_PTR ((void *)16)
62257 +#define ZERO_SIZE_PTR \
62258 +({ \
62259 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
62260 + (void *)(-MAX_ERRNO-1L); \
62261 +})
62262
62263 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
62264 - (unsigned long)ZERO_SIZE_PTR)
62265 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
62266
62267 /*
62268 * struct kmem_cache related prototypes
62269 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
62270 void kfree(const void *);
62271 void kzfree(const void *);
62272 size_t ksize(const void *);
62273 +void check_object_size(const void *ptr, unsigned long n, bool to);
62274
62275 /*
62276 * Allocator specific definitions. These are mainly used to establish optimized
62277 @@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
62278
62279 void __init kmem_cache_init_late(void);
62280
62281 +#define kmalloc(x, y) \
62282 +({ \
62283 + void *___retval; \
62284 + intoverflow_t ___x = (intoverflow_t)x; \
62285 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
62286 + ___retval = NULL; \
62287 + else \
62288 + ___retval = kmalloc((size_t)___x, (y)); \
62289 + ___retval; \
62290 +})
62291 +
62292 +#define kmalloc_node(x, y, z) \
62293 +({ \
62294 + void *___retval; \
62295 + intoverflow_t ___x = (intoverflow_t)x; \
62296 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
62297 + ___retval = NULL; \
62298 + else \
62299 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
62300 + ___retval; \
62301 +})
62302 +
62303 +#define kzalloc(x, y) \
62304 +({ \
62305 + void *___retval; \
62306 + intoverflow_t ___x = (intoverflow_t)x; \
62307 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
62308 + ___retval = NULL; \
62309 + else \
62310 + ___retval = kzalloc((size_t)___x, (y)); \
62311 + ___retval; \
62312 +})
62313 +
62314 +#define __krealloc(x, y, z) \
62315 +({ \
62316 + void *___retval; \
62317 + intoverflow_t ___y = (intoverflow_t)y; \
62318 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
62319 + ___retval = NULL; \
62320 + else \
62321 + ___retval = __krealloc((x), (size_t)___y, (z)); \
62322 + ___retval; \
62323 +})
62324 +
62325 +#define krealloc(x, y, z) \
62326 +({ \
62327 + void *___retval; \
62328 + intoverflow_t ___y = (intoverflow_t)y; \
62329 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
62330 + ___retval = NULL; \
62331 + else \
62332 + ___retval = krealloc((x), (size_t)___y, (z)); \
62333 + ___retval; \
62334 +})
62335 +
62336 #endif /* _LINUX_SLAB_H */
62337 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
62338 index fbd1117..1e5e46c 100644
62339 --- a/include/linux/slab_def.h
62340 +++ b/include/linux/slab_def.h
62341 @@ -66,10 +66,10 @@ struct kmem_cache {
62342 unsigned long node_allocs;
62343 unsigned long node_frees;
62344 unsigned long node_overflow;
62345 - atomic_t allochit;
62346 - atomic_t allocmiss;
62347 - atomic_t freehit;
62348 - atomic_t freemiss;
62349 + atomic_unchecked_t allochit;
62350 + atomic_unchecked_t allocmiss;
62351 + atomic_unchecked_t freehit;
62352 + atomic_unchecked_t freemiss;
62353
62354 /*
62355 * If debugging is enabled, then the allocator can add additional
62356 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
62357 index a32bcfd..53b71f4 100644
62358 --- a/include/linux/slub_def.h
62359 +++ b/include/linux/slub_def.h
62360 @@ -89,7 +89,7 @@ struct kmem_cache {
62361 struct kmem_cache_order_objects max;
62362 struct kmem_cache_order_objects min;
62363 gfp_t allocflags; /* gfp flags to use on each alloc */
62364 - int refcount; /* Refcount for slab cache destroy */
62365 + atomic_t refcount; /* Refcount for slab cache destroy */
62366 void (*ctor)(void *);
62367 int inuse; /* Offset to metadata */
62368 int align; /* Alignment */
62369 @@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
62370 }
62371
62372 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62373 -void *__kmalloc(size_t size, gfp_t flags);
62374 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
62375
62376 static __always_inline void *
62377 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
62378 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
62379 index de8832d..0147b46 100644
62380 --- a/include/linux/sonet.h
62381 +++ b/include/linux/sonet.h
62382 @@ -61,7 +61,7 @@ struct sonet_stats {
62383 #include <linux/atomic.h>
62384
62385 struct k_sonet_stats {
62386 -#define __HANDLE_ITEM(i) atomic_t i
62387 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
62388 __SONET_ITEMS
62389 #undef __HANDLE_ITEM
62390 };
62391 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
62392 index 2c5993a..b0e79f0 100644
62393 --- a/include/linux/sunrpc/clnt.h
62394 +++ b/include/linux/sunrpc/clnt.h
62395 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
62396 {
62397 switch (sap->sa_family) {
62398 case AF_INET:
62399 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
62400 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
62401 case AF_INET6:
62402 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
62403 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
62404 }
62405 return 0;
62406 }
62407 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
62408 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
62409 const struct sockaddr *src)
62410 {
62411 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
62412 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
62413 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
62414
62415 dsin->sin_family = ssin->sin_family;
62416 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
62417 if (sa->sa_family != AF_INET6)
62418 return 0;
62419
62420 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
62421 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
62422 }
62423
62424 #endif /* __KERNEL__ */
62425 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
62426 index e775689..9e206d9 100644
62427 --- a/include/linux/sunrpc/sched.h
62428 +++ b/include/linux/sunrpc/sched.h
62429 @@ -105,6 +105,7 @@ struct rpc_call_ops {
62430 void (*rpc_call_done)(struct rpc_task *, void *);
62431 void (*rpc_release)(void *);
62432 };
62433 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
62434
62435 struct rpc_task_setup {
62436 struct rpc_task *task;
62437 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
62438 index c14fe86..393245e 100644
62439 --- a/include/linux/sunrpc/svc_rdma.h
62440 +++ b/include/linux/sunrpc/svc_rdma.h
62441 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
62442 extern unsigned int svcrdma_max_requests;
62443 extern unsigned int svcrdma_max_req_size;
62444
62445 -extern atomic_t rdma_stat_recv;
62446 -extern atomic_t rdma_stat_read;
62447 -extern atomic_t rdma_stat_write;
62448 -extern atomic_t rdma_stat_sq_starve;
62449 -extern atomic_t rdma_stat_rq_starve;
62450 -extern atomic_t rdma_stat_rq_poll;
62451 -extern atomic_t rdma_stat_rq_prod;
62452 -extern atomic_t rdma_stat_sq_poll;
62453 -extern atomic_t rdma_stat_sq_prod;
62454 +extern atomic_unchecked_t rdma_stat_recv;
62455 +extern atomic_unchecked_t rdma_stat_read;
62456 +extern atomic_unchecked_t rdma_stat_write;
62457 +extern atomic_unchecked_t rdma_stat_sq_starve;
62458 +extern atomic_unchecked_t rdma_stat_rq_starve;
62459 +extern atomic_unchecked_t rdma_stat_rq_poll;
62460 +extern atomic_unchecked_t rdma_stat_rq_prod;
62461 +extern atomic_unchecked_t rdma_stat_sq_poll;
62462 +extern atomic_unchecked_t rdma_stat_sq_prod;
62463
62464 #define RPCRDMA_VERSION 1
62465
62466 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
62467 index bb9127d..34ab358 100644
62468 --- a/include/linux/sysctl.h
62469 +++ b/include/linux/sysctl.h
62470 @@ -155,7 +155,11 @@ enum
62471 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
62472 };
62473
62474 -
62475 +#ifdef CONFIG_PAX_SOFTMODE
62476 +enum {
62477 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
62478 +};
62479 +#endif
62480
62481 /* CTL_VM names: */
62482 enum
62483 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
62484
62485 extern int proc_dostring(struct ctl_table *, int,
62486 void __user *, size_t *, loff_t *);
62487 +extern int proc_dostring_modpriv(struct ctl_table *, int,
62488 + void __user *, size_t *, loff_t *);
62489 extern int proc_dointvec(struct ctl_table *, int,
62490 void __user *, size_t *, loff_t *);
62491 extern int proc_dointvec_minmax(struct ctl_table *, int,
62492 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
62493 index a71a292..51bd91d 100644
62494 --- a/include/linux/tracehook.h
62495 +++ b/include/linux/tracehook.h
62496 @@ -54,12 +54,12 @@ struct linux_binprm;
62497 /*
62498 * ptrace report for syscall entry and exit looks identical.
62499 */
62500 -static inline void ptrace_report_syscall(struct pt_regs *regs)
62501 +static inline int ptrace_report_syscall(struct pt_regs *regs)
62502 {
62503 int ptrace = current->ptrace;
62504
62505 if (!(ptrace & PT_PTRACED))
62506 - return;
62507 + return 0;
62508
62509 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
62510
62511 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
62512 send_sig(current->exit_code, current, 1);
62513 current->exit_code = 0;
62514 }
62515 +
62516 + return fatal_signal_pending(current);
62517 }
62518
62519 /**
62520 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
62521 static inline __must_check int tracehook_report_syscall_entry(
62522 struct pt_regs *regs)
62523 {
62524 - ptrace_report_syscall(regs);
62525 - return 0;
62526 + return ptrace_report_syscall(regs);
62527 }
62528
62529 /**
62530 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
62531 index ff7dc08..893e1bd 100644
62532 --- a/include/linux/tty_ldisc.h
62533 +++ b/include/linux/tty_ldisc.h
62534 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
62535
62536 struct module *owner;
62537
62538 - int refcount;
62539 + atomic_t refcount;
62540 };
62541
62542 struct tty_ldisc {
62543 diff --git a/include/linux/types.h b/include/linux/types.h
62544 index e5fa503..df6e8a4 100644
62545 --- a/include/linux/types.h
62546 +++ b/include/linux/types.h
62547 @@ -214,10 +214,26 @@ typedef struct {
62548 int counter;
62549 } atomic_t;
62550
62551 +#ifdef CONFIG_PAX_REFCOUNT
62552 +typedef struct {
62553 + int counter;
62554 +} atomic_unchecked_t;
62555 +#else
62556 +typedef atomic_t atomic_unchecked_t;
62557 +#endif
62558 +
62559 #ifdef CONFIG_64BIT
62560 typedef struct {
62561 long counter;
62562 } atomic64_t;
62563 +
62564 +#ifdef CONFIG_PAX_REFCOUNT
62565 +typedef struct {
62566 + long counter;
62567 +} atomic64_unchecked_t;
62568 +#else
62569 +typedef atomic64_t atomic64_unchecked_t;
62570 +#endif
62571 #endif
62572
62573 struct list_head {
62574 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
62575 index 5ca0951..ab496a5 100644
62576 --- a/include/linux/uaccess.h
62577 +++ b/include/linux/uaccess.h
62578 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
62579 long ret; \
62580 mm_segment_t old_fs = get_fs(); \
62581 \
62582 - set_fs(KERNEL_DS); \
62583 pagefault_disable(); \
62584 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
62585 - pagefault_enable(); \
62586 + set_fs(KERNEL_DS); \
62587 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
62588 set_fs(old_fs); \
62589 + pagefault_enable(); \
62590 ret; \
62591 })
62592
62593 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
62594 index 99c1b4d..bb94261 100644
62595 --- a/include/linux/unaligned/access_ok.h
62596 +++ b/include/linux/unaligned/access_ok.h
62597 @@ -6,32 +6,32 @@
62598
62599 static inline u16 get_unaligned_le16(const void *p)
62600 {
62601 - return le16_to_cpup((__le16 *)p);
62602 + return le16_to_cpup((const __le16 *)p);
62603 }
62604
62605 static inline u32 get_unaligned_le32(const void *p)
62606 {
62607 - return le32_to_cpup((__le32 *)p);
62608 + return le32_to_cpup((const __le32 *)p);
62609 }
62610
62611 static inline u64 get_unaligned_le64(const void *p)
62612 {
62613 - return le64_to_cpup((__le64 *)p);
62614 + return le64_to_cpup((const __le64 *)p);
62615 }
62616
62617 static inline u16 get_unaligned_be16(const void *p)
62618 {
62619 - return be16_to_cpup((__be16 *)p);
62620 + return be16_to_cpup((const __be16 *)p);
62621 }
62622
62623 static inline u32 get_unaligned_be32(const void *p)
62624 {
62625 - return be32_to_cpup((__be32 *)p);
62626 + return be32_to_cpup((const __be32 *)p);
62627 }
62628
62629 static inline u64 get_unaligned_be64(const void *p)
62630 {
62631 - return be64_to_cpup((__be64 *)p);
62632 + return be64_to_cpup((const __be64 *)p);
62633 }
62634
62635 static inline void put_unaligned_le16(u16 val, void *p)
62636 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
62637 index 0d3f988..000f101 100644
62638 --- a/include/linux/usb/renesas_usbhs.h
62639 +++ b/include/linux/usb/renesas_usbhs.h
62640 @@ -39,7 +39,7 @@ enum {
62641 */
62642 struct renesas_usbhs_driver_callback {
62643 int (*notify_hotplug)(struct platform_device *pdev);
62644 -};
62645 +} __no_const;
62646
62647 /*
62648 * callback functions for platform
62649 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
62650 * VBUS control is needed for Host
62651 */
62652 int (*set_vbus)(struct platform_device *pdev, int enable);
62653 -};
62654 +} __no_const;
62655
62656 /*
62657 * parameters for renesas usbhs
62658 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
62659 index 6f8fbcf..8259001 100644
62660 --- a/include/linux/vermagic.h
62661 +++ b/include/linux/vermagic.h
62662 @@ -25,9 +25,35 @@
62663 #define MODULE_ARCH_VERMAGIC ""
62664 #endif
62665
62666 +#ifdef CONFIG_PAX_REFCOUNT
62667 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
62668 +#else
62669 +#define MODULE_PAX_REFCOUNT ""
62670 +#endif
62671 +
62672 +#ifdef CONSTIFY_PLUGIN
62673 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
62674 +#else
62675 +#define MODULE_CONSTIFY_PLUGIN ""
62676 +#endif
62677 +
62678 +#ifdef STACKLEAK_PLUGIN
62679 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
62680 +#else
62681 +#define MODULE_STACKLEAK_PLUGIN ""
62682 +#endif
62683 +
62684 +#ifdef CONFIG_GRKERNSEC
62685 +#define MODULE_GRSEC "GRSEC "
62686 +#else
62687 +#define MODULE_GRSEC ""
62688 +#endif
62689 +
62690 #define VERMAGIC_STRING \
62691 UTS_RELEASE " " \
62692 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
62693 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
62694 - MODULE_ARCH_VERMAGIC
62695 + MODULE_ARCH_VERMAGIC \
62696 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
62697 + MODULE_GRSEC
62698
62699 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
62700 index dcdfc2b..f937197 100644
62701 --- a/include/linux/vmalloc.h
62702 +++ b/include/linux/vmalloc.h
62703 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
62704 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
62705 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
62706 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
62707 +
62708 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
62709 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
62710 +#endif
62711 +
62712 /* bits [20..32] reserved for arch specific ioremap internals */
62713
62714 /*
62715 @@ -157,4 +162,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
62716 # endif
62717 #endif
62718
62719 +#define vmalloc(x) \
62720 +({ \
62721 + void *___retval; \
62722 + intoverflow_t ___x = (intoverflow_t)x; \
62723 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
62724 + ___retval = NULL; \
62725 + else \
62726 + ___retval = vmalloc((unsigned long)___x); \
62727 + ___retval; \
62728 +})
62729 +
62730 +#define vzalloc(x) \
62731 +({ \
62732 + void *___retval; \
62733 + intoverflow_t ___x = (intoverflow_t)x; \
62734 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
62735 + ___retval = NULL; \
62736 + else \
62737 + ___retval = vzalloc((unsigned long)___x); \
62738 + ___retval; \
62739 +})
62740 +
62741 +#define __vmalloc(x, y, z) \
62742 +({ \
62743 + void *___retval; \
62744 + intoverflow_t ___x = (intoverflow_t)x; \
62745 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
62746 + ___retval = NULL; \
62747 + else \
62748 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
62749 + ___retval; \
62750 +})
62751 +
62752 +#define vmalloc_user(x) \
62753 +({ \
62754 + void *___retval; \
62755 + intoverflow_t ___x = (intoverflow_t)x; \
62756 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
62757 + ___retval = NULL; \
62758 + else \
62759 + ___retval = vmalloc_user((unsigned long)___x); \
62760 + ___retval; \
62761 +})
62762 +
62763 +#define vmalloc_exec(x) \
62764 +({ \
62765 + void *___retval; \
62766 + intoverflow_t ___x = (intoverflow_t)x; \
62767 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
62768 + ___retval = NULL; \
62769 + else \
62770 + ___retval = vmalloc_exec((unsigned long)___x); \
62771 + ___retval; \
62772 +})
62773 +
62774 +#define vmalloc_node(x, y) \
62775 +({ \
62776 + void *___retval; \
62777 + intoverflow_t ___x = (intoverflow_t)x; \
62778 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
62779 + ___retval = NULL; \
62780 + else \
62781 + ___retval = vmalloc_node((unsigned long)___x, (y));\
62782 + ___retval; \
62783 +})
62784 +
62785 +#define vzalloc_node(x, y) \
62786 +({ \
62787 + void *___retval; \
62788 + intoverflow_t ___x = (intoverflow_t)x; \
62789 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
62790 + ___retval = NULL; \
62791 + else \
62792 + ___retval = vzalloc_node((unsigned long)___x, (y));\
62793 + ___retval; \
62794 +})
62795 +
62796 +#define vmalloc_32(x) \
62797 +({ \
62798 + void *___retval; \
62799 + intoverflow_t ___x = (intoverflow_t)x; \
62800 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
62801 + ___retval = NULL; \
62802 + else \
62803 + ___retval = vmalloc_32((unsigned long)___x); \
62804 + ___retval; \
62805 +})
62806 +
62807 +#define vmalloc_32_user(x) \
62808 +({ \
62809 +void *___retval; \
62810 + intoverflow_t ___x = (intoverflow_t)x; \
62811 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
62812 + ___retval = NULL; \
62813 + else \
62814 + ___retval = vmalloc_32_user((unsigned long)___x);\
62815 + ___retval; \
62816 +})
62817 +
62818 #endif /* _LINUX_VMALLOC_H */
62819 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
62820 index 65efb92..137adbb 100644
62821 --- a/include/linux/vmstat.h
62822 +++ b/include/linux/vmstat.h
62823 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
62824 /*
62825 * Zone based page accounting with per cpu differentials.
62826 */
62827 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62828 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62829
62830 static inline void zone_page_state_add(long x, struct zone *zone,
62831 enum zone_stat_item item)
62832 {
62833 - atomic_long_add(x, &zone->vm_stat[item]);
62834 - atomic_long_add(x, &vm_stat[item]);
62835 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
62836 + atomic_long_add_unchecked(x, &vm_stat[item]);
62837 }
62838
62839 static inline unsigned long global_page_state(enum zone_stat_item item)
62840 {
62841 - long x = atomic_long_read(&vm_stat[item]);
62842 + long x = atomic_long_read_unchecked(&vm_stat[item]);
62843 #ifdef CONFIG_SMP
62844 if (x < 0)
62845 x = 0;
62846 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
62847 static inline unsigned long zone_page_state(struct zone *zone,
62848 enum zone_stat_item item)
62849 {
62850 - long x = atomic_long_read(&zone->vm_stat[item]);
62851 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
62852 #ifdef CONFIG_SMP
62853 if (x < 0)
62854 x = 0;
62855 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
62856 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
62857 enum zone_stat_item item)
62858 {
62859 - long x = atomic_long_read(&zone->vm_stat[item]);
62860 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
62861
62862 #ifdef CONFIG_SMP
62863 int cpu;
62864 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
62865
62866 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
62867 {
62868 - atomic_long_inc(&zone->vm_stat[item]);
62869 - atomic_long_inc(&vm_stat[item]);
62870 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
62871 + atomic_long_inc_unchecked(&vm_stat[item]);
62872 }
62873
62874 static inline void __inc_zone_page_state(struct page *page,
62875 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
62876
62877 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
62878 {
62879 - atomic_long_dec(&zone->vm_stat[item]);
62880 - atomic_long_dec(&vm_stat[item]);
62881 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
62882 + atomic_long_dec_unchecked(&vm_stat[item]);
62883 }
62884
62885 static inline void __dec_zone_page_state(struct page *page,
62886 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
62887 index e5d1220..ef6e406 100644
62888 --- a/include/linux/xattr.h
62889 +++ b/include/linux/xattr.h
62890 @@ -57,6 +57,11 @@
62891 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
62892 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
62893
62894 +/* User namespace */
62895 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
62896 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
62897 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
62898 +
62899 #ifdef __KERNEL__
62900
62901 #include <linux/types.h>
62902 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
62903 index 4aeff96..b378cdc 100644
62904 --- a/include/media/saa7146_vv.h
62905 +++ b/include/media/saa7146_vv.h
62906 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
62907 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
62908
62909 /* the extension can override this */
62910 - struct v4l2_ioctl_ops ops;
62911 + v4l2_ioctl_ops_no_const ops;
62912 /* pointer to the saa7146 core ops */
62913 const struct v4l2_ioctl_ops *core_ops;
62914
62915 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
62916 index c7c40f1..4f01585 100644
62917 --- a/include/media/v4l2-dev.h
62918 +++ b/include/media/v4l2-dev.h
62919 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
62920
62921
62922 struct v4l2_file_operations {
62923 - struct module *owner;
62924 + struct module * const owner;
62925 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
62926 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
62927 unsigned int (*poll) (struct file *, struct poll_table_struct *);
62928 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
62929 int (*open) (struct file *);
62930 int (*release) (struct file *);
62931 };
62932 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
62933
62934 /*
62935 * Newer version of video_device, handled by videodev2.c
62936 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
62937 index 3f5d60f..44210ed 100644
62938 --- a/include/media/v4l2-ioctl.h
62939 +++ b/include/media/v4l2-ioctl.h
62940 @@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
62941 long (*vidioc_default) (struct file *file, void *fh,
62942 bool valid_prio, int cmd, void *arg);
62943 };
62944 -
62945 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
62946
62947 /* v4l debugging and diagnostics */
62948
62949 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
62950 index 8d55251..dfe5b0a 100644
62951 --- a/include/net/caif/caif_hsi.h
62952 +++ b/include/net/caif/caif_hsi.h
62953 @@ -98,7 +98,7 @@ struct cfhsi_drv {
62954 void (*rx_done_cb) (struct cfhsi_drv *drv);
62955 void (*wake_up_cb) (struct cfhsi_drv *drv);
62956 void (*wake_down_cb) (struct cfhsi_drv *drv);
62957 -};
62958 +} __no_const;
62959
62960 /* Structure implemented by HSI device. */
62961 struct cfhsi_dev {
62962 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
62963 index 9e5425b..8136ffc 100644
62964 --- a/include/net/caif/cfctrl.h
62965 +++ b/include/net/caif/cfctrl.h
62966 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
62967 void (*radioset_rsp)(void);
62968 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
62969 struct cflayer *client_layer);
62970 -};
62971 +} __no_const;
62972
62973 /* Link Setup Parameters for CAIF-Links. */
62974 struct cfctrl_link_param {
62975 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
62976 struct cfctrl {
62977 struct cfsrvl serv;
62978 struct cfctrl_rsp res;
62979 - atomic_t req_seq_no;
62980 - atomic_t rsp_seq_no;
62981 + atomic_unchecked_t req_seq_no;
62982 + atomic_unchecked_t rsp_seq_no;
62983 struct list_head list;
62984 /* Protects from simultaneous access to first_req list */
62985 spinlock_t info_list_lock;
62986 diff --git a/include/net/flow.h b/include/net/flow.h
62987 index 6c469db..7743b8e 100644
62988 --- a/include/net/flow.h
62989 +++ b/include/net/flow.h
62990 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
62991
62992 extern void flow_cache_flush(void);
62993 extern void flow_cache_flush_deferred(void);
62994 -extern atomic_t flow_cache_genid;
62995 +extern atomic_unchecked_t flow_cache_genid;
62996
62997 #endif
62998 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
62999 index b94765e..053f68b 100644
63000 --- a/include/net/inetpeer.h
63001 +++ b/include/net/inetpeer.h
63002 @@ -48,8 +48,8 @@ struct inet_peer {
63003 */
63004 union {
63005 struct {
63006 - atomic_t rid; /* Frag reception counter */
63007 - atomic_t ip_id_count; /* IP ID for the next packet */
63008 + atomic_unchecked_t rid; /* Frag reception counter */
63009 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
63010 __u32 tcp_ts;
63011 __u32 tcp_ts_stamp;
63012 };
63013 @@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
63014 more++;
63015 inet_peer_refcheck(p);
63016 do {
63017 - old = atomic_read(&p->ip_id_count);
63018 + old = atomic_read_unchecked(&p->ip_id_count);
63019 new = old + more;
63020 if (!new)
63021 new = 1;
63022 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
63023 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
63024 return new;
63025 }
63026
63027 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
63028 index 10422ef..662570f 100644
63029 --- a/include/net/ip_fib.h
63030 +++ b/include/net/ip_fib.h
63031 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
63032
63033 #define FIB_RES_SADDR(net, res) \
63034 ((FIB_RES_NH(res).nh_saddr_genid == \
63035 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
63036 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
63037 FIB_RES_NH(res).nh_saddr : \
63038 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
63039 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
63040 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
63041 index ebe517f..1bd286b 100644
63042 --- a/include/net/ip_vs.h
63043 +++ b/include/net/ip_vs.h
63044 @@ -509,7 +509,7 @@ struct ip_vs_conn {
63045 struct ip_vs_conn *control; /* Master control connection */
63046 atomic_t n_control; /* Number of controlled ones */
63047 struct ip_vs_dest *dest; /* real server */
63048 - atomic_t in_pkts; /* incoming packet counter */
63049 + atomic_unchecked_t in_pkts; /* incoming packet counter */
63050
63051 /* packet transmitter for different forwarding methods. If it
63052 mangles the packet, it must return NF_DROP or better NF_STOLEN,
63053 @@ -647,7 +647,7 @@ struct ip_vs_dest {
63054 __be16 port; /* port number of the server */
63055 union nf_inet_addr addr; /* IP address of the server */
63056 volatile unsigned flags; /* dest status flags */
63057 - atomic_t conn_flags; /* flags to copy to conn */
63058 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
63059 atomic_t weight; /* server weight */
63060
63061 atomic_t refcnt; /* reference counter */
63062 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
63063 index 69b610a..fe3962c 100644
63064 --- a/include/net/irda/ircomm_core.h
63065 +++ b/include/net/irda/ircomm_core.h
63066 @@ -51,7 +51,7 @@ typedef struct {
63067 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
63068 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
63069 struct ircomm_info *);
63070 -} call_t;
63071 +} __no_const call_t;
63072
63073 struct ircomm_cb {
63074 irda_queue_t queue;
63075 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
63076 index 59ba38bc..d515662 100644
63077 --- a/include/net/irda/ircomm_tty.h
63078 +++ b/include/net/irda/ircomm_tty.h
63079 @@ -35,6 +35,7 @@
63080 #include <linux/termios.h>
63081 #include <linux/timer.h>
63082 #include <linux/tty.h> /* struct tty_struct */
63083 +#include <asm/local.h>
63084
63085 #include <net/irda/irias_object.h>
63086 #include <net/irda/ircomm_core.h>
63087 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
63088 unsigned short close_delay;
63089 unsigned short closing_wait; /* time to wait before closing */
63090
63091 - int open_count;
63092 - int blocked_open; /* # of blocked opens */
63093 + local_t open_count;
63094 + local_t blocked_open; /* # of blocked opens */
63095
63096 /* Protect concurent access to :
63097 * o self->open_count
63098 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
63099 index 0954ec9..7413562 100644
63100 --- a/include/net/iucv/af_iucv.h
63101 +++ b/include/net/iucv/af_iucv.h
63102 @@ -138,7 +138,7 @@ struct iucv_sock {
63103 struct iucv_sock_list {
63104 struct hlist_head head;
63105 rwlock_t lock;
63106 - atomic_t autobind_name;
63107 + atomic_unchecked_t autobind_name;
63108 };
63109
63110 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
63111 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
63112 index 34c996f..bb3b4d4 100644
63113 --- a/include/net/neighbour.h
63114 +++ b/include/net/neighbour.h
63115 @@ -123,7 +123,7 @@ struct neigh_ops {
63116 void (*error_report)(struct neighbour *, struct sk_buff *);
63117 int (*output)(struct neighbour *, struct sk_buff *);
63118 int (*connected_output)(struct neighbour *, struct sk_buff *);
63119 -};
63120 +} __do_const;
63121
63122 struct pneigh_entry {
63123 struct pneigh_entry *next;
63124 diff --git a/include/net/netlink.h b/include/net/netlink.h
63125 index cb1f350..3279d2c 100644
63126 --- a/include/net/netlink.h
63127 +++ b/include/net/netlink.h
63128 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
63129 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
63130 {
63131 if (mark)
63132 - skb_trim(skb, (unsigned char *) mark - skb->data);
63133 + skb_trim(skb, (const unsigned char *) mark - skb->data);
63134 }
63135
63136 /**
63137 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
63138 index bbd023a..97c6d0d 100644
63139 --- a/include/net/netns/ipv4.h
63140 +++ b/include/net/netns/ipv4.h
63141 @@ -57,8 +57,8 @@ struct netns_ipv4 {
63142 unsigned int sysctl_ping_group_range[2];
63143 long sysctl_tcp_mem[3];
63144
63145 - atomic_t rt_genid;
63146 - atomic_t dev_addr_genid;
63147 + atomic_unchecked_t rt_genid;
63148 + atomic_unchecked_t dev_addr_genid;
63149
63150 #ifdef CONFIG_IP_MROUTE
63151 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
63152 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
63153 index d368561..96aaa17 100644
63154 --- a/include/net/sctp/sctp.h
63155 +++ b/include/net/sctp/sctp.h
63156 @@ -318,9 +318,9 @@ do { \
63157
63158 #else /* SCTP_DEBUG */
63159
63160 -#define SCTP_DEBUG_PRINTK(whatever...)
63161 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
63162 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
63163 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
63164 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
63165 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
63166 #define SCTP_ENABLE_DEBUG
63167 #define SCTP_DISABLE_DEBUG
63168 #define SCTP_ASSERT(expr, str, func)
63169 diff --git a/include/net/sock.h b/include/net/sock.h
63170 index 91c1c8b..15ae923 100644
63171 --- a/include/net/sock.h
63172 +++ b/include/net/sock.h
63173 @@ -299,7 +299,7 @@ struct sock {
63174 #ifdef CONFIG_RPS
63175 __u32 sk_rxhash;
63176 #endif
63177 - atomic_t sk_drops;
63178 + atomic_unchecked_t sk_drops;
63179 int sk_rcvbuf;
63180
63181 struct sk_filter __rcu *sk_filter;
63182 @@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
63183 }
63184
63185 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
63186 - char __user *from, char *to,
63187 + char __user *from, unsigned char *to,
63188 int copy, int offset)
63189 {
63190 if (skb->ip_summed == CHECKSUM_NONE) {
63191 diff --git a/include/net/tcp.h b/include/net/tcp.h
63192 index 2d80c29..aa07caf 100644
63193 --- a/include/net/tcp.h
63194 +++ b/include/net/tcp.h
63195 @@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
63196 char *name;
63197 sa_family_t family;
63198 const struct file_operations *seq_fops;
63199 - struct seq_operations seq_ops;
63200 + seq_operations_no_const seq_ops;
63201 };
63202
63203 struct tcp_iter_state {
63204 diff --git a/include/net/udp.h b/include/net/udp.h
63205 index e39592f..fef9680 100644
63206 --- a/include/net/udp.h
63207 +++ b/include/net/udp.h
63208 @@ -243,7 +243,7 @@ struct udp_seq_afinfo {
63209 sa_family_t family;
63210 struct udp_table *udp_table;
63211 const struct file_operations *seq_fops;
63212 - struct seq_operations seq_ops;
63213 + seq_operations_no_const seq_ops;
63214 };
63215
63216 struct udp_iter_state {
63217 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
63218 index 89174e2..1f82598 100644
63219 --- a/include/net/xfrm.h
63220 +++ b/include/net/xfrm.h
63221 @@ -505,7 +505,7 @@ struct xfrm_policy {
63222 struct timer_list timer;
63223
63224 struct flow_cache_object flo;
63225 - atomic_t genid;
63226 + atomic_unchecked_t genid;
63227 u32 priority;
63228 u32 index;
63229 struct xfrm_mark mark;
63230 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
63231 index 1a046b1..ee0bef0 100644
63232 --- a/include/rdma/iw_cm.h
63233 +++ b/include/rdma/iw_cm.h
63234 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
63235 int backlog);
63236
63237 int (*destroy_listen)(struct iw_cm_id *cm_id);
63238 -};
63239 +} __no_const;
63240
63241 /**
63242 * iw_create_cm_id - Create an IW CM identifier.
63243 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
63244 index 6a3922f..0b73022 100644
63245 --- a/include/scsi/libfc.h
63246 +++ b/include/scsi/libfc.h
63247 @@ -748,6 +748,7 @@ struct libfc_function_template {
63248 */
63249 void (*disc_stop_final) (struct fc_lport *);
63250 };
63251 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
63252
63253 /**
63254 * struct fc_disc - Discovery context
63255 @@ -851,7 +852,7 @@ struct fc_lport {
63256 struct fc_vport *vport;
63257
63258 /* Operational Information */
63259 - struct libfc_function_template tt;
63260 + libfc_function_template_no_const tt;
63261 u8 link_up;
63262 u8 qfull;
63263 enum fc_lport_state state;
63264 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
63265 index 77273f2..dd4031f 100644
63266 --- a/include/scsi/scsi_device.h
63267 +++ b/include/scsi/scsi_device.h
63268 @@ -161,9 +161,9 @@ struct scsi_device {
63269 unsigned int max_device_blocked; /* what device_blocked counts down from */
63270 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
63271
63272 - atomic_t iorequest_cnt;
63273 - atomic_t iodone_cnt;
63274 - atomic_t ioerr_cnt;
63275 + atomic_unchecked_t iorequest_cnt;
63276 + atomic_unchecked_t iodone_cnt;
63277 + atomic_unchecked_t ioerr_cnt;
63278
63279 struct device sdev_gendev,
63280 sdev_dev;
63281 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
63282 index 2a65167..91e01f8 100644
63283 --- a/include/scsi/scsi_transport_fc.h
63284 +++ b/include/scsi/scsi_transport_fc.h
63285 @@ -711,7 +711,7 @@ struct fc_function_template {
63286 unsigned long show_host_system_hostname:1;
63287
63288 unsigned long disable_target_scan:1;
63289 -};
63290 +} __do_const;
63291
63292
63293 /**
63294 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
63295 index 030b87c..98a6954 100644
63296 --- a/include/sound/ak4xxx-adda.h
63297 +++ b/include/sound/ak4xxx-adda.h
63298 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
63299 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
63300 unsigned char val);
63301 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
63302 -};
63303 +} __no_const;
63304
63305 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
63306
63307 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
63308 index 8c05e47..2b5df97 100644
63309 --- a/include/sound/hwdep.h
63310 +++ b/include/sound/hwdep.h
63311 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
63312 struct snd_hwdep_dsp_status *status);
63313 int (*dsp_load)(struct snd_hwdep *hw,
63314 struct snd_hwdep_dsp_image *image);
63315 -};
63316 +} __no_const;
63317
63318 struct snd_hwdep {
63319 struct snd_card *card;
63320 diff --git a/include/sound/info.h b/include/sound/info.h
63321 index 9ca1a49..aba1728 100644
63322 --- a/include/sound/info.h
63323 +++ b/include/sound/info.h
63324 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
63325 struct snd_info_buffer *buffer);
63326 void (*write)(struct snd_info_entry *entry,
63327 struct snd_info_buffer *buffer);
63328 -};
63329 +} __no_const;
63330
63331 struct snd_info_entry_ops {
63332 int (*open)(struct snd_info_entry *entry,
63333 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
63334 index 0cf91b2..b70cae4 100644
63335 --- a/include/sound/pcm.h
63336 +++ b/include/sound/pcm.h
63337 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
63338 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
63339 int (*ack)(struct snd_pcm_substream *substream);
63340 };
63341 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
63342
63343 /*
63344 *
63345 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
63346 index af1b49e..a5d55a5 100644
63347 --- a/include/sound/sb16_csp.h
63348 +++ b/include/sound/sb16_csp.h
63349 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
63350 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
63351 int (*csp_stop) (struct snd_sb_csp * p);
63352 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
63353 -};
63354 +} __no_const;
63355
63356 /*
63357 * CSP private data
63358 diff --git a/include/sound/soc.h b/include/sound/soc.h
63359 index 0992dff..bb366fe 100644
63360 --- a/include/sound/soc.h
63361 +++ b/include/sound/soc.h
63362 @@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
63363 /* platform IO - used for platform DAPM */
63364 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
63365 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
63366 -};
63367 +} __do_const;
63368
63369 struct snd_soc_platform {
63370 const char *name;
63371 @@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
63372 struct snd_soc_dai_link *dai_link;
63373 struct mutex pcm_mutex;
63374 enum snd_soc_pcm_subclass pcm_subclass;
63375 - struct snd_pcm_ops ops;
63376 + snd_pcm_ops_no_const ops;
63377
63378 unsigned int complete:1;
63379 unsigned int dev_registered:1;
63380 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
63381 index 444cd6b..3327cc5 100644
63382 --- a/include/sound/ymfpci.h
63383 +++ b/include/sound/ymfpci.h
63384 @@ -358,7 +358,7 @@ struct snd_ymfpci {
63385 spinlock_t reg_lock;
63386 spinlock_t voice_lock;
63387 wait_queue_head_t interrupt_sleep;
63388 - atomic_t interrupt_sleep_count;
63389 + atomic_unchecked_t interrupt_sleep_count;
63390 struct snd_info_entry *proc_entry;
63391 const struct firmware *dsp_microcode;
63392 const struct firmware *controller_microcode;
63393 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
63394 index fe73eb8..56388b1 100644
63395 --- a/include/target/target_core_base.h
63396 +++ b/include/target/target_core_base.h
63397 @@ -443,7 +443,7 @@ struct t10_reservation_ops {
63398 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
63399 int (*t10_pr_register)(struct se_cmd *);
63400 int (*t10_pr_clear)(struct se_cmd *);
63401 -};
63402 +} __no_const;
63403
63404 struct t10_reservation {
63405 /* Reservation effects all target ports */
63406 @@ -561,8 +561,8 @@ struct se_cmd {
63407 atomic_t t_se_count;
63408 atomic_t t_task_cdbs_left;
63409 atomic_t t_task_cdbs_ex_left;
63410 - atomic_t t_task_cdbs_sent;
63411 - atomic_t t_transport_aborted;
63412 + atomic_unchecked_t t_task_cdbs_sent;
63413 + atomic_unchecked_t t_transport_aborted;
63414 atomic_t t_transport_active;
63415 atomic_t t_transport_complete;
63416 atomic_t t_transport_queue_active;
63417 @@ -799,7 +799,7 @@ struct se_device {
63418 spinlock_t stats_lock;
63419 /* Active commands on this virtual SE device */
63420 atomic_t simple_cmds;
63421 - atomic_t dev_ordered_id;
63422 + atomic_unchecked_t dev_ordered_id;
63423 atomic_t execute_tasks;
63424 atomic_t dev_ordered_sync;
63425 atomic_t dev_qf_count;
63426 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
63427 index 1c09820..7f5ec79 100644
63428 --- a/include/trace/events/irq.h
63429 +++ b/include/trace/events/irq.h
63430 @@ -36,7 +36,7 @@ struct softirq_action;
63431 */
63432 TRACE_EVENT(irq_handler_entry,
63433
63434 - TP_PROTO(int irq, struct irqaction *action),
63435 + TP_PROTO(int irq, const struct irqaction *action),
63436
63437 TP_ARGS(irq, action),
63438
63439 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
63440 */
63441 TRACE_EVENT(irq_handler_exit,
63442
63443 - TP_PROTO(int irq, struct irqaction *action, int ret),
63444 + TP_PROTO(int irq, const struct irqaction *action, int ret),
63445
63446 TP_ARGS(irq, action, ret),
63447
63448 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
63449 index c41f308..6918de3 100644
63450 --- a/include/video/udlfb.h
63451 +++ b/include/video/udlfb.h
63452 @@ -52,10 +52,10 @@ struct dlfb_data {
63453 u32 pseudo_palette[256];
63454 int blank_mode; /*one of FB_BLANK_ */
63455 /* blit-only rendering path metrics, exposed through sysfs */
63456 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63457 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
63458 - atomic_t bytes_sent; /* to usb, after compression including overhead */
63459 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
63460 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63461 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
63462 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
63463 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
63464 };
63465
63466 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
63467 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
63468 index 0993a22..32ba2fe 100644
63469 --- a/include/video/uvesafb.h
63470 +++ b/include/video/uvesafb.h
63471 @@ -177,6 +177,7 @@ struct uvesafb_par {
63472 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
63473 u8 pmi_setpal; /* PMI for palette changes */
63474 u16 *pmi_base; /* protected mode interface location */
63475 + u8 *pmi_code; /* protected mode code location */
63476 void *pmi_start;
63477 void *pmi_pal;
63478 u8 *vbe_state_orig; /*
63479 diff --git a/init/Kconfig b/init/Kconfig
63480 index 3f42cd6..613f41d 100644
63481 --- a/init/Kconfig
63482 +++ b/init/Kconfig
63483 @@ -799,6 +799,7 @@ endif # CGROUPS
63484
63485 config CHECKPOINT_RESTORE
63486 bool "Checkpoint/restore support" if EXPERT
63487 + depends on !GRKERNSEC
63488 default n
63489 help
63490 Enables additional kernel features in a sake of checkpoint/restore.
63491 @@ -1249,7 +1250,7 @@ config SLUB_DEBUG
63492
63493 config COMPAT_BRK
63494 bool "Disable heap randomization"
63495 - default y
63496 + default n
63497 help
63498 Randomizing heap placement makes heap exploits harder, but it
63499 also breaks ancient binaries (including anything libc5 based).
63500 diff --git a/init/do_mounts.c b/init/do_mounts.c
63501 index 2974c8b..0b863ae 100644
63502 --- a/init/do_mounts.c
63503 +++ b/init/do_mounts.c
63504 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
63505 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
63506 {
63507 struct super_block *s;
63508 - int err = sys_mount(name, "/root", fs, flags, data);
63509 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
63510 if (err)
63511 return err;
63512
63513 - sys_chdir((const char __user __force *)"/root");
63514 + sys_chdir((const char __force_user *)"/root");
63515 s = current->fs->pwd.dentry->d_sb;
63516 ROOT_DEV = s->s_dev;
63517 printk(KERN_INFO
63518 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
63519 va_start(args, fmt);
63520 vsprintf(buf, fmt, args);
63521 va_end(args);
63522 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
63523 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
63524 if (fd >= 0) {
63525 sys_ioctl(fd, FDEJECT, 0);
63526 sys_close(fd);
63527 }
63528 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
63529 - fd = sys_open("/dev/console", O_RDWR, 0);
63530 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
63531 if (fd >= 0) {
63532 sys_ioctl(fd, TCGETS, (long)&termios);
63533 termios.c_lflag &= ~ICANON;
63534 sys_ioctl(fd, TCSETSF, (long)&termios);
63535 - sys_read(fd, &c, 1);
63536 + sys_read(fd, (char __user *)&c, 1);
63537 termios.c_lflag |= ICANON;
63538 sys_ioctl(fd, TCSETSF, (long)&termios);
63539 sys_close(fd);
63540 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
63541 mount_root();
63542 out:
63543 devtmpfs_mount("dev");
63544 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
63545 - sys_chroot((const char __user __force *)".");
63546 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
63547 + sys_chroot((const char __force_user *)".");
63548 }
63549 diff --git a/init/do_mounts.h b/init/do_mounts.h
63550 index f5b978a..69dbfe8 100644
63551 --- a/init/do_mounts.h
63552 +++ b/init/do_mounts.h
63553 @@ -15,15 +15,15 @@ extern int root_mountflags;
63554
63555 static inline int create_dev(char *name, dev_t dev)
63556 {
63557 - sys_unlink(name);
63558 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
63559 + sys_unlink((char __force_user *)name);
63560 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
63561 }
63562
63563 #if BITS_PER_LONG == 32
63564 static inline u32 bstat(char *name)
63565 {
63566 struct stat64 stat;
63567 - if (sys_stat64(name, &stat) != 0)
63568 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
63569 return 0;
63570 if (!S_ISBLK(stat.st_mode))
63571 return 0;
63572 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
63573 static inline u32 bstat(char *name)
63574 {
63575 struct stat stat;
63576 - if (sys_newstat(name, &stat) != 0)
63577 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
63578 return 0;
63579 if (!S_ISBLK(stat.st_mode))
63580 return 0;
63581 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
63582 index 3098a38..253064e 100644
63583 --- a/init/do_mounts_initrd.c
63584 +++ b/init/do_mounts_initrd.c
63585 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
63586 create_dev("/dev/root.old", Root_RAM0);
63587 /* mount initrd on rootfs' /root */
63588 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
63589 - sys_mkdir("/old", 0700);
63590 - root_fd = sys_open("/", 0, 0);
63591 - old_fd = sys_open("/old", 0, 0);
63592 + sys_mkdir((const char __force_user *)"/old", 0700);
63593 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
63594 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
63595 /* move initrd over / and chdir/chroot in initrd root */
63596 - sys_chdir("/root");
63597 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
63598 - sys_chroot(".");
63599 + sys_chdir((const char __force_user *)"/root");
63600 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
63601 + sys_chroot((const char __force_user *)".");
63602
63603 /*
63604 * In case that a resume from disk is carried out by linuxrc or one of
63605 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
63606
63607 /* move initrd to rootfs' /old */
63608 sys_fchdir(old_fd);
63609 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
63610 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
63611 /* switch root and cwd back to / of rootfs */
63612 sys_fchdir(root_fd);
63613 - sys_chroot(".");
63614 + sys_chroot((const char __force_user *)".");
63615 sys_close(old_fd);
63616 sys_close(root_fd);
63617
63618 if (new_decode_dev(real_root_dev) == Root_RAM0) {
63619 - sys_chdir("/old");
63620 + sys_chdir((const char __force_user *)"/old");
63621 return;
63622 }
63623
63624 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
63625 mount_root();
63626
63627 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
63628 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
63629 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
63630 if (!error)
63631 printk("okay\n");
63632 else {
63633 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
63634 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
63635 if (error == -ENOENT)
63636 printk("/initrd does not exist. Ignored.\n");
63637 else
63638 printk("failed\n");
63639 printk(KERN_NOTICE "Unmounting old root\n");
63640 - sys_umount("/old", MNT_DETACH);
63641 + sys_umount((char __force_user *)"/old", MNT_DETACH);
63642 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
63643 if (fd < 0) {
63644 error = fd;
63645 @@ -116,11 +116,11 @@ int __init initrd_load(void)
63646 * mounted in the normal path.
63647 */
63648 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
63649 - sys_unlink("/initrd.image");
63650 + sys_unlink((const char __force_user *)"/initrd.image");
63651 handle_initrd();
63652 return 1;
63653 }
63654 }
63655 - sys_unlink("/initrd.image");
63656 + sys_unlink((const char __force_user *)"/initrd.image");
63657 return 0;
63658 }
63659 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
63660 index 32c4799..c27ee74 100644
63661 --- a/init/do_mounts_md.c
63662 +++ b/init/do_mounts_md.c
63663 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
63664 partitioned ? "_d" : "", minor,
63665 md_setup_args[ent].device_names);
63666
63667 - fd = sys_open(name, 0, 0);
63668 + fd = sys_open((char __force_user *)name, 0, 0);
63669 if (fd < 0) {
63670 printk(KERN_ERR "md: open failed - cannot start "
63671 "array %s\n", name);
63672 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
63673 * array without it
63674 */
63675 sys_close(fd);
63676 - fd = sys_open(name, 0, 0);
63677 + fd = sys_open((char __force_user *)name, 0, 0);
63678 sys_ioctl(fd, BLKRRPART, 0);
63679 }
63680 sys_close(fd);
63681 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
63682
63683 wait_for_device_probe();
63684
63685 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
63686 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
63687 if (fd >= 0) {
63688 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
63689 sys_close(fd);
63690 diff --git a/init/initramfs.c b/init/initramfs.c
63691 index 8216c30..25e8e32 100644
63692 --- a/init/initramfs.c
63693 +++ b/init/initramfs.c
63694 @@ -74,7 +74,7 @@ static void __init free_hash(void)
63695 }
63696 }
63697
63698 -static long __init do_utime(char __user *filename, time_t mtime)
63699 +static long __init do_utime(__force char __user *filename, time_t mtime)
63700 {
63701 struct timespec t[2];
63702
63703 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
63704 struct dir_entry *de, *tmp;
63705 list_for_each_entry_safe(de, tmp, &dir_list, list) {
63706 list_del(&de->list);
63707 - do_utime(de->name, de->mtime);
63708 + do_utime((char __force_user *)de->name, de->mtime);
63709 kfree(de->name);
63710 kfree(de);
63711 }
63712 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
63713 if (nlink >= 2) {
63714 char *old = find_link(major, minor, ino, mode, collected);
63715 if (old)
63716 - return (sys_link(old, collected) < 0) ? -1 : 1;
63717 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
63718 }
63719 return 0;
63720 }
63721 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
63722 {
63723 struct stat st;
63724
63725 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
63726 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
63727 if (S_ISDIR(st.st_mode))
63728 - sys_rmdir(path);
63729 + sys_rmdir((char __force_user *)path);
63730 else
63731 - sys_unlink(path);
63732 + sys_unlink((char __force_user *)path);
63733 }
63734 }
63735
63736 @@ -305,7 +305,7 @@ static int __init do_name(void)
63737 int openflags = O_WRONLY|O_CREAT;
63738 if (ml != 1)
63739 openflags |= O_TRUNC;
63740 - wfd = sys_open(collected, openflags, mode);
63741 + wfd = sys_open((char __force_user *)collected, openflags, mode);
63742
63743 if (wfd >= 0) {
63744 sys_fchown(wfd, uid, gid);
63745 @@ -317,17 +317,17 @@ static int __init do_name(void)
63746 }
63747 }
63748 } else if (S_ISDIR(mode)) {
63749 - sys_mkdir(collected, mode);
63750 - sys_chown(collected, uid, gid);
63751 - sys_chmod(collected, mode);
63752 + sys_mkdir((char __force_user *)collected, mode);
63753 + sys_chown((char __force_user *)collected, uid, gid);
63754 + sys_chmod((char __force_user *)collected, mode);
63755 dir_add(collected, mtime);
63756 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
63757 S_ISFIFO(mode) || S_ISSOCK(mode)) {
63758 if (maybe_link() == 0) {
63759 - sys_mknod(collected, mode, rdev);
63760 - sys_chown(collected, uid, gid);
63761 - sys_chmod(collected, mode);
63762 - do_utime(collected, mtime);
63763 + sys_mknod((char __force_user *)collected, mode, rdev);
63764 + sys_chown((char __force_user *)collected, uid, gid);
63765 + sys_chmod((char __force_user *)collected, mode);
63766 + do_utime((char __force_user *)collected, mtime);
63767 }
63768 }
63769 return 0;
63770 @@ -336,15 +336,15 @@ static int __init do_name(void)
63771 static int __init do_copy(void)
63772 {
63773 if (count >= body_len) {
63774 - sys_write(wfd, victim, body_len);
63775 + sys_write(wfd, (char __force_user *)victim, body_len);
63776 sys_close(wfd);
63777 - do_utime(vcollected, mtime);
63778 + do_utime((char __force_user *)vcollected, mtime);
63779 kfree(vcollected);
63780 eat(body_len);
63781 state = SkipIt;
63782 return 0;
63783 } else {
63784 - sys_write(wfd, victim, count);
63785 + sys_write(wfd, (char __force_user *)victim, count);
63786 body_len -= count;
63787 eat(count);
63788 return 1;
63789 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
63790 {
63791 collected[N_ALIGN(name_len) + body_len] = '\0';
63792 clean_path(collected, 0);
63793 - sys_symlink(collected + N_ALIGN(name_len), collected);
63794 - sys_lchown(collected, uid, gid);
63795 - do_utime(collected, mtime);
63796 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
63797 + sys_lchown((char __force_user *)collected, uid, gid);
63798 + do_utime((char __force_user *)collected, mtime);
63799 state = SkipIt;
63800 next_state = Reset;
63801 return 0;
63802 diff --git a/init/main.c b/init/main.c
63803 index ff49a6d..5fa0429 100644
63804 --- a/init/main.c
63805 +++ b/init/main.c
63806 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
63807 extern void tc_init(void);
63808 #endif
63809
63810 +extern void grsecurity_init(void);
63811 +
63812 /*
63813 * Debug helper: via this flag we know that we are in 'early bootup code'
63814 * where only the boot processor is running with IRQ disabled. This means
63815 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
63816
63817 __setup("reset_devices", set_reset_devices);
63818
63819 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
63820 +extern char pax_enter_kernel_user[];
63821 +extern char pax_exit_kernel_user[];
63822 +extern pgdval_t clone_pgd_mask;
63823 +#endif
63824 +
63825 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
63826 +static int __init setup_pax_nouderef(char *str)
63827 +{
63828 +#ifdef CONFIG_X86_32
63829 + unsigned int cpu;
63830 + struct desc_struct *gdt;
63831 +
63832 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
63833 + gdt = get_cpu_gdt_table(cpu);
63834 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
63835 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
63836 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
63837 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
63838 + }
63839 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
63840 +#else
63841 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
63842 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
63843 + clone_pgd_mask = ~(pgdval_t)0UL;
63844 +#endif
63845 +
63846 + return 0;
63847 +}
63848 +early_param("pax_nouderef", setup_pax_nouderef);
63849 +#endif
63850 +
63851 +#ifdef CONFIG_PAX_SOFTMODE
63852 +int pax_softmode;
63853 +
63854 +static int __init setup_pax_softmode(char *str)
63855 +{
63856 + get_option(&str, &pax_softmode);
63857 + return 1;
63858 +}
63859 +__setup("pax_softmode=", setup_pax_softmode);
63860 +#endif
63861 +
63862 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
63863 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
63864 static const char *panic_later, *panic_param;
63865 @@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
63866 {
63867 int count = preempt_count();
63868 int ret;
63869 + const char *msg1 = "", *msg2 = "";
63870
63871 if (initcall_debug)
63872 ret = do_one_initcall_debug(fn);
63873 @@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
63874 sprintf(msgbuf, "error code %d ", ret);
63875
63876 if (preempt_count() != count) {
63877 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
63878 + msg1 = " preemption imbalance";
63879 preempt_count() = count;
63880 }
63881 if (irqs_disabled()) {
63882 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
63883 + msg2 = " disabled interrupts";
63884 local_irq_enable();
63885 }
63886 - if (msgbuf[0]) {
63887 - printk("initcall %pF returned with %s\n", fn, msgbuf);
63888 + if (msgbuf[0] || *msg1 || *msg2) {
63889 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
63890 }
63891
63892 return ret;
63893 @@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
63894 do_basic_setup();
63895
63896 /* Open the /dev/console on the rootfs, this should never fail */
63897 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
63898 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
63899 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
63900
63901 (void) sys_dup(0);
63902 @@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
63903 if (!ramdisk_execute_command)
63904 ramdisk_execute_command = "/init";
63905
63906 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
63907 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
63908 ramdisk_execute_command = NULL;
63909 prepare_namespace();
63910 }
63911
63912 + grsecurity_init();
63913 +
63914 /*
63915 * Ok, we have completed the initial bootup, and
63916 * we're essentially up and running. Get rid of the
63917 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
63918 index 86ee272..773d937 100644
63919 --- a/ipc/mqueue.c
63920 +++ b/ipc/mqueue.c
63921 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
63922 mq_bytes = (mq_msg_tblsz +
63923 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
63924
63925 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
63926 spin_lock(&mq_lock);
63927 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
63928 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
63929 diff --git a/ipc/msg.c b/ipc/msg.c
63930 index 7385de2..a8180e08 100644
63931 --- a/ipc/msg.c
63932 +++ b/ipc/msg.c
63933 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
63934 return security_msg_queue_associate(msq, msgflg);
63935 }
63936
63937 +static struct ipc_ops msg_ops = {
63938 + .getnew = newque,
63939 + .associate = msg_security,
63940 + .more_checks = NULL
63941 +};
63942 +
63943 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
63944 {
63945 struct ipc_namespace *ns;
63946 - struct ipc_ops msg_ops;
63947 struct ipc_params msg_params;
63948
63949 ns = current->nsproxy->ipc_ns;
63950
63951 - msg_ops.getnew = newque;
63952 - msg_ops.associate = msg_security;
63953 - msg_ops.more_checks = NULL;
63954 -
63955 msg_params.key = key;
63956 msg_params.flg = msgflg;
63957
63958 diff --git a/ipc/sem.c b/ipc/sem.c
63959 index 5215a81..cfc0cac 100644
63960 --- a/ipc/sem.c
63961 +++ b/ipc/sem.c
63962 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
63963 return 0;
63964 }
63965
63966 +static struct ipc_ops sem_ops = {
63967 + .getnew = newary,
63968 + .associate = sem_security,
63969 + .more_checks = sem_more_checks
63970 +};
63971 +
63972 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
63973 {
63974 struct ipc_namespace *ns;
63975 - struct ipc_ops sem_ops;
63976 struct ipc_params sem_params;
63977
63978 ns = current->nsproxy->ipc_ns;
63979 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
63980 if (nsems < 0 || nsems > ns->sc_semmsl)
63981 return -EINVAL;
63982
63983 - sem_ops.getnew = newary;
63984 - sem_ops.associate = sem_security;
63985 - sem_ops.more_checks = sem_more_checks;
63986 -
63987 sem_params.key = key;
63988 sem_params.flg = semflg;
63989 sem_params.u.nsems = nsems;
63990 diff --git a/ipc/shm.c b/ipc/shm.c
63991 index b76be5b..859e750 100644
63992 --- a/ipc/shm.c
63993 +++ b/ipc/shm.c
63994 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
63995 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
63996 #endif
63997
63998 +#ifdef CONFIG_GRKERNSEC
63999 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64000 + const time_t shm_createtime, const uid_t cuid,
64001 + const int shmid);
64002 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64003 + const time_t shm_createtime);
64004 +#endif
64005 +
64006 void shm_init_ns(struct ipc_namespace *ns)
64007 {
64008 ns->shm_ctlmax = SHMMAX;
64009 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
64010 shp->shm_lprid = 0;
64011 shp->shm_atim = shp->shm_dtim = 0;
64012 shp->shm_ctim = get_seconds();
64013 +#ifdef CONFIG_GRKERNSEC
64014 + {
64015 + struct timespec timeval;
64016 + do_posix_clock_monotonic_gettime(&timeval);
64017 +
64018 + shp->shm_createtime = timeval.tv_sec;
64019 + }
64020 +#endif
64021 shp->shm_segsz = size;
64022 shp->shm_nattch = 0;
64023 shp->shm_file = file;
64024 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
64025 return 0;
64026 }
64027
64028 +static struct ipc_ops shm_ops = {
64029 + .getnew = newseg,
64030 + .associate = shm_security,
64031 + .more_checks = shm_more_checks
64032 +};
64033 +
64034 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
64035 {
64036 struct ipc_namespace *ns;
64037 - struct ipc_ops shm_ops;
64038 struct ipc_params shm_params;
64039
64040 ns = current->nsproxy->ipc_ns;
64041
64042 - shm_ops.getnew = newseg;
64043 - shm_ops.associate = shm_security;
64044 - shm_ops.more_checks = shm_more_checks;
64045 -
64046 shm_params.key = key;
64047 shm_params.flg = shmflg;
64048 shm_params.u.size = size;
64049 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64050 f_mode = FMODE_READ | FMODE_WRITE;
64051 }
64052 if (shmflg & SHM_EXEC) {
64053 +
64054 +#ifdef CONFIG_PAX_MPROTECT
64055 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
64056 + goto out;
64057 +#endif
64058 +
64059 prot |= PROT_EXEC;
64060 acc_mode |= S_IXUGO;
64061 }
64062 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64063 if (err)
64064 goto out_unlock;
64065
64066 +#ifdef CONFIG_GRKERNSEC
64067 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
64068 + shp->shm_perm.cuid, shmid) ||
64069 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
64070 + err = -EACCES;
64071 + goto out_unlock;
64072 + }
64073 +#endif
64074 +
64075 path = shp->shm_file->f_path;
64076 path_get(&path);
64077 shp->shm_nattch++;
64078 +#ifdef CONFIG_GRKERNSEC
64079 + shp->shm_lapid = current->pid;
64080 +#endif
64081 size = i_size_read(path.dentry->d_inode);
64082 shm_unlock(shp);
64083
64084 diff --git a/kernel/acct.c b/kernel/acct.c
64085 index 02e6167..54824f7 100644
64086 --- a/kernel/acct.c
64087 +++ b/kernel/acct.c
64088 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
64089 */
64090 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
64091 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
64092 - file->f_op->write(file, (char *)&ac,
64093 + file->f_op->write(file, (char __force_user *)&ac,
64094 sizeof(acct_t), &file->f_pos);
64095 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
64096 set_fs(fs);
64097 diff --git a/kernel/audit.c b/kernel/audit.c
64098 index bb0eb5b..cf2a03a 100644
64099 --- a/kernel/audit.c
64100 +++ b/kernel/audit.c
64101 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
64102 3) suppressed due to audit_rate_limit
64103 4) suppressed due to audit_backlog_limit
64104 */
64105 -static atomic_t audit_lost = ATOMIC_INIT(0);
64106 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
64107
64108 /* The netlink socket. */
64109 static struct sock *audit_sock;
64110 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
64111 unsigned long now;
64112 int print;
64113
64114 - atomic_inc(&audit_lost);
64115 + atomic_inc_unchecked(&audit_lost);
64116
64117 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
64118
64119 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
64120 printk(KERN_WARNING
64121 "audit: audit_lost=%d audit_rate_limit=%d "
64122 "audit_backlog_limit=%d\n",
64123 - atomic_read(&audit_lost),
64124 + atomic_read_unchecked(&audit_lost),
64125 audit_rate_limit,
64126 audit_backlog_limit);
64127 audit_panic(message);
64128 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
64129 status_set.pid = audit_pid;
64130 status_set.rate_limit = audit_rate_limit;
64131 status_set.backlog_limit = audit_backlog_limit;
64132 - status_set.lost = atomic_read(&audit_lost);
64133 + status_set.lost = atomic_read_unchecked(&audit_lost);
64134 status_set.backlog = skb_queue_len(&audit_skb_queue);
64135 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
64136 &status_set, sizeof(status_set));
64137 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
64138 index af1de0f..06dfe57 100644
64139 --- a/kernel/auditsc.c
64140 +++ b/kernel/auditsc.c
64141 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
64142 }
64143
64144 /* global counter which is incremented every time something logs in */
64145 -static atomic_t session_id = ATOMIC_INIT(0);
64146 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
64147
64148 /**
64149 * audit_set_loginuid - set current task's audit_context loginuid
64150 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
64151 return -EPERM;
64152 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
64153
64154 - sessionid = atomic_inc_return(&session_id);
64155 + sessionid = atomic_inc_return_unchecked(&session_id);
64156 if (context && context->in_syscall) {
64157 struct audit_buffer *ab;
64158
64159 diff --git a/kernel/capability.c b/kernel/capability.c
64160 index 3f1adb6..c564db0 100644
64161 --- a/kernel/capability.c
64162 +++ b/kernel/capability.c
64163 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
64164 * before modification is attempted and the application
64165 * fails.
64166 */
64167 + if (tocopy > ARRAY_SIZE(kdata))
64168 + return -EFAULT;
64169 +
64170 if (copy_to_user(dataptr, kdata, tocopy
64171 * sizeof(struct __user_cap_data_struct))) {
64172 return -EFAULT;
64173 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
64174 int ret;
64175
64176 rcu_read_lock();
64177 - ret = security_capable(__task_cred(t), ns, cap);
64178 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
64179 + gr_task_is_capable(t, __task_cred(t), cap);
64180 rcu_read_unlock();
64181
64182 - return (ret == 0);
64183 + return ret;
64184 }
64185
64186 /**
64187 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
64188 int ret;
64189
64190 rcu_read_lock();
64191 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
64192 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
64193 rcu_read_unlock();
64194
64195 - return (ret == 0);
64196 + return ret;
64197 }
64198
64199 /**
64200 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
64201 BUG();
64202 }
64203
64204 - if (security_capable(current_cred(), ns, cap) == 0) {
64205 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
64206 current->flags |= PF_SUPERPRIV;
64207 return true;
64208 }
64209 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
64210 }
64211 EXPORT_SYMBOL(ns_capable);
64212
64213 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
64214 +{
64215 + if (unlikely(!cap_valid(cap))) {
64216 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
64217 + BUG();
64218 + }
64219 +
64220 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
64221 + current->flags |= PF_SUPERPRIV;
64222 + return true;
64223 + }
64224 + return false;
64225 +}
64226 +EXPORT_SYMBOL(ns_capable_nolog);
64227 +
64228 /**
64229 * capable - Determine if the current task has a superior capability in effect
64230 * @cap: The capability to be tested for
64231 @@ -408,6 +427,12 @@ bool capable(int cap)
64232 }
64233 EXPORT_SYMBOL(capable);
64234
64235 +bool capable_nolog(int cap)
64236 +{
64237 + return ns_capable_nolog(&init_user_ns, cap);
64238 +}
64239 +EXPORT_SYMBOL(capable_nolog);
64240 +
64241 /**
64242 * nsown_capable - Check superior capability to one's own user_ns
64243 * @cap: The capability in question
64244 diff --git a/kernel/compat.c b/kernel/compat.c
64245 index f346ced..aa2b1f4 100644
64246 --- a/kernel/compat.c
64247 +++ b/kernel/compat.c
64248 @@ -13,6 +13,7 @@
64249
64250 #include <linux/linkage.h>
64251 #include <linux/compat.h>
64252 +#include <linux/module.h>
64253 #include <linux/errno.h>
64254 #include <linux/time.h>
64255 #include <linux/signal.h>
64256 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
64257 mm_segment_t oldfs;
64258 long ret;
64259
64260 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
64261 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
64262 oldfs = get_fs();
64263 set_fs(KERNEL_DS);
64264 ret = hrtimer_nanosleep_restart(restart);
64265 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
64266 oldfs = get_fs();
64267 set_fs(KERNEL_DS);
64268 ret = hrtimer_nanosleep(&tu,
64269 - rmtp ? (struct timespec __user *)&rmt : NULL,
64270 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
64271 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
64272 set_fs(oldfs);
64273
64274 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
64275 mm_segment_t old_fs = get_fs();
64276
64277 set_fs(KERNEL_DS);
64278 - ret = sys_sigpending((old_sigset_t __user *) &s);
64279 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
64280 set_fs(old_fs);
64281 if (ret == 0)
64282 ret = put_user(s, set);
64283 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
64284 old_fs = get_fs();
64285 set_fs(KERNEL_DS);
64286 ret = sys_sigprocmask(how,
64287 - set ? (old_sigset_t __user *) &s : NULL,
64288 - oset ? (old_sigset_t __user *) &s : NULL);
64289 + set ? (old_sigset_t __force_user *) &s : NULL,
64290 + oset ? (old_sigset_t __force_user *) &s : NULL);
64291 set_fs(old_fs);
64292 if (ret == 0)
64293 if (oset)
64294 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
64295 mm_segment_t old_fs = get_fs();
64296
64297 set_fs(KERNEL_DS);
64298 - ret = sys_old_getrlimit(resource, &r);
64299 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
64300 set_fs(old_fs);
64301
64302 if (!ret) {
64303 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
64304 mm_segment_t old_fs = get_fs();
64305
64306 set_fs(KERNEL_DS);
64307 - ret = sys_getrusage(who, (struct rusage __user *) &r);
64308 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
64309 set_fs(old_fs);
64310
64311 if (ret)
64312 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
64313 set_fs (KERNEL_DS);
64314 ret = sys_wait4(pid,
64315 (stat_addr ?
64316 - (unsigned int __user *) &status : NULL),
64317 - options, (struct rusage __user *) &r);
64318 + (unsigned int __force_user *) &status : NULL),
64319 + options, (struct rusage __force_user *) &r);
64320 set_fs (old_fs);
64321
64322 if (ret > 0) {
64323 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
64324 memset(&info, 0, sizeof(info));
64325
64326 set_fs(KERNEL_DS);
64327 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
64328 - uru ? (struct rusage __user *)&ru : NULL);
64329 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
64330 + uru ? (struct rusage __force_user *)&ru : NULL);
64331 set_fs(old_fs);
64332
64333 if ((ret < 0) || (info.si_signo == 0))
64334 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
64335 oldfs = get_fs();
64336 set_fs(KERNEL_DS);
64337 err = sys_timer_settime(timer_id, flags,
64338 - (struct itimerspec __user *) &newts,
64339 - (struct itimerspec __user *) &oldts);
64340 + (struct itimerspec __force_user *) &newts,
64341 + (struct itimerspec __force_user *) &oldts);
64342 set_fs(oldfs);
64343 if (!err && old && put_compat_itimerspec(old, &oldts))
64344 return -EFAULT;
64345 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
64346 oldfs = get_fs();
64347 set_fs(KERNEL_DS);
64348 err = sys_timer_gettime(timer_id,
64349 - (struct itimerspec __user *) &ts);
64350 + (struct itimerspec __force_user *) &ts);
64351 set_fs(oldfs);
64352 if (!err && put_compat_itimerspec(setting, &ts))
64353 return -EFAULT;
64354 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
64355 oldfs = get_fs();
64356 set_fs(KERNEL_DS);
64357 err = sys_clock_settime(which_clock,
64358 - (struct timespec __user *) &ts);
64359 + (struct timespec __force_user *) &ts);
64360 set_fs(oldfs);
64361 return err;
64362 }
64363 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
64364 oldfs = get_fs();
64365 set_fs(KERNEL_DS);
64366 err = sys_clock_gettime(which_clock,
64367 - (struct timespec __user *) &ts);
64368 + (struct timespec __force_user *) &ts);
64369 set_fs(oldfs);
64370 if (!err && put_compat_timespec(&ts, tp))
64371 return -EFAULT;
64372 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
64373
64374 oldfs = get_fs();
64375 set_fs(KERNEL_DS);
64376 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
64377 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
64378 set_fs(oldfs);
64379
64380 err = compat_put_timex(utp, &txc);
64381 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
64382 oldfs = get_fs();
64383 set_fs(KERNEL_DS);
64384 err = sys_clock_getres(which_clock,
64385 - (struct timespec __user *) &ts);
64386 + (struct timespec __force_user *) &ts);
64387 set_fs(oldfs);
64388 if (!err && tp && put_compat_timespec(&ts, tp))
64389 return -EFAULT;
64390 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
64391 long err;
64392 mm_segment_t oldfs;
64393 struct timespec tu;
64394 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
64395 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
64396
64397 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
64398 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
64399 oldfs = get_fs();
64400 set_fs(KERNEL_DS);
64401 err = clock_nanosleep_restart(restart);
64402 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
64403 oldfs = get_fs();
64404 set_fs(KERNEL_DS);
64405 err = sys_clock_nanosleep(which_clock, flags,
64406 - (struct timespec __user *) &in,
64407 - (struct timespec __user *) &out);
64408 + (struct timespec __force_user *) &in,
64409 + (struct timespec __force_user *) &out);
64410 set_fs(oldfs);
64411
64412 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
64413 diff --git a/kernel/configs.c b/kernel/configs.c
64414 index 42e8fa0..9e7406b 100644
64415 --- a/kernel/configs.c
64416 +++ b/kernel/configs.c
64417 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
64418 struct proc_dir_entry *entry;
64419
64420 /* create the current config file */
64421 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64422 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
64423 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
64424 + &ikconfig_file_ops);
64425 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64426 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
64427 + &ikconfig_file_ops);
64428 +#endif
64429 +#else
64430 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
64431 &ikconfig_file_ops);
64432 +#endif
64433 +
64434 if (!entry)
64435 return -ENOMEM;
64436
64437 diff --git a/kernel/cred.c b/kernel/cred.c
64438 index 5791612..a3c04dc 100644
64439 --- a/kernel/cred.c
64440 +++ b/kernel/cred.c
64441 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
64442 validate_creds(cred);
64443 put_cred(cred);
64444 }
64445 +
64446 +#ifdef CONFIG_GRKERNSEC_SETXID
64447 + cred = (struct cred *) tsk->delayed_cred;
64448 + if (cred) {
64449 + tsk->delayed_cred = NULL;
64450 + validate_creds(cred);
64451 + put_cred(cred);
64452 + }
64453 +#endif
64454 }
64455
64456 /**
64457 @@ -470,7 +479,7 @@ error_put:
64458 * Always returns 0 thus allowing this function to be tail-called at the end
64459 * of, say, sys_setgid().
64460 */
64461 -int commit_creds(struct cred *new)
64462 +static int __commit_creds(struct cred *new)
64463 {
64464 struct task_struct *task = current;
64465 const struct cred *old = task->real_cred;
64466 @@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
64467
64468 get_cred(new); /* we will require a ref for the subj creds too */
64469
64470 + gr_set_role_label(task, new->uid, new->gid);
64471 +
64472 /* dumpability changes */
64473 if (old->euid != new->euid ||
64474 old->egid != new->egid ||
64475 @@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
64476 put_cred(old);
64477 return 0;
64478 }
64479 +#ifdef CONFIG_GRKERNSEC_SETXID
64480 +extern int set_user(struct cred *new);
64481 +
64482 +void gr_delayed_cred_worker(void)
64483 +{
64484 + const struct cred *new = current->delayed_cred;
64485 + struct cred *ncred;
64486 +
64487 + current->delayed_cred = NULL;
64488 +
64489 + if (current_uid() && new != NULL) {
64490 + // from doing get_cred on it when queueing this
64491 + put_cred(new);
64492 + return;
64493 + } else if (new == NULL)
64494 + return;
64495 +
64496 + ncred = prepare_creds();
64497 + if (!ncred)
64498 + goto die;
64499 + // uids
64500 + ncred->uid = new->uid;
64501 + ncred->euid = new->euid;
64502 + ncred->suid = new->suid;
64503 + ncred->fsuid = new->fsuid;
64504 + // gids
64505 + ncred->gid = new->gid;
64506 + ncred->egid = new->egid;
64507 + ncred->sgid = new->sgid;
64508 + ncred->fsgid = new->fsgid;
64509 + // groups
64510 + if (set_groups(ncred, new->group_info) < 0) {
64511 + abort_creds(ncred);
64512 + goto die;
64513 + }
64514 + // caps
64515 + ncred->securebits = new->securebits;
64516 + ncred->cap_inheritable = new->cap_inheritable;
64517 + ncred->cap_permitted = new->cap_permitted;
64518 + ncred->cap_effective = new->cap_effective;
64519 + ncred->cap_bset = new->cap_bset;
64520 +
64521 + if (set_user(ncred)) {
64522 + abort_creds(ncred);
64523 + goto die;
64524 + }
64525 +
64526 + // from doing get_cred on it when queueing this
64527 + put_cred(new);
64528 +
64529 + __commit_creds(ncred);
64530 + return;
64531 +die:
64532 + // from doing get_cred on it when queueing this
64533 + put_cred(new);
64534 + do_group_exit(SIGKILL);
64535 +}
64536 +#endif
64537 +
64538 +int commit_creds(struct cred *new)
64539 +{
64540 +#ifdef CONFIG_GRKERNSEC_SETXID
64541 + struct task_struct *t;
64542 +
64543 + /* we won't get called with tasklist_lock held for writing
64544 + and interrupts disabled as the cred struct in that case is
64545 + init_cred
64546 + */
64547 + if (grsec_enable_setxid && !current_is_single_threaded() &&
64548 + !current_uid() && new->uid) {
64549 + rcu_read_lock();
64550 + read_lock(&tasklist_lock);
64551 + for (t = next_thread(current); t != current;
64552 + t = next_thread(t)) {
64553 + if (t->delayed_cred == NULL) {
64554 + t->delayed_cred = get_cred(new);
64555 + set_tsk_need_resched(t);
64556 + }
64557 + }
64558 + read_unlock(&tasklist_lock);
64559 + rcu_read_unlock();
64560 + }
64561 +#endif
64562 + return __commit_creds(new);
64563 +}
64564 +
64565 EXPORT_SYMBOL(commit_creds);
64566
64567 /**
64568 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
64569 index 0d7c087..01b8cef 100644
64570 --- a/kernel/debug/debug_core.c
64571 +++ b/kernel/debug/debug_core.c
64572 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
64573 */
64574 static atomic_t masters_in_kgdb;
64575 static atomic_t slaves_in_kgdb;
64576 -static atomic_t kgdb_break_tasklet_var;
64577 +static atomic_unchecked_t kgdb_break_tasklet_var;
64578 atomic_t kgdb_setting_breakpoint;
64579
64580 struct task_struct *kgdb_usethread;
64581 @@ -129,7 +129,7 @@ int kgdb_single_step;
64582 static pid_t kgdb_sstep_pid;
64583
64584 /* to keep track of the CPU which is doing the single stepping*/
64585 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
64586 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
64587
64588 /*
64589 * If you are debugging a problem where roundup (the collection of
64590 @@ -542,7 +542,7 @@ return_normal:
64591 * kernel will only try for the value of sstep_tries before
64592 * giving up and continuing on.
64593 */
64594 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
64595 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
64596 (kgdb_info[cpu].task &&
64597 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
64598 atomic_set(&kgdb_active, -1);
64599 @@ -636,8 +636,8 @@ cpu_master_loop:
64600 }
64601
64602 kgdb_restore:
64603 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
64604 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
64605 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
64606 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
64607 if (kgdb_info[sstep_cpu].task)
64608 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
64609 else
64610 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
64611 static void kgdb_tasklet_bpt(unsigned long ing)
64612 {
64613 kgdb_breakpoint();
64614 - atomic_set(&kgdb_break_tasklet_var, 0);
64615 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
64616 }
64617
64618 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
64619
64620 void kgdb_schedule_breakpoint(void)
64621 {
64622 - if (atomic_read(&kgdb_break_tasklet_var) ||
64623 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
64624 atomic_read(&kgdb_active) != -1 ||
64625 atomic_read(&kgdb_setting_breakpoint))
64626 return;
64627 - atomic_inc(&kgdb_break_tasklet_var);
64628 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
64629 tasklet_schedule(&kgdb_tasklet_breakpoint);
64630 }
64631 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
64632 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
64633 index e2ae734..08a4c5c 100644
64634 --- a/kernel/debug/kdb/kdb_main.c
64635 +++ b/kernel/debug/kdb/kdb_main.c
64636 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
64637 list_for_each_entry(mod, kdb_modules, list) {
64638
64639 kdb_printf("%-20s%8u 0x%p ", mod->name,
64640 - mod->core_size, (void *)mod);
64641 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
64642 #ifdef CONFIG_MODULE_UNLOAD
64643 kdb_printf("%4ld ", module_refcount(mod));
64644 #endif
64645 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
64646 kdb_printf(" (Loading)");
64647 else
64648 kdb_printf(" (Live)");
64649 - kdb_printf(" 0x%p", mod->module_core);
64650 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
64651
64652 #ifdef CONFIG_MODULE_UNLOAD
64653 {
64654 diff --git a/kernel/events/core.c b/kernel/events/core.c
64655 index 1b5c081..c375f83 100644
64656 --- a/kernel/events/core.c
64657 +++ b/kernel/events/core.c
64658 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
64659 return 0;
64660 }
64661
64662 -static atomic64_t perf_event_id;
64663 +static atomic64_unchecked_t perf_event_id;
64664
64665 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
64666 enum event_type_t event_type);
64667 @@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
64668
64669 static inline u64 perf_event_count(struct perf_event *event)
64670 {
64671 - return local64_read(&event->count) + atomic64_read(&event->child_count);
64672 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
64673 }
64674
64675 static u64 perf_event_read(struct perf_event *event)
64676 @@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
64677 mutex_lock(&event->child_mutex);
64678 total += perf_event_read(event);
64679 *enabled += event->total_time_enabled +
64680 - atomic64_read(&event->child_total_time_enabled);
64681 + atomic64_read_unchecked(&event->child_total_time_enabled);
64682 *running += event->total_time_running +
64683 - atomic64_read(&event->child_total_time_running);
64684 + atomic64_read_unchecked(&event->child_total_time_running);
64685
64686 list_for_each_entry(child, &event->child_list, child_list) {
64687 total += perf_event_read(child);
64688 @@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
64689 userpg->offset -= local64_read(&event->hw.prev_count);
64690
64691 userpg->time_enabled = enabled +
64692 - atomic64_read(&event->child_total_time_enabled);
64693 + atomic64_read_unchecked(&event->child_total_time_enabled);
64694
64695 userpg->time_running = running +
64696 - atomic64_read(&event->child_total_time_running);
64697 + atomic64_read_unchecked(&event->child_total_time_running);
64698
64699 barrier();
64700 ++userpg->lock;
64701 @@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
64702 values[n++] = perf_event_count(event);
64703 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
64704 values[n++] = enabled +
64705 - atomic64_read(&event->child_total_time_enabled);
64706 + atomic64_read_unchecked(&event->child_total_time_enabled);
64707 }
64708 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
64709 values[n++] = running +
64710 - atomic64_read(&event->child_total_time_running);
64711 + atomic64_read_unchecked(&event->child_total_time_running);
64712 }
64713 if (read_format & PERF_FORMAT_ID)
64714 values[n++] = primary_event_id(event);
64715 @@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
64716 * need to add enough zero bytes after the string to handle
64717 * the 64bit alignment we do later.
64718 */
64719 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
64720 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
64721 if (!buf) {
64722 name = strncpy(tmp, "//enomem", sizeof(tmp));
64723 goto got_name;
64724 }
64725 - name = d_path(&file->f_path, buf, PATH_MAX);
64726 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
64727 if (IS_ERR(name)) {
64728 name = strncpy(tmp, "//toolong", sizeof(tmp));
64729 goto got_name;
64730 @@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
64731 event->parent = parent_event;
64732
64733 event->ns = get_pid_ns(current->nsproxy->pid_ns);
64734 - event->id = atomic64_inc_return(&perf_event_id);
64735 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
64736
64737 event->state = PERF_EVENT_STATE_INACTIVE;
64738
64739 @@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
64740 /*
64741 * Add back the child's count to the parent's count:
64742 */
64743 - atomic64_add(child_val, &parent_event->child_count);
64744 - atomic64_add(child_event->total_time_enabled,
64745 + atomic64_add_unchecked(child_val, &parent_event->child_count);
64746 + atomic64_add_unchecked(child_event->total_time_enabled,
64747 &parent_event->child_total_time_enabled);
64748 - atomic64_add(child_event->total_time_running,
64749 + atomic64_add_unchecked(child_event->total_time_running,
64750 &parent_event->child_total_time_running);
64751
64752 /*
64753 diff --git a/kernel/exit.c b/kernel/exit.c
64754 index 4b4042f..5bdd8d5 100644
64755 --- a/kernel/exit.c
64756 +++ b/kernel/exit.c
64757 @@ -58,6 +58,10 @@
64758 #include <asm/pgtable.h>
64759 #include <asm/mmu_context.h>
64760
64761 +#ifdef CONFIG_GRKERNSEC
64762 +extern rwlock_t grsec_exec_file_lock;
64763 +#endif
64764 +
64765 static void exit_mm(struct task_struct * tsk);
64766
64767 static void __unhash_process(struct task_struct *p, bool group_dead)
64768 @@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
64769 struct task_struct *leader;
64770 int zap_leader;
64771 repeat:
64772 +#ifdef CONFIG_NET
64773 + gr_del_task_from_ip_table(p);
64774 +#endif
64775 +
64776 /* don't need to get the RCU readlock here - the process is dead and
64777 * can't be modifying its own credentials. But shut RCU-lockdep up */
64778 rcu_read_lock();
64779 @@ -381,7 +389,7 @@ int allow_signal(int sig)
64780 * know it'll be handled, so that they don't get converted to
64781 * SIGKILL or just silently dropped.
64782 */
64783 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
64784 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
64785 recalc_sigpending();
64786 spin_unlock_irq(&current->sighand->siglock);
64787 return 0;
64788 @@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
64789 vsnprintf(current->comm, sizeof(current->comm), name, args);
64790 va_end(args);
64791
64792 +#ifdef CONFIG_GRKERNSEC
64793 + write_lock(&grsec_exec_file_lock);
64794 + if (current->exec_file) {
64795 + fput(current->exec_file);
64796 + current->exec_file = NULL;
64797 + }
64798 + write_unlock(&grsec_exec_file_lock);
64799 +#endif
64800 +
64801 + gr_set_kernel_label(current);
64802 +
64803 /*
64804 * If we were started as result of loading a module, close all of the
64805 * user space pages. We don't need them, and if we didn't close them
64806 @@ -892,6 +911,8 @@ void do_exit(long code)
64807 struct task_struct *tsk = current;
64808 int group_dead;
64809
64810 + set_fs(USER_DS);
64811 +
64812 profile_task_exit(tsk);
64813
64814 WARN_ON(blk_needs_flush_plug(tsk));
64815 @@ -908,7 +929,6 @@ void do_exit(long code)
64816 * mm_release()->clear_child_tid() from writing to a user-controlled
64817 * kernel address.
64818 */
64819 - set_fs(USER_DS);
64820
64821 ptrace_event(PTRACE_EVENT_EXIT, code);
64822
64823 @@ -969,6 +989,9 @@ void do_exit(long code)
64824 tsk->exit_code = code;
64825 taskstats_exit(tsk, group_dead);
64826
64827 + gr_acl_handle_psacct(tsk, code);
64828 + gr_acl_handle_exit();
64829 +
64830 exit_mm(tsk);
64831
64832 if (group_dead)
64833 @@ -1085,7 +1108,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
64834 * Take down every thread in the group. This is called by fatal signals
64835 * as well as by sys_exit_group (below).
64836 */
64837 -void
64838 +__noreturn void
64839 do_group_exit(int exit_code)
64840 {
64841 struct signal_struct *sig = current->signal;
64842 diff --git a/kernel/fork.c b/kernel/fork.c
64843 index 26a7a67..a1053f9 100644
64844 --- a/kernel/fork.c
64845 +++ b/kernel/fork.c
64846 @@ -284,7 +284,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
64847 *stackend = STACK_END_MAGIC; /* for overflow detection */
64848
64849 #ifdef CONFIG_CC_STACKPROTECTOR
64850 - tsk->stack_canary = get_random_int();
64851 + tsk->stack_canary = pax_get_random_long();
64852 #endif
64853
64854 /*
64855 @@ -308,13 +308,77 @@ out:
64856 }
64857
64858 #ifdef CONFIG_MMU
64859 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
64860 +{
64861 + struct vm_area_struct *tmp;
64862 + unsigned long charge;
64863 + struct mempolicy *pol;
64864 + struct file *file;
64865 +
64866 + charge = 0;
64867 + if (mpnt->vm_flags & VM_ACCOUNT) {
64868 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
64869 + if (security_vm_enough_memory(len))
64870 + goto fail_nomem;
64871 + charge = len;
64872 + }
64873 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
64874 + if (!tmp)
64875 + goto fail_nomem;
64876 + *tmp = *mpnt;
64877 + tmp->vm_mm = mm;
64878 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
64879 + pol = mpol_dup(vma_policy(mpnt));
64880 + if (IS_ERR(pol))
64881 + goto fail_nomem_policy;
64882 + vma_set_policy(tmp, pol);
64883 + if (anon_vma_fork(tmp, mpnt))
64884 + goto fail_nomem_anon_vma_fork;
64885 + tmp->vm_flags &= ~VM_LOCKED;
64886 + tmp->vm_next = tmp->vm_prev = NULL;
64887 + tmp->vm_mirror = NULL;
64888 + file = tmp->vm_file;
64889 + if (file) {
64890 + struct inode *inode = file->f_path.dentry->d_inode;
64891 + struct address_space *mapping = file->f_mapping;
64892 +
64893 + get_file(file);
64894 + if (tmp->vm_flags & VM_DENYWRITE)
64895 + atomic_dec(&inode->i_writecount);
64896 + mutex_lock(&mapping->i_mmap_mutex);
64897 + if (tmp->vm_flags & VM_SHARED)
64898 + mapping->i_mmap_writable++;
64899 + flush_dcache_mmap_lock(mapping);
64900 + /* insert tmp into the share list, just after mpnt */
64901 + vma_prio_tree_add(tmp, mpnt);
64902 + flush_dcache_mmap_unlock(mapping);
64903 + mutex_unlock(&mapping->i_mmap_mutex);
64904 + }
64905 +
64906 + /*
64907 + * Clear hugetlb-related page reserves for children. This only
64908 + * affects MAP_PRIVATE mappings. Faults generated by the child
64909 + * are not guaranteed to succeed, even if read-only
64910 + */
64911 + if (is_vm_hugetlb_page(tmp))
64912 + reset_vma_resv_huge_pages(tmp);
64913 +
64914 + return tmp;
64915 +
64916 +fail_nomem_anon_vma_fork:
64917 + mpol_put(pol);
64918 +fail_nomem_policy:
64919 + kmem_cache_free(vm_area_cachep, tmp);
64920 +fail_nomem:
64921 + vm_unacct_memory(charge);
64922 + return NULL;
64923 +}
64924 +
64925 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64926 {
64927 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
64928 struct rb_node **rb_link, *rb_parent;
64929 int retval;
64930 - unsigned long charge;
64931 - struct mempolicy *pol;
64932
64933 down_write(&oldmm->mmap_sem);
64934 flush_cache_dup_mm(oldmm);
64935 @@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64936 mm->locked_vm = 0;
64937 mm->mmap = NULL;
64938 mm->mmap_cache = NULL;
64939 - mm->free_area_cache = oldmm->mmap_base;
64940 - mm->cached_hole_size = ~0UL;
64941 + mm->free_area_cache = oldmm->free_area_cache;
64942 + mm->cached_hole_size = oldmm->cached_hole_size;
64943 mm->map_count = 0;
64944 cpumask_clear(mm_cpumask(mm));
64945 mm->mm_rb = RB_ROOT;
64946 @@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64947
64948 prev = NULL;
64949 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
64950 - struct file *file;
64951 -
64952 if (mpnt->vm_flags & VM_DONTCOPY) {
64953 long pages = vma_pages(mpnt);
64954 mm->total_vm -= pages;
64955 @@ -352,53 +414,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64956 -pages);
64957 continue;
64958 }
64959 - charge = 0;
64960 - if (mpnt->vm_flags & VM_ACCOUNT) {
64961 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
64962 - if (security_vm_enough_memory(len))
64963 - goto fail_nomem;
64964 - charge = len;
64965 + tmp = dup_vma(mm, mpnt);
64966 + if (!tmp) {
64967 + retval = -ENOMEM;
64968 + goto out;
64969 }
64970 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
64971 - if (!tmp)
64972 - goto fail_nomem;
64973 - *tmp = *mpnt;
64974 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
64975 - pol = mpol_dup(vma_policy(mpnt));
64976 - retval = PTR_ERR(pol);
64977 - if (IS_ERR(pol))
64978 - goto fail_nomem_policy;
64979 - vma_set_policy(tmp, pol);
64980 - tmp->vm_mm = mm;
64981 - if (anon_vma_fork(tmp, mpnt))
64982 - goto fail_nomem_anon_vma_fork;
64983 - tmp->vm_flags &= ~VM_LOCKED;
64984 - tmp->vm_next = tmp->vm_prev = NULL;
64985 - file = tmp->vm_file;
64986 - if (file) {
64987 - struct inode *inode = file->f_path.dentry->d_inode;
64988 - struct address_space *mapping = file->f_mapping;
64989 -
64990 - get_file(file);
64991 - if (tmp->vm_flags & VM_DENYWRITE)
64992 - atomic_dec(&inode->i_writecount);
64993 - mutex_lock(&mapping->i_mmap_mutex);
64994 - if (tmp->vm_flags & VM_SHARED)
64995 - mapping->i_mmap_writable++;
64996 - flush_dcache_mmap_lock(mapping);
64997 - /* insert tmp into the share list, just after mpnt */
64998 - vma_prio_tree_add(tmp, mpnt);
64999 - flush_dcache_mmap_unlock(mapping);
65000 - mutex_unlock(&mapping->i_mmap_mutex);
65001 - }
65002 -
65003 - /*
65004 - * Clear hugetlb-related page reserves for children. This only
65005 - * affects MAP_PRIVATE mappings. Faults generated by the child
65006 - * are not guaranteed to succeed, even if read-only
65007 - */
65008 - if (is_vm_hugetlb_page(tmp))
65009 - reset_vma_resv_huge_pages(tmp);
65010
65011 /*
65012 * Link in the new vma and copy the page table entries.
65013 @@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65014 if (retval)
65015 goto out;
65016 }
65017 +
65018 +#ifdef CONFIG_PAX_SEGMEXEC
65019 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
65020 + struct vm_area_struct *mpnt_m;
65021 +
65022 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
65023 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
65024 +
65025 + if (!mpnt->vm_mirror)
65026 + continue;
65027 +
65028 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
65029 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
65030 + mpnt->vm_mirror = mpnt_m;
65031 + } else {
65032 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
65033 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
65034 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
65035 + mpnt->vm_mirror->vm_mirror = mpnt;
65036 + }
65037 + }
65038 + BUG_ON(mpnt_m);
65039 + }
65040 +#endif
65041 +
65042 /* a new mm has just been created */
65043 arch_dup_mmap(oldmm, mm);
65044 retval = 0;
65045 @@ -429,14 +474,6 @@ out:
65046 flush_tlb_mm(oldmm);
65047 up_write(&oldmm->mmap_sem);
65048 return retval;
65049 -fail_nomem_anon_vma_fork:
65050 - mpol_put(pol);
65051 -fail_nomem_policy:
65052 - kmem_cache_free(vm_area_cachep, tmp);
65053 -fail_nomem:
65054 - retval = -ENOMEM;
65055 - vm_unacct_memory(charge);
65056 - goto out;
65057 }
65058
65059 static inline int mm_alloc_pgd(struct mm_struct *mm)
65060 @@ -658,8 +695,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
65061 return ERR_PTR(err);
65062
65063 mm = get_task_mm(task);
65064 - if (mm && mm != current->mm &&
65065 - !ptrace_may_access(task, mode)) {
65066 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
65067 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
65068 mmput(mm);
65069 mm = ERR_PTR(-EACCES);
65070 }
65071 @@ -881,13 +918,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
65072 spin_unlock(&fs->lock);
65073 return -EAGAIN;
65074 }
65075 - fs->users++;
65076 + atomic_inc(&fs->users);
65077 spin_unlock(&fs->lock);
65078 return 0;
65079 }
65080 tsk->fs = copy_fs_struct(fs);
65081 if (!tsk->fs)
65082 return -ENOMEM;
65083 + gr_set_chroot_entries(tsk, &tsk->fs->root);
65084 return 0;
65085 }
65086
65087 @@ -1151,6 +1189,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65088 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
65089 #endif
65090 retval = -EAGAIN;
65091 +
65092 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
65093 +
65094 if (atomic_read(&p->real_cred->user->processes) >=
65095 task_rlimit(p, RLIMIT_NPROC)) {
65096 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
65097 @@ -1306,6 +1347,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65098 if (clone_flags & CLONE_THREAD)
65099 p->tgid = current->tgid;
65100
65101 + gr_copy_label(p);
65102 +
65103 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
65104 /*
65105 * Clear TID on mm_release()?
65106 @@ -1472,6 +1515,8 @@ bad_fork_cleanup_count:
65107 bad_fork_free:
65108 free_task(p);
65109 fork_out:
65110 + gr_log_forkfail(retval);
65111 +
65112 return ERR_PTR(retval);
65113 }
65114
65115 @@ -1572,6 +1617,8 @@ long do_fork(unsigned long clone_flags,
65116 if (clone_flags & CLONE_PARENT_SETTID)
65117 put_user(nr, parent_tidptr);
65118
65119 + gr_handle_brute_check();
65120 +
65121 if (clone_flags & CLONE_VFORK) {
65122 p->vfork_done = &vfork;
65123 init_completion(&vfork);
65124 @@ -1670,7 +1717,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
65125 return 0;
65126
65127 /* don't need lock here; in the worst case we'll do useless copy */
65128 - if (fs->users == 1)
65129 + if (atomic_read(&fs->users) == 1)
65130 return 0;
65131
65132 *new_fsp = copy_fs_struct(fs);
65133 @@ -1759,7 +1806,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
65134 fs = current->fs;
65135 spin_lock(&fs->lock);
65136 current->fs = new_fs;
65137 - if (--fs->users)
65138 + gr_set_chroot_entries(current, &current->fs->root);
65139 + if (atomic_dec_return(&fs->users))
65140 new_fs = NULL;
65141 else
65142 new_fs = fs;
65143 diff --git a/kernel/futex.c b/kernel/futex.c
65144 index 0677023..f3c3b79 100644
65145 --- a/kernel/futex.c
65146 +++ b/kernel/futex.c
65147 @@ -54,6 +54,7 @@
65148 #include <linux/mount.h>
65149 #include <linux/pagemap.h>
65150 #include <linux/syscalls.h>
65151 +#include <linux/ptrace.h>
65152 #include <linux/signal.h>
65153 #include <linux/export.h>
65154 #include <linux/magic.h>
65155 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
65156 struct page *page, *page_head;
65157 int err, ro = 0;
65158
65159 +#ifdef CONFIG_PAX_SEGMEXEC
65160 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
65161 + return -EFAULT;
65162 +#endif
65163 +
65164 /*
65165 * The futex address must be "naturally" aligned.
65166 */
65167 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
65168 if (!p)
65169 goto err_unlock;
65170 ret = -EPERM;
65171 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65172 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
65173 + goto err_unlock;
65174 +#endif
65175 pcred = __task_cred(p);
65176 /* If victim is in different user_ns, then uids are not
65177 comparable, so we must have CAP_SYS_PTRACE */
65178 @@ -2731,6 +2741,7 @@ static int __init futex_init(void)
65179 {
65180 u32 curval;
65181 int i;
65182 + mm_segment_t oldfs;
65183
65184 /*
65185 * This will fail and we want it. Some arch implementations do
65186 @@ -2742,8 +2753,11 @@ static int __init futex_init(void)
65187 * implementation, the non-functional ones will return
65188 * -ENOSYS.
65189 */
65190 + oldfs = get_fs();
65191 + set_fs(USER_DS);
65192 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
65193 futex_cmpxchg_enabled = 1;
65194 + set_fs(oldfs);
65195
65196 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
65197 plist_head_init(&futex_queues[i].chain);
65198 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
65199 index 5f9e689..582d46d 100644
65200 --- a/kernel/futex_compat.c
65201 +++ b/kernel/futex_compat.c
65202 @@ -10,6 +10,7 @@
65203 #include <linux/compat.h>
65204 #include <linux/nsproxy.h>
65205 #include <linux/futex.h>
65206 +#include <linux/ptrace.h>
65207
65208 #include <asm/uaccess.h>
65209
65210 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
65211 {
65212 struct compat_robust_list_head __user *head;
65213 unsigned long ret;
65214 - const struct cred *cred = current_cred(), *pcred;
65215 + const struct cred *cred = current_cred();
65216 + const struct cred *pcred;
65217
65218 if (!futex_cmpxchg_enabled)
65219 return -ENOSYS;
65220 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
65221 if (!p)
65222 goto err_unlock;
65223 ret = -EPERM;
65224 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65225 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
65226 + goto err_unlock;
65227 +#endif
65228 pcred = __task_cred(p);
65229 /* If victim is in different user_ns, then uids are not
65230 comparable, so we must have CAP_SYS_PTRACE */
65231 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
65232 index 9b22d03..6295b62 100644
65233 --- a/kernel/gcov/base.c
65234 +++ b/kernel/gcov/base.c
65235 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
65236 }
65237
65238 #ifdef CONFIG_MODULES
65239 -static inline int within(void *addr, void *start, unsigned long size)
65240 -{
65241 - return ((addr >= start) && (addr < start + size));
65242 -}
65243 -
65244 /* Update list and generate events when modules are unloaded. */
65245 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65246 void *data)
65247 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65248 prev = NULL;
65249 /* Remove entries located in module from linked list. */
65250 for (info = gcov_info_head; info; info = info->next) {
65251 - if (within(info, mod->module_core, mod->core_size)) {
65252 + if (within_module_core_rw((unsigned long)info, mod)) {
65253 if (prev)
65254 prev->next = info->next;
65255 else
65256 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
65257 index ae34bf5..4e2f3d0 100644
65258 --- a/kernel/hrtimer.c
65259 +++ b/kernel/hrtimer.c
65260 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
65261 local_irq_restore(flags);
65262 }
65263
65264 -static void run_hrtimer_softirq(struct softirq_action *h)
65265 +static void run_hrtimer_softirq(void)
65266 {
65267 hrtimer_peek_ahead_timers();
65268 }
65269 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
65270 index 01d3b70..9e4d098 100644
65271 --- a/kernel/jump_label.c
65272 +++ b/kernel/jump_label.c
65273 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
65274
65275 size = (((unsigned long)stop - (unsigned long)start)
65276 / sizeof(struct jump_entry));
65277 + pax_open_kernel();
65278 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
65279 + pax_close_kernel();
65280 }
65281
65282 static void jump_label_update(struct jump_label_key *key, int enable);
65283 @@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
65284 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
65285 struct jump_entry *iter;
65286
65287 + pax_open_kernel();
65288 for (iter = iter_start; iter < iter_stop; iter++) {
65289 if (within_module_init(iter->code, mod))
65290 iter->code = 0;
65291 }
65292 + pax_close_kernel();
65293 }
65294
65295 static int
65296 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
65297 index 079f1d3..a407562 100644
65298 --- a/kernel/kallsyms.c
65299 +++ b/kernel/kallsyms.c
65300 @@ -11,6 +11,9 @@
65301 * Changed the compression method from stem compression to "table lookup"
65302 * compression (see scripts/kallsyms.c for a more complete description)
65303 */
65304 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65305 +#define __INCLUDED_BY_HIDESYM 1
65306 +#endif
65307 #include <linux/kallsyms.h>
65308 #include <linux/module.h>
65309 #include <linux/init.h>
65310 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
65311
65312 static inline int is_kernel_inittext(unsigned long addr)
65313 {
65314 + if (system_state != SYSTEM_BOOTING)
65315 + return 0;
65316 +
65317 if (addr >= (unsigned long)_sinittext
65318 && addr <= (unsigned long)_einittext)
65319 return 1;
65320 return 0;
65321 }
65322
65323 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65324 +#ifdef CONFIG_MODULES
65325 +static inline int is_module_text(unsigned long addr)
65326 +{
65327 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
65328 + return 1;
65329 +
65330 + addr = ktla_ktva(addr);
65331 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
65332 +}
65333 +#else
65334 +static inline int is_module_text(unsigned long addr)
65335 +{
65336 + return 0;
65337 +}
65338 +#endif
65339 +#endif
65340 +
65341 static inline int is_kernel_text(unsigned long addr)
65342 {
65343 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65344 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
65345
65346 static inline int is_kernel(unsigned long addr)
65347 {
65348 +
65349 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65350 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
65351 + return 1;
65352 +
65353 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
65354 +#else
65355 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
65356 +#endif
65357 +
65358 return 1;
65359 return in_gate_area_no_mm(addr);
65360 }
65361
65362 static int is_ksym_addr(unsigned long addr)
65363 {
65364 +
65365 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65366 + if (is_module_text(addr))
65367 + return 0;
65368 +#endif
65369 +
65370 if (all_var)
65371 return is_kernel(addr);
65372
65373 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
65374
65375 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
65376 {
65377 - iter->name[0] = '\0';
65378 iter->nameoff = get_symbol_offset(new_pos);
65379 iter->pos = new_pos;
65380 }
65381 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
65382 {
65383 struct kallsym_iter *iter = m->private;
65384
65385 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65386 + if (current_uid())
65387 + return 0;
65388 +#endif
65389 +
65390 /* Some debugging symbols have no name. Ignore them. */
65391 if (!iter->name[0])
65392 return 0;
65393 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
65394 struct kallsym_iter *iter;
65395 int ret;
65396
65397 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
65398 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
65399 if (!iter)
65400 return -ENOMEM;
65401 reset_iter(iter, 0);
65402 diff --git a/kernel/kexec.c b/kernel/kexec.c
65403 index 7b08867..3bac516 100644
65404 --- a/kernel/kexec.c
65405 +++ b/kernel/kexec.c
65406 @@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
65407 unsigned long flags)
65408 {
65409 struct compat_kexec_segment in;
65410 - struct kexec_segment out, __user *ksegments;
65411 + struct kexec_segment out;
65412 + struct kexec_segment __user *ksegments;
65413 unsigned long i, result;
65414
65415 /* Don't allow clients that don't understand the native
65416 diff --git a/kernel/kmod.c b/kernel/kmod.c
65417 index a0a8854..642b106 100644
65418 --- a/kernel/kmod.c
65419 +++ b/kernel/kmod.c
65420 @@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
65421 * If module auto-loading support is disabled then this function
65422 * becomes a no-operation.
65423 */
65424 -int __request_module(bool wait, const char *fmt, ...)
65425 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
65426 {
65427 - va_list args;
65428 char module_name[MODULE_NAME_LEN];
65429 unsigned int max_modprobes;
65430 int ret;
65431 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
65432 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
65433 static char *envp[] = { "HOME=/",
65434 "TERM=linux",
65435 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
65436 @@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
65437 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
65438 static int kmod_loop_msg;
65439
65440 - va_start(args, fmt);
65441 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
65442 - va_end(args);
65443 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
65444 if (ret >= MODULE_NAME_LEN)
65445 return -ENAMETOOLONG;
65446
65447 @@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
65448 if (ret)
65449 return ret;
65450
65451 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65452 + if (!current_uid()) {
65453 + /* hack to workaround consolekit/udisks stupidity */
65454 + read_lock(&tasklist_lock);
65455 + if (!strcmp(current->comm, "mount") &&
65456 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
65457 + read_unlock(&tasklist_lock);
65458 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
65459 + return -EPERM;
65460 + }
65461 + read_unlock(&tasklist_lock);
65462 + }
65463 +#endif
65464 +
65465 /* If modprobe needs a service that is in a module, we get a recursive
65466 * loop. Limit the number of running kmod threads to max_threads/2 or
65467 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
65468 @@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
65469 atomic_dec(&kmod_concurrent);
65470 return ret;
65471 }
65472 +
65473 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
65474 +{
65475 + va_list args;
65476 + int ret;
65477 +
65478 + va_start(args, fmt);
65479 + ret = ____request_module(wait, module_param, fmt, args);
65480 + va_end(args);
65481 +
65482 + return ret;
65483 +}
65484 +
65485 +int __request_module(bool wait, const char *fmt, ...)
65486 +{
65487 + va_list args;
65488 + int ret;
65489 +
65490 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65491 + if (current_uid()) {
65492 + char module_param[MODULE_NAME_LEN];
65493 +
65494 + memset(module_param, 0, sizeof(module_param));
65495 +
65496 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
65497 +
65498 + va_start(args, fmt);
65499 + ret = ____request_module(wait, module_param, fmt, args);
65500 + va_end(args);
65501 +
65502 + return ret;
65503 + }
65504 +#endif
65505 +
65506 + va_start(args, fmt);
65507 + ret = ____request_module(wait, NULL, fmt, args);
65508 + va_end(args);
65509 +
65510 + return ret;
65511 +}
65512 +
65513 EXPORT_SYMBOL(__request_module);
65514 #endif /* CONFIG_MODULES */
65515
65516 @@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
65517 *
65518 * Thus the __user pointer cast is valid here.
65519 */
65520 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
65521 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
65522
65523 /*
65524 * If ret is 0, either ____call_usermodehelper failed and the
65525 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
65526 index c62b854..cb67968 100644
65527 --- a/kernel/kprobes.c
65528 +++ b/kernel/kprobes.c
65529 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
65530 * kernel image and loaded module images reside. This is required
65531 * so x86_64 can correctly handle the %rip-relative fixups.
65532 */
65533 - kip->insns = module_alloc(PAGE_SIZE);
65534 + kip->insns = module_alloc_exec(PAGE_SIZE);
65535 if (!kip->insns) {
65536 kfree(kip);
65537 return NULL;
65538 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
65539 */
65540 if (!list_is_singular(&kip->list)) {
65541 list_del(&kip->list);
65542 - module_free(NULL, kip->insns);
65543 + module_free_exec(NULL, kip->insns);
65544 kfree(kip);
65545 }
65546 return 1;
65547 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
65548 {
65549 int i, err = 0;
65550 unsigned long offset = 0, size = 0;
65551 - char *modname, namebuf[128];
65552 + char *modname, namebuf[KSYM_NAME_LEN];
65553 const char *symbol_name;
65554 void *addr;
65555 struct kprobe_blackpoint *kb;
65556 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
65557 const char *sym = NULL;
65558 unsigned int i = *(loff_t *) v;
65559 unsigned long offset = 0;
65560 - char *modname, namebuf[128];
65561 + char *modname, namebuf[KSYM_NAME_LEN];
65562
65563 head = &kprobe_table[i];
65564 preempt_disable();
65565 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
65566 index 8889f7d..95319b7 100644
65567 --- a/kernel/lockdep.c
65568 +++ b/kernel/lockdep.c
65569 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
65570 end = (unsigned long) &_end,
65571 addr = (unsigned long) obj;
65572
65573 +#ifdef CONFIG_PAX_KERNEXEC
65574 + start = ktla_ktva(start);
65575 +#endif
65576 +
65577 /*
65578 * static variable?
65579 */
65580 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
65581 if (!static_obj(lock->key)) {
65582 debug_locks_off();
65583 printk("INFO: trying to register non-static key.\n");
65584 + printk("lock:%pS key:%pS.\n", lock, lock->key);
65585 printk("the code is fine but needs lockdep annotation.\n");
65586 printk("turning off the locking correctness validator.\n");
65587 dump_stack();
65588 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
65589 if (!class)
65590 return 0;
65591 }
65592 - atomic_inc((atomic_t *)&class->ops);
65593 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
65594 if (very_verbose(class)) {
65595 printk("\nacquire class [%p] %s", class->key, class->name);
65596 if (class->name_version > 1)
65597 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
65598 index 91c32a0..b2c71c5 100644
65599 --- a/kernel/lockdep_proc.c
65600 +++ b/kernel/lockdep_proc.c
65601 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
65602
65603 static void print_name(struct seq_file *m, struct lock_class *class)
65604 {
65605 - char str[128];
65606 + char str[KSYM_NAME_LEN];
65607 const char *name = class->name;
65608
65609 if (!name) {
65610 diff --git a/kernel/module.c b/kernel/module.c
65611 index 3d56b6f..2a22bd0 100644
65612 --- a/kernel/module.c
65613 +++ b/kernel/module.c
65614 @@ -58,6 +58,7 @@
65615 #include <linux/jump_label.h>
65616 #include <linux/pfn.h>
65617 #include <linux/bsearch.h>
65618 +#include <linux/grsecurity.h>
65619
65620 #define CREATE_TRACE_POINTS
65621 #include <trace/events/module.h>
65622 @@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
65623
65624 /* Bounds of module allocation, for speeding __module_address.
65625 * Protected by module_mutex. */
65626 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
65627 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
65628 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
65629
65630 int register_module_notifier(struct notifier_block * nb)
65631 {
65632 @@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
65633 return true;
65634
65635 list_for_each_entry_rcu(mod, &modules, list) {
65636 - struct symsearch arr[] = {
65637 + struct symsearch modarr[] = {
65638 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
65639 NOT_GPL_ONLY, false },
65640 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
65641 @@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
65642 #endif
65643 };
65644
65645 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
65646 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
65647 return true;
65648 }
65649 return false;
65650 @@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
65651 static int percpu_modalloc(struct module *mod,
65652 unsigned long size, unsigned long align)
65653 {
65654 - if (align > PAGE_SIZE) {
65655 + if (align-1 >= PAGE_SIZE) {
65656 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
65657 mod->name, align, PAGE_SIZE);
65658 align = PAGE_SIZE;
65659 @@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
65660 static ssize_t show_coresize(struct module_attribute *mattr,
65661 struct module_kobject *mk, char *buffer)
65662 {
65663 - return sprintf(buffer, "%u\n", mk->mod->core_size);
65664 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
65665 }
65666
65667 static struct module_attribute modinfo_coresize =
65668 @@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
65669 static ssize_t show_initsize(struct module_attribute *mattr,
65670 struct module_kobject *mk, char *buffer)
65671 {
65672 - return sprintf(buffer, "%u\n", mk->mod->init_size);
65673 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
65674 }
65675
65676 static struct module_attribute modinfo_initsize =
65677 @@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
65678 */
65679 #ifdef CONFIG_SYSFS
65680
65681 -#ifdef CONFIG_KALLSYMS
65682 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65683 static inline bool sect_empty(const Elf_Shdr *sect)
65684 {
65685 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
65686 @@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
65687
65688 static void unset_module_core_ro_nx(struct module *mod)
65689 {
65690 - set_page_attributes(mod->module_core + mod->core_text_size,
65691 - mod->module_core + mod->core_size,
65692 + set_page_attributes(mod->module_core_rw,
65693 + mod->module_core_rw + mod->core_size_rw,
65694 set_memory_x);
65695 - set_page_attributes(mod->module_core,
65696 - mod->module_core + mod->core_ro_size,
65697 + set_page_attributes(mod->module_core_rx,
65698 + mod->module_core_rx + mod->core_size_rx,
65699 set_memory_rw);
65700 }
65701
65702 static void unset_module_init_ro_nx(struct module *mod)
65703 {
65704 - set_page_attributes(mod->module_init + mod->init_text_size,
65705 - mod->module_init + mod->init_size,
65706 + set_page_attributes(mod->module_init_rw,
65707 + mod->module_init_rw + mod->init_size_rw,
65708 set_memory_x);
65709 - set_page_attributes(mod->module_init,
65710 - mod->module_init + mod->init_ro_size,
65711 + set_page_attributes(mod->module_init_rx,
65712 + mod->module_init_rx + mod->init_size_rx,
65713 set_memory_rw);
65714 }
65715
65716 @@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
65717
65718 mutex_lock(&module_mutex);
65719 list_for_each_entry_rcu(mod, &modules, list) {
65720 - if ((mod->module_core) && (mod->core_text_size)) {
65721 - set_page_attributes(mod->module_core,
65722 - mod->module_core + mod->core_text_size,
65723 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
65724 + set_page_attributes(mod->module_core_rx,
65725 + mod->module_core_rx + mod->core_size_rx,
65726 set_memory_rw);
65727 }
65728 - if ((mod->module_init) && (mod->init_text_size)) {
65729 - set_page_attributes(mod->module_init,
65730 - mod->module_init + mod->init_text_size,
65731 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
65732 + set_page_attributes(mod->module_init_rx,
65733 + mod->module_init_rx + mod->init_size_rx,
65734 set_memory_rw);
65735 }
65736 }
65737 @@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
65738
65739 mutex_lock(&module_mutex);
65740 list_for_each_entry_rcu(mod, &modules, list) {
65741 - if ((mod->module_core) && (mod->core_text_size)) {
65742 - set_page_attributes(mod->module_core,
65743 - mod->module_core + mod->core_text_size,
65744 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
65745 + set_page_attributes(mod->module_core_rx,
65746 + mod->module_core_rx + mod->core_size_rx,
65747 set_memory_ro);
65748 }
65749 - if ((mod->module_init) && (mod->init_text_size)) {
65750 - set_page_attributes(mod->module_init,
65751 - mod->module_init + mod->init_text_size,
65752 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
65753 + set_page_attributes(mod->module_init_rx,
65754 + mod->module_init_rx + mod->init_size_rx,
65755 set_memory_ro);
65756 }
65757 }
65758 @@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
65759
65760 /* This may be NULL, but that's OK */
65761 unset_module_init_ro_nx(mod);
65762 - module_free(mod, mod->module_init);
65763 + module_free(mod, mod->module_init_rw);
65764 + module_free_exec(mod, mod->module_init_rx);
65765 kfree(mod->args);
65766 percpu_modfree(mod);
65767
65768 /* Free lock-classes: */
65769 - lockdep_free_key_range(mod->module_core, mod->core_size);
65770 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
65771 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
65772
65773 /* Finally, free the core (containing the module structure) */
65774 unset_module_core_ro_nx(mod);
65775 - module_free(mod, mod->module_core);
65776 + module_free_exec(mod, mod->module_core_rx);
65777 + module_free(mod, mod->module_core_rw);
65778
65779 #ifdef CONFIG_MPU
65780 update_protections(current->mm);
65781 @@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
65782 unsigned int i;
65783 int ret = 0;
65784 const struct kernel_symbol *ksym;
65785 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65786 + int is_fs_load = 0;
65787 + int register_filesystem_found = 0;
65788 + char *p;
65789 +
65790 + p = strstr(mod->args, "grsec_modharden_fs");
65791 + if (p) {
65792 + char *endptr = p + strlen("grsec_modharden_fs");
65793 + /* copy \0 as well */
65794 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
65795 + is_fs_load = 1;
65796 + }
65797 +#endif
65798
65799 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
65800 const char *name = info->strtab + sym[i].st_name;
65801
65802 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65803 + /* it's a real shame this will never get ripped and copied
65804 + upstream! ;(
65805 + */
65806 + if (is_fs_load && !strcmp(name, "register_filesystem"))
65807 + register_filesystem_found = 1;
65808 +#endif
65809 +
65810 switch (sym[i].st_shndx) {
65811 case SHN_COMMON:
65812 /* We compiled with -fno-common. These are not
65813 @@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
65814 ksym = resolve_symbol_wait(mod, info, name);
65815 /* Ok if resolved. */
65816 if (ksym && !IS_ERR(ksym)) {
65817 + pax_open_kernel();
65818 sym[i].st_value = ksym->value;
65819 + pax_close_kernel();
65820 break;
65821 }
65822
65823 @@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
65824 secbase = (unsigned long)mod_percpu(mod);
65825 else
65826 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
65827 + pax_open_kernel();
65828 sym[i].st_value += secbase;
65829 + pax_close_kernel();
65830 break;
65831 }
65832 }
65833
65834 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65835 + if (is_fs_load && !register_filesystem_found) {
65836 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
65837 + ret = -EPERM;
65838 + }
65839 +#endif
65840 +
65841 return ret;
65842 }
65843
65844 @@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
65845 || s->sh_entsize != ~0UL
65846 || strstarts(sname, ".init"))
65847 continue;
65848 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
65849 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
65850 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
65851 + else
65852 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
65853 pr_debug("\t%s\n", sname);
65854 }
65855 - switch (m) {
65856 - case 0: /* executable */
65857 - mod->core_size = debug_align(mod->core_size);
65858 - mod->core_text_size = mod->core_size;
65859 - break;
65860 - case 1: /* RO: text and ro-data */
65861 - mod->core_size = debug_align(mod->core_size);
65862 - mod->core_ro_size = mod->core_size;
65863 - break;
65864 - case 3: /* whole core */
65865 - mod->core_size = debug_align(mod->core_size);
65866 - break;
65867 - }
65868 }
65869
65870 pr_debug("Init section allocation order:\n");
65871 @@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
65872 || s->sh_entsize != ~0UL
65873 || !strstarts(sname, ".init"))
65874 continue;
65875 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
65876 - | INIT_OFFSET_MASK);
65877 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
65878 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
65879 + else
65880 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
65881 + s->sh_entsize |= INIT_OFFSET_MASK;
65882 pr_debug("\t%s\n", sname);
65883 }
65884 - switch (m) {
65885 - case 0: /* executable */
65886 - mod->init_size = debug_align(mod->init_size);
65887 - mod->init_text_size = mod->init_size;
65888 - break;
65889 - case 1: /* RO: text and ro-data */
65890 - mod->init_size = debug_align(mod->init_size);
65891 - mod->init_ro_size = mod->init_size;
65892 - break;
65893 - case 3: /* whole init */
65894 - mod->init_size = debug_align(mod->init_size);
65895 - break;
65896 - }
65897 }
65898 }
65899
65900 @@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
65901
65902 /* Put symbol section at end of init part of module. */
65903 symsect->sh_flags |= SHF_ALLOC;
65904 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
65905 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
65906 info->index.sym) | INIT_OFFSET_MASK;
65907 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
65908
65909 @@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
65910 }
65911
65912 /* Append room for core symbols at end of core part. */
65913 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
65914 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
65915 - mod->core_size += strtab_size;
65916 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
65917 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
65918 + mod->core_size_rx += strtab_size;
65919
65920 /* Put string table section at end of init part of module. */
65921 strsect->sh_flags |= SHF_ALLOC;
65922 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
65923 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
65924 info->index.str) | INIT_OFFSET_MASK;
65925 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
65926 }
65927 @@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
65928 /* Make sure we get permanent strtab: don't use info->strtab. */
65929 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
65930
65931 + pax_open_kernel();
65932 +
65933 /* Set types up while we still have access to sections. */
65934 for (i = 0; i < mod->num_symtab; i++)
65935 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
65936
65937 - mod->core_symtab = dst = mod->module_core + info->symoffs;
65938 - mod->core_strtab = s = mod->module_core + info->stroffs;
65939 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
65940 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
65941 src = mod->symtab;
65942 *dst = *src;
65943 *s++ = 0;
65944 @@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
65945 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
65946 }
65947 mod->core_num_syms = ndst;
65948 +
65949 + pax_close_kernel();
65950 }
65951 #else
65952 static inline void layout_symtab(struct module *mod, struct load_info *info)
65953 @@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
65954 return size == 0 ? NULL : vmalloc_exec(size);
65955 }
65956
65957 -static void *module_alloc_update_bounds(unsigned long size)
65958 +static void *module_alloc_update_bounds_rw(unsigned long size)
65959 {
65960 void *ret = module_alloc(size);
65961
65962 if (ret) {
65963 mutex_lock(&module_mutex);
65964 /* Update module bounds. */
65965 - if ((unsigned long)ret < module_addr_min)
65966 - module_addr_min = (unsigned long)ret;
65967 - if ((unsigned long)ret + size > module_addr_max)
65968 - module_addr_max = (unsigned long)ret + size;
65969 + if ((unsigned long)ret < module_addr_min_rw)
65970 + module_addr_min_rw = (unsigned long)ret;
65971 + if ((unsigned long)ret + size > module_addr_max_rw)
65972 + module_addr_max_rw = (unsigned long)ret + size;
65973 + mutex_unlock(&module_mutex);
65974 + }
65975 + return ret;
65976 +}
65977 +
65978 +static void *module_alloc_update_bounds_rx(unsigned long size)
65979 +{
65980 + void *ret = module_alloc_exec(size);
65981 +
65982 + if (ret) {
65983 + mutex_lock(&module_mutex);
65984 + /* Update module bounds. */
65985 + if ((unsigned long)ret < module_addr_min_rx)
65986 + module_addr_min_rx = (unsigned long)ret;
65987 + if ((unsigned long)ret + size > module_addr_max_rx)
65988 + module_addr_max_rx = (unsigned long)ret + size;
65989 mutex_unlock(&module_mutex);
65990 }
65991 return ret;
65992 @@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
65993 static int check_modinfo(struct module *mod, struct load_info *info)
65994 {
65995 const char *modmagic = get_modinfo(info, "vermagic");
65996 + const char *license = get_modinfo(info, "license");
65997 int err;
65998
65999 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
66000 + if (!license || !license_is_gpl_compatible(license))
66001 + return -ENOEXEC;
66002 +#endif
66003 +
66004 /* This is allowed: modprobe --force will invalidate it. */
66005 if (!modmagic) {
66006 err = try_to_force_load(mod, "bad vermagic");
66007 @@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
66008 }
66009
66010 /* Set up license info based on the info section */
66011 - set_license(mod, get_modinfo(info, "license"));
66012 + set_license(mod, license);
66013
66014 return 0;
66015 }
66016 @@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
66017 void *ptr;
66018
66019 /* Do the allocs. */
66020 - ptr = module_alloc_update_bounds(mod->core_size);
66021 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
66022 /*
66023 * The pointer to this block is stored in the module structure
66024 * which is inside the block. Just mark it as not being a
66025 @@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
66026 if (!ptr)
66027 return -ENOMEM;
66028
66029 - memset(ptr, 0, mod->core_size);
66030 - mod->module_core = ptr;
66031 + memset(ptr, 0, mod->core_size_rw);
66032 + mod->module_core_rw = ptr;
66033
66034 - ptr = module_alloc_update_bounds(mod->init_size);
66035 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
66036 /*
66037 * The pointer to this block is stored in the module structure
66038 * which is inside the block. This block doesn't need to be
66039 * scanned as it contains data and code that will be freed
66040 * after the module is initialized.
66041 */
66042 - kmemleak_ignore(ptr);
66043 - if (!ptr && mod->init_size) {
66044 - module_free(mod, mod->module_core);
66045 + kmemleak_not_leak(ptr);
66046 + if (!ptr && mod->init_size_rw) {
66047 + module_free(mod, mod->module_core_rw);
66048 return -ENOMEM;
66049 }
66050 - memset(ptr, 0, mod->init_size);
66051 - mod->module_init = ptr;
66052 + memset(ptr, 0, mod->init_size_rw);
66053 + mod->module_init_rw = ptr;
66054 +
66055 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
66056 + kmemleak_not_leak(ptr);
66057 + if (!ptr) {
66058 + module_free(mod, mod->module_init_rw);
66059 + module_free(mod, mod->module_core_rw);
66060 + return -ENOMEM;
66061 + }
66062 +
66063 + pax_open_kernel();
66064 + memset(ptr, 0, mod->core_size_rx);
66065 + pax_close_kernel();
66066 + mod->module_core_rx = ptr;
66067 +
66068 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
66069 + kmemleak_not_leak(ptr);
66070 + if (!ptr && mod->init_size_rx) {
66071 + module_free_exec(mod, mod->module_core_rx);
66072 + module_free(mod, mod->module_init_rw);
66073 + module_free(mod, mod->module_core_rw);
66074 + return -ENOMEM;
66075 + }
66076 +
66077 + pax_open_kernel();
66078 + memset(ptr, 0, mod->init_size_rx);
66079 + pax_close_kernel();
66080 + mod->module_init_rx = ptr;
66081
66082 /* Transfer each section which specifies SHF_ALLOC */
66083 pr_debug("final section addresses:\n");
66084 @@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
66085 if (!(shdr->sh_flags & SHF_ALLOC))
66086 continue;
66087
66088 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
66089 - dest = mod->module_init
66090 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66091 - else
66092 - dest = mod->module_core + shdr->sh_entsize;
66093 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
66094 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66095 + dest = mod->module_init_rw
66096 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66097 + else
66098 + dest = mod->module_init_rx
66099 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66100 + } else {
66101 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66102 + dest = mod->module_core_rw + shdr->sh_entsize;
66103 + else
66104 + dest = mod->module_core_rx + shdr->sh_entsize;
66105 + }
66106 +
66107 + if (shdr->sh_type != SHT_NOBITS) {
66108 +
66109 +#ifdef CONFIG_PAX_KERNEXEC
66110 +#ifdef CONFIG_X86_64
66111 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
66112 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
66113 +#endif
66114 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
66115 + pax_open_kernel();
66116 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66117 + pax_close_kernel();
66118 + } else
66119 +#endif
66120
66121 - if (shdr->sh_type != SHT_NOBITS)
66122 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66123 + }
66124 /* Update sh_addr to point to copy in image. */
66125 - shdr->sh_addr = (unsigned long)dest;
66126 +
66127 +#ifdef CONFIG_PAX_KERNEXEC
66128 + if (shdr->sh_flags & SHF_EXECINSTR)
66129 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
66130 + else
66131 +#endif
66132 +
66133 + shdr->sh_addr = (unsigned long)dest;
66134 pr_debug("\t0x%lx %s\n",
66135 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
66136 }
66137 @@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
66138 * Do it before processing of module parameters, so the module
66139 * can provide parameter accessor functions of its own.
66140 */
66141 - if (mod->module_init)
66142 - flush_icache_range((unsigned long)mod->module_init,
66143 - (unsigned long)mod->module_init
66144 - + mod->init_size);
66145 - flush_icache_range((unsigned long)mod->module_core,
66146 - (unsigned long)mod->module_core + mod->core_size);
66147 + if (mod->module_init_rx)
66148 + flush_icache_range((unsigned long)mod->module_init_rx,
66149 + (unsigned long)mod->module_init_rx
66150 + + mod->init_size_rx);
66151 + flush_icache_range((unsigned long)mod->module_core_rx,
66152 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
66153
66154 set_fs(old_fs);
66155 }
66156 @@ -2802,8 +2901,10 @@ out:
66157 static void module_deallocate(struct module *mod, struct load_info *info)
66158 {
66159 percpu_modfree(mod);
66160 - module_free(mod, mod->module_init);
66161 - module_free(mod, mod->module_core);
66162 + module_free_exec(mod, mod->module_init_rx);
66163 + module_free_exec(mod, mod->module_core_rx);
66164 + module_free(mod, mod->module_init_rw);
66165 + module_free(mod, mod->module_core_rw);
66166 }
66167
66168 int __weak module_finalize(const Elf_Ehdr *hdr,
66169 @@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
66170 if (err)
66171 goto free_unload;
66172
66173 + /* Now copy in args */
66174 + mod->args = strndup_user(uargs, ~0UL >> 1);
66175 + if (IS_ERR(mod->args)) {
66176 + err = PTR_ERR(mod->args);
66177 + goto free_unload;
66178 + }
66179 +
66180 /* Set up MODINFO_ATTR fields */
66181 setup_modinfo(mod, &info);
66182
66183 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66184 + {
66185 + char *p, *p2;
66186 +
66187 + if (strstr(mod->args, "grsec_modharden_netdev")) {
66188 + 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);
66189 + err = -EPERM;
66190 + goto free_modinfo;
66191 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
66192 + p += strlen("grsec_modharden_normal");
66193 + p2 = strstr(p, "_");
66194 + if (p2) {
66195 + *p2 = '\0';
66196 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
66197 + *p2 = '_';
66198 + }
66199 + err = -EPERM;
66200 + goto free_modinfo;
66201 + }
66202 + }
66203 +#endif
66204 +
66205 /* Fix up syms, so that st_value is a pointer to location. */
66206 err = simplify_symbols(mod, &info);
66207 if (err < 0)
66208 @@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
66209
66210 flush_module_icache(mod);
66211
66212 - /* Now copy in args */
66213 - mod->args = strndup_user(uargs, ~0UL >> 1);
66214 - if (IS_ERR(mod->args)) {
66215 - err = PTR_ERR(mod->args);
66216 - goto free_arch_cleanup;
66217 - }
66218 -
66219 /* Mark state as coming so strong_try_module_get() ignores us. */
66220 mod->state = MODULE_STATE_COMING;
66221
66222 @@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
66223 unlock:
66224 mutex_unlock(&module_mutex);
66225 synchronize_sched();
66226 - kfree(mod->args);
66227 - free_arch_cleanup:
66228 module_arch_cleanup(mod);
66229 free_modinfo:
66230 free_modinfo(mod);
66231 + kfree(mod->args);
66232 free_unload:
66233 module_unload_free(mod);
66234 free_module:
66235 @@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66236 MODULE_STATE_COMING, mod);
66237
66238 /* Set RO and NX regions for core */
66239 - set_section_ro_nx(mod->module_core,
66240 - mod->core_text_size,
66241 - mod->core_ro_size,
66242 - mod->core_size);
66243 + set_section_ro_nx(mod->module_core_rx,
66244 + mod->core_size_rx,
66245 + mod->core_size_rx,
66246 + mod->core_size_rx);
66247
66248 /* Set RO and NX regions for init */
66249 - set_section_ro_nx(mod->module_init,
66250 - mod->init_text_size,
66251 - mod->init_ro_size,
66252 - mod->init_size);
66253 + set_section_ro_nx(mod->module_init_rx,
66254 + mod->init_size_rx,
66255 + mod->init_size_rx,
66256 + mod->init_size_rx);
66257
66258 do_mod_ctors(mod);
66259 /* Start the module */
66260 @@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66261 mod->strtab = mod->core_strtab;
66262 #endif
66263 unset_module_init_ro_nx(mod);
66264 - module_free(mod, mod->module_init);
66265 - mod->module_init = NULL;
66266 - mod->init_size = 0;
66267 - mod->init_ro_size = 0;
66268 - mod->init_text_size = 0;
66269 + module_free(mod, mod->module_init_rw);
66270 + module_free_exec(mod, mod->module_init_rx);
66271 + mod->module_init_rw = NULL;
66272 + mod->module_init_rx = NULL;
66273 + mod->init_size_rw = 0;
66274 + mod->init_size_rx = 0;
66275 mutex_unlock(&module_mutex);
66276
66277 return 0;
66278 @@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
66279 unsigned long nextval;
66280
66281 /* At worse, next value is at end of module */
66282 - if (within_module_init(addr, mod))
66283 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
66284 + if (within_module_init_rx(addr, mod))
66285 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
66286 + else if (within_module_init_rw(addr, mod))
66287 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
66288 + else if (within_module_core_rx(addr, mod))
66289 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
66290 + else if (within_module_core_rw(addr, mod))
66291 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
66292 else
66293 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
66294 + return NULL;
66295
66296 /* Scan for closest preceding symbol, and next symbol. (ELF
66297 starts real symbols at 1). */
66298 @@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
66299 char buf[8];
66300
66301 seq_printf(m, "%s %u",
66302 - mod->name, mod->init_size + mod->core_size);
66303 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
66304 print_unload_info(m, mod);
66305
66306 /* Informative for users. */
66307 @@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
66308 mod->state == MODULE_STATE_COMING ? "Loading":
66309 "Live");
66310 /* Used by oprofile and other similar tools. */
66311 - seq_printf(m, " 0x%pK", mod->module_core);
66312 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
66313
66314 /* Taints info */
66315 if (mod->taints)
66316 @@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
66317
66318 static int __init proc_modules_init(void)
66319 {
66320 +#ifndef CONFIG_GRKERNSEC_HIDESYM
66321 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66322 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66323 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66324 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
66325 +#else
66326 proc_create("modules", 0, NULL, &proc_modules_operations);
66327 +#endif
66328 +#else
66329 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66330 +#endif
66331 return 0;
66332 }
66333 module_init(proc_modules_init);
66334 @@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
66335 {
66336 struct module *mod;
66337
66338 - if (addr < module_addr_min || addr > module_addr_max)
66339 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
66340 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
66341 return NULL;
66342
66343 list_for_each_entry_rcu(mod, &modules, list)
66344 - if (within_module_core(addr, mod)
66345 - || within_module_init(addr, mod))
66346 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
66347 return mod;
66348 return NULL;
66349 }
66350 @@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
66351 */
66352 struct module *__module_text_address(unsigned long addr)
66353 {
66354 - struct module *mod = __module_address(addr);
66355 + struct module *mod;
66356 +
66357 +#ifdef CONFIG_X86_32
66358 + addr = ktla_ktva(addr);
66359 +#endif
66360 +
66361 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
66362 + return NULL;
66363 +
66364 + mod = __module_address(addr);
66365 +
66366 if (mod) {
66367 /* Make sure it's within the text section. */
66368 - if (!within(addr, mod->module_init, mod->init_text_size)
66369 - && !within(addr, mod->module_core, mod->core_text_size))
66370 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
66371 mod = NULL;
66372 }
66373 return mod;
66374 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
66375 index 7e3443f..b2a1e6b 100644
66376 --- a/kernel/mutex-debug.c
66377 +++ b/kernel/mutex-debug.c
66378 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
66379 }
66380
66381 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66382 - struct thread_info *ti)
66383 + struct task_struct *task)
66384 {
66385 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
66386
66387 /* Mark the current thread as blocked on the lock: */
66388 - ti->task->blocked_on = waiter;
66389 + task->blocked_on = waiter;
66390 }
66391
66392 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66393 - struct thread_info *ti)
66394 + struct task_struct *task)
66395 {
66396 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
66397 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
66398 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
66399 - ti->task->blocked_on = NULL;
66400 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
66401 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
66402 + task->blocked_on = NULL;
66403
66404 list_del_init(&waiter->list);
66405 waiter->task = NULL;
66406 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
66407 index 0799fd3..d06ae3b 100644
66408 --- a/kernel/mutex-debug.h
66409 +++ b/kernel/mutex-debug.h
66410 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
66411 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
66412 extern void debug_mutex_add_waiter(struct mutex *lock,
66413 struct mutex_waiter *waiter,
66414 - struct thread_info *ti);
66415 + struct task_struct *task);
66416 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66417 - struct thread_info *ti);
66418 + struct task_struct *task);
66419 extern void debug_mutex_unlock(struct mutex *lock);
66420 extern void debug_mutex_init(struct mutex *lock, const char *name,
66421 struct lock_class_key *key);
66422 diff --git a/kernel/mutex.c b/kernel/mutex.c
66423 index 89096dd..f91ebc5 100644
66424 --- a/kernel/mutex.c
66425 +++ b/kernel/mutex.c
66426 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66427 spin_lock_mutex(&lock->wait_lock, flags);
66428
66429 debug_mutex_lock_common(lock, &waiter);
66430 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
66431 + debug_mutex_add_waiter(lock, &waiter, task);
66432
66433 /* add waiting tasks to the end of the waitqueue (FIFO): */
66434 list_add_tail(&waiter.list, &lock->wait_list);
66435 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66436 * TASK_UNINTERRUPTIBLE case.)
66437 */
66438 if (unlikely(signal_pending_state(state, task))) {
66439 - mutex_remove_waiter(lock, &waiter,
66440 - task_thread_info(task));
66441 + mutex_remove_waiter(lock, &waiter, task);
66442 mutex_release(&lock->dep_map, 1, ip);
66443 spin_unlock_mutex(&lock->wait_lock, flags);
66444
66445 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66446 done:
66447 lock_acquired(&lock->dep_map, ip);
66448 /* got the lock - rejoice! */
66449 - mutex_remove_waiter(lock, &waiter, current_thread_info());
66450 + mutex_remove_waiter(lock, &waiter, task);
66451 mutex_set_owner(lock);
66452
66453 /* set it to 0 if there are no waiters left: */
66454 diff --git a/kernel/padata.c b/kernel/padata.c
66455 index b452599..5d68f4e 100644
66456 --- a/kernel/padata.c
66457 +++ b/kernel/padata.c
66458 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
66459 padata->pd = pd;
66460 padata->cb_cpu = cb_cpu;
66461
66462 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
66463 - atomic_set(&pd->seq_nr, -1);
66464 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
66465 + atomic_set_unchecked(&pd->seq_nr, -1);
66466
66467 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
66468 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
66469
66470 target_cpu = padata_cpu_hash(padata);
66471 queue = per_cpu_ptr(pd->pqueue, target_cpu);
66472 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
66473 padata_init_pqueues(pd);
66474 padata_init_squeues(pd);
66475 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
66476 - atomic_set(&pd->seq_nr, -1);
66477 + atomic_set_unchecked(&pd->seq_nr, -1);
66478 atomic_set(&pd->reorder_objects, 0);
66479 atomic_set(&pd->refcnt, 0);
66480 pd->pinst = pinst;
66481 diff --git a/kernel/panic.c b/kernel/panic.c
66482 index 80aed44..f291d37 100644
66483 --- a/kernel/panic.c
66484 +++ b/kernel/panic.c
66485 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
66486 const char *board;
66487
66488 printk(KERN_WARNING "------------[ cut here ]------------\n");
66489 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
66490 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
66491 board = dmi_get_system_info(DMI_PRODUCT_NAME);
66492 if (board)
66493 printk(KERN_WARNING "Hardware name: %s\n", board);
66494 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
66495 */
66496 void __stack_chk_fail(void)
66497 {
66498 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
66499 + dump_stack();
66500 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
66501 __builtin_return_address(0));
66502 }
66503 EXPORT_SYMBOL(__stack_chk_fail);
66504 diff --git a/kernel/pid.c b/kernel/pid.c
66505 index 9f08dfa..6765c40 100644
66506 --- a/kernel/pid.c
66507 +++ b/kernel/pid.c
66508 @@ -33,6 +33,7 @@
66509 #include <linux/rculist.h>
66510 #include <linux/bootmem.h>
66511 #include <linux/hash.h>
66512 +#include <linux/security.h>
66513 #include <linux/pid_namespace.h>
66514 #include <linux/init_task.h>
66515 #include <linux/syscalls.h>
66516 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
66517
66518 int pid_max = PID_MAX_DEFAULT;
66519
66520 -#define RESERVED_PIDS 300
66521 +#define RESERVED_PIDS 500
66522
66523 int pid_max_min = RESERVED_PIDS + 1;
66524 int pid_max_max = PID_MAX_LIMIT;
66525 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
66526 */
66527 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
66528 {
66529 + struct task_struct *task;
66530 +
66531 rcu_lockdep_assert(rcu_read_lock_held(),
66532 "find_task_by_pid_ns() needs rcu_read_lock()"
66533 " protection");
66534 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66535 +
66536 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66537 +
66538 + if (gr_pid_is_chrooted(task))
66539 + return NULL;
66540 +
66541 + return task;
66542 }
66543
66544 struct task_struct *find_task_by_vpid(pid_t vnr)
66545 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
66546 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
66547 }
66548
66549 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
66550 +{
66551 + rcu_lockdep_assert(rcu_read_lock_held(),
66552 + "find_task_by_pid_ns() needs rcu_read_lock()"
66553 + " protection");
66554 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
66555 +}
66556 +
66557 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
66558 {
66559 struct pid *pid;
66560 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
66561 index 125cb67..a4d1c30 100644
66562 --- a/kernel/posix-cpu-timers.c
66563 +++ b/kernel/posix-cpu-timers.c
66564 @@ -6,6 +6,7 @@
66565 #include <linux/posix-timers.h>
66566 #include <linux/errno.h>
66567 #include <linux/math64.h>
66568 +#include <linux/security.h>
66569 #include <asm/uaccess.h>
66570 #include <linux/kernel_stat.h>
66571 #include <trace/events/timer.h>
66572 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
66573
66574 static __init int init_posix_cpu_timers(void)
66575 {
66576 - struct k_clock process = {
66577 + static struct k_clock process = {
66578 .clock_getres = process_cpu_clock_getres,
66579 .clock_get = process_cpu_clock_get,
66580 .timer_create = process_cpu_timer_create,
66581 .nsleep = process_cpu_nsleep,
66582 .nsleep_restart = process_cpu_nsleep_restart,
66583 };
66584 - struct k_clock thread = {
66585 + static struct k_clock thread = {
66586 .clock_getres = thread_cpu_clock_getres,
66587 .clock_get = thread_cpu_clock_get,
66588 .timer_create = thread_cpu_timer_create,
66589 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
66590 index 69185ae..cc2847a 100644
66591 --- a/kernel/posix-timers.c
66592 +++ b/kernel/posix-timers.c
66593 @@ -43,6 +43,7 @@
66594 #include <linux/idr.h>
66595 #include <linux/posix-clock.h>
66596 #include <linux/posix-timers.h>
66597 +#include <linux/grsecurity.h>
66598 #include <linux/syscalls.h>
66599 #include <linux/wait.h>
66600 #include <linux/workqueue.h>
66601 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
66602 * which we beg off on and pass to do_sys_settimeofday().
66603 */
66604
66605 -static struct k_clock posix_clocks[MAX_CLOCKS];
66606 +static struct k_clock *posix_clocks[MAX_CLOCKS];
66607
66608 /*
66609 * These ones are defined below.
66610 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
66611 */
66612 static __init int init_posix_timers(void)
66613 {
66614 - struct k_clock clock_realtime = {
66615 + static struct k_clock clock_realtime = {
66616 .clock_getres = hrtimer_get_res,
66617 .clock_get = posix_clock_realtime_get,
66618 .clock_set = posix_clock_realtime_set,
66619 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
66620 .timer_get = common_timer_get,
66621 .timer_del = common_timer_del,
66622 };
66623 - struct k_clock clock_monotonic = {
66624 + static struct k_clock clock_monotonic = {
66625 .clock_getres = hrtimer_get_res,
66626 .clock_get = posix_ktime_get_ts,
66627 .nsleep = common_nsleep,
66628 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
66629 .timer_get = common_timer_get,
66630 .timer_del = common_timer_del,
66631 };
66632 - struct k_clock clock_monotonic_raw = {
66633 + static struct k_clock clock_monotonic_raw = {
66634 .clock_getres = hrtimer_get_res,
66635 .clock_get = posix_get_monotonic_raw,
66636 };
66637 - struct k_clock clock_realtime_coarse = {
66638 + static struct k_clock clock_realtime_coarse = {
66639 .clock_getres = posix_get_coarse_res,
66640 .clock_get = posix_get_realtime_coarse,
66641 };
66642 - struct k_clock clock_monotonic_coarse = {
66643 + static struct k_clock clock_monotonic_coarse = {
66644 .clock_getres = posix_get_coarse_res,
66645 .clock_get = posix_get_monotonic_coarse,
66646 };
66647 - struct k_clock clock_boottime = {
66648 + static struct k_clock clock_boottime = {
66649 .clock_getres = hrtimer_get_res,
66650 .clock_get = posix_get_boottime,
66651 .nsleep = common_nsleep,
66652 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
66653 return;
66654 }
66655
66656 - posix_clocks[clock_id] = *new_clock;
66657 + posix_clocks[clock_id] = new_clock;
66658 }
66659 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
66660
66661 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
66662 return (id & CLOCKFD_MASK) == CLOCKFD ?
66663 &clock_posix_dynamic : &clock_posix_cpu;
66664
66665 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
66666 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
66667 return NULL;
66668 - return &posix_clocks[id];
66669 + return posix_clocks[id];
66670 }
66671
66672 static int common_timer_create(struct k_itimer *new_timer)
66673 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
66674 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
66675 return -EFAULT;
66676
66677 + /* only the CLOCK_REALTIME clock can be set, all other clocks
66678 + have their clock_set fptr set to a nosettime dummy function
66679 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
66680 + call common_clock_set, which calls do_sys_settimeofday, which
66681 + we hook
66682 + */
66683 +
66684 return kc->clock_set(which_clock, &new_tp);
66685 }
66686
66687 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
66688 index d523593..68197a4 100644
66689 --- a/kernel/power/poweroff.c
66690 +++ b/kernel/power/poweroff.c
66691 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
66692 .enable_mask = SYSRQ_ENABLE_BOOT,
66693 };
66694
66695 -static int pm_sysrq_init(void)
66696 +static int __init pm_sysrq_init(void)
66697 {
66698 register_sysrq_key('o', &sysrq_poweroff_op);
66699 return 0;
66700 diff --git a/kernel/power/process.c b/kernel/power/process.c
66701 index 7e42645..3d43df1 100644
66702 --- a/kernel/power/process.c
66703 +++ b/kernel/power/process.c
66704 @@ -32,6 +32,7 @@ static int try_to_freeze_tasks(bool user_only)
66705 u64 elapsed_csecs64;
66706 unsigned int elapsed_csecs;
66707 bool wakeup = false;
66708 + bool timedout = false;
66709
66710 do_gettimeofday(&start);
66711
66712 @@ -42,6 +43,8 @@ static int try_to_freeze_tasks(bool user_only)
66713
66714 while (true) {
66715 todo = 0;
66716 + if (time_after(jiffies, end_time))
66717 + timedout = true;
66718 read_lock(&tasklist_lock);
66719 do_each_thread(g, p) {
66720 if (p == current || !freeze_task(p))
66721 @@ -59,9 +62,13 @@ static int try_to_freeze_tasks(bool user_only)
66722 * try_to_stop() after schedule() in ptrace/signal
66723 * stop sees TIF_FREEZE.
66724 */
66725 - if (!task_is_stopped_or_traced(p) &&
66726 - !freezer_should_skip(p))
66727 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
66728 todo++;
66729 + if (timedout) {
66730 + printk(KERN_ERR "Task refusing to freeze:\n");
66731 + sched_show_task(p);
66732 + }
66733 + }
66734 } while_each_thread(g, p);
66735 read_unlock(&tasklist_lock);
66736
66737 @@ -70,7 +77,7 @@ static int try_to_freeze_tasks(bool user_only)
66738 todo += wq_busy;
66739 }
66740
66741 - if (!todo || time_after(jiffies, end_time))
66742 + if (!todo || timedout)
66743 break;
66744
66745 if (pm_wakeup_pending()) {
66746 diff --git a/kernel/printk.c b/kernel/printk.c
66747 index 32690a0..cd7c798 100644
66748 --- a/kernel/printk.c
66749 +++ b/kernel/printk.c
66750 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
66751 if (from_file && type != SYSLOG_ACTION_OPEN)
66752 return 0;
66753
66754 +#ifdef CONFIG_GRKERNSEC_DMESG
66755 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
66756 + return -EPERM;
66757 +#endif
66758 +
66759 if (syslog_action_restricted(type)) {
66760 if (capable(CAP_SYSLOG))
66761 return 0;
66762 diff --git a/kernel/profile.c b/kernel/profile.c
66763 index 76b8e77..a2930e8 100644
66764 --- a/kernel/profile.c
66765 +++ b/kernel/profile.c
66766 @@ -39,7 +39,7 @@ struct profile_hit {
66767 /* Oprofile timer tick hook */
66768 static int (*timer_hook)(struct pt_regs *) __read_mostly;
66769
66770 -static atomic_t *prof_buffer;
66771 +static atomic_unchecked_t *prof_buffer;
66772 static unsigned long prof_len, prof_shift;
66773
66774 int prof_on __read_mostly;
66775 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
66776 hits[i].pc = 0;
66777 continue;
66778 }
66779 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
66780 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
66781 hits[i].hits = hits[i].pc = 0;
66782 }
66783 }
66784 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
66785 * Add the current hit(s) and flush the write-queue out
66786 * to the global buffer:
66787 */
66788 - atomic_add(nr_hits, &prof_buffer[pc]);
66789 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
66790 for (i = 0; i < NR_PROFILE_HIT; ++i) {
66791 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
66792 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
66793 hits[i].pc = hits[i].hits = 0;
66794 }
66795 out:
66796 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
66797 {
66798 unsigned long pc;
66799 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
66800 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
66801 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
66802 }
66803 #endif /* !CONFIG_SMP */
66804
66805 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
66806 return -EFAULT;
66807 buf++; p++; count--; read++;
66808 }
66809 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
66810 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
66811 if (copy_to_user(buf, (void *)pnt, count))
66812 return -EFAULT;
66813 read += count;
66814 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
66815 }
66816 #endif
66817 profile_discard_flip_buffers();
66818 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
66819 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
66820 return count;
66821 }
66822
66823 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
66824 index 00ab2ca..d237f61 100644
66825 --- a/kernel/ptrace.c
66826 +++ b/kernel/ptrace.c
66827 @@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
66828 task->ptrace = PT_PTRACED;
66829 if (seize)
66830 task->ptrace |= PT_SEIZED;
66831 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
66832 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
66833 task->ptrace |= PT_PTRACE_CAP;
66834
66835 __ptrace_link(task, current);
66836 @@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
66837 break;
66838 return -EIO;
66839 }
66840 - if (copy_to_user(dst, buf, retval))
66841 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
66842 return -EFAULT;
66843 copied += retval;
66844 src += retval;
66845 @@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
66846 bool seized = child->ptrace & PT_SEIZED;
66847 int ret = -EIO;
66848 siginfo_t siginfo, *si;
66849 - void __user *datavp = (void __user *) data;
66850 + void __user *datavp = (__force void __user *) data;
66851 unsigned long __user *datalp = datavp;
66852 unsigned long flags;
66853
66854 @@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
66855 goto out;
66856 }
66857
66858 + if (gr_handle_ptrace(child, request)) {
66859 + ret = -EPERM;
66860 + goto out_put_task_struct;
66861 + }
66862 +
66863 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66864 ret = ptrace_attach(child, request, data);
66865 /*
66866 * Some architectures need to do book-keeping after
66867 * a ptrace attach.
66868 */
66869 - if (!ret)
66870 + if (!ret) {
66871 arch_ptrace_attach(child);
66872 + gr_audit_ptrace(child);
66873 + }
66874 goto out_put_task_struct;
66875 }
66876
66877 @@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
66878 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
66879 if (copied != sizeof(tmp))
66880 return -EIO;
66881 - return put_user(tmp, (unsigned long __user *)data);
66882 + return put_user(tmp, (__force unsigned long __user *)data);
66883 }
66884
66885 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
66886 @@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
66887 goto out;
66888 }
66889
66890 + if (gr_handle_ptrace(child, request)) {
66891 + ret = -EPERM;
66892 + goto out_put_task_struct;
66893 + }
66894 +
66895 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66896 ret = ptrace_attach(child, request, data);
66897 /*
66898 * Some architectures need to do book-keeping after
66899 * a ptrace attach.
66900 */
66901 - if (!ret)
66902 + if (!ret) {
66903 arch_ptrace_attach(child);
66904 + gr_audit_ptrace(child);
66905 + }
66906 goto out_put_task_struct;
66907 }
66908
66909 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
66910 index 977296d..c4744dc 100644
66911 --- a/kernel/rcutiny.c
66912 +++ b/kernel/rcutiny.c
66913 @@ -46,7 +46,7 @@
66914 struct rcu_ctrlblk;
66915 static void invoke_rcu_callbacks(void);
66916 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
66917 -static void rcu_process_callbacks(struct softirq_action *unused);
66918 +static void rcu_process_callbacks(void);
66919 static void __call_rcu(struct rcu_head *head,
66920 void (*func)(struct rcu_head *rcu),
66921 struct rcu_ctrlblk *rcp);
66922 @@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
66923 rcu_is_callbacks_kthread()));
66924 }
66925
66926 -static void rcu_process_callbacks(struct softirq_action *unused)
66927 +static void rcu_process_callbacks(void)
66928 {
66929 __rcu_process_callbacks(&rcu_sched_ctrlblk);
66930 __rcu_process_callbacks(&rcu_bh_ctrlblk);
66931 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
66932 index 9cb1ae4..aac7d3e 100644
66933 --- a/kernel/rcutiny_plugin.h
66934 +++ b/kernel/rcutiny_plugin.h
66935 @@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
66936 have_rcu_kthread_work = morework;
66937 local_irq_restore(flags);
66938 if (work)
66939 - rcu_process_callbacks(NULL);
66940 + rcu_process_callbacks();
66941 schedule_timeout_interruptible(1); /* Leave CPU for others. */
66942 }
66943
66944 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
66945 index a58ac28..196a3d8 100644
66946 --- a/kernel/rcutorture.c
66947 +++ b/kernel/rcutorture.c
66948 @@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
66949 { 0 };
66950 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
66951 { 0 };
66952 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
66953 -static atomic_t n_rcu_torture_alloc;
66954 -static atomic_t n_rcu_torture_alloc_fail;
66955 -static atomic_t n_rcu_torture_free;
66956 -static atomic_t n_rcu_torture_mberror;
66957 -static atomic_t n_rcu_torture_error;
66958 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
66959 +static atomic_unchecked_t n_rcu_torture_alloc;
66960 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
66961 +static atomic_unchecked_t n_rcu_torture_free;
66962 +static atomic_unchecked_t n_rcu_torture_mberror;
66963 +static atomic_unchecked_t n_rcu_torture_error;
66964 static long n_rcu_torture_boost_ktrerror;
66965 static long n_rcu_torture_boost_rterror;
66966 static long n_rcu_torture_boost_failure;
66967 @@ -243,11 +243,11 @@ rcu_torture_alloc(void)
66968
66969 spin_lock_bh(&rcu_torture_lock);
66970 if (list_empty(&rcu_torture_freelist)) {
66971 - atomic_inc(&n_rcu_torture_alloc_fail);
66972 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
66973 spin_unlock_bh(&rcu_torture_lock);
66974 return NULL;
66975 }
66976 - atomic_inc(&n_rcu_torture_alloc);
66977 + atomic_inc_unchecked(&n_rcu_torture_alloc);
66978 p = rcu_torture_freelist.next;
66979 list_del_init(p);
66980 spin_unlock_bh(&rcu_torture_lock);
66981 @@ -260,7 +260,7 @@ rcu_torture_alloc(void)
66982 static void
66983 rcu_torture_free(struct rcu_torture *p)
66984 {
66985 - atomic_inc(&n_rcu_torture_free);
66986 + atomic_inc_unchecked(&n_rcu_torture_free);
66987 spin_lock_bh(&rcu_torture_lock);
66988 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
66989 spin_unlock_bh(&rcu_torture_lock);
66990 @@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
66991 i = rp->rtort_pipe_count;
66992 if (i > RCU_TORTURE_PIPE_LEN)
66993 i = RCU_TORTURE_PIPE_LEN;
66994 - atomic_inc(&rcu_torture_wcount[i]);
66995 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
66996 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
66997 rp->rtort_mbtest = 0;
66998 rcu_torture_free(rp);
66999 @@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
67000 i = rp->rtort_pipe_count;
67001 if (i > RCU_TORTURE_PIPE_LEN)
67002 i = RCU_TORTURE_PIPE_LEN;
67003 - atomic_inc(&rcu_torture_wcount[i]);
67004 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67005 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67006 rp->rtort_mbtest = 0;
67007 list_del(&rp->rtort_free);
67008 @@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
67009 i = old_rp->rtort_pipe_count;
67010 if (i > RCU_TORTURE_PIPE_LEN)
67011 i = RCU_TORTURE_PIPE_LEN;
67012 - atomic_inc(&rcu_torture_wcount[i]);
67013 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67014 old_rp->rtort_pipe_count++;
67015 cur_ops->deferred_free(old_rp);
67016 }
67017 @@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
67018 return;
67019 }
67020 if (p->rtort_mbtest == 0)
67021 - atomic_inc(&n_rcu_torture_mberror);
67022 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67023 spin_lock(&rand_lock);
67024 cur_ops->read_delay(&rand);
67025 n_rcu_torture_timers++;
67026 @@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
67027 continue;
67028 }
67029 if (p->rtort_mbtest == 0)
67030 - atomic_inc(&n_rcu_torture_mberror);
67031 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67032 cur_ops->read_delay(&rand);
67033 preempt_disable();
67034 pipe_count = p->rtort_pipe_count;
67035 @@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
67036 rcu_torture_current,
67037 rcu_torture_current_version,
67038 list_empty(&rcu_torture_freelist),
67039 - atomic_read(&n_rcu_torture_alloc),
67040 - atomic_read(&n_rcu_torture_alloc_fail),
67041 - atomic_read(&n_rcu_torture_free),
67042 - atomic_read(&n_rcu_torture_mberror),
67043 + atomic_read_unchecked(&n_rcu_torture_alloc),
67044 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
67045 + atomic_read_unchecked(&n_rcu_torture_free),
67046 + atomic_read_unchecked(&n_rcu_torture_mberror),
67047 n_rcu_torture_boost_ktrerror,
67048 n_rcu_torture_boost_rterror,
67049 n_rcu_torture_boost_failure,
67050 @@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
67051 n_online_attempts,
67052 n_offline_successes,
67053 n_offline_attempts);
67054 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
67055 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
67056 n_rcu_torture_boost_ktrerror != 0 ||
67057 n_rcu_torture_boost_rterror != 0 ||
67058 n_rcu_torture_boost_failure != 0)
67059 @@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
67060 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
67061 if (i > 1) {
67062 cnt += sprintf(&page[cnt], "!!! ");
67063 - atomic_inc(&n_rcu_torture_error);
67064 + atomic_inc_unchecked(&n_rcu_torture_error);
67065 WARN_ON_ONCE(1);
67066 }
67067 cnt += sprintf(&page[cnt], "Reader Pipe: ");
67068 @@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
67069 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
67070 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67071 cnt += sprintf(&page[cnt], " %d",
67072 - atomic_read(&rcu_torture_wcount[i]));
67073 + atomic_read_unchecked(&rcu_torture_wcount[i]));
67074 }
67075 cnt += sprintf(&page[cnt], "\n");
67076 if (cur_ops->stats)
67077 @@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
67078
67079 if (cur_ops->cleanup)
67080 cur_ops->cleanup();
67081 - if (atomic_read(&n_rcu_torture_error))
67082 + if (atomic_read_unchecked(&n_rcu_torture_error))
67083 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
67084 else
67085 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
67086 @@ -1664,17 +1664,17 @@ rcu_torture_init(void)
67087
67088 rcu_torture_current = NULL;
67089 rcu_torture_current_version = 0;
67090 - atomic_set(&n_rcu_torture_alloc, 0);
67091 - atomic_set(&n_rcu_torture_alloc_fail, 0);
67092 - atomic_set(&n_rcu_torture_free, 0);
67093 - atomic_set(&n_rcu_torture_mberror, 0);
67094 - atomic_set(&n_rcu_torture_error, 0);
67095 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
67096 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
67097 + atomic_set_unchecked(&n_rcu_torture_free, 0);
67098 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
67099 + atomic_set_unchecked(&n_rcu_torture_error, 0);
67100 n_rcu_torture_boost_ktrerror = 0;
67101 n_rcu_torture_boost_rterror = 0;
67102 n_rcu_torture_boost_failure = 0;
67103 n_rcu_torture_boosts = 0;
67104 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
67105 - atomic_set(&rcu_torture_wcount[i], 0);
67106 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
67107 for_each_possible_cpu(cpu) {
67108 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67109 per_cpu(rcu_torture_count, cpu)[i] = 0;
67110 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
67111 index 6c4a672..70f3202 100644
67112 --- a/kernel/rcutree.c
67113 +++ b/kernel/rcutree.c
67114 @@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
67115 rcu_prepare_for_idle(smp_processor_id());
67116 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67117 smp_mb__before_atomic_inc(); /* See above. */
67118 - atomic_inc(&rdtp->dynticks);
67119 + atomic_inc_unchecked(&rdtp->dynticks);
67120 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
67121 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67122 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67123 }
67124
67125 /**
67126 @@ -438,10 +438,10 @@ void rcu_irq_exit(void)
67127 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
67128 {
67129 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
67130 - atomic_inc(&rdtp->dynticks);
67131 + atomic_inc_unchecked(&rdtp->dynticks);
67132 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67133 smp_mb__after_atomic_inc(); /* See above. */
67134 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67135 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67136 rcu_cleanup_after_idle(smp_processor_id());
67137 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
67138 if (!is_idle_task(current)) {
67139 @@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
67140 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
67141
67142 if (rdtp->dynticks_nmi_nesting == 0 &&
67143 - (atomic_read(&rdtp->dynticks) & 0x1))
67144 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
67145 return;
67146 rdtp->dynticks_nmi_nesting++;
67147 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
67148 - atomic_inc(&rdtp->dynticks);
67149 + atomic_inc_unchecked(&rdtp->dynticks);
67150 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67151 smp_mb__after_atomic_inc(); /* See above. */
67152 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67153 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67154 }
67155
67156 /**
67157 @@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
67158 return;
67159 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67160 smp_mb__before_atomic_inc(); /* See above. */
67161 - atomic_inc(&rdtp->dynticks);
67162 + atomic_inc_unchecked(&rdtp->dynticks);
67163 smp_mb__after_atomic_inc(); /* Force delay to next write. */
67164 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67165 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67166 }
67167
67168 #ifdef CONFIG_PROVE_RCU
67169 @@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
67170 int ret;
67171
67172 preempt_disable();
67173 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67174 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67175 preempt_enable();
67176 return ret;
67177 }
67178 @@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
67179 */
67180 static int dyntick_save_progress_counter(struct rcu_data *rdp)
67181 {
67182 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
67183 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67184 return (rdp->dynticks_snap & 0x1) == 0;
67185 }
67186
67187 @@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
67188 unsigned int curr;
67189 unsigned int snap;
67190
67191 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
67192 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67193 snap = (unsigned int)rdp->dynticks_snap;
67194
67195 /*
67196 @@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
67197 /*
67198 * Do RCU core processing for the current CPU.
67199 */
67200 -static void rcu_process_callbacks(struct softirq_action *unused)
67201 +static void rcu_process_callbacks(void)
67202 {
67203 trace_rcu_utilization("Start RCU core");
67204 __rcu_process_callbacks(&rcu_sched_state,
67205 @@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
67206 rdp->qlen = 0;
67207 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
67208 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
67209 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
67210 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
67211 rdp->cpu = cpu;
67212 rdp->rsp = rsp;
67213 raw_spin_unlock_irqrestore(&rnp->lock, flags);
67214 @@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
67215 rdp->n_force_qs_snap = rsp->n_force_qs;
67216 rdp->blimit = blimit;
67217 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
67218 - atomic_set(&rdp->dynticks->dynticks,
67219 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
67220 + atomic_set_unchecked(&rdp->dynticks->dynticks,
67221 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
67222 rcu_prepare_for_idle_init(cpu);
67223 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
67224
67225 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
67226 index fddff92..2c08359 100644
67227 --- a/kernel/rcutree.h
67228 +++ b/kernel/rcutree.h
67229 @@ -87,7 +87,7 @@ struct rcu_dynticks {
67230 long long dynticks_nesting; /* Track irq/process nesting level. */
67231 /* Process level is worth LLONG_MAX/2. */
67232 int dynticks_nmi_nesting; /* Track NMI nesting level. */
67233 - atomic_t dynticks; /* Even value for idle, else odd. */
67234 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
67235 };
67236
67237 /* RCU's kthread states for tracing. */
67238 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
67239 index 8bb35d7..6ea0a463 100644
67240 --- a/kernel/rcutree_plugin.h
67241 +++ b/kernel/rcutree_plugin.h
67242 @@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
67243
67244 /* Clean up and exit. */
67245 smp_mb(); /* ensure expedited GP seen before counter increment. */
67246 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
67247 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
67248 unlock_mb_ret:
67249 mutex_unlock(&sync_rcu_preempt_exp_mutex);
67250 mb_ret:
67251 @@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
67252
67253 #else /* #ifndef CONFIG_SMP */
67254
67255 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
67256 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
67257 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
67258 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
67259
67260 static int synchronize_sched_expedited_cpu_stop(void *data)
67261 {
67262 @@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
67263 int firstsnap, s, snap, trycount = 0;
67264
67265 /* Note that atomic_inc_return() implies full memory barrier. */
67266 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
67267 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
67268 get_online_cpus();
67269
67270 /*
67271 @@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
67272 }
67273
67274 /* Check to see if someone else did our work for us. */
67275 - s = atomic_read(&sync_sched_expedited_done);
67276 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67277 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
67278 smp_mb(); /* ensure test happens before caller kfree */
67279 return;
67280 @@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
67281 * grace period works for us.
67282 */
67283 get_online_cpus();
67284 - snap = atomic_read(&sync_sched_expedited_started);
67285 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
67286 smp_mb(); /* ensure read is before try_stop_cpus(). */
67287 }
67288
67289 @@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
67290 * than we did beat us to the punch.
67291 */
67292 do {
67293 - s = atomic_read(&sync_sched_expedited_done);
67294 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67295 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
67296 smp_mb(); /* ensure test happens before caller kfree */
67297 break;
67298 }
67299 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
67300 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
67301
67302 put_online_cpus();
67303 }
67304 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
67305 index 654cfe6..c0b28e2 100644
67306 --- a/kernel/rcutree_trace.c
67307 +++ b/kernel/rcutree_trace.c
67308 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
67309 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67310 rdp->qs_pending);
67311 seq_printf(m, " dt=%d/%llx/%d df=%lu",
67312 - atomic_read(&rdp->dynticks->dynticks),
67313 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67314 rdp->dynticks->dynticks_nesting,
67315 rdp->dynticks->dynticks_nmi_nesting,
67316 rdp->dynticks_fqs);
67317 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
67318 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67319 rdp->qs_pending);
67320 seq_printf(m, ",%d,%llx,%d,%lu",
67321 - atomic_read(&rdp->dynticks->dynticks),
67322 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67323 rdp->dynticks->dynticks_nesting,
67324 rdp->dynticks->dynticks_nmi_nesting,
67325 rdp->dynticks_fqs);
67326 diff --git a/kernel/resource.c b/kernel/resource.c
67327 index 7640b3a..5879283 100644
67328 --- a/kernel/resource.c
67329 +++ b/kernel/resource.c
67330 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
67331
67332 static int __init ioresources_init(void)
67333 {
67334 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67335 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67336 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
67337 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
67338 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67339 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
67340 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
67341 +#endif
67342 +#else
67343 proc_create("ioports", 0, NULL, &proc_ioports_operations);
67344 proc_create("iomem", 0, NULL, &proc_iomem_operations);
67345 +#endif
67346 return 0;
67347 }
67348 __initcall(ioresources_init);
67349 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
67350 index 98ec494..4241d6d 100644
67351 --- a/kernel/rtmutex-tester.c
67352 +++ b/kernel/rtmutex-tester.c
67353 @@ -20,7 +20,7 @@
67354 #define MAX_RT_TEST_MUTEXES 8
67355
67356 static spinlock_t rttest_lock;
67357 -static atomic_t rttest_event;
67358 +static atomic_unchecked_t rttest_event;
67359
67360 struct test_thread_data {
67361 int opcode;
67362 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67363
67364 case RTTEST_LOCKCONT:
67365 td->mutexes[td->opdata] = 1;
67366 - td->event = atomic_add_return(1, &rttest_event);
67367 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67368 return 0;
67369
67370 case RTTEST_RESET:
67371 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67372 return 0;
67373
67374 case RTTEST_RESETEVENT:
67375 - atomic_set(&rttest_event, 0);
67376 + atomic_set_unchecked(&rttest_event, 0);
67377 return 0;
67378
67379 default:
67380 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67381 return ret;
67382
67383 td->mutexes[id] = 1;
67384 - td->event = atomic_add_return(1, &rttest_event);
67385 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67386 rt_mutex_lock(&mutexes[id]);
67387 - td->event = atomic_add_return(1, &rttest_event);
67388 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67389 td->mutexes[id] = 4;
67390 return 0;
67391
67392 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67393 return ret;
67394
67395 td->mutexes[id] = 1;
67396 - td->event = atomic_add_return(1, &rttest_event);
67397 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67398 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
67399 - td->event = atomic_add_return(1, &rttest_event);
67400 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67401 td->mutexes[id] = ret ? 0 : 4;
67402 return ret ? -EINTR : 0;
67403
67404 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67405 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
67406 return ret;
67407
67408 - td->event = atomic_add_return(1, &rttest_event);
67409 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67410 rt_mutex_unlock(&mutexes[id]);
67411 - td->event = atomic_add_return(1, &rttest_event);
67412 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67413 td->mutexes[id] = 0;
67414 return 0;
67415
67416 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67417 break;
67418
67419 td->mutexes[dat] = 2;
67420 - td->event = atomic_add_return(1, &rttest_event);
67421 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67422 break;
67423
67424 default:
67425 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67426 return;
67427
67428 td->mutexes[dat] = 3;
67429 - td->event = atomic_add_return(1, &rttest_event);
67430 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67431 break;
67432
67433 case RTTEST_LOCKNOWAIT:
67434 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67435 return;
67436
67437 td->mutexes[dat] = 1;
67438 - td->event = atomic_add_return(1, &rttest_event);
67439 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67440 return;
67441
67442 default:
67443 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
67444 index e8a1f83..363d17d 100644
67445 --- a/kernel/sched/auto_group.c
67446 +++ b/kernel/sched/auto_group.c
67447 @@ -11,7 +11,7 @@
67448
67449 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
67450 static struct autogroup autogroup_default;
67451 -static atomic_t autogroup_seq_nr;
67452 +static atomic_unchecked_t autogroup_seq_nr;
67453
67454 void __init autogroup_init(struct task_struct *init_task)
67455 {
67456 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
67457
67458 kref_init(&ag->kref);
67459 init_rwsem(&ag->lock);
67460 - ag->id = atomic_inc_return(&autogroup_seq_nr);
67461 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
67462 ag->tg = tg;
67463 #ifdef CONFIG_RT_GROUP_SCHED
67464 /*
67465 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
67466 index b342f57..00324a0 100644
67467 --- a/kernel/sched/core.c
67468 +++ b/kernel/sched/core.c
67469 @@ -3143,6 +3143,19 @@ pick_next_task(struct rq *rq)
67470 BUG(); /* the idle class will always have a runnable task */
67471 }
67472
67473 +#ifdef CONFIG_GRKERNSEC_SETXID
67474 +extern void gr_delayed_cred_worker(void);
67475 +static inline void gr_cred_schedule(void)
67476 +{
67477 + if (unlikely(current->delayed_cred))
67478 + gr_delayed_cred_worker();
67479 +}
67480 +#else
67481 +static inline void gr_cred_schedule(void)
67482 +{
67483 +}
67484 +#endif
67485 +
67486 /*
67487 * __schedule() is the main scheduler function.
67488 */
67489 @@ -3162,6 +3175,8 @@ need_resched:
67490
67491 schedule_debug(prev);
67492
67493 + gr_cred_schedule();
67494 +
67495 if (sched_feat(HRTICK))
67496 hrtick_clear(rq);
67497
67498 @@ -3852,6 +3867,8 @@ int can_nice(const struct task_struct *p, const int nice)
67499 /* convert nice value [19,-20] to rlimit style value [1,40] */
67500 int nice_rlim = 20 - nice;
67501
67502 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
67503 +
67504 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
67505 capable(CAP_SYS_NICE));
67506 }
67507 @@ -3885,7 +3902,8 @@ SYSCALL_DEFINE1(nice, int, increment)
67508 if (nice > 19)
67509 nice = 19;
67510
67511 - if (increment < 0 && !can_nice(current, nice))
67512 + if (increment < 0 && (!can_nice(current, nice) ||
67513 + gr_handle_chroot_nice()))
67514 return -EPERM;
67515
67516 retval = security_task_setnice(current, nice);
67517 @@ -4042,6 +4060,7 @@ recheck:
67518 unsigned long rlim_rtprio =
67519 task_rlimit(p, RLIMIT_RTPRIO);
67520
67521 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
67522 /* can't set/change the rt policy */
67523 if (policy != p->policy && !rlim_rtprio)
67524 return -EPERM;
67525 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
67526 index aca16b8..8e3acc4 100644
67527 --- a/kernel/sched/fair.c
67528 +++ b/kernel/sched/fair.c
67529 @@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
67530 * run_rebalance_domains is triggered when needed from the scheduler tick.
67531 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
67532 */
67533 -static void run_rebalance_domains(struct softirq_action *h)
67534 +static void run_rebalance_domains(void)
67535 {
67536 int this_cpu = smp_processor_id();
67537 struct rq *this_rq = cpu_rq(this_cpu);
67538 diff --git a/kernel/signal.c b/kernel/signal.c
67539 index c73c428..7040057 100644
67540 --- a/kernel/signal.c
67541 +++ b/kernel/signal.c
67542 @@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
67543
67544 int print_fatal_signals __read_mostly;
67545
67546 -static void __user *sig_handler(struct task_struct *t, int sig)
67547 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
67548 {
67549 return t->sighand->action[sig - 1].sa.sa_handler;
67550 }
67551
67552 -static int sig_handler_ignored(void __user *handler, int sig)
67553 +static int sig_handler_ignored(__sighandler_t handler, int sig)
67554 {
67555 /* Is it explicitly or implicitly ignored? */
67556 return handler == SIG_IGN ||
67557 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
67558 static int sig_task_ignored(struct task_struct *t, int sig,
67559 int from_ancestor_ns)
67560 {
67561 - void __user *handler;
67562 + __sighandler_t handler;
67563
67564 handler = sig_handler(t, sig);
67565
67566 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
67567 atomic_inc(&user->sigpending);
67568 rcu_read_unlock();
67569
67570 + if (!override_rlimit)
67571 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
67572 +
67573 if (override_rlimit ||
67574 atomic_read(&user->sigpending) <=
67575 task_rlimit(t, RLIMIT_SIGPENDING)) {
67576 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
67577
67578 int unhandled_signal(struct task_struct *tsk, int sig)
67579 {
67580 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
67581 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
67582 if (is_global_init(tsk))
67583 return 1;
67584 if (handler != SIG_IGN && handler != SIG_DFL)
67585 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
67586 }
67587 }
67588
67589 + /* allow glibc communication via tgkill to other threads in our
67590 + thread group */
67591 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
67592 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
67593 + && gr_handle_signal(t, sig))
67594 + return -EPERM;
67595 +
67596 return security_task_kill(t, info, sig, 0);
67597 }
67598
67599 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
67600 return send_signal(sig, info, p, 1);
67601 }
67602
67603 -static int
67604 +int
67605 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67606 {
67607 return send_signal(sig, info, t, 0);
67608 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67609 unsigned long int flags;
67610 int ret, blocked, ignored;
67611 struct k_sigaction *action;
67612 + int is_unhandled = 0;
67613
67614 spin_lock_irqsave(&t->sighand->siglock, flags);
67615 action = &t->sighand->action[sig-1];
67616 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67617 }
67618 if (action->sa.sa_handler == SIG_DFL)
67619 t->signal->flags &= ~SIGNAL_UNKILLABLE;
67620 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
67621 + is_unhandled = 1;
67622 ret = specific_send_sig_info(sig, info, t);
67623 spin_unlock_irqrestore(&t->sighand->siglock, flags);
67624
67625 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
67626 + normal operation */
67627 + if (is_unhandled) {
67628 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
67629 + gr_handle_crash(t, sig);
67630 + }
67631 +
67632 return ret;
67633 }
67634
67635 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
67636 ret = check_kill_permission(sig, info, p);
67637 rcu_read_unlock();
67638
67639 - if (!ret && sig)
67640 + if (!ret && sig) {
67641 ret = do_send_sig_info(sig, info, p, true);
67642 + if (!ret)
67643 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
67644 + }
67645
67646 return ret;
67647 }
67648 @@ -2820,7 +2843,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
67649 int error = -ESRCH;
67650
67651 rcu_read_lock();
67652 - p = find_task_by_vpid(pid);
67653 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
67654 + /* allow glibc communication via tgkill to other threads in our
67655 + thread group */
67656 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
67657 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
67658 + p = find_task_by_vpid_unrestricted(pid);
67659 + else
67660 +#endif
67661 + p = find_task_by_vpid(pid);
67662 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
67663 error = check_kill_permission(sig, info, p);
67664 /*
67665 diff --git a/kernel/smp.c b/kernel/smp.c
67666 index db197d6..17aef0b 100644
67667 --- a/kernel/smp.c
67668 +++ b/kernel/smp.c
67669 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
67670 }
67671 EXPORT_SYMBOL(smp_call_function);
67672
67673 -void ipi_call_lock(void)
67674 +void ipi_call_lock(void) __acquires(call_function.lock)
67675 {
67676 raw_spin_lock(&call_function.lock);
67677 }
67678
67679 -void ipi_call_unlock(void)
67680 +void ipi_call_unlock(void) __releases(call_function.lock)
67681 {
67682 raw_spin_unlock(&call_function.lock);
67683 }
67684
67685 -void ipi_call_lock_irq(void)
67686 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
67687 {
67688 raw_spin_lock_irq(&call_function.lock);
67689 }
67690
67691 -void ipi_call_unlock_irq(void)
67692 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
67693 {
67694 raw_spin_unlock_irq(&call_function.lock);
67695 }
67696 diff --git a/kernel/softirq.c b/kernel/softirq.c
67697 index 4eb3a0f..6f1fa81 100644
67698 --- a/kernel/softirq.c
67699 +++ b/kernel/softirq.c
67700 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
67701
67702 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
67703
67704 -char *softirq_to_name[NR_SOFTIRQS] = {
67705 +const char * const softirq_to_name[NR_SOFTIRQS] = {
67706 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
67707 "TASKLET", "SCHED", "HRTIMER", "RCU"
67708 };
67709 @@ -235,7 +235,7 @@ restart:
67710 kstat_incr_softirqs_this_cpu(vec_nr);
67711
67712 trace_softirq_entry(vec_nr);
67713 - h->action(h);
67714 + h->action();
67715 trace_softirq_exit(vec_nr);
67716 if (unlikely(prev_count != preempt_count())) {
67717 printk(KERN_ERR "huh, entered softirq %u %s %p"
67718 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
67719 local_irq_restore(flags);
67720 }
67721
67722 -void open_softirq(int nr, void (*action)(struct softirq_action *))
67723 +void open_softirq(int nr, void (*action)(void))
67724 {
67725 - softirq_vec[nr].action = action;
67726 + pax_open_kernel();
67727 + *(void **)&softirq_vec[nr].action = action;
67728 + pax_close_kernel();
67729 }
67730
67731 /*
67732 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
67733
67734 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
67735
67736 -static void tasklet_action(struct softirq_action *a)
67737 +static void tasklet_action(void)
67738 {
67739 struct tasklet_struct *list;
67740
67741 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
67742 }
67743 }
67744
67745 -static void tasklet_hi_action(struct softirq_action *a)
67746 +static void tasklet_hi_action(void)
67747 {
67748 struct tasklet_struct *list;
67749
67750 diff --git a/kernel/sys.c b/kernel/sys.c
67751 index 888d227..f04b318 100644
67752 --- a/kernel/sys.c
67753 +++ b/kernel/sys.c
67754 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
67755 error = -EACCES;
67756 goto out;
67757 }
67758 +
67759 + if (gr_handle_chroot_setpriority(p, niceval)) {
67760 + error = -EACCES;
67761 + goto out;
67762 + }
67763 +
67764 no_nice = security_task_setnice(p, niceval);
67765 if (no_nice) {
67766 error = no_nice;
67767 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
67768 goto error;
67769 }
67770
67771 + if (gr_check_group_change(new->gid, new->egid, -1))
67772 + goto error;
67773 +
67774 if (rgid != (gid_t) -1 ||
67775 (egid != (gid_t) -1 && egid != old->gid))
67776 new->sgid = new->egid;
67777 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
67778 old = current_cred();
67779
67780 retval = -EPERM;
67781 +
67782 + if (gr_check_group_change(gid, gid, gid))
67783 + goto error;
67784 +
67785 if (nsown_capable(CAP_SETGID))
67786 new->gid = new->egid = new->sgid = new->fsgid = gid;
67787 else if (gid == old->gid || gid == old->sgid)
67788 @@ -618,7 +631,7 @@ error:
67789 /*
67790 * change the user struct in a credentials set to match the new UID
67791 */
67792 -static int set_user(struct cred *new)
67793 +int set_user(struct cred *new)
67794 {
67795 struct user_struct *new_user;
67796
67797 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
67798 goto error;
67799 }
67800
67801 + if (gr_check_user_change(new->uid, new->euid, -1))
67802 + goto error;
67803 +
67804 if (new->uid != old->uid) {
67805 retval = set_user(new);
67806 if (retval < 0)
67807 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
67808 old = current_cred();
67809
67810 retval = -EPERM;
67811 +
67812 + if (gr_check_crash_uid(uid))
67813 + goto error;
67814 + if (gr_check_user_change(uid, uid, uid))
67815 + goto error;
67816 +
67817 if (nsown_capable(CAP_SETUID)) {
67818 new->suid = new->uid = uid;
67819 if (uid != old->uid) {
67820 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
67821 goto error;
67822 }
67823
67824 + if (gr_check_user_change(ruid, euid, -1))
67825 + goto error;
67826 +
67827 if (ruid != (uid_t) -1) {
67828 new->uid = ruid;
67829 if (ruid != old->uid) {
67830 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
67831 goto error;
67832 }
67833
67834 + if (gr_check_group_change(rgid, egid, -1))
67835 + goto error;
67836 +
67837 if (rgid != (gid_t) -1)
67838 new->gid = rgid;
67839 if (egid != (gid_t) -1)
67840 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
67841 old = current_cred();
67842 old_fsuid = old->fsuid;
67843
67844 + if (gr_check_user_change(-1, -1, uid))
67845 + goto error;
67846 +
67847 if (uid == old->uid || uid == old->euid ||
67848 uid == old->suid || uid == old->fsuid ||
67849 nsown_capable(CAP_SETUID)) {
67850 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
67851 }
67852 }
67853
67854 +error:
67855 abort_creds(new);
67856 return old_fsuid;
67857
67858 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
67859 if (gid == old->gid || gid == old->egid ||
67860 gid == old->sgid || gid == old->fsgid ||
67861 nsown_capable(CAP_SETGID)) {
67862 + if (gr_check_group_change(-1, -1, gid))
67863 + goto error;
67864 +
67865 if (gid != old_fsgid) {
67866 new->fsgid = gid;
67867 goto change_okay;
67868 }
67869 }
67870
67871 +error:
67872 abort_creds(new);
67873 return old_fsgid;
67874
67875 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
67876 }
67877 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
67878 snprintf(buf, len, "2.6.%u%s", v, rest);
67879 - ret = copy_to_user(release, buf, len);
67880 + if (len > sizeof(buf))
67881 + ret = -EFAULT;
67882 + else
67883 + ret = copy_to_user(release, buf, len);
67884 }
67885 return ret;
67886 }
67887 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
67888 return -EFAULT;
67889
67890 down_read(&uts_sem);
67891 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
67892 + error = __copy_to_user(name->sysname, &utsname()->sysname,
67893 __OLD_UTS_LEN);
67894 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
67895 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
67896 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
67897 __OLD_UTS_LEN);
67898 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
67899 - error |= __copy_to_user(&name->release, &utsname()->release,
67900 + error |= __copy_to_user(name->release, &utsname()->release,
67901 __OLD_UTS_LEN);
67902 error |= __put_user(0, name->release + __OLD_UTS_LEN);
67903 - error |= __copy_to_user(&name->version, &utsname()->version,
67904 + error |= __copy_to_user(name->version, &utsname()->version,
67905 __OLD_UTS_LEN);
67906 error |= __put_user(0, name->version + __OLD_UTS_LEN);
67907 - error |= __copy_to_user(&name->machine, &utsname()->machine,
67908 + error |= __copy_to_user(name->machine, &utsname()->machine,
67909 __OLD_UTS_LEN);
67910 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
67911 up_read(&uts_sem);
67912 @@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
67913 error = get_dumpable(me->mm);
67914 break;
67915 case PR_SET_DUMPABLE:
67916 - if (arg2 < 0 || arg2 > 1) {
67917 + if (arg2 > 1) {
67918 error = -EINVAL;
67919 break;
67920 }
67921 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
67922 index f487f25..9056a9e 100644
67923 --- a/kernel/sysctl.c
67924 +++ b/kernel/sysctl.c
67925 @@ -86,6 +86,13 @@
67926
67927
67928 #if defined(CONFIG_SYSCTL)
67929 +#include <linux/grsecurity.h>
67930 +#include <linux/grinternal.h>
67931 +
67932 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
67933 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67934 + const int op);
67935 +extern int gr_handle_chroot_sysctl(const int op);
67936
67937 /* External variables not in a header file. */
67938 extern int sysctl_overcommit_memory;
67939 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
67940 }
67941
67942 #endif
67943 +extern struct ctl_table grsecurity_table[];
67944
67945 static struct ctl_table root_table[];
67946 static struct ctl_table_root sysctl_table_root;
67947 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
67948 int sysctl_legacy_va_layout;
67949 #endif
67950
67951 +#ifdef CONFIG_PAX_SOFTMODE
67952 +static ctl_table pax_table[] = {
67953 + {
67954 + .procname = "softmode",
67955 + .data = &pax_softmode,
67956 + .maxlen = sizeof(unsigned int),
67957 + .mode = 0600,
67958 + .proc_handler = &proc_dointvec,
67959 + },
67960 +
67961 + { }
67962 +};
67963 +#endif
67964 +
67965 /* The default sysctl tables: */
67966
67967 static struct ctl_table root_table[] = {
67968 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
67969 #endif
67970
67971 static struct ctl_table kern_table[] = {
67972 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
67973 + {
67974 + .procname = "grsecurity",
67975 + .mode = 0500,
67976 + .child = grsecurity_table,
67977 + },
67978 +#endif
67979 +
67980 +#ifdef CONFIG_PAX_SOFTMODE
67981 + {
67982 + .procname = "pax",
67983 + .mode = 0500,
67984 + .child = pax_table,
67985 + },
67986 +#endif
67987 +
67988 {
67989 .procname = "sched_child_runs_first",
67990 .data = &sysctl_sched_child_runs_first,
67991 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
67992 .data = &modprobe_path,
67993 .maxlen = KMOD_PATH_LEN,
67994 .mode = 0644,
67995 - .proc_handler = proc_dostring,
67996 + .proc_handler = proc_dostring_modpriv,
67997 },
67998 {
67999 .procname = "modules_disabled",
68000 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
68001 .extra1 = &zero,
68002 .extra2 = &one,
68003 },
68004 +#endif
68005 {
68006 .procname = "kptr_restrict",
68007 .data = &kptr_restrict,
68008 .maxlen = sizeof(int),
68009 .mode = 0644,
68010 .proc_handler = proc_dmesg_restrict,
68011 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68012 + .extra1 = &two,
68013 +#else
68014 .extra1 = &zero,
68015 +#endif
68016 .extra2 = &two,
68017 },
68018 -#endif
68019 {
68020 .procname = "ngroups_max",
68021 .data = &ngroups_max,
68022 @@ -1225,6 +1267,13 @@ static struct ctl_table vm_table[] = {
68023 .proc_handler = proc_dointvec_minmax,
68024 .extra1 = &zero,
68025 },
68026 + {
68027 + .procname = "heap_stack_gap",
68028 + .data = &sysctl_heap_stack_gap,
68029 + .maxlen = sizeof(sysctl_heap_stack_gap),
68030 + .mode = 0644,
68031 + .proc_handler = proc_doulongvec_minmax,
68032 + },
68033 #else
68034 {
68035 .procname = "nr_trim_pages",
68036 @@ -1729,6 +1778,17 @@ static int test_perm(int mode, int op)
68037 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
68038 {
68039 int mode;
68040 + int error;
68041 +
68042 + if (table->parent != NULL && table->parent->procname != NULL &&
68043 + table->procname != NULL &&
68044 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
68045 + return -EACCES;
68046 + if (gr_handle_chroot_sysctl(op))
68047 + return -EACCES;
68048 + error = gr_handle_sysctl(table, op);
68049 + if (error)
68050 + return error;
68051
68052 if (root->permissions)
68053 mode = root->permissions(root, current->nsproxy, table);
68054 @@ -2133,6 +2193,16 @@ int proc_dostring(struct ctl_table *table, int write,
68055 buffer, lenp, ppos);
68056 }
68057
68058 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68059 + void __user *buffer, size_t *lenp, loff_t *ppos)
68060 +{
68061 + if (write && !capable(CAP_SYS_MODULE))
68062 + return -EPERM;
68063 +
68064 + return _proc_do_string(table->data, table->maxlen, write,
68065 + buffer, lenp, ppos);
68066 +}
68067 +
68068 static size_t proc_skip_spaces(char **buf)
68069 {
68070 size_t ret;
68071 @@ -2238,6 +2308,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
68072 len = strlen(tmp);
68073 if (len > *size)
68074 len = *size;
68075 + if (len > sizeof(tmp))
68076 + len = sizeof(tmp);
68077 if (copy_to_user(*buf, tmp, len))
68078 return -EFAULT;
68079 *size -= len;
68080 @@ -2554,8 +2626,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
68081 *i = val;
68082 } else {
68083 val = convdiv * (*i) / convmul;
68084 - if (!first)
68085 + if (!first) {
68086 err = proc_put_char(&buffer, &left, '\t');
68087 + if (err)
68088 + break;
68089 + }
68090 err = proc_put_long(&buffer, &left, val, false);
68091 if (err)
68092 break;
68093 @@ -2950,6 +3025,12 @@ int proc_dostring(struct ctl_table *table, int write,
68094 return -ENOSYS;
68095 }
68096
68097 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68098 + void __user *buffer, size_t *lenp, loff_t *ppos)
68099 +{
68100 + return -ENOSYS;
68101 +}
68102 +
68103 int proc_dointvec(struct ctl_table *table, int write,
68104 void __user *buffer, size_t *lenp, loff_t *ppos)
68105 {
68106 @@ -3006,6 +3087,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
68107 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
68108 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
68109 EXPORT_SYMBOL(proc_dostring);
68110 +EXPORT_SYMBOL(proc_dostring_modpriv);
68111 EXPORT_SYMBOL(proc_doulongvec_minmax);
68112 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
68113 EXPORT_SYMBOL(register_sysctl_table);
68114 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
68115 index a650694..aaeeb20 100644
68116 --- a/kernel/sysctl_binary.c
68117 +++ b/kernel/sysctl_binary.c
68118 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
68119 int i;
68120
68121 set_fs(KERNEL_DS);
68122 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68123 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68124 set_fs(old_fs);
68125 if (result < 0)
68126 goto out_kfree;
68127 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
68128 }
68129
68130 set_fs(KERNEL_DS);
68131 - result = vfs_write(file, buffer, str - buffer, &pos);
68132 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68133 set_fs(old_fs);
68134 if (result < 0)
68135 goto out_kfree;
68136 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
68137 int i;
68138
68139 set_fs(KERNEL_DS);
68140 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68141 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68142 set_fs(old_fs);
68143 if (result < 0)
68144 goto out_kfree;
68145 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
68146 }
68147
68148 set_fs(KERNEL_DS);
68149 - result = vfs_write(file, buffer, str - buffer, &pos);
68150 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68151 set_fs(old_fs);
68152 if (result < 0)
68153 goto out_kfree;
68154 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
68155 int i;
68156
68157 set_fs(KERNEL_DS);
68158 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68159 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68160 set_fs(old_fs);
68161 if (result < 0)
68162 goto out;
68163 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68164 __le16 dnaddr;
68165
68166 set_fs(KERNEL_DS);
68167 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68168 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68169 set_fs(old_fs);
68170 if (result < 0)
68171 goto out;
68172 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68173 le16_to_cpu(dnaddr) & 0x3ff);
68174
68175 set_fs(KERNEL_DS);
68176 - result = vfs_write(file, buf, len, &pos);
68177 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
68178 set_fs(old_fs);
68179 if (result < 0)
68180 goto out;
68181 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
68182 index 362da65..ab8ef8c 100644
68183 --- a/kernel/sysctl_check.c
68184 +++ b/kernel/sysctl_check.c
68185 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
68186 set_fail(&fail, table, "Directory with extra2");
68187 } else {
68188 if ((table->proc_handler == proc_dostring) ||
68189 + (table->proc_handler == proc_dostring_modpriv) ||
68190 (table->proc_handler == proc_dointvec) ||
68191 (table->proc_handler == proc_dointvec_minmax) ||
68192 (table->proc_handler == proc_dointvec_jiffies) ||
68193 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
68194 index e660464..c8b9e67 100644
68195 --- a/kernel/taskstats.c
68196 +++ b/kernel/taskstats.c
68197 @@ -27,9 +27,12 @@
68198 #include <linux/cgroup.h>
68199 #include <linux/fs.h>
68200 #include <linux/file.h>
68201 +#include <linux/grsecurity.h>
68202 #include <net/genetlink.h>
68203 #include <linux/atomic.h>
68204
68205 +extern int gr_is_taskstats_denied(int pid);
68206 +
68207 /*
68208 * Maximum length of a cpumask that can be specified in
68209 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
68210 @@ -556,6 +559,9 @@ err:
68211
68212 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
68213 {
68214 + if (gr_is_taskstats_denied(current->pid))
68215 + return -EACCES;
68216 +
68217 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
68218 return cmd_attr_register_cpumask(info);
68219 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
68220 diff --git a/kernel/time.c b/kernel/time.c
68221 index 73e416d..cfc6f69 100644
68222 --- a/kernel/time.c
68223 +++ b/kernel/time.c
68224 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
68225 return error;
68226
68227 if (tz) {
68228 + /* we log in do_settimeofday called below, so don't log twice
68229 + */
68230 + if (!tv)
68231 + gr_log_timechange();
68232 +
68233 /* SMP safe, global irq locking makes it work. */
68234 sys_tz = *tz;
68235 update_vsyscall_tz();
68236 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
68237 index 8a46f5d..bbe6f9c 100644
68238 --- a/kernel/time/alarmtimer.c
68239 +++ b/kernel/time/alarmtimer.c
68240 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
68241 struct platform_device *pdev;
68242 int error = 0;
68243 int i;
68244 - struct k_clock alarm_clock = {
68245 + static struct k_clock alarm_clock = {
68246 .clock_getres = alarm_clock_getres,
68247 .clock_get = alarm_clock_get,
68248 .timer_create = alarm_timer_create,
68249 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
68250 index fd4a7b1..fae5c2a 100644
68251 --- a/kernel/time/tick-broadcast.c
68252 +++ b/kernel/time/tick-broadcast.c
68253 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
68254 * then clear the broadcast bit.
68255 */
68256 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
68257 - int cpu = smp_processor_id();
68258 + cpu = smp_processor_id();
68259
68260 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
68261 tick_broadcast_clear_oneshot(cpu);
68262 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
68263 index 0c63581..e25dcb6 100644
68264 --- a/kernel/time/timekeeping.c
68265 +++ b/kernel/time/timekeeping.c
68266 @@ -14,6 +14,7 @@
68267 #include <linux/init.h>
68268 #include <linux/mm.h>
68269 #include <linux/sched.h>
68270 +#include <linux/grsecurity.h>
68271 #include <linux/syscore_ops.h>
68272 #include <linux/clocksource.h>
68273 #include <linux/jiffies.h>
68274 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
68275 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
68276 return -EINVAL;
68277
68278 + gr_log_timechange();
68279 +
68280 write_seqlock_irqsave(&xtime_lock, flags);
68281
68282 timekeeping_forward_now();
68283 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
68284 index 3258455..f35227d 100644
68285 --- a/kernel/time/timer_list.c
68286 +++ b/kernel/time/timer_list.c
68287 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
68288
68289 static void print_name_offset(struct seq_file *m, void *sym)
68290 {
68291 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68292 + SEQ_printf(m, "<%p>", NULL);
68293 +#else
68294 char symname[KSYM_NAME_LEN];
68295
68296 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
68297 SEQ_printf(m, "<%pK>", sym);
68298 else
68299 SEQ_printf(m, "%s", symname);
68300 +#endif
68301 }
68302
68303 static void
68304 @@ -112,7 +116,11 @@ next_one:
68305 static void
68306 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
68307 {
68308 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68309 + SEQ_printf(m, " .base: %p\n", NULL);
68310 +#else
68311 SEQ_printf(m, " .base: %pK\n", base);
68312 +#endif
68313 SEQ_printf(m, " .index: %d\n",
68314 base->index);
68315 SEQ_printf(m, " .resolution: %Lu nsecs\n",
68316 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
68317 {
68318 struct proc_dir_entry *pe;
68319
68320 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68321 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
68322 +#else
68323 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
68324 +#endif
68325 if (!pe)
68326 return -ENOMEM;
68327 return 0;
68328 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
68329 index 0b537f2..9e71eca 100644
68330 --- a/kernel/time/timer_stats.c
68331 +++ b/kernel/time/timer_stats.c
68332 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
68333 static unsigned long nr_entries;
68334 static struct entry entries[MAX_ENTRIES];
68335
68336 -static atomic_t overflow_count;
68337 +static atomic_unchecked_t overflow_count;
68338
68339 /*
68340 * The entries are in a hash-table, for fast lookup:
68341 @@ -140,7 +140,7 @@ static void reset_entries(void)
68342 nr_entries = 0;
68343 memset(entries, 0, sizeof(entries));
68344 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
68345 - atomic_set(&overflow_count, 0);
68346 + atomic_set_unchecked(&overflow_count, 0);
68347 }
68348
68349 static struct entry *alloc_entry(void)
68350 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68351 if (likely(entry))
68352 entry->count++;
68353 else
68354 - atomic_inc(&overflow_count);
68355 + atomic_inc_unchecked(&overflow_count);
68356
68357 out_unlock:
68358 raw_spin_unlock_irqrestore(lock, flags);
68359 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68360
68361 static void print_name_offset(struct seq_file *m, unsigned long addr)
68362 {
68363 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68364 + seq_printf(m, "<%p>", NULL);
68365 +#else
68366 char symname[KSYM_NAME_LEN];
68367
68368 if (lookup_symbol_name(addr, symname) < 0)
68369 seq_printf(m, "<%p>", (void *)addr);
68370 else
68371 seq_printf(m, "%s", symname);
68372 +#endif
68373 }
68374
68375 static int tstats_show(struct seq_file *m, void *v)
68376 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
68377
68378 seq_puts(m, "Timer Stats Version: v0.2\n");
68379 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
68380 - if (atomic_read(&overflow_count))
68381 + if (atomic_read_unchecked(&overflow_count))
68382 seq_printf(m, "Overflow: %d entries\n",
68383 - atomic_read(&overflow_count));
68384 + atomic_read_unchecked(&overflow_count));
68385
68386 for (i = 0; i < nr_entries; i++) {
68387 entry = entries + i;
68388 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
68389 {
68390 struct proc_dir_entry *pe;
68391
68392 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68393 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
68394 +#else
68395 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
68396 +#endif
68397 if (!pe)
68398 return -ENOMEM;
68399 return 0;
68400 diff --git a/kernel/timer.c b/kernel/timer.c
68401 index a297ffc..5e16b0b 100644
68402 --- a/kernel/timer.c
68403 +++ b/kernel/timer.c
68404 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
68405 /*
68406 * This function runs timers and the timer-tq in bottom half context.
68407 */
68408 -static void run_timer_softirq(struct softirq_action *h)
68409 +static void run_timer_softirq(void)
68410 {
68411 struct tvec_base *base = __this_cpu_read(tvec_bases);
68412
68413 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
68414 index cdea7b5..9b820d4 100644
68415 --- a/kernel/trace/blktrace.c
68416 +++ b/kernel/trace/blktrace.c
68417 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
68418 struct blk_trace *bt = filp->private_data;
68419 char buf[16];
68420
68421 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
68422 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
68423
68424 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
68425 }
68426 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
68427 return 1;
68428
68429 bt = buf->chan->private_data;
68430 - atomic_inc(&bt->dropped);
68431 + atomic_inc_unchecked(&bt->dropped);
68432 return 0;
68433 }
68434
68435 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
68436
68437 bt->dir = dir;
68438 bt->dev = dev;
68439 - atomic_set(&bt->dropped, 0);
68440 + atomic_set_unchecked(&bt->dropped, 0);
68441
68442 ret = -EIO;
68443 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
68444 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
68445 index 683d559..d70d914 100644
68446 --- a/kernel/trace/ftrace.c
68447 +++ b/kernel/trace/ftrace.c
68448 @@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
68449 if (unlikely(ftrace_disabled))
68450 return 0;
68451
68452 + ret = ftrace_arch_code_modify_prepare();
68453 + FTRACE_WARN_ON(ret);
68454 + if (ret)
68455 + return 0;
68456 +
68457 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
68458 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
68459 if (ret) {
68460 ftrace_bug(ret, ip);
68461 - return 0;
68462 }
68463 - return 1;
68464 + return ret ? 0 : 1;
68465 }
68466
68467 /*
68468 @@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
68469
68470 int
68471 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
68472 - void *data)
68473 + void *data)
68474 {
68475 struct ftrace_func_probe *entry;
68476 struct ftrace_page *pg;
68477 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
68478 index a3f1bc5..5e651718 100644
68479 --- a/kernel/trace/trace.c
68480 +++ b/kernel/trace/trace.c
68481 @@ -4254,10 +4254,9 @@ static const struct file_operations tracing_dyn_info_fops = {
68482 };
68483 #endif
68484
68485 -static struct dentry *d_tracer;
68486 -
68487 struct dentry *tracing_init_dentry(void)
68488 {
68489 + static struct dentry *d_tracer;
68490 static int once;
68491
68492 if (d_tracer)
68493 @@ -4277,10 +4276,9 @@ struct dentry *tracing_init_dentry(void)
68494 return d_tracer;
68495 }
68496
68497 -static struct dentry *d_percpu;
68498 -
68499 struct dentry *tracing_dentry_percpu(void)
68500 {
68501 + static struct dentry *d_percpu;
68502 static int once;
68503 struct dentry *d_tracer;
68504
68505 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
68506 index c212a7f..7b02394 100644
68507 --- a/kernel/trace/trace_events.c
68508 +++ b/kernel/trace/trace_events.c
68509 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
68510 struct ftrace_module_file_ops {
68511 struct list_head list;
68512 struct module *mod;
68513 - struct file_operations id;
68514 - struct file_operations enable;
68515 - struct file_operations format;
68516 - struct file_operations filter;
68517 };
68518
68519 static struct ftrace_module_file_ops *
68520 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
68521
68522 file_ops->mod = mod;
68523
68524 - file_ops->id = ftrace_event_id_fops;
68525 - file_ops->id.owner = mod;
68526 -
68527 - file_ops->enable = ftrace_enable_fops;
68528 - file_ops->enable.owner = mod;
68529 -
68530 - file_ops->filter = ftrace_event_filter_fops;
68531 - file_ops->filter.owner = mod;
68532 -
68533 - file_ops->format = ftrace_event_format_fops;
68534 - file_ops->format.owner = mod;
68535 + pax_open_kernel();
68536 + *(void **)&mod->trace_id.owner = mod;
68537 + *(void **)&mod->trace_enable.owner = mod;
68538 + *(void **)&mod->trace_filter.owner = mod;
68539 + *(void **)&mod->trace_format.owner = mod;
68540 + pax_close_kernel();
68541
68542 list_add(&file_ops->list, &ftrace_module_file_list);
68543
68544 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
68545
68546 for_each_event(call, start, end) {
68547 __trace_add_event_call(*call, mod,
68548 - &file_ops->id, &file_ops->enable,
68549 - &file_ops->filter, &file_ops->format);
68550 + &mod->trace_id, &mod->trace_enable,
68551 + &mod->trace_filter, &mod->trace_format);
68552 }
68553 }
68554
68555 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
68556 index 00d527c..7c5b1a3 100644
68557 --- a/kernel/trace/trace_kprobe.c
68558 +++ b/kernel/trace/trace_kprobe.c
68559 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68560 long ret;
68561 int maxlen = get_rloc_len(*(u32 *)dest);
68562 u8 *dst = get_rloc_data(dest);
68563 - u8 *src = addr;
68564 + const u8 __user *src = (const u8 __force_user *)addr;
68565 mm_segment_t old_fs = get_fs();
68566 if (!maxlen)
68567 return;
68568 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68569 pagefault_disable();
68570 do
68571 ret = __copy_from_user_inatomic(dst++, src++, 1);
68572 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
68573 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
68574 dst[-1] = '\0';
68575 pagefault_enable();
68576 set_fs(old_fs);
68577 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68578 ((u8 *)get_rloc_data(dest))[0] = '\0';
68579 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
68580 } else
68581 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
68582 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
68583 get_rloc_offs(*(u32 *)dest));
68584 }
68585 /* Return the length of string -- including null terminal byte */
68586 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
68587 set_fs(KERNEL_DS);
68588 pagefault_disable();
68589 do {
68590 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
68591 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
68592 len++;
68593 } while (c && ret == 0 && len < MAX_STRING_SIZE);
68594 pagefault_enable();
68595 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
68596 index fd3c8aa..5f324a6 100644
68597 --- a/kernel/trace/trace_mmiotrace.c
68598 +++ b/kernel/trace/trace_mmiotrace.c
68599 @@ -24,7 +24,7 @@ struct header_iter {
68600 static struct trace_array *mmio_trace_array;
68601 static bool overrun_detected;
68602 static unsigned long prev_overruns;
68603 -static atomic_t dropped_count;
68604 +static atomic_unchecked_t dropped_count;
68605
68606 static void mmio_reset_data(struct trace_array *tr)
68607 {
68608 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
68609
68610 static unsigned long count_overruns(struct trace_iterator *iter)
68611 {
68612 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
68613 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
68614 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
68615
68616 if (over > prev_overruns)
68617 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
68618 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
68619 sizeof(*entry), 0, pc);
68620 if (!event) {
68621 - atomic_inc(&dropped_count);
68622 + atomic_inc_unchecked(&dropped_count);
68623 return;
68624 }
68625 entry = ring_buffer_event_data(event);
68626 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
68627 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
68628 sizeof(*entry), 0, pc);
68629 if (!event) {
68630 - atomic_inc(&dropped_count);
68631 + atomic_inc_unchecked(&dropped_count);
68632 return;
68633 }
68634 entry = ring_buffer_event_data(event);
68635 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
68636 index 0d6ff35..67e0ed7 100644
68637 --- a/kernel/trace/trace_output.c
68638 +++ b/kernel/trace/trace_output.c
68639 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
68640
68641 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
68642 if (!IS_ERR(p)) {
68643 - p = mangle_path(s->buffer + s->len, p, "\n");
68644 + p = mangle_path(s->buffer + s->len, p, "\n\\");
68645 if (p) {
68646 s->len = p - s->buffer;
68647 return 1;
68648 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
68649 index d4545f4..a9010a1 100644
68650 --- a/kernel/trace/trace_stack.c
68651 +++ b/kernel/trace/trace_stack.c
68652 @@ -53,7 +53,7 @@ static inline void check_stack(void)
68653 return;
68654
68655 /* we do not handle interrupt stacks yet */
68656 - if (!object_is_on_stack(&this_size))
68657 + if (!object_starts_on_stack(&this_size))
68658 return;
68659
68660 local_irq_save(flags);
68661 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
68662 index 209b379..7f76423 100644
68663 --- a/kernel/trace/trace_workqueue.c
68664 +++ b/kernel/trace/trace_workqueue.c
68665 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
68666 int cpu;
68667 pid_t pid;
68668 /* Can be inserted from interrupt or user context, need to be atomic */
68669 - atomic_t inserted;
68670 + atomic_unchecked_t inserted;
68671 /*
68672 * Don't need to be atomic, works are serialized in a single workqueue thread
68673 * on a single CPU.
68674 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
68675 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
68676 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
68677 if (node->pid == wq_thread->pid) {
68678 - atomic_inc(&node->inserted);
68679 + atomic_inc_unchecked(&node->inserted);
68680 goto found;
68681 }
68682 }
68683 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
68684 tsk = get_pid_task(pid, PIDTYPE_PID);
68685 if (tsk) {
68686 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
68687 - atomic_read(&cws->inserted), cws->executed,
68688 + atomic_read_unchecked(&cws->inserted), cws->executed,
68689 tsk->comm);
68690 put_task_struct(tsk);
68691 }
68692 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
68693 index 8745ac7..d144e37 100644
68694 --- a/lib/Kconfig.debug
68695 +++ b/lib/Kconfig.debug
68696 @@ -1103,6 +1103,7 @@ config LATENCYTOP
68697 depends on DEBUG_KERNEL
68698 depends on STACKTRACE_SUPPORT
68699 depends on PROC_FS
68700 + depends on !GRKERNSEC_HIDESYM
68701 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
68702 select KALLSYMS
68703 select KALLSYMS_ALL
68704 diff --git a/lib/bitmap.c b/lib/bitmap.c
68705 index 0d4a127..33a06c7 100644
68706 --- a/lib/bitmap.c
68707 +++ b/lib/bitmap.c
68708 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
68709 {
68710 int c, old_c, totaldigits, ndigits, nchunks, nbits;
68711 u32 chunk;
68712 - const char __user __force *ubuf = (const char __user __force *)buf;
68713 + const char __user *ubuf = (const char __force_user *)buf;
68714
68715 bitmap_zero(maskp, nmaskbits);
68716
68717 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
68718 {
68719 if (!access_ok(VERIFY_READ, ubuf, ulen))
68720 return -EFAULT;
68721 - return __bitmap_parse((const char __force *)ubuf,
68722 + return __bitmap_parse((const char __force_kernel *)ubuf,
68723 ulen, 1, maskp, nmaskbits);
68724
68725 }
68726 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
68727 {
68728 unsigned a, b;
68729 int c, old_c, totaldigits;
68730 - const char __user __force *ubuf = (const char __user __force *)buf;
68731 + const char __user *ubuf = (const char __force_user *)buf;
68732 int exp_digit, in_range;
68733
68734 totaldigits = c = 0;
68735 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
68736 {
68737 if (!access_ok(VERIFY_READ, ubuf, ulen))
68738 return -EFAULT;
68739 - return __bitmap_parselist((const char __force *)ubuf,
68740 + return __bitmap_parselist((const char __force_kernel *)ubuf,
68741 ulen, 1, maskp, nmaskbits);
68742 }
68743 EXPORT_SYMBOL(bitmap_parselist_user);
68744 diff --git a/lib/bug.c b/lib/bug.c
68745 index a28c141..2bd3d95 100644
68746 --- a/lib/bug.c
68747 +++ b/lib/bug.c
68748 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
68749 return BUG_TRAP_TYPE_NONE;
68750
68751 bug = find_bug(bugaddr);
68752 + if (!bug)
68753 + return BUG_TRAP_TYPE_NONE;
68754
68755 file = NULL;
68756 line = 0;
68757 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
68758 index 0ab9ae8..f01ceca 100644
68759 --- a/lib/debugobjects.c
68760 +++ b/lib/debugobjects.c
68761 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
68762 if (limit > 4)
68763 return;
68764
68765 - is_on_stack = object_is_on_stack(addr);
68766 + is_on_stack = object_starts_on_stack(addr);
68767 if (is_on_stack == onstack)
68768 return;
68769
68770 diff --git a/lib/devres.c b/lib/devres.c
68771 index 9676617..5149e15 100644
68772 --- a/lib/devres.c
68773 +++ b/lib/devres.c
68774 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
68775 void devm_iounmap(struct device *dev, void __iomem *addr)
68776 {
68777 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
68778 - (void *)addr));
68779 + (void __force *)addr));
68780 iounmap(addr);
68781 }
68782 EXPORT_SYMBOL(devm_iounmap);
68783 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
68784 {
68785 ioport_unmap(addr);
68786 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
68787 - devm_ioport_map_match, (void *)addr));
68788 + devm_ioport_map_match, (void __force *)addr));
68789 }
68790 EXPORT_SYMBOL(devm_ioport_unmap);
68791
68792 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
68793 index fea790a..ebb0e82 100644
68794 --- a/lib/dma-debug.c
68795 +++ b/lib/dma-debug.c
68796 @@ -925,7 +925,7 @@ out:
68797
68798 static void check_for_stack(struct device *dev, void *addr)
68799 {
68800 - if (object_is_on_stack(addr))
68801 + if (object_starts_on_stack(addr))
68802 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
68803 "stack [addr=%p]\n", addr);
68804 }
68805 diff --git a/lib/extable.c b/lib/extable.c
68806 index 4cac81e..63e9b8f 100644
68807 --- a/lib/extable.c
68808 +++ b/lib/extable.c
68809 @@ -13,6 +13,7 @@
68810 #include <linux/init.h>
68811 #include <linux/sort.h>
68812 #include <asm/uaccess.h>
68813 +#include <asm/pgtable.h>
68814
68815 #ifndef ARCH_HAS_SORT_EXTABLE
68816 /*
68817 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
68818 void sort_extable(struct exception_table_entry *start,
68819 struct exception_table_entry *finish)
68820 {
68821 + pax_open_kernel();
68822 sort(start, finish - start, sizeof(struct exception_table_entry),
68823 cmp_ex, NULL);
68824 + pax_close_kernel();
68825 }
68826
68827 #ifdef CONFIG_MODULES
68828 diff --git a/lib/inflate.c b/lib/inflate.c
68829 index 013a761..c28f3fc 100644
68830 --- a/lib/inflate.c
68831 +++ b/lib/inflate.c
68832 @@ -269,7 +269,7 @@ static void free(void *where)
68833 malloc_ptr = free_mem_ptr;
68834 }
68835 #else
68836 -#define malloc(a) kmalloc(a, GFP_KERNEL)
68837 +#define malloc(a) kmalloc((a), GFP_KERNEL)
68838 #define free(a) kfree(a)
68839 #endif
68840
68841 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
68842 index bd2bea9..6b3c95e 100644
68843 --- a/lib/is_single_threaded.c
68844 +++ b/lib/is_single_threaded.c
68845 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
68846 struct task_struct *p, *t;
68847 bool ret;
68848
68849 + if (!mm)
68850 + return true;
68851 +
68852 if (atomic_read(&task->signal->live) != 1)
68853 return false;
68854
68855 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
68856 index dc63d08..95ae14a 100644
68857 --- a/lib/radix-tree.c
68858 +++ b/lib/radix-tree.c
68859 @@ -78,7 +78,7 @@ struct radix_tree_preload {
68860 int nr;
68861 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
68862 };
68863 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
68864 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
68865
68866 static inline void *ptr_to_indirect(void *ptr)
68867 {
68868 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
68869 index 38e612e..4fb99a8 100644
68870 --- a/lib/vsprintf.c
68871 +++ b/lib/vsprintf.c
68872 @@ -16,6 +16,9 @@
68873 * - scnprintf and vscnprintf
68874 */
68875
68876 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68877 +#define __INCLUDED_BY_HIDESYM 1
68878 +#endif
68879 #include <stdarg.h>
68880 #include <linux/module.h>
68881 #include <linux/types.h>
68882 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
68883 char sym[KSYM_SYMBOL_LEN];
68884 if (ext == 'B')
68885 sprint_backtrace(sym, value);
68886 - else if (ext != 'f' && ext != 's')
68887 + else if (ext != 'f' && ext != 's' && ext != 'a')
68888 sprint_symbol(sym, value);
68889 else
68890 kallsyms_lookup(value, NULL, NULL, NULL, sym);
68891 @@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
68892 return number(buf, end, *(const netdev_features_t *)addr, spec);
68893 }
68894
68895 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68896 +int kptr_restrict __read_mostly = 2;
68897 +#else
68898 int kptr_restrict __read_mostly;
68899 +#endif
68900
68901 /*
68902 * Show a '%p' thing. A kernel extension is that the '%p' is followed
68903 @@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
68904 * - 'S' For symbolic direct pointers with offset
68905 * - 's' For symbolic direct pointers without offset
68906 * - 'B' For backtraced symbolic direct pointers with offset
68907 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
68908 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
68909 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
68910 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
68911 * - 'M' For a 6-byte MAC address, it prints the address in the
68912 @@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
68913 {
68914 if (!ptr && *fmt != 'K') {
68915 /*
68916 - * Print (null) with the same width as a pointer so it makes
68917 + * Print (nil) with the same width as a pointer so it makes
68918 * tabular output look nice.
68919 */
68920 if (spec.field_width == -1)
68921 spec.field_width = 2 * sizeof(void *);
68922 - return string(buf, end, "(null)", spec);
68923 + return string(buf, end, "(nil)", spec);
68924 }
68925
68926 switch (*fmt) {
68927 @@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
68928 /* Fallthrough */
68929 case 'S':
68930 case 's':
68931 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68932 + break;
68933 +#else
68934 + return symbol_string(buf, end, ptr, spec, *fmt);
68935 +#endif
68936 + case 'A':
68937 + case 'a':
68938 case 'B':
68939 return symbol_string(buf, end, ptr, spec, *fmt);
68940 case 'R':
68941 @@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
68942 typeof(type) value; \
68943 if (sizeof(type) == 8) { \
68944 args = PTR_ALIGN(args, sizeof(u32)); \
68945 - *(u32 *)&value = *(u32 *)args; \
68946 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
68947 + *(u32 *)&value = *(const u32 *)args; \
68948 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
68949 } else { \
68950 args = PTR_ALIGN(args, sizeof(type)); \
68951 - value = *(typeof(type) *)args; \
68952 + value = *(const typeof(type) *)args; \
68953 } \
68954 args += sizeof(type); \
68955 value; \
68956 @@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
68957 case FORMAT_TYPE_STR: {
68958 const char *str_arg = args;
68959 args += strlen(str_arg) + 1;
68960 - str = string(str, end, (char *)str_arg, spec);
68961 + str = string(str, end, str_arg, spec);
68962 break;
68963 }
68964
68965 diff --git a/localversion-grsec b/localversion-grsec
68966 new file mode 100644
68967 index 0000000..7cd6065
68968 --- /dev/null
68969 +++ b/localversion-grsec
68970 @@ -0,0 +1 @@
68971 +-grsec
68972 diff --git a/mm/Kconfig b/mm/Kconfig
68973 index e338407..49b5b7a 100644
68974 --- a/mm/Kconfig
68975 +++ b/mm/Kconfig
68976 @@ -247,10 +247,10 @@ config KSM
68977 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
68978
68979 config DEFAULT_MMAP_MIN_ADDR
68980 - int "Low address space to protect from user allocation"
68981 + int "Low address space to protect from user allocation"
68982 depends on MMU
68983 - default 4096
68984 - help
68985 + default 65536
68986 + help
68987 This is the portion of low virtual memory which should be protected
68988 from userspace allocation. Keeping a user from writing to low pages
68989 can help reduce the impact of kernel NULL pointer bugs.
68990 diff --git a/mm/filemap.c b/mm/filemap.c
68991 index b662757..3081ddd 100644
68992 --- a/mm/filemap.c
68993 +++ b/mm/filemap.c
68994 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
68995 struct address_space *mapping = file->f_mapping;
68996
68997 if (!mapping->a_ops->readpage)
68998 - return -ENOEXEC;
68999 + return -ENODEV;
69000 file_accessed(file);
69001 vma->vm_ops = &generic_file_vm_ops;
69002 vma->vm_flags |= VM_CAN_NONLINEAR;
69003 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
69004 *pos = i_size_read(inode);
69005
69006 if (limit != RLIM_INFINITY) {
69007 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
69008 if (*pos >= limit) {
69009 send_sig(SIGXFSZ, current, 0);
69010 return -EFBIG;
69011 diff --git a/mm/fremap.c b/mm/fremap.c
69012 index 9ed4fd4..c42648d 100644
69013 --- a/mm/fremap.c
69014 +++ b/mm/fremap.c
69015 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
69016 retry:
69017 vma = find_vma(mm, start);
69018
69019 +#ifdef CONFIG_PAX_SEGMEXEC
69020 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
69021 + goto out;
69022 +#endif
69023 +
69024 /*
69025 * Make sure the vma is shared, that it supports prefaulting,
69026 * and that the remapped range is valid and fully within
69027 diff --git a/mm/highmem.c b/mm/highmem.c
69028 index 57d82c6..e9e0552 100644
69029 --- a/mm/highmem.c
69030 +++ b/mm/highmem.c
69031 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
69032 * So no dangers, even with speculative execution.
69033 */
69034 page = pte_page(pkmap_page_table[i]);
69035 + pax_open_kernel();
69036 pte_clear(&init_mm, (unsigned long)page_address(page),
69037 &pkmap_page_table[i]);
69038 -
69039 + pax_close_kernel();
69040 set_page_address(page, NULL);
69041 need_flush = 1;
69042 }
69043 @@ -186,9 +187,11 @@ start:
69044 }
69045 }
69046 vaddr = PKMAP_ADDR(last_pkmap_nr);
69047 +
69048 + pax_open_kernel();
69049 set_pte_at(&init_mm, vaddr,
69050 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
69051 -
69052 + pax_close_kernel();
69053 pkmap_count[last_pkmap_nr] = 1;
69054 set_page_address(page, (void *)vaddr);
69055
69056 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
69057 index 8f7fc39..69bf1e9 100644
69058 --- a/mm/huge_memory.c
69059 +++ b/mm/huge_memory.c
69060 @@ -733,7 +733,7 @@ out:
69061 * run pte_offset_map on the pmd, if an huge pmd could
69062 * materialize from under us from a different thread.
69063 */
69064 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
69065 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69066 return VM_FAULT_OOM;
69067 /* if an huge pmd materialized from under us just retry later */
69068 if (unlikely(pmd_trans_huge(*pmd)))
69069 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
69070 index a876871..132cde0 100644
69071 --- a/mm/hugetlb.c
69072 +++ b/mm/hugetlb.c
69073 @@ -2346,6 +2346,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
69074 return 1;
69075 }
69076
69077 +#ifdef CONFIG_PAX_SEGMEXEC
69078 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
69079 +{
69080 + struct mm_struct *mm = vma->vm_mm;
69081 + struct vm_area_struct *vma_m;
69082 + unsigned long address_m;
69083 + pte_t *ptep_m;
69084 +
69085 + vma_m = pax_find_mirror_vma(vma);
69086 + if (!vma_m)
69087 + return;
69088 +
69089 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69090 + address_m = address + SEGMEXEC_TASK_SIZE;
69091 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
69092 + get_page(page_m);
69093 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
69094 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
69095 +}
69096 +#endif
69097 +
69098 /*
69099 * Hugetlb_cow() should be called with page lock of the original hugepage held.
69100 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
69101 @@ -2459,6 +2480,11 @@ retry_avoidcopy:
69102 make_huge_pte(vma, new_page, 1));
69103 page_remove_rmap(old_page);
69104 hugepage_add_new_anon_rmap(new_page, vma, address);
69105 +
69106 +#ifdef CONFIG_PAX_SEGMEXEC
69107 + pax_mirror_huge_pte(vma, address, new_page);
69108 +#endif
69109 +
69110 /* Make the old page be freed below */
69111 new_page = old_page;
69112 mmu_notifier_invalidate_range_end(mm,
69113 @@ -2613,6 +2639,10 @@ retry:
69114 && (vma->vm_flags & VM_SHARED)));
69115 set_huge_pte_at(mm, address, ptep, new_pte);
69116
69117 +#ifdef CONFIG_PAX_SEGMEXEC
69118 + pax_mirror_huge_pte(vma, address, page);
69119 +#endif
69120 +
69121 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
69122 /* Optimization, do the COW without a second fault */
69123 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
69124 @@ -2642,6 +2672,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69125 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
69126 struct hstate *h = hstate_vma(vma);
69127
69128 +#ifdef CONFIG_PAX_SEGMEXEC
69129 + struct vm_area_struct *vma_m;
69130 +#endif
69131 +
69132 address &= huge_page_mask(h);
69133
69134 ptep = huge_pte_offset(mm, address);
69135 @@ -2655,6 +2689,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69136 VM_FAULT_SET_HINDEX(h - hstates);
69137 }
69138
69139 +#ifdef CONFIG_PAX_SEGMEXEC
69140 + vma_m = pax_find_mirror_vma(vma);
69141 + if (vma_m) {
69142 + unsigned long address_m;
69143 +
69144 + if (vma->vm_start > vma_m->vm_start) {
69145 + address_m = address;
69146 + address -= SEGMEXEC_TASK_SIZE;
69147 + vma = vma_m;
69148 + h = hstate_vma(vma);
69149 + } else
69150 + address_m = address + SEGMEXEC_TASK_SIZE;
69151 +
69152 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
69153 + return VM_FAULT_OOM;
69154 + address_m &= HPAGE_MASK;
69155 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
69156 + }
69157 +#endif
69158 +
69159 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
69160 if (!ptep)
69161 return VM_FAULT_OOM;
69162 diff --git a/mm/internal.h b/mm/internal.h
69163 index 2189af4..f2ca332 100644
69164 --- a/mm/internal.h
69165 +++ b/mm/internal.h
69166 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
69167 * in mm/page_alloc.c
69168 */
69169 extern void __free_pages_bootmem(struct page *page, unsigned int order);
69170 +extern void free_compound_page(struct page *page);
69171 extern void prep_compound_page(struct page *page, unsigned long order);
69172 #ifdef CONFIG_MEMORY_FAILURE
69173 extern bool is_free_buddy_page(struct page *page);
69174 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
69175 index 45eb621..6ccd8ea 100644
69176 --- a/mm/kmemleak.c
69177 +++ b/mm/kmemleak.c
69178 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
69179
69180 for (i = 0; i < object->trace_len; i++) {
69181 void *ptr = (void *)object->trace[i];
69182 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
69183 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
69184 }
69185 }
69186
69187 diff --git a/mm/maccess.c b/mm/maccess.c
69188 index d53adf9..03a24bf 100644
69189 --- a/mm/maccess.c
69190 +++ b/mm/maccess.c
69191 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
69192 set_fs(KERNEL_DS);
69193 pagefault_disable();
69194 ret = __copy_from_user_inatomic(dst,
69195 - (__force const void __user *)src, size);
69196 + (const void __force_user *)src, size);
69197 pagefault_enable();
69198 set_fs(old_fs);
69199
69200 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
69201
69202 set_fs(KERNEL_DS);
69203 pagefault_disable();
69204 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
69205 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
69206 pagefault_enable();
69207 set_fs(old_fs);
69208
69209 diff --git a/mm/madvise.c b/mm/madvise.c
69210 index 74bf193..feb6fd3 100644
69211 --- a/mm/madvise.c
69212 +++ b/mm/madvise.c
69213 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
69214 pgoff_t pgoff;
69215 unsigned long new_flags = vma->vm_flags;
69216
69217 +#ifdef CONFIG_PAX_SEGMEXEC
69218 + struct vm_area_struct *vma_m;
69219 +#endif
69220 +
69221 switch (behavior) {
69222 case MADV_NORMAL:
69223 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
69224 @@ -110,6 +114,13 @@ success:
69225 /*
69226 * vm_flags is protected by the mmap_sem held in write mode.
69227 */
69228 +
69229 +#ifdef CONFIG_PAX_SEGMEXEC
69230 + vma_m = pax_find_mirror_vma(vma);
69231 + if (vma_m)
69232 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
69233 +#endif
69234 +
69235 vma->vm_flags = new_flags;
69236
69237 out:
69238 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69239 struct vm_area_struct ** prev,
69240 unsigned long start, unsigned long end)
69241 {
69242 +
69243 +#ifdef CONFIG_PAX_SEGMEXEC
69244 + struct vm_area_struct *vma_m;
69245 +#endif
69246 +
69247 *prev = vma;
69248 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
69249 return -EINVAL;
69250 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69251 zap_page_range(vma, start, end - start, &details);
69252 } else
69253 zap_page_range(vma, start, end - start, NULL);
69254 +
69255 +#ifdef CONFIG_PAX_SEGMEXEC
69256 + vma_m = pax_find_mirror_vma(vma);
69257 + if (vma_m) {
69258 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
69259 + struct zap_details details = {
69260 + .nonlinear_vma = vma_m,
69261 + .last_index = ULONG_MAX,
69262 + };
69263 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
69264 + } else
69265 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
69266 + }
69267 +#endif
69268 +
69269 return 0;
69270 }
69271
69272 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
69273 if (end < start)
69274 goto out;
69275
69276 +#ifdef CONFIG_PAX_SEGMEXEC
69277 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69278 + if (end > SEGMEXEC_TASK_SIZE)
69279 + goto out;
69280 + } else
69281 +#endif
69282 +
69283 + if (end > TASK_SIZE)
69284 + goto out;
69285 +
69286 error = 0;
69287 if (end == start)
69288 goto out;
69289 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
69290 index 56080ea..115071e 100644
69291 --- a/mm/memory-failure.c
69292 +++ b/mm/memory-failure.c
69293 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
69294
69295 int sysctl_memory_failure_recovery __read_mostly = 1;
69296
69297 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69298 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69299
69300 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
69301
69302 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
69303 si.si_signo = SIGBUS;
69304 si.si_errno = 0;
69305 si.si_code = BUS_MCEERR_AO;
69306 - si.si_addr = (void *)addr;
69307 + si.si_addr = (void __user *)addr;
69308 #ifdef __ARCH_SI_TRAPNO
69309 si.si_trapno = trapno;
69310 #endif
69311 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69312 }
69313
69314 nr_pages = 1 << compound_trans_order(hpage);
69315 - atomic_long_add(nr_pages, &mce_bad_pages);
69316 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
69317
69318 /*
69319 * We need/can do nothing about count=0 pages.
69320 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69321 if (!PageHWPoison(hpage)
69322 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
69323 || (p != hpage && TestSetPageHWPoison(hpage))) {
69324 - atomic_long_sub(nr_pages, &mce_bad_pages);
69325 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69326 return 0;
69327 }
69328 set_page_hwpoison_huge_page(hpage);
69329 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69330 }
69331 if (hwpoison_filter(p)) {
69332 if (TestClearPageHWPoison(p))
69333 - atomic_long_sub(nr_pages, &mce_bad_pages);
69334 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69335 unlock_page(hpage);
69336 put_page(hpage);
69337 return 0;
69338 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
69339 return 0;
69340 }
69341 if (TestClearPageHWPoison(p))
69342 - atomic_long_sub(nr_pages, &mce_bad_pages);
69343 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69344 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
69345 return 0;
69346 }
69347 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
69348 */
69349 if (TestClearPageHWPoison(page)) {
69350 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
69351 - atomic_long_sub(nr_pages, &mce_bad_pages);
69352 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69353 freeit = 1;
69354 if (PageHuge(page))
69355 clear_page_hwpoison_huge_page(page);
69356 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
69357 }
69358 done:
69359 if (!PageHWPoison(hpage))
69360 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
69361 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
69362 set_page_hwpoison_huge_page(hpage);
69363 dequeue_hwpoisoned_huge_page(hpage);
69364 /* keep elevated page count for bad page */
69365 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
69366 return ret;
69367
69368 done:
69369 - atomic_long_add(1, &mce_bad_pages);
69370 + atomic_long_add_unchecked(1, &mce_bad_pages);
69371 SetPageHWPoison(page);
69372 /* keep elevated page count for bad page */
69373 return ret;
69374 diff --git a/mm/memory.c b/mm/memory.c
69375 index 10b4dda..764ee07 100644
69376 --- a/mm/memory.c
69377 +++ b/mm/memory.c
69378 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
69379 return;
69380
69381 pmd = pmd_offset(pud, start);
69382 +
69383 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
69384 pud_clear(pud);
69385 pmd_free_tlb(tlb, pmd, start);
69386 +#endif
69387 +
69388 }
69389
69390 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69391 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69392 if (end - 1 > ceiling - 1)
69393 return;
69394
69395 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
69396 pud = pud_offset(pgd, start);
69397 pgd_clear(pgd);
69398 pud_free_tlb(tlb, pud, start);
69399 +#endif
69400 +
69401 }
69402
69403 /*
69404 @@ -1593,12 +1600,6 @@ no_page_table:
69405 return page;
69406 }
69407
69408 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
69409 -{
69410 - return stack_guard_page_start(vma, addr) ||
69411 - stack_guard_page_end(vma, addr+PAGE_SIZE);
69412 -}
69413 -
69414 /**
69415 * __get_user_pages() - pin user pages in memory
69416 * @tsk: task_struct of target task
69417 @@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69418 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
69419 i = 0;
69420
69421 - do {
69422 + while (nr_pages) {
69423 struct vm_area_struct *vma;
69424
69425 - vma = find_extend_vma(mm, start);
69426 + vma = find_vma(mm, start);
69427 if (!vma && in_gate_area(mm, start)) {
69428 unsigned long pg = start & PAGE_MASK;
69429 pgd_t *pgd;
69430 @@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69431 goto next_page;
69432 }
69433
69434 - if (!vma ||
69435 + if (!vma || start < vma->vm_start ||
69436 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
69437 !(vm_flags & vma->vm_flags))
69438 return i ? : -EFAULT;
69439 @@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69440 int ret;
69441 unsigned int fault_flags = 0;
69442
69443 - /* For mlock, just skip the stack guard page. */
69444 - if (foll_flags & FOLL_MLOCK) {
69445 - if (stack_guard_page(vma, start))
69446 - goto next_page;
69447 - }
69448 if (foll_flags & FOLL_WRITE)
69449 fault_flags |= FAULT_FLAG_WRITE;
69450 if (nonblocking)
69451 @@ -1827,7 +1823,7 @@ next_page:
69452 start += PAGE_SIZE;
69453 nr_pages--;
69454 } while (nr_pages && start < vma->vm_end);
69455 - } while (nr_pages);
69456 + }
69457 return i;
69458 }
69459 EXPORT_SYMBOL(__get_user_pages);
69460 @@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
69461 page_add_file_rmap(page);
69462 set_pte_at(mm, addr, pte, mk_pte(page, prot));
69463
69464 +#ifdef CONFIG_PAX_SEGMEXEC
69465 + pax_mirror_file_pte(vma, addr, page, ptl);
69466 +#endif
69467 +
69468 retval = 0;
69469 pte_unmap_unlock(pte, ptl);
69470 return retval;
69471 @@ -2068,10 +2068,22 @@ out:
69472 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
69473 struct page *page)
69474 {
69475 +
69476 +#ifdef CONFIG_PAX_SEGMEXEC
69477 + struct vm_area_struct *vma_m;
69478 +#endif
69479 +
69480 if (addr < vma->vm_start || addr >= vma->vm_end)
69481 return -EFAULT;
69482 if (!page_count(page))
69483 return -EINVAL;
69484 +
69485 +#ifdef CONFIG_PAX_SEGMEXEC
69486 + vma_m = pax_find_mirror_vma(vma);
69487 + if (vma_m)
69488 + vma_m->vm_flags |= VM_INSERTPAGE;
69489 +#endif
69490 +
69491 vma->vm_flags |= VM_INSERTPAGE;
69492 return insert_page(vma, addr, page, vma->vm_page_prot);
69493 }
69494 @@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
69495 unsigned long pfn)
69496 {
69497 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
69498 + BUG_ON(vma->vm_mirror);
69499
69500 if (addr < vma->vm_start || addr >= vma->vm_end)
69501 return -EFAULT;
69502 @@ -2472,6 +2485,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
69503 copy_user_highpage(dst, src, va, vma);
69504 }
69505
69506 +#ifdef CONFIG_PAX_SEGMEXEC
69507 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
69508 +{
69509 + struct mm_struct *mm = vma->vm_mm;
69510 + spinlock_t *ptl;
69511 + pte_t *pte, entry;
69512 +
69513 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
69514 + entry = *pte;
69515 + if (!pte_present(entry)) {
69516 + if (!pte_none(entry)) {
69517 + BUG_ON(pte_file(entry));
69518 + free_swap_and_cache(pte_to_swp_entry(entry));
69519 + pte_clear_not_present_full(mm, address, pte, 0);
69520 + }
69521 + } else {
69522 + struct page *page;
69523 +
69524 + flush_cache_page(vma, address, pte_pfn(entry));
69525 + entry = ptep_clear_flush(vma, address, pte);
69526 + BUG_ON(pte_dirty(entry));
69527 + page = vm_normal_page(vma, address, entry);
69528 + if (page) {
69529 + update_hiwater_rss(mm);
69530 + if (PageAnon(page))
69531 + dec_mm_counter_fast(mm, MM_ANONPAGES);
69532 + else
69533 + dec_mm_counter_fast(mm, MM_FILEPAGES);
69534 + page_remove_rmap(page);
69535 + page_cache_release(page);
69536 + }
69537 + }
69538 + pte_unmap_unlock(pte, ptl);
69539 +}
69540 +
69541 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
69542 + *
69543 + * the ptl of the lower mapped page is held on entry and is not released on exit
69544 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
69545 + */
69546 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
69547 +{
69548 + struct mm_struct *mm = vma->vm_mm;
69549 + unsigned long address_m;
69550 + spinlock_t *ptl_m;
69551 + struct vm_area_struct *vma_m;
69552 + pmd_t *pmd_m;
69553 + pte_t *pte_m, entry_m;
69554 +
69555 + BUG_ON(!page_m || !PageAnon(page_m));
69556 +
69557 + vma_m = pax_find_mirror_vma(vma);
69558 + if (!vma_m)
69559 + return;
69560 +
69561 + BUG_ON(!PageLocked(page_m));
69562 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69563 + address_m = address + SEGMEXEC_TASK_SIZE;
69564 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69565 + pte_m = pte_offset_map(pmd_m, address_m);
69566 + ptl_m = pte_lockptr(mm, pmd_m);
69567 + if (ptl != ptl_m) {
69568 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69569 + if (!pte_none(*pte_m))
69570 + goto out;
69571 + }
69572 +
69573 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
69574 + page_cache_get(page_m);
69575 + page_add_anon_rmap(page_m, vma_m, address_m);
69576 + inc_mm_counter_fast(mm, MM_ANONPAGES);
69577 + set_pte_at(mm, address_m, pte_m, entry_m);
69578 + update_mmu_cache(vma_m, address_m, entry_m);
69579 +out:
69580 + if (ptl != ptl_m)
69581 + spin_unlock(ptl_m);
69582 + pte_unmap(pte_m);
69583 + unlock_page(page_m);
69584 +}
69585 +
69586 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
69587 +{
69588 + struct mm_struct *mm = vma->vm_mm;
69589 + unsigned long address_m;
69590 + spinlock_t *ptl_m;
69591 + struct vm_area_struct *vma_m;
69592 + pmd_t *pmd_m;
69593 + pte_t *pte_m, entry_m;
69594 +
69595 + BUG_ON(!page_m || PageAnon(page_m));
69596 +
69597 + vma_m = pax_find_mirror_vma(vma);
69598 + if (!vma_m)
69599 + return;
69600 +
69601 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69602 + address_m = address + SEGMEXEC_TASK_SIZE;
69603 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69604 + pte_m = pte_offset_map(pmd_m, address_m);
69605 + ptl_m = pte_lockptr(mm, pmd_m);
69606 + if (ptl != ptl_m) {
69607 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69608 + if (!pte_none(*pte_m))
69609 + goto out;
69610 + }
69611 +
69612 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
69613 + page_cache_get(page_m);
69614 + page_add_file_rmap(page_m);
69615 + inc_mm_counter_fast(mm, MM_FILEPAGES);
69616 + set_pte_at(mm, address_m, pte_m, entry_m);
69617 + update_mmu_cache(vma_m, address_m, entry_m);
69618 +out:
69619 + if (ptl != ptl_m)
69620 + spin_unlock(ptl_m);
69621 + pte_unmap(pte_m);
69622 +}
69623 +
69624 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
69625 +{
69626 + struct mm_struct *mm = vma->vm_mm;
69627 + unsigned long address_m;
69628 + spinlock_t *ptl_m;
69629 + struct vm_area_struct *vma_m;
69630 + pmd_t *pmd_m;
69631 + pte_t *pte_m, entry_m;
69632 +
69633 + vma_m = pax_find_mirror_vma(vma);
69634 + if (!vma_m)
69635 + return;
69636 +
69637 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69638 + address_m = address + SEGMEXEC_TASK_SIZE;
69639 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69640 + pte_m = pte_offset_map(pmd_m, address_m);
69641 + ptl_m = pte_lockptr(mm, pmd_m);
69642 + if (ptl != ptl_m) {
69643 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69644 + if (!pte_none(*pte_m))
69645 + goto out;
69646 + }
69647 +
69648 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
69649 + set_pte_at(mm, address_m, pte_m, entry_m);
69650 +out:
69651 + if (ptl != ptl_m)
69652 + spin_unlock(ptl_m);
69653 + pte_unmap(pte_m);
69654 +}
69655 +
69656 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
69657 +{
69658 + struct page *page_m;
69659 + pte_t entry;
69660 +
69661 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
69662 + goto out;
69663 +
69664 + entry = *pte;
69665 + page_m = vm_normal_page(vma, address, entry);
69666 + if (!page_m)
69667 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
69668 + else if (PageAnon(page_m)) {
69669 + if (pax_find_mirror_vma(vma)) {
69670 + pte_unmap_unlock(pte, ptl);
69671 + lock_page(page_m);
69672 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
69673 + if (pte_same(entry, *pte))
69674 + pax_mirror_anon_pte(vma, address, page_m, ptl);
69675 + else
69676 + unlock_page(page_m);
69677 + }
69678 + } else
69679 + pax_mirror_file_pte(vma, address, page_m, ptl);
69680 +
69681 +out:
69682 + pte_unmap_unlock(pte, ptl);
69683 +}
69684 +#endif
69685 +
69686 /*
69687 * This routine handles present pages, when users try to write
69688 * to a shared page. It is done by copying the page to a new address
69689 @@ -2683,6 +2876,12 @@ gotten:
69690 */
69691 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
69692 if (likely(pte_same(*page_table, orig_pte))) {
69693 +
69694 +#ifdef CONFIG_PAX_SEGMEXEC
69695 + if (pax_find_mirror_vma(vma))
69696 + BUG_ON(!trylock_page(new_page));
69697 +#endif
69698 +
69699 if (old_page) {
69700 if (!PageAnon(old_page)) {
69701 dec_mm_counter_fast(mm, MM_FILEPAGES);
69702 @@ -2734,6 +2933,10 @@ gotten:
69703 page_remove_rmap(old_page);
69704 }
69705
69706 +#ifdef CONFIG_PAX_SEGMEXEC
69707 + pax_mirror_anon_pte(vma, address, new_page, ptl);
69708 +#endif
69709 +
69710 /* Free the old page.. */
69711 new_page = old_page;
69712 ret |= VM_FAULT_WRITE;
69713 @@ -3013,6 +3216,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
69714 swap_free(entry);
69715 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
69716 try_to_free_swap(page);
69717 +
69718 +#ifdef CONFIG_PAX_SEGMEXEC
69719 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
69720 +#endif
69721 +
69722 unlock_page(page);
69723 if (swapcache) {
69724 /*
69725 @@ -3036,6 +3244,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
69726
69727 /* No need to invalidate - it was non-present before */
69728 update_mmu_cache(vma, address, page_table);
69729 +
69730 +#ifdef CONFIG_PAX_SEGMEXEC
69731 + pax_mirror_anon_pte(vma, address, page, ptl);
69732 +#endif
69733 +
69734 unlock:
69735 pte_unmap_unlock(page_table, ptl);
69736 out:
69737 @@ -3055,40 +3268,6 @@ out_release:
69738 }
69739
69740 /*
69741 - * This is like a special single-page "expand_{down|up}wards()",
69742 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
69743 - * doesn't hit another vma.
69744 - */
69745 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
69746 -{
69747 - address &= PAGE_MASK;
69748 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
69749 - struct vm_area_struct *prev = vma->vm_prev;
69750 -
69751 - /*
69752 - * Is there a mapping abutting this one below?
69753 - *
69754 - * That's only ok if it's the same stack mapping
69755 - * that has gotten split..
69756 - */
69757 - if (prev && prev->vm_end == address)
69758 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
69759 -
69760 - expand_downwards(vma, address - PAGE_SIZE);
69761 - }
69762 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
69763 - struct vm_area_struct *next = vma->vm_next;
69764 -
69765 - /* As VM_GROWSDOWN but s/below/above/ */
69766 - if (next && next->vm_start == address + PAGE_SIZE)
69767 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
69768 -
69769 - expand_upwards(vma, address + PAGE_SIZE);
69770 - }
69771 - return 0;
69772 -}
69773 -
69774 -/*
69775 * We enter with non-exclusive mmap_sem (to exclude vma changes,
69776 * but allow concurrent faults), and pte mapped but not yet locked.
69777 * We return with mmap_sem still held, but pte unmapped and unlocked.
69778 @@ -3097,27 +3276,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
69779 unsigned long address, pte_t *page_table, pmd_t *pmd,
69780 unsigned int flags)
69781 {
69782 - struct page *page;
69783 + struct page *page = NULL;
69784 spinlock_t *ptl;
69785 pte_t entry;
69786
69787 - pte_unmap(page_table);
69788 -
69789 - /* Check if we need to add a guard page to the stack */
69790 - if (check_stack_guard_page(vma, address) < 0)
69791 - return VM_FAULT_SIGBUS;
69792 -
69793 - /* Use the zero-page for reads */
69794 if (!(flags & FAULT_FLAG_WRITE)) {
69795 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
69796 vma->vm_page_prot));
69797 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
69798 + ptl = pte_lockptr(mm, pmd);
69799 + spin_lock(ptl);
69800 if (!pte_none(*page_table))
69801 goto unlock;
69802 goto setpte;
69803 }
69804
69805 /* Allocate our own private page. */
69806 + pte_unmap(page_table);
69807 +
69808 if (unlikely(anon_vma_prepare(vma)))
69809 goto oom;
69810 page = alloc_zeroed_user_highpage_movable(vma, address);
69811 @@ -3136,6 +3311,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
69812 if (!pte_none(*page_table))
69813 goto release;
69814
69815 +#ifdef CONFIG_PAX_SEGMEXEC
69816 + if (pax_find_mirror_vma(vma))
69817 + BUG_ON(!trylock_page(page));
69818 +#endif
69819 +
69820 inc_mm_counter_fast(mm, MM_ANONPAGES);
69821 page_add_new_anon_rmap(page, vma, address);
69822 setpte:
69823 @@ -3143,6 +3323,12 @@ setpte:
69824
69825 /* No need to invalidate - it was non-present before */
69826 update_mmu_cache(vma, address, page_table);
69827 +
69828 +#ifdef CONFIG_PAX_SEGMEXEC
69829 + if (page)
69830 + pax_mirror_anon_pte(vma, address, page, ptl);
69831 +#endif
69832 +
69833 unlock:
69834 pte_unmap_unlock(page_table, ptl);
69835 return 0;
69836 @@ -3286,6 +3472,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69837 */
69838 /* Only go through if we didn't race with anybody else... */
69839 if (likely(pte_same(*page_table, orig_pte))) {
69840 +
69841 +#ifdef CONFIG_PAX_SEGMEXEC
69842 + if (anon && pax_find_mirror_vma(vma))
69843 + BUG_ON(!trylock_page(page));
69844 +#endif
69845 +
69846 flush_icache_page(vma, page);
69847 entry = mk_pte(page, vma->vm_page_prot);
69848 if (flags & FAULT_FLAG_WRITE)
69849 @@ -3305,6 +3497,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69850
69851 /* no need to invalidate: a not-present page won't be cached */
69852 update_mmu_cache(vma, address, page_table);
69853 +
69854 +#ifdef CONFIG_PAX_SEGMEXEC
69855 + if (anon)
69856 + pax_mirror_anon_pte(vma, address, page, ptl);
69857 + else
69858 + pax_mirror_file_pte(vma, address, page, ptl);
69859 +#endif
69860 +
69861 } else {
69862 if (cow_page)
69863 mem_cgroup_uncharge_page(cow_page);
69864 @@ -3458,6 +3658,12 @@ int handle_pte_fault(struct mm_struct *mm,
69865 if (flags & FAULT_FLAG_WRITE)
69866 flush_tlb_fix_spurious_fault(vma, address);
69867 }
69868 +
69869 +#ifdef CONFIG_PAX_SEGMEXEC
69870 + pax_mirror_pte(vma, address, pte, pmd, ptl);
69871 + return 0;
69872 +#endif
69873 +
69874 unlock:
69875 pte_unmap_unlock(pte, ptl);
69876 return 0;
69877 @@ -3474,6 +3680,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69878 pmd_t *pmd;
69879 pte_t *pte;
69880
69881 +#ifdef CONFIG_PAX_SEGMEXEC
69882 + struct vm_area_struct *vma_m;
69883 +#endif
69884 +
69885 __set_current_state(TASK_RUNNING);
69886
69887 count_vm_event(PGFAULT);
69888 @@ -3485,6 +3695,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69889 if (unlikely(is_vm_hugetlb_page(vma)))
69890 return hugetlb_fault(mm, vma, address, flags);
69891
69892 +#ifdef CONFIG_PAX_SEGMEXEC
69893 + vma_m = pax_find_mirror_vma(vma);
69894 + if (vma_m) {
69895 + unsigned long address_m;
69896 + pgd_t *pgd_m;
69897 + pud_t *pud_m;
69898 + pmd_t *pmd_m;
69899 +
69900 + if (vma->vm_start > vma_m->vm_start) {
69901 + address_m = address;
69902 + address -= SEGMEXEC_TASK_SIZE;
69903 + vma = vma_m;
69904 + } else
69905 + address_m = address + SEGMEXEC_TASK_SIZE;
69906 +
69907 + pgd_m = pgd_offset(mm, address_m);
69908 + pud_m = pud_alloc(mm, pgd_m, address_m);
69909 + if (!pud_m)
69910 + return VM_FAULT_OOM;
69911 + pmd_m = pmd_alloc(mm, pud_m, address_m);
69912 + if (!pmd_m)
69913 + return VM_FAULT_OOM;
69914 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
69915 + return VM_FAULT_OOM;
69916 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
69917 + }
69918 +#endif
69919 +
69920 pgd = pgd_offset(mm, address);
69921 pud = pud_alloc(mm, pgd, address);
69922 if (!pud)
69923 @@ -3514,7 +3752,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69924 * run pte_offset_map on the pmd, if an huge pmd could
69925 * materialize from under us from a different thread.
69926 */
69927 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
69928 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69929 return VM_FAULT_OOM;
69930 /* if an huge pmd materialized from under us just retry later */
69931 if (unlikely(pmd_trans_huge(*pmd)))
69932 @@ -3618,7 +3856,7 @@ static int __init gate_vma_init(void)
69933 gate_vma.vm_start = FIXADDR_USER_START;
69934 gate_vma.vm_end = FIXADDR_USER_END;
69935 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
69936 - gate_vma.vm_page_prot = __P101;
69937 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
69938 /*
69939 * Make sure the vDSO gets into every core dump.
69940 * Dumping its contents makes post-mortem fully interpretable later
69941 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
69942 index 0a37570..2048346 100644
69943 --- a/mm/mempolicy.c
69944 +++ b/mm/mempolicy.c
69945 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
69946 unsigned long vmstart;
69947 unsigned long vmend;
69948
69949 +#ifdef CONFIG_PAX_SEGMEXEC
69950 + struct vm_area_struct *vma_m;
69951 +#endif
69952 +
69953 vma = find_vma(mm, start);
69954 if (!vma || vma->vm_start > start)
69955 return -EFAULT;
69956 @@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
69957 err = policy_vma(vma, new_pol);
69958 if (err)
69959 goto out;
69960 +
69961 +#ifdef CONFIG_PAX_SEGMEXEC
69962 + vma_m = pax_find_mirror_vma(vma);
69963 + if (vma_m) {
69964 + err = policy_vma(vma_m, new_pol);
69965 + if (err)
69966 + goto out;
69967 + }
69968 +#endif
69969 +
69970 }
69971
69972 out:
69973 @@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
69974
69975 if (end < start)
69976 return -EINVAL;
69977 +
69978 +#ifdef CONFIG_PAX_SEGMEXEC
69979 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
69980 + if (end > SEGMEXEC_TASK_SIZE)
69981 + return -EINVAL;
69982 + } else
69983 +#endif
69984 +
69985 + if (end > TASK_SIZE)
69986 + return -EINVAL;
69987 +
69988 if (end == start)
69989 return 0;
69990
69991 @@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
69992 if (!mm)
69993 goto out;
69994
69995 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69996 + if (mm != current->mm &&
69997 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
69998 + err = -EPERM;
69999 + goto out;
70000 + }
70001 +#endif
70002 +
70003 /*
70004 * Check if this process has the right to modify the specified
70005 * process. The right exists if the process has administrative
70006 @@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70007 rcu_read_lock();
70008 tcred = __task_cred(task);
70009 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70010 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
70011 - !capable(CAP_SYS_NICE)) {
70012 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70013 rcu_read_unlock();
70014 err = -EPERM;
70015 goto out;
70016 diff --git a/mm/migrate.c b/mm/migrate.c
70017 index 1503b6b..156c672 100644
70018 --- a/mm/migrate.c
70019 +++ b/mm/migrate.c
70020 @@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
70021 if (!mm)
70022 return -EINVAL;
70023
70024 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70025 + if (mm != current->mm &&
70026 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70027 + err = -EPERM;
70028 + goto out;
70029 + }
70030 +#endif
70031 +
70032 /*
70033 * Check if this process has the right to modify the specified
70034 * process. The right exists if the process has administrative
70035 @@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
70036 rcu_read_lock();
70037 tcred = __task_cred(task);
70038 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70039 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
70040 - !capable(CAP_SYS_NICE)) {
70041 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70042 rcu_read_unlock();
70043 err = -EPERM;
70044 goto out;
70045 diff --git a/mm/mlock.c b/mm/mlock.c
70046 index ef726e8..13e0901 100644
70047 --- a/mm/mlock.c
70048 +++ b/mm/mlock.c
70049 @@ -13,6 +13,7 @@
70050 #include <linux/pagemap.h>
70051 #include <linux/mempolicy.h>
70052 #include <linux/syscalls.h>
70053 +#include <linux/security.h>
70054 #include <linux/sched.h>
70055 #include <linux/export.h>
70056 #include <linux/rmap.h>
70057 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
70058 return -EINVAL;
70059 if (end == start)
70060 return 0;
70061 + if (end > TASK_SIZE)
70062 + return -EINVAL;
70063 +
70064 vma = find_vma(current->mm, start);
70065 if (!vma || vma->vm_start > start)
70066 return -ENOMEM;
70067 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
70068 for (nstart = start ; ; ) {
70069 vm_flags_t newflags;
70070
70071 +#ifdef CONFIG_PAX_SEGMEXEC
70072 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70073 + break;
70074 +#endif
70075 +
70076 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
70077
70078 newflags = vma->vm_flags | VM_LOCKED;
70079 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
70080 lock_limit >>= PAGE_SHIFT;
70081
70082 /* check against resource limits */
70083 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
70084 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
70085 error = do_mlock(start, len, 1);
70086 up_write(&current->mm->mmap_sem);
70087 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
70088 static int do_mlockall(int flags)
70089 {
70090 struct vm_area_struct * vma, * prev = NULL;
70091 - unsigned int def_flags = 0;
70092
70093 if (flags & MCL_FUTURE)
70094 - def_flags = VM_LOCKED;
70095 - current->mm->def_flags = def_flags;
70096 + current->mm->def_flags |= VM_LOCKED;
70097 + else
70098 + current->mm->def_flags &= ~VM_LOCKED;
70099 if (flags == MCL_FUTURE)
70100 goto out;
70101
70102 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
70103 vm_flags_t newflags;
70104
70105 +#ifdef CONFIG_PAX_SEGMEXEC
70106 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70107 + break;
70108 +#endif
70109 +
70110 + BUG_ON(vma->vm_end > TASK_SIZE);
70111 newflags = vma->vm_flags | VM_LOCKED;
70112 if (!(flags & MCL_CURRENT))
70113 newflags &= ~VM_LOCKED;
70114 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
70115 lock_limit >>= PAGE_SHIFT;
70116
70117 ret = -ENOMEM;
70118 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
70119 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
70120 capable(CAP_IPC_LOCK))
70121 ret = do_mlockall(flags);
70122 diff --git a/mm/mmap.c b/mm/mmap.c
70123 index da15a79..2e3d9ff 100644
70124 --- a/mm/mmap.c
70125 +++ b/mm/mmap.c
70126 @@ -46,6 +46,16 @@
70127 #define arch_rebalance_pgtables(addr, len) (addr)
70128 #endif
70129
70130 +static inline void verify_mm_writelocked(struct mm_struct *mm)
70131 +{
70132 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
70133 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70134 + up_read(&mm->mmap_sem);
70135 + BUG();
70136 + }
70137 +#endif
70138 +}
70139 +
70140 static void unmap_region(struct mm_struct *mm,
70141 struct vm_area_struct *vma, struct vm_area_struct *prev,
70142 unsigned long start, unsigned long end);
70143 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
70144 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
70145 *
70146 */
70147 -pgprot_t protection_map[16] = {
70148 +pgprot_t protection_map[16] __read_only = {
70149 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
70150 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
70151 };
70152
70153 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
70154 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70155 {
70156 - return __pgprot(pgprot_val(protection_map[vm_flags &
70157 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
70158 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
70159 pgprot_val(arch_vm_get_page_prot(vm_flags)));
70160 +
70161 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70162 + if (!(__supported_pte_mask & _PAGE_NX) &&
70163 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
70164 + (vm_flags & (VM_READ | VM_WRITE)))
70165 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
70166 +#endif
70167 +
70168 + return prot;
70169 }
70170 EXPORT_SYMBOL(vm_get_page_prot);
70171
70172 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
70173 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
70174 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
70175 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
70176 /*
70177 * Make sure vm_committed_as in one cacheline and not cacheline shared with
70178 * other variables. It can be updated by several CPUs frequently.
70179 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
70180 struct vm_area_struct *next = vma->vm_next;
70181
70182 might_sleep();
70183 + BUG_ON(vma->vm_mirror);
70184 if (vma->vm_ops && vma->vm_ops->close)
70185 vma->vm_ops->close(vma);
70186 if (vma->vm_file) {
70187 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
70188 * not page aligned -Ram Gupta
70189 */
70190 rlim = rlimit(RLIMIT_DATA);
70191 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
70192 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
70193 (mm->end_data - mm->start_data) > rlim)
70194 goto out;
70195 @@ -689,6 +711,12 @@ static int
70196 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
70197 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70198 {
70199 +
70200 +#ifdef CONFIG_PAX_SEGMEXEC
70201 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
70202 + return 0;
70203 +#endif
70204 +
70205 if (is_mergeable_vma(vma, file, vm_flags) &&
70206 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70207 if (vma->vm_pgoff == vm_pgoff)
70208 @@ -708,6 +736,12 @@ static int
70209 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70210 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70211 {
70212 +
70213 +#ifdef CONFIG_PAX_SEGMEXEC
70214 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
70215 + return 0;
70216 +#endif
70217 +
70218 if (is_mergeable_vma(vma, file, vm_flags) &&
70219 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70220 pgoff_t vm_pglen;
70221 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70222 struct vm_area_struct *vma_merge(struct mm_struct *mm,
70223 struct vm_area_struct *prev, unsigned long addr,
70224 unsigned long end, unsigned long vm_flags,
70225 - struct anon_vma *anon_vma, struct file *file,
70226 + struct anon_vma *anon_vma, struct file *file,
70227 pgoff_t pgoff, struct mempolicy *policy)
70228 {
70229 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
70230 struct vm_area_struct *area, *next;
70231 int err;
70232
70233 +#ifdef CONFIG_PAX_SEGMEXEC
70234 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
70235 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
70236 +
70237 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
70238 +#endif
70239 +
70240 /*
70241 * We later require that vma->vm_flags == vm_flags,
70242 * so this tests vma->vm_flags & VM_SPECIAL, too.
70243 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70244 if (next && next->vm_end == end) /* cases 6, 7, 8 */
70245 next = next->vm_next;
70246
70247 +#ifdef CONFIG_PAX_SEGMEXEC
70248 + if (prev)
70249 + prev_m = pax_find_mirror_vma(prev);
70250 + if (area)
70251 + area_m = pax_find_mirror_vma(area);
70252 + if (next)
70253 + next_m = pax_find_mirror_vma(next);
70254 +#endif
70255 +
70256 /*
70257 * Can it merge with the predecessor?
70258 */
70259 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70260 /* cases 1, 6 */
70261 err = vma_adjust(prev, prev->vm_start,
70262 next->vm_end, prev->vm_pgoff, NULL);
70263 - } else /* cases 2, 5, 7 */
70264 +
70265 +#ifdef CONFIG_PAX_SEGMEXEC
70266 + if (!err && prev_m)
70267 + err = vma_adjust(prev_m, prev_m->vm_start,
70268 + next_m->vm_end, prev_m->vm_pgoff, NULL);
70269 +#endif
70270 +
70271 + } else { /* cases 2, 5, 7 */
70272 err = vma_adjust(prev, prev->vm_start,
70273 end, prev->vm_pgoff, NULL);
70274 +
70275 +#ifdef CONFIG_PAX_SEGMEXEC
70276 + if (!err && prev_m)
70277 + err = vma_adjust(prev_m, prev_m->vm_start,
70278 + end_m, prev_m->vm_pgoff, NULL);
70279 +#endif
70280 +
70281 + }
70282 if (err)
70283 return NULL;
70284 khugepaged_enter_vma_merge(prev);
70285 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70286 mpol_equal(policy, vma_policy(next)) &&
70287 can_vma_merge_before(next, vm_flags,
70288 anon_vma, file, pgoff+pglen)) {
70289 - if (prev && addr < prev->vm_end) /* case 4 */
70290 + if (prev && addr < prev->vm_end) { /* case 4 */
70291 err = vma_adjust(prev, prev->vm_start,
70292 addr, prev->vm_pgoff, NULL);
70293 - else /* cases 3, 8 */
70294 +
70295 +#ifdef CONFIG_PAX_SEGMEXEC
70296 + if (!err && prev_m)
70297 + err = vma_adjust(prev_m, prev_m->vm_start,
70298 + addr_m, prev_m->vm_pgoff, NULL);
70299 +#endif
70300 +
70301 + } else { /* cases 3, 8 */
70302 err = vma_adjust(area, addr, next->vm_end,
70303 next->vm_pgoff - pglen, NULL);
70304 +
70305 +#ifdef CONFIG_PAX_SEGMEXEC
70306 + if (!err && area_m)
70307 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
70308 + next_m->vm_pgoff - pglen, NULL);
70309 +#endif
70310 +
70311 + }
70312 if (err)
70313 return NULL;
70314 khugepaged_enter_vma_merge(area);
70315 @@ -921,14 +1001,11 @@ none:
70316 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
70317 struct file *file, long pages)
70318 {
70319 - const unsigned long stack_flags
70320 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
70321 -
70322 if (file) {
70323 mm->shared_vm += pages;
70324 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
70325 mm->exec_vm += pages;
70326 - } else if (flags & stack_flags)
70327 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
70328 mm->stack_vm += pages;
70329 if (flags & (VM_RESERVED|VM_IO))
70330 mm->reserved_vm += pages;
70331 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70332 * (the exception is when the underlying filesystem is noexec
70333 * mounted, in which case we dont add PROT_EXEC.)
70334 */
70335 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70336 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70337 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
70338 prot |= PROT_EXEC;
70339
70340 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70341 /* Obtain the address to map to. we verify (or select) it and ensure
70342 * that it represents a valid section of the address space.
70343 */
70344 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
70345 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
70346 if (addr & ~PAGE_MASK)
70347 return addr;
70348
70349 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70350 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
70351 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
70352
70353 +#ifdef CONFIG_PAX_MPROTECT
70354 + if (mm->pax_flags & MF_PAX_MPROTECT) {
70355 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
70356 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
70357 + gr_log_rwxmmap(file);
70358 +
70359 +#ifdef CONFIG_PAX_EMUPLT
70360 + vm_flags &= ~VM_EXEC;
70361 +#else
70362 + return -EPERM;
70363 +#endif
70364 +
70365 + }
70366 +
70367 + if (!(vm_flags & VM_EXEC))
70368 + vm_flags &= ~VM_MAYEXEC;
70369 +#else
70370 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70371 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70372 +#endif
70373 + else
70374 + vm_flags &= ~VM_MAYWRITE;
70375 + }
70376 +#endif
70377 +
70378 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70379 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
70380 + vm_flags &= ~VM_PAGEEXEC;
70381 +#endif
70382 +
70383 if (flags & MAP_LOCKED)
70384 if (!can_do_mlock())
70385 return -EPERM;
70386 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70387 locked += mm->locked_vm;
70388 lock_limit = rlimit(RLIMIT_MEMLOCK);
70389 lock_limit >>= PAGE_SHIFT;
70390 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70391 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
70392 return -EAGAIN;
70393 }
70394 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70395 if (error)
70396 return error;
70397
70398 + if (!gr_acl_handle_mmap(file, prot))
70399 + return -EACCES;
70400 +
70401 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
70402 }
70403 EXPORT_SYMBOL(do_mmap_pgoff);
70404 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
70405 vm_flags_t vm_flags = vma->vm_flags;
70406
70407 /* If it was private or non-writable, the write bit is already clear */
70408 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
70409 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
70410 return 0;
70411
70412 /* The backer wishes to know when pages are first written to? */
70413 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
70414 unsigned long charged = 0;
70415 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
70416
70417 +#ifdef CONFIG_PAX_SEGMEXEC
70418 + struct vm_area_struct *vma_m = NULL;
70419 +#endif
70420 +
70421 + /*
70422 + * mm->mmap_sem is required to protect against another thread
70423 + * changing the mappings in case we sleep.
70424 + */
70425 + verify_mm_writelocked(mm);
70426 +
70427 /* Clear old maps */
70428 error = -ENOMEM;
70429 -munmap_back:
70430 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70431 if (vma && vma->vm_start < addr + len) {
70432 if (do_munmap(mm, addr, len))
70433 return -ENOMEM;
70434 - goto munmap_back;
70435 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70436 + BUG_ON(vma && vma->vm_start < addr + len);
70437 }
70438
70439 /* Check against address space limit. */
70440 @@ -1258,6 +1379,16 @@ munmap_back:
70441 goto unacct_error;
70442 }
70443
70444 +#ifdef CONFIG_PAX_SEGMEXEC
70445 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
70446 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70447 + if (!vma_m) {
70448 + error = -ENOMEM;
70449 + goto free_vma;
70450 + }
70451 + }
70452 +#endif
70453 +
70454 vma->vm_mm = mm;
70455 vma->vm_start = addr;
70456 vma->vm_end = addr + len;
70457 @@ -1282,6 +1413,19 @@ munmap_back:
70458 error = file->f_op->mmap(file, vma);
70459 if (error)
70460 goto unmap_and_free_vma;
70461 +
70462 +#ifdef CONFIG_PAX_SEGMEXEC
70463 + if (vma_m && (vm_flags & VM_EXECUTABLE))
70464 + added_exe_file_vma(mm);
70465 +#endif
70466 +
70467 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70468 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
70469 + vma->vm_flags |= VM_PAGEEXEC;
70470 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
70471 + }
70472 +#endif
70473 +
70474 if (vm_flags & VM_EXECUTABLE)
70475 added_exe_file_vma(mm);
70476
70477 @@ -1319,6 +1463,11 @@ munmap_back:
70478 vma_link(mm, vma, prev, rb_link, rb_parent);
70479 file = vma->vm_file;
70480
70481 +#ifdef CONFIG_PAX_SEGMEXEC
70482 + if (vma_m)
70483 + BUG_ON(pax_mirror_vma(vma_m, vma));
70484 +#endif
70485 +
70486 /* Once vma denies write, undo our temporary denial count */
70487 if (correct_wcount)
70488 atomic_inc(&inode->i_writecount);
70489 @@ -1327,6 +1476,7 @@ out:
70490
70491 mm->total_vm += len >> PAGE_SHIFT;
70492 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
70493 + track_exec_limit(mm, addr, addr + len, vm_flags);
70494 if (vm_flags & VM_LOCKED) {
70495 if (!mlock_vma_pages_range(vma, addr, addr + len))
70496 mm->locked_vm += (len >> PAGE_SHIFT);
70497 @@ -1344,6 +1494,12 @@ unmap_and_free_vma:
70498 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
70499 charged = 0;
70500 free_vma:
70501 +
70502 +#ifdef CONFIG_PAX_SEGMEXEC
70503 + if (vma_m)
70504 + kmem_cache_free(vm_area_cachep, vma_m);
70505 +#endif
70506 +
70507 kmem_cache_free(vm_area_cachep, vma);
70508 unacct_error:
70509 if (charged)
70510 @@ -1351,6 +1507,44 @@ unacct_error:
70511 return error;
70512 }
70513
70514 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
70515 +{
70516 + if (!vma) {
70517 +#ifdef CONFIG_STACK_GROWSUP
70518 + if (addr > sysctl_heap_stack_gap)
70519 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
70520 + else
70521 + vma = find_vma(current->mm, 0);
70522 + if (vma && (vma->vm_flags & VM_GROWSUP))
70523 + return false;
70524 +#endif
70525 + return true;
70526 + }
70527 +
70528 + if (addr + len > vma->vm_start)
70529 + return false;
70530 +
70531 + if (vma->vm_flags & VM_GROWSDOWN)
70532 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
70533 +#ifdef CONFIG_STACK_GROWSUP
70534 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
70535 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
70536 +#endif
70537 +
70538 + return true;
70539 +}
70540 +
70541 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
70542 +{
70543 + if (vma->vm_start < len)
70544 + return -ENOMEM;
70545 + if (!(vma->vm_flags & VM_GROWSDOWN))
70546 + return vma->vm_start - len;
70547 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
70548 + return vma->vm_start - len - sysctl_heap_stack_gap;
70549 + return -ENOMEM;
70550 +}
70551 +
70552 /* Get an address range which is currently unmapped.
70553 * For shmat() with addr=0.
70554 *
70555 @@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
70556 if (flags & MAP_FIXED)
70557 return addr;
70558
70559 +#ifdef CONFIG_PAX_RANDMMAP
70560 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
70561 +#endif
70562 +
70563 if (addr) {
70564 addr = PAGE_ALIGN(addr);
70565 - vma = find_vma(mm, addr);
70566 - if (TASK_SIZE - len >= addr &&
70567 - (!vma || addr + len <= vma->vm_start))
70568 - return addr;
70569 + if (TASK_SIZE - len >= addr) {
70570 + vma = find_vma(mm, addr);
70571 + if (check_heap_stack_gap(vma, addr, len))
70572 + return addr;
70573 + }
70574 }
70575 if (len > mm->cached_hole_size) {
70576 - start_addr = addr = mm->free_area_cache;
70577 + start_addr = addr = mm->free_area_cache;
70578 } else {
70579 - start_addr = addr = TASK_UNMAPPED_BASE;
70580 - mm->cached_hole_size = 0;
70581 + start_addr = addr = mm->mmap_base;
70582 + mm->cached_hole_size = 0;
70583 }
70584
70585 full_search:
70586 @@ -1399,34 +1598,40 @@ full_search:
70587 * Start a new search - just in case we missed
70588 * some holes.
70589 */
70590 - if (start_addr != TASK_UNMAPPED_BASE) {
70591 - addr = TASK_UNMAPPED_BASE;
70592 - start_addr = addr;
70593 + if (start_addr != mm->mmap_base) {
70594 + start_addr = addr = mm->mmap_base;
70595 mm->cached_hole_size = 0;
70596 goto full_search;
70597 }
70598 return -ENOMEM;
70599 }
70600 - if (!vma || addr + len <= vma->vm_start) {
70601 - /*
70602 - * Remember the place where we stopped the search:
70603 - */
70604 - mm->free_area_cache = addr + len;
70605 - return addr;
70606 - }
70607 + if (check_heap_stack_gap(vma, addr, len))
70608 + break;
70609 if (addr + mm->cached_hole_size < vma->vm_start)
70610 mm->cached_hole_size = vma->vm_start - addr;
70611 addr = vma->vm_end;
70612 }
70613 +
70614 + /*
70615 + * Remember the place where we stopped the search:
70616 + */
70617 + mm->free_area_cache = addr + len;
70618 + return addr;
70619 }
70620 #endif
70621
70622 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
70623 {
70624 +
70625 +#ifdef CONFIG_PAX_SEGMEXEC
70626 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
70627 + return;
70628 +#endif
70629 +
70630 /*
70631 * Is this a new hole at the lowest possible address?
70632 */
70633 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
70634 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
70635 mm->free_area_cache = addr;
70636 mm->cached_hole_size = ~0UL;
70637 }
70638 @@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70639 {
70640 struct vm_area_struct *vma;
70641 struct mm_struct *mm = current->mm;
70642 - unsigned long addr = addr0;
70643 + unsigned long base = mm->mmap_base, addr = addr0;
70644
70645 /* requested length too big for entire address space */
70646 if (len > TASK_SIZE)
70647 @@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70648 if (flags & MAP_FIXED)
70649 return addr;
70650
70651 +#ifdef CONFIG_PAX_RANDMMAP
70652 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
70653 +#endif
70654 +
70655 /* requesting a specific address */
70656 if (addr) {
70657 addr = PAGE_ALIGN(addr);
70658 - vma = find_vma(mm, addr);
70659 - if (TASK_SIZE - len >= addr &&
70660 - (!vma || addr + len <= vma->vm_start))
70661 - return addr;
70662 + if (TASK_SIZE - len >= addr) {
70663 + vma = find_vma(mm, addr);
70664 + if (check_heap_stack_gap(vma, addr, len))
70665 + return addr;
70666 + }
70667 }
70668
70669 /* check if free_area_cache is useful for us */
70670 @@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70671 /* make sure it can fit in the remaining address space */
70672 if (addr > len) {
70673 vma = find_vma(mm, addr-len);
70674 - if (!vma || addr <= vma->vm_start)
70675 + if (check_heap_stack_gap(vma, addr - len, len))
70676 /* remember the address as a hint for next time */
70677 return (mm->free_area_cache = addr-len);
70678 }
70679 @@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70680 * return with success:
70681 */
70682 vma = find_vma(mm, addr);
70683 - if (!vma || addr+len <= vma->vm_start)
70684 + if (check_heap_stack_gap(vma, addr, len))
70685 /* remember the address as a hint for next time */
70686 return (mm->free_area_cache = addr);
70687
70688 @@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70689 mm->cached_hole_size = vma->vm_start - addr;
70690
70691 /* try just below the current vma->vm_start */
70692 - addr = vma->vm_start-len;
70693 - } while (len < vma->vm_start);
70694 + addr = skip_heap_stack_gap(vma, len);
70695 + } while (!IS_ERR_VALUE(addr));
70696
70697 bottomup:
70698 /*
70699 @@ -1510,13 +1720,21 @@ bottomup:
70700 * can happen with large stack limits and large mmap()
70701 * allocations.
70702 */
70703 + mm->mmap_base = TASK_UNMAPPED_BASE;
70704 +
70705 +#ifdef CONFIG_PAX_RANDMMAP
70706 + if (mm->pax_flags & MF_PAX_RANDMMAP)
70707 + mm->mmap_base += mm->delta_mmap;
70708 +#endif
70709 +
70710 + mm->free_area_cache = mm->mmap_base;
70711 mm->cached_hole_size = ~0UL;
70712 - mm->free_area_cache = TASK_UNMAPPED_BASE;
70713 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
70714 /*
70715 * Restore the topdown base:
70716 */
70717 - mm->free_area_cache = mm->mmap_base;
70718 + mm->mmap_base = base;
70719 + mm->free_area_cache = base;
70720 mm->cached_hole_size = ~0UL;
70721
70722 return addr;
70723 @@ -1525,6 +1743,12 @@ bottomup:
70724
70725 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
70726 {
70727 +
70728 +#ifdef CONFIG_PAX_SEGMEXEC
70729 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
70730 + return;
70731 +#endif
70732 +
70733 /*
70734 * Is this a new hole at the highest possible address?
70735 */
70736 @@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
70737 mm->free_area_cache = addr;
70738
70739 /* dont allow allocations above current base */
70740 - if (mm->free_area_cache > mm->mmap_base)
70741 + if (mm->free_area_cache > mm->mmap_base) {
70742 mm->free_area_cache = mm->mmap_base;
70743 + mm->cached_hole_size = ~0UL;
70744 + }
70745 }
70746
70747 unsigned long
70748 @@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
70749 return vma;
70750 }
70751
70752 +#ifdef CONFIG_PAX_SEGMEXEC
70753 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
70754 +{
70755 + struct vm_area_struct *vma_m;
70756 +
70757 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
70758 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
70759 + BUG_ON(vma->vm_mirror);
70760 + return NULL;
70761 + }
70762 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
70763 + vma_m = vma->vm_mirror;
70764 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
70765 + BUG_ON(vma->vm_file != vma_m->vm_file);
70766 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
70767 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
70768 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
70769 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
70770 + return vma_m;
70771 +}
70772 +#endif
70773 +
70774 /*
70775 * Verify that the stack growth is acceptable and
70776 * update accounting. This is shared with both the
70777 @@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
70778 return -ENOMEM;
70779
70780 /* Stack limit test */
70781 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
70782 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
70783 return -ENOMEM;
70784
70785 @@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
70786 locked = mm->locked_vm + grow;
70787 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
70788 limit >>= PAGE_SHIFT;
70789 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70790 if (locked > limit && !capable(CAP_IPC_LOCK))
70791 return -ENOMEM;
70792 }
70793 @@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
70794 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
70795 * vma is the last one with address > vma->vm_end. Have to extend vma.
70796 */
70797 +#ifndef CONFIG_IA64
70798 +static
70799 +#endif
70800 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
70801 {
70802 int error;
70803 + bool locknext;
70804
70805 if (!(vma->vm_flags & VM_GROWSUP))
70806 return -EFAULT;
70807
70808 + /* Also guard against wrapping around to address 0. */
70809 + if (address < PAGE_ALIGN(address+1))
70810 + address = PAGE_ALIGN(address+1);
70811 + else
70812 + return -ENOMEM;
70813 +
70814 /*
70815 * We must make sure the anon_vma is allocated
70816 * so that the anon_vma locking is not a noop.
70817 */
70818 if (unlikely(anon_vma_prepare(vma)))
70819 return -ENOMEM;
70820 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
70821 + if (locknext && anon_vma_prepare(vma->vm_next))
70822 + return -ENOMEM;
70823 vma_lock_anon_vma(vma);
70824 + if (locknext)
70825 + vma_lock_anon_vma(vma->vm_next);
70826
70827 /*
70828 * vma->vm_start/vm_end cannot change under us because the caller
70829 * is required to hold the mmap_sem in read mode. We need the
70830 - * anon_vma lock to serialize against concurrent expand_stacks.
70831 - * Also guard against wrapping around to address 0.
70832 + * anon_vma locks to serialize against concurrent expand_stacks
70833 + * and expand_upwards.
70834 */
70835 - if (address < PAGE_ALIGN(address+4))
70836 - address = PAGE_ALIGN(address+4);
70837 - else {
70838 - vma_unlock_anon_vma(vma);
70839 - return -ENOMEM;
70840 - }
70841 error = 0;
70842
70843 /* Somebody else might have raced and expanded it already */
70844 - if (address > vma->vm_end) {
70845 + 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)
70846 + error = -ENOMEM;
70847 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
70848 unsigned long size, grow;
70849
70850 size = address - vma->vm_start;
70851 @@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
70852 }
70853 }
70854 }
70855 + if (locknext)
70856 + vma_unlock_anon_vma(vma->vm_next);
70857 vma_unlock_anon_vma(vma);
70858 khugepaged_enter_vma_merge(vma);
70859 return error;
70860 @@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
70861 unsigned long address)
70862 {
70863 int error;
70864 + bool lockprev = false;
70865 + struct vm_area_struct *prev;
70866
70867 /*
70868 * We must make sure the anon_vma is allocated
70869 @@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
70870 if (error)
70871 return error;
70872
70873 + prev = vma->vm_prev;
70874 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
70875 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
70876 +#endif
70877 + if (lockprev && anon_vma_prepare(prev))
70878 + return -ENOMEM;
70879 + if (lockprev)
70880 + vma_lock_anon_vma(prev);
70881 +
70882 vma_lock_anon_vma(vma);
70883
70884 /*
70885 @@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
70886 */
70887
70888 /* Somebody else might have raced and expanded it already */
70889 - if (address < vma->vm_start) {
70890 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
70891 + error = -ENOMEM;
70892 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
70893 unsigned long size, grow;
70894
70895 +#ifdef CONFIG_PAX_SEGMEXEC
70896 + struct vm_area_struct *vma_m;
70897 +
70898 + vma_m = pax_find_mirror_vma(vma);
70899 +#endif
70900 +
70901 size = vma->vm_end - address;
70902 grow = (vma->vm_start - address) >> PAGE_SHIFT;
70903
70904 @@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
70905 if (!error) {
70906 vma->vm_start = address;
70907 vma->vm_pgoff -= grow;
70908 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
70909 +
70910 +#ifdef CONFIG_PAX_SEGMEXEC
70911 + if (vma_m) {
70912 + vma_m->vm_start -= grow << PAGE_SHIFT;
70913 + vma_m->vm_pgoff -= grow;
70914 + }
70915 +#endif
70916 +
70917 perf_event_mmap(vma);
70918 }
70919 }
70920 }
70921 vma_unlock_anon_vma(vma);
70922 + if (lockprev)
70923 + vma_unlock_anon_vma(prev);
70924 khugepaged_enter_vma_merge(vma);
70925 return error;
70926 }
70927 @@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
70928 do {
70929 long nrpages = vma_pages(vma);
70930
70931 +#ifdef CONFIG_PAX_SEGMEXEC
70932 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
70933 + vma = remove_vma(vma);
70934 + continue;
70935 + }
70936 +#endif
70937 +
70938 mm->total_vm -= nrpages;
70939 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
70940 vma = remove_vma(vma);
70941 @@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
70942 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
70943 vma->vm_prev = NULL;
70944 do {
70945 +
70946 +#ifdef CONFIG_PAX_SEGMEXEC
70947 + if (vma->vm_mirror) {
70948 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
70949 + vma->vm_mirror->vm_mirror = NULL;
70950 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
70951 + vma->vm_mirror = NULL;
70952 + }
70953 +#endif
70954 +
70955 rb_erase(&vma->vm_rb, &mm->mm_rb);
70956 mm->map_count--;
70957 tail_vma = vma;
70958 @@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
70959 struct vm_area_struct *new;
70960 int err = -ENOMEM;
70961
70962 +#ifdef CONFIG_PAX_SEGMEXEC
70963 + struct vm_area_struct *vma_m, *new_m = NULL;
70964 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
70965 +#endif
70966 +
70967 if (is_vm_hugetlb_page(vma) && (addr &
70968 ~(huge_page_mask(hstate_vma(vma)))))
70969 return -EINVAL;
70970
70971 +#ifdef CONFIG_PAX_SEGMEXEC
70972 + vma_m = pax_find_mirror_vma(vma);
70973 +#endif
70974 +
70975 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70976 if (!new)
70977 goto out_err;
70978
70979 +#ifdef CONFIG_PAX_SEGMEXEC
70980 + if (vma_m) {
70981 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70982 + if (!new_m) {
70983 + kmem_cache_free(vm_area_cachep, new);
70984 + goto out_err;
70985 + }
70986 + }
70987 +#endif
70988 +
70989 /* most fields are the same, copy all, and then fixup */
70990 *new = *vma;
70991
70992 @@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
70993 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
70994 }
70995
70996 +#ifdef CONFIG_PAX_SEGMEXEC
70997 + if (vma_m) {
70998 + *new_m = *vma_m;
70999 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
71000 + new_m->vm_mirror = new;
71001 + new->vm_mirror = new_m;
71002 +
71003 + if (new_below)
71004 + new_m->vm_end = addr_m;
71005 + else {
71006 + new_m->vm_start = addr_m;
71007 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
71008 + }
71009 + }
71010 +#endif
71011 +
71012 pol = mpol_dup(vma_policy(vma));
71013 if (IS_ERR(pol)) {
71014 err = PTR_ERR(pol);
71015 @@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71016 else
71017 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
71018
71019 +#ifdef CONFIG_PAX_SEGMEXEC
71020 + if (!err && vma_m) {
71021 + if (anon_vma_clone(new_m, vma_m))
71022 + goto out_free_mpol;
71023 +
71024 + mpol_get(pol);
71025 + vma_set_policy(new_m, pol);
71026 +
71027 + if (new_m->vm_file) {
71028 + get_file(new_m->vm_file);
71029 + if (vma_m->vm_flags & VM_EXECUTABLE)
71030 + added_exe_file_vma(mm);
71031 + }
71032 +
71033 + if (new_m->vm_ops && new_m->vm_ops->open)
71034 + new_m->vm_ops->open(new_m);
71035 +
71036 + if (new_below)
71037 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
71038 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
71039 + else
71040 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
71041 +
71042 + if (err) {
71043 + if (new_m->vm_ops && new_m->vm_ops->close)
71044 + new_m->vm_ops->close(new_m);
71045 + if (new_m->vm_file) {
71046 + if (vma_m->vm_flags & VM_EXECUTABLE)
71047 + removed_exe_file_vma(mm);
71048 + fput(new_m->vm_file);
71049 + }
71050 + mpol_put(pol);
71051 + }
71052 + }
71053 +#endif
71054 +
71055 /* Success. */
71056 if (!err)
71057 return 0;
71058 @@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71059 removed_exe_file_vma(mm);
71060 fput(new->vm_file);
71061 }
71062 - unlink_anon_vmas(new);
71063 out_free_mpol:
71064 mpol_put(pol);
71065 out_free_vma:
71066 +
71067 +#ifdef CONFIG_PAX_SEGMEXEC
71068 + if (new_m) {
71069 + unlink_anon_vmas(new_m);
71070 + kmem_cache_free(vm_area_cachep, new_m);
71071 + }
71072 +#endif
71073 +
71074 + unlink_anon_vmas(new);
71075 kmem_cache_free(vm_area_cachep, new);
71076 out_err:
71077 return err;
71078 @@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71079 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71080 unsigned long addr, int new_below)
71081 {
71082 +
71083 +#ifdef CONFIG_PAX_SEGMEXEC
71084 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71085 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
71086 + if (mm->map_count >= sysctl_max_map_count-1)
71087 + return -ENOMEM;
71088 + } else
71089 +#endif
71090 +
71091 if (mm->map_count >= sysctl_max_map_count)
71092 return -ENOMEM;
71093
71094 @@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71095 * work. This now handles partial unmappings.
71096 * Jeremy Fitzhardinge <jeremy@goop.org>
71097 */
71098 +#ifdef CONFIG_PAX_SEGMEXEC
71099 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71100 {
71101 + int ret = __do_munmap(mm, start, len);
71102 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
71103 + return ret;
71104 +
71105 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
71106 +}
71107 +
71108 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71109 +#else
71110 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71111 +#endif
71112 +{
71113 unsigned long end;
71114 struct vm_area_struct *vma, *prev, *last;
71115
71116 + /*
71117 + * mm->mmap_sem is required to protect against another thread
71118 + * changing the mappings in case we sleep.
71119 + */
71120 + verify_mm_writelocked(mm);
71121 +
71122 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
71123 return -EINVAL;
71124
71125 @@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71126 /* Fix up all other VM information */
71127 remove_vma_list(mm, vma);
71128
71129 + track_exec_limit(mm, start, end, 0UL);
71130 +
71131 return 0;
71132 }
71133
71134 @@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
71135
71136 profile_munmap(addr);
71137
71138 +#ifdef CONFIG_PAX_SEGMEXEC
71139 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
71140 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
71141 + return -EINVAL;
71142 +#endif
71143 +
71144 down_write(&mm->mmap_sem);
71145 ret = do_munmap(mm, addr, len);
71146 up_write(&mm->mmap_sem);
71147 return ret;
71148 }
71149
71150 -static inline void verify_mm_writelocked(struct mm_struct *mm)
71151 -{
71152 -#ifdef CONFIG_DEBUG_VM
71153 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71154 - WARN_ON(1);
71155 - up_read(&mm->mmap_sem);
71156 - }
71157 -#endif
71158 -}
71159 -
71160 /*
71161 * this is really a simplified "do_mmap". it only handles
71162 * anonymous maps. eventually we may be able to do some
71163 @@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71164 struct rb_node ** rb_link, * rb_parent;
71165 pgoff_t pgoff = addr >> PAGE_SHIFT;
71166 int error;
71167 + unsigned long charged;
71168
71169 len = PAGE_ALIGN(len);
71170 if (!len)
71171 @@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71172
71173 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
71174
71175 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
71176 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
71177 + flags &= ~VM_EXEC;
71178 +
71179 +#ifdef CONFIG_PAX_MPROTECT
71180 + if (mm->pax_flags & MF_PAX_MPROTECT)
71181 + flags &= ~VM_MAYEXEC;
71182 +#endif
71183 +
71184 + }
71185 +#endif
71186 +
71187 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
71188 if (error & ~PAGE_MASK)
71189 return error;
71190
71191 + charged = len >> PAGE_SHIFT;
71192 +
71193 /*
71194 * mlock MCL_FUTURE?
71195 */
71196 if (mm->def_flags & VM_LOCKED) {
71197 unsigned long locked, lock_limit;
71198 - locked = len >> PAGE_SHIFT;
71199 + locked = charged;
71200 locked += mm->locked_vm;
71201 lock_limit = rlimit(RLIMIT_MEMLOCK);
71202 lock_limit >>= PAGE_SHIFT;
71203 @@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71204 /*
71205 * Clear old maps. this also does some error checking for us
71206 */
71207 - munmap_back:
71208 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71209 if (vma && vma->vm_start < addr + len) {
71210 if (do_munmap(mm, addr, len))
71211 return -ENOMEM;
71212 - goto munmap_back;
71213 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71214 + BUG_ON(vma && vma->vm_start < addr + len);
71215 }
71216
71217 /* Check against address space limits *after* clearing old maps... */
71218 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
71219 + if (!may_expand_vm(mm, charged))
71220 return -ENOMEM;
71221
71222 if (mm->map_count > sysctl_max_map_count)
71223 return -ENOMEM;
71224
71225 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
71226 + if (security_vm_enough_memory(charged))
71227 return -ENOMEM;
71228
71229 /* Can we just expand an old private anonymous mapping? */
71230 @@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71231 */
71232 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71233 if (!vma) {
71234 - vm_unacct_memory(len >> PAGE_SHIFT);
71235 + vm_unacct_memory(charged);
71236 return -ENOMEM;
71237 }
71238
71239 @@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71240 vma_link(mm, vma, prev, rb_link, rb_parent);
71241 out:
71242 perf_event_mmap(vma);
71243 - mm->total_vm += len >> PAGE_SHIFT;
71244 + mm->total_vm += charged;
71245 if (flags & VM_LOCKED) {
71246 if (!mlock_vma_pages_range(vma, addr, addr + len))
71247 - mm->locked_vm += (len >> PAGE_SHIFT);
71248 + mm->locked_vm += charged;
71249 }
71250 + track_exec_limit(mm, addr, addr + len, flags);
71251 return addr;
71252 }
71253
71254 @@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
71255 * Walk the list again, actually closing and freeing it,
71256 * with preemption enabled, without holding any MM locks.
71257 */
71258 - while (vma)
71259 + while (vma) {
71260 + vma->vm_mirror = NULL;
71261 vma = remove_vma(vma);
71262 + }
71263
71264 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
71265 }
71266 @@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71267 struct vm_area_struct * __vma, * prev;
71268 struct rb_node ** rb_link, * rb_parent;
71269
71270 +#ifdef CONFIG_PAX_SEGMEXEC
71271 + struct vm_area_struct *vma_m = NULL;
71272 +#endif
71273 +
71274 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
71275 + return -EPERM;
71276 +
71277 /*
71278 * The vm_pgoff of a purely anonymous vma should be irrelevant
71279 * until its first write fault, when page's anon_vma and index
71280 @@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71281 if ((vma->vm_flags & VM_ACCOUNT) &&
71282 security_vm_enough_memory_mm(mm, vma_pages(vma)))
71283 return -ENOMEM;
71284 +
71285 +#ifdef CONFIG_PAX_SEGMEXEC
71286 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
71287 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71288 + if (!vma_m)
71289 + return -ENOMEM;
71290 + }
71291 +#endif
71292 +
71293 vma_link(mm, vma, prev, rb_link, rb_parent);
71294 +
71295 +#ifdef CONFIG_PAX_SEGMEXEC
71296 + if (vma_m)
71297 + BUG_ON(pax_mirror_vma(vma_m, vma));
71298 +#endif
71299 +
71300 return 0;
71301 }
71302
71303 @@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71304 struct mempolicy *pol;
71305 bool faulted_in_anon_vma = true;
71306
71307 + BUG_ON(vma->vm_mirror);
71308 +
71309 /*
71310 * If anonymous vma has not yet been faulted, update new pgoff
71311 * to match new location, to increase its chance of merging.
71312 @@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71313 return NULL;
71314 }
71315
71316 +#ifdef CONFIG_PAX_SEGMEXEC
71317 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
71318 +{
71319 + struct vm_area_struct *prev_m;
71320 + struct rb_node **rb_link_m, *rb_parent_m;
71321 + struct mempolicy *pol_m;
71322 +
71323 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
71324 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
71325 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
71326 + *vma_m = *vma;
71327 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
71328 + if (anon_vma_clone(vma_m, vma))
71329 + return -ENOMEM;
71330 + pol_m = vma_policy(vma_m);
71331 + mpol_get(pol_m);
71332 + vma_set_policy(vma_m, pol_m);
71333 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
71334 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
71335 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
71336 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
71337 + if (vma_m->vm_file)
71338 + get_file(vma_m->vm_file);
71339 + if (vma_m->vm_ops && vma_m->vm_ops->open)
71340 + vma_m->vm_ops->open(vma_m);
71341 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
71342 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
71343 + vma_m->vm_mirror = vma;
71344 + vma->vm_mirror = vma_m;
71345 + return 0;
71346 +}
71347 +#endif
71348 +
71349 /*
71350 * Return true if the calling process may expand its vm space by the passed
71351 * number of pages
71352 @@ -2392,7 +2882,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
71353 unsigned long lim;
71354
71355 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
71356 -
71357 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
71358 if (cur + npages > lim)
71359 return 0;
71360 return 1;
71361 @@ -2463,6 +2953,22 @@ int install_special_mapping(struct mm_struct *mm,
71362 vma->vm_start = addr;
71363 vma->vm_end = addr + len;
71364
71365 +#ifdef CONFIG_PAX_MPROTECT
71366 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71367 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71368 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
71369 + return -EPERM;
71370 + if (!(vm_flags & VM_EXEC))
71371 + vm_flags &= ~VM_MAYEXEC;
71372 +#else
71373 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71374 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71375 +#endif
71376 + else
71377 + vm_flags &= ~VM_MAYWRITE;
71378 + }
71379 +#endif
71380 +
71381 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
71382 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71383
71384 diff --git a/mm/mprotect.c b/mm/mprotect.c
71385 index f437d05..e3763f6 100644
71386 --- a/mm/mprotect.c
71387 +++ b/mm/mprotect.c
71388 @@ -23,10 +23,16 @@
71389 #include <linux/mmu_notifier.h>
71390 #include <linux/migrate.h>
71391 #include <linux/perf_event.h>
71392 +
71393 +#ifdef CONFIG_PAX_MPROTECT
71394 +#include <linux/elf.h>
71395 +#endif
71396 +
71397 #include <asm/uaccess.h>
71398 #include <asm/pgtable.h>
71399 #include <asm/cacheflush.h>
71400 #include <asm/tlbflush.h>
71401 +#include <asm/mmu_context.h>
71402
71403 #ifndef pgprot_modify
71404 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
71405 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
71406 flush_tlb_range(vma, start, end);
71407 }
71408
71409 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71410 +/* called while holding the mmap semaphor for writing except stack expansion */
71411 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
71412 +{
71413 + unsigned long oldlimit, newlimit = 0UL;
71414 +
71415 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
71416 + return;
71417 +
71418 + spin_lock(&mm->page_table_lock);
71419 + oldlimit = mm->context.user_cs_limit;
71420 + if ((prot & VM_EXEC) && oldlimit < end)
71421 + /* USER_CS limit moved up */
71422 + newlimit = end;
71423 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
71424 + /* USER_CS limit moved down */
71425 + newlimit = start;
71426 +
71427 + if (newlimit) {
71428 + mm->context.user_cs_limit = newlimit;
71429 +
71430 +#ifdef CONFIG_SMP
71431 + wmb();
71432 + cpus_clear(mm->context.cpu_user_cs_mask);
71433 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
71434 +#endif
71435 +
71436 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
71437 + }
71438 + spin_unlock(&mm->page_table_lock);
71439 + if (newlimit == end) {
71440 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
71441 +
71442 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
71443 + if (is_vm_hugetlb_page(vma))
71444 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
71445 + else
71446 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
71447 + }
71448 +}
71449 +#endif
71450 +
71451 int
71452 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71453 unsigned long start, unsigned long end, unsigned long newflags)
71454 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71455 int error;
71456 int dirty_accountable = 0;
71457
71458 +#ifdef CONFIG_PAX_SEGMEXEC
71459 + struct vm_area_struct *vma_m = NULL;
71460 + unsigned long start_m, end_m;
71461 +
71462 + start_m = start + SEGMEXEC_TASK_SIZE;
71463 + end_m = end + SEGMEXEC_TASK_SIZE;
71464 +#endif
71465 +
71466 if (newflags == oldflags) {
71467 *pprev = vma;
71468 return 0;
71469 }
71470
71471 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
71472 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
71473 +
71474 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
71475 + return -ENOMEM;
71476 +
71477 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
71478 + return -ENOMEM;
71479 + }
71480 +
71481 /*
71482 * If we make a private mapping writable we increase our commit;
71483 * but (without finer accounting) cannot reduce our commit if we
71484 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71485 }
71486 }
71487
71488 +#ifdef CONFIG_PAX_SEGMEXEC
71489 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
71490 + if (start != vma->vm_start) {
71491 + error = split_vma(mm, vma, start, 1);
71492 + if (error)
71493 + goto fail;
71494 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
71495 + *pprev = (*pprev)->vm_next;
71496 + }
71497 +
71498 + if (end != vma->vm_end) {
71499 + error = split_vma(mm, vma, end, 0);
71500 + if (error)
71501 + goto fail;
71502 + }
71503 +
71504 + if (pax_find_mirror_vma(vma)) {
71505 + error = __do_munmap(mm, start_m, end_m - start_m);
71506 + if (error)
71507 + goto fail;
71508 + } else {
71509 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71510 + if (!vma_m) {
71511 + error = -ENOMEM;
71512 + goto fail;
71513 + }
71514 + vma->vm_flags = newflags;
71515 + error = pax_mirror_vma(vma_m, vma);
71516 + if (error) {
71517 + vma->vm_flags = oldflags;
71518 + goto fail;
71519 + }
71520 + }
71521 + }
71522 +#endif
71523 +
71524 /*
71525 * First try to merge with previous and/or next vma.
71526 */
71527 @@ -204,9 +306,21 @@ success:
71528 * vm_flags and vm_page_prot are protected by the mmap_sem
71529 * held in write mode.
71530 */
71531 +
71532 +#ifdef CONFIG_PAX_SEGMEXEC
71533 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
71534 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
71535 +#endif
71536 +
71537 vma->vm_flags = newflags;
71538 +
71539 +#ifdef CONFIG_PAX_MPROTECT
71540 + if (mm->binfmt && mm->binfmt->handle_mprotect)
71541 + mm->binfmt->handle_mprotect(vma, newflags);
71542 +#endif
71543 +
71544 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
71545 - vm_get_page_prot(newflags));
71546 + vm_get_page_prot(vma->vm_flags));
71547
71548 if (vma_wants_writenotify(vma)) {
71549 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
71550 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71551 end = start + len;
71552 if (end <= start)
71553 return -ENOMEM;
71554 +
71555 +#ifdef CONFIG_PAX_SEGMEXEC
71556 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71557 + if (end > SEGMEXEC_TASK_SIZE)
71558 + return -EINVAL;
71559 + } else
71560 +#endif
71561 +
71562 + if (end > TASK_SIZE)
71563 + return -EINVAL;
71564 +
71565 if (!arch_validate_prot(prot))
71566 return -EINVAL;
71567
71568 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71569 /*
71570 * Does the application expect PROT_READ to imply PROT_EXEC:
71571 */
71572 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71573 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71574 prot |= PROT_EXEC;
71575
71576 vm_flags = calc_vm_prot_bits(prot);
71577 @@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71578 if (start > vma->vm_start)
71579 prev = vma;
71580
71581 +#ifdef CONFIG_PAX_MPROTECT
71582 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
71583 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
71584 +#endif
71585 +
71586 for (nstart = start ; ; ) {
71587 unsigned long newflags;
71588
71589 @@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71590
71591 /* newflags >> 4 shift VM_MAY% in place of VM_% */
71592 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
71593 + if (prot & (PROT_WRITE | PROT_EXEC))
71594 + gr_log_rwxmprotect(vma->vm_file);
71595 +
71596 + error = -EACCES;
71597 + goto out;
71598 + }
71599 +
71600 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
71601 error = -EACCES;
71602 goto out;
71603 }
71604 @@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71605 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
71606 if (error)
71607 goto out;
71608 +
71609 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
71610 +
71611 nstart = tmp;
71612
71613 if (nstart < prev->vm_end)
71614 diff --git a/mm/mremap.c b/mm/mremap.c
71615 index 87bb839..c3bfadb 100644
71616 --- a/mm/mremap.c
71617 +++ b/mm/mremap.c
71618 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
71619 continue;
71620 pte = ptep_get_and_clear(mm, old_addr, old_pte);
71621 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
71622 +
71623 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71624 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
71625 + pte = pte_exprotect(pte);
71626 +#endif
71627 +
71628 set_pte_at(mm, new_addr, new_pte, pte);
71629 }
71630
71631 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
71632 if (is_vm_hugetlb_page(vma))
71633 goto Einval;
71634
71635 +#ifdef CONFIG_PAX_SEGMEXEC
71636 + if (pax_find_mirror_vma(vma))
71637 + goto Einval;
71638 +#endif
71639 +
71640 /* We can't remap across vm area boundaries */
71641 if (old_len > vma->vm_end - addr)
71642 goto Efault;
71643 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
71644 unsigned long ret = -EINVAL;
71645 unsigned long charged = 0;
71646 unsigned long map_flags;
71647 + unsigned long pax_task_size = TASK_SIZE;
71648
71649 if (new_addr & ~PAGE_MASK)
71650 goto out;
71651
71652 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
71653 +#ifdef CONFIG_PAX_SEGMEXEC
71654 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
71655 + pax_task_size = SEGMEXEC_TASK_SIZE;
71656 +#endif
71657 +
71658 + pax_task_size -= PAGE_SIZE;
71659 +
71660 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
71661 goto out;
71662
71663 /* Check if the location we're moving into overlaps the
71664 * old location at all, and fail if it does.
71665 */
71666 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
71667 - goto out;
71668 -
71669 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
71670 + if (addr + old_len > new_addr && new_addr + new_len > addr)
71671 goto out;
71672
71673 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
71674 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
71675 struct vm_area_struct *vma;
71676 unsigned long ret = -EINVAL;
71677 unsigned long charged = 0;
71678 + unsigned long pax_task_size = TASK_SIZE;
71679
71680 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
71681 goto out;
71682 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
71683 if (!new_len)
71684 goto out;
71685
71686 +#ifdef CONFIG_PAX_SEGMEXEC
71687 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
71688 + pax_task_size = SEGMEXEC_TASK_SIZE;
71689 +#endif
71690 +
71691 + pax_task_size -= PAGE_SIZE;
71692 +
71693 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
71694 + old_len > pax_task_size || addr > pax_task_size-old_len)
71695 + goto out;
71696 +
71697 if (flags & MREMAP_FIXED) {
71698 if (flags & MREMAP_MAYMOVE)
71699 ret = mremap_to(addr, old_len, new_addr, new_len);
71700 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
71701 addr + new_len);
71702 }
71703 ret = addr;
71704 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
71705 goto out;
71706 }
71707 }
71708 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
71709 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
71710 if (ret)
71711 goto out;
71712 +
71713 + map_flags = vma->vm_flags;
71714 ret = move_vma(vma, addr, old_len, new_len, new_addr);
71715 + if (!(ret & ~PAGE_MASK)) {
71716 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
71717 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
71718 + }
71719 }
71720 out:
71721 if (ret & ~PAGE_MASK)
71722 diff --git a/mm/nommu.c b/mm/nommu.c
71723 index f59e170..34e2a2b 100644
71724 --- a/mm/nommu.c
71725 +++ b/mm/nommu.c
71726 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
71727 int sysctl_overcommit_ratio = 50; /* default is 50% */
71728 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
71729 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
71730 -int heap_stack_gap = 0;
71731
71732 atomic_long_t mmap_pages_allocated;
71733
71734 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
71735 EXPORT_SYMBOL(find_vma);
71736
71737 /*
71738 - * find a VMA
71739 - * - we don't extend stack VMAs under NOMMU conditions
71740 - */
71741 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
71742 -{
71743 - return find_vma(mm, addr);
71744 -}
71745 -
71746 -/*
71747 * expand a stack to a given address
71748 * - not supported under NOMMU conditions
71749 */
71750 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71751
71752 /* most fields are the same, copy all, and then fixup */
71753 *new = *vma;
71754 + INIT_LIST_HEAD(&new->anon_vma_chain);
71755 *region = *vma->vm_region;
71756 new->vm_region = region;
71757
71758 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
71759 index a13ded1..b949d15 100644
71760 --- a/mm/page_alloc.c
71761 +++ b/mm/page_alloc.c
71762 @@ -335,7 +335,7 @@ out:
71763 * This usage means that zero-order pages may not be compound.
71764 */
71765
71766 -static void free_compound_page(struct page *page)
71767 +void free_compound_page(struct page *page)
71768 {
71769 __free_pages_ok(page, compound_order(page));
71770 }
71771 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
71772 int i;
71773 int bad = 0;
71774
71775 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
71776 + unsigned long index = 1UL << order;
71777 +#endif
71778 +
71779 trace_mm_page_free(page, order);
71780 kmemcheck_free_shadow(page, order);
71781
71782 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
71783 debug_check_no_obj_freed(page_address(page),
71784 PAGE_SIZE << order);
71785 }
71786 +
71787 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
71788 + for (; index; --index)
71789 + sanitize_highpage(page + index - 1);
71790 +#endif
71791 +
71792 arch_free_page(page, order);
71793 kernel_map_pages(page, 1 << order, 0);
71794
71795 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
71796 arch_alloc_page(page, order);
71797 kernel_map_pages(page, 1 << order, 1);
71798
71799 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
71800 if (gfp_flags & __GFP_ZERO)
71801 prep_zero_page(page, order, gfp_flags);
71802 +#endif
71803
71804 if (order && (gfp_flags & __GFP_COMP))
71805 prep_compound_page(page, order);
71806 @@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
71807 unsigned long pfn;
71808
71809 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
71810 +#ifdef CONFIG_X86_32
71811 + /* boot failures in VMware 8 on 32bit vanilla since
71812 + this change */
71813 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
71814 +#else
71815 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
71816 +#endif
71817 return 1;
71818 }
71819 return 0;
71820 diff --git a/mm/percpu.c b/mm/percpu.c
71821 index f47af91..7eeef99 100644
71822 --- a/mm/percpu.c
71823 +++ b/mm/percpu.c
71824 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
71825 static unsigned int pcpu_high_unit_cpu __read_mostly;
71826
71827 /* the address of the first chunk which starts with the kernel static area */
71828 -void *pcpu_base_addr __read_mostly;
71829 +void *pcpu_base_addr __read_only;
71830 EXPORT_SYMBOL_GPL(pcpu_base_addr);
71831
71832 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
71833 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
71834 index c20ff48..137702a 100644
71835 --- a/mm/process_vm_access.c
71836 +++ b/mm/process_vm_access.c
71837 @@ -13,6 +13,7 @@
71838 #include <linux/uio.h>
71839 #include <linux/sched.h>
71840 #include <linux/highmem.h>
71841 +#include <linux/security.h>
71842 #include <linux/ptrace.h>
71843 #include <linux/slab.h>
71844 #include <linux/syscalls.h>
71845 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
71846 size_t iov_l_curr_offset = 0;
71847 ssize_t iov_len;
71848
71849 + return -ENOSYS; // PaX: until properly audited
71850 +
71851 /*
71852 * Work out how many pages of struct pages we're going to need
71853 * when eventually calling get_user_pages
71854 */
71855 for (i = 0; i < riovcnt; i++) {
71856 iov_len = rvec[i].iov_len;
71857 - if (iov_len > 0) {
71858 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
71859 - + iov_len)
71860 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
71861 - / PAGE_SIZE + 1;
71862 - nr_pages = max(nr_pages, nr_pages_iov);
71863 - }
71864 + if (iov_len <= 0)
71865 + continue;
71866 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
71867 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
71868 + nr_pages = max(nr_pages, nr_pages_iov);
71869 }
71870
71871 if (nr_pages == 0)
71872 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
71873 goto free_proc_pages;
71874 }
71875
71876 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
71877 + rc = -EPERM;
71878 + goto put_task_struct;
71879 + }
71880 +
71881 mm = mm_access(task, PTRACE_MODE_ATTACH);
71882 if (!mm || IS_ERR(mm)) {
71883 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
71884 diff --git a/mm/rmap.c b/mm/rmap.c
71885 index c8454e0..b04f3a2 100644
71886 --- a/mm/rmap.c
71887 +++ b/mm/rmap.c
71888 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
71889 struct anon_vma *anon_vma = vma->anon_vma;
71890 struct anon_vma_chain *avc;
71891
71892 +#ifdef CONFIG_PAX_SEGMEXEC
71893 + struct anon_vma_chain *avc_m = NULL;
71894 +#endif
71895 +
71896 might_sleep();
71897 if (unlikely(!anon_vma)) {
71898 struct mm_struct *mm = vma->vm_mm;
71899 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
71900 if (!avc)
71901 goto out_enomem;
71902
71903 +#ifdef CONFIG_PAX_SEGMEXEC
71904 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
71905 + if (!avc_m)
71906 + goto out_enomem_free_avc;
71907 +#endif
71908 +
71909 anon_vma = find_mergeable_anon_vma(vma);
71910 allocated = NULL;
71911 if (!anon_vma) {
71912 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
71913 /* page_table_lock to protect against threads */
71914 spin_lock(&mm->page_table_lock);
71915 if (likely(!vma->anon_vma)) {
71916 +
71917 +#ifdef CONFIG_PAX_SEGMEXEC
71918 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
71919 +
71920 + if (vma_m) {
71921 + BUG_ON(vma_m->anon_vma);
71922 + vma_m->anon_vma = anon_vma;
71923 + avc_m->anon_vma = anon_vma;
71924 + avc_m->vma = vma;
71925 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
71926 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
71927 + avc_m = NULL;
71928 + }
71929 +#endif
71930 +
71931 vma->anon_vma = anon_vma;
71932 avc->anon_vma = anon_vma;
71933 avc->vma = vma;
71934 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
71935
71936 if (unlikely(allocated))
71937 put_anon_vma(allocated);
71938 +
71939 +#ifdef CONFIG_PAX_SEGMEXEC
71940 + if (unlikely(avc_m))
71941 + anon_vma_chain_free(avc_m);
71942 +#endif
71943 +
71944 if (unlikely(avc))
71945 anon_vma_chain_free(avc);
71946 }
71947 return 0;
71948
71949 out_enomem_free_avc:
71950 +
71951 +#ifdef CONFIG_PAX_SEGMEXEC
71952 + if (avc_m)
71953 + anon_vma_chain_free(avc_m);
71954 +#endif
71955 +
71956 anon_vma_chain_free(avc);
71957 out_enomem:
71958 return -ENOMEM;
71959 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
71960 * Attach the anon_vmas from src to dst.
71961 * Returns 0 on success, -ENOMEM on failure.
71962 */
71963 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
71964 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
71965 {
71966 struct anon_vma_chain *avc, *pavc;
71967 struct anon_vma *root = NULL;
71968 @@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
71969 * the corresponding VMA in the parent process is attached to.
71970 * Returns 0 on success, non-zero on failure.
71971 */
71972 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
71973 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
71974 {
71975 struct anon_vma_chain *avc;
71976 struct anon_vma *anon_vma;
71977 diff --git a/mm/shmem.c b/mm/shmem.c
71978 index 269d049..a9d2b50 100644
71979 --- a/mm/shmem.c
71980 +++ b/mm/shmem.c
71981 @@ -31,7 +31,7 @@
71982 #include <linux/export.h>
71983 #include <linux/swap.h>
71984
71985 -static struct vfsmount *shm_mnt;
71986 +struct vfsmount *shm_mnt;
71987
71988 #ifdef CONFIG_SHMEM
71989 /*
71990 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
71991 #define BOGO_DIRENT_SIZE 20
71992
71993 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
71994 -#define SHORT_SYMLINK_LEN 128
71995 +#define SHORT_SYMLINK_LEN 64
71996
71997 struct shmem_xattr {
71998 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
71999 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
72000 int err = -ENOMEM;
72001
72002 /* Round up to L1_CACHE_BYTES to resist false sharing */
72003 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
72004 - L1_CACHE_BYTES), GFP_KERNEL);
72005 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
72006 if (!sbinfo)
72007 return -ENOMEM;
72008
72009 diff --git a/mm/slab.c b/mm/slab.c
72010 index f0bd785..348b96a 100644
72011 --- a/mm/slab.c
72012 +++ b/mm/slab.c
72013 @@ -153,7 +153,7 @@
72014
72015 /* Legal flag mask for kmem_cache_create(). */
72016 #if DEBUG
72017 -# define CREATE_MASK (SLAB_RED_ZONE | \
72018 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
72019 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
72020 SLAB_CACHE_DMA | \
72021 SLAB_STORE_USER | \
72022 @@ -161,7 +161,7 @@
72023 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72024 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
72025 #else
72026 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
72027 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
72028 SLAB_CACHE_DMA | \
72029 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
72030 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72031 @@ -290,7 +290,7 @@ struct kmem_list3 {
72032 * Need this for bootstrapping a per node allocator.
72033 */
72034 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
72035 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
72036 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
72037 #define CACHE_CACHE 0
72038 #define SIZE_AC MAX_NUMNODES
72039 #define SIZE_L3 (2 * MAX_NUMNODES)
72040 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
72041 if ((x)->max_freeable < i) \
72042 (x)->max_freeable = i; \
72043 } while (0)
72044 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
72045 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
72046 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
72047 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
72048 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
72049 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
72050 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
72051 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
72052 #else
72053 #define STATS_INC_ACTIVE(x) do { } while (0)
72054 #define STATS_DEC_ACTIVE(x) do { } while (0)
72055 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
72056 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
72057 */
72058 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
72059 - const struct slab *slab, void *obj)
72060 + const struct slab *slab, const void *obj)
72061 {
72062 u32 offset = (obj - slab->s_mem);
72063 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
72064 @@ -568,7 +568,7 @@ struct cache_names {
72065 static struct cache_names __initdata cache_names[] = {
72066 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
72067 #include <linux/kmalloc_sizes.h>
72068 - {NULL,}
72069 + {NULL}
72070 #undef CACHE
72071 };
72072
72073 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
72074 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
72075 sizes[INDEX_AC].cs_size,
72076 ARCH_KMALLOC_MINALIGN,
72077 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72078 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72079 NULL);
72080
72081 if (INDEX_AC != INDEX_L3) {
72082 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
72083 kmem_cache_create(names[INDEX_L3].name,
72084 sizes[INDEX_L3].cs_size,
72085 ARCH_KMALLOC_MINALIGN,
72086 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72087 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72088 NULL);
72089 }
72090
72091 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
72092 sizes->cs_cachep = kmem_cache_create(names->name,
72093 sizes->cs_size,
72094 ARCH_KMALLOC_MINALIGN,
72095 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72096 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72097 NULL);
72098 }
72099 #ifdef CONFIG_ZONE_DMA
72100 @@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
72101 }
72102 /* cpu stats */
72103 {
72104 - unsigned long allochit = atomic_read(&cachep->allochit);
72105 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
72106 - unsigned long freehit = atomic_read(&cachep->freehit);
72107 - unsigned long freemiss = atomic_read(&cachep->freemiss);
72108 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
72109 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
72110 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
72111 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
72112
72113 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
72114 allochit, allocmiss, freehit, freemiss);
72115 @@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
72116 {
72117 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
72118 #ifdef CONFIG_DEBUG_SLAB_LEAK
72119 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
72120 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
72121 #endif
72122 return 0;
72123 }
72124 module_init(slab_proc_init);
72125 #endif
72126
72127 +void check_object_size(const void *ptr, unsigned long n, bool to)
72128 +{
72129 +
72130 +#ifdef CONFIG_PAX_USERCOPY
72131 + struct page *page;
72132 + struct kmem_cache *cachep = NULL;
72133 + struct slab *slabp;
72134 + unsigned int objnr;
72135 + unsigned long offset;
72136 + const char *type;
72137 +
72138 + if (!n)
72139 + return;
72140 +
72141 + type = "<null>";
72142 + if (ZERO_OR_NULL_PTR(ptr))
72143 + goto report;
72144 +
72145 + if (!virt_addr_valid(ptr))
72146 + return;
72147 +
72148 + page = virt_to_head_page(ptr);
72149 +
72150 + type = "<process stack>";
72151 + if (!PageSlab(page)) {
72152 + if (object_is_on_stack(ptr, n) == -1)
72153 + goto report;
72154 + return;
72155 + }
72156 +
72157 + cachep = page_get_cache(page);
72158 + type = cachep->name;
72159 + if (!(cachep->flags & SLAB_USERCOPY))
72160 + goto report;
72161 +
72162 + slabp = page_get_slab(page);
72163 + objnr = obj_to_index(cachep, slabp, ptr);
72164 + BUG_ON(objnr >= cachep->num);
72165 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
72166 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
72167 + return;
72168 +
72169 +report:
72170 + pax_report_usercopy(ptr, n, to, type);
72171 +#endif
72172 +
72173 +}
72174 +EXPORT_SYMBOL(check_object_size);
72175 +
72176 /**
72177 * ksize - get the actual amount of memory allocated for a given object
72178 * @objp: Pointer to the object
72179 diff --git a/mm/slob.c b/mm/slob.c
72180 index 8105be4..e045f96 100644
72181 --- a/mm/slob.c
72182 +++ b/mm/slob.c
72183 @@ -29,7 +29,7 @@
72184 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
72185 * alloc_pages() directly, allocating compound pages so the page order
72186 * does not have to be separately tracked, and also stores the exact
72187 - * allocation size in page->private so that it can be used to accurately
72188 + * allocation size in slob_page->size so that it can be used to accurately
72189 * provide ksize(). These objects are detected in kfree() because slob_page()
72190 * is false for them.
72191 *
72192 @@ -58,6 +58,7 @@
72193 */
72194
72195 #include <linux/kernel.h>
72196 +#include <linux/sched.h>
72197 #include <linux/slab.h>
72198 #include <linux/mm.h>
72199 #include <linux/swap.h> /* struct reclaim_state */
72200 @@ -102,7 +103,8 @@ struct slob_page {
72201 unsigned long flags; /* mandatory */
72202 atomic_t _count; /* mandatory */
72203 slobidx_t units; /* free units left in page */
72204 - unsigned long pad[2];
72205 + unsigned long pad[1];
72206 + unsigned long size; /* size when >=PAGE_SIZE */
72207 slob_t *free; /* first free slob_t in page */
72208 struct list_head list; /* linked list of free pages */
72209 };
72210 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
72211 */
72212 static inline int is_slob_page(struct slob_page *sp)
72213 {
72214 - return PageSlab((struct page *)sp);
72215 + return PageSlab((struct page *)sp) && !sp->size;
72216 }
72217
72218 static inline void set_slob_page(struct slob_page *sp)
72219 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
72220
72221 static inline struct slob_page *slob_page(const void *addr)
72222 {
72223 - return (struct slob_page *)virt_to_page(addr);
72224 + return (struct slob_page *)virt_to_head_page(addr);
72225 }
72226
72227 /*
72228 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
72229 /*
72230 * Return the size of a slob block.
72231 */
72232 -static slobidx_t slob_units(slob_t *s)
72233 +static slobidx_t slob_units(const slob_t *s)
72234 {
72235 if (s->units > 0)
72236 return s->units;
72237 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
72238 /*
72239 * Return the next free slob block pointer after this one.
72240 */
72241 -static slob_t *slob_next(slob_t *s)
72242 +static slob_t *slob_next(const slob_t *s)
72243 {
72244 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
72245 slobidx_t next;
72246 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
72247 /*
72248 * Returns true if s is the last free block in its page.
72249 */
72250 -static int slob_last(slob_t *s)
72251 +static int slob_last(const slob_t *s)
72252 {
72253 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
72254 }
72255 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
72256 if (!page)
72257 return NULL;
72258
72259 + set_slob_page(page);
72260 return page_address(page);
72261 }
72262
72263 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
72264 if (!b)
72265 return NULL;
72266 sp = slob_page(b);
72267 - set_slob_page(sp);
72268
72269 spin_lock_irqsave(&slob_lock, flags);
72270 sp->units = SLOB_UNITS(PAGE_SIZE);
72271 sp->free = b;
72272 + sp->size = 0;
72273 INIT_LIST_HEAD(&sp->list);
72274 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
72275 set_slob_page_free(sp, slob_list);
72276 @@ -476,10 +479,9 @@ out:
72277 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
72278 */
72279
72280 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72281 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
72282 {
72283 - unsigned int *m;
72284 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72285 + slob_t *m;
72286 void *ret;
72287
72288 gfp &= gfp_allowed_mask;
72289 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72290
72291 if (!m)
72292 return NULL;
72293 - *m = size;
72294 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
72295 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
72296 + m[0].units = size;
72297 + m[1].units = align;
72298 ret = (void *)m + align;
72299
72300 trace_kmalloc_node(_RET_IP_, ret,
72301 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72302 gfp |= __GFP_COMP;
72303 ret = slob_new_pages(gfp, order, node);
72304 if (ret) {
72305 - struct page *page;
72306 - page = virt_to_page(ret);
72307 - page->private = size;
72308 + struct slob_page *sp;
72309 + sp = slob_page(ret);
72310 + sp->size = size;
72311 }
72312
72313 trace_kmalloc_node(_RET_IP_, ret,
72314 size, PAGE_SIZE << order, gfp, node);
72315 }
72316
72317 - kmemleak_alloc(ret, size, 1, gfp);
72318 + return ret;
72319 +}
72320 +
72321 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72322 +{
72323 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72324 + void *ret = __kmalloc_node_align(size, gfp, node, align);
72325 +
72326 + if (!ZERO_OR_NULL_PTR(ret))
72327 + kmemleak_alloc(ret, size, 1, gfp);
72328 return ret;
72329 }
72330 EXPORT_SYMBOL(__kmalloc_node);
72331 @@ -533,13 +547,92 @@ void kfree(const void *block)
72332 sp = slob_page(block);
72333 if (is_slob_page(sp)) {
72334 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72335 - unsigned int *m = (unsigned int *)(block - align);
72336 - slob_free(m, *m + align);
72337 - } else
72338 + slob_t *m = (slob_t *)(block - align);
72339 + slob_free(m, m[0].units + align);
72340 + } else {
72341 + clear_slob_page(sp);
72342 + free_slob_page(sp);
72343 + sp->size = 0;
72344 put_page(&sp->page);
72345 + }
72346 }
72347 EXPORT_SYMBOL(kfree);
72348
72349 +void check_object_size(const void *ptr, unsigned long n, bool to)
72350 +{
72351 +
72352 +#ifdef CONFIG_PAX_USERCOPY
72353 + struct slob_page *sp;
72354 + const slob_t *free;
72355 + const void *base;
72356 + unsigned long flags;
72357 + const char *type;
72358 +
72359 + if (!n)
72360 + return;
72361 +
72362 + type = "<null>";
72363 + if (ZERO_OR_NULL_PTR(ptr))
72364 + goto report;
72365 +
72366 + if (!virt_addr_valid(ptr))
72367 + return;
72368 +
72369 + type = "<process stack>";
72370 + sp = slob_page(ptr);
72371 + if (!PageSlab((struct page *)sp)) {
72372 + if (object_is_on_stack(ptr, n) == -1)
72373 + goto report;
72374 + return;
72375 + }
72376 +
72377 + type = "<slob>";
72378 + if (sp->size) {
72379 + base = page_address(&sp->page);
72380 + if (base <= ptr && n <= sp->size - (ptr - base))
72381 + return;
72382 + goto report;
72383 + }
72384 +
72385 + /* some tricky double walking to find the chunk */
72386 + spin_lock_irqsave(&slob_lock, flags);
72387 + base = (void *)((unsigned long)ptr & PAGE_MASK);
72388 + free = sp->free;
72389 +
72390 + while (!slob_last(free) && (void *)free <= ptr) {
72391 + base = free + slob_units(free);
72392 + free = slob_next(free);
72393 + }
72394 +
72395 + while (base < (void *)free) {
72396 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
72397 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
72398 + int offset;
72399 +
72400 + if (ptr < base + align)
72401 + break;
72402 +
72403 + offset = ptr - base - align;
72404 + if (offset >= m) {
72405 + base += size;
72406 + continue;
72407 + }
72408 +
72409 + if (n > m - offset)
72410 + break;
72411 +
72412 + spin_unlock_irqrestore(&slob_lock, flags);
72413 + return;
72414 + }
72415 +
72416 + spin_unlock_irqrestore(&slob_lock, flags);
72417 +report:
72418 + pax_report_usercopy(ptr, n, to, type);
72419 +#endif
72420 +
72421 +}
72422 +EXPORT_SYMBOL(check_object_size);
72423 +
72424 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
72425 size_t ksize(const void *block)
72426 {
72427 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
72428 sp = slob_page(block);
72429 if (is_slob_page(sp)) {
72430 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72431 - unsigned int *m = (unsigned int *)(block - align);
72432 - return SLOB_UNITS(*m) * SLOB_UNIT;
72433 + slob_t *m = (slob_t *)(block - align);
72434 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
72435 } else
72436 - return sp->page.private;
72437 + return sp->size;
72438 }
72439 EXPORT_SYMBOL(ksize);
72440
72441 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72442 {
72443 struct kmem_cache *c;
72444
72445 +#ifdef CONFIG_PAX_USERCOPY
72446 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
72447 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
72448 +#else
72449 c = slob_alloc(sizeof(struct kmem_cache),
72450 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
72451 +#endif
72452
72453 if (c) {
72454 c->name = name;
72455 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
72456
72457 lockdep_trace_alloc(flags);
72458
72459 +#ifdef CONFIG_PAX_USERCOPY
72460 + b = __kmalloc_node_align(c->size, flags, node, c->align);
72461 +#else
72462 if (c->size < PAGE_SIZE) {
72463 b = slob_alloc(c->size, flags, c->align, node);
72464 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72465 SLOB_UNITS(c->size) * SLOB_UNIT,
72466 flags, node);
72467 } else {
72468 + struct slob_page *sp;
72469 +
72470 b = slob_new_pages(flags, get_order(c->size), node);
72471 + sp = slob_page(b);
72472 + sp->size = c->size;
72473 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72474 PAGE_SIZE << get_order(c->size),
72475 flags, node);
72476 }
72477 +#endif
72478
72479 if (c->ctor)
72480 c->ctor(b);
72481 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
72482
72483 static void __kmem_cache_free(void *b, int size)
72484 {
72485 - if (size < PAGE_SIZE)
72486 + struct slob_page *sp = slob_page(b);
72487 +
72488 + if (is_slob_page(sp))
72489 slob_free(b, size);
72490 - else
72491 + else {
72492 + clear_slob_page(sp);
72493 + free_slob_page(sp);
72494 + sp->size = 0;
72495 slob_free_pages(b, get_order(size));
72496 + }
72497 }
72498
72499 static void kmem_rcu_free(struct rcu_head *head)
72500 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
72501
72502 void kmem_cache_free(struct kmem_cache *c, void *b)
72503 {
72504 + int size = c->size;
72505 +
72506 +#ifdef CONFIG_PAX_USERCOPY
72507 + if (size + c->align < PAGE_SIZE) {
72508 + size += c->align;
72509 + b -= c->align;
72510 + }
72511 +#endif
72512 +
72513 kmemleak_free_recursive(b, c->flags);
72514 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
72515 struct slob_rcu *slob_rcu;
72516 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
72517 - slob_rcu->size = c->size;
72518 + slob_rcu = b + (size - sizeof(struct slob_rcu));
72519 + slob_rcu->size = size;
72520 call_rcu(&slob_rcu->head, kmem_rcu_free);
72521 } else {
72522 - __kmem_cache_free(b, c->size);
72523 + __kmem_cache_free(b, size);
72524 }
72525
72526 +#ifdef CONFIG_PAX_USERCOPY
72527 + trace_kfree(_RET_IP_, b);
72528 +#else
72529 trace_kmem_cache_free(_RET_IP_, b);
72530 +#endif
72531 +
72532 }
72533 EXPORT_SYMBOL(kmem_cache_free);
72534
72535 diff --git a/mm/slub.c b/mm/slub.c
72536 index 0342a5d..8180ae9 100644
72537 --- a/mm/slub.c
72538 +++ b/mm/slub.c
72539 @@ -208,7 +208,7 @@ struct track {
72540
72541 enum track_item { TRACK_ALLOC, TRACK_FREE };
72542
72543 -#ifdef CONFIG_SYSFS
72544 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72545 static int sysfs_slab_add(struct kmem_cache *);
72546 static int sysfs_slab_alias(struct kmem_cache *, const char *);
72547 static void sysfs_slab_remove(struct kmem_cache *);
72548 @@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
72549 if (!t->addr)
72550 return;
72551
72552 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
72553 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
72554 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
72555 #ifdef CONFIG_STACKTRACE
72556 {
72557 @@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
72558
72559 page = virt_to_head_page(x);
72560
72561 + BUG_ON(!PageSlab(page));
72562 +
72563 slab_free(s, page, x, _RET_IP_);
72564
72565 trace_kmem_cache_free(_RET_IP_, x);
72566 @@ -2604,7 +2606,7 @@ static int slub_min_objects;
72567 * Merge control. If this is set then no merging of slab caches will occur.
72568 * (Could be removed. This was introduced to pacify the merge skeptics.)
72569 */
72570 -static int slub_nomerge;
72571 +static int slub_nomerge = 1;
72572
72573 /*
72574 * Calculate the order of allocation given an slab object size.
72575 @@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
72576 else
72577 s->cpu_partial = 30;
72578
72579 - s->refcount = 1;
72580 + atomic_set(&s->refcount, 1);
72581 #ifdef CONFIG_NUMA
72582 s->remote_node_defrag_ratio = 1000;
72583 #endif
72584 @@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
72585 void kmem_cache_destroy(struct kmem_cache *s)
72586 {
72587 down_write(&slub_lock);
72588 - s->refcount--;
72589 - if (!s->refcount) {
72590 + if (atomic_dec_and_test(&s->refcount)) {
72591 list_del(&s->list);
72592 up_write(&slub_lock);
72593 if (kmem_cache_close(s)) {
72594 @@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
72595 EXPORT_SYMBOL(__kmalloc_node);
72596 #endif
72597
72598 +void check_object_size(const void *ptr, unsigned long n, bool to)
72599 +{
72600 +
72601 +#ifdef CONFIG_PAX_USERCOPY
72602 + struct page *page;
72603 + struct kmem_cache *s = NULL;
72604 + unsigned long offset;
72605 + const char *type;
72606 +
72607 + if (!n)
72608 + return;
72609 +
72610 + type = "<null>";
72611 + if (ZERO_OR_NULL_PTR(ptr))
72612 + goto report;
72613 +
72614 + if (!virt_addr_valid(ptr))
72615 + return;
72616 +
72617 + page = virt_to_head_page(ptr);
72618 +
72619 + type = "<process stack>";
72620 + if (!PageSlab(page)) {
72621 + if (object_is_on_stack(ptr, n) == -1)
72622 + goto report;
72623 + return;
72624 + }
72625 +
72626 + s = page->slab;
72627 + type = s->name;
72628 + if (!(s->flags & SLAB_USERCOPY))
72629 + goto report;
72630 +
72631 + offset = (ptr - page_address(page)) % s->size;
72632 + if (offset <= s->objsize && n <= s->objsize - offset)
72633 + return;
72634 +
72635 +report:
72636 + pax_report_usercopy(ptr, n, to, type);
72637 +#endif
72638 +
72639 +}
72640 +EXPORT_SYMBOL(check_object_size);
72641 +
72642 size_t ksize(const void *object)
72643 {
72644 struct page *page;
72645 @@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
72646 int node;
72647
72648 list_add(&s->list, &slab_caches);
72649 - s->refcount = -1;
72650 + atomic_set(&s->refcount, -1);
72651
72652 for_each_node_state(node, N_NORMAL_MEMORY) {
72653 struct kmem_cache_node *n = get_node(s, node);
72654 @@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
72655
72656 /* Caches that are not of the two-to-the-power-of size */
72657 if (KMALLOC_MIN_SIZE <= 32) {
72658 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
72659 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
72660 caches++;
72661 }
72662
72663 if (KMALLOC_MIN_SIZE <= 64) {
72664 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
72665 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
72666 caches++;
72667 }
72668
72669 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
72670 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
72671 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
72672 caches++;
72673 }
72674
72675 @@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
72676 /*
72677 * We may have set a slab to be unmergeable during bootstrap.
72678 */
72679 - if (s->refcount < 0)
72680 + if (atomic_read(&s->refcount) < 0)
72681 return 1;
72682
72683 return 0;
72684 @@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72685 down_write(&slub_lock);
72686 s = find_mergeable(size, align, flags, name, ctor);
72687 if (s) {
72688 - s->refcount++;
72689 + atomic_inc(&s->refcount);
72690 /*
72691 * Adjust the object sizes so that we clear
72692 * the complete object on kzalloc.
72693 @@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72694 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
72695
72696 if (sysfs_slab_alias(s, name)) {
72697 - s->refcount--;
72698 + atomic_dec(&s->refcount);
72699 goto err;
72700 }
72701 up_write(&slub_lock);
72702 @@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
72703 }
72704 #endif
72705
72706 -#ifdef CONFIG_SYSFS
72707 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72708 static int count_inuse(struct page *page)
72709 {
72710 return page->inuse;
72711 @@ -4429,12 +4474,12 @@ static void resiliency_test(void)
72712 validate_slab_cache(kmalloc_caches[9]);
72713 }
72714 #else
72715 -#ifdef CONFIG_SYSFS
72716 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72717 static void resiliency_test(void) {};
72718 #endif
72719 #endif
72720
72721 -#ifdef CONFIG_SYSFS
72722 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72723 enum slab_stat_type {
72724 SL_ALL, /* All slabs */
72725 SL_PARTIAL, /* Only partially allocated slabs */
72726 @@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
72727
72728 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
72729 {
72730 - return sprintf(buf, "%d\n", s->refcount - 1);
72731 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
72732 }
72733 SLAB_ATTR_RO(aliases);
72734
72735 @@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
72736 return name;
72737 }
72738
72739 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72740 static int sysfs_slab_add(struct kmem_cache *s)
72741 {
72742 int err;
72743 @@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
72744 kobject_del(&s->kobj);
72745 kobject_put(&s->kobj);
72746 }
72747 +#endif
72748
72749 /*
72750 * Need to buffer aliases during bootup until sysfs becomes
72751 @@ -5319,6 +5366,7 @@ struct saved_alias {
72752
72753 static struct saved_alias *alias_list;
72754
72755 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72756 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
72757 {
72758 struct saved_alias *al;
72759 @@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
72760 alias_list = al;
72761 return 0;
72762 }
72763 +#endif
72764
72765 static int __init slab_sysfs_init(void)
72766 {
72767 diff --git a/mm/swap.c b/mm/swap.c
72768 index 14380e9..e244704 100644
72769 --- a/mm/swap.c
72770 +++ b/mm/swap.c
72771 @@ -30,6 +30,7 @@
72772 #include <linux/backing-dev.h>
72773 #include <linux/memcontrol.h>
72774 #include <linux/gfp.h>
72775 +#include <linux/hugetlb.h>
72776
72777 #include "internal.h"
72778
72779 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
72780
72781 __page_cache_release(page);
72782 dtor = get_compound_page_dtor(page);
72783 + if (!PageHuge(page))
72784 + BUG_ON(dtor != free_compound_page);
72785 (*dtor)(page);
72786 }
72787
72788 diff --git a/mm/swapfile.c b/mm/swapfile.c
72789 index f31b29d..8bdcae2 100644
72790 --- a/mm/swapfile.c
72791 +++ b/mm/swapfile.c
72792 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
72793
72794 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
72795 /* Activity counter to indicate that a swapon or swapoff has occurred */
72796 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
72797 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
72798
72799 static inline unsigned char swap_count(unsigned char ent)
72800 {
72801 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
72802 }
72803 filp_close(swap_file, NULL);
72804 err = 0;
72805 - atomic_inc(&proc_poll_event);
72806 + atomic_inc_unchecked(&proc_poll_event);
72807 wake_up_interruptible(&proc_poll_wait);
72808
72809 out_dput:
72810 @@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
72811
72812 poll_wait(file, &proc_poll_wait, wait);
72813
72814 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
72815 - seq->poll_event = atomic_read(&proc_poll_event);
72816 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
72817 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
72818 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
72819 }
72820
72821 @@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
72822 return ret;
72823
72824 seq = file->private_data;
72825 - seq->poll_event = atomic_read(&proc_poll_event);
72826 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
72827 return 0;
72828 }
72829
72830 @@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
72831 (p->flags & SWP_DISCARDABLE) ? "D" : "");
72832
72833 mutex_unlock(&swapon_mutex);
72834 - atomic_inc(&proc_poll_event);
72835 + atomic_inc_unchecked(&proc_poll_event);
72836 wake_up_interruptible(&proc_poll_wait);
72837
72838 if (S_ISREG(inode->i_mode))
72839 diff --git a/mm/util.c b/mm/util.c
72840 index 136ac4f..5117eef 100644
72841 --- a/mm/util.c
72842 +++ b/mm/util.c
72843 @@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
72844 * allocated buffer. Use this if you don't want to free the buffer immediately
72845 * like, for example, with RCU.
72846 */
72847 +#undef __krealloc
72848 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
72849 {
72850 void *ret;
72851 @@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
72852 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
72853 * %NULL pointer, the object pointed to is freed.
72854 */
72855 +#undef krealloc
72856 void *krealloc(const void *p, size_t new_size, gfp_t flags)
72857 {
72858 void *ret;
72859 @@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
72860 void arch_pick_mmap_layout(struct mm_struct *mm)
72861 {
72862 mm->mmap_base = TASK_UNMAPPED_BASE;
72863 +
72864 +#ifdef CONFIG_PAX_RANDMMAP
72865 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72866 + mm->mmap_base += mm->delta_mmap;
72867 +#endif
72868 +
72869 mm->get_unmapped_area = arch_get_unmapped_area;
72870 mm->unmap_area = arch_unmap_area;
72871 }
72872 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
72873 index 86ce9a5..0fa4d89 100644
72874 --- a/mm/vmalloc.c
72875 +++ b/mm/vmalloc.c
72876 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
72877
72878 pte = pte_offset_kernel(pmd, addr);
72879 do {
72880 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
72881 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
72882 +
72883 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
72884 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
72885 + BUG_ON(!pte_exec(*pte));
72886 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
72887 + continue;
72888 + }
72889 +#endif
72890 +
72891 + {
72892 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
72893 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
72894 + }
72895 } while (pte++, addr += PAGE_SIZE, addr != end);
72896 }
72897
72898 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
72899 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
72900 {
72901 pte_t *pte;
72902 + int ret = -ENOMEM;
72903
72904 /*
72905 * nr is a running index into the array which helps higher level
72906 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
72907 pte = pte_alloc_kernel(pmd, addr);
72908 if (!pte)
72909 return -ENOMEM;
72910 +
72911 + pax_open_kernel();
72912 do {
72913 struct page *page = pages[*nr];
72914
72915 - if (WARN_ON(!pte_none(*pte)))
72916 - return -EBUSY;
72917 - if (WARN_ON(!page))
72918 - return -ENOMEM;
72919 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
72920 + if (pgprot_val(prot) & _PAGE_NX)
72921 +#endif
72922 +
72923 + if (WARN_ON(!pte_none(*pte))) {
72924 + ret = -EBUSY;
72925 + goto out;
72926 + }
72927 + if (WARN_ON(!page)) {
72928 + ret = -ENOMEM;
72929 + goto out;
72930 + }
72931 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
72932 (*nr)++;
72933 } while (pte++, addr += PAGE_SIZE, addr != end);
72934 - return 0;
72935 + ret = 0;
72936 +out:
72937 + pax_close_kernel();
72938 + return ret;
72939 }
72940
72941 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
72942 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
72943 * and fall back on vmalloc() if that fails. Others
72944 * just put it in the vmalloc space.
72945 */
72946 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
72947 +#ifdef CONFIG_MODULES
72948 +#ifdef MODULES_VADDR
72949 unsigned long addr = (unsigned long)x;
72950 if (addr >= MODULES_VADDR && addr < MODULES_END)
72951 return 1;
72952 #endif
72953 +
72954 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
72955 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
72956 + return 1;
72957 +#endif
72958 +
72959 +#endif
72960 +
72961 return is_vmalloc_addr(x);
72962 }
72963
72964 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
72965
72966 if (!pgd_none(*pgd)) {
72967 pud_t *pud = pud_offset(pgd, addr);
72968 +#ifdef CONFIG_X86
72969 + if (!pud_large(*pud))
72970 +#endif
72971 if (!pud_none(*pud)) {
72972 pmd_t *pmd = pmd_offset(pud, addr);
72973 +#ifdef CONFIG_X86
72974 + if (!pmd_large(*pmd))
72975 +#endif
72976 if (!pmd_none(*pmd)) {
72977 pte_t *ptep, pte;
72978
72979 @@ -1319,6 +1359,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
72980 struct vm_struct *area;
72981
72982 BUG_ON(in_interrupt());
72983 +
72984 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72985 + if (flags & VM_KERNEXEC) {
72986 + if (start != VMALLOC_START || end != VMALLOC_END)
72987 + return NULL;
72988 + start = (unsigned long)MODULES_EXEC_VADDR;
72989 + end = (unsigned long)MODULES_EXEC_END;
72990 + }
72991 +#endif
72992 +
72993 if (flags & VM_IOREMAP) {
72994 int bit = fls(size);
72995
72996 @@ -1551,6 +1601,11 @@ void *vmap(struct page **pages, unsigned int count,
72997 if (count > totalram_pages)
72998 return NULL;
72999
73000 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73001 + if (!(pgprot_val(prot) & _PAGE_NX))
73002 + flags |= VM_KERNEXEC;
73003 +#endif
73004 +
73005 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
73006 __builtin_return_address(0));
73007 if (!area)
73008 @@ -1652,6 +1707,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
73009 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
73010 goto fail;
73011
73012 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73013 + if (!(pgprot_val(prot) & _PAGE_NX))
73014 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
73015 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
73016 + else
73017 +#endif
73018 +
73019 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
73020 start, end, node, gfp_mask, caller);
73021 if (!area)
73022 @@ -1704,6 +1766,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
73023 gfp_mask, prot, node, caller);
73024 }
73025
73026 +#undef __vmalloc
73027 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
73028 {
73029 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
73030 @@ -1727,6 +1790,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
73031 * For tight control over page level allocator and protection flags
73032 * use __vmalloc() instead.
73033 */
73034 +#undef vmalloc
73035 void *vmalloc(unsigned long size)
73036 {
73037 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
73038 @@ -1743,6 +1807,7 @@ EXPORT_SYMBOL(vmalloc);
73039 * For tight control over page level allocator and protection flags
73040 * use __vmalloc() instead.
73041 */
73042 +#undef vzalloc
73043 void *vzalloc(unsigned long size)
73044 {
73045 return __vmalloc_node_flags(size, -1,
73046 @@ -1757,6 +1822,7 @@ EXPORT_SYMBOL(vzalloc);
73047 * The resulting memory area is zeroed so it can be mapped to userspace
73048 * without leaking data.
73049 */
73050 +#undef vmalloc_user
73051 void *vmalloc_user(unsigned long size)
73052 {
73053 struct vm_struct *area;
73054 @@ -1784,6 +1850,7 @@ EXPORT_SYMBOL(vmalloc_user);
73055 * For tight control over page level allocator and protection flags
73056 * use __vmalloc() instead.
73057 */
73058 +#undef vmalloc_node
73059 void *vmalloc_node(unsigned long size, int node)
73060 {
73061 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
73062 @@ -1803,6 +1870,7 @@ EXPORT_SYMBOL(vmalloc_node);
73063 * For tight control over page level allocator and protection flags
73064 * use __vmalloc_node() instead.
73065 */
73066 +#undef vzalloc_node
73067 void *vzalloc_node(unsigned long size, int node)
73068 {
73069 return __vmalloc_node_flags(size, node,
73070 @@ -1825,10 +1893,10 @@ EXPORT_SYMBOL(vzalloc_node);
73071 * For tight control over page level allocator and protection flags
73072 * use __vmalloc() instead.
73073 */
73074 -
73075 +#undef vmalloc_exec
73076 void *vmalloc_exec(unsigned long size)
73077 {
73078 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
73079 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
73080 -1, __builtin_return_address(0));
73081 }
73082
73083 @@ -1847,6 +1915,7 @@ void *vmalloc_exec(unsigned long size)
73084 * Allocate enough 32bit PA addressable pages to cover @size from the
73085 * page level allocator and map them into contiguous kernel virtual space.
73086 */
73087 +#undef vmalloc_32
73088 void *vmalloc_32(unsigned long size)
73089 {
73090 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
73091 @@ -1861,6 +1930,7 @@ EXPORT_SYMBOL(vmalloc_32);
73092 * The resulting memory area is 32bit addressable and zeroed so it can be
73093 * mapped to userspace without leaking data.
73094 */
73095 +#undef vmalloc_32_user
73096 void *vmalloc_32_user(unsigned long size)
73097 {
73098 struct vm_struct *area;
73099 @@ -2123,6 +2193,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
73100 unsigned long uaddr = vma->vm_start;
73101 unsigned long usize = vma->vm_end - vma->vm_start;
73102
73103 + BUG_ON(vma->vm_mirror);
73104 +
73105 if ((PAGE_SIZE-1) & (unsigned long)addr)
73106 return -EINVAL;
73107
73108 diff --git a/mm/vmstat.c b/mm/vmstat.c
73109 index f600557..1459fc8 100644
73110 --- a/mm/vmstat.c
73111 +++ b/mm/vmstat.c
73112 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
73113 *
73114 * vm_stat contains the global counters
73115 */
73116 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73117 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73118 EXPORT_SYMBOL(vm_stat);
73119
73120 #ifdef CONFIG_SMP
73121 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
73122 v = p->vm_stat_diff[i];
73123 p->vm_stat_diff[i] = 0;
73124 local_irq_restore(flags);
73125 - atomic_long_add(v, &zone->vm_stat[i]);
73126 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
73127 global_diff[i] += v;
73128 #ifdef CONFIG_NUMA
73129 /* 3 seconds idle till flush */
73130 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
73131
73132 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
73133 if (global_diff[i])
73134 - atomic_long_add(global_diff[i], &vm_stat[i]);
73135 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
73136 }
73137
73138 #endif
73139 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
73140 start_cpu_timer(cpu);
73141 #endif
73142 #ifdef CONFIG_PROC_FS
73143 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
73144 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
73145 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
73146 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
73147 + {
73148 + mode_t gr_mode = S_IRUGO;
73149 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73150 + gr_mode = S_IRUSR;
73151 +#endif
73152 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
73153 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
73154 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73155 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
73156 +#else
73157 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
73158 +#endif
73159 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
73160 + }
73161 #endif
73162 return 0;
73163 }
73164 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
73165 index efea35b..9c8dd0b 100644
73166 --- a/net/8021q/vlan.c
73167 +++ b/net/8021q/vlan.c
73168 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
73169 err = -EPERM;
73170 if (!capable(CAP_NET_ADMIN))
73171 break;
73172 - if ((args.u.name_type >= 0) &&
73173 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
73174 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
73175 struct vlan_net *vn;
73176
73177 vn = net_generic(net, vlan_net_id);
73178 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
73179 index fccae26..e7ece2f 100644
73180 --- a/net/9p/trans_fd.c
73181 +++ b/net/9p/trans_fd.c
73182 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
73183 oldfs = get_fs();
73184 set_fs(get_ds());
73185 /* The cast to a user pointer is valid due to the set_fs() */
73186 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
73187 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
73188 set_fs(oldfs);
73189
73190 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
73191 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
73192 index 876fbe8..8bbea9f 100644
73193 --- a/net/atm/atm_misc.c
73194 +++ b/net/atm/atm_misc.c
73195 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
73196 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
73197 return 1;
73198 atm_return(vcc, truesize);
73199 - atomic_inc(&vcc->stats->rx_drop);
73200 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73201 return 0;
73202 }
73203 EXPORT_SYMBOL(atm_charge);
73204 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
73205 }
73206 }
73207 atm_return(vcc, guess);
73208 - atomic_inc(&vcc->stats->rx_drop);
73209 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73210 return NULL;
73211 }
73212 EXPORT_SYMBOL(atm_alloc_charge);
73213 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
73214
73215 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73216 {
73217 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73218 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73219 __SONET_ITEMS
73220 #undef __HANDLE_ITEM
73221 }
73222 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
73223
73224 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73225 {
73226 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73227 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
73228 __SONET_ITEMS
73229 #undef __HANDLE_ITEM
73230 }
73231 diff --git a/net/atm/lec.h b/net/atm/lec.h
73232 index dfc0719..47c5322 100644
73233 --- a/net/atm/lec.h
73234 +++ b/net/atm/lec.h
73235 @@ -48,7 +48,7 @@ struct lane2_ops {
73236 const u8 *tlvs, u32 sizeoftlvs);
73237 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
73238 const u8 *tlvs, u32 sizeoftlvs);
73239 -};
73240 +} __no_const;
73241
73242 /*
73243 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
73244 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
73245 index 0919a88..a23d54e 100644
73246 --- a/net/atm/mpc.h
73247 +++ b/net/atm/mpc.h
73248 @@ -33,7 +33,7 @@ struct mpoa_client {
73249 struct mpc_parameters parameters; /* parameters for this client */
73250
73251 const struct net_device_ops *old_ops;
73252 - struct net_device_ops new_ops;
73253 + net_device_ops_no_const new_ops;
73254 };
73255
73256
73257 diff --git a/net/atm/proc.c b/net/atm/proc.c
73258 index 0d020de..011c7bb 100644
73259 --- a/net/atm/proc.c
73260 +++ b/net/atm/proc.c
73261 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
73262 const struct k_atm_aal_stats *stats)
73263 {
73264 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
73265 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
73266 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
73267 - atomic_read(&stats->rx_drop));
73268 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
73269 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
73270 + atomic_read_unchecked(&stats->rx_drop));
73271 }
73272
73273 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
73274 diff --git a/net/atm/resources.c b/net/atm/resources.c
73275 index 23f45ce..c748f1a 100644
73276 --- a/net/atm/resources.c
73277 +++ b/net/atm/resources.c
73278 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
73279 static void copy_aal_stats(struct k_atm_aal_stats *from,
73280 struct atm_aal_stats *to)
73281 {
73282 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73283 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73284 __AAL_STAT_ITEMS
73285 #undef __HANDLE_ITEM
73286 }
73287 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
73288 static void subtract_aal_stats(struct k_atm_aal_stats *from,
73289 struct atm_aal_stats *to)
73290 {
73291 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73292 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
73293 __AAL_STAT_ITEMS
73294 #undef __HANDLE_ITEM
73295 }
73296 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
73297 index 3512e25..2b33401 100644
73298 --- a/net/batman-adv/bat_iv_ogm.c
73299 +++ b/net/batman-adv/bat_iv_ogm.c
73300 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
73301
73302 /* change sequence number to network order */
73303 batman_ogm_packet->seqno =
73304 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
73305 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
73306
73307 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
73308 batman_ogm_packet->tt_crc = htons((uint16_t)
73309 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
73310 else
73311 batman_ogm_packet->gw_flags = NO_FLAGS;
73312
73313 - atomic_inc(&hard_iface->seqno);
73314 + atomic_inc_unchecked(&hard_iface->seqno);
73315
73316 slide_own_bcast_window(hard_iface);
73317 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
73318 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
73319 return;
73320
73321 /* could be changed by schedule_own_packet() */
73322 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
73323 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
73324
73325 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
73326
73327 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
73328 index 7704df4..beb4e16 100644
73329 --- a/net/batman-adv/hard-interface.c
73330 +++ b/net/batman-adv/hard-interface.c
73331 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
73332 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
73333 dev_add_pack(&hard_iface->batman_adv_ptype);
73334
73335 - atomic_set(&hard_iface->seqno, 1);
73336 - atomic_set(&hard_iface->frag_seqno, 1);
73337 + atomic_set_unchecked(&hard_iface->seqno, 1);
73338 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
73339 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
73340 hard_iface->net_dev->name);
73341
73342 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
73343 index 987c75a..20d6f36 100644
73344 --- a/net/batman-adv/soft-interface.c
73345 +++ b/net/batman-adv/soft-interface.c
73346 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
73347
73348 /* set broadcast sequence number */
73349 bcast_packet->seqno =
73350 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
73351 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
73352
73353 add_bcast_packet_to_list(bat_priv, skb, 1);
73354
73355 @@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
73356 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
73357
73358 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
73359 - atomic_set(&bat_priv->bcast_seqno, 1);
73360 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
73361 atomic_set(&bat_priv->ttvn, 0);
73362 atomic_set(&bat_priv->tt_local_changes, 0);
73363 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
73364 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
73365 index e9eb043..d174eeb 100644
73366 --- a/net/batman-adv/types.h
73367 +++ b/net/batman-adv/types.h
73368 @@ -38,8 +38,8 @@ struct hard_iface {
73369 int16_t if_num;
73370 char if_status;
73371 struct net_device *net_dev;
73372 - atomic_t seqno;
73373 - atomic_t frag_seqno;
73374 + atomic_unchecked_t seqno;
73375 + atomic_unchecked_t frag_seqno;
73376 unsigned char *packet_buff;
73377 int packet_len;
73378 struct kobject *hardif_obj;
73379 @@ -154,7 +154,7 @@ struct bat_priv {
73380 atomic_t orig_interval; /* uint */
73381 atomic_t hop_penalty; /* uint */
73382 atomic_t log_level; /* uint */
73383 - atomic_t bcast_seqno;
73384 + atomic_unchecked_t bcast_seqno;
73385 atomic_t bcast_queue_left;
73386 atomic_t batman_queue_left;
73387 atomic_t ttvn; /* translation table version number */
73388 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
73389 index 07d1c1d..7e9bea9 100644
73390 --- a/net/batman-adv/unicast.c
73391 +++ b/net/batman-adv/unicast.c
73392 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
73393 frag1->flags = UNI_FRAG_HEAD | large_tail;
73394 frag2->flags = large_tail;
73395
73396 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
73397 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
73398 frag1->seqno = htons(seqno - 1);
73399 frag2->seqno = htons(seqno);
73400
73401 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
73402 index 07bc69e..21e76b1 100644
73403 --- a/net/bluetooth/hci_conn.c
73404 +++ b/net/bluetooth/hci_conn.c
73405 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
73406 memset(&cp, 0, sizeof(cp));
73407
73408 cp.handle = cpu_to_le16(conn->handle);
73409 - memcpy(cp.ltk, ltk, sizeof(ltk));
73410 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
73411
73412 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
73413 }
73414 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
73415 index 32d338c..d24bcdb 100644
73416 --- a/net/bluetooth/l2cap_core.c
73417 +++ b/net/bluetooth/l2cap_core.c
73418 @@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
73419 break;
73420
73421 case L2CAP_CONF_RFC:
73422 - if (olen == sizeof(rfc))
73423 - memcpy(&rfc, (void *)val, olen);
73424 + if (olen != sizeof(rfc))
73425 + break;
73426 +
73427 + memcpy(&rfc, (void *)val, olen);
73428
73429 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
73430 rfc.mode != chan->mode)
73431 @@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
73432
73433 switch (type) {
73434 case L2CAP_CONF_RFC:
73435 - if (olen == sizeof(rfc))
73436 - memcpy(&rfc, (void *)val, olen);
73437 + if (olen != sizeof(rfc))
73438 + break;
73439 +
73440 + memcpy(&rfc, (void *)val, olen);
73441 goto done;
73442 }
73443 }
73444 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
73445 index 5fe2ff3..10968b5 100644
73446 --- a/net/bridge/netfilter/ebtables.c
73447 +++ b/net/bridge/netfilter/ebtables.c
73448 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
73449 tmp.valid_hooks = t->table->valid_hooks;
73450 }
73451 mutex_unlock(&ebt_mutex);
73452 - if (copy_to_user(user, &tmp, *len) != 0){
73453 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
73454 BUGPRINT("c2u Didn't work\n");
73455 ret = -EFAULT;
73456 break;
73457 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
73458 index a97d97a..6f679ed 100644
73459 --- a/net/caif/caif_socket.c
73460 +++ b/net/caif/caif_socket.c
73461 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
73462 #ifdef CONFIG_DEBUG_FS
73463 struct debug_fs_counter {
73464 atomic_t caif_nr_socks;
73465 - atomic_t caif_sock_create;
73466 - atomic_t num_connect_req;
73467 - atomic_t num_connect_resp;
73468 - atomic_t num_connect_fail_resp;
73469 - atomic_t num_disconnect;
73470 - atomic_t num_remote_shutdown_ind;
73471 - atomic_t num_tx_flow_off_ind;
73472 - atomic_t num_tx_flow_on_ind;
73473 - atomic_t num_rx_flow_off;
73474 - atomic_t num_rx_flow_on;
73475 + atomic_unchecked_t caif_sock_create;
73476 + atomic_unchecked_t num_connect_req;
73477 + atomic_unchecked_t num_connect_resp;
73478 + atomic_unchecked_t num_connect_fail_resp;
73479 + atomic_unchecked_t num_disconnect;
73480 + atomic_unchecked_t num_remote_shutdown_ind;
73481 + atomic_unchecked_t num_tx_flow_off_ind;
73482 + atomic_unchecked_t num_tx_flow_on_ind;
73483 + atomic_unchecked_t num_rx_flow_off;
73484 + atomic_unchecked_t num_rx_flow_on;
73485 };
73486 static struct debug_fs_counter cnt;
73487 #define dbfs_atomic_inc(v) atomic_inc_return(v)
73488 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
73489 #define dbfs_atomic_dec(v) atomic_dec_return(v)
73490 #else
73491 #define dbfs_atomic_inc(v) 0
73492 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73493 atomic_read(&cf_sk->sk.sk_rmem_alloc),
73494 sk_rcvbuf_lowwater(cf_sk));
73495 set_rx_flow_off(cf_sk);
73496 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
73497 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
73498 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
73499 }
73500
73501 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73502 set_rx_flow_off(cf_sk);
73503 if (net_ratelimit())
73504 pr_debug("sending flow OFF due to rmem_schedule\n");
73505 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
73506 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
73507 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
73508 }
73509 skb->dev = NULL;
73510 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
73511 switch (flow) {
73512 case CAIF_CTRLCMD_FLOW_ON_IND:
73513 /* OK from modem to start sending again */
73514 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
73515 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
73516 set_tx_flow_on(cf_sk);
73517 cf_sk->sk.sk_state_change(&cf_sk->sk);
73518 break;
73519
73520 case CAIF_CTRLCMD_FLOW_OFF_IND:
73521 /* Modem asks us to shut up */
73522 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
73523 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
73524 set_tx_flow_off(cf_sk);
73525 cf_sk->sk.sk_state_change(&cf_sk->sk);
73526 break;
73527 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
73528 /* We're now connected */
73529 caif_client_register_refcnt(&cf_sk->layer,
73530 cfsk_hold, cfsk_put);
73531 - dbfs_atomic_inc(&cnt.num_connect_resp);
73532 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
73533 cf_sk->sk.sk_state = CAIF_CONNECTED;
73534 set_tx_flow_on(cf_sk);
73535 cf_sk->sk.sk_state_change(&cf_sk->sk);
73536 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
73537
73538 case CAIF_CTRLCMD_INIT_FAIL_RSP:
73539 /* Connect request failed */
73540 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
73541 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
73542 cf_sk->sk.sk_err = ECONNREFUSED;
73543 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
73544 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
73545 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
73546
73547 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
73548 /* Modem has closed this connection, or device is down. */
73549 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
73550 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
73551 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
73552 cf_sk->sk.sk_err = ECONNRESET;
73553 set_rx_flow_on(cf_sk);
73554 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
73555 return;
73556
73557 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
73558 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
73559 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
73560 set_rx_flow_on(cf_sk);
73561 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
73562 }
73563 @@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
73564 /*ifindex = id of the interface.*/
73565 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
73566
73567 - dbfs_atomic_inc(&cnt.num_connect_req);
73568 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
73569 cf_sk->layer.receive = caif_sktrecv_cb;
73570
73571 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
73572 @@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
73573 spin_unlock_bh(&sk->sk_receive_queue.lock);
73574 sock->sk = NULL;
73575
73576 - dbfs_atomic_inc(&cnt.num_disconnect);
73577 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
73578
73579 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
73580 if (cf_sk->debugfs_socket_dir != NULL)
73581 @@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
73582 cf_sk->conn_req.protocol = protocol;
73583 /* Increase the number of sockets created. */
73584 dbfs_atomic_inc(&cnt.caif_nr_socks);
73585 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
73586 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
73587 #ifdef CONFIG_DEBUG_FS
73588 if (!IS_ERR(debugfsdir)) {
73589
73590 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
73591 index 5cf5222..6f704ad 100644
73592 --- a/net/caif/cfctrl.c
73593 +++ b/net/caif/cfctrl.c
73594 @@ -9,6 +9,7 @@
73595 #include <linux/stddef.h>
73596 #include <linux/spinlock.h>
73597 #include <linux/slab.h>
73598 +#include <linux/sched.h>
73599 #include <net/caif/caif_layer.h>
73600 #include <net/caif/cfpkt.h>
73601 #include <net/caif/cfctrl.h>
73602 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
73603 memset(&dev_info, 0, sizeof(dev_info));
73604 dev_info.id = 0xff;
73605 cfsrvl_init(&this->serv, 0, &dev_info, false);
73606 - atomic_set(&this->req_seq_no, 1);
73607 - atomic_set(&this->rsp_seq_no, 1);
73608 + atomic_set_unchecked(&this->req_seq_no, 1);
73609 + atomic_set_unchecked(&this->rsp_seq_no, 1);
73610 this->serv.layer.receive = cfctrl_recv;
73611 sprintf(this->serv.layer.name, "ctrl");
73612 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
73613 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
73614 struct cfctrl_request_info *req)
73615 {
73616 spin_lock_bh(&ctrl->info_list_lock);
73617 - atomic_inc(&ctrl->req_seq_no);
73618 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
73619 + atomic_inc_unchecked(&ctrl->req_seq_no);
73620 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
73621 list_add_tail(&req->list, &ctrl->list);
73622 spin_unlock_bh(&ctrl->info_list_lock);
73623 }
73624 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
73625 if (p != first)
73626 pr_warn("Requests are not received in order\n");
73627
73628 - atomic_set(&ctrl->rsp_seq_no,
73629 + atomic_set_unchecked(&ctrl->rsp_seq_no,
73630 p->sequence_no);
73631 list_del(&p->list);
73632 goto out;
73633 diff --git a/net/can/gw.c b/net/can/gw.c
73634 index 3d79b12..8de85fa 100644
73635 --- a/net/can/gw.c
73636 +++ b/net/can/gw.c
73637 @@ -96,7 +96,7 @@ struct cf_mod {
73638 struct {
73639 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
73640 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
73641 - } csumfunc;
73642 + } __no_const csumfunc;
73643 };
73644
73645
73646 diff --git a/net/compat.c b/net/compat.c
73647 index 6def90e..c6992fa 100644
73648 --- a/net/compat.c
73649 +++ b/net/compat.c
73650 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
73651 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
73652 __get_user(kmsg->msg_flags, &umsg->msg_flags))
73653 return -EFAULT;
73654 - kmsg->msg_name = compat_ptr(tmp1);
73655 - kmsg->msg_iov = compat_ptr(tmp2);
73656 - kmsg->msg_control = compat_ptr(tmp3);
73657 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
73658 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
73659 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
73660 return 0;
73661 }
73662
73663 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
73664
73665 if (kern_msg->msg_namelen) {
73666 if (mode == VERIFY_READ) {
73667 - int err = move_addr_to_kernel(kern_msg->msg_name,
73668 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
73669 kern_msg->msg_namelen,
73670 kern_address);
73671 if (err < 0)
73672 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
73673 kern_msg->msg_name = NULL;
73674
73675 tot_len = iov_from_user_compat_to_kern(kern_iov,
73676 - (struct compat_iovec __user *)kern_msg->msg_iov,
73677 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
73678 kern_msg->msg_iovlen);
73679 if (tot_len >= 0)
73680 kern_msg->msg_iov = kern_iov;
73681 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
73682
73683 #define CMSG_COMPAT_FIRSTHDR(msg) \
73684 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
73685 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
73686 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
73687 (struct compat_cmsghdr __user *)NULL)
73688
73689 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
73690 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
73691 (ucmlen) <= (unsigned long) \
73692 ((mhdr)->msg_controllen - \
73693 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
73694 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
73695
73696 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
73697 struct compat_cmsghdr __user *cmsg, int cmsg_len)
73698 {
73699 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
73700 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
73701 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
73702 msg->msg_controllen)
73703 return NULL;
73704 return (struct compat_cmsghdr __user *)ptr;
73705 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
73706 {
73707 struct compat_timeval ctv;
73708 struct compat_timespec cts[3];
73709 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
73710 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
73711 struct compat_cmsghdr cmhdr;
73712 int cmlen;
73713
73714 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
73715
73716 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
73717 {
73718 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
73719 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
73720 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
73721 int fdnum = scm->fp->count;
73722 struct file **fp = scm->fp->fp;
73723 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
73724 return -EFAULT;
73725 old_fs = get_fs();
73726 set_fs(KERNEL_DS);
73727 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
73728 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
73729 set_fs(old_fs);
73730
73731 return err;
73732 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
73733 len = sizeof(ktime);
73734 old_fs = get_fs();
73735 set_fs(KERNEL_DS);
73736 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
73737 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
73738 set_fs(old_fs);
73739
73740 if (!err) {
73741 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
73742 case MCAST_JOIN_GROUP:
73743 case MCAST_LEAVE_GROUP:
73744 {
73745 - struct compat_group_req __user *gr32 = (void *)optval;
73746 + struct compat_group_req __user *gr32 = (void __user *)optval;
73747 struct group_req __user *kgr =
73748 compat_alloc_user_space(sizeof(struct group_req));
73749 u32 interface;
73750 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
73751 case MCAST_BLOCK_SOURCE:
73752 case MCAST_UNBLOCK_SOURCE:
73753 {
73754 - struct compat_group_source_req __user *gsr32 = (void *)optval;
73755 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
73756 struct group_source_req __user *kgsr = compat_alloc_user_space(
73757 sizeof(struct group_source_req));
73758 u32 interface;
73759 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
73760 }
73761 case MCAST_MSFILTER:
73762 {
73763 - struct compat_group_filter __user *gf32 = (void *)optval;
73764 + struct compat_group_filter __user *gf32 = (void __user *)optval;
73765 struct group_filter __user *kgf;
73766 u32 interface, fmode, numsrc;
73767
73768 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
73769 char __user *optval, int __user *optlen,
73770 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
73771 {
73772 - struct compat_group_filter __user *gf32 = (void *)optval;
73773 + struct compat_group_filter __user *gf32 = (void __user *)optval;
73774 struct group_filter __user *kgf;
73775 int __user *koptlen;
73776 u32 interface, fmode, numsrc;
73777 diff --git a/net/core/datagram.c b/net/core/datagram.c
73778 index 68bbf9f..5ef0d12 100644
73779 --- a/net/core/datagram.c
73780 +++ b/net/core/datagram.c
73781 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
73782 }
73783
73784 kfree_skb(skb);
73785 - atomic_inc(&sk->sk_drops);
73786 + atomic_inc_unchecked(&sk->sk_drops);
73787 sk_mem_reclaim_partial(sk);
73788
73789 return err;
73790 diff --git a/net/core/dev.c b/net/core/dev.c
73791 index a4bf943..9c83051 100644
73792 --- a/net/core/dev.c
73793 +++ b/net/core/dev.c
73794 @@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
73795 if (no_module && capable(CAP_NET_ADMIN))
73796 no_module = request_module("netdev-%s", name);
73797 if (no_module && capable(CAP_SYS_MODULE)) {
73798 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
73799 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
73800 +#else
73801 if (!request_module("%s", name))
73802 pr_err("Loading kernel module for a network device "
73803 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
73804 "instead\n", name);
73805 +#endif
73806 }
73807 }
73808 EXPORT_SYMBOL(dev_load);
73809 @@ -1585,7 +1589,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
73810 {
73811 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
73812 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
73813 - atomic_long_inc(&dev->rx_dropped);
73814 + atomic_long_inc_unchecked(&dev->rx_dropped);
73815 kfree_skb(skb);
73816 return NET_RX_DROP;
73817 }
73818 @@ -1595,7 +1599,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
73819 nf_reset(skb);
73820
73821 if (unlikely(!is_skb_forwardable(dev, skb))) {
73822 - atomic_long_inc(&dev->rx_dropped);
73823 + atomic_long_inc_unchecked(&dev->rx_dropped);
73824 kfree_skb(skb);
73825 return NET_RX_DROP;
73826 }
73827 @@ -2057,7 +2061,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
73828
73829 struct dev_gso_cb {
73830 void (*destructor)(struct sk_buff *skb);
73831 -};
73832 +} __no_const;
73833
73834 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
73835
73836 @@ -2913,7 +2917,7 @@ enqueue:
73837
73838 local_irq_restore(flags);
73839
73840 - atomic_long_inc(&skb->dev->rx_dropped);
73841 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
73842 kfree_skb(skb);
73843 return NET_RX_DROP;
73844 }
73845 @@ -2985,7 +2989,7 @@ int netif_rx_ni(struct sk_buff *skb)
73846 }
73847 EXPORT_SYMBOL(netif_rx_ni);
73848
73849 -static void net_tx_action(struct softirq_action *h)
73850 +static void net_tx_action(void)
73851 {
73852 struct softnet_data *sd = &__get_cpu_var(softnet_data);
73853
73854 @@ -3273,7 +3277,7 @@ ncls:
73855 if (pt_prev) {
73856 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
73857 } else {
73858 - atomic_long_inc(&skb->dev->rx_dropped);
73859 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
73860 kfree_skb(skb);
73861 /* Jamal, now you will not able to escape explaining
73862 * me how you were going to use this. :-)
73863 @@ -3833,7 +3837,7 @@ void netif_napi_del(struct napi_struct *napi)
73864 }
73865 EXPORT_SYMBOL(netif_napi_del);
73866
73867 -static void net_rx_action(struct softirq_action *h)
73868 +static void net_rx_action(void)
73869 {
73870 struct softnet_data *sd = &__get_cpu_var(softnet_data);
73871 unsigned long time_limit = jiffies + 2;
73872 @@ -5890,7 +5894,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
73873 } else {
73874 netdev_stats_to_stats64(storage, &dev->stats);
73875 }
73876 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
73877 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
73878 return storage;
73879 }
73880 EXPORT_SYMBOL(dev_get_stats);
73881 diff --git a/net/core/flow.c b/net/core/flow.c
73882 index e318c7e..168b1d0 100644
73883 --- a/net/core/flow.c
73884 +++ b/net/core/flow.c
73885 @@ -61,7 +61,7 @@ struct flow_cache {
73886 struct timer_list rnd_timer;
73887 };
73888
73889 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
73890 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
73891 EXPORT_SYMBOL(flow_cache_genid);
73892 static struct flow_cache flow_cache_global;
73893 static struct kmem_cache *flow_cachep __read_mostly;
73894 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
73895
73896 static int flow_entry_valid(struct flow_cache_entry *fle)
73897 {
73898 - if (atomic_read(&flow_cache_genid) != fle->genid)
73899 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
73900 return 0;
73901 if (fle->object && !fle->object->ops->check(fle->object))
73902 return 0;
73903 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
73904 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
73905 fcp->hash_count++;
73906 }
73907 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
73908 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
73909 flo = fle->object;
73910 if (!flo)
73911 goto ret_object;
73912 @@ -280,7 +280,7 @@ nocache:
73913 }
73914 flo = resolver(net, key, family, dir, flo, ctx);
73915 if (fle) {
73916 - fle->genid = atomic_read(&flow_cache_genid);
73917 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
73918 if (!IS_ERR(flo))
73919 fle->object = flo;
73920 else
73921 diff --git a/net/core/iovec.c b/net/core/iovec.c
73922 index c40f27e..7f49254 100644
73923 --- a/net/core/iovec.c
73924 +++ b/net/core/iovec.c
73925 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
73926 if (m->msg_namelen) {
73927 if (mode == VERIFY_READ) {
73928 void __user *namep;
73929 - namep = (void __user __force *) m->msg_name;
73930 + namep = (void __force_user *) m->msg_name;
73931 err = move_addr_to_kernel(namep, m->msg_namelen,
73932 address);
73933 if (err < 0)
73934 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
73935 }
73936
73937 size = m->msg_iovlen * sizeof(struct iovec);
73938 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
73939 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
73940 return -EFAULT;
73941
73942 m->msg_iov = iov;
73943 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
73944 index 5c30296..ebe7b61 100644
73945 --- a/net/core/rtnetlink.c
73946 +++ b/net/core/rtnetlink.c
73947 @@ -57,7 +57,7 @@ struct rtnl_link {
73948 rtnl_doit_func doit;
73949 rtnl_dumpit_func dumpit;
73950 rtnl_calcit_func calcit;
73951 -};
73952 +} __no_const;
73953
73954 static DEFINE_MUTEX(rtnl_mutex);
73955
73956 diff --git a/net/core/scm.c b/net/core/scm.c
73957 index ff52ad0..aff1c0f 100644
73958 --- a/net/core/scm.c
73959 +++ b/net/core/scm.c
73960 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
73961 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
73962 {
73963 struct cmsghdr __user *cm
73964 - = (__force struct cmsghdr __user *)msg->msg_control;
73965 + = (struct cmsghdr __force_user *)msg->msg_control;
73966 struct cmsghdr cmhdr;
73967 int cmlen = CMSG_LEN(len);
73968 int err;
73969 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
73970 err = -EFAULT;
73971 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
73972 goto out;
73973 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
73974 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
73975 goto out;
73976 cmlen = CMSG_SPACE(len);
73977 if (msg->msg_controllen < cmlen)
73978 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
73979 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
73980 {
73981 struct cmsghdr __user *cm
73982 - = (__force struct cmsghdr __user*)msg->msg_control;
73983 + = (struct cmsghdr __force_user *)msg->msg_control;
73984
73985 int fdmax = 0;
73986 int fdnum = scm->fp->count;
73987 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
73988 if (fdnum < fdmax)
73989 fdmax = fdnum;
73990
73991 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
73992 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
73993 i++, cmfptr++)
73994 {
73995 int new_fd;
73996 diff --git a/net/core/sock.c b/net/core/sock.c
73997 index 02f8dfe..86dfd4a 100644
73998 --- a/net/core/sock.c
73999 +++ b/net/core/sock.c
74000 @@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74001 struct sk_buff_head *list = &sk->sk_receive_queue;
74002
74003 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
74004 - atomic_inc(&sk->sk_drops);
74005 + atomic_inc_unchecked(&sk->sk_drops);
74006 trace_sock_rcvqueue_full(sk, skb);
74007 return -ENOMEM;
74008 }
74009 @@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74010 return err;
74011
74012 if (!sk_rmem_schedule(sk, skb->truesize)) {
74013 - atomic_inc(&sk->sk_drops);
74014 + atomic_inc_unchecked(&sk->sk_drops);
74015 return -ENOBUFS;
74016 }
74017
74018 @@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74019 skb_dst_force(skb);
74020
74021 spin_lock_irqsave(&list->lock, flags);
74022 - skb->dropcount = atomic_read(&sk->sk_drops);
74023 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74024 __skb_queue_tail(list, skb);
74025 spin_unlock_irqrestore(&list->lock, flags);
74026
74027 @@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74028 skb->dev = NULL;
74029
74030 if (sk_rcvqueues_full(sk, skb)) {
74031 - atomic_inc(&sk->sk_drops);
74032 + atomic_inc_unchecked(&sk->sk_drops);
74033 goto discard_and_relse;
74034 }
74035 if (nested)
74036 @@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74037 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
74038 } else if (sk_add_backlog(sk, skb)) {
74039 bh_unlock_sock(sk);
74040 - atomic_inc(&sk->sk_drops);
74041 + atomic_inc_unchecked(&sk->sk_drops);
74042 goto discard_and_relse;
74043 }
74044
74045 @@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74046 if (len > sizeof(peercred))
74047 len = sizeof(peercred);
74048 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
74049 - if (copy_to_user(optval, &peercred, len))
74050 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
74051 return -EFAULT;
74052 goto lenout;
74053 }
74054 @@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74055 return -ENOTCONN;
74056 if (lv < len)
74057 return -EINVAL;
74058 - if (copy_to_user(optval, address, len))
74059 + if (len > sizeof(address) || copy_to_user(optval, address, len))
74060 return -EFAULT;
74061 goto lenout;
74062 }
74063 @@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74064
74065 if (len > lv)
74066 len = lv;
74067 - if (copy_to_user(optval, &v, len))
74068 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
74069 return -EFAULT;
74070 lenout:
74071 if (put_user(len, optlen))
74072 @@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
74073 */
74074 smp_wmb();
74075 atomic_set(&sk->sk_refcnt, 1);
74076 - atomic_set(&sk->sk_drops, 0);
74077 + atomic_set_unchecked(&sk->sk_drops, 0);
74078 }
74079 EXPORT_SYMBOL(sock_init_data);
74080
74081 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
74082 index b9868e1..849f809 100644
74083 --- a/net/core/sock_diag.c
74084 +++ b/net/core/sock_diag.c
74085 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
74086
74087 int sock_diag_check_cookie(void *sk, __u32 *cookie)
74088 {
74089 +#ifndef CONFIG_GRKERNSEC_HIDESYM
74090 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
74091 cookie[1] != INET_DIAG_NOCOOKIE) &&
74092 ((u32)(unsigned long)sk != cookie[0] ||
74093 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
74094 return -ESTALE;
74095 else
74096 +#endif
74097 return 0;
74098 }
74099 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
74100
74101 void sock_diag_save_cookie(void *sk, __u32 *cookie)
74102 {
74103 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74104 + cookie[0] = 0;
74105 + cookie[1] = 0;
74106 +#else
74107 cookie[0] = (u32)(unsigned long)sk;
74108 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
74109 +#endif
74110 }
74111 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
74112
74113 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
74114 index 02e75d1..9a57a7c 100644
74115 --- a/net/decnet/sysctl_net_decnet.c
74116 +++ b/net/decnet/sysctl_net_decnet.c
74117 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
74118
74119 if (len > *lenp) len = *lenp;
74120
74121 - if (copy_to_user(buffer, addr, len))
74122 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
74123 return -EFAULT;
74124
74125 *lenp = len;
74126 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
74127
74128 if (len > *lenp) len = *lenp;
74129
74130 - if (copy_to_user(buffer, devname, len))
74131 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
74132 return -EFAULT;
74133
74134 *lenp = len;
74135 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
74136 index 39a2d29..f39c0fe 100644
74137 --- a/net/econet/Kconfig
74138 +++ b/net/econet/Kconfig
74139 @@ -4,7 +4,7 @@
74140
74141 config ECONET
74142 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
74143 - depends on EXPERIMENTAL && INET
74144 + depends on EXPERIMENTAL && INET && BROKEN
74145 ---help---
74146 Econet is a fairly old and slow networking protocol mainly used by
74147 Acorn computers to access file and print servers. It uses native
74148 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
74149 index 92fc5f6..b790d91 100644
74150 --- a/net/ipv4/fib_frontend.c
74151 +++ b/net/ipv4/fib_frontend.c
74152 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
74153 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74154 fib_sync_up(dev);
74155 #endif
74156 - atomic_inc(&net->ipv4.dev_addr_genid);
74157 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74158 rt_cache_flush(dev_net(dev), -1);
74159 break;
74160 case NETDEV_DOWN:
74161 fib_del_ifaddr(ifa, NULL);
74162 - atomic_inc(&net->ipv4.dev_addr_genid);
74163 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74164 if (ifa->ifa_dev->ifa_list == NULL) {
74165 /* Last address was deleted from this interface.
74166 * Disable IP.
74167 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
74168 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74169 fib_sync_up(dev);
74170 #endif
74171 - atomic_inc(&net->ipv4.dev_addr_genid);
74172 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74173 rt_cache_flush(dev_net(dev), -1);
74174 break;
74175 case NETDEV_DOWN:
74176 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
74177 index 80106d8..232e898 100644
74178 --- a/net/ipv4/fib_semantics.c
74179 +++ b/net/ipv4/fib_semantics.c
74180 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
74181 nh->nh_saddr = inet_select_addr(nh->nh_dev,
74182 nh->nh_gw,
74183 nh->nh_parent->fib_scope);
74184 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
74185 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
74186
74187 return nh->nh_saddr;
74188 }
74189 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
74190 index 984ec65..97ac518 100644
74191 --- a/net/ipv4/inet_hashtables.c
74192 +++ b/net/ipv4/inet_hashtables.c
74193 @@ -18,12 +18,15 @@
74194 #include <linux/sched.h>
74195 #include <linux/slab.h>
74196 #include <linux/wait.h>
74197 +#include <linux/security.h>
74198
74199 #include <net/inet_connection_sock.h>
74200 #include <net/inet_hashtables.h>
74201 #include <net/secure_seq.h>
74202 #include <net/ip.h>
74203
74204 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
74205 +
74206 /*
74207 * Allocate and initialize a new local port bind bucket.
74208 * The bindhash mutex for snum's hash chain must be held here.
74209 @@ -530,6 +533,8 @@ ok:
74210 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
74211 spin_unlock(&head->lock);
74212
74213 + gr_update_task_in_ip_table(current, inet_sk(sk));
74214 +
74215 if (tw) {
74216 inet_twsk_deschedule(tw, death_row);
74217 while (twrefcnt) {
74218 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
74219 index d4d61b6..b81aec8 100644
74220 --- a/net/ipv4/inetpeer.c
74221 +++ b/net/ipv4/inetpeer.c
74222 @@ -487,8 +487,8 @@ relookup:
74223 if (p) {
74224 p->daddr = *daddr;
74225 atomic_set(&p->refcnt, 1);
74226 - atomic_set(&p->rid, 0);
74227 - atomic_set(&p->ip_id_count,
74228 + atomic_set_unchecked(&p->rid, 0);
74229 + atomic_set_unchecked(&p->ip_id_count,
74230 (daddr->family == AF_INET) ?
74231 secure_ip_id(daddr->addr.a4) :
74232 secure_ipv6_id(daddr->addr.a6));
74233 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
74234 index 1f23a57..7180dfe 100644
74235 --- a/net/ipv4/ip_fragment.c
74236 +++ b/net/ipv4/ip_fragment.c
74237 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
74238 return 0;
74239
74240 start = qp->rid;
74241 - end = atomic_inc_return(&peer->rid);
74242 + end = atomic_inc_return_unchecked(&peer->rid);
74243 qp->rid = end;
74244
74245 rc = qp->q.fragments && (end - start) > max;
74246 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
74247 index 8aa87c1..35c3248 100644
74248 --- a/net/ipv4/ip_sockglue.c
74249 +++ b/net/ipv4/ip_sockglue.c
74250 @@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74251 len = min_t(unsigned int, len, opt->optlen);
74252 if (put_user(len, optlen))
74253 return -EFAULT;
74254 - if (copy_to_user(optval, opt->__data, len))
74255 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
74256 + copy_to_user(optval, opt->__data, len))
74257 return -EFAULT;
74258 return 0;
74259 }
74260 @@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74261 if (sk->sk_type != SOCK_STREAM)
74262 return -ENOPROTOOPT;
74263
74264 - msg.msg_control = optval;
74265 + msg.msg_control = (void __force_kernel *)optval;
74266 msg.msg_controllen = len;
74267 msg.msg_flags = flags;
74268
74269 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
74270 index 6e412a6..6640538 100644
74271 --- a/net/ipv4/ipconfig.c
74272 +++ b/net/ipv4/ipconfig.c
74273 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
74274
74275 mm_segment_t oldfs = get_fs();
74276 set_fs(get_ds());
74277 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74278 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74279 set_fs(oldfs);
74280 return res;
74281 }
74282 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
74283
74284 mm_segment_t oldfs = get_fs();
74285 set_fs(get_ds());
74286 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74287 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74288 set_fs(oldfs);
74289 return res;
74290 }
74291 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
74292
74293 mm_segment_t oldfs = get_fs();
74294 set_fs(get_ds());
74295 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
74296 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
74297 set_fs(oldfs);
74298 return res;
74299 }
74300 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
74301 index 2133c30..5c4b40b 100644
74302 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
74303 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
74304 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
74305
74306 *len = 0;
74307
74308 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
74309 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
74310 if (*octets == NULL)
74311 return 0;
74312
74313 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
74314 index b072386..abdebcf 100644
74315 --- a/net/ipv4/ping.c
74316 +++ b/net/ipv4/ping.c
74317 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
74318 sk_rmem_alloc_get(sp),
74319 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74320 atomic_read(&sp->sk_refcnt), sp,
74321 - atomic_read(&sp->sk_drops), len);
74322 + atomic_read_unchecked(&sp->sk_drops), len);
74323 }
74324
74325 static int ping_seq_show(struct seq_file *seq, void *v)
74326 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
74327 index 3ccda5a..3c1e61d 100644
74328 --- a/net/ipv4/raw.c
74329 +++ b/net/ipv4/raw.c
74330 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
74331 int raw_rcv(struct sock *sk, struct sk_buff *skb)
74332 {
74333 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
74334 - atomic_inc(&sk->sk_drops);
74335 + atomic_inc_unchecked(&sk->sk_drops);
74336 kfree_skb(skb);
74337 return NET_RX_DROP;
74338 }
74339 @@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
74340
74341 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
74342 {
74343 + struct icmp_filter filter;
74344 +
74345 if (optlen > sizeof(struct icmp_filter))
74346 optlen = sizeof(struct icmp_filter);
74347 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
74348 + if (copy_from_user(&filter, optval, optlen))
74349 return -EFAULT;
74350 + raw_sk(sk)->filter = filter;
74351 return 0;
74352 }
74353
74354 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
74355 {
74356 int len, ret = -EFAULT;
74357 + struct icmp_filter filter;
74358
74359 if (get_user(len, optlen))
74360 goto out;
74361 @@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
74362 if (len > sizeof(struct icmp_filter))
74363 len = sizeof(struct icmp_filter);
74364 ret = -EFAULT;
74365 - if (put_user(len, optlen) ||
74366 - copy_to_user(optval, &raw_sk(sk)->filter, len))
74367 + filter = raw_sk(sk)->filter;
74368 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
74369 goto out;
74370 ret = 0;
74371 out: return ret;
74372 @@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74373 sk_wmem_alloc_get(sp),
74374 sk_rmem_alloc_get(sp),
74375 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74376 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74377 + atomic_read(&sp->sk_refcnt),
74378 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74379 + NULL,
74380 +#else
74381 + sp,
74382 +#endif
74383 + atomic_read_unchecked(&sp->sk_drops));
74384 }
74385
74386 static int raw_seq_show(struct seq_file *seq, void *v)
74387 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
74388 index 0197747..7adb0dc 100644
74389 --- a/net/ipv4/route.c
74390 +++ b/net/ipv4/route.c
74391 @@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
74392
74393 static inline int rt_genid(struct net *net)
74394 {
74395 - return atomic_read(&net->ipv4.rt_genid);
74396 + return atomic_read_unchecked(&net->ipv4.rt_genid);
74397 }
74398
74399 #ifdef CONFIG_PROC_FS
74400 @@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
74401 unsigned char shuffle;
74402
74403 get_random_bytes(&shuffle, sizeof(shuffle));
74404 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
74405 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
74406 inetpeer_invalidate_tree(AF_INET);
74407 }
74408
74409 @@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
74410 error = rt->dst.error;
74411 if (peer) {
74412 inet_peer_refcheck(rt->peer);
74413 - id = atomic_read(&peer->ip_id_count) & 0xffff;
74414 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
74415 if (peer->tcp_ts_stamp) {
74416 ts = peer->tcp_ts;
74417 tsage = get_seconds() - peer->tcp_ts_stamp;
74418 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
74419 index fd54c5f..96d6407 100644
74420 --- a/net/ipv4/tcp_ipv4.c
74421 +++ b/net/ipv4/tcp_ipv4.c
74422 @@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
74423 int sysctl_tcp_low_latency __read_mostly;
74424 EXPORT_SYMBOL(sysctl_tcp_low_latency);
74425
74426 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74427 +extern int grsec_enable_blackhole;
74428 +#endif
74429
74430 #ifdef CONFIG_TCP_MD5SIG
74431 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
74432 @@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
74433 return 0;
74434
74435 reset:
74436 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74437 + if (!grsec_enable_blackhole)
74438 +#endif
74439 tcp_v4_send_reset(rsk, skb);
74440 discard:
74441 kfree_skb(skb);
74442 @@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
74443 TCP_SKB_CB(skb)->sacked = 0;
74444
74445 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
74446 - if (!sk)
74447 + if (!sk) {
74448 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74449 + ret = 1;
74450 +#endif
74451 goto no_tcp_socket;
74452 -
74453 + }
74454 process:
74455 - if (sk->sk_state == TCP_TIME_WAIT)
74456 + if (sk->sk_state == TCP_TIME_WAIT) {
74457 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74458 + ret = 2;
74459 +#endif
74460 goto do_time_wait;
74461 + }
74462
74463 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
74464 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
74465 @@ -1755,6 +1768,10 @@ no_tcp_socket:
74466 bad_packet:
74467 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
74468 } else {
74469 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74470 + if (!grsec_enable_blackhole || (ret == 1 &&
74471 + (skb->dev->flags & IFF_LOOPBACK)))
74472 +#endif
74473 tcp_v4_send_reset(NULL, skb);
74474 }
74475
74476 @@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
74477 0, /* non standard timer */
74478 0, /* open_requests have no inode */
74479 atomic_read(&sk->sk_refcnt),
74480 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74481 + NULL,
74482 +#else
74483 req,
74484 +#endif
74485 len);
74486 }
74487
74488 @@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
74489 sock_i_uid(sk),
74490 icsk->icsk_probes_out,
74491 sock_i_ino(sk),
74492 - atomic_read(&sk->sk_refcnt), sk,
74493 + atomic_read(&sk->sk_refcnt),
74494 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74495 + NULL,
74496 +#else
74497 + sk,
74498 +#endif
74499 jiffies_to_clock_t(icsk->icsk_rto),
74500 jiffies_to_clock_t(icsk->icsk_ack.ato),
74501 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
74502 @@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
74503 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
74504 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
74505 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74506 - atomic_read(&tw->tw_refcnt), tw, len);
74507 + atomic_read(&tw->tw_refcnt),
74508 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74509 + NULL,
74510 +#else
74511 + tw,
74512 +#endif
74513 + len);
74514 }
74515
74516 #define TMPSZ 150
74517 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
74518 index 550e755..25721b3 100644
74519 --- a/net/ipv4/tcp_minisocks.c
74520 +++ b/net/ipv4/tcp_minisocks.c
74521 @@ -27,6 +27,10 @@
74522 #include <net/inet_common.h>
74523 #include <net/xfrm.h>
74524
74525 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74526 +extern int grsec_enable_blackhole;
74527 +#endif
74528 +
74529 int sysctl_tcp_syncookies __read_mostly = 1;
74530 EXPORT_SYMBOL(sysctl_tcp_syncookies);
74531
74532 @@ -753,6 +757,10 @@ listen_overflow:
74533
74534 embryonic_reset:
74535 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
74536 +
74537 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74538 + if (!grsec_enable_blackhole)
74539 +#endif
74540 if (!(flg & TCP_FLAG_RST))
74541 req->rsk_ops->send_reset(sk, skb);
74542
74543 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
74544 index 85ee7eb..53277ab 100644
74545 --- a/net/ipv4/tcp_probe.c
74546 +++ b/net/ipv4/tcp_probe.c
74547 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
74548 if (cnt + width >= len)
74549 break;
74550
74551 - if (copy_to_user(buf + cnt, tbuf, width))
74552 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
74553 return -EFAULT;
74554 cnt += width;
74555 }
74556 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
74557 index cd2e072..1fffee2 100644
74558 --- a/net/ipv4/tcp_timer.c
74559 +++ b/net/ipv4/tcp_timer.c
74560 @@ -22,6 +22,10 @@
74561 #include <linux/gfp.h>
74562 #include <net/tcp.h>
74563
74564 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74565 +extern int grsec_lastack_retries;
74566 +#endif
74567 +
74568 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
74569 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
74570 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
74571 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
74572 }
74573 }
74574
74575 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74576 + if ((sk->sk_state == TCP_LAST_ACK) &&
74577 + (grsec_lastack_retries > 0) &&
74578 + (grsec_lastack_retries < retry_until))
74579 + retry_until = grsec_lastack_retries;
74580 +#endif
74581 +
74582 if (retransmits_timed_out(sk, retry_until,
74583 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
74584 /* Has it gone just too far? */
74585 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
74586 index 5d075b5..d907d5f 100644
74587 --- a/net/ipv4/udp.c
74588 +++ b/net/ipv4/udp.c
74589 @@ -86,6 +86,7 @@
74590 #include <linux/types.h>
74591 #include <linux/fcntl.h>
74592 #include <linux/module.h>
74593 +#include <linux/security.h>
74594 #include <linux/socket.h>
74595 #include <linux/sockios.h>
74596 #include <linux/igmp.h>
74597 @@ -108,6 +109,10 @@
74598 #include <trace/events/udp.h>
74599 #include "udp_impl.h"
74600
74601 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74602 +extern int grsec_enable_blackhole;
74603 +#endif
74604 +
74605 struct udp_table udp_table __read_mostly;
74606 EXPORT_SYMBOL(udp_table);
74607
74608 @@ -566,6 +571,9 @@ found:
74609 return s;
74610 }
74611
74612 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
74613 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
74614 +
74615 /*
74616 * This routine is called by the ICMP module when it gets some
74617 * sort of error condition. If err < 0 then the socket should
74618 @@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
74619 dport = usin->sin_port;
74620 if (dport == 0)
74621 return -EINVAL;
74622 +
74623 + err = gr_search_udp_sendmsg(sk, usin);
74624 + if (err)
74625 + return err;
74626 } else {
74627 if (sk->sk_state != TCP_ESTABLISHED)
74628 return -EDESTADDRREQ;
74629 +
74630 + err = gr_search_udp_sendmsg(sk, NULL);
74631 + if (err)
74632 + return err;
74633 +
74634 daddr = inet->inet_daddr;
74635 dport = inet->inet_dport;
74636 /* Open fast path for connected socket.
74637 @@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
74638 udp_lib_checksum_complete(skb)) {
74639 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
74640 IS_UDPLITE(sk));
74641 - atomic_inc(&sk->sk_drops);
74642 + atomic_inc_unchecked(&sk->sk_drops);
74643 __skb_unlink(skb, rcvq);
74644 __skb_queue_tail(&list_kill, skb);
74645 }
74646 @@ -1186,6 +1203,10 @@ try_again:
74647 if (!skb)
74648 goto out;
74649
74650 + err = gr_search_udp_recvmsg(sk, skb);
74651 + if (err)
74652 + goto out_free;
74653 +
74654 ulen = skb->len - sizeof(struct udphdr);
74655 copied = len;
74656 if (copied > ulen)
74657 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74658
74659 drop:
74660 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
74661 - atomic_inc(&sk->sk_drops);
74662 + atomic_inc_unchecked(&sk->sk_drops);
74663 kfree_skb(skb);
74664 return -1;
74665 }
74666 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
74667 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
74668
74669 if (!skb1) {
74670 - atomic_inc(&sk->sk_drops);
74671 + atomic_inc_unchecked(&sk->sk_drops);
74672 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
74673 IS_UDPLITE(sk));
74674 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
74675 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
74676 goto csum_error;
74677
74678 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
74679 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74680 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
74681 +#endif
74682 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
74683
74684 /*
74685 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
74686 sk_wmem_alloc_get(sp),
74687 sk_rmem_alloc_get(sp),
74688 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74689 - atomic_read(&sp->sk_refcnt), sp,
74690 - atomic_read(&sp->sk_drops), len);
74691 + atomic_read(&sp->sk_refcnt),
74692 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74693 + NULL,
74694 +#else
74695 + sp,
74696 +#endif
74697 + atomic_read_unchecked(&sp->sk_drops), len);
74698 }
74699
74700 int udp4_seq_show(struct seq_file *seq, void *v)
74701 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
74702 index 6b8ebc5..1d624f4 100644
74703 --- a/net/ipv6/addrconf.c
74704 +++ b/net/ipv6/addrconf.c
74705 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
74706 p.iph.ihl = 5;
74707 p.iph.protocol = IPPROTO_IPV6;
74708 p.iph.ttl = 64;
74709 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
74710 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
74711
74712 if (ops->ndo_do_ioctl) {
74713 mm_segment_t oldfs = get_fs();
74714 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
74715 index 02dd203..e03fcc9 100644
74716 --- a/net/ipv6/inet6_connection_sock.c
74717 +++ b/net/ipv6/inet6_connection_sock.c
74718 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
74719 #ifdef CONFIG_XFRM
74720 {
74721 struct rt6_info *rt = (struct rt6_info *)dst;
74722 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
74723 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
74724 }
74725 #endif
74726 }
74727 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
74728 #ifdef CONFIG_XFRM
74729 if (dst) {
74730 struct rt6_info *rt = (struct rt6_info *)dst;
74731 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
74732 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
74733 __sk_dst_reset(sk);
74734 dst = NULL;
74735 }
74736 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
74737 index 18a2719..779f36a 100644
74738 --- a/net/ipv6/ipv6_sockglue.c
74739 +++ b/net/ipv6/ipv6_sockglue.c
74740 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
74741 if (sk->sk_type != SOCK_STREAM)
74742 return -ENOPROTOOPT;
74743
74744 - msg.msg_control = optval;
74745 + msg.msg_control = (void __force_kernel *)optval;
74746 msg.msg_controllen = len;
74747 msg.msg_flags = flags;
74748
74749 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
74750 index d02f7e4..2d2a0f1 100644
74751 --- a/net/ipv6/raw.c
74752 +++ b/net/ipv6/raw.c
74753 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
74754 {
74755 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
74756 skb_checksum_complete(skb)) {
74757 - atomic_inc(&sk->sk_drops);
74758 + atomic_inc_unchecked(&sk->sk_drops);
74759 kfree_skb(skb);
74760 return NET_RX_DROP;
74761 }
74762 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
74763 struct raw6_sock *rp = raw6_sk(sk);
74764
74765 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
74766 - atomic_inc(&sk->sk_drops);
74767 + atomic_inc_unchecked(&sk->sk_drops);
74768 kfree_skb(skb);
74769 return NET_RX_DROP;
74770 }
74771 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
74772
74773 if (inet->hdrincl) {
74774 if (skb_checksum_complete(skb)) {
74775 - atomic_inc(&sk->sk_drops);
74776 + atomic_inc_unchecked(&sk->sk_drops);
74777 kfree_skb(skb);
74778 return NET_RX_DROP;
74779 }
74780 @@ -602,7 +602,7 @@ out:
74781 return err;
74782 }
74783
74784 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
74785 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
74786 struct flowi6 *fl6, struct dst_entry **dstp,
74787 unsigned int flags)
74788 {
74789 @@ -912,12 +912,15 @@ do_confirm:
74790 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
74791 char __user *optval, int optlen)
74792 {
74793 + struct icmp6_filter filter;
74794 +
74795 switch (optname) {
74796 case ICMPV6_FILTER:
74797 if (optlen > sizeof(struct icmp6_filter))
74798 optlen = sizeof(struct icmp6_filter);
74799 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
74800 + if (copy_from_user(&filter, optval, optlen))
74801 return -EFAULT;
74802 + raw6_sk(sk)->filter = filter;
74803 return 0;
74804 default:
74805 return -ENOPROTOOPT;
74806 @@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
74807 char __user *optval, int __user *optlen)
74808 {
74809 int len;
74810 + struct icmp6_filter filter;
74811
74812 switch (optname) {
74813 case ICMPV6_FILTER:
74814 @@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
74815 len = sizeof(struct icmp6_filter);
74816 if (put_user(len, optlen))
74817 return -EFAULT;
74818 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
74819 + filter = raw6_sk(sk)->filter;
74820 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
74821 return -EFAULT;
74822 return 0;
74823 default:
74824 @@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74825 0, 0L, 0,
74826 sock_i_uid(sp), 0,
74827 sock_i_ino(sp),
74828 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74829 + atomic_read(&sp->sk_refcnt),
74830 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74831 + NULL,
74832 +#else
74833 + sp,
74834 +#endif
74835 + atomic_read_unchecked(&sp->sk_drops));
74836 }
74837
74838 static int raw6_seq_show(struct seq_file *seq, void *v)
74839 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
74840 index 3edd05a..63aad01 100644
74841 --- a/net/ipv6/tcp_ipv6.c
74842 +++ b/net/ipv6/tcp_ipv6.c
74843 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
74844 }
74845 #endif
74846
74847 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74848 +extern int grsec_enable_blackhole;
74849 +#endif
74850 +
74851 static void tcp_v6_hash(struct sock *sk)
74852 {
74853 if (sk->sk_state != TCP_CLOSE) {
74854 @@ -1650,6 +1654,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
74855 return 0;
74856
74857 reset:
74858 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74859 + if (!grsec_enable_blackhole)
74860 +#endif
74861 tcp_v6_send_reset(sk, skb);
74862 discard:
74863 if (opt_skb)
74864 @@ -1729,12 +1736,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
74865 TCP_SKB_CB(skb)->sacked = 0;
74866
74867 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
74868 - if (!sk)
74869 + if (!sk) {
74870 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74871 + ret = 1;
74872 +#endif
74873 goto no_tcp_socket;
74874 + }
74875
74876 process:
74877 - if (sk->sk_state == TCP_TIME_WAIT)
74878 + if (sk->sk_state == TCP_TIME_WAIT) {
74879 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74880 + ret = 2;
74881 +#endif
74882 goto do_time_wait;
74883 + }
74884
74885 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
74886 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
74887 @@ -1782,6 +1797,10 @@ no_tcp_socket:
74888 bad_packet:
74889 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
74890 } else {
74891 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74892 + if (!grsec_enable_blackhole || (ret == 1 &&
74893 + (skb->dev->flags & IFF_LOOPBACK)))
74894 +#endif
74895 tcp_v6_send_reset(NULL, skb);
74896 }
74897
74898 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
74899 uid,
74900 0, /* non standard timer */
74901 0, /* open_requests have no inode */
74902 - 0, req);
74903 + 0,
74904 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74905 + NULL
74906 +#else
74907 + req
74908 +#endif
74909 + );
74910 }
74911
74912 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
74913 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
74914 sock_i_uid(sp),
74915 icsk->icsk_probes_out,
74916 sock_i_ino(sp),
74917 - atomic_read(&sp->sk_refcnt), sp,
74918 + atomic_read(&sp->sk_refcnt),
74919 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74920 + NULL,
74921 +#else
74922 + sp,
74923 +#endif
74924 jiffies_to_clock_t(icsk->icsk_rto),
74925 jiffies_to_clock_t(icsk->icsk_ack.ato),
74926 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
74927 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
74928 dest->s6_addr32[2], dest->s6_addr32[3], destp,
74929 tw->tw_substate, 0, 0,
74930 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74931 - atomic_read(&tw->tw_refcnt), tw);
74932 + atomic_read(&tw->tw_refcnt),
74933 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74934 + NULL
74935 +#else
74936 + tw
74937 +#endif
74938 + );
74939 }
74940
74941 static int tcp6_seq_show(struct seq_file *seq, void *v)
74942 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
74943 index 4f96b5c..75543d7 100644
74944 --- a/net/ipv6/udp.c
74945 +++ b/net/ipv6/udp.c
74946 @@ -50,6 +50,10 @@
74947 #include <linux/seq_file.h>
74948 #include "udp_impl.h"
74949
74950 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74951 +extern int grsec_enable_blackhole;
74952 +#endif
74953 +
74954 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
74955 {
74956 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
74957 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
74958
74959 return 0;
74960 drop:
74961 - atomic_inc(&sk->sk_drops);
74962 + atomic_inc_unchecked(&sk->sk_drops);
74963 drop_no_sk_drops_inc:
74964 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
74965 kfree_skb(skb);
74966 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
74967 continue;
74968 }
74969 drop:
74970 - atomic_inc(&sk->sk_drops);
74971 + atomic_inc_unchecked(&sk->sk_drops);
74972 UDP6_INC_STATS_BH(sock_net(sk),
74973 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
74974 UDP6_INC_STATS_BH(sock_net(sk),
74975 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
74976 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
74977 proto == IPPROTO_UDPLITE);
74978
74979 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74980 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
74981 +#endif
74982 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
74983
74984 kfree_skb(skb);
74985 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
74986 if (!sock_owned_by_user(sk))
74987 udpv6_queue_rcv_skb(sk, skb);
74988 else if (sk_add_backlog(sk, skb)) {
74989 - atomic_inc(&sk->sk_drops);
74990 + atomic_inc_unchecked(&sk->sk_drops);
74991 bh_unlock_sock(sk);
74992 sock_put(sk);
74993 goto discard;
74994 @@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
74995 0, 0L, 0,
74996 sock_i_uid(sp), 0,
74997 sock_i_ino(sp),
74998 - atomic_read(&sp->sk_refcnt), sp,
74999 - atomic_read(&sp->sk_drops));
75000 + atomic_read(&sp->sk_refcnt),
75001 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75002 + NULL,
75003 +#else
75004 + sp,
75005 +#endif
75006 + atomic_read_unchecked(&sp->sk_drops));
75007 }
75008
75009 int udp6_seq_show(struct seq_file *seq, void *v)
75010 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
75011 index 253695d..9481ce8 100644
75012 --- a/net/irda/ircomm/ircomm_tty.c
75013 +++ b/net/irda/ircomm/ircomm_tty.c
75014 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75015 add_wait_queue(&self->open_wait, &wait);
75016
75017 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
75018 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75019 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75020
75021 /* As far as I can see, we protect open_count - Jean II */
75022 spin_lock_irqsave(&self->spinlock, flags);
75023 if (!tty_hung_up_p(filp)) {
75024 extra_count = 1;
75025 - self->open_count--;
75026 + local_dec(&self->open_count);
75027 }
75028 spin_unlock_irqrestore(&self->spinlock, flags);
75029 - self->blocked_open++;
75030 + local_inc(&self->blocked_open);
75031
75032 while (1) {
75033 if (tty->termios->c_cflag & CBAUD) {
75034 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75035 }
75036
75037 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
75038 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75039 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75040
75041 schedule();
75042 }
75043 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75044 if (extra_count) {
75045 /* ++ is not atomic, so this should be protected - Jean II */
75046 spin_lock_irqsave(&self->spinlock, flags);
75047 - self->open_count++;
75048 + local_inc(&self->open_count);
75049 spin_unlock_irqrestore(&self->spinlock, flags);
75050 }
75051 - self->blocked_open--;
75052 + local_dec(&self->blocked_open);
75053
75054 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
75055 - __FILE__,__LINE__, tty->driver->name, self->open_count);
75056 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
75057
75058 if (!retval)
75059 self->flags |= ASYNC_NORMAL_ACTIVE;
75060 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
75061 }
75062 /* ++ is not atomic, so this should be protected - Jean II */
75063 spin_lock_irqsave(&self->spinlock, flags);
75064 - self->open_count++;
75065 + local_inc(&self->open_count);
75066
75067 tty->driver_data = self;
75068 self->tty = tty;
75069 spin_unlock_irqrestore(&self->spinlock, flags);
75070
75071 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
75072 - self->line, self->open_count);
75073 + self->line, local_read(&self->open_count));
75074
75075 /* Not really used by us, but lets do it anyway */
75076 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
75077 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75078 return;
75079 }
75080
75081 - if ((tty->count == 1) && (self->open_count != 1)) {
75082 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
75083 /*
75084 * Uh, oh. tty->count is 1, which means that the tty
75085 * structure will be freed. state->count should always
75086 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75087 */
75088 IRDA_DEBUG(0, "%s(), bad serial port count; "
75089 "tty->count is 1, state->count is %d\n", __func__ ,
75090 - self->open_count);
75091 - self->open_count = 1;
75092 + local_read(&self->open_count));
75093 + local_set(&self->open_count, 1);
75094 }
75095
75096 - if (--self->open_count < 0) {
75097 + if (local_dec_return(&self->open_count) < 0) {
75098 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
75099 - __func__, self->line, self->open_count);
75100 - self->open_count = 0;
75101 + __func__, self->line, local_read(&self->open_count));
75102 + local_set(&self->open_count, 0);
75103 }
75104 - if (self->open_count) {
75105 + if (local_read(&self->open_count)) {
75106 spin_unlock_irqrestore(&self->spinlock, flags);
75107
75108 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
75109 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75110 tty->closing = 0;
75111 self->tty = NULL;
75112
75113 - if (self->blocked_open) {
75114 + if (local_read(&self->blocked_open)) {
75115 if (self->close_delay)
75116 schedule_timeout_interruptible(self->close_delay);
75117 wake_up_interruptible(&self->open_wait);
75118 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
75119 spin_lock_irqsave(&self->spinlock, flags);
75120 self->flags &= ~ASYNC_NORMAL_ACTIVE;
75121 self->tty = NULL;
75122 - self->open_count = 0;
75123 + local_set(&self->open_count, 0);
75124 spin_unlock_irqrestore(&self->spinlock, flags);
75125
75126 wake_up_interruptible(&self->open_wait);
75127 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
75128 seq_putc(m, '\n');
75129
75130 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
75131 - seq_printf(m, "Open count: %d\n", self->open_count);
75132 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
75133 seq_printf(m, "Max data size: %d\n", self->max_data_size);
75134 seq_printf(m, "Max header size: %d\n", self->max_header_size);
75135
75136 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
75137 index d5c5b8f..33beff0 100644
75138 --- a/net/iucv/af_iucv.c
75139 +++ b/net/iucv/af_iucv.c
75140 @@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
75141
75142 write_lock_bh(&iucv_sk_list.lock);
75143
75144 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
75145 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75146 while (__iucv_get_sock_by_name(name)) {
75147 sprintf(name, "%08x",
75148 - atomic_inc_return(&iucv_sk_list.autobind_name));
75149 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75150 }
75151
75152 write_unlock_bh(&iucv_sk_list.lock);
75153 diff --git a/net/key/af_key.c b/net/key/af_key.c
75154 index 11dbb22..c20f667 100644
75155 --- a/net/key/af_key.c
75156 +++ b/net/key/af_key.c
75157 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
75158 static u32 get_acqseq(void)
75159 {
75160 u32 res;
75161 - static atomic_t acqseq;
75162 + static atomic_unchecked_t acqseq;
75163
75164 do {
75165 - res = atomic_inc_return(&acqseq);
75166 + res = atomic_inc_return_unchecked(&acqseq);
75167 } while (!res);
75168 return res;
75169 }
75170 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
75171 index 2f0642d..e5c6fba 100644
75172 --- a/net/mac80211/ieee80211_i.h
75173 +++ b/net/mac80211/ieee80211_i.h
75174 @@ -28,6 +28,7 @@
75175 #include <net/ieee80211_radiotap.h>
75176 #include <net/cfg80211.h>
75177 #include <net/mac80211.h>
75178 +#include <asm/local.h>
75179 #include "key.h"
75180 #include "sta_info.h"
75181
75182 @@ -781,7 +782,7 @@ struct ieee80211_local {
75183 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
75184 spinlock_t queue_stop_reason_lock;
75185
75186 - int open_count;
75187 + local_t open_count;
75188 int monitors, cooked_mntrs;
75189 /* number of interfaces with corresponding FIF_ flags */
75190 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
75191 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
75192 index 8e2137b..2974283 100644
75193 --- a/net/mac80211/iface.c
75194 +++ b/net/mac80211/iface.c
75195 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75196 break;
75197 }
75198
75199 - if (local->open_count == 0) {
75200 + if (local_read(&local->open_count) == 0) {
75201 res = drv_start(local);
75202 if (res)
75203 goto err_del_bss;
75204 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75205 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
75206
75207 if (!is_valid_ether_addr(dev->dev_addr)) {
75208 - if (!local->open_count)
75209 + if (!local_read(&local->open_count))
75210 drv_stop(local);
75211 return -EADDRNOTAVAIL;
75212 }
75213 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75214 mutex_unlock(&local->mtx);
75215
75216 if (coming_up)
75217 - local->open_count++;
75218 + local_inc(&local->open_count);
75219
75220 if (hw_reconf_flags)
75221 ieee80211_hw_config(local, hw_reconf_flags);
75222 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75223 err_del_interface:
75224 drv_remove_interface(local, sdata);
75225 err_stop:
75226 - if (!local->open_count)
75227 + if (!local_read(&local->open_count))
75228 drv_stop(local);
75229 err_del_bss:
75230 sdata->bss = NULL;
75231 @@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75232 }
75233
75234 if (going_down)
75235 - local->open_count--;
75236 + local_dec(&local->open_count);
75237
75238 switch (sdata->vif.type) {
75239 case NL80211_IFTYPE_AP_VLAN:
75240 @@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75241
75242 ieee80211_recalc_ps(local, -1);
75243
75244 - if (local->open_count == 0) {
75245 + if (local_read(&local->open_count) == 0) {
75246 if (local->ops->napi_poll)
75247 napi_disable(&local->napi);
75248 ieee80211_clear_tx_pending(local);
75249 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
75250 index b142bd4..a651749 100644
75251 --- a/net/mac80211/main.c
75252 +++ b/net/mac80211/main.c
75253 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
75254 local->hw.conf.power_level = power;
75255 }
75256
75257 - if (changed && local->open_count) {
75258 + if (changed && local_read(&local->open_count)) {
75259 ret = drv_config(local, changed);
75260 /*
75261 * Goal:
75262 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
75263 index 596efaf..8f1911f 100644
75264 --- a/net/mac80211/pm.c
75265 +++ b/net/mac80211/pm.c
75266 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75267 struct ieee80211_sub_if_data *sdata;
75268 struct sta_info *sta;
75269
75270 - if (!local->open_count)
75271 + if (!local_read(&local->open_count))
75272 goto suspend;
75273
75274 ieee80211_scan_cancel(local);
75275 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75276 cancel_work_sync(&local->dynamic_ps_enable_work);
75277 del_timer_sync(&local->dynamic_ps_timer);
75278
75279 - local->wowlan = wowlan && local->open_count;
75280 + local->wowlan = wowlan && local_read(&local->open_count);
75281 if (local->wowlan) {
75282 int err = drv_suspend(local, wowlan);
75283 if (err < 0) {
75284 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75285 }
75286
75287 /* stop hardware - this must stop RX */
75288 - if (local->open_count)
75289 + if (local_read(&local->open_count))
75290 ieee80211_stop_device(local);
75291
75292 suspend:
75293 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
75294 index f9b8e81..bb89b46 100644
75295 --- a/net/mac80211/rate.c
75296 +++ b/net/mac80211/rate.c
75297 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
75298
75299 ASSERT_RTNL();
75300
75301 - if (local->open_count)
75302 + if (local_read(&local->open_count))
75303 return -EBUSY;
75304
75305 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
75306 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
75307 index c97a065..ff61928 100644
75308 --- a/net/mac80211/rc80211_pid_debugfs.c
75309 +++ b/net/mac80211/rc80211_pid_debugfs.c
75310 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
75311
75312 spin_unlock_irqrestore(&events->lock, status);
75313
75314 - if (copy_to_user(buf, pb, p))
75315 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
75316 return -EFAULT;
75317
75318 return p;
75319 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
75320 index 9919892..8c49803 100644
75321 --- a/net/mac80211/util.c
75322 +++ b/net/mac80211/util.c
75323 @@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
75324 }
75325 #endif
75326 /* everything else happens only if HW was up & running */
75327 - if (!local->open_count)
75328 + if (!local_read(&local->open_count))
75329 goto wake_up;
75330
75331 /*
75332 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
75333 index f8ac4ef..b02560b 100644
75334 --- a/net/netfilter/Kconfig
75335 +++ b/net/netfilter/Kconfig
75336 @@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
75337
75338 To compile it as a module, choose M here. If unsure, say N.
75339
75340 +config NETFILTER_XT_MATCH_GRADM
75341 + tristate '"gradm" match support'
75342 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
75343 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
75344 + ---help---
75345 + The gradm match allows to match on grsecurity RBAC being enabled.
75346 + It is useful when iptables rules are applied early on bootup to
75347 + prevent connections to the machine (except from a trusted host)
75348 + while the RBAC system is disabled.
75349 +
75350 config NETFILTER_XT_MATCH_HASHLIMIT
75351 tristate '"hashlimit" match support'
75352 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
75353 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
75354 index 40f4c3d..0d5dd6b 100644
75355 --- a/net/netfilter/Makefile
75356 +++ b/net/netfilter/Makefile
75357 @@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
75358 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
75359 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
75360 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
75361 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
75362 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
75363 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
75364 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
75365 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
75366 index 29fa5ba..8debc79 100644
75367 --- a/net/netfilter/ipvs/ip_vs_conn.c
75368 +++ b/net/netfilter/ipvs/ip_vs_conn.c
75369 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
75370 /* Increase the refcnt counter of the dest */
75371 atomic_inc(&dest->refcnt);
75372
75373 - conn_flags = atomic_read(&dest->conn_flags);
75374 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
75375 if (cp->protocol != IPPROTO_UDP)
75376 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
75377 /* Bind with the destination and its corresponding transmitter */
75378 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
75379 atomic_set(&cp->refcnt, 1);
75380
75381 atomic_set(&cp->n_control, 0);
75382 - atomic_set(&cp->in_pkts, 0);
75383 + atomic_set_unchecked(&cp->in_pkts, 0);
75384
75385 atomic_inc(&ipvs->conn_count);
75386 if (flags & IP_VS_CONN_F_NO_CPORT)
75387 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
75388
75389 /* Don't drop the entry if its number of incoming packets is not
75390 located in [0, 8] */
75391 - i = atomic_read(&cp->in_pkts);
75392 + i = atomic_read_unchecked(&cp->in_pkts);
75393 if (i > 8 || i < 0) return 0;
75394
75395 if (!todrop_rate[i]) return 0;
75396 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
75397 index 2555816..31492d9 100644
75398 --- a/net/netfilter/ipvs/ip_vs_core.c
75399 +++ b/net/netfilter/ipvs/ip_vs_core.c
75400 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
75401 ret = cp->packet_xmit(skb, cp, pd->pp);
75402 /* do not touch skb anymore */
75403
75404 - atomic_inc(&cp->in_pkts);
75405 + atomic_inc_unchecked(&cp->in_pkts);
75406 ip_vs_conn_put(cp);
75407 return ret;
75408 }
75409 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
75410 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
75411 pkts = sysctl_sync_threshold(ipvs);
75412 else
75413 - pkts = atomic_add_return(1, &cp->in_pkts);
75414 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75415
75416 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
75417 cp->protocol == IPPROTO_SCTP) {
75418 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
75419 index b3afe18..08ec940 100644
75420 --- a/net/netfilter/ipvs/ip_vs_ctl.c
75421 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
75422 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
75423 ip_vs_rs_hash(ipvs, dest);
75424 write_unlock_bh(&ipvs->rs_lock);
75425 }
75426 - atomic_set(&dest->conn_flags, conn_flags);
75427 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
75428
75429 /* bind the service */
75430 if (!dest->svc) {
75431 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75432 " %-7s %-6d %-10d %-10d\n",
75433 &dest->addr.in6,
75434 ntohs(dest->port),
75435 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75436 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75437 atomic_read(&dest->weight),
75438 atomic_read(&dest->activeconns),
75439 atomic_read(&dest->inactconns));
75440 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75441 "%-7s %-6d %-10d %-10d\n",
75442 ntohl(dest->addr.ip),
75443 ntohs(dest->port),
75444 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75445 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75446 atomic_read(&dest->weight),
75447 atomic_read(&dest->activeconns),
75448 atomic_read(&dest->inactconns));
75449 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
75450
75451 entry.addr = dest->addr.ip;
75452 entry.port = dest->port;
75453 - entry.conn_flags = atomic_read(&dest->conn_flags);
75454 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
75455 entry.weight = atomic_read(&dest->weight);
75456 entry.u_threshold = dest->u_threshold;
75457 entry.l_threshold = dest->l_threshold;
75458 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
75459 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
75460
75461 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
75462 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75463 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75464 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
75465 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
75466 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
75467 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
75468 index 8a0d6d6..90ec197 100644
75469 --- a/net/netfilter/ipvs/ip_vs_sync.c
75470 +++ b/net/netfilter/ipvs/ip_vs_sync.c
75471 @@ -649,7 +649,7 @@ control:
75472 * i.e only increment in_pkts for Templates.
75473 */
75474 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
75475 - int pkts = atomic_add_return(1, &cp->in_pkts);
75476 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75477
75478 if (pkts % sysctl_sync_period(ipvs) != 1)
75479 return;
75480 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
75481
75482 if (opt)
75483 memcpy(&cp->in_seq, opt, sizeof(*opt));
75484 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75485 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75486 cp->state = state;
75487 cp->old_state = cp->state;
75488 /*
75489 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
75490 index 7fd66de..e6fb361 100644
75491 --- a/net/netfilter/ipvs/ip_vs_xmit.c
75492 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
75493 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
75494 else
75495 rc = NF_ACCEPT;
75496 /* do not touch skb anymore */
75497 - atomic_inc(&cp->in_pkts);
75498 + atomic_inc_unchecked(&cp->in_pkts);
75499 goto out;
75500 }
75501
75502 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
75503 else
75504 rc = NF_ACCEPT;
75505 /* do not touch skb anymore */
75506 - atomic_inc(&cp->in_pkts);
75507 + atomic_inc_unchecked(&cp->in_pkts);
75508 goto out;
75509 }
75510
75511 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
75512 index 66b2c54..c7884e3 100644
75513 --- a/net/netfilter/nfnetlink_log.c
75514 +++ b/net/netfilter/nfnetlink_log.c
75515 @@ -70,7 +70,7 @@ struct nfulnl_instance {
75516 };
75517
75518 static DEFINE_SPINLOCK(instances_lock);
75519 -static atomic_t global_seq;
75520 +static atomic_unchecked_t global_seq;
75521
75522 #define INSTANCE_BUCKETS 16
75523 static struct hlist_head instance_table[INSTANCE_BUCKETS];
75524 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
75525 /* global sequence number */
75526 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
75527 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
75528 - htonl(atomic_inc_return(&global_seq)));
75529 + htonl(atomic_inc_return_unchecked(&global_seq)));
75530
75531 if (data_len) {
75532 struct nlattr *nla;
75533 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
75534 new file mode 100644
75535 index 0000000..6905327
75536 --- /dev/null
75537 +++ b/net/netfilter/xt_gradm.c
75538 @@ -0,0 +1,51 @@
75539 +/*
75540 + * gradm match for netfilter
75541 + * Copyright © Zbigniew Krzystolik, 2010
75542 + *
75543 + * This program is free software; you can redistribute it and/or modify
75544 + * it under the terms of the GNU General Public License; either version
75545 + * 2 or 3 as published by the Free Software Foundation.
75546 + */
75547 +#include <linux/module.h>
75548 +#include <linux/moduleparam.h>
75549 +#include <linux/skbuff.h>
75550 +#include <linux/netfilter/x_tables.h>
75551 +#include <linux/grsecurity.h>
75552 +#include <linux/netfilter/xt_gradm.h>
75553 +
75554 +static bool
75555 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
75556 +{
75557 + const struct xt_gradm_mtinfo *info = par->matchinfo;
75558 + bool retval = false;
75559 + if (gr_acl_is_enabled())
75560 + retval = true;
75561 + return retval ^ info->invflags;
75562 +}
75563 +
75564 +static struct xt_match gradm_mt_reg __read_mostly = {
75565 + .name = "gradm",
75566 + .revision = 0,
75567 + .family = NFPROTO_UNSPEC,
75568 + .match = gradm_mt,
75569 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
75570 + .me = THIS_MODULE,
75571 +};
75572 +
75573 +static int __init gradm_mt_init(void)
75574 +{
75575 + return xt_register_match(&gradm_mt_reg);
75576 +}
75577 +
75578 +static void __exit gradm_mt_exit(void)
75579 +{
75580 + xt_unregister_match(&gradm_mt_reg);
75581 +}
75582 +
75583 +module_init(gradm_mt_init);
75584 +module_exit(gradm_mt_exit);
75585 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
75586 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
75587 +MODULE_LICENSE("GPL");
75588 +MODULE_ALIAS("ipt_gradm");
75589 +MODULE_ALIAS("ip6t_gradm");
75590 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
75591 index 4fe4fb4..87a89e5 100644
75592 --- a/net/netfilter/xt_statistic.c
75593 +++ b/net/netfilter/xt_statistic.c
75594 @@ -19,7 +19,7 @@
75595 #include <linux/module.h>
75596
75597 struct xt_statistic_priv {
75598 - atomic_t count;
75599 + atomic_unchecked_t count;
75600 } ____cacheline_aligned_in_smp;
75601
75602 MODULE_LICENSE("GPL");
75603 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
75604 break;
75605 case XT_STATISTIC_MODE_NTH:
75606 do {
75607 - oval = atomic_read(&info->master->count);
75608 + oval = atomic_read_unchecked(&info->master->count);
75609 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
75610 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
75611 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
75612 if (nval == 0)
75613 ret = !ret;
75614 break;
75615 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
75616 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
75617 if (info->master == NULL)
75618 return -ENOMEM;
75619 - atomic_set(&info->master->count, info->u.nth.count);
75620 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
75621
75622 return 0;
75623 }
75624 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
75625 index 629b061..21cd04c 100644
75626 --- a/net/netlink/af_netlink.c
75627 +++ b/net/netlink/af_netlink.c
75628 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
75629 sk->sk_error_report(sk);
75630 }
75631 }
75632 - atomic_inc(&sk->sk_drops);
75633 + atomic_inc_unchecked(&sk->sk_drops);
75634 }
75635
75636 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
75637 @@ -1995,7 +1995,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
75638 sk_wmem_alloc_get(s),
75639 nlk->cb,
75640 atomic_read(&s->sk_refcnt),
75641 - atomic_read(&s->sk_drops),
75642 + atomic_read_unchecked(&s->sk_drops),
75643 sock_i_ino(s)
75644 );
75645
75646 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
75647 index 7dab229..212156f 100644
75648 --- a/net/netrom/af_netrom.c
75649 +++ b/net/netrom/af_netrom.c
75650 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
75651 struct sock *sk = sock->sk;
75652 struct nr_sock *nr = nr_sk(sk);
75653
75654 + memset(sax, 0, sizeof(*sax));
75655 lock_sock(sk);
75656 if (peer != 0) {
75657 if (sk->sk_state != TCP_ESTABLISHED) {
75658 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
75659 *uaddr_len = sizeof(struct full_sockaddr_ax25);
75660 } else {
75661 sax->fsa_ax25.sax25_family = AF_NETROM;
75662 - sax->fsa_ax25.sax25_ndigis = 0;
75663 sax->fsa_ax25.sax25_call = nr->source_addr;
75664 *uaddr_len = sizeof(struct sockaddr_ax25);
75665 }
75666 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
75667 index 2dbb32b..a1b4722 100644
75668 --- a/net/packet/af_packet.c
75669 +++ b/net/packet/af_packet.c
75670 @@ -1676,7 +1676,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
75671
75672 spin_lock(&sk->sk_receive_queue.lock);
75673 po->stats.tp_packets++;
75674 - skb->dropcount = atomic_read(&sk->sk_drops);
75675 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75676 __skb_queue_tail(&sk->sk_receive_queue, skb);
75677 spin_unlock(&sk->sk_receive_queue.lock);
75678 sk->sk_data_ready(sk, skb->len);
75679 @@ -1685,7 +1685,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
75680 drop_n_acct:
75681 spin_lock(&sk->sk_receive_queue.lock);
75682 po->stats.tp_drops++;
75683 - atomic_inc(&sk->sk_drops);
75684 + atomic_inc_unchecked(&sk->sk_drops);
75685 spin_unlock(&sk->sk_receive_queue.lock);
75686
75687 drop_n_restore:
75688 @@ -3271,7 +3271,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
75689 case PACKET_HDRLEN:
75690 if (len > sizeof(int))
75691 len = sizeof(int);
75692 - if (copy_from_user(&val, optval, len))
75693 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
75694 return -EFAULT;
75695 switch (val) {
75696 case TPACKET_V1:
75697 @@ -3321,7 +3321,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
75698
75699 if (put_user(len, optlen))
75700 return -EFAULT;
75701 - if (copy_to_user(optval, data, len))
75702 + if (len > sizeof(st) || copy_to_user(optval, data, len))
75703 return -EFAULT;
75704 return 0;
75705 }
75706 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
75707 index d65f699..05aa6ce 100644
75708 --- a/net/phonet/af_phonet.c
75709 +++ b/net/phonet/af_phonet.c
75710 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
75711 {
75712 struct phonet_protocol *pp;
75713
75714 - if (protocol >= PHONET_NPROTO)
75715 + if (protocol < 0 || protocol >= PHONET_NPROTO)
75716 return NULL;
75717
75718 rcu_read_lock();
75719 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
75720 {
75721 int err = 0;
75722
75723 - if (protocol >= PHONET_NPROTO)
75724 + if (protocol < 0 || protocol >= PHONET_NPROTO)
75725 return -EINVAL;
75726
75727 err = proto_register(pp->prot, 1);
75728 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
75729 index 9f60008..ae96f04 100644
75730 --- a/net/phonet/pep.c
75731 +++ b/net/phonet/pep.c
75732 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
75733
75734 case PNS_PEP_CTRL_REQ:
75735 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
75736 - atomic_inc(&sk->sk_drops);
75737 + atomic_inc_unchecked(&sk->sk_drops);
75738 break;
75739 }
75740 __skb_pull(skb, 4);
75741 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
75742 }
75743
75744 if (pn->rx_credits == 0) {
75745 - atomic_inc(&sk->sk_drops);
75746 + atomic_inc_unchecked(&sk->sk_drops);
75747 err = -ENOBUFS;
75748 break;
75749 }
75750 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
75751 }
75752
75753 if (pn->rx_credits == 0) {
75754 - atomic_inc(&sk->sk_drops);
75755 + atomic_inc_unchecked(&sk->sk_drops);
75756 err = NET_RX_DROP;
75757 break;
75758 }
75759 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
75760 index 4c7eff3..59c727f 100644
75761 --- a/net/phonet/socket.c
75762 +++ b/net/phonet/socket.c
75763 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
75764 pn->resource, sk->sk_state,
75765 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
75766 sock_i_uid(sk), sock_i_ino(sk),
75767 - atomic_read(&sk->sk_refcnt), sk,
75768 - atomic_read(&sk->sk_drops), &len);
75769 + atomic_read(&sk->sk_refcnt),
75770 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75771 + NULL,
75772 +#else
75773 + sk,
75774 +#endif
75775 + atomic_read_unchecked(&sk->sk_drops), &len);
75776 }
75777 seq_printf(seq, "%*s\n", 127 - len, "");
75778 return 0;
75779 diff --git a/net/rds/cong.c b/net/rds/cong.c
75780 index e5b65ac..f3b6fb7 100644
75781 --- a/net/rds/cong.c
75782 +++ b/net/rds/cong.c
75783 @@ -78,7 +78,7 @@
75784 * finds that the saved generation number is smaller than the global generation
75785 * number, it wakes up the process.
75786 */
75787 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
75788 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
75789
75790 /*
75791 * Congestion monitoring
75792 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
75793 rdsdebug("waking map %p for %pI4\n",
75794 map, &map->m_addr);
75795 rds_stats_inc(s_cong_update_received);
75796 - atomic_inc(&rds_cong_generation);
75797 + atomic_inc_unchecked(&rds_cong_generation);
75798 if (waitqueue_active(&map->m_waitq))
75799 wake_up(&map->m_waitq);
75800 if (waitqueue_active(&rds_poll_waitq))
75801 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
75802
75803 int rds_cong_updated_since(unsigned long *recent)
75804 {
75805 - unsigned long gen = atomic_read(&rds_cong_generation);
75806 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
75807
75808 if (likely(*recent == gen))
75809 return 0;
75810 diff --git a/net/rds/ib.h b/net/rds/ib.h
75811 index edfaaaf..8c89879 100644
75812 --- a/net/rds/ib.h
75813 +++ b/net/rds/ib.h
75814 @@ -128,7 +128,7 @@ struct rds_ib_connection {
75815 /* sending acks */
75816 unsigned long i_ack_flags;
75817 #ifdef KERNEL_HAS_ATOMIC64
75818 - atomic64_t i_ack_next; /* next ACK to send */
75819 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
75820 #else
75821 spinlock_t i_ack_lock; /* protect i_ack_next */
75822 u64 i_ack_next; /* next ACK to send */
75823 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
75824 index 51c8689..36c555f 100644
75825 --- a/net/rds/ib_cm.c
75826 +++ b/net/rds/ib_cm.c
75827 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
75828 /* Clear the ACK state */
75829 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
75830 #ifdef KERNEL_HAS_ATOMIC64
75831 - atomic64_set(&ic->i_ack_next, 0);
75832 + atomic64_set_unchecked(&ic->i_ack_next, 0);
75833 #else
75834 ic->i_ack_next = 0;
75835 #endif
75836 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
75837 index e29e0ca..fa3a6a3 100644
75838 --- a/net/rds/ib_recv.c
75839 +++ b/net/rds/ib_recv.c
75840 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
75841 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
75842 int ack_required)
75843 {
75844 - atomic64_set(&ic->i_ack_next, seq);
75845 + atomic64_set_unchecked(&ic->i_ack_next, seq);
75846 if (ack_required) {
75847 smp_mb__before_clear_bit();
75848 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
75849 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
75850 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
75851 smp_mb__after_clear_bit();
75852
75853 - return atomic64_read(&ic->i_ack_next);
75854 + return atomic64_read_unchecked(&ic->i_ack_next);
75855 }
75856 #endif
75857
75858 diff --git a/net/rds/iw.h b/net/rds/iw.h
75859 index 04ce3b1..48119a6 100644
75860 --- a/net/rds/iw.h
75861 +++ b/net/rds/iw.h
75862 @@ -134,7 +134,7 @@ struct rds_iw_connection {
75863 /* sending acks */
75864 unsigned long i_ack_flags;
75865 #ifdef KERNEL_HAS_ATOMIC64
75866 - atomic64_t i_ack_next; /* next ACK to send */
75867 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
75868 #else
75869 spinlock_t i_ack_lock; /* protect i_ack_next */
75870 u64 i_ack_next; /* next ACK to send */
75871 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
75872 index 9556d28..f046d0e 100644
75873 --- a/net/rds/iw_cm.c
75874 +++ b/net/rds/iw_cm.c
75875 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
75876 /* Clear the ACK state */
75877 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
75878 #ifdef KERNEL_HAS_ATOMIC64
75879 - atomic64_set(&ic->i_ack_next, 0);
75880 + atomic64_set_unchecked(&ic->i_ack_next, 0);
75881 #else
75882 ic->i_ack_next = 0;
75883 #endif
75884 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
75885 index 5e57347..3916042 100644
75886 --- a/net/rds/iw_recv.c
75887 +++ b/net/rds/iw_recv.c
75888 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
75889 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
75890 int ack_required)
75891 {
75892 - atomic64_set(&ic->i_ack_next, seq);
75893 + atomic64_set_unchecked(&ic->i_ack_next, seq);
75894 if (ack_required) {
75895 smp_mb__before_clear_bit();
75896 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
75897 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
75898 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
75899 smp_mb__after_clear_bit();
75900
75901 - return atomic64_read(&ic->i_ack_next);
75902 + return atomic64_read_unchecked(&ic->i_ack_next);
75903 }
75904 #endif
75905
75906 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
75907 index edac9ef..16bcb98 100644
75908 --- a/net/rds/tcp.c
75909 +++ b/net/rds/tcp.c
75910 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
75911 int val = 1;
75912
75913 set_fs(KERNEL_DS);
75914 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
75915 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
75916 sizeof(val));
75917 set_fs(oldfs);
75918 }
75919 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
75920 index 1b4fd68..2234175 100644
75921 --- a/net/rds/tcp_send.c
75922 +++ b/net/rds/tcp_send.c
75923 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
75924
75925 oldfs = get_fs();
75926 set_fs(KERNEL_DS);
75927 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
75928 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
75929 sizeof(val));
75930 set_fs(oldfs);
75931 }
75932 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
75933 index 74c064c..fdec26f 100644
75934 --- a/net/rxrpc/af_rxrpc.c
75935 +++ b/net/rxrpc/af_rxrpc.c
75936 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
75937 __be32 rxrpc_epoch;
75938
75939 /* current debugging ID */
75940 -atomic_t rxrpc_debug_id;
75941 +atomic_unchecked_t rxrpc_debug_id;
75942
75943 /* count of skbs currently in use */
75944 atomic_t rxrpc_n_skbs;
75945 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
75946 index c3126e8..21facc7 100644
75947 --- a/net/rxrpc/ar-ack.c
75948 +++ b/net/rxrpc/ar-ack.c
75949 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
75950
75951 _enter("{%d,%d,%d,%d},",
75952 call->acks_hard, call->acks_unacked,
75953 - atomic_read(&call->sequence),
75954 + atomic_read_unchecked(&call->sequence),
75955 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
75956
75957 stop = 0;
75958 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
75959
75960 /* each Tx packet has a new serial number */
75961 sp->hdr.serial =
75962 - htonl(atomic_inc_return(&call->conn->serial));
75963 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
75964
75965 hdr = (struct rxrpc_header *) txb->head;
75966 hdr->serial = sp->hdr.serial;
75967 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
75968 */
75969 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
75970 {
75971 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
75972 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
75973 }
75974
75975 /*
75976 @@ -629,7 +629,7 @@ process_further:
75977
75978 latest = ntohl(sp->hdr.serial);
75979 hard = ntohl(ack.firstPacket);
75980 - tx = atomic_read(&call->sequence);
75981 + tx = atomic_read_unchecked(&call->sequence);
75982
75983 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
75984 latest,
75985 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
75986 goto maybe_reschedule;
75987
75988 send_ACK_with_skew:
75989 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
75990 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
75991 ntohl(ack.serial));
75992 send_ACK:
75993 mtu = call->conn->trans->peer->if_mtu;
75994 @@ -1173,7 +1173,7 @@ send_ACK:
75995 ackinfo.rxMTU = htonl(5692);
75996 ackinfo.jumbo_max = htonl(4);
75997
75998 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
75999 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76000 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76001 ntohl(hdr.serial),
76002 ntohs(ack.maxSkew),
76003 @@ -1191,7 +1191,7 @@ send_ACK:
76004 send_message:
76005 _debug("send message");
76006
76007 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76008 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76009 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
76010 send_message_2:
76011
76012 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
76013 index bf656c2..48f9d27 100644
76014 --- a/net/rxrpc/ar-call.c
76015 +++ b/net/rxrpc/ar-call.c
76016 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
76017 spin_lock_init(&call->lock);
76018 rwlock_init(&call->state_lock);
76019 atomic_set(&call->usage, 1);
76020 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
76021 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76022 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
76023
76024 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
76025 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
76026 index 4106ca9..a338d7a 100644
76027 --- a/net/rxrpc/ar-connection.c
76028 +++ b/net/rxrpc/ar-connection.c
76029 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
76030 rwlock_init(&conn->lock);
76031 spin_lock_init(&conn->state_lock);
76032 atomic_set(&conn->usage, 1);
76033 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
76034 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76035 conn->avail_calls = RXRPC_MAXCALLS;
76036 conn->size_align = 4;
76037 conn->header_size = sizeof(struct rxrpc_header);
76038 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
76039 index e7ed43a..6afa140 100644
76040 --- a/net/rxrpc/ar-connevent.c
76041 +++ b/net/rxrpc/ar-connevent.c
76042 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
76043
76044 len = iov[0].iov_len + iov[1].iov_len;
76045
76046 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76047 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76048 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
76049
76050 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76051 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
76052 index 1a2b0633..e8d1382 100644
76053 --- a/net/rxrpc/ar-input.c
76054 +++ b/net/rxrpc/ar-input.c
76055 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
76056 /* track the latest serial number on this connection for ACK packet
76057 * information */
76058 serial = ntohl(sp->hdr.serial);
76059 - hi_serial = atomic_read(&call->conn->hi_serial);
76060 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
76061 while (serial > hi_serial)
76062 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
76063 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
76064 serial);
76065
76066 /* request ACK generation for any ACK or DATA packet that requests
76067 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
76068 index 8e22bd3..f66d1c0 100644
76069 --- a/net/rxrpc/ar-internal.h
76070 +++ b/net/rxrpc/ar-internal.h
76071 @@ -272,8 +272,8 @@ struct rxrpc_connection {
76072 int error; /* error code for local abort */
76073 int debug_id; /* debug ID for printks */
76074 unsigned call_counter; /* call ID counter */
76075 - atomic_t serial; /* packet serial number counter */
76076 - atomic_t hi_serial; /* highest serial number received */
76077 + atomic_unchecked_t serial; /* packet serial number counter */
76078 + atomic_unchecked_t hi_serial; /* highest serial number received */
76079 u8 avail_calls; /* number of calls available */
76080 u8 size_align; /* data size alignment (for security) */
76081 u8 header_size; /* rxrpc + security header size */
76082 @@ -346,7 +346,7 @@ struct rxrpc_call {
76083 spinlock_t lock;
76084 rwlock_t state_lock; /* lock for state transition */
76085 atomic_t usage;
76086 - atomic_t sequence; /* Tx data packet sequence counter */
76087 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
76088 u32 abort_code; /* local/remote abort code */
76089 enum { /* current state of call */
76090 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
76091 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
76092 */
76093 extern atomic_t rxrpc_n_skbs;
76094 extern __be32 rxrpc_epoch;
76095 -extern atomic_t rxrpc_debug_id;
76096 +extern atomic_unchecked_t rxrpc_debug_id;
76097 extern struct workqueue_struct *rxrpc_workqueue;
76098
76099 /*
76100 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
76101 index 87f7135..74d3703 100644
76102 --- a/net/rxrpc/ar-local.c
76103 +++ b/net/rxrpc/ar-local.c
76104 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
76105 spin_lock_init(&local->lock);
76106 rwlock_init(&local->services_lock);
76107 atomic_set(&local->usage, 1);
76108 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
76109 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76110 memcpy(&local->srx, srx, sizeof(*srx));
76111 }
76112
76113 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
76114 index 16ae887..d24f12b 100644
76115 --- a/net/rxrpc/ar-output.c
76116 +++ b/net/rxrpc/ar-output.c
76117 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
76118 sp->hdr.cid = call->cid;
76119 sp->hdr.callNumber = call->call_id;
76120 sp->hdr.seq =
76121 - htonl(atomic_inc_return(&call->sequence));
76122 + htonl(atomic_inc_return_unchecked(&call->sequence));
76123 sp->hdr.serial =
76124 - htonl(atomic_inc_return(&conn->serial));
76125 + htonl(atomic_inc_return_unchecked(&conn->serial));
76126 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
76127 sp->hdr.userStatus = 0;
76128 sp->hdr.securityIndex = conn->security_ix;
76129 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
76130 index 2754f09..b20e38f 100644
76131 --- a/net/rxrpc/ar-peer.c
76132 +++ b/net/rxrpc/ar-peer.c
76133 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
76134 INIT_LIST_HEAD(&peer->error_targets);
76135 spin_lock_init(&peer->lock);
76136 atomic_set(&peer->usage, 1);
76137 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
76138 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76139 memcpy(&peer->srx, srx, sizeof(*srx));
76140
76141 rxrpc_assess_MTU_size(peer);
76142 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
76143 index 38047f7..9f48511 100644
76144 --- a/net/rxrpc/ar-proc.c
76145 +++ b/net/rxrpc/ar-proc.c
76146 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
76147 atomic_read(&conn->usage),
76148 rxrpc_conn_states[conn->state],
76149 key_serial(conn->key),
76150 - atomic_read(&conn->serial),
76151 - atomic_read(&conn->hi_serial));
76152 + atomic_read_unchecked(&conn->serial),
76153 + atomic_read_unchecked(&conn->hi_serial));
76154
76155 return 0;
76156 }
76157 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
76158 index 92df566..87ec1bf 100644
76159 --- a/net/rxrpc/ar-transport.c
76160 +++ b/net/rxrpc/ar-transport.c
76161 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
76162 spin_lock_init(&trans->client_lock);
76163 rwlock_init(&trans->conn_lock);
76164 atomic_set(&trans->usage, 1);
76165 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
76166 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76167
76168 if (peer->srx.transport.family == AF_INET) {
76169 switch (peer->srx.transport_type) {
76170 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
76171 index 7635107..4670276 100644
76172 --- a/net/rxrpc/rxkad.c
76173 +++ b/net/rxrpc/rxkad.c
76174 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
76175
76176 len = iov[0].iov_len + iov[1].iov_len;
76177
76178 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76179 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76180 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
76181
76182 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76183 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
76184
76185 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
76186
76187 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
76188 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76189 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
76190
76191 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
76192 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
76193 index 1e2eee8..ce3967e 100644
76194 --- a/net/sctp/proc.c
76195 +++ b/net/sctp/proc.c
76196 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
76197 seq_printf(seq,
76198 "%8pK %8pK %-3d %-3d %-2d %-4d "
76199 "%4d %8d %8d %7d %5lu %-5d %5d ",
76200 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
76201 + assoc, sk,
76202 + sctp_sk(sk)->type, sk->sk_state,
76203 assoc->state, hash,
76204 assoc->assoc_id,
76205 assoc->sndbuf_used,
76206 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
76207 index 408ebd0..202aa85 100644
76208 --- a/net/sctp/socket.c
76209 +++ b/net/sctp/socket.c
76210 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
76211 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
76212 if (space_left < addrlen)
76213 return -ENOMEM;
76214 - if (copy_to_user(to, &temp, addrlen))
76215 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
76216 return -EFAULT;
76217 to += addrlen;
76218 cnt++;
76219 diff --git a/net/socket.c b/net/socket.c
76220 index 28a96af..61a7a06 100644
76221 --- a/net/socket.c
76222 +++ b/net/socket.c
76223 @@ -88,6 +88,7 @@
76224 #include <linux/nsproxy.h>
76225 #include <linux/magic.h>
76226 #include <linux/slab.h>
76227 +#include <linux/in.h>
76228
76229 #include <asm/uaccess.h>
76230 #include <asm/unistd.h>
76231 @@ -105,6 +106,8 @@
76232 #include <linux/sockios.h>
76233 #include <linux/atalk.h>
76234
76235 +#include <linux/grsock.h>
76236 +
76237 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
76238 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
76239 unsigned long nr_segs, loff_t pos);
76240 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
76241 &sockfs_dentry_operations, SOCKFS_MAGIC);
76242 }
76243
76244 -static struct vfsmount *sock_mnt __read_mostly;
76245 +struct vfsmount *sock_mnt __read_mostly;
76246
76247 static struct file_system_type sock_fs_type = {
76248 .name = "sockfs",
76249 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
76250 return -EAFNOSUPPORT;
76251 if (type < 0 || type >= SOCK_MAX)
76252 return -EINVAL;
76253 + if (protocol < 0)
76254 + return -EINVAL;
76255
76256 /* Compatibility.
76257
76258 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
76259 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
76260 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
76261
76262 + if(!gr_search_socket(family, type, protocol)) {
76263 + retval = -EACCES;
76264 + goto out;
76265 + }
76266 +
76267 + if (gr_handle_sock_all(family, type, protocol)) {
76268 + retval = -EACCES;
76269 + goto out;
76270 + }
76271 +
76272 retval = sock_create(family, type, protocol, &sock);
76273 if (retval < 0)
76274 goto out;
76275 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76276 if (sock) {
76277 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
76278 if (err >= 0) {
76279 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
76280 + err = -EACCES;
76281 + goto error;
76282 + }
76283 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
76284 + if (err)
76285 + goto error;
76286 +
76287 err = security_socket_bind(sock,
76288 (struct sockaddr *)&address,
76289 addrlen);
76290 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76291 (struct sockaddr *)
76292 &address, addrlen);
76293 }
76294 +error:
76295 fput_light(sock->file, fput_needed);
76296 }
76297 return err;
76298 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
76299 if ((unsigned)backlog > somaxconn)
76300 backlog = somaxconn;
76301
76302 + if (gr_handle_sock_server_other(sock->sk)) {
76303 + err = -EPERM;
76304 + goto error;
76305 + }
76306 +
76307 + err = gr_search_listen(sock);
76308 + if (err)
76309 + goto error;
76310 +
76311 err = security_socket_listen(sock, backlog);
76312 if (!err)
76313 err = sock->ops->listen(sock, backlog);
76314
76315 +error:
76316 fput_light(sock->file, fput_needed);
76317 }
76318 return err;
76319 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76320 newsock->type = sock->type;
76321 newsock->ops = sock->ops;
76322
76323 + if (gr_handle_sock_server_other(sock->sk)) {
76324 + err = -EPERM;
76325 + sock_release(newsock);
76326 + goto out_put;
76327 + }
76328 +
76329 + err = gr_search_accept(sock);
76330 + if (err) {
76331 + sock_release(newsock);
76332 + goto out_put;
76333 + }
76334 +
76335 /*
76336 * We don't need try_module_get here, as the listening socket (sock)
76337 * has the protocol module (sock->ops->owner) held.
76338 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76339 fd_install(newfd, newfile);
76340 err = newfd;
76341
76342 + gr_attach_curr_ip(newsock->sk);
76343 +
76344 out_put:
76345 fput_light(sock->file, fput_needed);
76346 out:
76347 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76348 int, addrlen)
76349 {
76350 struct socket *sock;
76351 + struct sockaddr *sck;
76352 struct sockaddr_storage address;
76353 int err, fput_needed;
76354
76355 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76356 if (err < 0)
76357 goto out_put;
76358
76359 + sck = (struct sockaddr *)&address;
76360 +
76361 + if (gr_handle_sock_client(sck)) {
76362 + err = -EACCES;
76363 + goto out_put;
76364 + }
76365 +
76366 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
76367 + if (err)
76368 + goto out_put;
76369 +
76370 err =
76371 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
76372 if (err)
76373 @@ -1970,7 +2030,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
76374 * checking falls down on this.
76375 */
76376 if (copy_from_user(ctl_buf,
76377 - (void __user __force *)msg_sys->msg_control,
76378 + (void __force_user *)msg_sys->msg_control,
76379 ctl_len))
76380 goto out_freectl;
76381 msg_sys->msg_control = ctl_buf;
76382 @@ -2140,7 +2200,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
76383 * kernel msghdr to use the kernel address space)
76384 */
76385
76386 - uaddr = (__force void __user *)msg_sys->msg_name;
76387 + uaddr = (void __force_user *)msg_sys->msg_name;
76388 uaddr_len = COMPAT_NAMELEN(msg);
76389 if (MSG_CMSG_COMPAT & flags) {
76390 err = verify_compat_iovec(msg_sys, iov,
76391 @@ -2768,7 +2828,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76392 }
76393
76394 ifr = compat_alloc_user_space(buf_size);
76395 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
76396 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
76397
76398 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
76399 return -EFAULT;
76400 @@ -2792,12 +2852,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76401 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
76402
76403 if (copy_in_user(rxnfc, compat_rxnfc,
76404 - (void *)(&rxnfc->fs.m_ext + 1) -
76405 - (void *)rxnfc) ||
76406 + (void __user *)(&rxnfc->fs.m_ext + 1) -
76407 + (void __user *)rxnfc) ||
76408 copy_in_user(&rxnfc->fs.ring_cookie,
76409 &compat_rxnfc->fs.ring_cookie,
76410 - (void *)(&rxnfc->fs.location + 1) -
76411 - (void *)&rxnfc->fs.ring_cookie) ||
76412 + (void __user *)(&rxnfc->fs.location + 1) -
76413 + (void __user *)&rxnfc->fs.ring_cookie) ||
76414 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
76415 sizeof(rxnfc->rule_cnt)))
76416 return -EFAULT;
76417 @@ -2809,12 +2869,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76418
76419 if (convert_out) {
76420 if (copy_in_user(compat_rxnfc, rxnfc,
76421 - (const void *)(&rxnfc->fs.m_ext + 1) -
76422 - (const void *)rxnfc) ||
76423 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
76424 + (const void __user *)rxnfc) ||
76425 copy_in_user(&compat_rxnfc->fs.ring_cookie,
76426 &rxnfc->fs.ring_cookie,
76427 - (const void *)(&rxnfc->fs.location + 1) -
76428 - (const void *)&rxnfc->fs.ring_cookie) ||
76429 + (const void __user *)(&rxnfc->fs.location + 1) -
76430 + (const void __user *)&rxnfc->fs.ring_cookie) ||
76431 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
76432 sizeof(rxnfc->rule_cnt)))
76433 return -EFAULT;
76434 @@ -2884,7 +2944,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
76435 old_fs = get_fs();
76436 set_fs(KERNEL_DS);
76437 err = dev_ioctl(net, cmd,
76438 - (struct ifreq __user __force *) &kifr);
76439 + (struct ifreq __force_user *) &kifr);
76440 set_fs(old_fs);
76441
76442 return err;
76443 @@ -2993,7 +3053,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
76444
76445 old_fs = get_fs();
76446 set_fs(KERNEL_DS);
76447 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
76448 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
76449 set_fs(old_fs);
76450
76451 if (cmd == SIOCGIFMAP && !err) {
76452 @@ -3098,7 +3158,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
76453 ret |= __get_user(rtdev, &(ur4->rt_dev));
76454 if (rtdev) {
76455 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
76456 - r4.rt_dev = (char __user __force *)devname;
76457 + r4.rt_dev = (char __force_user *)devname;
76458 devname[15] = 0;
76459 } else
76460 r4.rt_dev = NULL;
76461 @@ -3324,8 +3384,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
76462 int __user *uoptlen;
76463 int err;
76464
76465 - uoptval = (char __user __force *) optval;
76466 - uoptlen = (int __user __force *) optlen;
76467 + uoptval = (char __force_user *) optval;
76468 + uoptlen = (int __force_user *) optlen;
76469
76470 set_fs(KERNEL_DS);
76471 if (level == SOL_SOCKET)
76472 @@ -3345,7 +3405,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
76473 char __user *uoptval;
76474 int err;
76475
76476 - uoptval = (char __user __force *) optval;
76477 + uoptval = (char __force_user *) optval;
76478
76479 set_fs(KERNEL_DS);
76480 if (level == SOL_SOCKET)
76481 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
76482 index 8efd96c..b492ab2 100644
76483 --- a/net/sunrpc/sched.c
76484 +++ b/net/sunrpc/sched.c
76485 @@ -239,9 +239,9 @@ static int rpc_wait_bit_killable(void *word)
76486 #ifdef RPC_DEBUG
76487 static void rpc_task_set_debuginfo(struct rpc_task *task)
76488 {
76489 - static atomic_t rpc_pid;
76490 + static atomic_unchecked_t rpc_pid;
76491
76492 - task->tk_pid = atomic_inc_return(&rpc_pid);
76493 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
76494 }
76495 #else
76496 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
76497 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
76498 index 4645709..d41d668 100644
76499 --- a/net/sunrpc/svcsock.c
76500 +++ b/net/sunrpc/svcsock.c
76501 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
76502 int buflen, unsigned int base)
76503 {
76504 size_t save_iovlen;
76505 - void __user *save_iovbase;
76506 + void *save_iovbase;
76507 unsigned int i;
76508 int ret;
76509
76510 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
76511 index 09af4fa..77110a9 100644
76512 --- a/net/sunrpc/xprtrdma/svc_rdma.c
76513 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
76514 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
76515 static unsigned int min_max_inline = 4096;
76516 static unsigned int max_max_inline = 65536;
76517
76518 -atomic_t rdma_stat_recv;
76519 -atomic_t rdma_stat_read;
76520 -atomic_t rdma_stat_write;
76521 -atomic_t rdma_stat_sq_starve;
76522 -atomic_t rdma_stat_rq_starve;
76523 -atomic_t rdma_stat_rq_poll;
76524 -atomic_t rdma_stat_rq_prod;
76525 -atomic_t rdma_stat_sq_poll;
76526 -atomic_t rdma_stat_sq_prod;
76527 +atomic_unchecked_t rdma_stat_recv;
76528 +atomic_unchecked_t rdma_stat_read;
76529 +atomic_unchecked_t rdma_stat_write;
76530 +atomic_unchecked_t rdma_stat_sq_starve;
76531 +atomic_unchecked_t rdma_stat_rq_starve;
76532 +atomic_unchecked_t rdma_stat_rq_poll;
76533 +atomic_unchecked_t rdma_stat_rq_prod;
76534 +atomic_unchecked_t rdma_stat_sq_poll;
76535 +atomic_unchecked_t rdma_stat_sq_prod;
76536
76537 /* Temporary NFS request map and context caches */
76538 struct kmem_cache *svc_rdma_map_cachep;
76539 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
76540 len -= *ppos;
76541 if (len > *lenp)
76542 len = *lenp;
76543 - if (len && copy_to_user(buffer, str_buf, len))
76544 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
76545 return -EFAULT;
76546 *lenp = len;
76547 *ppos += len;
76548 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
76549 {
76550 .procname = "rdma_stat_read",
76551 .data = &rdma_stat_read,
76552 - .maxlen = sizeof(atomic_t),
76553 + .maxlen = sizeof(atomic_unchecked_t),
76554 .mode = 0644,
76555 .proc_handler = read_reset_stat,
76556 },
76557 {
76558 .procname = "rdma_stat_recv",
76559 .data = &rdma_stat_recv,
76560 - .maxlen = sizeof(atomic_t),
76561 + .maxlen = sizeof(atomic_unchecked_t),
76562 .mode = 0644,
76563 .proc_handler = read_reset_stat,
76564 },
76565 {
76566 .procname = "rdma_stat_write",
76567 .data = &rdma_stat_write,
76568 - .maxlen = sizeof(atomic_t),
76569 + .maxlen = sizeof(atomic_unchecked_t),
76570 .mode = 0644,
76571 .proc_handler = read_reset_stat,
76572 },
76573 {
76574 .procname = "rdma_stat_sq_starve",
76575 .data = &rdma_stat_sq_starve,
76576 - .maxlen = sizeof(atomic_t),
76577 + .maxlen = sizeof(atomic_unchecked_t),
76578 .mode = 0644,
76579 .proc_handler = read_reset_stat,
76580 },
76581 {
76582 .procname = "rdma_stat_rq_starve",
76583 .data = &rdma_stat_rq_starve,
76584 - .maxlen = sizeof(atomic_t),
76585 + .maxlen = sizeof(atomic_unchecked_t),
76586 .mode = 0644,
76587 .proc_handler = read_reset_stat,
76588 },
76589 {
76590 .procname = "rdma_stat_rq_poll",
76591 .data = &rdma_stat_rq_poll,
76592 - .maxlen = sizeof(atomic_t),
76593 + .maxlen = sizeof(atomic_unchecked_t),
76594 .mode = 0644,
76595 .proc_handler = read_reset_stat,
76596 },
76597 {
76598 .procname = "rdma_stat_rq_prod",
76599 .data = &rdma_stat_rq_prod,
76600 - .maxlen = sizeof(atomic_t),
76601 + .maxlen = sizeof(atomic_unchecked_t),
76602 .mode = 0644,
76603 .proc_handler = read_reset_stat,
76604 },
76605 {
76606 .procname = "rdma_stat_sq_poll",
76607 .data = &rdma_stat_sq_poll,
76608 - .maxlen = sizeof(atomic_t),
76609 + .maxlen = sizeof(atomic_unchecked_t),
76610 .mode = 0644,
76611 .proc_handler = read_reset_stat,
76612 },
76613 {
76614 .procname = "rdma_stat_sq_prod",
76615 .data = &rdma_stat_sq_prod,
76616 - .maxlen = sizeof(atomic_t),
76617 + .maxlen = sizeof(atomic_unchecked_t),
76618 .mode = 0644,
76619 .proc_handler = read_reset_stat,
76620 },
76621 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
76622 index df67211..c354b13 100644
76623 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
76624 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
76625 @@ -499,7 +499,7 @@ next_sge:
76626 svc_rdma_put_context(ctxt, 0);
76627 goto out;
76628 }
76629 - atomic_inc(&rdma_stat_read);
76630 + atomic_inc_unchecked(&rdma_stat_read);
76631
76632 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
76633 chl_map->ch[ch_no].count -= read_wr.num_sge;
76634 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
76635 dto_q);
76636 list_del_init(&ctxt->dto_q);
76637 } else {
76638 - atomic_inc(&rdma_stat_rq_starve);
76639 + atomic_inc_unchecked(&rdma_stat_rq_starve);
76640 clear_bit(XPT_DATA, &xprt->xpt_flags);
76641 ctxt = NULL;
76642 }
76643 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
76644 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
76645 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
76646 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
76647 - atomic_inc(&rdma_stat_recv);
76648 + atomic_inc_unchecked(&rdma_stat_recv);
76649
76650 /* Build up the XDR from the receive buffers. */
76651 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
76652 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
76653 index 249a835..fb2794b 100644
76654 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
76655 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
76656 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
76657 write_wr.wr.rdma.remote_addr = to;
76658
76659 /* Post It */
76660 - atomic_inc(&rdma_stat_write);
76661 + atomic_inc_unchecked(&rdma_stat_write);
76662 if (svc_rdma_send(xprt, &write_wr))
76663 goto err;
76664 return 0;
76665 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
76666 index 894cb42..cf5bafb 100644
76667 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
76668 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
76669 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
76670 return;
76671
76672 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
76673 - atomic_inc(&rdma_stat_rq_poll);
76674 + atomic_inc_unchecked(&rdma_stat_rq_poll);
76675
76676 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
76677 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
76678 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
76679 }
76680
76681 if (ctxt)
76682 - atomic_inc(&rdma_stat_rq_prod);
76683 + atomic_inc_unchecked(&rdma_stat_rq_prod);
76684
76685 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
76686 /*
76687 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
76688 return;
76689
76690 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
76691 - atomic_inc(&rdma_stat_sq_poll);
76692 + atomic_inc_unchecked(&rdma_stat_sq_poll);
76693 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
76694 if (wc.status != IB_WC_SUCCESS)
76695 /* Close the transport */
76696 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
76697 }
76698
76699 if (ctxt)
76700 - atomic_inc(&rdma_stat_sq_prod);
76701 + atomic_inc_unchecked(&rdma_stat_sq_prod);
76702 }
76703
76704 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
76705 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
76706 spin_lock_bh(&xprt->sc_lock);
76707 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
76708 spin_unlock_bh(&xprt->sc_lock);
76709 - atomic_inc(&rdma_stat_sq_starve);
76710 + atomic_inc_unchecked(&rdma_stat_sq_starve);
76711
76712 /* See if we can opportunistically reap SQ WR to make room */
76713 sq_cq_reap(xprt);
76714 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
76715 index e758139..d29ea47 100644
76716 --- a/net/sysctl_net.c
76717 +++ b/net/sysctl_net.c
76718 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
76719 struct ctl_table *table)
76720 {
76721 /* Allow network administrator to have same access as root. */
76722 - if (capable(CAP_NET_ADMIN)) {
76723 + if (capable_nolog(CAP_NET_ADMIN)) {
76724 int mode = (table->mode >> 6) & 7;
76725 return (mode << 6) | (mode << 3) | mode;
76726 }
76727 diff --git a/net/tipc/link.c b/net/tipc/link.c
76728 index ac1832a..533ed97 100644
76729 --- a/net/tipc/link.c
76730 +++ b/net/tipc/link.c
76731 @@ -1205,7 +1205,7 @@ static int link_send_sections_long(struct tipc_port *sender,
76732 struct tipc_msg fragm_hdr;
76733 struct sk_buff *buf, *buf_chain, *prev;
76734 u32 fragm_crs, fragm_rest, hsz, sect_rest;
76735 - const unchar *sect_crs;
76736 + const unchar __user *sect_crs;
76737 int curr_sect;
76738 u32 fragm_no;
76739
76740 @@ -1249,7 +1249,7 @@ again:
76741
76742 if (!sect_rest) {
76743 sect_rest = msg_sect[++curr_sect].iov_len;
76744 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
76745 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
76746 }
76747
76748 if (sect_rest < fragm_rest)
76749 @@ -1268,7 +1268,7 @@ error:
76750 }
76751 } else
76752 skb_copy_to_linear_data_offset(buf, fragm_crs,
76753 - sect_crs, sz);
76754 + (const void __force_kernel *)sect_crs, sz);
76755 sect_crs += sz;
76756 sect_rest -= sz;
76757 fragm_crs += sz;
76758 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
76759 index 3e4d3e2..27b55dc 100644
76760 --- a/net/tipc/msg.c
76761 +++ b/net/tipc/msg.c
76762 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
76763 msg_sect[cnt].iov_len);
76764 else
76765 skb_copy_to_linear_data_offset(*buf, pos,
76766 - msg_sect[cnt].iov_base,
76767 + (const void __force_kernel *)msg_sect[cnt].iov_base,
76768 msg_sect[cnt].iov_len);
76769 pos += msg_sect[cnt].iov_len;
76770 }
76771 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
76772 index 8c49566..14510cb 100644
76773 --- a/net/tipc/subscr.c
76774 +++ b/net/tipc/subscr.c
76775 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
76776 {
76777 struct iovec msg_sect;
76778
76779 - msg_sect.iov_base = (void *)&sub->evt;
76780 + msg_sect.iov_base = (void __force_user *)&sub->evt;
76781 msg_sect.iov_len = sizeof(struct tipc_event);
76782
76783 sub->evt.event = htohl(event, sub->swap);
76784 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
76785 index 85d3bb7..79f4487 100644
76786 --- a/net/unix/af_unix.c
76787 +++ b/net/unix/af_unix.c
76788 @@ -770,6 +770,12 @@ static struct sock *unix_find_other(struct net *net,
76789 err = -ECONNREFUSED;
76790 if (!S_ISSOCK(inode->i_mode))
76791 goto put_fail;
76792 +
76793 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
76794 + err = -EACCES;
76795 + goto put_fail;
76796 + }
76797 +
76798 u = unix_find_socket_byinode(inode);
76799 if (!u)
76800 goto put_fail;
76801 @@ -790,6 +796,13 @@ static struct sock *unix_find_other(struct net *net,
76802 if (u) {
76803 struct dentry *dentry;
76804 dentry = unix_sk(u)->dentry;
76805 +
76806 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
76807 + err = -EPERM;
76808 + sock_put(u);
76809 + goto fail;
76810 + }
76811 +
76812 if (dentry)
76813 touch_atime(unix_sk(u)->mnt, dentry);
76814 } else
76815 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
76816 err = security_path_mknod(&path, dentry, mode, 0);
76817 if (err)
76818 goto out_mknod_drop_write;
76819 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
76820 + err = -EACCES;
76821 + goto out_mknod_drop_write;
76822 + }
76823 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
76824 out_mknod_drop_write:
76825 mnt_drop_write(path.mnt);
76826 if (err)
76827 goto out_mknod_dput;
76828 +
76829 + gr_handle_create(dentry, path.mnt);
76830 +
76831 mutex_unlock(&path.dentry->d_inode->i_mutex);
76832 dput(path.dentry);
76833 path.dentry = dentry;
76834 diff --git a/net/wireless/core.h b/net/wireless/core.h
76835 index 43ad9c8..ab5127c 100644
76836 --- a/net/wireless/core.h
76837 +++ b/net/wireless/core.h
76838 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
76839 struct mutex mtx;
76840
76841 /* rfkill support */
76842 - struct rfkill_ops rfkill_ops;
76843 + rfkill_ops_no_const rfkill_ops;
76844 struct rfkill *rfkill;
76845 struct work_struct rfkill_sync;
76846
76847 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
76848 index 0af7f54..c916d2f 100644
76849 --- a/net/wireless/wext-core.c
76850 +++ b/net/wireless/wext-core.c
76851 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
76852 */
76853
76854 /* Support for very large requests */
76855 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
76856 - (user_length > descr->max_tokens)) {
76857 + if (user_length > descr->max_tokens) {
76858 /* Allow userspace to GET more than max so
76859 * we can support any size GET requests.
76860 * There is still a limit : -ENOMEM.
76861 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
76862 }
76863 }
76864
76865 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
76866 - /*
76867 - * If this is a GET, but not NOMAX, it means that the extra
76868 - * data is not bounded by userspace, but by max_tokens. Thus
76869 - * set the length to max_tokens. This matches the extra data
76870 - * allocation.
76871 - * The driver should fill it with the number of tokens it
76872 - * provided, and it may check iwp->length rather than having
76873 - * knowledge of max_tokens. If the driver doesn't change the
76874 - * iwp->length, this ioctl just copies back max_token tokens
76875 - * filled with zeroes. Hopefully the driver isn't claiming
76876 - * them to be valid data.
76877 - */
76878 - iwp->length = descr->max_tokens;
76879 - }
76880 -
76881 err = handler(dev, info, (union iwreq_data *) iwp, extra);
76882
76883 iwp->length += essid_compat;
76884 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
76885 index 7661576..80f7627 100644
76886 --- a/net/xfrm/xfrm_policy.c
76887 +++ b/net/xfrm/xfrm_policy.c
76888 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
76889 {
76890 policy->walk.dead = 1;
76891
76892 - atomic_inc(&policy->genid);
76893 + atomic_inc_unchecked(&policy->genid);
76894
76895 if (del_timer(&policy->timer))
76896 xfrm_pol_put(policy);
76897 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
76898 hlist_add_head(&policy->bydst, chain);
76899 xfrm_pol_hold(policy);
76900 net->xfrm.policy_count[dir]++;
76901 - atomic_inc(&flow_cache_genid);
76902 + atomic_inc_unchecked(&flow_cache_genid);
76903 if (delpol)
76904 __xfrm_policy_unlink(delpol, dir);
76905 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
76906 @@ -1530,7 +1530,7 @@ free_dst:
76907 goto out;
76908 }
76909
76910 -static int inline
76911 +static inline int
76912 xfrm_dst_alloc_copy(void **target, const void *src, int size)
76913 {
76914 if (!*target) {
76915 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
76916 return 0;
76917 }
76918
76919 -static int inline
76920 +static inline int
76921 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
76922 {
76923 #ifdef CONFIG_XFRM_SUB_POLICY
76924 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
76925 #endif
76926 }
76927
76928 -static int inline
76929 +static inline int
76930 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
76931 {
76932 #ifdef CONFIG_XFRM_SUB_POLICY
76933 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
76934
76935 xdst->num_pols = num_pols;
76936 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
76937 - xdst->policy_genid = atomic_read(&pols[0]->genid);
76938 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
76939
76940 return xdst;
76941 }
76942 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
76943 if (xdst->xfrm_genid != dst->xfrm->genid)
76944 return 0;
76945 if (xdst->num_pols > 0 &&
76946 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
76947 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
76948 return 0;
76949
76950 mtu = dst_mtu(dst->child);
76951 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
76952 sizeof(pol->xfrm_vec[i].saddr));
76953 pol->xfrm_vec[i].encap_family = mp->new_family;
76954 /* flush bundles */
76955 - atomic_inc(&pol->genid);
76956 + atomic_inc_unchecked(&pol->genid);
76957 }
76958 }
76959
76960 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
76961 index d2b366c..51ff91ebc 100644
76962 --- a/scripts/Makefile.build
76963 +++ b/scripts/Makefile.build
76964 @@ -109,7 +109,7 @@ endif
76965 endif
76966
76967 # Do not include host rules unless needed
76968 -ifneq ($(hostprogs-y)$(hostprogs-m),)
76969 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
76970 include scripts/Makefile.host
76971 endif
76972
76973 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
76974 index 686cb0d..9d653bf 100644
76975 --- a/scripts/Makefile.clean
76976 +++ b/scripts/Makefile.clean
76977 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
76978 __clean-files := $(extra-y) $(always) \
76979 $(targets) $(clean-files) \
76980 $(host-progs) \
76981 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
76982 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
76983 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
76984
76985 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
76986
76987 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
76988 index 1ac414f..a1c1451 100644
76989 --- a/scripts/Makefile.host
76990 +++ b/scripts/Makefile.host
76991 @@ -31,6 +31,7 @@
76992 # Note: Shared libraries consisting of C++ files are not supported
76993
76994 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
76995 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
76996
76997 # C code
76998 # Executables compiled from a single .c file
76999 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
77000 # Shared libaries (only .c supported)
77001 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
77002 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
77003 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
77004 # Remove .so files from "xxx-objs"
77005 host-cobjs := $(filter-out %.so,$(host-cobjs))
77006
77007 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
77008 index cb1f50c..cef2a7c 100644
77009 --- a/scripts/basic/fixdep.c
77010 +++ b/scripts/basic/fixdep.c
77011 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
77012 /*
77013 * Lookup a value in the configuration string.
77014 */
77015 -static int is_defined_config(const char *name, int len, unsigned int hash)
77016 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
77017 {
77018 struct item *aux;
77019
77020 @@ -211,10 +211,10 @@ static void clear_config(void)
77021 /*
77022 * Record the use of a CONFIG_* word.
77023 */
77024 -static void use_config(const char *m, int slen)
77025 +static void use_config(const char *m, unsigned int slen)
77026 {
77027 unsigned int hash = strhash(m, slen);
77028 - int c, i;
77029 + unsigned int c, i;
77030
77031 if (is_defined_config(m, slen, hash))
77032 return;
77033 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
77034
77035 static void parse_config_file(const char *map, size_t len)
77036 {
77037 - const int *end = (const int *) (map + len);
77038 + const unsigned int *end = (const unsigned int *) (map + len);
77039 /* start at +1, so that p can never be < map */
77040 - const int *m = (const int *) map + 1;
77041 + const unsigned int *m = (const unsigned int *) map + 1;
77042 const char *p, *q;
77043
77044 for (; m < end; m++) {
77045 @@ -406,7 +406,7 @@ static void print_deps(void)
77046 static void traps(void)
77047 {
77048 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
77049 - int *p = (int *)test;
77050 + unsigned int *p = (unsigned int *)test;
77051
77052 if (*p != INT_CONF) {
77053 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
77054 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
77055 new file mode 100644
77056 index 0000000..8729101
77057 --- /dev/null
77058 +++ b/scripts/gcc-plugin.sh
77059 @@ -0,0 +1,2 @@
77060 +#!/bin/sh
77061 +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"
77062 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
77063 index b89efe6..2c30808 100644
77064 --- a/scripts/mod/file2alias.c
77065 +++ b/scripts/mod/file2alias.c
77066 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
77067 unsigned long size, unsigned long id_size,
77068 void *symval)
77069 {
77070 - int i;
77071 + unsigned int i;
77072
77073 if (size % id_size || size < id_size) {
77074 if (cross_build != 0)
77075 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
77076 /* USB is special because the bcdDevice can be matched against a numeric range */
77077 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
77078 static void do_usb_entry(struct usb_device_id *id,
77079 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
77080 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
77081 unsigned char range_lo, unsigned char range_hi,
77082 unsigned char max, struct module *mod)
77083 {
77084 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
77085 {
77086 unsigned int devlo, devhi;
77087 unsigned char chi, clo, max;
77088 - int ndigits;
77089 + unsigned int ndigits;
77090
77091 id->match_flags = TO_NATIVE(id->match_flags);
77092 id->idVendor = TO_NATIVE(id->idVendor);
77093 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
77094 for (i = 0; i < count; i++) {
77095 const char *id = (char *)devs[i].id;
77096 char acpi_id[sizeof(devs[0].id)];
77097 - int j;
77098 + unsigned int j;
77099
77100 buf_printf(&mod->dev_table_buf,
77101 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77102 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77103
77104 for (j = 0; j < PNP_MAX_DEVICES; j++) {
77105 const char *id = (char *)card->devs[j].id;
77106 - int i2, j2;
77107 + unsigned int i2, j2;
77108 int dup = 0;
77109
77110 if (!id[0])
77111 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77112 /* add an individual alias for every device entry */
77113 if (!dup) {
77114 char acpi_id[sizeof(card->devs[0].id)];
77115 - int k;
77116 + unsigned int k;
77117
77118 buf_printf(&mod->dev_table_buf,
77119 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77120 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
77121 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
77122 char *alias)
77123 {
77124 - int i, j;
77125 + unsigned int i, j;
77126
77127 sprintf(alias, "dmi*");
77128
77129 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
77130 index 9adb667..c6ac044 100644
77131 --- a/scripts/mod/modpost.c
77132 +++ b/scripts/mod/modpost.c
77133 @@ -919,6 +919,7 @@ enum mismatch {
77134 ANY_INIT_TO_ANY_EXIT,
77135 ANY_EXIT_TO_ANY_INIT,
77136 EXPORT_TO_INIT_EXIT,
77137 + DATA_TO_TEXT
77138 };
77139
77140 struct sectioncheck {
77141 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
77142 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
77143 .mismatch = EXPORT_TO_INIT_EXIT,
77144 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
77145 +},
77146 +/* Do not reference code from writable data */
77147 +{
77148 + .fromsec = { DATA_SECTIONS, NULL },
77149 + .tosec = { TEXT_SECTIONS, NULL },
77150 + .mismatch = DATA_TO_TEXT
77151 }
77152 };
77153
77154 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
77155 continue;
77156 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
77157 continue;
77158 - if (sym->st_value == addr)
77159 - return sym;
77160 /* Find a symbol nearby - addr are maybe negative */
77161 d = sym->st_value - addr;
77162 + if (d == 0)
77163 + return sym;
77164 if (d < 0)
77165 d = addr - sym->st_value;
77166 if (d < distance) {
77167 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
77168 tosym, prl_to, prl_to, tosym);
77169 free(prl_to);
77170 break;
77171 + case DATA_TO_TEXT:
77172 +/*
77173 + fprintf(stderr,
77174 + "The variable %s references\n"
77175 + "the %s %s%s%s\n",
77176 + fromsym, to, sec2annotation(tosec), tosym, to_p);
77177 +*/
77178 + break;
77179 }
77180 fprintf(stderr, "\n");
77181 }
77182 @@ -1665,7 +1680,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
77183 static void check_sec_ref(struct module *mod, const char *modname,
77184 struct elf_info *elf)
77185 {
77186 - int i;
77187 + unsigned int i;
77188 Elf_Shdr *sechdrs = elf->sechdrs;
77189
77190 /* Walk through all sections */
77191 @@ -1763,7 +1778,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
77192 va_end(ap);
77193 }
77194
77195 -void buf_write(struct buffer *buf, const char *s, int len)
77196 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
77197 {
77198 if (buf->size - buf->pos < len) {
77199 buf->size += len + SZ;
77200 @@ -1981,7 +1996,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
77201 if (fstat(fileno(file), &st) < 0)
77202 goto close_write;
77203
77204 - if (st.st_size != b->pos)
77205 + if (st.st_size != (off_t)b->pos)
77206 goto close_write;
77207
77208 tmp = NOFAIL(malloc(b->pos));
77209 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
77210 index 2031119..b5433af 100644
77211 --- a/scripts/mod/modpost.h
77212 +++ b/scripts/mod/modpost.h
77213 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
77214
77215 struct buffer {
77216 char *p;
77217 - int pos;
77218 - int size;
77219 + unsigned int pos;
77220 + unsigned int size;
77221 };
77222
77223 void __attribute__((format(printf, 2, 3)))
77224 buf_printf(struct buffer *buf, const char *fmt, ...);
77225
77226 void
77227 -buf_write(struct buffer *buf, const char *s, int len);
77228 +buf_write(struct buffer *buf, const char *s, unsigned int len);
77229
77230 struct module {
77231 struct module *next;
77232 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
77233 index 9dfcd6d..099068e 100644
77234 --- a/scripts/mod/sumversion.c
77235 +++ b/scripts/mod/sumversion.c
77236 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
77237 goto out;
77238 }
77239
77240 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
77241 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
77242 warn("writing sum in %s failed: %s\n",
77243 filename, strerror(errno));
77244 goto out;
77245 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
77246 index 5c11312..72742b5 100644
77247 --- a/scripts/pnmtologo.c
77248 +++ b/scripts/pnmtologo.c
77249 @@ -237,14 +237,14 @@ static void write_header(void)
77250 fprintf(out, " * Linux logo %s\n", logoname);
77251 fputs(" */\n\n", out);
77252 fputs("#include <linux/linux_logo.h>\n\n", out);
77253 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
77254 + fprintf(out, "static unsigned char %s_data[] = {\n",
77255 logoname);
77256 }
77257
77258 static void write_footer(void)
77259 {
77260 fputs("\n};\n\n", out);
77261 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
77262 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
77263 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
77264 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
77265 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
77266 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
77267 fputs("\n};\n\n", out);
77268
77269 /* write logo clut */
77270 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
77271 + fprintf(out, "static unsigned char %s_clut[] = {\n",
77272 logoname);
77273 write_hex_cnt = 0;
77274 for (i = 0; i < logo_clutsize; i++) {
77275 diff --git a/security/Kconfig b/security/Kconfig
77276 index 51bd5a0..3a4ebd0 100644
77277 --- a/security/Kconfig
77278 +++ b/security/Kconfig
77279 @@ -4,6 +4,627 @@
77280
77281 menu "Security options"
77282
77283 +source grsecurity/Kconfig
77284 +
77285 +menu "PaX"
77286 +
77287 + config ARCH_TRACK_EXEC_LIMIT
77288 + bool
77289 +
77290 + config PAX_KERNEXEC_PLUGIN
77291 + bool
77292 +
77293 + config PAX_PER_CPU_PGD
77294 + bool
77295 +
77296 + config TASK_SIZE_MAX_SHIFT
77297 + int
77298 + depends on X86_64
77299 + default 47 if !PAX_PER_CPU_PGD
77300 + default 42 if PAX_PER_CPU_PGD
77301 +
77302 + config PAX_ENABLE_PAE
77303 + bool
77304 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
77305 +
77306 +config PAX
77307 + bool "Enable various PaX features"
77308 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
77309 + help
77310 + This allows you to enable various PaX features. PaX adds
77311 + intrusion prevention mechanisms to the kernel that reduce
77312 + the risks posed by exploitable memory corruption bugs.
77313 +
77314 +menu "PaX Control"
77315 + depends on PAX
77316 +
77317 +config PAX_SOFTMODE
77318 + bool 'Support soft mode'
77319 + help
77320 + Enabling this option will allow you to run PaX in soft mode, that
77321 + is, PaX features will not be enforced by default, only on executables
77322 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
77323 + support as they are the only way to mark executables for soft mode use.
77324 +
77325 + Soft mode can be activated by using the "pax_softmode=1" kernel command
77326 + line option on boot. Furthermore you can control various PaX features
77327 + at runtime via the entries in /proc/sys/kernel/pax.
77328 +
77329 +config PAX_EI_PAX
77330 + bool 'Use legacy ELF header marking'
77331 + help
77332 + Enabling this option will allow you to control PaX features on
77333 + a per executable basis via the 'chpax' utility available at
77334 + http://pax.grsecurity.net/. The control flags will be read from
77335 + an otherwise reserved part of the ELF header. This marking has
77336 + numerous drawbacks (no support for soft-mode, toolchain does not
77337 + know about the non-standard use of the ELF header) therefore it
77338 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
77339 + support.
77340 +
77341 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77342 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
77343 + option otherwise they will not get any protection.
77344 +
77345 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
77346 + support as well, they will override the legacy EI_PAX marks.
77347 +
77348 +config PAX_PT_PAX_FLAGS
77349 + bool 'Use ELF program header marking'
77350 + help
77351 + Enabling this option will allow you to control PaX features on
77352 + a per executable basis via the 'paxctl' utility available at
77353 + http://pax.grsecurity.net/. The control flags will be read from
77354 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
77355 + has the benefits of supporting both soft mode and being fully
77356 + integrated into the toolchain (the binutils patch is available
77357 + from http://pax.grsecurity.net).
77358 +
77359 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77360 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
77361 + support otherwise they will not get any protection.
77362 +
77363 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
77364 + must make sure that the marks are the same if a binary has both marks.
77365 +
77366 + Note that if you enable the legacy EI_PAX marking support as well,
77367 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
77368 +
77369 +config PAX_XATTR_PAX_FLAGS
77370 + bool 'Use filesystem extended attributes marking'
77371 + depends on EXPERT
77372 + select CIFS_XATTR if CIFS
77373 + select EXT2_FS_XATTR if EXT2_FS
77374 + select EXT3_FS_XATTR if EXT3_FS
77375 + select EXT4_FS_XATTR if EXT4_FS
77376 + select JFFS2_FS_XATTR if JFFS2_FS
77377 + select REISERFS_FS_XATTR if REISERFS_FS
77378 + select SQUASHFS_XATTR if SQUASHFS
77379 + select TMPFS_XATTR if TMPFS
77380 + select UBIFS_FS_XATTR if UBIFS_FS
77381 + help
77382 + Enabling this option will allow you to control PaX features on
77383 + a per executable basis via the 'setfattr' utility. The control
77384 + flags will be read from the user.pax.flags extended attribute of
77385 + the file. This marking has the benefit of supporting binary-only
77386 + applications that self-check themselves (e.g., skype) and would
77387 + not tolerate chpax/paxctl changes. The main drawback is that
77388 + extended attributes are not supported by some filesystems (e.g.,
77389 + isofs, udf, vfat) so copying files through such filesystems will
77390 + lose the extended attributes and these PaX markings.
77391 +
77392 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77393 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
77394 + support otherwise they will not get any protection.
77395 +
77396 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
77397 + must make sure that the marks are the same if a binary has both marks.
77398 +
77399 + Note that if you enable the legacy EI_PAX marking support as well,
77400 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
77401 +
77402 +choice
77403 + prompt 'MAC system integration'
77404 + default PAX_HAVE_ACL_FLAGS
77405 + help
77406 + Mandatory Access Control systems have the option of controlling
77407 + PaX flags on a per executable basis, choose the method supported
77408 + by your particular system.
77409 +
77410 + - "none": if your MAC system does not interact with PaX,
77411 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
77412 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
77413 +
77414 + NOTE: this option is for developers/integrators only.
77415 +
77416 + config PAX_NO_ACL_FLAGS
77417 + bool 'none'
77418 +
77419 + config PAX_HAVE_ACL_FLAGS
77420 + bool 'direct'
77421 +
77422 + config PAX_HOOK_ACL_FLAGS
77423 + bool 'hook'
77424 +endchoice
77425 +
77426 +endmenu
77427 +
77428 +menu "Non-executable pages"
77429 + depends on PAX
77430 +
77431 +config PAX_NOEXEC
77432 + bool "Enforce non-executable pages"
77433 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
77434 + help
77435 + By design some architectures do not allow for protecting memory
77436 + pages against execution or even if they do, Linux does not make
77437 + use of this feature. In practice this means that if a page is
77438 + readable (such as the stack or heap) it is also executable.
77439 +
77440 + There is a well known exploit technique that makes use of this
77441 + fact and a common programming mistake where an attacker can
77442 + introduce code of his choice somewhere in the attacked program's
77443 + memory (typically the stack or the heap) and then execute it.
77444 +
77445 + If the attacked program was running with different (typically
77446 + higher) privileges than that of the attacker, then he can elevate
77447 + his own privilege level (e.g. get a root shell, write to files for
77448 + which he does not have write access to, etc).
77449 +
77450 + Enabling this option will let you choose from various features
77451 + that prevent the injection and execution of 'foreign' code in
77452 + a program.
77453 +
77454 + This will also break programs that rely on the old behaviour and
77455 + expect that dynamically allocated memory via the malloc() family
77456 + of functions is executable (which it is not). Notable examples
77457 + are the XFree86 4.x server, the java runtime and wine.
77458 +
77459 +config PAX_PAGEEXEC
77460 + bool "Paging based non-executable pages"
77461 + 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)
77462 + select S390_SWITCH_AMODE if S390
77463 + select S390_EXEC_PROTECT if S390
77464 + select ARCH_TRACK_EXEC_LIMIT if X86_32
77465 + help
77466 + This implementation is based on the paging feature of the CPU.
77467 + On i386 without hardware non-executable bit support there is a
77468 + variable but usually low performance impact, however on Intel's
77469 + P4 core based CPUs it is very high so you should not enable this
77470 + for kernels meant to be used on such CPUs.
77471 +
77472 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
77473 + with hardware non-executable bit support there is no performance
77474 + impact, on ppc the impact is negligible.
77475 +
77476 + Note that several architectures require various emulations due to
77477 + badly designed userland ABIs, this will cause a performance impact
77478 + but will disappear as soon as userland is fixed. For example, ppc
77479 + userland MUST have been built with secure-plt by a recent toolchain.
77480 +
77481 +config PAX_SEGMEXEC
77482 + bool "Segmentation based non-executable pages"
77483 + depends on PAX_NOEXEC && X86_32
77484 + help
77485 + This implementation is based on the segmentation feature of the
77486 + CPU and has a very small performance impact, however applications
77487 + will be limited to a 1.5 GB address space instead of the normal
77488 + 3 GB.
77489 +
77490 +config PAX_EMUTRAMP
77491 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
77492 + default y if PARISC
77493 + help
77494 + There are some programs and libraries that for one reason or
77495 + another attempt to execute special small code snippets from
77496 + non-executable memory pages. Most notable examples are the
77497 + signal handler return code generated by the kernel itself and
77498 + the GCC trampolines.
77499 +
77500 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
77501 + such programs will no longer work under your kernel.
77502 +
77503 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
77504 + utilities to enable trampoline emulation for the affected programs
77505 + yet still have the protection provided by the non-executable pages.
77506 +
77507 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
77508 + your system will not even boot.
77509 +
77510 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
77511 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
77512 + for the affected files.
77513 +
77514 + NOTE: enabling this feature *may* open up a loophole in the
77515 + protection provided by non-executable pages that an attacker
77516 + could abuse. Therefore the best solution is to not have any
77517 + files on your system that would require this option. This can
77518 + be achieved by not using libc5 (which relies on the kernel
77519 + signal handler return code) and not using or rewriting programs
77520 + that make use of the nested function implementation of GCC.
77521 + Skilled users can just fix GCC itself so that it implements
77522 + nested function calls in a way that does not interfere with PaX.
77523 +
77524 +config PAX_EMUSIGRT
77525 + bool "Automatically emulate sigreturn trampolines"
77526 + depends on PAX_EMUTRAMP && PARISC
77527 + default y
77528 + help
77529 + Enabling this option will have the kernel automatically detect
77530 + and emulate signal return trampolines executing on the stack
77531 + that would otherwise lead to task termination.
77532 +
77533 + This solution is intended as a temporary one for users with
77534 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
77535 + Modula-3 runtime, etc) or executables linked to such, basically
77536 + everything that does not specify its own SA_RESTORER function in
77537 + normal executable memory like glibc 2.1+ does.
77538 +
77539 + On parisc you MUST enable this option, otherwise your system will
77540 + not even boot.
77541 +
77542 + NOTE: this feature cannot be disabled on a per executable basis
77543 + and since it *does* open up a loophole in the protection provided
77544 + by non-executable pages, the best solution is to not have any
77545 + files on your system that would require this option.
77546 +
77547 +config PAX_MPROTECT
77548 + bool "Restrict mprotect()"
77549 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
77550 + help
77551 + Enabling this option will prevent programs from
77552 + - changing the executable status of memory pages that were
77553 + not originally created as executable,
77554 + - making read-only executable pages writable again,
77555 + - creating executable pages from anonymous memory,
77556 + - making read-only-after-relocations (RELRO) data pages writable again.
77557 +
77558 + You should say Y here to complete the protection provided by
77559 + the enforcement of non-executable pages.
77560 +
77561 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
77562 + this feature on a per file basis.
77563 +
77564 +config PAX_MPROTECT_COMPAT
77565 + bool "Use legacy/compat protection demoting (read help)"
77566 + depends on PAX_MPROTECT
77567 + default n
77568 + help
77569 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
77570 + by sending the proper error code to the application. For some broken
77571 + userland, this can cause problems with Python or other applications. The
77572 + current implementation however allows for applications like clamav to
77573 + detect if JIT compilation/execution is allowed and to fall back gracefully
77574 + to an interpreter-based mode if it does not. While we encourage everyone
77575 + to use the current implementation as-is and push upstream to fix broken
77576 + userland (note that the RWX logging option can assist with this), in some
77577 + environments this may not be possible. Having to disable MPROTECT
77578 + completely on certain binaries reduces the security benefit of PaX,
77579 + so this option is provided for those environments to revert to the old
77580 + behavior.
77581 +
77582 +config PAX_ELFRELOCS
77583 + bool "Allow ELF text relocations (read help)"
77584 + depends on PAX_MPROTECT
77585 + default n
77586 + help
77587 + Non-executable pages and mprotect() restrictions are effective
77588 + in preventing the introduction of new executable code into an
77589 + attacked task's address space. There remain only two venues
77590 + for this kind of attack: if the attacker can execute already
77591 + existing code in the attacked task then he can either have it
77592 + create and mmap() a file containing his code or have it mmap()
77593 + an already existing ELF library that does not have position
77594 + independent code in it and use mprotect() on it to make it
77595 + writable and copy his code there. While protecting against
77596 + the former approach is beyond PaX, the latter can be prevented
77597 + by having only PIC ELF libraries on one's system (which do not
77598 + need to relocate their code). If you are sure this is your case,
77599 + as is the case with all modern Linux distributions, then leave
77600 + this option disabled. You should say 'n' here.
77601 +
77602 +config PAX_ETEXECRELOCS
77603 + bool "Allow ELF ET_EXEC text relocations"
77604 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
77605 + select PAX_ELFRELOCS
77606 + default y
77607 + help
77608 + On some architectures there are incorrectly created applications
77609 + that require text relocations and would not work without enabling
77610 + this option. If you are an alpha, ia64 or parisc user, you should
77611 + enable this option and disable it once you have made sure that
77612 + none of your applications need it.
77613 +
77614 +config PAX_EMUPLT
77615 + bool "Automatically emulate ELF PLT"
77616 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
77617 + default y
77618 + help
77619 + Enabling this option will have the kernel automatically detect
77620 + and emulate the Procedure Linkage Table entries in ELF files.
77621 + On some architectures such entries are in writable memory, and
77622 + become non-executable leading to task termination. Therefore
77623 + it is mandatory that you enable this option on alpha, parisc,
77624 + sparc and sparc64, otherwise your system would not even boot.
77625 +
77626 + NOTE: this feature *does* open up a loophole in the protection
77627 + provided by the non-executable pages, therefore the proper
77628 + solution is to modify the toolchain to produce a PLT that does
77629 + not need to be writable.
77630 +
77631 +config PAX_DLRESOLVE
77632 + bool 'Emulate old glibc resolver stub'
77633 + depends on PAX_EMUPLT && SPARC
77634 + default n
77635 + help
77636 + This option is needed if userland has an old glibc (before 2.4)
77637 + that puts a 'save' instruction into the runtime generated resolver
77638 + stub that needs special emulation.
77639 +
77640 +config PAX_KERNEXEC
77641 + bool "Enforce non-executable kernel pages"
77642 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
77643 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
77644 + select PAX_KERNEXEC_PLUGIN if X86_64
77645 + help
77646 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
77647 + that is, enabling this option will make it harder to inject
77648 + and execute 'foreign' code in kernel memory itself.
77649 +
77650 + Note that on x86_64 kernels there is a known regression when
77651 + this feature and KVM/VMX are both enabled in the host kernel.
77652 +
77653 +choice
77654 + prompt "Return Address Instrumentation Method"
77655 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
77656 + depends on PAX_KERNEXEC_PLUGIN
77657 + help
77658 + Select the method used to instrument function pointer dereferences.
77659 + Note that binary modules cannot be instrumented by this approach.
77660 +
77661 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
77662 + bool "bts"
77663 + help
77664 + This method is compatible with binary only modules but has
77665 + a higher runtime overhead.
77666 +
77667 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
77668 + bool "or"
77669 + depends on !PARAVIRT
77670 + help
77671 + This method is incompatible with binary only modules but has
77672 + a lower runtime overhead.
77673 +endchoice
77674 +
77675 +config PAX_KERNEXEC_PLUGIN_METHOD
77676 + string
77677 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
77678 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
77679 + default ""
77680 +
77681 +config PAX_KERNEXEC_MODULE_TEXT
77682 + int "Minimum amount of memory reserved for module code"
77683 + default "4"
77684 + depends on PAX_KERNEXEC && X86_32 && MODULES
77685 + help
77686 + Due to implementation details the kernel must reserve a fixed
77687 + amount of memory for module code at compile time that cannot be
77688 + changed at runtime. Here you can specify the minimum amount
77689 + in MB that will be reserved. Due to the same implementation
77690 + details this size will always be rounded up to the next 2/4 MB
77691 + boundary (depends on PAE) so the actually available memory for
77692 + module code will usually be more than this minimum.
77693 +
77694 + The default 4 MB should be enough for most users but if you have
77695 + an excessive number of modules (e.g., most distribution configs
77696 + compile many drivers as modules) or use huge modules such as
77697 + nvidia's kernel driver, you will need to adjust this amount.
77698 + A good rule of thumb is to look at your currently loaded kernel
77699 + modules and add up their sizes.
77700 +
77701 +endmenu
77702 +
77703 +menu "Address Space Layout Randomization"
77704 + depends on PAX
77705 +
77706 +config PAX_ASLR
77707 + bool "Address Space Layout Randomization"
77708 + help
77709 + Many if not most exploit techniques rely on the knowledge of
77710 + certain addresses in the attacked program. The following options
77711 + will allow the kernel to apply a certain amount of randomization
77712 + to specific parts of the program thereby forcing an attacker to
77713 + guess them in most cases. Any failed guess will most likely crash
77714 + the attacked program which allows the kernel to detect such attempts
77715 + and react on them. PaX itself provides no reaction mechanisms,
77716 + instead it is strongly encouraged that you make use of Nergal's
77717 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
77718 + (http://www.grsecurity.net/) built-in crash detection features or
77719 + develop one yourself.
77720 +
77721 + By saying Y here you can choose to randomize the following areas:
77722 + - top of the task's kernel stack
77723 + - top of the task's userland stack
77724 + - base address for mmap() requests that do not specify one
77725 + (this includes all libraries)
77726 + - base address of the main executable
77727 +
77728 + It is strongly recommended to say Y here as address space layout
77729 + randomization has negligible impact on performance yet it provides
77730 + a very effective protection.
77731 +
77732 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
77733 + this feature on a per file basis.
77734 +
77735 +config PAX_RANDKSTACK
77736 + bool "Randomize kernel stack base"
77737 + depends on X86_TSC && X86
77738 + help
77739 + By saying Y here the kernel will randomize every task's kernel
77740 + stack on every system call. This will not only force an attacker
77741 + to guess it but also prevent him from making use of possible
77742 + leaked information about it.
77743 +
77744 + Since the kernel stack is a rather scarce resource, randomization
77745 + may cause unexpected stack overflows, therefore you should very
77746 + carefully test your system. Note that once enabled in the kernel
77747 + configuration, this feature cannot be disabled on a per file basis.
77748 +
77749 +config PAX_RANDUSTACK
77750 + bool "Randomize user stack base"
77751 + depends on PAX_ASLR
77752 + help
77753 + By saying Y here the kernel will randomize every task's userland
77754 + stack. The randomization is done in two steps where the second
77755 + one may apply a big amount of shift to the top of the stack and
77756 + cause problems for programs that want to use lots of memory (more
77757 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
77758 + For this reason the second step can be controlled by 'chpax' or
77759 + 'paxctl' on a per file basis.
77760 +
77761 +config PAX_RANDMMAP
77762 + bool "Randomize mmap() base"
77763 + depends on PAX_ASLR
77764 + help
77765 + By saying Y here the kernel will use a randomized base address for
77766 + mmap() requests that do not specify one themselves. As a result
77767 + all dynamically loaded libraries will appear at random addresses
77768 + and therefore be harder to exploit by a technique where an attacker
77769 + attempts to execute library code for his purposes (e.g. spawn a
77770 + shell from an exploited program that is running at an elevated
77771 + privilege level).
77772 +
77773 + Furthermore, if a program is relinked as a dynamic ELF file, its
77774 + base address will be randomized as well, completing the full
77775 + randomization of the address space layout. Attacking such programs
77776 + becomes a guess game. You can find an example of doing this at
77777 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
77778 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
77779 +
77780 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
77781 + feature on a per file basis.
77782 +
77783 +endmenu
77784 +
77785 +menu "Miscellaneous hardening features"
77786 +
77787 +config PAX_MEMORY_SANITIZE
77788 + bool "Sanitize all freed memory"
77789 + depends on !HIBERNATION
77790 + help
77791 + By saying Y here the kernel will erase memory pages as soon as they
77792 + are freed. This in turn reduces the lifetime of data stored in the
77793 + pages, making it less likely that sensitive information such as
77794 + passwords, cryptographic secrets, etc stay in memory for too long.
77795 +
77796 + This is especially useful for programs whose runtime is short, long
77797 + lived processes and the kernel itself benefit from this as long as
77798 + they operate on whole memory pages and ensure timely freeing of pages
77799 + that may hold sensitive information.
77800 +
77801 + The tradeoff is performance impact, on a single CPU system kernel
77802 + compilation sees a 3% slowdown, other systems and workloads may vary
77803 + and you are advised to test this feature on your expected workload
77804 + before deploying it.
77805 +
77806 + Note that this feature does not protect data stored in live pages,
77807 + e.g., process memory swapped to disk may stay there for a long time.
77808 +
77809 +config PAX_MEMORY_STACKLEAK
77810 + bool "Sanitize kernel stack"
77811 + depends on X86
77812 + help
77813 + By saying Y here the kernel will erase the kernel stack before it
77814 + returns from a system call. This in turn reduces the information
77815 + that a kernel stack leak bug can reveal.
77816 +
77817 + Note that such a bug can still leak information that was put on
77818 + the stack by the current system call (the one eventually triggering
77819 + the bug) but traces of earlier system calls on the kernel stack
77820 + cannot leak anymore.
77821 +
77822 + The tradeoff is performance impact: on a single CPU system kernel
77823 + compilation sees a 1% slowdown, other systems and workloads may vary
77824 + and you are advised to test this feature on your expected workload
77825 + before deploying it.
77826 +
77827 + Note: full support for this feature requires gcc with plugin support
77828 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
77829 + versions means that functions with large enough stack frames may
77830 + leave uninitialized memory behind that may be exposed to a later
77831 + syscall leaking the stack.
77832 +
77833 +config PAX_MEMORY_UDEREF
77834 + bool "Prevent invalid userland pointer dereference"
77835 + depends on X86 && !UML_X86 && !XEN
77836 + select PAX_PER_CPU_PGD if X86_64
77837 + help
77838 + By saying Y here the kernel will be prevented from dereferencing
77839 + userland pointers in contexts where the kernel expects only kernel
77840 + pointers. This is both a useful runtime debugging feature and a
77841 + security measure that prevents exploiting a class of kernel bugs.
77842 +
77843 + The tradeoff is that some virtualization solutions may experience
77844 + a huge slowdown and therefore you should not enable this feature
77845 + for kernels meant to run in such environments. Whether a given VM
77846 + solution is affected or not is best determined by simply trying it
77847 + out, the performance impact will be obvious right on boot as this
77848 + mechanism engages from very early on. A good rule of thumb is that
77849 + VMs running on CPUs without hardware virtualization support (i.e.,
77850 + the majority of IA-32 CPUs) will likely experience the slowdown.
77851 +
77852 +config PAX_REFCOUNT
77853 + bool "Prevent various kernel object reference counter overflows"
77854 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
77855 + help
77856 + By saying Y here the kernel will detect and prevent overflowing
77857 + various (but not all) kinds of object reference counters. Such
77858 + overflows can normally occur due to bugs only and are often, if
77859 + not always, exploitable.
77860 +
77861 + The tradeoff is that data structures protected by an overflowed
77862 + refcount will never be freed and therefore will leak memory. Note
77863 + that this leak also happens even without this protection but in
77864 + that case the overflow can eventually trigger the freeing of the
77865 + data structure while it is still being used elsewhere, resulting
77866 + in the exploitable situation that this feature prevents.
77867 +
77868 + Since this has a negligible performance impact, you should enable
77869 + this feature.
77870 +
77871 +config PAX_USERCOPY
77872 + bool "Harden heap object copies between kernel and userland"
77873 + depends on X86 || PPC || SPARC || ARM
77874 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
77875 + help
77876 + By saying Y here the kernel will enforce the size of heap objects
77877 + when they are copied in either direction between the kernel and
77878 + userland, even if only a part of the heap object is copied.
77879 +
77880 + Specifically, this checking prevents information leaking from the
77881 + kernel heap during kernel to userland copies (if the kernel heap
77882 + object is otherwise fully initialized) and prevents kernel heap
77883 + overflows during userland to kernel copies.
77884 +
77885 + Note that the current implementation provides the strictest bounds
77886 + checks for the SLUB allocator.
77887 +
77888 + Enabling this option also enables per-slab cache protection against
77889 + data in a given cache being copied into/out of via userland
77890 + accessors. Though the whitelist of regions will be reduced over
77891 + time, it notably protects important data structures like task structs.
77892 +
77893 + If frame pointers are enabled on x86, this option will also restrict
77894 + copies into and out of the kernel stack to local variables within a
77895 + single frame.
77896 +
77897 + Since this has a negligible performance impact, you should enable
77898 + this feature.
77899 +
77900 +endmenu
77901 +
77902 +endmenu
77903 +
77904 config KEYS
77905 bool "Enable access key retention support"
77906 help
77907 @@ -169,7 +790,7 @@ config INTEL_TXT
77908 config LSM_MMAP_MIN_ADDR
77909 int "Low address space for LSM to protect from user allocation"
77910 depends on SECURITY && SECURITY_SELINUX
77911 - default 32768 if ARM
77912 + default 32768 if ALPHA || ARM || PARISC || SPARC32
77913 default 65536
77914 help
77915 This is the portion of low virtual memory which should be protected
77916 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
77917 index 97ce8fa..23dad96 100644
77918 --- a/security/apparmor/lsm.c
77919 +++ b/security/apparmor/lsm.c
77920 @@ -620,7 +620,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
77921 return error;
77922 }
77923
77924 -static struct security_operations apparmor_ops = {
77925 +static struct security_operations apparmor_ops __read_only = {
77926 .name = "apparmor",
77927
77928 .ptrace_access_check = apparmor_ptrace_access_check,
77929 diff --git a/security/commoncap.c b/security/commoncap.c
77930 index 7ce191e..6c29c34 100644
77931 --- a/security/commoncap.c
77932 +++ b/security/commoncap.c
77933 @@ -28,6 +28,7 @@
77934 #include <linux/prctl.h>
77935 #include <linux/securebits.h>
77936 #include <linux/user_namespace.h>
77937 +#include <net/sock.h>
77938
77939 /*
77940 * If a non-root user executes a setuid-root binary in
77941 @@ -569,6 +570,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
77942 {
77943 const struct cred *cred = current_cred();
77944
77945 + if (gr_acl_enable_at_secure())
77946 + return 1;
77947 +
77948 if (cred->uid != 0) {
77949 if (bprm->cap_effective)
77950 return 1;
77951 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
77952 index 3ccf7ac..d73ad64 100644
77953 --- a/security/integrity/ima/ima.h
77954 +++ b/security/integrity/ima/ima.h
77955 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
77956 extern spinlock_t ima_queue_lock;
77957
77958 struct ima_h_table {
77959 - atomic_long_t len; /* number of stored measurements in the list */
77960 - atomic_long_t violations;
77961 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
77962 + atomic_long_unchecked_t violations;
77963 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
77964 };
77965 extern struct ima_h_table ima_htable;
77966 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
77967 index 88a2788..581ab92 100644
77968 --- a/security/integrity/ima/ima_api.c
77969 +++ b/security/integrity/ima/ima_api.c
77970 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
77971 int result;
77972
77973 /* can overflow, only indicator */
77974 - atomic_long_inc(&ima_htable.violations);
77975 + atomic_long_inc_unchecked(&ima_htable.violations);
77976
77977 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
77978 if (!entry) {
77979 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
77980 index e1aa2b4..52027bf 100644
77981 --- a/security/integrity/ima/ima_fs.c
77982 +++ b/security/integrity/ima/ima_fs.c
77983 @@ -28,12 +28,12 @@
77984 static int valid_policy = 1;
77985 #define TMPBUFLEN 12
77986 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
77987 - loff_t *ppos, atomic_long_t *val)
77988 + loff_t *ppos, atomic_long_unchecked_t *val)
77989 {
77990 char tmpbuf[TMPBUFLEN];
77991 ssize_t len;
77992
77993 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
77994 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
77995 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
77996 }
77997
77998 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
77999 index 55a6271..ad829c3 100644
78000 --- a/security/integrity/ima/ima_queue.c
78001 +++ b/security/integrity/ima/ima_queue.c
78002 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
78003 INIT_LIST_HEAD(&qe->later);
78004 list_add_tail_rcu(&qe->later, &ima_measurements);
78005
78006 - atomic_long_inc(&ima_htable.len);
78007 + atomic_long_inc_unchecked(&ima_htable.len);
78008 key = ima_hash_key(entry->digest);
78009 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
78010 return 0;
78011 diff --git a/security/keys/compat.c b/security/keys/compat.c
78012 index 4c48e13..7abdac9 100644
78013 --- a/security/keys/compat.c
78014 +++ b/security/keys/compat.c
78015 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
78016 if (ret == 0)
78017 goto no_payload_free;
78018
78019 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78020 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78021
78022 if (iov != iovstack)
78023 kfree(iov);
78024 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
78025 index 0b3f5d7..892c8a6 100644
78026 --- a/security/keys/keyctl.c
78027 +++ b/security/keys/keyctl.c
78028 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
78029 /*
78030 * Copy the iovec data from userspace
78031 */
78032 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78033 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
78034 unsigned ioc)
78035 {
78036 for (; ioc > 0; ioc--) {
78037 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78038 * If successful, 0 will be returned.
78039 */
78040 long keyctl_instantiate_key_common(key_serial_t id,
78041 - const struct iovec *payload_iov,
78042 + const struct iovec __user *payload_iov,
78043 unsigned ioc,
78044 size_t plen,
78045 key_serial_t ringid)
78046 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
78047 [0].iov_len = plen
78048 };
78049
78050 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
78051 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
78052 }
78053
78054 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
78055 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
78056 if (ret == 0)
78057 goto no_payload_free;
78058
78059 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78060 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78061
78062 if (iov != iovstack)
78063 kfree(iov);
78064 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
78065 index d605f75..2bc6be9 100644
78066 --- a/security/keys/keyring.c
78067 +++ b/security/keys/keyring.c
78068 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
78069 ret = -EFAULT;
78070
78071 for (loop = 0; loop < klist->nkeys; loop++) {
78072 + key_serial_t serial;
78073 key = klist->keys[loop];
78074 + serial = key->serial;
78075
78076 tmp = sizeof(key_serial_t);
78077 if (tmp > buflen)
78078 tmp = buflen;
78079
78080 - if (copy_to_user(buffer,
78081 - &key->serial,
78082 - tmp) != 0)
78083 + if (copy_to_user(buffer, &serial, tmp))
78084 goto error;
78085
78086 buflen -= tmp;
78087 diff --git a/security/min_addr.c b/security/min_addr.c
78088 index f728728..6457a0c 100644
78089 --- a/security/min_addr.c
78090 +++ b/security/min_addr.c
78091 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
78092 */
78093 static void update_mmap_min_addr(void)
78094 {
78095 +#ifndef SPARC
78096 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
78097 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
78098 mmap_min_addr = dac_mmap_min_addr;
78099 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
78100 #else
78101 mmap_min_addr = dac_mmap_min_addr;
78102 #endif
78103 +#endif
78104 }
78105
78106 /*
78107 diff --git a/security/security.c b/security/security.c
78108 index d754249..8bf426e 100644
78109 --- a/security/security.c
78110 +++ b/security/security.c
78111 @@ -26,8 +26,8 @@
78112 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
78113 CONFIG_DEFAULT_SECURITY;
78114
78115 -static struct security_operations *security_ops;
78116 -static struct security_operations default_security_ops = {
78117 +static struct security_operations *security_ops __read_only;
78118 +static struct security_operations default_security_ops __read_only = {
78119 .name = "default",
78120 };
78121
78122 @@ -68,7 +68,9 @@ int __init security_init(void)
78123
78124 void reset_security_ops(void)
78125 {
78126 + pax_open_kernel();
78127 security_ops = &default_security_ops;
78128 + pax_close_kernel();
78129 }
78130
78131 /* Save user chosen LSM */
78132 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
78133 index 6a3683e..f52f4c0 100644
78134 --- a/security/selinux/hooks.c
78135 +++ b/security/selinux/hooks.c
78136 @@ -94,8 +94,6 @@
78137
78138 #define NUM_SEL_MNT_OPTS 5
78139
78140 -extern struct security_operations *security_ops;
78141 -
78142 /* SECMARK reference count */
78143 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
78144
78145 @@ -5429,7 +5427,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
78146
78147 #endif
78148
78149 -static struct security_operations selinux_ops = {
78150 +static struct security_operations selinux_ops __read_only = {
78151 .name = "selinux",
78152
78153 .ptrace_access_check = selinux_ptrace_access_check,
78154 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
78155 index b43813c..74be837 100644
78156 --- a/security/selinux/include/xfrm.h
78157 +++ b/security/selinux/include/xfrm.h
78158 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
78159
78160 static inline void selinux_xfrm_notify_policyload(void)
78161 {
78162 - atomic_inc(&flow_cache_genid);
78163 + atomic_inc_unchecked(&flow_cache_genid);
78164 }
78165 #else
78166 static inline int selinux_xfrm_enabled(void)
78167 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
78168 index e8af5b0b..78527ef 100644
78169 --- a/security/smack/smack_lsm.c
78170 +++ b/security/smack/smack_lsm.c
78171 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
78172 return 0;
78173 }
78174
78175 -struct security_operations smack_ops = {
78176 +struct security_operations smack_ops __read_only = {
78177 .name = "smack",
78178
78179 .ptrace_access_check = smack_ptrace_access_check,
78180 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
78181 index 620d37c..e2ad89b 100644
78182 --- a/security/tomoyo/tomoyo.c
78183 +++ b/security/tomoyo/tomoyo.c
78184 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
78185 * tomoyo_security_ops is a "struct security_operations" which is used for
78186 * registering TOMOYO.
78187 */
78188 -static struct security_operations tomoyo_security_ops = {
78189 +static struct security_operations tomoyo_security_ops __read_only = {
78190 .name = "tomoyo",
78191 .cred_alloc_blank = tomoyo_cred_alloc_blank,
78192 .cred_prepare = tomoyo_cred_prepare,
78193 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
78194 index 762af68..7103453 100644
78195 --- a/sound/aoa/codecs/onyx.c
78196 +++ b/sound/aoa/codecs/onyx.c
78197 @@ -54,7 +54,7 @@ struct onyx {
78198 spdif_locked:1,
78199 analog_locked:1,
78200 original_mute:2;
78201 - int open_count;
78202 + local_t open_count;
78203 struct codec_info *codec_info;
78204
78205 /* mutex serializes concurrent access to the device
78206 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
78207 struct onyx *onyx = cii->codec_data;
78208
78209 mutex_lock(&onyx->mutex);
78210 - onyx->open_count++;
78211 + local_inc(&onyx->open_count);
78212 mutex_unlock(&onyx->mutex);
78213
78214 return 0;
78215 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
78216 struct onyx *onyx = cii->codec_data;
78217
78218 mutex_lock(&onyx->mutex);
78219 - onyx->open_count--;
78220 - if (!onyx->open_count)
78221 + if (local_dec_and_test(&onyx->open_count))
78222 onyx->spdif_locked = onyx->analog_locked = 0;
78223 mutex_unlock(&onyx->mutex);
78224
78225 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
78226 index ffd2025..df062c9 100644
78227 --- a/sound/aoa/codecs/onyx.h
78228 +++ b/sound/aoa/codecs/onyx.h
78229 @@ -11,6 +11,7 @@
78230 #include <linux/i2c.h>
78231 #include <asm/pmac_low_i2c.h>
78232 #include <asm/prom.h>
78233 +#include <asm/local.h>
78234
78235 /* PCM3052 register definitions */
78236
78237 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
78238 index 08fde00..0bf641a 100644
78239 --- a/sound/core/oss/pcm_oss.c
78240 +++ b/sound/core/oss/pcm_oss.c
78241 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
78242 if (in_kernel) {
78243 mm_segment_t fs;
78244 fs = snd_enter_user();
78245 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78246 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78247 snd_leave_user(fs);
78248 } else {
78249 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78250 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78251 }
78252 if (ret != -EPIPE && ret != -ESTRPIPE)
78253 break;
78254 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
78255 if (in_kernel) {
78256 mm_segment_t fs;
78257 fs = snd_enter_user();
78258 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78259 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78260 snd_leave_user(fs);
78261 } else {
78262 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78263 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78264 }
78265 if (ret == -EPIPE) {
78266 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
78267 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
78268 struct snd_pcm_plugin_channel *channels;
78269 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
78270 if (!in_kernel) {
78271 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
78272 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
78273 return -EFAULT;
78274 buf = runtime->oss.buffer;
78275 }
78276 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
78277 }
78278 } else {
78279 tmp = snd_pcm_oss_write2(substream,
78280 - (const char __force *)buf,
78281 + (const char __force_kernel *)buf,
78282 runtime->oss.period_bytes, 0);
78283 if (tmp <= 0)
78284 goto err;
78285 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
78286 struct snd_pcm_runtime *runtime = substream->runtime;
78287 snd_pcm_sframes_t frames, frames1;
78288 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
78289 - char __user *final_dst = (char __force __user *)buf;
78290 + char __user *final_dst = (char __force_user *)buf;
78291 if (runtime->oss.plugin_first) {
78292 struct snd_pcm_plugin_channel *channels;
78293 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
78294 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
78295 xfer += tmp;
78296 runtime->oss.buffer_used -= tmp;
78297 } else {
78298 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
78299 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
78300 runtime->oss.period_bytes, 0);
78301 if (tmp <= 0)
78302 goto err;
78303 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
78304 size1);
78305 size1 /= runtime->channels; /* frames */
78306 fs = snd_enter_user();
78307 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
78308 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
78309 snd_leave_user(fs);
78310 }
78311 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
78312 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
78313 index 91cdf94..4085161 100644
78314 --- a/sound/core/pcm_compat.c
78315 +++ b/sound/core/pcm_compat.c
78316 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
78317 int err;
78318
78319 fs = snd_enter_user();
78320 - err = snd_pcm_delay(substream, &delay);
78321 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
78322 snd_leave_user(fs);
78323 if (err < 0)
78324 return err;
78325 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
78326 index 25ed9fe..24c46e9 100644
78327 --- a/sound/core/pcm_native.c
78328 +++ b/sound/core/pcm_native.c
78329 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
78330 switch (substream->stream) {
78331 case SNDRV_PCM_STREAM_PLAYBACK:
78332 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
78333 - (void __user *)arg);
78334 + (void __force_user *)arg);
78335 break;
78336 case SNDRV_PCM_STREAM_CAPTURE:
78337 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
78338 - (void __user *)arg);
78339 + (void __force_user *)arg);
78340 break;
78341 default:
78342 result = -EINVAL;
78343 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
78344 index 5cf8d65..912a79c 100644
78345 --- a/sound/core/seq/seq_device.c
78346 +++ b/sound/core/seq/seq_device.c
78347 @@ -64,7 +64,7 @@ struct ops_list {
78348 int argsize; /* argument size */
78349
78350 /* operators */
78351 - struct snd_seq_dev_ops ops;
78352 + struct snd_seq_dev_ops *ops;
78353
78354 /* registred devices */
78355 struct list_head dev_list; /* list of devices */
78356 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
78357
78358 mutex_lock(&ops->reg_mutex);
78359 /* copy driver operators */
78360 - ops->ops = *entry;
78361 + ops->ops = entry;
78362 ops->driver |= DRIVER_LOADED;
78363 ops->argsize = argsize;
78364
78365 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
78366 dev->name, ops->id, ops->argsize, dev->argsize);
78367 return -EINVAL;
78368 }
78369 - if (ops->ops.init_device(dev) >= 0) {
78370 + if (ops->ops->init_device(dev) >= 0) {
78371 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
78372 ops->num_init_devices++;
78373 } else {
78374 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
78375 dev->name, ops->id, ops->argsize, dev->argsize);
78376 return -EINVAL;
78377 }
78378 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
78379 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
78380 dev->status = SNDRV_SEQ_DEVICE_FREE;
78381 dev->driver_data = NULL;
78382 ops->num_init_devices--;
78383 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
78384 index 621e60e..f4543f5 100644
78385 --- a/sound/drivers/mts64.c
78386 +++ b/sound/drivers/mts64.c
78387 @@ -29,6 +29,7 @@
78388 #include <sound/initval.h>
78389 #include <sound/rawmidi.h>
78390 #include <sound/control.h>
78391 +#include <asm/local.h>
78392
78393 #define CARD_NAME "Miditerminal 4140"
78394 #define DRIVER_NAME "MTS64"
78395 @@ -67,7 +68,7 @@ struct mts64 {
78396 struct pardevice *pardev;
78397 int pardev_claimed;
78398
78399 - int open_count;
78400 + local_t open_count;
78401 int current_midi_output_port;
78402 int current_midi_input_port;
78403 u8 mode[MTS64_NUM_INPUT_PORTS];
78404 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
78405 {
78406 struct mts64 *mts = substream->rmidi->private_data;
78407
78408 - if (mts->open_count == 0) {
78409 + if (local_read(&mts->open_count) == 0) {
78410 /* We don't need a spinlock here, because this is just called
78411 if the device has not been opened before.
78412 So there aren't any IRQs from the device */
78413 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
78414
78415 msleep(50);
78416 }
78417 - ++(mts->open_count);
78418 + local_inc(&mts->open_count);
78419
78420 return 0;
78421 }
78422 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
78423 struct mts64 *mts = substream->rmidi->private_data;
78424 unsigned long flags;
78425
78426 - --(mts->open_count);
78427 - if (mts->open_count == 0) {
78428 + if (local_dec_return(&mts->open_count) == 0) {
78429 /* We need the spinlock_irqsave here because we can still
78430 have IRQs at this point */
78431 spin_lock_irqsave(&mts->lock, flags);
78432 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
78433
78434 msleep(500);
78435
78436 - } else if (mts->open_count < 0)
78437 - mts->open_count = 0;
78438 + } else if (local_read(&mts->open_count) < 0)
78439 + local_set(&mts->open_count, 0);
78440
78441 return 0;
78442 }
78443 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
78444 index b953fb4..1999c01 100644
78445 --- a/sound/drivers/opl4/opl4_lib.c
78446 +++ b/sound/drivers/opl4/opl4_lib.c
78447 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
78448 MODULE_DESCRIPTION("OPL4 driver");
78449 MODULE_LICENSE("GPL");
78450
78451 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
78452 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
78453 {
78454 int timeout = 10;
78455 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
78456 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
78457 index 3e32bd3..46fc152 100644
78458 --- a/sound/drivers/portman2x4.c
78459 +++ b/sound/drivers/portman2x4.c
78460 @@ -48,6 +48,7 @@
78461 #include <sound/initval.h>
78462 #include <sound/rawmidi.h>
78463 #include <sound/control.h>
78464 +#include <asm/local.h>
78465
78466 #define CARD_NAME "Portman 2x4"
78467 #define DRIVER_NAME "portman"
78468 @@ -85,7 +86,7 @@ struct portman {
78469 struct pardevice *pardev;
78470 int pardev_claimed;
78471
78472 - int open_count;
78473 + local_t open_count;
78474 int mode[PORTMAN_NUM_INPUT_PORTS];
78475 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
78476 };
78477 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
78478 index 87657dd..a8268d4 100644
78479 --- a/sound/firewire/amdtp.c
78480 +++ b/sound/firewire/amdtp.c
78481 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
78482 ptr = s->pcm_buffer_pointer + data_blocks;
78483 if (ptr >= pcm->runtime->buffer_size)
78484 ptr -= pcm->runtime->buffer_size;
78485 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
78486 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
78487
78488 s->pcm_period_pointer += data_blocks;
78489 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
78490 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
78491 */
78492 void amdtp_out_stream_update(struct amdtp_out_stream *s)
78493 {
78494 - ACCESS_ONCE(s->source_node_id_field) =
78495 + ACCESS_ONCE_RW(s->source_node_id_field) =
78496 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
78497 }
78498 EXPORT_SYMBOL(amdtp_out_stream_update);
78499 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
78500 index 537a9cb..8e8c8e9 100644
78501 --- a/sound/firewire/amdtp.h
78502 +++ b/sound/firewire/amdtp.h
78503 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
78504 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
78505 struct snd_pcm_substream *pcm)
78506 {
78507 - ACCESS_ONCE(s->pcm) = pcm;
78508 + ACCESS_ONCE_RW(s->pcm) = pcm;
78509 }
78510
78511 /**
78512 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
78513 index cd094ec..eca1277 100644
78514 --- a/sound/firewire/isight.c
78515 +++ b/sound/firewire/isight.c
78516 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
78517 ptr += count;
78518 if (ptr >= runtime->buffer_size)
78519 ptr -= runtime->buffer_size;
78520 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
78521 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
78522
78523 isight->period_counter += count;
78524 if (isight->period_counter >= runtime->period_size) {
78525 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
78526 if (err < 0)
78527 return err;
78528
78529 - ACCESS_ONCE(isight->pcm_active) = true;
78530 + ACCESS_ONCE_RW(isight->pcm_active) = true;
78531
78532 return 0;
78533 }
78534 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
78535 {
78536 struct isight *isight = substream->private_data;
78537
78538 - ACCESS_ONCE(isight->pcm_active) = false;
78539 + ACCESS_ONCE_RW(isight->pcm_active) = false;
78540
78541 mutex_lock(&isight->mutex);
78542 isight_stop_streaming(isight);
78543 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
78544
78545 switch (cmd) {
78546 case SNDRV_PCM_TRIGGER_START:
78547 - ACCESS_ONCE(isight->pcm_running) = true;
78548 + ACCESS_ONCE_RW(isight->pcm_running) = true;
78549 break;
78550 case SNDRV_PCM_TRIGGER_STOP:
78551 - ACCESS_ONCE(isight->pcm_running) = false;
78552 + ACCESS_ONCE_RW(isight->pcm_running) = false;
78553 break;
78554 default:
78555 return -EINVAL;
78556 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
78557 index 7bd5e33..1fcab12 100644
78558 --- a/sound/isa/cmi8330.c
78559 +++ b/sound/isa/cmi8330.c
78560 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
78561
78562 struct snd_pcm *pcm;
78563 struct snd_cmi8330_stream {
78564 - struct snd_pcm_ops ops;
78565 + snd_pcm_ops_no_const ops;
78566 snd_pcm_open_callback_t open;
78567 void *private_data; /* sb or wss */
78568 } streams[2];
78569 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
78570 index 733b014..56ce96f 100644
78571 --- a/sound/oss/sb_audio.c
78572 +++ b/sound/oss/sb_audio.c
78573 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
78574 buf16 = (signed short *)(localbuf + localoffs);
78575 while (c)
78576 {
78577 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
78578 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
78579 if (copy_from_user(lbuf8,
78580 userbuf+useroffs + p,
78581 locallen))
78582 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
78583 index 09d4648..cf234c7 100644
78584 --- a/sound/oss/swarm_cs4297a.c
78585 +++ b/sound/oss/swarm_cs4297a.c
78586 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
78587 {
78588 struct cs4297a_state *s;
78589 u32 pwr, id;
78590 - mm_segment_t fs;
78591 int rval;
78592 #ifndef CONFIG_BCM_CS4297A_CSWARM
78593 u64 cfg;
78594 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
78595 if (!rval) {
78596 char *sb1250_duart_present;
78597
78598 +#if 0
78599 + mm_segment_t fs;
78600 fs = get_fs();
78601 set_fs(KERNEL_DS);
78602 -#if 0
78603 val = SOUND_MASK_LINE;
78604 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
78605 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
78606 val = initvol[i].vol;
78607 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
78608 }
78609 + set_fs(fs);
78610 // cs4297a_write_ac97(s, 0x18, 0x0808);
78611 #else
78612 // cs4297a_write_ac97(s, 0x5e, 0x180);
78613 cs4297a_write_ac97(s, 0x02, 0x0808);
78614 cs4297a_write_ac97(s, 0x18, 0x0808);
78615 #endif
78616 - set_fs(fs);
78617
78618 list_add(&s->list, &cs4297a_devs);
78619
78620 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
78621 index f0f1943..8e1f96c 100644
78622 --- a/sound/pci/hda/hda_codec.h
78623 +++ b/sound/pci/hda/hda_codec.h
78624 @@ -611,7 +611,7 @@ struct hda_bus_ops {
78625 /* notify power-up/down from codec to controller */
78626 void (*pm_notify)(struct hda_bus *bus);
78627 #endif
78628 -};
78629 +} __no_const;
78630
78631 /* template to pass to the bus constructor */
78632 struct hda_bus_template {
78633 @@ -713,6 +713,7 @@ struct hda_codec_ops {
78634 #endif
78635 void (*reboot_notify)(struct hda_codec *codec);
78636 };
78637 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
78638
78639 /* record for amp information cache */
78640 struct hda_cache_head {
78641 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
78642 struct snd_pcm_substream *substream);
78643 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
78644 struct snd_pcm_substream *substream);
78645 -};
78646 +} __no_const;
78647
78648 /* PCM information for each substream */
78649 struct hda_pcm_stream {
78650 @@ -801,7 +802,7 @@ struct hda_codec {
78651 const char *modelname; /* model name for preset */
78652
78653 /* set by patch */
78654 - struct hda_codec_ops patch_ops;
78655 + hda_codec_ops_no_const patch_ops;
78656
78657 /* PCM to create, set by patch_ops.build_pcms callback */
78658 unsigned int num_pcms;
78659 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
78660 index 0da778a..bc38b84 100644
78661 --- a/sound/pci/ice1712/ice1712.h
78662 +++ b/sound/pci/ice1712/ice1712.h
78663 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
78664 unsigned int mask_flags; /* total mask bits */
78665 struct snd_akm4xxx_ops {
78666 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
78667 - } ops;
78668 + } __no_const ops;
78669 };
78670
78671 struct snd_ice1712_spdif {
78672 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
78673 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
78674 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
78675 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
78676 - } ops;
78677 + } __no_const ops;
78678 };
78679
78680
78681 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
78682 index 12a9a2b..2b6138f 100644
78683 --- a/sound/pci/ymfpci/ymfpci_main.c
78684 +++ b/sound/pci/ymfpci/ymfpci_main.c
78685 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
78686 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
78687 break;
78688 }
78689 - if (atomic_read(&chip->interrupt_sleep_count)) {
78690 - atomic_set(&chip->interrupt_sleep_count, 0);
78691 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
78692 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
78693 wake_up(&chip->interrupt_sleep);
78694 }
78695 __end:
78696 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
78697 continue;
78698 init_waitqueue_entry(&wait, current);
78699 add_wait_queue(&chip->interrupt_sleep, &wait);
78700 - atomic_inc(&chip->interrupt_sleep_count);
78701 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
78702 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
78703 remove_wait_queue(&chip->interrupt_sleep, &wait);
78704 }
78705 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
78706 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
78707 spin_unlock(&chip->reg_lock);
78708
78709 - if (atomic_read(&chip->interrupt_sleep_count)) {
78710 - atomic_set(&chip->interrupt_sleep_count, 0);
78711 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
78712 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
78713 wake_up(&chip->interrupt_sleep);
78714 }
78715 }
78716 @@ -2389,7 +2389,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
78717 spin_lock_init(&chip->reg_lock);
78718 spin_lock_init(&chip->voice_lock);
78719 init_waitqueue_head(&chip->interrupt_sleep);
78720 - atomic_set(&chip->interrupt_sleep_count, 0);
78721 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
78722 chip->card = card;
78723 chip->pci = pci;
78724 chip->irq = -1;
78725 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
78726 index cdc860a..db34a93 100644
78727 --- a/sound/soc/soc-pcm.c
78728 +++ b/sound/soc/soc-pcm.c
78729 @@ -605,7 +605,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
78730 struct snd_soc_platform *platform = rtd->platform;
78731 struct snd_soc_dai *codec_dai = rtd->codec_dai;
78732 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
78733 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
78734 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
78735 struct snd_pcm *pcm;
78736 char new_name[64];
78737 int ret = 0, playback = 0, capture = 0;
78738 diff --git a/sound/usb/card.h b/sound/usb/card.h
78739 index da5fa1a..113cd02 100644
78740 --- a/sound/usb/card.h
78741 +++ b/sound/usb/card.h
78742 @@ -45,6 +45,7 @@ struct snd_urb_ops {
78743 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
78744 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
78745 };
78746 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
78747
78748 struct snd_usb_substream {
78749 struct snd_usb_stream *stream;
78750 @@ -94,7 +95,7 @@ struct snd_usb_substream {
78751 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
78752 spinlock_t lock;
78753
78754 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
78755 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
78756 int last_frame_number; /* stored frame number */
78757 int last_delay; /* stored delay */
78758 };
78759 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
78760 new file mode 100644
78761 index 0000000..894c8bf
78762 --- /dev/null
78763 +++ b/tools/gcc/Makefile
78764 @@ -0,0 +1,23 @@
78765 +#CC := gcc
78766 +#PLUGIN_SOURCE_FILES := pax_plugin.c
78767 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
78768 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
78769 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
78770 +
78771 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
78772 +
78773 +hostlibs-y := constify_plugin.so
78774 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
78775 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
78776 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
78777 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
78778 +hostlibs-y += colorize_plugin.so
78779 +
78780 +always := $(hostlibs-y)
78781 +
78782 +constify_plugin-objs := constify_plugin.o
78783 +stackleak_plugin-objs := stackleak_plugin.o
78784 +kallocstat_plugin-objs := kallocstat_plugin.o
78785 +kernexec_plugin-objs := kernexec_plugin.o
78786 +checker_plugin-objs := checker_plugin.o
78787 +colorize_plugin-objs := colorize_plugin.o
78788 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
78789 new file mode 100644
78790 index 0000000..d41b5af
78791 --- /dev/null
78792 +++ b/tools/gcc/checker_plugin.c
78793 @@ -0,0 +1,171 @@
78794 +/*
78795 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78796 + * Licensed under the GPL v2
78797 + *
78798 + * Note: the choice of the license means that the compilation process is
78799 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78800 + * but for the kernel it doesn't matter since it doesn't link against
78801 + * any of the gcc libraries
78802 + *
78803 + * gcc plugin to implement various sparse (source code checker) features
78804 + *
78805 + * TODO:
78806 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
78807 + *
78808 + * BUGS:
78809 + * - none known
78810 + */
78811 +#include "gcc-plugin.h"
78812 +#include "config.h"
78813 +#include "system.h"
78814 +#include "coretypes.h"
78815 +#include "tree.h"
78816 +#include "tree-pass.h"
78817 +#include "flags.h"
78818 +#include "intl.h"
78819 +#include "toplev.h"
78820 +#include "plugin.h"
78821 +//#include "expr.h" where are you...
78822 +#include "diagnostic.h"
78823 +#include "plugin-version.h"
78824 +#include "tm.h"
78825 +#include "function.h"
78826 +#include "basic-block.h"
78827 +#include "gimple.h"
78828 +#include "rtl.h"
78829 +#include "emit-rtl.h"
78830 +#include "tree-flow.h"
78831 +#include "target.h"
78832 +
78833 +extern void c_register_addr_space (const char *str, addr_space_t as);
78834 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
78835 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
78836 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
78837 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
78838 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
78839 +
78840 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78841 +extern rtx emit_move_insn(rtx x, rtx y);
78842 +
78843 +int plugin_is_GPL_compatible;
78844 +
78845 +static struct plugin_info checker_plugin_info = {
78846 + .version = "201111150100",
78847 +};
78848 +
78849 +#define ADDR_SPACE_KERNEL 0
78850 +#define ADDR_SPACE_FORCE_KERNEL 1
78851 +#define ADDR_SPACE_USER 2
78852 +#define ADDR_SPACE_FORCE_USER 3
78853 +#define ADDR_SPACE_IOMEM 0
78854 +#define ADDR_SPACE_FORCE_IOMEM 0
78855 +#define ADDR_SPACE_PERCPU 0
78856 +#define ADDR_SPACE_FORCE_PERCPU 0
78857 +#define ADDR_SPACE_RCU 0
78858 +#define ADDR_SPACE_FORCE_RCU 0
78859 +
78860 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
78861 +{
78862 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
78863 +}
78864 +
78865 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
78866 +{
78867 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
78868 +}
78869 +
78870 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
78871 +{
78872 + return default_addr_space_valid_pointer_mode(mode, as);
78873 +}
78874 +
78875 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
78876 +{
78877 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
78878 +}
78879 +
78880 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
78881 +{
78882 + return default_addr_space_legitimize_address(x, oldx, mode, as);
78883 +}
78884 +
78885 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
78886 +{
78887 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
78888 + return true;
78889 +
78890 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
78891 + return true;
78892 +
78893 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
78894 + return true;
78895 +
78896 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
78897 + return true;
78898 +
78899 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
78900 + return true;
78901 +
78902 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
78903 + return true;
78904 +
78905 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
78906 + return true;
78907 +
78908 + return subset == superset;
78909 +}
78910 +
78911 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
78912 +{
78913 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
78914 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
78915 +
78916 + return op;
78917 +}
78918 +
78919 +static void register_checker_address_spaces(void *event_data, void *data)
78920 +{
78921 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
78922 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
78923 + c_register_addr_space("__user", ADDR_SPACE_USER);
78924 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
78925 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
78926 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
78927 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
78928 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
78929 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
78930 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
78931 +
78932 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
78933 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
78934 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
78935 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
78936 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
78937 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
78938 + targetm.addr_space.convert = checker_addr_space_convert;
78939 +}
78940 +
78941 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78942 +{
78943 + const char * const plugin_name = plugin_info->base_name;
78944 + const int argc = plugin_info->argc;
78945 + const struct plugin_argument * const argv = plugin_info->argv;
78946 + int i;
78947 +
78948 + if (!plugin_default_version_check(version, &gcc_version)) {
78949 + error(G_("incompatible gcc/plugin versions"));
78950 + return 1;
78951 + }
78952 +
78953 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
78954 +
78955 + for (i = 0; i < argc; ++i)
78956 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78957 +
78958 + if (TARGET_64BIT == 0)
78959 + return 0;
78960 +
78961 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
78962 +
78963 + return 0;
78964 +}
78965 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
78966 new file mode 100644
78967 index 0000000..ee950d0
78968 --- /dev/null
78969 +++ b/tools/gcc/colorize_plugin.c
78970 @@ -0,0 +1,147 @@
78971 +/*
78972 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
78973 + * Licensed under the GPL v2
78974 + *
78975 + * Note: the choice of the license means that the compilation process is
78976 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78977 + * but for the kernel it doesn't matter since it doesn't link against
78978 + * any of the gcc libraries
78979 + *
78980 + * gcc plugin to colorize diagnostic output
78981 + *
78982 + */
78983 +
78984 +#include "gcc-plugin.h"
78985 +#include "config.h"
78986 +#include "system.h"
78987 +#include "coretypes.h"
78988 +#include "tree.h"
78989 +#include "tree-pass.h"
78990 +#include "flags.h"
78991 +#include "intl.h"
78992 +#include "toplev.h"
78993 +#include "plugin.h"
78994 +#include "diagnostic.h"
78995 +#include "plugin-version.h"
78996 +#include "tm.h"
78997 +
78998 +int plugin_is_GPL_compatible;
78999 +
79000 +static struct plugin_info colorize_plugin_info = {
79001 + .version = "201203092200",
79002 +};
79003 +
79004 +#define GREEN "\033[32m\033[2m"
79005 +#define LIGHTGREEN "\033[32m\033[1m"
79006 +#define YELLOW "\033[33m\033[2m"
79007 +#define LIGHTYELLOW "\033[33m\033[1m"
79008 +#define RED "\033[31m\033[2m"
79009 +#define LIGHTRED "\033[31m\033[1m"
79010 +#define BLUE "\033[34m\033[2m"
79011 +#define LIGHTBLUE "\033[34m\033[1m"
79012 +#define BRIGHT "\033[m\033[1m"
79013 +#define NORMAL "\033[m"
79014 +
79015 +static diagnostic_starter_fn old_starter;
79016 +static diagnostic_finalizer_fn old_finalizer;
79017 +
79018 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79019 +{
79020 + const char *color;
79021 + char *newprefix;
79022 +
79023 + switch (diagnostic->kind) {
79024 + case DK_NOTE:
79025 + color = LIGHTBLUE;
79026 + break;
79027 +
79028 + case DK_PEDWARN:
79029 + case DK_WARNING:
79030 + color = LIGHTYELLOW;
79031 + break;
79032 +
79033 + case DK_ERROR:
79034 + case DK_FATAL:
79035 + case DK_ICE:
79036 + case DK_PERMERROR:
79037 + case DK_SORRY:
79038 + color = LIGHTRED;
79039 + break;
79040 +
79041 + default:
79042 + color = NORMAL;
79043 + }
79044 +
79045 + old_starter(context, diagnostic);
79046 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
79047 + return;
79048 + pp_destroy_prefix(context->printer);
79049 + pp_set_prefix(context->printer, newprefix);
79050 +}
79051 +
79052 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79053 +{
79054 + old_finalizer(context, diagnostic);
79055 +}
79056 +
79057 +static void colorize_arm(void)
79058 +{
79059 + old_starter = diagnostic_starter(global_dc);
79060 + old_finalizer = diagnostic_finalizer(global_dc);
79061 +
79062 + diagnostic_starter(global_dc) = start_colorize;
79063 + diagnostic_finalizer(global_dc) = finalize_colorize;
79064 +}
79065 +
79066 +static unsigned int execute_colorize_rearm(void)
79067 +{
79068 + if (diagnostic_starter(global_dc) == start_colorize)
79069 + return 0;
79070 +
79071 + colorize_arm();
79072 + return 0;
79073 +}
79074 +
79075 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
79076 + .pass = {
79077 + .type = SIMPLE_IPA_PASS,
79078 + .name = "colorize_rearm",
79079 + .gate = NULL,
79080 + .execute = execute_colorize_rearm,
79081 + .sub = NULL,
79082 + .next = NULL,
79083 + .static_pass_number = 0,
79084 + .tv_id = TV_NONE,
79085 + .properties_required = 0,
79086 + .properties_provided = 0,
79087 + .properties_destroyed = 0,
79088 + .todo_flags_start = 0,
79089 + .todo_flags_finish = 0
79090 + }
79091 +};
79092 +
79093 +static void colorize_start_unit(void *gcc_data, void *user_data)
79094 +{
79095 + colorize_arm();
79096 +}
79097 +
79098 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79099 +{
79100 + const char * const plugin_name = plugin_info->base_name;
79101 + struct register_pass_info colorize_rearm_pass_info = {
79102 + .pass = &pass_ipa_colorize_rearm.pass,
79103 + .reference_pass_name = "*free_lang_data",
79104 + .ref_pass_instance_number = 0,
79105 + .pos_op = PASS_POS_INSERT_AFTER
79106 + };
79107 +
79108 + if (!plugin_default_version_check(version, &gcc_version)) {
79109 + error(G_("incompatible gcc/plugin versions"));
79110 + return 1;
79111 + }
79112 +
79113 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
79114 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
79115 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
79116 + return 0;
79117 +}
79118 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
79119 new file mode 100644
79120 index 0000000..704a564
79121 --- /dev/null
79122 +++ b/tools/gcc/constify_plugin.c
79123 @@ -0,0 +1,303 @@
79124 +/*
79125 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
79126 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
79127 + * Licensed under the GPL v2, or (at your option) v3
79128 + *
79129 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
79130 + *
79131 + * Homepage:
79132 + * http://www.grsecurity.net/~ephox/const_plugin/
79133 + *
79134 + * Usage:
79135 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
79136 + * $ gcc -fplugin=constify_plugin.so test.c -O2
79137 + */
79138 +
79139 +#include "gcc-plugin.h"
79140 +#include "config.h"
79141 +#include "system.h"
79142 +#include "coretypes.h"
79143 +#include "tree.h"
79144 +#include "tree-pass.h"
79145 +#include "flags.h"
79146 +#include "intl.h"
79147 +#include "toplev.h"
79148 +#include "plugin.h"
79149 +#include "diagnostic.h"
79150 +#include "plugin-version.h"
79151 +#include "tm.h"
79152 +#include "function.h"
79153 +#include "basic-block.h"
79154 +#include "gimple.h"
79155 +#include "rtl.h"
79156 +#include "emit-rtl.h"
79157 +#include "tree-flow.h"
79158 +
79159 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
79160 +
79161 +int plugin_is_GPL_compatible;
79162 +
79163 +static struct plugin_info const_plugin_info = {
79164 + .version = "201111150100",
79165 + .help = "no-constify\tturn off constification\n",
79166 +};
79167 +
79168 +static void constify_type(tree type);
79169 +static bool walk_struct(tree node);
79170 +
79171 +static tree deconstify_type(tree old_type)
79172 +{
79173 + tree new_type, field;
79174 +
79175 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
79176 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
79177 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
79178 + DECL_FIELD_CONTEXT(field) = new_type;
79179 + TYPE_READONLY(new_type) = 0;
79180 + C_TYPE_FIELDS_READONLY(new_type) = 0;
79181 + return new_type;
79182 +}
79183 +
79184 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
79185 +{
79186 + tree type;
79187 +
79188 + *no_add_attrs = true;
79189 + if (TREE_CODE(*node) == FUNCTION_DECL) {
79190 + error("%qE attribute does not apply to functions", name);
79191 + return NULL_TREE;
79192 + }
79193 +
79194 + if (TREE_CODE(*node) == VAR_DECL) {
79195 + error("%qE attribute does not apply to variables", name);
79196 + return NULL_TREE;
79197 + }
79198 +
79199 + if (TYPE_P(*node)) {
79200 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
79201 + *no_add_attrs = false;
79202 + else
79203 + error("%qE attribute applies to struct and union types only", name);
79204 + return NULL_TREE;
79205 + }
79206 +
79207 + type = TREE_TYPE(*node);
79208 +
79209 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
79210 + error("%qE attribute applies to struct and union types only", name);
79211 + return NULL_TREE;
79212 + }
79213 +
79214 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
79215 + error("%qE attribute is already applied to the type", name);
79216 + return NULL_TREE;
79217 + }
79218 +
79219 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
79220 + error("%qE attribute used on type that is not constified", name);
79221 + return NULL_TREE;
79222 + }
79223 +
79224 + if (TREE_CODE(*node) == TYPE_DECL) {
79225 + TREE_TYPE(*node) = deconstify_type(type);
79226 + TREE_READONLY(*node) = 0;
79227 + return NULL_TREE;
79228 + }
79229 +
79230 + return NULL_TREE;
79231 +}
79232 +
79233 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
79234 +{
79235 + *no_add_attrs = true;
79236 + if (!TYPE_P(*node)) {
79237 + error("%qE attribute applies to types only", name);
79238 + return NULL_TREE;
79239 + }
79240 +
79241 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
79242 + error("%qE attribute applies to struct and union types only", name);
79243 + return NULL_TREE;
79244 + }
79245 +
79246 + *no_add_attrs = false;
79247 + constify_type(*node);
79248 + return NULL_TREE;
79249 +}
79250 +
79251 +static struct attribute_spec no_const_attr = {
79252 + .name = "no_const",
79253 + .min_length = 0,
79254 + .max_length = 0,
79255 + .decl_required = false,
79256 + .type_required = false,
79257 + .function_type_required = false,
79258 + .handler = handle_no_const_attribute,
79259 +#if BUILDING_GCC_VERSION >= 4007
79260 + .affects_type_identity = true
79261 +#endif
79262 +};
79263 +
79264 +static struct attribute_spec do_const_attr = {
79265 + .name = "do_const",
79266 + .min_length = 0,
79267 + .max_length = 0,
79268 + .decl_required = false,
79269 + .type_required = false,
79270 + .function_type_required = false,
79271 + .handler = handle_do_const_attribute,
79272 +#if BUILDING_GCC_VERSION >= 4007
79273 + .affects_type_identity = true
79274 +#endif
79275 +};
79276 +
79277 +static void register_attributes(void *event_data, void *data)
79278 +{
79279 + register_attribute(&no_const_attr);
79280 + register_attribute(&do_const_attr);
79281 +}
79282 +
79283 +static void constify_type(tree type)
79284 +{
79285 + TYPE_READONLY(type) = 1;
79286 + C_TYPE_FIELDS_READONLY(type) = 1;
79287 +}
79288 +
79289 +static bool is_fptr(tree field)
79290 +{
79291 + tree ptr = TREE_TYPE(field);
79292 +
79293 + if (TREE_CODE(ptr) != POINTER_TYPE)
79294 + return false;
79295 +
79296 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
79297 +}
79298 +
79299 +static bool walk_struct(tree node)
79300 +{
79301 + tree field;
79302 +
79303 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
79304 + return false;
79305 +
79306 + if (TYPE_FIELDS(node) == NULL_TREE)
79307 + return false;
79308 +
79309 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
79310 + tree type = TREE_TYPE(field);
79311 + enum tree_code code = TREE_CODE(type);
79312 + if (code == RECORD_TYPE || code == UNION_TYPE) {
79313 + if (!(walk_struct(type)))
79314 + return false;
79315 + } else if (!is_fptr(field) && !TREE_READONLY(field))
79316 + return false;
79317 + }
79318 + return true;
79319 +}
79320 +
79321 +static void finish_type(void *event_data, void *data)
79322 +{
79323 + tree type = (tree)event_data;
79324 +
79325 + if (type == NULL_TREE)
79326 + return;
79327 +
79328 + if (TYPE_READONLY(type))
79329 + return;
79330 +
79331 + if (walk_struct(type))
79332 + constify_type(type);
79333 +}
79334 +
79335 +static unsigned int check_local_variables(void);
79336 +
79337 +struct gimple_opt_pass pass_local_variable = {
79338 + {
79339 + .type = GIMPLE_PASS,
79340 + .name = "check_local_variables",
79341 + .gate = NULL,
79342 + .execute = check_local_variables,
79343 + .sub = NULL,
79344 + .next = NULL,
79345 + .static_pass_number = 0,
79346 + .tv_id = TV_NONE,
79347 + .properties_required = 0,
79348 + .properties_provided = 0,
79349 + .properties_destroyed = 0,
79350 + .todo_flags_start = 0,
79351 + .todo_flags_finish = 0
79352 + }
79353 +};
79354 +
79355 +static unsigned int check_local_variables(void)
79356 +{
79357 + tree var;
79358 + referenced_var_iterator rvi;
79359 +
79360 +#if BUILDING_GCC_VERSION == 4005
79361 + FOR_EACH_REFERENCED_VAR(var, rvi) {
79362 +#else
79363 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
79364 +#endif
79365 + tree type = TREE_TYPE(var);
79366 +
79367 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
79368 + continue;
79369 +
79370 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
79371 + continue;
79372 +
79373 + if (!TYPE_READONLY(type))
79374 + continue;
79375 +
79376 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
79377 +// continue;
79378 +
79379 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
79380 +// continue;
79381 +
79382 + if (walk_struct(type)) {
79383 + error("constified variable %qE cannot be local", var);
79384 + return 1;
79385 + }
79386 + }
79387 + return 0;
79388 +}
79389 +
79390 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79391 +{
79392 + const char * const plugin_name = plugin_info->base_name;
79393 + const int argc = plugin_info->argc;
79394 + const struct plugin_argument * const argv = plugin_info->argv;
79395 + int i;
79396 + bool constify = true;
79397 +
79398 + struct register_pass_info local_variable_pass_info = {
79399 + .pass = &pass_local_variable.pass,
79400 + .reference_pass_name = "*referenced_vars",
79401 + .ref_pass_instance_number = 0,
79402 + .pos_op = PASS_POS_INSERT_AFTER
79403 + };
79404 +
79405 + if (!plugin_default_version_check(version, &gcc_version)) {
79406 + error(G_("incompatible gcc/plugin versions"));
79407 + return 1;
79408 + }
79409 +
79410 + for (i = 0; i < argc; ++i) {
79411 + if (!(strcmp(argv[i].key, "no-constify"))) {
79412 + constify = false;
79413 + continue;
79414 + }
79415 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79416 + }
79417 +
79418 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
79419 + if (constify) {
79420 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
79421 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
79422 + }
79423 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
79424 +
79425 + return 0;
79426 +}
79427 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
79428 new file mode 100644
79429 index 0000000..a5eabce
79430 --- /dev/null
79431 +++ b/tools/gcc/kallocstat_plugin.c
79432 @@ -0,0 +1,167 @@
79433 +/*
79434 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79435 + * Licensed under the GPL v2
79436 + *
79437 + * Note: the choice of the license means that the compilation process is
79438 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79439 + * but for the kernel it doesn't matter since it doesn't link against
79440 + * any of the gcc libraries
79441 + *
79442 + * gcc plugin to find the distribution of k*alloc sizes
79443 + *
79444 + * TODO:
79445 + *
79446 + * BUGS:
79447 + * - none known
79448 + */
79449 +#include "gcc-plugin.h"
79450 +#include "config.h"
79451 +#include "system.h"
79452 +#include "coretypes.h"
79453 +#include "tree.h"
79454 +#include "tree-pass.h"
79455 +#include "flags.h"
79456 +#include "intl.h"
79457 +#include "toplev.h"
79458 +#include "plugin.h"
79459 +//#include "expr.h" where are you...
79460 +#include "diagnostic.h"
79461 +#include "plugin-version.h"
79462 +#include "tm.h"
79463 +#include "function.h"
79464 +#include "basic-block.h"
79465 +#include "gimple.h"
79466 +#include "rtl.h"
79467 +#include "emit-rtl.h"
79468 +
79469 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79470 +
79471 +int plugin_is_GPL_compatible;
79472 +
79473 +static const char * const kalloc_functions[] = {
79474 + "__kmalloc",
79475 + "kmalloc",
79476 + "kmalloc_large",
79477 + "kmalloc_node",
79478 + "kmalloc_order",
79479 + "kmalloc_order_trace",
79480 + "kmalloc_slab",
79481 + "kzalloc",
79482 + "kzalloc_node",
79483 +};
79484 +
79485 +static struct plugin_info kallocstat_plugin_info = {
79486 + .version = "201111150100",
79487 +};
79488 +
79489 +static unsigned int execute_kallocstat(void);
79490 +
79491 +static struct gimple_opt_pass kallocstat_pass = {
79492 + .pass = {
79493 + .type = GIMPLE_PASS,
79494 + .name = "kallocstat",
79495 + .gate = NULL,
79496 + .execute = execute_kallocstat,
79497 + .sub = NULL,
79498 + .next = NULL,
79499 + .static_pass_number = 0,
79500 + .tv_id = TV_NONE,
79501 + .properties_required = 0,
79502 + .properties_provided = 0,
79503 + .properties_destroyed = 0,
79504 + .todo_flags_start = 0,
79505 + .todo_flags_finish = 0
79506 + }
79507 +};
79508 +
79509 +static bool is_kalloc(const char *fnname)
79510 +{
79511 + size_t i;
79512 +
79513 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
79514 + if (!strcmp(fnname, kalloc_functions[i]))
79515 + return true;
79516 + return false;
79517 +}
79518 +
79519 +static unsigned int execute_kallocstat(void)
79520 +{
79521 + basic_block bb;
79522 +
79523 + // 1. loop through BBs and GIMPLE statements
79524 + FOR_EACH_BB(bb) {
79525 + gimple_stmt_iterator gsi;
79526 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
79527 + // gimple match:
79528 + tree fndecl, size;
79529 + gimple call_stmt;
79530 + const char *fnname;
79531 +
79532 + // is it a call
79533 + call_stmt = gsi_stmt(gsi);
79534 + if (!is_gimple_call(call_stmt))
79535 + continue;
79536 + fndecl = gimple_call_fndecl(call_stmt);
79537 + if (fndecl == NULL_TREE)
79538 + continue;
79539 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
79540 + continue;
79541 +
79542 + // is it a call to k*alloc
79543 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
79544 + if (!is_kalloc(fnname))
79545 + continue;
79546 +
79547 + // is the size arg the result of a simple const assignment
79548 + size = gimple_call_arg(call_stmt, 0);
79549 + while (true) {
79550 + gimple def_stmt;
79551 + expanded_location xloc;
79552 + size_t size_val;
79553 +
79554 + if (TREE_CODE(size) != SSA_NAME)
79555 + break;
79556 + def_stmt = SSA_NAME_DEF_STMT(size);
79557 + if (!def_stmt || !is_gimple_assign(def_stmt))
79558 + break;
79559 + if (gimple_num_ops(def_stmt) != 2)
79560 + break;
79561 + size = gimple_assign_rhs1(def_stmt);
79562 + if (!TREE_CONSTANT(size))
79563 + continue;
79564 + xloc = expand_location(gimple_location(def_stmt));
79565 + if (!xloc.file)
79566 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
79567 + size_val = TREE_INT_CST_LOW(size);
79568 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
79569 + break;
79570 + }
79571 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
79572 +//debug_tree(gimple_call_fn(call_stmt));
79573 +//print_node(stderr, "pax", fndecl, 4);
79574 + }
79575 + }
79576 +
79577 + return 0;
79578 +}
79579 +
79580 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79581 +{
79582 + const char * const plugin_name = plugin_info->base_name;
79583 + struct register_pass_info kallocstat_pass_info = {
79584 + .pass = &kallocstat_pass.pass,
79585 + .reference_pass_name = "ssa",
79586 + .ref_pass_instance_number = 0,
79587 + .pos_op = PASS_POS_INSERT_AFTER
79588 + };
79589 +
79590 + if (!plugin_default_version_check(version, &gcc_version)) {
79591 + error(G_("incompatible gcc/plugin versions"));
79592 + return 1;
79593 + }
79594 +
79595 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
79596 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
79597 +
79598 + return 0;
79599 +}
79600 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
79601 new file mode 100644
79602 index 0000000..008f159
79603 --- /dev/null
79604 +++ b/tools/gcc/kernexec_plugin.c
79605 @@ -0,0 +1,427 @@
79606 +/*
79607 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79608 + * Licensed under the GPL v2
79609 + *
79610 + * Note: the choice of the license means that the compilation process is
79611 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79612 + * but for the kernel it doesn't matter since it doesn't link against
79613 + * any of the gcc libraries
79614 + *
79615 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
79616 + *
79617 + * TODO:
79618 + *
79619 + * BUGS:
79620 + * - none known
79621 + */
79622 +#include "gcc-plugin.h"
79623 +#include "config.h"
79624 +#include "system.h"
79625 +#include "coretypes.h"
79626 +#include "tree.h"
79627 +#include "tree-pass.h"
79628 +#include "flags.h"
79629 +#include "intl.h"
79630 +#include "toplev.h"
79631 +#include "plugin.h"
79632 +//#include "expr.h" where are you...
79633 +#include "diagnostic.h"
79634 +#include "plugin-version.h"
79635 +#include "tm.h"
79636 +#include "function.h"
79637 +#include "basic-block.h"
79638 +#include "gimple.h"
79639 +#include "rtl.h"
79640 +#include "emit-rtl.h"
79641 +#include "tree-flow.h"
79642 +
79643 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79644 +extern rtx emit_move_insn(rtx x, rtx y);
79645 +
79646 +int plugin_is_GPL_compatible;
79647 +
79648 +static struct plugin_info kernexec_plugin_info = {
79649 + .version = "201111291120",
79650 + .help = "method=[bts|or]\tinstrumentation method\n"
79651 +};
79652 +
79653 +static unsigned int execute_kernexec_reload(void);
79654 +static unsigned int execute_kernexec_fptr(void);
79655 +static unsigned int execute_kernexec_retaddr(void);
79656 +static bool kernexec_cmodel_check(void);
79657 +
79658 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
79659 +static void (*kernexec_instrument_retaddr)(rtx);
79660 +
79661 +static struct gimple_opt_pass kernexec_reload_pass = {
79662 + .pass = {
79663 + .type = GIMPLE_PASS,
79664 + .name = "kernexec_reload",
79665 + .gate = kernexec_cmodel_check,
79666 + .execute = execute_kernexec_reload,
79667 + .sub = NULL,
79668 + .next = NULL,
79669 + .static_pass_number = 0,
79670 + .tv_id = TV_NONE,
79671 + .properties_required = 0,
79672 + .properties_provided = 0,
79673 + .properties_destroyed = 0,
79674 + .todo_flags_start = 0,
79675 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
79676 + }
79677 +};
79678 +
79679 +static struct gimple_opt_pass kernexec_fptr_pass = {
79680 + .pass = {
79681 + .type = GIMPLE_PASS,
79682 + .name = "kernexec_fptr",
79683 + .gate = kernexec_cmodel_check,
79684 + .execute = execute_kernexec_fptr,
79685 + .sub = NULL,
79686 + .next = NULL,
79687 + .static_pass_number = 0,
79688 + .tv_id = TV_NONE,
79689 + .properties_required = 0,
79690 + .properties_provided = 0,
79691 + .properties_destroyed = 0,
79692 + .todo_flags_start = 0,
79693 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
79694 + }
79695 +};
79696 +
79697 +static struct rtl_opt_pass kernexec_retaddr_pass = {
79698 + .pass = {
79699 + .type = RTL_PASS,
79700 + .name = "kernexec_retaddr",
79701 + .gate = kernexec_cmodel_check,
79702 + .execute = execute_kernexec_retaddr,
79703 + .sub = NULL,
79704 + .next = NULL,
79705 + .static_pass_number = 0,
79706 + .tv_id = TV_NONE,
79707 + .properties_required = 0,
79708 + .properties_provided = 0,
79709 + .properties_destroyed = 0,
79710 + .todo_flags_start = 0,
79711 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
79712 + }
79713 +};
79714 +
79715 +static bool kernexec_cmodel_check(void)
79716 +{
79717 + tree section;
79718 +
79719 + if (ix86_cmodel != CM_KERNEL)
79720 + return false;
79721 +
79722 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
79723 + if (!section || !TREE_VALUE(section))
79724 + return true;
79725 +
79726 + section = TREE_VALUE(TREE_VALUE(section));
79727 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
79728 + return true;
79729 +
79730 + return false;
79731 +}
79732 +
79733 +/*
79734 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
79735 + */
79736 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
79737 +{
79738 + gimple asm_movabs_stmt;
79739 +
79740 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
79741 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
79742 + gimple_asm_set_volatile(asm_movabs_stmt, true);
79743 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
79744 + update_stmt(asm_movabs_stmt);
79745 +}
79746 +
79747 +/*
79748 + * find all asm() stmts that clobber r10 and add a reload of r10
79749 + */
79750 +static unsigned int execute_kernexec_reload(void)
79751 +{
79752 + basic_block bb;
79753 +
79754 + // 1. loop through BBs and GIMPLE statements
79755 + FOR_EACH_BB(bb) {
79756 + gimple_stmt_iterator gsi;
79757 +
79758 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
79759 + // gimple match: __asm__ ("" : : : "r10");
79760 + gimple asm_stmt;
79761 + size_t nclobbers;
79762 +
79763 + // is it an asm ...
79764 + asm_stmt = gsi_stmt(gsi);
79765 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
79766 + continue;
79767 +
79768 + // ... clobbering r10
79769 + nclobbers = gimple_asm_nclobbers(asm_stmt);
79770 + while (nclobbers--) {
79771 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
79772 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
79773 + continue;
79774 + kernexec_reload_fptr_mask(&gsi);
79775 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
79776 + break;
79777 + }
79778 + }
79779 + }
79780 +
79781 + return 0;
79782 +}
79783 +
79784 +/*
79785 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
79786 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
79787 + */
79788 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
79789 +{
79790 + gimple assign_intptr, assign_new_fptr, call_stmt;
79791 + tree intptr, old_fptr, new_fptr, kernexec_mask;
79792 +
79793 + call_stmt = gsi_stmt(*gsi);
79794 + old_fptr = gimple_call_fn(call_stmt);
79795 +
79796 + // create temporary unsigned long variable used for bitops and cast fptr to it
79797 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
79798 + add_referenced_var(intptr);
79799 + mark_sym_for_renaming(intptr);
79800 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
79801 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
79802 + update_stmt(assign_intptr);
79803 +
79804 + // apply logical or to temporary unsigned long and bitmask
79805 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
79806 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
79807 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
79808 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
79809 + update_stmt(assign_intptr);
79810 +
79811 + // cast temporary unsigned long back to a temporary fptr variable
79812 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
79813 + add_referenced_var(new_fptr);
79814 + mark_sym_for_renaming(new_fptr);
79815 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
79816 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
79817 + update_stmt(assign_new_fptr);
79818 +
79819 + // replace call stmt fn with the new fptr
79820 + gimple_call_set_fn(call_stmt, new_fptr);
79821 + update_stmt(call_stmt);
79822 +}
79823 +
79824 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
79825 +{
79826 + gimple asm_or_stmt, call_stmt;
79827 + tree old_fptr, new_fptr, input, output;
79828 + VEC(tree, gc) *inputs = NULL;
79829 + VEC(tree, gc) *outputs = NULL;
79830 +
79831 + call_stmt = gsi_stmt(*gsi);
79832 + old_fptr = gimple_call_fn(call_stmt);
79833 +
79834 + // create temporary fptr variable
79835 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
79836 + add_referenced_var(new_fptr);
79837 + mark_sym_for_renaming(new_fptr);
79838 +
79839 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
79840 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
79841 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
79842 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
79843 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
79844 + VEC_safe_push(tree, gc, inputs, input);
79845 + VEC_safe_push(tree, gc, outputs, output);
79846 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
79847 + gimple_asm_set_volatile(asm_or_stmt, true);
79848 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
79849 + update_stmt(asm_or_stmt);
79850 +
79851 + // replace call stmt fn with the new fptr
79852 + gimple_call_set_fn(call_stmt, new_fptr);
79853 + update_stmt(call_stmt);
79854 +}
79855 +
79856 +/*
79857 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
79858 + */
79859 +static unsigned int execute_kernexec_fptr(void)
79860 +{
79861 + basic_block bb;
79862 +
79863 + // 1. loop through BBs and GIMPLE statements
79864 + FOR_EACH_BB(bb) {
79865 + gimple_stmt_iterator gsi;
79866 +
79867 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
79868 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
79869 + tree fn;
79870 + gimple call_stmt;
79871 +
79872 + // is it a call ...
79873 + call_stmt = gsi_stmt(gsi);
79874 + if (!is_gimple_call(call_stmt))
79875 + continue;
79876 + fn = gimple_call_fn(call_stmt);
79877 + if (TREE_CODE(fn) == ADDR_EXPR)
79878 + continue;
79879 + if (TREE_CODE(fn) != SSA_NAME)
79880 + gcc_unreachable();
79881 +
79882 + // ... through a function pointer
79883 + fn = SSA_NAME_VAR(fn);
79884 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
79885 + continue;
79886 + fn = TREE_TYPE(fn);
79887 + if (TREE_CODE(fn) != POINTER_TYPE)
79888 + continue;
79889 + fn = TREE_TYPE(fn);
79890 + if (TREE_CODE(fn) != FUNCTION_TYPE)
79891 + continue;
79892 +
79893 + kernexec_instrument_fptr(&gsi);
79894 +
79895 +//debug_tree(gimple_call_fn(call_stmt));
79896 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
79897 + }
79898 + }
79899 +
79900 + return 0;
79901 +}
79902 +
79903 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
79904 +static void kernexec_instrument_retaddr_bts(rtx insn)
79905 +{
79906 + rtx btsq;
79907 + rtvec argvec, constraintvec, labelvec;
79908 + int line;
79909 +
79910 + // create asm volatile("btsq $63,(%%rsp)":::)
79911 + argvec = rtvec_alloc(0);
79912 + constraintvec = rtvec_alloc(0);
79913 + labelvec = rtvec_alloc(0);
79914 + line = expand_location(RTL_LOCATION(insn)).line;
79915 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
79916 + MEM_VOLATILE_P(btsq) = 1;
79917 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
79918 + emit_insn_before(btsq, insn);
79919 +}
79920 +
79921 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
79922 +static void kernexec_instrument_retaddr_or(rtx insn)
79923 +{
79924 + rtx orq;
79925 + rtvec argvec, constraintvec, labelvec;
79926 + int line;
79927 +
79928 + // create asm volatile("orq %%r10,(%%rsp)":::)
79929 + argvec = rtvec_alloc(0);
79930 + constraintvec = rtvec_alloc(0);
79931 + labelvec = rtvec_alloc(0);
79932 + line = expand_location(RTL_LOCATION(insn)).line;
79933 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
79934 + MEM_VOLATILE_P(orq) = 1;
79935 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
79936 + emit_insn_before(orq, insn);
79937 +}
79938 +
79939 +/*
79940 + * find all asm level function returns and forcibly set the highest bit of the return address
79941 + */
79942 +static unsigned int execute_kernexec_retaddr(void)
79943 +{
79944 + rtx insn;
79945 +
79946 + // 1. find function returns
79947 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
79948 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
79949 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
79950 + rtx body;
79951 +
79952 + // is it a retn
79953 + if (!JUMP_P(insn))
79954 + continue;
79955 + body = PATTERN(insn);
79956 + if (GET_CODE(body) == PARALLEL)
79957 + body = XVECEXP(body, 0, 0);
79958 + if (GET_CODE(body) != RETURN)
79959 + continue;
79960 + kernexec_instrument_retaddr(insn);
79961 + }
79962 +
79963 +// print_simple_rtl(stderr, get_insns());
79964 +// print_rtl(stderr, get_insns());
79965 +
79966 + return 0;
79967 +}
79968 +
79969 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79970 +{
79971 + const char * const plugin_name = plugin_info->base_name;
79972 + const int argc = plugin_info->argc;
79973 + const struct plugin_argument * const argv = plugin_info->argv;
79974 + int i;
79975 + struct register_pass_info kernexec_reload_pass_info = {
79976 + .pass = &kernexec_reload_pass.pass,
79977 + .reference_pass_name = "ssa",
79978 + .ref_pass_instance_number = 0,
79979 + .pos_op = PASS_POS_INSERT_AFTER
79980 + };
79981 + struct register_pass_info kernexec_fptr_pass_info = {
79982 + .pass = &kernexec_fptr_pass.pass,
79983 + .reference_pass_name = "ssa",
79984 + .ref_pass_instance_number = 0,
79985 + .pos_op = PASS_POS_INSERT_AFTER
79986 + };
79987 + struct register_pass_info kernexec_retaddr_pass_info = {
79988 + .pass = &kernexec_retaddr_pass.pass,
79989 + .reference_pass_name = "pro_and_epilogue",
79990 + .ref_pass_instance_number = 0,
79991 + .pos_op = PASS_POS_INSERT_AFTER
79992 + };
79993 +
79994 + if (!plugin_default_version_check(version, &gcc_version)) {
79995 + error(G_("incompatible gcc/plugin versions"));
79996 + return 1;
79997 + }
79998 +
79999 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
80000 +
80001 + if (TARGET_64BIT == 0)
80002 + return 0;
80003 +
80004 + for (i = 0; i < argc; ++i) {
80005 + if (!strcmp(argv[i].key, "method")) {
80006 + if (!argv[i].value) {
80007 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80008 + continue;
80009 + }
80010 + if (!strcmp(argv[i].value, "bts")) {
80011 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
80012 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
80013 + } else if (!strcmp(argv[i].value, "or")) {
80014 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
80015 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
80016 + fix_register("r10", 1, 1);
80017 + } else
80018 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80019 + continue;
80020 + }
80021 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80022 + }
80023 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
80024 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
80025 +
80026 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
80027 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
80028 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
80029 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
80030 +
80031 + return 0;
80032 +}
80033 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
80034 new file mode 100644
80035 index 0000000..b87ec9d
80036 --- /dev/null
80037 +++ b/tools/gcc/stackleak_plugin.c
80038 @@ -0,0 +1,313 @@
80039 +/*
80040 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80041 + * Licensed under the GPL v2
80042 + *
80043 + * Note: the choice of the license means that the compilation process is
80044 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80045 + * but for the kernel it doesn't matter since it doesn't link against
80046 + * any of the gcc libraries
80047 + *
80048 + * gcc plugin to help implement various PaX features
80049 + *
80050 + * - track lowest stack pointer
80051 + *
80052 + * TODO:
80053 + * - initialize all local variables
80054 + *
80055 + * BUGS:
80056 + * - none known
80057 + */
80058 +#include "gcc-plugin.h"
80059 +#include "config.h"
80060 +#include "system.h"
80061 +#include "coretypes.h"
80062 +#include "tree.h"
80063 +#include "tree-pass.h"
80064 +#include "flags.h"
80065 +#include "intl.h"
80066 +#include "toplev.h"
80067 +#include "plugin.h"
80068 +//#include "expr.h" where are you...
80069 +#include "diagnostic.h"
80070 +#include "plugin-version.h"
80071 +#include "tm.h"
80072 +#include "function.h"
80073 +#include "basic-block.h"
80074 +#include "gimple.h"
80075 +#include "rtl.h"
80076 +#include "emit-rtl.h"
80077 +
80078 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80079 +
80080 +int plugin_is_GPL_compatible;
80081 +
80082 +static int track_frame_size = -1;
80083 +static const char track_function[] = "pax_track_stack";
80084 +static const char check_function[] = "pax_check_alloca";
80085 +static bool init_locals;
80086 +
80087 +static struct plugin_info stackleak_plugin_info = {
80088 + .version = "201203140940",
80089 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
80090 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
80091 +};
80092 +
80093 +static bool gate_stackleak_track_stack(void);
80094 +static unsigned int execute_stackleak_tree_instrument(void);
80095 +static unsigned int execute_stackleak_final(void);
80096 +
80097 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
80098 + .pass = {
80099 + .type = GIMPLE_PASS,
80100 + .name = "stackleak_tree_instrument",
80101 + .gate = gate_stackleak_track_stack,
80102 + .execute = execute_stackleak_tree_instrument,
80103 + .sub = NULL,
80104 + .next = NULL,
80105 + .static_pass_number = 0,
80106 + .tv_id = TV_NONE,
80107 + .properties_required = PROP_gimple_leh | PROP_cfg,
80108 + .properties_provided = 0,
80109 + .properties_destroyed = 0,
80110 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
80111 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
80112 + }
80113 +};
80114 +
80115 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
80116 + .pass = {
80117 + .type = RTL_PASS,
80118 + .name = "stackleak_final",
80119 + .gate = gate_stackleak_track_stack,
80120 + .execute = execute_stackleak_final,
80121 + .sub = NULL,
80122 + .next = NULL,
80123 + .static_pass_number = 0,
80124 + .tv_id = TV_NONE,
80125 + .properties_required = 0,
80126 + .properties_provided = 0,
80127 + .properties_destroyed = 0,
80128 + .todo_flags_start = 0,
80129 + .todo_flags_finish = TODO_dump_func
80130 + }
80131 +};
80132 +
80133 +static bool gate_stackleak_track_stack(void)
80134 +{
80135 + return track_frame_size >= 0;
80136 +}
80137 +
80138 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
80139 +{
80140 + gimple check_alloca;
80141 + tree fntype, fndecl, alloca_size;
80142 +
80143 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
80144 + fndecl = build_fn_decl(check_function, fntype);
80145 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
80146 +
80147 + // insert call to void pax_check_alloca(unsigned long size)
80148 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
80149 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
80150 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
80151 +}
80152 +
80153 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
80154 +{
80155 + gimple track_stack;
80156 + tree fntype, fndecl;
80157 +
80158 + fntype = build_function_type_list(void_type_node, NULL_TREE);
80159 + fndecl = build_fn_decl(track_function, fntype);
80160 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
80161 +
80162 + // insert call to void pax_track_stack(void)
80163 + track_stack = gimple_build_call(fndecl, 0);
80164 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
80165 +}
80166 +
80167 +#if BUILDING_GCC_VERSION == 4005
80168 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
80169 +{
80170 + tree fndecl;
80171 +
80172 + if (!is_gimple_call(stmt))
80173 + return false;
80174 + fndecl = gimple_call_fndecl(stmt);
80175 + if (!fndecl)
80176 + return false;
80177 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
80178 + return false;
80179 +// print_node(stderr, "pax", fndecl, 4);
80180 + return DECL_FUNCTION_CODE(fndecl) == code;
80181 +}
80182 +#endif
80183 +
80184 +static bool is_alloca(gimple stmt)
80185 +{
80186 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
80187 + return true;
80188 +
80189 +#if BUILDING_GCC_VERSION >= 4007
80190 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
80191 + return true;
80192 +#endif
80193 +
80194 + return false;
80195 +}
80196 +
80197 +static unsigned int execute_stackleak_tree_instrument(void)
80198 +{
80199 + basic_block bb, entry_bb;
80200 + bool prologue_instrumented = false, is_leaf = true;
80201 +
80202 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
80203 +
80204 + // 1. loop through BBs and GIMPLE statements
80205 + FOR_EACH_BB(bb) {
80206 + gimple_stmt_iterator gsi;
80207 +
80208 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80209 + gimple stmt;
80210 +
80211 + stmt = gsi_stmt(gsi);
80212 +
80213 + if (is_gimple_call(stmt))
80214 + is_leaf = false;
80215 +
80216 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
80217 + if (!is_alloca(stmt))
80218 + continue;
80219 +
80220 + // 2. insert stack overflow check before each __builtin_alloca call
80221 + stackleak_check_alloca(&gsi);
80222 +
80223 + // 3. insert track call after each __builtin_alloca call
80224 + stackleak_add_instrumentation(&gsi);
80225 + if (bb == entry_bb)
80226 + prologue_instrumented = true;
80227 + }
80228 + }
80229 +
80230 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
80231 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
80232 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
80233 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
80234 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
80235 + return 0;
80236 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
80237 + return 0;
80238 +
80239 + // 4. insert track call at the beginning
80240 + if (!prologue_instrumented) {
80241 + gimple_stmt_iterator gsi;
80242 +
80243 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
80244 + if (dom_info_available_p(CDI_DOMINATORS))
80245 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
80246 + gsi = gsi_start_bb(bb);
80247 + stackleak_add_instrumentation(&gsi);
80248 + }
80249 +
80250 + return 0;
80251 +}
80252 +
80253 +static unsigned int execute_stackleak_final(void)
80254 +{
80255 + rtx insn;
80256 +
80257 + if (cfun->calls_alloca)
80258 + return 0;
80259 +
80260 + // keep calls only if function frame is big enough
80261 + if (get_frame_size() >= track_frame_size)
80262 + return 0;
80263 +
80264 + // 1. find pax_track_stack calls
80265 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
80266 + // 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))
80267 + rtx body;
80268 +
80269 + if (!CALL_P(insn))
80270 + continue;
80271 + body = PATTERN(insn);
80272 + if (GET_CODE(body) != CALL)
80273 + continue;
80274 + body = XEXP(body, 0);
80275 + if (GET_CODE(body) != MEM)
80276 + continue;
80277 + body = XEXP(body, 0);
80278 + if (GET_CODE(body) != SYMBOL_REF)
80279 + continue;
80280 + if (strcmp(XSTR(body, 0), track_function))
80281 + continue;
80282 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
80283 + // 2. delete call
80284 + insn = delete_insn_and_edges(insn);
80285 +#if BUILDING_GCC_VERSION >= 4007
80286 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
80287 + insn = delete_insn_and_edges(insn);
80288 +#endif
80289 + }
80290 +
80291 +// print_simple_rtl(stderr, get_insns());
80292 +// print_rtl(stderr, get_insns());
80293 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
80294 +
80295 + return 0;
80296 +}
80297 +
80298 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80299 +{
80300 + const char * const plugin_name = plugin_info->base_name;
80301 + const int argc = plugin_info->argc;
80302 + const struct plugin_argument * const argv = plugin_info->argv;
80303 + int i;
80304 + struct register_pass_info stackleak_tree_instrument_pass_info = {
80305 + .pass = &stackleak_tree_instrument_pass.pass,
80306 +// .reference_pass_name = "tree_profile",
80307 + .reference_pass_name = "optimized",
80308 + .ref_pass_instance_number = 0,
80309 + .pos_op = PASS_POS_INSERT_BEFORE
80310 + };
80311 + struct register_pass_info stackleak_final_pass_info = {
80312 + .pass = &stackleak_final_rtl_opt_pass.pass,
80313 + .reference_pass_name = "final",
80314 + .ref_pass_instance_number = 0,
80315 + .pos_op = PASS_POS_INSERT_BEFORE
80316 + };
80317 +
80318 + if (!plugin_default_version_check(version, &gcc_version)) {
80319 + error(G_("incompatible gcc/plugin versions"));
80320 + return 1;
80321 + }
80322 +
80323 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
80324 +
80325 + for (i = 0; i < argc; ++i) {
80326 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
80327 + if (!argv[i].value) {
80328 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80329 + continue;
80330 + }
80331 + track_frame_size = atoi(argv[i].value);
80332 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
80333 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80334 + continue;
80335 + }
80336 + if (!strcmp(argv[i].key, "initialize-locals")) {
80337 + if (argv[i].value) {
80338 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80339 + continue;
80340 + }
80341 + init_locals = true;
80342 + continue;
80343 + }
80344 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80345 + }
80346 +
80347 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
80348 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
80349 +
80350 + return 0;
80351 +}
80352 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
80353 index 6789d78..4afd019 100644
80354 --- a/tools/perf/util/include/asm/alternative-asm.h
80355 +++ b/tools/perf/util/include/asm/alternative-asm.h
80356 @@ -5,4 +5,7 @@
80357
80358 #define altinstruction_entry #
80359
80360 + .macro pax_force_retaddr rip=0, reload=0
80361 + .endm
80362 +
80363 #endif
80364 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
80365 index af0f22f..9a7d479 100644
80366 --- a/usr/gen_init_cpio.c
80367 +++ b/usr/gen_init_cpio.c
80368 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
80369 int retval;
80370 int rc = -1;
80371 int namesize;
80372 - int i;
80373 + unsigned int i;
80374
80375 mode |= S_IFREG;
80376
80377 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
80378 *env_var = *expanded = '\0';
80379 strncat(env_var, start + 2, end - start - 2);
80380 strncat(expanded, new_location, start - new_location);
80381 - strncat(expanded, getenv(env_var), PATH_MAX);
80382 - strncat(expanded, end + 1, PATH_MAX);
80383 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
80384 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
80385 strncpy(new_location, expanded, PATH_MAX);
80386 + new_location[PATH_MAX] = 0;
80387 } else
80388 break;
80389 }
80390 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
80391 index a91f980..a58d32c 100644
80392 --- a/virt/kvm/kvm_main.c
80393 +++ b/virt/kvm/kvm_main.c
80394 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
80395
80396 static cpumask_var_t cpus_hardware_enabled;
80397 static int kvm_usage_count = 0;
80398 -static atomic_t hardware_enable_failed;
80399 +static atomic_unchecked_t hardware_enable_failed;
80400
80401 struct kmem_cache *kvm_vcpu_cache;
80402 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
80403 @@ -2312,7 +2312,7 @@ static void hardware_enable_nolock(void *junk)
80404
80405 if (r) {
80406 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
80407 - atomic_inc(&hardware_enable_failed);
80408 + atomic_inc_unchecked(&hardware_enable_failed);
80409 printk(KERN_INFO "kvm: enabling virtualization on "
80410 "CPU%d failed\n", cpu);
80411 }
80412 @@ -2366,10 +2366,10 @@ static int hardware_enable_all(void)
80413
80414 kvm_usage_count++;
80415 if (kvm_usage_count == 1) {
80416 - atomic_set(&hardware_enable_failed, 0);
80417 + atomic_set_unchecked(&hardware_enable_failed, 0);
80418 on_each_cpu(hardware_enable_nolock, NULL, 1);
80419
80420 - if (atomic_read(&hardware_enable_failed)) {
80421 + if (atomic_read_unchecked(&hardware_enable_failed)) {
80422 hardware_disable_all_nolock();
80423 r = -EBUSY;
80424 }
80425 @@ -2732,7 +2732,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
80426 kvm_arch_vcpu_put(vcpu);
80427 }
80428
80429 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80430 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80431 struct module *module)
80432 {
80433 int r;
80434 @@ -2795,7 +2795,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80435 if (!vcpu_align)
80436 vcpu_align = __alignof__(struct kvm_vcpu);
80437 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
80438 - 0, NULL);
80439 + SLAB_USERCOPY, NULL);
80440 if (!kvm_vcpu_cache) {
80441 r = -ENOMEM;
80442 goto out_free_3;
80443 @@ -2805,9 +2805,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80444 if (r)
80445 goto out_free;
80446
80447 - kvm_chardev_ops.owner = module;
80448 - kvm_vm_fops.owner = module;
80449 - kvm_vcpu_fops.owner = module;
80450 + pax_open_kernel();
80451 + *(void **)&kvm_chardev_ops.owner = module;
80452 + *(void **)&kvm_vm_fops.owner = module;
80453 + *(void **)&kvm_vcpu_fops.owner = module;
80454 + pax_close_kernel();
80455
80456 r = misc_register(&kvm_dev);
80457 if (r) {