]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.2.2-2.6.32.46-201110200052.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.32.46-201110200052.patch
1 diff -urNp linux-2.6.32.46/Documentation/dontdiff linux-2.6.32.46/Documentation/dontdiff
2 --- linux-2.6.32.46/Documentation/dontdiff 2011-03-27 14:31:47.000000000 -0400
3 +++ linux-2.6.32.46/Documentation/dontdiff 2011-08-21 18:59:02.000000000 -0400
4 @@ -1,13 +1,16 @@
5 *.a
6 *.aux
7 *.bin
8 +*.cis
9 *.cpio
10 *.csp
11 +*.dbg
12 *.dsp
13 *.dvi
14 *.elf
15 *.eps
16 *.fw
17 +*.gcno
18 *.gen.S
19 *.gif
20 *.grep
21 @@ -38,8 +41,10 @@
22 *.tab.h
23 *.tex
24 *.ver
25 +*.vim
26 *.xml
27 *_MODULES
28 +*_reg_safe.h
29 *_vga16.c
30 *~
31 *.9
32 @@ -49,11 +54,16 @@
33 53c700_d.h
34 CVS
35 ChangeSet
36 +GPATH
37 +GRTAGS
38 +GSYMS
39 +GTAGS
40 Image
41 Kerntypes
42 Module.markers
43 Module.symvers
44 PENDING
45 +PERF*
46 SCCS
47 System.map*
48 TAGS
49 @@ -76,7 +86,11 @@ btfixupprep
50 build
51 bvmlinux
52 bzImage*
53 +capability_names.h
54 +capflags.c
55 classlist.h*
56 +clut_vga16.c
57 +common-cmds.h
58 comp*.log
59 compile.h*
60 conf
61 @@ -97,19 +111,21 @@ elfconfig.h*
62 fixdep
63 fore200e_mkfirm
64 fore200e_pca_fw.c*
65 +gate.lds
66 gconf
67 gen-devlist
68 gen_crc32table
69 gen_init_cpio
70 genksyms
71 *_gray256.c
72 +hash
73 ihex2fw
74 ikconfig.h*
75 initramfs_data.cpio
76 +initramfs_data.cpio.bz2
77 initramfs_data.cpio.gz
78 initramfs_list
79 kallsyms
80 -kconfig
81 keywords.c
82 ksym.c*
83 ksym.h*
84 @@ -133,7 +149,9 @@ mkboot
85 mkbugboot
86 mkcpustr
87 mkdep
88 +mkpiggy
89 mkprep
90 +mkregtable
91 mktables
92 mktree
93 modpost
94 @@ -149,6 +167,7 @@ patches*
95 pca200e.bin
96 pca200e_ecd.bin2
97 piggy.gz
98 +piggy.S
99 piggyback
100 pnmtologo
101 ppc_defs.h*
102 @@ -157,12 +176,15 @@ qconf
103 raid6altivec*.c
104 raid6int*.c
105 raid6tables.c
106 +regdb.c
107 relocs
108 +rlim_names.h
109 series
110 setup
111 setup.bin
112 setup.elf
113 sImage
114 +slabinfo
115 sm_tbl*
116 split-include
117 syscalltab.h
118 @@ -186,14 +208,20 @@ version.h*
119 vmlinux
120 vmlinux-*
121 vmlinux.aout
122 +vmlinux.bin.all
123 +vmlinux.bin.bz2
124 vmlinux.lds
125 +vmlinux.relocs
126 +voffset.h
127 vsyscall.lds
128 vsyscall_32.lds
129 wanxlfw.inc
130 uImage
131 unifdef
132 +utsrelease.h
133 wakeup.bin
134 wakeup.elf
135 wakeup.lds
136 zImage*
137 zconf.hash.c
138 +zoffset.h
139 diff -urNp linux-2.6.32.46/Documentation/kernel-parameters.txt linux-2.6.32.46/Documentation/kernel-parameters.txt
140 --- linux-2.6.32.46/Documentation/kernel-parameters.txt 2011-03-27 14:31:47.000000000 -0400
141 +++ linux-2.6.32.46/Documentation/kernel-parameters.txt 2011-04-17 15:56:45.000000000 -0400
142 @@ -1837,6 +1837,13 @@ and is between 256 and 4096 characters.
143 the specified number of seconds. This is to be used if
144 your oopses keep scrolling off the screen.
145
146 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
147 + virtualization environments that don't cope well with the
148 + expand down segment used by UDEREF on X86-32 or the frequent
149 + page table updates on X86-64.
150 +
151 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
152 +
153 pcbit= [HW,ISDN]
154
155 pcd. [PARIDE]
156 diff -urNp linux-2.6.32.46/Makefile linux-2.6.32.46/Makefile
157 --- linux-2.6.32.46/Makefile 2011-08-29 22:24:44.000000000 -0400
158 +++ linux-2.6.32.46/Makefile 2011-10-08 08:14:40.000000000 -0400
159 @@ -221,8 +221,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
160
161 HOSTCC = gcc
162 HOSTCXX = g++
163 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
164 -HOSTCXXFLAGS = -O2
165 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
166 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
167 +HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
168
169 # Decide whether to build built-in, modular, or both.
170 # Normally, just do built-in.
171 @@ -342,10 +343,12 @@ LINUXINCLUDE := -Iinclude \
172 KBUILD_CPPFLAGS := -D__KERNEL__
173
174 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
175 + -W -Wno-unused-parameter -Wno-missing-field-initializers \
176 -fno-strict-aliasing -fno-common \
177 -Werror-implicit-function-declaration \
178 -Wno-format-security \
179 -fno-delete-null-pointer-checks
180 +KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
181 KBUILD_AFLAGS := -D__ASSEMBLY__
182
183 # Read KERNELRELEASE from include/config/kernel.release (if it exists)
184 @@ -376,8 +379,8 @@ export RCS_TAR_IGNORE := --exclude SCCS
185 # Rules shared between *config targets and build targets
186
187 # Basic helpers built in scripts/
188 -PHONY += scripts_basic
189 -scripts_basic:
190 +PHONY += scripts_basic gcc-plugins
191 +scripts_basic: gcc-plugins
192 $(Q)$(MAKE) $(build)=scripts/basic
193
194 # To avoid any implicit rule to kick in, define an empty command.
195 @@ -403,7 +406,7 @@ endif
196 # of make so .config is not included in this case either (for *config).
197
198 no-dot-config-targets := clean mrproper distclean \
199 - cscope TAGS tags help %docs check% \
200 + cscope gtags TAGS tags help %docs check% \
201 include/linux/version.h headers_% \
202 kernelrelease kernelversion
203
204 @@ -526,6 +529,36 @@ else
205 KBUILD_CFLAGS += -O2
206 endif
207
208 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
209 +CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
210 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
211 +STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -fplugin-arg-stackleak_plugin-track-lowest-sp=100
212 +endif
213 +ifdef CONFIG_KALLOCSTAT_PLUGIN
214 +KALLOCSTAT_PLUGIN := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
215 +endif
216 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
217 +KERNEXEC_PLUGIN := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
218 +endif
219 +ifdef CONFIG_CHECKER_PLUGIN
220 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
221 +CHECKER_PLUGIN := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
222 +endif
223 +endif
224 +GCC_PLUGINS := $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN) $(KALLOCSTAT_PLUGIN) $(KERNEXEC_PLUGIN) $(CHECKER_PLUGIN)
225 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
226 +gcc-plugins:
227 + $(Q)$(MAKE) $(build)=tools/gcc
228 +else
229 +gcc-plugins:
230 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
231 + $(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.))
232 +else
233 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
234 +endif
235 + $(Q)echo "PAX_MEMORY_STACKLEAK and constification will be less secure"
236 +endif
237 +
238 include $(srctree)/arch/$(SRCARCH)/Makefile
239
240 ifneq ($(CONFIG_FRAME_WARN),0)
241 @@ -644,7 +677,7 @@ export mod_strip_cmd
242
243
244 ifeq ($(KBUILD_EXTMOD),)
245 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
246 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
247
248 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
249 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
250 @@ -865,6 +898,7 @@ vmlinux.o: $(modpost-init) $(vmlinux-mai
251
252 # The actual objects are generated when descending,
253 # make sure no implicit rule kicks in
254 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS)
255 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
256
257 # Handle descending into subdirectories listed in $(vmlinux-dirs)
258 @@ -874,7 +908,7 @@ $(sort $(vmlinux-init) $(vmlinux-main))
259 # Error messages still appears in the original language
260
261 PHONY += $(vmlinux-dirs)
262 -$(vmlinux-dirs): prepare scripts
263 +$(vmlinux-dirs): gcc-plugins prepare scripts
264 $(Q)$(MAKE) $(build)=$@
265
266 # Build the kernel release string
267 @@ -983,6 +1017,7 @@ prepare0: archprepare FORCE
268 $(Q)$(MAKE) $(build)=. missing-syscalls
269
270 # All the preparing..
271 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS),$(KBUILD_CFLAGS))
272 prepare: prepare0
273
274 # The asm symlink changes when $(ARCH) changes.
275 @@ -1124,6 +1159,7 @@ all: modules
276 # using awk while concatenating to the final file.
277
278 PHONY += modules
279 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
280 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
281 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
282 @$(kecho) ' Building modules, stage 2.';
283 @@ -1133,7 +1169,7 @@ modules: $(vmlinux-dirs) $(if $(KBUILD_B
284
285 # Target to prepare building external modules
286 PHONY += modules_prepare
287 -modules_prepare: prepare scripts
288 +modules_prepare: gcc-plugins prepare scripts
289
290 # Target to install modules
291 PHONY += modules_install
292 @@ -1198,7 +1234,7 @@ MRPROPER_FILES += .config .config.old in
293 include/linux/autoconf.h include/linux/version.h \
294 include/linux/utsrelease.h \
295 include/linux/bounds.h include/asm*/asm-offsets.h \
296 - Module.symvers Module.markers tags TAGS cscope*
297 + Module.symvers Module.markers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
298
299 # clean - Delete most, but leave enough to build external modules
300 #
301 @@ -1242,7 +1278,7 @@ distclean: mrproper
302 @find $(srctree) $(RCS_FIND_IGNORE) \
303 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
304 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
305 - -o -name '.*.rej' -o -size 0 \
306 + -o -name '.*.rej' -o -name '*.so' -o -size 0 \
307 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
308 -type f -print | xargs rm -f
309
310 @@ -1289,6 +1325,7 @@ help:
311 @echo ' modules_prepare - Set up for building external modules'
312 @echo ' tags/TAGS - Generate tags file for editors'
313 @echo ' cscope - Generate cscope index'
314 + @echo ' gtags - Generate GNU GLOBAL index'
315 @echo ' kernelrelease - Output the release version string'
316 @echo ' kernelversion - Output the version stored in Makefile'
317 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
318 @@ -1390,6 +1427,7 @@ PHONY += $(module-dirs) modules
319 $(module-dirs): crmodverdir $(objtree)/Module.symvers
320 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
321
322 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
323 modules: $(module-dirs)
324 @$(kecho) ' Building modules, stage 2.';
325 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
326 @@ -1445,7 +1483,7 @@ endif # KBUILD_EXTMOD
327 quiet_cmd_tags = GEN $@
328 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
329
330 -tags TAGS cscope: FORCE
331 +tags TAGS cscope gtags: FORCE
332 $(call cmd,tags)
333
334 # Scripts to check various things for consistency
335 @@ -1510,17 +1548,19 @@ else
336 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
337 endif
338
339 -%.s: %.c prepare scripts FORCE
340 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS)
341 +%.s: %.c gcc-plugins prepare scripts FORCE
342 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
343 %.i: %.c prepare scripts FORCE
344 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
345 -%.o: %.c prepare scripts FORCE
346 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS)
347 +%.o: %.c gcc-plugins prepare scripts FORCE
348 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
349 %.lst: %.c prepare scripts FORCE
350 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
351 -%.s: %.S prepare scripts FORCE
352 +%.s: %.S gcc-plugins prepare scripts FORCE
353 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
354 -%.o: %.S prepare scripts FORCE
355 +%.o: %.S gcc-plugins prepare scripts FORCE
356 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
357 %.symtypes: %.c prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359 @@ -1530,11 +1570,13 @@ endif
360 $(cmd_crmodverdir)
361 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
362 $(build)=$(build-dir)
363 -%/: prepare scripts FORCE
364 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS)
365 +%/: gcc-plugins prepare scripts FORCE
366 $(cmd_crmodverdir)
367 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
368 $(build)=$(build-dir)
369 -%.ko: prepare scripts FORCE
370 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS)
371 +%.ko: gcc-plugins prepare scripts FORCE
372 $(cmd_crmodverdir)
373 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
374 $(build)=$(build-dir) $(@:.ko=.o)
375 diff -urNp linux-2.6.32.46/arch/alpha/include/asm/elf.h linux-2.6.32.46/arch/alpha/include/asm/elf.h
376 --- linux-2.6.32.46/arch/alpha/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
377 +++ linux-2.6.32.46/arch/alpha/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
378 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
379
380 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
381
382 +#ifdef CONFIG_PAX_ASLR
383 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
384 +
385 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
386 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
387 +#endif
388 +
389 /* $0 is set by ld.so to a pointer to a function which might be
390 registered using atexit. This provides a mean for the dynamic
391 linker to call DT_FINI functions for shared libraries that have
392 diff -urNp linux-2.6.32.46/arch/alpha/include/asm/pgtable.h linux-2.6.32.46/arch/alpha/include/asm/pgtable.h
393 --- linux-2.6.32.46/arch/alpha/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
394 +++ linux-2.6.32.46/arch/alpha/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
395 @@ -101,6 +101,17 @@ struct vm_area_struct;
396 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
397 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
398 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
399 +
400 +#ifdef CONFIG_PAX_PAGEEXEC
401 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
402 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
403 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
404 +#else
405 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
406 +# define PAGE_COPY_NOEXEC PAGE_COPY
407 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
408 +#endif
409 +
410 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
411
412 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
413 diff -urNp linux-2.6.32.46/arch/alpha/kernel/module.c linux-2.6.32.46/arch/alpha/kernel/module.c
414 --- linux-2.6.32.46/arch/alpha/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
415 +++ linux-2.6.32.46/arch/alpha/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
416 @@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
417
418 /* The small sections were sorted to the end of the segment.
419 The following should definitely cover them. */
420 - gp = (u64)me->module_core + me->core_size - 0x8000;
421 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
422 got = sechdrs[me->arch.gotsecindex].sh_addr;
423
424 for (i = 0; i < n; i++) {
425 diff -urNp linux-2.6.32.46/arch/alpha/kernel/osf_sys.c linux-2.6.32.46/arch/alpha/kernel/osf_sys.c
426 --- linux-2.6.32.46/arch/alpha/kernel/osf_sys.c 2011-08-09 18:35:28.000000000 -0400
427 +++ linux-2.6.32.46/arch/alpha/kernel/osf_sys.c 2011-06-13 17:19:47.000000000 -0400
428 @@ -1172,7 +1172,7 @@ arch_get_unmapped_area_1(unsigned long a
429 /* At this point: (!vma || addr < vma->vm_end). */
430 if (limit - len < addr)
431 return -ENOMEM;
432 - if (!vma || addr + len <= vma->vm_start)
433 + if (check_heap_stack_gap(vma, addr, len))
434 return addr;
435 addr = vma->vm_end;
436 vma = vma->vm_next;
437 @@ -1208,6 +1208,10 @@ arch_get_unmapped_area(struct file *filp
438 merely specific addresses, but regions of memory -- perhaps
439 this feature should be incorporated into all ports? */
440
441 +#ifdef CONFIG_PAX_RANDMMAP
442 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
443 +#endif
444 +
445 if (addr) {
446 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
447 if (addr != (unsigned long) -ENOMEM)
448 @@ -1215,8 +1219,8 @@ arch_get_unmapped_area(struct file *filp
449 }
450
451 /* Next, try allocating at TASK_UNMAPPED_BASE. */
452 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
453 - len, limit);
454 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
455 +
456 if (addr != (unsigned long) -ENOMEM)
457 return addr;
458
459 diff -urNp linux-2.6.32.46/arch/alpha/mm/fault.c linux-2.6.32.46/arch/alpha/mm/fault.c
460 --- linux-2.6.32.46/arch/alpha/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
461 +++ linux-2.6.32.46/arch/alpha/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
462 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
463 __reload_thread(pcb);
464 }
465
466 +#ifdef CONFIG_PAX_PAGEEXEC
467 +/*
468 + * PaX: decide what to do with offenders (regs->pc = fault address)
469 + *
470 + * returns 1 when task should be killed
471 + * 2 when patched PLT trampoline was detected
472 + * 3 when unpatched PLT trampoline was detected
473 + */
474 +static int pax_handle_fetch_fault(struct pt_regs *regs)
475 +{
476 +
477 +#ifdef CONFIG_PAX_EMUPLT
478 + int err;
479 +
480 + do { /* PaX: patched PLT emulation #1 */
481 + unsigned int ldah, ldq, jmp;
482 +
483 + err = get_user(ldah, (unsigned int *)regs->pc);
484 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
485 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
486 +
487 + if (err)
488 + break;
489 +
490 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
491 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
492 + jmp == 0x6BFB0000U)
493 + {
494 + unsigned long r27, addr;
495 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
496 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
497 +
498 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
499 + err = get_user(r27, (unsigned long *)addr);
500 + if (err)
501 + break;
502 +
503 + regs->r27 = r27;
504 + regs->pc = r27;
505 + return 2;
506 + }
507 + } while (0);
508 +
509 + do { /* PaX: patched PLT emulation #2 */
510 + unsigned int ldah, lda, br;
511 +
512 + err = get_user(ldah, (unsigned int *)regs->pc);
513 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
514 + err |= get_user(br, (unsigned int *)(regs->pc+8));
515 +
516 + if (err)
517 + break;
518 +
519 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
520 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
521 + (br & 0xFFE00000U) == 0xC3E00000U)
522 + {
523 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
524 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
525 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
526 +
527 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
528 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
529 + return 2;
530 + }
531 + } while (0);
532 +
533 + do { /* PaX: unpatched PLT emulation */
534 + unsigned int br;
535 +
536 + err = get_user(br, (unsigned int *)regs->pc);
537 +
538 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
539 + unsigned int br2, ldq, nop, jmp;
540 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
541 +
542 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
543 + err = get_user(br2, (unsigned int *)addr);
544 + err |= get_user(ldq, (unsigned int *)(addr+4));
545 + err |= get_user(nop, (unsigned int *)(addr+8));
546 + err |= get_user(jmp, (unsigned int *)(addr+12));
547 + err |= get_user(resolver, (unsigned long *)(addr+16));
548 +
549 + if (err)
550 + break;
551 +
552 + if (br2 == 0xC3600000U &&
553 + ldq == 0xA77B000CU &&
554 + nop == 0x47FF041FU &&
555 + jmp == 0x6B7B0000U)
556 + {
557 + regs->r28 = regs->pc+4;
558 + regs->r27 = addr+16;
559 + regs->pc = resolver;
560 + return 3;
561 + }
562 + }
563 + } while (0);
564 +#endif
565 +
566 + return 1;
567 +}
568 +
569 +void pax_report_insns(void *pc, void *sp)
570 +{
571 + unsigned long i;
572 +
573 + printk(KERN_ERR "PAX: bytes at PC: ");
574 + for (i = 0; i < 5; i++) {
575 + unsigned int c;
576 + if (get_user(c, (unsigned int *)pc+i))
577 + printk(KERN_CONT "???????? ");
578 + else
579 + printk(KERN_CONT "%08x ", c);
580 + }
581 + printk("\n");
582 +}
583 +#endif
584
585 /*
586 * This routine handles page faults. It determines the address,
587 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
588 good_area:
589 si_code = SEGV_ACCERR;
590 if (cause < 0) {
591 - if (!(vma->vm_flags & VM_EXEC))
592 + if (!(vma->vm_flags & VM_EXEC)) {
593 +
594 +#ifdef CONFIG_PAX_PAGEEXEC
595 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
596 + goto bad_area;
597 +
598 + up_read(&mm->mmap_sem);
599 + switch (pax_handle_fetch_fault(regs)) {
600 +
601 +#ifdef CONFIG_PAX_EMUPLT
602 + case 2:
603 + case 3:
604 + return;
605 +#endif
606 +
607 + }
608 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
609 + do_group_exit(SIGKILL);
610 +#else
611 goto bad_area;
612 +#endif
613 +
614 + }
615 } else if (!cause) {
616 /* Allow reads even for write-only mappings */
617 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
618 diff -urNp linux-2.6.32.46/arch/arm/include/asm/elf.h linux-2.6.32.46/arch/arm/include/asm/elf.h
619 --- linux-2.6.32.46/arch/arm/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
620 +++ linux-2.6.32.46/arch/arm/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
621 @@ -109,7 +109,14 @@ int dump_task_regs(struct task_struct *t
622 the loader. We need to make sure that it is out of the way of the program
623 that it will "exec", and that there is sufficient room for the brk. */
624
625 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
626 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
627 +
628 +#ifdef CONFIG_PAX_ASLR
629 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
630 +
631 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
632 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
633 +#endif
634
635 /* When the program starts, a1 contains a pointer to a function to be
636 registered with atexit, as per the SVR4 ABI. A value of 0 means we
637 diff -urNp linux-2.6.32.46/arch/arm/include/asm/kmap_types.h linux-2.6.32.46/arch/arm/include/asm/kmap_types.h
638 --- linux-2.6.32.46/arch/arm/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
639 +++ linux-2.6.32.46/arch/arm/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
640 @@ -19,6 +19,7 @@ enum km_type {
641 KM_SOFTIRQ0,
642 KM_SOFTIRQ1,
643 KM_L2_CACHE,
644 + KM_CLEARPAGE,
645 KM_TYPE_NR
646 };
647
648 diff -urNp linux-2.6.32.46/arch/arm/include/asm/uaccess.h linux-2.6.32.46/arch/arm/include/asm/uaccess.h
649 --- linux-2.6.32.46/arch/arm/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
650 +++ linux-2.6.32.46/arch/arm/include/asm/uaccess.h 2011-06-29 21:02:24.000000000 -0400
651 @@ -22,6 +22,8 @@
652 #define VERIFY_READ 0
653 #define VERIFY_WRITE 1
654
655 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
656 +
657 /*
658 * The exception table consists of pairs of addresses: the first is the
659 * address of an instruction that is allowed to fault, and the second is
660 @@ -387,8 +389,23 @@ do { \
661
662
663 #ifdef CONFIG_MMU
664 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
665 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
666 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
667 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
668 +
669 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
670 +{
671 + if (!__builtin_constant_p(n))
672 + check_object_size(to, n, false);
673 + return ___copy_from_user(to, from, n);
674 +}
675 +
676 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
677 +{
678 + if (!__builtin_constant_p(n))
679 + check_object_size(from, n, true);
680 + return ___copy_to_user(to, from, n);
681 +}
682 +
683 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
684 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
685 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
686 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strn
687
688 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
689 {
690 + if ((long)n < 0)
691 + return n;
692 +
693 if (access_ok(VERIFY_READ, from, n))
694 n = __copy_from_user(to, from, n);
695 else /* security hole - plug it */
696 @@ -412,6 +432,9 @@ static inline unsigned long __must_check
697
698 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
699 {
700 + if ((long)n < 0)
701 + return n;
702 +
703 if (access_ok(VERIFY_WRITE, to, n))
704 n = __copy_to_user(to, from, n);
705 return n;
706 diff -urNp linux-2.6.32.46/arch/arm/kernel/armksyms.c linux-2.6.32.46/arch/arm/kernel/armksyms.c
707 --- linux-2.6.32.46/arch/arm/kernel/armksyms.c 2011-03-27 14:31:47.000000000 -0400
708 +++ linux-2.6.32.46/arch/arm/kernel/armksyms.c 2011-07-06 19:51:50.000000000 -0400
709 @@ -118,8 +118,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
710 #ifdef CONFIG_MMU
711 EXPORT_SYMBOL(copy_page);
712
713 -EXPORT_SYMBOL(__copy_from_user);
714 -EXPORT_SYMBOL(__copy_to_user);
715 +EXPORT_SYMBOL(___copy_from_user);
716 +EXPORT_SYMBOL(___copy_to_user);
717 EXPORT_SYMBOL(__clear_user);
718
719 EXPORT_SYMBOL(__get_user_1);
720 diff -urNp linux-2.6.32.46/arch/arm/kernel/kgdb.c linux-2.6.32.46/arch/arm/kernel/kgdb.c
721 --- linux-2.6.32.46/arch/arm/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
722 +++ linux-2.6.32.46/arch/arm/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
723 @@ -190,7 +190,7 @@ void kgdb_arch_exit(void)
724 * and we handle the normal undef case within the do_undefinstr
725 * handler.
726 */
727 -struct kgdb_arch arch_kgdb_ops = {
728 +const struct kgdb_arch arch_kgdb_ops = {
729 #ifndef __ARMEB__
730 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
731 #else /* ! __ARMEB__ */
732 diff -urNp linux-2.6.32.46/arch/arm/kernel/traps.c linux-2.6.32.46/arch/arm/kernel/traps.c
733 --- linux-2.6.32.46/arch/arm/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
734 +++ linux-2.6.32.46/arch/arm/kernel/traps.c 2011-06-13 21:31:18.000000000 -0400
735 @@ -247,6 +247,8 @@ static void __die(const char *str, int e
736
737 DEFINE_SPINLOCK(die_lock);
738
739 +extern void gr_handle_kernel_exploit(void);
740 +
741 /*
742 * This function is protected against re-entrancy.
743 */
744 @@ -271,6 +273,8 @@ NORET_TYPE void die(const char *str, str
745 if (panic_on_oops)
746 panic("Fatal exception");
747
748 + gr_handle_kernel_exploit();
749 +
750 do_exit(SIGSEGV);
751 }
752
753 diff -urNp linux-2.6.32.46/arch/arm/lib/copy_from_user.S linux-2.6.32.46/arch/arm/lib/copy_from_user.S
754 --- linux-2.6.32.46/arch/arm/lib/copy_from_user.S 2011-03-27 14:31:47.000000000 -0400
755 +++ linux-2.6.32.46/arch/arm/lib/copy_from_user.S 2011-06-29 20:48:38.000000000 -0400
756 @@ -16,7 +16,7 @@
757 /*
758 * Prototype:
759 *
760 - * size_t __copy_from_user(void *to, const void *from, size_t n)
761 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
762 *
763 * Purpose:
764 *
765 @@ -84,11 +84,11 @@
766
767 .text
768
769 -ENTRY(__copy_from_user)
770 +ENTRY(___copy_from_user)
771
772 #include "copy_template.S"
773
774 -ENDPROC(__copy_from_user)
775 +ENDPROC(___copy_from_user)
776
777 .section .fixup,"ax"
778 .align 0
779 diff -urNp linux-2.6.32.46/arch/arm/lib/copy_to_user.S linux-2.6.32.46/arch/arm/lib/copy_to_user.S
780 --- linux-2.6.32.46/arch/arm/lib/copy_to_user.S 2011-03-27 14:31:47.000000000 -0400
781 +++ linux-2.6.32.46/arch/arm/lib/copy_to_user.S 2011-06-29 20:46:49.000000000 -0400
782 @@ -16,7 +16,7 @@
783 /*
784 * Prototype:
785 *
786 - * size_t __copy_to_user(void *to, const void *from, size_t n)
787 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
788 *
789 * Purpose:
790 *
791 @@ -88,11 +88,11 @@
792 .text
793
794 ENTRY(__copy_to_user_std)
795 -WEAK(__copy_to_user)
796 +WEAK(___copy_to_user)
797
798 #include "copy_template.S"
799
800 -ENDPROC(__copy_to_user)
801 +ENDPROC(___copy_to_user)
802
803 .section .fixup,"ax"
804 .align 0
805 diff -urNp linux-2.6.32.46/arch/arm/lib/uaccess.S linux-2.6.32.46/arch/arm/lib/uaccess.S
806 --- linux-2.6.32.46/arch/arm/lib/uaccess.S 2011-03-27 14:31:47.000000000 -0400
807 +++ linux-2.6.32.46/arch/arm/lib/uaccess.S 2011-06-29 20:48:53.000000000 -0400
808 @@ -19,7 +19,7 @@
809
810 #define PAGE_SHIFT 12
811
812 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
813 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
814 * Purpose : copy a block to user memory from kernel memory
815 * Params : to - user memory
816 * : from - kernel memory
817 @@ -39,7 +39,7 @@ USER( strgtbt r3, [r0], #1) @ May fau
818 sub r2, r2, ip
819 b .Lc2u_dest_aligned
820
821 -ENTRY(__copy_to_user)
822 +ENTRY(___copy_to_user)
823 stmfd sp!, {r2, r4 - r7, lr}
824 cmp r2, #4
825 blt .Lc2u_not_enough
826 @@ -277,14 +277,14 @@ USER( strgebt r3, [r0], #1) @ May fau
827 ldrgtb r3, [r1], #0
828 USER( strgtbt r3, [r0], #1) @ May fault
829 b .Lc2u_finished
830 -ENDPROC(__copy_to_user)
831 +ENDPROC(___copy_to_user)
832
833 .section .fixup,"ax"
834 .align 0
835 9001: ldmfd sp!, {r0, r4 - r7, pc}
836 .previous
837
838 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
839 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
840 * Purpose : copy a block from user memory to kernel memory
841 * Params : to - kernel memory
842 * : from - user memory
843 @@ -303,7 +303,7 @@ USER( ldrgtbt r3, [r1], #1) @ May fau
844 sub r2, r2, ip
845 b .Lcfu_dest_aligned
846
847 -ENTRY(__copy_from_user)
848 +ENTRY(___copy_from_user)
849 stmfd sp!, {r0, r2, r4 - r7, lr}
850 cmp r2, #4
851 blt .Lcfu_not_enough
852 @@ -543,7 +543,7 @@ USER( ldrgebt r3, [r1], #1) @ May fau
853 USER( ldrgtbt r3, [r1], #1) @ May fault
854 strgtb r3, [r0], #1
855 b .Lcfu_finished
856 -ENDPROC(__copy_from_user)
857 +ENDPROC(___copy_from_user)
858
859 .section .fixup,"ax"
860 .align 0
861 diff -urNp linux-2.6.32.46/arch/arm/lib/uaccess_with_memcpy.c linux-2.6.32.46/arch/arm/lib/uaccess_with_memcpy.c
862 --- linux-2.6.32.46/arch/arm/lib/uaccess_with_memcpy.c 2011-03-27 14:31:47.000000000 -0400
863 +++ linux-2.6.32.46/arch/arm/lib/uaccess_with_memcpy.c 2011-06-29 20:44:35.000000000 -0400
864 @@ -97,7 +97,7 @@ out:
865 }
866
867 unsigned long
868 -__copy_to_user(void __user *to, const void *from, unsigned long n)
869 +___copy_to_user(void __user *to, const void *from, unsigned long n)
870 {
871 /*
872 * This test is stubbed out of the main function above to keep
873 diff -urNp linux-2.6.32.46/arch/arm/mach-at91/pm.c linux-2.6.32.46/arch/arm/mach-at91/pm.c
874 --- linux-2.6.32.46/arch/arm/mach-at91/pm.c 2011-03-27 14:31:47.000000000 -0400
875 +++ linux-2.6.32.46/arch/arm/mach-at91/pm.c 2011-04-17 15:56:45.000000000 -0400
876 @@ -348,7 +348,7 @@ static void at91_pm_end(void)
877 }
878
879
880 -static struct platform_suspend_ops at91_pm_ops ={
881 +static const struct platform_suspend_ops at91_pm_ops ={
882 .valid = at91_pm_valid_state,
883 .begin = at91_pm_begin,
884 .enter = at91_pm_enter,
885 diff -urNp linux-2.6.32.46/arch/arm/mach-omap1/pm.c linux-2.6.32.46/arch/arm/mach-omap1/pm.c
886 --- linux-2.6.32.46/arch/arm/mach-omap1/pm.c 2011-03-27 14:31:47.000000000 -0400
887 +++ linux-2.6.32.46/arch/arm/mach-omap1/pm.c 2011-04-17 15:56:45.000000000 -0400
888 @@ -647,7 +647,7 @@ static struct irqaction omap_wakeup_irq
889
890
891
892 -static struct platform_suspend_ops omap_pm_ops ={
893 +static const struct platform_suspend_ops omap_pm_ops ={
894 .prepare = omap_pm_prepare,
895 .enter = omap_pm_enter,
896 .finish = omap_pm_finish,
897 diff -urNp linux-2.6.32.46/arch/arm/mach-omap2/pm24xx.c linux-2.6.32.46/arch/arm/mach-omap2/pm24xx.c
898 --- linux-2.6.32.46/arch/arm/mach-omap2/pm24xx.c 2011-03-27 14:31:47.000000000 -0400
899 +++ linux-2.6.32.46/arch/arm/mach-omap2/pm24xx.c 2011-04-17 15:56:45.000000000 -0400
900 @@ -326,7 +326,7 @@ static void omap2_pm_finish(void)
901 enable_hlt();
902 }
903
904 -static struct platform_suspend_ops omap_pm_ops = {
905 +static const struct platform_suspend_ops omap_pm_ops = {
906 .prepare = omap2_pm_prepare,
907 .enter = omap2_pm_enter,
908 .finish = omap2_pm_finish,
909 diff -urNp linux-2.6.32.46/arch/arm/mach-omap2/pm34xx.c linux-2.6.32.46/arch/arm/mach-omap2/pm34xx.c
910 --- linux-2.6.32.46/arch/arm/mach-omap2/pm34xx.c 2011-03-27 14:31:47.000000000 -0400
911 +++ linux-2.6.32.46/arch/arm/mach-omap2/pm34xx.c 2011-04-17 15:56:45.000000000 -0400
912 @@ -401,7 +401,7 @@ static void omap3_pm_end(void)
913 return;
914 }
915
916 -static struct platform_suspend_ops omap_pm_ops = {
917 +static const struct platform_suspend_ops omap_pm_ops = {
918 .begin = omap3_pm_begin,
919 .end = omap3_pm_end,
920 .prepare = omap3_pm_prepare,
921 diff -urNp linux-2.6.32.46/arch/arm/mach-pnx4008/pm.c linux-2.6.32.46/arch/arm/mach-pnx4008/pm.c
922 --- linux-2.6.32.46/arch/arm/mach-pnx4008/pm.c 2011-03-27 14:31:47.000000000 -0400
923 +++ linux-2.6.32.46/arch/arm/mach-pnx4008/pm.c 2011-04-17 15:56:45.000000000 -0400
924 @@ -116,7 +116,7 @@ static int pnx4008_pm_valid(suspend_stat
925 (state == PM_SUSPEND_MEM);
926 }
927
928 -static struct platform_suspend_ops pnx4008_pm_ops = {
929 +static const struct platform_suspend_ops pnx4008_pm_ops = {
930 .enter = pnx4008_pm_enter,
931 .valid = pnx4008_pm_valid,
932 };
933 diff -urNp linux-2.6.32.46/arch/arm/mach-pxa/pm.c linux-2.6.32.46/arch/arm/mach-pxa/pm.c
934 --- linux-2.6.32.46/arch/arm/mach-pxa/pm.c 2011-03-27 14:31:47.000000000 -0400
935 +++ linux-2.6.32.46/arch/arm/mach-pxa/pm.c 2011-04-17 15:56:45.000000000 -0400
936 @@ -95,7 +95,7 @@ void pxa_pm_finish(void)
937 pxa_cpu_pm_fns->finish();
938 }
939
940 -static struct platform_suspend_ops pxa_pm_ops = {
941 +static const struct platform_suspend_ops pxa_pm_ops = {
942 .valid = pxa_pm_valid,
943 .enter = pxa_pm_enter,
944 .prepare = pxa_pm_prepare,
945 diff -urNp linux-2.6.32.46/arch/arm/mach-pxa/sharpsl_pm.c linux-2.6.32.46/arch/arm/mach-pxa/sharpsl_pm.c
946 --- linux-2.6.32.46/arch/arm/mach-pxa/sharpsl_pm.c 2011-03-27 14:31:47.000000000 -0400
947 +++ linux-2.6.32.46/arch/arm/mach-pxa/sharpsl_pm.c 2011-04-17 15:56:45.000000000 -0400
948 @@ -891,7 +891,7 @@ static void sharpsl_apm_get_power_status
949 }
950
951 #ifdef CONFIG_PM
952 -static struct platform_suspend_ops sharpsl_pm_ops = {
953 +static const struct platform_suspend_ops sharpsl_pm_ops = {
954 .prepare = pxa_pm_prepare,
955 .finish = pxa_pm_finish,
956 .enter = corgi_pxa_pm_enter,
957 diff -urNp linux-2.6.32.46/arch/arm/mach-sa1100/pm.c linux-2.6.32.46/arch/arm/mach-sa1100/pm.c
958 --- linux-2.6.32.46/arch/arm/mach-sa1100/pm.c 2011-03-27 14:31:47.000000000 -0400
959 +++ linux-2.6.32.46/arch/arm/mach-sa1100/pm.c 2011-04-17 15:56:45.000000000 -0400
960 @@ -120,7 +120,7 @@ unsigned long sleep_phys_sp(void *sp)
961 return virt_to_phys(sp);
962 }
963
964 -static struct platform_suspend_ops sa11x0_pm_ops = {
965 +static const struct platform_suspend_ops sa11x0_pm_ops = {
966 .enter = sa11x0_pm_enter,
967 .valid = suspend_valid_only_mem,
968 };
969 diff -urNp linux-2.6.32.46/arch/arm/mm/fault.c linux-2.6.32.46/arch/arm/mm/fault.c
970 --- linux-2.6.32.46/arch/arm/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
971 +++ linux-2.6.32.46/arch/arm/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
972 @@ -166,6 +166,13 @@ __do_user_fault(struct task_struct *tsk,
973 }
974 #endif
975
976 +#ifdef CONFIG_PAX_PAGEEXEC
977 + if (fsr & FSR_LNX_PF) {
978 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
979 + do_group_exit(SIGKILL);
980 + }
981 +#endif
982 +
983 tsk->thread.address = addr;
984 tsk->thread.error_code = fsr;
985 tsk->thread.trap_no = 14;
986 @@ -357,6 +364,33 @@ do_page_fault(unsigned long addr, unsign
987 }
988 #endif /* CONFIG_MMU */
989
990 +#ifdef CONFIG_PAX_PAGEEXEC
991 +void pax_report_insns(void *pc, void *sp)
992 +{
993 + long i;
994 +
995 + printk(KERN_ERR "PAX: bytes at PC: ");
996 + for (i = 0; i < 20; i++) {
997 + unsigned char c;
998 + if (get_user(c, (__force unsigned char __user *)pc+i))
999 + printk(KERN_CONT "?? ");
1000 + else
1001 + printk(KERN_CONT "%02x ", c);
1002 + }
1003 + printk("\n");
1004 +
1005 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1006 + for (i = -1; i < 20; i++) {
1007 + unsigned long c;
1008 + if (get_user(c, (__force unsigned long __user *)sp+i))
1009 + printk(KERN_CONT "???????? ");
1010 + else
1011 + printk(KERN_CONT "%08lx ", c);
1012 + }
1013 + printk("\n");
1014 +}
1015 +#endif
1016 +
1017 /*
1018 * First Level Translation Fault Handler
1019 *
1020 diff -urNp linux-2.6.32.46/arch/arm/mm/mmap.c linux-2.6.32.46/arch/arm/mm/mmap.c
1021 --- linux-2.6.32.46/arch/arm/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
1022 +++ linux-2.6.32.46/arch/arm/mm/mmap.c 2011-04-17 15:56:45.000000000 -0400
1023 @@ -63,6 +63,10 @@ arch_get_unmapped_area(struct file *filp
1024 if (len > TASK_SIZE)
1025 return -ENOMEM;
1026
1027 +#ifdef CONFIG_PAX_RANDMMAP
1028 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1029 +#endif
1030 +
1031 if (addr) {
1032 if (do_align)
1033 addr = COLOUR_ALIGN(addr, pgoff);
1034 @@ -70,15 +74,14 @@ arch_get_unmapped_area(struct file *filp
1035 addr = PAGE_ALIGN(addr);
1036
1037 vma = find_vma(mm, addr);
1038 - if (TASK_SIZE - len >= addr &&
1039 - (!vma || addr + len <= vma->vm_start))
1040 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1041 return addr;
1042 }
1043 if (len > mm->cached_hole_size) {
1044 - start_addr = addr = mm->free_area_cache;
1045 + start_addr = addr = mm->free_area_cache;
1046 } else {
1047 - start_addr = addr = TASK_UNMAPPED_BASE;
1048 - mm->cached_hole_size = 0;
1049 + start_addr = addr = mm->mmap_base;
1050 + mm->cached_hole_size = 0;
1051 }
1052
1053 full_search:
1054 @@ -94,14 +97,14 @@ full_search:
1055 * Start a new search - just in case we missed
1056 * some holes.
1057 */
1058 - if (start_addr != TASK_UNMAPPED_BASE) {
1059 - start_addr = addr = TASK_UNMAPPED_BASE;
1060 + if (start_addr != mm->mmap_base) {
1061 + start_addr = addr = mm->mmap_base;
1062 mm->cached_hole_size = 0;
1063 goto full_search;
1064 }
1065 return -ENOMEM;
1066 }
1067 - if (!vma || addr + len <= vma->vm_start) {
1068 + if (check_heap_stack_gap(vma, addr, len)) {
1069 /*
1070 * Remember the place where we stopped the search:
1071 */
1072 diff -urNp linux-2.6.32.46/arch/arm/plat-s3c/pm.c linux-2.6.32.46/arch/arm/plat-s3c/pm.c
1073 --- linux-2.6.32.46/arch/arm/plat-s3c/pm.c 2011-03-27 14:31:47.000000000 -0400
1074 +++ linux-2.6.32.46/arch/arm/plat-s3c/pm.c 2011-04-17 15:56:45.000000000 -0400
1075 @@ -355,7 +355,7 @@ static void s3c_pm_finish(void)
1076 s3c_pm_check_cleanup();
1077 }
1078
1079 -static struct platform_suspend_ops s3c_pm_ops = {
1080 +static const struct platform_suspend_ops s3c_pm_ops = {
1081 .enter = s3c_pm_enter,
1082 .prepare = s3c_pm_prepare,
1083 .finish = s3c_pm_finish,
1084 diff -urNp linux-2.6.32.46/arch/avr32/include/asm/elf.h linux-2.6.32.46/arch/avr32/include/asm/elf.h
1085 --- linux-2.6.32.46/arch/avr32/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1086 +++ linux-2.6.32.46/arch/avr32/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1087 @@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
1088 the loader. We need to make sure that it is out of the way of the program
1089 that it will "exec", and that there is sufficient room for the brk. */
1090
1091 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1092 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1093
1094 +#ifdef CONFIG_PAX_ASLR
1095 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1096 +
1097 +#define PAX_DELTA_MMAP_LEN 15
1098 +#define PAX_DELTA_STACK_LEN 15
1099 +#endif
1100
1101 /* This yields a mask that user programs can use to figure out what
1102 instruction set this CPU supports. This could be done in user space,
1103 diff -urNp linux-2.6.32.46/arch/avr32/include/asm/kmap_types.h linux-2.6.32.46/arch/avr32/include/asm/kmap_types.h
1104 --- linux-2.6.32.46/arch/avr32/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
1105 +++ linux-2.6.32.46/arch/avr32/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
1106 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1107 D(11) KM_IRQ1,
1108 D(12) KM_SOFTIRQ0,
1109 D(13) KM_SOFTIRQ1,
1110 -D(14) KM_TYPE_NR
1111 +D(14) KM_CLEARPAGE,
1112 +D(15) KM_TYPE_NR
1113 };
1114
1115 #undef D
1116 diff -urNp linux-2.6.32.46/arch/avr32/mach-at32ap/pm.c linux-2.6.32.46/arch/avr32/mach-at32ap/pm.c
1117 --- linux-2.6.32.46/arch/avr32/mach-at32ap/pm.c 2011-03-27 14:31:47.000000000 -0400
1118 +++ linux-2.6.32.46/arch/avr32/mach-at32ap/pm.c 2011-04-17 15:56:45.000000000 -0400
1119 @@ -176,7 +176,7 @@ out:
1120 return 0;
1121 }
1122
1123 -static struct platform_suspend_ops avr32_pm_ops = {
1124 +static const struct platform_suspend_ops avr32_pm_ops = {
1125 .valid = avr32_pm_valid_state,
1126 .enter = avr32_pm_enter,
1127 };
1128 diff -urNp linux-2.6.32.46/arch/avr32/mm/fault.c linux-2.6.32.46/arch/avr32/mm/fault.c
1129 --- linux-2.6.32.46/arch/avr32/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1130 +++ linux-2.6.32.46/arch/avr32/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1131 @@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
1132
1133 int exception_trace = 1;
1134
1135 +#ifdef CONFIG_PAX_PAGEEXEC
1136 +void pax_report_insns(void *pc, void *sp)
1137 +{
1138 + unsigned long i;
1139 +
1140 + printk(KERN_ERR "PAX: bytes at PC: ");
1141 + for (i = 0; i < 20; i++) {
1142 + unsigned char c;
1143 + if (get_user(c, (unsigned char *)pc+i))
1144 + printk(KERN_CONT "???????? ");
1145 + else
1146 + printk(KERN_CONT "%02x ", c);
1147 + }
1148 + printk("\n");
1149 +}
1150 +#endif
1151 +
1152 /*
1153 * This routine handles page faults. It determines the address and the
1154 * problem, and then passes it off to one of the appropriate routines.
1155 @@ -157,6 +174,16 @@ bad_area:
1156 up_read(&mm->mmap_sem);
1157
1158 if (user_mode(regs)) {
1159 +
1160 +#ifdef CONFIG_PAX_PAGEEXEC
1161 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1162 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1163 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1164 + do_group_exit(SIGKILL);
1165 + }
1166 + }
1167 +#endif
1168 +
1169 if (exception_trace && printk_ratelimit())
1170 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1171 "sp %08lx ecr %lu\n",
1172 diff -urNp linux-2.6.32.46/arch/blackfin/kernel/kgdb.c linux-2.6.32.46/arch/blackfin/kernel/kgdb.c
1173 --- linux-2.6.32.46/arch/blackfin/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
1174 +++ linux-2.6.32.46/arch/blackfin/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
1175 @@ -428,7 +428,7 @@ int kgdb_arch_handle_exception(int vecto
1176 return -1; /* this means that we do not want to exit from the handler */
1177 }
1178
1179 -struct kgdb_arch arch_kgdb_ops = {
1180 +const struct kgdb_arch arch_kgdb_ops = {
1181 .gdb_bpt_instr = {0xa1},
1182 #ifdef CONFIG_SMP
1183 .flags = KGDB_HW_BREAKPOINT|KGDB_THR_PROC_SWAP,
1184 diff -urNp linux-2.6.32.46/arch/blackfin/mach-common/pm.c linux-2.6.32.46/arch/blackfin/mach-common/pm.c
1185 --- linux-2.6.32.46/arch/blackfin/mach-common/pm.c 2011-03-27 14:31:47.000000000 -0400
1186 +++ linux-2.6.32.46/arch/blackfin/mach-common/pm.c 2011-04-17 15:56:45.000000000 -0400
1187 @@ -255,7 +255,7 @@ static int bfin_pm_enter(suspend_state_t
1188 return 0;
1189 }
1190
1191 -struct platform_suspend_ops bfin_pm_ops = {
1192 +const struct platform_suspend_ops bfin_pm_ops = {
1193 .enter = bfin_pm_enter,
1194 .valid = bfin_pm_valid,
1195 };
1196 diff -urNp linux-2.6.32.46/arch/frv/include/asm/kmap_types.h linux-2.6.32.46/arch/frv/include/asm/kmap_types.h
1197 --- linux-2.6.32.46/arch/frv/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
1198 +++ linux-2.6.32.46/arch/frv/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
1199 @@ -23,6 +23,7 @@ enum km_type {
1200 KM_IRQ1,
1201 KM_SOFTIRQ0,
1202 KM_SOFTIRQ1,
1203 + KM_CLEARPAGE,
1204 KM_TYPE_NR
1205 };
1206
1207 diff -urNp linux-2.6.32.46/arch/frv/mm/elf-fdpic.c linux-2.6.32.46/arch/frv/mm/elf-fdpic.c
1208 --- linux-2.6.32.46/arch/frv/mm/elf-fdpic.c 2011-03-27 14:31:47.000000000 -0400
1209 +++ linux-2.6.32.46/arch/frv/mm/elf-fdpic.c 2011-04-17 15:56:45.000000000 -0400
1210 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
1211 if (addr) {
1212 addr = PAGE_ALIGN(addr);
1213 vma = find_vma(current->mm, addr);
1214 - if (TASK_SIZE - len >= addr &&
1215 - (!vma || addr + len <= vma->vm_start))
1216 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1217 goto success;
1218 }
1219
1220 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
1221 for (; vma; vma = vma->vm_next) {
1222 if (addr > limit)
1223 break;
1224 - if (addr + len <= vma->vm_start)
1225 + if (check_heap_stack_gap(vma, addr, len))
1226 goto success;
1227 addr = vma->vm_end;
1228 }
1229 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
1230 for (; vma; vma = vma->vm_next) {
1231 if (addr > limit)
1232 break;
1233 - if (addr + len <= vma->vm_start)
1234 + if (check_heap_stack_gap(vma, addr, len))
1235 goto success;
1236 addr = vma->vm_end;
1237 }
1238 diff -urNp linux-2.6.32.46/arch/ia64/hp/common/hwsw_iommu.c linux-2.6.32.46/arch/ia64/hp/common/hwsw_iommu.c
1239 --- linux-2.6.32.46/arch/ia64/hp/common/hwsw_iommu.c 2011-03-27 14:31:47.000000000 -0400
1240 +++ linux-2.6.32.46/arch/ia64/hp/common/hwsw_iommu.c 2011-04-17 15:56:45.000000000 -0400
1241 @@ -17,7 +17,7 @@
1242 #include <linux/swiotlb.h>
1243 #include <asm/machvec.h>
1244
1245 -extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1246 +extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1247
1248 /* swiotlb declarations & definitions: */
1249 extern int swiotlb_late_init_with_default_size (size_t size);
1250 @@ -33,7 +33,7 @@ static inline int use_swiotlb(struct dev
1251 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
1252 }
1253
1254 -struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1255 +const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1256 {
1257 if (use_swiotlb(dev))
1258 return &swiotlb_dma_ops;
1259 diff -urNp linux-2.6.32.46/arch/ia64/hp/common/sba_iommu.c linux-2.6.32.46/arch/ia64/hp/common/sba_iommu.c
1260 --- linux-2.6.32.46/arch/ia64/hp/common/sba_iommu.c 2011-03-27 14:31:47.000000000 -0400
1261 +++ linux-2.6.32.46/arch/ia64/hp/common/sba_iommu.c 2011-04-17 15:56:45.000000000 -0400
1262 @@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_d
1263 },
1264 };
1265
1266 -extern struct dma_map_ops swiotlb_dma_ops;
1267 +extern const struct dma_map_ops swiotlb_dma_ops;
1268
1269 static int __init
1270 sba_init(void)
1271 @@ -2211,7 +2211,7 @@ sba_page_override(char *str)
1272
1273 __setup("sbapagesize=",sba_page_override);
1274
1275 -struct dma_map_ops sba_dma_ops = {
1276 +const struct dma_map_ops sba_dma_ops = {
1277 .alloc_coherent = sba_alloc_coherent,
1278 .free_coherent = sba_free_coherent,
1279 .map_page = sba_map_page,
1280 diff -urNp linux-2.6.32.46/arch/ia64/ia32/binfmt_elf32.c linux-2.6.32.46/arch/ia64/ia32/binfmt_elf32.c
1281 --- linux-2.6.32.46/arch/ia64/ia32/binfmt_elf32.c 2011-03-27 14:31:47.000000000 -0400
1282 +++ linux-2.6.32.46/arch/ia64/ia32/binfmt_elf32.c 2011-04-17 15:56:45.000000000 -0400
1283 @@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
1284
1285 #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
1286
1287 +#ifdef CONFIG_PAX_ASLR
1288 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1289 +
1290 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1291 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1292 +#endif
1293 +
1294 /* Ugly but avoids duplication */
1295 #include "../../../fs/binfmt_elf.c"
1296
1297 diff -urNp linux-2.6.32.46/arch/ia64/ia32/ia32priv.h linux-2.6.32.46/arch/ia64/ia32/ia32priv.h
1298 --- linux-2.6.32.46/arch/ia64/ia32/ia32priv.h 2011-03-27 14:31:47.000000000 -0400
1299 +++ linux-2.6.32.46/arch/ia64/ia32/ia32priv.h 2011-04-17 15:56:45.000000000 -0400
1300 @@ -296,7 +296,14 @@ typedef struct compat_siginfo {
1301 #define ELF_DATA ELFDATA2LSB
1302 #define ELF_ARCH EM_386
1303
1304 -#define IA32_STACK_TOP IA32_PAGE_OFFSET
1305 +#ifdef CONFIG_PAX_RANDUSTACK
1306 +#define __IA32_DELTA_STACK (current->mm->delta_stack)
1307 +#else
1308 +#define __IA32_DELTA_STACK 0UL
1309 +#endif
1310 +
1311 +#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
1312 +
1313 #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
1314 #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
1315
1316 diff -urNp linux-2.6.32.46/arch/ia64/include/asm/dma-mapping.h linux-2.6.32.46/arch/ia64/include/asm/dma-mapping.h
1317 --- linux-2.6.32.46/arch/ia64/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
1318 +++ linux-2.6.32.46/arch/ia64/include/asm/dma-mapping.h 2011-04-17 15:56:45.000000000 -0400
1319 @@ -12,7 +12,7 @@
1320
1321 #define ARCH_HAS_DMA_GET_REQUIRED_MASK
1322
1323 -extern struct dma_map_ops *dma_ops;
1324 +extern const struct dma_map_ops *dma_ops;
1325 extern struct ia64_machine_vector ia64_mv;
1326 extern void set_iommu_machvec(void);
1327
1328 @@ -24,7 +24,7 @@ extern void machvec_dma_sync_sg(struct d
1329 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1330 dma_addr_t *daddr, gfp_t gfp)
1331 {
1332 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1333 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1334 void *caddr;
1335
1336 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
1337 @@ -35,7 +35,7 @@ static inline void *dma_alloc_coherent(s
1338 static inline void dma_free_coherent(struct device *dev, size_t size,
1339 void *caddr, dma_addr_t daddr)
1340 {
1341 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1342 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1343 debug_dma_free_coherent(dev, size, caddr, daddr);
1344 ops->free_coherent(dev, size, caddr, daddr);
1345 }
1346 @@ -49,13 +49,13 @@ static inline void dma_free_coherent(str
1347
1348 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
1349 {
1350 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1351 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1352 return ops->mapping_error(dev, daddr);
1353 }
1354
1355 static inline int dma_supported(struct device *dev, u64 mask)
1356 {
1357 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1358 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1359 return ops->dma_supported(dev, mask);
1360 }
1361
1362 diff -urNp linux-2.6.32.46/arch/ia64/include/asm/elf.h linux-2.6.32.46/arch/ia64/include/asm/elf.h
1363 --- linux-2.6.32.46/arch/ia64/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1364 +++ linux-2.6.32.46/arch/ia64/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1365 @@ -43,6 +43,13 @@
1366 */
1367 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1368
1369 +#ifdef CONFIG_PAX_ASLR
1370 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1371 +
1372 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1373 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1374 +#endif
1375 +
1376 #define PT_IA_64_UNWIND 0x70000001
1377
1378 /* IA-64 relocations: */
1379 diff -urNp linux-2.6.32.46/arch/ia64/include/asm/machvec.h linux-2.6.32.46/arch/ia64/include/asm/machvec.h
1380 --- linux-2.6.32.46/arch/ia64/include/asm/machvec.h 2011-03-27 14:31:47.000000000 -0400
1381 +++ linux-2.6.32.46/arch/ia64/include/asm/machvec.h 2011-04-17 15:56:45.000000000 -0400
1382 @@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event
1383 /* DMA-mapping interface: */
1384 typedef void ia64_mv_dma_init (void);
1385 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
1386 -typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1387 +typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1388
1389 /*
1390 * WARNING: The legacy I/O space is _architected_. Platforms are
1391 @@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(co
1392 # endif /* CONFIG_IA64_GENERIC */
1393
1394 extern void swiotlb_dma_init(void);
1395 -extern struct dma_map_ops *dma_get_ops(struct device *);
1396 +extern const struct dma_map_ops *dma_get_ops(struct device *);
1397
1398 /*
1399 * Define default versions so we can extend machvec for new platforms without having
1400 diff -urNp linux-2.6.32.46/arch/ia64/include/asm/pgtable.h linux-2.6.32.46/arch/ia64/include/asm/pgtable.h
1401 --- linux-2.6.32.46/arch/ia64/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
1402 +++ linux-2.6.32.46/arch/ia64/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
1403 @@ -12,7 +12,7 @@
1404 * David Mosberger-Tang <davidm@hpl.hp.com>
1405 */
1406
1407 -
1408 +#include <linux/const.h>
1409 #include <asm/mman.h>
1410 #include <asm/page.h>
1411 #include <asm/processor.h>
1412 @@ -143,6 +143,17 @@
1413 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1414 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1415 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1416 +
1417 +#ifdef CONFIG_PAX_PAGEEXEC
1418 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1419 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1420 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1421 +#else
1422 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1423 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1424 +# define PAGE_COPY_NOEXEC PAGE_COPY
1425 +#endif
1426 +
1427 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1428 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1429 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1430 diff -urNp linux-2.6.32.46/arch/ia64/include/asm/spinlock.h linux-2.6.32.46/arch/ia64/include/asm/spinlock.h
1431 --- linux-2.6.32.46/arch/ia64/include/asm/spinlock.h 2011-03-27 14:31:47.000000000 -0400
1432 +++ linux-2.6.32.46/arch/ia64/include/asm/spinlock.h 2011-04-17 15:56:45.000000000 -0400
1433 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spi
1434 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1435
1436 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1437 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1438 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1439 }
1440
1441 static __always_inline void __ticket_spin_unlock_wait(raw_spinlock_t *lock)
1442 diff -urNp linux-2.6.32.46/arch/ia64/include/asm/uaccess.h linux-2.6.32.46/arch/ia64/include/asm/uaccess.h
1443 --- linux-2.6.32.46/arch/ia64/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
1444 +++ linux-2.6.32.46/arch/ia64/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
1445 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
1446 const void *__cu_from = (from); \
1447 long __cu_len = (n); \
1448 \
1449 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1450 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1451 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1452 __cu_len; \
1453 })
1454 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
1455 long __cu_len = (n); \
1456 \
1457 __chk_user_ptr(__cu_from); \
1458 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1459 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1460 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1461 __cu_len; \
1462 })
1463 diff -urNp linux-2.6.32.46/arch/ia64/kernel/dma-mapping.c linux-2.6.32.46/arch/ia64/kernel/dma-mapping.c
1464 --- linux-2.6.32.46/arch/ia64/kernel/dma-mapping.c 2011-03-27 14:31:47.000000000 -0400
1465 +++ linux-2.6.32.46/arch/ia64/kernel/dma-mapping.c 2011-04-17 15:56:45.000000000 -0400
1466 @@ -3,7 +3,7 @@
1467 /* Set this to 1 if there is a HW IOMMU in the system */
1468 int iommu_detected __read_mostly;
1469
1470 -struct dma_map_ops *dma_ops;
1471 +const struct dma_map_ops *dma_ops;
1472 EXPORT_SYMBOL(dma_ops);
1473
1474 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1475 @@ -16,7 +16,7 @@ static int __init dma_init(void)
1476 }
1477 fs_initcall(dma_init);
1478
1479 -struct dma_map_ops *dma_get_ops(struct device *dev)
1480 +const struct dma_map_ops *dma_get_ops(struct device *dev)
1481 {
1482 return dma_ops;
1483 }
1484 diff -urNp linux-2.6.32.46/arch/ia64/kernel/module.c linux-2.6.32.46/arch/ia64/kernel/module.c
1485 --- linux-2.6.32.46/arch/ia64/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
1486 +++ linux-2.6.32.46/arch/ia64/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
1487 @@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1488 void
1489 module_free (struct module *mod, void *module_region)
1490 {
1491 - if (mod && mod->arch.init_unw_table &&
1492 - module_region == mod->module_init) {
1493 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1494 unw_remove_unwind_table(mod->arch.init_unw_table);
1495 mod->arch.init_unw_table = NULL;
1496 }
1497 @@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
1498 }
1499
1500 static inline int
1501 +in_init_rx (const struct module *mod, uint64_t addr)
1502 +{
1503 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1504 +}
1505 +
1506 +static inline int
1507 +in_init_rw (const struct module *mod, uint64_t addr)
1508 +{
1509 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1510 +}
1511 +
1512 +static inline int
1513 in_init (const struct module *mod, uint64_t addr)
1514 {
1515 - return addr - (uint64_t) mod->module_init < mod->init_size;
1516 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1517 +}
1518 +
1519 +static inline int
1520 +in_core_rx (const struct module *mod, uint64_t addr)
1521 +{
1522 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1523 +}
1524 +
1525 +static inline int
1526 +in_core_rw (const struct module *mod, uint64_t addr)
1527 +{
1528 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1529 }
1530
1531 static inline int
1532 in_core (const struct module *mod, uint64_t addr)
1533 {
1534 - return addr - (uint64_t) mod->module_core < mod->core_size;
1535 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1536 }
1537
1538 static inline int
1539 @@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
1540 break;
1541
1542 case RV_BDREL:
1543 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1544 + if (in_init_rx(mod, val))
1545 + val -= (uint64_t) mod->module_init_rx;
1546 + else if (in_init_rw(mod, val))
1547 + val -= (uint64_t) mod->module_init_rw;
1548 + else if (in_core_rx(mod, val))
1549 + val -= (uint64_t) mod->module_core_rx;
1550 + else if (in_core_rw(mod, val))
1551 + val -= (uint64_t) mod->module_core_rw;
1552 break;
1553
1554 case RV_LTV:
1555 @@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
1556 * addresses have been selected...
1557 */
1558 uint64_t gp;
1559 - if (mod->core_size > MAX_LTOFF)
1560 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1561 /*
1562 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1563 * at the end of the module.
1564 */
1565 - gp = mod->core_size - MAX_LTOFF / 2;
1566 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1567 else
1568 - gp = mod->core_size / 2;
1569 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1570 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1571 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1572 mod->arch.gp = gp;
1573 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1574 }
1575 diff -urNp linux-2.6.32.46/arch/ia64/kernel/pci-dma.c linux-2.6.32.46/arch/ia64/kernel/pci-dma.c
1576 --- linux-2.6.32.46/arch/ia64/kernel/pci-dma.c 2011-03-27 14:31:47.000000000 -0400
1577 +++ linux-2.6.32.46/arch/ia64/kernel/pci-dma.c 2011-04-17 15:56:45.000000000 -0400
1578 @@ -43,7 +43,7 @@ struct device fallback_dev = {
1579 .dma_mask = &fallback_dev.coherent_dma_mask,
1580 };
1581
1582 -extern struct dma_map_ops intel_dma_ops;
1583 +extern const struct dma_map_ops intel_dma_ops;
1584
1585 static int __init pci_iommu_init(void)
1586 {
1587 @@ -96,15 +96,34 @@ int iommu_dma_supported(struct device *d
1588 }
1589 EXPORT_SYMBOL(iommu_dma_supported);
1590
1591 +extern void *intel_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t flags);
1592 +extern void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle);
1593 +extern int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1594 +extern void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1595 +extern dma_addr_t intel_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs);
1596 +extern void intel_unmap_page(struct device *dev, dma_addr_t dev_addr, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs);
1597 +extern int intel_mapping_error(struct device *dev, dma_addr_t dma_addr);
1598 +
1599 +static const struct dma_map_ops intel_iommu_dma_ops = {
1600 + /* from drivers/pci/intel-iommu.c:intel_dma_ops */
1601 + .alloc_coherent = intel_alloc_coherent,
1602 + .free_coherent = intel_free_coherent,
1603 + .map_sg = intel_map_sg,
1604 + .unmap_sg = intel_unmap_sg,
1605 + .map_page = intel_map_page,
1606 + .unmap_page = intel_unmap_page,
1607 + .mapping_error = intel_mapping_error,
1608 +
1609 + .sync_single_for_cpu = machvec_dma_sync_single,
1610 + .sync_sg_for_cpu = machvec_dma_sync_sg,
1611 + .sync_single_for_device = machvec_dma_sync_single,
1612 + .sync_sg_for_device = machvec_dma_sync_sg,
1613 + .dma_supported = iommu_dma_supported,
1614 +};
1615 +
1616 void __init pci_iommu_alloc(void)
1617 {
1618 - dma_ops = &intel_dma_ops;
1619 -
1620 - dma_ops->sync_single_for_cpu = machvec_dma_sync_single;
1621 - dma_ops->sync_sg_for_cpu = machvec_dma_sync_sg;
1622 - dma_ops->sync_single_for_device = machvec_dma_sync_single;
1623 - dma_ops->sync_sg_for_device = machvec_dma_sync_sg;
1624 - dma_ops->dma_supported = iommu_dma_supported;
1625 + dma_ops = &intel_iommu_dma_ops;
1626
1627 /*
1628 * The order of these functions is important for
1629 diff -urNp linux-2.6.32.46/arch/ia64/kernel/pci-swiotlb.c linux-2.6.32.46/arch/ia64/kernel/pci-swiotlb.c
1630 --- linux-2.6.32.46/arch/ia64/kernel/pci-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
1631 +++ linux-2.6.32.46/arch/ia64/kernel/pci-swiotlb.c 2011-04-17 15:56:45.000000000 -0400
1632 @@ -21,7 +21,7 @@ static void *ia64_swiotlb_alloc_coherent
1633 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1634 }
1635
1636 -struct dma_map_ops swiotlb_dma_ops = {
1637 +const struct dma_map_ops swiotlb_dma_ops = {
1638 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1639 .free_coherent = swiotlb_free_coherent,
1640 .map_page = swiotlb_map_page,
1641 diff -urNp linux-2.6.32.46/arch/ia64/kernel/sys_ia64.c linux-2.6.32.46/arch/ia64/kernel/sys_ia64.c
1642 --- linux-2.6.32.46/arch/ia64/kernel/sys_ia64.c 2011-03-27 14:31:47.000000000 -0400
1643 +++ linux-2.6.32.46/arch/ia64/kernel/sys_ia64.c 2011-04-17 15:56:45.000000000 -0400
1644 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
1645 if (REGION_NUMBER(addr) == RGN_HPAGE)
1646 addr = 0;
1647 #endif
1648 +
1649 +#ifdef CONFIG_PAX_RANDMMAP
1650 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1651 + addr = mm->free_area_cache;
1652 + else
1653 +#endif
1654 +
1655 if (!addr)
1656 addr = mm->free_area_cache;
1657
1658 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
1659 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1660 /* At this point: (!vma || addr < vma->vm_end). */
1661 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1662 - if (start_addr != TASK_UNMAPPED_BASE) {
1663 + if (start_addr != mm->mmap_base) {
1664 /* Start a new search --- just in case we missed some holes. */
1665 - addr = TASK_UNMAPPED_BASE;
1666 + addr = mm->mmap_base;
1667 goto full_search;
1668 }
1669 return -ENOMEM;
1670 }
1671 - if (!vma || addr + len <= vma->vm_start) {
1672 + if (check_heap_stack_gap(vma, addr, len)) {
1673 /* Remember the address where we stopped this search: */
1674 mm->free_area_cache = addr + len;
1675 return addr;
1676 diff -urNp linux-2.6.32.46/arch/ia64/kernel/topology.c linux-2.6.32.46/arch/ia64/kernel/topology.c
1677 --- linux-2.6.32.46/arch/ia64/kernel/topology.c 2011-03-27 14:31:47.000000000 -0400
1678 +++ linux-2.6.32.46/arch/ia64/kernel/topology.c 2011-04-17 15:56:45.000000000 -0400
1679 @@ -282,7 +282,7 @@ static ssize_t cache_show(struct kobject
1680 return ret;
1681 }
1682
1683 -static struct sysfs_ops cache_sysfs_ops = {
1684 +static const struct sysfs_ops cache_sysfs_ops = {
1685 .show = cache_show
1686 };
1687
1688 diff -urNp linux-2.6.32.46/arch/ia64/kernel/vmlinux.lds.S linux-2.6.32.46/arch/ia64/kernel/vmlinux.lds.S
1689 --- linux-2.6.32.46/arch/ia64/kernel/vmlinux.lds.S 2011-03-27 14:31:47.000000000 -0400
1690 +++ linux-2.6.32.46/arch/ia64/kernel/vmlinux.lds.S 2011-04-17 15:56:45.000000000 -0400
1691 @@ -190,7 +190,7 @@ SECTIONS
1692 /* Per-cpu data: */
1693 . = ALIGN(PERCPU_PAGE_SIZE);
1694 PERCPU_VADDR(PERCPU_ADDR, :percpu)
1695 - __phys_per_cpu_start = __per_cpu_load;
1696 + __phys_per_cpu_start = per_cpu_load;
1697 . = __phys_per_cpu_start + PERCPU_PAGE_SIZE; /* ensure percpu data fits
1698 * into percpu page size
1699 */
1700 diff -urNp linux-2.6.32.46/arch/ia64/mm/fault.c linux-2.6.32.46/arch/ia64/mm/fault.c
1701 --- linux-2.6.32.46/arch/ia64/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1702 +++ linux-2.6.32.46/arch/ia64/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1703 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
1704 return pte_present(pte);
1705 }
1706
1707 +#ifdef CONFIG_PAX_PAGEEXEC
1708 +void pax_report_insns(void *pc, void *sp)
1709 +{
1710 + unsigned long i;
1711 +
1712 + printk(KERN_ERR "PAX: bytes at PC: ");
1713 + for (i = 0; i < 8; i++) {
1714 + unsigned int c;
1715 + if (get_user(c, (unsigned int *)pc+i))
1716 + printk(KERN_CONT "???????? ");
1717 + else
1718 + printk(KERN_CONT "%08x ", c);
1719 + }
1720 + printk("\n");
1721 +}
1722 +#endif
1723 +
1724 void __kprobes
1725 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1726 {
1727 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
1728 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1729 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1730
1731 - if ((vma->vm_flags & mask) != mask)
1732 + if ((vma->vm_flags & mask) != mask) {
1733 +
1734 +#ifdef CONFIG_PAX_PAGEEXEC
1735 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1736 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1737 + goto bad_area;
1738 +
1739 + up_read(&mm->mmap_sem);
1740 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1741 + do_group_exit(SIGKILL);
1742 + }
1743 +#endif
1744 +
1745 goto bad_area;
1746
1747 + }
1748 +
1749 survive:
1750 /*
1751 * If for any reason at all we couldn't handle the fault, make
1752 diff -urNp linux-2.6.32.46/arch/ia64/mm/hugetlbpage.c linux-2.6.32.46/arch/ia64/mm/hugetlbpage.c
1753 --- linux-2.6.32.46/arch/ia64/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
1754 +++ linux-2.6.32.46/arch/ia64/mm/hugetlbpage.c 2011-04-17 15:56:45.000000000 -0400
1755 @@ -172,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(
1756 /* At this point: (!vmm || addr < vmm->vm_end). */
1757 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1758 return -ENOMEM;
1759 - if (!vmm || (addr + len) <= vmm->vm_start)
1760 + if (check_heap_stack_gap(vmm, addr, len))
1761 return addr;
1762 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1763 }
1764 diff -urNp linux-2.6.32.46/arch/ia64/mm/init.c linux-2.6.32.46/arch/ia64/mm/init.c
1765 --- linux-2.6.32.46/arch/ia64/mm/init.c 2011-03-27 14:31:47.000000000 -0400
1766 +++ linux-2.6.32.46/arch/ia64/mm/init.c 2011-04-17 15:56:45.000000000 -0400
1767 @@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1768 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1769 vma->vm_end = vma->vm_start + PAGE_SIZE;
1770 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1771 +
1772 +#ifdef CONFIG_PAX_PAGEEXEC
1773 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1774 + vma->vm_flags &= ~VM_EXEC;
1775 +
1776 +#ifdef CONFIG_PAX_MPROTECT
1777 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1778 + vma->vm_flags &= ~VM_MAYEXEC;
1779 +#endif
1780 +
1781 + }
1782 +#endif
1783 +
1784 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1785 down_write(&current->mm->mmap_sem);
1786 if (insert_vm_struct(current->mm, vma)) {
1787 diff -urNp linux-2.6.32.46/arch/ia64/sn/pci/pci_dma.c linux-2.6.32.46/arch/ia64/sn/pci/pci_dma.c
1788 --- linux-2.6.32.46/arch/ia64/sn/pci/pci_dma.c 2011-03-27 14:31:47.000000000 -0400
1789 +++ linux-2.6.32.46/arch/ia64/sn/pci/pci_dma.c 2011-04-17 15:56:45.000000000 -0400
1790 @@ -464,7 +464,7 @@ int sn_pci_legacy_write(struct pci_bus *
1791 return ret;
1792 }
1793
1794 -static struct dma_map_ops sn_dma_ops = {
1795 +static const struct dma_map_ops sn_dma_ops = {
1796 .alloc_coherent = sn_dma_alloc_coherent,
1797 .free_coherent = sn_dma_free_coherent,
1798 .map_page = sn_dma_map_page,
1799 diff -urNp linux-2.6.32.46/arch/m32r/lib/usercopy.c linux-2.6.32.46/arch/m32r/lib/usercopy.c
1800 --- linux-2.6.32.46/arch/m32r/lib/usercopy.c 2011-03-27 14:31:47.000000000 -0400
1801 +++ linux-2.6.32.46/arch/m32r/lib/usercopy.c 2011-04-17 15:56:45.000000000 -0400
1802 @@ -14,6 +14,9 @@
1803 unsigned long
1804 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1805 {
1806 + if ((long)n < 0)
1807 + return n;
1808 +
1809 prefetch(from);
1810 if (access_ok(VERIFY_WRITE, to, n))
1811 __copy_user(to,from,n);
1812 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1813 unsigned long
1814 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1815 {
1816 + if ((long)n < 0)
1817 + return n;
1818 +
1819 prefetchw(to);
1820 if (access_ok(VERIFY_READ, from, n))
1821 __copy_user_zeroing(to,from,n);
1822 diff -urNp linux-2.6.32.46/arch/mips/Makefile linux-2.6.32.46/arch/mips/Makefile
1823 --- linux-2.6.32.46/arch/mips/Makefile 2011-03-27 14:31:47.000000000 -0400
1824 +++ linux-2.6.32.46/arch/mips/Makefile 2011-08-21 19:26:52.000000000 -0400
1825 @@ -51,6 +51,8 @@ endif
1826 cflags-y := -ffunction-sections
1827 cflags-y += $(call cc-option, -mno-check-zero-division)
1828
1829 +cflags-y += -Wno-sign-compare -Wno-extra
1830 +
1831 ifdef CONFIG_32BIT
1832 ld-emul = $(32bit-emul)
1833 vmlinux-32 = vmlinux
1834 diff -urNp linux-2.6.32.46/arch/mips/alchemy/devboards/pm.c linux-2.6.32.46/arch/mips/alchemy/devboards/pm.c
1835 --- linux-2.6.32.46/arch/mips/alchemy/devboards/pm.c 2011-03-27 14:31:47.000000000 -0400
1836 +++ linux-2.6.32.46/arch/mips/alchemy/devboards/pm.c 2011-04-17 15:56:45.000000000 -0400
1837 @@ -78,7 +78,7 @@ static void db1x_pm_end(void)
1838
1839 }
1840
1841 -static struct platform_suspend_ops db1x_pm_ops = {
1842 +static const struct platform_suspend_ops db1x_pm_ops = {
1843 .valid = suspend_valid_only_mem,
1844 .begin = db1x_pm_begin,
1845 .enter = db1x_pm_enter,
1846 diff -urNp linux-2.6.32.46/arch/mips/include/asm/elf.h linux-2.6.32.46/arch/mips/include/asm/elf.h
1847 --- linux-2.6.32.46/arch/mips/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1848 +++ linux-2.6.32.46/arch/mips/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1849 @@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_str
1850 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1851 #endif
1852
1853 +#ifdef CONFIG_PAX_ASLR
1854 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1855 +
1856 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1857 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1858 +#endif
1859 +
1860 #endif /* _ASM_ELF_H */
1861 diff -urNp linux-2.6.32.46/arch/mips/include/asm/page.h linux-2.6.32.46/arch/mips/include/asm/page.h
1862 --- linux-2.6.32.46/arch/mips/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
1863 +++ linux-2.6.32.46/arch/mips/include/asm/page.h 2011-04-17 15:56:45.000000000 -0400
1864 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
1865 #ifdef CONFIG_CPU_MIPS32
1866 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1867 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1868 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1869 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1870 #else
1871 typedef struct { unsigned long long pte; } pte_t;
1872 #define pte_val(x) ((x).pte)
1873 diff -urNp linux-2.6.32.46/arch/mips/include/asm/reboot.h linux-2.6.32.46/arch/mips/include/asm/reboot.h
1874 --- linux-2.6.32.46/arch/mips/include/asm/reboot.h 2011-03-27 14:31:47.000000000 -0400
1875 +++ linux-2.6.32.46/arch/mips/include/asm/reboot.h 2011-08-21 17:35:02.000000000 -0400
1876 @@ -9,7 +9,7 @@
1877 #ifndef _ASM_REBOOT_H
1878 #define _ASM_REBOOT_H
1879
1880 -extern void (*_machine_restart)(char *command);
1881 -extern void (*_machine_halt)(void);
1882 +extern void (*__noreturn _machine_restart)(char *command);
1883 +extern void (*__noreturn _machine_halt)(void);
1884
1885 #endif /* _ASM_REBOOT_H */
1886 diff -urNp linux-2.6.32.46/arch/mips/include/asm/system.h linux-2.6.32.46/arch/mips/include/asm/system.h
1887 --- linux-2.6.32.46/arch/mips/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
1888 +++ linux-2.6.32.46/arch/mips/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
1889 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1890 */
1891 #define __ARCH_WANT_UNLOCKED_CTXSW
1892
1893 -extern unsigned long arch_align_stack(unsigned long sp);
1894 +#define arch_align_stack(x) ((x) & ~0xfUL)
1895
1896 #endif /* _ASM_SYSTEM_H */
1897 diff -urNp linux-2.6.32.46/arch/mips/kernel/binfmt_elfn32.c linux-2.6.32.46/arch/mips/kernel/binfmt_elfn32.c
1898 --- linux-2.6.32.46/arch/mips/kernel/binfmt_elfn32.c 2011-03-27 14:31:47.000000000 -0400
1899 +++ linux-2.6.32.46/arch/mips/kernel/binfmt_elfn32.c 2011-04-17 15:56:45.000000000 -0400
1900 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1901 #undef ELF_ET_DYN_BASE
1902 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1903
1904 +#ifdef CONFIG_PAX_ASLR
1905 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1906 +
1907 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1908 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1909 +#endif
1910 +
1911 #include <asm/processor.h>
1912 #include <linux/module.h>
1913 #include <linux/elfcore.h>
1914 diff -urNp linux-2.6.32.46/arch/mips/kernel/binfmt_elfo32.c linux-2.6.32.46/arch/mips/kernel/binfmt_elfo32.c
1915 --- linux-2.6.32.46/arch/mips/kernel/binfmt_elfo32.c 2011-03-27 14:31:47.000000000 -0400
1916 +++ linux-2.6.32.46/arch/mips/kernel/binfmt_elfo32.c 2011-04-17 15:56:45.000000000 -0400
1917 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1918 #undef ELF_ET_DYN_BASE
1919 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1920
1921 +#ifdef CONFIG_PAX_ASLR
1922 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1923 +
1924 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1925 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1926 +#endif
1927 +
1928 #include <asm/processor.h>
1929
1930 /*
1931 diff -urNp linux-2.6.32.46/arch/mips/kernel/kgdb.c linux-2.6.32.46/arch/mips/kernel/kgdb.c
1932 --- linux-2.6.32.46/arch/mips/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
1933 +++ linux-2.6.32.46/arch/mips/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
1934 @@ -245,6 +245,7 @@ int kgdb_arch_handle_exception(int vecto
1935 return -1;
1936 }
1937
1938 +/* cannot be const */
1939 struct kgdb_arch arch_kgdb_ops;
1940
1941 /*
1942 diff -urNp linux-2.6.32.46/arch/mips/kernel/process.c linux-2.6.32.46/arch/mips/kernel/process.c
1943 --- linux-2.6.32.46/arch/mips/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
1944 +++ linux-2.6.32.46/arch/mips/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
1945 @@ -470,15 +470,3 @@ unsigned long get_wchan(struct task_stru
1946 out:
1947 return pc;
1948 }
1949 -
1950 -/*
1951 - * Don't forget that the stack pointer must be aligned on a 8 bytes
1952 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1953 - */
1954 -unsigned long arch_align_stack(unsigned long sp)
1955 -{
1956 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1957 - sp -= get_random_int() & ~PAGE_MASK;
1958 -
1959 - return sp & ALMASK;
1960 -}
1961 diff -urNp linux-2.6.32.46/arch/mips/kernel/reset.c linux-2.6.32.46/arch/mips/kernel/reset.c
1962 --- linux-2.6.32.46/arch/mips/kernel/reset.c 2011-03-27 14:31:47.000000000 -0400
1963 +++ linux-2.6.32.46/arch/mips/kernel/reset.c 2011-08-21 17:35:26.000000000 -0400
1964 @@ -19,8 +19,8 @@
1965 * So handle all using function pointers to machine specific
1966 * functions.
1967 */
1968 -void (*_machine_restart)(char *command);
1969 -void (*_machine_halt)(void);
1970 +void (*__noreturn _machine_restart)(char *command);
1971 +void (*__noreturn _machine_halt)(void);
1972 void (*pm_power_off)(void);
1973
1974 EXPORT_SYMBOL(pm_power_off);
1975 @@ -29,16 +29,19 @@ void machine_restart(char *command)
1976 {
1977 if (_machine_restart)
1978 _machine_restart(command);
1979 + BUG();
1980 }
1981
1982 void machine_halt(void)
1983 {
1984 if (_machine_halt)
1985 _machine_halt();
1986 + BUG();
1987 }
1988
1989 void machine_power_off(void)
1990 {
1991 if (pm_power_off)
1992 pm_power_off();
1993 + BUG();
1994 }
1995 diff -urNp linux-2.6.32.46/arch/mips/kernel/syscall.c linux-2.6.32.46/arch/mips/kernel/syscall.c
1996 --- linux-2.6.32.46/arch/mips/kernel/syscall.c 2011-03-27 14:31:47.000000000 -0400
1997 +++ linux-2.6.32.46/arch/mips/kernel/syscall.c 2011-04-17 15:56:45.000000000 -0400
1998 @@ -102,17 +102,21 @@ unsigned long arch_get_unmapped_area(str
1999 do_color_align = 0;
2000 if (filp || (flags & MAP_SHARED))
2001 do_color_align = 1;
2002 +
2003 +#ifdef CONFIG_PAX_RANDMMAP
2004 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2005 +#endif
2006 +
2007 if (addr) {
2008 if (do_color_align)
2009 addr = COLOUR_ALIGN(addr, pgoff);
2010 else
2011 addr = PAGE_ALIGN(addr);
2012 vmm = find_vma(current->mm, addr);
2013 - if (task_size - len >= addr &&
2014 - (!vmm || addr + len <= vmm->vm_start))
2015 + if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
2016 return addr;
2017 }
2018 - addr = TASK_UNMAPPED_BASE;
2019 + addr = current->mm->mmap_base;
2020 if (do_color_align)
2021 addr = COLOUR_ALIGN(addr, pgoff);
2022 else
2023 @@ -122,7 +126,7 @@ unsigned long arch_get_unmapped_area(str
2024 /* At this point: (!vmm || addr < vmm->vm_end). */
2025 if (task_size - len < addr)
2026 return -ENOMEM;
2027 - if (!vmm || addr + len <= vmm->vm_start)
2028 + if (check_heap_stack_gap(vmm, addr, len))
2029 return addr;
2030 addr = vmm->vm_end;
2031 if (do_color_align)
2032 diff -urNp linux-2.6.32.46/arch/mips/mm/fault.c linux-2.6.32.46/arch/mips/mm/fault.c
2033 --- linux-2.6.32.46/arch/mips/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
2034 +++ linux-2.6.32.46/arch/mips/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
2035 @@ -26,6 +26,23 @@
2036 #include <asm/ptrace.h>
2037 #include <asm/highmem.h> /* For VMALLOC_END */
2038
2039 +#ifdef CONFIG_PAX_PAGEEXEC
2040 +void pax_report_insns(void *pc, void *sp)
2041 +{
2042 + unsigned long i;
2043 +
2044 + printk(KERN_ERR "PAX: bytes at PC: ");
2045 + for (i = 0; i < 5; i++) {
2046 + unsigned int c;
2047 + if (get_user(c, (unsigned int *)pc+i))
2048 + printk(KERN_CONT "???????? ");
2049 + else
2050 + printk(KERN_CONT "%08x ", c);
2051 + }
2052 + printk("\n");
2053 +}
2054 +#endif
2055 +
2056 /*
2057 * This routine handles page faults. It determines the address,
2058 * and the problem, and then passes it off to one of the appropriate
2059 diff -urNp linux-2.6.32.46/arch/parisc/include/asm/elf.h linux-2.6.32.46/arch/parisc/include/asm/elf.h
2060 --- linux-2.6.32.46/arch/parisc/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
2061 +++ linux-2.6.32.46/arch/parisc/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
2062 @@ -343,6 +343,13 @@ struct pt_regs; /* forward declaration..
2063
2064 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2065
2066 +#ifdef CONFIG_PAX_ASLR
2067 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2068 +
2069 +#define PAX_DELTA_MMAP_LEN 16
2070 +#define PAX_DELTA_STACK_LEN 16
2071 +#endif
2072 +
2073 /* This yields a mask that user programs can use to figure out what
2074 instruction set this CPU supports. This could be done in user space,
2075 but it's not easy, and we've already done it here. */
2076 diff -urNp linux-2.6.32.46/arch/parisc/include/asm/pgtable.h linux-2.6.32.46/arch/parisc/include/asm/pgtable.h
2077 --- linux-2.6.32.46/arch/parisc/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
2078 +++ linux-2.6.32.46/arch/parisc/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
2079 @@ -207,6 +207,17 @@
2080 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2081 #define PAGE_COPY PAGE_EXECREAD
2082 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2083 +
2084 +#ifdef CONFIG_PAX_PAGEEXEC
2085 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2086 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2087 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2088 +#else
2089 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2090 +# define PAGE_COPY_NOEXEC PAGE_COPY
2091 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2092 +#endif
2093 +
2094 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2095 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
2096 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
2097 diff -urNp linux-2.6.32.46/arch/parisc/kernel/module.c linux-2.6.32.46/arch/parisc/kernel/module.c
2098 --- linux-2.6.32.46/arch/parisc/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
2099 +++ linux-2.6.32.46/arch/parisc/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
2100 @@ -95,16 +95,38 @@
2101
2102 /* three functions to determine where in the module core
2103 * or init pieces the location is */
2104 +static inline int in_init_rx(struct module *me, void *loc)
2105 +{
2106 + return (loc >= me->module_init_rx &&
2107 + loc < (me->module_init_rx + me->init_size_rx));
2108 +}
2109 +
2110 +static inline int in_init_rw(struct module *me, void *loc)
2111 +{
2112 + return (loc >= me->module_init_rw &&
2113 + loc < (me->module_init_rw + me->init_size_rw));
2114 +}
2115 +
2116 static inline int in_init(struct module *me, void *loc)
2117 {
2118 - return (loc >= me->module_init &&
2119 - loc <= (me->module_init + me->init_size));
2120 + return in_init_rx(me, loc) || in_init_rw(me, loc);
2121 +}
2122 +
2123 +static inline int in_core_rx(struct module *me, void *loc)
2124 +{
2125 + return (loc >= me->module_core_rx &&
2126 + loc < (me->module_core_rx + me->core_size_rx));
2127 +}
2128 +
2129 +static inline int in_core_rw(struct module *me, void *loc)
2130 +{
2131 + return (loc >= me->module_core_rw &&
2132 + loc < (me->module_core_rw + me->core_size_rw));
2133 }
2134
2135 static inline int in_core(struct module *me, void *loc)
2136 {
2137 - return (loc >= me->module_core &&
2138 - loc <= (me->module_core + me->core_size));
2139 + return in_core_rx(me, loc) || in_core_rw(me, loc);
2140 }
2141
2142 static inline int in_local(struct module *me, void *loc)
2143 @@ -364,13 +386,13 @@ int module_frob_arch_sections(CONST Elf_
2144 }
2145
2146 /* align things a bit */
2147 - me->core_size = ALIGN(me->core_size, 16);
2148 - me->arch.got_offset = me->core_size;
2149 - me->core_size += gots * sizeof(struct got_entry);
2150 -
2151 - me->core_size = ALIGN(me->core_size, 16);
2152 - me->arch.fdesc_offset = me->core_size;
2153 - me->core_size += fdescs * sizeof(Elf_Fdesc);
2154 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2155 + me->arch.got_offset = me->core_size_rw;
2156 + me->core_size_rw += gots * sizeof(struct got_entry);
2157 +
2158 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2159 + me->arch.fdesc_offset = me->core_size_rw;
2160 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
2161
2162 me->arch.got_max = gots;
2163 me->arch.fdesc_max = fdescs;
2164 @@ -388,7 +410,7 @@ static Elf64_Word get_got(struct module
2165
2166 BUG_ON(value == 0);
2167
2168 - got = me->module_core + me->arch.got_offset;
2169 + got = me->module_core_rw + me->arch.got_offset;
2170 for (i = 0; got[i].addr; i++)
2171 if (got[i].addr == value)
2172 goto out;
2173 @@ -406,7 +428,7 @@ static Elf64_Word get_got(struct module
2174 #ifdef CONFIG_64BIT
2175 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2176 {
2177 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
2178 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
2179
2180 if (!value) {
2181 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
2182 @@ -424,7 +446,7 @@ static Elf_Addr get_fdesc(struct module
2183
2184 /* Create new one */
2185 fdesc->addr = value;
2186 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2187 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2188 return (Elf_Addr)fdesc;
2189 }
2190 #endif /* CONFIG_64BIT */
2191 @@ -848,7 +870,7 @@ register_unwind_table(struct module *me,
2192
2193 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
2194 end = table + sechdrs[me->arch.unwind_section].sh_size;
2195 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2196 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2197
2198 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
2199 me->arch.unwind_section, table, end, gp);
2200 diff -urNp linux-2.6.32.46/arch/parisc/kernel/sys_parisc.c linux-2.6.32.46/arch/parisc/kernel/sys_parisc.c
2201 --- linux-2.6.32.46/arch/parisc/kernel/sys_parisc.c 2011-03-27 14:31:47.000000000 -0400
2202 +++ linux-2.6.32.46/arch/parisc/kernel/sys_parisc.c 2011-04-17 15:56:45.000000000 -0400
2203 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
2204 /* At this point: (!vma || addr < vma->vm_end). */
2205 if (TASK_SIZE - len < addr)
2206 return -ENOMEM;
2207 - if (!vma || addr + len <= vma->vm_start)
2208 + if (check_heap_stack_gap(vma, addr, len))
2209 return addr;
2210 addr = vma->vm_end;
2211 }
2212 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
2213 /* At this point: (!vma || addr < vma->vm_end). */
2214 if (TASK_SIZE - len < addr)
2215 return -ENOMEM;
2216 - if (!vma || addr + len <= vma->vm_start)
2217 + if (check_heap_stack_gap(vma, addr, len))
2218 return addr;
2219 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
2220 if (addr < vma->vm_end) /* handle wraparound */
2221 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
2222 if (flags & MAP_FIXED)
2223 return addr;
2224 if (!addr)
2225 - addr = TASK_UNMAPPED_BASE;
2226 + addr = current->mm->mmap_base;
2227
2228 if (filp) {
2229 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
2230 diff -urNp linux-2.6.32.46/arch/parisc/kernel/traps.c linux-2.6.32.46/arch/parisc/kernel/traps.c
2231 --- linux-2.6.32.46/arch/parisc/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
2232 +++ linux-2.6.32.46/arch/parisc/kernel/traps.c 2011-04-17 15:56:45.000000000 -0400
2233 @@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
2234
2235 down_read(&current->mm->mmap_sem);
2236 vma = find_vma(current->mm,regs->iaoq[0]);
2237 - if (vma && (regs->iaoq[0] >= vma->vm_start)
2238 - && (vma->vm_flags & VM_EXEC)) {
2239 -
2240 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
2241 fault_address = regs->iaoq[0];
2242 fault_space = regs->iasq[0];
2243
2244 diff -urNp linux-2.6.32.46/arch/parisc/mm/fault.c linux-2.6.32.46/arch/parisc/mm/fault.c
2245 --- linux-2.6.32.46/arch/parisc/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
2246 +++ linux-2.6.32.46/arch/parisc/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
2247 @@ -15,6 +15,7 @@
2248 #include <linux/sched.h>
2249 #include <linux/interrupt.h>
2250 #include <linux/module.h>
2251 +#include <linux/unistd.h>
2252
2253 #include <asm/uaccess.h>
2254 #include <asm/traps.h>
2255 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
2256 static unsigned long
2257 parisc_acctyp(unsigned long code, unsigned int inst)
2258 {
2259 - if (code == 6 || code == 16)
2260 + if (code == 6 || code == 7 || code == 16)
2261 return VM_EXEC;
2262
2263 switch (inst & 0xf0000000) {
2264 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
2265 }
2266 #endif
2267
2268 +#ifdef CONFIG_PAX_PAGEEXEC
2269 +/*
2270 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
2271 + *
2272 + * returns 1 when task should be killed
2273 + * 2 when rt_sigreturn trampoline was detected
2274 + * 3 when unpatched PLT trampoline was detected
2275 + */
2276 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2277 +{
2278 +
2279 +#ifdef CONFIG_PAX_EMUPLT
2280 + int err;
2281 +
2282 + do { /* PaX: unpatched PLT emulation */
2283 + unsigned int bl, depwi;
2284 +
2285 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
2286 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
2287 +
2288 + if (err)
2289 + break;
2290 +
2291 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
2292 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
2293 +
2294 + err = get_user(ldw, (unsigned int *)addr);
2295 + err |= get_user(bv, (unsigned int *)(addr+4));
2296 + err |= get_user(ldw2, (unsigned int *)(addr+8));
2297 +
2298 + if (err)
2299 + break;
2300 +
2301 + if (ldw == 0x0E801096U &&
2302 + bv == 0xEAC0C000U &&
2303 + ldw2 == 0x0E881095U)
2304 + {
2305 + unsigned int resolver, map;
2306 +
2307 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
2308 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
2309 + if (err)
2310 + break;
2311 +
2312 + regs->gr[20] = instruction_pointer(regs)+8;
2313 + regs->gr[21] = map;
2314 + regs->gr[22] = resolver;
2315 + regs->iaoq[0] = resolver | 3UL;
2316 + regs->iaoq[1] = regs->iaoq[0] + 4;
2317 + return 3;
2318 + }
2319 + }
2320 + } while (0);
2321 +#endif
2322 +
2323 +#ifdef CONFIG_PAX_EMUTRAMP
2324 +
2325 +#ifndef CONFIG_PAX_EMUSIGRT
2326 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
2327 + return 1;
2328 +#endif
2329 +
2330 + do { /* PaX: rt_sigreturn emulation */
2331 + unsigned int ldi1, ldi2, bel, nop;
2332 +
2333 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2334 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2335 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2336 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2337 +
2338 + if (err)
2339 + break;
2340 +
2341 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2342 + ldi2 == 0x3414015AU &&
2343 + bel == 0xE4008200U &&
2344 + nop == 0x08000240U)
2345 + {
2346 + regs->gr[25] = (ldi1 & 2) >> 1;
2347 + regs->gr[20] = __NR_rt_sigreturn;
2348 + regs->gr[31] = regs->iaoq[1] + 16;
2349 + regs->sr[0] = regs->iasq[1];
2350 + regs->iaoq[0] = 0x100UL;
2351 + regs->iaoq[1] = regs->iaoq[0] + 4;
2352 + regs->iasq[0] = regs->sr[2];
2353 + regs->iasq[1] = regs->sr[2];
2354 + return 2;
2355 + }
2356 + } while (0);
2357 +#endif
2358 +
2359 + return 1;
2360 +}
2361 +
2362 +void pax_report_insns(void *pc, void *sp)
2363 +{
2364 + unsigned long i;
2365 +
2366 + printk(KERN_ERR "PAX: bytes at PC: ");
2367 + for (i = 0; i < 5; i++) {
2368 + unsigned int c;
2369 + if (get_user(c, (unsigned int *)pc+i))
2370 + printk(KERN_CONT "???????? ");
2371 + else
2372 + printk(KERN_CONT "%08x ", c);
2373 + }
2374 + printk("\n");
2375 +}
2376 +#endif
2377 +
2378 int fixup_exception(struct pt_regs *regs)
2379 {
2380 const struct exception_table_entry *fix;
2381 @@ -192,8 +303,33 @@ good_area:
2382
2383 acc_type = parisc_acctyp(code,regs->iir);
2384
2385 - if ((vma->vm_flags & acc_type) != acc_type)
2386 + if ((vma->vm_flags & acc_type) != acc_type) {
2387 +
2388 +#ifdef CONFIG_PAX_PAGEEXEC
2389 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2390 + (address & ~3UL) == instruction_pointer(regs))
2391 + {
2392 + up_read(&mm->mmap_sem);
2393 + switch (pax_handle_fetch_fault(regs)) {
2394 +
2395 +#ifdef CONFIG_PAX_EMUPLT
2396 + case 3:
2397 + return;
2398 +#endif
2399 +
2400 +#ifdef CONFIG_PAX_EMUTRAMP
2401 + case 2:
2402 + return;
2403 +#endif
2404 +
2405 + }
2406 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2407 + do_group_exit(SIGKILL);
2408 + }
2409 +#endif
2410 +
2411 goto bad_area;
2412 + }
2413
2414 /*
2415 * If for any reason at all we couldn't handle the fault, make
2416 diff -urNp linux-2.6.32.46/arch/powerpc/Makefile linux-2.6.32.46/arch/powerpc/Makefile
2417 --- linux-2.6.32.46/arch/powerpc/Makefile 2011-03-27 14:31:47.000000000 -0400
2418 +++ linux-2.6.32.46/arch/powerpc/Makefile 2011-08-21 19:27:08.000000000 -0400
2419 @@ -74,6 +74,8 @@ KBUILD_AFLAGS += -Iarch/$(ARCH)
2420 KBUILD_CFLAGS += -msoft-float -pipe -Iarch/$(ARCH) $(CFLAGS-y)
2421 CPP = $(CC) -E $(KBUILD_CFLAGS)
2422
2423 +cflags-y += -Wno-sign-compare -Wno-extra
2424 +
2425 CHECKFLAGS += -m$(CONFIG_WORD_SIZE) -D__powerpc__ -D__powerpc$(CONFIG_WORD_SIZE)__
2426
2427 ifeq ($(CONFIG_PPC64),y)
2428 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/device.h linux-2.6.32.46/arch/powerpc/include/asm/device.h
2429 --- linux-2.6.32.46/arch/powerpc/include/asm/device.h 2011-03-27 14:31:47.000000000 -0400
2430 +++ linux-2.6.32.46/arch/powerpc/include/asm/device.h 2011-04-17 15:56:45.000000000 -0400
2431 @@ -14,7 +14,7 @@ struct dev_archdata {
2432 struct device_node *of_node;
2433
2434 /* DMA operations on that device */
2435 - struct dma_map_ops *dma_ops;
2436 + const struct dma_map_ops *dma_ops;
2437
2438 /*
2439 * When an iommu is in use, dma_data is used as a ptr to the base of the
2440 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/dma-mapping.h linux-2.6.32.46/arch/powerpc/include/asm/dma-mapping.h
2441 --- linux-2.6.32.46/arch/powerpc/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
2442 +++ linux-2.6.32.46/arch/powerpc/include/asm/dma-mapping.h 2011-04-17 15:56:45.000000000 -0400
2443 @@ -69,9 +69,9 @@ static inline unsigned long device_to_ma
2444 #ifdef CONFIG_PPC64
2445 extern struct dma_map_ops dma_iommu_ops;
2446 #endif
2447 -extern struct dma_map_ops dma_direct_ops;
2448 +extern const struct dma_map_ops dma_direct_ops;
2449
2450 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2451 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2452 {
2453 /* We don't handle the NULL dev case for ISA for now. We could
2454 * do it via an out of line call but it is not needed for now. The
2455 @@ -84,7 +84,7 @@ static inline struct dma_map_ops *get_dm
2456 return dev->archdata.dma_ops;
2457 }
2458
2459 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
2460 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
2461 {
2462 dev->archdata.dma_ops = ops;
2463 }
2464 @@ -118,7 +118,7 @@ static inline void set_dma_offset(struct
2465
2466 static inline int dma_supported(struct device *dev, u64 mask)
2467 {
2468 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2469 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2470
2471 if (unlikely(dma_ops == NULL))
2472 return 0;
2473 @@ -132,7 +132,7 @@ static inline int dma_supported(struct d
2474
2475 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
2476 {
2477 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2478 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2479
2480 if (unlikely(dma_ops == NULL))
2481 return -EIO;
2482 @@ -147,7 +147,7 @@ static inline int dma_set_mask(struct de
2483 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
2484 dma_addr_t *dma_handle, gfp_t flag)
2485 {
2486 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2487 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2488 void *cpu_addr;
2489
2490 BUG_ON(!dma_ops);
2491 @@ -162,7 +162,7 @@ static inline void *dma_alloc_coherent(s
2492 static inline void dma_free_coherent(struct device *dev, size_t size,
2493 void *cpu_addr, dma_addr_t dma_handle)
2494 {
2495 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2496 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2497
2498 BUG_ON(!dma_ops);
2499
2500 @@ -173,7 +173,7 @@ static inline void dma_free_coherent(str
2501
2502 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
2503 {
2504 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2505 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2506
2507 if (dma_ops->mapping_error)
2508 return dma_ops->mapping_error(dev, dma_addr);
2509 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/elf.h linux-2.6.32.46/arch/powerpc/include/asm/elf.h
2510 --- linux-2.6.32.46/arch/powerpc/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
2511 +++ linux-2.6.32.46/arch/powerpc/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
2512 @@ -179,8 +179,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
2513 the loader. We need to make sure that it is out of the way of the program
2514 that it will "exec", and that there is sufficient room for the brk. */
2515
2516 -extern unsigned long randomize_et_dyn(unsigned long base);
2517 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2518 +#define ELF_ET_DYN_BASE (0x20000000)
2519 +
2520 +#ifdef CONFIG_PAX_ASLR
2521 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2522 +
2523 +#ifdef __powerpc64__
2524 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2525 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2526 +#else
2527 +#define PAX_DELTA_MMAP_LEN 15
2528 +#define PAX_DELTA_STACK_LEN 15
2529 +#endif
2530 +#endif
2531
2532 /*
2533 * Our registers are always unsigned longs, whether we're a 32 bit
2534 @@ -275,9 +286,6 @@ extern int arch_setup_additional_pages(s
2535 (0x7ff >> (PAGE_SHIFT - 12)) : \
2536 (0x3ffff >> (PAGE_SHIFT - 12)))
2537
2538 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2539 -#define arch_randomize_brk arch_randomize_brk
2540 -
2541 #endif /* __KERNEL__ */
2542
2543 /*
2544 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/iommu.h linux-2.6.32.46/arch/powerpc/include/asm/iommu.h
2545 --- linux-2.6.32.46/arch/powerpc/include/asm/iommu.h 2011-03-27 14:31:47.000000000 -0400
2546 +++ linux-2.6.32.46/arch/powerpc/include/asm/iommu.h 2011-04-17 15:56:45.000000000 -0400
2547 @@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(voi
2548 extern void iommu_init_early_dart(void);
2549 extern void iommu_init_early_pasemi(void);
2550
2551 +/* dma-iommu.c */
2552 +extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
2553 +
2554 #ifdef CONFIG_PCI
2555 extern void pci_iommu_init(void);
2556 extern void pci_direct_iommu_init(void);
2557 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/kmap_types.h linux-2.6.32.46/arch/powerpc/include/asm/kmap_types.h
2558 --- linux-2.6.32.46/arch/powerpc/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
2559 +++ linux-2.6.32.46/arch/powerpc/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
2560 @@ -26,6 +26,7 @@ enum km_type {
2561 KM_SOFTIRQ1,
2562 KM_PPC_SYNC_PAGE,
2563 KM_PPC_SYNC_ICACHE,
2564 + KM_CLEARPAGE,
2565 KM_TYPE_NR
2566 };
2567
2568 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/page.h linux-2.6.32.46/arch/powerpc/include/asm/page.h
2569 --- linux-2.6.32.46/arch/powerpc/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
2570 +++ linux-2.6.32.46/arch/powerpc/include/asm/page.h 2011-08-21 16:07:39.000000000 -0400
2571 @@ -116,8 +116,9 @@ extern phys_addr_t kernstart_addr;
2572 * and needs to be executable. This means the whole heap ends
2573 * up being executable.
2574 */
2575 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2576 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2577 +#define VM_DATA_DEFAULT_FLAGS32 \
2578 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2579 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2580
2581 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2582 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2583 @@ -145,6 +146,9 @@ extern phys_addr_t kernstart_addr;
2584 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2585 #endif
2586
2587 +#define ktla_ktva(addr) (addr)
2588 +#define ktva_ktla(addr) (addr)
2589 +
2590 #ifndef __ASSEMBLY__
2591
2592 #undef STRICT_MM_TYPECHECKS
2593 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/page_64.h linux-2.6.32.46/arch/powerpc/include/asm/page_64.h
2594 --- linux-2.6.32.46/arch/powerpc/include/asm/page_64.h 2011-03-27 14:31:47.000000000 -0400
2595 +++ linux-2.6.32.46/arch/powerpc/include/asm/page_64.h 2011-04-17 15:56:45.000000000 -0400
2596 @@ -180,15 +180,18 @@ do { \
2597 * stack by default, so in the absense of a PT_GNU_STACK program header
2598 * we turn execute permission off.
2599 */
2600 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2601 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2602 +#define VM_STACK_DEFAULT_FLAGS32 \
2603 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2604 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2605
2606 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2607 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2608
2609 +#ifndef CONFIG_PAX_PAGEEXEC
2610 #define VM_STACK_DEFAULT_FLAGS \
2611 (test_thread_flag(TIF_32BIT) ? \
2612 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2613 +#endif
2614
2615 #include <asm-generic/getorder.h>
2616
2617 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/pci.h linux-2.6.32.46/arch/powerpc/include/asm/pci.h
2618 --- linux-2.6.32.46/arch/powerpc/include/asm/pci.h 2011-03-27 14:31:47.000000000 -0400
2619 +++ linux-2.6.32.46/arch/powerpc/include/asm/pci.h 2011-04-17 15:56:45.000000000 -0400
2620 @@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq
2621 }
2622
2623 #ifdef CONFIG_PCI
2624 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
2625 -extern struct dma_map_ops *get_pci_dma_ops(void);
2626 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
2627 +extern const struct dma_map_ops *get_pci_dma_ops(void);
2628 #else /* CONFIG_PCI */
2629 #define set_pci_dma_ops(d)
2630 #define get_pci_dma_ops() NULL
2631 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/pgtable.h linux-2.6.32.46/arch/powerpc/include/asm/pgtable.h
2632 --- linux-2.6.32.46/arch/powerpc/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
2633 +++ linux-2.6.32.46/arch/powerpc/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
2634 @@ -2,6 +2,7 @@
2635 #define _ASM_POWERPC_PGTABLE_H
2636 #ifdef __KERNEL__
2637
2638 +#include <linux/const.h>
2639 #ifndef __ASSEMBLY__
2640 #include <asm/processor.h> /* For TASK_SIZE */
2641 #include <asm/mmu.h>
2642 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/pte-hash32.h linux-2.6.32.46/arch/powerpc/include/asm/pte-hash32.h
2643 --- linux-2.6.32.46/arch/powerpc/include/asm/pte-hash32.h 2011-03-27 14:31:47.000000000 -0400
2644 +++ linux-2.6.32.46/arch/powerpc/include/asm/pte-hash32.h 2011-04-17 15:56:45.000000000 -0400
2645 @@ -21,6 +21,7 @@
2646 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2647 #define _PAGE_USER 0x004 /* usermode access allowed */
2648 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2649 +#define _PAGE_EXEC _PAGE_GUARDED
2650 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2651 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2652 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2653 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/ptrace.h linux-2.6.32.46/arch/powerpc/include/asm/ptrace.h
2654 --- linux-2.6.32.46/arch/powerpc/include/asm/ptrace.h 2011-03-27 14:31:47.000000000 -0400
2655 +++ linux-2.6.32.46/arch/powerpc/include/asm/ptrace.h 2011-08-21 15:53:58.000000000 -0400
2656 @@ -103,7 +103,7 @@ extern unsigned long profile_pc(struct p
2657 } while(0)
2658
2659 struct task_struct;
2660 -extern unsigned long ptrace_get_reg(struct task_struct *task, int regno);
2661 +extern unsigned long ptrace_get_reg(struct task_struct *task, unsigned int regno);
2662 extern int ptrace_put_reg(struct task_struct *task, int regno,
2663 unsigned long data);
2664
2665 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/reg.h linux-2.6.32.46/arch/powerpc/include/asm/reg.h
2666 --- linux-2.6.32.46/arch/powerpc/include/asm/reg.h 2011-03-27 14:31:47.000000000 -0400
2667 +++ linux-2.6.32.46/arch/powerpc/include/asm/reg.h 2011-04-17 15:56:45.000000000 -0400
2668 @@ -191,6 +191,7 @@
2669 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2670 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2671 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2672 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2673 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2674 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2675 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2676 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/swiotlb.h linux-2.6.32.46/arch/powerpc/include/asm/swiotlb.h
2677 --- linux-2.6.32.46/arch/powerpc/include/asm/swiotlb.h 2011-03-27 14:31:47.000000000 -0400
2678 +++ linux-2.6.32.46/arch/powerpc/include/asm/swiotlb.h 2011-04-17 15:56:45.000000000 -0400
2679 @@ -13,7 +13,7 @@
2680
2681 #include <linux/swiotlb.h>
2682
2683 -extern struct dma_map_ops swiotlb_dma_ops;
2684 +extern const struct dma_map_ops swiotlb_dma_ops;
2685
2686 static inline void dma_mark_clean(void *addr, size_t size) {}
2687
2688 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/system.h linux-2.6.32.46/arch/powerpc/include/asm/system.h
2689 --- linux-2.6.32.46/arch/powerpc/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
2690 +++ linux-2.6.32.46/arch/powerpc/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
2691 @@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsi
2692 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2693 #endif
2694
2695 -extern unsigned long arch_align_stack(unsigned long sp);
2696 +#define arch_align_stack(x) ((x) & ~0xfUL)
2697
2698 /* Used in very early kernel initialization. */
2699 extern unsigned long reloc_offset(void);
2700 diff -urNp linux-2.6.32.46/arch/powerpc/include/asm/uaccess.h linux-2.6.32.46/arch/powerpc/include/asm/uaccess.h
2701 --- linux-2.6.32.46/arch/powerpc/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
2702 +++ linux-2.6.32.46/arch/powerpc/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
2703 @@ -13,6 +13,8 @@
2704 #define VERIFY_READ 0
2705 #define VERIFY_WRITE 1
2706
2707 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
2708 +
2709 /*
2710 * The fs value determines whether argument validity checking should be
2711 * performed or not. If get_fs() == USER_DS, checking is performed, with
2712 @@ -327,52 +329,6 @@ do { \
2713 extern unsigned long __copy_tofrom_user(void __user *to,
2714 const void __user *from, unsigned long size);
2715
2716 -#ifndef __powerpc64__
2717 -
2718 -static inline unsigned long copy_from_user(void *to,
2719 - const void __user *from, unsigned long n)
2720 -{
2721 - unsigned long over;
2722 -
2723 - if (access_ok(VERIFY_READ, from, n))
2724 - return __copy_tofrom_user((__force void __user *)to, from, n);
2725 - if ((unsigned long)from < TASK_SIZE) {
2726 - over = (unsigned long)from + n - TASK_SIZE;
2727 - return __copy_tofrom_user((__force void __user *)to, from,
2728 - n - over) + over;
2729 - }
2730 - return n;
2731 -}
2732 -
2733 -static inline unsigned long copy_to_user(void __user *to,
2734 - const void *from, unsigned long n)
2735 -{
2736 - unsigned long over;
2737 -
2738 - if (access_ok(VERIFY_WRITE, to, n))
2739 - return __copy_tofrom_user(to, (__force void __user *)from, n);
2740 - if ((unsigned long)to < TASK_SIZE) {
2741 - over = (unsigned long)to + n - TASK_SIZE;
2742 - return __copy_tofrom_user(to, (__force void __user *)from,
2743 - n - over) + over;
2744 - }
2745 - return n;
2746 -}
2747 -
2748 -#else /* __powerpc64__ */
2749 -
2750 -#define __copy_in_user(to, from, size) \
2751 - __copy_tofrom_user((to), (from), (size))
2752 -
2753 -extern unsigned long copy_from_user(void *to, const void __user *from,
2754 - unsigned long n);
2755 -extern unsigned long copy_to_user(void __user *to, const void *from,
2756 - unsigned long n);
2757 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
2758 - unsigned long n);
2759 -
2760 -#endif /* __powerpc64__ */
2761 -
2762 static inline unsigned long __copy_from_user_inatomic(void *to,
2763 const void __user *from, unsigned long n)
2764 {
2765 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
2766 if (ret == 0)
2767 return 0;
2768 }
2769 +
2770 + if (!__builtin_constant_p(n))
2771 + check_object_size(to, n, false);
2772 +
2773 return __copy_tofrom_user((__force void __user *)to, from, n);
2774 }
2775
2776 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
2777 if (ret == 0)
2778 return 0;
2779 }
2780 +
2781 + if (!__builtin_constant_p(n))
2782 + check_object_size(from, n, true);
2783 +
2784 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2785 }
2786
2787 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
2788 return __copy_to_user_inatomic(to, from, size);
2789 }
2790
2791 +#ifndef __powerpc64__
2792 +
2793 +static inline unsigned long __must_check copy_from_user(void *to,
2794 + const void __user *from, unsigned long n)
2795 +{
2796 + unsigned long over;
2797 +
2798 + if ((long)n < 0)
2799 + return n;
2800 +
2801 + if (access_ok(VERIFY_READ, from, n)) {
2802 + if (!__builtin_constant_p(n))
2803 + check_object_size(to, n, false);
2804 + return __copy_tofrom_user((__force void __user *)to, from, n);
2805 + }
2806 + if ((unsigned long)from < TASK_SIZE) {
2807 + over = (unsigned long)from + n - TASK_SIZE;
2808 + if (!__builtin_constant_p(n - over))
2809 + check_object_size(to, n - over, false);
2810 + return __copy_tofrom_user((__force void __user *)to, from,
2811 + n - over) + over;
2812 + }
2813 + return n;
2814 +}
2815 +
2816 +static inline unsigned long __must_check copy_to_user(void __user *to,
2817 + const void *from, unsigned long n)
2818 +{
2819 + unsigned long over;
2820 +
2821 + if ((long)n < 0)
2822 + return n;
2823 +
2824 + if (access_ok(VERIFY_WRITE, to, n)) {
2825 + if (!__builtin_constant_p(n))
2826 + check_object_size(from, n, true);
2827 + return __copy_tofrom_user(to, (__force void __user *)from, n);
2828 + }
2829 + if ((unsigned long)to < TASK_SIZE) {
2830 + over = (unsigned long)to + n - TASK_SIZE;
2831 + if (!__builtin_constant_p(n))
2832 + check_object_size(from, n - over, true);
2833 + return __copy_tofrom_user(to, (__force void __user *)from,
2834 + n - over) + over;
2835 + }
2836 + return n;
2837 +}
2838 +
2839 +#else /* __powerpc64__ */
2840 +
2841 +#define __copy_in_user(to, from, size) \
2842 + __copy_tofrom_user((to), (from), (size))
2843 +
2844 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2845 +{
2846 + if ((long)n < 0 || n > INT_MAX)
2847 + return n;
2848 +
2849 + if (!__builtin_constant_p(n))
2850 + check_object_size(to, n, false);
2851 +
2852 + if (likely(access_ok(VERIFY_READ, from, n)))
2853 + n = __copy_from_user(to, from, n);
2854 + else
2855 + memset(to, 0, n);
2856 + return n;
2857 +}
2858 +
2859 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2860 +{
2861 + if ((long)n < 0 || n > INT_MAX)
2862 + return n;
2863 +
2864 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
2865 + if (!__builtin_constant_p(n))
2866 + check_object_size(from, n, true);
2867 + n = __copy_to_user(to, from, n);
2868 + }
2869 + return n;
2870 +}
2871 +
2872 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
2873 + unsigned long n);
2874 +
2875 +#endif /* __powerpc64__ */
2876 +
2877 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2878
2879 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2880 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/cacheinfo.c linux-2.6.32.46/arch/powerpc/kernel/cacheinfo.c
2881 --- linux-2.6.32.46/arch/powerpc/kernel/cacheinfo.c 2011-03-27 14:31:47.000000000 -0400
2882 +++ linux-2.6.32.46/arch/powerpc/kernel/cacheinfo.c 2011-04-17 15:56:45.000000000 -0400
2883 @@ -642,7 +642,7 @@ static struct kobj_attribute *cache_inde
2884 &cache_assoc_attr,
2885 };
2886
2887 -static struct sysfs_ops cache_index_ops = {
2888 +static const struct sysfs_ops cache_index_ops = {
2889 .show = cache_index_show,
2890 };
2891
2892 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/dma-iommu.c linux-2.6.32.46/arch/powerpc/kernel/dma-iommu.c
2893 --- linux-2.6.32.46/arch/powerpc/kernel/dma-iommu.c 2011-03-27 14:31:47.000000000 -0400
2894 +++ linux-2.6.32.46/arch/powerpc/kernel/dma-iommu.c 2011-04-17 15:56:45.000000000 -0400
2895 @@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct de
2896 }
2897
2898 /* We support DMA to/from any memory page via the iommu */
2899 -static int dma_iommu_dma_supported(struct device *dev, u64 mask)
2900 +int dma_iommu_dma_supported(struct device *dev, u64 mask)
2901 {
2902 struct iommu_table *tbl = get_iommu_table_base(dev);
2903
2904 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.32.46/arch/powerpc/kernel/dma-swiotlb.c
2905 --- linux-2.6.32.46/arch/powerpc/kernel/dma-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
2906 +++ linux-2.6.32.46/arch/powerpc/kernel/dma-swiotlb.c 2011-04-17 15:56:45.000000000 -0400
2907 @@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
2908 * map_page, and unmap_page on highmem, use normal dma_ops
2909 * for everything else.
2910 */
2911 -struct dma_map_ops swiotlb_dma_ops = {
2912 +const struct dma_map_ops swiotlb_dma_ops = {
2913 .alloc_coherent = dma_direct_alloc_coherent,
2914 .free_coherent = dma_direct_free_coherent,
2915 .map_sg = swiotlb_map_sg_attrs,
2916 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/dma.c linux-2.6.32.46/arch/powerpc/kernel/dma.c
2917 --- linux-2.6.32.46/arch/powerpc/kernel/dma.c 2011-03-27 14:31:47.000000000 -0400
2918 +++ linux-2.6.32.46/arch/powerpc/kernel/dma.c 2011-04-17 15:56:45.000000000 -0400
2919 @@ -134,7 +134,7 @@ static inline void dma_direct_sync_singl
2920 }
2921 #endif
2922
2923 -struct dma_map_ops dma_direct_ops = {
2924 +const struct dma_map_ops dma_direct_ops = {
2925 .alloc_coherent = dma_direct_alloc_coherent,
2926 .free_coherent = dma_direct_free_coherent,
2927 .map_sg = dma_direct_map_sg,
2928 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/exceptions-64e.S linux-2.6.32.46/arch/powerpc/kernel/exceptions-64e.S
2929 --- linux-2.6.32.46/arch/powerpc/kernel/exceptions-64e.S 2011-03-27 14:31:47.000000000 -0400
2930 +++ linux-2.6.32.46/arch/powerpc/kernel/exceptions-64e.S 2011-04-17 15:56:45.000000000 -0400
2931 @@ -455,6 +455,7 @@ storage_fault_common:
2932 std r14,_DAR(r1)
2933 std r15,_DSISR(r1)
2934 addi r3,r1,STACK_FRAME_OVERHEAD
2935 + bl .save_nvgprs
2936 mr r4,r14
2937 mr r5,r15
2938 ld r14,PACA_EXGEN+EX_R14(r13)
2939 @@ -464,8 +465,7 @@ storage_fault_common:
2940 cmpdi r3,0
2941 bne- 1f
2942 b .ret_from_except_lite
2943 -1: bl .save_nvgprs
2944 - mr r5,r3
2945 +1: mr r5,r3
2946 addi r3,r1,STACK_FRAME_OVERHEAD
2947 ld r4,_DAR(r1)
2948 bl .bad_page_fault
2949 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/exceptions-64s.S linux-2.6.32.46/arch/powerpc/kernel/exceptions-64s.S
2950 --- linux-2.6.32.46/arch/powerpc/kernel/exceptions-64s.S 2011-03-27 14:31:47.000000000 -0400
2951 +++ linux-2.6.32.46/arch/powerpc/kernel/exceptions-64s.S 2011-04-17 15:56:45.000000000 -0400
2952 @@ -818,10 +818,10 @@ handle_page_fault:
2953 11: ld r4,_DAR(r1)
2954 ld r5,_DSISR(r1)
2955 addi r3,r1,STACK_FRAME_OVERHEAD
2956 + bl .save_nvgprs
2957 bl .do_page_fault
2958 cmpdi r3,0
2959 beq+ 13f
2960 - bl .save_nvgprs
2961 mr r5,r3
2962 addi r3,r1,STACK_FRAME_OVERHEAD
2963 lwz r4,_DAR(r1)
2964 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/ibmebus.c linux-2.6.32.46/arch/powerpc/kernel/ibmebus.c
2965 --- linux-2.6.32.46/arch/powerpc/kernel/ibmebus.c 2011-03-27 14:31:47.000000000 -0400
2966 +++ linux-2.6.32.46/arch/powerpc/kernel/ibmebus.c 2011-04-17 15:56:45.000000000 -0400
2967 @@ -127,7 +127,7 @@ static int ibmebus_dma_supported(struct
2968 return 1;
2969 }
2970
2971 -static struct dma_map_ops ibmebus_dma_ops = {
2972 +static const struct dma_map_ops ibmebus_dma_ops = {
2973 .alloc_coherent = ibmebus_alloc_coherent,
2974 .free_coherent = ibmebus_free_coherent,
2975 .map_sg = ibmebus_map_sg,
2976 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/kgdb.c linux-2.6.32.46/arch/powerpc/kernel/kgdb.c
2977 --- linux-2.6.32.46/arch/powerpc/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
2978 +++ linux-2.6.32.46/arch/powerpc/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
2979 @@ -126,7 +126,7 @@ static int kgdb_handle_breakpoint(struct
2980 if (kgdb_handle_exception(0, SIGTRAP, 0, regs) != 0)
2981 return 0;
2982
2983 - if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
2984 + if (*(u32 *) (regs->nip) == *(const u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
2985 regs->nip += 4;
2986
2987 return 1;
2988 @@ -353,7 +353,7 @@ int kgdb_arch_handle_exception(int vecto
2989 /*
2990 * Global data
2991 */
2992 -struct kgdb_arch arch_kgdb_ops = {
2993 +const struct kgdb_arch arch_kgdb_ops = {
2994 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
2995 };
2996
2997 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/module.c linux-2.6.32.46/arch/powerpc/kernel/module.c
2998 --- linux-2.6.32.46/arch/powerpc/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
2999 +++ linux-2.6.32.46/arch/powerpc/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
3000 @@ -31,11 +31,24 @@
3001
3002 LIST_HEAD(module_bug_list);
3003
3004 +#ifdef CONFIG_PAX_KERNEXEC
3005 void *module_alloc(unsigned long size)
3006 {
3007 if (size == 0)
3008 return NULL;
3009
3010 + return vmalloc(size);
3011 +}
3012 +
3013 +void *module_alloc_exec(unsigned long size)
3014 +#else
3015 +void *module_alloc(unsigned long size)
3016 +#endif
3017 +
3018 +{
3019 + if (size == 0)
3020 + return NULL;
3021 +
3022 return vmalloc_exec(size);
3023 }
3024
3025 @@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
3026 vfree(module_region);
3027 }
3028
3029 +#ifdef CONFIG_PAX_KERNEXEC
3030 +void module_free_exec(struct module *mod, void *module_region)
3031 +{
3032 + module_free(mod, module_region);
3033 +}
3034 +#endif
3035 +
3036 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
3037 const Elf_Shdr *sechdrs,
3038 const char *name)
3039 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/module_32.c linux-2.6.32.46/arch/powerpc/kernel/module_32.c
3040 --- linux-2.6.32.46/arch/powerpc/kernel/module_32.c 2011-03-27 14:31:47.000000000 -0400
3041 +++ linux-2.6.32.46/arch/powerpc/kernel/module_32.c 2011-04-17 15:56:45.000000000 -0400
3042 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
3043 me->arch.core_plt_section = i;
3044 }
3045 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3046 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3047 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3048 return -ENOEXEC;
3049 }
3050
3051 @@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
3052
3053 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3054 /* Init, or core PLT? */
3055 - if (location >= mod->module_core
3056 - && location < mod->module_core + mod->core_size)
3057 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3058 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3059 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3060 - else
3061 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3062 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3063 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3064 + else {
3065 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3066 + return ~0UL;
3067 + }
3068
3069 /* Find this entry, or if that fails, the next avail. entry */
3070 while (entry->jump[0]) {
3071 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/pci-common.c linux-2.6.32.46/arch/powerpc/kernel/pci-common.c
3072 --- linux-2.6.32.46/arch/powerpc/kernel/pci-common.c 2011-03-27 14:31:47.000000000 -0400
3073 +++ linux-2.6.32.46/arch/powerpc/kernel/pci-common.c 2011-04-17 15:56:45.000000000 -0400
3074 @@ -50,14 +50,14 @@ resource_size_t isa_mem_base;
3075 unsigned int ppc_pci_flags = 0;
3076
3077
3078 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3079 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3080
3081 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
3082 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
3083 {
3084 pci_dma_ops = dma_ops;
3085 }
3086
3087 -struct dma_map_ops *get_pci_dma_ops(void)
3088 +const struct dma_map_ops *get_pci_dma_ops(void)
3089 {
3090 return pci_dma_ops;
3091 }
3092 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/process.c linux-2.6.32.46/arch/powerpc/kernel/process.c
3093 --- linux-2.6.32.46/arch/powerpc/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
3094 +++ linux-2.6.32.46/arch/powerpc/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
3095 @@ -539,8 +539,8 @@ void show_regs(struct pt_regs * regs)
3096 * Lookup NIP late so we have the best change of getting the
3097 * above info out without failing
3098 */
3099 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3100 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3101 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3102 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3103 #endif
3104 show_stack(current, (unsigned long *) regs->gpr[1]);
3105 if (!user_mode(regs))
3106 @@ -1034,10 +1034,10 @@ void show_stack(struct task_struct *tsk,
3107 newsp = stack[0];
3108 ip = stack[STACK_FRAME_LR_SAVE];
3109 if (!firstframe || ip != lr) {
3110 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3111 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3112 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3113 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3114 - printk(" (%pS)",
3115 + printk(" (%pA)",
3116 (void *)current->ret_stack[curr_frame].ret);
3117 curr_frame--;
3118 }
3119 @@ -1057,7 +1057,7 @@ void show_stack(struct task_struct *tsk,
3120 struct pt_regs *regs = (struct pt_regs *)
3121 (sp + STACK_FRAME_OVERHEAD);
3122 lr = regs->link;
3123 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3124 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3125 regs->trap, (void *)regs->nip, (void *)lr);
3126 firstframe = 1;
3127 }
3128 @@ -1134,58 +1134,3 @@ void thread_info_cache_init(void)
3129 }
3130
3131 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3132 -
3133 -unsigned long arch_align_stack(unsigned long sp)
3134 -{
3135 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3136 - sp -= get_random_int() & ~PAGE_MASK;
3137 - return sp & ~0xf;
3138 -}
3139 -
3140 -static inline unsigned long brk_rnd(void)
3141 -{
3142 - unsigned long rnd = 0;
3143 -
3144 - /* 8MB for 32bit, 1GB for 64bit */
3145 - if (is_32bit_task())
3146 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3147 - else
3148 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3149 -
3150 - return rnd << PAGE_SHIFT;
3151 -}
3152 -
3153 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3154 -{
3155 - unsigned long base = mm->brk;
3156 - unsigned long ret;
3157 -
3158 -#ifdef CONFIG_PPC_STD_MMU_64
3159 - /*
3160 - * If we are using 1TB segments and we are allowed to randomise
3161 - * the heap, we can put it above 1TB so it is backed by a 1TB
3162 - * segment. Otherwise the heap will be in the bottom 1TB
3163 - * which always uses 256MB segments and this may result in a
3164 - * performance penalty.
3165 - */
3166 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3167 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3168 -#endif
3169 -
3170 - ret = PAGE_ALIGN(base + brk_rnd());
3171 -
3172 - if (ret < mm->brk)
3173 - return mm->brk;
3174 -
3175 - return ret;
3176 -}
3177 -
3178 -unsigned long randomize_et_dyn(unsigned long base)
3179 -{
3180 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3181 -
3182 - if (ret < base)
3183 - return base;
3184 -
3185 - return ret;
3186 -}
3187 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/ptrace.c linux-2.6.32.46/arch/powerpc/kernel/ptrace.c
3188 --- linux-2.6.32.46/arch/powerpc/kernel/ptrace.c 2011-03-27 14:31:47.000000000 -0400
3189 +++ linux-2.6.32.46/arch/powerpc/kernel/ptrace.c 2011-08-21 15:53:39.000000000 -0400
3190 @@ -86,7 +86,7 @@ static int set_user_trap(struct task_str
3191 /*
3192 * Get contents of register REGNO in task TASK.
3193 */
3194 -unsigned long ptrace_get_reg(struct task_struct *task, int regno)
3195 +unsigned long ptrace_get_reg(struct task_struct *task, unsigned int regno)
3196 {
3197 if (task->thread.regs == NULL)
3198 return -EIO;
3199 @@ -894,7 +894,7 @@ long arch_ptrace(struct task_struct *chi
3200
3201 CHECK_FULL_REGS(child->thread.regs);
3202 if (index < PT_FPR0) {
3203 - tmp = ptrace_get_reg(child, (int) index);
3204 + tmp = ptrace_get_reg(child, index);
3205 } else {
3206 flush_fp_to_thread(child);
3207 tmp = ((unsigned long *)child->thread.fpr)
3208 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/signal_32.c linux-2.6.32.46/arch/powerpc/kernel/signal_32.c
3209 --- linux-2.6.32.46/arch/powerpc/kernel/signal_32.c 2011-03-27 14:31:47.000000000 -0400
3210 +++ linux-2.6.32.46/arch/powerpc/kernel/signal_32.c 2011-04-17 15:56:45.000000000 -0400
3211 @@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
3212 /* Save user registers on the stack */
3213 frame = &rt_sf->uc.uc_mcontext;
3214 addr = frame;
3215 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3216 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3217 if (save_user_regs(regs, frame, 0, 1))
3218 goto badframe;
3219 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3220 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/signal_64.c linux-2.6.32.46/arch/powerpc/kernel/signal_64.c
3221 --- linux-2.6.32.46/arch/powerpc/kernel/signal_64.c 2011-03-27 14:31:47.000000000 -0400
3222 +++ linux-2.6.32.46/arch/powerpc/kernel/signal_64.c 2011-04-17 15:56:45.000000000 -0400
3223 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
3224 current->thread.fpscr.val = 0;
3225
3226 /* Set up to return from userspace. */
3227 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3228 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3229 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3230 } else {
3231 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3232 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/sys_ppc32.c linux-2.6.32.46/arch/powerpc/kernel/sys_ppc32.c
3233 --- linux-2.6.32.46/arch/powerpc/kernel/sys_ppc32.c 2011-03-27 14:31:47.000000000 -0400
3234 +++ linux-2.6.32.46/arch/powerpc/kernel/sys_ppc32.c 2011-04-17 15:56:45.000000000 -0400
3235 @@ -563,10 +563,10 @@ asmlinkage long compat_sys_sysctl(struct
3236 if (oldlenp) {
3237 if (!error) {
3238 if (get_user(oldlen, oldlenp) ||
3239 - put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
3240 + put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
3241 + copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
3242 error = -EFAULT;
3243 }
3244 - copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
3245 }
3246 return error;
3247 }
3248 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/traps.c linux-2.6.32.46/arch/powerpc/kernel/traps.c
3249 --- linux-2.6.32.46/arch/powerpc/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
3250 +++ linux-2.6.32.46/arch/powerpc/kernel/traps.c 2011-06-13 21:33:37.000000000 -0400
3251 @@ -99,6 +99,8 @@ static void pmac_backlight_unblank(void)
3252 static inline void pmac_backlight_unblank(void) { }
3253 #endif
3254
3255 +extern void gr_handle_kernel_exploit(void);
3256 +
3257 int die(const char *str, struct pt_regs *regs, long err)
3258 {
3259 static struct {
3260 @@ -168,6 +170,8 @@ int die(const char *str, struct pt_regs
3261 if (panic_on_oops)
3262 panic("Fatal exception");
3263
3264 + gr_handle_kernel_exploit();
3265 +
3266 oops_exit();
3267 do_exit(err);
3268
3269 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/vdso.c linux-2.6.32.46/arch/powerpc/kernel/vdso.c
3270 --- linux-2.6.32.46/arch/powerpc/kernel/vdso.c 2011-03-27 14:31:47.000000000 -0400
3271 +++ linux-2.6.32.46/arch/powerpc/kernel/vdso.c 2011-04-17 15:56:45.000000000 -0400
3272 @@ -36,6 +36,7 @@
3273 #include <asm/firmware.h>
3274 #include <asm/vdso.h>
3275 #include <asm/vdso_datapage.h>
3276 +#include <asm/mman.h>
3277
3278 #include "setup.h"
3279
3280 @@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
3281 vdso_base = VDSO32_MBASE;
3282 #endif
3283
3284 - current->mm->context.vdso_base = 0;
3285 + current->mm->context.vdso_base = ~0UL;
3286
3287 /* vDSO has a problem and was disabled, just don't "enable" it for the
3288 * process
3289 @@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
3290 vdso_base = get_unmapped_area(NULL, vdso_base,
3291 (vdso_pages << PAGE_SHIFT) +
3292 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3293 - 0, 0);
3294 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3295 if (IS_ERR_VALUE(vdso_base)) {
3296 rc = vdso_base;
3297 goto fail_mmapsem;
3298 diff -urNp linux-2.6.32.46/arch/powerpc/kernel/vio.c linux-2.6.32.46/arch/powerpc/kernel/vio.c
3299 --- linux-2.6.32.46/arch/powerpc/kernel/vio.c 2011-03-27 14:31:47.000000000 -0400
3300 +++ linux-2.6.32.46/arch/powerpc/kernel/vio.c 2011-04-17 15:56:45.000000000 -0400
3301 @@ -601,11 +601,12 @@ static void vio_dma_iommu_unmap_sg(struc
3302 vio_cmo_dealloc(viodev, alloc_size);
3303 }
3304
3305 -struct dma_map_ops vio_dma_mapping_ops = {
3306 +static const struct dma_map_ops vio_dma_mapping_ops = {
3307 .alloc_coherent = vio_dma_iommu_alloc_coherent,
3308 .free_coherent = vio_dma_iommu_free_coherent,
3309 .map_sg = vio_dma_iommu_map_sg,
3310 .unmap_sg = vio_dma_iommu_unmap_sg,
3311 + .dma_supported = dma_iommu_dma_supported,
3312 .map_page = vio_dma_iommu_map_page,
3313 .unmap_page = vio_dma_iommu_unmap_page,
3314
3315 @@ -857,7 +858,6 @@ static void vio_cmo_bus_remove(struct vi
3316
3317 static void vio_cmo_set_dma_ops(struct vio_dev *viodev)
3318 {
3319 - vio_dma_mapping_ops.dma_supported = dma_iommu_ops.dma_supported;
3320 viodev->dev.archdata.dma_ops = &vio_dma_mapping_ops;
3321 }
3322
3323 diff -urNp linux-2.6.32.46/arch/powerpc/lib/usercopy_64.c linux-2.6.32.46/arch/powerpc/lib/usercopy_64.c
3324 --- linux-2.6.32.46/arch/powerpc/lib/usercopy_64.c 2011-03-27 14:31:47.000000000 -0400
3325 +++ linux-2.6.32.46/arch/powerpc/lib/usercopy_64.c 2011-04-17 15:56:45.000000000 -0400
3326 @@ -9,22 +9,6 @@
3327 #include <linux/module.h>
3328 #include <asm/uaccess.h>
3329
3330 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3331 -{
3332 - if (likely(access_ok(VERIFY_READ, from, n)))
3333 - n = __copy_from_user(to, from, n);
3334 - else
3335 - memset(to, 0, n);
3336 - return n;
3337 -}
3338 -
3339 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3340 -{
3341 - if (likely(access_ok(VERIFY_WRITE, to, n)))
3342 - n = __copy_to_user(to, from, n);
3343 - return n;
3344 -}
3345 -
3346 unsigned long copy_in_user(void __user *to, const void __user *from,
3347 unsigned long n)
3348 {
3349 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
3350 return n;
3351 }
3352
3353 -EXPORT_SYMBOL(copy_from_user);
3354 -EXPORT_SYMBOL(copy_to_user);
3355 EXPORT_SYMBOL(copy_in_user);
3356
3357 diff -urNp linux-2.6.32.46/arch/powerpc/mm/fault.c linux-2.6.32.46/arch/powerpc/mm/fault.c
3358 --- linux-2.6.32.46/arch/powerpc/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
3359 +++ linux-2.6.32.46/arch/powerpc/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
3360 @@ -30,6 +30,10 @@
3361 #include <linux/kprobes.h>
3362 #include <linux/kdebug.h>
3363 #include <linux/perf_event.h>
3364 +#include <linux/slab.h>
3365 +#include <linux/pagemap.h>
3366 +#include <linux/compiler.h>
3367 +#include <linux/unistd.h>
3368
3369 #include <asm/firmware.h>
3370 #include <asm/page.h>
3371 @@ -40,6 +44,7 @@
3372 #include <asm/uaccess.h>
3373 #include <asm/tlbflush.h>
3374 #include <asm/siginfo.h>
3375 +#include <asm/ptrace.h>
3376
3377
3378 #ifdef CONFIG_KPROBES
3379 @@ -64,6 +69,33 @@ static inline int notify_page_fault(stru
3380 }
3381 #endif
3382
3383 +#ifdef CONFIG_PAX_PAGEEXEC
3384 +/*
3385 + * PaX: decide what to do with offenders (regs->nip = fault address)
3386 + *
3387 + * returns 1 when task should be killed
3388 + */
3389 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3390 +{
3391 + return 1;
3392 +}
3393 +
3394 +void pax_report_insns(void *pc, void *sp)
3395 +{
3396 + unsigned long i;
3397 +
3398 + printk(KERN_ERR "PAX: bytes at PC: ");
3399 + for (i = 0; i < 5; i++) {
3400 + unsigned int c;
3401 + if (get_user(c, (unsigned int __user *)pc+i))
3402 + printk(KERN_CONT "???????? ");
3403 + else
3404 + printk(KERN_CONT "%08x ", c);
3405 + }
3406 + printk("\n");
3407 +}
3408 +#endif
3409 +
3410 /*
3411 * Check whether the instruction at regs->nip is a store using
3412 * an update addressing form which will update r1.
3413 @@ -134,7 +166,7 @@ int __kprobes do_page_fault(struct pt_re
3414 * indicate errors in DSISR but can validly be set in SRR1.
3415 */
3416 if (trap == 0x400)
3417 - error_code &= 0x48200000;
3418 + error_code &= 0x58200000;
3419 else
3420 is_write = error_code & DSISR_ISSTORE;
3421 #else
3422 @@ -250,7 +282,7 @@ good_area:
3423 * "undefined". Of those that can be set, this is the only
3424 * one which seems bad.
3425 */
3426 - if (error_code & 0x10000000)
3427 + if (error_code & DSISR_GUARDED)
3428 /* Guarded storage error. */
3429 goto bad_area;
3430 #endif /* CONFIG_8xx */
3431 @@ -265,7 +297,7 @@ good_area:
3432 * processors use the same I/D cache coherency mechanism
3433 * as embedded.
3434 */
3435 - if (error_code & DSISR_PROTFAULT)
3436 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
3437 goto bad_area;
3438 #endif /* CONFIG_PPC_STD_MMU */
3439
3440 @@ -335,6 +367,23 @@ bad_area:
3441 bad_area_nosemaphore:
3442 /* User mode accesses cause a SIGSEGV */
3443 if (user_mode(regs)) {
3444 +
3445 +#ifdef CONFIG_PAX_PAGEEXEC
3446 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3447 +#ifdef CONFIG_PPC_STD_MMU
3448 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
3449 +#else
3450 + if (is_exec && regs->nip == address) {
3451 +#endif
3452 + switch (pax_handle_fetch_fault(regs)) {
3453 + }
3454 +
3455 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
3456 + do_group_exit(SIGKILL);
3457 + }
3458 + }
3459 +#endif
3460 +
3461 _exception(SIGSEGV, regs, code, address);
3462 return 0;
3463 }
3464 diff -urNp linux-2.6.32.46/arch/powerpc/mm/mem.c linux-2.6.32.46/arch/powerpc/mm/mem.c
3465 --- linux-2.6.32.46/arch/powerpc/mm/mem.c 2011-03-27 14:31:47.000000000 -0400
3466 +++ linux-2.6.32.46/arch/powerpc/mm/mem.c 2011-08-21 15:50:39.000000000 -0400
3467 @@ -250,7 +250,7 @@ static int __init mark_nonram_nosave(voi
3468 {
3469 unsigned long lmb_next_region_start_pfn,
3470 lmb_region_max_pfn;
3471 - int i;
3472 + unsigned int i;
3473
3474 for (i = 0; i < lmb.memory.cnt - 1; i++) {
3475 lmb_region_max_pfn =
3476 diff -urNp linux-2.6.32.46/arch/powerpc/mm/mmap_64.c linux-2.6.32.46/arch/powerpc/mm/mmap_64.c
3477 --- linux-2.6.32.46/arch/powerpc/mm/mmap_64.c 2011-03-27 14:31:47.000000000 -0400
3478 +++ linux-2.6.32.46/arch/powerpc/mm/mmap_64.c 2011-04-17 15:56:45.000000000 -0400
3479 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
3480 */
3481 if (mmap_is_legacy()) {
3482 mm->mmap_base = TASK_UNMAPPED_BASE;
3483 +
3484 +#ifdef CONFIG_PAX_RANDMMAP
3485 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3486 + mm->mmap_base += mm->delta_mmap;
3487 +#endif
3488 +
3489 mm->get_unmapped_area = arch_get_unmapped_area;
3490 mm->unmap_area = arch_unmap_area;
3491 } else {
3492 mm->mmap_base = mmap_base();
3493 +
3494 +#ifdef CONFIG_PAX_RANDMMAP
3495 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3496 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3497 +#endif
3498 +
3499 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3500 mm->unmap_area = arch_unmap_area_topdown;
3501 }
3502 diff -urNp linux-2.6.32.46/arch/powerpc/mm/slice.c linux-2.6.32.46/arch/powerpc/mm/slice.c
3503 --- linux-2.6.32.46/arch/powerpc/mm/slice.c 2011-03-27 14:31:47.000000000 -0400
3504 +++ linux-2.6.32.46/arch/powerpc/mm/slice.c 2011-04-17 15:56:45.000000000 -0400
3505 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
3506 if ((mm->task_size - len) < addr)
3507 return 0;
3508 vma = find_vma(mm, addr);
3509 - return (!vma || (addr + len) <= vma->vm_start);
3510 + return check_heap_stack_gap(vma, addr, len);
3511 }
3512
3513 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
3514 @@ -256,7 +256,7 @@ full_search:
3515 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
3516 continue;
3517 }
3518 - if (!vma || addr + len <= vma->vm_start) {
3519 + if (check_heap_stack_gap(vma, addr, len)) {
3520 /*
3521 * Remember the place where we stopped the search:
3522 */
3523 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_top
3524 }
3525 }
3526
3527 - addr = mm->mmap_base;
3528 - while (addr > len) {
3529 + if (mm->mmap_base < len)
3530 + addr = -ENOMEM;
3531 + else
3532 + addr = mm->mmap_base - len;
3533 +
3534 + while (!IS_ERR_VALUE(addr)) {
3535 /* Go down by chunk size */
3536 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
3537 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
3538
3539 /* Check for hit with different page size */
3540 mask = slice_range_to_mask(addr, len);
3541 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_top
3542 * return with success:
3543 */
3544 vma = find_vma(mm, addr);
3545 - if (!vma || (addr + len) <= vma->vm_start) {
3546 + if (check_heap_stack_gap(vma, addr, len)) {
3547 /* remember the address as a hint for next time */
3548 if (use_cache)
3549 mm->free_area_cache = addr;
3550 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_top
3551 mm->cached_hole_size = vma->vm_start - addr;
3552
3553 /* try just below the current vma->vm_start */
3554 - addr = vma->vm_start;
3555 + addr = skip_heap_stack_gap(vma, len);
3556 }
3557
3558 /*
3559 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(un
3560 if (fixed && addr > (mm->task_size - len))
3561 return -EINVAL;
3562
3563 +#ifdef CONFIG_PAX_RANDMMAP
3564 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3565 + addr = 0;
3566 +#endif
3567 +
3568 /* If hint, make sure it matches our alignment restrictions */
3569 if (!fixed && addr) {
3570 addr = _ALIGN_UP(addr, 1ul << pshift);
3571 diff -urNp linux-2.6.32.46/arch/powerpc/platforms/52xx/lite5200_pm.c linux-2.6.32.46/arch/powerpc/platforms/52xx/lite5200_pm.c
3572 --- linux-2.6.32.46/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-03-27 14:31:47.000000000 -0400
3573 +++ linux-2.6.32.46/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-04-17 15:56:45.000000000 -0400
3574 @@ -235,7 +235,7 @@ static void lite5200_pm_end(void)
3575 lite5200_pm_target_state = PM_SUSPEND_ON;
3576 }
3577
3578 -static struct platform_suspend_ops lite5200_pm_ops = {
3579 +static const struct platform_suspend_ops lite5200_pm_ops = {
3580 .valid = lite5200_pm_valid,
3581 .begin = lite5200_pm_begin,
3582 .prepare = lite5200_pm_prepare,
3583 diff -urNp linux-2.6.32.46/arch/powerpc/platforms/52xx/mpc52xx_pm.c linux-2.6.32.46/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3584 --- linux-2.6.32.46/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-03-27 14:31:47.000000000 -0400
3585 +++ linux-2.6.32.46/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-04-17 15:56:45.000000000 -0400
3586 @@ -180,7 +180,7 @@ void mpc52xx_pm_finish(void)
3587 iounmap(mbar);
3588 }
3589
3590 -static struct platform_suspend_ops mpc52xx_pm_ops = {
3591 +static const struct platform_suspend_ops mpc52xx_pm_ops = {
3592 .valid = mpc52xx_pm_valid,
3593 .prepare = mpc52xx_pm_prepare,
3594 .enter = mpc52xx_pm_enter,
3595 diff -urNp linux-2.6.32.46/arch/powerpc/platforms/83xx/suspend.c linux-2.6.32.46/arch/powerpc/platforms/83xx/suspend.c
3596 --- linux-2.6.32.46/arch/powerpc/platforms/83xx/suspend.c 2011-03-27 14:31:47.000000000 -0400
3597 +++ linux-2.6.32.46/arch/powerpc/platforms/83xx/suspend.c 2011-04-17 15:56:45.000000000 -0400
3598 @@ -273,7 +273,7 @@ static int mpc83xx_is_pci_agent(void)
3599 return ret;
3600 }
3601
3602 -static struct platform_suspend_ops mpc83xx_suspend_ops = {
3603 +static const struct platform_suspend_ops mpc83xx_suspend_ops = {
3604 .valid = mpc83xx_suspend_valid,
3605 .begin = mpc83xx_suspend_begin,
3606 .enter = mpc83xx_suspend_enter,
3607 diff -urNp linux-2.6.32.46/arch/powerpc/platforms/cell/iommu.c linux-2.6.32.46/arch/powerpc/platforms/cell/iommu.c
3608 --- linux-2.6.32.46/arch/powerpc/platforms/cell/iommu.c 2011-03-27 14:31:47.000000000 -0400
3609 +++ linux-2.6.32.46/arch/powerpc/platforms/cell/iommu.c 2011-04-17 15:56:45.000000000 -0400
3610 @@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struc
3611
3612 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
3613
3614 -struct dma_map_ops dma_iommu_fixed_ops = {
3615 +const struct dma_map_ops dma_iommu_fixed_ops = {
3616 .alloc_coherent = dma_fixed_alloc_coherent,
3617 .free_coherent = dma_fixed_free_coherent,
3618 .map_sg = dma_fixed_map_sg,
3619 diff -urNp linux-2.6.32.46/arch/powerpc/platforms/ps3/system-bus.c linux-2.6.32.46/arch/powerpc/platforms/ps3/system-bus.c
3620 --- linux-2.6.32.46/arch/powerpc/platforms/ps3/system-bus.c 2011-03-27 14:31:47.000000000 -0400
3621 +++ linux-2.6.32.46/arch/powerpc/platforms/ps3/system-bus.c 2011-04-17 15:56:45.000000000 -0400
3622 @@ -694,7 +694,7 @@ static int ps3_dma_supported(struct devi
3623 return mask >= DMA_BIT_MASK(32);
3624 }
3625
3626 -static struct dma_map_ops ps3_sb_dma_ops = {
3627 +static const struct dma_map_ops ps3_sb_dma_ops = {
3628 .alloc_coherent = ps3_alloc_coherent,
3629 .free_coherent = ps3_free_coherent,
3630 .map_sg = ps3_sb_map_sg,
3631 @@ -704,7 +704,7 @@ static struct dma_map_ops ps3_sb_dma_ops
3632 .unmap_page = ps3_unmap_page,
3633 };
3634
3635 -static struct dma_map_ops ps3_ioc0_dma_ops = {
3636 +static const struct dma_map_ops ps3_ioc0_dma_ops = {
3637 .alloc_coherent = ps3_alloc_coherent,
3638 .free_coherent = ps3_free_coherent,
3639 .map_sg = ps3_ioc0_map_sg,
3640 diff -urNp linux-2.6.32.46/arch/powerpc/platforms/pseries/Kconfig linux-2.6.32.46/arch/powerpc/platforms/pseries/Kconfig
3641 --- linux-2.6.32.46/arch/powerpc/platforms/pseries/Kconfig 2011-03-27 14:31:47.000000000 -0400
3642 +++ linux-2.6.32.46/arch/powerpc/platforms/pseries/Kconfig 2011-04-17 15:56:45.000000000 -0400
3643 @@ -2,6 +2,8 @@ config PPC_PSERIES
3644 depends on PPC64 && PPC_BOOK3S
3645 bool "IBM pSeries & new (POWER5-based) iSeries"
3646 select MPIC
3647 + select PCI_MSI
3648 + select XICS
3649 select PPC_I8259
3650 select PPC_RTAS
3651 select RTAS_ERROR_LOGGING
3652 diff -urNp linux-2.6.32.46/arch/s390/Kconfig linux-2.6.32.46/arch/s390/Kconfig
3653 --- linux-2.6.32.46/arch/s390/Kconfig 2011-03-27 14:31:47.000000000 -0400
3654 +++ linux-2.6.32.46/arch/s390/Kconfig 2011-04-17 15:56:45.000000000 -0400
3655 @@ -194,28 +194,26 @@ config AUDIT_ARCH
3656
3657 config S390_SWITCH_AMODE
3658 bool "Switch kernel/user addressing modes"
3659 + default y
3660 help
3661 This option allows to switch the addressing modes of kernel and user
3662 - space. The kernel parameter switch_amode=on will enable this feature,
3663 - default is disabled. Enabling this (via kernel parameter) on machines
3664 - earlier than IBM System z9-109 EC/BC will reduce system performance.
3665 + space. Enabling this on machines earlier than IBM System z9-109 EC/BC
3666 + will reduce system performance.
3667
3668 Note that this option will also be selected by selecting the execute
3669 - protection option below. Enabling the execute protection via the
3670 - noexec kernel parameter will also switch the addressing modes,
3671 - independent of the switch_amode kernel parameter.
3672 + protection option below. Enabling the execute protection will also
3673 + switch the addressing modes, independent of this option.
3674
3675
3676 config S390_EXEC_PROTECT
3677 bool "Data execute protection"
3678 + default y
3679 select S390_SWITCH_AMODE
3680 help
3681 This option allows to enable a buffer overflow protection for user
3682 space programs and it also selects the addressing mode option above.
3683 - The kernel parameter noexec=on will enable this feature and also
3684 - switch the addressing modes, default is disabled. Enabling this (via
3685 - kernel parameter) on machines earlier than IBM System z9-109 EC/BC
3686 - will reduce system performance.
3687 + Enabling this on machines earlier than IBM System z9-109 EC/BC will
3688 + reduce system performance.
3689
3690 comment "Code generation options"
3691
3692 diff -urNp linux-2.6.32.46/arch/s390/include/asm/elf.h linux-2.6.32.46/arch/s390/include/asm/elf.h
3693 --- linux-2.6.32.46/arch/s390/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
3694 +++ linux-2.6.32.46/arch/s390/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
3695 @@ -164,6 +164,13 @@ extern unsigned int vdso_enabled;
3696 that it will "exec", and that there is sufficient room for the brk. */
3697 #define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
3698
3699 +#ifdef CONFIG_PAX_ASLR
3700 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3701 +
3702 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3703 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3704 +#endif
3705 +
3706 /* This yields a mask that user programs can use to figure out what
3707 instruction set this CPU supports. */
3708
3709 diff -urNp linux-2.6.32.46/arch/s390/include/asm/setup.h linux-2.6.32.46/arch/s390/include/asm/setup.h
3710 --- linux-2.6.32.46/arch/s390/include/asm/setup.h 2011-03-27 14:31:47.000000000 -0400
3711 +++ linux-2.6.32.46/arch/s390/include/asm/setup.h 2011-04-17 15:56:45.000000000 -0400
3712 @@ -50,13 +50,13 @@ extern unsigned long memory_end;
3713 void detect_memory_layout(struct mem_chunk chunk[]);
3714
3715 #ifdef CONFIG_S390_SWITCH_AMODE
3716 -extern unsigned int switch_amode;
3717 +#define switch_amode (1)
3718 #else
3719 #define switch_amode (0)
3720 #endif
3721
3722 #ifdef CONFIG_S390_EXEC_PROTECT
3723 -extern unsigned int s390_noexec;
3724 +#define s390_noexec (1)
3725 #else
3726 #define s390_noexec (0)
3727 #endif
3728 diff -urNp linux-2.6.32.46/arch/s390/include/asm/uaccess.h linux-2.6.32.46/arch/s390/include/asm/uaccess.h
3729 --- linux-2.6.32.46/arch/s390/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
3730 +++ linux-2.6.32.46/arch/s390/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
3731 @@ -232,6 +232,10 @@ static inline unsigned long __must_check
3732 copy_to_user(void __user *to, const void *from, unsigned long n)
3733 {
3734 might_fault();
3735 +
3736 + if ((long)n < 0)
3737 + return n;
3738 +
3739 if (access_ok(VERIFY_WRITE, to, n))
3740 n = __copy_to_user(to, from, n);
3741 return n;
3742 @@ -257,6 +261,9 @@ copy_to_user(void __user *to, const void
3743 static inline unsigned long __must_check
3744 __copy_from_user(void *to, const void __user *from, unsigned long n)
3745 {
3746 + if ((long)n < 0)
3747 + return n;
3748 +
3749 if (__builtin_constant_p(n) && (n <= 256))
3750 return uaccess.copy_from_user_small(n, from, to);
3751 else
3752 @@ -283,6 +290,10 @@ static inline unsigned long __must_check
3753 copy_from_user(void *to, const void __user *from, unsigned long n)
3754 {
3755 might_fault();
3756 +
3757 + if ((long)n < 0)
3758 + return n;
3759 +
3760 if (access_ok(VERIFY_READ, from, n))
3761 n = __copy_from_user(to, from, n);
3762 else
3763 diff -urNp linux-2.6.32.46/arch/s390/kernel/module.c linux-2.6.32.46/arch/s390/kernel/module.c
3764 --- linux-2.6.32.46/arch/s390/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
3765 +++ linux-2.6.32.46/arch/s390/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
3766 @@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
3767
3768 /* Increase core size by size of got & plt and set start
3769 offsets for got and plt. */
3770 - me->core_size = ALIGN(me->core_size, 4);
3771 - me->arch.got_offset = me->core_size;
3772 - me->core_size += me->arch.got_size;
3773 - me->arch.plt_offset = me->core_size;
3774 - me->core_size += me->arch.plt_size;
3775 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
3776 + me->arch.got_offset = me->core_size_rw;
3777 + me->core_size_rw += me->arch.got_size;
3778 + me->arch.plt_offset = me->core_size_rx;
3779 + me->core_size_rx += me->arch.plt_size;
3780 return 0;
3781 }
3782
3783 @@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3784 if (info->got_initialized == 0) {
3785 Elf_Addr *gotent;
3786
3787 - gotent = me->module_core + me->arch.got_offset +
3788 + gotent = me->module_core_rw + me->arch.got_offset +
3789 info->got_offset;
3790 *gotent = val;
3791 info->got_initialized = 1;
3792 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3793 else if (r_type == R_390_GOTENT ||
3794 r_type == R_390_GOTPLTENT)
3795 *(unsigned int *) loc =
3796 - (val + (Elf_Addr) me->module_core - loc) >> 1;
3797 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3798 else if (r_type == R_390_GOT64 ||
3799 r_type == R_390_GOTPLT64)
3800 *(unsigned long *) loc = val;
3801 @@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3802 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3803 if (info->plt_initialized == 0) {
3804 unsigned int *ip;
3805 - ip = me->module_core + me->arch.plt_offset +
3806 + ip = me->module_core_rx + me->arch.plt_offset +
3807 info->plt_offset;
3808 #ifndef CONFIG_64BIT
3809 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3810 @@ -319,7 +319,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3811 val - loc + 0xffffUL < 0x1ffffeUL) ||
3812 (r_type == R_390_PLT32DBL &&
3813 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3814 - val = (Elf_Addr) me->module_core +
3815 + val = (Elf_Addr) me->module_core_rx +
3816 me->arch.plt_offset +
3817 info->plt_offset;
3818 val += rela->r_addend - loc;
3819 @@ -341,7 +341,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3820 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3821 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3822 val = val + rela->r_addend -
3823 - ((Elf_Addr) me->module_core + me->arch.got_offset);
3824 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3825 if (r_type == R_390_GOTOFF16)
3826 *(unsigned short *) loc = val;
3827 else if (r_type == R_390_GOTOFF32)
3828 @@ -351,7 +351,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3829 break;
3830 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3831 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3832 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
3833 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3834 rela->r_addend - loc;
3835 if (r_type == R_390_GOTPC)
3836 *(unsigned int *) loc = val;
3837 diff -urNp linux-2.6.32.46/arch/s390/kernel/setup.c linux-2.6.32.46/arch/s390/kernel/setup.c
3838 --- linux-2.6.32.46/arch/s390/kernel/setup.c 2011-03-27 14:31:47.000000000 -0400
3839 +++ linux-2.6.32.46/arch/s390/kernel/setup.c 2011-04-17 15:56:45.000000000 -0400
3840 @@ -306,9 +306,6 @@ static int __init early_parse_mem(char *
3841 early_param("mem", early_parse_mem);
3842
3843 #ifdef CONFIG_S390_SWITCH_AMODE
3844 -unsigned int switch_amode = 0;
3845 -EXPORT_SYMBOL_GPL(switch_amode);
3846 -
3847 static int set_amode_and_uaccess(unsigned long user_amode,
3848 unsigned long user32_amode)
3849 {
3850 @@ -334,17 +331,6 @@ static int set_amode_and_uaccess(unsigne
3851 return 0;
3852 }
3853 }
3854 -
3855 -/*
3856 - * Switch kernel/user addressing modes?
3857 - */
3858 -static int __init early_parse_switch_amode(char *p)
3859 -{
3860 - switch_amode = 1;
3861 - return 0;
3862 -}
3863 -early_param("switch_amode", early_parse_switch_amode);
3864 -
3865 #else /* CONFIG_S390_SWITCH_AMODE */
3866 static inline int set_amode_and_uaccess(unsigned long user_amode,
3867 unsigned long user32_amode)
3868 @@ -353,24 +339,6 @@ static inline int set_amode_and_uaccess(
3869 }
3870 #endif /* CONFIG_S390_SWITCH_AMODE */
3871
3872 -#ifdef CONFIG_S390_EXEC_PROTECT
3873 -unsigned int s390_noexec = 0;
3874 -EXPORT_SYMBOL_GPL(s390_noexec);
3875 -
3876 -/*
3877 - * Enable execute protection?
3878 - */
3879 -static int __init early_parse_noexec(char *p)
3880 -{
3881 - if (!strncmp(p, "off", 3))
3882 - return 0;
3883 - switch_amode = 1;
3884 - s390_noexec = 1;
3885 - return 0;
3886 -}
3887 -early_param("noexec", early_parse_noexec);
3888 -#endif /* CONFIG_S390_EXEC_PROTECT */
3889 -
3890 static void setup_addressing_mode(void)
3891 {
3892 if (s390_noexec) {
3893 diff -urNp linux-2.6.32.46/arch/s390/mm/mmap.c linux-2.6.32.46/arch/s390/mm/mmap.c
3894 --- linux-2.6.32.46/arch/s390/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
3895 +++ linux-2.6.32.46/arch/s390/mm/mmap.c 2011-04-17 15:56:45.000000000 -0400
3896 @@ -78,10 +78,22 @@ void arch_pick_mmap_layout(struct mm_str
3897 */
3898 if (mmap_is_legacy()) {
3899 mm->mmap_base = TASK_UNMAPPED_BASE;
3900 +
3901 +#ifdef CONFIG_PAX_RANDMMAP
3902 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3903 + mm->mmap_base += mm->delta_mmap;
3904 +#endif
3905 +
3906 mm->get_unmapped_area = arch_get_unmapped_area;
3907 mm->unmap_area = arch_unmap_area;
3908 } else {
3909 mm->mmap_base = mmap_base();
3910 +
3911 +#ifdef CONFIG_PAX_RANDMMAP
3912 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3913 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3914 +#endif
3915 +
3916 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3917 mm->unmap_area = arch_unmap_area_topdown;
3918 }
3919 @@ -153,10 +165,22 @@ void arch_pick_mmap_layout(struct mm_str
3920 */
3921 if (mmap_is_legacy()) {
3922 mm->mmap_base = TASK_UNMAPPED_BASE;
3923 +
3924 +#ifdef CONFIG_PAX_RANDMMAP
3925 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3926 + mm->mmap_base += mm->delta_mmap;
3927 +#endif
3928 +
3929 mm->get_unmapped_area = s390_get_unmapped_area;
3930 mm->unmap_area = arch_unmap_area;
3931 } else {
3932 mm->mmap_base = mmap_base();
3933 +
3934 +#ifdef CONFIG_PAX_RANDMMAP
3935 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3936 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3937 +#endif
3938 +
3939 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3940 mm->unmap_area = arch_unmap_area_topdown;
3941 }
3942 diff -urNp linux-2.6.32.46/arch/score/include/asm/system.h linux-2.6.32.46/arch/score/include/asm/system.h
3943 --- linux-2.6.32.46/arch/score/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
3944 +++ linux-2.6.32.46/arch/score/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
3945 @@ -17,7 +17,7 @@ do { \
3946 #define finish_arch_switch(prev) do {} while (0)
3947
3948 typedef void (*vi_handler_t)(void);
3949 -extern unsigned long arch_align_stack(unsigned long sp);
3950 +#define arch_align_stack(x) (x)
3951
3952 #define mb() barrier()
3953 #define rmb() barrier()
3954 diff -urNp linux-2.6.32.46/arch/score/kernel/process.c linux-2.6.32.46/arch/score/kernel/process.c
3955 --- linux-2.6.32.46/arch/score/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
3956 +++ linux-2.6.32.46/arch/score/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
3957 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
3958
3959 return task_pt_regs(task)->cp0_epc;
3960 }
3961 -
3962 -unsigned long arch_align_stack(unsigned long sp)
3963 -{
3964 - return sp;
3965 -}
3966 diff -urNp linux-2.6.32.46/arch/sh/boards/mach-hp6xx/pm.c linux-2.6.32.46/arch/sh/boards/mach-hp6xx/pm.c
3967 --- linux-2.6.32.46/arch/sh/boards/mach-hp6xx/pm.c 2011-03-27 14:31:47.000000000 -0400
3968 +++ linux-2.6.32.46/arch/sh/boards/mach-hp6xx/pm.c 2011-04-17 15:56:45.000000000 -0400
3969 @@ -143,7 +143,7 @@ static int hp6x0_pm_enter(suspend_state_
3970 return 0;
3971 }
3972
3973 -static struct platform_suspend_ops hp6x0_pm_ops = {
3974 +static const struct platform_suspend_ops hp6x0_pm_ops = {
3975 .enter = hp6x0_pm_enter,
3976 .valid = suspend_valid_only_mem,
3977 };
3978 diff -urNp linux-2.6.32.46/arch/sh/kernel/cpu/sh4/sq.c linux-2.6.32.46/arch/sh/kernel/cpu/sh4/sq.c
3979 --- linux-2.6.32.46/arch/sh/kernel/cpu/sh4/sq.c 2011-03-27 14:31:47.000000000 -0400
3980 +++ linux-2.6.32.46/arch/sh/kernel/cpu/sh4/sq.c 2011-04-17 15:56:46.000000000 -0400
3981 @@ -327,7 +327,7 @@ static struct attribute *sq_sysfs_attrs[
3982 NULL,
3983 };
3984
3985 -static struct sysfs_ops sq_sysfs_ops = {
3986 +static const struct sysfs_ops sq_sysfs_ops = {
3987 .show = sq_sysfs_show,
3988 .store = sq_sysfs_store,
3989 };
3990 diff -urNp linux-2.6.32.46/arch/sh/kernel/cpu/shmobile/pm.c linux-2.6.32.46/arch/sh/kernel/cpu/shmobile/pm.c
3991 --- linux-2.6.32.46/arch/sh/kernel/cpu/shmobile/pm.c 2011-03-27 14:31:47.000000000 -0400
3992 +++ linux-2.6.32.46/arch/sh/kernel/cpu/shmobile/pm.c 2011-04-17 15:56:46.000000000 -0400
3993 @@ -58,7 +58,7 @@ static int sh_pm_enter(suspend_state_t s
3994 return 0;
3995 }
3996
3997 -static struct platform_suspend_ops sh_pm_ops = {
3998 +static const struct platform_suspend_ops sh_pm_ops = {
3999 .enter = sh_pm_enter,
4000 .valid = suspend_valid_only_mem,
4001 };
4002 diff -urNp linux-2.6.32.46/arch/sh/kernel/kgdb.c linux-2.6.32.46/arch/sh/kernel/kgdb.c
4003 --- linux-2.6.32.46/arch/sh/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
4004 +++ linux-2.6.32.46/arch/sh/kernel/kgdb.c 2011-04-17 15:56:46.000000000 -0400
4005 @@ -271,7 +271,7 @@ void kgdb_arch_exit(void)
4006 {
4007 }
4008
4009 -struct kgdb_arch arch_kgdb_ops = {
4010 +const struct kgdb_arch arch_kgdb_ops = {
4011 /* Breakpoint instruction: trapa #0x3c */
4012 #ifdef CONFIG_CPU_LITTLE_ENDIAN
4013 .gdb_bpt_instr = { 0x3c, 0xc3 },
4014 diff -urNp linux-2.6.32.46/arch/sh/mm/mmap.c linux-2.6.32.46/arch/sh/mm/mmap.c
4015 --- linux-2.6.32.46/arch/sh/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
4016 +++ linux-2.6.32.46/arch/sh/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
4017 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
4018 addr = PAGE_ALIGN(addr);
4019
4020 vma = find_vma(mm, addr);
4021 - if (TASK_SIZE - len >= addr &&
4022 - (!vma || addr + len <= vma->vm_start))
4023 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4024 return addr;
4025 }
4026
4027 @@ -106,7 +105,7 @@ full_search:
4028 }
4029 return -ENOMEM;
4030 }
4031 - if (likely(!vma || addr + len <= vma->vm_start)) {
4032 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4033 /*
4034 * Remember the place where we stopped the search:
4035 */
4036 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
4037 addr = PAGE_ALIGN(addr);
4038
4039 vma = find_vma(mm, addr);
4040 - if (TASK_SIZE - len >= addr &&
4041 - (!vma || addr + len <= vma->vm_start))
4042 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4043 return addr;
4044 }
4045
4046 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
4047 /* make sure it can fit in the remaining address space */
4048 if (likely(addr > len)) {
4049 vma = find_vma(mm, addr-len);
4050 - if (!vma || addr <= vma->vm_start) {
4051 + if (check_heap_stack_gap(vma, addr - len, len)) {
4052 /* remember the address as a hint for next time */
4053 return (mm->free_area_cache = addr-len);
4054 }
4055 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct fi
4056 if (unlikely(mm->mmap_base < len))
4057 goto bottomup;
4058
4059 - addr = mm->mmap_base-len;
4060 - if (do_colour_align)
4061 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4062 + addr = mm->mmap_base - len;
4063
4064 do {
4065 + if (do_colour_align)
4066 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4067 /*
4068 * Lookup failure means no vma is above this address,
4069 * else if new region fits below vma->vm_start,
4070 * return with success:
4071 */
4072 vma = find_vma(mm, addr);
4073 - if (likely(!vma || addr+len <= vma->vm_start)) {
4074 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4075 /* remember the address as a hint for next time */
4076 return (mm->free_area_cache = addr);
4077 }
4078 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct fi
4079 mm->cached_hole_size = vma->vm_start - addr;
4080
4081 /* try just below the current vma->vm_start */
4082 - addr = vma->vm_start-len;
4083 - if (do_colour_align)
4084 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4085 - } while (likely(len < vma->vm_start));
4086 + addr = skip_heap_stack_gap(vma, len);
4087 + } while (!IS_ERR_VALUE(addr));
4088
4089 bottomup:
4090 /*
4091 diff -urNp linux-2.6.32.46/arch/sparc/Makefile linux-2.6.32.46/arch/sparc/Makefile
4092 --- linux-2.6.32.46/arch/sparc/Makefile 2011-03-27 14:31:47.000000000 -0400
4093 +++ linux-2.6.32.46/arch/sparc/Makefile 2011-04-17 15:56:46.000000000 -0400
4094 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
4095 # Export what is needed by arch/sparc/boot/Makefile
4096 export VMLINUX_INIT VMLINUX_MAIN
4097 VMLINUX_INIT := $(head-y) $(init-y)
4098 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4099 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4100 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4101 VMLINUX_MAIN += $(drivers-y) $(net-y)
4102
4103 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/atomic_64.h linux-2.6.32.46/arch/sparc/include/asm/atomic_64.h
4104 --- linux-2.6.32.46/arch/sparc/include/asm/atomic_64.h 2011-03-27 14:31:47.000000000 -0400
4105 +++ linux-2.6.32.46/arch/sparc/include/asm/atomic_64.h 2011-08-18 23:11:34.000000000 -0400
4106 @@ -14,18 +14,40 @@
4107 #define ATOMIC64_INIT(i) { (i) }
4108
4109 #define atomic_read(v) ((v)->counter)
4110 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4111 +{
4112 + return v->counter;
4113 +}
4114 #define atomic64_read(v) ((v)->counter)
4115 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4116 +{
4117 + return v->counter;
4118 +}
4119
4120 #define atomic_set(v, i) (((v)->counter) = i)
4121 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4122 +{
4123 + v->counter = i;
4124 +}
4125 #define atomic64_set(v, i) (((v)->counter) = i)
4126 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4127 +{
4128 + v->counter = i;
4129 +}
4130
4131 extern void atomic_add(int, atomic_t *);
4132 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4133 extern void atomic64_add(long, atomic64_t *);
4134 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4135 extern void atomic_sub(int, atomic_t *);
4136 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4137 extern void atomic64_sub(long, atomic64_t *);
4138 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4139
4140 extern int atomic_add_ret(int, atomic_t *);
4141 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4142 extern long atomic64_add_ret(long, atomic64_t *);
4143 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4144 extern int atomic_sub_ret(int, atomic_t *);
4145 extern long atomic64_sub_ret(long, atomic64_t *);
4146
4147 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomi
4148 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4149
4150 #define atomic_inc_return(v) atomic_add_ret(1, v)
4151 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4152 +{
4153 + return atomic_add_ret_unchecked(1, v);
4154 +}
4155 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4156 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4157 +{
4158 + return atomic64_add_ret_unchecked(1, v);
4159 +}
4160
4161 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4162 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4163
4164 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4165 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4166 +{
4167 + return atomic_add_ret_unchecked(i, v);
4168 +}
4169 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4170 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4171 +{
4172 + return atomic64_add_ret_unchecked(i, v);
4173 +}
4174
4175 /*
4176 * atomic_inc_and_test - increment and test
4177 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomi
4178 * other cases.
4179 */
4180 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4181 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4182 +{
4183 + return atomic_inc_return_unchecked(v) == 0;
4184 +}
4185 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4186
4187 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4188 @@ -59,30 +101,65 @@ extern long atomic64_sub_ret(long, atomi
4189 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4190
4191 #define atomic_inc(v) atomic_add(1, v)
4192 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4193 +{
4194 + atomic_add_unchecked(1, v);
4195 +}
4196 #define atomic64_inc(v) atomic64_add(1, v)
4197 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4198 +{
4199 + atomic64_add_unchecked(1, v);
4200 +}
4201
4202 #define atomic_dec(v) atomic_sub(1, v)
4203 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4204 +{
4205 + atomic_sub_unchecked(1, v);
4206 +}
4207 #define atomic64_dec(v) atomic64_sub(1, v)
4208 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4209 +{
4210 + atomic64_sub_unchecked(1, v);
4211 +}
4212
4213 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4214 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4215
4216 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4217 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4218 +{
4219 + return cmpxchg(&v->counter, old, new);
4220 +}
4221 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4222 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4223 +{
4224 + return xchg(&v->counter, new);
4225 +}
4226
4227 static inline int atomic_add_unless(atomic_t *v, int a, int u)
4228 {
4229 - int c, old;
4230 + int c, old, new;
4231 c = atomic_read(v);
4232 for (;;) {
4233 - if (unlikely(c == (u)))
4234 + if (unlikely(c == u))
4235 break;
4236 - old = atomic_cmpxchg((v), c, c + (a));
4237 +
4238 + asm volatile("addcc %2, %0, %0\n"
4239 +
4240 +#ifdef CONFIG_PAX_REFCOUNT
4241 + "tvs %%icc, 6\n"
4242 +#endif
4243 +
4244 + : "=r" (new)
4245 + : "0" (c), "ir" (a)
4246 + : "cc");
4247 +
4248 + old = atomic_cmpxchg(v, c, new);
4249 if (likely(old == c))
4250 break;
4251 c = old;
4252 }
4253 - return c != (u);
4254 + return c != u;
4255 }
4256
4257 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
4258 @@ -90,20 +167,35 @@ static inline int atomic_add_unless(atom
4259 #define atomic64_cmpxchg(v, o, n) \
4260 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4261 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4262 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4263 +{
4264 + return xchg(&v->counter, new);
4265 +}
4266
4267 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4268 {
4269 - long c, old;
4270 + long c, old, new;
4271 c = atomic64_read(v);
4272 for (;;) {
4273 - if (unlikely(c == (u)))
4274 + if (unlikely(c == u))
4275 break;
4276 - old = atomic64_cmpxchg((v), c, c + (a));
4277 +
4278 + asm volatile("addcc %2, %0, %0\n"
4279 +
4280 +#ifdef CONFIG_PAX_REFCOUNT
4281 + "tvs %%xcc, 6\n"
4282 +#endif
4283 +
4284 + : "=r" (new)
4285 + : "0" (c), "ir" (a)
4286 + : "cc");
4287 +
4288 + old = atomic64_cmpxchg(v, c, new);
4289 if (likely(old == c))
4290 break;
4291 c = old;
4292 }
4293 - return c != (u);
4294 + return c != u;
4295 }
4296
4297 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4298 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/cache.h linux-2.6.32.46/arch/sparc/include/asm/cache.h
4299 --- linux-2.6.32.46/arch/sparc/include/asm/cache.h 2011-03-27 14:31:47.000000000 -0400
4300 +++ linux-2.6.32.46/arch/sparc/include/asm/cache.h 2011-07-06 19:53:33.000000000 -0400
4301 @@ -8,7 +8,7 @@
4302 #define _SPARC_CACHE_H
4303
4304 #define L1_CACHE_SHIFT 5
4305 -#define L1_CACHE_BYTES 32
4306 +#define L1_CACHE_BYTES 32UL
4307 #define L1_CACHE_ALIGN(x) ((((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1)))
4308
4309 #ifdef CONFIG_SPARC32
4310 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/dma-mapping.h linux-2.6.32.46/arch/sparc/include/asm/dma-mapping.h
4311 --- linux-2.6.32.46/arch/sparc/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
4312 +++ linux-2.6.32.46/arch/sparc/include/asm/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
4313 @@ -14,10 +14,10 @@ extern int dma_set_mask(struct device *d
4314 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
4315 #define dma_is_consistent(d, h) (1)
4316
4317 -extern struct dma_map_ops *dma_ops, pci32_dma_ops;
4318 +extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
4319 extern struct bus_type pci_bus_type;
4320
4321 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4322 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
4323 {
4324 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
4325 if (dev->bus == &pci_bus_type)
4326 @@ -31,7 +31,7 @@ static inline struct dma_map_ops *get_dm
4327 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
4328 dma_addr_t *dma_handle, gfp_t flag)
4329 {
4330 - struct dma_map_ops *ops = get_dma_ops(dev);
4331 + const struct dma_map_ops *ops = get_dma_ops(dev);
4332 void *cpu_addr;
4333
4334 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
4335 @@ -42,7 +42,7 @@ static inline void *dma_alloc_coherent(s
4336 static inline void dma_free_coherent(struct device *dev, size_t size,
4337 void *cpu_addr, dma_addr_t dma_handle)
4338 {
4339 - struct dma_map_ops *ops = get_dma_ops(dev);
4340 + const struct dma_map_ops *ops = get_dma_ops(dev);
4341
4342 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
4343 ops->free_coherent(dev, size, cpu_addr, dma_handle);
4344 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/elf_32.h linux-2.6.32.46/arch/sparc/include/asm/elf_32.h
4345 --- linux-2.6.32.46/arch/sparc/include/asm/elf_32.h 2011-03-27 14:31:47.000000000 -0400
4346 +++ linux-2.6.32.46/arch/sparc/include/asm/elf_32.h 2011-04-17 15:56:46.000000000 -0400
4347 @@ -116,6 +116,13 @@ typedef struct {
4348
4349 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4350
4351 +#ifdef CONFIG_PAX_ASLR
4352 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4353 +
4354 +#define PAX_DELTA_MMAP_LEN 16
4355 +#define PAX_DELTA_STACK_LEN 16
4356 +#endif
4357 +
4358 /* This yields a mask that user programs can use to figure out what
4359 instruction set this cpu supports. This can NOT be done in userspace
4360 on Sparc. */
4361 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/elf_64.h linux-2.6.32.46/arch/sparc/include/asm/elf_64.h
4362 --- linux-2.6.32.46/arch/sparc/include/asm/elf_64.h 2011-03-27 14:31:47.000000000 -0400
4363 +++ linux-2.6.32.46/arch/sparc/include/asm/elf_64.h 2011-04-17 15:56:46.000000000 -0400
4364 @@ -163,6 +163,12 @@ typedef struct {
4365 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4366 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4367
4368 +#ifdef CONFIG_PAX_ASLR
4369 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4370 +
4371 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4372 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4373 +#endif
4374
4375 /* This yields a mask that user programs can use to figure out what
4376 instruction set this cpu supports. */
4377 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/pgtable_32.h linux-2.6.32.46/arch/sparc/include/asm/pgtable_32.h
4378 --- linux-2.6.32.46/arch/sparc/include/asm/pgtable_32.h 2011-03-27 14:31:47.000000000 -0400
4379 +++ linux-2.6.32.46/arch/sparc/include/asm/pgtable_32.h 2011-04-17 15:56:46.000000000 -0400
4380 @@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4381 BTFIXUPDEF_INT(page_none)
4382 BTFIXUPDEF_INT(page_copy)
4383 BTFIXUPDEF_INT(page_readonly)
4384 +
4385 +#ifdef CONFIG_PAX_PAGEEXEC
4386 +BTFIXUPDEF_INT(page_shared_noexec)
4387 +BTFIXUPDEF_INT(page_copy_noexec)
4388 +BTFIXUPDEF_INT(page_readonly_noexec)
4389 +#endif
4390 +
4391 BTFIXUPDEF_INT(page_kernel)
4392
4393 #define PMD_SHIFT SUN4C_PMD_SHIFT
4394 @@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
4395 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4396 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4397
4398 +#ifdef CONFIG_PAX_PAGEEXEC
4399 +extern pgprot_t PAGE_SHARED_NOEXEC;
4400 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4401 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4402 +#else
4403 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4404 +# define PAGE_COPY_NOEXEC PAGE_COPY
4405 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4406 +#endif
4407 +
4408 extern unsigned long page_kernel;
4409
4410 #ifdef MODULE
4411 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.32.46/arch/sparc/include/asm/pgtsrmmu.h
4412 --- linux-2.6.32.46/arch/sparc/include/asm/pgtsrmmu.h 2011-03-27 14:31:47.000000000 -0400
4413 +++ linux-2.6.32.46/arch/sparc/include/asm/pgtsrmmu.h 2011-04-17 15:56:46.000000000 -0400
4414 @@ -115,6 +115,13 @@
4415 SRMMU_EXEC | SRMMU_REF)
4416 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4417 SRMMU_EXEC | SRMMU_REF)
4418 +
4419 +#ifdef CONFIG_PAX_PAGEEXEC
4420 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4421 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4422 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4423 +#endif
4424 +
4425 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4426 SRMMU_DIRTY | SRMMU_REF)
4427
4428 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/spinlock_64.h linux-2.6.32.46/arch/sparc/include/asm/spinlock_64.h
4429 --- linux-2.6.32.46/arch/sparc/include/asm/spinlock_64.h 2011-03-27 14:31:47.000000000 -0400
4430 +++ linux-2.6.32.46/arch/sparc/include/asm/spinlock_64.h 2011-08-18 23:19:30.000000000 -0400
4431 @@ -92,14 +92,19 @@ static inline void __raw_spin_lock_flags
4432
4433 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4434
4435 -static void inline arch_read_lock(raw_rwlock_t *lock)
4436 +static inline void arch_read_lock(raw_rwlock_t *lock)
4437 {
4438 unsigned long tmp1, tmp2;
4439
4440 __asm__ __volatile__ (
4441 "1: ldsw [%2], %0\n"
4442 " brlz,pn %0, 2f\n"
4443 -"4: add %0, 1, %1\n"
4444 +"4: addcc %0, 1, %1\n"
4445 +
4446 +#ifdef CONFIG_PAX_REFCOUNT
4447 +" tvs %%icc, 6\n"
4448 +#endif
4449 +
4450 " cas [%2], %0, %1\n"
4451 " cmp %0, %1\n"
4452 " bne,pn %%icc, 1b\n"
4453 @@ -112,10 +117,10 @@ static void inline arch_read_lock(raw_rw
4454 " .previous"
4455 : "=&r" (tmp1), "=&r" (tmp2)
4456 : "r" (lock)
4457 - : "memory");
4458 + : "memory", "cc");
4459 }
4460
4461 -static int inline arch_read_trylock(raw_rwlock_t *lock)
4462 +static inline int arch_read_trylock(raw_rwlock_t *lock)
4463 {
4464 int tmp1, tmp2;
4465
4466 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(raw_
4467 "1: ldsw [%2], %0\n"
4468 " brlz,a,pn %0, 2f\n"
4469 " mov 0, %0\n"
4470 -" add %0, 1, %1\n"
4471 +" addcc %0, 1, %1\n"
4472 +
4473 +#ifdef CONFIG_PAX_REFCOUNT
4474 +" tvs %%icc, 6\n"
4475 +#endif
4476 +
4477 " cas [%2], %0, %1\n"
4478 " cmp %0, %1\n"
4479 " bne,pn %%icc, 1b\n"
4480 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(raw_
4481 return tmp1;
4482 }
4483
4484 -static void inline arch_read_unlock(raw_rwlock_t *lock)
4485 +static inline void arch_read_unlock(raw_rwlock_t *lock)
4486 {
4487 unsigned long tmp1, tmp2;
4488
4489 __asm__ __volatile__(
4490 "1: lduw [%2], %0\n"
4491 -" sub %0, 1, %1\n"
4492 +" subcc %0, 1, %1\n"
4493 +
4494 +#ifdef CONFIG_PAX_REFCOUNT
4495 +" tvs %%icc, 6\n"
4496 +#endif
4497 +
4498 " cas [%2], %0, %1\n"
4499 " cmp %0, %1\n"
4500 " bne,pn %%xcc, 1b\n"
4501 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(raw_
4502 : "memory");
4503 }
4504
4505 -static void inline arch_write_lock(raw_rwlock_t *lock)
4506 +static inline void arch_write_lock(raw_rwlock_t *lock)
4507 {
4508 unsigned long mask, tmp1, tmp2;
4509
4510 @@ -177,7 +192,7 @@ static void inline arch_write_lock(raw_r
4511 : "memory");
4512 }
4513
4514 -static void inline arch_write_unlock(raw_rwlock_t *lock)
4515 +static inline void arch_write_unlock(raw_rwlock_t *lock)
4516 {
4517 __asm__ __volatile__(
4518 " stw %%g0, [%0]"
4519 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(raw
4520 : "memory");
4521 }
4522
4523 -static int inline arch_write_trylock(raw_rwlock_t *lock)
4524 +static inline int arch_write_trylock(raw_rwlock_t *lock)
4525 {
4526 unsigned long mask, tmp1, tmp2, result;
4527
4528 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/thread_info_32.h linux-2.6.32.46/arch/sparc/include/asm/thread_info_32.h
4529 --- linux-2.6.32.46/arch/sparc/include/asm/thread_info_32.h 2011-03-27 14:31:47.000000000 -0400
4530 +++ linux-2.6.32.46/arch/sparc/include/asm/thread_info_32.h 2011-06-04 20:46:01.000000000 -0400
4531 @@ -50,6 +50,8 @@ struct thread_info {
4532 unsigned long w_saved;
4533
4534 struct restart_block restart_block;
4535 +
4536 + unsigned long lowest_stack;
4537 };
4538
4539 /*
4540 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/thread_info_64.h linux-2.6.32.46/arch/sparc/include/asm/thread_info_64.h
4541 --- linux-2.6.32.46/arch/sparc/include/asm/thread_info_64.h 2011-03-27 14:31:47.000000000 -0400
4542 +++ linux-2.6.32.46/arch/sparc/include/asm/thread_info_64.h 2011-06-04 20:46:21.000000000 -0400
4543 @@ -68,6 +68,8 @@ struct thread_info {
4544 struct pt_regs *kern_una_regs;
4545 unsigned int kern_una_insn;
4546
4547 + unsigned long lowest_stack;
4548 +
4549 unsigned long fpregs[0] __attribute__ ((aligned(64)));
4550 };
4551
4552 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/uaccess.h linux-2.6.32.46/arch/sparc/include/asm/uaccess.h
4553 --- linux-2.6.32.46/arch/sparc/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
4554 +++ linux-2.6.32.46/arch/sparc/include/asm/uaccess.h 2011-04-17 15:56:46.000000000 -0400
4555 @@ -1,5 +1,13 @@
4556 #ifndef ___ASM_SPARC_UACCESS_H
4557 #define ___ASM_SPARC_UACCESS_H
4558 +
4559 +#ifdef __KERNEL__
4560 +#ifndef __ASSEMBLY__
4561 +#include <linux/types.h>
4562 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4563 +#endif
4564 +#endif
4565 +
4566 #if defined(__sparc__) && defined(__arch64__)
4567 #include <asm/uaccess_64.h>
4568 #else
4569 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/uaccess_32.h linux-2.6.32.46/arch/sparc/include/asm/uaccess_32.h
4570 --- linux-2.6.32.46/arch/sparc/include/asm/uaccess_32.h 2011-03-27 14:31:47.000000000 -0400
4571 +++ linux-2.6.32.46/arch/sparc/include/asm/uaccess_32.h 2011-04-17 15:56:46.000000000 -0400
4572 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
4573
4574 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4575 {
4576 - if (n && __access_ok((unsigned long) to, n))
4577 + if ((long)n < 0)
4578 + return n;
4579 +
4580 + if (n && __access_ok((unsigned long) to, n)) {
4581 + if (!__builtin_constant_p(n))
4582 + check_object_size(from, n, true);
4583 return __copy_user(to, (__force void __user *) from, n);
4584 - else
4585 + } else
4586 return n;
4587 }
4588
4589 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
4590 {
4591 + if ((long)n < 0)
4592 + return n;
4593 +
4594 + if (!__builtin_constant_p(n))
4595 + check_object_size(from, n, true);
4596 +
4597 return __copy_user(to, (__force void __user *) from, n);
4598 }
4599
4600 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4601 {
4602 - if (n && __access_ok((unsigned long) from, n))
4603 + if ((long)n < 0)
4604 + return n;
4605 +
4606 + if (n && __access_ok((unsigned long) from, n)) {
4607 + if (!__builtin_constant_p(n))
4608 + check_object_size(to, n, false);
4609 return __copy_user((__force void __user *) to, from, n);
4610 - else
4611 + } else
4612 return n;
4613 }
4614
4615 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
4616 {
4617 + if ((long)n < 0)
4618 + return n;
4619 +
4620 return __copy_user((__force void __user *) to, from, n);
4621 }
4622
4623 diff -urNp linux-2.6.32.46/arch/sparc/include/asm/uaccess_64.h linux-2.6.32.46/arch/sparc/include/asm/uaccess_64.h
4624 --- linux-2.6.32.46/arch/sparc/include/asm/uaccess_64.h 2011-03-27 14:31:47.000000000 -0400
4625 +++ linux-2.6.32.46/arch/sparc/include/asm/uaccess_64.h 2011-04-17 15:56:46.000000000 -0400
4626 @@ -9,6 +9,7 @@
4627 #include <linux/compiler.h>
4628 #include <linux/string.h>
4629 #include <linux/thread_info.h>
4630 +#include <linux/kernel.h>
4631 #include <asm/asi.h>
4632 #include <asm/system.h>
4633 #include <asm/spitfire.h>
4634 @@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixu
4635 static inline unsigned long __must_check
4636 copy_from_user(void *to, const void __user *from, unsigned long size)
4637 {
4638 - unsigned long ret = ___copy_from_user(to, from, size);
4639 + unsigned long ret;
4640
4641 + if ((long)size < 0 || size > INT_MAX)
4642 + return size;
4643 +
4644 + if (!__builtin_constant_p(size))
4645 + check_object_size(to, size, false);
4646 +
4647 + ret = ___copy_from_user(to, from, size);
4648 if (unlikely(ret))
4649 ret = copy_from_user_fixup(to, from, size);
4650 return ret;
4651 @@ -228,8 +236,15 @@ extern unsigned long copy_to_user_fixup(
4652 static inline unsigned long __must_check
4653 copy_to_user(void __user *to, const void *from, unsigned long size)
4654 {
4655 - unsigned long ret = ___copy_to_user(to, from, size);
4656 + unsigned long ret;
4657 +
4658 + if ((long)size < 0 || size > INT_MAX)
4659 + return size;
4660 +
4661 + if (!__builtin_constant_p(size))
4662 + check_object_size(from, size, true);
4663
4664 + ret = ___copy_to_user(to, from, size);
4665 if (unlikely(ret))
4666 ret = copy_to_user_fixup(to, from, size);
4667 return ret;
4668 diff -urNp linux-2.6.32.46/arch/sparc/kernel/Makefile linux-2.6.32.46/arch/sparc/kernel/Makefile
4669 --- linux-2.6.32.46/arch/sparc/kernel/Makefile 2011-03-27 14:31:47.000000000 -0400
4670 +++ linux-2.6.32.46/arch/sparc/kernel/Makefile 2011-04-17 15:56:46.000000000 -0400
4671 @@ -3,7 +3,7 @@
4672 #
4673
4674 asflags-y := -ansi
4675 -ccflags-y := -Werror
4676 +#ccflags-y := -Werror
4677
4678 extra-y := head_$(BITS).o
4679 extra-y += init_task.o
4680 diff -urNp linux-2.6.32.46/arch/sparc/kernel/iommu.c linux-2.6.32.46/arch/sparc/kernel/iommu.c
4681 --- linux-2.6.32.46/arch/sparc/kernel/iommu.c 2011-03-27 14:31:47.000000000 -0400
4682 +++ linux-2.6.32.46/arch/sparc/kernel/iommu.c 2011-04-17 15:56:46.000000000 -0400
4683 @@ -826,7 +826,7 @@ static void dma_4u_sync_sg_for_cpu(struc
4684 spin_unlock_irqrestore(&iommu->lock, flags);
4685 }
4686
4687 -static struct dma_map_ops sun4u_dma_ops = {
4688 +static const struct dma_map_ops sun4u_dma_ops = {
4689 .alloc_coherent = dma_4u_alloc_coherent,
4690 .free_coherent = dma_4u_free_coherent,
4691 .map_page = dma_4u_map_page,
4692 @@ -837,7 +837,7 @@ static struct dma_map_ops sun4u_dma_ops
4693 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
4694 };
4695
4696 -struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4697 +const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4698 EXPORT_SYMBOL(dma_ops);
4699
4700 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
4701 diff -urNp linux-2.6.32.46/arch/sparc/kernel/ioport.c linux-2.6.32.46/arch/sparc/kernel/ioport.c
4702 --- linux-2.6.32.46/arch/sparc/kernel/ioport.c 2011-03-27 14:31:47.000000000 -0400
4703 +++ linux-2.6.32.46/arch/sparc/kernel/ioport.c 2011-04-17 15:56:46.000000000 -0400
4704 @@ -392,7 +392,7 @@ static void sbus_sync_sg_for_device(stru
4705 BUG();
4706 }
4707
4708 -struct dma_map_ops sbus_dma_ops = {
4709 +const struct dma_map_ops sbus_dma_ops = {
4710 .alloc_coherent = sbus_alloc_coherent,
4711 .free_coherent = sbus_free_coherent,
4712 .map_page = sbus_map_page,
4713 @@ -403,7 +403,7 @@ struct dma_map_ops sbus_dma_ops = {
4714 .sync_sg_for_device = sbus_sync_sg_for_device,
4715 };
4716
4717 -struct dma_map_ops *dma_ops = &sbus_dma_ops;
4718 +const struct dma_map_ops *dma_ops = &sbus_dma_ops;
4719 EXPORT_SYMBOL(dma_ops);
4720
4721 static int __init sparc_register_ioport(void)
4722 @@ -640,7 +640,7 @@ static void pci32_sync_sg_for_device(str
4723 }
4724 }
4725
4726 -struct dma_map_ops pci32_dma_ops = {
4727 +const struct dma_map_ops pci32_dma_ops = {
4728 .alloc_coherent = pci32_alloc_coherent,
4729 .free_coherent = pci32_free_coherent,
4730 .map_page = pci32_map_page,
4731 diff -urNp linux-2.6.32.46/arch/sparc/kernel/kgdb_32.c linux-2.6.32.46/arch/sparc/kernel/kgdb_32.c
4732 --- linux-2.6.32.46/arch/sparc/kernel/kgdb_32.c 2011-03-27 14:31:47.000000000 -0400
4733 +++ linux-2.6.32.46/arch/sparc/kernel/kgdb_32.c 2011-04-17 15:56:46.000000000 -0400
4734 @@ -158,7 +158,7 @@ void kgdb_arch_exit(void)
4735 {
4736 }
4737
4738 -struct kgdb_arch arch_kgdb_ops = {
4739 +const struct kgdb_arch arch_kgdb_ops = {
4740 /* Breakpoint instruction: ta 0x7d */
4741 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
4742 };
4743 diff -urNp linux-2.6.32.46/arch/sparc/kernel/kgdb_64.c linux-2.6.32.46/arch/sparc/kernel/kgdb_64.c
4744 --- linux-2.6.32.46/arch/sparc/kernel/kgdb_64.c 2011-03-27 14:31:47.000000000 -0400
4745 +++ linux-2.6.32.46/arch/sparc/kernel/kgdb_64.c 2011-04-17 15:56:46.000000000 -0400
4746 @@ -180,7 +180,7 @@ void kgdb_arch_exit(void)
4747 {
4748 }
4749
4750 -struct kgdb_arch arch_kgdb_ops = {
4751 +const struct kgdb_arch arch_kgdb_ops = {
4752 /* Breakpoint instruction: ta 0x72 */
4753 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
4754 };
4755 diff -urNp linux-2.6.32.46/arch/sparc/kernel/pci_sun4v.c linux-2.6.32.46/arch/sparc/kernel/pci_sun4v.c
4756 --- linux-2.6.32.46/arch/sparc/kernel/pci_sun4v.c 2011-03-27 14:31:47.000000000 -0400
4757 +++ linux-2.6.32.46/arch/sparc/kernel/pci_sun4v.c 2011-04-17 15:56:46.000000000 -0400
4758 @@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
4759 spin_unlock_irqrestore(&iommu->lock, flags);
4760 }
4761
4762 -static struct dma_map_ops sun4v_dma_ops = {
4763 +static const struct dma_map_ops sun4v_dma_ops = {
4764 .alloc_coherent = dma_4v_alloc_coherent,
4765 .free_coherent = dma_4v_free_coherent,
4766 .map_page = dma_4v_map_page,
4767 diff -urNp linux-2.6.32.46/arch/sparc/kernel/process_32.c linux-2.6.32.46/arch/sparc/kernel/process_32.c
4768 --- linux-2.6.32.46/arch/sparc/kernel/process_32.c 2011-03-27 14:31:47.000000000 -0400
4769 +++ linux-2.6.32.46/arch/sparc/kernel/process_32.c 2011-04-17 15:56:46.000000000 -0400
4770 @@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
4771 rw->ins[4], rw->ins[5],
4772 rw->ins[6],
4773 rw->ins[7]);
4774 - printk("%pS\n", (void *) rw->ins[7]);
4775 + printk("%pA\n", (void *) rw->ins[7]);
4776 rw = (struct reg_window32 *) rw->ins[6];
4777 }
4778 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4779 @@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
4780
4781 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4782 r->psr, r->pc, r->npc, r->y, print_tainted());
4783 - printk("PC: <%pS>\n", (void *) r->pc);
4784 + printk("PC: <%pA>\n", (void *) r->pc);
4785 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4786 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4787 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4788 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4789 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4790 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4791 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4792 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4793
4794 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4795 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
4796 @@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
4797 rw = (struct reg_window32 *) fp;
4798 pc = rw->ins[7];
4799 printk("[%08lx : ", pc);
4800 - printk("%pS ] ", (void *) pc);
4801 + printk("%pA ] ", (void *) pc);
4802 fp = rw->ins[6];
4803 } while (++count < 16);
4804 printk("\n");
4805 diff -urNp linux-2.6.32.46/arch/sparc/kernel/process_64.c linux-2.6.32.46/arch/sparc/kernel/process_64.c
4806 --- linux-2.6.32.46/arch/sparc/kernel/process_64.c 2011-03-27 14:31:47.000000000 -0400
4807 +++ linux-2.6.32.46/arch/sparc/kernel/process_64.c 2011-04-17 15:56:46.000000000 -0400
4808 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
4809 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
4810 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
4811 if (regs->tstate & TSTATE_PRIV)
4812 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
4813 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
4814 }
4815
4816 void show_regs(struct pt_regs *regs)
4817 {
4818 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
4819 regs->tpc, regs->tnpc, regs->y, print_tainted());
4820 - printk("TPC: <%pS>\n", (void *) regs->tpc);
4821 + printk("TPC: <%pA>\n", (void *) regs->tpc);
4822 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
4823 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
4824 regs->u_regs[3]);
4825 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
4826 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
4827 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
4828 regs->u_regs[15]);
4829 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
4830 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
4831 show_regwindow(regs);
4832 }
4833
4834 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void
4835 ((tp && tp->task) ? tp->task->pid : -1));
4836
4837 if (gp->tstate & TSTATE_PRIV) {
4838 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
4839 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
4840 (void *) gp->tpc,
4841 (void *) gp->o7,
4842 (void *) gp->i7,
4843 diff -urNp linux-2.6.32.46/arch/sparc/kernel/sys_sparc_32.c linux-2.6.32.46/arch/sparc/kernel/sys_sparc_32.c
4844 --- linux-2.6.32.46/arch/sparc/kernel/sys_sparc_32.c 2011-03-27 14:31:47.000000000 -0400
4845 +++ linux-2.6.32.46/arch/sparc/kernel/sys_sparc_32.c 2011-04-17 15:56:46.000000000 -0400
4846 @@ -57,7 +57,7 @@ unsigned long arch_get_unmapped_area(str
4847 if (ARCH_SUN4C && len > 0x20000000)
4848 return -ENOMEM;
4849 if (!addr)
4850 - addr = TASK_UNMAPPED_BASE;
4851 + addr = current->mm->mmap_base;
4852
4853 if (flags & MAP_SHARED)
4854 addr = COLOUR_ALIGN(addr);
4855 @@ -72,7 +72,7 @@ unsigned long arch_get_unmapped_area(str
4856 }
4857 if (TASK_SIZE - PAGE_SIZE - len < addr)
4858 return -ENOMEM;
4859 - if (!vmm || addr + len <= vmm->vm_start)
4860 + if (check_heap_stack_gap(vmm, addr, len))
4861 return addr;
4862 addr = vmm->vm_end;
4863 if (flags & MAP_SHARED)
4864 diff -urNp linux-2.6.32.46/arch/sparc/kernel/sys_sparc_64.c linux-2.6.32.46/arch/sparc/kernel/sys_sparc_64.c
4865 --- linux-2.6.32.46/arch/sparc/kernel/sys_sparc_64.c 2011-03-27 14:31:47.000000000 -0400
4866 +++ linux-2.6.32.46/arch/sparc/kernel/sys_sparc_64.c 2011-04-17 15:56:46.000000000 -0400
4867 @@ -125,7 +125,7 @@ unsigned long arch_get_unmapped_area(str
4868 /* We do not accept a shared mapping if it would violate
4869 * cache aliasing constraints.
4870 */
4871 - if ((flags & MAP_SHARED) &&
4872 + if ((filp || (flags & MAP_SHARED)) &&
4873 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4874 return -EINVAL;
4875 return addr;
4876 @@ -140,6 +140,10 @@ unsigned long arch_get_unmapped_area(str
4877 if (filp || (flags & MAP_SHARED))
4878 do_color_align = 1;
4879
4880 +#ifdef CONFIG_PAX_RANDMMAP
4881 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4882 +#endif
4883 +
4884 if (addr) {
4885 if (do_color_align)
4886 addr = COLOUR_ALIGN(addr, pgoff);
4887 @@ -147,15 +151,14 @@ unsigned long arch_get_unmapped_area(str
4888 addr = PAGE_ALIGN(addr);
4889
4890 vma = find_vma(mm, addr);
4891 - if (task_size - len >= addr &&
4892 - (!vma || addr + len <= vma->vm_start))
4893 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4894 return addr;
4895 }
4896
4897 if (len > mm->cached_hole_size) {
4898 - start_addr = addr = mm->free_area_cache;
4899 + start_addr = addr = mm->free_area_cache;
4900 } else {
4901 - start_addr = addr = TASK_UNMAPPED_BASE;
4902 + start_addr = addr = mm->mmap_base;
4903 mm->cached_hole_size = 0;
4904 }
4905
4906 @@ -175,14 +178,14 @@ full_search:
4907 vma = find_vma(mm, VA_EXCLUDE_END);
4908 }
4909 if (unlikely(task_size < addr)) {
4910 - if (start_addr != TASK_UNMAPPED_BASE) {
4911 - start_addr = addr = TASK_UNMAPPED_BASE;
4912 + if (start_addr != mm->mmap_base) {
4913 + start_addr = addr = mm->mmap_base;
4914 mm->cached_hole_size = 0;
4915 goto full_search;
4916 }
4917 return -ENOMEM;
4918 }
4919 - if (likely(!vma || addr + len <= vma->vm_start)) {
4920 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4921 /*
4922 * Remember the place where we stopped the search:
4923 */
4924 @@ -216,7 +219,7 @@ arch_get_unmapped_area_topdown(struct fi
4925 /* We do not accept a shared mapping if it would violate
4926 * cache aliasing constraints.
4927 */
4928 - if ((flags & MAP_SHARED) &&
4929 + if ((filp || (flags & MAP_SHARED)) &&
4930 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4931 return -EINVAL;
4932 return addr;
4933 @@ -237,8 +240,7 @@ arch_get_unmapped_area_topdown(struct fi
4934 addr = PAGE_ALIGN(addr);
4935
4936 vma = find_vma(mm, addr);
4937 - if (task_size - len >= addr &&
4938 - (!vma || addr + len <= vma->vm_start))
4939 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4940 return addr;
4941 }
4942
4943 @@ -259,7 +261,7 @@ arch_get_unmapped_area_topdown(struct fi
4944 /* make sure it can fit in the remaining address space */
4945 if (likely(addr > len)) {
4946 vma = find_vma(mm, addr-len);
4947 - if (!vma || addr <= vma->vm_start) {
4948 + if (check_heap_stack_gap(vma, addr - len, len)) {
4949 /* remember the address as a hint for next time */
4950 return (mm->free_area_cache = addr-len);
4951 }
4952 @@ -268,18 +270,18 @@ arch_get_unmapped_area_topdown(struct fi
4953 if (unlikely(mm->mmap_base < len))
4954 goto bottomup;
4955
4956 - addr = mm->mmap_base-len;
4957 - if (do_color_align)
4958 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4959 + addr = mm->mmap_base - len;
4960
4961 do {
4962 + if (do_color_align)
4963 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4964 /*
4965 * Lookup failure means no vma is above this address,
4966 * else if new region fits below vma->vm_start,
4967 * return with success:
4968 */
4969 vma = find_vma(mm, addr);
4970 - if (likely(!vma || addr+len <= vma->vm_start)) {
4971 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4972 /* remember the address as a hint for next time */
4973 return (mm->free_area_cache = addr);
4974 }
4975 @@ -289,10 +291,8 @@ arch_get_unmapped_area_topdown(struct fi
4976 mm->cached_hole_size = vma->vm_start - addr;
4977
4978 /* try just below the current vma->vm_start */
4979 - addr = vma->vm_start-len;
4980 - if (do_color_align)
4981 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4982 - } while (likely(len < vma->vm_start));
4983 + addr = skip_heap_stack_gap(vma, len);
4984 + } while (!IS_ERR_VALUE(addr));
4985
4986 bottomup:
4987 /*
4988 @@ -384,6 +384,12 @@ void arch_pick_mmap_layout(struct mm_str
4989 current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
4990 sysctl_legacy_va_layout) {
4991 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4992 +
4993 +#ifdef CONFIG_PAX_RANDMMAP
4994 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4995 + mm->mmap_base += mm->delta_mmap;
4996 +#endif
4997 +
4998 mm->get_unmapped_area = arch_get_unmapped_area;
4999 mm->unmap_area = arch_unmap_area;
5000 } else {
5001 @@ -398,6 +404,12 @@ void arch_pick_mmap_layout(struct mm_str
5002 gap = (task_size / 6 * 5);
5003
5004 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5005 +
5006 +#ifdef CONFIG_PAX_RANDMMAP
5007 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5008 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5009 +#endif
5010 +
5011 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5012 mm->unmap_area = arch_unmap_area_topdown;
5013 }
5014 diff -urNp linux-2.6.32.46/arch/sparc/kernel/traps_32.c linux-2.6.32.46/arch/sparc/kernel/traps_32.c
5015 --- linux-2.6.32.46/arch/sparc/kernel/traps_32.c 2011-03-27 14:31:47.000000000 -0400
5016 +++ linux-2.6.32.46/arch/sparc/kernel/traps_32.c 2011-06-13 21:25:39.000000000 -0400
5017 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned lo
5018 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5019 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5020
5021 +extern void gr_handle_kernel_exploit(void);
5022 +
5023 void die_if_kernel(char *str, struct pt_regs *regs)
5024 {
5025 static int die_counter;
5026 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_
5027 count++ < 30 &&
5028 (((unsigned long) rw) >= PAGE_OFFSET) &&
5029 !(((unsigned long) rw) & 0x7)) {
5030 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5031 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5032 (void *) rw->ins[7]);
5033 rw = (struct reg_window32 *)rw->ins[6];
5034 }
5035 }
5036 printk("Instruction DUMP:");
5037 instruction_dump ((unsigned long *) regs->pc);
5038 - if(regs->psr & PSR_PS)
5039 + if(regs->psr & PSR_PS) {
5040 + gr_handle_kernel_exploit();
5041 do_exit(SIGKILL);
5042 + }
5043 do_exit(SIGSEGV);
5044 }
5045
5046 diff -urNp linux-2.6.32.46/arch/sparc/kernel/traps_64.c linux-2.6.32.46/arch/sparc/kernel/traps_64.c
5047 --- linux-2.6.32.46/arch/sparc/kernel/traps_64.c 2011-03-27 14:31:47.000000000 -0400
5048 +++ linux-2.6.32.46/arch/sparc/kernel/traps_64.c 2011-06-13 21:24:11.000000000 -0400
5049 @@ -73,7 +73,7 @@ static void dump_tl1_traplog(struct tl1_
5050 i + 1,
5051 p->trapstack[i].tstate, p->trapstack[i].tpc,
5052 p->trapstack[i].tnpc, p->trapstack[i].tt);
5053 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5054 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5055 }
5056 }
5057
5058 @@ -93,6 +93,12 @@ void bad_trap(struct pt_regs *regs, long
5059
5060 lvl -= 0x100;
5061 if (regs->tstate & TSTATE_PRIV) {
5062 +
5063 +#ifdef CONFIG_PAX_REFCOUNT
5064 + if (lvl == 6)
5065 + pax_report_refcount_overflow(regs);
5066 +#endif
5067 +
5068 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5069 die_if_kernel(buffer, regs);
5070 }
5071 @@ -111,11 +117,16 @@ void bad_trap(struct pt_regs *regs, long
5072 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5073 {
5074 char buffer[32];
5075 -
5076 +
5077 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5078 0, lvl, SIGTRAP) == NOTIFY_STOP)
5079 return;
5080
5081 +#ifdef CONFIG_PAX_REFCOUNT
5082 + if (lvl == 6)
5083 + pax_report_refcount_overflow(regs);
5084 +#endif
5085 +
5086 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5087
5088 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5089 @@ -1139,7 +1150,7 @@ static void cheetah_log_errors(struct pt
5090 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5091 printk("%s" "ERROR(%d): ",
5092 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5093 - printk("TPC<%pS>\n", (void *) regs->tpc);
5094 + printk("TPC<%pA>\n", (void *) regs->tpc);
5095 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5096 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5097 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5098 @@ -1746,7 +1757,7 @@ void cheetah_plus_parity_error(int type,
5099 smp_processor_id(),
5100 (type & 0x1) ? 'I' : 'D',
5101 regs->tpc);
5102 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5103 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5104 panic("Irrecoverable Cheetah+ parity error.");
5105 }
5106
5107 @@ -1754,7 +1765,7 @@ void cheetah_plus_parity_error(int type,
5108 smp_processor_id(),
5109 (type & 0x1) ? 'I' : 'D',
5110 regs->tpc);
5111 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5112 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5113 }
5114
5115 struct sun4v_error_entry {
5116 @@ -1961,9 +1972,9 @@ void sun4v_itlb_error_report(struct pt_r
5117
5118 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5119 regs->tpc, tl);
5120 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5121 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5122 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5123 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5124 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5125 (void *) regs->u_regs[UREG_I7]);
5126 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5127 "pte[%lx] error[%lx]\n",
5128 @@ -1985,9 +1996,9 @@ void sun4v_dtlb_error_report(struct pt_r
5129
5130 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5131 regs->tpc, tl);
5132 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5133 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5134 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5135 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5136 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5137 (void *) regs->u_regs[UREG_I7]);
5138 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5139 "pte[%lx] error[%lx]\n",
5140 @@ -2191,7 +2202,7 @@ void show_stack(struct task_struct *tsk,
5141 fp = (unsigned long)sf->fp + STACK_BIAS;
5142 }
5143
5144 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5145 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5146 } while (++count < 16);
5147 }
5148
5149 @@ -2233,6 +2244,8 @@ static inline struct reg_window *kernel_
5150 return (struct reg_window *) (fp + STACK_BIAS);
5151 }
5152
5153 +extern void gr_handle_kernel_exploit(void);
5154 +
5155 void die_if_kernel(char *str, struct pt_regs *regs)
5156 {
5157 static int die_counter;
5158 @@ -2260,7 +2273,7 @@ void die_if_kernel(char *str, struct pt_
5159 while (rw &&
5160 count++ < 30&&
5161 is_kernel_stack(current, rw)) {
5162 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
5163 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
5164 (void *) rw->ins[7]);
5165
5166 rw = kernel_stack_up(rw);
5167 @@ -2273,8 +2286,11 @@ void die_if_kernel(char *str, struct pt_
5168 }
5169 user_instruction_dump ((unsigned int __user *) regs->tpc);
5170 }
5171 - if (regs->tstate & TSTATE_PRIV)
5172 + if (regs->tstate & TSTATE_PRIV) {
5173 + gr_handle_kernel_exploit();
5174 do_exit(SIGKILL);
5175 + }
5176 +
5177 do_exit(SIGSEGV);
5178 }
5179 EXPORT_SYMBOL(die_if_kernel);
5180 diff -urNp linux-2.6.32.46/arch/sparc/kernel/una_asm_64.S linux-2.6.32.46/arch/sparc/kernel/una_asm_64.S
5181 --- linux-2.6.32.46/arch/sparc/kernel/una_asm_64.S 2011-03-27 14:31:47.000000000 -0400
5182 +++ linux-2.6.32.46/arch/sparc/kernel/una_asm_64.S 2011-07-13 22:20:05.000000000 -0400
5183 @@ -127,7 +127,7 @@ do_int_load:
5184 wr %o5, 0x0, %asi
5185 retl
5186 mov 0, %o0
5187 - .size __do_int_load, .-__do_int_load
5188 + .size do_int_load, .-do_int_load
5189
5190 .section __ex_table,"a"
5191 .word 4b, __retl_efault
5192 diff -urNp linux-2.6.32.46/arch/sparc/kernel/unaligned_64.c linux-2.6.32.46/arch/sparc/kernel/unaligned_64.c
5193 --- linux-2.6.32.46/arch/sparc/kernel/unaligned_64.c 2011-03-27 14:31:47.000000000 -0400
5194 +++ linux-2.6.32.46/arch/sparc/kernel/unaligned_64.c 2011-04-17 15:56:46.000000000 -0400
5195 @@ -288,7 +288,7 @@ static void log_unaligned(struct pt_regs
5196 if (count < 5) {
5197 last_time = jiffies;
5198 count++;
5199 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
5200 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
5201 regs->tpc, (void *) regs->tpc);
5202 }
5203 }
5204 diff -urNp linux-2.6.32.46/arch/sparc/lib/Makefile linux-2.6.32.46/arch/sparc/lib/Makefile
5205 --- linux-2.6.32.46/arch/sparc/lib/Makefile 2011-03-27 14:31:47.000000000 -0400
5206 +++ linux-2.6.32.46/arch/sparc/lib/Makefile 2011-05-17 19:26:34.000000000 -0400
5207 @@ -2,7 +2,7 @@
5208 #
5209
5210 asflags-y := -ansi -DST_DIV0=0x02
5211 -ccflags-y := -Werror
5212 +#ccflags-y := -Werror
5213
5214 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5215 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5216 diff -urNp linux-2.6.32.46/arch/sparc/lib/atomic_64.S linux-2.6.32.46/arch/sparc/lib/atomic_64.S
5217 --- linux-2.6.32.46/arch/sparc/lib/atomic_64.S 2011-03-27 14:31:47.000000000 -0400
5218 +++ linux-2.6.32.46/arch/sparc/lib/atomic_64.S 2011-04-17 15:56:46.000000000 -0400
5219 @@ -18,7 +18,12 @@
5220 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5221 BACKOFF_SETUP(%o2)
5222 1: lduw [%o1], %g1
5223 - add %g1, %o0, %g7
5224 + addcc %g1, %o0, %g7
5225 +
5226 +#ifdef CONFIG_PAX_REFCOUNT
5227 + tvs %icc, 6
5228 +#endif
5229 +
5230 cas [%o1], %g1, %g7
5231 cmp %g1, %g7
5232 bne,pn %icc, 2f
5233 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
5234 2: BACKOFF_SPIN(%o2, %o3, 1b)
5235 .size atomic_add, .-atomic_add
5236
5237 + .globl atomic_add_unchecked
5238 + .type atomic_add_unchecked,#function
5239 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5240 + BACKOFF_SETUP(%o2)
5241 +1: lduw [%o1], %g1
5242 + add %g1, %o0, %g7
5243 + cas [%o1], %g1, %g7
5244 + cmp %g1, %g7
5245 + bne,pn %icc, 2f
5246 + nop
5247 + retl
5248 + nop
5249 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5250 + .size atomic_add_unchecked, .-atomic_add_unchecked
5251 +
5252 .globl atomic_sub
5253 .type atomic_sub,#function
5254 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5255 BACKOFF_SETUP(%o2)
5256 1: lduw [%o1], %g1
5257 - sub %g1, %o0, %g7
5258 + subcc %g1, %o0, %g7
5259 +
5260 +#ifdef CONFIG_PAX_REFCOUNT
5261 + tvs %icc, 6
5262 +#endif
5263 +
5264 cas [%o1], %g1, %g7
5265 cmp %g1, %g7
5266 bne,pn %icc, 2f
5267 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
5268 2: BACKOFF_SPIN(%o2, %o3, 1b)
5269 .size atomic_sub, .-atomic_sub
5270
5271 + .globl atomic_sub_unchecked
5272 + .type atomic_sub_unchecked,#function
5273 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5274 + BACKOFF_SETUP(%o2)
5275 +1: lduw [%o1], %g1
5276 + sub %g1, %o0, %g7
5277 + cas [%o1], %g1, %g7
5278 + cmp %g1, %g7
5279 + bne,pn %icc, 2f
5280 + nop
5281 + retl
5282 + nop
5283 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5284 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
5285 +
5286 .globl atomic_add_ret
5287 .type atomic_add_ret,#function
5288 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5289 BACKOFF_SETUP(%o2)
5290 1: lduw [%o1], %g1
5291 - add %g1, %o0, %g7
5292 + addcc %g1, %o0, %g7
5293 +
5294 +#ifdef CONFIG_PAX_REFCOUNT
5295 + tvs %icc, 6
5296 +#endif
5297 +
5298 cas [%o1], %g1, %g7
5299 cmp %g1, %g7
5300 bne,pn %icc, 2f
5301 @@ -59,12 +104,33 @@ atomic_add_ret: /* %o0 = increment, %o1
5302 2: BACKOFF_SPIN(%o2, %o3, 1b)
5303 .size atomic_add_ret, .-atomic_add_ret
5304
5305 + .globl atomic_add_ret_unchecked
5306 + .type atomic_add_ret_unchecked,#function
5307 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5308 + BACKOFF_SETUP(%o2)
5309 +1: lduw [%o1], %g1
5310 + addcc %g1, %o0, %g7
5311 + cas [%o1], %g1, %g7
5312 + cmp %g1, %g7
5313 + bne,pn %icc, 2f
5314 + add %g7, %o0, %g7
5315 + sra %g7, 0, %o0
5316 + retl
5317 + nop
5318 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5319 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5320 +
5321 .globl atomic_sub_ret
5322 .type atomic_sub_ret,#function
5323 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5324 BACKOFF_SETUP(%o2)
5325 1: lduw [%o1], %g1
5326 - sub %g1, %o0, %g7
5327 + subcc %g1, %o0, %g7
5328 +
5329 +#ifdef CONFIG_PAX_REFCOUNT
5330 + tvs %icc, 6
5331 +#endif
5332 +
5333 cas [%o1], %g1, %g7
5334 cmp %g1, %g7
5335 bne,pn %icc, 2f
5336 @@ -80,7 +146,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
5337 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5338 BACKOFF_SETUP(%o2)
5339 1: ldx [%o1], %g1
5340 - add %g1, %o0, %g7
5341 + addcc %g1, %o0, %g7
5342 +
5343 +#ifdef CONFIG_PAX_REFCOUNT
5344 + tvs %xcc, 6
5345 +#endif
5346 +
5347 casx [%o1], %g1, %g7
5348 cmp %g1, %g7
5349 bne,pn %xcc, 2f
5350 @@ -90,12 +161,32 @@ atomic64_add: /* %o0 = increment, %o1 =
5351 2: BACKOFF_SPIN(%o2, %o3, 1b)
5352 .size atomic64_add, .-atomic64_add
5353
5354 + .globl atomic64_add_unchecked
5355 + .type atomic64_add_unchecked,#function
5356 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5357 + BACKOFF_SETUP(%o2)
5358 +1: ldx [%o1], %g1
5359 + addcc %g1, %o0, %g7
5360 + casx [%o1], %g1, %g7
5361 + cmp %g1, %g7
5362 + bne,pn %xcc, 2f
5363 + nop
5364 + retl
5365 + nop
5366 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5367 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
5368 +
5369 .globl atomic64_sub
5370 .type atomic64_sub,#function
5371 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5372 BACKOFF_SETUP(%o2)
5373 1: ldx [%o1], %g1
5374 - sub %g1, %o0, %g7
5375 + subcc %g1, %o0, %g7
5376 +
5377 +#ifdef CONFIG_PAX_REFCOUNT
5378 + tvs %xcc, 6
5379 +#endif
5380 +
5381 casx [%o1], %g1, %g7
5382 cmp %g1, %g7
5383 bne,pn %xcc, 2f
5384 @@ -105,12 +196,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
5385 2: BACKOFF_SPIN(%o2, %o3, 1b)
5386 .size atomic64_sub, .-atomic64_sub
5387
5388 + .globl atomic64_sub_unchecked
5389 + .type atomic64_sub_unchecked,#function
5390 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5391 + BACKOFF_SETUP(%o2)
5392 +1: ldx [%o1], %g1
5393 + subcc %g1, %o0, %g7
5394 + casx [%o1], %g1, %g7
5395 + cmp %g1, %g7
5396 + bne,pn %xcc, 2f
5397 + nop
5398 + retl
5399 + nop
5400 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5401 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5402 +
5403 .globl atomic64_add_ret
5404 .type atomic64_add_ret,#function
5405 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5406 BACKOFF_SETUP(%o2)
5407 1: ldx [%o1], %g1
5408 - add %g1, %o0, %g7
5409 + addcc %g1, %o0, %g7
5410 +
5411 +#ifdef CONFIG_PAX_REFCOUNT
5412 + tvs %xcc, 6
5413 +#endif
5414 +
5415 casx [%o1], %g1, %g7
5416 cmp %g1, %g7
5417 bne,pn %xcc, 2f
5418 @@ -121,12 +232,33 @@ atomic64_add_ret: /* %o0 = increment, %o
5419 2: BACKOFF_SPIN(%o2, %o3, 1b)
5420 .size atomic64_add_ret, .-atomic64_add_ret
5421
5422 + .globl atomic64_add_ret_unchecked
5423 + .type atomic64_add_ret_unchecked,#function
5424 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5425 + BACKOFF_SETUP(%o2)
5426 +1: ldx [%o1], %g1
5427 + addcc %g1, %o0, %g7
5428 + casx [%o1], %g1, %g7
5429 + cmp %g1, %g7
5430 + bne,pn %xcc, 2f
5431 + add %g7, %o0, %g7
5432 + mov %g7, %o0
5433 + retl
5434 + nop
5435 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5436 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5437 +
5438 .globl atomic64_sub_ret
5439 .type atomic64_sub_ret,#function
5440 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5441 BACKOFF_SETUP(%o2)
5442 1: ldx [%o1], %g1
5443 - sub %g1, %o0, %g7
5444 + subcc %g1, %o0, %g7
5445 +
5446 +#ifdef CONFIG_PAX_REFCOUNT
5447 + tvs %xcc, 6
5448 +#endif
5449 +
5450 casx [%o1], %g1, %g7
5451 cmp %g1, %g7
5452 bne,pn %xcc, 2f
5453 diff -urNp linux-2.6.32.46/arch/sparc/lib/ksyms.c linux-2.6.32.46/arch/sparc/lib/ksyms.c
5454 --- linux-2.6.32.46/arch/sparc/lib/ksyms.c 2011-03-27 14:31:47.000000000 -0400
5455 +++ linux-2.6.32.46/arch/sparc/lib/ksyms.c 2011-08-19 23:05:14.000000000 -0400
5456 @@ -144,12 +144,18 @@ EXPORT_SYMBOL(__downgrade_write);
5457
5458 /* Atomic counter implementation. */
5459 EXPORT_SYMBOL(atomic_add);
5460 +EXPORT_SYMBOL(atomic_add_unchecked);
5461 EXPORT_SYMBOL(atomic_add_ret);
5462 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
5463 EXPORT_SYMBOL(atomic_sub);
5464 +EXPORT_SYMBOL(atomic_sub_unchecked);
5465 EXPORT_SYMBOL(atomic_sub_ret);
5466 EXPORT_SYMBOL(atomic64_add);
5467 +EXPORT_SYMBOL(atomic64_add_unchecked);
5468 EXPORT_SYMBOL(atomic64_add_ret);
5469 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5470 EXPORT_SYMBOL(atomic64_sub);
5471 +EXPORT_SYMBOL(atomic64_sub_unchecked);
5472 EXPORT_SYMBOL(atomic64_sub_ret);
5473
5474 /* Atomic bit operations. */
5475 diff -urNp linux-2.6.32.46/arch/sparc/lib/rwsem_64.S linux-2.6.32.46/arch/sparc/lib/rwsem_64.S
5476 --- linux-2.6.32.46/arch/sparc/lib/rwsem_64.S 2011-03-27 14:31:47.000000000 -0400
5477 +++ linux-2.6.32.46/arch/sparc/lib/rwsem_64.S 2011-04-17 15:56:46.000000000 -0400
5478 @@ -11,7 +11,12 @@
5479 .globl __down_read
5480 __down_read:
5481 1: lduw [%o0], %g1
5482 - add %g1, 1, %g7
5483 + addcc %g1, 1, %g7
5484 +
5485 +#ifdef CONFIG_PAX_REFCOUNT
5486 + tvs %icc, 6
5487 +#endif
5488 +
5489 cas [%o0], %g1, %g7
5490 cmp %g1, %g7
5491 bne,pn %icc, 1b
5492 @@ -33,7 +38,12 @@ __down_read:
5493 .globl __down_read_trylock
5494 __down_read_trylock:
5495 1: lduw [%o0], %g1
5496 - add %g1, 1, %g7
5497 + addcc %g1, 1, %g7
5498 +
5499 +#ifdef CONFIG_PAX_REFCOUNT
5500 + tvs %icc, 6
5501 +#endif
5502 +
5503 cmp %g7, 0
5504 bl,pn %icc, 2f
5505 mov 0, %o1
5506 @@ -51,7 +61,12 @@ __down_write:
5507 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
5508 1:
5509 lduw [%o0], %g3
5510 - add %g3, %g1, %g7
5511 + addcc %g3, %g1, %g7
5512 +
5513 +#ifdef CONFIG_PAX_REFCOUNT
5514 + tvs %icc, 6
5515 +#endif
5516 +
5517 cas [%o0], %g3, %g7
5518 cmp %g3, %g7
5519 bne,pn %icc, 1b
5520 @@ -77,7 +92,12 @@ __down_write_trylock:
5521 cmp %g3, 0
5522 bne,pn %icc, 2f
5523 mov 0, %o1
5524 - add %g3, %g1, %g7
5525 + addcc %g3, %g1, %g7
5526 +
5527 +#ifdef CONFIG_PAX_REFCOUNT
5528 + tvs %icc, 6
5529 +#endif
5530 +
5531 cas [%o0], %g3, %g7
5532 cmp %g3, %g7
5533 bne,pn %icc, 1b
5534 @@ -90,7 +110,12 @@ __down_write_trylock:
5535 __up_read:
5536 1:
5537 lduw [%o0], %g1
5538 - sub %g1, 1, %g7
5539 + subcc %g1, 1, %g7
5540 +
5541 +#ifdef CONFIG_PAX_REFCOUNT
5542 + tvs %icc, 6
5543 +#endif
5544 +
5545 cas [%o0], %g1, %g7
5546 cmp %g1, %g7
5547 bne,pn %icc, 1b
5548 @@ -118,7 +143,12 @@ __up_write:
5549 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
5550 1:
5551 lduw [%o0], %g3
5552 - sub %g3, %g1, %g7
5553 + subcc %g3, %g1, %g7
5554 +
5555 +#ifdef CONFIG_PAX_REFCOUNT
5556 + tvs %icc, 6
5557 +#endif
5558 +
5559 cas [%o0], %g3, %g7
5560 cmp %g3, %g7
5561 bne,pn %icc, 1b
5562 @@ -143,7 +173,12 @@ __downgrade_write:
5563 or %g1, %lo(RWSEM_WAITING_BIAS), %g1
5564 1:
5565 lduw [%o0], %g3
5566 - sub %g3, %g1, %g7
5567 + subcc %g3, %g1, %g7
5568 +
5569 +#ifdef CONFIG_PAX_REFCOUNT
5570 + tvs %icc, 6
5571 +#endif
5572 +
5573 cas [%o0], %g3, %g7
5574 cmp %g3, %g7
5575 bne,pn %icc, 1b
5576 diff -urNp linux-2.6.32.46/arch/sparc/mm/Makefile linux-2.6.32.46/arch/sparc/mm/Makefile
5577 --- linux-2.6.32.46/arch/sparc/mm/Makefile 2011-03-27 14:31:47.000000000 -0400
5578 +++ linux-2.6.32.46/arch/sparc/mm/Makefile 2011-04-17 15:56:46.000000000 -0400
5579 @@ -2,7 +2,7 @@
5580 #
5581
5582 asflags-y := -ansi
5583 -ccflags-y := -Werror
5584 +#ccflags-y := -Werror
5585
5586 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
5587 obj-y += fault_$(BITS).o
5588 diff -urNp linux-2.6.32.46/arch/sparc/mm/fault_32.c linux-2.6.32.46/arch/sparc/mm/fault_32.c
5589 --- linux-2.6.32.46/arch/sparc/mm/fault_32.c 2011-03-27 14:31:47.000000000 -0400
5590 +++ linux-2.6.32.46/arch/sparc/mm/fault_32.c 2011-04-17 15:56:46.000000000 -0400
5591 @@ -21,6 +21,9 @@
5592 #include <linux/interrupt.h>
5593 #include <linux/module.h>
5594 #include <linux/kdebug.h>
5595 +#include <linux/slab.h>
5596 +#include <linux/pagemap.h>
5597 +#include <linux/compiler.h>
5598
5599 #include <asm/system.h>
5600 #include <asm/page.h>
5601 @@ -167,6 +170,267 @@ static unsigned long compute_si_addr(str
5602 return safe_compute_effective_address(regs, insn);
5603 }
5604
5605 +#ifdef CONFIG_PAX_PAGEEXEC
5606 +#ifdef CONFIG_PAX_DLRESOLVE
5607 +static void pax_emuplt_close(struct vm_area_struct *vma)
5608 +{
5609 + vma->vm_mm->call_dl_resolve = 0UL;
5610 +}
5611 +
5612 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5613 +{
5614 + unsigned int *kaddr;
5615 +
5616 + vmf->page = alloc_page(GFP_HIGHUSER);
5617 + if (!vmf->page)
5618 + return VM_FAULT_OOM;
5619 +
5620 + kaddr = kmap(vmf->page);
5621 + memset(kaddr, 0, PAGE_SIZE);
5622 + kaddr[0] = 0x9DE3BFA8U; /* save */
5623 + flush_dcache_page(vmf->page);
5624 + kunmap(vmf->page);
5625 + return VM_FAULT_MAJOR;
5626 +}
5627 +
5628 +static const struct vm_operations_struct pax_vm_ops = {
5629 + .close = pax_emuplt_close,
5630 + .fault = pax_emuplt_fault
5631 +};
5632 +
5633 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5634 +{
5635 + int ret;
5636 +
5637 + vma->vm_mm = current->mm;
5638 + vma->vm_start = addr;
5639 + vma->vm_end = addr + PAGE_SIZE;
5640 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5641 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5642 + vma->vm_ops = &pax_vm_ops;
5643 +
5644 + ret = insert_vm_struct(current->mm, vma);
5645 + if (ret)
5646 + return ret;
5647 +
5648 + ++current->mm->total_vm;
5649 + return 0;
5650 +}
5651 +#endif
5652 +
5653 +/*
5654 + * PaX: decide what to do with offenders (regs->pc = fault address)
5655 + *
5656 + * returns 1 when task should be killed
5657 + * 2 when patched PLT trampoline was detected
5658 + * 3 when unpatched PLT trampoline was detected
5659 + */
5660 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5661 +{
5662 +
5663 +#ifdef CONFIG_PAX_EMUPLT
5664 + int err;
5665 +
5666 + do { /* PaX: patched PLT emulation #1 */
5667 + unsigned int sethi1, sethi2, jmpl;
5668 +
5669 + err = get_user(sethi1, (unsigned int *)regs->pc);
5670 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
5671 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
5672 +
5673 + if (err)
5674 + break;
5675 +
5676 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5677 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5678 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5679 + {
5680 + unsigned int addr;
5681 +
5682 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5683 + addr = regs->u_regs[UREG_G1];
5684 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5685 + regs->pc = addr;
5686 + regs->npc = addr+4;
5687 + return 2;
5688 + }
5689 + } while (0);
5690 +
5691 + { /* PaX: patched PLT emulation #2 */
5692 + unsigned int ba;
5693 +
5694 + err = get_user(ba, (unsigned int *)regs->pc);
5695 +
5696 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5697 + unsigned int addr;
5698 +
5699 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5700 + regs->pc = addr;
5701 + regs->npc = addr+4;
5702 + return 2;
5703 + }
5704 + }
5705 +
5706 + do { /* PaX: patched PLT emulation #3 */
5707 + unsigned int sethi, jmpl, nop;
5708 +
5709 + err = get_user(sethi, (unsigned int *)regs->pc);
5710 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
5711 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
5712 +
5713 + if (err)
5714 + break;
5715 +
5716 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5717 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5718 + nop == 0x01000000U)
5719 + {
5720 + unsigned int addr;
5721 +
5722 + addr = (sethi & 0x003FFFFFU) << 10;
5723 + regs->u_regs[UREG_G1] = addr;
5724 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5725 + regs->pc = addr;
5726 + regs->npc = addr+4;
5727 + return 2;
5728 + }
5729 + } while (0);
5730 +
5731 + do { /* PaX: unpatched PLT emulation step 1 */
5732 + unsigned int sethi, ba, nop;
5733 +
5734 + err = get_user(sethi, (unsigned int *)regs->pc);
5735 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
5736 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
5737 +
5738 + if (err)
5739 + break;
5740 +
5741 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5742 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5743 + nop == 0x01000000U)
5744 + {
5745 + unsigned int addr, save, call;
5746 +
5747 + if ((ba & 0xFFC00000U) == 0x30800000U)
5748 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5749 + else
5750 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
5751 +
5752 + err = get_user(save, (unsigned int *)addr);
5753 + err |= get_user(call, (unsigned int *)(addr+4));
5754 + err |= get_user(nop, (unsigned int *)(addr+8));
5755 + if (err)
5756 + break;
5757 +
5758 +#ifdef CONFIG_PAX_DLRESOLVE
5759 + if (save == 0x9DE3BFA8U &&
5760 + (call & 0xC0000000U) == 0x40000000U &&
5761 + nop == 0x01000000U)
5762 + {
5763 + struct vm_area_struct *vma;
5764 + unsigned long call_dl_resolve;
5765 +
5766 + down_read(&current->mm->mmap_sem);
5767 + call_dl_resolve = current->mm->call_dl_resolve;
5768 + up_read(&current->mm->mmap_sem);
5769 + if (likely(call_dl_resolve))
5770 + goto emulate;
5771 +
5772 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5773 +
5774 + down_write(&current->mm->mmap_sem);
5775 + if (current->mm->call_dl_resolve) {
5776 + call_dl_resolve = current->mm->call_dl_resolve;
5777 + up_write(&current->mm->mmap_sem);
5778 + if (vma)
5779 + kmem_cache_free(vm_area_cachep, vma);
5780 + goto emulate;
5781 + }
5782 +
5783 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5784 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5785 + up_write(&current->mm->mmap_sem);
5786 + if (vma)
5787 + kmem_cache_free(vm_area_cachep, vma);
5788 + return 1;
5789 + }
5790 +
5791 + if (pax_insert_vma(vma, call_dl_resolve)) {
5792 + up_write(&current->mm->mmap_sem);
5793 + kmem_cache_free(vm_area_cachep, vma);
5794 + return 1;
5795 + }
5796 +
5797 + current->mm->call_dl_resolve = call_dl_resolve;
5798 + up_write(&current->mm->mmap_sem);
5799 +
5800 +emulate:
5801 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5802 + regs->pc = call_dl_resolve;
5803 + regs->npc = addr+4;
5804 + return 3;
5805 + }
5806 +#endif
5807 +
5808 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5809 + if ((save & 0xFFC00000U) == 0x05000000U &&
5810 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5811 + nop == 0x01000000U)
5812 + {
5813 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5814 + regs->u_regs[UREG_G2] = addr + 4;
5815 + addr = (save & 0x003FFFFFU) << 10;
5816 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5817 + regs->pc = addr;
5818 + regs->npc = addr+4;
5819 + return 3;
5820 + }
5821 + }
5822 + } while (0);
5823 +
5824 + do { /* PaX: unpatched PLT emulation step 2 */
5825 + unsigned int save, call, nop;
5826 +
5827 + err = get_user(save, (unsigned int *)(regs->pc-4));
5828 + err |= get_user(call, (unsigned int *)regs->pc);
5829 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
5830 + if (err)
5831 + break;
5832 +
5833 + if (save == 0x9DE3BFA8U &&
5834 + (call & 0xC0000000U) == 0x40000000U &&
5835 + nop == 0x01000000U)
5836 + {
5837 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
5838 +
5839 + regs->u_regs[UREG_RETPC] = regs->pc;
5840 + regs->pc = dl_resolve;
5841 + regs->npc = dl_resolve+4;
5842 + return 3;
5843 + }
5844 + } while (0);
5845 +#endif
5846 +
5847 + return 1;
5848 +}
5849 +
5850 +void pax_report_insns(void *pc, void *sp)
5851 +{
5852 + unsigned long i;
5853 +
5854 + printk(KERN_ERR "PAX: bytes at PC: ");
5855 + for (i = 0; i < 8; i++) {
5856 + unsigned int c;
5857 + if (get_user(c, (unsigned int *)pc+i))
5858 + printk(KERN_CONT "???????? ");
5859 + else
5860 + printk(KERN_CONT "%08x ", c);
5861 + }
5862 + printk("\n");
5863 +}
5864 +#endif
5865 +
5866 asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
5867 unsigned long address)
5868 {
5869 @@ -231,6 +495,24 @@ good_area:
5870 if(!(vma->vm_flags & VM_WRITE))
5871 goto bad_area;
5872 } else {
5873 +
5874 +#ifdef CONFIG_PAX_PAGEEXEC
5875 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
5876 + up_read(&mm->mmap_sem);
5877 + switch (pax_handle_fetch_fault(regs)) {
5878 +
5879 +#ifdef CONFIG_PAX_EMUPLT
5880 + case 2:
5881 + case 3:
5882 + return;
5883 +#endif
5884 +
5885 + }
5886 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
5887 + do_group_exit(SIGKILL);
5888 + }
5889 +#endif
5890 +
5891 /* Allow reads even for write-only mappings */
5892 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
5893 goto bad_area;
5894 diff -urNp linux-2.6.32.46/arch/sparc/mm/fault_64.c linux-2.6.32.46/arch/sparc/mm/fault_64.c
5895 --- linux-2.6.32.46/arch/sparc/mm/fault_64.c 2011-03-27 14:31:47.000000000 -0400
5896 +++ linux-2.6.32.46/arch/sparc/mm/fault_64.c 2011-04-17 15:56:46.000000000 -0400
5897 @@ -20,6 +20,9 @@
5898 #include <linux/kprobes.h>
5899 #include <linux/kdebug.h>
5900 #include <linux/percpu.h>
5901 +#include <linux/slab.h>
5902 +#include <linux/pagemap.h>
5903 +#include <linux/compiler.h>
5904
5905 #include <asm/page.h>
5906 #include <asm/pgtable.h>
5907 @@ -78,7 +81,7 @@ static void bad_kernel_pc(struct pt_regs
5908 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
5909 regs->tpc);
5910 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
5911 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
5912 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
5913 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
5914 dump_stack();
5915 unhandled_fault(regs->tpc, current, regs);
5916 @@ -249,6 +252,456 @@ static void noinline bogus_32bit_fault_a
5917 show_regs(regs);
5918 }
5919
5920 +#ifdef CONFIG_PAX_PAGEEXEC
5921 +#ifdef CONFIG_PAX_DLRESOLVE
5922 +static void pax_emuplt_close(struct vm_area_struct *vma)
5923 +{
5924 + vma->vm_mm->call_dl_resolve = 0UL;
5925 +}
5926 +
5927 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5928 +{
5929 + unsigned int *kaddr;
5930 +
5931 + vmf->page = alloc_page(GFP_HIGHUSER);
5932 + if (!vmf->page)
5933 + return VM_FAULT_OOM;
5934 +
5935 + kaddr = kmap(vmf->page);
5936 + memset(kaddr, 0, PAGE_SIZE);
5937 + kaddr[0] = 0x9DE3BFA8U; /* save */
5938 + flush_dcache_page(vmf->page);
5939 + kunmap(vmf->page);
5940 + return VM_FAULT_MAJOR;
5941 +}
5942 +
5943 +static const struct vm_operations_struct pax_vm_ops = {
5944 + .close = pax_emuplt_close,
5945 + .fault = pax_emuplt_fault
5946 +};
5947 +
5948 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5949 +{
5950 + int ret;
5951 +
5952 + vma->vm_mm = current->mm;
5953 + vma->vm_start = addr;
5954 + vma->vm_end = addr + PAGE_SIZE;
5955 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5956 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5957 + vma->vm_ops = &pax_vm_ops;
5958 +
5959 + ret = insert_vm_struct(current->mm, vma);
5960 + if (ret)
5961 + return ret;
5962 +
5963 + ++current->mm->total_vm;
5964 + return 0;
5965 +}
5966 +#endif
5967 +
5968 +/*
5969 + * PaX: decide what to do with offenders (regs->tpc = fault address)
5970 + *
5971 + * returns 1 when task should be killed
5972 + * 2 when patched PLT trampoline was detected
5973 + * 3 when unpatched PLT trampoline was detected
5974 + */
5975 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5976 +{
5977 +
5978 +#ifdef CONFIG_PAX_EMUPLT
5979 + int err;
5980 +
5981 + do { /* PaX: patched PLT emulation #1 */
5982 + unsigned int sethi1, sethi2, jmpl;
5983 +
5984 + err = get_user(sethi1, (unsigned int *)regs->tpc);
5985 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
5986 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
5987 +
5988 + if (err)
5989 + break;
5990 +
5991 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5992 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5993 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5994 + {
5995 + unsigned long addr;
5996 +
5997 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5998 + addr = regs->u_regs[UREG_G1];
5999 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6000 +
6001 + if (test_thread_flag(TIF_32BIT))
6002 + addr &= 0xFFFFFFFFUL;
6003 +
6004 + regs->tpc = addr;
6005 + regs->tnpc = addr+4;
6006 + return 2;
6007 + }
6008 + } while (0);
6009 +
6010 + { /* PaX: patched PLT emulation #2 */
6011 + unsigned int ba;
6012 +
6013 + err = get_user(ba, (unsigned int *)regs->tpc);
6014 +
6015 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6016 + unsigned long addr;
6017 +
6018 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6019 +
6020 + if (test_thread_flag(TIF_32BIT))
6021 + addr &= 0xFFFFFFFFUL;
6022 +
6023 + regs->tpc = addr;
6024 + regs->tnpc = addr+4;
6025 + return 2;
6026 + }
6027 + }
6028 +
6029 + do { /* PaX: patched PLT emulation #3 */
6030 + unsigned int sethi, jmpl, nop;
6031 +
6032 + err = get_user(sethi, (unsigned int *)regs->tpc);
6033 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6034 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6035 +
6036 + if (err)
6037 + break;
6038 +
6039 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6040 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6041 + nop == 0x01000000U)
6042 + {
6043 + unsigned long addr;
6044 +
6045 + addr = (sethi & 0x003FFFFFU) << 10;
6046 + regs->u_regs[UREG_G1] = addr;
6047 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6048 +
6049 + if (test_thread_flag(TIF_32BIT))
6050 + addr &= 0xFFFFFFFFUL;
6051 +
6052 + regs->tpc = addr;
6053 + regs->tnpc = addr+4;
6054 + return 2;
6055 + }
6056 + } while (0);
6057 +
6058 + do { /* PaX: patched PLT emulation #4 */
6059 + unsigned int sethi, mov1, call, mov2;
6060 +
6061 + err = get_user(sethi, (unsigned int *)regs->tpc);
6062 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6063 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6064 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6065 +
6066 + if (err)
6067 + break;
6068 +
6069 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6070 + mov1 == 0x8210000FU &&
6071 + (call & 0xC0000000U) == 0x40000000U &&
6072 + mov2 == 0x9E100001U)
6073 + {
6074 + unsigned long addr;
6075 +
6076 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6077 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6078 +
6079 + if (test_thread_flag(TIF_32BIT))
6080 + addr &= 0xFFFFFFFFUL;
6081 +
6082 + regs->tpc = addr;
6083 + regs->tnpc = addr+4;
6084 + return 2;
6085 + }
6086 + } while (0);
6087 +
6088 + do { /* PaX: patched PLT emulation #5 */
6089 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6090 +
6091 + err = get_user(sethi, (unsigned int *)regs->tpc);
6092 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6093 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6094 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6095 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6096 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6097 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6098 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6099 +
6100 + if (err)
6101 + break;
6102 +
6103 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6104 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6105 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6106 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6107 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6108 + sllx == 0x83287020U &&
6109 + jmpl == 0x81C04005U &&
6110 + nop == 0x01000000U)
6111 + {
6112 + unsigned long addr;
6113 +
6114 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6115 + regs->u_regs[UREG_G1] <<= 32;
6116 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6117 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6118 + regs->tpc = addr;
6119 + regs->tnpc = addr+4;
6120 + return 2;
6121 + }
6122 + } while (0);
6123 +
6124 + do { /* PaX: patched PLT emulation #6 */
6125 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6126 +
6127 + err = get_user(sethi, (unsigned int *)regs->tpc);
6128 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6129 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6130 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6131 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6132 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6133 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6134 +
6135 + if (err)
6136 + break;
6137 +
6138 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6139 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6140 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6141 + sllx == 0x83287020U &&
6142 + (or & 0xFFFFE000U) == 0x8A116000U &&
6143 + jmpl == 0x81C04005U &&
6144 + nop == 0x01000000U)
6145 + {
6146 + unsigned long addr;
6147 +
6148 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6149 + regs->u_regs[UREG_G1] <<= 32;
6150 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6151 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6152 + regs->tpc = addr;
6153 + regs->tnpc = addr+4;
6154 + return 2;
6155 + }
6156 + } while (0);
6157 +
6158 + do { /* PaX: unpatched PLT emulation step 1 */
6159 + unsigned int sethi, ba, nop;
6160 +
6161 + err = get_user(sethi, (unsigned int *)regs->tpc);
6162 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6163 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6164 +
6165 + if (err)
6166 + break;
6167 +
6168 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6169 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6170 + nop == 0x01000000U)
6171 + {
6172 + unsigned long addr;
6173 + unsigned int save, call;
6174 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6175 +
6176 + if ((ba & 0xFFC00000U) == 0x30800000U)
6177 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6178 + else
6179 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6180 +
6181 + if (test_thread_flag(TIF_32BIT))
6182 + addr &= 0xFFFFFFFFUL;
6183 +
6184 + err = get_user(save, (unsigned int *)addr);
6185 + err |= get_user(call, (unsigned int *)(addr+4));
6186 + err |= get_user(nop, (unsigned int *)(addr+8));
6187 + if (err)
6188 + break;
6189 +
6190 +#ifdef CONFIG_PAX_DLRESOLVE
6191 + if (save == 0x9DE3BFA8U &&
6192 + (call & 0xC0000000U) == 0x40000000U &&
6193 + nop == 0x01000000U)
6194 + {
6195 + struct vm_area_struct *vma;
6196 + unsigned long call_dl_resolve;
6197 +
6198 + down_read(&current->mm->mmap_sem);
6199 + call_dl_resolve = current->mm->call_dl_resolve;
6200 + up_read(&current->mm->mmap_sem);
6201 + if (likely(call_dl_resolve))
6202 + goto emulate;
6203 +
6204 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6205 +
6206 + down_write(&current->mm->mmap_sem);
6207 + if (current->mm->call_dl_resolve) {
6208 + call_dl_resolve = current->mm->call_dl_resolve;
6209 + up_write(&current->mm->mmap_sem);
6210 + if (vma)
6211 + kmem_cache_free(vm_area_cachep, vma);
6212 + goto emulate;
6213 + }
6214 +
6215 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6216 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6217 + up_write(&current->mm->mmap_sem);
6218 + if (vma)
6219 + kmem_cache_free(vm_area_cachep, vma);
6220 + return 1;
6221 + }
6222 +
6223 + if (pax_insert_vma(vma, call_dl_resolve)) {
6224 + up_write(&current->mm->mmap_sem);
6225 + kmem_cache_free(vm_area_cachep, vma);
6226 + return 1;
6227 + }
6228 +
6229 + current->mm->call_dl_resolve = call_dl_resolve;
6230 + up_write(&current->mm->mmap_sem);
6231 +
6232 +emulate:
6233 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6234 + regs->tpc = call_dl_resolve;
6235 + regs->tnpc = addr+4;
6236 + return 3;
6237 + }
6238 +#endif
6239 +
6240 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6241 + if ((save & 0xFFC00000U) == 0x05000000U &&
6242 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6243 + nop == 0x01000000U)
6244 + {
6245 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6246 + regs->u_regs[UREG_G2] = addr + 4;
6247 + addr = (save & 0x003FFFFFU) << 10;
6248 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6249 +
6250 + if (test_thread_flag(TIF_32BIT))
6251 + addr &= 0xFFFFFFFFUL;
6252 +
6253 + regs->tpc = addr;
6254 + regs->tnpc = addr+4;
6255 + return 3;
6256 + }
6257 +
6258 + /* PaX: 64-bit PLT stub */
6259 + err = get_user(sethi1, (unsigned int *)addr);
6260 + err |= get_user(sethi2, (unsigned int *)(addr+4));
6261 + err |= get_user(or1, (unsigned int *)(addr+8));
6262 + err |= get_user(or2, (unsigned int *)(addr+12));
6263 + err |= get_user(sllx, (unsigned int *)(addr+16));
6264 + err |= get_user(add, (unsigned int *)(addr+20));
6265 + err |= get_user(jmpl, (unsigned int *)(addr+24));
6266 + err |= get_user(nop, (unsigned int *)(addr+28));
6267 + if (err)
6268 + break;
6269 +
6270 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6271 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6272 + (or1 & 0xFFFFE000U) == 0x88112000U &&
6273 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6274 + sllx == 0x89293020U &&
6275 + add == 0x8A010005U &&
6276 + jmpl == 0x89C14000U &&
6277 + nop == 0x01000000U)
6278 + {
6279 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6280 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6281 + regs->u_regs[UREG_G4] <<= 32;
6282 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6283 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6284 + regs->u_regs[UREG_G4] = addr + 24;
6285 + addr = regs->u_regs[UREG_G5];
6286 + regs->tpc = addr;
6287 + regs->tnpc = addr+4;
6288 + return 3;
6289 + }
6290 + }
6291 + } while (0);
6292 +
6293 +#ifdef CONFIG_PAX_DLRESOLVE
6294 + do { /* PaX: unpatched PLT emulation step 2 */
6295 + unsigned int save, call, nop;
6296 +
6297 + err = get_user(save, (unsigned int *)(regs->tpc-4));
6298 + err |= get_user(call, (unsigned int *)regs->tpc);
6299 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6300 + if (err)
6301 + break;
6302 +
6303 + if (save == 0x9DE3BFA8U &&
6304 + (call & 0xC0000000U) == 0x40000000U &&
6305 + nop == 0x01000000U)
6306 + {
6307 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6308 +
6309 + if (test_thread_flag(TIF_32BIT))
6310 + dl_resolve &= 0xFFFFFFFFUL;
6311 +
6312 + regs->u_regs[UREG_RETPC] = regs->tpc;
6313 + regs->tpc = dl_resolve;
6314 + regs->tnpc = dl_resolve+4;
6315 + return 3;
6316 + }
6317 + } while (0);
6318 +#endif
6319 +
6320 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6321 + unsigned int sethi, ba, nop;
6322 +
6323 + err = get_user(sethi, (unsigned int *)regs->tpc);
6324 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6325 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6326 +
6327 + if (err)
6328 + break;
6329 +
6330 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6331 + (ba & 0xFFF00000U) == 0x30600000U &&
6332 + nop == 0x01000000U)
6333 + {
6334 + unsigned long addr;
6335 +
6336 + addr = (sethi & 0x003FFFFFU) << 10;
6337 + regs->u_regs[UREG_G1] = addr;
6338 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6339 +
6340 + if (test_thread_flag(TIF_32BIT))
6341 + addr &= 0xFFFFFFFFUL;
6342 +
6343 + regs->tpc = addr;
6344 + regs->tnpc = addr+4;
6345 + return 2;
6346 + }
6347 + } while (0);
6348 +
6349 +#endif
6350 +
6351 + return 1;
6352 +}
6353 +
6354 +void pax_report_insns(void *pc, void *sp)
6355 +{
6356 + unsigned long i;
6357 +
6358 + printk(KERN_ERR "PAX: bytes at PC: ");
6359 + for (i = 0; i < 8; i++) {
6360 + unsigned int c;
6361 + if (get_user(c, (unsigned int *)pc+i))
6362 + printk(KERN_CONT "???????? ");
6363 + else
6364 + printk(KERN_CONT "%08x ", c);
6365 + }
6366 + printk("\n");
6367 +}
6368 +#endif
6369 +
6370 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6371 {
6372 struct mm_struct *mm = current->mm;
6373 @@ -315,6 +768,29 @@ asmlinkage void __kprobes do_sparc64_fau
6374 if (!vma)
6375 goto bad_area;
6376
6377 +#ifdef CONFIG_PAX_PAGEEXEC
6378 + /* PaX: detect ITLB misses on non-exec pages */
6379 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6380 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6381 + {
6382 + if (address != regs->tpc)
6383 + goto good_area;
6384 +
6385 + up_read(&mm->mmap_sem);
6386 + switch (pax_handle_fetch_fault(regs)) {
6387 +
6388 +#ifdef CONFIG_PAX_EMUPLT
6389 + case 2:
6390 + case 3:
6391 + return;
6392 +#endif
6393 +
6394 + }
6395 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6396 + do_group_exit(SIGKILL);
6397 + }
6398 +#endif
6399 +
6400 /* Pure DTLB misses do not tell us whether the fault causing
6401 * load/store/atomic was a write or not, it only says that there
6402 * was no match. So in such a case we (carefully) read the
6403 diff -urNp linux-2.6.32.46/arch/sparc/mm/hugetlbpage.c linux-2.6.32.46/arch/sparc/mm/hugetlbpage.c
6404 --- linux-2.6.32.46/arch/sparc/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
6405 +++ linux-2.6.32.46/arch/sparc/mm/hugetlbpage.c 2011-04-17 15:56:46.000000000 -0400
6406 @@ -69,7 +69,7 @@ full_search:
6407 }
6408 return -ENOMEM;
6409 }
6410 - if (likely(!vma || addr + len <= vma->vm_start)) {
6411 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6412 /*
6413 * Remember the place where we stopped the search:
6414 */
6415 @@ -108,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct
6416 /* make sure it can fit in the remaining address space */
6417 if (likely(addr > len)) {
6418 vma = find_vma(mm, addr-len);
6419 - if (!vma || addr <= vma->vm_start) {
6420 + if (check_heap_stack_gap(vma, addr - len, len)) {
6421 /* remember the address as a hint for next time */
6422 return (mm->free_area_cache = addr-len);
6423 }
6424 @@ -117,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct
6425 if (unlikely(mm->mmap_base < len))
6426 goto bottomup;
6427
6428 - addr = (mm->mmap_base-len) & HPAGE_MASK;
6429 + addr = mm->mmap_base - len;
6430
6431 do {
6432 + addr &= HPAGE_MASK;
6433 /*
6434 * Lookup failure means no vma is above this address,
6435 * else if new region fits below vma->vm_start,
6436 * return with success:
6437 */
6438 vma = find_vma(mm, addr);
6439 - if (likely(!vma || addr+len <= vma->vm_start)) {
6440 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6441 /* remember the address as a hint for next time */
6442 return (mm->free_area_cache = addr);
6443 }
6444 @@ -136,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct
6445 mm->cached_hole_size = vma->vm_start - addr;
6446
6447 /* try just below the current vma->vm_start */
6448 - addr = (vma->vm_start-len) & HPAGE_MASK;
6449 - } while (likely(len < vma->vm_start));
6450 + addr = skip_heap_stack_gap(vma, len);
6451 + } while (!IS_ERR_VALUE(addr));
6452
6453 bottomup:
6454 /*
6455 @@ -183,8 +184,7 @@ hugetlb_get_unmapped_area(struct file *f
6456 if (addr) {
6457 addr = ALIGN(addr, HPAGE_SIZE);
6458 vma = find_vma(mm, addr);
6459 - if (task_size - len >= addr &&
6460 - (!vma || addr + len <= vma->vm_start))
6461 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6462 return addr;
6463 }
6464 if (mm->get_unmapped_area == arch_get_unmapped_area)
6465 diff -urNp linux-2.6.32.46/arch/sparc/mm/init_32.c linux-2.6.32.46/arch/sparc/mm/init_32.c
6466 --- linux-2.6.32.46/arch/sparc/mm/init_32.c 2011-03-27 14:31:47.000000000 -0400
6467 +++ linux-2.6.32.46/arch/sparc/mm/init_32.c 2011-04-17 15:56:46.000000000 -0400
6468 @@ -317,6 +317,9 @@ extern void device_scan(void);
6469 pgprot_t PAGE_SHARED __read_mostly;
6470 EXPORT_SYMBOL(PAGE_SHARED);
6471
6472 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6473 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6474 +
6475 void __init paging_init(void)
6476 {
6477 switch(sparc_cpu_model) {
6478 @@ -345,17 +348,17 @@ void __init paging_init(void)
6479
6480 /* Initialize the protection map with non-constant, MMU dependent values. */
6481 protection_map[0] = PAGE_NONE;
6482 - protection_map[1] = PAGE_READONLY;
6483 - protection_map[2] = PAGE_COPY;
6484 - protection_map[3] = PAGE_COPY;
6485 + protection_map[1] = PAGE_READONLY_NOEXEC;
6486 + protection_map[2] = PAGE_COPY_NOEXEC;
6487 + protection_map[3] = PAGE_COPY_NOEXEC;
6488 protection_map[4] = PAGE_READONLY;
6489 protection_map[5] = PAGE_READONLY;
6490 protection_map[6] = PAGE_COPY;
6491 protection_map[7] = PAGE_COPY;
6492 protection_map[8] = PAGE_NONE;
6493 - protection_map[9] = PAGE_READONLY;
6494 - protection_map[10] = PAGE_SHARED;
6495 - protection_map[11] = PAGE_SHARED;
6496 + protection_map[9] = PAGE_READONLY_NOEXEC;
6497 + protection_map[10] = PAGE_SHARED_NOEXEC;
6498 + protection_map[11] = PAGE_SHARED_NOEXEC;
6499 protection_map[12] = PAGE_READONLY;
6500 protection_map[13] = PAGE_READONLY;
6501 protection_map[14] = PAGE_SHARED;
6502 diff -urNp linux-2.6.32.46/arch/sparc/mm/srmmu.c linux-2.6.32.46/arch/sparc/mm/srmmu.c
6503 --- linux-2.6.32.46/arch/sparc/mm/srmmu.c 2011-03-27 14:31:47.000000000 -0400
6504 +++ linux-2.6.32.46/arch/sparc/mm/srmmu.c 2011-04-17 15:56:46.000000000 -0400
6505 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6506 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6507 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6508 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6509 +
6510 +#ifdef CONFIG_PAX_PAGEEXEC
6511 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6512 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6513 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6514 +#endif
6515 +
6516 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6517 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6518
6519 diff -urNp linux-2.6.32.46/arch/um/include/asm/kmap_types.h linux-2.6.32.46/arch/um/include/asm/kmap_types.h
6520 --- linux-2.6.32.46/arch/um/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
6521 +++ linux-2.6.32.46/arch/um/include/asm/kmap_types.h 2011-04-17 15:56:46.000000000 -0400
6522 @@ -23,6 +23,7 @@ enum km_type {
6523 KM_IRQ1,
6524 KM_SOFTIRQ0,
6525 KM_SOFTIRQ1,
6526 + KM_CLEARPAGE,
6527 KM_TYPE_NR
6528 };
6529
6530 diff -urNp linux-2.6.32.46/arch/um/include/asm/page.h linux-2.6.32.46/arch/um/include/asm/page.h
6531 --- linux-2.6.32.46/arch/um/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
6532 +++ linux-2.6.32.46/arch/um/include/asm/page.h 2011-04-17 15:56:46.000000000 -0400
6533 @@ -14,6 +14,9 @@
6534 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6535 #define PAGE_MASK (~(PAGE_SIZE-1))
6536
6537 +#define ktla_ktva(addr) (addr)
6538 +#define ktva_ktla(addr) (addr)
6539 +
6540 #ifndef __ASSEMBLY__
6541
6542 struct page;
6543 diff -urNp linux-2.6.32.46/arch/um/kernel/process.c linux-2.6.32.46/arch/um/kernel/process.c
6544 --- linux-2.6.32.46/arch/um/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
6545 +++ linux-2.6.32.46/arch/um/kernel/process.c 2011-04-17 15:56:46.000000000 -0400
6546 @@ -393,22 +393,6 @@ int singlestepping(void * t)
6547 return 2;
6548 }
6549
6550 -/*
6551 - * Only x86 and x86_64 have an arch_align_stack().
6552 - * All other arches have "#define arch_align_stack(x) (x)"
6553 - * in their asm/system.h
6554 - * As this is included in UML from asm-um/system-generic.h,
6555 - * we can use it to behave as the subarch does.
6556 - */
6557 -#ifndef arch_align_stack
6558 -unsigned long arch_align_stack(unsigned long sp)
6559 -{
6560 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6561 - sp -= get_random_int() % 8192;
6562 - return sp & ~0xf;
6563 -}
6564 -#endif
6565 -
6566 unsigned long get_wchan(struct task_struct *p)
6567 {
6568 unsigned long stack_page, sp, ip;
6569 diff -urNp linux-2.6.32.46/arch/um/sys-i386/syscalls.c linux-2.6.32.46/arch/um/sys-i386/syscalls.c
6570 --- linux-2.6.32.46/arch/um/sys-i386/syscalls.c 2011-03-27 14:31:47.000000000 -0400
6571 +++ linux-2.6.32.46/arch/um/sys-i386/syscalls.c 2011-04-17 15:56:46.000000000 -0400
6572 @@ -11,6 +11,21 @@
6573 #include "asm/uaccess.h"
6574 #include "asm/unistd.h"
6575
6576 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
6577 +{
6578 + unsigned long pax_task_size = TASK_SIZE;
6579 +
6580 +#ifdef CONFIG_PAX_SEGMEXEC
6581 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
6582 + pax_task_size = SEGMEXEC_TASK_SIZE;
6583 +#endif
6584 +
6585 + if (len > pax_task_size || addr > pax_task_size - len)
6586 + return -EINVAL;
6587 +
6588 + return 0;
6589 +}
6590 +
6591 /*
6592 * Perform the select(nd, in, out, ex, tv) and mmap() system
6593 * calls. Linux/i386 didn't use to be able to handle more than
6594 diff -urNp linux-2.6.32.46/arch/x86/Kconfig linux-2.6.32.46/arch/x86/Kconfig
6595 --- linux-2.6.32.46/arch/x86/Kconfig 2011-03-27 14:31:47.000000000 -0400
6596 +++ linux-2.6.32.46/arch/x86/Kconfig 2011-10-07 08:11:49.000000000 -0400
6597 @@ -223,7 +223,7 @@ config X86_TRAMPOLINE
6598
6599 config X86_32_LAZY_GS
6600 def_bool y
6601 - depends on X86_32 && !CC_STACKPROTECTOR
6602 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
6603
6604 config KTIME_SCALAR
6605 def_bool X86_32
6606 @@ -1008,7 +1008,7 @@ choice
6607
6608 config NOHIGHMEM
6609 bool "off"
6610 - depends on !X86_NUMAQ
6611 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
6612 ---help---
6613 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
6614 However, the address space of 32-bit x86 processors is only 4
6615 @@ -1045,7 +1045,7 @@ config NOHIGHMEM
6616
6617 config HIGHMEM4G
6618 bool "4GB"
6619 - depends on !X86_NUMAQ
6620 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
6621 ---help---
6622 Select this if you have a 32-bit processor and between 1 and 4
6623 gigabytes of physical RAM.
6624 @@ -1099,7 +1099,7 @@ config PAGE_OFFSET
6625 hex
6626 default 0xB0000000 if VMSPLIT_3G_OPT
6627 default 0x80000000 if VMSPLIT_2G
6628 - default 0x78000000 if VMSPLIT_2G_OPT
6629 + default 0x70000000 if VMSPLIT_2G_OPT
6630 default 0x40000000 if VMSPLIT_1G
6631 default 0xC0000000
6632 depends on X86_32
6633 @@ -1460,6 +1460,7 @@ config SECCOMP
6634
6635 config CC_STACKPROTECTOR
6636 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
6637 + depends on X86_64 || !PAX_MEMORY_UDEREF
6638 ---help---
6639 This option turns on the -fstack-protector GCC feature. This
6640 feature puts, at the beginning of functions, a canary value on
6641 @@ -1517,6 +1518,7 @@ config KEXEC_JUMP
6642 config PHYSICAL_START
6643 hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
6644 default "0x1000000"
6645 + range 0x400000 0x40000000
6646 ---help---
6647 This gives the physical address where the kernel is loaded.
6648
6649 @@ -1581,6 +1583,7 @@ config PHYSICAL_ALIGN
6650 hex
6651 prompt "Alignment value to which kernel should be aligned" if X86_32
6652 default "0x1000000"
6653 + range 0x400000 0x1000000 if PAX_KERNEXEC
6654 range 0x2000 0x1000000
6655 ---help---
6656 This value puts the alignment restrictions on physical address
6657 @@ -1612,9 +1615,10 @@ config HOTPLUG_CPU
6658 Say N if you want to disable CPU hotplug.
6659
6660 config COMPAT_VDSO
6661 - def_bool y
6662 + def_bool n
6663 prompt "Compat VDSO support"
6664 depends on X86_32 || IA32_EMULATION
6665 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
6666 ---help---
6667 Map the 32-bit VDSO to the predictable old-style address too.
6668 ---help---
6669 diff -urNp linux-2.6.32.46/arch/x86/Kconfig.cpu linux-2.6.32.46/arch/x86/Kconfig.cpu
6670 --- linux-2.6.32.46/arch/x86/Kconfig.cpu 2011-03-27 14:31:47.000000000 -0400
6671 +++ linux-2.6.32.46/arch/x86/Kconfig.cpu 2011-04-17 15:56:46.000000000 -0400
6672 @@ -340,7 +340,7 @@ config X86_PPRO_FENCE
6673
6674 config X86_F00F_BUG
6675 def_bool y
6676 - depends on M586MMX || M586TSC || M586 || M486 || M386
6677 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
6678
6679 config X86_WP_WORKS_OK
6680 def_bool y
6681 @@ -360,7 +360,7 @@ config X86_POPAD_OK
6682
6683 config X86_ALIGNMENT_16
6684 def_bool y
6685 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
6686 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
6687
6688 config X86_INTEL_USERCOPY
6689 def_bool y
6690 @@ -406,7 +406,7 @@ config X86_CMPXCHG64
6691 # generates cmov.
6692 config X86_CMOV
6693 def_bool y
6694 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
6695 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
6696
6697 config X86_MINIMUM_CPU_FAMILY
6698 int
6699 diff -urNp linux-2.6.32.46/arch/x86/Kconfig.debug linux-2.6.32.46/arch/x86/Kconfig.debug
6700 --- linux-2.6.32.46/arch/x86/Kconfig.debug 2011-03-27 14:31:47.000000000 -0400
6701 +++ linux-2.6.32.46/arch/x86/Kconfig.debug 2011-04-17 15:56:46.000000000 -0400
6702 @@ -99,7 +99,7 @@ config X86_PTDUMP
6703 config DEBUG_RODATA
6704 bool "Write protect kernel read-only data structures"
6705 default y
6706 - depends on DEBUG_KERNEL
6707 + depends on DEBUG_KERNEL && BROKEN
6708 ---help---
6709 Mark the kernel read-only data as write-protected in the pagetables,
6710 in order to catch accidental (and incorrect) writes to such const
6711 diff -urNp linux-2.6.32.46/arch/x86/Makefile linux-2.6.32.46/arch/x86/Makefile
6712 --- linux-2.6.32.46/arch/x86/Makefile 2011-03-27 14:31:47.000000000 -0400
6713 +++ linux-2.6.32.46/arch/x86/Makefile 2011-07-19 18:16:02.000000000 -0400
6714 @@ -44,6 +44,7 @@ ifeq ($(CONFIG_X86_32),y)
6715 else
6716 BITS := 64
6717 UTS_MACHINE := x86_64
6718 + biarch := $(call cc-option,-m64)
6719 CHECKFLAGS += -D__x86_64__ -m64
6720
6721 KBUILD_AFLAGS += -m64
6722 @@ -189,3 +190,12 @@ define archhelp
6723 echo ' FDARGS="..." arguments for the booted kernel'
6724 echo ' FDINITRD=file initrd for the booted kernel'
6725 endef
6726 +
6727 +define OLD_LD
6728 +
6729 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
6730 +*** Please upgrade your binutils to 2.18 or newer
6731 +endef
6732 +
6733 +archprepare:
6734 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
6735 diff -urNp linux-2.6.32.46/arch/x86/boot/Makefile linux-2.6.32.46/arch/x86/boot/Makefile
6736 --- linux-2.6.32.46/arch/x86/boot/Makefile 2011-03-27 14:31:47.000000000 -0400
6737 +++ linux-2.6.32.46/arch/x86/boot/Makefile 2011-08-07 14:38:13.000000000 -0400
6738 @@ -69,6 +69,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os
6739 $(call cc-option, -fno-stack-protector) \
6740 $(call cc-option, -mpreferred-stack-boundary=2)
6741 KBUILD_CFLAGS += $(call cc-option, -m32)
6742 +ifdef CONSTIFY_PLUGIN
6743 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6744 +endif
6745 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
6746 GCOV_PROFILE := n
6747
6748 diff -urNp linux-2.6.32.46/arch/x86/boot/bitops.h linux-2.6.32.46/arch/x86/boot/bitops.h
6749 --- linux-2.6.32.46/arch/x86/boot/bitops.h 2011-03-27 14:31:47.000000000 -0400
6750 +++ linux-2.6.32.46/arch/x86/boot/bitops.h 2011-04-17 15:56:46.000000000 -0400
6751 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int
6752 u8 v;
6753 const u32 *p = (const u32 *)addr;
6754
6755 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
6756 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
6757 return v;
6758 }
6759
6760 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int
6761
6762 static inline void set_bit(int nr, void *addr)
6763 {
6764 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
6765 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
6766 }
6767
6768 #endif /* BOOT_BITOPS_H */
6769 diff -urNp linux-2.6.32.46/arch/x86/boot/boot.h linux-2.6.32.46/arch/x86/boot/boot.h
6770 --- linux-2.6.32.46/arch/x86/boot/boot.h 2011-03-27 14:31:47.000000000 -0400
6771 +++ linux-2.6.32.46/arch/x86/boot/boot.h 2011-04-17 15:56:46.000000000 -0400
6772 @@ -82,7 +82,7 @@ static inline void io_delay(void)
6773 static inline u16 ds(void)
6774 {
6775 u16 seg;
6776 - asm("movw %%ds,%0" : "=rm" (seg));
6777 + asm volatile("movw %%ds,%0" : "=rm" (seg));
6778 return seg;
6779 }
6780
6781 @@ -178,7 +178,7 @@ static inline void wrgs32(u32 v, addr_t
6782 static inline int memcmp(const void *s1, const void *s2, size_t len)
6783 {
6784 u8 diff;
6785 - asm("repe; cmpsb; setnz %0"
6786 + asm volatile("repe; cmpsb; setnz %0"
6787 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
6788 return diff;
6789 }
6790 diff -urNp linux-2.6.32.46/arch/x86/boot/compressed/Makefile linux-2.6.32.46/arch/x86/boot/compressed/Makefile
6791 --- linux-2.6.32.46/arch/x86/boot/compressed/Makefile 2011-03-27 14:31:47.000000000 -0400
6792 +++ linux-2.6.32.46/arch/x86/boot/compressed/Makefile 2011-08-07 14:38:34.000000000 -0400
6793 @@ -13,6 +13,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=smal
6794 KBUILD_CFLAGS += $(cflags-y)
6795 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
6796 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
6797 +ifdef CONSTIFY_PLUGIN
6798 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6799 +endif
6800
6801 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
6802 GCOV_PROFILE := n
6803 diff -urNp linux-2.6.32.46/arch/x86/boot/compressed/head_32.S linux-2.6.32.46/arch/x86/boot/compressed/head_32.S
6804 --- linux-2.6.32.46/arch/x86/boot/compressed/head_32.S 2011-03-27 14:31:47.000000000 -0400
6805 +++ linux-2.6.32.46/arch/x86/boot/compressed/head_32.S 2011-04-17 15:56:46.000000000 -0400
6806 @@ -76,7 +76,7 @@ ENTRY(startup_32)
6807 notl %eax
6808 andl %eax, %ebx
6809 #else
6810 - movl $LOAD_PHYSICAL_ADDR, %ebx
6811 + movl $____LOAD_PHYSICAL_ADDR, %ebx
6812 #endif
6813
6814 /* Target address to relocate to for decompression */
6815 @@ -149,7 +149,7 @@ relocated:
6816 * and where it was actually loaded.
6817 */
6818 movl %ebp, %ebx
6819 - subl $LOAD_PHYSICAL_ADDR, %ebx
6820 + subl $____LOAD_PHYSICAL_ADDR, %ebx
6821 jz 2f /* Nothing to be done if loaded at compiled addr. */
6822 /*
6823 * Process relocations.
6824 @@ -157,8 +157,7 @@ relocated:
6825
6826 1: subl $4, %edi
6827 movl (%edi), %ecx
6828 - testl %ecx, %ecx
6829 - jz 2f
6830 + jecxz 2f
6831 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
6832 jmp 1b
6833 2:
6834 diff -urNp linux-2.6.32.46/arch/x86/boot/compressed/head_64.S linux-2.6.32.46/arch/x86/boot/compressed/head_64.S
6835 --- linux-2.6.32.46/arch/x86/boot/compressed/head_64.S 2011-03-27 14:31:47.000000000 -0400
6836 +++ linux-2.6.32.46/arch/x86/boot/compressed/head_64.S 2011-07-01 18:53:00.000000000 -0400
6837 @@ -91,7 +91,7 @@ ENTRY(startup_32)
6838 notl %eax
6839 andl %eax, %ebx
6840 #else
6841 - movl $LOAD_PHYSICAL_ADDR, %ebx
6842 + movl $____LOAD_PHYSICAL_ADDR, %ebx
6843 #endif
6844
6845 /* Target address to relocate to for decompression */
6846 @@ -183,7 +183,7 @@ no_longmode:
6847 hlt
6848 jmp 1b
6849
6850 -#include "../../kernel/verify_cpu_64.S"
6851 +#include "../../kernel/verify_cpu.S"
6852
6853 /*
6854 * Be careful here startup_64 needs to be at a predictable
6855 @@ -234,7 +234,7 @@ ENTRY(startup_64)
6856 notq %rax
6857 andq %rax, %rbp
6858 #else
6859 - movq $LOAD_PHYSICAL_ADDR, %rbp
6860 + movq $____LOAD_PHYSICAL_ADDR, %rbp
6861 #endif
6862
6863 /* Target address to relocate to for decompression */
6864 diff -urNp linux-2.6.32.46/arch/x86/boot/compressed/misc.c linux-2.6.32.46/arch/x86/boot/compressed/misc.c
6865 --- linux-2.6.32.46/arch/x86/boot/compressed/misc.c 2011-03-27 14:31:47.000000000 -0400
6866 +++ linux-2.6.32.46/arch/x86/boot/compressed/misc.c 2011-04-17 15:56:46.000000000 -0400
6867 @@ -288,7 +288,7 @@ static void parse_elf(void *output)
6868 case PT_LOAD:
6869 #ifdef CONFIG_RELOCATABLE
6870 dest = output;
6871 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
6872 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
6873 #else
6874 dest = (void *)(phdr->p_paddr);
6875 #endif
6876 @@ -335,7 +335,7 @@ asmlinkage void decompress_kernel(void *
6877 error("Destination address too large");
6878 #endif
6879 #ifndef CONFIG_RELOCATABLE
6880 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
6881 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
6882 error("Wrong destination address");
6883 #endif
6884
6885 diff -urNp linux-2.6.32.46/arch/x86/boot/compressed/mkpiggy.c linux-2.6.32.46/arch/x86/boot/compressed/mkpiggy.c
6886 --- linux-2.6.32.46/arch/x86/boot/compressed/mkpiggy.c 2011-03-27 14:31:47.000000000 -0400
6887 +++ linux-2.6.32.46/arch/x86/boot/compressed/mkpiggy.c 2011-04-17 15:56:46.000000000 -0400
6888 @@ -74,7 +74,7 @@ int main(int argc, char *argv[])
6889
6890 offs = (olen > ilen) ? olen - ilen : 0;
6891 offs += olen >> 12; /* Add 8 bytes for each 32K block */
6892 - offs += 32*1024 + 18; /* Add 32K + 18 bytes slack */
6893 + offs += 64*1024; /* Add 64K bytes slack */
6894 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
6895
6896 printf(".section \".rodata.compressed\",\"a\",@progbits\n");
6897 diff -urNp linux-2.6.32.46/arch/x86/boot/compressed/relocs.c linux-2.6.32.46/arch/x86/boot/compressed/relocs.c
6898 --- linux-2.6.32.46/arch/x86/boot/compressed/relocs.c 2011-03-27 14:31:47.000000000 -0400
6899 +++ linux-2.6.32.46/arch/x86/boot/compressed/relocs.c 2011-04-17 15:56:46.000000000 -0400
6900 @@ -10,8 +10,11 @@
6901 #define USE_BSD
6902 #include <endian.h>
6903
6904 +#include "../../../../include/linux/autoconf.h"
6905 +
6906 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
6907 static Elf32_Ehdr ehdr;
6908 +static Elf32_Phdr *phdr;
6909 static unsigned long reloc_count, reloc_idx;
6910 static unsigned long *relocs;
6911
6912 @@ -37,7 +40,7 @@ static const char* safe_abs_relocs[] = {
6913
6914 static int is_safe_abs_reloc(const char* sym_name)
6915 {
6916 - int i;
6917 + unsigned int i;
6918
6919 for (i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) {
6920 if (!strcmp(sym_name, safe_abs_relocs[i]))
6921 @@ -245,9 +248,39 @@ static void read_ehdr(FILE *fp)
6922 }
6923 }
6924
6925 +static void read_phdrs(FILE *fp)
6926 +{
6927 + unsigned int i;
6928 +
6929 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
6930 + if (!phdr) {
6931 + die("Unable to allocate %d program headers\n",
6932 + ehdr.e_phnum);
6933 + }
6934 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
6935 + die("Seek to %d failed: %s\n",
6936 + ehdr.e_phoff, strerror(errno));
6937 + }
6938 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
6939 + die("Cannot read ELF program headers: %s\n",
6940 + strerror(errno));
6941 + }
6942 + for(i = 0; i < ehdr.e_phnum; i++) {
6943 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
6944 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
6945 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
6946 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
6947 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
6948 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
6949 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
6950 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
6951 + }
6952 +
6953 +}
6954 +
6955 static void read_shdrs(FILE *fp)
6956 {
6957 - int i;
6958 + unsigned int i;
6959 Elf32_Shdr shdr;
6960
6961 secs = calloc(ehdr.e_shnum, sizeof(struct section));
6962 @@ -282,7 +315,7 @@ static void read_shdrs(FILE *fp)
6963
6964 static void read_strtabs(FILE *fp)
6965 {
6966 - int i;
6967 + unsigned int i;
6968 for (i = 0; i < ehdr.e_shnum; i++) {
6969 struct section *sec = &secs[i];
6970 if (sec->shdr.sh_type != SHT_STRTAB) {
6971 @@ -307,7 +340,7 @@ static void read_strtabs(FILE *fp)
6972
6973 static void read_symtabs(FILE *fp)
6974 {
6975 - int i,j;
6976 + unsigned int i,j;
6977 for (i = 0; i < ehdr.e_shnum; i++) {
6978 struct section *sec = &secs[i];
6979 if (sec->shdr.sh_type != SHT_SYMTAB) {
6980 @@ -340,7 +373,9 @@ static void read_symtabs(FILE *fp)
6981
6982 static void read_relocs(FILE *fp)
6983 {
6984 - int i,j;
6985 + unsigned int i,j;
6986 + uint32_t base;
6987 +
6988 for (i = 0; i < ehdr.e_shnum; i++) {
6989 struct section *sec = &secs[i];
6990 if (sec->shdr.sh_type != SHT_REL) {
6991 @@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
6992 die("Cannot read symbol table: %s\n",
6993 strerror(errno));
6994 }
6995 + base = 0;
6996 + for (j = 0; j < ehdr.e_phnum; j++) {
6997 + if (phdr[j].p_type != PT_LOAD )
6998 + continue;
6999 + 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)
7000 + continue;
7001 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7002 + break;
7003 + }
7004 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7005 Elf32_Rel *rel = &sec->reltab[j];
7006 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7007 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7008 rel->r_info = elf32_to_cpu(rel->r_info);
7009 }
7010 }
7011 @@ -371,14 +415,14 @@ static void read_relocs(FILE *fp)
7012
7013 static void print_absolute_symbols(void)
7014 {
7015 - int i;
7016 + unsigned int i;
7017 printf("Absolute symbols\n");
7018 printf(" Num: Value Size Type Bind Visibility Name\n");
7019 for (i = 0; i < ehdr.e_shnum; i++) {
7020 struct section *sec = &secs[i];
7021 char *sym_strtab;
7022 Elf32_Sym *sh_symtab;
7023 - int j;
7024 + unsigned int j;
7025
7026 if (sec->shdr.sh_type != SHT_SYMTAB) {
7027 continue;
7028 @@ -406,14 +450,14 @@ static void print_absolute_symbols(void)
7029
7030 static void print_absolute_relocs(void)
7031 {
7032 - int i, printed = 0;
7033 + unsigned int i, printed = 0;
7034
7035 for (i = 0; i < ehdr.e_shnum; i++) {
7036 struct section *sec = &secs[i];
7037 struct section *sec_applies, *sec_symtab;
7038 char *sym_strtab;
7039 Elf32_Sym *sh_symtab;
7040 - int j;
7041 + unsigned int j;
7042 if (sec->shdr.sh_type != SHT_REL) {
7043 continue;
7044 }
7045 @@ -474,13 +518,13 @@ static void print_absolute_relocs(void)
7046
7047 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7048 {
7049 - int i;
7050 + unsigned int i;
7051 /* Walk through the relocations */
7052 for (i = 0; i < ehdr.e_shnum; i++) {
7053 char *sym_strtab;
7054 Elf32_Sym *sh_symtab;
7055 struct section *sec_applies, *sec_symtab;
7056 - int j;
7057 + unsigned int j;
7058 struct section *sec = &secs[i];
7059
7060 if (sec->shdr.sh_type != SHT_REL) {
7061 @@ -504,6 +548,21 @@ static void walk_relocs(void (*visit)(El
7062 if (sym->st_shndx == SHN_ABS) {
7063 continue;
7064 }
7065 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7066 + if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7067 + continue;
7068 +
7069 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7070 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7071 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7072 + continue;
7073 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7074 + continue;
7075 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7076 + continue;
7077 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7078 + continue;
7079 +#endif
7080 if (r_type == R_386_NONE || r_type == R_386_PC32) {
7081 /*
7082 * NONE can be ignored and and PC relative
7083 @@ -541,7 +600,7 @@ static int cmp_relocs(const void *va, co
7084
7085 static void emit_relocs(int as_text)
7086 {
7087 - int i;
7088 + unsigned int i;
7089 /* Count how many relocations I have and allocate space for them. */
7090 reloc_count = 0;
7091 walk_relocs(count_reloc);
7092 @@ -634,6 +693,7 @@ int main(int argc, char **argv)
7093 fname, strerror(errno));
7094 }
7095 read_ehdr(fp);
7096 + read_phdrs(fp);
7097 read_shdrs(fp);
7098 read_strtabs(fp);
7099 read_symtabs(fp);
7100 diff -urNp linux-2.6.32.46/arch/x86/boot/cpucheck.c linux-2.6.32.46/arch/x86/boot/cpucheck.c
7101 --- linux-2.6.32.46/arch/x86/boot/cpucheck.c 2011-03-27 14:31:47.000000000 -0400
7102 +++ linux-2.6.32.46/arch/x86/boot/cpucheck.c 2011-04-17 15:56:46.000000000 -0400
7103 @@ -74,7 +74,7 @@ static int has_fpu(void)
7104 u16 fcw = -1, fsw = -1;
7105 u32 cr0;
7106
7107 - asm("movl %%cr0,%0" : "=r" (cr0));
7108 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7109 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7110 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7111 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7112 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7113 {
7114 u32 f0, f1;
7115
7116 - asm("pushfl ; "
7117 + asm volatile("pushfl ; "
7118 "pushfl ; "
7119 "popl %0 ; "
7120 "movl %0,%1 ; "
7121 @@ -115,7 +115,7 @@ static void get_flags(void)
7122 set_bit(X86_FEATURE_FPU, cpu.flags);
7123
7124 if (has_eflag(X86_EFLAGS_ID)) {
7125 - asm("cpuid"
7126 + asm volatile("cpuid"
7127 : "=a" (max_intel_level),
7128 "=b" (cpu_vendor[0]),
7129 "=d" (cpu_vendor[1]),
7130 @@ -124,7 +124,7 @@ static void get_flags(void)
7131
7132 if (max_intel_level >= 0x00000001 &&
7133 max_intel_level <= 0x0000ffff) {
7134 - asm("cpuid"
7135 + asm volatile("cpuid"
7136 : "=a" (tfms),
7137 "=c" (cpu.flags[4]),
7138 "=d" (cpu.flags[0])
7139 @@ -136,7 +136,7 @@ static void get_flags(void)
7140 cpu.model += ((tfms >> 16) & 0xf) << 4;
7141 }
7142
7143 - asm("cpuid"
7144 + asm volatile("cpuid"
7145 : "=a" (max_amd_level)
7146 : "a" (0x80000000)
7147 : "ebx", "ecx", "edx");
7148 @@ -144,7 +144,7 @@ static void get_flags(void)
7149 if (max_amd_level >= 0x80000001 &&
7150 max_amd_level <= 0x8000ffff) {
7151 u32 eax = 0x80000001;
7152 - asm("cpuid"
7153 + asm volatile("cpuid"
7154 : "+a" (eax),
7155 "=c" (cpu.flags[6]),
7156 "=d" (cpu.flags[1])
7157 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7158 u32 ecx = MSR_K7_HWCR;
7159 u32 eax, edx;
7160
7161 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7162 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7163 eax &= ~(1 << 15);
7164 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7165 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7166
7167 get_flags(); /* Make sure it really did something */
7168 err = check_flags();
7169 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7170 u32 ecx = MSR_VIA_FCR;
7171 u32 eax, edx;
7172
7173 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7174 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7175 eax |= (1<<1)|(1<<7);
7176 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7177 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7178
7179 set_bit(X86_FEATURE_CX8, cpu.flags);
7180 err = check_flags();
7181 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
7182 u32 eax, edx;
7183 u32 level = 1;
7184
7185 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7186 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7187 - asm("cpuid"
7188 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7189 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7190 + asm volatile("cpuid"
7191 : "+a" (level), "=d" (cpu.flags[0])
7192 : : "ecx", "ebx");
7193 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7194 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7195
7196 err = check_flags();
7197 }
7198 diff -urNp linux-2.6.32.46/arch/x86/boot/header.S linux-2.6.32.46/arch/x86/boot/header.S
7199 --- linux-2.6.32.46/arch/x86/boot/header.S 2011-03-27 14:31:47.000000000 -0400
7200 +++ linux-2.6.32.46/arch/x86/boot/header.S 2011-04-17 15:56:46.000000000 -0400
7201 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
7202 # single linked list of
7203 # struct setup_data
7204
7205 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7206 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7207
7208 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7209 #define VO_INIT_SIZE (VO__end - VO__text)
7210 diff -urNp linux-2.6.32.46/arch/x86/boot/memory.c linux-2.6.32.46/arch/x86/boot/memory.c
7211 --- linux-2.6.32.46/arch/x86/boot/memory.c 2011-03-27 14:31:47.000000000 -0400
7212 +++ linux-2.6.32.46/arch/x86/boot/memory.c 2011-04-17 15:56:46.000000000 -0400
7213 @@ -19,7 +19,7 @@
7214
7215 static int detect_memory_e820(void)
7216 {
7217 - int count = 0;
7218 + unsigned int count = 0;
7219 struct biosregs ireg, oreg;
7220 struct e820entry *desc = boot_params.e820_map;
7221 static struct e820entry buf; /* static so it is zeroed */
7222 diff -urNp linux-2.6.32.46/arch/x86/boot/video-vesa.c linux-2.6.32.46/arch/x86/boot/video-vesa.c
7223 --- linux-2.6.32.46/arch/x86/boot/video-vesa.c 2011-03-27 14:31:47.000000000 -0400
7224 +++ linux-2.6.32.46/arch/x86/boot/video-vesa.c 2011-04-17 15:56:46.000000000 -0400
7225 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7226
7227 boot_params.screen_info.vesapm_seg = oreg.es;
7228 boot_params.screen_info.vesapm_off = oreg.di;
7229 + boot_params.screen_info.vesapm_size = oreg.cx;
7230 }
7231
7232 /*
7233 diff -urNp linux-2.6.32.46/arch/x86/boot/video.c linux-2.6.32.46/arch/x86/boot/video.c
7234 --- linux-2.6.32.46/arch/x86/boot/video.c 2011-03-27 14:31:47.000000000 -0400
7235 +++ linux-2.6.32.46/arch/x86/boot/video.c 2011-04-17 15:56:46.000000000 -0400
7236 @@ -90,7 +90,7 @@ static void store_mode_params(void)
7237 static unsigned int get_entry(void)
7238 {
7239 char entry_buf[4];
7240 - int i, len = 0;
7241 + unsigned int i, len = 0;
7242 int key;
7243 unsigned int v;
7244
7245 diff -urNp linux-2.6.32.46/arch/x86/crypto/aes-x86_64-asm_64.S linux-2.6.32.46/arch/x86/crypto/aes-x86_64-asm_64.S
7246 --- linux-2.6.32.46/arch/x86/crypto/aes-x86_64-asm_64.S 2011-03-27 14:31:47.000000000 -0400
7247 +++ linux-2.6.32.46/arch/x86/crypto/aes-x86_64-asm_64.S 2011-10-06 09:37:14.000000000 -0400
7248 @@ -8,6 +8,8 @@
7249 * including this sentence is retained in full.
7250 */
7251
7252 +#include <asm/alternative-asm.h>
7253 +
7254 .extern crypto_ft_tab
7255 .extern crypto_it_tab
7256 .extern crypto_fl_tab
7257 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7258 je B192; \
7259 leaq 32(r9),r9;
7260
7261 +#define ret pax_force_retaddr; ret
7262 +
7263 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7264 movq r1,r2; \
7265 movq r3,r4; \
7266 diff -urNp linux-2.6.32.46/arch/x86/crypto/salsa20-x86_64-asm_64.S linux-2.6.32.46/arch/x86/crypto/salsa20-x86_64-asm_64.S
7267 --- linux-2.6.32.46/arch/x86/crypto/salsa20-x86_64-asm_64.S 2011-03-27 14:31:47.000000000 -0400
7268 +++ linux-2.6.32.46/arch/x86/crypto/salsa20-x86_64-asm_64.S 2011-10-06 09:37:14.000000000 -0400
7269 @@ -1,3 +1,5 @@
7270 +#include <asm/alternative-asm.h>
7271 +
7272 # enter ECRYPT_encrypt_bytes
7273 .text
7274 .p2align 5
7275 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
7276 add %r11,%rsp
7277 mov %rdi,%rax
7278 mov %rsi,%rdx
7279 + pax_force_retaddr
7280 ret
7281 # bytesatleast65:
7282 ._bytesatleast65:
7283 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
7284 add %r11,%rsp
7285 mov %rdi,%rax
7286 mov %rsi,%rdx
7287 + pax_force_retaddr
7288 ret
7289 # enter ECRYPT_ivsetup
7290 .text
7291 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
7292 add %r11,%rsp
7293 mov %rdi,%rax
7294 mov %rsi,%rdx
7295 + pax_force_retaddr
7296 ret
7297 diff -urNp linux-2.6.32.46/arch/x86/crypto/twofish-x86_64-asm_64.S linux-2.6.32.46/arch/x86/crypto/twofish-x86_64-asm_64.S
7298 --- linux-2.6.32.46/arch/x86/crypto/twofish-x86_64-asm_64.S 2011-03-27 14:31:47.000000000 -0400
7299 +++ linux-2.6.32.46/arch/x86/crypto/twofish-x86_64-asm_64.S 2011-10-06 09:37:14.000000000 -0400
7300 @@ -21,6 +21,7 @@
7301 .text
7302
7303 #include <asm/asm-offsets.h>
7304 +#include <asm/alternative-asm.h>
7305
7306 #define a_offset 0
7307 #define b_offset 4
7308 @@ -269,6 +270,7 @@ twofish_enc_blk:
7309
7310 popq R1
7311 movq $1,%rax
7312 + pax_force_retaddr
7313 ret
7314
7315 twofish_dec_blk:
7316 @@ -321,4 +323,5 @@ twofish_dec_blk:
7317
7318 popq R1
7319 movq $1,%rax
7320 + pax_force_retaddr
7321 ret
7322 diff -urNp linux-2.6.32.46/arch/x86/ia32/ia32_aout.c linux-2.6.32.46/arch/x86/ia32/ia32_aout.c
7323 --- linux-2.6.32.46/arch/x86/ia32/ia32_aout.c 2011-03-27 14:31:47.000000000 -0400
7324 +++ linux-2.6.32.46/arch/x86/ia32/ia32_aout.c 2011-04-17 15:56:46.000000000 -0400
7325 @@ -169,6 +169,8 @@ static int aout_core_dump(long signr, st
7326 unsigned long dump_start, dump_size;
7327 struct user32 dump;
7328
7329 + memset(&dump, 0, sizeof(dump));
7330 +
7331 fs = get_fs();
7332 set_fs(KERNEL_DS);
7333 has_dumped = 1;
7334 @@ -218,12 +220,6 @@ static int aout_core_dump(long signr, st
7335 dump_size = dump.u_ssize << PAGE_SHIFT;
7336 DUMP_WRITE(dump_start, dump_size);
7337 }
7338 - /*
7339 - * Finally dump the task struct. Not be used by gdb, but
7340 - * could be useful
7341 - */
7342 - set_fs(KERNEL_DS);
7343 - DUMP_WRITE(current, sizeof(*current));
7344 end_coredump:
7345 set_fs(fs);
7346 return has_dumped;
7347 diff -urNp linux-2.6.32.46/arch/x86/ia32/ia32_signal.c linux-2.6.32.46/arch/x86/ia32/ia32_signal.c
7348 --- linux-2.6.32.46/arch/x86/ia32/ia32_signal.c 2011-03-27 14:31:47.000000000 -0400
7349 +++ linux-2.6.32.46/arch/x86/ia32/ia32_signal.c 2011-10-06 09:37:08.000000000 -0400
7350 @@ -167,7 +167,7 @@ asmlinkage long sys32_sigaltstack(const
7351 }
7352 seg = get_fs();
7353 set_fs(KERNEL_DS);
7354 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
7355 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
7356 set_fs(seg);
7357 if (ret >= 0 && uoss_ptr) {
7358 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
7359 @@ -374,7 +374,7 @@ static int ia32_setup_sigcontext(struct
7360 */
7361 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7362 size_t frame_size,
7363 - void **fpstate)
7364 + void __user **fpstate)
7365 {
7366 unsigned long sp;
7367
7368 @@ -395,7 +395,7 @@ static void __user *get_sigframe(struct
7369
7370 if (used_math()) {
7371 sp = sp - sig_xstate_ia32_size;
7372 - *fpstate = (struct _fpstate_ia32 *) sp;
7373 + *fpstate = (struct _fpstate_ia32 __user *) sp;
7374 if (save_i387_xstate_ia32(*fpstate) < 0)
7375 return (void __user *) -1L;
7376 }
7377 @@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
7378 sp -= frame_size;
7379 /* Align the stack pointer according to the i386 ABI,
7380 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
7381 - sp = ((sp + 4) & -16ul) - 4;
7382 + sp = ((sp - 12) & -16ul) - 4;
7383 return (void __user *) sp;
7384 }
7385
7386 @@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
7387 * These are actually not used anymore, but left because some
7388 * gdb versions depend on them as a marker.
7389 */
7390 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
7391 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
7392 } put_user_catch(err);
7393
7394 if (err)
7395 @@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
7396 0xb8,
7397 __NR_ia32_rt_sigreturn,
7398 0x80cd,
7399 - 0,
7400 + 0
7401 };
7402
7403 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
7404 @@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
7405
7406 if (ka->sa.sa_flags & SA_RESTORER)
7407 restorer = ka->sa.sa_restorer;
7408 + else if (current->mm->context.vdso)
7409 + /* Return stub is in 32bit vsyscall page */
7410 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
7411 else
7412 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
7413 - rt_sigreturn);
7414 + restorer = &frame->retcode;
7415 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
7416
7417 /*
7418 * Not actually used anymore, but left because some gdb
7419 * versions need it.
7420 */
7421 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
7422 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
7423 } put_user_catch(err);
7424
7425 if (err)
7426 diff -urNp linux-2.6.32.46/arch/x86/ia32/ia32entry.S linux-2.6.32.46/arch/x86/ia32/ia32entry.S
7427 --- linux-2.6.32.46/arch/x86/ia32/ia32entry.S 2011-03-27 14:31:47.000000000 -0400
7428 +++ linux-2.6.32.46/arch/x86/ia32/ia32entry.S 2011-08-25 17:42:18.000000000 -0400
7429 @@ -13,6 +13,7 @@
7430 #include <asm/thread_info.h>
7431 #include <asm/segment.h>
7432 #include <asm/irqflags.h>
7433 +#include <asm/pgtable.h>
7434 #include <linux/linkage.h>
7435
7436 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
7437 @@ -93,6 +94,29 @@ ENTRY(native_irq_enable_sysexit)
7438 ENDPROC(native_irq_enable_sysexit)
7439 #endif
7440
7441 + .macro pax_enter_kernel_user
7442 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7443 + call pax_enter_kernel_user
7444 +#endif
7445 + .endm
7446 +
7447 + .macro pax_exit_kernel_user
7448 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7449 + call pax_exit_kernel_user
7450 +#endif
7451 +#ifdef CONFIG_PAX_RANDKSTACK
7452 + pushq %rax
7453 + call pax_randomize_kstack
7454 + popq %rax
7455 +#endif
7456 + .endm
7457 +
7458 +.macro pax_erase_kstack
7459 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7460 + call pax_erase_kstack
7461 +#endif
7462 +.endm
7463 +
7464 /*
7465 * 32bit SYSENTER instruction entry.
7466 *
7467 @@ -119,7 +143,7 @@ ENTRY(ia32_sysenter_target)
7468 CFI_REGISTER rsp,rbp
7469 SWAPGS_UNSAFE_STACK
7470 movq PER_CPU_VAR(kernel_stack), %rsp
7471 - addq $(KERNEL_STACK_OFFSET),%rsp
7472 + pax_enter_kernel_user
7473 /*
7474 * No need to follow this irqs on/off section: the syscall
7475 * disabled irqs, here we enable it straight after entry:
7476 @@ -135,7 +159,8 @@ ENTRY(ia32_sysenter_target)
7477 pushfq
7478 CFI_ADJUST_CFA_OFFSET 8
7479 /*CFI_REL_OFFSET rflags,0*/
7480 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
7481 + GET_THREAD_INFO(%r10)
7482 + movl TI_sysenter_return(%r10), %r10d
7483 CFI_REGISTER rip,r10
7484 pushq $__USER32_CS
7485 CFI_ADJUST_CFA_OFFSET 8
7486 @@ -150,6 +175,12 @@ ENTRY(ia32_sysenter_target)
7487 SAVE_ARGS 0,0,1
7488 /* no need to do an access_ok check here because rbp has been
7489 32bit zero extended */
7490 +
7491 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7492 + mov $PAX_USER_SHADOW_BASE,%r10
7493 + add %r10,%rbp
7494 +#endif
7495 +
7496 1: movl (%rbp),%ebp
7497 .section __ex_table,"a"
7498 .quad 1b,ia32_badarg
7499 @@ -172,6 +203,8 @@ sysenter_dispatch:
7500 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
7501 jnz sysexit_audit
7502 sysexit_from_sys_call:
7503 + pax_exit_kernel_user
7504 + pax_erase_kstack
7505 andl $~TS_COMPAT,TI_status(%r10)
7506 /* clear IF, that popfq doesn't enable interrupts early */
7507 andl $~0x200,EFLAGS-R11(%rsp)
7508 @@ -200,6 +233,9 @@ sysexit_from_sys_call:
7509 movl %eax,%esi /* 2nd arg: syscall number */
7510 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
7511 call audit_syscall_entry
7512 +
7513 + pax_erase_kstack
7514 +
7515 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
7516 cmpq $(IA32_NR_syscalls-1),%rax
7517 ja ia32_badsys
7518 @@ -252,6 +288,9 @@ sysenter_tracesys:
7519 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
7520 movq %rsp,%rdi /* &pt_regs -> arg1 */
7521 call syscall_trace_enter
7522 +
7523 + pax_erase_kstack
7524 +
7525 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
7526 RESTORE_REST
7527 cmpq $(IA32_NR_syscalls-1),%rax
7528 @@ -283,19 +322,24 @@ ENDPROC(ia32_sysenter_target)
7529 ENTRY(ia32_cstar_target)
7530 CFI_STARTPROC32 simple
7531 CFI_SIGNAL_FRAME
7532 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
7533 + CFI_DEF_CFA rsp,0
7534 CFI_REGISTER rip,rcx
7535 /*CFI_REGISTER rflags,r11*/
7536 SWAPGS_UNSAFE_STACK
7537 movl %esp,%r8d
7538 CFI_REGISTER rsp,r8
7539 movq PER_CPU_VAR(kernel_stack),%rsp
7540 +
7541 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7542 + pax_enter_kernel_user
7543 +#endif
7544 +
7545 /*
7546 * No need to follow this irqs on/off section: the syscall
7547 * disabled irqs and here we enable it straight after entry:
7548 */
7549 ENABLE_INTERRUPTS(CLBR_NONE)
7550 - SAVE_ARGS 8,1,1
7551 + SAVE_ARGS 8*6,1,1
7552 movl %eax,%eax /* zero extension */
7553 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
7554 movq %rcx,RIP-ARGOFFSET(%rsp)
7555 @@ -311,6 +355,12 @@ ENTRY(ia32_cstar_target)
7556 /* no need to do an access_ok check here because r8 has been
7557 32bit zero extended */
7558 /* hardware stack frame is complete now */
7559 +
7560 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7561 + mov $PAX_USER_SHADOW_BASE,%r10
7562 + add %r10,%r8
7563 +#endif
7564 +
7565 1: movl (%r8),%r9d
7566 .section __ex_table,"a"
7567 .quad 1b,ia32_badarg
7568 @@ -333,6 +383,8 @@ cstar_dispatch:
7569 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
7570 jnz sysretl_audit
7571 sysretl_from_sys_call:
7572 + pax_exit_kernel_user
7573 + pax_erase_kstack
7574 andl $~TS_COMPAT,TI_status(%r10)
7575 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
7576 movl RIP-ARGOFFSET(%rsp),%ecx
7577 @@ -370,6 +422,9 @@ cstar_tracesys:
7578 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
7579 movq %rsp,%rdi /* &pt_regs -> arg1 */
7580 call syscall_trace_enter
7581 +
7582 + pax_erase_kstack
7583 +
7584 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
7585 RESTORE_REST
7586 xchgl %ebp,%r9d
7587 @@ -415,6 +470,7 @@ ENTRY(ia32_syscall)
7588 CFI_REL_OFFSET rip,RIP-RIP
7589 PARAVIRT_ADJUST_EXCEPTION_FRAME
7590 SWAPGS
7591 + pax_enter_kernel_user
7592 /*
7593 * No need to follow this irqs on/off section: the syscall
7594 * disabled irqs and here we enable it straight after entry:
7595 @@ -448,6 +504,9 @@ ia32_tracesys:
7596 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
7597 movq %rsp,%rdi /* &pt_regs -> arg1 */
7598 call syscall_trace_enter
7599 +
7600 + pax_erase_kstack
7601 +
7602 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
7603 RESTORE_REST
7604 cmpq $(IA32_NR_syscalls-1),%rax
7605 diff -urNp linux-2.6.32.46/arch/x86/ia32/sys_ia32.c linux-2.6.32.46/arch/x86/ia32/sys_ia32.c
7606 --- linux-2.6.32.46/arch/x86/ia32/sys_ia32.c 2011-03-27 14:31:47.000000000 -0400
7607 +++ linux-2.6.32.46/arch/x86/ia32/sys_ia32.c 2011-10-06 09:37:14.000000000 -0400
7608 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsign
7609 */
7610 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
7611 {
7612 - typeof(ubuf->st_uid) uid = 0;
7613 - typeof(ubuf->st_gid) gid = 0;
7614 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
7615 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
7616 SET_UID(uid, stat->uid);
7617 SET_GID(gid, stat->gid);
7618 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
7619 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int
7620 }
7621 set_fs(KERNEL_DS);
7622 ret = sys_rt_sigprocmask(how,
7623 - set ? (sigset_t __user *)&s : NULL,
7624 - oset ? (sigset_t __user *)&s : NULL,
7625 + set ? (sigset_t __force_user *)&s : NULL,
7626 + oset ? (sigset_t __force_user *)&s : NULL,
7627 sigsetsize);
7628 set_fs(old_fs);
7629 if (ret)
7630 @@ -371,7 +371,7 @@ asmlinkage long sys32_sched_rr_get_inter
7631 mm_segment_t old_fs = get_fs();
7632
7633 set_fs(KERNEL_DS);
7634 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
7635 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
7636 set_fs(old_fs);
7637 if (put_compat_timespec(&t, interval))
7638 return -EFAULT;
7639 @@ -387,7 +387,7 @@ asmlinkage long sys32_rt_sigpending(comp
7640 mm_segment_t old_fs = get_fs();
7641
7642 set_fs(KERNEL_DS);
7643 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
7644 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
7645 set_fs(old_fs);
7646 if (!ret) {
7647 switch (_NSIG_WORDS) {
7648 @@ -412,7 +412,7 @@ asmlinkage long sys32_rt_sigqueueinfo(in
7649 if (copy_siginfo_from_user32(&info, uinfo))
7650 return -EFAULT;
7651 set_fs(KERNEL_DS);
7652 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
7653 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
7654 set_fs(old_fs);
7655 return ret;
7656 }
7657 @@ -513,7 +513,7 @@ asmlinkage long sys32_sendfile(int out_f
7658 return -EFAULT;
7659
7660 set_fs(KERNEL_DS);
7661 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
7662 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
7663 count);
7664 set_fs(old_fs);
7665
7666 diff -urNp linux-2.6.32.46/arch/x86/include/asm/alternative-asm.h linux-2.6.32.46/arch/x86/include/asm/alternative-asm.h
7667 --- linux-2.6.32.46/arch/x86/include/asm/alternative-asm.h 2011-03-27 14:31:47.000000000 -0400
7668 +++ linux-2.6.32.46/arch/x86/include/asm/alternative-asm.h 2011-10-08 08:14:37.000000000 -0400
7669 @@ -19,4 +19,18 @@
7670 .endm
7671 #endif
7672
7673 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
7674 + .macro pax_force_retaddr rip=0
7675 + btsq $63,\rip(%rsp)
7676 + .endm
7677 + .macro pax_force_fptr ptr
7678 + btsq $63,\ptr
7679 + .endm
7680 +#else
7681 + .macro pax_force_retaddr rip=0
7682 + .endm
7683 + .macro pax_force_fptr ptr
7684 + .endm
7685 +#endif
7686 +
7687 #endif /* __ASSEMBLY__ */
7688 diff -urNp linux-2.6.32.46/arch/x86/include/asm/alternative.h linux-2.6.32.46/arch/x86/include/asm/alternative.h
7689 --- linux-2.6.32.46/arch/x86/include/asm/alternative.h 2011-03-27 14:31:47.000000000 -0400
7690 +++ linux-2.6.32.46/arch/x86/include/asm/alternative.h 2011-04-17 15:56:46.000000000 -0400
7691 @@ -85,7 +85,7 @@ static inline void alternatives_smp_swit
7692 " .byte 662b-661b\n" /* sourcelen */ \
7693 " .byte 664f-663f\n" /* replacementlen */ \
7694 ".previous\n" \
7695 - ".section .altinstr_replacement, \"ax\"\n" \
7696 + ".section .altinstr_replacement, \"a\"\n" \
7697 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
7698 ".previous"
7699
7700 diff -urNp linux-2.6.32.46/arch/x86/include/asm/apic.h linux-2.6.32.46/arch/x86/include/asm/apic.h
7701 --- linux-2.6.32.46/arch/x86/include/asm/apic.h 2011-03-27 14:31:47.000000000 -0400
7702 +++ linux-2.6.32.46/arch/x86/include/asm/apic.h 2011-08-17 20:01:15.000000000 -0400
7703 @@ -46,7 +46,7 @@ static inline void generic_apic_probe(vo
7704
7705 #ifdef CONFIG_X86_LOCAL_APIC
7706
7707 -extern unsigned int apic_verbosity;
7708 +extern int apic_verbosity;
7709 extern int local_apic_timer_c2_ok;
7710
7711 extern int disable_apic;
7712 diff -urNp linux-2.6.32.46/arch/x86/include/asm/apm.h linux-2.6.32.46/arch/x86/include/asm/apm.h
7713 --- linux-2.6.32.46/arch/x86/include/asm/apm.h 2011-03-27 14:31:47.000000000 -0400
7714 +++ linux-2.6.32.46/arch/x86/include/asm/apm.h 2011-04-17 15:56:46.000000000 -0400
7715 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
7716 __asm__ __volatile__(APM_DO_ZERO_SEGS
7717 "pushl %%edi\n\t"
7718 "pushl %%ebp\n\t"
7719 - "lcall *%%cs:apm_bios_entry\n\t"
7720 + "lcall *%%ss:apm_bios_entry\n\t"
7721 "setc %%al\n\t"
7722 "popl %%ebp\n\t"
7723 "popl %%edi\n\t"
7724 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
7725 __asm__ __volatile__(APM_DO_ZERO_SEGS
7726 "pushl %%edi\n\t"
7727 "pushl %%ebp\n\t"
7728 - "lcall *%%cs:apm_bios_entry\n\t"
7729 + "lcall *%%ss:apm_bios_entry\n\t"
7730 "setc %%bl\n\t"
7731 "popl %%ebp\n\t"
7732 "popl %%edi\n\t"
7733 diff -urNp linux-2.6.32.46/arch/x86/include/asm/atomic_32.h linux-2.6.32.46/arch/x86/include/asm/atomic_32.h
7734 --- linux-2.6.32.46/arch/x86/include/asm/atomic_32.h 2011-03-27 14:31:47.000000000 -0400
7735 +++ linux-2.6.32.46/arch/x86/include/asm/atomic_32.h 2011-05-04 17:56:20.000000000 -0400
7736 @@ -25,6 +25,17 @@ static inline int atomic_read(const atom
7737 }
7738
7739 /**
7740 + * atomic_read_unchecked - read atomic variable
7741 + * @v: pointer of type atomic_unchecked_t
7742 + *
7743 + * Atomically reads the value of @v.
7744 + */
7745 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7746 +{
7747 + return v->counter;
7748 +}
7749 +
7750 +/**
7751 * atomic_set - set atomic variable
7752 * @v: pointer of type atomic_t
7753 * @i: required value
7754 @@ -37,6 +48,18 @@ static inline void atomic_set(atomic_t *
7755 }
7756
7757 /**
7758 + * atomic_set_unchecked - set atomic variable
7759 + * @v: pointer of type atomic_unchecked_t
7760 + * @i: required value
7761 + *
7762 + * Atomically sets the value of @v to @i.
7763 + */
7764 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7765 +{
7766 + v->counter = i;
7767 +}
7768 +
7769 +/**
7770 * atomic_add - add integer to atomic variable
7771 * @i: integer value to add
7772 * @v: pointer of type atomic_t
7773 @@ -45,7 +68,29 @@ static inline void atomic_set(atomic_t *
7774 */
7775 static inline void atomic_add(int i, atomic_t *v)
7776 {
7777 - asm volatile(LOCK_PREFIX "addl %1,%0"
7778 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7779 +
7780 +#ifdef CONFIG_PAX_REFCOUNT
7781 + "jno 0f\n"
7782 + LOCK_PREFIX "subl %1,%0\n"
7783 + "int $4\n0:\n"
7784 + _ASM_EXTABLE(0b, 0b)
7785 +#endif
7786 +
7787 + : "+m" (v->counter)
7788 + : "ir" (i));
7789 +}
7790 +
7791 +/**
7792 + * atomic_add_unchecked - add integer to atomic variable
7793 + * @i: integer value to add
7794 + * @v: pointer of type atomic_unchecked_t
7795 + *
7796 + * Atomically adds @i to @v.
7797 + */
7798 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
7799 +{
7800 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7801 : "+m" (v->counter)
7802 : "ir" (i));
7803 }
7804 @@ -59,7 +104,29 @@ static inline void atomic_add(int i, ato
7805 */
7806 static inline void atomic_sub(int i, atomic_t *v)
7807 {
7808 - asm volatile(LOCK_PREFIX "subl %1,%0"
7809 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7810 +
7811 +#ifdef CONFIG_PAX_REFCOUNT
7812 + "jno 0f\n"
7813 + LOCK_PREFIX "addl %1,%0\n"
7814 + "int $4\n0:\n"
7815 + _ASM_EXTABLE(0b, 0b)
7816 +#endif
7817 +
7818 + : "+m" (v->counter)
7819 + : "ir" (i));
7820 +}
7821 +
7822 +/**
7823 + * atomic_sub_unchecked - subtract integer from atomic variable
7824 + * @i: integer value to subtract
7825 + * @v: pointer of type atomic_unchecked_t
7826 + *
7827 + * Atomically subtracts @i from @v.
7828 + */
7829 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7830 +{
7831 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7832 : "+m" (v->counter)
7833 : "ir" (i));
7834 }
7835 @@ -77,7 +144,16 @@ static inline int atomic_sub_and_test(in
7836 {
7837 unsigned char c;
7838
7839 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7840 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
7841 +
7842 +#ifdef CONFIG_PAX_REFCOUNT
7843 + "jno 0f\n"
7844 + LOCK_PREFIX "addl %2,%0\n"
7845 + "int $4\n0:\n"
7846 + _ASM_EXTABLE(0b, 0b)
7847 +#endif
7848 +
7849 + "sete %1\n"
7850 : "+m" (v->counter), "=qm" (c)
7851 : "ir" (i) : "memory");
7852 return c;
7853 @@ -91,7 +167,27 @@ static inline int atomic_sub_and_test(in
7854 */
7855 static inline void atomic_inc(atomic_t *v)
7856 {
7857 - asm volatile(LOCK_PREFIX "incl %0"
7858 + asm volatile(LOCK_PREFIX "incl %0\n"
7859 +
7860 +#ifdef CONFIG_PAX_REFCOUNT
7861 + "jno 0f\n"
7862 + LOCK_PREFIX "decl %0\n"
7863 + "int $4\n0:\n"
7864 + _ASM_EXTABLE(0b, 0b)
7865 +#endif
7866 +
7867 + : "+m" (v->counter));
7868 +}
7869 +
7870 +/**
7871 + * atomic_inc_unchecked - increment atomic variable
7872 + * @v: pointer of type atomic_unchecked_t
7873 + *
7874 + * Atomically increments @v by 1.
7875 + */
7876 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7877 +{
7878 + asm volatile(LOCK_PREFIX "incl %0\n"
7879 : "+m" (v->counter));
7880 }
7881
7882 @@ -103,7 +199,27 @@ static inline void atomic_inc(atomic_t *
7883 */
7884 static inline void atomic_dec(atomic_t *v)
7885 {
7886 - asm volatile(LOCK_PREFIX "decl %0"
7887 + asm volatile(LOCK_PREFIX "decl %0\n"
7888 +
7889 +#ifdef CONFIG_PAX_REFCOUNT
7890 + "jno 0f\n"
7891 + LOCK_PREFIX "incl %0\n"
7892 + "int $4\n0:\n"
7893 + _ASM_EXTABLE(0b, 0b)
7894 +#endif
7895 +
7896 + : "+m" (v->counter));
7897 +}
7898 +
7899 +/**
7900 + * atomic_dec_unchecked - decrement atomic variable
7901 + * @v: pointer of type atomic_unchecked_t
7902 + *
7903 + * Atomically decrements @v by 1.
7904 + */
7905 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7906 +{
7907 + asm volatile(LOCK_PREFIX "decl %0\n"
7908 : "+m" (v->counter));
7909 }
7910
7911 @@ -119,7 +235,16 @@ static inline int atomic_dec_and_test(at
7912 {
7913 unsigned char c;
7914
7915 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
7916 + asm volatile(LOCK_PREFIX "decl %0\n"
7917 +
7918 +#ifdef CONFIG_PAX_REFCOUNT
7919 + "jno 0f\n"
7920 + LOCK_PREFIX "incl %0\n"
7921 + "int $4\n0:\n"
7922 + _ASM_EXTABLE(0b, 0b)
7923 +#endif
7924 +
7925 + "sete %1\n"
7926 : "+m" (v->counter), "=qm" (c)
7927 : : "memory");
7928 return c != 0;
7929 @@ -137,7 +262,35 @@ static inline int atomic_inc_and_test(at
7930 {
7931 unsigned char c;
7932
7933 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
7934 + asm volatile(LOCK_PREFIX "incl %0\n"
7935 +
7936 +#ifdef CONFIG_PAX_REFCOUNT
7937 + "jno 0f\n"
7938 + LOCK_PREFIX "decl %0\n"
7939 + "into\n0:\n"
7940 + _ASM_EXTABLE(0b, 0b)
7941 +#endif
7942 +
7943 + "sete %1\n"
7944 + : "+m" (v->counter), "=qm" (c)
7945 + : : "memory");
7946 + return c != 0;
7947 +}
7948 +
7949 +/**
7950 + * atomic_inc_and_test_unchecked - increment and test
7951 + * @v: pointer of type atomic_unchecked_t
7952 + *
7953 + * Atomically increments @v by 1
7954 + * and returns true if the result is zero, or false for all
7955 + * other cases.
7956 + */
7957 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7958 +{
7959 + unsigned char c;
7960 +
7961 + asm volatile(LOCK_PREFIX "incl %0\n"
7962 + "sete %1\n"
7963 : "+m" (v->counter), "=qm" (c)
7964 : : "memory");
7965 return c != 0;
7966 @@ -156,7 +309,16 @@ static inline int atomic_add_negative(in
7967 {
7968 unsigned char c;
7969
7970 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7971 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
7972 +
7973 +#ifdef CONFIG_PAX_REFCOUNT
7974 + "jno 0f\n"
7975 + LOCK_PREFIX "subl %2,%0\n"
7976 + "int $4\n0:\n"
7977 + _ASM_EXTABLE(0b, 0b)
7978 +#endif
7979 +
7980 + "sets %1\n"
7981 : "+m" (v->counter), "=qm" (c)
7982 : "ir" (i) : "memory");
7983 return c;
7984 @@ -179,6 +341,46 @@ static inline int atomic_add_return(int
7985 #endif
7986 /* Modern 486+ processor */
7987 __i = i;
7988 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7989 +
7990 +#ifdef CONFIG_PAX_REFCOUNT
7991 + "jno 0f\n"
7992 + "movl %0, %1\n"
7993 + "int $4\n0:\n"
7994 + _ASM_EXTABLE(0b, 0b)
7995 +#endif
7996 +
7997 + : "+r" (i), "+m" (v->counter)
7998 + : : "memory");
7999 + return i + __i;
8000 +
8001 +#ifdef CONFIG_M386
8002 +no_xadd: /* Legacy 386 processor */
8003 + local_irq_save(flags);
8004 + __i = atomic_read(v);
8005 + atomic_set(v, i + __i);
8006 + local_irq_restore(flags);
8007 + return i + __i;
8008 +#endif
8009 +}
8010 +
8011 +/**
8012 + * atomic_add_return_unchecked - add integer and return
8013 + * @v: pointer of type atomic_unchecked_t
8014 + * @i: integer value to add
8015 + *
8016 + * Atomically adds @i to @v and returns @i + @v
8017 + */
8018 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8019 +{
8020 + int __i;
8021 +#ifdef CONFIG_M386
8022 + unsigned long flags;
8023 + if (unlikely(boot_cpu_data.x86 <= 3))
8024 + goto no_xadd;
8025 +#endif
8026 + /* Modern 486+ processor */
8027 + __i = i;
8028 asm volatile(LOCK_PREFIX "xaddl %0, %1"
8029 : "+r" (i), "+m" (v->counter)
8030 : : "memory");
8031 @@ -211,11 +413,21 @@ static inline int atomic_cmpxchg(atomic_
8032 return cmpxchg(&v->counter, old, new);
8033 }
8034
8035 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8036 +{
8037 + return cmpxchg(&v->counter, old, new);
8038 +}
8039 +
8040 static inline int atomic_xchg(atomic_t *v, int new)
8041 {
8042 return xchg(&v->counter, new);
8043 }
8044
8045 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8046 +{
8047 + return xchg(&v->counter, new);
8048 +}
8049 +
8050 /**
8051 * atomic_add_unless - add unless the number is already a given value
8052 * @v: pointer of type atomic_t
8053 @@ -227,22 +439,39 @@ static inline int atomic_xchg(atomic_t *
8054 */
8055 static inline int atomic_add_unless(atomic_t *v, int a, int u)
8056 {
8057 - int c, old;
8058 + int c, old, new;
8059 c = atomic_read(v);
8060 for (;;) {
8061 - if (unlikely(c == (u)))
8062 + if (unlikely(c == u))
8063 break;
8064 - old = atomic_cmpxchg((v), c, c + (a));
8065 +
8066 + asm volatile("addl %2,%0\n"
8067 +
8068 +#ifdef CONFIG_PAX_REFCOUNT
8069 + "jno 0f\n"
8070 + "subl %2,%0\n"
8071 + "int $4\n0:\n"
8072 + _ASM_EXTABLE(0b, 0b)
8073 +#endif
8074 +
8075 + : "=r" (new)
8076 + : "0" (c), "ir" (a));
8077 +
8078 + old = atomic_cmpxchg(v, c, new);
8079 if (likely(old == c))
8080 break;
8081 c = old;
8082 }
8083 - return c != (u);
8084 + return c != u;
8085 }
8086
8087 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
8088
8089 #define atomic_inc_return(v) (atomic_add_return(1, v))
8090 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8091 +{
8092 + return atomic_add_return_unchecked(1, v);
8093 +}
8094 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8095
8096 /* These are x86-specific, used by some header files */
8097 @@ -266,9 +495,18 @@ typedef struct {
8098 u64 __aligned(8) counter;
8099 } atomic64_t;
8100
8101 +#ifdef CONFIG_PAX_REFCOUNT
8102 +typedef struct {
8103 + u64 __aligned(8) counter;
8104 +} atomic64_unchecked_t;
8105 +#else
8106 +typedef atomic64_t atomic64_unchecked_t;
8107 +#endif
8108 +
8109 #define ATOMIC64_INIT(val) { (val) }
8110
8111 extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
8112 +extern u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val);
8113
8114 /**
8115 * atomic64_xchg - xchg atomic64 variable
8116 @@ -279,6 +517,7 @@ extern u64 atomic64_cmpxchg(atomic64_t *
8117 * the old value.
8118 */
8119 extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
8120 +extern u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
8121
8122 /**
8123 * atomic64_set - set atomic64 variable
8124 @@ -290,6 +529,15 @@ extern u64 atomic64_xchg(atomic64_t *ptr
8125 extern void atomic64_set(atomic64_t *ptr, u64 new_val);
8126
8127 /**
8128 + * atomic64_unchecked_set - set atomic64 variable
8129 + * @ptr: pointer to type atomic64_unchecked_t
8130 + * @new_val: value to assign
8131 + *
8132 + * Atomically sets the value of @ptr to @new_val.
8133 + */
8134 +extern void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
8135 +
8136 +/**
8137 * atomic64_read - read atomic64 variable
8138 * @ptr: pointer to type atomic64_t
8139 *
8140 @@ -317,7 +565,33 @@ static inline u64 atomic64_read(atomic64
8141 return res;
8142 }
8143
8144 -extern u64 atomic64_read(atomic64_t *ptr);
8145 +/**
8146 + * atomic64_read_unchecked - read atomic64 variable
8147 + * @ptr: pointer to type atomic64_unchecked_t
8148 + *
8149 + * Atomically reads the value of @ptr and returns it.
8150 + */
8151 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *ptr)
8152 +{
8153 + u64 res;
8154 +
8155 + /*
8156 + * Note, we inline this atomic64_unchecked_t primitive because
8157 + * it only clobbers EAX/EDX and leaves the others
8158 + * untouched. We also (somewhat subtly) rely on the
8159 + * fact that cmpxchg8b returns the current 64-bit value
8160 + * of the memory location we are touching:
8161 + */
8162 + asm volatile(
8163 + "mov %%ebx, %%eax\n\t"
8164 + "mov %%ecx, %%edx\n\t"
8165 + LOCK_PREFIX "cmpxchg8b %1\n"
8166 + : "=&A" (res)
8167 + : "m" (*ptr)
8168 + );
8169 +
8170 + return res;
8171 +}
8172
8173 /**
8174 * atomic64_add_return - add and return
8175 @@ -332,8 +606,11 @@ extern u64 atomic64_add_return(u64 delta
8176 * Other variants with different arithmetic operators:
8177 */
8178 extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
8179 +extern u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8180 extern u64 atomic64_inc_return(atomic64_t *ptr);
8181 +extern u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr);
8182 extern u64 atomic64_dec_return(atomic64_t *ptr);
8183 +extern u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr);
8184
8185 /**
8186 * atomic64_add - add integer to atomic64 variable
8187 @@ -345,6 +622,15 @@ extern u64 atomic64_dec_return(atomic64_
8188 extern void atomic64_add(u64 delta, atomic64_t *ptr);
8189
8190 /**
8191 + * atomic64_add_unchecked - add integer to atomic64 variable
8192 + * @delta: integer value to add
8193 + * @ptr: pointer to type atomic64_unchecked_t
8194 + *
8195 + * Atomically adds @delta to @ptr.
8196 + */
8197 +extern void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8198 +
8199 +/**
8200 * atomic64_sub - subtract the atomic64 variable
8201 * @delta: integer value to subtract
8202 * @ptr: pointer to type atomic64_t
8203 @@ -354,6 +640,15 @@ extern void atomic64_add(u64 delta, atom
8204 extern void atomic64_sub(u64 delta, atomic64_t *ptr);
8205
8206 /**
8207 + * atomic64_sub_unchecked - subtract the atomic64 variable
8208 + * @delta: integer value to subtract
8209 + * @ptr: pointer to type atomic64_unchecked_t
8210 + *
8211 + * Atomically subtracts @delta from @ptr.
8212 + */
8213 +extern void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8214 +
8215 +/**
8216 * atomic64_sub_and_test - subtract value from variable and test result
8217 * @delta: integer value to subtract
8218 * @ptr: pointer to type atomic64_t
8219 @@ -373,6 +668,14 @@ extern int atomic64_sub_and_test(u64 del
8220 extern void atomic64_inc(atomic64_t *ptr);
8221
8222 /**
8223 + * atomic64_inc_unchecked - increment atomic64 variable
8224 + * @ptr: pointer to type atomic64_unchecked_t
8225 + *
8226 + * Atomically increments @ptr by 1.
8227 + */
8228 +extern void atomic64_inc_unchecked(atomic64_unchecked_t *ptr);
8229 +
8230 +/**
8231 * atomic64_dec - decrement atomic64 variable
8232 * @ptr: pointer to type atomic64_t
8233 *
8234 @@ -381,6 +684,14 @@ extern void atomic64_inc(atomic64_t *ptr
8235 extern void atomic64_dec(atomic64_t *ptr);
8236
8237 /**
8238 + * atomic64_dec_unchecked - decrement atomic64 variable
8239 + * @ptr: pointer to type atomic64_unchecked_t
8240 + *
8241 + * Atomically decrements @ptr by 1.
8242 + */
8243 +extern void atomic64_dec_unchecked(atomic64_unchecked_t *ptr);
8244 +
8245 +/**
8246 * atomic64_dec_and_test - decrement and test
8247 * @ptr: pointer to type atomic64_t
8248 *
8249 diff -urNp linux-2.6.32.46/arch/x86/include/asm/atomic_64.h linux-2.6.32.46/arch/x86/include/asm/atomic_64.h
8250 --- linux-2.6.32.46/arch/x86/include/asm/atomic_64.h 2011-03-27 14:31:47.000000000 -0400
8251 +++ linux-2.6.32.46/arch/x86/include/asm/atomic_64.h 2011-05-04 18:35:31.000000000 -0400
8252 @@ -24,6 +24,17 @@ static inline int atomic_read(const atom
8253 }
8254
8255 /**
8256 + * atomic_read_unchecked - read atomic variable
8257 + * @v: pointer of type atomic_unchecked_t
8258 + *
8259 + * Atomically reads the value of @v.
8260 + */
8261 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8262 +{
8263 + return v->counter;
8264 +}
8265 +
8266 +/**
8267 * atomic_set - set atomic variable
8268 * @v: pointer of type atomic_t
8269 * @i: required value
8270 @@ -36,6 +47,18 @@ static inline void atomic_set(atomic_t *
8271 }
8272
8273 /**
8274 + * atomic_set_unchecked - set atomic variable
8275 + * @v: pointer of type atomic_unchecked_t
8276 + * @i: required value
8277 + *
8278 + * Atomically sets the value of @v to @i.
8279 + */
8280 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8281 +{
8282 + v->counter = i;
8283 +}
8284 +
8285 +/**
8286 * atomic_add - add integer to atomic variable
8287 * @i: integer value to add
8288 * @v: pointer of type atomic_t
8289 @@ -44,7 +67,29 @@ static inline void atomic_set(atomic_t *
8290 */
8291 static inline void atomic_add(int i, atomic_t *v)
8292 {
8293 - asm volatile(LOCK_PREFIX "addl %1,%0"
8294 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8295 +
8296 +#ifdef CONFIG_PAX_REFCOUNT
8297 + "jno 0f\n"
8298 + LOCK_PREFIX "subl %1,%0\n"
8299 + "int $4\n0:\n"
8300 + _ASM_EXTABLE(0b, 0b)
8301 +#endif
8302 +
8303 + : "=m" (v->counter)
8304 + : "ir" (i), "m" (v->counter));
8305 +}
8306 +
8307 +/**
8308 + * atomic_add_unchecked - add integer to atomic variable
8309 + * @i: integer value to add
8310 + * @v: pointer of type atomic_unchecked_t
8311 + *
8312 + * Atomically adds @i to @v.
8313 + */
8314 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8315 +{
8316 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8317 : "=m" (v->counter)
8318 : "ir" (i), "m" (v->counter));
8319 }
8320 @@ -58,7 +103,29 @@ static inline void atomic_add(int i, ato
8321 */
8322 static inline void atomic_sub(int i, atomic_t *v)
8323 {
8324 - asm volatile(LOCK_PREFIX "subl %1,%0"
8325 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8326 +
8327 +#ifdef CONFIG_PAX_REFCOUNT
8328 + "jno 0f\n"
8329 + LOCK_PREFIX "addl %1,%0\n"
8330 + "int $4\n0:\n"
8331 + _ASM_EXTABLE(0b, 0b)
8332 +#endif
8333 +
8334 + : "=m" (v->counter)
8335 + : "ir" (i), "m" (v->counter));
8336 +}
8337 +
8338 +/**
8339 + * atomic_sub_unchecked - subtract the atomic variable
8340 + * @i: integer value to subtract
8341 + * @v: pointer of type atomic_unchecked_t
8342 + *
8343 + * Atomically subtracts @i from @v.
8344 + */
8345 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8346 +{
8347 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8348 : "=m" (v->counter)
8349 : "ir" (i), "m" (v->counter));
8350 }
8351 @@ -76,7 +143,16 @@ static inline int atomic_sub_and_test(in
8352 {
8353 unsigned char c;
8354
8355 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8356 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8357 +
8358 +#ifdef CONFIG_PAX_REFCOUNT
8359 + "jno 0f\n"
8360 + LOCK_PREFIX "addl %2,%0\n"
8361 + "int $4\n0:\n"
8362 + _ASM_EXTABLE(0b, 0b)
8363 +#endif
8364 +
8365 + "sete %1\n"
8366 : "=m" (v->counter), "=qm" (c)
8367 : "ir" (i), "m" (v->counter) : "memory");
8368 return c;
8369 @@ -90,7 +166,28 @@ static inline int atomic_sub_and_test(in
8370 */
8371 static inline void atomic_inc(atomic_t *v)
8372 {
8373 - asm volatile(LOCK_PREFIX "incl %0"
8374 + asm volatile(LOCK_PREFIX "incl %0\n"
8375 +
8376 +#ifdef CONFIG_PAX_REFCOUNT
8377 + "jno 0f\n"
8378 + LOCK_PREFIX "decl %0\n"
8379 + "int $4\n0:\n"
8380 + _ASM_EXTABLE(0b, 0b)
8381 +#endif
8382 +
8383 + : "=m" (v->counter)
8384 + : "m" (v->counter));
8385 +}
8386 +
8387 +/**
8388 + * atomic_inc_unchecked - increment atomic variable
8389 + * @v: pointer of type atomic_unchecked_t
8390 + *
8391 + * Atomically increments @v by 1.
8392 + */
8393 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8394 +{
8395 + asm volatile(LOCK_PREFIX "incl %0\n"
8396 : "=m" (v->counter)
8397 : "m" (v->counter));
8398 }
8399 @@ -103,7 +200,28 @@ static inline void atomic_inc(atomic_t *
8400 */
8401 static inline void atomic_dec(atomic_t *v)
8402 {
8403 - asm volatile(LOCK_PREFIX "decl %0"
8404 + asm volatile(LOCK_PREFIX "decl %0\n"
8405 +
8406 +#ifdef CONFIG_PAX_REFCOUNT
8407 + "jno 0f\n"
8408 + LOCK_PREFIX "incl %0\n"
8409 + "int $4\n0:\n"
8410 + _ASM_EXTABLE(0b, 0b)
8411 +#endif
8412 +
8413 + : "=m" (v->counter)
8414 + : "m" (v->counter));
8415 +}
8416 +
8417 +/**
8418 + * atomic_dec_unchecked - decrement atomic variable
8419 + * @v: pointer of type atomic_unchecked_t
8420 + *
8421 + * Atomically decrements @v by 1.
8422 + */
8423 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8424 +{
8425 + asm volatile(LOCK_PREFIX "decl %0\n"
8426 : "=m" (v->counter)
8427 : "m" (v->counter));
8428 }
8429 @@ -120,7 +238,16 @@ static inline int atomic_dec_and_test(at
8430 {
8431 unsigned char c;
8432
8433 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8434 + asm volatile(LOCK_PREFIX "decl %0\n"
8435 +
8436 +#ifdef CONFIG_PAX_REFCOUNT
8437 + "jno 0f\n"
8438 + LOCK_PREFIX "incl %0\n"
8439 + "int $4\n0:\n"
8440 + _ASM_EXTABLE(0b, 0b)
8441 +#endif
8442 +
8443 + "sete %1\n"
8444 : "=m" (v->counter), "=qm" (c)
8445 : "m" (v->counter) : "memory");
8446 return c != 0;
8447 @@ -138,7 +265,35 @@ static inline int atomic_inc_and_test(at
8448 {
8449 unsigned char c;
8450
8451 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8452 + asm volatile(LOCK_PREFIX "incl %0\n"
8453 +
8454 +#ifdef CONFIG_PAX_REFCOUNT
8455 + "jno 0f\n"
8456 + LOCK_PREFIX "decl %0\n"
8457 + "int $4\n0:\n"
8458 + _ASM_EXTABLE(0b, 0b)
8459 +#endif
8460 +
8461 + "sete %1\n"
8462 + : "=m" (v->counter), "=qm" (c)
8463 + : "m" (v->counter) : "memory");
8464 + return c != 0;
8465 +}
8466 +
8467 +/**
8468 + * atomic_inc_and_test_unchecked - increment and test
8469 + * @v: pointer of type atomic_unchecked_t
8470 + *
8471 + * Atomically increments @v by 1
8472 + * and returns true if the result is zero, or false for all
8473 + * other cases.
8474 + */
8475 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8476 +{
8477 + unsigned char c;
8478 +
8479 + asm volatile(LOCK_PREFIX "incl %0\n"
8480 + "sete %1\n"
8481 : "=m" (v->counter), "=qm" (c)
8482 : "m" (v->counter) : "memory");
8483 return c != 0;
8484 @@ -157,7 +312,16 @@ static inline int atomic_add_negative(in
8485 {
8486 unsigned char c;
8487
8488 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8489 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8490 +
8491 +#ifdef CONFIG_PAX_REFCOUNT
8492 + "jno 0f\n"
8493 + LOCK_PREFIX "subl %2,%0\n"
8494 + "int $4\n0:\n"
8495 + _ASM_EXTABLE(0b, 0b)
8496 +#endif
8497 +
8498 + "sets %1\n"
8499 : "=m" (v->counter), "=qm" (c)
8500 : "ir" (i), "m" (v->counter) : "memory");
8501 return c;
8502 @@ -173,7 +337,31 @@ static inline int atomic_add_negative(in
8503 static inline int atomic_add_return(int i, atomic_t *v)
8504 {
8505 int __i = i;
8506 - asm volatile(LOCK_PREFIX "xaddl %0, %1"
8507 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
8508 +
8509 +#ifdef CONFIG_PAX_REFCOUNT
8510 + "jno 0f\n"
8511 + "movl %0, %1\n"
8512 + "int $4\n0:\n"
8513 + _ASM_EXTABLE(0b, 0b)
8514 +#endif
8515 +
8516 + : "+r" (i), "+m" (v->counter)
8517 + : : "memory");
8518 + return i + __i;
8519 +}
8520 +
8521 +/**
8522 + * atomic_add_return_unchecked - add and return
8523 + * @i: integer value to add
8524 + * @v: pointer of type atomic_unchecked_t
8525 + *
8526 + * Atomically adds @i to @v and returns @i + @v
8527 + */
8528 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8529 +{
8530 + int __i = i;
8531 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
8532 : "+r" (i), "+m" (v->counter)
8533 : : "memory");
8534 return i + __i;
8535 @@ -185,6 +373,10 @@ static inline int atomic_sub_return(int
8536 }
8537
8538 #define atomic_inc_return(v) (atomic_add_return(1, v))
8539 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8540 +{
8541 + return atomic_add_return_unchecked(1, v);
8542 +}
8543 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8544
8545 /* The 64-bit atomic type */
8546 @@ -204,6 +396,18 @@ static inline long atomic64_read(const a
8547 }
8548
8549 /**
8550 + * atomic64_read_unchecked - read atomic64 variable
8551 + * @v: pointer of type atomic64_unchecked_t
8552 + *
8553 + * Atomically reads the value of @v.
8554 + * Doesn't imply a read memory barrier.
8555 + */
8556 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8557 +{
8558 + return v->counter;
8559 +}
8560 +
8561 +/**
8562 * atomic64_set - set atomic64 variable
8563 * @v: pointer to type atomic64_t
8564 * @i: required value
8565 @@ -216,6 +420,18 @@ static inline void atomic64_set(atomic64
8566 }
8567
8568 /**
8569 + * atomic64_set_unchecked - set atomic64 variable
8570 + * @v: pointer to type atomic64_unchecked_t
8571 + * @i: required value
8572 + *
8573 + * Atomically sets the value of @v to @i.
8574 + */
8575 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8576 +{
8577 + v->counter = i;
8578 +}
8579 +
8580 +/**
8581 * atomic64_add - add integer to atomic64 variable
8582 * @i: integer value to add
8583 * @v: pointer to type atomic64_t
8584 @@ -224,6 +440,28 @@ static inline void atomic64_set(atomic64
8585 */
8586 static inline void atomic64_add(long i, atomic64_t *v)
8587 {
8588 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
8589 +
8590 +#ifdef CONFIG_PAX_REFCOUNT
8591 + "jno 0f\n"
8592 + LOCK_PREFIX "subq %1,%0\n"
8593 + "int $4\n0:\n"
8594 + _ASM_EXTABLE(0b, 0b)
8595 +#endif
8596 +
8597 + : "=m" (v->counter)
8598 + : "er" (i), "m" (v->counter));
8599 +}
8600 +
8601 +/**
8602 + * atomic64_add_unchecked - add integer to atomic64 variable
8603 + * @i: integer value to add
8604 + * @v: pointer to type atomic64_unchecked_t
8605 + *
8606 + * Atomically adds @i to @v.
8607 + */
8608 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
8609 +{
8610 asm volatile(LOCK_PREFIX "addq %1,%0"
8611 : "=m" (v->counter)
8612 : "er" (i), "m" (v->counter));
8613 @@ -238,7 +476,15 @@ static inline void atomic64_add(long i,
8614 */
8615 static inline void atomic64_sub(long i, atomic64_t *v)
8616 {
8617 - asm volatile(LOCK_PREFIX "subq %1,%0"
8618 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8619 +
8620 +#ifdef CONFIG_PAX_REFCOUNT
8621 + "jno 0f\n"
8622 + LOCK_PREFIX "addq %1,%0\n"
8623 + "int $4\n0:\n"
8624 + _ASM_EXTABLE(0b, 0b)
8625 +#endif
8626 +
8627 : "=m" (v->counter)
8628 : "er" (i), "m" (v->counter));
8629 }
8630 @@ -256,7 +502,16 @@ static inline int atomic64_sub_and_test(
8631 {
8632 unsigned char c;
8633
8634 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
8635 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
8636 +
8637 +#ifdef CONFIG_PAX_REFCOUNT
8638 + "jno 0f\n"
8639 + LOCK_PREFIX "addq %2,%0\n"
8640 + "int $4\n0:\n"
8641 + _ASM_EXTABLE(0b, 0b)
8642 +#endif
8643 +
8644 + "sete %1\n"
8645 : "=m" (v->counter), "=qm" (c)
8646 : "er" (i), "m" (v->counter) : "memory");
8647 return c;
8648 @@ -270,6 +525,27 @@ static inline int atomic64_sub_and_test(
8649 */
8650 static inline void atomic64_inc(atomic64_t *v)
8651 {
8652 + asm volatile(LOCK_PREFIX "incq %0\n"
8653 +
8654 +#ifdef CONFIG_PAX_REFCOUNT
8655 + "jno 0f\n"
8656 + LOCK_PREFIX "decq %0\n"
8657 + "int $4\n0:\n"
8658 + _ASM_EXTABLE(0b, 0b)
8659 +#endif
8660 +
8661 + : "=m" (v->counter)
8662 + : "m" (v->counter));
8663 +}
8664 +
8665 +/**
8666 + * atomic64_inc_unchecked - increment atomic64 variable
8667 + * @v: pointer to type atomic64_unchecked_t
8668 + *
8669 + * Atomically increments @v by 1.
8670 + */
8671 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8672 +{
8673 asm volatile(LOCK_PREFIX "incq %0"
8674 : "=m" (v->counter)
8675 : "m" (v->counter));
8676 @@ -283,7 +559,28 @@ static inline void atomic64_inc(atomic64
8677 */
8678 static inline void atomic64_dec(atomic64_t *v)
8679 {
8680 - asm volatile(LOCK_PREFIX "decq %0"
8681 + asm volatile(LOCK_PREFIX "decq %0\n"
8682 +
8683 +#ifdef CONFIG_PAX_REFCOUNT
8684 + "jno 0f\n"
8685 + LOCK_PREFIX "incq %0\n"
8686 + "int $4\n0:\n"
8687 + _ASM_EXTABLE(0b, 0b)
8688 +#endif
8689 +
8690 + : "=m" (v->counter)
8691 + : "m" (v->counter));
8692 +}
8693 +
8694 +/**
8695 + * atomic64_dec_unchecked - decrement atomic64 variable
8696 + * @v: pointer to type atomic64_t
8697 + *
8698 + * Atomically decrements @v by 1.
8699 + */
8700 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8701 +{
8702 + asm volatile(LOCK_PREFIX "decq %0\n"
8703 : "=m" (v->counter)
8704 : "m" (v->counter));
8705 }
8706 @@ -300,7 +597,16 @@ static inline int atomic64_dec_and_test(
8707 {
8708 unsigned char c;
8709
8710 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
8711 + asm volatile(LOCK_PREFIX "decq %0\n"
8712 +
8713 +#ifdef CONFIG_PAX_REFCOUNT
8714 + "jno 0f\n"
8715 + LOCK_PREFIX "incq %0\n"
8716 + "int $4\n0:\n"
8717 + _ASM_EXTABLE(0b, 0b)
8718 +#endif
8719 +
8720 + "sete %1\n"
8721 : "=m" (v->counter), "=qm" (c)
8722 : "m" (v->counter) : "memory");
8723 return c != 0;
8724 @@ -318,7 +624,16 @@ static inline int atomic64_inc_and_test(
8725 {
8726 unsigned char c;
8727
8728 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
8729 + asm volatile(LOCK_PREFIX "incq %0\n"
8730 +
8731 +#ifdef CONFIG_PAX_REFCOUNT
8732 + "jno 0f\n"
8733 + LOCK_PREFIX "decq %0\n"
8734 + "int $4\n0:\n"
8735 + _ASM_EXTABLE(0b, 0b)
8736 +#endif
8737 +
8738 + "sete %1\n"
8739 : "=m" (v->counter), "=qm" (c)
8740 : "m" (v->counter) : "memory");
8741 return c != 0;
8742 @@ -337,7 +652,16 @@ static inline int atomic64_add_negative(
8743 {
8744 unsigned char c;
8745
8746 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
8747 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
8748 +
8749 +#ifdef CONFIG_PAX_REFCOUNT
8750 + "jno 0f\n"
8751 + LOCK_PREFIX "subq %2,%0\n"
8752 + "int $4\n0:\n"
8753 + _ASM_EXTABLE(0b, 0b)
8754 +#endif
8755 +
8756 + "sets %1\n"
8757 : "=m" (v->counter), "=qm" (c)
8758 : "er" (i), "m" (v->counter) : "memory");
8759 return c;
8760 @@ -353,7 +677,31 @@ static inline int atomic64_add_negative(
8761 static inline long atomic64_add_return(long i, atomic64_t *v)
8762 {
8763 long __i = i;
8764 - asm volatile(LOCK_PREFIX "xaddq %0, %1;"
8765 + asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
8766 +
8767 +#ifdef CONFIG_PAX_REFCOUNT
8768 + "jno 0f\n"
8769 + "movq %0, %1\n"
8770 + "int $4\n0:\n"
8771 + _ASM_EXTABLE(0b, 0b)
8772 +#endif
8773 +
8774 + : "+r" (i), "+m" (v->counter)
8775 + : : "memory");
8776 + return i + __i;
8777 +}
8778 +
8779 +/**
8780 + * atomic64_add_return_unchecked - add and return
8781 + * @i: integer value to add
8782 + * @v: pointer to type atomic64_unchecked_t
8783 + *
8784 + * Atomically adds @i to @v and returns @i + @v
8785 + */
8786 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8787 +{
8788 + long __i = i;
8789 + asm volatile(LOCK_PREFIX "xaddq %0, %1"
8790 : "+r" (i), "+m" (v->counter)
8791 : : "memory");
8792 return i + __i;
8793 @@ -365,6 +713,10 @@ static inline long atomic64_sub_return(l
8794 }
8795
8796 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
8797 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8798 +{
8799 + return atomic64_add_return_unchecked(1, v);
8800 +}
8801 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
8802
8803 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8804 @@ -372,21 +724,41 @@ static inline long atomic64_cmpxchg(atom
8805 return cmpxchg(&v->counter, old, new);
8806 }
8807
8808 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8809 +{
8810 + return cmpxchg(&v->counter, old, new);
8811 +}
8812 +
8813 static inline long atomic64_xchg(atomic64_t *v, long new)
8814 {
8815 return xchg(&v->counter, new);
8816 }
8817
8818 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8819 +{
8820 + return xchg(&v->counter, new);
8821 +}
8822 +
8823 static inline long atomic_cmpxchg(atomic_t *v, int old, int new)
8824 {
8825 return cmpxchg(&v->counter, old, new);
8826 }
8827
8828 +static inline long atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8829 +{
8830 + return cmpxchg(&v->counter, old, new);
8831 +}
8832 +
8833 static inline long atomic_xchg(atomic_t *v, int new)
8834 {
8835 return xchg(&v->counter, new);
8836 }
8837
8838 +static inline long atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8839 +{
8840 + return xchg(&v->counter, new);
8841 +}
8842 +
8843 /**
8844 * atomic_add_unless - add unless the number is a given value
8845 * @v: pointer of type atomic_t
8846 @@ -398,17 +770,30 @@ static inline long atomic_xchg(atomic_t
8847 */
8848 static inline int atomic_add_unless(atomic_t *v, int a, int u)
8849 {
8850 - int c, old;
8851 + int c, old, new;
8852 c = atomic_read(v);
8853 for (;;) {
8854 - if (unlikely(c == (u)))
8855 + if (unlikely(c == u))
8856 break;
8857 - old = atomic_cmpxchg((v), c, c + (a));
8858 +
8859 + asm volatile("addl %2,%0\n"
8860 +
8861 +#ifdef CONFIG_PAX_REFCOUNT
8862 + "jno 0f\n"
8863 + "subl %2,%0\n"
8864 + "int $4\n0:\n"
8865 + _ASM_EXTABLE(0b, 0b)
8866 +#endif
8867 +
8868 + : "=r" (new)
8869 + : "0" (c), "ir" (a));
8870 +
8871 + old = atomic_cmpxchg(v, c, new);
8872 if (likely(old == c))
8873 break;
8874 c = old;
8875 }
8876 - return c != (u);
8877 + return c != u;
8878 }
8879
8880 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
8881 @@ -424,17 +809,30 @@ static inline int atomic_add_unless(atom
8882 */
8883 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8884 {
8885 - long c, old;
8886 + long c, old, new;
8887 c = atomic64_read(v);
8888 for (;;) {
8889 - if (unlikely(c == (u)))
8890 + if (unlikely(c == u))
8891 break;
8892 - old = atomic64_cmpxchg((v), c, c + (a));
8893 +
8894 + asm volatile("addq %2,%0\n"
8895 +
8896 +#ifdef CONFIG_PAX_REFCOUNT
8897 + "jno 0f\n"
8898 + "subq %2,%0\n"
8899 + "int $4\n0:\n"
8900 + _ASM_EXTABLE(0b, 0b)
8901 +#endif
8902 +
8903 + : "=r" (new)
8904 + : "0" (c), "er" (a));
8905 +
8906 + old = atomic64_cmpxchg(v, c, new);
8907 if (likely(old == c))
8908 break;
8909 c = old;
8910 }
8911 - return c != (u);
8912 + return c != u;
8913 }
8914
8915 /**
8916 diff -urNp linux-2.6.32.46/arch/x86/include/asm/bitops.h linux-2.6.32.46/arch/x86/include/asm/bitops.h
8917 --- linux-2.6.32.46/arch/x86/include/asm/bitops.h 2011-03-27 14:31:47.000000000 -0400
8918 +++ linux-2.6.32.46/arch/x86/include/asm/bitops.h 2011-04-17 15:56:46.000000000 -0400
8919 @@ -38,7 +38,7 @@
8920 * a mask operation on a byte.
8921 */
8922 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
8923 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
8924 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
8925 #define CONST_MASK(nr) (1 << ((nr) & 7))
8926
8927 /**
8928 diff -urNp linux-2.6.32.46/arch/x86/include/asm/boot.h linux-2.6.32.46/arch/x86/include/asm/boot.h
8929 --- linux-2.6.32.46/arch/x86/include/asm/boot.h 2011-03-27 14:31:47.000000000 -0400
8930 +++ linux-2.6.32.46/arch/x86/include/asm/boot.h 2011-04-17 15:56:46.000000000 -0400
8931 @@ -11,10 +11,15 @@
8932 #include <asm/pgtable_types.h>
8933
8934 /* Physical address where kernel should be loaded. */
8935 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8936 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8937 + (CONFIG_PHYSICAL_ALIGN - 1)) \
8938 & ~(CONFIG_PHYSICAL_ALIGN - 1))
8939
8940 +#ifndef __ASSEMBLY__
8941 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
8942 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
8943 +#endif
8944 +
8945 /* Minimum kernel alignment, as a power of two */
8946 #ifdef CONFIG_X86_64
8947 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
8948 diff -urNp linux-2.6.32.46/arch/x86/include/asm/cache.h linux-2.6.32.46/arch/x86/include/asm/cache.h
8949 --- linux-2.6.32.46/arch/x86/include/asm/cache.h 2011-03-27 14:31:47.000000000 -0400
8950 +++ linux-2.6.32.46/arch/x86/include/asm/cache.h 2011-07-06 19:53:33.000000000 -0400
8951 @@ -5,9 +5,10 @@
8952
8953 /* L1 cache line size */
8954 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8955 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8956 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8957
8958 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
8959 +#define __read_only __attribute__((__section__(".data.read_only")))
8960
8961 #ifdef CONFIG_X86_VSMP
8962 /* vSMP Internode cacheline shift */
8963 diff -urNp linux-2.6.32.46/arch/x86/include/asm/cacheflush.h linux-2.6.32.46/arch/x86/include/asm/cacheflush.h
8964 --- linux-2.6.32.46/arch/x86/include/asm/cacheflush.h 2011-03-27 14:31:47.000000000 -0400
8965 +++ linux-2.6.32.46/arch/x86/include/asm/cacheflush.h 2011-04-17 15:56:46.000000000 -0400
8966 @@ -60,7 +60,7 @@ PAGEFLAG(WC, WC)
8967 static inline unsigned long get_page_memtype(struct page *pg)
8968 {
8969 if (!PageUncached(pg) && !PageWC(pg))
8970 - return -1;
8971 + return ~0UL;
8972 else if (!PageUncached(pg) && PageWC(pg))
8973 return _PAGE_CACHE_WC;
8974 else if (PageUncached(pg) && !PageWC(pg))
8975 @@ -85,7 +85,7 @@ static inline void set_page_memtype(stru
8976 SetPageWC(pg);
8977 break;
8978 default:
8979 - case -1:
8980 + case ~0UL:
8981 ClearPageUncached(pg);
8982 ClearPageWC(pg);
8983 break;
8984 diff -urNp linux-2.6.32.46/arch/x86/include/asm/calling.h linux-2.6.32.46/arch/x86/include/asm/calling.h
8985 --- linux-2.6.32.46/arch/x86/include/asm/calling.h 2011-03-27 14:31:47.000000000 -0400
8986 +++ linux-2.6.32.46/arch/x86/include/asm/calling.h 2011-10-06 10:08:42.000000000 -0400
8987 @@ -52,32 +52,32 @@ For 32-bit we have the following convent
8988 * for assembly code:
8989 */
8990
8991 -#define R15 0
8992 -#define R14 8
8993 -#define R13 16
8994 -#define R12 24
8995 -#define RBP 32
8996 -#define RBX 40
8997 +#define R15 (0)
8998 +#define R14 (8)
8999 +#define R13 (16)
9000 +#define R12 (24)
9001 +#define RBP (32)
9002 +#define RBX (40)
9003
9004 /* arguments: interrupts/non tracing syscalls only save up to here: */
9005 -#define R11 48
9006 -#define R10 56
9007 -#define R9 64
9008 -#define R8 72
9009 -#define RAX 80
9010 -#define RCX 88
9011 -#define RDX 96
9012 -#define RSI 104
9013 -#define RDI 112
9014 -#define ORIG_RAX 120 /* + error_code */
9015 +#define R11 (48)
9016 +#define R10 (56)
9017 +#define R9 (64)
9018 +#define R8 (72)
9019 +#define RAX (80)
9020 +#define RCX (88)
9021 +#define RDX (96)
9022 +#define RSI (104)
9023 +#define RDI (112)
9024 +#define ORIG_RAX (120) /* + error_code */
9025 /* end of arguments */
9026
9027 /* cpu exception frame or undefined in case of fast syscall: */
9028 -#define RIP 128
9029 -#define CS 136
9030 -#define EFLAGS 144
9031 -#define RSP 152
9032 -#define SS 160
9033 +#define RIP (128)
9034 +#define CS (136)
9035 +#define EFLAGS (144)
9036 +#define RSP (152)
9037 +#define SS (160)
9038
9039 #define ARGOFFSET R11
9040 #define SWFRAME ORIG_RAX
9041 diff -urNp linux-2.6.32.46/arch/x86/include/asm/checksum_32.h linux-2.6.32.46/arch/x86/include/asm/checksum_32.h
9042 --- linux-2.6.32.46/arch/x86/include/asm/checksum_32.h 2011-03-27 14:31:47.000000000 -0400
9043 +++ linux-2.6.32.46/arch/x86/include/asm/checksum_32.h 2011-04-17 15:56:46.000000000 -0400
9044 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
9045 int len, __wsum sum,
9046 int *src_err_ptr, int *dst_err_ptr);
9047
9048 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9049 + int len, __wsum sum,
9050 + int *src_err_ptr, int *dst_err_ptr);
9051 +
9052 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9053 + int len, __wsum sum,
9054 + int *src_err_ptr, int *dst_err_ptr);
9055 +
9056 /*
9057 * Note: when you get a NULL pointer exception here this means someone
9058 * passed in an incorrect kernel address to one of these functions.
9059 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
9060 int *err_ptr)
9061 {
9062 might_sleep();
9063 - return csum_partial_copy_generic((__force void *)src, dst,
9064 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9065 len, sum, err_ptr, NULL);
9066 }
9067
9068 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
9069 {
9070 might_sleep();
9071 if (access_ok(VERIFY_WRITE, dst, len))
9072 - return csum_partial_copy_generic(src, (__force void *)dst,
9073 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9074 len, sum, NULL, err_ptr);
9075
9076 if (len)
9077 diff -urNp linux-2.6.32.46/arch/x86/include/asm/desc.h linux-2.6.32.46/arch/x86/include/asm/desc.h
9078 --- linux-2.6.32.46/arch/x86/include/asm/desc.h 2011-03-27 14:31:47.000000000 -0400
9079 +++ linux-2.6.32.46/arch/x86/include/asm/desc.h 2011-04-23 12:56:10.000000000 -0400
9080 @@ -4,6 +4,7 @@
9081 #include <asm/desc_defs.h>
9082 #include <asm/ldt.h>
9083 #include <asm/mmu.h>
9084 +#include <asm/pgtable.h>
9085 #include <linux/smp.h>
9086
9087 static inline void fill_ldt(struct desc_struct *desc,
9088 @@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
9089 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
9090 desc->type = (info->read_exec_only ^ 1) << 1;
9091 desc->type |= info->contents << 2;
9092 + desc->type |= info->seg_not_present ^ 1;
9093 desc->s = 1;
9094 desc->dpl = 0x3;
9095 desc->p = info->seg_not_present ^ 1;
9096 @@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
9097 }
9098
9099 extern struct desc_ptr idt_descr;
9100 -extern gate_desc idt_table[];
9101 -
9102 -struct gdt_page {
9103 - struct desc_struct gdt[GDT_ENTRIES];
9104 -} __attribute__((aligned(PAGE_SIZE)));
9105 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9106 +extern gate_desc idt_table[256];
9107
9108 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9109 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9110 {
9111 - return per_cpu(gdt_page, cpu).gdt;
9112 + return cpu_gdt_table[cpu];
9113 }
9114
9115 #ifdef CONFIG_X86_64
9116 @@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *
9117 unsigned long base, unsigned dpl, unsigned flags,
9118 unsigned short seg)
9119 {
9120 - gate->a = (seg << 16) | (base & 0xffff);
9121 - gate->b = (base & 0xffff0000) |
9122 - (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9123 + gate->gate.offset_low = base;
9124 + gate->gate.seg = seg;
9125 + gate->gate.reserved = 0;
9126 + gate->gate.type = type;
9127 + gate->gate.s = 0;
9128 + gate->gate.dpl = dpl;
9129 + gate->gate.p = 1;
9130 + gate->gate.offset_high = base >> 16;
9131 }
9132
9133 #endif
9134 @@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(str
9135 static inline void native_write_idt_entry(gate_desc *idt, int entry,
9136 const gate_desc *gate)
9137 {
9138 + pax_open_kernel();
9139 memcpy(&idt[entry], gate, sizeof(*gate));
9140 + pax_close_kernel();
9141 }
9142
9143 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
9144 const void *desc)
9145 {
9146 + pax_open_kernel();
9147 memcpy(&ldt[entry], desc, 8);
9148 + pax_close_kernel();
9149 }
9150
9151 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9152 @@ -139,7 +146,10 @@ static inline void native_write_gdt_entr
9153 size = sizeof(struct desc_struct);
9154 break;
9155 }
9156 +
9157 + pax_open_kernel();
9158 memcpy(&gdt[entry], desc, size);
9159 + pax_close_kernel();
9160 }
9161
9162 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9163 @@ -211,7 +221,9 @@ static inline void native_set_ldt(const
9164
9165 static inline void native_load_tr_desc(void)
9166 {
9167 + pax_open_kernel();
9168 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9169 + pax_close_kernel();
9170 }
9171
9172 static inline void native_load_gdt(const struct desc_ptr *dtr)
9173 @@ -246,8 +258,10 @@ static inline void native_load_tls(struc
9174 unsigned int i;
9175 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9176
9177 + pax_open_kernel();
9178 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9179 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9180 + pax_close_kernel();
9181 }
9182
9183 #define _LDT_empty(info) \
9184 @@ -309,7 +323,7 @@ static inline void set_desc_limit(struct
9185 desc->limit = (limit >> 16) & 0xf;
9186 }
9187
9188 -static inline void _set_gate(int gate, unsigned type, void *addr,
9189 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9190 unsigned dpl, unsigned ist, unsigned seg)
9191 {
9192 gate_desc s;
9193 @@ -327,7 +341,7 @@ static inline void _set_gate(int gate, u
9194 * Pentium F0 0F bugfix can have resulted in the mapped
9195 * IDT being write-protected.
9196 */
9197 -static inline void set_intr_gate(unsigned int n, void *addr)
9198 +static inline void set_intr_gate(unsigned int n, const void *addr)
9199 {
9200 BUG_ON((unsigned)n > 0xFF);
9201 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9202 @@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsig
9203 /*
9204 * This routine sets up an interrupt gate at directory privilege level 3.
9205 */
9206 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9207 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9208 {
9209 BUG_ON((unsigned)n > 0xFF);
9210 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9211 }
9212
9213 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9214 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9215 {
9216 BUG_ON((unsigned)n > 0xFF);
9217 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9218 }
9219
9220 -static inline void set_trap_gate(unsigned int n, void *addr)
9221 +static inline void set_trap_gate(unsigned int n, const void *addr)
9222 {
9223 BUG_ON((unsigned)n > 0xFF);
9224 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9225 @@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigne
9226 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9227 {
9228 BUG_ON((unsigned)n > 0xFF);
9229 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9230 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9231 }
9232
9233 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9234 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9235 {
9236 BUG_ON((unsigned)n > 0xFF);
9237 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9238 }
9239
9240 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9241 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9242 {
9243 BUG_ON((unsigned)n > 0xFF);
9244 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9245 }
9246
9247 +#ifdef CONFIG_X86_32
9248 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9249 +{
9250 + struct desc_struct d;
9251 +
9252 + if (likely(limit))
9253 + limit = (limit - 1UL) >> PAGE_SHIFT;
9254 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9255 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9256 +}
9257 +#endif
9258 +
9259 #endif /* _ASM_X86_DESC_H */
9260 diff -urNp linux-2.6.32.46/arch/x86/include/asm/desc_defs.h linux-2.6.32.46/arch/x86/include/asm/desc_defs.h
9261 --- linux-2.6.32.46/arch/x86/include/asm/desc_defs.h 2011-03-27 14:31:47.000000000 -0400
9262 +++ linux-2.6.32.46/arch/x86/include/asm/desc_defs.h 2011-04-17 15:56:46.000000000 -0400
9263 @@ -31,6 +31,12 @@ struct desc_struct {
9264 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9265 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9266 };
9267 + struct {
9268 + u16 offset_low;
9269 + u16 seg;
9270 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9271 + unsigned offset_high: 16;
9272 + } gate;
9273 };
9274 } __attribute__((packed));
9275
9276 diff -urNp linux-2.6.32.46/arch/x86/include/asm/device.h linux-2.6.32.46/arch/x86/include/asm/device.h
9277 --- linux-2.6.32.46/arch/x86/include/asm/device.h 2011-03-27 14:31:47.000000000 -0400
9278 +++ linux-2.6.32.46/arch/x86/include/asm/device.h 2011-04-17 15:56:46.000000000 -0400
9279 @@ -6,7 +6,7 @@ struct dev_archdata {
9280 void *acpi_handle;
9281 #endif
9282 #ifdef CONFIG_X86_64
9283 -struct dma_map_ops *dma_ops;
9284 + const struct dma_map_ops *dma_ops;
9285 #endif
9286 #ifdef CONFIG_DMAR
9287 void *iommu; /* hook for IOMMU specific extension */
9288 diff -urNp linux-2.6.32.46/arch/x86/include/asm/dma-mapping.h linux-2.6.32.46/arch/x86/include/asm/dma-mapping.h
9289 --- linux-2.6.32.46/arch/x86/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
9290 +++ linux-2.6.32.46/arch/x86/include/asm/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
9291 @@ -25,9 +25,9 @@ extern int iommu_merge;
9292 extern struct device x86_dma_fallback_dev;
9293 extern int panic_on_overflow;
9294
9295 -extern struct dma_map_ops *dma_ops;
9296 +extern const struct dma_map_ops *dma_ops;
9297
9298 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9299 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
9300 {
9301 #ifdef CONFIG_X86_32
9302 return dma_ops;
9303 @@ -44,7 +44,7 @@ static inline struct dma_map_ops *get_dm
9304 /* Make sure we keep the same behaviour */
9305 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
9306 {
9307 - struct dma_map_ops *ops = get_dma_ops(dev);
9308 + const struct dma_map_ops *ops = get_dma_ops(dev);
9309 if (ops->mapping_error)
9310 return ops->mapping_error(dev, dma_addr);
9311
9312 @@ -122,7 +122,7 @@ static inline void *
9313 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9314 gfp_t gfp)
9315 {
9316 - struct dma_map_ops *ops = get_dma_ops(dev);
9317 + const struct dma_map_ops *ops = get_dma_ops(dev);
9318 void *memory;
9319
9320 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
9321 @@ -149,7 +149,7 @@ dma_alloc_coherent(struct device *dev, s
9322 static inline void dma_free_coherent(struct device *dev, size_t size,
9323 void *vaddr, dma_addr_t bus)
9324 {
9325 - struct dma_map_ops *ops = get_dma_ops(dev);
9326 + const struct dma_map_ops *ops = get_dma_ops(dev);
9327
9328 WARN_ON(irqs_disabled()); /* for portability */
9329
9330 diff -urNp linux-2.6.32.46/arch/x86/include/asm/e820.h linux-2.6.32.46/arch/x86/include/asm/e820.h
9331 --- linux-2.6.32.46/arch/x86/include/asm/e820.h 2011-03-27 14:31:47.000000000 -0400
9332 +++ linux-2.6.32.46/arch/x86/include/asm/e820.h 2011-04-17 15:56:46.000000000 -0400
9333 @@ -133,7 +133,7 @@ extern char *default_machine_specific_me
9334 #define ISA_END_ADDRESS 0x100000
9335 #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
9336
9337 -#define BIOS_BEGIN 0x000a0000
9338 +#define BIOS_BEGIN 0x000c0000
9339 #define BIOS_END 0x00100000
9340
9341 #ifdef __KERNEL__
9342 diff -urNp linux-2.6.32.46/arch/x86/include/asm/elf.h linux-2.6.32.46/arch/x86/include/asm/elf.h
9343 --- linux-2.6.32.46/arch/x86/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
9344 +++ linux-2.6.32.46/arch/x86/include/asm/elf.h 2011-08-23 20:24:19.000000000 -0400
9345 @@ -257,7 +257,25 @@ extern int force_personality32;
9346 the loader. We need to make sure that it is out of the way of the program
9347 that it will "exec", and that there is sufficient room for the brk. */
9348
9349 +#ifdef CONFIG_PAX_SEGMEXEC
9350 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9351 +#else
9352 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9353 +#endif
9354 +
9355 +#ifdef CONFIG_PAX_ASLR
9356 +#ifdef CONFIG_X86_32
9357 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9358 +
9359 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9360 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9361 +#else
9362 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9363 +
9364 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9365 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9366 +#endif
9367 +#endif
9368
9369 /* This yields a mask that user programs can use to figure out what
9370 instruction set this CPU supports. This could be done in user space,
9371 @@ -310,9 +328,7 @@ do { \
9372
9373 #define ARCH_DLINFO \
9374 do { \
9375 - if (vdso_enabled) \
9376 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9377 - (unsigned long)current->mm->context.vdso); \
9378 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
9379 } while (0)
9380
9381 #define AT_SYSINFO 32
9382 @@ -323,7 +339,7 @@ do { \
9383
9384 #endif /* !CONFIG_X86_32 */
9385
9386 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9387 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9388
9389 #define VDSO_ENTRY \
9390 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9391 @@ -337,7 +353,4 @@ extern int arch_setup_additional_pages(s
9392 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9393 #define compat_arch_setup_additional_pages syscall32_setup_pages
9394
9395 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9396 -#define arch_randomize_brk arch_randomize_brk
9397 -
9398 #endif /* _ASM_X86_ELF_H */
9399 diff -urNp linux-2.6.32.46/arch/x86/include/asm/emergency-restart.h linux-2.6.32.46/arch/x86/include/asm/emergency-restart.h
9400 --- linux-2.6.32.46/arch/x86/include/asm/emergency-restart.h 2011-03-27 14:31:47.000000000 -0400
9401 +++ linux-2.6.32.46/arch/x86/include/asm/emergency-restart.h 2011-05-22 23:02:06.000000000 -0400
9402 @@ -15,6 +15,6 @@ enum reboot_type {
9403
9404 extern enum reboot_type reboot_type;
9405
9406 -extern void machine_emergency_restart(void);
9407 +extern void machine_emergency_restart(void) __noreturn;
9408
9409 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
9410 diff -urNp linux-2.6.32.46/arch/x86/include/asm/futex.h linux-2.6.32.46/arch/x86/include/asm/futex.h
9411 --- linux-2.6.32.46/arch/x86/include/asm/futex.h 2011-03-27 14:31:47.000000000 -0400
9412 +++ linux-2.6.32.46/arch/x86/include/asm/futex.h 2011-10-06 09:37:08.000000000 -0400
9413 @@ -12,16 +12,18 @@
9414 #include <asm/system.h>
9415
9416 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
9417 + typecheck(u32 __user *, uaddr); \
9418 asm volatile("1:\t" insn "\n" \
9419 "2:\t.section .fixup,\"ax\"\n" \
9420 "3:\tmov\t%3, %1\n" \
9421 "\tjmp\t2b\n" \
9422 "\t.previous\n" \
9423 _ASM_EXTABLE(1b, 3b) \
9424 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
9425 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
9426 : "i" (-EFAULT), "0" (oparg), "1" (0))
9427
9428 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
9429 + typecheck(u32 __user *, uaddr); \
9430 asm volatile("1:\tmovl %2, %0\n" \
9431 "\tmovl\t%0, %3\n" \
9432 "\t" insn "\n" \
9433 @@ -34,10 +36,10 @@
9434 _ASM_EXTABLE(1b, 4b) \
9435 _ASM_EXTABLE(2b, 4b) \
9436 : "=&a" (oldval), "=&r" (ret), \
9437 - "+m" (*uaddr), "=&r" (tem) \
9438 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
9439 : "r" (oparg), "i" (-EFAULT), "1" (0))
9440
9441 -static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
9442 +static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
9443 {
9444 int op = (encoded_op >> 28) & 7;
9445 int cmp = (encoded_op >> 24) & 15;
9446 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
9447
9448 switch (op) {
9449 case FUTEX_OP_SET:
9450 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
9451 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
9452 break;
9453 case FUTEX_OP_ADD:
9454 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
9455 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
9456 uaddr, oparg);
9457 break;
9458 case FUTEX_OP_OR:
9459 @@ -109,7 +111,7 @@ static inline int futex_atomic_op_inuser
9460 return ret;
9461 }
9462
9463 -static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
9464 +static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
9465 int newval)
9466 {
9467
9468 @@ -119,16 +121,16 @@ static inline int futex_atomic_cmpxchg_i
9469 return -ENOSYS;
9470 #endif
9471
9472 - if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
9473 + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
9474 return -EFAULT;
9475
9476 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n"
9477 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %1\n"
9478 "2:\t.section .fixup, \"ax\"\n"
9479 "3:\tmov %2, %0\n"
9480 "\tjmp 2b\n"
9481 "\t.previous\n"
9482 _ASM_EXTABLE(1b, 3b)
9483 - : "=a" (oldval), "+m" (*uaddr)
9484 + : "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
9485 : "i" (-EFAULT), "r" (newval), "0" (oldval)
9486 : "memory"
9487 );
9488 diff -urNp linux-2.6.32.46/arch/x86/include/asm/hw_irq.h linux-2.6.32.46/arch/x86/include/asm/hw_irq.h
9489 --- linux-2.6.32.46/arch/x86/include/asm/hw_irq.h 2011-03-27 14:31:47.000000000 -0400
9490 +++ linux-2.6.32.46/arch/x86/include/asm/hw_irq.h 2011-05-04 17:56:28.000000000 -0400
9491 @@ -92,8 +92,8 @@ extern void setup_ioapic_dest(void);
9492 extern void enable_IO_APIC(void);
9493
9494 /* Statistics */
9495 -extern atomic_t irq_err_count;
9496 -extern atomic_t irq_mis_count;
9497 +extern atomic_unchecked_t irq_err_count;
9498 +extern atomic_unchecked_t irq_mis_count;
9499
9500 /* EISA */
9501 extern void eisa_set_level_irq(unsigned int irq);
9502 diff -urNp linux-2.6.32.46/arch/x86/include/asm/i387.h linux-2.6.32.46/arch/x86/include/asm/i387.h
9503 --- linux-2.6.32.46/arch/x86/include/asm/i387.h 2011-03-27 14:31:47.000000000 -0400
9504 +++ linux-2.6.32.46/arch/x86/include/asm/i387.h 2011-04-17 15:56:46.000000000 -0400
9505 @@ -60,6 +60,11 @@ static inline int fxrstor_checking(struc
9506 {
9507 int err;
9508
9509 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9510 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9511 + fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
9512 +#endif
9513 +
9514 asm volatile("1: rex64/fxrstor (%[fx])\n\t"
9515 "2:\n"
9516 ".section .fixup,\"ax\"\n"
9517 @@ -105,6 +110,11 @@ static inline int fxsave_user(struct i38
9518 {
9519 int err;
9520
9521 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9522 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9523 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
9524 +#endif
9525 +
9526 asm volatile("1: rex64/fxsave (%[fx])\n\t"
9527 "2:\n"
9528 ".section .fixup,\"ax\"\n"
9529 @@ -195,13 +205,8 @@ static inline int fxrstor_checking(struc
9530 }
9531
9532 /* We need a safe address that is cheap to find and that is already
9533 - in L1 during context switch. The best choices are unfortunately
9534 - different for UP and SMP */
9535 -#ifdef CONFIG_SMP
9536 -#define safe_address (__per_cpu_offset[0])
9537 -#else
9538 -#define safe_address (kstat_cpu(0).cpustat.user)
9539 -#endif
9540 + in L1 during context switch. */
9541 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
9542
9543 /*
9544 * These must be called with preempt disabled
9545 @@ -291,7 +296,7 @@ static inline void kernel_fpu_begin(void
9546 struct thread_info *me = current_thread_info();
9547 preempt_disable();
9548 if (me->status & TS_USEDFPU)
9549 - __save_init_fpu(me->task);
9550 + __save_init_fpu(current);
9551 else
9552 clts();
9553 }
9554 diff -urNp linux-2.6.32.46/arch/x86/include/asm/io_32.h linux-2.6.32.46/arch/x86/include/asm/io_32.h
9555 --- linux-2.6.32.46/arch/x86/include/asm/io_32.h 2011-03-27 14:31:47.000000000 -0400
9556 +++ linux-2.6.32.46/arch/x86/include/asm/io_32.h 2011-04-17 15:56:46.000000000 -0400
9557 @@ -3,6 +3,7 @@
9558
9559 #include <linux/string.h>
9560 #include <linux/compiler.h>
9561 +#include <asm/processor.h>
9562
9563 /*
9564 * This file contains the definitions for the x86 IO instructions
9565 @@ -42,6 +43,17 @@
9566
9567 #ifdef __KERNEL__
9568
9569 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
9570 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
9571 +{
9572 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9573 +}
9574 +
9575 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
9576 +{
9577 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9578 +}
9579 +
9580 #include <asm-generic/iomap.h>
9581
9582 #include <linux/vmalloc.h>
9583 diff -urNp linux-2.6.32.46/arch/x86/include/asm/io_64.h linux-2.6.32.46/arch/x86/include/asm/io_64.h
9584 --- linux-2.6.32.46/arch/x86/include/asm/io_64.h 2011-03-27 14:31:47.000000000 -0400
9585 +++ linux-2.6.32.46/arch/x86/include/asm/io_64.h 2011-04-17 15:56:46.000000000 -0400
9586 @@ -140,6 +140,17 @@ __OUTS(l)
9587
9588 #include <linux/vmalloc.h>
9589
9590 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
9591 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
9592 +{
9593 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9594 +}
9595 +
9596 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
9597 +{
9598 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9599 +}
9600 +
9601 #include <asm-generic/iomap.h>
9602
9603 void __memcpy_fromio(void *, unsigned long, unsigned);
9604 diff -urNp linux-2.6.32.46/arch/x86/include/asm/iommu.h linux-2.6.32.46/arch/x86/include/asm/iommu.h
9605 --- linux-2.6.32.46/arch/x86/include/asm/iommu.h 2011-03-27 14:31:47.000000000 -0400
9606 +++ linux-2.6.32.46/arch/x86/include/asm/iommu.h 2011-04-17 15:56:46.000000000 -0400
9607 @@ -3,7 +3,7 @@
9608
9609 extern void pci_iommu_shutdown(void);
9610 extern void no_iommu_init(void);
9611 -extern struct dma_map_ops nommu_dma_ops;
9612 +extern const struct dma_map_ops nommu_dma_ops;
9613 extern int force_iommu, no_iommu;
9614 extern int iommu_detected;
9615 extern int iommu_pass_through;
9616 diff -urNp linux-2.6.32.46/arch/x86/include/asm/irqflags.h linux-2.6.32.46/arch/x86/include/asm/irqflags.h
9617 --- linux-2.6.32.46/arch/x86/include/asm/irqflags.h 2011-03-27 14:31:47.000000000 -0400
9618 +++ linux-2.6.32.46/arch/x86/include/asm/irqflags.h 2011-04-17 15:56:46.000000000 -0400
9619 @@ -142,6 +142,11 @@ static inline unsigned long __raw_local_
9620 sti; \
9621 sysexit
9622
9623 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
9624 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
9625 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
9626 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
9627 +
9628 #else
9629 #define INTERRUPT_RETURN iret
9630 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
9631 diff -urNp linux-2.6.32.46/arch/x86/include/asm/kprobes.h linux-2.6.32.46/arch/x86/include/asm/kprobes.h
9632 --- linux-2.6.32.46/arch/x86/include/asm/kprobes.h 2011-03-27 14:31:47.000000000 -0400
9633 +++ linux-2.6.32.46/arch/x86/include/asm/kprobes.h 2011-04-23 12:56:12.000000000 -0400
9634 @@ -34,13 +34,8 @@ typedef u8 kprobe_opcode_t;
9635 #define BREAKPOINT_INSTRUCTION 0xcc
9636 #define RELATIVEJUMP_INSTRUCTION 0xe9
9637 #define MAX_INSN_SIZE 16
9638 -#define MAX_STACK_SIZE 64
9639 -#define MIN_STACK_SIZE(ADDR) \
9640 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
9641 - THREAD_SIZE - (unsigned long)(ADDR))) \
9642 - ? (MAX_STACK_SIZE) \
9643 - : (((unsigned long)current_thread_info()) + \
9644 - THREAD_SIZE - (unsigned long)(ADDR)))
9645 +#define MAX_STACK_SIZE 64UL
9646 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
9647
9648 #define flush_insn_slot(p) do { } while (0)
9649
9650 diff -urNp linux-2.6.32.46/arch/x86/include/asm/kvm_host.h linux-2.6.32.46/arch/x86/include/asm/kvm_host.h
9651 --- linux-2.6.32.46/arch/x86/include/asm/kvm_host.h 2011-05-10 22:12:01.000000000 -0400
9652 +++ linux-2.6.32.46/arch/x86/include/asm/kvm_host.h 2011-08-26 20:19:09.000000000 -0400
9653 @@ -534,9 +534,9 @@ struct kvm_x86_ops {
9654 bool (*gb_page_enable)(void);
9655
9656 const struct trace_print_flags *exit_reasons_str;
9657 -};
9658 +} __do_const;
9659
9660 -extern struct kvm_x86_ops *kvm_x86_ops;
9661 +extern const struct kvm_x86_ops *kvm_x86_ops;
9662
9663 int kvm_mmu_module_init(void);
9664 void kvm_mmu_module_exit(void);
9665 diff -urNp linux-2.6.32.46/arch/x86/include/asm/local.h linux-2.6.32.46/arch/x86/include/asm/local.h
9666 --- linux-2.6.32.46/arch/x86/include/asm/local.h 2011-03-27 14:31:47.000000000 -0400
9667 +++ linux-2.6.32.46/arch/x86/include/asm/local.h 2011-04-17 15:56:46.000000000 -0400
9668 @@ -18,26 +18,58 @@ typedef struct {
9669
9670 static inline void local_inc(local_t *l)
9671 {
9672 - asm volatile(_ASM_INC "%0"
9673 + asm volatile(_ASM_INC "%0\n"
9674 +
9675 +#ifdef CONFIG_PAX_REFCOUNT
9676 + "jno 0f\n"
9677 + _ASM_DEC "%0\n"
9678 + "int $4\n0:\n"
9679 + _ASM_EXTABLE(0b, 0b)
9680 +#endif
9681 +
9682 : "+m" (l->a.counter));
9683 }
9684
9685 static inline void local_dec(local_t *l)
9686 {
9687 - asm volatile(_ASM_DEC "%0"
9688 + asm volatile(_ASM_DEC "%0\n"
9689 +
9690 +#ifdef CONFIG_PAX_REFCOUNT
9691 + "jno 0f\n"
9692 + _ASM_INC "%0\n"
9693 + "int $4\n0:\n"
9694 + _ASM_EXTABLE(0b, 0b)
9695 +#endif
9696 +
9697 : "+m" (l->a.counter));
9698 }
9699
9700 static inline void local_add(long i, local_t *l)
9701 {
9702 - asm volatile(_ASM_ADD "%1,%0"
9703 + asm volatile(_ASM_ADD "%1,%0\n"
9704 +
9705 +#ifdef CONFIG_PAX_REFCOUNT
9706 + "jno 0f\n"
9707 + _ASM_SUB "%1,%0\n"
9708 + "int $4\n0:\n"
9709 + _ASM_EXTABLE(0b, 0b)
9710 +#endif
9711 +
9712 : "+m" (l->a.counter)
9713 : "ir" (i));
9714 }
9715
9716 static inline void local_sub(long i, local_t *l)
9717 {
9718 - asm volatile(_ASM_SUB "%1,%0"
9719 + asm volatile(_ASM_SUB "%1,%0\n"
9720 +
9721 +#ifdef CONFIG_PAX_REFCOUNT
9722 + "jno 0f\n"
9723 + _ASM_ADD "%1,%0\n"
9724 + "int $4\n0:\n"
9725 + _ASM_EXTABLE(0b, 0b)
9726 +#endif
9727 +
9728 : "+m" (l->a.counter)
9729 : "ir" (i));
9730 }
9731 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
9732 {
9733 unsigned char c;
9734
9735 - asm volatile(_ASM_SUB "%2,%0; sete %1"
9736 + asm volatile(_ASM_SUB "%2,%0\n"
9737 +
9738 +#ifdef CONFIG_PAX_REFCOUNT
9739 + "jno 0f\n"
9740 + _ASM_ADD "%2,%0\n"
9741 + "int $4\n0:\n"
9742 + _ASM_EXTABLE(0b, 0b)
9743 +#endif
9744 +
9745 + "sete %1\n"
9746 : "+m" (l->a.counter), "=qm" (c)
9747 : "ir" (i) : "memory");
9748 return c;
9749 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
9750 {
9751 unsigned char c;
9752
9753 - asm volatile(_ASM_DEC "%0; sete %1"
9754 + asm volatile(_ASM_DEC "%0\n"
9755 +
9756 +#ifdef CONFIG_PAX_REFCOUNT
9757 + "jno 0f\n"
9758 + _ASM_INC "%0\n"
9759 + "int $4\n0:\n"
9760 + _ASM_EXTABLE(0b, 0b)
9761 +#endif
9762 +
9763 + "sete %1\n"
9764 : "+m" (l->a.counter), "=qm" (c)
9765 : : "memory");
9766 return c != 0;
9767 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
9768 {
9769 unsigned char c;
9770
9771 - asm volatile(_ASM_INC "%0; sete %1"
9772 + asm volatile(_ASM_INC "%0\n"
9773 +
9774 +#ifdef CONFIG_PAX_REFCOUNT
9775 + "jno 0f\n"
9776 + _ASM_DEC "%0\n"
9777 + "int $4\n0:\n"
9778 + _ASM_EXTABLE(0b, 0b)
9779 +#endif
9780 +
9781 + "sete %1\n"
9782 : "+m" (l->a.counter), "=qm" (c)
9783 : : "memory");
9784 return c != 0;
9785 @@ -110,7 +169,16 @@ static inline int local_add_negative(lon
9786 {
9787 unsigned char c;
9788
9789 - asm volatile(_ASM_ADD "%2,%0; sets %1"
9790 + asm volatile(_ASM_ADD "%2,%0\n"
9791 +
9792 +#ifdef CONFIG_PAX_REFCOUNT
9793 + "jno 0f\n"
9794 + _ASM_SUB "%2,%0\n"
9795 + "int $4\n0:\n"
9796 + _ASM_EXTABLE(0b, 0b)
9797 +#endif
9798 +
9799 + "sets %1\n"
9800 : "+m" (l->a.counter), "=qm" (c)
9801 : "ir" (i) : "memory");
9802 return c;
9803 @@ -133,7 +201,15 @@ static inline long local_add_return(long
9804 #endif
9805 /* Modern 486+ processor */
9806 __i = i;
9807 - asm volatile(_ASM_XADD "%0, %1;"
9808 + asm volatile(_ASM_XADD "%0, %1\n"
9809 +
9810 +#ifdef CONFIG_PAX_REFCOUNT
9811 + "jno 0f\n"
9812 + _ASM_MOV "%0,%1\n"
9813 + "int $4\n0:\n"
9814 + _ASM_EXTABLE(0b, 0b)
9815 +#endif
9816 +
9817 : "+r" (i), "+m" (l->a.counter)
9818 : : "memory");
9819 return i + __i;
9820 diff -urNp linux-2.6.32.46/arch/x86/include/asm/microcode.h linux-2.6.32.46/arch/x86/include/asm/microcode.h
9821 --- linux-2.6.32.46/arch/x86/include/asm/microcode.h 2011-03-27 14:31:47.000000000 -0400
9822 +++ linux-2.6.32.46/arch/x86/include/asm/microcode.h 2011-04-17 15:56:46.000000000 -0400
9823 @@ -12,13 +12,13 @@ struct device;
9824 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
9825
9826 struct microcode_ops {
9827 - enum ucode_state (*request_microcode_user) (int cpu,
9828 + enum ucode_state (* const request_microcode_user) (int cpu,
9829 const void __user *buf, size_t size);
9830
9831 - enum ucode_state (*request_microcode_fw) (int cpu,
9832 + enum ucode_state (* const request_microcode_fw) (int cpu,
9833 struct device *device);
9834
9835 - void (*microcode_fini_cpu) (int cpu);
9836 + void (* const microcode_fini_cpu) (int cpu);
9837
9838 /*
9839 * The generic 'microcode_core' part guarantees that
9840 @@ -38,18 +38,18 @@ struct ucode_cpu_info {
9841 extern struct ucode_cpu_info ucode_cpu_info[];
9842
9843 #ifdef CONFIG_MICROCODE_INTEL
9844 -extern struct microcode_ops * __init init_intel_microcode(void);
9845 +extern const struct microcode_ops * __init init_intel_microcode(void);
9846 #else
9847 -static inline struct microcode_ops * __init init_intel_microcode(void)
9848 +static inline const struct microcode_ops * __init init_intel_microcode(void)
9849 {
9850 return NULL;
9851 }
9852 #endif /* CONFIG_MICROCODE_INTEL */
9853
9854 #ifdef CONFIG_MICROCODE_AMD
9855 -extern struct microcode_ops * __init init_amd_microcode(void);
9856 +extern const struct microcode_ops * __init init_amd_microcode(void);
9857 #else
9858 -static inline struct microcode_ops * __init init_amd_microcode(void)
9859 +static inline const struct microcode_ops * __init init_amd_microcode(void)
9860 {
9861 return NULL;
9862 }
9863 diff -urNp linux-2.6.32.46/arch/x86/include/asm/mman.h linux-2.6.32.46/arch/x86/include/asm/mman.h
9864 --- linux-2.6.32.46/arch/x86/include/asm/mman.h 2011-03-27 14:31:47.000000000 -0400
9865 +++ linux-2.6.32.46/arch/x86/include/asm/mman.h 2011-04-17 15:56:46.000000000 -0400
9866 @@ -5,4 +5,14 @@
9867
9868 #include <asm-generic/mman.h>
9869
9870 +#ifdef __KERNEL__
9871 +#ifndef __ASSEMBLY__
9872 +#ifdef CONFIG_X86_32
9873 +#define arch_mmap_check i386_mmap_check
9874 +int i386_mmap_check(unsigned long addr, unsigned long len,
9875 + unsigned long flags);
9876 +#endif
9877 +#endif
9878 +#endif
9879 +
9880 #endif /* _ASM_X86_MMAN_H */
9881 diff -urNp linux-2.6.32.46/arch/x86/include/asm/mmu.h linux-2.6.32.46/arch/x86/include/asm/mmu.h
9882 --- linux-2.6.32.46/arch/x86/include/asm/mmu.h 2011-03-27 14:31:47.000000000 -0400
9883 +++ linux-2.6.32.46/arch/x86/include/asm/mmu.h 2011-04-17 15:56:46.000000000 -0400
9884 @@ -9,10 +9,23 @@
9885 * we put the segment information here.
9886 */
9887 typedef struct {
9888 - void *ldt;
9889 + struct desc_struct *ldt;
9890 int size;
9891 struct mutex lock;
9892 - void *vdso;
9893 + unsigned long vdso;
9894 +
9895 +#ifdef CONFIG_X86_32
9896 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
9897 + unsigned long user_cs_base;
9898 + unsigned long user_cs_limit;
9899 +
9900 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9901 + cpumask_t cpu_user_cs_mask;
9902 +#endif
9903 +
9904 +#endif
9905 +#endif
9906 +
9907 } mm_context_t;
9908
9909 #ifdef CONFIG_SMP
9910 diff -urNp linux-2.6.32.46/arch/x86/include/asm/mmu_context.h linux-2.6.32.46/arch/x86/include/asm/mmu_context.h
9911 --- linux-2.6.32.46/arch/x86/include/asm/mmu_context.h 2011-03-27 14:31:47.000000000 -0400
9912 +++ linux-2.6.32.46/arch/x86/include/asm/mmu_context.h 2011-08-23 20:24:19.000000000 -0400
9913 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *m
9914
9915 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
9916 {
9917 +
9918 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9919 + unsigned int i;
9920 + pgd_t *pgd;
9921 +
9922 + pax_open_kernel();
9923 + pgd = get_cpu_pgd(smp_processor_id());
9924 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
9925 + set_pgd_batched(pgd+i, native_make_pgd(0));
9926 + pax_close_kernel();
9927 +#endif
9928 +
9929 #ifdef CONFIG_SMP
9930 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
9931 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
9932 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_s
9933 struct task_struct *tsk)
9934 {
9935 unsigned cpu = smp_processor_id();
9936 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)) && defined(CONFIG_SMP)
9937 + int tlbstate = TLBSTATE_OK;
9938 +#endif
9939
9940 if (likely(prev != next)) {
9941 #ifdef CONFIG_SMP
9942 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9943 + tlbstate = percpu_read(cpu_tlbstate.state);
9944 +#endif
9945 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
9946 percpu_write(cpu_tlbstate.active_mm, next);
9947 #endif
9948 cpumask_set_cpu(cpu, mm_cpumask(next));
9949
9950 /* Re-load page tables */
9951 +#ifdef CONFIG_PAX_PER_CPU_PGD
9952 + pax_open_kernel();
9953 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9954 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9955 + pax_close_kernel();
9956 + load_cr3(get_cpu_pgd(cpu));
9957 +#else
9958 load_cr3(next->pgd);
9959 +#endif
9960
9961 /* stop flush ipis for the previous mm */
9962 cpumask_clear_cpu(cpu, mm_cpumask(prev));
9963 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_s
9964 */
9965 if (unlikely(prev->context.ldt != next->context.ldt))
9966 load_LDT_nolock(&next->context);
9967 - }
9968 +
9969 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9970 + if (!nx_enabled) {
9971 + smp_mb__before_clear_bit();
9972 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
9973 + smp_mb__after_clear_bit();
9974 + cpu_set(cpu, next->context.cpu_user_cs_mask);
9975 + }
9976 +#endif
9977 +
9978 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9979 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
9980 + prev->context.user_cs_limit != next->context.user_cs_limit))
9981 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9982 #ifdef CONFIG_SMP
9983 + else if (unlikely(tlbstate != TLBSTATE_OK))
9984 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9985 +#endif
9986 +#endif
9987 +
9988 + }
9989 else {
9990 +
9991 +#ifdef CONFIG_PAX_PER_CPU_PGD
9992 + pax_open_kernel();
9993 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9994 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9995 + pax_close_kernel();
9996 + load_cr3(get_cpu_pgd(cpu));
9997 +#endif
9998 +
9999 +#ifdef CONFIG_SMP
10000 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10001 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10002
10003 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_s
10004 * tlb flush IPI delivery. We must reload CR3
10005 * to make sure to use no freed page tables.
10006 */
10007 +
10008 +#ifndef CONFIG_PAX_PER_CPU_PGD
10009 load_cr3(next->pgd);
10010 +#endif
10011 +
10012 load_LDT_nolock(&next->context);
10013 +
10014 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10015 + if (!nx_enabled)
10016 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10017 +#endif
10018 +
10019 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10020 +#ifdef CONFIG_PAX_PAGEEXEC
10021 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
10022 +#endif
10023 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10024 +#endif
10025 +
10026 }
10027 - }
10028 #endif
10029 + }
10030 }
10031
10032 #define activate_mm(prev, next) \
10033 diff -urNp linux-2.6.32.46/arch/x86/include/asm/module.h linux-2.6.32.46/arch/x86/include/asm/module.h
10034 --- linux-2.6.32.46/arch/x86/include/asm/module.h 2011-03-27 14:31:47.000000000 -0400
10035 +++ linux-2.6.32.46/arch/x86/include/asm/module.h 2011-10-08 08:16:59.000000000 -0400
10036 @@ -5,6 +5,7 @@
10037
10038 #ifdef CONFIG_X86_64
10039 /* X86_64 does not define MODULE_PROC_FAMILY */
10040 +#define MODULE_PROC_FAMILY ""
10041 #elif defined CONFIG_M386
10042 #define MODULE_PROC_FAMILY "386 "
10043 #elif defined CONFIG_M486
10044 @@ -59,13 +60,24 @@
10045 #error unknown processor family
10046 #endif
10047
10048 -#ifdef CONFIG_X86_32
10049 -# ifdef CONFIG_4KSTACKS
10050 -# define MODULE_STACKSIZE "4KSTACKS "
10051 -# else
10052 -# define MODULE_STACKSIZE ""
10053 -# endif
10054 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
10055 +#if defined(CONFIG_X86_32) && defined(CONFIG_4KSTACKS)
10056 +#define MODULE_STACKSIZE "4KSTACKS "
10057 +#else
10058 +#define MODULE_STACKSIZE ""
10059 +#endif
10060 +
10061 +#ifdef CONFIG_PAX_KERNEXEC
10062 +#define MODULE_PAX_KERNEXEC "KERNEXEC "
10063 +#else
10064 +#define MODULE_PAX_KERNEXEC ""
10065 #endif
10066
10067 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10068 +#define MODULE_PAX_UDEREF "UDEREF "
10069 +#else
10070 +#define MODULE_PAX_UDEREF ""
10071 +#endif
10072 +
10073 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10074 +
10075 #endif /* _ASM_X86_MODULE_H */
10076 diff -urNp linux-2.6.32.46/arch/x86/include/asm/page_64_types.h linux-2.6.32.46/arch/x86/include/asm/page_64_types.h
10077 --- linux-2.6.32.46/arch/x86/include/asm/page_64_types.h 2011-03-27 14:31:47.000000000 -0400
10078 +++ linux-2.6.32.46/arch/x86/include/asm/page_64_types.h 2011-04-17 15:56:46.000000000 -0400
10079 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10080
10081 /* duplicated to the one in bootmem.h */
10082 extern unsigned long max_pfn;
10083 -extern unsigned long phys_base;
10084 +extern const unsigned long phys_base;
10085
10086 extern unsigned long __phys_addr(unsigned long);
10087 #define __phys_reloc_hide(x) (x)
10088 diff -urNp linux-2.6.32.46/arch/x86/include/asm/paravirt.h linux-2.6.32.46/arch/x86/include/asm/paravirt.h
10089 --- linux-2.6.32.46/arch/x86/include/asm/paravirt.h 2011-03-27 14:31:47.000000000 -0400
10090 +++ linux-2.6.32.46/arch/x86/include/asm/paravirt.h 2011-08-23 21:36:48.000000000 -0400
10091 @@ -648,6 +648,18 @@ static inline void set_pgd(pgd_t *pgdp,
10092 val);
10093 }
10094
10095 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10096 +{
10097 + pgdval_t val = native_pgd_val(pgd);
10098 +
10099 + if (sizeof(pgdval_t) > sizeof(long))
10100 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10101 + val, (u64)val >> 32);
10102 + else
10103 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10104 + val);
10105 +}
10106 +
10107 static inline void pgd_clear(pgd_t *pgdp)
10108 {
10109 set_pgd(pgdp, __pgd(0));
10110 @@ -729,6 +741,21 @@ static inline void __set_fixmap(unsigned
10111 pv_mmu_ops.set_fixmap(idx, phys, flags);
10112 }
10113
10114 +#ifdef CONFIG_PAX_KERNEXEC
10115 +static inline unsigned long pax_open_kernel(void)
10116 +{
10117 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10118 +}
10119 +
10120 +static inline unsigned long pax_close_kernel(void)
10121 +{
10122 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10123 +}
10124 +#else
10125 +static inline unsigned long pax_open_kernel(void) { return 0; }
10126 +static inline unsigned long pax_close_kernel(void) { return 0; }
10127 +#endif
10128 +
10129 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10130
10131 static inline int __raw_spin_is_locked(struct raw_spinlock *lock)
10132 @@ -945,7 +972,7 @@ extern void default_banner(void);
10133
10134 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10135 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10136 -#define PARA_INDIRECT(addr) *%cs:addr
10137 +#define PARA_INDIRECT(addr) *%ss:addr
10138 #endif
10139
10140 #define INTERRUPT_RETURN \
10141 @@ -1022,6 +1049,21 @@ extern void default_banner(void);
10142 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10143 CLBR_NONE, \
10144 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10145 +
10146 +#define GET_CR0_INTO_RDI \
10147 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10148 + mov %rax,%rdi
10149 +
10150 +#define SET_RDI_INTO_CR0 \
10151 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10152 +
10153 +#define GET_CR3_INTO_RDI \
10154 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10155 + mov %rax,%rdi
10156 +
10157 +#define SET_RDI_INTO_CR3 \
10158 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10159 +
10160 #endif /* CONFIG_X86_32 */
10161
10162 #endif /* __ASSEMBLY__ */
10163 diff -urNp linux-2.6.32.46/arch/x86/include/asm/paravirt_types.h linux-2.6.32.46/arch/x86/include/asm/paravirt_types.h
10164 --- linux-2.6.32.46/arch/x86/include/asm/paravirt_types.h 2011-03-27 14:31:47.000000000 -0400
10165 +++ linux-2.6.32.46/arch/x86/include/asm/paravirt_types.h 2011-08-23 20:24:19.000000000 -0400
10166 @@ -78,19 +78,19 @@ struct pv_init_ops {
10167 */
10168 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10169 unsigned long addr, unsigned len);
10170 -};
10171 +} __no_const;
10172
10173
10174 struct pv_lazy_ops {
10175 /* Set deferred update mode, used for batching operations. */
10176 void (*enter)(void);
10177 void (*leave)(void);
10178 -};
10179 +} __no_const;
10180
10181 struct pv_time_ops {
10182 unsigned long long (*sched_clock)(void);
10183 unsigned long (*get_tsc_khz)(void);
10184 -};
10185 +} __no_const;
10186
10187 struct pv_cpu_ops {
10188 /* hooks for various privileged instructions */
10189 @@ -186,7 +186,7 @@ struct pv_cpu_ops {
10190
10191 void (*start_context_switch)(struct task_struct *prev);
10192 void (*end_context_switch)(struct task_struct *next);
10193 -};
10194 +} __no_const;
10195
10196 struct pv_irq_ops {
10197 /*
10198 @@ -217,7 +217,7 @@ struct pv_apic_ops {
10199 unsigned long start_eip,
10200 unsigned long start_esp);
10201 #endif
10202 -};
10203 +} __no_const;
10204
10205 struct pv_mmu_ops {
10206 unsigned long (*read_cr2)(void);
10207 @@ -301,6 +301,7 @@ struct pv_mmu_ops {
10208 struct paravirt_callee_save make_pud;
10209
10210 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10211 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10212 #endif /* PAGETABLE_LEVELS == 4 */
10213 #endif /* PAGETABLE_LEVELS >= 3 */
10214
10215 @@ -316,6 +317,12 @@ struct pv_mmu_ops {
10216 an mfn. We can tell which is which from the index. */
10217 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10218 phys_addr_t phys, pgprot_t flags);
10219 +
10220 +#ifdef CONFIG_PAX_KERNEXEC
10221 + unsigned long (*pax_open_kernel)(void);
10222 + unsigned long (*pax_close_kernel)(void);
10223 +#endif
10224 +
10225 };
10226
10227 struct raw_spinlock;
10228 @@ -326,7 +333,7 @@ struct pv_lock_ops {
10229 void (*spin_lock_flags)(struct raw_spinlock *lock, unsigned long flags);
10230 int (*spin_trylock)(struct raw_spinlock *lock);
10231 void (*spin_unlock)(struct raw_spinlock *lock);
10232 -};
10233 +} __no_const;
10234
10235 /* This contains all the paravirt structures: we get a convenient
10236 * number for each function using the offset which we use to indicate
10237 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pci_x86.h linux-2.6.32.46/arch/x86/include/asm/pci_x86.h
10238 --- linux-2.6.32.46/arch/x86/include/asm/pci_x86.h 2011-03-27 14:31:47.000000000 -0400
10239 +++ linux-2.6.32.46/arch/x86/include/asm/pci_x86.h 2011-04-17 15:56:46.000000000 -0400
10240 @@ -89,16 +89,16 @@ extern int (*pcibios_enable_irq)(struct
10241 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
10242
10243 struct pci_raw_ops {
10244 - int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10245 + int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10246 int reg, int len, u32 *val);
10247 - int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10248 + int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10249 int reg, int len, u32 val);
10250 };
10251
10252 -extern struct pci_raw_ops *raw_pci_ops;
10253 -extern struct pci_raw_ops *raw_pci_ext_ops;
10254 +extern const struct pci_raw_ops *raw_pci_ops;
10255 +extern const struct pci_raw_ops *raw_pci_ext_ops;
10256
10257 -extern struct pci_raw_ops pci_direct_conf1;
10258 +extern const struct pci_raw_ops pci_direct_conf1;
10259 extern bool port_cf9_safe;
10260
10261 /* arch_initcall level */
10262 diff -urNp linux-2.6.32.46/arch/x86/include/asm/percpu.h linux-2.6.32.46/arch/x86/include/asm/percpu.h
10263 --- linux-2.6.32.46/arch/x86/include/asm/percpu.h 2011-03-27 14:31:47.000000000 -0400
10264 +++ linux-2.6.32.46/arch/x86/include/asm/percpu.h 2011-08-17 19:33:59.000000000 -0400
10265 @@ -78,6 +78,7 @@ do { \
10266 if (0) { \
10267 T__ tmp__; \
10268 tmp__ = (val); \
10269 + (void)tmp__; \
10270 } \
10271 switch (sizeof(var)) { \
10272 case 1: \
10273 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pgalloc.h linux-2.6.32.46/arch/x86/include/asm/pgalloc.h
10274 --- linux-2.6.32.46/arch/x86/include/asm/pgalloc.h 2011-03-27 14:31:47.000000000 -0400
10275 +++ linux-2.6.32.46/arch/x86/include/asm/pgalloc.h 2011-04-17 15:56:46.000000000 -0400
10276 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
10277 pmd_t *pmd, pte_t *pte)
10278 {
10279 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10280 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10281 +}
10282 +
10283 +static inline void pmd_populate_user(struct mm_struct *mm,
10284 + pmd_t *pmd, pte_t *pte)
10285 +{
10286 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10287 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10288 }
10289
10290 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pgtable-2level.h linux-2.6.32.46/arch/x86/include/asm/pgtable-2level.h
10291 --- linux-2.6.32.46/arch/x86/include/asm/pgtable-2level.h 2011-03-27 14:31:47.000000000 -0400
10292 +++ linux-2.6.32.46/arch/x86/include/asm/pgtable-2level.h 2011-04-17 15:56:46.000000000 -0400
10293 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
10294
10295 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10296 {
10297 + pax_open_kernel();
10298 *pmdp = pmd;
10299 + pax_close_kernel();
10300 }
10301
10302 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10303 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pgtable-3level.h linux-2.6.32.46/arch/x86/include/asm/pgtable-3level.h
10304 --- linux-2.6.32.46/arch/x86/include/asm/pgtable-3level.h 2011-03-27 14:31:47.000000000 -0400
10305 +++ linux-2.6.32.46/arch/x86/include/asm/pgtable-3level.h 2011-04-17 15:56:46.000000000 -0400
10306 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
10307
10308 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10309 {
10310 + pax_open_kernel();
10311 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10312 + pax_close_kernel();
10313 }
10314
10315 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10316 {
10317 + pax_open_kernel();
10318 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10319 + pax_close_kernel();
10320 }
10321
10322 /*
10323 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pgtable.h linux-2.6.32.46/arch/x86/include/asm/pgtable.h
10324 --- linux-2.6.32.46/arch/x86/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
10325 +++ linux-2.6.32.46/arch/x86/include/asm/pgtable.h 2011-08-23 20:24:19.000000000 -0400
10326 @@ -39,6 +39,7 @@ extern struct list_head pgd_list;
10327
10328 #ifndef __PAGETABLE_PUD_FOLDED
10329 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10330 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10331 #define pgd_clear(pgd) native_pgd_clear(pgd)
10332 #endif
10333
10334 @@ -74,12 +75,51 @@ extern struct list_head pgd_list;
10335
10336 #define arch_end_context_switch(prev) do {} while(0)
10337
10338 +#define pax_open_kernel() native_pax_open_kernel()
10339 +#define pax_close_kernel() native_pax_close_kernel()
10340 #endif /* CONFIG_PARAVIRT */
10341
10342 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10343 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10344 +
10345 +#ifdef CONFIG_PAX_KERNEXEC
10346 +static inline unsigned long native_pax_open_kernel(void)
10347 +{
10348 + unsigned long cr0;
10349 +
10350 + preempt_disable();
10351 + barrier();
10352 + cr0 = read_cr0() ^ X86_CR0_WP;
10353 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10354 + write_cr0(cr0);
10355 + return cr0 ^ X86_CR0_WP;
10356 +}
10357 +
10358 +static inline unsigned long native_pax_close_kernel(void)
10359 +{
10360 + unsigned long cr0;
10361 +
10362 + cr0 = read_cr0() ^ X86_CR0_WP;
10363 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10364 + write_cr0(cr0);
10365 + barrier();
10366 + preempt_enable_no_resched();
10367 + return cr0 ^ X86_CR0_WP;
10368 +}
10369 +#else
10370 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10371 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10372 +#endif
10373 +
10374 /*
10375 * The following only work if pte_present() is true.
10376 * Undefined behaviour if not..
10377 */
10378 +static inline int pte_user(pte_t pte)
10379 +{
10380 + return pte_val(pte) & _PAGE_USER;
10381 +}
10382 +
10383 static inline int pte_dirty(pte_t pte)
10384 {
10385 return pte_flags(pte) & _PAGE_DIRTY;
10386 @@ -167,9 +207,29 @@ static inline pte_t pte_wrprotect(pte_t
10387 return pte_clear_flags(pte, _PAGE_RW);
10388 }
10389
10390 +static inline pte_t pte_mkread(pte_t pte)
10391 +{
10392 + return __pte(pte_val(pte) | _PAGE_USER);
10393 +}
10394 +
10395 static inline pte_t pte_mkexec(pte_t pte)
10396 {
10397 - return pte_clear_flags(pte, _PAGE_NX);
10398 +#ifdef CONFIG_X86_PAE
10399 + if (__supported_pte_mask & _PAGE_NX)
10400 + return pte_clear_flags(pte, _PAGE_NX);
10401 + else
10402 +#endif
10403 + return pte_set_flags(pte, _PAGE_USER);
10404 +}
10405 +
10406 +static inline pte_t pte_exprotect(pte_t pte)
10407 +{
10408 +#ifdef CONFIG_X86_PAE
10409 + if (__supported_pte_mask & _PAGE_NX)
10410 + return pte_set_flags(pte, _PAGE_NX);
10411 + else
10412 +#endif
10413 + return pte_clear_flags(pte, _PAGE_USER);
10414 }
10415
10416 static inline pte_t pte_mkdirty(pte_t pte)
10417 @@ -302,6 +362,15 @@ pte_t *populate_extra_pte(unsigned long
10418 #endif
10419
10420 #ifndef __ASSEMBLY__
10421 +
10422 +#ifdef CONFIG_PAX_PER_CPU_PGD
10423 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10424 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10425 +{
10426 + return cpu_pgd[cpu];
10427 +}
10428 +#endif
10429 +
10430 #include <linux/mm_types.h>
10431
10432 static inline int pte_none(pte_t pte)
10433 @@ -472,7 +541,7 @@ static inline pud_t *pud_offset(pgd_t *p
10434
10435 static inline int pgd_bad(pgd_t pgd)
10436 {
10437 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10438 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10439 }
10440
10441 static inline int pgd_none(pgd_t pgd)
10442 @@ -495,7 +564,12 @@ static inline int pgd_none(pgd_t pgd)
10443 * pgd_offset() returns a (pgd_t *)
10444 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10445 */
10446 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10447 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10448 +
10449 +#ifdef CONFIG_PAX_PER_CPU_PGD
10450 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10451 +#endif
10452 +
10453 /*
10454 * a shortcut which implies the use of the kernel's pgd, instead
10455 * of a process's
10456 @@ -506,6 +580,20 @@ static inline int pgd_none(pgd_t pgd)
10457 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10458 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10459
10460 +#ifdef CONFIG_X86_32
10461 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10462 +#else
10463 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10464 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10465 +
10466 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10467 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10468 +#else
10469 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10470 +#endif
10471 +
10472 +#endif
10473 +
10474 #ifndef __ASSEMBLY__
10475
10476 extern int direct_gbpages;
10477 @@ -611,11 +699,23 @@ static inline void ptep_set_wrprotect(st
10478 * dst and src can be on the same page, but the range must not overlap,
10479 * and must not cross a page boundary.
10480 */
10481 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10482 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10483 {
10484 - memcpy(dst, src, count * sizeof(pgd_t));
10485 + pax_open_kernel();
10486 + while (count--)
10487 + *dst++ = *src++;
10488 + pax_close_kernel();
10489 }
10490
10491 +#ifdef CONFIG_PAX_PER_CPU_PGD
10492 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10493 +#endif
10494 +
10495 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10496 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10497 +#else
10498 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10499 +#endif
10500
10501 #include <asm-generic/pgtable.h>
10502 #endif /* __ASSEMBLY__ */
10503 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pgtable_32.h linux-2.6.32.46/arch/x86/include/asm/pgtable_32.h
10504 --- linux-2.6.32.46/arch/x86/include/asm/pgtable_32.h 2011-03-27 14:31:47.000000000 -0400
10505 +++ linux-2.6.32.46/arch/x86/include/asm/pgtable_32.h 2011-04-17 15:56:46.000000000 -0400
10506 @@ -26,9 +26,6 @@
10507 struct mm_struct;
10508 struct vm_area_struct;
10509
10510 -extern pgd_t swapper_pg_dir[1024];
10511 -extern pgd_t trampoline_pg_dir[1024];
10512 -
10513 static inline void pgtable_cache_init(void) { }
10514 static inline void check_pgt_cache(void) { }
10515 void paging_init(void);
10516 @@ -49,6 +46,12 @@ extern void set_pmd_pfn(unsigned long, u
10517 # include <asm/pgtable-2level.h>
10518 #endif
10519
10520 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10521 +extern pgd_t trampoline_pg_dir[PTRS_PER_PGD];
10522 +#ifdef CONFIG_X86_PAE
10523 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10524 +#endif
10525 +
10526 #if defined(CONFIG_HIGHPTE)
10527 #define __KM_PTE \
10528 (in_nmi() ? KM_NMI_PTE : \
10529 @@ -73,7 +76,9 @@ extern void set_pmd_pfn(unsigned long, u
10530 /* Clear a kernel PTE and flush it from the TLB */
10531 #define kpte_clear_flush(ptep, vaddr) \
10532 do { \
10533 + pax_open_kernel(); \
10534 pte_clear(&init_mm, (vaddr), (ptep)); \
10535 + pax_close_kernel(); \
10536 __flush_tlb_one((vaddr)); \
10537 } while (0)
10538
10539 @@ -85,6 +90,9 @@ do { \
10540
10541 #endif /* !__ASSEMBLY__ */
10542
10543 +#define HAVE_ARCH_UNMAPPED_AREA
10544 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
10545 +
10546 /*
10547 * kern_addr_valid() is (1) for FLATMEM and (0) for
10548 * SPARSEMEM and DISCONTIGMEM
10549 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pgtable_32_types.h linux-2.6.32.46/arch/x86/include/asm/pgtable_32_types.h
10550 --- linux-2.6.32.46/arch/x86/include/asm/pgtable_32_types.h 2011-03-27 14:31:47.000000000 -0400
10551 +++ linux-2.6.32.46/arch/x86/include/asm/pgtable_32_types.h 2011-04-17 15:56:46.000000000 -0400
10552 @@ -8,7 +8,7 @@
10553 */
10554 #ifdef CONFIG_X86_PAE
10555 # include <asm/pgtable-3level_types.h>
10556 -# define PMD_SIZE (1UL << PMD_SHIFT)
10557 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
10558 # define PMD_MASK (~(PMD_SIZE - 1))
10559 #else
10560 # include <asm/pgtable-2level_types.h>
10561 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
10562 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
10563 #endif
10564
10565 +#ifdef CONFIG_PAX_KERNEXEC
10566 +#ifndef __ASSEMBLY__
10567 +extern unsigned char MODULES_EXEC_VADDR[];
10568 +extern unsigned char MODULES_EXEC_END[];
10569 +#endif
10570 +#include <asm/boot.h>
10571 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
10572 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
10573 +#else
10574 +#define ktla_ktva(addr) (addr)
10575 +#define ktva_ktla(addr) (addr)
10576 +#endif
10577 +
10578 #define MODULES_VADDR VMALLOC_START
10579 #define MODULES_END VMALLOC_END
10580 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
10581 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pgtable_64.h linux-2.6.32.46/arch/x86/include/asm/pgtable_64.h
10582 --- linux-2.6.32.46/arch/x86/include/asm/pgtable_64.h 2011-03-27 14:31:47.000000000 -0400
10583 +++ linux-2.6.32.46/arch/x86/include/asm/pgtable_64.h 2011-08-23 20:24:19.000000000 -0400
10584 @@ -16,10 +16,13 @@
10585
10586 extern pud_t level3_kernel_pgt[512];
10587 extern pud_t level3_ident_pgt[512];
10588 +extern pud_t level3_vmalloc_pgt[512];
10589 +extern pud_t level3_vmemmap_pgt[512];
10590 +extern pud_t level2_vmemmap_pgt[512];
10591 extern pmd_t level2_kernel_pgt[512];
10592 extern pmd_t level2_fixmap_pgt[512];
10593 -extern pmd_t level2_ident_pgt[512];
10594 -extern pgd_t init_level4_pgt[];
10595 +extern pmd_t level2_ident_pgt[512*2];
10596 +extern pgd_t init_level4_pgt[512];
10597
10598 #define swapper_pg_dir init_level4_pgt
10599
10600 @@ -74,7 +77,9 @@ static inline pte_t native_ptep_get_and_
10601
10602 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10603 {
10604 + pax_open_kernel();
10605 *pmdp = pmd;
10606 + pax_close_kernel();
10607 }
10608
10609 static inline void native_pmd_clear(pmd_t *pmd)
10610 @@ -94,6 +99,13 @@ static inline void native_pud_clear(pud_
10611
10612 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
10613 {
10614 + pax_open_kernel();
10615 + *pgdp = pgd;
10616 + pax_close_kernel();
10617 +}
10618 +
10619 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10620 +{
10621 *pgdp = pgd;
10622 }
10623
10624 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pgtable_64_types.h linux-2.6.32.46/arch/x86/include/asm/pgtable_64_types.h
10625 --- linux-2.6.32.46/arch/x86/include/asm/pgtable_64_types.h 2011-03-27 14:31:47.000000000 -0400
10626 +++ linux-2.6.32.46/arch/x86/include/asm/pgtable_64_types.h 2011-04-17 15:56:46.000000000 -0400
10627 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
10628 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
10629 #define MODULES_END _AC(0xffffffffff000000, UL)
10630 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
10631 +#define MODULES_EXEC_VADDR MODULES_VADDR
10632 +#define MODULES_EXEC_END MODULES_END
10633 +
10634 +#define ktla_ktva(addr) (addr)
10635 +#define ktva_ktla(addr) (addr)
10636
10637 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
10638 diff -urNp linux-2.6.32.46/arch/x86/include/asm/pgtable_types.h linux-2.6.32.46/arch/x86/include/asm/pgtable_types.h
10639 --- linux-2.6.32.46/arch/x86/include/asm/pgtable_types.h 2011-03-27 14:31:47.000000000 -0400
10640 +++ linux-2.6.32.46/arch/x86/include/asm/pgtable_types.h 2011-04-17 15:56:46.000000000 -0400
10641 @@ -16,12 +16,11 @@
10642 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
10643 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
10644 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
10645 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
10646 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
10647 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
10648 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
10649 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
10650 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
10651 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
10652 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
10653 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
10654
10655 /* If _PAGE_BIT_PRESENT is clear, we use these: */
10656 @@ -39,7 +38,6 @@
10657 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
10658 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
10659 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
10660 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
10661 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
10662 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
10663 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
10664 @@ -55,8 +53,10 @@
10665
10666 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
10667 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
10668 -#else
10669 +#elif defined(CONFIG_KMEMCHECK)
10670 #define _PAGE_NX (_AT(pteval_t, 0))
10671 +#else
10672 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
10673 #endif
10674
10675 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
10676 @@ -93,6 +93,9 @@
10677 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
10678 _PAGE_ACCESSED)
10679
10680 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
10681 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
10682 +
10683 #define __PAGE_KERNEL_EXEC \
10684 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
10685 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
10686 @@ -103,8 +106,8 @@
10687 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
10688 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
10689 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
10690 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
10691 -#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
10692 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
10693 +#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
10694 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
10695 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
10696 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
10697 @@ -163,8 +166,8 @@
10698 * bits are combined, this will alow user to access the high address mapped
10699 * VDSO in the presence of CONFIG_COMPAT_VDSO
10700 */
10701 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
10702 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
10703 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10704 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10705 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
10706 #endif
10707
10708 @@ -202,7 +205,17 @@ static inline pgdval_t pgd_flags(pgd_t p
10709 {
10710 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
10711 }
10712 +#endif
10713
10714 +#if PAGETABLE_LEVELS == 3
10715 +#include <asm-generic/pgtable-nopud.h>
10716 +#endif
10717 +
10718 +#if PAGETABLE_LEVELS == 2
10719 +#include <asm-generic/pgtable-nopmd.h>
10720 +#endif
10721 +
10722 +#ifndef __ASSEMBLY__
10723 #if PAGETABLE_LEVELS > 3
10724 typedef struct { pudval_t pud; } pud_t;
10725
10726 @@ -216,8 +229,6 @@ static inline pudval_t native_pud_val(pu
10727 return pud.pud;
10728 }
10729 #else
10730 -#include <asm-generic/pgtable-nopud.h>
10731 -
10732 static inline pudval_t native_pud_val(pud_t pud)
10733 {
10734 return native_pgd_val(pud.pgd);
10735 @@ -237,8 +248,6 @@ static inline pmdval_t native_pmd_val(pm
10736 return pmd.pmd;
10737 }
10738 #else
10739 -#include <asm-generic/pgtable-nopmd.h>
10740 -
10741 static inline pmdval_t native_pmd_val(pmd_t pmd)
10742 {
10743 return native_pgd_val(pmd.pud.pgd);
10744 @@ -278,7 +287,16 @@ typedef struct page *pgtable_t;
10745
10746 extern pteval_t __supported_pte_mask;
10747 extern void set_nx(void);
10748 +
10749 +#ifdef CONFIG_X86_32
10750 +#ifdef CONFIG_X86_PAE
10751 extern int nx_enabled;
10752 +#else
10753 +#define nx_enabled (0)
10754 +#endif
10755 +#else
10756 +#define nx_enabled (1)
10757 +#endif
10758
10759 #define pgprot_writecombine pgprot_writecombine
10760 extern pgprot_t pgprot_writecombine(pgprot_t prot);
10761 diff -urNp linux-2.6.32.46/arch/x86/include/asm/processor.h linux-2.6.32.46/arch/x86/include/asm/processor.h
10762 --- linux-2.6.32.46/arch/x86/include/asm/processor.h 2011-04-22 19:16:29.000000000 -0400
10763 +++ linux-2.6.32.46/arch/x86/include/asm/processor.h 2011-05-11 18:25:15.000000000 -0400
10764 @@ -272,7 +272,7 @@ struct tss_struct {
10765
10766 } ____cacheline_aligned;
10767
10768 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
10769 +extern struct tss_struct init_tss[NR_CPUS];
10770
10771 /*
10772 * Save the original ist values for checking stack pointers during debugging
10773 @@ -888,11 +888,18 @@ static inline void spin_lock_prefetch(co
10774 */
10775 #define TASK_SIZE PAGE_OFFSET
10776 #define TASK_SIZE_MAX TASK_SIZE
10777 +
10778 +#ifdef CONFIG_PAX_SEGMEXEC
10779 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
10780 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
10781 +#else
10782 #define STACK_TOP TASK_SIZE
10783 -#define STACK_TOP_MAX STACK_TOP
10784 +#endif
10785 +
10786 +#define STACK_TOP_MAX TASK_SIZE
10787
10788 #define INIT_THREAD { \
10789 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10790 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10791 .vm86_info = NULL, \
10792 .sysenter_cs = __KERNEL_CS, \
10793 .io_bitmap_ptr = NULL, \
10794 @@ -906,7 +913,7 @@ static inline void spin_lock_prefetch(co
10795 */
10796 #define INIT_TSS { \
10797 .x86_tss = { \
10798 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10799 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10800 .ss0 = __KERNEL_DS, \
10801 .ss1 = __KERNEL_CS, \
10802 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
10803 @@ -917,11 +924,7 @@ static inline void spin_lock_prefetch(co
10804 extern unsigned long thread_saved_pc(struct task_struct *tsk);
10805
10806 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
10807 -#define KSTK_TOP(info) \
10808 -({ \
10809 - unsigned long *__ptr = (unsigned long *)(info); \
10810 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
10811 -})
10812 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
10813
10814 /*
10815 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
10816 @@ -936,7 +939,7 @@ extern unsigned long thread_saved_pc(str
10817 #define task_pt_regs(task) \
10818 ({ \
10819 struct pt_regs *__regs__; \
10820 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
10821 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
10822 __regs__ - 1; \
10823 })
10824
10825 @@ -946,13 +949,13 @@ extern unsigned long thread_saved_pc(str
10826 /*
10827 * User space process size. 47bits minus one guard page.
10828 */
10829 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
10830 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
10831
10832 /* This decides where the kernel will search for a free chunk of vm
10833 * space during mmap's.
10834 */
10835 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
10836 - 0xc0000000 : 0xFFFFe000)
10837 + 0xc0000000 : 0xFFFFf000)
10838
10839 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
10840 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
10841 @@ -963,11 +966,11 @@ extern unsigned long thread_saved_pc(str
10842 #define STACK_TOP_MAX TASK_SIZE_MAX
10843
10844 #define INIT_THREAD { \
10845 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10846 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10847 }
10848
10849 #define INIT_TSS { \
10850 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10851 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10852 }
10853
10854 /*
10855 @@ -989,6 +992,10 @@ extern void start_thread(struct pt_regs
10856 */
10857 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
10858
10859 +#ifdef CONFIG_PAX_SEGMEXEC
10860 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
10861 +#endif
10862 +
10863 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
10864
10865 /* Get/set a process' ability to use the timestamp counter instruction */
10866 diff -urNp linux-2.6.32.46/arch/x86/include/asm/ptrace.h linux-2.6.32.46/arch/x86/include/asm/ptrace.h
10867 --- linux-2.6.32.46/arch/x86/include/asm/ptrace.h 2011-03-27 14:31:47.000000000 -0400
10868 +++ linux-2.6.32.46/arch/x86/include/asm/ptrace.h 2011-04-17 15:56:46.000000000 -0400
10869 @@ -151,28 +151,29 @@ static inline unsigned long regs_return_
10870 }
10871
10872 /*
10873 - * user_mode_vm(regs) determines whether a register set came from user mode.
10874 + * user_mode(regs) determines whether a register set came from user mode.
10875 * This is true if V8086 mode was enabled OR if the register set was from
10876 * protected mode with RPL-3 CS value. This tricky test checks that with
10877 * one comparison. Many places in the kernel can bypass this full check
10878 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
10879 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
10880 + * be used.
10881 */
10882 -static inline int user_mode(struct pt_regs *regs)
10883 +static inline int user_mode_novm(struct pt_regs *regs)
10884 {
10885 #ifdef CONFIG_X86_32
10886 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
10887 #else
10888 - return !!(regs->cs & 3);
10889 + return !!(regs->cs & SEGMENT_RPL_MASK);
10890 #endif
10891 }
10892
10893 -static inline int user_mode_vm(struct pt_regs *regs)
10894 +static inline int user_mode(struct pt_regs *regs)
10895 {
10896 #ifdef CONFIG_X86_32
10897 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
10898 USER_RPL;
10899 #else
10900 - return user_mode(regs);
10901 + return user_mode_novm(regs);
10902 #endif
10903 }
10904
10905 diff -urNp linux-2.6.32.46/arch/x86/include/asm/reboot.h linux-2.6.32.46/arch/x86/include/asm/reboot.h
10906 --- linux-2.6.32.46/arch/x86/include/asm/reboot.h 2011-03-27 14:31:47.000000000 -0400
10907 +++ linux-2.6.32.46/arch/x86/include/asm/reboot.h 2011-08-05 20:33:55.000000000 -0400
10908 @@ -6,19 +6,19 @@
10909 struct pt_regs;
10910
10911 struct machine_ops {
10912 - void (*restart)(char *cmd);
10913 - void (*halt)(void);
10914 - void (*power_off)(void);
10915 + void (* __noreturn restart)(char *cmd);
10916 + void (* __noreturn halt)(void);
10917 + void (* __noreturn power_off)(void);
10918 void (*shutdown)(void);
10919 void (*crash_shutdown)(struct pt_regs *);
10920 - void (*emergency_restart)(void);
10921 -};
10922 + void (* __noreturn emergency_restart)(void);
10923 +} __no_const;
10924
10925 extern struct machine_ops machine_ops;
10926
10927 void native_machine_crash_shutdown(struct pt_regs *regs);
10928 void native_machine_shutdown(void);
10929 -void machine_real_restart(const unsigned char *code, int length);
10930 +void machine_real_restart(const unsigned char *code, unsigned int length) __noreturn;
10931
10932 typedef void (*nmi_shootdown_cb)(int, struct die_args*);
10933 void nmi_shootdown_cpus(nmi_shootdown_cb callback);
10934 diff -urNp linux-2.6.32.46/arch/x86/include/asm/rwsem.h linux-2.6.32.46/arch/x86/include/asm/rwsem.h
10935 --- linux-2.6.32.46/arch/x86/include/asm/rwsem.h 2011-03-27 14:31:47.000000000 -0400
10936 +++ linux-2.6.32.46/arch/x86/include/asm/rwsem.h 2011-04-17 15:56:46.000000000 -0400
10937 @@ -118,6 +118,14 @@ static inline void __down_read(struct rw
10938 {
10939 asm volatile("# beginning down_read\n\t"
10940 LOCK_PREFIX _ASM_INC "(%1)\n\t"
10941 +
10942 +#ifdef CONFIG_PAX_REFCOUNT
10943 + "jno 0f\n"
10944 + LOCK_PREFIX _ASM_DEC "(%1)\n\t"
10945 + "int $4\n0:\n"
10946 + _ASM_EXTABLE(0b, 0b)
10947 +#endif
10948 +
10949 /* adds 0x00000001, returns the old value */
10950 " jns 1f\n"
10951 " call call_rwsem_down_read_failed\n"
10952 @@ -139,6 +147,14 @@ static inline int __down_read_trylock(st
10953 "1:\n\t"
10954 " mov %1,%2\n\t"
10955 " add %3,%2\n\t"
10956 +
10957 +#ifdef CONFIG_PAX_REFCOUNT
10958 + "jno 0f\n"
10959 + "sub %3,%2\n"
10960 + "int $4\n0:\n"
10961 + _ASM_EXTABLE(0b, 0b)
10962 +#endif
10963 +
10964 " jle 2f\n\t"
10965 LOCK_PREFIX " cmpxchg %2,%0\n\t"
10966 " jnz 1b\n\t"
10967 @@ -160,6 +176,14 @@ static inline void __down_write_nested(s
10968 tmp = RWSEM_ACTIVE_WRITE_BIAS;
10969 asm volatile("# beginning down_write\n\t"
10970 LOCK_PREFIX " xadd %1,(%2)\n\t"
10971 +
10972 +#ifdef CONFIG_PAX_REFCOUNT
10973 + "jno 0f\n"
10974 + "mov %1,(%2)\n"
10975 + "int $4\n0:\n"
10976 + _ASM_EXTABLE(0b, 0b)
10977 +#endif
10978 +
10979 /* subtract 0x0000ffff, returns the old value */
10980 " test %1,%1\n\t"
10981 /* was the count 0 before? */
10982 @@ -198,6 +222,14 @@ static inline void __up_read(struct rw_s
10983 rwsem_count_t tmp = -RWSEM_ACTIVE_READ_BIAS;
10984 asm volatile("# beginning __up_read\n\t"
10985 LOCK_PREFIX " xadd %1,(%2)\n\t"
10986 +
10987 +#ifdef CONFIG_PAX_REFCOUNT
10988 + "jno 0f\n"
10989 + "mov %1,(%2)\n"
10990 + "int $4\n0:\n"
10991 + _ASM_EXTABLE(0b, 0b)
10992 +#endif
10993 +
10994 /* subtracts 1, returns the old value */
10995 " jns 1f\n\t"
10996 " call call_rwsem_wake\n"
10997 @@ -216,6 +248,14 @@ static inline void __up_write(struct rw_
10998 rwsem_count_t tmp;
10999 asm volatile("# beginning __up_write\n\t"
11000 LOCK_PREFIX " xadd %1,(%2)\n\t"
11001 +
11002 +#ifdef CONFIG_PAX_REFCOUNT
11003 + "jno 0f\n"
11004 + "mov %1,(%2)\n"
11005 + "int $4\n0:\n"
11006 + _ASM_EXTABLE(0b, 0b)
11007 +#endif
11008 +
11009 /* tries to transition
11010 0xffff0001 -> 0x00000000 */
11011 " jz 1f\n"
11012 @@ -234,6 +274,14 @@ static inline void __downgrade_write(str
11013 {
11014 asm volatile("# beginning __downgrade_write\n\t"
11015 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11016 +
11017 +#ifdef CONFIG_PAX_REFCOUNT
11018 + "jno 0f\n"
11019 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11020 + "int $4\n0:\n"
11021 + _ASM_EXTABLE(0b, 0b)
11022 +#endif
11023 +
11024 /*
11025 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11026 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11027 @@ -253,7 +301,15 @@ static inline void __downgrade_write(str
11028 static inline void rwsem_atomic_add(rwsem_count_t delta,
11029 struct rw_semaphore *sem)
11030 {
11031 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11032 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11033 +
11034 +#ifdef CONFIG_PAX_REFCOUNT
11035 + "jno 0f\n"
11036 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11037 + "int $4\n0:\n"
11038 + _ASM_EXTABLE(0b, 0b)
11039 +#endif
11040 +
11041 : "+m" (sem->count)
11042 : "er" (delta));
11043 }
11044 @@ -266,7 +322,15 @@ static inline rwsem_count_t rwsem_atomic
11045 {
11046 rwsem_count_t tmp = delta;
11047
11048 - asm volatile(LOCK_PREFIX "xadd %0,%1"
11049 + asm volatile(LOCK_PREFIX "xadd %0,%1\n"
11050 +
11051 +#ifdef CONFIG_PAX_REFCOUNT
11052 + "jno 0f\n"
11053 + "mov %0,%1\n"
11054 + "int $4\n0:\n"
11055 + _ASM_EXTABLE(0b, 0b)
11056 +#endif
11057 +
11058 : "+r" (tmp), "+m" (sem->count)
11059 : : "memory");
11060
11061 diff -urNp linux-2.6.32.46/arch/x86/include/asm/segment.h linux-2.6.32.46/arch/x86/include/asm/segment.h
11062 --- linux-2.6.32.46/arch/x86/include/asm/segment.h 2011-03-27 14:31:47.000000000 -0400
11063 +++ linux-2.6.32.46/arch/x86/include/asm/segment.h 2011-10-06 09:37:08.000000000 -0400
11064 @@ -62,10 +62,15 @@
11065 * 26 - ESPFIX small SS
11066 * 27 - per-cpu [ offset to per-cpu data area ]
11067 * 28 - stack_canary-20 [ for stack protector ]
11068 - * 29 - unused
11069 - * 30 - unused
11070 + * 29 - PCI BIOS CS
11071 + * 30 - PCI BIOS DS
11072 * 31 - TSS for double fault handler
11073 */
11074 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11075 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11076 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11077 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11078 +
11079 #define GDT_ENTRY_TLS_MIN 6
11080 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11081
11082 @@ -77,6 +82,8 @@
11083
11084 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
11085
11086 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11087 +
11088 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
11089
11090 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
11091 @@ -88,7 +95,7 @@
11092 #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
11093 #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
11094
11095 -#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
11096 +#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
11097 #ifdef CONFIG_SMP
11098 #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
11099 #else
11100 @@ -102,6 +109,12 @@
11101 #define __KERNEL_STACK_CANARY 0
11102 #endif
11103
11104 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 17)
11105 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11106 +
11107 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 18)
11108 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11109 +
11110 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11111
11112 /*
11113 @@ -139,7 +152,7 @@
11114 */
11115
11116 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11117 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11118 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11119
11120
11121 #else
11122 @@ -163,6 +176,8 @@
11123 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
11124 #define __USER32_DS __USER_DS
11125
11126 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11127 +
11128 #define GDT_ENTRY_TSS 8 /* needs two entries */
11129 #define GDT_ENTRY_LDT 10 /* needs two entries */
11130 #define GDT_ENTRY_TLS_MIN 12
11131 @@ -183,6 +198,7 @@
11132 #endif
11133
11134 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
11135 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS * 8)
11136 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
11137 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
11138 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
11139 diff -urNp linux-2.6.32.46/arch/x86/include/asm/smp.h linux-2.6.32.46/arch/x86/include/asm/smp.h
11140 --- linux-2.6.32.46/arch/x86/include/asm/smp.h 2011-03-27 14:31:47.000000000 -0400
11141 +++ linux-2.6.32.46/arch/x86/include/asm/smp.h 2011-08-05 20:33:55.000000000 -0400
11142 @@ -24,7 +24,7 @@ extern unsigned int num_processors;
11143 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
11144 DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11145 DECLARE_PER_CPU(u16, cpu_llc_id);
11146 -DECLARE_PER_CPU(int, cpu_number);
11147 +DECLARE_PER_CPU(unsigned int, cpu_number);
11148
11149 static inline struct cpumask *cpu_sibling_mask(int cpu)
11150 {
11151 @@ -40,10 +40,7 @@ DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_ap
11152 DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
11153
11154 /* Static state in head.S used to set up a CPU */
11155 -extern struct {
11156 - void *sp;
11157 - unsigned short ss;
11158 -} stack_start;
11159 +extern unsigned long stack_start; /* Initial stack pointer address */
11160
11161 struct smp_ops {
11162 void (*smp_prepare_boot_cpu)(void);
11163 @@ -60,7 +57,7 @@ struct smp_ops {
11164
11165 void (*send_call_func_ipi)(const struct cpumask *mask);
11166 void (*send_call_func_single_ipi)(int cpu);
11167 -};
11168 +} __no_const;
11169
11170 /* Globals due to paravirt */
11171 extern void set_cpu_sibling_map(int cpu);
11172 @@ -175,14 +172,8 @@ extern unsigned disabled_cpus __cpuinitd
11173 extern int safe_smp_processor_id(void);
11174
11175 #elif defined(CONFIG_X86_64_SMP)
11176 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11177 -
11178 -#define stack_smp_processor_id() \
11179 -({ \
11180 - struct thread_info *ti; \
11181 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11182 - ti->cpu; \
11183 -})
11184 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11185 +#define stack_smp_processor_id() raw_smp_processor_id()
11186 #define safe_smp_processor_id() smp_processor_id()
11187
11188 #endif
11189 diff -urNp linux-2.6.32.46/arch/x86/include/asm/spinlock.h linux-2.6.32.46/arch/x86/include/asm/spinlock.h
11190 --- linux-2.6.32.46/arch/x86/include/asm/spinlock.h 2011-03-27 14:31:47.000000000 -0400
11191 +++ linux-2.6.32.46/arch/x86/include/asm/spinlock.h 2011-04-17 15:56:46.000000000 -0400
11192 @@ -249,6 +249,14 @@ static inline int __raw_write_can_lock(r
11193 static inline void __raw_read_lock(raw_rwlock_t *rw)
11194 {
11195 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
11196 +
11197 +#ifdef CONFIG_PAX_REFCOUNT
11198 + "jno 0f\n"
11199 + LOCK_PREFIX " addl $1,(%0)\n"
11200 + "int $4\n0:\n"
11201 + _ASM_EXTABLE(0b, 0b)
11202 +#endif
11203 +
11204 "jns 1f\n"
11205 "call __read_lock_failed\n\t"
11206 "1:\n"
11207 @@ -258,6 +266,14 @@ static inline void __raw_read_lock(raw_r
11208 static inline void __raw_write_lock(raw_rwlock_t *rw)
11209 {
11210 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
11211 +
11212 +#ifdef CONFIG_PAX_REFCOUNT
11213 + "jno 0f\n"
11214 + LOCK_PREFIX " addl %1,(%0)\n"
11215 + "int $4\n0:\n"
11216 + _ASM_EXTABLE(0b, 0b)
11217 +#endif
11218 +
11219 "jz 1f\n"
11220 "call __write_lock_failed\n\t"
11221 "1:\n"
11222 @@ -286,12 +302,29 @@ static inline int __raw_write_trylock(ra
11223
11224 static inline void __raw_read_unlock(raw_rwlock_t *rw)
11225 {
11226 - asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
11227 + asm volatile(LOCK_PREFIX "incl %0\n"
11228 +
11229 +#ifdef CONFIG_PAX_REFCOUNT
11230 + "jno 0f\n"
11231 + LOCK_PREFIX "decl %0\n"
11232 + "int $4\n0:\n"
11233 + _ASM_EXTABLE(0b, 0b)
11234 +#endif
11235 +
11236 + :"+m" (rw->lock) : : "memory");
11237 }
11238
11239 static inline void __raw_write_unlock(raw_rwlock_t *rw)
11240 {
11241 - asm volatile(LOCK_PREFIX "addl %1, %0"
11242 + asm volatile(LOCK_PREFIX "addl %1, %0\n"
11243 +
11244 +#ifdef CONFIG_PAX_REFCOUNT
11245 + "jno 0f\n"
11246 + LOCK_PREFIX "subl %1, %0\n"
11247 + "int $4\n0:\n"
11248 + _ASM_EXTABLE(0b, 0b)
11249 +#endif
11250 +
11251 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
11252 }
11253
11254 diff -urNp linux-2.6.32.46/arch/x86/include/asm/stackprotector.h linux-2.6.32.46/arch/x86/include/asm/stackprotector.h
11255 --- linux-2.6.32.46/arch/x86/include/asm/stackprotector.h 2011-03-27 14:31:47.000000000 -0400
11256 +++ linux-2.6.32.46/arch/x86/include/asm/stackprotector.h 2011-07-06 19:53:33.000000000 -0400
11257 @@ -48,7 +48,7 @@
11258 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11259 */
11260 #define GDT_STACK_CANARY_INIT \
11261 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11262 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11263
11264 /*
11265 * Initialize the stackprotector canary value.
11266 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
11267
11268 static inline void load_stack_canary_segment(void)
11269 {
11270 -#ifdef CONFIG_X86_32
11271 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11272 asm volatile ("mov %0, %%gs" : : "r" (0));
11273 #endif
11274 }
11275 diff -urNp linux-2.6.32.46/arch/x86/include/asm/system.h linux-2.6.32.46/arch/x86/include/asm/system.h
11276 --- linux-2.6.32.46/arch/x86/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
11277 +++ linux-2.6.32.46/arch/x86/include/asm/system.h 2011-05-22 23:02:03.000000000 -0400
11278 @@ -132,7 +132,7 @@ do { \
11279 "thread_return:\n\t" \
11280 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11281 __switch_canary \
11282 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11283 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11284 "movq %%rax,%%rdi\n\t" \
11285 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11286 "jnz ret_from_fork\n\t" \
11287 @@ -143,7 +143,7 @@ do { \
11288 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11289 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11290 [_tif_fork] "i" (_TIF_FORK), \
11291 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11292 + [thread_info] "m" (per_cpu_var(current_tinfo)), \
11293 [current_task] "m" (per_cpu_var(current_task)) \
11294 __switch_canary_iparam \
11295 : "memory", "cc" __EXTRA_CLOBBER)
11296 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
11297 {
11298 unsigned long __limit;
11299 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11300 - return __limit + 1;
11301 + return __limit;
11302 }
11303
11304 static inline void native_clts(void)
11305 @@ -340,12 +340,12 @@ void enable_hlt(void);
11306
11307 void cpu_idle_wait(void);
11308
11309 -extern unsigned long arch_align_stack(unsigned long sp);
11310 +#define arch_align_stack(x) ((x) & ~0xfUL)
11311 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11312
11313 void default_idle(void);
11314
11315 -void stop_this_cpu(void *dummy);
11316 +void stop_this_cpu(void *dummy) __noreturn;
11317
11318 /*
11319 * Force strict CPU ordering.
11320 diff -urNp linux-2.6.32.46/arch/x86/include/asm/thread_info.h linux-2.6.32.46/arch/x86/include/asm/thread_info.h
11321 --- linux-2.6.32.46/arch/x86/include/asm/thread_info.h 2011-03-27 14:31:47.000000000 -0400
11322 +++ linux-2.6.32.46/arch/x86/include/asm/thread_info.h 2011-05-17 19:26:34.000000000 -0400
11323 @@ -10,6 +10,7 @@
11324 #include <linux/compiler.h>
11325 #include <asm/page.h>
11326 #include <asm/types.h>
11327 +#include <asm/percpu.h>
11328
11329 /*
11330 * low level task data that entry.S needs immediate access to
11331 @@ -24,7 +25,6 @@ struct exec_domain;
11332 #include <asm/atomic.h>
11333
11334 struct thread_info {
11335 - struct task_struct *task; /* main task structure */
11336 struct exec_domain *exec_domain; /* execution domain */
11337 __u32 flags; /* low level flags */
11338 __u32 status; /* thread synchronous flags */
11339 @@ -34,18 +34,12 @@ struct thread_info {
11340 mm_segment_t addr_limit;
11341 struct restart_block restart_block;
11342 void __user *sysenter_return;
11343 -#ifdef CONFIG_X86_32
11344 - unsigned long previous_esp; /* ESP of the previous stack in
11345 - case of nested (IRQ) stacks
11346 - */
11347 - __u8 supervisor_stack[0];
11348 -#endif
11349 + unsigned long lowest_stack;
11350 int uaccess_err;
11351 };
11352
11353 -#define INIT_THREAD_INFO(tsk) \
11354 +#define INIT_THREAD_INFO \
11355 { \
11356 - .task = &tsk, \
11357 .exec_domain = &default_exec_domain, \
11358 .flags = 0, \
11359 .cpu = 0, \
11360 @@ -56,7 +50,7 @@ struct thread_info {
11361 }, \
11362 }
11363
11364 -#define init_thread_info (init_thread_union.thread_info)
11365 +#define init_thread_info (init_thread_union.stack)
11366 #define init_stack (init_thread_union.stack)
11367
11368 #else /* !__ASSEMBLY__ */
11369 @@ -163,6 +157,23 @@ struct thread_info {
11370 #define alloc_thread_info(tsk) \
11371 ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
11372
11373 +#ifdef __ASSEMBLY__
11374 +/* how to get the thread information struct from ASM */
11375 +#define GET_THREAD_INFO(reg) \
11376 + mov PER_CPU_VAR(current_tinfo), reg
11377 +
11378 +/* use this one if reg already contains %esp */
11379 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11380 +#else
11381 +/* how to get the thread information struct from C */
11382 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11383 +
11384 +static __always_inline struct thread_info *current_thread_info(void)
11385 +{
11386 + return percpu_read_stable(current_tinfo);
11387 +}
11388 +#endif
11389 +
11390 #ifdef CONFIG_X86_32
11391
11392 #define STACK_WARN (THREAD_SIZE/8)
11393 @@ -173,35 +184,13 @@ struct thread_info {
11394 */
11395 #ifndef __ASSEMBLY__
11396
11397 -
11398 /* how to get the current stack pointer from C */
11399 register unsigned long current_stack_pointer asm("esp") __used;
11400
11401 -/* how to get the thread information struct from C */
11402 -static inline struct thread_info *current_thread_info(void)
11403 -{
11404 - return (struct thread_info *)
11405 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11406 -}
11407 -
11408 -#else /* !__ASSEMBLY__ */
11409 -
11410 -/* how to get the thread information struct from ASM */
11411 -#define GET_THREAD_INFO(reg) \
11412 - movl $-THREAD_SIZE, reg; \
11413 - andl %esp, reg
11414 -
11415 -/* use this one if reg already contains %esp */
11416 -#define GET_THREAD_INFO_WITH_ESP(reg) \
11417 - andl $-THREAD_SIZE, reg
11418 -
11419 #endif
11420
11421 #else /* X86_32 */
11422
11423 -#include <asm/percpu.h>
11424 -#define KERNEL_STACK_OFFSET (5*8)
11425 -
11426 /*
11427 * macros/functions for gaining access to the thread information structure
11428 * preempt_count needs to be 1 initially, until the scheduler is functional.
11429 @@ -209,21 +198,8 @@ static inline struct thread_info *curren
11430 #ifndef __ASSEMBLY__
11431 DECLARE_PER_CPU(unsigned long, kernel_stack);
11432
11433 -static inline struct thread_info *current_thread_info(void)
11434 -{
11435 - struct thread_info *ti;
11436 - ti = (void *)(percpu_read_stable(kernel_stack) +
11437 - KERNEL_STACK_OFFSET - THREAD_SIZE);
11438 - return ti;
11439 -}
11440 -
11441 -#else /* !__ASSEMBLY__ */
11442 -
11443 -/* how to get the thread information struct from ASM */
11444 -#define GET_THREAD_INFO(reg) \
11445 - movq PER_CPU_VAR(kernel_stack),reg ; \
11446 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11447 -
11448 +/* how to get the current stack pointer from C */
11449 +register unsigned long current_stack_pointer asm("rsp") __used;
11450 #endif
11451
11452 #endif /* !X86_32 */
11453 @@ -260,5 +236,16 @@ extern void arch_task_cache_init(void);
11454 extern void free_thread_info(struct thread_info *ti);
11455 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
11456 #define arch_task_cache_init arch_task_cache_init
11457 +
11458 +#define __HAVE_THREAD_FUNCTIONS
11459 +#define task_thread_info(task) (&(task)->tinfo)
11460 +#define task_stack_page(task) ((task)->stack)
11461 +#define setup_thread_stack(p, org) do {} while (0)
11462 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
11463 +
11464 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
11465 +extern struct task_struct *alloc_task_struct(void);
11466 +extern void free_task_struct(struct task_struct *);
11467 +
11468 #endif
11469 #endif /* _ASM_X86_THREAD_INFO_H */
11470 diff -urNp linux-2.6.32.46/arch/x86/include/asm/uaccess.h linux-2.6.32.46/arch/x86/include/asm/uaccess.h
11471 --- linux-2.6.32.46/arch/x86/include/asm/uaccess.h 2011-06-25 12:55:34.000000000 -0400
11472 +++ linux-2.6.32.46/arch/x86/include/asm/uaccess.h 2011-10-06 09:37:08.000000000 -0400
11473 @@ -8,12 +8,15 @@
11474 #include <linux/thread_info.h>
11475 #include <linux/prefetch.h>
11476 #include <linux/string.h>
11477 +#include <linux/sched.h>
11478 #include <asm/asm.h>
11479 #include <asm/page.h>
11480
11481 #define VERIFY_READ 0
11482 #define VERIFY_WRITE 1
11483
11484 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
11485 +
11486 /*
11487 * The fs value determines whether argument validity checking should be
11488 * performed or not. If get_fs() == USER_DS, checking is performed, with
11489 @@ -29,7 +32,12 @@
11490
11491 #define get_ds() (KERNEL_DS)
11492 #define get_fs() (current_thread_info()->addr_limit)
11493 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
11494 +void __set_fs(mm_segment_t x);
11495 +void set_fs(mm_segment_t x);
11496 +#else
11497 #define set_fs(x) (current_thread_info()->addr_limit = (x))
11498 +#endif
11499
11500 #define segment_eq(a, b) ((a).seg == (b).seg)
11501
11502 @@ -77,7 +85,33 @@
11503 * checks that the pointer is in the user space range - after calling
11504 * this function, memory access functions may still return -EFAULT.
11505 */
11506 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
11507 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
11508 +#define access_ok(type, addr, size) \
11509 +({ \
11510 + long __size = size; \
11511 + unsigned long __addr = (unsigned long)addr; \
11512 + unsigned long __addr_ao = __addr & PAGE_MASK; \
11513 + unsigned long __end_ao = __addr + __size - 1; \
11514 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
11515 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
11516 + while(__addr_ao <= __end_ao) { \
11517 + char __c_ao; \
11518 + __addr_ao += PAGE_SIZE; \
11519 + if (__size > PAGE_SIZE) \
11520 + cond_resched(); \
11521 + if (__get_user(__c_ao, (char __user *)__addr)) \
11522 + break; \
11523 + if (type != VERIFY_WRITE) { \
11524 + __addr = __addr_ao; \
11525 + continue; \
11526 + } \
11527 + if (__put_user(__c_ao, (char __user *)__addr)) \
11528 + break; \
11529 + __addr = __addr_ao; \
11530 + } \
11531 + } \
11532 + __ret_ao; \
11533 +})
11534
11535 /*
11536 * The exception table consists of pairs of addresses: the first is the
11537 @@ -183,12 +217,20 @@ extern int __get_user_bad(void);
11538 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
11539 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
11540
11541 -
11542 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
11543 +#define __copyuser_seg "gs;"
11544 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
11545 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
11546 +#else
11547 +#define __copyuser_seg
11548 +#define __COPYUSER_SET_ES
11549 +#define __COPYUSER_RESTORE_ES
11550 +#endif
11551
11552 #ifdef CONFIG_X86_32
11553 #define __put_user_asm_u64(x, addr, err, errret) \
11554 - asm volatile("1: movl %%eax,0(%2)\n" \
11555 - "2: movl %%edx,4(%2)\n" \
11556 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
11557 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
11558 "3:\n" \
11559 ".section .fixup,\"ax\"\n" \
11560 "4: movl %3,%0\n" \
11561 @@ -200,8 +242,8 @@ extern int __get_user_bad(void);
11562 : "A" (x), "r" (addr), "i" (errret), "0" (err))
11563
11564 #define __put_user_asm_ex_u64(x, addr) \
11565 - asm volatile("1: movl %%eax,0(%1)\n" \
11566 - "2: movl %%edx,4(%1)\n" \
11567 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
11568 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
11569 "3:\n" \
11570 _ASM_EXTABLE(1b, 2b - 1b) \
11571 _ASM_EXTABLE(2b, 3b - 2b) \
11572 @@ -253,7 +295,7 @@ extern void __put_user_8(void);
11573 __typeof__(*(ptr)) __pu_val; \
11574 __chk_user_ptr(ptr); \
11575 might_fault(); \
11576 - __pu_val = x; \
11577 + __pu_val = (x); \
11578 switch (sizeof(*(ptr))) { \
11579 case 1: \
11580 __put_user_x(1, __pu_val, ptr, __ret_pu); \
11581 @@ -374,7 +416,7 @@ do { \
11582 } while (0)
11583
11584 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
11585 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
11586 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
11587 "2:\n" \
11588 ".section .fixup,\"ax\"\n" \
11589 "3: mov %3,%0\n" \
11590 @@ -382,7 +424,7 @@ do { \
11591 " jmp 2b\n" \
11592 ".previous\n" \
11593 _ASM_EXTABLE(1b, 3b) \
11594 - : "=r" (err), ltype(x) \
11595 + : "=r" (err), ltype (x) \
11596 : "m" (__m(addr)), "i" (errret), "0" (err))
11597
11598 #define __get_user_size_ex(x, ptr, size) \
11599 @@ -407,7 +449,7 @@ do { \
11600 } while (0)
11601
11602 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
11603 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
11604 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
11605 "2:\n" \
11606 _ASM_EXTABLE(1b, 2b - 1b) \
11607 : ltype(x) : "m" (__m(addr)))
11608 @@ -424,13 +466,24 @@ do { \
11609 int __gu_err; \
11610 unsigned long __gu_val; \
11611 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
11612 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
11613 + (x) = (__typeof__(*(ptr)))__gu_val; \
11614 __gu_err; \
11615 })
11616
11617 /* FIXME: this hack is definitely wrong -AK */
11618 struct __large_struct { unsigned long buf[100]; };
11619 -#define __m(x) (*(struct __large_struct __user *)(x))
11620 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11621 +#define ____m(x) \
11622 +({ \
11623 + unsigned long ____x = (unsigned long)(x); \
11624 + if (____x < PAX_USER_SHADOW_BASE) \
11625 + ____x += PAX_USER_SHADOW_BASE; \
11626 + (void __user *)____x; \
11627 +})
11628 +#else
11629 +#define ____m(x) (x)
11630 +#endif
11631 +#define __m(x) (*(struct __large_struct __user *)____m(x))
11632
11633 /*
11634 * Tell gcc we read from memory instead of writing: this is because
11635 @@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
11636 * aliasing issues.
11637 */
11638 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
11639 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
11640 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
11641 "2:\n" \
11642 ".section .fixup,\"ax\"\n" \
11643 "3: mov %3,%0\n" \
11644 @@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
11645 ".previous\n" \
11646 _ASM_EXTABLE(1b, 3b) \
11647 : "=r"(err) \
11648 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
11649 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
11650
11651 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
11652 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
11653 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
11654 "2:\n" \
11655 _ASM_EXTABLE(1b, 2b - 1b) \
11656 : : ltype(x), "m" (__m(addr)))
11657 @@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
11658 * On error, the variable @x is set to zero.
11659 */
11660
11661 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11662 +#define __get_user(x, ptr) get_user((x), (ptr))
11663 +#else
11664 #define __get_user(x, ptr) \
11665 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
11666 +#endif
11667
11668 /**
11669 * __put_user: - Write a simple value into user space, with less checking.
11670 @@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
11671 * Returns zero on success, or -EFAULT on error.
11672 */
11673
11674 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11675 +#define __put_user(x, ptr) put_user((x), (ptr))
11676 +#else
11677 #define __put_user(x, ptr) \
11678 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
11679 +#endif
11680
11681 #define __get_user_unaligned __get_user
11682 #define __put_user_unaligned __put_user
11683 @@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
11684 #define get_user_ex(x, ptr) do { \
11685 unsigned long __gue_val; \
11686 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
11687 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
11688 + (x) = (__typeof__(*(ptr)))__gue_val; \
11689 } while (0)
11690
11691 #ifdef CONFIG_X86_WP_WORKS_OK
11692 @@ -567,6 +628,7 @@ extern struct movsl_mask {
11693
11694 #define ARCH_HAS_NOCACHE_UACCESS 1
11695
11696 +#define ARCH_HAS_SORT_EXTABLE
11697 #ifdef CONFIG_X86_32
11698 # include "uaccess_32.h"
11699 #else
11700 diff -urNp linux-2.6.32.46/arch/x86/include/asm/uaccess_32.h linux-2.6.32.46/arch/x86/include/asm/uaccess_32.h
11701 --- linux-2.6.32.46/arch/x86/include/asm/uaccess_32.h 2011-03-27 14:31:47.000000000 -0400
11702 +++ linux-2.6.32.46/arch/x86/include/asm/uaccess_32.h 2011-05-16 21:46:57.000000000 -0400
11703 @@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_u
11704 static __always_inline unsigned long __must_check
11705 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11706 {
11707 + pax_track_stack();
11708 +
11709 + if ((long)n < 0)
11710 + return n;
11711 +
11712 if (__builtin_constant_p(n)) {
11713 unsigned long ret;
11714
11715 @@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to,
11716 return ret;
11717 }
11718 }
11719 + if (!__builtin_constant_p(n))
11720 + check_object_size(from, n, true);
11721 return __copy_to_user_ll(to, from, n);
11722 }
11723
11724 @@ -83,12 +90,16 @@ static __always_inline unsigned long __m
11725 __copy_to_user(void __user *to, const void *from, unsigned long n)
11726 {
11727 might_fault();
11728 +
11729 return __copy_to_user_inatomic(to, from, n);
11730 }
11731
11732 static __always_inline unsigned long
11733 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
11734 {
11735 + if ((long)n < 0)
11736 + return n;
11737 +
11738 /* Avoid zeroing the tail if the copy fails..
11739 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
11740 * but as the zeroing behaviour is only significant when n is not
11741 @@ -138,6 +149,12 @@ static __always_inline unsigned long
11742 __copy_from_user(void *to, const void __user *from, unsigned long n)
11743 {
11744 might_fault();
11745 +
11746 + pax_track_stack();
11747 +
11748 + if ((long)n < 0)
11749 + return n;
11750 +
11751 if (__builtin_constant_p(n)) {
11752 unsigned long ret;
11753
11754 @@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __
11755 return ret;
11756 }
11757 }
11758 + if (!__builtin_constant_p(n))
11759 + check_object_size(to, n, false);
11760 return __copy_from_user_ll(to, from, n);
11761 }
11762
11763 @@ -160,6 +179,10 @@ static __always_inline unsigned long __c
11764 const void __user *from, unsigned long n)
11765 {
11766 might_fault();
11767 +
11768 + if ((long)n < 0)
11769 + return n;
11770 +
11771 if (__builtin_constant_p(n)) {
11772 unsigned long ret;
11773
11774 @@ -182,14 +205,62 @@ static __always_inline unsigned long
11775 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
11776 unsigned long n)
11777 {
11778 - return __copy_from_user_ll_nocache_nozero(to, from, n);
11779 + if ((long)n < 0)
11780 + return n;
11781 +
11782 + return __copy_from_user_ll_nocache_nozero(to, from, n);
11783 +}
11784 +
11785 +/**
11786 + * copy_to_user: - Copy a block of data into user space.
11787 + * @to: Destination address, in user space.
11788 + * @from: Source address, in kernel space.
11789 + * @n: Number of bytes to copy.
11790 + *
11791 + * Context: User context only. This function may sleep.
11792 + *
11793 + * Copy data from kernel space to user space.
11794 + *
11795 + * Returns number of bytes that could not be copied.
11796 + * On success, this will be zero.
11797 + */
11798 +static __always_inline unsigned long __must_check
11799 +copy_to_user(void __user *to, const void *from, unsigned long n)
11800 +{
11801 + if (access_ok(VERIFY_WRITE, to, n))
11802 + n = __copy_to_user(to, from, n);
11803 + return n;
11804 +}
11805 +
11806 +/**
11807 + * copy_from_user: - Copy a block of data from user space.
11808 + * @to: Destination address, in kernel space.
11809 + * @from: Source address, in user space.
11810 + * @n: Number of bytes to copy.
11811 + *
11812 + * Context: User context only. This function may sleep.
11813 + *
11814 + * Copy data from user space to kernel space.
11815 + *
11816 + * Returns number of bytes that could not be copied.
11817 + * On success, this will be zero.
11818 + *
11819 + * If some data could not be copied, this function will pad the copied
11820 + * data to the requested size using zero bytes.
11821 + */
11822 +static __always_inline unsigned long __must_check
11823 +copy_from_user(void *to, const void __user *from, unsigned long n)
11824 +{
11825 + if (access_ok(VERIFY_READ, from, n))
11826 + n = __copy_from_user(to, from, n);
11827 + else if ((long)n > 0) {
11828 + if (!__builtin_constant_p(n))
11829 + check_object_size(to, n, false);
11830 + memset(to, 0, n);
11831 + }
11832 + return n;
11833 }
11834
11835 -unsigned long __must_check copy_to_user(void __user *to,
11836 - const void *from, unsigned long n);
11837 -unsigned long __must_check copy_from_user(void *to,
11838 - const void __user *from,
11839 - unsigned long n);
11840 long __must_check strncpy_from_user(char *dst, const char __user *src,
11841 long count);
11842 long __must_check __strncpy_from_user(char *dst,
11843 diff -urNp linux-2.6.32.46/arch/x86/include/asm/uaccess_64.h linux-2.6.32.46/arch/x86/include/asm/uaccess_64.h
11844 --- linux-2.6.32.46/arch/x86/include/asm/uaccess_64.h 2011-03-27 14:31:47.000000000 -0400
11845 +++ linux-2.6.32.46/arch/x86/include/asm/uaccess_64.h 2011-10-06 09:37:08.000000000 -0400
11846 @@ -9,6 +9,9 @@
11847 #include <linux/prefetch.h>
11848 #include <linux/lockdep.h>
11849 #include <asm/page.h>
11850 +#include <asm/pgtable.h>
11851 +
11852 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
11853
11854 /*
11855 * Copy To/From Userspace
11856 @@ -19,113 +22,203 @@ __must_check unsigned long
11857 copy_user_generic(void *to, const void *from, unsigned len);
11858
11859 __must_check unsigned long
11860 -copy_to_user(void __user *to, const void *from, unsigned len);
11861 -__must_check unsigned long
11862 -copy_from_user(void *to, const void __user *from, unsigned len);
11863 -__must_check unsigned long
11864 copy_in_user(void __user *to, const void __user *from, unsigned len);
11865
11866 static __always_inline __must_check
11867 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
11868 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
11869 {
11870 - int ret = 0;
11871 + unsigned ret = 0;
11872
11873 might_fault();
11874 - if (!__builtin_constant_p(size))
11875 - return copy_user_generic(dst, (__force void *)src, size);
11876 +
11877 + if ((int)size < 0)
11878 + return size;
11879 +
11880 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11881 + if (!__access_ok(VERIFY_READ, src, size))
11882 + return size;
11883 +#endif
11884 +
11885 + if (!__builtin_constant_p(size)) {
11886 + check_object_size(dst, size, false);
11887 +
11888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11889 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11890 + src += PAX_USER_SHADOW_BASE;
11891 +#endif
11892 +
11893 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11894 + }
11895 switch (size) {
11896 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
11897 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
11898 ret, "b", "b", "=q", 1);
11899 return ret;
11900 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
11901 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
11902 ret, "w", "w", "=r", 2);
11903 return ret;
11904 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
11905 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
11906 ret, "l", "k", "=r", 4);
11907 return ret;
11908 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
11909 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11910 ret, "q", "", "=r", 8);
11911 return ret;
11912 case 10:
11913 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11914 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11915 ret, "q", "", "=r", 10);
11916 if (unlikely(ret))
11917 return ret;
11918 __get_user_asm(*(u16 *)(8 + (char *)dst),
11919 - (u16 __user *)(8 + (char __user *)src),
11920 + (const u16 __user *)(8 + (const char __user *)src),
11921 ret, "w", "w", "=r", 2);
11922 return ret;
11923 case 16:
11924 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11925 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11926 ret, "q", "", "=r", 16);
11927 if (unlikely(ret))
11928 return ret;
11929 __get_user_asm(*(u64 *)(8 + (char *)dst),
11930 - (u64 __user *)(8 + (char __user *)src),
11931 + (const u64 __user *)(8 + (const char __user *)src),
11932 ret, "q", "", "=r", 8);
11933 return ret;
11934 default:
11935 - return copy_user_generic(dst, (__force void *)src, size);
11936 +
11937 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11938 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11939 + src += PAX_USER_SHADOW_BASE;
11940 +#endif
11941 +
11942 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11943 }
11944 }
11945
11946 static __always_inline __must_check
11947 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
11948 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
11949 {
11950 - int ret = 0;
11951 + unsigned ret = 0;
11952
11953 might_fault();
11954 - if (!__builtin_constant_p(size))
11955 - return copy_user_generic((__force void *)dst, src, size);
11956 +
11957 + pax_track_stack();
11958 +
11959 + if ((int)size < 0)
11960 + return size;
11961 +
11962 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11963 + if (!__access_ok(VERIFY_WRITE, dst, size))
11964 + return size;
11965 +#endif
11966 +
11967 + if (!__builtin_constant_p(size)) {
11968 + check_object_size(src, size, true);
11969 +
11970 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11971 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11972 + dst += PAX_USER_SHADOW_BASE;
11973 +#endif
11974 +
11975 + return copy_user_generic((__force_kernel void *)dst, src, size);
11976 + }
11977 switch (size) {
11978 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11979 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11980 ret, "b", "b", "iq", 1);
11981 return ret;
11982 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11983 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11984 ret, "w", "w", "ir", 2);
11985 return ret;
11986 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11987 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11988 ret, "l", "k", "ir", 4);
11989 return ret;
11990 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11991 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11992 ret, "q", "", "er", 8);
11993 return ret;
11994 case 10:
11995 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11996 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11997 ret, "q", "", "er", 10);
11998 if (unlikely(ret))
11999 return ret;
12000 asm("":::"memory");
12001 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12002 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12003 ret, "w", "w", "ir", 2);
12004 return ret;
12005 case 16:
12006 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12007 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12008 ret, "q", "", "er", 16);
12009 if (unlikely(ret))
12010 return ret;
12011 asm("":::"memory");
12012 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12013 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12014 ret, "q", "", "er", 8);
12015 return ret;
12016 default:
12017 - return copy_user_generic((__force void *)dst, src, size);
12018 +
12019 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12020 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12021 + dst += PAX_USER_SHADOW_BASE;
12022 +#endif
12023 +
12024 + return copy_user_generic((__force_kernel void *)dst, src, size);
12025 + }
12026 +}
12027 +
12028 +static __always_inline __must_check
12029 +unsigned long copy_to_user(void __user *to, const void *from, unsigned len)
12030 +{
12031 + if (access_ok(VERIFY_WRITE, to, len))
12032 + len = __copy_to_user(to, from, len);
12033 + return len;
12034 +}
12035 +
12036 +static __always_inline __must_check
12037 +unsigned long copy_from_user(void *to, const void __user *from, unsigned len)
12038 +{
12039 + if ((int)len < 0)
12040 + return len;
12041 +
12042 + if (access_ok(VERIFY_READ, from, len))
12043 + len = __copy_from_user(to, from, len);
12044 + else if ((int)len > 0) {
12045 + if (!__builtin_constant_p(len))
12046 + check_object_size(to, len, false);
12047 + memset(to, 0, len);
12048 }
12049 + return len;
12050 }
12051
12052 static __always_inline __must_check
12053 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12054 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12055 {
12056 - int ret = 0;
12057 + unsigned ret = 0;
12058
12059 might_fault();
12060 - if (!__builtin_constant_p(size))
12061 - return copy_user_generic((__force void *)dst,
12062 - (__force void *)src, size);
12063 +
12064 + pax_track_stack();
12065 +
12066 + if ((int)size < 0)
12067 + return size;
12068 +
12069 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12070 + if (!__access_ok(VERIFY_READ, src, size))
12071 + return size;
12072 + if (!__access_ok(VERIFY_WRITE, dst, size))
12073 + return size;
12074 +#endif
12075 +
12076 + if (!__builtin_constant_p(size)) {
12077 +
12078 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12079 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12080 + src += PAX_USER_SHADOW_BASE;
12081 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12082 + dst += PAX_USER_SHADOW_BASE;
12083 +#endif
12084 +
12085 + return copy_user_generic((__force_kernel void *)dst,
12086 + (__force_kernel const void *)src, size);
12087 + }
12088 switch (size) {
12089 case 1: {
12090 u8 tmp;
12091 - __get_user_asm(tmp, (u8 __user *)src,
12092 + __get_user_asm(tmp, (const u8 __user *)src,
12093 ret, "b", "b", "=q", 1);
12094 if (likely(!ret))
12095 __put_user_asm(tmp, (u8 __user *)dst,
12096 @@ -134,7 +227,7 @@ int __copy_in_user(void __user *dst, con
12097 }
12098 case 2: {
12099 u16 tmp;
12100 - __get_user_asm(tmp, (u16 __user *)src,
12101 + __get_user_asm(tmp, (const u16 __user *)src,
12102 ret, "w", "w", "=r", 2);
12103 if (likely(!ret))
12104 __put_user_asm(tmp, (u16 __user *)dst,
12105 @@ -144,7 +237,7 @@ int __copy_in_user(void __user *dst, con
12106
12107 case 4: {
12108 u32 tmp;
12109 - __get_user_asm(tmp, (u32 __user *)src,
12110 + __get_user_asm(tmp, (const u32 __user *)src,
12111 ret, "l", "k", "=r", 4);
12112 if (likely(!ret))
12113 __put_user_asm(tmp, (u32 __user *)dst,
12114 @@ -153,7 +246,7 @@ int __copy_in_user(void __user *dst, con
12115 }
12116 case 8: {
12117 u64 tmp;
12118 - __get_user_asm(tmp, (u64 __user *)src,
12119 + __get_user_asm(tmp, (const u64 __user *)src,
12120 ret, "q", "", "=r", 8);
12121 if (likely(!ret))
12122 __put_user_asm(tmp, (u64 __user *)dst,
12123 @@ -161,8 +254,16 @@ int __copy_in_user(void __user *dst, con
12124 return ret;
12125 }
12126 default:
12127 - return copy_user_generic((__force void *)dst,
12128 - (__force void *)src, size);
12129 +
12130 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12131 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12132 + src += PAX_USER_SHADOW_BASE;
12133 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12134 + dst += PAX_USER_SHADOW_BASE;
12135 +#endif
12136 +
12137 + return copy_user_generic((__force_kernel void *)dst,
12138 + (__force_kernel const void *)src, size);
12139 }
12140 }
12141
12142 @@ -176,33 +277,75 @@ __must_check long strlen_user(const char
12143 __must_check unsigned long clear_user(void __user *mem, unsigned long len);
12144 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12145
12146 -__must_check long __copy_from_user_inatomic(void *dst, const void __user *src,
12147 - unsigned size);
12148 +static __must_check __always_inline unsigned long
12149 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12150 +{
12151 + pax_track_stack();
12152 +
12153 + if ((int)size < 0)
12154 + return size;
12155 +
12156 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12157 + if (!__access_ok(VERIFY_READ, src, size))
12158 + return size;
12159 +
12160 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12161 + src += PAX_USER_SHADOW_BASE;
12162 +#endif
12163
12164 -static __must_check __always_inline int
12165 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12166 +}
12167 +
12168 +static __must_check __always_inline unsigned long
12169 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12170 {
12171 - return copy_user_generic((__force void *)dst, src, size);
12172 + if ((int)size < 0)
12173 + return size;
12174 +
12175 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12176 + if (!__access_ok(VERIFY_WRITE, dst, size))
12177 + return size;
12178 +
12179 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12180 + dst += PAX_USER_SHADOW_BASE;
12181 +#endif
12182 +
12183 + return copy_user_generic((__force_kernel void *)dst, src, size);
12184 }
12185
12186 -extern long __copy_user_nocache(void *dst, const void __user *src,
12187 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12188 unsigned size, int zerorest);
12189
12190 -static inline int
12191 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12192 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12193 {
12194 might_sleep();
12195 +
12196 + if ((int)size < 0)
12197 + return size;
12198 +
12199 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12200 + if (!__access_ok(VERIFY_READ, src, size))
12201 + return size;
12202 +#endif
12203 +
12204 return __copy_user_nocache(dst, src, size, 1);
12205 }
12206
12207 -static inline int
12208 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12209 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12210 unsigned size)
12211 {
12212 + if ((int)size < 0)
12213 + return size;
12214 +
12215 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12216 + if (!__access_ok(VERIFY_READ, src, size))
12217 + return size;
12218 +#endif
12219 +
12220 return __copy_user_nocache(dst, src, size, 0);
12221 }
12222
12223 -unsigned long
12224 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12225 +extern unsigned long
12226 +copy_user_handle_tail(char __user *to, char __user *from, unsigned len, unsigned zerorest);
12227
12228 #endif /* _ASM_X86_UACCESS_64_H */
12229 diff -urNp linux-2.6.32.46/arch/x86/include/asm/vdso.h linux-2.6.32.46/arch/x86/include/asm/vdso.h
12230 --- linux-2.6.32.46/arch/x86/include/asm/vdso.h 2011-03-27 14:31:47.000000000 -0400
12231 +++ linux-2.6.32.46/arch/x86/include/asm/vdso.h 2011-10-06 09:37:14.000000000 -0400
12232 @@ -25,7 +25,7 @@ extern const char VDSO32_PRELINK[];
12233 #define VDSO32_SYMBOL(base, name) \
12234 ({ \
12235 extern const char VDSO32_##name[]; \
12236 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12237 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12238 })
12239 #endif
12240
12241 diff -urNp linux-2.6.32.46/arch/x86/include/asm/vgtod.h linux-2.6.32.46/arch/x86/include/asm/vgtod.h
12242 --- linux-2.6.32.46/arch/x86/include/asm/vgtod.h 2011-03-27 14:31:47.000000000 -0400
12243 +++ linux-2.6.32.46/arch/x86/include/asm/vgtod.h 2011-04-17 15:56:46.000000000 -0400
12244 @@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
12245 int sysctl_enabled;
12246 struct timezone sys_tz;
12247 struct { /* extract of a clocksource struct */
12248 + char name[8];
12249 cycle_t (*vread)(void);
12250 cycle_t cycle_last;
12251 cycle_t mask;
12252 diff -urNp linux-2.6.32.46/arch/x86/include/asm/vmi.h linux-2.6.32.46/arch/x86/include/asm/vmi.h
12253 --- linux-2.6.32.46/arch/x86/include/asm/vmi.h 2011-03-27 14:31:47.000000000 -0400
12254 +++ linux-2.6.32.46/arch/x86/include/asm/vmi.h 2011-04-17 15:56:46.000000000 -0400
12255 @@ -191,6 +191,7 @@ struct vrom_header {
12256 u8 reserved[96]; /* Reserved for headers */
12257 char vmi_init[8]; /* VMI_Init jump point */
12258 char get_reloc[8]; /* VMI_GetRelocationInfo jump point */
12259 + char rom_data[8048]; /* rest of the option ROM */
12260 } __attribute__((packed));
12261
12262 struct pnp_header {
12263 diff -urNp linux-2.6.32.46/arch/x86/include/asm/vmi_time.h linux-2.6.32.46/arch/x86/include/asm/vmi_time.h
12264 --- linux-2.6.32.46/arch/x86/include/asm/vmi_time.h 2011-03-27 14:31:47.000000000 -0400
12265 +++ linux-2.6.32.46/arch/x86/include/asm/vmi_time.h 2011-08-05 20:33:55.000000000 -0400
12266 @@ -43,7 +43,7 @@ extern struct vmi_timer_ops {
12267 int (*wallclock_updated)(void);
12268 void (*set_alarm)(u32 flags, u64 expiry, u64 period);
12269 void (*cancel_alarm)(u32 flags);
12270 -} vmi_timer_ops;
12271 +} __no_const vmi_timer_ops;
12272
12273 /* Prototypes */
12274 extern void __init vmi_time_init(void);
12275 diff -urNp linux-2.6.32.46/arch/x86/include/asm/vsyscall.h linux-2.6.32.46/arch/x86/include/asm/vsyscall.h
12276 --- linux-2.6.32.46/arch/x86/include/asm/vsyscall.h 2011-03-27 14:31:47.000000000 -0400
12277 +++ linux-2.6.32.46/arch/x86/include/asm/vsyscall.h 2011-04-17 15:56:46.000000000 -0400
12278 @@ -15,9 +15,10 @@ enum vsyscall_num {
12279
12280 #ifdef __KERNEL__
12281 #include <linux/seqlock.h>
12282 +#include <linux/getcpu.h>
12283 +#include <linux/time.h>
12284
12285 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
12286 -#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
12287
12288 /* Definitions for CONFIG_GENERIC_TIME definitions */
12289 #define __section_vsyscall_gtod_data __attribute__ \
12290 @@ -31,7 +32,6 @@ enum vsyscall_num {
12291 #define VGETCPU_LSL 2
12292
12293 extern int __vgetcpu_mode;
12294 -extern volatile unsigned long __jiffies;
12295
12296 /* kernel space (writeable) */
12297 extern int vgetcpu_mode;
12298 @@ -39,6 +39,9 @@ extern struct timezone sys_tz;
12299
12300 extern void map_vsyscall(void);
12301
12302 +extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
12303 +extern time_t vtime(time_t *t);
12304 +extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
12305 #endif /* __KERNEL__ */
12306
12307 #endif /* _ASM_X86_VSYSCALL_H */
12308 diff -urNp linux-2.6.32.46/arch/x86/include/asm/x86_init.h linux-2.6.32.46/arch/x86/include/asm/x86_init.h
12309 --- linux-2.6.32.46/arch/x86/include/asm/x86_init.h 2011-03-27 14:31:47.000000000 -0400
12310 +++ linux-2.6.32.46/arch/x86/include/asm/x86_init.h 2011-08-05 20:33:55.000000000 -0400
12311 @@ -28,7 +28,7 @@ struct x86_init_mpparse {
12312 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
12313 void (*find_smp_config)(unsigned int reserve);
12314 void (*get_smp_config)(unsigned int early);
12315 -};
12316 +} __no_const;
12317
12318 /**
12319 * struct x86_init_resources - platform specific resource related ops
12320 @@ -42,7 +42,7 @@ struct x86_init_resources {
12321 void (*probe_roms)(void);
12322 void (*reserve_resources)(void);
12323 char *(*memory_setup)(void);
12324 -};
12325 +} __no_const;
12326
12327 /**
12328 * struct x86_init_irqs - platform specific interrupt setup
12329 @@ -55,7 +55,7 @@ struct x86_init_irqs {
12330 void (*pre_vector_init)(void);
12331 void (*intr_init)(void);
12332 void (*trap_init)(void);
12333 -};
12334 +} __no_const;
12335
12336 /**
12337 * struct x86_init_oem - oem platform specific customizing functions
12338 @@ -65,7 +65,7 @@ struct x86_init_irqs {
12339 struct x86_init_oem {
12340 void (*arch_setup)(void);
12341 void (*banner)(void);
12342 -};
12343 +} __no_const;
12344
12345 /**
12346 * struct x86_init_paging - platform specific paging functions
12347 @@ -75,7 +75,7 @@ struct x86_init_oem {
12348 struct x86_init_paging {
12349 void (*pagetable_setup_start)(pgd_t *base);
12350 void (*pagetable_setup_done)(pgd_t *base);
12351 -};
12352 +} __no_const;
12353
12354 /**
12355 * struct x86_init_timers - platform specific timer setup
12356 @@ -88,7 +88,7 @@ struct x86_init_timers {
12357 void (*setup_percpu_clockev)(void);
12358 void (*tsc_pre_init)(void);
12359 void (*timer_init)(void);
12360 -};
12361 +} __no_const;
12362
12363 /**
12364 * struct x86_init_ops - functions for platform specific setup
12365 @@ -101,7 +101,7 @@ struct x86_init_ops {
12366 struct x86_init_oem oem;
12367 struct x86_init_paging paging;
12368 struct x86_init_timers timers;
12369 -};
12370 +} __no_const;
12371
12372 /**
12373 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
12374 @@ -109,7 +109,7 @@ struct x86_init_ops {
12375 */
12376 struct x86_cpuinit_ops {
12377 void (*setup_percpu_clockev)(void);
12378 -};
12379 +} __no_const;
12380
12381 /**
12382 * struct x86_platform_ops - platform specific runtime functions
12383 @@ -121,7 +121,7 @@ struct x86_platform_ops {
12384 unsigned long (*calibrate_tsc)(void);
12385 unsigned long (*get_wallclock)(void);
12386 int (*set_wallclock)(unsigned long nowtime);
12387 -};
12388 +} __no_const;
12389
12390 extern struct x86_init_ops x86_init;
12391 extern struct x86_cpuinit_ops x86_cpuinit;
12392 diff -urNp linux-2.6.32.46/arch/x86/include/asm/xsave.h linux-2.6.32.46/arch/x86/include/asm/xsave.h
12393 --- linux-2.6.32.46/arch/x86/include/asm/xsave.h 2011-03-27 14:31:47.000000000 -0400
12394 +++ linux-2.6.32.46/arch/x86/include/asm/xsave.h 2011-10-06 09:37:08.000000000 -0400
12395 @@ -56,6 +56,12 @@ static inline int xrstor_checking(struct
12396 static inline int xsave_user(struct xsave_struct __user *buf)
12397 {
12398 int err;
12399 +
12400 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12401 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12402 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12403 +#endif
12404 +
12405 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
12406 "2:\n"
12407 ".section .fixup,\"ax\"\n"
12408 @@ -78,10 +84,15 @@ static inline int xsave_user(struct xsav
12409 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
12410 {
12411 int err;
12412 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
12413 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
12414 u32 lmask = mask;
12415 u32 hmask = mask >> 32;
12416
12417 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12418 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
12419 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
12420 +#endif
12421 +
12422 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
12423 "2:\n"
12424 ".section .fixup,\"ax\"\n"
12425 diff -urNp linux-2.6.32.46/arch/x86/kernel/acpi/realmode/Makefile linux-2.6.32.46/arch/x86/kernel/acpi/realmode/Makefile
12426 --- linux-2.6.32.46/arch/x86/kernel/acpi/realmode/Makefile 2011-03-27 14:31:47.000000000 -0400
12427 +++ linux-2.6.32.46/arch/x86/kernel/acpi/realmode/Makefile 2011-08-07 14:38:58.000000000 -0400
12428 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os
12429 $(call cc-option, -fno-stack-protector) \
12430 $(call cc-option, -mpreferred-stack-boundary=2)
12431 KBUILD_CFLAGS += $(call cc-option, -m32)
12432 +ifdef CONSTIFY_PLUGIN
12433 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
12434 +endif
12435 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12436 GCOV_PROFILE := n
12437
12438 diff -urNp linux-2.6.32.46/arch/x86/kernel/acpi/realmode/wakeup.S linux-2.6.32.46/arch/x86/kernel/acpi/realmode/wakeup.S
12439 --- linux-2.6.32.46/arch/x86/kernel/acpi/realmode/wakeup.S 2011-03-27 14:31:47.000000000 -0400
12440 +++ linux-2.6.32.46/arch/x86/kernel/acpi/realmode/wakeup.S 2011-07-01 18:53:40.000000000 -0400
12441 @@ -91,6 +91,9 @@ _start:
12442 /* Do any other stuff... */
12443
12444 #ifndef CONFIG_64BIT
12445 + /* Recheck NX bit overrides (64bit path does this in trampoline) */
12446 + call verify_cpu
12447 +
12448 /* This could also be done in C code... */
12449 movl pmode_cr3, %eax
12450 movl %eax, %cr3
12451 @@ -104,7 +107,7 @@ _start:
12452 movl %eax, %ecx
12453 orl %edx, %ecx
12454 jz 1f
12455 - movl $0xc0000080, %ecx
12456 + mov $MSR_EFER, %ecx
12457 wrmsr
12458 1:
12459
12460 @@ -114,6 +117,7 @@ _start:
12461 movl pmode_cr0, %eax
12462 movl %eax, %cr0
12463 jmp pmode_return
12464 +# include "../../verify_cpu.S"
12465 #else
12466 pushw $0
12467 pushw trampoline_segment
12468 diff -urNp linux-2.6.32.46/arch/x86/kernel/acpi/sleep.c linux-2.6.32.46/arch/x86/kernel/acpi/sleep.c
12469 --- linux-2.6.32.46/arch/x86/kernel/acpi/sleep.c 2011-03-27 14:31:47.000000000 -0400
12470 +++ linux-2.6.32.46/arch/x86/kernel/acpi/sleep.c 2011-07-01 19:01:34.000000000 -0400
12471 @@ -11,11 +11,12 @@
12472 #include <linux/cpumask.h>
12473 #include <asm/segment.h>
12474 #include <asm/desc.h>
12475 +#include <asm/e820.h>
12476
12477 #include "realmode/wakeup.h"
12478 #include "sleep.h"
12479
12480 -unsigned long acpi_wakeup_address;
12481 +unsigned long acpi_wakeup_address = 0x2000;
12482 unsigned long acpi_realmode_flags;
12483
12484 /* address in low memory of the wakeup routine. */
12485 @@ -98,9 +99,13 @@ int acpi_save_state_mem(void)
12486 #else /* CONFIG_64BIT */
12487 header->trampoline_segment = setup_trampoline() >> 4;
12488 #ifdef CONFIG_SMP
12489 - stack_start.sp = temp_stack + sizeof(temp_stack);
12490 + stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
12491 +
12492 + pax_open_kernel();
12493 early_gdt_descr.address =
12494 (unsigned long)get_cpu_gdt_table(smp_processor_id());
12495 + pax_close_kernel();
12496 +
12497 initial_gs = per_cpu_offset(smp_processor_id());
12498 #endif
12499 initial_code = (unsigned long)wakeup_long64;
12500 @@ -134,14 +139,8 @@ void __init acpi_reserve_bootmem(void)
12501 return;
12502 }
12503
12504 - acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
12505 -
12506 - if (!acpi_realmode) {
12507 - printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
12508 - return;
12509 - }
12510 -
12511 - acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
12512 + reserve_early(acpi_wakeup_address, acpi_wakeup_address + WAKEUP_SIZE, "ACPI Wakeup Code");
12513 + acpi_realmode = (unsigned long)__va(acpi_wakeup_address);;
12514 }
12515
12516
12517 diff -urNp linux-2.6.32.46/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.32.46/arch/x86/kernel/acpi/wakeup_32.S
12518 --- linux-2.6.32.46/arch/x86/kernel/acpi/wakeup_32.S 2011-03-27 14:31:47.000000000 -0400
12519 +++ linux-2.6.32.46/arch/x86/kernel/acpi/wakeup_32.S 2011-04-17 15:56:46.000000000 -0400
12520 @@ -30,13 +30,11 @@ wakeup_pmode_return:
12521 # and restore the stack ... but you need gdt for this to work
12522 movl saved_context_esp, %esp
12523
12524 - movl %cs:saved_magic, %eax
12525 - cmpl $0x12345678, %eax
12526 + cmpl $0x12345678, saved_magic
12527 jne bogus_magic
12528
12529 # jump to place where we left off
12530 - movl saved_eip, %eax
12531 - jmp *%eax
12532 + jmp *(saved_eip)
12533
12534 bogus_magic:
12535 jmp bogus_magic
12536 diff -urNp linux-2.6.32.46/arch/x86/kernel/alternative.c linux-2.6.32.46/arch/x86/kernel/alternative.c
12537 --- linux-2.6.32.46/arch/x86/kernel/alternative.c 2011-03-27 14:31:47.000000000 -0400
12538 +++ linux-2.6.32.46/arch/x86/kernel/alternative.c 2011-04-17 15:56:46.000000000 -0400
12539 @@ -407,7 +407,7 @@ void __init_or_module apply_paravirt(str
12540
12541 BUG_ON(p->len > MAX_PATCH_LEN);
12542 /* prep the buffer with the original instructions */
12543 - memcpy(insnbuf, p->instr, p->len);
12544 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
12545 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
12546 (unsigned long)p->instr, p->len);
12547
12548 @@ -475,7 +475,7 @@ void __init alternative_instructions(voi
12549 if (smp_alt_once)
12550 free_init_pages("SMP alternatives",
12551 (unsigned long)__smp_locks,
12552 - (unsigned long)__smp_locks_end);
12553 + PAGE_ALIGN((unsigned long)__smp_locks_end));
12554
12555 restart_nmi();
12556 }
12557 @@ -492,13 +492,17 @@ void __init alternative_instructions(voi
12558 * instructions. And on the local CPU you need to be protected again NMI or MCE
12559 * handlers seeing an inconsistent instruction while you patch.
12560 */
12561 -static void *__init_or_module text_poke_early(void *addr, const void *opcode,
12562 +static void *__kprobes text_poke_early(void *addr, const void *opcode,
12563 size_t len)
12564 {
12565 unsigned long flags;
12566 local_irq_save(flags);
12567 - memcpy(addr, opcode, len);
12568 +
12569 + pax_open_kernel();
12570 + memcpy(ktla_ktva(addr), opcode, len);
12571 sync_core();
12572 + pax_close_kernel();
12573 +
12574 local_irq_restore(flags);
12575 /* Could also do a CLFLUSH here to speed up CPU recovery; but
12576 that causes hangs on some VIA CPUs. */
12577 @@ -520,35 +524,21 @@ static void *__init_or_module text_poke_
12578 */
12579 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
12580 {
12581 - unsigned long flags;
12582 - char *vaddr;
12583 + unsigned char *vaddr = ktla_ktva(addr);
12584 struct page *pages[2];
12585 - int i;
12586 + size_t i;
12587
12588 if (!core_kernel_text((unsigned long)addr)) {
12589 - pages[0] = vmalloc_to_page(addr);
12590 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
12591 + pages[0] = vmalloc_to_page(vaddr);
12592 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
12593 } else {
12594 - pages[0] = virt_to_page(addr);
12595 + pages[0] = virt_to_page(vaddr);
12596 WARN_ON(!PageReserved(pages[0]));
12597 - pages[1] = virt_to_page(addr + PAGE_SIZE);
12598 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
12599 }
12600 BUG_ON(!pages[0]);
12601 - local_irq_save(flags);
12602 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
12603 - if (pages[1])
12604 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
12605 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
12606 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
12607 - clear_fixmap(FIX_TEXT_POKE0);
12608 - if (pages[1])
12609 - clear_fixmap(FIX_TEXT_POKE1);
12610 - local_flush_tlb();
12611 - sync_core();
12612 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
12613 - that causes hangs on some VIA CPUs. */
12614 + text_poke_early(addr, opcode, len);
12615 for (i = 0; i < len; i++)
12616 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
12617 - local_irq_restore(flags);
12618 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
12619 return addr;
12620 }
12621 diff -urNp linux-2.6.32.46/arch/x86/kernel/amd_iommu.c linux-2.6.32.46/arch/x86/kernel/amd_iommu.c
12622 --- linux-2.6.32.46/arch/x86/kernel/amd_iommu.c 2011-03-27 14:31:47.000000000 -0400
12623 +++ linux-2.6.32.46/arch/x86/kernel/amd_iommu.c 2011-04-17 15:56:46.000000000 -0400
12624 @@ -2076,7 +2076,7 @@ static void prealloc_protection_domains(
12625 }
12626 }
12627
12628 -static struct dma_map_ops amd_iommu_dma_ops = {
12629 +static const struct dma_map_ops amd_iommu_dma_ops = {
12630 .alloc_coherent = alloc_coherent,
12631 .free_coherent = free_coherent,
12632 .map_page = map_page,
12633 diff -urNp linux-2.6.32.46/arch/x86/kernel/apic/apic.c linux-2.6.32.46/arch/x86/kernel/apic/apic.c
12634 --- linux-2.6.32.46/arch/x86/kernel/apic/apic.c 2011-03-27 14:31:47.000000000 -0400
12635 +++ linux-2.6.32.46/arch/x86/kernel/apic/apic.c 2011-08-17 20:00:16.000000000 -0400
12636 @@ -170,7 +170,7 @@ int first_system_vector = 0xfe;
12637 /*
12638 * Debug level, exported for io_apic.c
12639 */
12640 -unsigned int apic_verbosity;
12641 +int apic_verbosity;
12642
12643 int pic_mode;
12644
12645 @@ -1794,7 +1794,7 @@ void smp_error_interrupt(struct pt_regs
12646 apic_write(APIC_ESR, 0);
12647 v1 = apic_read(APIC_ESR);
12648 ack_APIC_irq();
12649 - atomic_inc(&irq_err_count);
12650 + atomic_inc_unchecked(&irq_err_count);
12651
12652 /*
12653 * Here is what the APIC error bits mean:
12654 @@ -2184,6 +2184,8 @@ static int __cpuinit apic_cluster_num(vo
12655 u16 *bios_cpu_apicid;
12656 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
12657
12658 + pax_track_stack();
12659 +
12660 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
12661 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
12662
12663 diff -urNp linux-2.6.32.46/arch/x86/kernel/apic/io_apic.c linux-2.6.32.46/arch/x86/kernel/apic/io_apic.c
12664 --- linux-2.6.32.46/arch/x86/kernel/apic/io_apic.c 2011-03-27 14:31:47.000000000 -0400
12665 +++ linux-2.6.32.46/arch/x86/kernel/apic/io_apic.c 2011-05-04 17:56:20.000000000 -0400
12666 @@ -716,7 +716,7 @@ struct IO_APIC_route_entry **alloc_ioapi
12667 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
12668 GFP_ATOMIC);
12669 if (!ioapic_entries)
12670 - return 0;
12671 + return NULL;
12672
12673 for (apic = 0; apic < nr_ioapics; apic++) {
12674 ioapic_entries[apic] =
12675 @@ -733,7 +733,7 @@ nomem:
12676 kfree(ioapic_entries[apic]);
12677 kfree(ioapic_entries);
12678
12679 - return 0;
12680 + return NULL;
12681 }
12682
12683 /*
12684 @@ -1150,7 +1150,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
12685 }
12686 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
12687
12688 -void lock_vector_lock(void)
12689 +void lock_vector_lock(void) __acquires(vector_lock)
12690 {
12691 /* Used to the online set of cpus does not change
12692 * during assign_irq_vector.
12693 @@ -1158,7 +1158,7 @@ void lock_vector_lock(void)
12694 spin_lock(&vector_lock);
12695 }
12696
12697 -void unlock_vector_lock(void)
12698 +void unlock_vector_lock(void) __releases(vector_lock)
12699 {
12700 spin_unlock(&vector_lock);
12701 }
12702 @@ -2542,7 +2542,7 @@ static void ack_apic_edge(unsigned int i
12703 ack_APIC_irq();
12704 }
12705
12706 -atomic_t irq_mis_count;
12707 +atomic_unchecked_t irq_mis_count;
12708
12709 static void ack_apic_level(unsigned int irq)
12710 {
12711 @@ -2626,7 +2626,7 @@ static void ack_apic_level(unsigned int
12712
12713 /* Tail end of version 0x11 I/O APIC bug workaround */
12714 if (!(v & (1 << (i & 0x1f)))) {
12715 - atomic_inc(&irq_mis_count);
12716 + atomic_inc_unchecked(&irq_mis_count);
12717 spin_lock(&ioapic_lock);
12718 __mask_and_edge_IO_APIC_irq(cfg);
12719 __unmask_and_level_IO_APIC_irq(cfg);
12720 diff -urNp linux-2.6.32.46/arch/x86/kernel/apm_32.c linux-2.6.32.46/arch/x86/kernel/apm_32.c
12721 --- linux-2.6.32.46/arch/x86/kernel/apm_32.c 2011-03-27 14:31:47.000000000 -0400
12722 +++ linux-2.6.32.46/arch/x86/kernel/apm_32.c 2011-04-23 12:56:10.000000000 -0400
12723 @@ -410,7 +410,7 @@ static DEFINE_SPINLOCK(user_list_lock);
12724 * This is for buggy BIOS's that refer to (real mode) segment 0x40
12725 * even though they are called in protected mode.
12726 */
12727 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
12728 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
12729 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
12730
12731 static const char driver_version[] = "1.16ac"; /* no spaces */
12732 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
12733 BUG_ON(cpu != 0);
12734 gdt = get_cpu_gdt_table(cpu);
12735 save_desc_40 = gdt[0x40 / 8];
12736 +
12737 + pax_open_kernel();
12738 gdt[0x40 / 8] = bad_bios_desc;
12739 + pax_close_kernel();
12740
12741 apm_irq_save(flags);
12742 APM_DO_SAVE_SEGS;
12743 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
12744 &call->esi);
12745 APM_DO_RESTORE_SEGS;
12746 apm_irq_restore(flags);
12747 +
12748 + pax_open_kernel();
12749 gdt[0x40 / 8] = save_desc_40;
12750 + pax_close_kernel();
12751 +
12752 put_cpu();
12753
12754 return call->eax & 0xff;
12755 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void
12756 BUG_ON(cpu != 0);
12757 gdt = get_cpu_gdt_table(cpu);
12758 save_desc_40 = gdt[0x40 / 8];
12759 +
12760 + pax_open_kernel();
12761 gdt[0x40 / 8] = bad_bios_desc;
12762 + pax_close_kernel();
12763
12764 apm_irq_save(flags);
12765 APM_DO_SAVE_SEGS;
12766 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void
12767 &call->eax);
12768 APM_DO_RESTORE_SEGS;
12769 apm_irq_restore(flags);
12770 +
12771 + pax_open_kernel();
12772 gdt[0x40 / 8] = save_desc_40;
12773 + pax_close_kernel();
12774 +
12775 put_cpu();
12776 return error;
12777 }
12778 @@ -975,7 +989,7 @@ recalc:
12779
12780 static void apm_power_off(void)
12781 {
12782 - unsigned char po_bios_call[] = {
12783 + const unsigned char po_bios_call[] = {
12784 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
12785 0x8e, 0xd0, /* movw ax,ss */
12786 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
12787 @@ -2357,12 +2371,15 @@ static int __init apm_init(void)
12788 * code to that CPU.
12789 */
12790 gdt = get_cpu_gdt_table(0);
12791 +
12792 + pax_open_kernel();
12793 set_desc_base(&gdt[APM_CS >> 3],
12794 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
12795 set_desc_base(&gdt[APM_CS_16 >> 3],
12796 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
12797 set_desc_base(&gdt[APM_DS >> 3],
12798 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
12799 + pax_close_kernel();
12800
12801 proc_create("apm", 0, NULL, &apm_file_ops);
12802
12803 diff -urNp linux-2.6.32.46/arch/x86/kernel/asm-offsets_32.c linux-2.6.32.46/arch/x86/kernel/asm-offsets_32.c
12804 --- linux-2.6.32.46/arch/x86/kernel/asm-offsets_32.c 2011-03-27 14:31:47.000000000 -0400
12805 +++ linux-2.6.32.46/arch/x86/kernel/asm-offsets_32.c 2011-05-16 21:46:57.000000000 -0400
12806 @@ -51,7 +51,6 @@ void foo(void)
12807 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
12808 BLANK();
12809
12810 - OFFSET(TI_task, thread_info, task);
12811 OFFSET(TI_exec_domain, thread_info, exec_domain);
12812 OFFSET(TI_flags, thread_info, flags);
12813 OFFSET(TI_status, thread_info, status);
12814 @@ -60,6 +59,8 @@ void foo(void)
12815 OFFSET(TI_restart_block, thread_info, restart_block);
12816 OFFSET(TI_sysenter_return, thread_info, sysenter_return);
12817 OFFSET(TI_cpu, thread_info, cpu);
12818 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
12819 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12820 BLANK();
12821
12822 OFFSET(GDS_size, desc_ptr, size);
12823 @@ -99,6 +100,7 @@ void foo(void)
12824
12825 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
12826 DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
12827 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12828 DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
12829 DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
12830 DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
12831 @@ -115,6 +117,11 @@ void foo(void)
12832 OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
12833 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12834 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12835 +
12836 +#ifdef CONFIG_PAX_KERNEXEC
12837 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12838 +#endif
12839 +
12840 #endif
12841
12842 #ifdef CONFIG_XEN
12843 diff -urNp linux-2.6.32.46/arch/x86/kernel/asm-offsets_64.c linux-2.6.32.46/arch/x86/kernel/asm-offsets_64.c
12844 --- linux-2.6.32.46/arch/x86/kernel/asm-offsets_64.c 2011-03-27 14:31:47.000000000 -0400
12845 +++ linux-2.6.32.46/arch/x86/kernel/asm-offsets_64.c 2011-08-23 20:24:19.000000000 -0400
12846 @@ -44,6 +44,8 @@ int main(void)
12847 ENTRY(addr_limit);
12848 ENTRY(preempt_count);
12849 ENTRY(status);
12850 + ENTRY(lowest_stack);
12851 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12852 #ifdef CONFIG_IA32_EMULATION
12853 ENTRY(sysenter_return);
12854 #endif
12855 @@ -63,6 +65,18 @@ int main(void)
12856 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12857 OFFSET(PV_CPU_swapgs, pv_cpu_ops, swapgs);
12858 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
12859 +
12860 +#ifdef CONFIG_PAX_KERNEXEC
12861 + OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12862 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12863 +#endif
12864 +
12865 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12866 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
12867 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
12868 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
12869 +#endif
12870 +
12871 #endif
12872
12873
12874 @@ -115,6 +129,7 @@ int main(void)
12875 ENTRY(cr8);
12876 BLANK();
12877 #undef ENTRY
12878 + DEFINE(TSS_size, sizeof(struct tss_struct));
12879 DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
12880 BLANK();
12881 DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
12882 @@ -130,6 +145,7 @@ int main(void)
12883
12884 BLANK();
12885 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
12886 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12887 #ifdef CONFIG_XEN
12888 BLANK();
12889 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
12890 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/Makefile linux-2.6.32.46/arch/x86/kernel/cpu/Makefile
12891 --- linux-2.6.32.46/arch/x86/kernel/cpu/Makefile 2011-03-27 14:31:47.000000000 -0400
12892 +++ linux-2.6.32.46/arch/x86/kernel/cpu/Makefile 2011-04-17 15:56:46.000000000 -0400
12893 @@ -7,10 +7,6 @@ ifdef CONFIG_FUNCTION_TRACER
12894 CFLAGS_REMOVE_common.o = -pg
12895 endif
12896
12897 -# Make sure load_percpu_segment has no stackprotector
12898 -nostackp := $(call cc-option, -fno-stack-protector)
12899 -CFLAGS_common.o := $(nostackp)
12900 -
12901 obj-y := intel_cacheinfo.o addon_cpuid_features.o
12902 obj-y += proc.o capflags.o powerflags.o common.o
12903 obj-y += vmware.o hypervisor.o sched.o
12904 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/amd.c linux-2.6.32.46/arch/x86/kernel/cpu/amd.c
12905 --- linux-2.6.32.46/arch/x86/kernel/cpu/amd.c 2011-06-25 12:55:34.000000000 -0400
12906 +++ linux-2.6.32.46/arch/x86/kernel/cpu/amd.c 2011-06-25 12:56:37.000000000 -0400
12907 @@ -602,7 +602,7 @@ static unsigned int __cpuinit amd_size_c
12908 unsigned int size)
12909 {
12910 /* AMD errata T13 (order #21922) */
12911 - if ((c->x86 == 6)) {
12912 + if (c->x86 == 6) {
12913 /* Duron Rev A0 */
12914 if (c->x86_model == 3 && c->x86_mask == 0)
12915 size = 64;
12916 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/common.c linux-2.6.32.46/arch/x86/kernel/cpu/common.c
12917 --- linux-2.6.32.46/arch/x86/kernel/cpu/common.c 2011-03-27 14:31:47.000000000 -0400
12918 +++ linux-2.6.32.46/arch/x86/kernel/cpu/common.c 2011-05-11 18:25:15.000000000 -0400
12919 @@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
12920
12921 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
12922
12923 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
12924 -#ifdef CONFIG_X86_64
12925 - /*
12926 - * We need valid kernel segments for data and code in long mode too
12927 - * IRET will check the segment types kkeil 2000/10/28
12928 - * Also sysret mandates a special GDT layout
12929 - *
12930 - * TLS descriptors are currently at a different place compared to i386.
12931 - * Hopefully nobody expects them at a fixed place (Wine?)
12932 - */
12933 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
12934 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
12935 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
12936 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
12937 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
12938 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
12939 -#else
12940 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
12941 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12942 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
12943 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
12944 - /*
12945 - * Segments used for calling PnP BIOS have byte granularity.
12946 - * They code segments and data segments have fixed 64k limits,
12947 - * the transfer segment sizes are set at run time.
12948 - */
12949 - /* 32-bit code */
12950 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12951 - /* 16-bit code */
12952 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12953 - /* 16-bit data */
12954 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
12955 - /* 16-bit data */
12956 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
12957 - /* 16-bit data */
12958 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
12959 - /*
12960 - * The APM segments have byte granularity and their bases
12961 - * are set at run time. All have 64k limits.
12962 - */
12963 - /* 32-bit code */
12964 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12965 - /* 16-bit code */
12966 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12967 - /* data */
12968 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
12969 -
12970 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12971 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12972 - GDT_STACK_CANARY_INIT
12973 -#endif
12974 -} };
12975 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
12976 -
12977 static int __init x86_xsave_setup(char *s)
12978 {
12979 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
12980 @@ -344,7 +290,7 @@ void switch_to_new_gdt(int cpu)
12981 {
12982 struct desc_ptr gdt_descr;
12983
12984 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
12985 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
12986 gdt_descr.size = GDT_SIZE - 1;
12987 load_gdt(&gdt_descr);
12988 /* Reload the per-cpu base */
12989 @@ -798,6 +744,10 @@ static void __cpuinit identify_cpu(struc
12990 /* Filter out anything that depends on CPUID levels we don't have */
12991 filter_cpuid_features(c, true);
12992
12993 +#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
12994 + setup_clear_cpu_cap(X86_FEATURE_SEP);
12995 +#endif
12996 +
12997 /* If the model name is still unset, do table lookup. */
12998 if (!c->x86_model_id[0]) {
12999 const char *p;
13000 @@ -980,6 +930,9 @@ static __init int setup_disablecpuid(cha
13001 }
13002 __setup("clearcpuid=", setup_disablecpuid);
13003
13004 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13005 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13006 +
13007 #ifdef CONFIG_X86_64
13008 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13009
13010 @@ -995,7 +948,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
13011 EXPORT_PER_CPU_SYMBOL(current_task);
13012
13013 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13014 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13015 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13016 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13017
13018 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13019 @@ -1060,7 +1013,7 @@ struct pt_regs * __cpuinit idle_regs(str
13020 {
13021 memset(regs, 0, sizeof(struct pt_regs));
13022 regs->fs = __KERNEL_PERCPU;
13023 - regs->gs = __KERNEL_STACK_CANARY;
13024 + savesegment(gs, regs->gs);
13025
13026 return regs;
13027 }
13028 @@ -1101,7 +1054,7 @@ void __cpuinit cpu_init(void)
13029 int i;
13030
13031 cpu = stack_smp_processor_id();
13032 - t = &per_cpu(init_tss, cpu);
13033 + t = init_tss + cpu;
13034 orig_ist = &per_cpu(orig_ist, cpu);
13035
13036 #ifdef CONFIG_NUMA
13037 @@ -1127,7 +1080,7 @@ void __cpuinit cpu_init(void)
13038 switch_to_new_gdt(cpu);
13039 loadsegment(fs, 0);
13040
13041 - load_idt((const struct desc_ptr *)&idt_descr);
13042 + load_idt(&idt_descr);
13043
13044 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13045 syscall_init();
13046 @@ -1136,7 +1089,6 @@ void __cpuinit cpu_init(void)
13047 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13048 barrier();
13049
13050 - check_efer();
13051 if (cpu != 0)
13052 enable_x2apic();
13053
13054 @@ -1199,7 +1151,7 @@ void __cpuinit cpu_init(void)
13055 {
13056 int cpu = smp_processor_id();
13057 struct task_struct *curr = current;
13058 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13059 + struct tss_struct *t = init_tss + cpu;
13060 struct thread_struct *thread = &curr->thread;
13061
13062 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13063 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/intel.c linux-2.6.32.46/arch/x86/kernel/cpu/intel.c
13064 --- linux-2.6.32.46/arch/x86/kernel/cpu/intel.c 2011-03-27 14:31:47.000000000 -0400
13065 +++ linux-2.6.32.46/arch/x86/kernel/cpu/intel.c 2011-04-17 15:56:46.000000000 -0400
13066 @@ -162,7 +162,7 @@ static void __cpuinit trap_init_f00f_bug
13067 * Update the IDT descriptor and reload the IDT so that
13068 * it uses the read-only mapped virtual address.
13069 */
13070 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13071 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13072 load_idt(&idt_descr);
13073 }
13074 #endif
13075 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/intel_cacheinfo.c linux-2.6.32.46/arch/x86/kernel/cpu/intel_cacheinfo.c
13076 --- linux-2.6.32.46/arch/x86/kernel/cpu/intel_cacheinfo.c 2011-03-27 14:31:47.000000000 -0400
13077 +++ linux-2.6.32.46/arch/x86/kernel/cpu/intel_cacheinfo.c 2011-04-17 15:56:46.000000000 -0400
13078 @@ -921,7 +921,7 @@ static ssize_t store(struct kobject *kob
13079 return ret;
13080 }
13081
13082 -static struct sysfs_ops sysfs_ops = {
13083 +static const struct sysfs_ops sysfs_ops = {
13084 .show = show,
13085 .store = store,
13086 };
13087 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce-inject.c linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce-inject.c
13088 --- linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce-inject.c 2011-03-27 14:31:47.000000000 -0400
13089 +++ linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce-inject.c 2011-08-05 20:33:55.000000000 -0400
13090 @@ -211,7 +211,9 @@ static ssize_t mce_write(struct file *fi
13091 static int inject_init(void)
13092 {
13093 printk(KERN_INFO "Machine check injector initialized\n");
13094 - mce_chrdev_ops.write = mce_write;
13095 + pax_open_kernel();
13096 + *(void **)&mce_chrdev_ops.write = mce_write;
13097 + pax_close_kernel();
13098 register_die_notifier(&mce_raise_nb);
13099 return 0;
13100 }
13101 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce.c linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce.c
13102 --- linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce.c 2011-03-27 14:31:47.000000000 -0400
13103 +++ linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-04 17:56:20.000000000 -0400
13104 @@ -43,6 +43,7 @@
13105 #include <asm/ipi.h>
13106 #include <asm/mce.h>
13107 #include <asm/msr.h>
13108 +#include <asm/local.h>
13109
13110 #include "mce-internal.h"
13111
13112 @@ -187,7 +188,7 @@ static void print_mce(struct mce *m)
13113 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13114 m->cs, m->ip);
13115
13116 - if (m->cs == __KERNEL_CS)
13117 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13118 print_symbol("{%s}", m->ip);
13119 pr_cont("\n");
13120 }
13121 @@ -221,10 +222,10 @@ static void print_mce_tail(void)
13122
13123 #define PANIC_TIMEOUT 5 /* 5 seconds */
13124
13125 -static atomic_t mce_paniced;
13126 +static atomic_unchecked_t mce_paniced;
13127
13128 static int fake_panic;
13129 -static atomic_t mce_fake_paniced;
13130 +static atomic_unchecked_t mce_fake_paniced;
13131
13132 /* Panic in progress. Enable interrupts and wait for final IPI */
13133 static void wait_for_panic(void)
13134 @@ -248,7 +249,7 @@ static void mce_panic(char *msg, struct
13135 /*
13136 * Make sure only one CPU runs in machine check panic
13137 */
13138 - if (atomic_inc_return(&mce_paniced) > 1)
13139 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13140 wait_for_panic();
13141 barrier();
13142
13143 @@ -256,7 +257,7 @@ static void mce_panic(char *msg, struct
13144 console_verbose();
13145 } else {
13146 /* Don't log too much for fake panic */
13147 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13148 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13149 return;
13150 }
13151 print_mce_head();
13152 @@ -616,7 +617,7 @@ static int mce_timed_out(u64 *t)
13153 * might have been modified by someone else.
13154 */
13155 rmb();
13156 - if (atomic_read(&mce_paniced))
13157 + if (atomic_read_unchecked(&mce_paniced))
13158 wait_for_panic();
13159 if (!monarch_timeout)
13160 goto out;
13161 @@ -1429,14 +1430,14 @@ void __cpuinit mcheck_init(struct cpuinf
13162 */
13163
13164 static DEFINE_SPINLOCK(mce_state_lock);
13165 -static int open_count; /* #times opened */
13166 +static local_t open_count; /* #times opened */
13167 static int open_exclu; /* already open exclusive? */
13168
13169 static int mce_open(struct inode *inode, struct file *file)
13170 {
13171 spin_lock(&mce_state_lock);
13172
13173 - if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
13174 + if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
13175 spin_unlock(&mce_state_lock);
13176
13177 return -EBUSY;
13178 @@ -1444,7 +1445,7 @@ static int mce_open(struct inode *inode,
13179
13180 if (file->f_flags & O_EXCL)
13181 open_exclu = 1;
13182 - open_count++;
13183 + local_inc(&open_count);
13184
13185 spin_unlock(&mce_state_lock);
13186
13187 @@ -1455,7 +1456,7 @@ static int mce_release(struct inode *ino
13188 {
13189 spin_lock(&mce_state_lock);
13190
13191 - open_count--;
13192 + local_dec(&open_count);
13193 open_exclu = 0;
13194
13195 spin_unlock(&mce_state_lock);
13196 @@ -2082,7 +2083,7 @@ struct dentry *mce_get_debugfs_dir(void)
13197 static void mce_reset(void)
13198 {
13199 cpu_missing = 0;
13200 - atomic_set(&mce_fake_paniced, 0);
13201 + atomic_set_unchecked(&mce_fake_paniced, 0);
13202 atomic_set(&mce_executing, 0);
13203 atomic_set(&mce_callin, 0);
13204 atomic_set(&global_nwo, 0);
13205 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce_amd.c linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce_amd.c
13206 --- linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce_amd.c 2011-05-23 16:56:59.000000000 -0400
13207 +++ linux-2.6.32.46/arch/x86/kernel/cpu/mcheck/mce_amd.c 2011-05-23 16:57:13.000000000 -0400
13208 @@ -385,7 +385,7 @@ static ssize_t store(struct kobject *kob
13209 return ret;
13210 }
13211
13212 -static struct sysfs_ops threshold_ops = {
13213 +static const struct sysfs_ops threshold_ops = {
13214 .show = show,
13215 .store = store,
13216 };
13217 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/amd.c linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/amd.c
13218 --- linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/amd.c 2011-03-27 14:31:47.000000000 -0400
13219 +++ linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/amd.c 2011-04-17 15:56:46.000000000 -0400
13220 @@ -108,7 +108,7 @@ amd_validate_add_page(unsigned long base
13221 return 0;
13222 }
13223
13224 -static struct mtrr_ops amd_mtrr_ops = {
13225 +static const struct mtrr_ops amd_mtrr_ops = {
13226 .vendor = X86_VENDOR_AMD,
13227 .set = amd_set_mtrr,
13228 .get = amd_get_mtrr,
13229 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/centaur.c linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/centaur.c
13230 --- linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/centaur.c 2011-03-27 14:31:47.000000000 -0400
13231 +++ linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/centaur.c 2011-04-17 15:56:46.000000000 -0400
13232 @@ -110,7 +110,7 @@ centaur_validate_add_page(unsigned long
13233 return 0;
13234 }
13235
13236 -static struct mtrr_ops centaur_mtrr_ops = {
13237 +static const struct mtrr_ops centaur_mtrr_ops = {
13238 .vendor = X86_VENDOR_CENTAUR,
13239 .set = centaur_set_mcr,
13240 .get = centaur_get_mcr,
13241 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/cyrix.c linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/cyrix.c
13242 --- linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/cyrix.c 2011-03-27 14:31:47.000000000 -0400
13243 +++ linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/cyrix.c 2011-04-17 15:56:46.000000000 -0400
13244 @@ -265,7 +265,7 @@ static void cyrix_set_all(void)
13245 post_set();
13246 }
13247
13248 -static struct mtrr_ops cyrix_mtrr_ops = {
13249 +static const struct mtrr_ops cyrix_mtrr_ops = {
13250 .vendor = X86_VENDOR_CYRIX,
13251 .set_all = cyrix_set_all,
13252 .set = cyrix_set_arr,
13253 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/generic.c linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/generic.c
13254 --- linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/generic.c 2011-03-27 14:31:47.000000000 -0400
13255 +++ linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/generic.c 2011-04-23 12:56:10.000000000 -0400
13256 @@ -752,7 +752,7 @@ int positive_have_wrcomb(void)
13257 /*
13258 * Generic structure...
13259 */
13260 -struct mtrr_ops generic_mtrr_ops = {
13261 +const struct mtrr_ops generic_mtrr_ops = {
13262 .use_intel_if = 1,
13263 .set_all = generic_set_all,
13264 .get = generic_get_mtrr,
13265 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/main.c linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/main.c
13266 --- linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/main.c 2011-04-17 17:00:52.000000000 -0400
13267 +++ linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/main.c 2011-04-17 17:03:05.000000000 -0400
13268 @@ -60,14 +60,14 @@ static DEFINE_MUTEX(mtrr_mutex);
13269 u64 size_or_mask, size_and_mask;
13270 static bool mtrr_aps_delayed_init;
13271
13272 -static struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13273 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13274
13275 -struct mtrr_ops *mtrr_if;
13276 +const struct mtrr_ops *mtrr_if;
13277
13278 static void set_mtrr(unsigned int reg, unsigned long base,
13279 unsigned long size, mtrr_type type);
13280
13281 -void set_mtrr_ops(struct mtrr_ops *ops)
13282 +void set_mtrr_ops(const struct mtrr_ops *ops)
13283 {
13284 if (ops->vendor && ops->vendor < X86_VENDOR_NUM)
13285 mtrr_ops[ops->vendor] = ops;
13286 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/mtrr.h linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/mtrr.h
13287 --- linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-03-27 14:31:47.000000000 -0400
13288 +++ linux-2.6.32.46/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-08-26 20:23:57.000000000 -0400
13289 @@ -25,14 +25,14 @@ struct mtrr_ops {
13290 int (*validate_add_page)(unsigned long base, unsigned long size,
13291 unsigned int type);
13292 int (*have_wrcomb)(void);
13293 -};
13294 +} __do_const;
13295
13296 extern int generic_get_free_region(unsigned long base, unsigned long size,
13297 int replace_reg);
13298 extern int generic_validate_add_page(unsigned long base, unsigned long size,
13299 unsigned int type);
13300
13301 -extern struct mtrr_ops generic_mtrr_ops;
13302 +extern const struct mtrr_ops generic_mtrr_ops;
13303
13304 extern int positive_have_wrcomb(void);
13305
13306 @@ -53,10 +53,10 @@ void fill_mtrr_var_range(unsigned int in
13307 u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
13308 void get_mtrr_state(void);
13309
13310 -extern void set_mtrr_ops(struct mtrr_ops *ops);
13311 +extern void set_mtrr_ops(const struct mtrr_ops *ops);
13312
13313 extern u64 size_or_mask, size_and_mask;
13314 -extern struct mtrr_ops *mtrr_if;
13315 +extern const struct mtrr_ops *mtrr_if;
13316
13317 #define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
13318 #define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1)
13319 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/perf_event.c linux-2.6.32.46/arch/x86/kernel/cpu/perf_event.c
13320 --- linux-2.6.32.46/arch/x86/kernel/cpu/perf_event.c 2011-03-27 14:31:47.000000000 -0400
13321 +++ linux-2.6.32.46/arch/x86/kernel/cpu/perf_event.c 2011-05-04 17:56:20.000000000 -0400
13322 @@ -723,10 +723,10 @@ x86_perf_event_update(struct perf_event
13323 * count to the generic event atomically:
13324 */
13325 again:
13326 - prev_raw_count = atomic64_read(&hwc->prev_count);
13327 + prev_raw_count = atomic64_read_unchecked(&hwc->prev_count);
13328 rdmsrl(hwc->event_base + idx, new_raw_count);
13329
13330 - if (atomic64_cmpxchg(&hwc->prev_count, prev_raw_count,
13331 + if (atomic64_cmpxchg_unchecked(&hwc->prev_count, prev_raw_count,
13332 new_raw_count) != prev_raw_count)
13333 goto again;
13334
13335 @@ -741,7 +741,7 @@ again:
13336 delta = (new_raw_count << shift) - (prev_raw_count << shift);
13337 delta >>= shift;
13338
13339 - atomic64_add(delta, &event->count);
13340 + atomic64_add_unchecked(delta, &event->count);
13341 atomic64_sub(delta, &hwc->period_left);
13342
13343 return new_raw_count;
13344 @@ -1353,7 +1353,7 @@ x86_perf_event_set_period(struct perf_ev
13345 * The hw event starts counting from this event offset,
13346 * mark it to be able to extra future deltas:
13347 */
13348 - atomic64_set(&hwc->prev_count, (u64)-left);
13349 + atomic64_set_unchecked(&hwc->prev_count, (u64)-left);
13350
13351 err = checking_wrmsrl(hwc->event_base + idx,
13352 (u64)(-left) & x86_pmu.event_mask);
13353 @@ -2357,7 +2357,7 @@ perf_callchain_user(struct pt_regs *regs
13354 break;
13355
13356 callchain_store(entry, frame.return_address);
13357 - fp = frame.next_frame;
13358 + fp = (__force const void __user *)frame.next_frame;
13359 }
13360 }
13361
13362 diff -urNp linux-2.6.32.46/arch/x86/kernel/cpu/perfctr-watchdog.c linux-2.6.32.46/arch/x86/kernel/cpu/perfctr-watchdog.c
13363 --- linux-2.6.32.46/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-03-27 14:31:47.000000000 -0400
13364 +++ linux-2.6.32.46/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-04-17 15:56:46.000000000 -0400
13365 @@ -30,11 +30,11 @@ struct nmi_watchdog_ctlblk {
13366
13367 /* Interface defining a CPU specific perfctr watchdog */
13368 struct wd_ops {
13369 - int (*reserve)(void);
13370 - void (*unreserve)(void);
13371 - int (*setup)(unsigned nmi_hz);
13372 - void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
13373 - void (*stop)(void);
13374 + int (* const reserve)(void);
13375 + void (* const unreserve)(void);
13376 + int (* const setup)(unsigned nmi_hz);
13377 + void (* const rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
13378 + void (* const stop)(void);
13379 unsigned perfctr;
13380 unsigned evntsel;
13381 u64 checkbit;
13382 @@ -645,6 +645,7 @@ static const struct wd_ops p4_wd_ops = {
13383 #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
13384 #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
13385
13386 +/* cannot be const */
13387 static struct wd_ops intel_arch_wd_ops;
13388
13389 static int setup_intel_arch_watchdog(unsigned nmi_hz)
13390 @@ -697,6 +698,7 @@ static int setup_intel_arch_watchdog(uns
13391 return 1;
13392 }
13393
13394 +/* cannot be const */
13395 static struct wd_ops intel_arch_wd_ops __read_mostly = {
13396 .reserve = single_msr_reserve,
13397 .unreserve = single_msr_unreserve,
13398 diff -urNp linux-2.6.32.46/arch/x86/kernel/crash.c linux-2.6.32.46/arch/x86/kernel/crash.c
13399 --- linux-2.6.32.46/arch/x86/kernel/crash.c 2011-03-27 14:31:47.000000000 -0400
13400 +++ linux-2.6.32.46/arch/x86/kernel/crash.c 2011-04-17 15:56:46.000000000 -0400
13401 @@ -41,7 +41,7 @@ static void kdump_nmi_callback(int cpu,
13402 regs = args->regs;
13403
13404 #ifdef CONFIG_X86_32
13405 - if (!user_mode_vm(regs)) {
13406 + if (!user_mode(regs)) {
13407 crash_fixup_ss_esp(&fixed_regs, regs);
13408 regs = &fixed_regs;
13409 }
13410 diff -urNp linux-2.6.32.46/arch/x86/kernel/doublefault_32.c linux-2.6.32.46/arch/x86/kernel/doublefault_32.c
13411 --- linux-2.6.32.46/arch/x86/kernel/doublefault_32.c 2011-03-27 14:31:47.000000000 -0400
13412 +++ linux-2.6.32.46/arch/x86/kernel/doublefault_32.c 2011-04-17 15:56:46.000000000 -0400
13413 @@ -11,7 +11,7 @@
13414
13415 #define DOUBLEFAULT_STACKSIZE (1024)
13416 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13417 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13418 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13419
13420 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13421
13422 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
13423 unsigned long gdt, tss;
13424
13425 store_gdt(&gdt_desc);
13426 - gdt = gdt_desc.address;
13427 + gdt = (unsigned long)gdt_desc.address;
13428
13429 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13430
13431 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
13432 /* 0x2 bit is always set */
13433 .flags = X86_EFLAGS_SF | 0x2,
13434 .sp = STACK_START,
13435 - .es = __USER_DS,
13436 + .es = __KERNEL_DS,
13437 .cs = __KERNEL_CS,
13438 .ss = __KERNEL_DS,
13439 - .ds = __USER_DS,
13440 + .ds = __KERNEL_DS,
13441 .fs = __KERNEL_PERCPU,
13442
13443 .__cr3 = __pa_nodebug(swapper_pg_dir),
13444 diff -urNp linux-2.6.32.46/arch/x86/kernel/dumpstack.c linux-2.6.32.46/arch/x86/kernel/dumpstack.c
13445 --- linux-2.6.32.46/arch/x86/kernel/dumpstack.c 2011-03-27 14:31:47.000000000 -0400
13446 +++ linux-2.6.32.46/arch/x86/kernel/dumpstack.c 2011-04-17 15:56:46.000000000 -0400
13447 @@ -2,6 +2,9 @@
13448 * Copyright (C) 1991, 1992 Linus Torvalds
13449 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13450 */
13451 +#ifdef CONFIG_GRKERNSEC_HIDESYM
13452 +#define __INCLUDED_BY_HIDESYM 1
13453 +#endif
13454 #include <linux/kallsyms.h>
13455 #include <linux/kprobes.h>
13456 #include <linux/uaccess.h>
13457 @@ -28,7 +31,7 @@ static int die_counter;
13458
13459 void printk_address(unsigned long address, int reliable)
13460 {
13461 - printk(" [<%p>] %s%pS\n", (void *) address,
13462 + printk(" [<%p>] %s%pA\n", (void *) address,
13463 reliable ? "" : "? ", (void *) address);
13464 }
13465
13466 @@ -36,9 +39,8 @@ void printk_address(unsigned long addres
13467 static void
13468 print_ftrace_graph_addr(unsigned long addr, void *data,
13469 const struct stacktrace_ops *ops,
13470 - struct thread_info *tinfo, int *graph)
13471 + struct task_struct *task, int *graph)
13472 {
13473 - struct task_struct *task = tinfo->task;
13474 unsigned long ret_addr;
13475 int index = task->curr_ret_stack;
13476
13477 @@ -59,7 +61,7 @@ print_ftrace_graph_addr(unsigned long ad
13478 static inline void
13479 print_ftrace_graph_addr(unsigned long addr, void *data,
13480 const struct stacktrace_ops *ops,
13481 - struct thread_info *tinfo, int *graph)
13482 + struct task_struct *task, int *graph)
13483 { }
13484 #endif
13485
13486 @@ -70,10 +72,8 @@ print_ftrace_graph_addr(unsigned long ad
13487 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13488 */
13489
13490 -static inline int valid_stack_ptr(struct thread_info *tinfo,
13491 - void *p, unsigned int size, void *end)
13492 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13493 {
13494 - void *t = tinfo;
13495 if (end) {
13496 if (p < end && p >= (end-THREAD_SIZE))
13497 return 1;
13498 @@ -84,14 +84,14 @@ static inline int valid_stack_ptr(struct
13499 }
13500
13501 unsigned long
13502 -print_context_stack(struct thread_info *tinfo,
13503 +print_context_stack(struct task_struct *task, void *stack_start,
13504 unsigned long *stack, unsigned long bp,
13505 const struct stacktrace_ops *ops, void *data,
13506 unsigned long *end, int *graph)
13507 {
13508 struct stack_frame *frame = (struct stack_frame *)bp;
13509
13510 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13511 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13512 unsigned long addr;
13513
13514 addr = *stack;
13515 @@ -103,7 +103,7 @@ print_context_stack(struct thread_info *
13516 } else {
13517 ops->address(data, addr, 0);
13518 }
13519 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13520 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13521 }
13522 stack++;
13523 }
13524 @@ -180,7 +180,7 @@ void dump_stack(void)
13525 #endif
13526
13527 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13528 - current->pid, current->comm, print_tainted(),
13529 + task_pid_nr(current), current->comm, print_tainted(),
13530 init_utsname()->release,
13531 (int)strcspn(init_utsname()->version, " "),
13532 init_utsname()->version);
13533 @@ -220,6 +220,8 @@ unsigned __kprobes long oops_begin(void)
13534 return flags;
13535 }
13536
13537 +extern void gr_handle_kernel_exploit(void);
13538 +
13539 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13540 {
13541 if (regs && kexec_should_crash(current))
13542 @@ -241,7 +243,10 @@ void __kprobes oops_end(unsigned long fl
13543 panic("Fatal exception in interrupt");
13544 if (panic_on_oops)
13545 panic("Fatal exception");
13546 - do_exit(signr);
13547 +
13548 + gr_handle_kernel_exploit();
13549 +
13550 + do_group_exit(signr);
13551 }
13552
13553 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13554 @@ -295,7 +300,7 @@ void die(const char *str, struct pt_regs
13555 unsigned long flags = oops_begin();
13556 int sig = SIGSEGV;
13557
13558 - if (!user_mode_vm(regs))
13559 + if (!user_mode(regs))
13560 report_bug(regs->ip, regs);
13561
13562 if (__die(str, regs, err))
13563 diff -urNp linux-2.6.32.46/arch/x86/kernel/dumpstack.h linux-2.6.32.46/arch/x86/kernel/dumpstack.h
13564 --- linux-2.6.32.46/arch/x86/kernel/dumpstack.h 2011-03-27 14:31:47.000000000 -0400
13565 +++ linux-2.6.32.46/arch/x86/kernel/dumpstack.h 2011-04-23 13:25:26.000000000 -0400
13566 @@ -15,7 +15,7 @@
13567 #endif
13568
13569 extern unsigned long
13570 -print_context_stack(struct thread_info *tinfo,
13571 +print_context_stack(struct task_struct *task, void *stack_start,
13572 unsigned long *stack, unsigned long bp,
13573 const struct stacktrace_ops *ops, void *data,
13574 unsigned long *end, int *graph);
13575 diff -urNp linux-2.6.32.46/arch/x86/kernel/dumpstack_32.c linux-2.6.32.46/arch/x86/kernel/dumpstack_32.c
13576 --- linux-2.6.32.46/arch/x86/kernel/dumpstack_32.c 2011-03-27 14:31:47.000000000 -0400
13577 +++ linux-2.6.32.46/arch/x86/kernel/dumpstack_32.c 2011-04-17 15:56:46.000000000 -0400
13578 @@ -53,16 +53,12 @@ void dump_trace(struct task_struct *task
13579 #endif
13580
13581 for (;;) {
13582 - struct thread_info *context;
13583 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13584 + bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13585
13586 - context = (struct thread_info *)
13587 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
13588 - bp = print_context_stack(context, stack, bp, ops,
13589 - data, NULL, &graph);
13590 -
13591 - stack = (unsigned long *)context->previous_esp;
13592 - if (!stack)
13593 + if (stack_start == task_stack_page(task))
13594 break;
13595 + stack = *(unsigned long **)stack_start;
13596 if (ops->stack(data, "IRQ") < 0)
13597 break;
13598 touch_nmi_watchdog();
13599 @@ -112,11 +108,12 @@ void show_registers(struct pt_regs *regs
13600 * When in-kernel, we also print out the stack and code at the
13601 * time of the fault..
13602 */
13603 - if (!user_mode_vm(regs)) {
13604 + if (!user_mode(regs)) {
13605 unsigned int code_prologue = code_bytes * 43 / 64;
13606 unsigned int code_len = code_bytes;
13607 unsigned char c;
13608 u8 *ip;
13609 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
13610
13611 printk(KERN_EMERG "Stack:\n");
13612 show_stack_log_lvl(NULL, regs, &regs->sp,
13613 @@ -124,10 +121,10 @@ void show_registers(struct pt_regs *regs
13614
13615 printk(KERN_EMERG "Code: ");
13616
13617 - ip = (u8 *)regs->ip - code_prologue;
13618 + ip = (u8 *)regs->ip - code_prologue + cs_base;
13619 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
13620 /* try starting at IP */
13621 - ip = (u8 *)regs->ip;
13622 + ip = (u8 *)regs->ip + cs_base;
13623 code_len = code_len - code_prologue + 1;
13624 }
13625 for (i = 0; i < code_len; i++, ip++) {
13626 @@ -136,7 +133,7 @@ void show_registers(struct pt_regs *regs
13627 printk(" Bad EIP value.");
13628 break;
13629 }
13630 - if (ip == (u8 *)regs->ip)
13631 + if (ip == (u8 *)regs->ip + cs_base)
13632 printk("<%02x> ", c);
13633 else
13634 printk("%02x ", c);
13635 @@ -149,6 +146,7 @@ int is_valid_bugaddr(unsigned long ip)
13636 {
13637 unsigned short ud2;
13638
13639 + ip = ktla_ktva(ip);
13640 if (ip < PAGE_OFFSET)
13641 return 0;
13642 if (probe_kernel_address((unsigned short *)ip, ud2))
13643 diff -urNp linux-2.6.32.46/arch/x86/kernel/dumpstack_64.c linux-2.6.32.46/arch/x86/kernel/dumpstack_64.c
13644 --- linux-2.6.32.46/arch/x86/kernel/dumpstack_64.c 2011-03-27 14:31:47.000000000 -0400
13645 +++ linux-2.6.32.46/arch/x86/kernel/dumpstack_64.c 2011-04-17 15:56:46.000000000 -0400
13646 @@ -116,8 +116,8 @@ void dump_trace(struct task_struct *task
13647 unsigned long *irq_stack_end =
13648 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
13649 unsigned used = 0;
13650 - struct thread_info *tinfo;
13651 int graph = 0;
13652 + void *stack_start;
13653
13654 if (!task)
13655 task = current;
13656 @@ -146,10 +146,10 @@ void dump_trace(struct task_struct *task
13657 * current stack address. If the stacks consist of nested
13658 * exceptions
13659 */
13660 - tinfo = task_thread_info(task);
13661 for (;;) {
13662 char *id;
13663 unsigned long *estack_end;
13664 +
13665 estack_end = in_exception_stack(cpu, (unsigned long)stack,
13666 &used, &id);
13667
13668 @@ -157,7 +157,7 @@ void dump_trace(struct task_struct *task
13669 if (ops->stack(data, id) < 0)
13670 break;
13671
13672 - bp = print_context_stack(tinfo, stack, bp, ops,
13673 + bp = print_context_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
13674 data, estack_end, &graph);
13675 ops->stack(data, "<EOE>");
13676 /*
13677 @@ -176,7 +176,7 @@ void dump_trace(struct task_struct *task
13678 if (stack >= irq_stack && stack < irq_stack_end) {
13679 if (ops->stack(data, "IRQ") < 0)
13680 break;
13681 - bp = print_context_stack(tinfo, stack, bp,
13682 + bp = print_context_stack(task, irq_stack, stack, bp,
13683 ops, data, irq_stack_end, &graph);
13684 /*
13685 * We link to the next stack (which would be
13686 @@ -195,7 +195,8 @@ void dump_trace(struct task_struct *task
13687 /*
13688 * This handles the process stack:
13689 */
13690 - bp = print_context_stack(tinfo, stack, bp, ops, data, NULL, &graph);
13691 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13692 + bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13693 put_cpu();
13694 }
13695 EXPORT_SYMBOL(dump_trace);
13696 diff -urNp linux-2.6.32.46/arch/x86/kernel/e820.c linux-2.6.32.46/arch/x86/kernel/e820.c
13697 --- linux-2.6.32.46/arch/x86/kernel/e820.c 2011-03-27 14:31:47.000000000 -0400
13698 +++ linux-2.6.32.46/arch/x86/kernel/e820.c 2011-04-17 15:56:46.000000000 -0400
13699 @@ -733,7 +733,7 @@ struct early_res {
13700 };
13701 static struct early_res early_res[MAX_EARLY_RES] __initdata = {
13702 { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */
13703 - {}
13704 + { 0, 0, {0}, 0 }
13705 };
13706
13707 static int __init find_overlapped_early(u64 start, u64 end)
13708 diff -urNp linux-2.6.32.46/arch/x86/kernel/early_printk.c linux-2.6.32.46/arch/x86/kernel/early_printk.c
13709 --- linux-2.6.32.46/arch/x86/kernel/early_printk.c 2011-03-27 14:31:47.000000000 -0400
13710 +++ linux-2.6.32.46/arch/x86/kernel/early_printk.c 2011-05-16 21:46:57.000000000 -0400
13711 @@ -7,6 +7,7 @@
13712 #include <linux/pci_regs.h>
13713 #include <linux/pci_ids.h>
13714 #include <linux/errno.h>
13715 +#include <linux/sched.h>
13716 #include <asm/io.h>
13717 #include <asm/processor.h>
13718 #include <asm/fcntl.h>
13719 @@ -170,6 +171,8 @@ asmlinkage void early_printk(const char
13720 int n;
13721 va_list ap;
13722
13723 + pax_track_stack();
13724 +
13725 va_start(ap, fmt);
13726 n = vscnprintf(buf, sizeof(buf), fmt, ap);
13727 early_console->write(early_console, buf, n);
13728 diff -urNp linux-2.6.32.46/arch/x86/kernel/efi_32.c linux-2.6.32.46/arch/x86/kernel/efi_32.c
13729 --- linux-2.6.32.46/arch/x86/kernel/efi_32.c 2011-03-27 14:31:47.000000000 -0400
13730 +++ linux-2.6.32.46/arch/x86/kernel/efi_32.c 2011-10-06 09:37:08.000000000 -0400
13731 @@ -38,70 +38,56 @@
13732 */
13733
13734 static unsigned long efi_rt_eflags;
13735 -static pgd_t efi_bak_pg_dir_pointer[2];
13736 +static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
13737
13738 -void efi_call_phys_prelog(void)
13739 +void __init efi_call_phys_prelog(void)
13740 {
13741 - unsigned long cr4;
13742 - unsigned long temp;
13743 struct desc_ptr gdt_descr;
13744
13745 - local_irq_save(efi_rt_eflags);
13746 +#ifdef CONFIG_PAX_KERNEXEC
13747 + struct desc_struct d;
13748 +#endif
13749
13750 - /*
13751 - * If I don't have PAE, I should just duplicate two entries in page
13752 - * directory. If I have PAE, I just need to duplicate one entry in
13753 - * page directory.
13754 - */
13755 - cr4 = read_cr4_safe();
13756 + local_irq_save(efi_rt_eflags);
13757
13758 - if (cr4 & X86_CR4_PAE) {
13759 - efi_bak_pg_dir_pointer[0].pgd =
13760 - swapper_pg_dir[pgd_index(0)].pgd;
13761 - swapper_pg_dir[0].pgd =
13762 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
13763 - } else {
13764 - efi_bak_pg_dir_pointer[0].pgd =
13765 - swapper_pg_dir[pgd_index(0)].pgd;
13766 - efi_bak_pg_dir_pointer[1].pgd =
13767 - swapper_pg_dir[pgd_index(0x400000)].pgd;
13768 - swapper_pg_dir[pgd_index(0)].pgd =
13769 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
13770 - temp = PAGE_OFFSET + 0x400000;
13771 - swapper_pg_dir[pgd_index(0x400000)].pgd =
13772 - swapper_pg_dir[pgd_index(temp)].pgd;
13773 - }
13774 + clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
13775 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
13776 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
13777
13778 /*
13779 * After the lock is released, the original page table is restored.
13780 */
13781 __flush_tlb_all();
13782
13783 +#ifdef CONFIG_PAX_KERNEXEC
13784 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
13785 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
13786 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
13787 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
13788 +#endif
13789 +
13790 gdt_descr.address = __pa(get_cpu_gdt_table(0));
13791 gdt_descr.size = GDT_SIZE - 1;
13792 load_gdt(&gdt_descr);
13793 }
13794
13795 -void efi_call_phys_epilog(void)
13796 +void __init efi_call_phys_epilog(void)
13797 {
13798 - unsigned long cr4;
13799 struct desc_ptr gdt_descr;
13800
13801 +#ifdef CONFIG_PAX_KERNEXEC
13802 + struct desc_struct d;
13803 +
13804 + memset(&d, 0, sizeof d);
13805 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
13806 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
13807 +#endif
13808 +
13809 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
13810 gdt_descr.size = GDT_SIZE - 1;
13811 load_gdt(&gdt_descr);
13812
13813 - cr4 = read_cr4_safe();
13814 -
13815 - if (cr4 & X86_CR4_PAE) {
13816 - swapper_pg_dir[pgd_index(0)].pgd =
13817 - efi_bak_pg_dir_pointer[0].pgd;
13818 - } else {
13819 - swapper_pg_dir[pgd_index(0)].pgd =
13820 - efi_bak_pg_dir_pointer[0].pgd;
13821 - swapper_pg_dir[pgd_index(0x400000)].pgd =
13822 - efi_bak_pg_dir_pointer[1].pgd;
13823 - }
13824 + clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
13825
13826 /*
13827 * After the lock is released, the original page table is restored.
13828 diff -urNp linux-2.6.32.46/arch/x86/kernel/efi_stub_32.S linux-2.6.32.46/arch/x86/kernel/efi_stub_32.S
13829 --- linux-2.6.32.46/arch/x86/kernel/efi_stub_32.S 2011-03-27 14:31:47.000000000 -0400
13830 +++ linux-2.6.32.46/arch/x86/kernel/efi_stub_32.S 2011-10-06 09:37:08.000000000 -0400
13831 @@ -6,7 +6,9 @@
13832 */
13833
13834 #include <linux/linkage.h>
13835 +#include <linux/init.h>
13836 #include <asm/page_types.h>
13837 +#include <asm/segment.h>
13838
13839 /*
13840 * efi_call_phys(void *, ...) is a function with variable parameters.
13841 @@ -20,7 +22,7 @@
13842 * service functions will comply with gcc calling convention, too.
13843 */
13844
13845 -.text
13846 +__INIT
13847 ENTRY(efi_call_phys)
13848 /*
13849 * 0. The function can only be called in Linux kernel. So CS has been
13850 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
13851 * The mapping of lower virtual memory has been created in prelog and
13852 * epilog.
13853 */
13854 - movl $1f, %edx
13855 - subl $__PAGE_OFFSET, %edx
13856 - jmp *%edx
13857 + movl $(__KERNEXEC_EFI_DS), %edx
13858 + mov %edx, %ds
13859 + mov %edx, %es
13860 + mov %edx, %ss
13861 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
13862 1:
13863
13864 /*
13865 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
13866 * parameter 2, ..., param n. To make things easy, we save the return
13867 * address of efi_call_phys in a global variable.
13868 */
13869 - popl %edx
13870 - movl %edx, saved_return_addr
13871 - /* get the function pointer into ECX*/
13872 - popl %ecx
13873 - movl %ecx, efi_rt_function_ptr
13874 - movl $2f, %edx
13875 - subl $__PAGE_OFFSET, %edx
13876 - pushl %edx
13877 + popl (saved_return_addr)
13878 + popl (efi_rt_function_ptr)
13879
13880 /*
13881 * 3. Clear PG bit in %CR0.
13882 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
13883 /*
13884 * 5. Call the physical function.
13885 */
13886 - jmp *%ecx
13887 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
13888
13889 -2:
13890 /*
13891 * 6. After EFI runtime service returns, control will return to
13892 * following instruction. We'd better readjust stack pointer first.
13893 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
13894 movl %cr0, %edx
13895 orl $0x80000000, %edx
13896 movl %edx, %cr0
13897 - jmp 1f
13898 -1:
13899 +
13900 /*
13901 * 8. Now restore the virtual mode from flat mode by
13902 * adding EIP with PAGE_OFFSET.
13903 */
13904 - movl $1f, %edx
13905 - jmp *%edx
13906 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
13907 1:
13908 + movl $(__KERNEL_DS), %edx
13909 + mov %edx, %ds
13910 + mov %edx, %es
13911 + mov %edx, %ss
13912
13913 /*
13914 * 9. Balance the stack. And because EAX contain the return value,
13915 * we'd better not clobber it.
13916 */
13917 - leal efi_rt_function_ptr, %edx
13918 - movl (%edx), %ecx
13919 - pushl %ecx
13920 + pushl (efi_rt_function_ptr)
13921
13922 /*
13923 - * 10. Push the saved return address onto the stack and return.
13924 + * 10. Return to the saved return address.
13925 */
13926 - leal saved_return_addr, %edx
13927 - movl (%edx), %ecx
13928 - pushl %ecx
13929 - ret
13930 + jmpl *(saved_return_addr)
13931 ENDPROC(efi_call_phys)
13932 .previous
13933
13934 -.data
13935 +__INITDATA
13936 saved_return_addr:
13937 .long 0
13938 efi_rt_function_ptr:
13939 diff -urNp linux-2.6.32.46/arch/x86/kernel/efi_stub_64.S linux-2.6.32.46/arch/x86/kernel/efi_stub_64.S
13940 --- linux-2.6.32.46/arch/x86/kernel/efi_stub_64.S 2011-03-27 14:31:47.000000000 -0400
13941 +++ linux-2.6.32.46/arch/x86/kernel/efi_stub_64.S 2011-10-06 09:37:14.000000000 -0400
13942 @@ -7,6 +7,7 @@
13943 */
13944
13945 #include <linux/linkage.h>
13946 +#include <asm/alternative-asm.h>
13947
13948 #define SAVE_XMM \
13949 mov %rsp, %rax; \
13950 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
13951 call *%rdi
13952 addq $32, %rsp
13953 RESTORE_XMM
13954 + pax_force_retaddr
13955 ret
13956 ENDPROC(efi_call0)
13957
13958 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
13959 call *%rdi
13960 addq $32, %rsp
13961 RESTORE_XMM
13962 + pax_force_retaddr
13963 ret
13964 ENDPROC(efi_call1)
13965
13966 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
13967 call *%rdi
13968 addq $32, %rsp
13969 RESTORE_XMM
13970 + pax_force_retaddr
13971 ret
13972 ENDPROC(efi_call2)
13973
13974 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
13975 call *%rdi
13976 addq $32, %rsp
13977 RESTORE_XMM
13978 + pax_force_retaddr
13979 ret
13980 ENDPROC(efi_call3)
13981
13982 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
13983 call *%rdi
13984 addq $32, %rsp
13985 RESTORE_XMM
13986 + pax_force_retaddr
13987 ret
13988 ENDPROC(efi_call4)
13989
13990 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
13991 call *%rdi
13992 addq $48, %rsp
13993 RESTORE_XMM
13994 + pax_force_retaddr
13995 ret
13996 ENDPROC(efi_call5)
13997
13998 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
13999 call *%rdi
14000 addq $48, %rsp
14001 RESTORE_XMM
14002 + pax_force_retaddr
14003 ret
14004 ENDPROC(efi_call6)
14005 diff -urNp linux-2.6.32.46/arch/x86/kernel/entry_32.S linux-2.6.32.46/arch/x86/kernel/entry_32.S
14006 --- linux-2.6.32.46/arch/x86/kernel/entry_32.S 2011-03-27 14:31:47.000000000 -0400
14007 +++ linux-2.6.32.46/arch/x86/kernel/entry_32.S 2011-08-30 18:19:52.000000000 -0400
14008 @@ -185,13 +185,146 @@
14009 /*CFI_REL_OFFSET gs, PT_GS*/
14010 .endm
14011 .macro SET_KERNEL_GS reg
14012 +
14013 +#ifdef CONFIG_CC_STACKPROTECTOR
14014 movl $(__KERNEL_STACK_CANARY), \reg
14015 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14016 + movl $(__USER_DS), \reg
14017 +#else
14018 + xorl \reg, \reg
14019 +#endif
14020 +
14021 movl \reg, %gs
14022 .endm
14023
14024 #endif /* CONFIG_X86_32_LAZY_GS */
14025
14026 -.macro SAVE_ALL
14027 +.macro pax_enter_kernel
14028 +#ifdef CONFIG_PAX_KERNEXEC
14029 + call pax_enter_kernel
14030 +#endif
14031 +.endm
14032 +
14033 +.macro pax_exit_kernel
14034 +#ifdef CONFIG_PAX_KERNEXEC
14035 + call pax_exit_kernel
14036 +#endif
14037 +.endm
14038 +
14039 +#ifdef CONFIG_PAX_KERNEXEC
14040 +ENTRY(pax_enter_kernel)
14041 +#ifdef CONFIG_PARAVIRT
14042 + pushl %eax
14043 + pushl %ecx
14044 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14045 + mov %eax, %esi
14046 +#else
14047 + mov %cr0, %esi
14048 +#endif
14049 + bts $16, %esi
14050 + jnc 1f
14051 + mov %cs, %esi
14052 + cmp $__KERNEL_CS, %esi
14053 + jz 3f
14054 + ljmp $__KERNEL_CS, $3f
14055 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14056 +2:
14057 +#ifdef CONFIG_PARAVIRT
14058 + mov %esi, %eax
14059 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14060 +#else
14061 + mov %esi, %cr0
14062 +#endif
14063 +3:
14064 +#ifdef CONFIG_PARAVIRT
14065 + popl %ecx
14066 + popl %eax
14067 +#endif
14068 + ret
14069 +ENDPROC(pax_enter_kernel)
14070 +
14071 +ENTRY(pax_exit_kernel)
14072 +#ifdef CONFIG_PARAVIRT
14073 + pushl %eax
14074 + pushl %ecx
14075 +#endif
14076 + mov %cs, %esi
14077 + cmp $__KERNEXEC_KERNEL_CS, %esi
14078 + jnz 2f
14079 +#ifdef CONFIG_PARAVIRT
14080 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14081 + mov %eax, %esi
14082 +#else
14083 + mov %cr0, %esi
14084 +#endif
14085 + btr $16, %esi
14086 + ljmp $__KERNEL_CS, $1f
14087 +1:
14088 +#ifdef CONFIG_PARAVIRT
14089 + mov %esi, %eax
14090 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14091 +#else
14092 + mov %esi, %cr0
14093 +#endif
14094 +2:
14095 +#ifdef CONFIG_PARAVIRT
14096 + popl %ecx
14097 + popl %eax
14098 +#endif
14099 + ret
14100 +ENDPROC(pax_exit_kernel)
14101 +#endif
14102 +
14103 +.macro pax_erase_kstack
14104 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14105 + call pax_erase_kstack
14106 +#endif
14107 +.endm
14108 +
14109 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14110 +/*
14111 + * ebp: thread_info
14112 + * ecx, edx: can be clobbered
14113 + */
14114 +ENTRY(pax_erase_kstack)
14115 + pushl %edi
14116 + pushl %eax
14117 +
14118 + mov TI_lowest_stack(%ebp), %edi
14119 + mov $-0xBEEF, %eax
14120 + std
14121 +
14122 +1: mov %edi, %ecx
14123 + and $THREAD_SIZE_asm - 1, %ecx
14124 + shr $2, %ecx
14125 + repne scasl
14126 + jecxz 2f
14127 +
14128 + cmp $2*16, %ecx
14129 + jc 2f
14130 +
14131 + mov $2*16, %ecx
14132 + repe scasl
14133 + jecxz 2f
14134 + jne 1b
14135 +
14136 +2: cld
14137 + mov %esp, %ecx
14138 + sub %edi, %ecx
14139 + shr $2, %ecx
14140 + rep stosl
14141 +
14142 + mov TI_task_thread_sp0(%ebp), %edi
14143 + sub $128, %edi
14144 + mov %edi, TI_lowest_stack(%ebp)
14145 +
14146 + popl %eax
14147 + popl %edi
14148 + ret
14149 +ENDPROC(pax_erase_kstack)
14150 +#endif
14151 +
14152 +.macro __SAVE_ALL _DS
14153 cld
14154 PUSH_GS
14155 pushl %fs
14156 @@ -224,7 +357,7 @@
14157 pushl %ebx
14158 CFI_ADJUST_CFA_OFFSET 4
14159 CFI_REL_OFFSET ebx, 0
14160 - movl $(__USER_DS), %edx
14161 + movl $\_DS, %edx
14162 movl %edx, %ds
14163 movl %edx, %es
14164 movl $(__KERNEL_PERCPU), %edx
14165 @@ -232,6 +365,15 @@
14166 SET_KERNEL_GS %edx
14167 .endm
14168
14169 +.macro SAVE_ALL
14170 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14171 + __SAVE_ALL __KERNEL_DS
14172 + pax_enter_kernel
14173 +#else
14174 + __SAVE_ALL __USER_DS
14175 +#endif
14176 +.endm
14177 +
14178 .macro RESTORE_INT_REGS
14179 popl %ebx
14180 CFI_ADJUST_CFA_OFFSET -4
14181 @@ -352,7 +494,15 @@ check_userspace:
14182 movb PT_CS(%esp), %al
14183 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
14184 cmpl $USER_RPL, %eax
14185 +
14186 +#ifdef CONFIG_PAX_KERNEXEC
14187 + jae resume_userspace
14188 +
14189 + PAX_EXIT_KERNEL
14190 + jmp resume_kernel
14191 +#else
14192 jb resume_kernel # not returning to v8086 or userspace
14193 +#endif
14194
14195 ENTRY(resume_userspace)
14196 LOCKDEP_SYS_EXIT
14197 @@ -364,7 +514,7 @@ ENTRY(resume_userspace)
14198 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14199 # int/exception return?
14200 jne work_pending
14201 - jmp restore_all
14202 + jmp restore_all_pax
14203 END(ret_from_exception)
14204
14205 #ifdef CONFIG_PREEMPT
14206 @@ -414,25 +564,36 @@ sysenter_past_esp:
14207 /*CFI_REL_OFFSET cs, 0*/
14208 /*
14209 * Push current_thread_info()->sysenter_return to the stack.
14210 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14211 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14212 */
14213 - pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
14214 + pushl $0
14215 CFI_ADJUST_CFA_OFFSET 4
14216 CFI_REL_OFFSET eip, 0
14217
14218 pushl %eax
14219 CFI_ADJUST_CFA_OFFSET 4
14220 SAVE_ALL
14221 + GET_THREAD_INFO(%ebp)
14222 + movl TI_sysenter_return(%ebp),%ebp
14223 + movl %ebp,PT_EIP(%esp)
14224 ENABLE_INTERRUPTS(CLBR_NONE)
14225
14226 /*
14227 * Load the potential sixth argument from user stack.
14228 * Careful about security.
14229 */
14230 + movl PT_OLDESP(%esp),%ebp
14231 +
14232 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14233 + mov PT_OLDSS(%esp),%ds
14234 +1: movl %ds:(%ebp),%ebp
14235 + push %ss
14236 + pop %ds
14237 +#else
14238 cmpl $__PAGE_OFFSET-3,%ebp
14239 jae syscall_fault
14240 1: movl (%ebp),%ebp
14241 +#endif
14242 +
14243 movl %ebp,PT_EBP(%esp)
14244 .section __ex_table,"a"
14245 .align 4
14246 @@ -455,12 +616,24 @@ sysenter_do_call:
14247 testl $_TIF_ALLWORK_MASK, %ecx
14248 jne sysexit_audit
14249 sysenter_exit:
14250 +
14251 +#ifdef CONFIG_PAX_RANDKSTACK
14252 + pushl_cfi %eax
14253 + movl %esp, %eax
14254 + call pax_randomize_kstack
14255 + popl_cfi %eax
14256 +#endif
14257 +
14258 + pax_erase_kstack
14259 +
14260 /* if something modifies registers it must also disable sysexit */
14261 movl PT_EIP(%esp), %edx
14262 movl PT_OLDESP(%esp), %ecx
14263 xorl %ebp,%ebp
14264 TRACE_IRQS_ON
14265 1: mov PT_FS(%esp), %fs
14266 +2: mov PT_DS(%esp), %ds
14267 +3: mov PT_ES(%esp), %es
14268 PTGS_TO_GS
14269 ENABLE_INTERRUPTS_SYSEXIT
14270
14271 @@ -477,6 +650,9 @@ sysenter_audit:
14272 movl %eax,%edx /* 2nd arg: syscall number */
14273 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14274 call audit_syscall_entry
14275 +
14276 + pax_erase_kstack
14277 +
14278 pushl %ebx
14279 CFI_ADJUST_CFA_OFFSET 4
14280 movl PT_EAX(%esp),%eax /* reload syscall number */
14281 @@ -504,11 +680,17 @@ sysexit_audit:
14282
14283 CFI_ENDPROC
14284 .pushsection .fixup,"ax"
14285 -2: movl $0,PT_FS(%esp)
14286 +4: movl $0,PT_FS(%esp)
14287 + jmp 1b
14288 +5: movl $0,PT_DS(%esp)
14289 + jmp 1b
14290 +6: movl $0,PT_ES(%esp)
14291 jmp 1b
14292 .section __ex_table,"a"
14293 .align 4
14294 - .long 1b,2b
14295 + .long 1b,4b
14296 + .long 2b,5b
14297 + .long 3b,6b
14298 .popsection
14299 PTGS_TO_GS_EX
14300 ENDPROC(ia32_sysenter_target)
14301 @@ -538,6 +720,15 @@ syscall_exit:
14302 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14303 jne syscall_exit_work
14304
14305 +restore_all_pax:
14306 +
14307 +#ifdef CONFIG_PAX_RANDKSTACK
14308 + movl %esp, %eax
14309 + call pax_randomize_kstack
14310 +#endif
14311 +
14312 + pax_erase_kstack
14313 +
14314 restore_all:
14315 TRACE_IRQS_IRET
14316 restore_all_notrace:
14317 @@ -602,10 +793,29 @@ ldt_ss:
14318 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14319 mov %dx, %ax /* eax: new kernel esp */
14320 sub %eax, %edx /* offset (low word is 0) */
14321 - PER_CPU(gdt_page, %ebx)
14322 +#ifdef CONFIG_SMP
14323 + movl PER_CPU_VAR(cpu_number), %ebx
14324 + shll $PAGE_SHIFT_asm, %ebx
14325 + addl $cpu_gdt_table, %ebx
14326 +#else
14327 + movl $cpu_gdt_table, %ebx
14328 +#endif
14329 shr $16, %edx
14330 +
14331 +#ifdef CONFIG_PAX_KERNEXEC
14332 + mov %cr0, %esi
14333 + btr $16, %esi
14334 + mov %esi, %cr0
14335 +#endif
14336 +
14337 mov %dl, GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx) /* bits 16..23 */
14338 mov %dh, GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx) /* bits 24..31 */
14339 +
14340 +#ifdef CONFIG_PAX_KERNEXEC
14341 + bts $16, %esi
14342 + mov %esi, %cr0
14343 +#endif
14344 +
14345 pushl $__ESPFIX_SS
14346 CFI_ADJUST_CFA_OFFSET 4
14347 push %eax /* new kernel esp */
14348 @@ -636,31 +846,25 @@ work_resched:
14349 movl TI_flags(%ebp), %ecx
14350 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14351 # than syscall tracing?
14352 - jz restore_all
14353 + jz restore_all_pax
14354 testb $_TIF_NEED_RESCHED, %cl
14355 jnz work_resched
14356
14357 work_notifysig: # deal with pending signals and
14358 # notify-resume requests
14359 + movl %esp, %eax
14360 #ifdef CONFIG_VM86
14361 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14362 - movl %esp, %eax
14363 - jne work_notifysig_v86 # returning to kernel-space or
14364 + jz 1f # returning to kernel-space or
14365 # vm86-space
14366 - xorl %edx, %edx
14367 - call do_notify_resume
14368 - jmp resume_userspace_sig
14369
14370 - ALIGN
14371 -work_notifysig_v86:
14372 pushl %ecx # save ti_flags for do_notify_resume
14373 CFI_ADJUST_CFA_OFFSET 4
14374 call save_v86_state # %eax contains pt_regs pointer
14375 popl %ecx
14376 CFI_ADJUST_CFA_OFFSET -4
14377 movl %eax, %esp
14378 -#else
14379 - movl %esp, %eax
14380 +1:
14381 #endif
14382 xorl %edx, %edx
14383 call do_notify_resume
14384 @@ -673,6 +877,9 @@ syscall_trace_entry:
14385 movl $-ENOSYS,PT_EAX(%esp)
14386 movl %esp, %eax
14387 call syscall_trace_enter
14388 +
14389 + pax_erase_kstack
14390 +
14391 /* What it returned is what we'll actually use. */
14392 cmpl $(nr_syscalls), %eax
14393 jnae syscall_call
14394 @@ -695,6 +902,10 @@ END(syscall_exit_work)
14395
14396 RING0_INT_FRAME # can't unwind into user space anyway
14397 syscall_fault:
14398 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14399 + push %ss
14400 + pop %ds
14401 +#endif
14402 GET_THREAD_INFO(%ebp)
14403 movl $-EFAULT,PT_EAX(%esp)
14404 jmp resume_userspace
14405 @@ -726,6 +937,33 @@ PTREGSCALL(rt_sigreturn)
14406 PTREGSCALL(vm86)
14407 PTREGSCALL(vm86old)
14408
14409 + ALIGN;
14410 +ENTRY(kernel_execve)
14411 + push %ebp
14412 + sub $PT_OLDSS+4,%esp
14413 + push %edi
14414 + push %ecx
14415 + push %eax
14416 + lea 3*4(%esp),%edi
14417 + mov $PT_OLDSS/4+1,%ecx
14418 + xorl %eax,%eax
14419 + rep stosl
14420 + pop %eax
14421 + pop %ecx
14422 + pop %edi
14423 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14424 + mov %eax,PT_EBX(%esp)
14425 + mov %edx,PT_ECX(%esp)
14426 + mov %ecx,PT_EDX(%esp)
14427 + mov %esp,%eax
14428 + call sys_execve
14429 + GET_THREAD_INFO(%ebp)
14430 + test %eax,%eax
14431 + jz syscall_exit
14432 + add $PT_OLDSS+4,%esp
14433 + pop %ebp
14434 + ret
14435 +
14436 .macro FIXUP_ESPFIX_STACK
14437 /*
14438 * Switch back for ESPFIX stack to the normal zerobased stack
14439 @@ -735,7 +973,13 @@ PTREGSCALL(vm86old)
14440 * normal stack and adjusts ESP with the matching offset.
14441 */
14442 /* fixup the stack */
14443 - PER_CPU(gdt_page, %ebx)
14444 +#ifdef CONFIG_SMP
14445 + movl PER_CPU_VAR(cpu_number), %ebx
14446 + shll $PAGE_SHIFT_asm, %ebx
14447 + addl $cpu_gdt_table, %ebx
14448 +#else
14449 + movl $cpu_gdt_table, %ebx
14450 +#endif
14451 mov GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx), %al /* bits 16..23 */
14452 mov GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx), %ah /* bits 24..31 */
14453 shl $16, %eax
14454 @@ -1198,7 +1442,6 @@ return_to_handler:
14455 ret
14456 #endif
14457
14458 -.section .rodata,"a"
14459 #include "syscall_table_32.S"
14460
14461 syscall_table_size=(.-sys_call_table)
14462 @@ -1255,9 +1498,12 @@ error_code:
14463 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
14464 REG_TO_PTGS %ecx
14465 SET_KERNEL_GS %ecx
14466 - movl $(__USER_DS), %ecx
14467 + movl $(__KERNEL_DS), %ecx
14468 movl %ecx, %ds
14469 movl %ecx, %es
14470 +
14471 + pax_enter_kernel
14472 +
14473 TRACE_IRQS_OFF
14474 movl %esp,%eax # pt_regs pointer
14475 call *%edi
14476 @@ -1351,6 +1597,9 @@ nmi_stack_correct:
14477 xorl %edx,%edx # zero error code
14478 movl %esp,%eax # pt_regs pointer
14479 call do_nmi
14480 +
14481 + pax_exit_kernel
14482 +
14483 jmp restore_all_notrace
14484 CFI_ENDPROC
14485
14486 @@ -1391,6 +1640,9 @@ nmi_espfix_stack:
14487 FIXUP_ESPFIX_STACK # %eax == %esp
14488 xorl %edx,%edx # zero error code
14489 call do_nmi
14490 +
14491 + pax_exit_kernel
14492 +
14493 RESTORE_REGS
14494 lss 12+4(%esp), %esp # back to espfix stack
14495 CFI_ADJUST_CFA_OFFSET -24
14496 diff -urNp linux-2.6.32.46/arch/x86/kernel/entry_64.S linux-2.6.32.46/arch/x86/kernel/entry_64.S
14497 --- linux-2.6.32.46/arch/x86/kernel/entry_64.S 2011-03-27 14:31:47.000000000 -0400
14498 +++ linux-2.6.32.46/arch/x86/kernel/entry_64.S 2011-10-08 08:14:37.000000000 -0400
14499 @@ -53,6 +53,8 @@
14500 #include <asm/paravirt.h>
14501 #include <asm/ftrace.h>
14502 #include <asm/percpu.h>
14503 +#include <asm/pgtable.h>
14504 +#include <asm/alternative-asm.h>
14505
14506 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14507 #include <linux/elf-em.h>
14508 @@ -64,6 +66,7 @@
14509 #ifdef CONFIG_FUNCTION_TRACER
14510 #ifdef CONFIG_DYNAMIC_FTRACE
14511 ENTRY(mcount)
14512 + pax_force_retaddr
14513 retq
14514 END(mcount)
14515
14516 @@ -88,6 +91,7 @@ GLOBAL(ftrace_graph_call)
14517 #endif
14518
14519 GLOBAL(ftrace_stub)
14520 + pax_force_retaddr
14521 retq
14522 END(ftrace_caller)
14523
14524 @@ -108,6 +112,7 @@ ENTRY(mcount)
14525 #endif
14526
14527 GLOBAL(ftrace_stub)
14528 + pax_force_retaddr
14529 retq
14530
14531 trace:
14532 @@ -117,6 +122,7 @@ trace:
14533 movq 8(%rbp), %rsi
14534 subq $MCOUNT_INSN_SIZE, %rdi
14535
14536 + pax_force_fptr ftrace_trace_function
14537 call *ftrace_trace_function
14538
14539 MCOUNT_RESTORE_FRAME
14540 @@ -142,6 +148,7 @@ ENTRY(ftrace_graph_caller)
14541
14542 MCOUNT_RESTORE_FRAME
14543
14544 + pax_force_retaddr
14545 retq
14546 END(ftrace_graph_caller)
14547
14548 @@ -159,6 +166,7 @@ GLOBAL(return_to_handler)
14549 movq 8(%rsp), %rdx
14550 movq (%rsp), %rax
14551 addq $16, %rsp
14552 + pax_force_retaddr
14553 retq
14554 #endif
14555
14556 @@ -174,6 +182,269 @@ ENTRY(native_usergs_sysret64)
14557 ENDPROC(native_usergs_sysret64)
14558 #endif /* CONFIG_PARAVIRT */
14559
14560 + .macro ljmpq sel, off
14561 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
14562 + .byte 0x48; ljmp *1234f(%rip)
14563 + .pushsection .rodata
14564 + .align 16
14565 + 1234: .quad \off; .word \sel
14566 + .popsection
14567 +#else
14568 + pushq $\sel
14569 + pushq $\off
14570 + lretq
14571 +#endif
14572 + .endm
14573 +
14574 + .macro pax_enter_kernel
14575 +#ifdef CONFIG_PAX_KERNEXEC
14576 + call pax_enter_kernel
14577 +#endif
14578 + .endm
14579 +
14580 + .macro pax_exit_kernel
14581 +#ifdef CONFIG_PAX_KERNEXEC
14582 + call pax_exit_kernel
14583 +#endif
14584 + .endm
14585 +
14586 +#ifdef CONFIG_PAX_KERNEXEC
14587 +ENTRY(pax_enter_kernel)
14588 + pushq %rdi
14589 +
14590 +#ifdef CONFIG_PARAVIRT
14591 + PV_SAVE_REGS(CLBR_RDI)
14592 +#endif
14593 +
14594 + GET_CR0_INTO_RDI
14595 + bts $16,%rdi
14596 + jnc 1f
14597 + mov %cs,%edi
14598 + cmp $__KERNEL_CS,%edi
14599 + jz 3f
14600 + ljmpq __KERNEL_CS,3f
14601 +1: ljmpq __KERNEXEC_KERNEL_CS,2f
14602 +2: SET_RDI_INTO_CR0
14603 +3:
14604 +
14605 +#ifdef CONFIG_PARAVIRT
14606 + PV_RESTORE_REGS(CLBR_RDI)
14607 +#endif
14608 +
14609 + popq %rdi
14610 + pax_force_retaddr
14611 + retq
14612 +ENDPROC(pax_enter_kernel)
14613 +
14614 +ENTRY(pax_exit_kernel)
14615 + pushq %rdi
14616 +
14617 +#ifdef CONFIG_PARAVIRT
14618 + PV_SAVE_REGS(CLBR_RDI)
14619 +#endif
14620 +
14621 + mov %cs,%rdi
14622 + cmp $__KERNEXEC_KERNEL_CS,%edi
14623 + jnz 2f
14624 + GET_CR0_INTO_RDI
14625 + btr $16,%rdi
14626 + ljmpq __KERNEL_CS,1f
14627 +1: SET_RDI_INTO_CR0
14628 +2:
14629 +
14630 +#ifdef CONFIG_PARAVIRT
14631 + PV_RESTORE_REGS(CLBR_RDI);
14632 +#endif
14633 +
14634 + popq %rdi
14635 + pax_force_retaddr
14636 + retq
14637 +ENDPROC(pax_exit_kernel)
14638 +#endif
14639 +
14640 + .macro pax_enter_kernel_user
14641 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14642 + call pax_enter_kernel_user
14643 +#endif
14644 + .endm
14645 +
14646 + .macro pax_exit_kernel_user
14647 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14648 + call pax_exit_kernel_user
14649 +#endif
14650 +#ifdef CONFIG_PAX_RANDKSTACK
14651 + push %rax
14652 + call pax_randomize_kstack
14653 + pop %rax
14654 +#endif
14655 + .endm
14656 +
14657 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14658 +ENTRY(pax_enter_kernel_user)
14659 + pushq %rdi
14660 + pushq %rbx
14661 +
14662 +#ifdef CONFIG_PARAVIRT
14663 + PV_SAVE_REGS(CLBR_RDI)
14664 +#endif
14665 +
14666 + GET_CR3_INTO_RDI
14667 + mov %rdi,%rbx
14668 + add $__START_KERNEL_map,%rbx
14669 + sub phys_base(%rip),%rbx
14670 +
14671 +#ifdef CONFIG_PARAVIRT
14672 + pushq %rdi
14673 + cmpl $0, pv_info+PARAVIRT_enabled
14674 + jz 1f
14675 + i = 0
14676 + .rept USER_PGD_PTRS
14677 + mov i*8(%rbx),%rsi
14678 + mov $0,%sil
14679 + lea i*8(%rbx),%rdi
14680 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
14681 + i = i + 1
14682 + .endr
14683 + jmp 2f
14684 +1:
14685 +#endif
14686 +
14687 + i = 0
14688 + .rept USER_PGD_PTRS
14689 + movb $0,i*8(%rbx)
14690 + i = i + 1
14691 + .endr
14692 +
14693 +#ifdef CONFIG_PARAVIRT
14694 +2: popq %rdi
14695 +#endif
14696 + SET_RDI_INTO_CR3
14697 +
14698 +#ifdef CONFIG_PAX_KERNEXEC
14699 + GET_CR0_INTO_RDI
14700 + bts $16,%rdi
14701 + SET_RDI_INTO_CR0
14702 +#endif
14703 +
14704 +#ifdef CONFIG_PARAVIRT
14705 + PV_RESTORE_REGS(CLBR_RDI)
14706 +#endif
14707 +
14708 + popq %rbx
14709 + popq %rdi
14710 + pax_force_retaddr
14711 + retq
14712 +ENDPROC(pax_enter_kernel_user)
14713 +
14714 +ENTRY(pax_exit_kernel_user)
14715 + push %rdi
14716 +
14717 +#ifdef CONFIG_PARAVIRT
14718 + pushq %rbx
14719 + PV_SAVE_REGS(CLBR_RDI)
14720 +#endif
14721 +
14722 +#ifdef CONFIG_PAX_KERNEXEC
14723 + GET_CR0_INTO_RDI
14724 + btr $16,%rdi
14725 + SET_RDI_INTO_CR0
14726 +#endif
14727 +
14728 + GET_CR3_INTO_RDI
14729 + add $__START_KERNEL_map,%rdi
14730 + sub phys_base(%rip),%rdi
14731 +
14732 +#ifdef CONFIG_PARAVIRT
14733 + cmpl $0, pv_info+PARAVIRT_enabled
14734 + jz 1f
14735 + mov %rdi,%rbx
14736 + i = 0
14737 + .rept USER_PGD_PTRS
14738 + mov i*8(%rbx),%rsi
14739 + mov $0x67,%sil
14740 + lea i*8(%rbx),%rdi
14741 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
14742 + i = i + 1
14743 + .endr
14744 + jmp 2f
14745 +1:
14746 +#endif
14747 +
14748 + i = 0
14749 + .rept USER_PGD_PTRS
14750 + movb $0x67,i*8(%rdi)
14751 + i = i + 1
14752 + .endr
14753 +
14754 +#ifdef CONFIG_PARAVIRT
14755 +2: PV_RESTORE_REGS(CLBR_RDI)
14756 + popq %rbx
14757 +#endif
14758 +
14759 + popq %rdi
14760 + pax_force_retaddr
14761 + retq
14762 +ENDPROC(pax_exit_kernel_user)
14763 +#endif
14764 +
14765 +.macro pax_erase_kstack
14766 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14767 + call pax_erase_kstack
14768 +#endif
14769 +.endm
14770 +
14771 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14772 +/*
14773 + * r10: thread_info
14774 + * rcx, rdx: can be clobbered
14775 + */
14776 +ENTRY(pax_erase_kstack)
14777 + pushq %rdi
14778 + pushq %rax
14779 + pushq %r10
14780 +
14781 + GET_THREAD_INFO(%r10)
14782 + mov TI_lowest_stack(%r10), %rdi
14783 + mov $-0xBEEF, %rax
14784 + std
14785 +
14786 +1: mov %edi, %ecx
14787 + and $THREAD_SIZE_asm - 1, %ecx
14788 + shr $3, %ecx
14789 + repne scasq
14790 + jecxz 2f
14791 +
14792 + cmp $2*8, %ecx
14793 + jc 2f
14794 +
14795 + mov $2*8, %ecx
14796 + repe scasq
14797 + jecxz 2f
14798 + jne 1b
14799 +
14800 +2: cld
14801 + mov %esp, %ecx
14802 + sub %edi, %ecx
14803 +
14804 + cmp $THREAD_SIZE_asm, %rcx
14805 + jb 3f
14806 + ud2
14807 +3:
14808 +
14809 + shr $3, %ecx
14810 + rep stosq
14811 +
14812 + mov TI_task_thread_sp0(%r10), %rdi
14813 + sub $256, %rdi
14814 + mov %rdi, TI_lowest_stack(%r10)
14815 +
14816 + popq %r10
14817 + popq %rax
14818 + popq %rdi
14819 + pax_force_retaddr
14820 + ret
14821 +ENDPROC(pax_erase_kstack)
14822 +#endif
14823
14824 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
14825 #ifdef CONFIG_TRACE_IRQFLAGS
14826 @@ -317,7 +588,7 @@ ENTRY(save_args)
14827 leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */
14828 movq_cfi rbp, 8 /* push %rbp */
14829 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
14830 - testl $3, CS(%rdi)
14831 + testb $3, CS(%rdi)
14832 je 1f
14833 SWAPGS
14834 /*
14835 @@ -337,6 +608,7 @@ ENTRY(save_args)
14836 * We entered an interrupt context - irqs are off:
14837 */
14838 2: TRACE_IRQS_OFF
14839 + pax_force_retaddr
14840 ret
14841 CFI_ENDPROC
14842 END(save_args)
14843 @@ -352,6 +624,7 @@ ENTRY(save_rest)
14844 movq_cfi r15, R15+16
14845 movq %r11, 8(%rsp) /* return address */
14846 FIXUP_TOP_OF_STACK %r11, 16
14847 + pax_force_retaddr
14848 ret
14849 CFI_ENDPROC
14850 END(save_rest)
14851 @@ -383,7 +656,8 @@ ENTRY(save_paranoid)
14852 js 1f /* negative -> in kernel */
14853 SWAPGS
14854 xorl %ebx,%ebx
14855 -1: ret
14856 +1: pax_force_retaddr
14857 + ret
14858 CFI_ENDPROC
14859 END(save_paranoid)
14860 .popsection
14861 @@ -409,7 +683,7 @@ ENTRY(ret_from_fork)
14862
14863 RESTORE_REST
14864
14865 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14866 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14867 je int_ret_from_sys_call
14868
14869 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
14870 @@ -455,7 +729,7 @@ END(ret_from_fork)
14871 ENTRY(system_call)
14872 CFI_STARTPROC simple
14873 CFI_SIGNAL_FRAME
14874 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14875 + CFI_DEF_CFA rsp,0
14876 CFI_REGISTER rip,rcx
14877 /*CFI_REGISTER rflags,r11*/
14878 SWAPGS_UNSAFE_STACK
14879 @@ -468,12 +742,13 @@ ENTRY(system_call_after_swapgs)
14880
14881 movq %rsp,PER_CPU_VAR(old_rsp)
14882 movq PER_CPU_VAR(kernel_stack),%rsp
14883 + pax_enter_kernel_user
14884 /*
14885 * No need to follow this irqs off/on section - it's straight
14886 * and short:
14887 */
14888 ENABLE_INTERRUPTS(CLBR_NONE)
14889 - SAVE_ARGS 8,1
14890 + SAVE_ARGS 8*6,1
14891 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14892 movq %rcx,RIP-ARGOFFSET(%rsp)
14893 CFI_REL_OFFSET rip,RIP-ARGOFFSET
14894 @@ -502,6 +777,8 @@ sysret_check:
14895 andl %edi,%edx
14896 jnz sysret_careful
14897 CFI_REMEMBER_STATE
14898 + pax_exit_kernel_user
14899 + pax_erase_kstack
14900 /*
14901 * sysretq will re-enable interrupts:
14902 */
14903 @@ -562,6 +839,9 @@ auditsys:
14904 movq %rax,%rsi /* 2nd arg: syscall number */
14905 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
14906 call audit_syscall_entry
14907 +
14908 + pax_erase_kstack
14909 +
14910 LOAD_ARGS 0 /* reload call-clobbered registers */
14911 jmp system_call_fastpath
14912
14913 @@ -592,6 +872,9 @@ tracesys:
14914 FIXUP_TOP_OF_STACK %rdi
14915 movq %rsp,%rdi
14916 call syscall_trace_enter
14917 +
14918 + pax_erase_kstack
14919 +
14920 /*
14921 * Reload arg registers from stack in case ptrace changed them.
14922 * We don't reload %rax because syscall_trace_enter() returned
14923 @@ -613,7 +896,7 @@ tracesys:
14924 GLOBAL(int_ret_from_sys_call)
14925 DISABLE_INTERRUPTS(CLBR_NONE)
14926 TRACE_IRQS_OFF
14927 - testl $3,CS-ARGOFFSET(%rsp)
14928 + testb $3,CS-ARGOFFSET(%rsp)
14929 je retint_restore_args
14930 movl $_TIF_ALLWORK_MASK,%edi
14931 /* edi: mask to check */
14932 @@ -708,6 +991,7 @@ ENTRY(ptregscall_common)
14933 movq_cfi_restore R12+8, r12
14934 movq_cfi_restore RBP+8, rbp
14935 movq_cfi_restore RBX+8, rbx
14936 + pax_force_retaddr
14937 ret $REST_SKIP /* pop extended registers */
14938 CFI_ENDPROC
14939 END(ptregscall_common)
14940 @@ -800,6 +1084,16 @@ END(interrupt)
14941 CFI_ADJUST_CFA_OFFSET 10*8
14942 call save_args
14943 PARTIAL_FRAME 0
14944 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14945 + testb $3, CS(%rdi)
14946 + jnz 1f
14947 + pax_enter_kernel
14948 + jmp 2f
14949 +1: pax_enter_kernel_user
14950 +2:
14951 +#else
14952 + pax_enter_kernel
14953 +#endif
14954 call \func
14955 .endm
14956
14957 @@ -822,7 +1116,7 @@ ret_from_intr:
14958 CFI_ADJUST_CFA_OFFSET -8
14959 exit_intr:
14960 GET_THREAD_INFO(%rcx)
14961 - testl $3,CS-ARGOFFSET(%rsp)
14962 + testb $3,CS-ARGOFFSET(%rsp)
14963 je retint_kernel
14964
14965 /* Interrupt came from user space */
14966 @@ -844,12 +1138,16 @@ retint_swapgs: /* return to user-space
14967 * The iretq could re-enable interrupts:
14968 */
14969 DISABLE_INTERRUPTS(CLBR_ANY)
14970 + pax_exit_kernel_user
14971 + pax_erase_kstack
14972 TRACE_IRQS_IRETQ
14973 SWAPGS
14974 jmp restore_args
14975
14976 retint_restore_args: /* return to kernel space */
14977 DISABLE_INTERRUPTS(CLBR_ANY)
14978 + pax_exit_kernel
14979 + pax_force_retaddr RIP-ARGOFFSET
14980 /*
14981 * The iretq could re-enable interrupts:
14982 */
14983 @@ -1032,6 +1330,16 @@ ENTRY(\sym)
14984 CFI_ADJUST_CFA_OFFSET 15*8
14985 call error_entry
14986 DEFAULT_FRAME 0
14987 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14988 + testb $3, CS(%rsp)
14989 + jnz 1f
14990 + pax_enter_kernel
14991 + jmp 2f
14992 +1: pax_enter_kernel_user
14993 +2:
14994 +#else
14995 + pax_enter_kernel
14996 +#endif
14997 movq %rsp,%rdi /* pt_regs pointer */
14998 xorl %esi,%esi /* no error code */
14999 call \do_sym
15000 @@ -1049,6 +1357,16 @@ ENTRY(\sym)
15001 subq $15*8, %rsp
15002 call save_paranoid
15003 TRACE_IRQS_OFF
15004 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15005 + testb $3, CS(%rsp)
15006 + jnz 1f
15007 + pax_enter_kernel
15008 + jmp 2f
15009 +1: pax_enter_kernel_user
15010 +2:
15011 +#else
15012 + pax_enter_kernel
15013 +#endif
15014 movq %rsp,%rdi /* pt_regs pointer */
15015 xorl %esi,%esi /* no error code */
15016 call \do_sym
15017 @@ -1066,9 +1384,24 @@ ENTRY(\sym)
15018 subq $15*8, %rsp
15019 call save_paranoid
15020 TRACE_IRQS_OFF
15021 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15022 + testb $3, CS(%rsp)
15023 + jnz 1f
15024 + pax_enter_kernel
15025 + jmp 2f
15026 +1: pax_enter_kernel_user
15027 +2:
15028 +#else
15029 + pax_enter_kernel
15030 +#endif
15031 movq %rsp,%rdi /* pt_regs pointer */
15032 xorl %esi,%esi /* no error code */
15033 - PER_CPU(init_tss, %rbp)
15034 +#ifdef CONFIG_SMP
15035 + imul $TSS_size, PER_CPU_VAR(cpu_number), %ebp
15036 + lea init_tss(%rbp), %rbp
15037 +#else
15038 + lea init_tss(%rip), %rbp
15039 +#endif
15040 subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
15041 call \do_sym
15042 addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
15043 @@ -1085,6 +1418,16 @@ ENTRY(\sym)
15044 CFI_ADJUST_CFA_OFFSET 15*8
15045 call error_entry
15046 DEFAULT_FRAME 0
15047 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15048 + testb $3, CS(%rsp)
15049 + jnz 1f
15050 + pax_enter_kernel
15051 + jmp 2f
15052 +1: pax_enter_kernel_user
15053 +2:
15054 +#else
15055 + pax_enter_kernel
15056 +#endif
15057 movq %rsp,%rdi /* pt_regs pointer */
15058 movq ORIG_RAX(%rsp),%rsi /* get error code */
15059 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15060 @@ -1104,6 +1447,16 @@ ENTRY(\sym)
15061 call save_paranoid
15062 DEFAULT_FRAME 0
15063 TRACE_IRQS_OFF
15064 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15065 + testb $3, CS(%rsp)
15066 + jnz 1f
15067 + pax_enter_kernel
15068 + jmp 2f
15069 +1: pax_enter_kernel_user
15070 +2:
15071 +#else
15072 + pax_enter_kernel
15073 +#endif
15074 movq %rsp,%rdi /* pt_regs pointer */
15075 movq ORIG_RAX(%rsp),%rsi /* get error code */
15076 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15077 @@ -1141,6 +1494,7 @@ gs_change:
15078 SWAPGS
15079 popf
15080 CFI_ADJUST_CFA_OFFSET -8
15081 + pax_force_retaddr
15082 ret
15083 CFI_ENDPROC
15084 END(native_load_gs_index)
15085 @@ -1195,6 +1549,7 @@ ENTRY(kernel_thread)
15086 */
15087 RESTORE_ALL
15088 UNFAKE_STACK_FRAME
15089 + pax_force_retaddr
15090 ret
15091 CFI_ENDPROC
15092 END(kernel_thread)
15093 @@ -1208,6 +1563,7 @@ ENTRY(child_rip)
15094 */
15095 movq %rdi, %rax
15096 movq %rsi, %rdi
15097 + pax_force_fptr %rax
15098 call *%rax
15099 # exit
15100 mov %eax, %edi
15101 @@ -1243,6 +1599,7 @@ ENTRY(kernel_execve)
15102 je int_ret_from_sys_call
15103 RESTORE_ARGS
15104 UNFAKE_STACK_FRAME
15105 + pax_force_retaddr
15106 ret
15107 CFI_ENDPROC
15108 END(kernel_execve)
15109 @@ -1263,6 +1620,7 @@ ENTRY(call_softirq)
15110 CFI_DEF_CFA_REGISTER rsp
15111 CFI_ADJUST_CFA_OFFSET -8
15112 decl PER_CPU_VAR(irq_count)
15113 + pax_force_retaddr
15114 ret
15115 CFI_ENDPROC
15116 END(call_softirq)
15117 @@ -1405,16 +1763,31 @@ ENTRY(paranoid_exit)
15118 TRACE_IRQS_OFF
15119 testl %ebx,%ebx /* swapgs needed? */
15120 jnz paranoid_restore
15121 - testl $3,CS(%rsp)
15122 + testb $3,CS(%rsp)
15123 jnz paranoid_userspace
15124 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15125 + pax_exit_kernel
15126 + TRACE_IRQS_IRETQ 0
15127 + SWAPGS_UNSAFE_STACK
15128 + RESTORE_ALL 8
15129 + pax_force_retaddr
15130 + jmp irq_return
15131 +#endif
15132 paranoid_swapgs:
15133 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15134 + pax_exit_kernel_user
15135 +#else
15136 + pax_exit_kernel
15137 +#endif
15138 TRACE_IRQS_IRETQ 0
15139 SWAPGS_UNSAFE_STACK
15140 RESTORE_ALL 8
15141 jmp irq_return
15142 paranoid_restore:
15143 + pax_exit_kernel
15144 TRACE_IRQS_IRETQ 0
15145 RESTORE_ALL 8
15146 + pax_force_retaddr
15147 jmp irq_return
15148 paranoid_userspace:
15149 GET_THREAD_INFO(%rcx)
15150 @@ -1470,12 +1843,13 @@ ENTRY(error_entry)
15151 movq_cfi r14, R14+8
15152 movq_cfi r15, R15+8
15153 xorl %ebx,%ebx
15154 - testl $3,CS+8(%rsp)
15155 + testb $3,CS+8(%rsp)
15156 je error_kernelspace
15157 error_swapgs:
15158 SWAPGS
15159 error_sti:
15160 TRACE_IRQS_OFF
15161 + pax_force_retaddr
15162 ret
15163 CFI_ENDPROC
15164
15165 @@ -1529,6 +1903,16 @@ ENTRY(nmi)
15166 CFI_ADJUST_CFA_OFFSET 15*8
15167 call save_paranoid
15168 DEFAULT_FRAME 0
15169 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15170 + testb $3, CS(%rsp)
15171 + jnz 1f
15172 + pax_enter_kernel
15173 + jmp 2f
15174 +1: pax_enter_kernel_user
15175 +2:
15176 +#else
15177 + pax_enter_kernel
15178 +#endif
15179 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
15180 movq %rsp,%rdi
15181 movq $-1,%rsi
15182 @@ -1539,12 +1923,28 @@ ENTRY(nmi)
15183 DISABLE_INTERRUPTS(CLBR_NONE)
15184 testl %ebx,%ebx /* swapgs needed? */
15185 jnz nmi_restore
15186 - testl $3,CS(%rsp)
15187 + testb $3,CS(%rsp)
15188 jnz nmi_userspace
15189 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15190 + pax_exit_kernel
15191 + SWAPGS_UNSAFE_STACK
15192 + RESTORE_ALL 8
15193 + pax_force_retaddr
15194 + jmp irq_return
15195 +#endif
15196 nmi_swapgs:
15197 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15198 + pax_exit_kernel_user
15199 +#else
15200 + pax_exit_kernel
15201 +#endif
15202 SWAPGS_UNSAFE_STACK
15203 + RESTORE_ALL 8
15204 + jmp irq_return
15205 nmi_restore:
15206 + pax_exit_kernel
15207 RESTORE_ALL 8
15208 + pax_force_retaddr
15209 jmp irq_return
15210 nmi_userspace:
15211 GET_THREAD_INFO(%rcx)
15212 diff -urNp linux-2.6.32.46/arch/x86/kernel/ftrace.c linux-2.6.32.46/arch/x86/kernel/ftrace.c
15213 --- linux-2.6.32.46/arch/x86/kernel/ftrace.c 2011-03-27 14:31:47.000000000 -0400
15214 +++ linux-2.6.32.46/arch/x86/kernel/ftrace.c 2011-05-04 17:56:20.000000000 -0400
15215 @@ -103,7 +103,7 @@ static void *mod_code_ip; /* holds the
15216 static void *mod_code_newcode; /* holds the text to write to the IP */
15217
15218 static unsigned nmi_wait_count;
15219 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
15220 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
15221
15222 int ftrace_arch_read_dyn_info(char *buf, int size)
15223 {
15224 @@ -111,7 +111,7 @@ int ftrace_arch_read_dyn_info(char *buf,
15225
15226 r = snprintf(buf, size, "%u %u",
15227 nmi_wait_count,
15228 - atomic_read(&nmi_update_count));
15229 + atomic_read_unchecked(&nmi_update_count));
15230 return r;
15231 }
15232
15233 @@ -149,8 +149,10 @@ void ftrace_nmi_enter(void)
15234 {
15235 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
15236 smp_rmb();
15237 + pax_open_kernel();
15238 ftrace_mod_code();
15239 - atomic_inc(&nmi_update_count);
15240 + pax_close_kernel();
15241 + atomic_inc_unchecked(&nmi_update_count);
15242 }
15243 /* Must have previous changes seen before executions */
15244 smp_mb();
15245 @@ -215,7 +217,7 @@ do_ftrace_mod_code(unsigned long ip, voi
15246
15247
15248
15249 -static unsigned char ftrace_nop[MCOUNT_INSN_SIZE];
15250 +static unsigned char ftrace_nop[MCOUNT_INSN_SIZE] __read_only;
15251
15252 static unsigned char *ftrace_nop_replace(void)
15253 {
15254 @@ -228,6 +230,8 @@ ftrace_modify_code(unsigned long ip, uns
15255 {
15256 unsigned char replaced[MCOUNT_INSN_SIZE];
15257
15258 + ip = ktla_ktva(ip);
15259 +
15260 /*
15261 * Note: Due to modules and __init, code can
15262 * disappear and change, we need to protect against faulting
15263 @@ -284,7 +288,7 @@ int ftrace_update_ftrace_func(ftrace_fun
15264 unsigned char old[MCOUNT_INSN_SIZE], *new;
15265 int ret;
15266
15267 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
15268 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
15269 new = ftrace_call_replace(ip, (unsigned long)func);
15270 ret = ftrace_modify_code(ip, old, new);
15271
15272 @@ -337,15 +341,15 @@ int __init ftrace_dyn_arch_init(void *da
15273 switch (faulted) {
15274 case 0:
15275 pr_info("ftrace: converting mcount calls to 0f 1f 44 00 00\n");
15276 - memcpy(ftrace_nop, ftrace_test_p6nop, MCOUNT_INSN_SIZE);
15277 + memcpy(ftrace_nop, ktla_ktva(ftrace_test_p6nop), MCOUNT_INSN_SIZE);
15278 break;
15279 case 1:
15280 pr_info("ftrace: converting mcount calls to 66 66 66 66 90\n");
15281 - memcpy(ftrace_nop, ftrace_test_nop5, MCOUNT_INSN_SIZE);
15282 + memcpy(ftrace_nop, ktla_ktva(ftrace_test_nop5), MCOUNT_INSN_SIZE);
15283 break;
15284 case 2:
15285 pr_info("ftrace: converting mcount calls to jmp . + 5\n");
15286 - memcpy(ftrace_nop, ftrace_test_jmp, MCOUNT_INSN_SIZE);
15287 + memcpy(ftrace_nop, ktla_ktva(ftrace_test_jmp), MCOUNT_INSN_SIZE);
15288 break;
15289 }
15290
15291 @@ -366,6 +370,8 @@ static int ftrace_mod_jmp(unsigned long
15292 {
15293 unsigned char code[MCOUNT_INSN_SIZE];
15294
15295 + ip = ktla_ktva(ip);
15296 +
15297 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
15298 return -EFAULT;
15299
15300 diff -urNp linux-2.6.32.46/arch/x86/kernel/head32.c linux-2.6.32.46/arch/x86/kernel/head32.c
15301 --- linux-2.6.32.46/arch/x86/kernel/head32.c 2011-03-27 14:31:47.000000000 -0400
15302 +++ linux-2.6.32.46/arch/x86/kernel/head32.c 2011-04-17 15:56:46.000000000 -0400
15303 @@ -16,6 +16,7 @@
15304 #include <asm/apic.h>
15305 #include <asm/io_apic.h>
15306 #include <asm/bios_ebda.h>
15307 +#include <asm/boot.h>
15308
15309 static void __init i386_default_early_setup(void)
15310 {
15311 @@ -31,7 +32,7 @@ void __init i386_start_kernel(void)
15312 {
15313 reserve_trampoline_memory();
15314
15315 - reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
15316 + reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
15317
15318 #ifdef CONFIG_BLK_DEV_INITRD
15319 /* Reserve INITRD */
15320 diff -urNp linux-2.6.32.46/arch/x86/kernel/head_32.S linux-2.6.32.46/arch/x86/kernel/head_32.S
15321 --- linux-2.6.32.46/arch/x86/kernel/head_32.S 2011-03-27 14:31:47.000000000 -0400
15322 +++ linux-2.6.32.46/arch/x86/kernel/head_32.S 2011-07-06 19:53:33.000000000 -0400
15323 @@ -19,10 +19,17 @@
15324 #include <asm/setup.h>
15325 #include <asm/processor-flags.h>
15326 #include <asm/percpu.h>
15327 +#include <asm/msr-index.h>
15328
15329 /* Physical address */
15330 #define pa(X) ((X) - __PAGE_OFFSET)
15331
15332 +#ifdef CONFIG_PAX_KERNEXEC
15333 +#define ta(X) (X)
15334 +#else
15335 +#define ta(X) ((X) - __PAGE_OFFSET)
15336 +#endif
15337 +
15338 /*
15339 * References to members of the new_cpu_data structure.
15340 */
15341 @@ -52,11 +59,7 @@
15342 * and small than max_low_pfn, otherwise will waste some page table entries
15343 */
15344
15345 -#if PTRS_PER_PMD > 1
15346 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
15347 -#else
15348 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
15349 -#endif
15350 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
15351
15352 /* Enough space to fit pagetables for the low memory linear map */
15353 MAPPING_BEYOND_END = \
15354 @@ -73,6 +76,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
15355 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
15356
15357 /*
15358 + * Real beginning of normal "text" segment
15359 + */
15360 +ENTRY(stext)
15361 +ENTRY(_stext)
15362 +
15363 +/*
15364 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
15365 * %esi points to the real-mode code as a 32-bit pointer.
15366 * CS and DS must be 4 GB flat segments, but we don't depend on
15367 @@ -80,7 +89,16 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
15368 * can.
15369 */
15370 __HEAD
15371 +
15372 +#ifdef CONFIG_PAX_KERNEXEC
15373 + jmp startup_32
15374 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
15375 +.fill PAGE_SIZE-5,1,0xcc
15376 +#endif
15377 +
15378 ENTRY(startup_32)
15379 + movl pa(stack_start),%ecx
15380 +
15381 /* test KEEP_SEGMENTS flag to see if the bootloader is asking
15382 us to not reload segments */
15383 testb $(1<<6), BP_loadflags(%esi)
15384 @@ -95,7 +113,60 @@ ENTRY(startup_32)
15385 movl %eax,%es
15386 movl %eax,%fs
15387 movl %eax,%gs
15388 + movl %eax,%ss
15389 2:
15390 + leal -__PAGE_OFFSET(%ecx),%esp
15391 +
15392 +#ifdef CONFIG_SMP
15393 + movl $pa(cpu_gdt_table),%edi
15394 + movl $__per_cpu_load,%eax
15395 + movw %ax,__KERNEL_PERCPU + 2(%edi)
15396 + rorl $16,%eax
15397 + movb %al,__KERNEL_PERCPU + 4(%edi)
15398 + movb %ah,__KERNEL_PERCPU + 7(%edi)
15399 + movl $__per_cpu_end - 1,%eax
15400 + subl $__per_cpu_start,%eax
15401 + movw %ax,__KERNEL_PERCPU + 0(%edi)
15402 +#endif
15403 +
15404 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15405 + movl $NR_CPUS,%ecx
15406 + movl $pa(cpu_gdt_table),%edi
15407 +1:
15408 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
15409 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
15410 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
15411 + addl $PAGE_SIZE_asm,%edi
15412 + loop 1b
15413 +#endif
15414 +
15415 +#ifdef CONFIG_PAX_KERNEXEC
15416 + movl $pa(boot_gdt),%edi
15417 + movl $__LOAD_PHYSICAL_ADDR,%eax
15418 + movw %ax,__BOOT_CS + 2(%edi)
15419 + rorl $16,%eax
15420 + movb %al,__BOOT_CS + 4(%edi)
15421 + movb %ah,__BOOT_CS + 7(%edi)
15422 + rorl $16,%eax
15423 +
15424 + ljmp $(__BOOT_CS),$1f
15425 +1:
15426 +
15427 + movl $NR_CPUS,%ecx
15428 + movl $pa(cpu_gdt_table),%edi
15429 + addl $__PAGE_OFFSET,%eax
15430 +1:
15431 + movw %ax,__KERNEL_CS + 2(%edi)
15432 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
15433 + rorl $16,%eax
15434 + movb %al,__KERNEL_CS + 4(%edi)
15435 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
15436 + movb %ah,__KERNEL_CS + 7(%edi)
15437 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
15438 + rorl $16,%eax
15439 + addl $PAGE_SIZE_asm,%edi
15440 + loop 1b
15441 +#endif
15442
15443 /*
15444 * Clear BSS first so that there are no surprises...
15445 @@ -140,9 +211,7 @@ ENTRY(startup_32)
15446 cmpl $num_subarch_entries, %eax
15447 jae bad_subarch
15448
15449 - movl pa(subarch_entries)(,%eax,4), %eax
15450 - subl $__PAGE_OFFSET, %eax
15451 - jmp *%eax
15452 + jmp *pa(subarch_entries)(,%eax,4)
15453
15454 bad_subarch:
15455 WEAK(lguest_entry)
15456 @@ -154,10 +223,10 @@ WEAK(xen_entry)
15457 __INITDATA
15458
15459 subarch_entries:
15460 - .long default_entry /* normal x86/PC */
15461 - .long lguest_entry /* lguest hypervisor */
15462 - .long xen_entry /* Xen hypervisor */
15463 - .long default_entry /* Moorestown MID */
15464 + .long ta(default_entry) /* normal x86/PC */
15465 + .long ta(lguest_entry) /* lguest hypervisor */
15466 + .long ta(xen_entry) /* Xen hypervisor */
15467 + .long ta(default_entry) /* Moorestown MID */
15468 num_subarch_entries = (. - subarch_entries) / 4
15469 .previous
15470 #endif /* CONFIG_PARAVIRT */
15471 @@ -218,8 +287,11 @@ default_entry:
15472 movl %eax, pa(max_pfn_mapped)
15473
15474 /* Do early initialization of the fixmap area */
15475 - movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
15476 - movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
15477 +#ifdef CONFIG_COMPAT_VDSO
15478 + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_pmd+0x1000*KPMDS-8)
15479 +#else
15480 + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
15481 +#endif
15482 #else /* Not PAE */
15483
15484 page_pde_offset = (__PAGE_OFFSET >> 20);
15485 @@ -249,8 +321,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
15486 movl %eax, pa(max_pfn_mapped)
15487
15488 /* Do early initialization of the fixmap area */
15489 - movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
15490 - movl %eax,pa(swapper_pg_dir+0xffc)
15491 +#ifdef CONFIG_COMPAT_VDSO
15492 + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_dir+0xffc)
15493 +#else
15494 + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_dir+0xffc)
15495 +#endif
15496 #endif
15497 jmp 3f
15498 /*
15499 @@ -272,6 +347,9 @@ ENTRY(startup_32_smp)
15500 movl %eax,%es
15501 movl %eax,%fs
15502 movl %eax,%gs
15503 + movl pa(stack_start),%ecx
15504 + movl %eax,%ss
15505 + leal -__PAGE_OFFSET(%ecx),%esp
15506 #endif /* CONFIG_SMP */
15507 3:
15508
15509 @@ -297,6 +375,7 @@ ENTRY(startup_32_smp)
15510 orl %edx,%eax
15511 movl %eax,%cr4
15512
15513 +#ifdef CONFIG_X86_PAE
15514 btl $5, %eax # check if PAE is enabled
15515 jnc 6f
15516
15517 @@ -305,6 +384,10 @@ ENTRY(startup_32_smp)
15518 cpuid
15519 cmpl $0x80000000, %eax
15520 jbe 6f
15521 +
15522 + /* Clear bogus XD_DISABLE bits */
15523 + call verify_cpu
15524 +
15525 mov $0x80000001, %eax
15526 cpuid
15527 /* Execute Disable bit supported? */
15528 @@ -312,13 +395,17 @@ ENTRY(startup_32_smp)
15529 jnc 6f
15530
15531 /* Setup EFER (Extended Feature Enable Register) */
15532 - movl $0xc0000080, %ecx
15533 + movl $MSR_EFER, %ecx
15534 rdmsr
15535
15536 btsl $11, %eax
15537 /* Make changes effective */
15538 wrmsr
15539
15540 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
15541 + movl $1,pa(nx_enabled)
15542 +#endif
15543 +
15544 6:
15545
15546 /*
15547 @@ -331,8 +418,8 @@ ENTRY(startup_32_smp)
15548 movl %eax,%cr0 /* ..and set paging (PG) bit */
15549 ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */
15550 1:
15551 - /* Set up the stack pointer */
15552 - lss stack_start,%esp
15553 + /* Shift the stack pointer to a virtual address */
15554 + addl $__PAGE_OFFSET, %esp
15555
15556 /*
15557 * Initialize eflags. Some BIOS's leave bits like NT set. This would
15558 @@ -344,9 +431,7 @@ ENTRY(startup_32_smp)
15559
15560 #ifdef CONFIG_SMP
15561 cmpb $0, ready
15562 - jz 1f /* Initial CPU cleans BSS */
15563 - jmp checkCPUtype
15564 -1:
15565 + jnz checkCPUtype
15566 #endif /* CONFIG_SMP */
15567
15568 /*
15569 @@ -424,7 +509,7 @@ is386: movl $2,%ecx # set MP
15570 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
15571 movl %eax,%ss # after changing gdt.
15572
15573 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
15574 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
15575 movl %eax,%ds
15576 movl %eax,%es
15577
15578 @@ -438,15 +523,22 @@ is386: movl $2,%ecx # set MP
15579 */
15580 cmpb $0,ready
15581 jne 1f
15582 - movl $per_cpu__gdt_page,%eax
15583 + movl $cpu_gdt_table,%eax
15584 movl $per_cpu__stack_canary,%ecx
15585 +#ifdef CONFIG_SMP
15586 + addl $__per_cpu_load,%ecx
15587 +#endif
15588 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
15589 shrl $16, %ecx
15590 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
15591 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
15592 1:
15593 -#endif
15594 movl $(__KERNEL_STACK_CANARY),%eax
15595 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15596 + movl $(__USER_DS),%eax
15597 +#else
15598 + xorl %eax,%eax
15599 +#endif
15600 movl %eax,%gs
15601
15602 xorl %eax,%eax # Clear LDT
15603 @@ -454,14 +546,7 @@ is386: movl $2,%ecx # set MP
15604
15605 cld # gcc2 wants the direction flag cleared at all times
15606 pushl $0 # fake return address for unwinder
15607 -#ifdef CONFIG_SMP
15608 - movb ready, %cl
15609 movb $1, ready
15610 - cmpb $0,%cl # the first CPU calls start_kernel
15611 - je 1f
15612 - movl (stack_start), %esp
15613 -1:
15614 -#endif /* CONFIG_SMP */
15615 jmp *(initial_code)
15616
15617 /*
15618 @@ -546,22 +631,22 @@ early_page_fault:
15619 jmp early_fault
15620
15621 early_fault:
15622 - cld
15623 #ifdef CONFIG_PRINTK
15624 + cmpl $1,%ss:early_recursion_flag
15625 + je hlt_loop
15626 + incl %ss:early_recursion_flag
15627 + cld
15628 pusha
15629 movl $(__KERNEL_DS),%eax
15630 movl %eax,%ds
15631 movl %eax,%es
15632 - cmpl $2,early_recursion_flag
15633 - je hlt_loop
15634 - incl early_recursion_flag
15635 movl %cr2,%eax
15636 pushl %eax
15637 pushl %edx /* trapno */
15638 pushl $fault_msg
15639 call printk
15640 +; call dump_stack
15641 #endif
15642 - call dump_stack
15643 hlt_loop:
15644 hlt
15645 jmp hlt_loop
15646 @@ -569,8 +654,11 @@ hlt_loop:
15647 /* This is the default interrupt "handler" :-) */
15648 ALIGN
15649 ignore_int:
15650 - cld
15651 #ifdef CONFIG_PRINTK
15652 + cmpl $2,%ss:early_recursion_flag
15653 + je hlt_loop
15654 + incl %ss:early_recursion_flag
15655 + cld
15656 pushl %eax
15657 pushl %ecx
15658 pushl %edx
15659 @@ -579,9 +667,6 @@ ignore_int:
15660 movl $(__KERNEL_DS),%eax
15661 movl %eax,%ds
15662 movl %eax,%es
15663 - cmpl $2,early_recursion_flag
15664 - je hlt_loop
15665 - incl early_recursion_flag
15666 pushl 16(%esp)
15667 pushl 24(%esp)
15668 pushl 32(%esp)
15669 @@ -600,6 +685,8 @@ ignore_int:
15670 #endif
15671 iret
15672
15673 +#include "verify_cpu.S"
15674 +
15675 __REFDATA
15676 .align 4
15677 ENTRY(initial_code)
15678 @@ -610,31 +697,47 @@ ENTRY(initial_page_table)
15679 /*
15680 * BSS section
15681 */
15682 -__PAGE_ALIGNED_BSS
15683 - .align PAGE_SIZE_asm
15684 #ifdef CONFIG_X86_PAE
15685 +.section .swapper_pg_pmd,"a",@progbits
15686 swapper_pg_pmd:
15687 .fill 1024*KPMDS,4,0
15688 #else
15689 +.section .swapper_pg_dir,"a",@progbits
15690 ENTRY(swapper_pg_dir)
15691 .fill 1024,4,0
15692 #endif
15693 +.section .swapper_pg_fixmap,"a",@progbits
15694 swapper_pg_fixmap:
15695 .fill 1024,4,0
15696 #ifdef CONFIG_X86_TRAMPOLINE
15697 +.section .trampoline_pg_dir,"a",@progbits
15698 ENTRY(trampoline_pg_dir)
15699 +#ifdef CONFIG_X86_PAE
15700 + .fill 4,8,0
15701 +#else
15702 .fill 1024,4,0
15703 #endif
15704 +#endif
15705 +
15706 +.section .empty_zero_page,"a",@progbits
15707 ENTRY(empty_zero_page)
15708 .fill 4096,1,0
15709
15710 /*
15711 + * The IDT has to be page-aligned to simplify the Pentium
15712 + * F0 0F bug workaround.. We have a special link segment
15713 + * for this.
15714 + */
15715 +.section .idt,"a",@progbits
15716 +ENTRY(idt_table)
15717 + .fill 256,8,0
15718 +
15719 +/*
15720 * This starts the data section.
15721 */
15722 #ifdef CONFIG_X86_PAE
15723 -__PAGE_ALIGNED_DATA
15724 - /* Page-aligned for the benefit of paravirt? */
15725 - .align PAGE_SIZE_asm
15726 +.section .swapper_pg_dir,"a",@progbits
15727 +
15728 ENTRY(swapper_pg_dir)
15729 .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
15730 # if KPMDS == 3
15731 @@ -653,15 +756,24 @@ ENTRY(swapper_pg_dir)
15732 # error "Kernel PMDs should be 1, 2 or 3"
15733 # endif
15734 .align PAGE_SIZE_asm /* needs to be page-sized too */
15735 +
15736 +#ifdef CONFIG_PAX_PER_CPU_PGD
15737 +ENTRY(cpu_pgd)
15738 + .rept NR_CPUS
15739 + .fill 4,8,0
15740 + .endr
15741 +#endif
15742 +
15743 #endif
15744
15745 .data
15746 +.balign 4
15747 ENTRY(stack_start)
15748 - .long init_thread_union+THREAD_SIZE
15749 - .long __BOOT_DS
15750 + .long init_thread_union+THREAD_SIZE-8
15751
15752 ready: .byte 0
15753
15754 +.section .rodata,"a",@progbits
15755 early_recursion_flag:
15756 .long 0
15757
15758 @@ -697,7 +809,7 @@ fault_msg:
15759 .word 0 # 32 bit align gdt_desc.address
15760 boot_gdt_descr:
15761 .word __BOOT_DS+7
15762 - .long boot_gdt - __PAGE_OFFSET
15763 + .long pa(boot_gdt)
15764
15765 .word 0 # 32-bit align idt_desc.address
15766 idt_descr:
15767 @@ -708,7 +820,7 @@ idt_descr:
15768 .word 0 # 32 bit align gdt_desc.address
15769 ENTRY(early_gdt_descr)
15770 .word GDT_ENTRIES*8-1
15771 - .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
15772 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
15773
15774 /*
15775 * The boot_gdt must mirror the equivalent in setup.S and is
15776 @@ -717,5 +829,65 @@ ENTRY(early_gdt_descr)
15777 .align L1_CACHE_BYTES
15778 ENTRY(boot_gdt)
15779 .fill GDT_ENTRY_BOOT_CS,8,0
15780 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
15781 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
15782 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
15783 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
15784 +
15785 + .align PAGE_SIZE_asm
15786 +ENTRY(cpu_gdt_table)
15787 + .rept NR_CPUS
15788 + .quad 0x0000000000000000 /* NULL descriptor */
15789 + .quad 0x0000000000000000 /* 0x0b reserved */
15790 + .quad 0x0000000000000000 /* 0x13 reserved */
15791 + .quad 0x0000000000000000 /* 0x1b reserved */
15792 +
15793 +#ifdef CONFIG_PAX_KERNEXEC
15794 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
15795 +#else
15796 + .quad 0x0000000000000000 /* 0x20 unused */
15797 +#endif
15798 +
15799 + .quad 0x0000000000000000 /* 0x28 unused */
15800 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
15801 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
15802 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
15803 + .quad 0x0000000000000000 /* 0x4b reserved */
15804 + .quad 0x0000000000000000 /* 0x53 reserved */
15805 + .quad 0x0000000000000000 /* 0x5b reserved */
15806 +
15807 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
15808 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
15809 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
15810 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
15811 +
15812 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
15813 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
15814 +
15815 + /*
15816 + * Segments used for calling PnP BIOS have byte granularity.
15817 + * The code segments and data segments have fixed 64k limits,
15818 + * the transfer segment sizes are set at run time.
15819 + */
15820 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
15821 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
15822 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
15823 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
15824 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
15825 +
15826 + /*
15827 + * The APM segments have byte granularity and their bases
15828 + * are set at run time. All have 64k limits.
15829 + */
15830 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
15831 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
15832 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
15833 +
15834 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
15835 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
15836 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
15837 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
15838 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
15839 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
15840 +
15841 + /* Be sure this is zeroed to avoid false validations in Xen */
15842 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
15843 + .endr
15844 diff -urNp linux-2.6.32.46/arch/x86/kernel/head_64.S linux-2.6.32.46/arch/x86/kernel/head_64.S
15845 --- linux-2.6.32.46/arch/x86/kernel/head_64.S 2011-03-27 14:31:47.000000000 -0400
15846 +++ linux-2.6.32.46/arch/x86/kernel/head_64.S 2011-04-17 15:56:46.000000000 -0400
15847 @@ -19,6 +19,7 @@
15848 #include <asm/cache.h>
15849 #include <asm/processor-flags.h>
15850 #include <asm/percpu.h>
15851 +#include <asm/cpufeature.h>
15852
15853 #ifdef CONFIG_PARAVIRT
15854 #include <asm/asm-offsets.h>
15855 @@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
15856 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
15857 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
15858 L3_START_KERNEL = pud_index(__START_KERNEL_map)
15859 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
15860 +L3_VMALLOC_START = pud_index(VMALLOC_START)
15861 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
15862 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
15863
15864 .text
15865 __HEAD
15866 @@ -85,35 +90,22 @@ startup_64:
15867 */
15868 addq %rbp, init_level4_pgt + 0(%rip)
15869 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15870 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15871 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15872 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15873
15874 addq %rbp, level3_ident_pgt + 0(%rip)
15875 +#ifndef CONFIG_XEN
15876 + addq %rbp, level3_ident_pgt + 8(%rip)
15877 +#endif
15878
15879 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15880 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15881 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15882
15883 - addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15884 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15885 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15886
15887 - /* Add an Identity mapping if I am above 1G */
15888 - leaq _text(%rip), %rdi
15889 - andq $PMD_PAGE_MASK, %rdi
15890 -
15891 - movq %rdi, %rax
15892 - shrq $PUD_SHIFT, %rax
15893 - andq $(PTRS_PER_PUD - 1), %rax
15894 - jz ident_complete
15895 -
15896 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15897 - leaq level3_ident_pgt(%rip), %rbx
15898 - movq %rdx, 0(%rbx, %rax, 8)
15899 -
15900 - movq %rdi, %rax
15901 - shrq $PMD_SHIFT, %rax
15902 - andq $(PTRS_PER_PMD - 1), %rax
15903 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15904 - leaq level2_spare_pgt(%rip), %rbx
15905 - movq %rdx, 0(%rbx, %rax, 8)
15906 -ident_complete:
15907 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15908 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15909
15910 /*
15911 * Fixup the kernel text+data virtual addresses. Note that
15912 @@ -161,8 +153,8 @@ ENTRY(secondary_startup_64)
15913 * after the boot processor executes this code.
15914 */
15915
15916 - /* Enable PAE mode and PGE */
15917 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15918 + /* Enable PAE mode and PSE/PGE */
15919 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15920 movq %rax, %cr4
15921
15922 /* Setup early boot stage 4 level pagetables. */
15923 @@ -184,9 +176,13 @@ ENTRY(secondary_startup_64)
15924 movl $MSR_EFER, %ecx
15925 rdmsr
15926 btsl $_EFER_SCE, %eax /* Enable System Call */
15927 - btl $20,%edi /* No Execute supported? */
15928 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15929 jnc 1f
15930 btsl $_EFER_NX, %eax
15931 + leaq init_level4_pgt(%rip), %rdi
15932 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15933 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15934 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15935 1: wrmsr /* Make changes effective */
15936
15937 /* Setup cr0 */
15938 @@ -262,16 +258,16 @@ ENTRY(secondary_startup_64)
15939 .quad x86_64_start_kernel
15940 ENTRY(initial_gs)
15941 .quad INIT_PER_CPU_VAR(irq_stack_union)
15942 - __FINITDATA
15943
15944 ENTRY(stack_start)
15945 .quad init_thread_union+THREAD_SIZE-8
15946 .word 0
15947 + __FINITDATA
15948
15949 bad_address:
15950 jmp bad_address
15951
15952 - .section ".init.text","ax"
15953 + __INIT
15954 #ifdef CONFIG_EARLY_PRINTK
15955 .globl early_idt_handlers
15956 early_idt_handlers:
15957 @@ -316,18 +312,23 @@ ENTRY(early_idt_handler)
15958 #endif /* EARLY_PRINTK */
15959 1: hlt
15960 jmp 1b
15961 + .previous
15962
15963 #ifdef CONFIG_EARLY_PRINTK
15964 + __INITDATA
15965 early_recursion_flag:
15966 .long 0
15967 + .previous
15968
15969 + .section .rodata,"a",@progbits
15970 early_idt_msg:
15971 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15972 early_idt_ripmsg:
15973 .asciz "RIP %s\n"
15974 -#endif /* CONFIG_EARLY_PRINTK */
15975 .previous
15976 +#endif /* CONFIG_EARLY_PRINTK */
15977
15978 + .section .rodata,"a",@progbits
15979 #define NEXT_PAGE(name) \
15980 .balign PAGE_SIZE; \
15981 ENTRY(name)
15982 @@ -350,13 +351,36 @@ NEXT_PAGE(init_level4_pgt)
15983 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15984 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15985 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15986 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
15987 + .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
15988 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15989 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15990 .org init_level4_pgt + L4_START_KERNEL*8, 0
15991 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15992 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15993
15994 +#ifdef CONFIG_PAX_PER_CPU_PGD
15995 +NEXT_PAGE(cpu_pgd)
15996 + .rept NR_CPUS
15997 + .fill 512,8,0
15998 + .endr
15999 +#endif
16000 +
16001 NEXT_PAGE(level3_ident_pgt)
16002 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16003 +#ifdef CONFIG_XEN
16004 .fill 511,8,0
16005 +#else
16006 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16007 + .fill 510,8,0
16008 +#endif
16009 +
16010 +NEXT_PAGE(level3_vmalloc_pgt)
16011 + .fill 512,8,0
16012 +
16013 +NEXT_PAGE(level3_vmemmap_pgt)
16014 + .fill L3_VMEMMAP_START,8,0
16015 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16016
16017 NEXT_PAGE(level3_kernel_pgt)
16018 .fill L3_START_KERNEL,8,0
16019 @@ -364,20 +388,23 @@ NEXT_PAGE(level3_kernel_pgt)
16020 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16021 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16022
16023 +NEXT_PAGE(level2_vmemmap_pgt)
16024 + .fill 512,8,0
16025 +
16026 NEXT_PAGE(level2_fixmap_pgt)
16027 - .fill 506,8,0
16028 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16029 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16030 - .fill 5,8,0
16031 + .fill 507,8,0
16032 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16033 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16034 + .fill 4,8,0
16035
16036 -NEXT_PAGE(level1_fixmap_pgt)
16037 +NEXT_PAGE(level1_vsyscall_pgt)
16038 .fill 512,8,0
16039
16040 -NEXT_PAGE(level2_ident_pgt)
16041 - /* Since I easily can, map the first 1G.
16042 + /* Since I easily can, map the first 2G.
16043 * Don't set NX because code runs from these pages.
16044 */
16045 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16046 +NEXT_PAGE(level2_ident_pgt)
16047 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16048
16049 NEXT_PAGE(level2_kernel_pgt)
16050 /*
16051 @@ -390,33 +417,55 @@ NEXT_PAGE(level2_kernel_pgt)
16052 * If you want to increase this then increase MODULES_VADDR
16053 * too.)
16054 */
16055 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16056 - KERNEL_IMAGE_SIZE/PMD_SIZE)
16057 -
16058 -NEXT_PAGE(level2_spare_pgt)
16059 - .fill 512, 8, 0
16060 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16061
16062 #undef PMDS
16063 #undef NEXT_PAGE
16064
16065 - .data
16066 + .align PAGE_SIZE
16067 +ENTRY(cpu_gdt_table)
16068 + .rept NR_CPUS
16069 + .quad 0x0000000000000000 /* NULL descriptor */
16070 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16071 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
16072 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
16073 + .quad 0x00cffb000000ffff /* __USER32_CS */
16074 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16075 + .quad 0x00affb000000ffff /* __USER_CS */
16076 +
16077 +#ifdef CONFIG_PAX_KERNEXEC
16078 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16079 +#else
16080 + .quad 0x0 /* unused */
16081 +#endif
16082 +
16083 + .quad 0,0 /* TSS */
16084 + .quad 0,0 /* LDT */
16085 + .quad 0,0,0 /* three TLS descriptors */
16086 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
16087 + /* asm/segment.h:GDT_ENTRIES must match this */
16088 +
16089 + /* zero the remaining page */
16090 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16091 + .endr
16092 +
16093 .align 16
16094 .globl early_gdt_descr
16095 early_gdt_descr:
16096 .word GDT_ENTRIES*8-1
16097 early_gdt_descr_base:
16098 - .quad INIT_PER_CPU_VAR(gdt_page)
16099 + .quad cpu_gdt_table
16100
16101 ENTRY(phys_base)
16102 /* This must match the first entry in level2_kernel_pgt */
16103 .quad 0x0000000000000000
16104
16105 #include "../../x86/xen/xen-head.S"
16106 -
16107 - .section .bss, "aw", @nobits
16108 +
16109 + .section .rodata,"a",@progbits
16110 .align L1_CACHE_BYTES
16111 ENTRY(idt_table)
16112 - .skip IDT_ENTRIES * 16
16113 + .fill 512,8,0
16114
16115 __PAGE_ALIGNED_BSS
16116 .align PAGE_SIZE
16117 diff -urNp linux-2.6.32.46/arch/x86/kernel/i386_ksyms_32.c linux-2.6.32.46/arch/x86/kernel/i386_ksyms_32.c
16118 --- linux-2.6.32.46/arch/x86/kernel/i386_ksyms_32.c 2011-03-27 14:31:47.000000000 -0400
16119 +++ linux-2.6.32.46/arch/x86/kernel/i386_ksyms_32.c 2011-04-17 15:56:46.000000000 -0400
16120 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
16121 EXPORT_SYMBOL(cmpxchg8b_emu);
16122 #endif
16123
16124 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
16125 +
16126 /* Networking helper routines. */
16127 EXPORT_SYMBOL(csum_partial_copy_generic);
16128 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
16129 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
16130
16131 EXPORT_SYMBOL(__get_user_1);
16132 EXPORT_SYMBOL(__get_user_2);
16133 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
16134
16135 EXPORT_SYMBOL(csum_partial);
16136 EXPORT_SYMBOL(empty_zero_page);
16137 +
16138 +#ifdef CONFIG_PAX_KERNEXEC
16139 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
16140 +#endif
16141 diff -urNp linux-2.6.32.46/arch/x86/kernel/i8259.c linux-2.6.32.46/arch/x86/kernel/i8259.c
16142 --- linux-2.6.32.46/arch/x86/kernel/i8259.c 2011-03-27 14:31:47.000000000 -0400
16143 +++ linux-2.6.32.46/arch/x86/kernel/i8259.c 2011-05-04 17:56:28.000000000 -0400
16144 @@ -208,7 +208,7 @@ spurious_8259A_irq:
16145 "spurious 8259A interrupt: IRQ%d.\n", irq);
16146 spurious_irq_mask |= irqmask;
16147 }
16148 - atomic_inc(&irq_err_count);
16149 + atomic_inc_unchecked(&irq_err_count);
16150 /*
16151 * Theoretically we do not have to handle this IRQ,
16152 * but in Linux this does not cause problems and is
16153 diff -urNp linux-2.6.32.46/arch/x86/kernel/init_task.c linux-2.6.32.46/arch/x86/kernel/init_task.c
16154 --- linux-2.6.32.46/arch/x86/kernel/init_task.c 2011-03-27 14:31:47.000000000 -0400
16155 +++ linux-2.6.32.46/arch/x86/kernel/init_task.c 2011-04-17 15:56:46.000000000 -0400
16156 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
16157 * way process stacks are handled. This is done by having a special
16158 * "init_task" linker map entry..
16159 */
16160 -union thread_union init_thread_union __init_task_data =
16161 - { INIT_THREAD_INFO(init_task) };
16162 +union thread_union init_thread_union __init_task_data;
16163
16164 /*
16165 * Initial task structure.
16166 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
16167 * section. Since TSS's are completely CPU-local, we want them
16168 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
16169 */
16170 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
16171 -
16172 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
16173 +EXPORT_SYMBOL(init_tss);
16174 diff -urNp linux-2.6.32.46/arch/x86/kernel/ioport.c linux-2.6.32.46/arch/x86/kernel/ioport.c
16175 --- linux-2.6.32.46/arch/x86/kernel/ioport.c 2011-03-27 14:31:47.000000000 -0400
16176 +++ linux-2.6.32.46/arch/x86/kernel/ioport.c 2011-04-17 15:56:46.000000000 -0400
16177 @@ -6,6 +6,7 @@
16178 #include <linux/sched.h>
16179 #include <linux/kernel.h>
16180 #include <linux/capability.h>
16181 +#include <linux/security.h>
16182 #include <linux/errno.h>
16183 #include <linux/types.h>
16184 #include <linux/ioport.h>
16185 @@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long
16186
16187 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
16188 return -EINVAL;
16189 +#ifdef CONFIG_GRKERNSEC_IO
16190 + if (turn_on && grsec_disable_privio) {
16191 + gr_handle_ioperm();
16192 + return -EPERM;
16193 + }
16194 +#endif
16195 if (turn_on && !capable(CAP_SYS_RAWIO))
16196 return -EPERM;
16197
16198 @@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long
16199 * because the ->io_bitmap_max value must match the bitmap
16200 * contents:
16201 */
16202 - tss = &per_cpu(init_tss, get_cpu());
16203 + tss = init_tss + get_cpu();
16204
16205 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
16206
16207 @@ -111,6 +118,12 @@ static int do_iopl(unsigned int level, s
16208 return -EINVAL;
16209 /* Trying to gain more privileges? */
16210 if (level > old) {
16211 +#ifdef CONFIG_GRKERNSEC_IO
16212 + if (grsec_disable_privio) {
16213 + gr_handle_iopl();
16214 + return -EPERM;
16215 + }
16216 +#endif
16217 if (!capable(CAP_SYS_RAWIO))
16218 return -EPERM;
16219 }
16220 diff -urNp linux-2.6.32.46/arch/x86/kernel/irq.c linux-2.6.32.46/arch/x86/kernel/irq.c
16221 --- linux-2.6.32.46/arch/x86/kernel/irq.c 2011-03-27 14:31:47.000000000 -0400
16222 +++ linux-2.6.32.46/arch/x86/kernel/irq.c 2011-05-04 17:56:28.000000000 -0400
16223 @@ -15,7 +15,7 @@
16224 #include <asm/mce.h>
16225 #include <asm/hw_irq.h>
16226
16227 -atomic_t irq_err_count;
16228 +atomic_unchecked_t irq_err_count;
16229
16230 /* Function pointer for generic interrupt vector handling */
16231 void (*generic_interrupt_extension)(void) = NULL;
16232 @@ -114,9 +114,9 @@ static int show_other_interrupts(struct
16233 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
16234 seq_printf(p, " Machine check polls\n");
16235 #endif
16236 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
16237 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
16238 #if defined(CONFIG_X86_IO_APIC)
16239 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
16240 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
16241 #endif
16242 return 0;
16243 }
16244 @@ -209,10 +209,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
16245
16246 u64 arch_irq_stat(void)
16247 {
16248 - u64 sum = atomic_read(&irq_err_count);
16249 + u64 sum = atomic_read_unchecked(&irq_err_count);
16250
16251 #ifdef CONFIG_X86_IO_APIC
16252 - sum += atomic_read(&irq_mis_count);
16253 + sum += atomic_read_unchecked(&irq_mis_count);
16254 #endif
16255 return sum;
16256 }
16257 diff -urNp linux-2.6.32.46/arch/x86/kernel/irq_32.c linux-2.6.32.46/arch/x86/kernel/irq_32.c
16258 --- linux-2.6.32.46/arch/x86/kernel/irq_32.c 2011-03-27 14:31:47.000000000 -0400
16259 +++ linux-2.6.32.46/arch/x86/kernel/irq_32.c 2011-07-06 19:53:33.000000000 -0400
16260 @@ -35,7 +35,7 @@ static int check_stack_overflow(void)
16261 __asm__ __volatile__("andl %%esp,%0" :
16262 "=r" (sp) : "0" (THREAD_SIZE - 1));
16263
16264 - return sp < (sizeof(struct thread_info) + STACK_WARN);
16265 + return sp < STACK_WARN;
16266 }
16267
16268 static void print_stack_overflow(void)
16269 @@ -54,9 +54,9 @@ static inline void print_stack_overflow(
16270 * per-CPU IRQ handling contexts (thread information and stack)
16271 */
16272 union irq_ctx {
16273 - struct thread_info tinfo;
16274 - u32 stack[THREAD_SIZE/sizeof(u32)];
16275 -} __attribute__((aligned(PAGE_SIZE)));
16276 + unsigned long previous_esp;
16277 + u32 stack[THREAD_SIZE/sizeof(u32)];
16278 +} __attribute__((aligned(THREAD_SIZE)));
16279
16280 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
16281 static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx);
16282 @@ -78,10 +78,9 @@ static void call_on_stack(void *func, vo
16283 static inline int
16284 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16285 {
16286 - union irq_ctx *curctx, *irqctx;
16287 + union irq_ctx *irqctx;
16288 u32 *isp, arg1, arg2;
16289
16290 - curctx = (union irq_ctx *) current_thread_info();
16291 irqctx = __get_cpu_var(hardirq_ctx);
16292
16293 /*
16294 @@ -90,21 +89,16 @@ execute_on_irq_stack(int overflow, struc
16295 * handler) we can't do that and just have to keep using the
16296 * current stack (which is the irq stack already after all)
16297 */
16298 - if (unlikely(curctx == irqctx))
16299 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
16300 return 0;
16301
16302 /* build the stack frame on the IRQ stack */
16303 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
16304 - irqctx->tinfo.task = curctx->tinfo.task;
16305 - irqctx->tinfo.previous_esp = current_stack_pointer;
16306 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
16307 + irqctx->previous_esp = current_stack_pointer;
16308
16309 - /*
16310 - * Copy the softirq bits in preempt_count so that the
16311 - * softirq checks work in the hardirq context.
16312 - */
16313 - irqctx->tinfo.preempt_count =
16314 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
16315 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
16316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16317 + __set_fs(MAKE_MM_SEG(0));
16318 +#endif
16319
16320 if (unlikely(overflow))
16321 call_on_stack(print_stack_overflow, isp);
16322 @@ -116,6 +110,11 @@ execute_on_irq_stack(int overflow, struc
16323 : "0" (irq), "1" (desc), "2" (isp),
16324 "D" (desc->handle_irq)
16325 : "memory", "cc", "ecx");
16326 +
16327 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16328 + __set_fs(current_thread_info()->addr_limit);
16329 +#endif
16330 +
16331 return 1;
16332 }
16333
16334 @@ -124,28 +123,11 @@ execute_on_irq_stack(int overflow, struc
16335 */
16336 void __cpuinit irq_ctx_init(int cpu)
16337 {
16338 - union irq_ctx *irqctx;
16339 -
16340 if (per_cpu(hardirq_ctx, cpu))
16341 return;
16342
16343 - irqctx = &per_cpu(hardirq_stack, cpu);
16344 - irqctx->tinfo.task = NULL;
16345 - irqctx->tinfo.exec_domain = NULL;
16346 - irqctx->tinfo.cpu = cpu;
16347 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
16348 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
16349 -
16350 - per_cpu(hardirq_ctx, cpu) = irqctx;
16351 -
16352 - irqctx = &per_cpu(softirq_stack, cpu);
16353 - irqctx->tinfo.task = NULL;
16354 - irqctx->tinfo.exec_domain = NULL;
16355 - irqctx->tinfo.cpu = cpu;
16356 - irqctx->tinfo.preempt_count = 0;
16357 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
16358 -
16359 - per_cpu(softirq_ctx, cpu) = irqctx;
16360 + per_cpu(hardirq_ctx, cpu) = &per_cpu(hardirq_stack, cpu);
16361 + per_cpu(softirq_ctx, cpu) = &per_cpu(softirq_stack, cpu);
16362
16363 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
16364 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
16365 @@ -159,7 +141,6 @@ void irq_ctx_exit(int cpu)
16366 asmlinkage void do_softirq(void)
16367 {
16368 unsigned long flags;
16369 - struct thread_info *curctx;
16370 union irq_ctx *irqctx;
16371 u32 *isp;
16372
16373 @@ -169,15 +150,22 @@ asmlinkage void do_softirq(void)
16374 local_irq_save(flags);
16375
16376 if (local_softirq_pending()) {
16377 - curctx = current_thread_info();
16378 irqctx = __get_cpu_var(softirq_ctx);
16379 - irqctx->tinfo.task = curctx->task;
16380 - irqctx->tinfo.previous_esp = current_stack_pointer;
16381 + irqctx->previous_esp = current_stack_pointer;
16382
16383 /* build the stack frame on the softirq stack */
16384 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
16385 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
16386 +
16387 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16388 + __set_fs(MAKE_MM_SEG(0));
16389 +#endif
16390
16391 call_on_stack(__do_softirq, isp);
16392 +
16393 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16394 + __set_fs(current_thread_info()->addr_limit);
16395 +#endif
16396 +
16397 /*
16398 * Shouldnt happen, we returned above if in_interrupt():
16399 */
16400 diff -urNp linux-2.6.32.46/arch/x86/kernel/kgdb.c linux-2.6.32.46/arch/x86/kernel/kgdb.c
16401 --- linux-2.6.32.46/arch/x86/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
16402 +++ linux-2.6.32.46/arch/x86/kernel/kgdb.c 2011-05-04 17:56:20.000000000 -0400
16403 @@ -390,13 +390,13 @@ int kgdb_arch_handle_exception(int e_vec
16404
16405 /* clear the trace bit */
16406 linux_regs->flags &= ~X86_EFLAGS_TF;
16407 - atomic_set(&kgdb_cpu_doing_single_step, -1);
16408 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
16409
16410 /* set the trace bit if we're stepping */
16411 if (remcomInBuffer[0] == 's') {
16412 linux_regs->flags |= X86_EFLAGS_TF;
16413 kgdb_single_step = 1;
16414 - atomic_set(&kgdb_cpu_doing_single_step,
16415 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
16416 raw_smp_processor_id());
16417 }
16418
16419 @@ -476,7 +476,7 @@ static int __kgdb_notify(struct die_args
16420 break;
16421
16422 case DIE_DEBUG:
16423 - if (atomic_read(&kgdb_cpu_doing_single_step) ==
16424 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) ==
16425 raw_smp_processor_id()) {
16426 if (user_mode(regs))
16427 return single_step_cont(regs, args);
16428 @@ -573,7 +573,7 @@ unsigned long kgdb_arch_pc(int exception
16429 return instruction_pointer(regs);
16430 }
16431
16432 -struct kgdb_arch arch_kgdb_ops = {
16433 +const struct kgdb_arch arch_kgdb_ops = {
16434 /* Breakpoint instruction: */
16435 .gdb_bpt_instr = { 0xcc },
16436 .flags = KGDB_HW_BREAKPOINT,
16437 diff -urNp linux-2.6.32.46/arch/x86/kernel/kprobes.c linux-2.6.32.46/arch/x86/kernel/kprobes.c
16438 --- linux-2.6.32.46/arch/x86/kernel/kprobes.c 2011-03-27 14:31:47.000000000 -0400
16439 +++ linux-2.6.32.46/arch/x86/kernel/kprobes.c 2011-04-17 15:56:46.000000000 -0400
16440 @@ -166,9 +166,13 @@ static void __kprobes set_jmp_op(void *f
16441 char op;
16442 s32 raddr;
16443 } __attribute__((packed)) * jop;
16444 - jop = (struct __arch_jmp_op *)from;
16445 +
16446 + jop = (struct __arch_jmp_op *)(ktla_ktva(from));
16447 +
16448 + pax_open_kernel();
16449 jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
16450 jop->op = RELATIVEJUMP_INSTRUCTION;
16451 + pax_close_kernel();
16452 }
16453
16454 /*
16455 @@ -193,7 +197,7 @@ static int __kprobes can_boost(kprobe_op
16456 kprobe_opcode_t opcode;
16457 kprobe_opcode_t *orig_opcodes = opcodes;
16458
16459 - if (search_exception_tables((unsigned long)opcodes))
16460 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
16461 return 0; /* Page fault may occur on this address. */
16462
16463 retry:
16464 @@ -337,7 +341,9 @@ static void __kprobes fix_riprel(struct
16465 disp = (u8 *) p->addr + *((s32 *) insn) -
16466 (u8 *) p->ainsn.insn;
16467 BUG_ON((s64) (s32) disp != disp); /* Sanity check. */
16468 + pax_open_kernel();
16469 *(s32 *)insn = (s32) disp;
16470 + pax_close_kernel();
16471 }
16472 }
16473 #endif
16474 @@ -345,16 +351,18 @@ static void __kprobes fix_riprel(struct
16475
16476 static void __kprobes arch_copy_kprobe(struct kprobe *p)
16477 {
16478 - memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
16479 + pax_open_kernel();
16480 + memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
16481 + pax_close_kernel();
16482
16483 fix_riprel(p);
16484
16485 - if (can_boost(p->addr))
16486 + if (can_boost(ktla_ktva(p->addr)))
16487 p->ainsn.boostable = 0;
16488 else
16489 p->ainsn.boostable = -1;
16490
16491 - p->opcode = *p->addr;
16492 + p->opcode = *(ktla_ktva(p->addr));
16493 }
16494
16495 int __kprobes arch_prepare_kprobe(struct kprobe *p)
16496 @@ -432,7 +440,7 @@ static void __kprobes prepare_singlestep
16497 if (p->opcode == BREAKPOINT_INSTRUCTION)
16498 regs->ip = (unsigned long)p->addr;
16499 else
16500 - regs->ip = (unsigned long)p->ainsn.insn;
16501 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
16502 }
16503
16504 void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
16505 @@ -453,7 +461,7 @@ static void __kprobes setup_singlestep(s
16506 if (p->ainsn.boostable == 1 && !p->post_handler) {
16507 /* Boost up -- we can execute copied instructions directly */
16508 reset_current_kprobe();
16509 - regs->ip = (unsigned long)p->ainsn.insn;
16510 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
16511 preempt_enable_no_resched();
16512 return;
16513 }
16514 @@ -523,7 +531,7 @@ static int __kprobes kprobe_handler(stru
16515 struct kprobe_ctlblk *kcb;
16516
16517 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
16518 - if (*addr != BREAKPOINT_INSTRUCTION) {
16519 + if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
16520 /*
16521 * The breakpoint instruction was removed right
16522 * after we hit it. Another cpu has removed
16523 @@ -775,7 +783,7 @@ static void __kprobes resume_execution(s
16524 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
16525 {
16526 unsigned long *tos = stack_addr(regs);
16527 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
16528 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
16529 unsigned long orig_ip = (unsigned long)p->addr;
16530 kprobe_opcode_t *insn = p->ainsn.insn;
16531
16532 @@ -958,7 +966,7 @@ int __kprobes kprobe_exceptions_notify(s
16533 struct die_args *args = data;
16534 int ret = NOTIFY_DONE;
16535
16536 - if (args->regs && user_mode_vm(args->regs))
16537 + if (args->regs && user_mode(args->regs))
16538 return ret;
16539
16540 switch (val) {
16541 diff -urNp linux-2.6.32.46/arch/x86/kernel/kvm.c linux-2.6.32.46/arch/x86/kernel/kvm.c
16542 --- linux-2.6.32.46/arch/x86/kernel/kvm.c 2011-03-27 14:31:47.000000000 -0400
16543 +++ linux-2.6.32.46/arch/x86/kernel/kvm.c 2011-08-24 18:35:52.000000000 -0400
16544 @@ -216,6 +216,7 @@ static void __init paravirt_ops_setup(vo
16545 pv_mmu_ops.set_pud = kvm_set_pud;
16546 #if PAGETABLE_LEVELS == 4
16547 pv_mmu_ops.set_pgd = kvm_set_pgd;
16548 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
16549 #endif
16550 #endif
16551 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
16552 diff -urNp linux-2.6.32.46/arch/x86/kernel/ldt.c linux-2.6.32.46/arch/x86/kernel/ldt.c
16553 --- linux-2.6.32.46/arch/x86/kernel/ldt.c 2011-03-27 14:31:47.000000000 -0400
16554 +++ linux-2.6.32.46/arch/x86/kernel/ldt.c 2011-04-17 15:56:46.000000000 -0400
16555 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, i
16556 if (reload) {
16557 #ifdef CONFIG_SMP
16558 preempt_disable();
16559 - load_LDT(pc);
16560 + load_LDT_nolock(pc);
16561 if (!cpumask_equal(mm_cpumask(current->mm),
16562 cpumask_of(smp_processor_id())))
16563 smp_call_function(flush_ldt, current->mm, 1);
16564 preempt_enable();
16565 #else
16566 - load_LDT(pc);
16567 + load_LDT_nolock(pc);
16568 #endif
16569 }
16570 if (oldsize) {
16571 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t
16572 return err;
16573
16574 for (i = 0; i < old->size; i++)
16575 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
16576 + write_ldt_entry(new->ldt, i, old->ldt + i);
16577 return 0;
16578 }
16579
16580 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct
16581 retval = copy_ldt(&mm->context, &old_mm->context);
16582 mutex_unlock(&old_mm->context.lock);
16583 }
16584 +
16585 + if (tsk == current) {
16586 + mm->context.vdso = 0;
16587 +
16588 +#ifdef CONFIG_X86_32
16589 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16590 + mm->context.user_cs_base = 0UL;
16591 + mm->context.user_cs_limit = ~0UL;
16592 +
16593 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16594 + cpus_clear(mm->context.cpu_user_cs_mask);
16595 +#endif
16596 +
16597 +#endif
16598 +#endif
16599 +
16600 + }
16601 +
16602 return retval;
16603 }
16604
16605 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, u
16606 }
16607 }
16608
16609 +#ifdef CONFIG_PAX_SEGMEXEC
16610 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
16611 + error = -EINVAL;
16612 + goto out_unlock;
16613 + }
16614 +#endif
16615 +
16616 fill_ldt(&ldt, &ldt_info);
16617 if (oldmode)
16618 ldt.avl = 0;
16619 diff -urNp linux-2.6.32.46/arch/x86/kernel/machine_kexec_32.c linux-2.6.32.46/arch/x86/kernel/machine_kexec_32.c
16620 --- linux-2.6.32.46/arch/x86/kernel/machine_kexec_32.c 2011-03-27 14:31:47.000000000 -0400
16621 +++ linux-2.6.32.46/arch/x86/kernel/machine_kexec_32.c 2011-04-17 15:56:46.000000000 -0400
16622 @@ -26,7 +26,7 @@
16623 #include <asm/system.h>
16624 #include <asm/cacheflush.h>
16625
16626 -static void set_idt(void *newidt, __u16 limit)
16627 +static void set_idt(struct desc_struct *newidt, __u16 limit)
16628 {
16629 struct desc_ptr curidt;
16630
16631 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16
16632 }
16633
16634
16635 -static void set_gdt(void *newgdt, __u16 limit)
16636 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
16637 {
16638 struct desc_ptr curgdt;
16639
16640 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
16641 }
16642
16643 control_page = page_address(image->control_code_page);
16644 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
16645 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
16646
16647 relocate_kernel_ptr = control_page;
16648 page_list[PA_CONTROL_PAGE] = __pa(control_page);
16649 diff -urNp linux-2.6.32.46/arch/x86/kernel/microcode_amd.c linux-2.6.32.46/arch/x86/kernel/microcode_amd.c
16650 --- linux-2.6.32.46/arch/x86/kernel/microcode_amd.c 2011-04-17 17:00:52.000000000 -0400
16651 +++ linux-2.6.32.46/arch/x86/kernel/microcode_amd.c 2011-04-17 17:03:05.000000000 -0400
16652 @@ -364,7 +364,7 @@ static void microcode_fini_cpu_amd(int c
16653 uci->mc = NULL;
16654 }
16655
16656 -static struct microcode_ops microcode_amd_ops = {
16657 +static const struct microcode_ops microcode_amd_ops = {
16658 .request_microcode_user = request_microcode_user,
16659 .request_microcode_fw = request_microcode_fw,
16660 .collect_cpu_info = collect_cpu_info_amd,
16661 @@ -372,7 +372,7 @@ static struct microcode_ops microcode_am
16662 .microcode_fini_cpu = microcode_fini_cpu_amd,
16663 };
16664
16665 -struct microcode_ops * __init init_amd_microcode(void)
16666 +const struct microcode_ops * __init init_amd_microcode(void)
16667 {
16668 return &microcode_amd_ops;
16669 }
16670 diff -urNp linux-2.6.32.46/arch/x86/kernel/microcode_core.c linux-2.6.32.46/arch/x86/kernel/microcode_core.c
16671 --- linux-2.6.32.46/arch/x86/kernel/microcode_core.c 2011-03-27 14:31:47.000000000 -0400
16672 +++ linux-2.6.32.46/arch/x86/kernel/microcode_core.c 2011-04-17 15:56:46.000000000 -0400
16673 @@ -90,7 +90,7 @@ MODULE_LICENSE("GPL");
16674
16675 #define MICROCODE_VERSION "2.00"
16676
16677 -static struct microcode_ops *microcode_ops;
16678 +static const struct microcode_ops *microcode_ops;
16679
16680 /*
16681 * Synchronization.
16682 diff -urNp linux-2.6.32.46/arch/x86/kernel/microcode_intel.c linux-2.6.32.46/arch/x86/kernel/microcode_intel.c
16683 --- linux-2.6.32.46/arch/x86/kernel/microcode_intel.c 2011-03-27 14:31:47.000000000 -0400
16684 +++ linux-2.6.32.46/arch/x86/kernel/microcode_intel.c 2011-10-06 09:37:08.000000000 -0400
16685 @@ -443,13 +443,13 @@ static enum ucode_state request_microcod
16686
16687 static int get_ucode_user(void *to, const void *from, size_t n)
16688 {
16689 - return copy_from_user(to, from, n);
16690 + return copy_from_user(to, (const void __force_user *)from, n);
16691 }
16692
16693 static enum ucode_state
16694 request_microcode_user(int cpu, const void __user *buf, size_t size)
16695 {
16696 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
16697 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
16698 }
16699
16700 static void microcode_fini_cpu(int cpu)
16701 @@ -460,7 +460,7 @@ static void microcode_fini_cpu(int cpu)
16702 uci->mc = NULL;
16703 }
16704
16705 -static struct microcode_ops microcode_intel_ops = {
16706 +static const struct microcode_ops microcode_intel_ops = {
16707 .request_microcode_user = request_microcode_user,
16708 .request_microcode_fw = request_microcode_fw,
16709 .collect_cpu_info = collect_cpu_info,
16710 @@ -468,7 +468,7 @@ static struct microcode_ops microcode_in
16711 .microcode_fini_cpu = microcode_fini_cpu,
16712 };
16713
16714 -struct microcode_ops * __init init_intel_microcode(void)
16715 +const struct microcode_ops * __init init_intel_microcode(void)
16716 {
16717 return &microcode_intel_ops;
16718 }
16719 diff -urNp linux-2.6.32.46/arch/x86/kernel/module.c linux-2.6.32.46/arch/x86/kernel/module.c
16720 --- linux-2.6.32.46/arch/x86/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
16721 +++ linux-2.6.32.46/arch/x86/kernel/module.c 2011-04-17 15:56:46.000000000 -0400
16722 @@ -34,7 +34,7 @@
16723 #define DEBUGP(fmt...)
16724 #endif
16725
16726 -void *module_alloc(unsigned long size)
16727 +static void *__module_alloc(unsigned long size, pgprot_t prot)
16728 {
16729 struct vm_struct *area;
16730
16731 @@ -48,8 +48,18 @@ void *module_alloc(unsigned long size)
16732 if (!area)
16733 return NULL;
16734
16735 - return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM,
16736 - PAGE_KERNEL_EXEC);
16737 + return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot);
16738 +}
16739 +
16740 +void *module_alloc(unsigned long size)
16741 +{
16742 +
16743 +#ifdef CONFIG_PAX_KERNEXEC
16744 + return __module_alloc(size, PAGE_KERNEL);
16745 +#else
16746 + return __module_alloc(size, PAGE_KERNEL_EXEC);
16747 +#endif
16748 +
16749 }
16750
16751 /* Free memory returned from module_alloc */
16752 @@ -58,6 +68,40 @@ void module_free(struct module *mod, voi
16753 vfree(module_region);
16754 }
16755
16756 +#ifdef CONFIG_PAX_KERNEXEC
16757 +#ifdef CONFIG_X86_32
16758 +void *module_alloc_exec(unsigned long size)
16759 +{
16760 + struct vm_struct *area;
16761 +
16762 + if (size == 0)
16763 + return NULL;
16764 +
16765 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
16766 + return area ? area->addr : NULL;
16767 +}
16768 +EXPORT_SYMBOL(module_alloc_exec);
16769 +
16770 +void module_free_exec(struct module *mod, void *module_region)
16771 +{
16772 + vunmap(module_region);
16773 +}
16774 +EXPORT_SYMBOL(module_free_exec);
16775 +#else
16776 +void module_free_exec(struct module *mod, void *module_region)
16777 +{
16778 + module_free(mod, module_region);
16779 +}
16780 +EXPORT_SYMBOL(module_free_exec);
16781 +
16782 +void *module_alloc_exec(unsigned long size)
16783 +{
16784 + return __module_alloc(size, PAGE_KERNEL_RX);
16785 +}
16786 +EXPORT_SYMBOL(module_alloc_exec);
16787 +#endif
16788 +#endif
16789 +
16790 /* We don't need anything special. */
16791 int module_frob_arch_sections(Elf_Ehdr *hdr,
16792 Elf_Shdr *sechdrs,
16793 @@ -77,14 +121,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16794 unsigned int i;
16795 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
16796 Elf32_Sym *sym;
16797 - uint32_t *location;
16798 + uint32_t *plocation, location;
16799
16800 DEBUGP("Applying relocate section %u to %u\n", relsec,
16801 sechdrs[relsec].sh_info);
16802 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
16803 /* This is where to make the change */
16804 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
16805 - + rel[i].r_offset;
16806 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
16807 + location = (uint32_t)plocation;
16808 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
16809 + plocation = ktla_ktva((void *)plocation);
16810 /* This is the symbol it is referring to. Note that all
16811 undefined symbols have been resolved. */
16812 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
16813 @@ -93,11 +139,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16814 switch (ELF32_R_TYPE(rel[i].r_info)) {
16815 case R_386_32:
16816 /* We add the value into the location given */
16817 - *location += sym->st_value;
16818 + pax_open_kernel();
16819 + *plocation += sym->st_value;
16820 + pax_close_kernel();
16821 break;
16822 case R_386_PC32:
16823 /* Add the value, subtract its postition */
16824 - *location += sym->st_value - (uint32_t)location;
16825 + pax_open_kernel();
16826 + *plocation += sym->st_value - location;
16827 + pax_close_kernel();
16828 break;
16829 default:
16830 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
16831 @@ -153,21 +203,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
16832 case R_X86_64_NONE:
16833 break;
16834 case R_X86_64_64:
16835 + pax_open_kernel();
16836 *(u64 *)loc = val;
16837 + pax_close_kernel();
16838 break;
16839 case R_X86_64_32:
16840 + pax_open_kernel();
16841 *(u32 *)loc = val;
16842 + pax_close_kernel();
16843 if (val != *(u32 *)loc)
16844 goto overflow;
16845 break;
16846 case R_X86_64_32S:
16847 + pax_open_kernel();
16848 *(s32 *)loc = val;
16849 + pax_close_kernel();
16850 if ((s64)val != *(s32 *)loc)
16851 goto overflow;
16852 break;
16853 case R_X86_64_PC32:
16854 val -= (u64)loc;
16855 + pax_open_kernel();
16856 *(u32 *)loc = val;
16857 + pax_close_kernel();
16858 +
16859 #if 0
16860 if ((s64)val != *(s32 *)loc)
16861 goto overflow;
16862 diff -urNp linux-2.6.32.46/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.32.46/arch/x86/kernel/paravirt-spinlocks.c
16863 --- linux-2.6.32.46/arch/x86/kernel/paravirt-spinlocks.c 2011-03-27 14:31:47.000000000 -0400
16864 +++ linux-2.6.32.46/arch/x86/kernel/paravirt-spinlocks.c 2011-04-17 15:56:46.000000000 -0400
16865 @@ -13,7 +13,7 @@ default_spin_lock_flags(raw_spinlock_t *
16866 __raw_spin_lock(lock);
16867 }
16868
16869 -struct pv_lock_ops pv_lock_ops = {
16870 +struct pv_lock_ops pv_lock_ops __read_only = {
16871 #ifdef CONFIG_SMP
16872 .spin_is_locked = __ticket_spin_is_locked,
16873 .spin_is_contended = __ticket_spin_is_contended,
16874 diff -urNp linux-2.6.32.46/arch/x86/kernel/paravirt.c linux-2.6.32.46/arch/x86/kernel/paravirt.c
16875 --- linux-2.6.32.46/arch/x86/kernel/paravirt.c 2011-03-27 14:31:47.000000000 -0400
16876 +++ linux-2.6.32.46/arch/x86/kernel/paravirt.c 2011-08-23 20:24:19.000000000 -0400
16877 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
16878 {
16879 return x;
16880 }
16881 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16882 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
16883 +#endif
16884
16885 void __init default_banner(void)
16886 {
16887 @@ -122,7 +125,7 @@ unsigned paravirt_patch_jmp(void *insnbu
16888 * corresponding structure. */
16889 static void *get_call_destination(u8 type)
16890 {
16891 - struct paravirt_patch_template tmpl = {
16892 + const struct paravirt_patch_template tmpl = {
16893 .pv_init_ops = pv_init_ops,
16894 .pv_time_ops = pv_time_ops,
16895 .pv_cpu_ops = pv_cpu_ops,
16896 @@ -133,6 +136,8 @@ static void *get_call_destination(u8 typ
16897 .pv_lock_ops = pv_lock_ops,
16898 #endif
16899 };
16900 +
16901 + pax_track_stack();
16902 return *((void **)&tmpl + type);
16903 }
16904
16905 @@ -145,15 +150,19 @@ unsigned paravirt_patch_default(u8 type,
16906 if (opfunc == NULL)
16907 /* If there's no function, patch it with a ud2a (BUG) */
16908 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16909 - else if (opfunc == _paravirt_nop)
16910 + else if (opfunc == (void *)_paravirt_nop)
16911 /* If the operation is a nop, then nop the callsite */
16912 ret = paravirt_patch_nop();
16913
16914 /* identity functions just return their single argument */
16915 - else if (opfunc == _paravirt_ident_32)
16916 + else if (opfunc == (void *)_paravirt_ident_32)
16917 ret = paravirt_patch_ident_32(insnbuf, len);
16918 - else if (opfunc == _paravirt_ident_64)
16919 + else if (opfunc == (void *)_paravirt_ident_64)
16920 + ret = paravirt_patch_ident_64(insnbuf, len);
16921 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16922 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
16923 ret = paravirt_patch_ident_64(insnbuf, len);
16924 +#endif
16925
16926 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16927 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
16928 @@ -178,7 +187,7 @@ unsigned paravirt_patch_insns(void *insn
16929 if (insn_len > len || start == NULL)
16930 insn_len = len;
16931 else
16932 - memcpy(insnbuf, start, insn_len);
16933 + memcpy(insnbuf, ktla_ktva(start), insn_len);
16934
16935 return insn_len;
16936 }
16937 @@ -294,22 +303,22 @@ void arch_flush_lazy_mmu_mode(void)
16938 preempt_enable();
16939 }
16940
16941 -struct pv_info pv_info = {
16942 +struct pv_info pv_info __read_only = {
16943 .name = "bare hardware",
16944 .paravirt_enabled = 0,
16945 .kernel_rpl = 0,
16946 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
16947 };
16948
16949 -struct pv_init_ops pv_init_ops = {
16950 +struct pv_init_ops pv_init_ops __read_only = {
16951 .patch = native_patch,
16952 };
16953
16954 -struct pv_time_ops pv_time_ops = {
16955 +struct pv_time_ops pv_time_ops __read_only = {
16956 .sched_clock = native_sched_clock,
16957 };
16958
16959 -struct pv_irq_ops pv_irq_ops = {
16960 +struct pv_irq_ops pv_irq_ops __read_only = {
16961 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16962 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16963 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16964 @@ -321,7 +330,7 @@ struct pv_irq_ops pv_irq_ops = {
16965 #endif
16966 };
16967
16968 -struct pv_cpu_ops pv_cpu_ops = {
16969 +struct pv_cpu_ops pv_cpu_ops __read_only = {
16970 .cpuid = native_cpuid,
16971 .get_debugreg = native_get_debugreg,
16972 .set_debugreg = native_set_debugreg,
16973 @@ -382,21 +391,26 @@ struct pv_cpu_ops pv_cpu_ops = {
16974 .end_context_switch = paravirt_nop,
16975 };
16976
16977 -struct pv_apic_ops pv_apic_ops = {
16978 +struct pv_apic_ops pv_apic_ops __read_only = {
16979 #ifdef CONFIG_X86_LOCAL_APIC
16980 .startup_ipi_hook = paravirt_nop,
16981 #endif
16982 };
16983
16984 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
16985 +#ifdef CONFIG_X86_32
16986 +#ifdef CONFIG_X86_PAE
16987 +/* 64-bit pagetable entries */
16988 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
16989 +#else
16990 /* 32-bit pagetable entries */
16991 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
16992 +#endif
16993 #else
16994 /* 64-bit pagetable entries */
16995 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16996 #endif
16997
16998 -struct pv_mmu_ops pv_mmu_ops = {
16999 +struct pv_mmu_ops pv_mmu_ops __read_only = {
17000
17001 .read_cr2 = native_read_cr2,
17002 .write_cr2 = native_write_cr2,
17003 @@ -448,6 +462,7 @@ struct pv_mmu_ops pv_mmu_ops = {
17004 .make_pud = PTE_IDENT,
17005
17006 .set_pgd = native_set_pgd,
17007 + .set_pgd_batched = native_set_pgd_batched,
17008 #endif
17009 #endif /* PAGETABLE_LEVELS >= 3 */
17010
17011 @@ -467,6 +482,12 @@ struct pv_mmu_ops pv_mmu_ops = {
17012 },
17013
17014 .set_fixmap = native_set_fixmap,
17015 +
17016 +#ifdef CONFIG_PAX_KERNEXEC
17017 + .pax_open_kernel = native_pax_open_kernel,
17018 + .pax_close_kernel = native_pax_close_kernel,
17019 +#endif
17020 +
17021 };
17022
17023 EXPORT_SYMBOL_GPL(pv_time_ops);
17024 diff -urNp linux-2.6.32.46/arch/x86/kernel/pci-calgary_64.c linux-2.6.32.46/arch/x86/kernel/pci-calgary_64.c
17025 --- linux-2.6.32.46/arch/x86/kernel/pci-calgary_64.c 2011-03-27 14:31:47.000000000 -0400
17026 +++ linux-2.6.32.46/arch/x86/kernel/pci-calgary_64.c 2011-04-17 15:56:46.000000000 -0400
17027 @@ -477,7 +477,7 @@ static void calgary_free_coherent(struct
17028 free_pages((unsigned long)vaddr, get_order(size));
17029 }
17030
17031 -static struct dma_map_ops calgary_dma_ops = {
17032 +static const struct dma_map_ops calgary_dma_ops = {
17033 .alloc_coherent = calgary_alloc_coherent,
17034 .free_coherent = calgary_free_coherent,
17035 .map_sg = calgary_map_sg,
17036 diff -urNp linux-2.6.32.46/arch/x86/kernel/pci-dma.c linux-2.6.32.46/arch/x86/kernel/pci-dma.c
17037 --- linux-2.6.32.46/arch/x86/kernel/pci-dma.c 2011-03-27 14:31:47.000000000 -0400
17038 +++ linux-2.6.32.46/arch/x86/kernel/pci-dma.c 2011-04-17 15:56:46.000000000 -0400
17039 @@ -14,7 +14,7 @@
17040
17041 static int forbid_dac __read_mostly;
17042
17043 -struct dma_map_ops *dma_ops;
17044 +const struct dma_map_ops *dma_ops;
17045 EXPORT_SYMBOL(dma_ops);
17046
17047 static int iommu_sac_force __read_mostly;
17048 @@ -243,7 +243,7 @@ early_param("iommu", iommu_setup);
17049
17050 int dma_supported(struct device *dev, u64 mask)
17051 {
17052 - struct dma_map_ops *ops = get_dma_ops(dev);
17053 + const struct dma_map_ops *ops = get_dma_ops(dev);
17054
17055 #ifdef CONFIG_PCI
17056 if (mask > 0xffffffff && forbid_dac > 0) {
17057 diff -urNp linux-2.6.32.46/arch/x86/kernel/pci-gart_64.c linux-2.6.32.46/arch/x86/kernel/pci-gart_64.c
17058 --- linux-2.6.32.46/arch/x86/kernel/pci-gart_64.c 2011-03-27 14:31:47.000000000 -0400
17059 +++ linux-2.6.32.46/arch/x86/kernel/pci-gart_64.c 2011-04-17 15:56:46.000000000 -0400
17060 @@ -682,7 +682,7 @@ static __init int init_k8_gatt(struct ag
17061 return -1;
17062 }
17063
17064 -static struct dma_map_ops gart_dma_ops = {
17065 +static const struct dma_map_ops gart_dma_ops = {
17066 .map_sg = gart_map_sg,
17067 .unmap_sg = gart_unmap_sg,
17068 .map_page = gart_map_page,
17069 diff -urNp linux-2.6.32.46/arch/x86/kernel/pci-nommu.c linux-2.6.32.46/arch/x86/kernel/pci-nommu.c
17070 --- linux-2.6.32.46/arch/x86/kernel/pci-nommu.c 2011-03-27 14:31:47.000000000 -0400
17071 +++ linux-2.6.32.46/arch/x86/kernel/pci-nommu.c 2011-04-17 15:56:46.000000000 -0400
17072 @@ -94,7 +94,7 @@ static void nommu_sync_sg_for_device(str
17073 flush_write_buffers();
17074 }
17075
17076 -struct dma_map_ops nommu_dma_ops = {
17077 +const struct dma_map_ops nommu_dma_ops = {
17078 .alloc_coherent = dma_generic_alloc_coherent,
17079 .free_coherent = nommu_free_coherent,
17080 .map_sg = nommu_map_sg,
17081 diff -urNp linux-2.6.32.46/arch/x86/kernel/pci-swiotlb.c linux-2.6.32.46/arch/x86/kernel/pci-swiotlb.c
17082 --- linux-2.6.32.46/arch/x86/kernel/pci-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
17083 +++ linux-2.6.32.46/arch/x86/kernel/pci-swiotlb.c 2011-04-17 15:56:46.000000000 -0400
17084 @@ -25,7 +25,7 @@ static void *x86_swiotlb_alloc_coherent(
17085 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
17086 }
17087
17088 -static struct dma_map_ops swiotlb_dma_ops = {
17089 +static const struct dma_map_ops swiotlb_dma_ops = {
17090 .mapping_error = swiotlb_dma_mapping_error,
17091 .alloc_coherent = x86_swiotlb_alloc_coherent,
17092 .free_coherent = swiotlb_free_coherent,
17093 diff -urNp linux-2.6.32.46/arch/x86/kernel/process.c linux-2.6.32.46/arch/x86/kernel/process.c
17094 --- linux-2.6.32.46/arch/x86/kernel/process.c 2011-04-22 19:16:29.000000000 -0400
17095 +++ linux-2.6.32.46/arch/x86/kernel/process.c 2011-08-30 18:19:52.000000000 -0400
17096 @@ -51,16 +51,33 @@ void free_thread_xstate(struct task_stru
17097
17098 void free_thread_info(struct thread_info *ti)
17099 {
17100 - free_thread_xstate(ti->task);
17101 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
17102 }
17103
17104 +static struct kmem_cache *task_struct_cachep;
17105 +
17106 void arch_task_cache_init(void)
17107 {
17108 - task_xstate_cachep =
17109 - kmem_cache_create("task_xstate", xstate_size,
17110 + /* create a slab on which task_structs can be allocated */
17111 + task_struct_cachep =
17112 + kmem_cache_create("task_struct", sizeof(struct task_struct),
17113 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
17114 +
17115 + task_xstate_cachep =
17116 + kmem_cache_create("task_xstate", xstate_size,
17117 __alignof__(union thread_xstate),
17118 - SLAB_PANIC | SLAB_NOTRACK, NULL);
17119 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
17120 +}
17121 +
17122 +struct task_struct *alloc_task_struct(void)
17123 +{
17124 + return kmem_cache_alloc(task_struct_cachep, GFP_KERNEL);
17125 +}
17126 +
17127 +void free_task_struct(struct task_struct *task)
17128 +{
17129 + free_thread_xstate(task);
17130 + kmem_cache_free(task_struct_cachep, task);
17131 }
17132
17133 /*
17134 @@ -73,7 +90,7 @@ void exit_thread(void)
17135 unsigned long *bp = t->io_bitmap_ptr;
17136
17137 if (bp) {
17138 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
17139 + struct tss_struct *tss = init_tss + get_cpu();
17140
17141 t->io_bitmap_ptr = NULL;
17142 clear_thread_flag(TIF_IO_BITMAP);
17143 @@ -93,6 +110,9 @@ void flush_thread(void)
17144
17145 clear_tsk_thread_flag(tsk, TIF_DEBUG);
17146
17147 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17148 + loadsegment(gs, 0);
17149 +#endif
17150 tsk->thread.debugreg0 = 0;
17151 tsk->thread.debugreg1 = 0;
17152 tsk->thread.debugreg2 = 0;
17153 @@ -307,7 +327,7 @@ void default_idle(void)
17154 EXPORT_SYMBOL(default_idle);
17155 #endif
17156
17157 -void stop_this_cpu(void *dummy)
17158 +__noreturn void stop_this_cpu(void *dummy)
17159 {
17160 local_irq_disable();
17161 /*
17162 @@ -568,16 +588,38 @@ static int __init idle_setup(char *str)
17163 }
17164 early_param("idle", idle_setup);
17165
17166 -unsigned long arch_align_stack(unsigned long sp)
17167 +#ifdef CONFIG_PAX_RANDKSTACK
17168 +void pax_randomize_kstack(struct pt_regs *regs)
17169 {
17170 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
17171 - sp -= get_random_int() % 8192;
17172 - return sp & ~0xf;
17173 -}
17174 + struct thread_struct *thread = &current->thread;
17175 + unsigned long time;
17176
17177 -unsigned long arch_randomize_brk(struct mm_struct *mm)
17178 -{
17179 - unsigned long range_end = mm->brk + 0x02000000;
17180 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
17181 + if (!randomize_va_space)
17182 + return;
17183 +
17184 + if (v8086_mode(regs))
17185 + return;
17186 +
17187 + rdtscl(time);
17188 +
17189 + /* P4 seems to return a 0 LSB, ignore it */
17190 +#ifdef CONFIG_MPENTIUM4
17191 + time &= 0x3EUL;
17192 + time <<= 2;
17193 +#elif defined(CONFIG_X86_64)
17194 + time &= 0xFUL;
17195 + time <<= 4;
17196 +#else
17197 + time &= 0x1FUL;
17198 + time <<= 3;
17199 +#endif
17200 +
17201 + thread->sp0 ^= time;
17202 + load_sp0(init_tss + smp_processor_id(), thread);
17203 +
17204 +#ifdef CONFIG_X86_64
17205 + percpu_write(kernel_stack, thread->sp0);
17206 +#endif
17207 }
17208 +#endif
17209
17210 diff -urNp linux-2.6.32.46/arch/x86/kernel/process_32.c linux-2.6.32.46/arch/x86/kernel/process_32.c
17211 --- linux-2.6.32.46/arch/x86/kernel/process_32.c 2011-06-25 12:55:34.000000000 -0400
17212 +++ linux-2.6.32.46/arch/x86/kernel/process_32.c 2011-06-25 12:56:37.000000000 -0400
17213 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __as
17214 unsigned long thread_saved_pc(struct task_struct *tsk)
17215 {
17216 return ((unsigned long *)tsk->thread.sp)[3];
17217 +//XXX return tsk->thread.eip;
17218 }
17219
17220 #ifndef CONFIG_SMP
17221 @@ -129,15 +130,14 @@ void __show_regs(struct pt_regs *regs, i
17222 unsigned short ss, gs;
17223 const char *board;
17224
17225 - if (user_mode_vm(regs)) {
17226 + if (user_mode(regs)) {
17227 sp = regs->sp;
17228 ss = regs->ss & 0xffff;
17229 - gs = get_user_gs(regs);
17230 } else {
17231 sp = (unsigned long) (&regs->sp);
17232 savesegment(ss, ss);
17233 - savesegment(gs, gs);
17234 }
17235 + gs = get_user_gs(regs);
17236
17237 printk("\n");
17238
17239 @@ -210,10 +210,10 @@ int kernel_thread(int (*fn)(void *), voi
17240 regs.bx = (unsigned long) fn;
17241 regs.dx = (unsigned long) arg;
17242
17243 - regs.ds = __USER_DS;
17244 - regs.es = __USER_DS;
17245 + regs.ds = __KERNEL_DS;
17246 + regs.es = __KERNEL_DS;
17247 regs.fs = __KERNEL_PERCPU;
17248 - regs.gs = __KERNEL_STACK_CANARY;
17249 + savesegment(gs, regs.gs);
17250 regs.orig_ax = -1;
17251 regs.ip = (unsigned long) kernel_thread_helper;
17252 regs.cs = __KERNEL_CS | get_kernel_rpl();
17253 @@ -247,13 +247,14 @@ int copy_thread(unsigned long clone_flag
17254 struct task_struct *tsk;
17255 int err;
17256
17257 - childregs = task_pt_regs(p);
17258 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
17259 *childregs = *regs;
17260 childregs->ax = 0;
17261 childregs->sp = sp;
17262
17263 p->thread.sp = (unsigned long) childregs;
17264 p->thread.sp0 = (unsigned long) (childregs+1);
17265 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17266
17267 p->thread.ip = (unsigned long) ret_from_fork;
17268
17269 @@ -345,7 +346,7 @@ __switch_to(struct task_struct *prev_p,
17270 struct thread_struct *prev = &prev_p->thread,
17271 *next = &next_p->thread;
17272 int cpu = smp_processor_id();
17273 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
17274 + struct tss_struct *tss = init_tss + cpu;
17275 bool preload_fpu;
17276
17277 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
17278 @@ -380,6 +381,10 @@ __switch_to(struct task_struct *prev_p,
17279 */
17280 lazy_save_gs(prev->gs);
17281
17282 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17283 + __set_fs(task_thread_info(next_p)->addr_limit);
17284 +#endif
17285 +
17286 /*
17287 * Load the per-thread Thread-Local Storage descriptor.
17288 */
17289 @@ -415,6 +420,9 @@ __switch_to(struct task_struct *prev_p,
17290 */
17291 arch_end_context_switch(next_p);
17292
17293 + percpu_write(current_task, next_p);
17294 + percpu_write(current_tinfo, &next_p->tinfo);
17295 +
17296 if (preload_fpu)
17297 __math_state_restore();
17298
17299 @@ -424,8 +432,6 @@ __switch_to(struct task_struct *prev_p,
17300 if (prev->gs | next->gs)
17301 lazy_load_gs(next->gs);
17302
17303 - percpu_write(current_task, next_p);
17304 -
17305 return prev_p;
17306 }
17307
17308 @@ -495,4 +501,3 @@ unsigned long get_wchan(struct task_stru
17309 } while (count++ < 16);
17310 return 0;
17311 }
17312 -
17313 diff -urNp linux-2.6.32.46/arch/x86/kernel/process_64.c linux-2.6.32.46/arch/x86/kernel/process_64.c
17314 --- linux-2.6.32.46/arch/x86/kernel/process_64.c 2011-06-25 12:55:34.000000000 -0400
17315 +++ linux-2.6.32.46/arch/x86/kernel/process_64.c 2011-06-25 12:56:37.000000000 -0400
17316 @@ -91,7 +91,7 @@ static void __exit_idle(void)
17317 void exit_idle(void)
17318 {
17319 /* idle loop has pid 0 */
17320 - if (current->pid)
17321 + if (task_pid_nr(current))
17322 return;
17323 __exit_idle();
17324 }
17325 @@ -170,7 +170,7 @@ void __show_regs(struct pt_regs *regs, i
17326 if (!board)
17327 board = "";
17328 printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s %s\n",
17329 - current->pid, current->comm, print_tainted(),
17330 + task_pid_nr(current), current->comm, print_tainted(),
17331 init_utsname()->release,
17332 (int)strcspn(init_utsname()->version, " "),
17333 init_utsname()->version, board);
17334 @@ -280,8 +280,7 @@ int copy_thread(unsigned long clone_flag
17335 struct pt_regs *childregs;
17336 struct task_struct *me = current;
17337
17338 - childregs = ((struct pt_regs *)
17339 - (THREAD_SIZE + task_stack_page(p))) - 1;
17340 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
17341 *childregs = *regs;
17342
17343 childregs->ax = 0;
17344 @@ -292,6 +291,7 @@ int copy_thread(unsigned long clone_flag
17345 p->thread.sp = (unsigned long) childregs;
17346 p->thread.sp0 = (unsigned long) (childregs+1);
17347 p->thread.usersp = me->thread.usersp;
17348 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17349
17350 set_tsk_thread_flag(p, TIF_FORK);
17351
17352 @@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p,
17353 struct thread_struct *prev = &prev_p->thread;
17354 struct thread_struct *next = &next_p->thread;
17355 int cpu = smp_processor_id();
17356 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
17357 + struct tss_struct *tss = init_tss + cpu;
17358 unsigned fsindex, gsindex;
17359 bool preload_fpu;
17360
17361 @@ -475,10 +475,9 @@ __switch_to(struct task_struct *prev_p,
17362 prev->usersp = percpu_read(old_rsp);
17363 percpu_write(old_rsp, next->usersp);
17364 percpu_write(current_task, next_p);
17365 + percpu_write(current_tinfo, &next_p->tinfo);
17366
17367 - percpu_write(kernel_stack,
17368 - (unsigned long)task_stack_page(next_p) +
17369 - THREAD_SIZE - KERNEL_STACK_OFFSET);
17370 + percpu_write(kernel_stack, next->sp0);
17371
17372 /*
17373 * Now maybe reload the debug registers and handle I/O bitmaps
17374 @@ -559,12 +558,11 @@ unsigned long get_wchan(struct task_stru
17375 if (!p || p == current || p->state == TASK_RUNNING)
17376 return 0;
17377 stack = (unsigned long)task_stack_page(p);
17378 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
17379 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
17380 return 0;
17381 fp = *(u64 *)(p->thread.sp);
17382 do {
17383 - if (fp < (unsigned long)stack ||
17384 - fp >= (unsigned long)stack+THREAD_SIZE)
17385 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
17386 return 0;
17387 ip = *(u64 *)(fp+8);
17388 if (!in_sched_functions(ip))
17389 diff -urNp linux-2.6.32.46/arch/x86/kernel/ptrace.c linux-2.6.32.46/arch/x86/kernel/ptrace.c
17390 --- linux-2.6.32.46/arch/x86/kernel/ptrace.c 2011-03-27 14:31:47.000000000 -0400
17391 +++ linux-2.6.32.46/arch/x86/kernel/ptrace.c 2011-04-17 15:56:46.000000000 -0400
17392 @@ -925,7 +925,7 @@ static const struct user_regset_view use
17393 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
17394 {
17395 int ret;
17396 - unsigned long __user *datap = (unsigned long __user *)data;
17397 + unsigned long __user *datap = (__force unsigned long __user *)data;
17398
17399 switch (request) {
17400 /* read the word at location addr in the USER area. */
17401 @@ -1012,14 +1012,14 @@ long arch_ptrace(struct task_struct *chi
17402 if (addr < 0)
17403 return -EIO;
17404 ret = do_get_thread_area(child, addr,
17405 - (struct user_desc __user *) data);
17406 + (__force struct user_desc __user *) data);
17407 break;
17408
17409 case PTRACE_SET_THREAD_AREA:
17410 if (addr < 0)
17411 return -EIO;
17412 ret = do_set_thread_area(child, addr,
17413 - (struct user_desc __user *) data, 0);
17414 + (__force struct user_desc __user *) data, 0);
17415 break;
17416 #endif
17417
17418 @@ -1038,12 +1038,12 @@ long arch_ptrace(struct task_struct *chi
17419 #ifdef CONFIG_X86_PTRACE_BTS
17420 case PTRACE_BTS_CONFIG:
17421 ret = ptrace_bts_config
17422 - (child, data, (struct ptrace_bts_config __user *)addr);
17423 + (child, data, (__force struct ptrace_bts_config __user *)addr);
17424 break;
17425
17426 case PTRACE_BTS_STATUS:
17427 ret = ptrace_bts_status
17428 - (child, data, (struct ptrace_bts_config __user *)addr);
17429 + (child, data, (__force struct ptrace_bts_config __user *)addr);
17430 break;
17431
17432 case PTRACE_BTS_SIZE:
17433 @@ -1052,7 +1052,7 @@ long arch_ptrace(struct task_struct *chi
17434
17435 case PTRACE_BTS_GET:
17436 ret = ptrace_bts_read_record
17437 - (child, data, (struct bts_struct __user *) addr);
17438 + (child, data, (__force struct bts_struct __user *) addr);
17439 break;
17440
17441 case PTRACE_BTS_CLEAR:
17442 @@ -1061,7 +1061,7 @@ long arch_ptrace(struct task_struct *chi
17443
17444 case PTRACE_BTS_DRAIN:
17445 ret = ptrace_bts_drain
17446 - (child, data, (struct bts_struct __user *) addr);
17447 + (child, data, (__force struct bts_struct __user *) addr);
17448 break;
17449 #endif /* CONFIG_X86_PTRACE_BTS */
17450
17451 @@ -1450,7 +1450,7 @@ void send_sigtrap(struct task_struct *ts
17452 info.si_code = si_code;
17453
17454 /* User-mode ip? */
17455 - info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
17456 + info.si_addr = user_mode(regs) ? (__force void __user *) regs->ip : NULL;
17457
17458 /* Send us the fake SIGTRAP */
17459 force_sig_info(SIGTRAP, &info, tsk);
17460 @@ -1469,7 +1469,7 @@ void send_sigtrap(struct task_struct *ts
17461 * We must return the syscall number to actually look up in the table.
17462 * This can be -1L to skip running any syscall at all.
17463 */
17464 -asmregparm long syscall_trace_enter(struct pt_regs *regs)
17465 +long syscall_trace_enter(struct pt_regs *regs)
17466 {
17467 long ret = 0;
17468
17469 @@ -1514,7 +1514,7 @@ asmregparm long syscall_trace_enter(stru
17470 return ret ?: regs->orig_ax;
17471 }
17472
17473 -asmregparm void syscall_trace_leave(struct pt_regs *regs)
17474 +void syscall_trace_leave(struct pt_regs *regs)
17475 {
17476 if (unlikely(current->audit_context))
17477 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
17478 diff -urNp linux-2.6.32.46/arch/x86/kernel/reboot.c linux-2.6.32.46/arch/x86/kernel/reboot.c
17479 --- linux-2.6.32.46/arch/x86/kernel/reboot.c 2011-08-09 18:35:28.000000000 -0400
17480 +++ linux-2.6.32.46/arch/x86/kernel/reboot.c 2011-08-09 18:33:59.000000000 -0400
17481 @@ -33,7 +33,7 @@ void (*pm_power_off)(void);
17482 EXPORT_SYMBOL(pm_power_off);
17483
17484 static const struct desc_ptr no_idt = {};
17485 -static int reboot_mode;
17486 +static unsigned short reboot_mode;
17487 enum reboot_type reboot_type = BOOT_KBD;
17488 int reboot_force;
17489
17490 @@ -292,12 +292,12 @@ core_initcall(reboot_init);
17491 controller to pulse the CPU reset line, which is more thorough, but
17492 doesn't work with at least one type of 486 motherboard. It is easy
17493 to stop this code working; hence the copious comments. */
17494 -static const unsigned long long
17495 -real_mode_gdt_entries [3] =
17496 +static struct desc_struct
17497 +real_mode_gdt_entries [3] __read_only =
17498 {
17499 - 0x0000000000000000ULL, /* Null descriptor */
17500 - 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
17501 - 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
17502 + GDT_ENTRY_INIT(0, 0, 0), /* Null descriptor */
17503 + GDT_ENTRY_INIT(0x9b, 0, 0xffff), /* 16-bit real-mode 64k code at 0x00000000 */
17504 + GDT_ENTRY_INIT(0x93, 0x100, 0xffff) /* 16-bit real-mode 64k data at 0x00000100 */
17505 };
17506
17507 static const struct desc_ptr
17508 @@ -346,7 +346,7 @@ static const unsigned char jump_to_bios
17509 * specified by the code and length parameters.
17510 * We assume that length will aways be less that 100!
17511 */
17512 -void machine_real_restart(const unsigned char *code, int length)
17513 +__noreturn void machine_real_restart(const unsigned char *code, unsigned int length)
17514 {
17515 local_irq_disable();
17516
17517 @@ -366,8 +366,8 @@ void machine_real_restart(const unsigned
17518 /* Remap the kernel at virtual address zero, as well as offset zero
17519 from the kernel segment. This assumes the kernel segment starts at
17520 virtual address PAGE_OFFSET. */
17521 - memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17522 - sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
17523 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17524 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
17525
17526 /*
17527 * Use `swapper_pg_dir' as our page directory.
17528 @@ -379,16 +379,15 @@ void machine_real_restart(const unsigned
17529 boot)". This seems like a fairly standard thing that gets set by
17530 REBOOT.COM programs, and the previous reset routine did this
17531 too. */
17532 - *((unsigned short *)0x472) = reboot_mode;
17533 + *(unsigned short *)(__va(0x472)) = reboot_mode;
17534
17535 /* For the switch to real mode, copy some code to low memory. It has
17536 to be in the first 64k because it is running in 16-bit mode, and it
17537 has to have the same physical and virtual address, because it turns
17538 off paging. Copy it near the end of the first page, out of the way
17539 of BIOS variables. */
17540 - memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
17541 - real_mode_switch, sizeof (real_mode_switch));
17542 - memcpy((void *)(0x1000 - 100), code, length);
17543 + memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
17544 + memcpy(__va(0x1000 - 100), code, length);
17545
17546 /* Set up the IDT for real mode. */
17547 load_idt(&real_mode_idt);
17548 @@ -416,6 +415,7 @@ void machine_real_restart(const unsigned
17549 __asm__ __volatile__ ("ljmp $0x0008,%0"
17550 :
17551 : "i" ((void *)(0x1000 - sizeof (real_mode_switch) - 100)));
17552 + do { } while (1);
17553 }
17554 #ifdef CONFIG_APM_MODULE
17555 EXPORT_SYMBOL(machine_real_restart);
17556 @@ -544,7 +544,7 @@ void __attribute__((weak)) mach_reboot_f
17557 {
17558 }
17559
17560 -static void native_machine_emergency_restart(void)
17561 +__noreturn static void native_machine_emergency_restart(void)
17562 {
17563 int i;
17564
17565 @@ -659,13 +659,13 @@ void native_machine_shutdown(void)
17566 #endif
17567 }
17568
17569 -static void __machine_emergency_restart(int emergency)
17570 +static __noreturn void __machine_emergency_restart(int emergency)
17571 {
17572 reboot_emergency = emergency;
17573 machine_ops.emergency_restart();
17574 }
17575
17576 -static void native_machine_restart(char *__unused)
17577 +static __noreturn void native_machine_restart(char *__unused)
17578 {
17579 printk("machine restart\n");
17580
17581 @@ -674,7 +674,7 @@ static void native_machine_restart(char
17582 __machine_emergency_restart(0);
17583 }
17584
17585 -static void native_machine_halt(void)
17586 +static __noreturn void native_machine_halt(void)
17587 {
17588 /* stop other cpus and apics */
17589 machine_shutdown();
17590 @@ -685,7 +685,7 @@ static void native_machine_halt(void)
17591 stop_this_cpu(NULL);
17592 }
17593
17594 -static void native_machine_power_off(void)
17595 +__noreturn static void native_machine_power_off(void)
17596 {
17597 if (pm_power_off) {
17598 if (!reboot_force)
17599 @@ -694,6 +694,7 @@ static void native_machine_power_off(voi
17600 }
17601 /* a fallback in case there is no PM info available */
17602 tboot_shutdown(TB_SHUTDOWN_HALT);
17603 + do { } while (1);
17604 }
17605
17606 struct machine_ops machine_ops = {
17607 diff -urNp linux-2.6.32.46/arch/x86/kernel/setup.c linux-2.6.32.46/arch/x86/kernel/setup.c
17608 --- linux-2.6.32.46/arch/x86/kernel/setup.c 2011-04-17 17:00:52.000000000 -0400
17609 +++ linux-2.6.32.46/arch/x86/kernel/setup.c 2011-04-17 17:03:05.000000000 -0400
17610 @@ -783,14 +783,14 @@ void __init setup_arch(char **cmdline_p)
17611
17612 if (!boot_params.hdr.root_flags)
17613 root_mountflags &= ~MS_RDONLY;
17614 - init_mm.start_code = (unsigned long) _text;
17615 - init_mm.end_code = (unsigned long) _etext;
17616 + init_mm.start_code = ktla_ktva((unsigned long) _text);
17617 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
17618 init_mm.end_data = (unsigned long) _edata;
17619 init_mm.brk = _brk_end;
17620
17621 - code_resource.start = virt_to_phys(_text);
17622 - code_resource.end = virt_to_phys(_etext)-1;
17623 - data_resource.start = virt_to_phys(_etext);
17624 + code_resource.start = virt_to_phys(ktla_ktva(_text));
17625 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
17626 + data_resource.start = virt_to_phys(_sdata);
17627 data_resource.end = virt_to_phys(_edata)-1;
17628 bss_resource.start = virt_to_phys(&__bss_start);
17629 bss_resource.end = virt_to_phys(&__bss_stop)-1;
17630 diff -urNp linux-2.6.32.46/arch/x86/kernel/setup_percpu.c linux-2.6.32.46/arch/x86/kernel/setup_percpu.c
17631 --- linux-2.6.32.46/arch/x86/kernel/setup_percpu.c 2011-03-27 14:31:47.000000000 -0400
17632 +++ linux-2.6.32.46/arch/x86/kernel/setup_percpu.c 2011-06-04 20:36:29.000000000 -0400
17633 @@ -25,19 +25,17 @@
17634 # define DBG(x...)
17635 #endif
17636
17637 -DEFINE_PER_CPU(int, cpu_number);
17638 +#ifdef CONFIG_SMP
17639 +DEFINE_PER_CPU(unsigned int, cpu_number);
17640 EXPORT_PER_CPU_SYMBOL(cpu_number);
17641 +#endif
17642
17643 -#ifdef CONFIG_X86_64
17644 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
17645 -#else
17646 -#define BOOT_PERCPU_OFFSET 0
17647 -#endif
17648
17649 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
17650 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
17651
17652 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
17653 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
17654 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
17655 };
17656 EXPORT_SYMBOL(__per_cpu_offset);
17657 @@ -159,10 +157,10 @@ static inline void setup_percpu_segment(
17658 {
17659 #ifdef CONFIG_X86_32
17660 struct desc_struct gdt;
17661 + unsigned long base = per_cpu_offset(cpu);
17662
17663 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
17664 - 0x2 | DESCTYPE_S, 0x8);
17665 - gdt.s = 1;
17666 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
17667 + 0x83 | DESCTYPE_S, 0xC);
17668 write_gdt_entry(get_cpu_gdt_table(cpu),
17669 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
17670 #endif
17671 @@ -212,6 +210,11 @@ void __init setup_per_cpu_areas(void)
17672 /* alrighty, percpu areas up and running */
17673 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
17674 for_each_possible_cpu(cpu) {
17675 +#ifdef CONFIG_CC_STACKPROTECTOR
17676 +#ifdef CONFIG_X86_32
17677 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
17678 +#endif
17679 +#endif
17680 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
17681 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
17682 per_cpu(cpu_number, cpu) = cpu;
17683 @@ -239,6 +242,12 @@ void __init setup_per_cpu_areas(void)
17684 early_per_cpu_map(x86_cpu_to_node_map, cpu);
17685 #endif
17686 #endif
17687 +#ifdef CONFIG_CC_STACKPROTECTOR
17688 +#ifdef CONFIG_X86_32
17689 + if (!cpu)
17690 + per_cpu(stack_canary.canary, cpu) = canary;
17691 +#endif
17692 +#endif
17693 /*
17694 * Up to this point, the boot CPU has been using .data.init
17695 * area. Reload any changed state for the boot CPU.
17696 diff -urNp linux-2.6.32.46/arch/x86/kernel/signal.c linux-2.6.32.46/arch/x86/kernel/signal.c
17697 --- linux-2.6.32.46/arch/x86/kernel/signal.c 2011-03-27 14:31:47.000000000 -0400
17698 +++ linux-2.6.32.46/arch/x86/kernel/signal.c 2011-05-22 23:02:03.000000000 -0400
17699 @@ -197,7 +197,7 @@ static unsigned long align_sigframe(unsi
17700 * Align the stack pointer according to the i386 ABI,
17701 * i.e. so that on function entry ((sp + 4) & 15) == 0.
17702 */
17703 - sp = ((sp + 4) & -16ul) - 4;
17704 + sp = ((sp - 12) & -16ul) - 4;
17705 #else /* !CONFIG_X86_32 */
17706 sp = round_down(sp, 16) - 8;
17707 #endif
17708 @@ -248,11 +248,11 @@ get_sigframe(struct k_sigaction *ka, str
17709 * Return an always-bogus address instead so we will die with SIGSEGV.
17710 */
17711 if (onsigstack && !likely(on_sig_stack(sp)))
17712 - return (void __user *)-1L;
17713 + return (__force void __user *)-1L;
17714
17715 /* save i387 state */
17716 if (used_math() && save_i387_xstate(*fpstate) < 0)
17717 - return (void __user *)-1L;
17718 + return (__force void __user *)-1L;
17719
17720 return (void __user *)sp;
17721 }
17722 @@ -307,9 +307,9 @@ __setup_frame(int sig, struct k_sigactio
17723 }
17724
17725 if (current->mm->context.vdso)
17726 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17727 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17728 else
17729 - restorer = &frame->retcode;
17730 + restorer = (void __user *)&frame->retcode;
17731 if (ka->sa.sa_flags & SA_RESTORER)
17732 restorer = ka->sa.sa_restorer;
17733
17734 @@ -323,7 +323,7 @@ __setup_frame(int sig, struct k_sigactio
17735 * reasons and because gdb uses it as a signature to notice
17736 * signal handler stack frames.
17737 */
17738 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
17739 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
17740
17741 if (err)
17742 return -EFAULT;
17743 @@ -377,7 +377,10 @@ static int __setup_rt_frame(int sig, str
17744 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
17745
17746 /* Set up to return from userspace. */
17747 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17748 + if (current->mm->context.vdso)
17749 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17750 + else
17751 + restorer = (void __user *)&frame->retcode;
17752 if (ka->sa.sa_flags & SA_RESTORER)
17753 restorer = ka->sa.sa_restorer;
17754 put_user_ex(restorer, &frame->pretcode);
17755 @@ -389,7 +392,7 @@ static int __setup_rt_frame(int sig, str
17756 * reasons and because gdb uses it as a signature to notice
17757 * signal handler stack frames.
17758 */
17759 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
17760 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
17761 } put_user_catch(err);
17762
17763 if (err)
17764 @@ -782,6 +785,8 @@ static void do_signal(struct pt_regs *re
17765 int signr;
17766 sigset_t *oldset;
17767
17768 + pax_track_stack();
17769 +
17770 /*
17771 * We want the common case to go fast, which is why we may in certain
17772 * cases get here from kernel mode. Just return without doing anything
17773 @@ -789,7 +794,7 @@ static void do_signal(struct pt_regs *re
17774 * X86_32: vm86 regs switched out by assembly code before reaching
17775 * here, so testing against kernel CS suffices.
17776 */
17777 - if (!user_mode(regs))
17778 + if (!user_mode_novm(regs))
17779 return;
17780
17781 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
17782 diff -urNp linux-2.6.32.46/arch/x86/kernel/smpboot.c linux-2.6.32.46/arch/x86/kernel/smpboot.c
17783 --- linux-2.6.32.46/arch/x86/kernel/smpboot.c 2011-03-27 14:31:47.000000000 -0400
17784 +++ linux-2.6.32.46/arch/x86/kernel/smpboot.c 2011-07-01 19:10:03.000000000 -0400
17785 @@ -94,14 +94,14 @@ static DEFINE_PER_CPU(struct task_struct
17786 */
17787 static DEFINE_MUTEX(x86_cpu_hotplug_driver_mutex);
17788
17789 -void cpu_hotplug_driver_lock()
17790 +void cpu_hotplug_driver_lock(void)
17791 {
17792 - mutex_lock(&x86_cpu_hotplug_driver_mutex);
17793 + mutex_lock(&x86_cpu_hotplug_driver_mutex);
17794 }
17795
17796 -void cpu_hotplug_driver_unlock()
17797 +void cpu_hotplug_driver_unlock(void)
17798 {
17799 - mutex_unlock(&x86_cpu_hotplug_driver_mutex);
17800 + mutex_unlock(&x86_cpu_hotplug_driver_mutex);
17801 }
17802
17803 ssize_t arch_cpu_probe(const char *buf, size_t count) { return -1; }
17804 @@ -625,7 +625,7 @@ wakeup_secondary_cpu_via_init(int phys_a
17805 * target processor state.
17806 */
17807 startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
17808 - (unsigned long)stack_start.sp);
17809 + stack_start);
17810
17811 /*
17812 * Run STARTUP IPI loop.
17813 @@ -743,6 +743,7 @@ static int __cpuinit do_boot_cpu(int api
17814 set_idle_for_cpu(cpu, c_idle.idle);
17815 do_rest:
17816 per_cpu(current_task, cpu) = c_idle.idle;
17817 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
17818 #ifdef CONFIG_X86_32
17819 /* Stack for startup_32 can be just as for start_secondary onwards */
17820 irq_ctx_init(cpu);
17821 @@ -750,13 +751,15 @@ do_rest:
17822 #else
17823 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
17824 initial_gs = per_cpu_offset(cpu);
17825 - per_cpu(kernel_stack, cpu) =
17826 - (unsigned long)task_stack_page(c_idle.idle) -
17827 - KERNEL_STACK_OFFSET + THREAD_SIZE;
17828 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
17829 #endif
17830 +
17831 + pax_open_kernel();
17832 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17833 + pax_close_kernel();
17834 +
17835 initial_code = (unsigned long)start_secondary;
17836 - stack_start.sp = (void *) c_idle.idle->thread.sp;
17837 + stack_start = c_idle.idle->thread.sp;
17838
17839 /* start_ip had better be page-aligned! */
17840 start_ip = setup_trampoline();
17841 @@ -891,6 +894,12 @@ int __cpuinit native_cpu_up(unsigned int
17842
17843 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
17844
17845 +#ifdef CONFIG_PAX_PER_CPU_PGD
17846 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
17847 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17848 + KERNEL_PGD_PTRS);
17849 +#endif
17850 +
17851 err = do_boot_cpu(apicid, cpu);
17852
17853 if (err) {
17854 diff -urNp linux-2.6.32.46/arch/x86/kernel/step.c linux-2.6.32.46/arch/x86/kernel/step.c
17855 --- linux-2.6.32.46/arch/x86/kernel/step.c 2011-03-27 14:31:47.000000000 -0400
17856 +++ linux-2.6.32.46/arch/x86/kernel/step.c 2011-04-17 15:56:46.000000000 -0400
17857 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
17858 struct desc_struct *desc;
17859 unsigned long base;
17860
17861 - seg &= ~7UL;
17862 + seg >>= 3;
17863
17864 mutex_lock(&child->mm->context.lock);
17865 - if (unlikely((seg >> 3) >= child->mm->context.size))
17866 + if (unlikely(seg >= child->mm->context.size))
17867 addr = -1L; /* bogus selector, access would fault */
17868 else {
17869 desc = child->mm->context.ldt + seg;
17870 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
17871 addr += base;
17872 }
17873 mutex_unlock(&child->mm->context.lock);
17874 - }
17875 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
17876 + addr = ktla_ktva(addr);
17877
17878 return addr;
17879 }
17880 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
17881 unsigned char opcode[15];
17882 unsigned long addr = convert_ip_to_linear(child, regs);
17883
17884 + if (addr == -EINVAL)
17885 + return 0;
17886 +
17887 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17888 for (i = 0; i < copied; i++) {
17889 switch (opcode[i]) {
17890 @@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
17891
17892 #ifdef CONFIG_X86_64
17893 case 0x40 ... 0x4f:
17894 - if (regs->cs != __USER_CS)
17895 + if ((regs->cs & 0xffff) != __USER_CS)
17896 /* 32-bit mode: register increment */
17897 return 0;
17898 /* 64-bit mode: REX prefix */
17899 diff -urNp linux-2.6.32.46/arch/x86/kernel/sys_i386_32.c linux-2.6.32.46/arch/x86/kernel/sys_i386_32.c
17900 --- linux-2.6.32.46/arch/x86/kernel/sys_i386_32.c 2011-03-27 14:31:47.000000000 -0400
17901 +++ linux-2.6.32.46/arch/x86/kernel/sys_i386_32.c 2011-04-17 15:56:46.000000000 -0400
17902 @@ -24,6 +24,21 @@
17903
17904 #include <asm/syscalls.h>
17905
17906 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17907 +{
17908 + unsigned long pax_task_size = TASK_SIZE;
17909 +
17910 +#ifdef CONFIG_PAX_SEGMEXEC
17911 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17912 + pax_task_size = SEGMEXEC_TASK_SIZE;
17913 +#endif
17914 +
17915 + if (len > pax_task_size || addr > pax_task_size - len)
17916 + return -EINVAL;
17917 +
17918 + return 0;
17919 +}
17920 +
17921 /*
17922 * Perform the select(nd, in, out, ex, tv) and mmap() system
17923 * calls. Linux/i386 didn't use to be able to handle more than
17924 @@ -58,6 +73,212 @@ out:
17925 return err;
17926 }
17927
17928 +unsigned long
17929 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
17930 + unsigned long len, unsigned long pgoff, unsigned long flags)
17931 +{
17932 + struct mm_struct *mm = current->mm;
17933 + struct vm_area_struct *vma;
17934 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17935 +
17936 +#ifdef CONFIG_PAX_SEGMEXEC
17937 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17938 + pax_task_size = SEGMEXEC_TASK_SIZE;
17939 +#endif
17940 +
17941 + pax_task_size -= PAGE_SIZE;
17942 +
17943 + if (len > pax_task_size)
17944 + return -ENOMEM;
17945 +
17946 + if (flags & MAP_FIXED)
17947 + return addr;
17948 +
17949 +#ifdef CONFIG_PAX_RANDMMAP
17950 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17951 +#endif
17952 +
17953 + if (addr) {
17954 + addr = PAGE_ALIGN(addr);
17955 + if (pax_task_size - len >= addr) {
17956 + vma = find_vma(mm, addr);
17957 + if (check_heap_stack_gap(vma, addr, len))
17958 + return addr;
17959 + }
17960 + }
17961 + if (len > mm->cached_hole_size) {
17962 + start_addr = addr = mm->free_area_cache;
17963 + } else {
17964 + start_addr = addr = mm->mmap_base;
17965 + mm->cached_hole_size = 0;
17966 + }
17967 +
17968 +#ifdef CONFIG_PAX_PAGEEXEC
17969 + if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17970 + start_addr = 0x00110000UL;
17971 +
17972 +#ifdef CONFIG_PAX_RANDMMAP
17973 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17974 + start_addr += mm->delta_mmap & 0x03FFF000UL;
17975 +#endif
17976 +
17977 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17978 + start_addr = addr = mm->mmap_base;
17979 + else
17980 + addr = start_addr;
17981 + }
17982 +#endif
17983 +
17984 +full_search:
17985 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17986 + /* At this point: (!vma || addr < vma->vm_end). */
17987 + if (pax_task_size - len < addr) {
17988 + /*
17989 + * Start a new search - just in case we missed
17990 + * some holes.
17991 + */
17992 + if (start_addr != mm->mmap_base) {
17993 + start_addr = addr = mm->mmap_base;
17994 + mm->cached_hole_size = 0;
17995 + goto full_search;
17996 + }
17997 + return -ENOMEM;
17998 + }
17999 + if (check_heap_stack_gap(vma, addr, len))
18000 + break;
18001 + if (addr + mm->cached_hole_size < vma->vm_start)
18002 + mm->cached_hole_size = vma->vm_start - addr;
18003 + addr = vma->vm_end;
18004 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
18005 + start_addr = addr = mm->mmap_base;
18006 + mm->cached_hole_size = 0;
18007 + goto full_search;
18008 + }
18009 + }
18010 +
18011 + /*
18012 + * Remember the place where we stopped the search:
18013 + */
18014 + mm->free_area_cache = addr + len;
18015 + return addr;
18016 +}
18017 +
18018 +unsigned long
18019 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18020 + const unsigned long len, const unsigned long pgoff,
18021 + const unsigned long flags)
18022 +{
18023 + struct vm_area_struct *vma;
18024 + struct mm_struct *mm = current->mm;
18025 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
18026 +
18027 +#ifdef CONFIG_PAX_SEGMEXEC
18028 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18029 + pax_task_size = SEGMEXEC_TASK_SIZE;
18030 +#endif
18031 +
18032 + pax_task_size -= PAGE_SIZE;
18033 +
18034 + /* requested length too big for entire address space */
18035 + if (len > pax_task_size)
18036 + return -ENOMEM;
18037 +
18038 + if (flags & MAP_FIXED)
18039 + return addr;
18040 +
18041 +#ifdef CONFIG_PAX_PAGEEXEC
18042 + if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
18043 + goto bottomup;
18044 +#endif
18045 +
18046 +#ifdef CONFIG_PAX_RANDMMAP
18047 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18048 +#endif
18049 +
18050 + /* requesting a specific address */
18051 + if (addr) {
18052 + addr = PAGE_ALIGN(addr);
18053 + if (pax_task_size - len >= addr) {
18054 + vma = find_vma(mm, addr);
18055 + if (check_heap_stack_gap(vma, addr, len))
18056 + return addr;
18057 + }
18058 + }
18059 +
18060 + /* check if free_area_cache is useful for us */
18061 + if (len <= mm->cached_hole_size) {
18062 + mm->cached_hole_size = 0;
18063 + mm->free_area_cache = mm->mmap_base;
18064 + }
18065 +
18066 + /* either no address requested or can't fit in requested address hole */
18067 + addr = mm->free_area_cache;
18068 +
18069 + /* make sure it can fit in the remaining address space */
18070 + if (addr > len) {
18071 + vma = find_vma(mm, addr-len);
18072 + if (check_heap_stack_gap(vma, addr - len, len))
18073 + /* remember the address as a hint for next time */
18074 + return (mm->free_area_cache = addr-len);
18075 + }
18076 +
18077 + if (mm->mmap_base < len)
18078 + goto bottomup;
18079 +
18080 + addr = mm->mmap_base-len;
18081 +
18082 + do {
18083 + /*
18084 + * Lookup failure means no vma is above this address,
18085 + * else if new region fits below vma->vm_start,
18086 + * return with success:
18087 + */
18088 + vma = find_vma(mm, addr);
18089 + if (check_heap_stack_gap(vma, addr, len))
18090 + /* remember the address as a hint for next time */
18091 + return (mm->free_area_cache = addr);
18092 +
18093 + /* remember the largest hole we saw so far */
18094 + if (addr + mm->cached_hole_size < vma->vm_start)
18095 + mm->cached_hole_size = vma->vm_start - addr;
18096 +
18097 + /* try just below the current vma->vm_start */
18098 + addr = skip_heap_stack_gap(vma, len);
18099 + } while (!IS_ERR_VALUE(addr));
18100 +
18101 +bottomup:
18102 + /*
18103 + * A failed mmap() very likely causes application failure,
18104 + * so fall back to the bottom-up function here. This scenario
18105 + * can happen with large stack limits and large mmap()
18106 + * allocations.
18107 + */
18108 +
18109 +#ifdef CONFIG_PAX_SEGMEXEC
18110 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18111 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
18112 + else
18113 +#endif
18114 +
18115 + mm->mmap_base = TASK_UNMAPPED_BASE;
18116 +
18117 +#ifdef CONFIG_PAX_RANDMMAP
18118 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18119 + mm->mmap_base += mm->delta_mmap;
18120 +#endif
18121 +
18122 + mm->free_area_cache = mm->mmap_base;
18123 + mm->cached_hole_size = ~0UL;
18124 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18125 + /*
18126 + * Restore the topdown base:
18127 + */
18128 + mm->mmap_base = base;
18129 + mm->free_area_cache = base;
18130 + mm->cached_hole_size = ~0UL;
18131 +
18132 + return addr;
18133 +}
18134
18135 struct sel_arg_struct {
18136 unsigned long n;
18137 @@ -93,7 +314,7 @@ asmlinkage int sys_ipc(uint call, int fi
18138 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
18139 case SEMTIMEDOP:
18140 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
18141 - (const struct timespec __user *)fifth);
18142 + (__force const struct timespec __user *)fifth);
18143
18144 case SEMGET:
18145 return sys_semget(first, second, third);
18146 @@ -140,7 +361,7 @@ asmlinkage int sys_ipc(uint call, int fi
18147 ret = do_shmat(first, (char __user *) ptr, second, &raddr);
18148 if (ret)
18149 return ret;
18150 - return put_user(raddr, (ulong __user *) third);
18151 + return put_user(raddr, (__force ulong __user *) third);
18152 }
18153 case 1: /* iBCS2 emulator entry point */
18154 if (!segment_eq(get_fs(), get_ds()))
18155 @@ -207,17 +428,3 @@ asmlinkage int sys_olduname(struct oldol
18156
18157 return error;
18158 }
18159 -
18160 -
18161 -/*
18162 - * Do a system call from kernel instead of calling sys_execve so we
18163 - * end up with proper pt_regs.
18164 - */
18165 -int kernel_execve(const char *filename, char *const argv[], char *const envp[])
18166 -{
18167 - long __res;
18168 - asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
18169 - : "=a" (__res)
18170 - : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
18171 - return __res;
18172 -}
18173 diff -urNp linux-2.6.32.46/arch/x86/kernel/sys_x86_64.c linux-2.6.32.46/arch/x86/kernel/sys_x86_64.c
18174 --- linux-2.6.32.46/arch/x86/kernel/sys_x86_64.c 2011-03-27 14:31:47.000000000 -0400
18175 +++ linux-2.6.32.46/arch/x86/kernel/sys_x86_64.c 2011-04-17 15:56:46.000000000 -0400
18176 @@ -32,8 +32,8 @@ out:
18177 return error;
18178 }
18179
18180 -static void find_start_end(unsigned long flags, unsigned long *begin,
18181 - unsigned long *end)
18182 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
18183 + unsigned long *begin, unsigned long *end)
18184 {
18185 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
18186 unsigned long new_begin;
18187 @@ -52,7 +52,7 @@ static void find_start_end(unsigned long
18188 *begin = new_begin;
18189 }
18190 } else {
18191 - *begin = TASK_UNMAPPED_BASE;
18192 + *begin = mm->mmap_base;
18193 *end = TASK_SIZE;
18194 }
18195 }
18196 @@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
18197 if (flags & MAP_FIXED)
18198 return addr;
18199
18200 - find_start_end(flags, &begin, &end);
18201 + find_start_end(mm, flags, &begin, &end);
18202
18203 if (len > end)
18204 return -ENOMEM;
18205
18206 +#ifdef CONFIG_PAX_RANDMMAP
18207 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18208 +#endif
18209 +
18210 if (addr) {
18211 addr = PAGE_ALIGN(addr);
18212 vma = find_vma(mm, addr);
18213 - if (end - len >= addr &&
18214 - (!vma || addr + len <= vma->vm_start))
18215 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
18216 return addr;
18217 }
18218 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
18219 @@ -106,7 +109,7 @@ full_search:
18220 }
18221 return -ENOMEM;
18222 }
18223 - if (!vma || addr + len <= vma->vm_start) {
18224 + if (check_heap_stack_gap(vma, addr, len)) {
18225 /*
18226 * Remember the place where we stopped the search:
18227 */
18228 @@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
18229 {
18230 struct vm_area_struct *vma;
18231 struct mm_struct *mm = current->mm;
18232 - unsigned long addr = addr0;
18233 + unsigned long base = mm->mmap_base, addr = addr0;
18234
18235 /* requested length too big for entire address space */
18236 if (len > TASK_SIZE)
18237 @@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
18238 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
18239 goto bottomup;
18240
18241 +#ifdef CONFIG_PAX_RANDMMAP
18242 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18243 +#endif
18244 +
18245 /* requesting a specific address */
18246 if (addr) {
18247 addr = PAGE_ALIGN(addr);
18248 - vma = find_vma(mm, addr);
18249 - if (TASK_SIZE - len >= addr &&
18250 - (!vma || addr + len <= vma->vm_start))
18251 - return addr;
18252 + if (TASK_SIZE - len >= addr) {
18253 + vma = find_vma(mm, addr);
18254 + if (check_heap_stack_gap(vma, addr, len))
18255 + return addr;
18256 + }
18257 }
18258
18259 /* check if free_area_cache is useful for us */
18260 @@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
18261 /* make sure it can fit in the remaining address space */
18262 if (addr > len) {
18263 vma = find_vma(mm, addr-len);
18264 - if (!vma || addr <= vma->vm_start)
18265 + if (check_heap_stack_gap(vma, addr - len, len))
18266 /* remember the address as a hint for next time */
18267 return mm->free_area_cache = addr-len;
18268 }
18269 @@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
18270 * return with success:
18271 */
18272 vma = find_vma(mm, addr);
18273 - if (!vma || addr+len <= vma->vm_start)
18274 + if (check_heap_stack_gap(vma, addr, len))
18275 /* remember the address as a hint for next time */
18276 return mm->free_area_cache = addr;
18277
18278 @@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
18279 mm->cached_hole_size = vma->vm_start - addr;
18280
18281 /* try just below the current vma->vm_start */
18282 - addr = vma->vm_start-len;
18283 - } while (len < vma->vm_start);
18284 + addr = skip_heap_stack_gap(vma, len);
18285 + } while (!IS_ERR_VALUE(addr));
18286
18287 bottomup:
18288 /*
18289 @@ -198,13 +206,21 @@ bottomup:
18290 * can happen with large stack limits and large mmap()
18291 * allocations.
18292 */
18293 + mm->mmap_base = TASK_UNMAPPED_BASE;
18294 +
18295 +#ifdef CONFIG_PAX_RANDMMAP
18296 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18297 + mm->mmap_base += mm->delta_mmap;
18298 +#endif
18299 +
18300 + mm->free_area_cache = mm->mmap_base;
18301 mm->cached_hole_size = ~0UL;
18302 - mm->free_area_cache = TASK_UNMAPPED_BASE;
18303 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18304 /*
18305 * Restore the topdown base:
18306 */
18307 - mm->free_area_cache = mm->mmap_base;
18308 + mm->mmap_base = base;
18309 + mm->free_area_cache = base;
18310 mm->cached_hole_size = ~0UL;
18311
18312 return addr;
18313 diff -urNp linux-2.6.32.46/arch/x86/kernel/syscall_table_32.S linux-2.6.32.46/arch/x86/kernel/syscall_table_32.S
18314 --- linux-2.6.32.46/arch/x86/kernel/syscall_table_32.S 2011-03-27 14:31:47.000000000 -0400
18315 +++ linux-2.6.32.46/arch/x86/kernel/syscall_table_32.S 2011-04-17 15:56:46.000000000 -0400
18316 @@ -1,3 +1,4 @@
18317 +.section .rodata,"a",@progbits
18318 ENTRY(sys_call_table)
18319 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
18320 .long sys_exit
18321 diff -urNp linux-2.6.32.46/arch/x86/kernel/tboot.c linux-2.6.32.46/arch/x86/kernel/tboot.c
18322 --- linux-2.6.32.46/arch/x86/kernel/tboot.c 2011-03-27 14:31:47.000000000 -0400
18323 +++ linux-2.6.32.46/arch/x86/kernel/tboot.c 2011-05-22 23:02:03.000000000 -0400
18324 @@ -216,7 +216,7 @@ static int tboot_setup_sleep(void)
18325
18326 void tboot_shutdown(u32 shutdown_type)
18327 {
18328 - void (*shutdown)(void);
18329 + void (* __noreturn shutdown)(void);
18330
18331 if (!tboot_enabled())
18332 return;
18333 @@ -238,7 +238,7 @@ void tboot_shutdown(u32 shutdown_type)
18334
18335 switch_to_tboot_pt();
18336
18337 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
18338 + shutdown = (void *)tboot->shutdown_entry;
18339 shutdown();
18340
18341 /* should not reach here */
18342 @@ -295,7 +295,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
18343 tboot_shutdown(acpi_shutdown_map[sleep_state]);
18344 }
18345
18346 -static atomic_t ap_wfs_count;
18347 +static atomic_unchecked_t ap_wfs_count;
18348
18349 static int tboot_wait_for_aps(int num_aps)
18350 {
18351 @@ -319,9 +319,9 @@ static int __cpuinit tboot_cpu_callback(
18352 {
18353 switch (action) {
18354 case CPU_DYING:
18355 - atomic_inc(&ap_wfs_count);
18356 + atomic_inc_unchecked(&ap_wfs_count);
18357 if (num_online_cpus() == 1)
18358 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
18359 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
18360 return NOTIFY_BAD;
18361 break;
18362 }
18363 @@ -340,7 +340,7 @@ static __init int tboot_late_init(void)
18364
18365 tboot_create_trampoline();
18366
18367 - atomic_set(&ap_wfs_count, 0);
18368 + atomic_set_unchecked(&ap_wfs_count, 0);
18369 register_hotcpu_notifier(&tboot_cpu_notifier);
18370 return 0;
18371 }
18372 diff -urNp linux-2.6.32.46/arch/x86/kernel/time.c linux-2.6.32.46/arch/x86/kernel/time.c
18373 --- linux-2.6.32.46/arch/x86/kernel/time.c 2011-03-27 14:31:47.000000000 -0400
18374 +++ linux-2.6.32.46/arch/x86/kernel/time.c 2011-04-17 15:56:46.000000000 -0400
18375 @@ -26,17 +26,13 @@
18376 int timer_ack;
18377 #endif
18378
18379 -#ifdef CONFIG_X86_64
18380 -volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
18381 -#endif
18382 -
18383 unsigned long profile_pc(struct pt_regs *regs)
18384 {
18385 unsigned long pc = instruction_pointer(regs);
18386
18387 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
18388 + if (!user_mode(regs) && in_lock_functions(pc)) {
18389 #ifdef CONFIG_FRAME_POINTER
18390 - return *(unsigned long *)(regs->bp + sizeof(long));
18391 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
18392 #else
18393 unsigned long *sp =
18394 (unsigned long *)kernel_stack_pointer(regs);
18395 @@ -45,11 +41,17 @@ unsigned long profile_pc(struct pt_regs
18396 * or above a saved flags. Eflags has bits 22-31 zero,
18397 * kernel addresses don't.
18398 */
18399 +
18400 +#ifdef CONFIG_PAX_KERNEXEC
18401 + return ktla_ktva(sp[0]);
18402 +#else
18403 if (sp[0] >> 22)
18404 return sp[0];
18405 if (sp[1] >> 22)
18406 return sp[1];
18407 #endif
18408 +
18409 +#endif
18410 }
18411 return pc;
18412 }
18413 diff -urNp linux-2.6.32.46/arch/x86/kernel/tls.c linux-2.6.32.46/arch/x86/kernel/tls.c
18414 --- linux-2.6.32.46/arch/x86/kernel/tls.c 2011-03-27 14:31:47.000000000 -0400
18415 +++ linux-2.6.32.46/arch/x86/kernel/tls.c 2011-04-17 15:56:46.000000000 -0400
18416 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
18417 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
18418 return -EINVAL;
18419
18420 +#ifdef CONFIG_PAX_SEGMEXEC
18421 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
18422 + return -EINVAL;
18423 +#endif
18424 +
18425 set_tls_desc(p, idx, &info, 1);
18426
18427 return 0;
18428 diff -urNp linux-2.6.32.46/arch/x86/kernel/trampoline_32.S linux-2.6.32.46/arch/x86/kernel/trampoline_32.S
18429 --- linux-2.6.32.46/arch/x86/kernel/trampoline_32.S 2011-03-27 14:31:47.000000000 -0400
18430 +++ linux-2.6.32.46/arch/x86/kernel/trampoline_32.S 2011-04-17 15:56:46.000000000 -0400
18431 @@ -32,6 +32,12 @@
18432 #include <asm/segment.h>
18433 #include <asm/page_types.h>
18434
18435 +#ifdef CONFIG_PAX_KERNEXEC
18436 +#define ta(X) (X)
18437 +#else
18438 +#define ta(X) ((X) - __PAGE_OFFSET)
18439 +#endif
18440 +
18441 /* We can free up trampoline after bootup if cpu hotplug is not supported. */
18442 __CPUINITRODATA
18443 .code16
18444 @@ -60,7 +66,7 @@ r_base = .
18445 inc %ax # protected mode (PE) bit
18446 lmsw %ax # into protected mode
18447 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
18448 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
18449 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
18450
18451 # These need to be in the same 64K segment as the above;
18452 # hence we don't use the boot_gdt_descr defined in head.S
18453 diff -urNp linux-2.6.32.46/arch/x86/kernel/trampoline_64.S linux-2.6.32.46/arch/x86/kernel/trampoline_64.S
18454 --- linux-2.6.32.46/arch/x86/kernel/trampoline_64.S 2011-03-27 14:31:47.000000000 -0400
18455 +++ linux-2.6.32.46/arch/x86/kernel/trampoline_64.S 2011-07-01 18:53:26.000000000 -0400
18456 @@ -91,7 +91,7 @@ startup_32:
18457 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
18458 movl %eax, %ds
18459
18460 - movl $X86_CR4_PAE, %eax
18461 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18462 movl %eax, %cr4 # Enable PAE mode
18463
18464 # Setup trampoline 4 level pagetables
18465 @@ -127,7 +127,7 @@ startup_64:
18466 no_longmode:
18467 hlt
18468 jmp no_longmode
18469 -#include "verify_cpu_64.S"
18470 +#include "verify_cpu.S"
18471
18472 # Careful these need to be in the same 64K segment as the above;
18473 tidt:
18474 @@ -138,7 +138,7 @@ tidt:
18475 # so the kernel can live anywhere
18476 .balign 4
18477 tgdt:
18478 - .short tgdt_end - tgdt # gdt limit
18479 + .short tgdt_end - tgdt - 1 # gdt limit
18480 .long tgdt - r_base
18481 .short 0
18482 .quad 0x00cf9b000000ffff # __KERNEL32_CS
18483 diff -urNp linux-2.6.32.46/arch/x86/kernel/traps.c linux-2.6.32.46/arch/x86/kernel/traps.c
18484 --- linux-2.6.32.46/arch/x86/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
18485 +++ linux-2.6.32.46/arch/x86/kernel/traps.c 2011-07-06 19:53:33.000000000 -0400
18486 @@ -69,12 +69,6 @@ asmlinkage int system_call(void);
18487
18488 /* Do we ignore FPU interrupts ? */
18489 char ignore_fpu_irq;
18490 -
18491 -/*
18492 - * The IDT has to be page-aligned to simplify the Pentium
18493 - * F0 0F bug workaround.
18494 - */
18495 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
18496 #endif
18497
18498 DECLARE_BITMAP(used_vectors, NR_VECTORS);
18499 @@ -112,19 +106,19 @@ static inline void preempt_conditional_c
18500 static inline void
18501 die_if_kernel(const char *str, struct pt_regs *regs, long err)
18502 {
18503 - if (!user_mode_vm(regs))
18504 + if (!user_mode(regs))
18505 die(str, regs, err);
18506 }
18507 #endif
18508
18509 static void __kprobes
18510 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
18511 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
18512 long error_code, siginfo_t *info)
18513 {
18514 struct task_struct *tsk = current;
18515
18516 #ifdef CONFIG_X86_32
18517 - if (regs->flags & X86_VM_MASK) {
18518 + if (v8086_mode(regs)) {
18519 /*
18520 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
18521 * On nmi (interrupt 2), do_trap should not be called.
18522 @@ -135,7 +129,7 @@ do_trap(int trapnr, int signr, char *str
18523 }
18524 #endif
18525
18526 - if (!user_mode(regs))
18527 + if (!user_mode_novm(regs))
18528 goto kernel_trap;
18529
18530 #ifdef CONFIG_X86_32
18531 @@ -158,7 +152,7 @@ trap_signal:
18532 printk_ratelimit()) {
18533 printk(KERN_INFO
18534 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
18535 - tsk->comm, tsk->pid, str,
18536 + tsk->comm, task_pid_nr(tsk), str,
18537 regs->ip, regs->sp, error_code);
18538 print_vma_addr(" in ", regs->ip);
18539 printk("\n");
18540 @@ -175,8 +169,20 @@ kernel_trap:
18541 if (!fixup_exception(regs)) {
18542 tsk->thread.error_code = error_code;
18543 tsk->thread.trap_no = trapnr;
18544 +
18545 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18546 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
18547 + str = "PAX: suspicious stack segment fault";
18548 +#endif
18549 +
18550 die(str, regs, error_code);
18551 }
18552 +
18553 +#ifdef CONFIG_PAX_REFCOUNT
18554 + if (trapnr == 4)
18555 + pax_report_refcount_overflow(regs);
18556 +#endif
18557 +
18558 return;
18559
18560 #ifdef CONFIG_X86_32
18561 @@ -265,14 +271,30 @@ do_general_protection(struct pt_regs *re
18562 conditional_sti(regs);
18563
18564 #ifdef CONFIG_X86_32
18565 - if (regs->flags & X86_VM_MASK)
18566 + if (v8086_mode(regs))
18567 goto gp_in_vm86;
18568 #endif
18569
18570 tsk = current;
18571 - if (!user_mode(regs))
18572 + if (!user_mode_novm(regs))
18573 goto gp_in_kernel;
18574
18575 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18576 + if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
18577 + struct mm_struct *mm = tsk->mm;
18578 + unsigned long limit;
18579 +
18580 + down_write(&mm->mmap_sem);
18581 + limit = mm->context.user_cs_limit;
18582 + if (limit < TASK_SIZE) {
18583 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
18584 + up_write(&mm->mmap_sem);
18585 + return;
18586 + }
18587 + up_write(&mm->mmap_sem);
18588 + }
18589 +#endif
18590 +
18591 tsk->thread.error_code = error_code;
18592 tsk->thread.trap_no = 13;
18593
18594 @@ -305,6 +327,13 @@ gp_in_kernel:
18595 if (notify_die(DIE_GPF, "general protection fault", regs,
18596 error_code, 13, SIGSEGV) == NOTIFY_STOP)
18597 return;
18598 +
18599 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18600 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
18601 + die("PAX: suspicious general protection fault", regs, error_code);
18602 + else
18603 +#endif
18604 +
18605 die("general protection fault", regs, error_code);
18606 }
18607
18608 @@ -435,6 +464,17 @@ static notrace __kprobes void default_do
18609 dotraplinkage notrace __kprobes void
18610 do_nmi(struct pt_regs *regs, long error_code)
18611 {
18612 +
18613 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18614 + if (!user_mode(regs)) {
18615 + unsigned long cs = regs->cs & 0xFFFF;
18616 + unsigned long ip = ktva_ktla(regs->ip);
18617 +
18618 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18619 + regs->ip = ip;
18620 + }
18621 +#endif
18622 +
18623 nmi_enter();
18624
18625 inc_irq_stat(__nmi_count);
18626 @@ -558,7 +598,7 @@ dotraplinkage void __kprobes do_debug(st
18627 }
18628
18629 #ifdef CONFIG_X86_32
18630 - if (regs->flags & X86_VM_MASK)
18631 + if (v8086_mode(regs))
18632 goto debug_vm86;
18633 #endif
18634
18635 @@ -570,7 +610,7 @@ dotraplinkage void __kprobes do_debug(st
18636 * kernel space (but re-enable TF when returning to user mode).
18637 */
18638 if (condition & DR_STEP) {
18639 - if (!user_mode(regs))
18640 + if (!user_mode_novm(regs))
18641 goto clear_TF_reenable;
18642 }
18643
18644 @@ -757,7 +797,7 @@ do_simd_coprocessor_error(struct pt_regs
18645 * Handle strange cache flush from user space exception
18646 * in all other cases. This is undocumented behaviour.
18647 */
18648 - if (regs->flags & X86_VM_MASK) {
18649 + if (v8086_mode(regs)) {
18650 handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
18651 return;
18652 }
18653 @@ -798,7 +838,7 @@ asmlinkage void __attribute__((weak)) sm
18654 void __math_state_restore(void)
18655 {
18656 struct thread_info *thread = current_thread_info();
18657 - struct task_struct *tsk = thread->task;
18658 + struct task_struct *tsk = current;
18659
18660 /*
18661 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
18662 @@ -825,8 +865,7 @@ void __math_state_restore(void)
18663 */
18664 asmlinkage void math_state_restore(void)
18665 {
18666 - struct thread_info *thread = current_thread_info();
18667 - struct task_struct *tsk = thread->task;
18668 + struct task_struct *tsk = current;
18669
18670 if (!tsk_used_math(tsk)) {
18671 local_irq_enable();
18672 diff -urNp linux-2.6.32.46/arch/x86/kernel/verify_cpu.S linux-2.6.32.46/arch/x86/kernel/verify_cpu.S
18673 --- linux-2.6.32.46/arch/x86/kernel/verify_cpu.S 1969-12-31 19:00:00.000000000 -0500
18674 +++ linux-2.6.32.46/arch/x86/kernel/verify_cpu.S 2011-07-01 18:28:42.000000000 -0400
18675 @@ -0,0 +1,140 @@
18676 +/*
18677 + *
18678 + * verify_cpu.S - Code for cpu long mode and SSE verification. This
18679 + * code has been borrowed from boot/setup.S and was introduced by
18680 + * Andi Kleen.
18681 + *
18682 + * Copyright (c) 2007 Andi Kleen (ak@suse.de)
18683 + * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
18684 + * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
18685 + * Copyright (c) 2010 Kees Cook (kees.cook@canonical.com)
18686 + *
18687 + * This source code is licensed under the GNU General Public License,
18688 + * Version 2. See the file COPYING for more details.
18689 + *
18690 + * This is a common code for verification whether CPU supports
18691 + * long mode and SSE or not. It is not called directly instead this
18692 + * file is included at various places and compiled in that context.
18693 + * This file is expected to run in 32bit code. Currently:
18694 + *
18695 + * arch/x86/boot/compressed/head_64.S: Boot cpu verification
18696 + * arch/x86/kernel/trampoline_64.S: secondary processor verification
18697 + * arch/x86/kernel/head_32.S: processor startup
18698 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
18699 + *
18700 + * verify_cpu, returns the status of longmode and SSE in register %eax.
18701 + * 0: Success 1: Failure
18702 + *
18703 + * On Intel, the XD_DISABLE flag will be cleared as a side-effect.
18704 + *
18705 + * The caller needs to check for the error code and take the action
18706 + * appropriately. Either display a message or halt.
18707 + */
18708 +
18709 +#include <asm/cpufeature.h>
18710 +#include <asm/msr-index.h>
18711 +
18712 +verify_cpu:
18713 + pushfl # Save caller passed flags
18714 + pushl $0 # Kill any dangerous flags
18715 + popfl
18716 +
18717 + pushfl # standard way to check for cpuid
18718 + popl %eax
18719 + movl %eax,%ebx
18720 + xorl $0x200000,%eax
18721 + pushl %eax
18722 + popfl
18723 + pushfl
18724 + popl %eax
18725 + cmpl %eax,%ebx
18726 + jz verify_cpu_no_longmode # cpu has no cpuid
18727 +
18728 + movl $0x0,%eax # See if cpuid 1 is implemented
18729 + cpuid
18730 + cmpl $0x1,%eax
18731 + jb verify_cpu_no_longmode # no cpuid 1
18732 +
18733 + xor %di,%di
18734 + cmpl $0x68747541,%ebx # AuthenticAMD
18735 + jnz verify_cpu_noamd
18736 + cmpl $0x69746e65,%edx
18737 + jnz verify_cpu_noamd
18738 + cmpl $0x444d4163,%ecx
18739 + jnz verify_cpu_noamd
18740 + mov $1,%di # cpu is from AMD
18741 + jmp verify_cpu_check
18742 +
18743 +verify_cpu_noamd:
18744 + cmpl $0x756e6547,%ebx # GenuineIntel?
18745 + jnz verify_cpu_check
18746 + cmpl $0x49656e69,%edx
18747 + jnz verify_cpu_check
18748 + cmpl $0x6c65746e,%ecx
18749 + jnz verify_cpu_check
18750 +
18751 + # only call IA32_MISC_ENABLE when:
18752 + # family > 6 || (family == 6 && model >= 0xd)
18753 + movl $0x1, %eax # check CPU family and model
18754 + cpuid
18755 + movl %eax, %ecx
18756 +
18757 + andl $0x0ff00f00, %eax # mask family and extended family
18758 + shrl $8, %eax
18759 + cmpl $6, %eax
18760 + ja verify_cpu_clear_xd # family > 6, ok
18761 + jb verify_cpu_check # family < 6, skip
18762 +
18763 + andl $0x000f00f0, %ecx # mask model and extended model
18764 + shrl $4, %ecx
18765 + cmpl $0xd, %ecx
18766 + jb verify_cpu_check # family == 6, model < 0xd, skip
18767 +
18768 +verify_cpu_clear_xd:
18769 + movl $MSR_IA32_MISC_ENABLE, %ecx
18770 + rdmsr
18771 + btrl $2, %edx # clear MSR_IA32_MISC_ENABLE_XD_DISABLE
18772 + jnc verify_cpu_check # only write MSR if bit was changed
18773 + wrmsr
18774 +
18775 +verify_cpu_check:
18776 + movl $0x1,%eax # Does the cpu have what it takes
18777 + cpuid
18778 + andl $REQUIRED_MASK0,%edx
18779 + xorl $REQUIRED_MASK0,%edx
18780 + jnz verify_cpu_no_longmode
18781 +
18782 + movl $0x80000000,%eax # See if extended cpuid is implemented
18783 + cpuid
18784 + cmpl $0x80000001,%eax
18785 + jb verify_cpu_no_longmode # no extended cpuid
18786 +
18787 + movl $0x80000001,%eax # Does the cpu have what it takes
18788 + cpuid
18789 + andl $REQUIRED_MASK1,%edx
18790 + xorl $REQUIRED_MASK1,%edx
18791 + jnz verify_cpu_no_longmode
18792 +
18793 +verify_cpu_sse_test:
18794 + movl $1,%eax
18795 + cpuid
18796 + andl $SSE_MASK,%edx
18797 + cmpl $SSE_MASK,%edx
18798 + je verify_cpu_sse_ok
18799 + test %di,%di
18800 + jz verify_cpu_no_longmode # only try to force SSE on AMD
18801 + movl $MSR_K7_HWCR,%ecx
18802 + rdmsr
18803 + btr $15,%eax # enable SSE
18804 + wrmsr
18805 + xor %di,%di # don't loop
18806 + jmp verify_cpu_sse_test # try again
18807 +
18808 +verify_cpu_no_longmode:
18809 + popfl # Restore caller passed flags
18810 + movl $1,%eax
18811 + ret
18812 +verify_cpu_sse_ok:
18813 + popfl # Restore caller passed flags
18814 + xorl %eax, %eax
18815 + ret
18816 diff -urNp linux-2.6.32.46/arch/x86/kernel/verify_cpu_64.S linux-2.6.32.46/arch/x86/kernel/verify_cpu_64.S
18817 --- linux-2.6.32.46/arch/x86/kernel/verify_cpu_64.S 2011-03-27 14:31:47.000000000 -0400
18818 +++ linux-2.6.32.46/arch/x86/kernel/verify_cpu_64.S 1969-12-31 19:00:00.000000000 -0500
18819 @@ -1,105 +0,0 @@
18820 -/*
18821 - *
18822 - * verify_cpu.S - Code for cpu long mode and SSE verification. This
18823 - * code has been borrowed from boot/setup.S and was introduced by
18824 - * Andi Kleen.
18825 - *
18826 - * Copyright (c) 2007 Andi Kleen (ak@suse.de)
18827 - * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
18828 - * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
18829 - *
18830 - * This source code is licensed under the GNU General Public License,
18831 - * Version 2. See the file COPYING for more details.
18832 - *
18833 - * This is a common code for verification whether CPU supports
18834 - * long mode and SSE or not. It is not called directly instead this
18835 - * file is included at various places and compiled in that context.
18836 - * Following are the current usage.
18837 - *
18838 - * This file is included by both 16bit and 32bit code.
18839 - *
18840 - * arch/x86_64/boot/setup.S : Boot cpu verification (16bit)
18841 - * arch/x86_64/boot/compressed/head.S: Boot cpu verification (32bit)
18842 - * arch/x86_64/kernel/trampoline.S: secondary processor verfication (16bit)
18843 - * arch/x86_64/kernel/acpi/wakeup.S:Verfication at resume (16bit)
18844 - *
18845 - * verify_cpu, returns the status of cpu check in register %eax.
18846 - * 0: Success 1: Failure
18847 - *
18848 - * The caller needs to check for the error code and take the action
18849 - * appropriately. Either display a message or halt.
18850 - */
18851 -
18852 -#include <asm/cpufeature.h>
18853 -
18854 -verify_cpu:
18855 - pushfl # Save caller passed flags
18856 - pushl $0 # Kill any dangerous flags
18857 - popfl
18858 -
18859 - pushfl # standard way to check for cpuid
18860 - popl %eax
18861 - movl %eax,%ebx
18862 - xorl $0x200000,%eax
18863 - pushl %eax
18864 - popfl
18865 - pushfl
18866 - popl %eax
18867 - cmpl %eax,%ebx
18868 - jz verify_cpu_no_longmode # cpu has no cpuid
18869 -
18870 - movl $0x0,%eax # See if cpuid 1 is implemented
18871 - cpuid
18872 - cmpl $0x1,%eax
18873 - jb verify_cpu_no_longmode # no cpuid 1
18874 -
18875 - xor %di,%di
18876 - cmpl $0x68747541,%ebx # AuthenticAMD
18877 - jnz verify_cpu_noamd
18878 - cmpl $0x69746e65,%edx
18879 - jnz verify_cpu_noamd
18880 - cmpl $0x444d4163,%ecx
18881 - jnz verify_cpu_noamd
18882 - mov $1,%di # cpu is from AMD
18883 -
18884 -verify_cpu_noamd:
18885 - movl $0x1,%eax # Does the cpu have what it takes
18886 - cpuid
18887 - andl $REQUIRED_MASK0,%edx
18888 - xorl $REQUIRED_MASK0,%edx
18889 - jnz verify_cpu_no_longmode
18890 -
18891 - movl $0x80000000,%eax # See if extended cpuid is implemented
18892 - cpuid
18893 - cmpl $0x80000001,%eax
18894 - jb verify_cpu_no_longmode # no extended cpuid
18895 -
18896 - movl $0x80000001,%eax # Does the cpu have what it takes
18897 - cpuid
18898 - andl $REQUIRED_MASK1,%edx
18899 - xorl $REQUIRED_MASK1,%edx
18900 - jnz verify_cpu_no_longmode
18901 -
18902 -verify_cpu_sse_test:
18903 - movl $1,%eax
18904 - cpuid
18905 - andl $SSE_MASK,%edx
18906 - cmpl $SSE_MASK,%edx
18907 - je verify_cpu_sse_ok
18908 - test %di,%di
18909 - jz verify_cpu_no_longmode # only try to force SSE on AMD
18910 - movl $0xc0010015,%ecx # HWCR
18911 - rdmsr
18912 - btr $15,%eax # enable SSE
18913 - wrmsr
18914 - xor %di,%di # don't loop
18915 - jmp verify_cpu_sse_test # try again
18916 -
18917 -verify_cpu_no_longmode:
18918 - popfl # Restore caller passed flags
18919 - movl $1,%eax
18920 - ret
18921 -verify_cpu_sse_ok:
18922 - popfl # Restore caller passed flags
18923 - xorl %eax, %eax
18924 - ret
18925 diff -urNp linux-2.6.32.46/arch/x86/kernel/vm86_32.c linux-2.6.32.46/arch/x86/kernel/vm86_32.c
18926 --- linux-2.6.32.46/arch/x86/kernel/vm86_32.c 2011-03-27 14:31:47.000000000 -0400
18927 +++ linux-2.6.32.46/arch/x86/kernel/vm86_32.c 2011-04-17 15:56:46.000000000 -0400
18928 @@ -41,6 +41,7 @@
18929 #include <linux/ptrace.h>
18930 #include <linux/audit.h>
18931 #include <linux/stddef.h>
18932 +#include <linux/grsecurity.h>
18933
18934 #include <asm/uaccess.h>
18935 #include <asm/io.h>
18936 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
18937 do_exit(SIGSEGV);
18938 }
18939
18940 - tss = &per_cpu(init_tss, get_cpu());
18941 + tss = init_tss + get_cpu();
18942 current->thread.sp0 = current->thread.saved_sp0;
18943 current->thread.sysenter_cs = __KERNEL_CS;
18944 load_sp0(tss, &current->thread);
18945 @@ -208,6 +209,13 @@ int sys_vm86old(struct pt_regs *regs)
18946 struct task_struct *tsk;
18947 int tmp, ret = -EPERM;
18948
18949 +#ifdef CONFIG_GRKERNSEC_VM86
18950 + if (!capable(CAP_SYS_RAWIO)) {
18951 + gr_handle_vm86();
18952 + goto out;
18953 + }
18954 +#endif
18955 +
18956 tsk = current;
18957 if (tsk->thread.saved_sp0)
18958 goto out;
18959 @@ -238,6 +246,14 @@ int sys_vm86(struct pt_regs *regs)
18960 int tmp, ret;
18961 struct vm86plus_struct __user *v86;
18962
18963 +#ifdef CONFIG_GRKERNSEC_VM86
18964 + if (!capable(CAP_SYS_RAWIO)) {
18965 + gr_handle_vm86();
18966 + ret = -EPERM;
18967 + goto out;
18968 + }
18969 +#endif
18970 +
18971 tsk = current;
18972 switch (regs->bx) {
18973 case VM86_REQUEST_IRQ:
18974 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
18975 tsk->thread.saved_fs = info->regs32->fs;
18976 tsk->thread.saved_gs = get_user_gs(info->regs32);
18977
18978 - tss = &per_cpu(init_tss, get_cpu());
18979 + tss = init_tss + get_cpu();
18980 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
18981 if (cpu_has_sep)
18982 tsk->thread.sysenter_cs = 0;
18983 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
18984 goto cannot_handle;
18985 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
18986 goto cannot_handle;
18987 - intr_ptr = (unsigned long __user *) (i << 2);
18988 + intr_ptr = (__force unsigned long __user *) (i << 2);
18989 if (get_user(segoffs, intr_ptr))
18990 goto cannot_handle;
18991 if ((segoffs >> 16) == BIOSSEG)
18992 diff -urNp linux-2.6.32.46/arch/x86/kernel/vmi_32.c linux-2.6.32.46/arch/x86/kernel/vmi_32.c
18993 --- linux-2.6.32.46/arch/x86/kernel/vmi_32.c 2011-03-27 14:31:47.000000000 -0400
18994 +++ linux-2.6.32.46/arch/x86/kernel/vmi_32.c 2011-08-05 20:33:55.000000000 -0400
18995 @@ -44,12 +44,17 @@ typedef u32 __attribute__((regparm(1)))
18996 typedef u64 __attribute__((regparm(2))) (VROMLONGFUNC)(int);
18997
18998 #define call_vrom_func(rom,func) \
18999 - (((VROMFUNC *)(rom->func))())
19000 + (((VROMFUNC *)(ktva_ktla(rom.func)))())
19001
19002 #define call_vrom_long_func(rom,func,arg) \
19003 - (((VROMLONGFUNC *)(rom->func)) (arg))
19004 +({\
19005 + u64 __reloc = ((VROMLONGFUNC *)(ktva_ktla(rom.func))) (arg);\
19006 + struct vmi_relocation_info *const __rel = (struct vmi_relocation_info *)&__reloc;\
19007 + __rel->eip = (unsigned char *)ktva_ktla((unsigned long)__rel->eip);\
19008 + __reloc;\
19009 +})
19010
19011 -static struct vrom_header *vmi_rom;
19012 +static struct vrom_header vmi_rom __attribute((__section__(".vmi.rom"), __aligned__(PAGE_SIZE)));
19013 static int disable_pge;
19014 static int disable_pse;
19015 static int disable_sep;
19016 @@ -76,10 +81,10 @@ static struct {
19017 void (*set_initial_ap_state)(int, int);
19018 void (*halt)(void);
19019 void (*set_lazy_mode)(int mode);
19020 -} vmi_ops;
19021 +} __no_const vmi_ops __read_only;
19022
19023 /* Cached VMI operations */
19024 -struct vmi_timer_ops vmi_timer_ops;
19025 +struct vmi_timer_ops vmi_timer_ops __read_only;
19026
19027 /*
19028 * VMI patching routines.
19029 @@ -94,7 +99,7 @@ struct vmi_timer_ops vmi_timer_ops;
19030 static inline void patch_offset(void *insnbuf,
19031 unsigned long ip, unsigned long dest)
19032 {
19033 - *(unsigned long *)(insnbuf+1) = dest-ip-5;
19034 + *(unsigned long *)(insnbuf+1) = dest-ip-5;
19035 }
19036
19037 static unsigned patch_internal(int call, unsigned len, void *insnbuf,
19038 @@ -102,6 +107,7 @@ static unsigned patch_internal(int call,
19039 {
19040 u64 reloc;
19041 struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
19042 +
19043 reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
19044 switch(rel->type) {
19045 case VMI_RELOCATION_CALL_REL:
19046 @@ -404,13 +410,13 @@ static void vmi_set_pud(pud_t *pudp, pud
19047
19048 static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
19049 {
19050 - const pte_t pte = { .pte = 0 };
19051 + const pte_t pte = __pte(0ULL);
19052 vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
19053 }
19054
19055 static void vmi_pmd_clear(pmd_t *pmd)
19056 {
19057 - const pte_t pte = { .pte = 0 };
19058 + const pte_t pte = __pte(0ULL);
19059 vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
19060 }
19061 #endif
19062 @@ -438,10 +444,10 @@ vmi_startup_ipi_hook(int phys_apicid, un
19063 ap.ss = __KERNEL_DS;
19064 ap.esp = (unsigned long) start_esp;
19065
19066 - ap.ds = __USER_DS;
19067 - ap.es = __USER_DS;
19068 + ap.ds = __KERNEL_DS;
19069 + ap.es = __KERNEL_DS;
19070 ap.fs = __KERNEL_PERCPU;
19071 - ap.gs = __KERNEL_STACK_CANARY;
19072 + savesegment(gs, ap.gs);
19073
19074 ap.eflags = 0;
19075
19076 @@ -486,6 +492,18 @@ static void vmi_leave_lazy_mmu(void)
19077 paravirt_leave_lazy_mmu();
19078 }
19079
19080 +#ifdef CONFIG_PAX_KERNEXEC
19081 +static unsigned long vmi_pax_open_kernel(void)
19082 +{
19083 + return 0;
19084 +}
19085 +
19086 +static unsigned long vmi_pax_close_kernel(void)
19087 +{
19088 + return 0;
19089 +}
19090 +#endif
19091 +
19092 static inline int __init check_vmi_rom(struct vrom_header *rom)
19093 {
19094 struct pci_header *pci;
19095 @@ -498,6 +516,10 @@ static inline int __init check_vmi_rom(s
19096 return 0;
19097 if (rom->vrom_signature != VMI_SIGNATURE)
19098 return 0;
19099 + if (rom->rom_length * 512 > sizeof(*rom)) {
19100 + printk(KERN_WARNING "PAX: VMI: ROM size too big: %x\n", rom->rom_length * 512);
19101 + return 0;
19102 + }
19103 if (rom->api_version_maj != VMI_API_REV_MAJOR ||
19104 rom->api_version_min+1 < VMI_API_REV_MINOR+1) {
19105 printk(KERN_WARNING "VMI: Found mismatched rom version %d.%d\n",
19106 @@ -562,7 +584,7 @@ static inline int __init probe_vmi_rom(v
19107 struct vrom_header *romstart;
19108 romstart = (struct vrom_header *)isa_bus_to_virt(base);
19109 if (check_vmi_rom(romstart)) {
19110 - vmi_rom = romstart;
19111 + vmi_rom = *romstart;
19112 return 1;
19113 }
19114 }
19115 @@ -836,6 +858,11 @@ static inline int __init activate_vmi(vo
19116
19117 para_fill(pv_irq_ops.safe_halt, Halt);
19118
19119 +#ifdef CONFIG_PAX_KERNEXEC
19120 + pv_mmu_ops.pax_open_kernel = vmi_pax_open_kernel;
19121 + pv_mmu_ops.pax_close_kernel = vmi_pax_close_kernel;
19122 +#endif
19123 +
19124 /*
19125 * Alternative instruction rewriting doesn't happen soon enough
19126 * to convert VMI_IRET to a call instead of a jump; so we have
19127 @@ -853,16 +880,16 @@ static inline int __init activate_vmi(vo
19128
19129 void __init vmi_init(void)
19130 {
19131 - if (!vmi_rom)
19132 + if (!vmi_rom.rom_signature)
19133 probe_vmi_rom();
19134 else
19135 - check_vmi_rom(vmi_rom);
19136 + check_vmi_rom(&vmi_rom);
19137
19138 /* In case probing for or validating the ROM failed, basil */
19139 - if (!vmi_rom)
19140 + if (!vmi_rom.rom_signature)
19141 return;
19142
19143 - reserve_top_address(-vmi_rom->virtual_top);
19144 + reserve_top_address(-vmi_rom.virtual_top);
19145
19146 #ifdef CONFIG_X86_IO_APIC
19147 /* This is virtual hardware; timer routing is wired correctly */
19148 @@ -874,7 +901,7 @@ void __init vmi_activate(void)
19149 {
19150 unsigned long flags;
19151
19152 - if (!vmi_rom)
19153 + if (!vmi_rom.rom_signature)
19154 return;
19155
19156 local_irq_save(flags);
19157 diff -urNp linux-2.6.32.46/arch/x86/kernel/vmlinux.lds.S linux-2.6.32.46/arch/x86/kernel/vmlinux.lds.S
19158 --- linux-2.6.32.46/arch/x86/kernel/vmlinux.lds.S 2011-03-27 14:31:47.000000000 -0400
19159 +++ linux-2.6.32.46/arch/x86/kernel/vmlinux.lds.S 2011-04-17 15:56:46.000000000 -0400
19160 @@ -26,6 +26,13 @@
19161 #include <asm/page_types.h>
19162 #include <asm/cache.h>
19163 #include <asm/boot.h>
19164 +#include <asm/segment.h>
19165 +
19166 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19167 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19168 +#else
19169 +#define __KERNEL_TEXT_OFFSET 0
19170 +#endif
19171
19172 #undef i386 /* in case the preprocessor is a 32bit one */
19173
19174 @@ -34,40 +41,53 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
19175 #ifdef CONFIG_X86_32
19176 OUTPUT_ARCH(i386)
19177 ENTRY(phys_startup_32)
19178 -jiffies = jiffies_64;
19179 #else
19180 OUTPUT_ARCH(i386:x86-64)
19181 ENTRY(phys_startup_64)
19182 -jiffies_64 = jiffies;
19183 #endif
19184
19185 PHDRS {
19186 text PT_LOAD FLAGS(5); /* R_E */
19187 - data PT_LOAD FLAGS(7); /* RWE */
19188 +#ifdef CONFIG_X86_32
19189 + module PT_LOAD FLAGS(5); /* R_E */
19190 +#endif
19191 +#ifdef CONFIG_XEN
19192 + rodata PT_LOAD FLAGS(5); /* R_E */
19193 +#else
19194 + rodata PT_LOAD FLAGS(4); /* R__ */
19195 +#endif
19196 + data PT_LOAD FLAGS(6); /* RW_ */
19197 #ifdef CONFIG_X86_64
19198 user PT_LOAD FLAGS(5); /* R_E */
19199 +#endif
19200 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19201 #ifdef CONFIG_SMP
19202 percpu PT_LOAD FLAGS(6); /* RW_ */
19203 #endif
19204 + text.init PT_LOAD FLAGS(5); /* R_E */
19205 + text.exit PT_LOAD FLAGS(5); /* R_E */
19206 init PT_LOAD FLAGS(7); /* RWE */
19207 -#endif
19208 note PT_NOTE FLAGS(0); /* ___ */
19209 }
19210
19211 SECTIONS
19212 {
19213 #ifdef CONFIG_X86_32
19214 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19215 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19216 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19217 #else
19218 - . = __START_KERNEL;
19219 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19220 + . = __START_KERNEL;
19221 #endif
19222
19223 /* Text and read-only data */
19224 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19225 - _text = .;
19226 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19227 /* bootstrapping code */
19228 +#ifdef CONFIG_X86_32
19229 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19230 +#else
19231 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19232 +#endif
19233 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19234 + _text = .;
19235 HEAD_TEXT
19236 #ifdef CONFIG_X86_32
19237 . = ALIGN(PAGE_SIZE);
19238 @@ -82,28 +102,71 @@ SECTIONS
19239 IRQENTRY_TEXT
19240 *(.fixup)
19241 *(.gnu.warning)
19242 - /* End of text section */
19243 - _etext = .;
19244 } :text = 0x9090
19245
19246 - NOTES :text :note
19247 + . += __KERNEL_TEXT_OFFSET;
19248 +
19249 +#ifdef CONFIG_X86_32
19250 + . = ALIGN(PAGE_SIZE);
19251 + .vmi.rom : AT(ADDR(.vmi.rom) - LOAD_OFFSET) {
19252 + *(.vmi.rom)
19253 + } :module
19254 +
19255 + . = ALIGN(PAGE_SIZE);
19256 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19257 +
19258 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19259 + MODULES_EXEC_VADDR = .;
19260 + BYTE(0)
19261 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19262 + . = ALIGN(HPAGE_SIZE);
19263 + MODULES_EXEC_END = . - 1;
19264 +#endif
19265 +
19266 + } :module
19267 +#endif
19268
19269 - EXCEPTION_TABLE(16) :text = 0x9090
19270 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19271 + /* End of text section */
19272 + _etext = . - __KERNEL_TEXT_OFFSET;
19273 + }
19274 +
19275 +#ifdef CONFIG_X86_32
19276 + . = ALIGN(PAGE_SIZE);
19277 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19278 + *(.idt)
19279 + . = ALIGN(PAGE_SIZE);
19280 + *(.empty_zero_page)
19281 + *(.swapper_pg_fixmap)
19282 + *(.swapper_pg_pmd)
19283 + *(.swapper_pg_dir)
19284 + *(.trampoline_pg_dir)
19285 + } :rodata
19286 +#endif
19287 +
19288 + . = ALIGN(PAGE_SIZE);
19289 + NOTES :rodata :note
19290 +
19291 + EXCEPTION_TABLE(16) :rodata
19292
19293 RO_DATA(PAGE_SIZE)
19294
19295 /* Data */
19296 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19297 +
19298 +#ifdef CONFIG_PAX_KERNEXEC
19299 + . = ALIGN(HPAGE_SIZE);
19300 +#else
19301 + . = ALIGN(PAGE_SIZE);
19302 +#endif
19303 +
19304 /* Start of data section */
19305 _sdata = .;
19306
19307 /* init_task */
19308 INIT_TASK_DATA(THREAD_SIZE)
19309
19310 -#ifdef CONFIG_X86_32
19311 - /* 32 bit has nosave before _edata */
19312 NOSAVE_DATA
19313 -#endif
19314
19315 PAGE_ALIGNED_DATA(PAGE_SIZE)
19316
19317 @@ -112,6 +175,8 @@ SECTIONS
19318 DATA_DATA
19319 CONSTRUCTORS
19320
19321 + jiffies = jiffies_64;
19322 +
19323 /* rarely changed data like cpu maps */
19324 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
19325
19326 @@ -166,12 +231,6 @@ SECTIONS
19327 }
19328 vgetcpu_mode = VVIRT(.vgetcpu_mode);
19329
19330 - . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
19331 - .jiffies : AT(VLOAD(.jiffies)) {
19332 - *(.jiffies)
19333 - }
19334 - jiffies = VVIRT(.jiffies);
19335 -
19336 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
19337 *(.vsyscall_3)
19338 }
19339 @@ -187,12 +246,19 @@ SECTIONS
19340 #endif /* CONFIG_X86_64 */
19341
19342 /* Init code and data - will be freed after init */
19343 - . = ALIGN(PAGE_SIZE);
19344 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19345 + BYTE(0)
19346 +
19347 +#ifdef CONFIG_PAX_KERNEXEC
19348 + . = ALIGN(HPAGE_SIZE);
19349 +#else
19350 + . = ALIGN(PAGE_SIZE);
19351 +#endif
19352 +
19353 __init_begin = .; /* paired with __init_end */
19354 - }
19355 + } :init.begin
19356
19357 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19358 +#ifdef CONFIG_SMP
19359 /*
19360 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19361 * output PHDR, so the next output section - .init.text - should
19362 @@ -201,12 +267,27 @@ SECTIONS
19363 PERCPU_VADDR(0, :percpu)
19364 #endif
19365
19366 - INIT_TEXT_SECTION(PAGE_SIZE)
19367 -#ifdef CONFIG_X86_64
19368 - :init
19369 -#endif
19370 + . = ALIGN(PAGE_SIZE);
19371 + init_begin = .;
19372 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19373 + VMLINUX_SYMBOL(_sinittext) = .;
19374 + INIT_TEXT
19375 + VMLINUX_SYMBOL(_einittext) = .;
19376 + . = ALIGN(PAGE_SIZE);
19377 + } :text.init
19378
19379 - INIT_DATA_SECTION(16)
19380 + /*
19381 + * .exit.text is discard at runtime, not link time, to deal with
19382 + * references from .altinstructions and .eh_frame
19383 + */
19384 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19385 + EXIT_TEXT
19386 + . = ALIGN(16);
19387 + } :text.exit
19388 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19389 +
19390 + . = ALIGN(PAGE_SIZE);
19391 + INIT_DATA_SECTION(16) :init
19392
19393 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
19394 __x86_cpu_dev_start = .;
19395 @@ -232,19 +313,11 @@ SECTIONS
19396 *(.altinstr_replacement)
19397 }
19398
19399 - /*
19400 - * .exit.text is discard at runtime, not link time, to deal with
19401 - * references from .altinstructions and .eh_frame
19402 - */
19403 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19404 - EXIT_TEXT
19405 - }
19406 -
19407 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19408 EXIT_DATA
19409 }
19410
19411 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19412 +#ifndef CONFIG_SMP
19413 PERCPU(PAGE_SIZE)
19414 #endif
19415
19416 @@ -267,12 +340,6 @@ SECTIONS
19417 . = ALIGN(PAGE_SIZE);
19418 }
19419
19420 -#ifdef CONFIG_X86_64
19421 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19422 - NOSAVE_DATA
19423 - }
19424 -#endif
19425 -
19426 /* BSS */
19427 . = ALIGN(PAGE_SIZE);
19428 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19429 @@ -288,6 +355,7 @@ SECTIONS
19430 __brk_base = .;
19431 . += 64 * 1024; /* 64k alignment slop space */
19432 *(.brk_reservation) /* areas brk users have reserved */
19433 + . = ALIGN(HPAGE_SIZE);
19434 __brk_limit = .;
19435 }
19436
19437 @@ -316,13 +384,12 @@ SECTIONS
19438 * for the boot processor.
19439 */
19440 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
19441 -INIT_PER_CPU(gdt_page);
19442 INIT_PER_CPU(irq_stack_union);
19443
19444 /*
19445 * Build-time check on the image size:
19446 */
19447 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19448 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19449 "kernel image bigger than KERNEL_IMAGE_SIZE");
19450
19451 #ifdef CONFIG_SMP
19452 diff -urNp linux-2.6.32.46/arch/x86/kernel/vsyscall_64.c linux-2.6.32.46/arch/x86/kernel/vsyscall_64.c
19453 --- linux-2.6.32.46/arch/x86/kernel/vsyscall_64.c 2011-03-27 14:31:47.000000000 -0400
19454 +++ linux-2.6.32.46/arch/x86/kernel/vsyscall_64.c 2011-04-23 12:56:10.000000000 -0400
19455 @@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
19456
19457 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
19458 /* copy vsyscall data */
19459 + strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
19460 vsyscall_gtod_data.clock.vread = clock->vread;
19461 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
19462 vsyscall_gtod_data.clock.mask = clock->mask;
19463 @@ -203,7 +204,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
19464 We do this here because otherwise user space would do it on
19465 its own in a likely inferior way (no access to jiffies).
19466 If you don't like it pass NULL. */
19467 - if (tcache && tcache->blob[0] == (j = __jiffies)) {
19468 + if (tcache && tcache->blob[0] == (j = jiffies)) {
19469 p = tcache->blob[1];
19470 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
19471 /* Load per CPU data from RDTSCP */
19472 diff -urNp linux-2.6.32.46/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.32.46/arch/x86/kernel/x8664_ksyms_64.c
19473 --- linux-2.6.32.46/arch/x86/kernel/x8664_ksyms_64.c 2011-03-27 14:31:47.000000000 -0400
19474 +++ linux-2.6.32.46/arch/x86/kernel/x8664_ksyms_64.c 2011-04-17 15:56:46.000000000 -0400
19475 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(__put_user_8);
19476
19477 EXPORT_SYMBOL(copy_user_generic);
19478 EXPORT_SYMBOL(__copy_user_nocache);
19479 -EXPORT_SYMBOL(copy_from_user);
19480 -EXPORT_SYMBOL(copy_to_user);
19481 EXPORT_SYMBOL(__copy_from_user_inatomic);
19482
19483 EXPORT_SYMBOL(copy_page);
19484 diff -urNp linux-2.6.32.46/arch/x86/kernel/xsave.c linux-2.6.32.46/arch/x86/kernel/xsave.c
19485 --- linux-2.6.32.46/arch/x86/kernel/xsave.c 2011-03-27 14:31:47.000000000 -0400
19486 +++ linux-2.6.32.46/arch/x86/kernel/xsave.c 2011-10-06 09:37:08.000000000 -0400
19487 @@ -54,7 +54,7 @@ int check_for_xstate(struct i387_fxsave_
19488 fx_sw_user->xstate_size > fx_sw_user->extended_size)
19489 return -1;
19490
19491 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
19492 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
19493 fx_sw_user->extended_size -
19494 FP_XSTATE_MAGIC2_SIZE));
19495 /*
19496 @@ -196,7 +196,7 @@ fx_only:
19497 * the other extended state.
19498 */
19499 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
19500 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
19501 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
19502 }
19503
19504 /*
19505 @@ -228,7 +228,7 @@ int restore_i387_xstate(void __user *buf
19506 if (task_thread_info(tsk)->status & TS_XSAVE)
19507 err = restore_user_xstate(buf);
19508 else
19509 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
19510 + err = fxrstor_checking((struct i387_fxsave_struct __user *)
19511 buf);
19512 if (unlikely(err)) {
19513 /*
19514 diff -urNp linux-2.6.32.46/arch/x86/kvm/emulate.c linux-2.6.32.46/arch/x86/kvm/emulate.c
19515 --- linux-2.6.32.46/arch/x86/kvm/emulate.c 2011-03-27 14:31:47.000000000 -0400
19516 +++ linux-2.6.32.46/arch/x86/kvm/emulate.c 2011-04-17 15:56:46.000000000 -0400
19517 @@ -81,8 +81,8 @@
19518 #define Src2CL (1<<29)
19519 #define Src2ImmByte (2<<29)
19520 #define Src2One (3<<29)
19521 -#define Src2Imm16 (4<<29)
19522 -#define Src2Mask (7<<29)
19523 +#define Src2Imm16 (4U<<29)
19524 +#define Src2Mask (7U<<29)
19525
19526 enum {
19527 Group1_80, Group1_81, Group1_82, Group1_83,
19528 @@ -411,6 +411,7 @@ static u32 group2_table[] = {
19529
19530 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix) \
19531 do { \
19532 + unsigned long _tmp; \
19533 __asm__ __volatile__ ( \
19534 _PRE_EFLAGS("0", "4", "2") \
19535 _op _suffix " %"_x"3,%1; " \
19536 @@ -424,8 +425,6 @@ static u32 group2_table[] = {
19537 /* Raw emulation: instruction has two explicit operands. */
19538 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
19539 do { \
19540 - unsigned long _tmp; \
19541 - \
19542 switch ((_dst).bytes) { \
19543 case 2: \
19544 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w"); \
19545 @@ -441,7 +440,6 @@ static u32 group2_table[] = {
19546
19547 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
19548 do { \
19549 - unsigned long _tmp; \
19550 switch ((_dst).bytes) { \
19551 case 1: \
19552 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b"); \
19553 diff -urNp linux-2.6.32.46/arch/x86/kvm/lapic.c linux-2.6.32.46/arch/x86/kvm/lapic.c
19554 --- linux-2.6.32.46/arch/x86/kvm/lapic.c 2011-03-27 14:31:47.000000000 -0400
19555 +++ linux-2.6.32.46/arch/x86/kvm/lapic.c 2011-04-17 15:56:46.000000000 -0400
19556 @@ -52,7 +52,7 @@
19557 #define APIC_BUS_CYCLE_NS 1
19558
19559 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
19560 -#define apic_debug(fmt, arg...)
19561 +#define apic_debug(fmt, arg...) do {} while (0)
19562
19563 #define APIC_LVT_NUM 6
19564 /* 14 is the version for Xeon and Pentium 8.4.8*/
19565 diff -urNp linux-2.6.32.46/arch/x86/kvm/paging_tmpl.h linux-2.6.32.46/arch/x86/kvm/paging_tmpl.h
19566 --- linux-2.6.32.46/arch/x86/kvm/paging_tmpl.h 2011-03-27 14:31:47.000000000 -0400
19567 +++ linux-2.6.32.46/arch/x86/kvm/paging_tmpl.h 2011-05-16 21:46:57.000000000 -0400
19568 @@ -416,6 +416,8 @@ static int FNAME(page_fault)(struct kvm_
19569 int level = PT_PAGE_TABLE_LEVEL;
19570 unsigned long mmu_seq;
19571
19572 + pax_track_stack();
19573 +
19574 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
19575 kvm_mmu_audit(vcpu, "pre page fault");
19576
19577 diff -urNp linux-2.6.32.46/arch/x86/kvm/svm.c linux-2.6.32.46/arch/x86/kvm/svm.c
19578 --- linux-2.6.32.46/arch/x86/kvm/svm.c 2011-03-27 14:31:47.000000000 -0400
19579 +++ linux-2.6.32.46/arch/x86/kvm/svm.c 2011-08-05 20:33:55.000000000 -0400
19580 @@ -2485,7 +2485,11 @@ static void reload_tss(struct kvm_vcpu *
19581 int cpu = raw_smp_processor_id();
19582
19583 struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
19584 +
19585 + pax_open_kernel();
19586 svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
19587 + pax_close_kernel();
19588 +
19589 load_TR_desc();
19590 }
19591
19592 @@ -2946,7 +2950,7 @@ static bool svm_gb_page_enable(void)
19593 return true;
19594 }
19595
19596 -static struct kvm_x86_ops svm_x86_ops = {
19597 +static const struct kvm_x86_ops svm_x86_ops = {
19598 .cpu_has_kvm_support = has_svm,
19599 .disabled_by_bios = is_disabled,
19600 .hardware_setup = svm_hardware_setup,
19601 diff -urNp linux-2.6.32.46/arch/x86/kvm/vmx.c linux-2.6.32.46/arch/x86/kvm/vmx.c
19602 --- linux-2.6.32.46/arch/x86/kvm/vmx.c 2011-03-27 14:31:47.000000000 -0400
19603 +++ linux-2.6.32.46/arch/x86/kvm/vmx.c 2011-05-04 17:56:20.000000000 -0400
19604 @@ -570,7 +570,11 @@ static void reload_tss(void)
19605
19606 kvm_get_gdt(&gdt);
19607 descs = (void *)gdt.base;
19608 +
19609 + pax_open_kernel();
19610 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
19611 + pax_close_kernel();
19612 +
19613 load_TR_desc();
19614 }
19615
19616 @@ -1409,8 +1413,11 @@ static __init int hardware_setup(void)
19617 if (!cpu_has_vmx_flexpriority())
19618 flexpriority_enabled = 0;
19619
19620 - if (!cpu_has_vmx_tpr_shadow())
19621 - kvm_x86_ops->update_cr8_intercept = NULL;
19622 + if (!cpu_has_vmx_tpr_shadow()) {
19623 + pax_open_kernel();
19624 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
19625 + pax_close_kernel();
19626 + }
19627
19628 if (enable_ept && !cpu_has_vmx_ept_2m_page())
19629 kvm_disable_largepages();
19630 @@ -2361,7 +2368,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
19631 vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */
19632
19633 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
19634 - vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
19635 + vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
19636 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
19637 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
19638 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, 0);
19639 @@ -3717,6 +3724,12 @@ static void vmx_vcpu_run(struct kvm_vcpu
19640 "jmp .Lkvm_vmx_return \n\t"
19641 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
19642 ".Lkvm_vmx_return: "
19643 +
19644 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19645 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
19646 + ".Lkvm_vmx_return2: "
19647 +#endif
19648 +
19649 /* Save guest registers, load host registers, keep flags */
19650 "xchg %0, (%%"R"sp) \n\t"
19651 "mov %%"R"ax, %c[rax](%0) \n\t"
19652 @@ -3763,8 +3776,13 @@ static void vmx_vcpu_run(struct kvm_vcpu
19653 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
19654 #endif
19655 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
19656 +
19657 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19658 + ,[cs]"i"(__KERNEL_CS)
19659 +#endif
19660 +
19661 : "cc", "memory"
19662 - , R"bx", R"di", R"si"
19663 + , R"ax", R"bx", R"di", R"si"
19664 #ifdef CONFIG_X86_64
19665 , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
19666 #endif
19667 @@ -3781,7 +3799,16 @@ static void vmx_vcpu_run(struct kvm_vcpu
19668 if (vmx->rmode.irq.pending)
19669 fixup_rmode_irq(vmx);
19670
19671 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
19672 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
19673 +
19674 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19675 + loadsegment(fs, __KERNEL_PERCPU);
19676 +#endif
19677 +
19678 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19679 + __set_fs(current_thread_info()->addr_limit);
19680 +#endif
19681 +
19682 vmx->launched = 1;
19683
19684 vmx_complete_interrupts(vmx);
19685 @@ -3956,7 +3983,7 @@ static bool vmx_gb_page_enable(void)
19686 return false;
19687 }
19688
19689 -static struct kvm_x86_ops vmx_x86_ops = {
19690 +static const struct kvm_x86_ops vmx_x86_ops = {
19691 .cpu_has_kvm_support = cpu_has_kvm_support,
19692 .disabled_by_bios = vmx_disabled_by_bios,
19693 .hardware_setup = hardware_setup,
19694 diff -urNp linux-2.6.32.46/arch/x86/kvm/x86.c linux-2.6.32.46/arch/x86/kvm/x86.c
19695 --- linux-2.6.32.46/arch/x86/kvm/x86.c 2011-05-10 22:12:01.000000000 -0400
19696 +++ linux-2.6.32.46/arch/x86/kvm/x86.c 2011-05-10 22:12:26.000000000 -0400
19697 @@ -82,7 +82,7 @@ static void update_cr8_intercept(struct
19698 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
19699 struct kvm_cpuid_entry2 __user *entries);
19700
19701 -struct kvm_x86_ops *kvm_x86_ops;
19702 +const struct kvm_x86_ops *kvm_x86_ops;
19703 EXPORT_SYMBOL_GPL(kvm_x86_ops);
19704
19705 int ignore_msrs = 0;
19706 @@ -1430,15 +1430,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
19707 struct kvm_cpuid2 *cpuid,
19708 struct kvm_cpuid_entry2 __user *entries)
19709 {
19710 - int r;
19711 + int r, i;
19712
19713 r = -E2BIG;
19714 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
19715 goto out;
19716 r = -EFAULT;
19717 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
19718 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19719 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19720 goto out;
19721 + for (i = 0; i < cpuid->nent; ++i) {
19722 + struct kvm_cpuid_entry2 cpuid_entry;
19723 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
19724 + goto out;
19725 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
19726 + }
19727 vcpu->arch.cpuid_nent = cpuid->nent;
19728 kvm_apic_set_version(vcpu);
19729 return 0;
19730 @@ -1451,16 +1456,20 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
19731 struct kvm_cpuid2 *cpuid,
19732 struct kvm_cpuid_entry2 __user *entries)
19733 {
19734 - int r;
19735 + int r, i;
19736
19737 vcpu_load(vcpu);
19738 r = -E2BIG;
19739 if (cpuid->nent < vcpu->arch.cpuid_nent)
19740 goto out;
19741 r = -EFAULT;
19742 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
19743 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19744 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19745 goto out;
19746 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
19747 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
19748 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
19749 + goto out;
19750 + }
19751 return 0;
19752
19753 out:
19754 @@ -1678,7 +1687,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
19755 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
19756 struct kvm_interrupt *irq)
19757 {
19758 - if (irq->irq < 0 || irq->irq >= 256)
19759 + if (irq->irq >= 256)
19760 return -EINVAL;
19761 if (irqchip_in_kernel(vcpu->kvm))
19762 return -ENXIO;
19763 @@ -3260,10 +3269,10 @@ static struct notifier_block kvmclock_cp
19764 .notifier_call = kvmclock_cpufreq_notifier
19765 };
19766
19767 -int kvm_arch_init(void *opaque)
19768 +int kvm_arch_init(const void *opaque)
19769 {
19770 int r, cpu;
19771 - struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
19772 + const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
19773
19774 if (kvm_x86_ops) {
19775 printk(KERN_ERR "kvm: already loaded the other module\n");
19776 diff -urNp linux-2.6.32.46/arch/x86/lguest/boot.c linux-2.6.32.46/arch/x86/lguest/boot.c
19777 --- linux-2.6.32.46/arch/x86/lguest/boot.c 2011-03-27 14:31:47.000000000 -0400
19778 +++ linux-2.6.32.46/arch/x86/lguest/boot.c 2011-08-05 20:33:55.000000000 -0400
19779 @@ -1172,9 +1172,10 @@ static __init int early_put_chars(u32 vt
19780 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
19781 * Launcher to reboot us.
19782 */
19783 -static void lguest_restart(char *reason)
19784 +static __noreturn void lguest_restart(char *reason)
19785 {
19786 kvm_hypercall2(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART);
19787 + BUG();
19788 }
19789
19790 /*G:050
19791 diff -urNp linux-2.6.32.46/arch/x86/lib/atomic64_32.c linux-2.6.32.46/arch/x86/lib/atomic64_32.c
19792 --- linux-2.6.32.46/arch/x86/lib/atomic64_32.c 2011-03-27 14:31:47.000000000 -0400
19793 +++ linux-2.6.32.46/arch/x86/lib/atomic64_32.c 2011-05-04 17:56:28.000000000 -0400
19794 @@ -25,6 +25,12 @@ u64 atomic64_cmpxchg(atomic64_t *ptr, u6
19795 }
19796 EXPORT_SYMBOL(atomic64_cmpxchg);
19797
19798 +u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val)
19799 +{
19800 + return cmpxchg8b(&ptr->counter, old_val, new_val);
19801 +}
19802 +EXPORT_SYMBOL(atomic64_cmpxchg_unchecked);
19803 +
19804 /**
19805 * atomic64_xchg - xchg atomic64 variable
19806 * @ptr: pointer to type atomic64_t
19807 @@ -56,6 +62,36 @@ u64 atomic64_xchg(atomic64_t *ptr, u64 n
19808 EXPORT_SYMBOL(atomic64_xchg);
19809
19810 /**
19811 + * atomic64_xchg_unchecked - xchg atomic64 variable
19812 + * @ptr: pointer to type atomic64_unchecked_t
19813 + * @new_val: value to assign
19814 + *
19815 + * Atomically xchgs the value of @ptr to @new_val and returns
19816 + * the old value.
19817 + */
19818 +u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
19819 +{
19820 + /*
19821 + * Try first with a (possibly incorrect) assumption about
19822 + * what we have there. We'll do two loops most likely,
19823 + * but we'll get an ownership MESI transaction straight away
19824 + * instead of a read transaction followed by a
19825 + * flush-for-ownership transaction:
19826 + */
19827 + u64 old_val, real_val = 0;
19828 +
19829 + do {
19830 + old_val = real_val;
19831 +
19832 + real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
19833 +
19834 + } while (real_val != old_val);
19835 +
19836 + return old_val;
19837 +}
19838 +EXPORT_SYMBOL(atomic64_xchg_unchecked);
19839 +
19840 +/**
19841 * atomic64_set - set atomic64 variable
19842 * @ptr: pointer to type atomic64_t
19843 * @new_val: value to assign
19844 @@ -69,7 +105,19 @@ void atomic64_set(atomic64_t *ptr, u64 n
19845 EXPORT_SYMBOL(atomic64_set);
19846
19847 /**
19848 -EXPORT_SYMBOL(atomic64_read);
19849 + * atomic64_unchecked_set - set atomic64 variable
19850 + * @ptr: pointer to type atomic64_unchecked_t
19851 + * @new_val: value to assign
19852 + *
19853 + * Atomically sets the value of @ptr to @new_val.
19854 + */
19855 +void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
19856 +{
19857 + atomic64_xchg_unchecked(ptr, new_val);
19858 +}
19859 +EXPORT_SYMBOL(atomic64_set_unchecked);
19860 +
19861 +/**
19862 * atomic64_add_return - add and return
19863 * @delta: integer value to add
19864 * @ptr: pointer to type atomic64_t
19865 @@ -99,24 +147,72 @@ noinline u64 atomic64_add_return(u64 del
19866 }
19867 EXPORT_SYMBOL(atomic64_add_return);
19868
19869 +/**
19870 + * atomic64_add_return_unchecked - add and return
19871 + * @delta: integer value to add
19872 + * @ptr: pointer to type atomic64_unchecked_t
19873 + *
19874 + * Atomically adds @delta to @ptr and returns @delta + *@ptr
19875 + */
19876 +noinline u64 atomic64_add_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
19877 +{
19878 + /*
19879 + * Try first with a (possibly incorrect) assumption about
19880 + * what we have there. We'll do two loops most likely,
19881 + * but we'll get an ownership MESI transaction straight away
19882 + * instead of a read transaction followed by a
19883 + * flush-for-ownership transaction:
19884 + */
19885 + u64 old_val, new_val, real_val = 0;
19886 +
19887 + do {
19888 + old_val = real_val;
19889 + new_val = old_val + delta;
19890 +
19891 + real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
19892 +
19893 + } while (real_val != old_val);
19894 +
19895 + return new_val;
19896 +}
19897 +EXPORT_SYMBOL(atomic64_add_return_unchecked);
19898 +
19899 u64 atomic64_sub_return(u64 delta, atomic64_t *ptr)
19900 {
19901 return atomic64_add_return(-delta, ptr);
19902 }
19903 EXPORT_SYMBOL(atomic64_sub_return);
19904
19905 +u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
19906 +{
19907 + return atomic64_add_return_unchecked(-delta, ptr);
19908 +}
19909 +EXPORT_SYMBOL(atomic64_sub_return_unchecked);
19910 +
19911 u64 atomic64_inc_return(atomic64_t *ptr)
19912 {
19913 return atomic64_add_return(1, ptr);
19914 }
19915 EXPORT_SYMBOL(atomic64_inc_return);
19916
19917 +u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr)
19918 +{
19919 + return atomic64_add_return_unchecked(1, ptr);
19920 +}
19921 +EXPORT_SYMBOL(atomic64_inc_return_unchecked);
19922 +
19923 u64 atomic64_dec_return(atomic64_t *ptr)
19924 {
19925 return atomic64_sub_return(1, ptr);
19926 }
19927 EXPORT_SYMBOL(atomic64_dec_return);
19928
19929 +u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr)
19930 +{
19931 + return atomic64_sub_return_unchecked(1, ptr);
19932 +}
19933 +EXPORT_SYMBOL(atomic64_dec_return_unchecked);
19934 +
19935 /**
19936 * atomic64_add - add integer to atomic64 variable
19937 * @delta: integer value to add
19938 @@ -131,6 +227,19 @@ void atomic64_add(u64 delta, atomic64_t
19939 EXPORT_SYMBOL(atomic64_add);
19940
19941 /**
19942 + * atomic64_add_unchecked - add integer to atomic64 variable
19943 + * @delta: integer value to add
19944 + * @ptr: pointer to type atomic64_unchecked_t
19945 + *
19946 + * Atomically adds @delta to @ptr.
19947 + */
19948 +void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr)
19949 +{
19950 + atomic64_add_return_unchecked(delta, ptr);
19951 +}
19952 +EXPORT_SYMBOL(atomic64_add_unchecked);
19953 +
19954 +/**
19955 * atomic64_sub - subtract the atomic64 variable
19956 * @delta: integer value to subtract
19957 * @ptr: pointer to type atomic64_t
19958 @@ -144,6 +253,19 @@ void atomic64_sub(u64 delta, atomic64_t
19959 EXPORT_SYMBOL(atomic64_sub);
19960
19961 /**
19962 + * atomic64_sub_unchecked - subtract the atomic64 variable
19963 + * @delta: integer value to subtract
19964 + * @ptr: pointer to type atomic64_unchecked_t
19965 + *
19966 + * Atomically subtracts @delta from @ptr.
19967 + */
19968 +void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr)
19969 +{
19970 + atomic64_add_unchecked(-delta, ptr);
19971 +}
19972 +EXPORT_SYMBOL(atomic64_sub_unchecked);
19973 +
19974 +/**
19975 * atomic64_sub_and_test - subtract value from variable and test result
19976 * @delta: integer value to subtract
19977 * @ptr: pointer to type atomic64_t
19978 @@ -173,6 +295,18 @@ void atomic64_inc(atomic64_t *ptr)
19979 EXPORT_SYMBOL(atomic64_inc);
19980
19981 /**
19982 + * atomic64_inc_unchecked - increment atomic64 variable
19983 + * @ptr: pointer to type atomic64_unchecked_t
19984 + *
19985 + * Atomically increments @ptr by 1.
19986 + */
19987 +void atomic64_inc_unchecked(atomic64_unchecked_t *ptr)
19988 +{
19989 + atomic64_add_unchecked(1, ptr);
19990 +}
19991 +EXPORT_SYMBOL(atomic64_inc_unchecked);
19992 +
19993 +/**
19994 * atomic64_dec - decrement atomic64 variable
19995 * @ptr: pointer to type atomic64_t
19996 *
19997 @@ -185,6 +319,18 @@ void atomic64_dec(atomic64_t *ptr)
19998 EXPORT_SYMBOL(atomic64_dec);
19999
20000 /**
20001 + * atomic64_dec_unchecked - decrement atomic64 variable
20002 + * @ptr: pointer to type atomic64_unchecked_t
20003 + *
20004 + * Atomically decrements @ptr by 1.
20005 + */
20006 +void atomic64_dec_unchecked(atomic64_unchecked_t *ptr)
20007 +{
20008 + atomic64_sub_unchecked(1, ptr);
20009 +}
20010 +EXPORT_SYMBOL(atomic64_dec_unchecked);
20011 +
20012 +/**
20013 * atomic64_dec_and_test - decrement and test
20014 * @ptr: pointer to type atomic64_t
20015 *
20016 diff -urNp linux-2.6.32.46/arch/x86/lib/checksum_32.S linux-2.6.32.46/arch/x86/lib/checksum_32.S
20017 --- linux-2.6.32.46/arch/x86/lib/checksum_32.S 2011-03-27 14:31:47.000000000 -0400
20018 +++ linux-2.6.32.46/arch/x86/lib/checksum_32.S 2011-04-17 15:56:46.000000000 -0400
20019 @@ -28,7 +28,8 @@
20020 #include <linux/linkage.h>
20021 #include <asm/dwarf2.h>
20022 #include <asm/errno.h>
20023 -
20024 +#include <asm/segment.h>
20025 +
20026 /*
20027 * computes a partial checksum, e.g. for TCP/UDP fragments
20028 */
20029 @@ -304,9 +305,28 @@ unsigned int csum_partial_copy_generic (
20030
20031 #define ARGBASE 16
20032 #define FP 12
20033 -
20034 -ENTRY(csum_partial_copy_generic)
20035 +
20036 +ENTRY(csum_partial_copy_generic_to_user)
20037 CFI_STARTPROC
20038 +
20039 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20040 + pushl %gs
20041 + CFI_ADJUST_CFA_OFFSET 4
20042 + popl %es
20043 + CFI_ADJUST_CFA_OFFSET -4
20044 + jmp csum_partial_copy_generic
20045 +#endif
20046 +
20047 +ENTRY(csum_partial_copy_generic_from_user)
20048 +
20049 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20050 + pushl %gs
20051 + CFI_ADJUST_CFA_OFFSET 4
20052 + popl %ds
20053 + CFI_ADJUST_CFA_OFFSET -4
20054 +#endif
20055 +
20056 +ENTRY(csum_partial_copy_generic)
20057 subl $4,%esp
20058 CFI_ADJUST_CFA_OFFSET 4
20059 pushl %edi
20060 @@ -331,7 +351,7 @@ ENTRY(csum_partial_copy_generic)
20061 jmp 4f
20062 SRC(1: movw (%esi), %bx )
20063 addl $2, %esi
20064 -DST( movw %bx, (%edi) )
20065 +DST( movw %bx, %es:(%edi) )
20066 addl $2, %edi
20067 addw %bx, %ax
20068 adcl $0, %eax
20069 @@ -343,30 +363,30 @@ DST( movw %bx, (%edi) )
20070 SRC(1: movl (%esi), %ebx )
20071 SRC( movl 4(%esi), %edx )
20072 adcl %ebx, %eax
20073 -DST( movl %ebx, (%edi) )
20074 +DST( movl %ebx, %es:(%edi) )
20075 adcl %edx, %eax
20076 -DST( movl %edx, 4(%edi) )
20077 +DST( movl %edx, %es:4(%edi) )
20078
20079 SRC( movl 8(%esi), %ebx )
20080 SRC( movl 12(%esi), %edx )
20081 adcl %ebx, %eax
20082 -DST( movl %ebx, 8(%edi) )
20083 +DST( movl %ebx, %es:8(%edi) )
20084 adcl %edx, %eax
20085 -DST( movl %edx, 12(%edi) )
20086 +DST( movl %edx, %es:12(%edi) )
20087
20088 SRC( movl 16(%esi), %ebx )
20089 SRC( movl 20(%esi), %edx )
20090 adcl %ebx, %eax
20091 -DST( movl %ebx, 16(%edi) )
20092 +DST( movl %ebx, %es:16(%edi) )
20093 adcl %edx, %eax
20094 -DST( movl %edx, 20(%edi) )
20095 +DST( movl %edx, %es:20(%edi) )
20096
20097 SRC( movl 24(%esi), %ebx )
20098 SRC( movl 28(%esi), %edx )
20099 adcl %ebx, %eax
20100 -DST( movl %ebx, 24(%edi) )
20101 +DST( movl %ebx, %es:24(%edi) )
20102 adcl %edx, %eax
20103 -DST( movl %edx, 28(%edi) )
20104 +DST( movl %edx, %es:28(%edi) )
20105
20106 lea 32(%esi), %esi
20107 lea 32(%edi), %edi
20108 @@ -380,7 +400,7 @@ DST( movl %edx, 28(%edi) )
20109 shrl $2, %edx # This clears CF
20110 SRC(3: movl (%esi), %ebx )
20111 adcl %ebx, %eax
20112 -DST( movl %ebx, (%edi) )
20113 +DST( movl %ebx, %es:(%edi) )
20114 lea 4(%esi), %esi
20115 lea 4(%edi), %edi
20116 dec %edx
20117 @@ -392,12 +412,12 @@ DST( movl %ebx, (%edi) )
20118 jb 5f
20119 SRC( movw (%esi), %cx )
20120 leal 2(%esi), %esi
20121 -DST( movw %cx, (%edi) )
20122 +DST( movw %cx, %es:(%edi) )
20123 leal 2(%edi), %edi
20124 je 6f
20125 shll $16,%ecx
20126 SRC(5: movb (%esi), %cl )
20127 -DST( movb %cl, (%edi) )
20128 +DST( movb %cl, %es:(%edi) )
20129 6: addl %ecx, %eax
20130 adcl $0, %eax
20131 7:
20132 @@ -408,7 +428,7 @@ DST( movb %cl, (%edi) )
20133
20134 6001:
20135 movl ARGBASE+20(%esp), %ebx # src_err_ptr
20136 - movl $-EFAULT, (%ebx)
20137 + movl $-EFAULT, %ss:(%ebx)
20138
20139 # zero the complete destination - computing the rest
20140 # is too much work
20141 @@ -421,11 +441,19 @@ DST( movb %cl, (%edi) )
20142
20143 6002:
20144 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20145 - movl $-EFAULT,(%ebx)
20146 + movl $-EFAULT,%ss:(%ebx)
20147 jmp 5000b
20148
20149 .previous
20150
20151 + pushl %ss
20152 + CFI_ADJUST_CFA_OFFSET 4
20153 + popl %ds
20154 + CFI_ADJUST_CFA_OFFSET -4
20155 + pushl %ss
20156 + CFI_ADJUST_CFA_OFFSET 4
20157 + popl %es
20158 + CFI_ADJUST_CFA_OFFSET -4
20159 popl %ebx
20160 CFI_ADJUST_CFA_OFFSET -4
20161 CFI_RESTORE ebx
20162 @@ -439,26 +467,47 @@ DST( movb %cl, (%edi) )
20163 CFI_ADJUST_CFA_OFFSET -4
20164 ret
20165 CFI_ENDPROC
20166 -ENDPROC(csum_partial_copy_generic)
20167 +ENDPROC(csum_partial_copy_generic_to_user)
20168
20169 #else
20170
20171 /* Version for PentiumII/PPro */
20172
20173 #define ROUND1(x) \
20174 + nop; nop; nop; \
20175 SRC(movl x(%esi), %ebx ) ; \
20176 addl %ebx, %eax ; \
20177 - DST(movl %ebx, x(%edi) ) ;
20178 + DST(movl %ebx, %es:x(%edi)) ;
20179
20180 #define ROUND(x) \
20181 + nop; nop; nop; \
20182 SRC(movl x(%esi), %ebx ) ; \
20183 adcl %ebx, %eax ; \
20184 - DST(movl %ebx, x(%edi) ) ;
20185 + DST(movl %ebx, %es:x(%edi)) ;
20186
20187 #define ARGBASE 12
20188 -
20189 -ENTRY(csum_partial_copy_generic)
20190 +
20191 +ENTRY(csum_partial_copy_generic_to_user)
20192 CFI_STARTPROC
20193 +
20194 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20195 + pushl %gs
20196 + CFI_ADJUST_CFA_OFFSET 4
20197 + popl %es
20198 + CFI_ADJUST_CFA_OFFSET -4
20199 + jmp csum_partial_copy_generic
20200 +#endif
20201 +
20202 +ENTRY(csum_partial_copy_generic_from_user)
20203 +
20204 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20205 + pushl %gs
20206 + CFI_ADJUST_CFA_OFFSET 4
20207 + popl %ds
20208 + CFI_ADJUST_CFA_OFFSET -4
20209 +#endif
20210 +
20211 +ENTRY(csum_partial_copy_generic)
20212 pushl %ebx
20213 CFI_ADJUST_CFA_OFFSET 4
20214 CFI_REL_OFFSET ebx, 0
20215 @@ -482,7 +531,7 @@ ENTRY(csum_partial_copy_generic)
20216 subl %ebx, %edi
20217 lea -1(%esi),%edx
20218 andl $-32,%edx
20219 - lea 3f(%ebx,%ebx), %ebx
20220 + lea 3f(%ebx,%ebx,2), %ebx
20221 testl %esi, %esi
20222 jmp *%ebx
20223 1: addl $64,%esi
20224 @@ -503,19 +552,19 @@ ENTRY(csum_partial_copy_generic)
20225 jb 5f
20226 SRC( movw (%esi), %dx )
20227 leal 2(%esi), %esi
20228 -DST( movw %dx, (%edi) )
20229 +DST( movw %dx, %es:(%edi) )
20230 leal 2(%edi), %edi
20231 je 6f
20232 shll $16,%edx
20233 5:
20234 SRC( movb (%esi), %dl )
20235 -DST( movb %dl, (%edi) )
20236 +DST( movb %dl, %es:(%edi) )
20237 6: addl %edx, %eax
20238 adcl $0, %eax
20239 7:
20240 .section .fixup, "ax"
20241 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
20242 - movl $-EFAULT, (%ebx)
20243 + movl $-EFAULT, %ss:(%ebx)
20244 # zero the complete destination (computing the rest is too much work)
20245 movl ARGBASE+8(%esp),%edi # dst
20246 movl ARGBASE+12(%esp),%ecx # len
20247 @@ -523,10 +572,21 @@ DST( movb %dl, (%edi) )
20248 rep; stosb
20249 jmp 7b
20250 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20251 - movl $-EFAULT, (%ebx)
20252 + movl $-EFAULT, %ss:(%ebx)
20253 jmp 7b
20254 .previous
20255
20256 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20257 + pushl %ss
20258 + CFI_ADJUST_CFA_OFFSET 4
20259 + popl %ds
20260 + CFI_ADJUST_CFA_OFFSET -4
20261 + pushl %ss
20262 + CFI_ADJUST_CFA_OFFSET 4
20263 + popl %es
20264 + CFI_ADJUST_CFA_OFFSET -4
20265 +#endif
20266 +
20267 popl %esi
20268 CFI_ADJUST_CFA_OFFSET -4
20269 CFI_RESTORE esi
20270 @@ -538,7 +598,7 @@ DST( movb %dl, (%edi) )
20271 CFI_RESTORE ebx
20272 ret
20273 CFI_ENDPROC
20274 -ENDPROC(csum_partial_copy_generic)
20275 +ENDPROC(csum_partial_copy_generic_to_user)
20276
20277 #undef ROUND
20278 #undef ROUND1
20279 diff -urNp linux-2.6.32.46/arch/x86/lib/clear_page_64.S linux-2.6.32.46/arch/x86/lib/clear_page_64.S
20280 --- linux-2.6.32.46/arch/x86/lib/clear_page_64.S 2011-03-27 14:31:47.000000000 -0400
20281 +++ linux-2.6.32.46/arch/x86/lib/clear_page_64.S 2011-10-06 09:37:08.000000000 -0400
20282 @@ -1,5 +1,6 @@
20283 #include <linux/linkage.h>
20284 #include <asm/dwarf2.h>
20285 +#include <asm/alternative-asm.h>
20286
20287 /*
20288 * Zero a page.
20289 @@ -10,6 +11,7 @@ ENTRY(clear_page_c)
20290 movl $4096/8,%ecx
20291 xorl %eax,%eax
20292 rep stosq
20293 + pax_force_retaddr
20294 ret
20295 CFI_ENDPROC
20296 ENDPROC(clear_page_c)
20297 @@ -33,6 +35,7 @@ ENTRY(clear_page)
20298 leaq 64(%rdi),%rdi
20299 jnz .Lloop
20300 nop
20301 + pax_force_retaddr
20302 ret
20303 CFI_ENDPROC
20304 .Lclear_page_end:
20305 @@ -43,7 +46,7 @@ ENDPROC(clear_page)
20306
20307 #include <asm/cpufeature.h>
20308
20309 - .section .altinstr_replacement,"ax"
20310 + .section .altinstr_replacement,"a"
20311 1: .byte 0xeb /* jmp <disp8> */
20312 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
20313 2:
20314 diff -urNp linux-2.6.32.46/arch/x86/lib/copy_page_64.S linux-2.6.32.46/arch/x86/lib/copy_page_64.S
20315 --- linux-2.6.32.46/arch/x86/lib/copy_page_64.S 2011-03-27 14:31:47.000000000 -0400
20316 +++ linux-2.6.32.46/arch/x86/lib/copy_page_64.S 2011-10-06 09:37:08.000000000 -0400
20317 @@ -2,12 +2,14 @@
20318
20319 #include <linux/linkage.h>
20320 #include <asm/dwarf2.h>
20321 +#include <asm/alternative-asm.h>
20322
20323 ALIGN
20324 copy_page_c:
20325 CFI_STARTPROC
20326 movl $4096/8,%ecx
20327 rep movsq
20328 + pax_force_retaddr
20329 ret
20330 CFI_ENDPROC
20331 ENDPROC(copy_page_c)
20332 @@ -94,6 +96,7 @@ ENTRY(copy_page)
20333 CFI_RESTORE r13
20334 addq $3*8,%rsp
20335 CFI_ADJUST_CFA_OFFSET -3*8
20336 + pax_force_retaddr
20337 ret
20338 .Lcopy_page_end:
20339 CFI_ENDPROC
20340 @@ -104,7 +107,7 @@ ENDPROC(copy_page)
20341
20342 #include <asm/cpufeature.h>
20343
20344 - .section .altinstr_replacement,"ax"
20345 + .section .altinstr_replacement,"a"
20346 1: .byte 0xeb /* jmp <disp8> */
20347 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
20348 2:
20349 diff -urNp linux-2.6.32.46/arch/x86/lib/copy_user_64.S linux-2.6.32.46/arch/x86/lib/copy_user_64.S
20350 --- linux-2.6.32.46/arch/x86/lib/copy_user_64.S 2011-06-25 12:55:34.000000000 -0400
20351 +++ linux-2.6.32.46/arch/x86/lib/copy_user_64.S 2011-10-06 10:12:52.000000000 -0400
20352 @@ -15,13 +15,15 @@
20353 #include <asm/asm-offsets.h>
20354 #include <asm/thread_info.h>
20355 #include <asm/cpufeature.h>
20356 +#include <asm/pgtable.h>
20357 +#include <asm/alternative-asm.h>
20358
20359 .macro ALTERNATIVE_JUMP feature,orig,alt
20360 0:
20361 .byte 0xe9 /* 32bit jump */
20362 .long \orig-1f /* by default jump to orig */
20363 1:
20364 - .section .altinstr_replacement,"ax"
20365 + .section .altinstr_replacement,"a"
20366 2: .byte 0xe9 /* near jump with 32bit immediate */
20367 .long \alt-1b /* offset */ /* or alternatively to alt */
20368 .previous
20369 @@ -64,55 +66,26 @@
20370 #endif
20371 .endm
20372
20373 -/* Standard copy_to_user with segment limit checking */
20374 -ENTRY(copy_to_user)
20375 - CFI_STARTPROC
20376 - GET_THREAD_INFO(%rax)
20377 - movq %rdi,%rcx
20378 - addq %rdx,%rcx
20379 - jc bad_to_user
20380 - cmpq TI_addr_limit(%rax),%rcx
20381 - ja bad_to_user
20382 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
20383 - CFI_ENDPROC
20384 -ENDPROC(copy_to_user)
20385 -
20386 -/* Standard copy_from_user with segment limit checking */
20387 -ENTRY(copy_from_user)
20388 - CFI_STARTPROC
20389 - GET_THREAD_INFO(%rax)
20390 - movq %rsi,%rcx
20391 - addq %rdx,%rcx
20392 - jc bad_from_user
20393 - cmpq TI_addr_limit(%rax),%rcx
20394 - ja bad_from_user
20395 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
20396 - CFI_ENDPROC
20397 -ENDPROC(copy_from_user)
20398 -
20399 ENTRY(copy_user_generic)
20400 CFI_STARTPROC
20401 ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
20402 CFI_ENDPROC
20403 ENDPROC(copy_user_generic)
20404
20405 -ENTRY(__copy_from_user_inatomic)
20406 - CFI_STARTPROC
20407 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
20408 - CFI_ENDPROC
20409 -ENDPROC(__copy_from_user_inatomic)
20410 -
20411 .section .fixup,"ax"
20412 /* must zero dest */
20413 ENTRY(bad_from_user)
20414 bad_from_user:
20415 CFI_STARTPROC
20416 + testl %edx,%edx
20417 + js bad_to_user
20418 movl %edx,%ecx
20419 xorl %eax,%eax
20420 rep
20421 stosb
20422 bad_to_user:
20423 movl %edx,%eax
20424 + pax_force_retaddr
20425 ret
20426 CFI_ENDPROC
20427 ENDPROC(bad_from_user)
20428 @@ -180,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
20429 decl %ecx
20430 jnz 21b
20431 23: xor %eax,%eax
20432 + pax_force_retaddr
20433 ret
20434
20435 .section .fixup,"ax"
20436 @@ -252,6 +226,7 @@ ENTRY(copy_user_generic_string)
20437 3: rep
20438 movsb
20439 4: xorl %eax,%eax
20440 + pax_force_retaddr
20441 ret
20442
20443 .section .fixup,"ax"
20444 diff -urNp linux-2.6.32.46/arch/x86/lib/copy_user_nocache_64.S linux-2.6.32.46/arch/x86/lib/copy_user_nocache_64.S
20445 --- linux-2.6.32.46/arch/x86/lib/copy_user_nocache_64.S 2011-03-27 14:31:47.000000000 -0400
20446 +++ linux-2.6.32.46/arch/x86/lib/copy_user_nocache_64.S 2011-10-06 09:37:08.000000000 -0400
20447 @@ -8,12 +8,14 @@
20448
20449 #include <linux/linkage.h>
20450 #include <asm/dwarf2.h>
20451 +#include <asm/alternative-asm.h>
20452
20453 #define FIX_ALIGNMENT 1
20454
20455 #include <asm/current.h>
20456 #include <asm/asm-offsets.h>
20457 #include <asm/thread_info.h>
20458 +#include <asm/pgtable.h>
20459
20460 .macro ALIGN_DESTINATION
20461 #ifdef FIX_ALIGNMENT
20462 @@ -50,6 +52,15 @@
20463 */
20464 ENTRY(__copy_user_nocache)
20465 CFI_STARTPROC
20466 +
20467 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20468 + mov $PAX_USER_SHADOW_BASE,%rcx
20469 + cmp %rcx,%rsi
20470 + jae 1f
20471 + add %rcx,%rsi
20472 +1:
20473 +#endif
20474 +
20475 cmpl $8,%edx
20476 jb 20f /* less then 8 bytes, go to byte copy loop */
20477 ALIGN_DESTINATION
20478 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
20479 jnz 21b
20480 23: xorl %eax,%eax
20481 sfence
20482 + pax_force_retaddr
20483 ret
20484
20485 .section .fixup,"ax"
20486 diff -urNp linux-2.6.32.46/arch/x86/lib/csum-copy_64.S linux-2.6.32.46/arch/x86/lib/csum-copy_64.S
20487 --- linux-2.6.32.46/arch/x86/lib/csum-copy_64.S 2011-03-27 14:31:47.000000000 -0400
20488 +++ linux-2.6.32.46/arch/x86/lib/csum-copy_64.S 2011-10-06 09:37:14.000000000 -0400
20489 @@ -8,6 +8,7 @@
20490 #include <linux/linkage.h>
20491 #include <asm/dwarf2.h>
20492 #include <asm/errno.h>
20493 +#include <asm/alternative-asm.h>
20494
20495 /*
20496 * Checksum copy with exception handling.
20497 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
20498 CFI_RESTORE rbp
20499 addq $7*8,%rsp
20500 CFI_ADJUST_CFA_OFFSET -7*8
20501 + pax_force_retaddr
20502 ret
20503 CFI_RESTORE_STATE
20504
20505 diff -urNp linux-2.6.32.46/arch/x86/lib/csum-wrappers_64.c linux-2.6.32.46/arch/x86/lib/csum-wrappers_64.c
20506 --- linux-2.6.32.46/arch/x86/lib/csum-wrappers_64.c 2011-03-27 14:31:47.000000000 -0400
20507 +++ linux-2.6.32.46/arch/x86/lib/csum-wrappers_64.c 2011-10-06 09:37:08.000000000 -0400
20508 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void _
20509 len -= 2;
20510 }
20511 }
20512 - isum = csum_partial_copy_generic((__force const void *)src,
20513 +
20514 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20515 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
20516 + src += PAX_USER_SHADOW_BASE;
20517 +#endif
20518 +
20519 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
20520 dst, len, isum, errp, NULL);
20521 if (unlikely(*errp))
20522 goto out_err;
20523 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *sr
20524 }
20525
20526 *errp = 0;
20527 - return csum_partial_copy_generic(src, (void __force *)dst,
20528 +
20529 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20530 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
20531 + dst += PAX_USER_SHADOW_BASE;
20532 +#endif
20533 +
20534 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
20535 len, isum, NULL, errp);
20536 }
20537 EXPORT_SYMBOL(csum_partial_copy_to_user);
20538 diff -urNp linux-2.6.32.46/arch/x86/lib/getuser.S linux-2.6.32.46/arch/x86/lib/getuser.S
20539 --- linux-2.6.32.46/arch/x86/lib/getuser.S 2011-03-27 14:31:47.000000000 -0400
20540 +++ linux-2.6.32.46/arch/x86/lib/getuser.S 2011-10-08 08:14:37.000000000 -0400
20541 @@ -33,15 +33,38 @@
20542 #include <asm/asm-offsets.h>
20543 #include <asm/thread_info.h>
20544 #include <asm/asm.h>
20545 +#include <asm/segment.h>
20546 +#include <asm/pgtable.h>
20547 +#include <asm/alternative-asm.h>
20548 +
20549 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20550 +#define __copyuser_seg gs;
20551 +#else
20552 +#define __copyuser_seg
20553 +#endif
20554
20555 .text
20556 ENTRY(__get_user_1)
20557 CFI_STARTPROC
20558 +
20559 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20560 GET_THREAD_INFO(%_ASM_DX)
20561 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
20562 jae bad_get_user
20563 -1: movzb (%_ASM_AX),%edx
20564 +
20565 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20566 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
20567 + cmp %_ASM_DX,%_ASM_AX
20568 + jae 1234f
20569 + add %_ASM_DX,%_ASM_AX
20570 +1234:
20571 +#endif
20572 +
20573 +#endif
20574 +
20575 +1: __copyuser_seg movzb (%_ASM_AX),%edx
20576 xor %eax,%eax
20577 + pax_force_retaddr
20578 ret
20579 CFI_ENDPROC
20580 ENDPROC(__get_user_1)
20581 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
20582 ENTRY(__get_user_2)
20583 CFI_STARTPROC
20584 add $1,%_ASM_AX
20585 +
20586 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20587 jc bad_get_user
20588 GET_THREAD_INFO(%_ASM_DX)
20589 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
20590 jae bad_get_user
20591 -2: movzwl -1(%_ASM_AX),%edx
20592 +
20593 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20594 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
20595 + cmp %_ASM_DX,%_ASM_AX
20596 + jae 1234f
20597 + add %_ASM_DX,%_ASM_AX
20598 +1234:
20599 +#endif
20600 +
20601 +#endif
20602 +
20603 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
20604 xor %eax,%eax
20605 + pax_force_retaddr
20606 ret
20607 CFI_ENDPROC
20608 ENDPROC(__get_user_2)
20609 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
20610 ENTRY(__get_user_4)
20611 CFI_STARTPROC
20612 add $3,%_ASM_AX
20613 +
20614 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20615 jc bad_get_user
20616 GET_THREAD_INFO(%_ASM_DX)
20617 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
20618 jae bad_get_user
20619 -3: mov -3(%_ASM_AX),%edx
20620 +
20621 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20622 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
20623 + cmp %_ASM_DX,%_ASM_AX
20624 + jae 1234f
20625 + add %_ASM_DX,%_ASM_AX
20626 +1234:
20627 +#endif
20628 +
20629 +#endif
20630 +
20631 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
20632 xor %eax,%eax
20633 + pax_force_retaddr
20634 ret
20635 CFI_ENDPROC
20636 ENDPROC(__get_user_4)
20637 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
20638 GET_THREAD_INFO(%_ASM_DX)
20639 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
20640 jae bad_get_user
20641 +
20642 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20643 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
20644 + cmp %_ASM_DX,%_ASM_AX
20645 + jae 1234f
20646 + add %_ASM_DX,%_ASM_AX
20647 +1234:
20648 +#endif
20649 +
20650 4: movq -7(%_ASM_AX),%_ASM_DX
20651 xor %eax,%eax
20652 + pax_force_retaddr
20653 ret
20654 CFI_ENDPROC
20655 ENDPROC(__get_user_8)
20656 @@ -91,6 +152,7 @@ bad_get_user:
20657 CFI_STARTPROC
20658 xor %edx,%edx
20659 mov $(-EFAULT),%_ASM_AX
20660 + pax_force_retaddr
20661 ret
20662 CFI_ENDPROC
20663 END(bad_get_user)
20664 diff -urNp linux-2.6.32.46/arch/x86/lib/iomap_copy_64.S linux-2.6.32.46/arch/x86/lib/iomap_copy_64.S
20665 --- linux-2.6.32.46/arch/x86/lib/iomap_copy_64.S 2011-03-27 14:31:47.000000000 -0400
20666 +++ linux-2.6.32.46/arch/x86/lib/iomap_copy_64.S 2011-10-06 09:37:14.000000000 -0400
20667 @@ -17,6 +17,7 @@
20668
20669 #include <linux/linkage.h>
20670 #include <asm/dwarf2.h>
20671 +#include <asm/alternative-asm.h>
20672
20673 /*
20674 * override generic version in lib/iomap_copy.c
20675 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
20676 CFI_STARTPROC
20677 movl %edx,%ecx
20678 rep movsd
20679 + pax_force_retaddr
20680 ret
20681 CFI_ENDPROC
20682 ENDPROC(__iowrite32_copy)
20683 diff -urNp linux-2.6.32.46/arch/x86/lib/memcpy_64.S linux-2.6.32.46/arch/x86/lib/memcpy_64.S
20684 --- linux-2.6.32.46/arch/x86/lib/memcpy_64.S 2011-03-27 14:31:47.000000000 -0400
20685 +++ linux-2.6.32.46/arch/x86/lib/memcpy_64.S 2011-10-06 10:13:49.000000000 -0400
20686 @@ -4,6 +4,7 @@
20687
20688 #include <asm/cpufeature.h>
20689 #include <asm/dwarf2.h>
20690 +#include <asm/alternative-asm.h>
20691
20692 /*
20693 * memcpy - Copy a memory block.
20694 @@ -34,6 +35,7 @@ memcpy_c:
20695 rep movsq
20696 movl %edx, %ecx
20697 rep movsb
20698 + pax_force_retaddr
20699 ret
20700 CFI_ENDPROC
20701 ENDPROC(memcpy_c)
20702 @@ -118,6 +120,7 @@ ENTRY(memcpy)
20703 jnz .Lloop_1
20704
20705 .Lend:
20706 + pax_force_retaddr
20707 ret
20708 CFI_ENDPROC
20709 ENDPROC(memcpy)
20710 @@ -128,7 +131,7 @@ ENDPROC(__memcpy)
20711 * It is also a lot simpler. Use this when possible:
20712 */
20713
20714 - .section .altinstr_replacement, "ax"
20715 + .section .altinstr_replacement, "a"
20716 1: .byte 0xeb /* jmp <disp8> */
20717 .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
20718 2:
20719 diff -urNp linux-2.6.32.46/arch/x86/lib/memset_64.S linux-2.6.32.46/arch/x86/lib/memset_64.S
20720 --- linux-2.6.32.46/arch/x86/lib/memset_64.S 2011-03-27 14:31:47.000000000 -0400
20721 +++ linux-2.6.32.46/arch/x86/lib/memset_64.S 2011-10-06 09:37:08.000000000 -0400
20722 @@ -2,6 +2,7 @@
20723
20724 #include <linux/linkage.h>
20725 #include <asm/dwarf2.h>
20726 +#include <asm/alternative-asm.h>
20727
20728 /*
20729 * ISO C memset - set a memory block to a byte value.
20730 @@ -28,6 +29,7 @@ memset_c:
20731 movl %r8d,%ecx
20732 rep stosb
20733 movq %r9,%rax
20734 + pax_force_retaddr
20735 ret
20736 CFI_ENDPROC
20737 ENDPROC(memset_c)
20738 @@ -96,6 +98,7 @@ ENTRY(__memset)
20739
20740 .Lende:
20741 movq %r10,%rax
20742 + pax_force_retaddr
20743 ret
20744
20745 CFI_RESTORE_STATE
20746 @@ -118,7 +121,7 @@ ENDPROC(__memset)
20747
20748 #include <asm/cpufeature.h>
20749
20750 - .section .altinstr_replacement,"ax"
20751 + .section .altinstr_replacement,"a"
20752 1: .byte 0xeb /* jmp <disp8> */
20753 .byte (memset_c - memset) - (2f - 1b) /* offset */
20754 2:
20755 diff -urNp linux-2.6.32.46/arch/x86/lib/mmx_32.c linux-2.6.32.46/arch/x86/lib/mmx_32.c
20756 --- linux-2.6.32.46/arch/x86/lib/mmx_32.c 2011-03-27 14:31:47.000000000 -0400
20757 +++ linux-2.6.32.46/arch/x86/lib/mmx_32.c 2011-04-17 15:56:46.000000000 -0400
20758 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
20759 {
20760 void *p;
20761 int i;
20762 + unsigned long cr0;
20763
20764 if (unlikely(in_interrupt()))
20765 return __memcpy(to, from, len);
20766 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
20767 kernel_fpu_begin();
20768
20769 __asm__ __volatile__ (
20770 - "1: prefetch (%0)\n" /* This set is 28 bytes */
20771 - " prefetch 64(%0)\n"
20772 - " prefetch 128(%0)\n"
20773 - " prefetch 192(%0)\n"
20774 - " prefetch 256(%0)\n"
20775 + "1: prefetch (%1)\n" /* This set is 28 bytes */
20776 + " prefetch 64(%1)\n"
20777 + " prefetch 128(%1)\n"
20778 + " prefetch 192(%1)\n"
20779 + " prefetch 256(%1)\n"
20780 "2: \n"
20781 ".section .fixup, \"ax\"\n"
20782 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20783 + "3: \n"
20784 +
20785 +#ifdef CONFIG_PAX_KERNEXEC
20786 + " movl %%cr0, %0\n"
20787 + " movl %0, %%eax\n"
20788 + " andl $0xFFFEFFFF, %%eax\n"
20789 + " movl %%eax, %%cr0\n"
20790 +#endif
20791 +
20792 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20793 +
20794 +#ifdef CONFIG_PAX_KERNEXEC
20795 + " movl %0, %%cr0\n"
20796 +#endif
20797 +
20798 " jmp 2b\n"
20799 ".previous\n"
20800 _ASM_EXTABLE(1b, 3b)
20801 - : : "r" (from));
20802 + : "=&r" (cr0) : "r" (from) : "ax");
20803
20804 for ( ; i > 5; i--) {
20805 __asm__ __volatile__ (
20806 - "1: prefetch 320(%0)\n"
20807 - "2: movq (%0), %%mm0\n"
20808 - " movq 8(%0), %%mm1\n"
20809 - " movq 16(%0), %%mm2\n"
20810 - " movq 24(%0), %%mm3\n"
20811 - " movq %%mm0, (%1)\n"
20812 - " movq %%mm1, 8(%1)\n"
20813 - " movq %%mm2, 16(%1)\n"
20814 - " movq %%mm3, 24(%1)\n"
20815 - " movq 32(%0), %%mm0\n"
20816 - " movq 40(%0), %%mm1\n"
20817 - " movq 48(%0), %%mm2\n"
20818 - " movq 56(%0), %%mm3\n"
20819 - " movq %%mm0, 32(%1)\n"
20820 - " movq %%mm1, 40(%1)\n"
20821 - " movq %%mm2, 48(%1)\n"
20822 - " movq %%mm3, 56(%1)\n"
20823 + "1: prefetch 320(%1)\n"
20824 + "2: movq (%1), %%mm0\n"
20825 + " movq 8(%1), %%mm1\n"
20826 + " movq 16(%1), %%mm2\n"
20827 + " movq 24(%1), %%mm3\n"
20828 + " movq %%mm0, (%2)\n"
20829 + " movq %%mm1, 8(%2)\n"
20830 + " movq %%mm2, 16(%2)\n"
20831 + " movq %%mm3, 24(%2)\n"
20832 + " movq 32(%1), %%mm0\n"
20833 + " movq 40(%1), %%mm1\n"
20834 + " movq 48(%1), %%mm2\n"
20835 + " movq 56(%1), %%mm3\n"
20836 + " movq %%mm0, 32(%2)\n"
20837 + " movq %%mm1, 40(%2)\n"
20838 + " movq %%mm2, 48(%2)\n"
20839 + " movq %%mm3, 56(%2)\n"
20840 ".section .fixup, \"ax\"\n"
20841 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20842 + "3:\n"
20843 +
20844 +#ifdef CONFIG_PAX_KERNEXEC
20845 + " movl %%cr0, %0\n"
20846 + " movl %0, %%eax\n"
20847 + " andl $0xFFFEFFFF, %%eax\n"
20848 + " movl %%eax, %%cr0\n"
20849 +#endif
20850 +
20851 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20852 +
20853 +#ifdef CONFIG_PAX_KERNEXEC
20854 + " movl %0, %%cr0\n"
20855 +#endif
20856 +
20857 " jmp 2b\n"
20858 ".previous\n"
20859 _ASM_EXTABLE(1b, 3b)
20860 - : : "r" (from), "r" (to) : "memory");
20861 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20862
20863 from += 64;
20864 to += 64;
20865 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
20866 static void fast_copy_page(void *to, void *from)
20867 {
20868 int i;
20869 + unsigned long cr0;
20870
20871 kernel_fpu_begin();
20872
20873 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
20874 * but that is for later. -AV
20875 */
20876 __asm__ __volatile__(
20877 - "1: prefetch (%0)\n"
20878 - " prefetch 64(%0)\n"
20879 - " prefetch 128(%0)\n"
20880 - " prefetch 192(%0)\n"
20881 - " prefetch 256(%0)\n"
20882 + "1: prefetch (%1)\n"
20883 + " prefetch 64(%1)\n"
20884 + " prefetch 128(%1)\n"
20885 + " prefetch 192(%1)\n"
20886 + " prefetch 256(%1)\n"
20887 "2: \n"
20888 ".section .fixup, \"ax\"\n"
20889 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20890 + "3: \n"
20891 +
20892 +#ifdef CONFIG_PAX_KERNEXEC
20893 + " movl %%cr0, %0\n"
20894 + " movl %0, %%eax\n"
20895 + " andl $0xFFFEFFFF, %%eax\n"
20896 + " movl %%eax, %%cr0\n"
20897 +#endif
20898 +
20899 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20900 +
20901 +#ifdef CONFIG_PAX_KERNEXEC
20902 + " movl %0, %%cr0\n"
20903 +#endif
20904 +
20905 " jmp 2b\n"
20906 ".previous\n"
20907 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20908 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20909
20910 for (i = 0; i < (4096-320)/64; i++) {
20911 __asm__ __volatile__ (
20912 - "1: prefetch 320(%0)\n"
20913 - "2: movq (%0), %%mm0\n"
20914 - " movntq %%mm0, (%1)\n"
20915 - " movq 8(%0), %%mm1\n"
20916 - " movntq %%mm1, 8(%1)\n"
20917 - " movq 16(%0), %%mm2\n"
20918 - " movntq %%mm2, 16(%1)\n"
20919 - " movq 24(%0), %%mm3\n"
20920 - " movntq %%mm3, 24(%1)\n"
20921 - " movq 32(%0), %%mm4\n"
20922 - " movntq %%mm4, 32(%1)\n"
20923 - " movq 40(%0), %%mm5\n"
20924 - " movntq %%mm5, 40(%1)\n"
20925 - " movq 48(%0), %%mm6\n"
20926 - " movntq %%mm6, 48(%1)\n"
20927 - " movq 56(%0), %%mm7\n"
20928 - " movntq %%mm7, 56(%1)\n"
20929 + "1: prefetch 320(%1)\n"
20930 + "2: movq (%1), %%mm0\n"
20931 + " movntq %%mm0, (%2)\n"
20932 + " movq 8(%1), %%mm1\n"
20933 + " movntq %%mm1, 8(%2)\n"
20934 + " movq 16(%1), %%mm2\n"
20935 + " movntq %%mm2, 16(%2)\n"
20936 + " movq 24(%1), %%mm3\n"
20937 + " movntq %%mm3, 24(%2)\n"
20938 + " movq 32(%1), %%mm4\n"
20939 + " movntq %%mm4, 32(%2)\n"
20940 + " movq 40(%1), %%mm5\n"
20941 + " movntq %%mm5, 40(%2)\n"
20942 + " movq 48(%1), %%mm6\n"
20943 + " movntq %%mm6, 48(%2)\n"
20944 + " movq 56(%1), %%mm7\n"
20945 + " movntq %%mm7, 56(%2)\n"
20946 ".section .fixup, \"ax\"\n"
20947 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20948 + "3:\n"
20949 +
20950 +#ifdef CONFIG_PAX_KERNEXEC
20951 + " movl %%cr0, %0\n"
20952 + " movl %0, %%eax\n"
20953 + " andl $0xFFFEFFFF, %%eax\n"
20954 + " movl %%eax, %%cr0\n"
20955 +#endif
20956 +
20957 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20958 +
20959 +#ifdef CONFIG_PAX_KERNEXEC
20960 + " movl %0, %%cr0\n"
20961 +#endif
20962 +
20963 " jmp 2b\n"
20964 ".previous\n"
20965 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
20966 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20967
20968 from += 64;
20969 to += 64;
20970 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
20971 static void fast_copy_page(void *to, void *from)
20972 {
20973 int i;
20974 + unsigned long cr0;
20975
20976 kernel_fpu_begin();
20977
20978 __asm__ __volatile__ (
20979 - "1: prefetch (%0)\n"
20980 - " prefetch 64(%0)\n"
20981 - " prefetch 128(%0)\n"
20982 - " prefetch 192(%0)\n"
20983 - " prefetch 256(%0)\n"
20984 + "1: prefetch (%1)\n"
20985 + " prefetch 64(%1)\n"
20986 + " prefetch 128(%1)\n"
20987 + " prefetch 192(%1)\n"
20988 + " prefetch 256(%1)\n"
20989 "2: \n"
20990 ".section .fixup, \"ax\"\n"
20991 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20992 + "3: \n"
20993 +
20994 +#ifdef CONFIG_PAX_KERNEXEC
20995 + " movl %%cr0, %0\n"
20996 + " movl %0, %%eax\n"
20997 + " andl $0xFFFEFFFF, %%eax\n"
20998 + " movl %%eax, %%cr0\n"
20999 +#endif
21000 +
21001 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21002 +
21003 +#ifdef CONFIG_PAX_KERNEXEC
21004 + " movl %0, %%cr0\n"
21005 +#endif
21006 +
21007 " jmp 2b\n"
21008 ".previous\n"
21009 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
21010 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
21011
21012 for (i = 0; i < 4096/64; i++) {
21013 __asm__ __volatile__ (
21014 - "1: prefetch 320(%0)\n"
21015 - "2: movq (%0), %%mm0\n"
21016 - " movq 8(%0), %%mm1\n"
21017 - " movq 16(%0), %%mm2\n"
21018 - " movq 24(%0), %%mm3\n"
21019 - " movq %%mm0, (%1)\n"
21020 - " movq %%mm1, 8(%1)\n"
21021 - " movq %%mm2, 16(%1)\n"
21022 - " movq %%mm3, 24(%1)\n"
21023 - " movq 32(%0), %%mm0\n"
21024 - " movq 40(%0), %%mm1\n"
21025 - " movq 48(%0), %%mm2\n"
21026 - " movq 56(%0), %%mm3\n"
21027 - " movq %%mm0, 32(%1)\n"
21028 - " movq %%mm1, 40(%1)\n"
21029 - " movq %%mm2, 48(%1)\n"
21030 - " movq %%mm3, 56(%1)\n"
21031 + "1: prefetch 320(%1)\n"
21032 + "2: movq (%1), %%mm0\n"
21033 + " movq 8(%1), %%mm1\n"
21034 + " movq 16(%1), %%mm2\n"
21035 + " movq 24(%1), %%mm3\n"
21036 + " movq %%mm0, (%2)\n"
21037 + " movq %%mm1, 8(%2)\n"
21038 + " movq %%mm2, 16(%2)\n"
21039 + " movq %%mm3, 24(%2)\n"
21040 + " movq 32(%1), %%mm0\n"
21041 + " movq 40(%1), %%mm1\n"
21042 + " movq 48(%1), %%mm2\n"
21043 + " movq 56(%1), %%mm3\n"
21044 + " movq %%mm0, 32(%2)\n"
21045 + " movq %%mm1, 40(%2)\n"
21046 + " movq %%mm2, 48(%2)\n"
21047 + " movq %%mm3, 56(%2)\n"
21048 ".section .fixup, \"ax\"\n"
21049 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21050 + "3:\n"
21051 +
21052 +#ifdef CONFIG_PAX_KERNEXEC
21053 + " movl %%cr0, %0\n"
21054 + " movl %0, %%eax\n"
21055 + " andl $0xFFFEFFFF, %%eax\n"
21056 + " movl %%eax, %%cr0\n"
21057 +#endif
21058 +
21059 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21060 +
21061 +#ifdef CONFIG_PAX_KERNEXEC
21062 + " movl %0, %%cr0\n"
21063 +#endif
21064 +
21065 " jmp 2b\n"
21066 ".previous\n"
21067 _ASM_EXTABLE(1b, 3b)
21068 - : : "r" (from), "r" (to) : "memory");
21069 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21070
21071 from += 64;
21072 to += 64;
21073 diff -urNp linux-2.6.32.46/arch/x86/lib/msr-reg.S linux-2.6.32.46/arch/x86/lib/msr-reg.S
21074 --- linux-2.6.32.46/arch/x86/lib/msr-reg.S 2011-03-27 14:31:47.000000000 -0400
21075 +++ linux-2.6.32.46/arch/x86/lib/msr-reg.S 2011-10-08 08:14:40.000000000 -0400
21076 @@ -3,6 +3,7 @@
21077 #include <asm/dwarf2.h>
21078 #include <asm/asm.h>
21079 #include <asm/msr.h>
21080 +#include <asm/alternative-asm.h>
21081
21082 #ifdef CONFIG_X86_64
21083 /*
21084 @@ -37,6 +38,7 @@ ENTRY(native_\op\()_safe_regs)
21085 movl %edi, 28(%r10)
21086 popq_cfi %rbp
21087 popq_cfi %rbx
21088 + pax_force_retaddr
21089 ret
21090 3:
21091 CFI_RESTORE_STATE
21092 diff -urNp linux-2.6.32.46/arch/x86/lib/putuser.S linux-2.6.32.46/arch/x86/lib/putuser.S
21093 --- linux-2.6.32.46/arch/x86/lib/putuser.S 2011-03-27 14:31:47.000000000 -0400
21094 +++ linux-2.6.32.46/arch/x86/lib/putuser.S 2011-10-08 08:14:40.000000000 -0400
21095 @@ -15,7 +15,9 @@
21096 #include <asm/thread_info.h>
21097 #include <asm/errno.h>
21098 #include <asm/asm.h>
21099 -
21100 +#include <asm/segment.h>
21101 +#include <asm/pgtable.h>
21102 +#include <asm/alternative-asm.h>
21103
21104 /*
21105 * __put_user_X
21106 @@ -29,52 +31,119 @@
21107 * as they get called from within inline assembly.
21108 */
21109
21110 -#define ENTER CFI_STARTPROC ; \
21111 - GET_THREAD_INFO(%_ASM_BX)
21112 -#define EXIT ret ; \
21113 +#define ENTER CFI_STARTPROC
21114 +#define EXIT pax_force_retaddr; ret ; \
21115 CFI_ENDPROC
21116
21117 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21118 +#define _DEST %_ASM_CX,%_ASM_BX
21119 +#else
21120 +#define _DEST %_ASM_CX
21121 +#endif
21122 +
21123 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21124 +#define __copyuser_seg gs;
21125 +#else
21126 +#define __copyuser_seg
21127 +#endif
21128 +
21129 .text
21130 ENTRY(__put_user_1)
21131 ENTER
21132 +
21133 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21134 + GET_THREAD_INFO(%_ASM_BX)
21135 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
21136 jae bad_put_user
21137 -1: movb %al,(%_ASM_CX)
21138 +
21139 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21140 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21141 + cmp %_ASM_BX,%_ASM_CX
21142 + jb 1234f
21143 + xor %ebx,%ebx
21144 +1234:
21145 +#endif
21146 +
21147 +#endif
21148 +
21149 +1: __copyuser_seg movb %al,(_DEST)
21150 xor %eax,%eax
21151 EXIT
21152 ENDPROC(__put_user_1)
21153
21154 ENTRY(__put_user_2)
21155 ENTER
21156 +
21157 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21158 + GET_THREAD_INFO(%_ASM_BX)
21159 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21160 sub $1,%_ASM_BX
21161 cmp %_ASM_BX,%_ASM_CX
21162 jae bad_put_user
21163 -2: movw %ax,(%_ASM_CX)
21164 +
21165 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21166 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21167 + cmp %_ASM_BX,%_ASM_CX
21168 + jb 1234f
21169 + xor %ebx,%ebx
21170 +1234:
21171 +#endif
21172 +
21173 +#endif
21174 +
21175 +2: __copyuser_seg movw %ax,(_DEST)
21176 xor %eax,%eax
21177 EXIT
21178 ENDPROC(__put_user_2)
21179
21180 ENTRY(__put_user_4)
21181 ENTER
21182 +
21183 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21184 + GET_THREAD_INFO(%_ASM_BX)
21185 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21186 sub $3,%_ASM_BX
21187 cmp %_ASM_BX,%_ASM_CX
21188 jae bad_put_user
21189 -3: movl %eax,(%_ASM_CX)
21190 +
21191 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21192 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21193 + cmp %_ASM_BX,%_ASM_CX
21194 + jb 1234f
21195 + xor %ebx,%ebx
21196 +1234:
21197 +#endif
21198 +
21199 +#endif
21200 +
21201 +3: __copyuser_seg movl %eax,(_DEST)
21202 xor %eax,%eax
21203 EXIT
21204 ENDPROC(__put_user_4)
21205
21206 ENTRY(__put_user_8)
21207 ENTER
21208 +
21209 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21210 + GET_THREAD_INFO(%_ASM_BX)
21211 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21212 sub $7,%_ASM_BX
21213 cmp %_ASM_BX,%_ASM_CX
21214 jae bad_put_user
21215 -4: mov %_ASM_AX,(%_ASM_CX)
21216 +
21217 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21218 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21219 + cmp %_ASM_BX,%_ASM_CX
21220 + jb 1234f
21221 + xor %ebx,%ebx
21222 +1234:
21223 +#endif
21224 +
21225 +#endif
21226 +
21227 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
21228 #ifdef CONFIG_X86_32
21229 -5: movl %edx,4(%_ASM_CX)
21230 +5: __copyuser_seg movl %edx,4(_DEST)
21231 #endif
21232 xor %eax,%eax
21233 EXIT
21234 diff -urNp linux-2.6.32.46/arch/x86/lib/rwlock_64.S linux-2.6.32.46/arch/x86/lib/rwlock_64.S
21235 --- linux-2.6.32.46/arch/x86/lib/rwlock_64.S 2011-03-27 14:31:47.000000000 -0400
21236 +++ linux-2.6.32.46/arch/x86/lib/rwlock_64.S 2011-10-06 09:37:14.000000000 -0400
21237 @@ -17,6 +17,7 @@ ENTRY(__write_lock_failed)
21238 LOCK_PREFIX
21239 subl $RW_LOCK_BIAS,(%rdi)
21240 jnz __write_lock_failed
21241 + pax_force_retaddr
21242 ret
21243 CFI_ENDPROC
21244 END(__write_lock_failed)
21245 @@ -33,6 +34,7 @@ ENTRY(__read_lock_failed)
21246 LOCK_PREFIX
21247 decl (%rdi)
21248 js __read_lock_failed
21249 + pax_force_retaddr
21250 ret
21251 CFI_ENDPROC
21252 END(__read_lock_failed)
21253 diff -urNp linux-2.6.32.46/arch/x86/lib/rwsem_64.S linux-2.6.32.46/arch/x86/lib/rwsem_64.S
21254 --- linux-2.6.32.46/arch/x86/lib/rwsem_64.S 2011-03-27 14:31:47.000000000 -0400
21255 +++ linux-2.6.32.46/arch/x86/lib/rwsem_64.S 2011-10-06 09:37:14.000000000 -0400
21256 @@ -48,6 +48,7 @@ ENTRY(call_rwsem_down_read_failed)
21257 call rwsem_down_read_failed
21258 popq %rdx
21259 restore_common_regs
21260 + pax_force_retaddr
21261 ret
21262 ENDPROC(call_rwsem_down_read_failed)
21263
21264 @@ -56,6 +57,7 @@ ENTRY(call_rwsem_down_write_failed)
21265 movq %rax,%rdi
21266 call rwsem_down_write_failed
21267 restore_common_regs
21268 + pax_force_retaddr
21269 ret
21270 ENDPROC(call_rwsem_down_write_failed)
21271
21272 @@ -66,7 +68,8 @@ ENTRY(call_rwsem_wake)
21273 movq %rax,%rdi
21274 call rwsem_wake
21275 restore_common_regs
21276 -1: ret
21277 +1: pax_force_retaddr
21278 + ret
21279 ENDPROC(call_rwsem_wake)
21280
21281 /* Fix up special calling conventions */
21282 @@ -77,5 +80,6 @@ ENTRY(call_rwsem_downgrade_wake)
21283 call rwsem_downgrade_wake
21284 popq %rdx
21285 restore_common_regs
21286 + pax_force_retaddr
21287 ret
21288 ENDPROC(call_rwsem_downgrade_wake)
21289 diff -urNp linux-2.6.32.46/arch/x86/lib/thunk_64.S linux-2.6.32.46/arch/x86/lib/thunk_64.S
21290 --- linux-2.6.32.46/arch/x86/lib/thunk_64.S 2011-03-27 14:31:47.000000000 -0400
21291 +++ linux-2.6.32.46/arch/x86/lib/thunk_64.S 2011-10-06 09:37:14.000000000 -0400
21292 @@ -10,7 +10,8 @@
21293 #include <asm/dwarf2.h>
21294 #include <asm/calling.h>
21295 #include <asm/rwlock.h>
21296 -
21297 + #include <asm/alternative-asm.h>
21298 +
21299 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
21300 .macro thunk name,func
21301 .globl \name
21302 @@ -70,6 +71,7 @@
21303 SAVE_ARGS
21304 restore:
21305 RESTORE_ARGS
21306 + pax_force_retaddr
21307 ret
21308 CFI_ENDPROC
21309
21310 @@ -77,5 +79,6 @@ restore:
21311 SAVE_ARGS
21312 restore_norax:
21313 RESTORE_ARGS 1
21314 + pax_force_retaddr
21315 ret
21316 CFI_ENDPROC
21317 diff -urNp linux-2.6.32.46/arch/x86/lib/usercopy_32.c linux-2.6.32.46/arch/x86/lib/usercopy_32.c
21318 --- linux-2.6.32.46/arch/x86/lib/usercopy_32.c 2011-03-27 14:31:47.000000000 -0400
21319 +++ linux-2.6.32.46/arch/x86/lib/usercopy_32.c 2011-04-23 21:12:28.000000000 -0400
21320 @@ -43,7 +43,7 @@ do { \
21321 __asm__ __volatile__( \
21322 " testl %1,%1\n" \
21323 " jz 2f\n" \
21324 - "0: lodsb\n" \
21325 + "0: "__copyuser_seg"lodsb\n" \
21326 " stosb\n" \
21327 " testb %%al,%%al\n" \
21328 " jz 1f\n" \
21329 @@ -128,10 +128,12 @@ do { \
21330 int __d0; \
21331 might_fault(); \
21332 __asm__ __volatile__( \
21333 + __COPYUSER_SET_ES \
21334 "0: rep; stosl\n" \
21335 " movl %2,%0\n" \
21336 "1: rep; stosb\n" \
21337 "2:\n" \
21338 + __COPYUSER_RESTORE_ES \
21339 ".section .fixup,\"ax\"\n" \
21340 "3: lea 0(%2,%0,4),%0\n" \
21341 " jmp 2b\n" \
21342 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
21343 might_fault();
21344
21345 __asm__ __volatile__(
21346 + __COPYUSER_SET_ES
21347 " testl %0, %0\n"
21348 " jz 3f\n"
21349 " andl %0,%%ecx\n"
21350 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
21351 " subl %%ecx,%0\n"
21352 " addl %0,%%eax\n"
21353 "1:\n"
21354 + __COPYUSER_RESTORE_ES
21355 ".section .fixup,\"ax\"\n"
21356 "2: xorl %%eax,%%eax\n"
21357 " jmp 1b\n"
21358 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
21359
21360 #ifdef CONFIG_X86_INTEL_USERCOPY
21361 static unsigned long
21362 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
21363 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
21364 {
21365 int d0, d1;
21366 __asm__ __volatile__(
21367 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
21368 " .align 2,0x90\n"
21369 "3: movl 0(%4), %%eax\n"
21370 "4: movl 4(%4), %%edx\n"
21371 - "5: movl %%eax, 0(%3)\n"
21372 - "6: movl %%edx, 4(%3)\n"
21373 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
21374 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
21375 "7: movl 8(%4), %%eax\n"
21376 "8: movl 12(%4),%%edx\n"
21377 - "9: movl %%eax, 8(%3)\n"
21378 - "10: movl %%edx, 12(%3)\n"
21379 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
21380 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
21381 "11: movl 16(%4), %%eax\n"
21382 "12: movl 20(%4), %%edx\n"
21383 - "13: movl %%eax, 16(%3)\n"
21384 - "14: movl %%edx, 20(%3)\n"
21385 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
21386 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
21387 "15: movl 24(%4), %%eax\n"
21388 "16: movl 28(%4), %%edx\n"
21389 - "17: movl %%eax, 24(%3)\n"
21390 - "18: movl %%edx, 28(%3)\n"
21391 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
21392 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
21393 "19: movl 32(%4), %%eax\n"
21394 "20: movl 36(%4), %%edx\n"
21395 - "21: movl %%eax, 32(%3)\n"
21396 - "22: movl %%edx, 36(%3)\n"
21397 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
21398 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
21399 "23: movl 40(%4), %%eax\n"
21400 "24: movl 44(%4), %%edx\n"
21401 - "25: movl %%eax, 40(%3)\n"
21402 - "26: movl %%edx, 44(%3)\n"
21403 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
21404 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
21405 "27: movl 48(%4), %%eax\n"
21406 "28: movl 52(%4), %%edx\n"
21407 - "29: movl %%eax, 48(%3)\n"
21408 - "30: movl %%edx, 52(%3)\n"
21409 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
21410 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
21411 "31: movl 56(%4), %%eax\n"
21412 "32: movl 60(%4), %%edx\n"
21413 - "33: movl %%eax, 56(%3)\n"
21414 - "34: movl %%edx, 60(%3)\n"
21415 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
21416 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
21417 " addl $-64, %0\n"
21418 " addl $64, %4\n"
21419 " addl $64, %3\n"
21420 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
21421 " shrl $2, %0\n"
21422 " andl $3, %%eax\n"
21423 " cld\n"
21424 + __COPYUSER_SET_ES
21425 "99: rep; movsl\n"
21426 "36: movl %%eax, %0\n"
21427 "37: rep; movsb\n"
21428 "100:\n"
21429 + __COPYUSER_RESTORE_ES
21430 + ".section .fixup,\"ax\"\n"
21431 + "101: lea 0(%%eax,%0,4),%0\n"
21432 + " jmp 100b\n"
21433 + ".previous\n"
21434 + ".section __ex_table,\"a\"\n"
21435 + " .align 4\n"
21436 + " .long 1b,100b\n"
21437 + " .long 2b,100b\n"
21438 + " .long 3b,100b\n"
21439 + " .long 4b,100b\n"
21440 + " .long 5b,100b\n"
21441 + " .long 6b,100b\n"
21442 + " .long 7b,100b\n"
21443 + " .long 8b,100b\n"
21444 + " .long 9b,100b\n"
21445 + " .long 10b,100b\n"
21446 + " .long 11b,100b\n"
21447 + " .long 12b,100b\n"
21448 + " .long 13b,100b\n"
21449 + " .long 14b,100b\n"
21450 + " .long 15b,100b\n"
21451 + " .long 16b,100b\n"
21452 + " .long 17b,100b\n"
21453 + " .long 18b,100b\n"
21454 + " .long 19b,100b\n"
21455 + " .long 20b,100b\n"
21456 + " .long 21b,100b\n"
21457 + " .long 22b,100b\n"
21458 + " .long 23b,100b\n"
21459 + " .long 24b,100b\n"
21460 + " .long 25b,100b\n"
21461 + " .long 26b,100b\n"
21462 + " .long 27b,100b\n"
21463 + " .long 28b,100b\n"
21464 + " .long 29b,100b\n"
21465 + " .long 30b,100b\n"
21466 + " .long 31b,100b\n"
21467 + " .long 32b,100b\n"
21468 + " .long 33b,100b\n"
21469 + " .long 34b,100b\n"
21470 + " .long 35b,100b\n"
21471 + " .long 36b,100b\n"
21472 + " .long 37b,100b\n"
21473 + " .long 99b,101b\n"
21474 + ".previous"
21475 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
21476 + : "1"(to), "2"(from), "0"(size)
21477 + : "eax", "edx", "memory");
21478 + return size;
21479 +}
21480 +
21481 +static unsigned long
21482 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
21483 +{
21484 + int d0, d1;
21485 + __asm__ __volatile__(
21486 + " .align 2,0x90\n"
21487 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
21488 + " cmpl $67, %0\n"
21489 + " jbe 3f\n"
21490 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
21491 + " .align 2,0x90\n"
21492 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
21493 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
21494 + "5: movl %%eax, 0(%3)\n"
21495 + "6: movl %%edx, 4(%3)\n"
21496 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
21497 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
21498 + "9: movl %%eax, 8(%3)\n"
21499 + "10: movl %%edx, 12(%3)\n"
21500 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
21501 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
21502 + "13: movl %%eax, 16(%3)\n"
21503 + "14: movl %%edx, 20(%3)\n"
21504 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
21505 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
21506 + "17: movl %%eax, 24(%3)\n"
21507 + "18: movl %%edx, 28(%3)\n"
21508 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
21509 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
21510 + "21: movl %%eax, 32(%3)\n"
21511 + "22: movl %%edx, 36(%3)\n"
21512 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
21513 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
21514 + "25: movl %%eax, 40(%3)\n"
21515 + "26: movl %%edx, 44(%3)\n"
21516 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
21517 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
21518 + "29: movl %%eax, 48(%3)\n"
21519 + "30: movl %%edx, 52(%3)\n"
21520 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
21521 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
21522 + "33: movl %%eax, 56(%3)\n"
21523 + "34: movl %%edx, 60(%3)\n"
21524 + " addl $-64, %0\n"
21525 + " addl $64, %4\n"
21526 + " addl $64, %3\n"
21527 + " cmpl $63, %0\n"
21528 + " ja 1b\n"
21529 + "35: movl %0, %%eax\n"
21530 + " shrl $2, %0\n"
21531 + " andl $3, %%eax\n"
21532 + " cld\n"
21533 + "99: rep; "__copyuser_seg" movsl\n"
21534 + "36: movl %%eax, %0\n"
21535 + "37: rep; "__copyuser_seg" movsb\n"
21536 + "100:\n"
21537 ".section .fixup,\"ax\"\n"
21538 "101: lea 0(%%eax,%0,4),%0\n"
21539 " jmp 100b\n"
21540 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
21541 int d0, d1;
21542 __asm__ __volatile__(
21543 " .align 2,0x90\n"
21544 - "0: movl 32(%4), %%eax\n"
21545 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21546 " cmpl $67, %0\n"
21547 " jbe 2f\n"
21548 - "1: movl 64(%4), %%eax\n"
21549 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21550 " .align 2,0x90\n"
21551 - "2: movl 0(%4), %%eax\n"
21552 - "21: movl 4(%4), %%edx\n"
21553 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21554 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21555 " movl %%eax, 0(%3)\n"
21556 " movl %%edx, 4(%3)\n"
21557 - "3: movl 8(%4), %%eax\n"
21558 - "31: movl 12(%4),%%edx\n"
21559 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21560 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21561 " movl %%eax, 8(%3)\n"
21562 " movl %%edx, 12(%3)\n"
21563 - "4: movl 16(%4), %%eax\n"
21564 - "41: movl 20(%4), %%edx\n"
21565 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21566 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21567 " movl %%eax, 16(%3)\n"
21568 " movl %%edx, 20(%3)\n"
21569 - "10: movl 24(%4), %%eax\n"
21570 - "51: movl 28(%4), %%edx\n"
21571 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21572 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21573 " movl %%eax, 24(%3)\n"
21574 " movl %%edx, 28(%3)\n"
21575 - "11: movl 32(%4), %%eax\n"
21576 - "61: movl 36(%4), %%edx\n"
21577 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21578 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21579 " movl %%eax, 32(%3)\n"
21580 " movl %%edx, 36(%3)\n"
21581 - "12: movl 40(%4), %%eax\n"
21582 - "71: movl 44(%4), %%edx\n"
21583 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21584 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21585 " movl %%eax, 40(%3)\n"
21586 " movl %%edx, 44(%3)\n"
21587 - "13: movl 48(%4), %%eax\n"
21588 - "81: movl 52(%4), %%edx\n"
21589 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21590 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21591 " movl %%eax, 48(%3)\n"
21592 " movl %%edx, 52(%3)\n"
21593 - "14: movl 56(%4), %%eax\n"
21594 - "91: movl 60(%4), %%edx\n"
21595 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21596 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21597 " movl %%eax, 56(%3)\n"
21598 " movl %%edx, 60(%3)\n"
21599 " addl $-64, %0\n"
21600 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
21601 " shrl $2, %0\n"
21602 " andl $3, %%eax\n"
21603 " cld\n"
21604 - "6: rep; movsl\n"
21605 + "6: rep; "__copyuser_seg" movsl\n"
21606 " movl %%eax,%0\n"
21607 - "7: rep; movsb\n"
21608 + "7: rep; "__copyuser_seg" movsb\n"
21609 "8:\n"
21610 ".section .fixup,\"ax\"\n"
21611 "9: lea 0(%%eax,%0,4),%0\n"
21612 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
21613
21614 __asm__ __volatile__(
21615 " .align 2,0x90\n"
21616 - "0: movl 32(%4), %%eax\n"
21617 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21618 " cmpl $67, %0\n"
21619 " jbe 2f\n"
21620 - "1: movl 64(%4), %%eax\n"
21621 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21622 " .align 2,0x90\n"
21623 - "2: movl 0(%4), %%eax\n"
21624 - "21: movl 4(%4), %%edx\n"
21625 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21626 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21627 " movnti %%eax, 0(%3)\n"
21628 " movnti %%edx, 4(%3)\n"
21629 - "3: movl 8(%4), %%eax\n"
21630 - "31: movl 12(%4),%%edx\n"
21631 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21632 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21633 " movnti %%eax, 8(%3)\n"
21634 " movnti %%edx, 12(%3)\n"
21635 - "4: movl 16(%4), %%eax\n"
21636 - "41: movl 20(%4), %%edx\n"
21637 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21638 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21639 " movnti %%eax, 16(%3)\n"
21640 " movnti %%edx, 20(%3)\n"
21641 - "10: movl 24(%4), %%eax\n"
21642 - "51: movl 28(%4), %%edx\n"
21643 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21644 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21645 " movnti %%eax, 24(%3)\n"
21646 " movnti %%edx, 28(%3)\n"
21647 - "11: movl 32(%4), %%eax\n"
21648 - "61: movl 36(%4), %%edx\n"
21649 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21650 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21651 " movnti %%eax, 32(%3)\n"
21652 " movnti %%edx, 36(%3)\n"
21653 - "12: movl 40(%4), %%eax\n"
21654 - "71: movl 44(%4), %%edx\n"
21655 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21656 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21657 " movnti %%eax, 40(%3)\n"
21658 " movnti %%edx, 44(%3)\n"
21659 - "13: movl 48(%4), %%eax\n"
21660 - "81: movl 52(%4), %%edx\n"
21661 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21662 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21663 " movnti %%eax, 48(%3)\n"
21664 " movnti %%edx, 52(%3)\n"
21665 - "14: movl 56(%4), %%eax\n"
21666 - "91: movl 60(%4), %%edx\n"
21667 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21668 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21669 " movnti %%eax, 56(%3)\n"
21670 " movnti %%edx, 60(%3)\n"
21671 " addl $-64, %0\n"
21672 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
21673 " shrl $2, %0\n"
21674 " andl $3, %%eax\n"
21675 " cld\n"
21676 - "6: rep; movsl\n"
21677 + "6: rep; "__copyuser_seg" movsl\n"
21678 " movl %%eax,%0\n"
21679 - "7: rep; movsb\n"
21680 + "7: rep; "__copyuser_seg" movsb\n"
21681 "8:\n"
21682 ".section .fixup,\"ax\"\n"
21683 "9: lea 0(%%eax,%0,4),%0\n"
21684 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
21685
21686 __asm__ __volatile__(
21687 " .align 2,0x90\n"
21688 - "0: movl 32(%4), %%eax\n"
21689 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21690 " cmpl $67, %0\n"
21691 " jbe 2f\n"
21692 - "1: movl 64(%4), %%eax\n"
21693 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21694 " .align 2,0x90\n"
21695 - "2: movl 0(%4), %%eax\n"
21696 - "21: movl 4(%4), %%edx\n"
21697 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21698 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21699 " movnti %%eax, 0(%3)\n"
21700 " movnti %%edx, 4(%3)\n"
21701 - "3: movl 8(%4), %%eax\n"
21702 - "31: movl 12(%4),%%edx\n"
21703 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21704 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21705 " movnti %%eax, 8(%3)\n"
21706 " movnti %%edx, 12(%3)\n"
21707 - "4: movl 16(%4), %%eax\n"
21708 - "41: movl 20(%4), %%edx\n"
21709 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21710 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21711 " movnti %%eax, 16(%3)\n"
21712 " movnti %%edx, 20(%3)\n"
21713 - "10: movl 24(%4), %%eax\n"
21714 - "51: movl 28(%4), %%edx\n"
21715 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21716 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21717 " movnti %%eax, 24(%3)\n"
21718 " movnti %%edx, 28(%3)\n"
21719 - "11: movl 32(%4), %%eax\n"
21720 - "61: movl 36(%4), %%edx\n"
21721 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21722 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21723 " movnti %%eax, 32(%3)\n"
21724 " movnti %%edx, 36(%3)\n"
21725 - "12: movl 40(%4), %%eax\n"
21726 - "71: movl 44(%4), %%edx\n"
21727 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21728 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21729 " movnti %%eax, 40(%3)\n"
21730 " movnti %%edx, 44(%3)\n"
21731 - "13: movl 48(%4), %%eax\n"
21732 - "81: movl 52(%4), %%edx\n"
21733 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21734 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21735 " movnti %%eax, 48(%3)\n"
21736 " movnti %%edx, 52(%3)\n"
21737 - "14: movl 56(%4), %%eax\n"
21738 - "91: movl 60(%4), %%edx\n"
21739 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21740 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21741 " movnti %%eax, 56(%3)\n"
21742 " movnti %%edx, 60(%3)\n"
21743 " addl $-64, %0\n"
21744 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
21745 " shrl $2, %0\n"
21746 " andl $3, %%eax\n"
21747 " cld\n"
21748 - "6: rep; movsl\n"
21749 + "6: rep; "__copyuser_seg" movsl\n"
21750 " movl %%eax,%0\n"
21751 - "7: rep; movsb\n"
21752 + "7: rep; "__copyuser_seg" movsb\n"
21753 "8:\n"
21754 ".section .fixup,\"ax\"\n"
21755 "9: lea 0(%%eax,%0,4),%0\n"
21756 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
21757 */
21758 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
21759 unsigned long size);
21760 -unsigned long __copy_user_intel(void __user *to, const void *from,
21761 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
21762 + unsigned long size);
21763 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
21764 unsigned long size);
21765 unsigned long __copy_user_zeroing_intel_nocache(void *to,
21766 const void __user *from, unsigned long size);
21767 #endif /* CONFIG_X86_INTEL_USERCOPY */
21768
21769 /* Generic arbitrary sized copy. */
21770 -#define __copy_user(to, from, size) \
21771 +#define __copy_user(to, from, size, prefix, set, restore) \
21772 do { \
21773 int __d0, __d1, __d2; \
21774 __asm__ __volatile__( \
21775 + set \
21776 " cmp $7,%0\n" \
21777 " jbe 1f\n" \
21778 " movl %1,%0\n" \
21779 " negl %0\n" \
21780 " andl $7,%0\n" \
21781 " subl %0,%3\n" \
21782 - "4: rep; movsb\n" \
21783 + "4: rep; "prefix"movsb\n" \
21784 " movl %3,%0\n" \
21785 " shrl $2,%0\n" \
21786 " andl $3,%3\n" \
21787 " .align 2,0x90\n" \
21788 - "0: rep; movsl\n" \
21789 + "0: rep; "prefix"movsl\n" \
21790 " movl %3,%0\n" \
21791 - "1: rep; movsb\n" \
21792 + "1: rep; "prefix"movsb\n" \
21793 "2:\n" \
21794 + restore \
21795 ".section .fixup,\"ax\"\n" \
21796 "5: addl %3,%0\n" \
21797 " jmp 2b\n" \
21798 @@ -682,14 +799,14 @@ do { \
21799 " negl %0\n" \
21800 " andl $7,%0\n" \
21801 " subl %0,%3\n" \
21802 - "4: rep; movsb\n" \
21803 + "4: rep; "__copyuser_seg"movsb\n" \
21804 " movl %3,%0\n" \
21805 " shrl $2,%0\n" \
21806 " andl $3,%3\n" \
21807 " .align 2,0x90\n" \
21808 - "0: rep; movsl\n" \
21809 + "0: rep; "__copyuser_seg"movsl\n" \
21810 " movl %3,%0\n" \
21811 - "1: rep; movsb\n" \
21812 + "1: rep; "__copyuser_seg"movsb\n" \
21813 "2:\n" \
21814 ".section .fixup,\"ax\"\n" \
21815 "5: addl %3,%0\n" \
21816 @@ -775,9 +892,9 @@ survive:
21817 }
21818 #endif
21819 if (movsl_is_ok(to, from, n))
21820 - __copy_user(to, from, n);
21821 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
21822 else
21823 - n = __copy_user_intel(to, from, n);
21824 + n = __generic_copy_to_user_intel(to, from, n);
21825 return n;
21826 }
21827 EXPORT_SYMBOL(__copy_to_user_ll);
21828 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
21829 unsigned long n)
21830 {
21831 if (movsl_is_ok(to, from, n))
21832 - __copy_user(to, from, n);
21833 + __copy_user(to, from, n, __copyuser_seg, "", "");
21834 else
21835 - n = __copy_user_intel((void __user *)to,
21836 - (const void *)from, n);
21837 + n = __generic_copy_from_user_intel(to, from, n);
21838 return n;
21839 }
21840 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
21841 @@ -827,59 +943,38 @@ unsigned long __copy_from_user_ll_nocach
21842 if (n > 64 && cpu_has_xmm2)
21843 n = __copy_user_intel_nocache(to, from, n);
21844 else
21845 - __copy_user(to, from, n);
21846 + __copy_user(to, from, n, __copyuser_seg, "", "");
21847 #else
21848 - __copy_user(to, from, n);
21849 + __copy_user(to, from, n, __copyuser_seg, "", "");
21850 #endif
21851 return n;
21852 }
21853 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
21854
21855 -/**
21856 - * copy_to_user: - Copy a block of data into user space.
21857 - * @to: Destination address, in user space.
21858 - * @from: Source address, in kernel space.
21859 - * @n: Number of bytes to copy.
21860 - *
21861 - * Context: User context only. This function may sleep.
21862 - *
21863 - * Copy data from kernel space to user space.
21864 - *
21865 - * Returns number of bytes that could not be copied.
21866 - * On success, this will be zero.
21867 - */
21868 -unsigned long
21869 -copy_to_user(void __user *to, const void *from, unsigned long n)
21870 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21871 +void __set_fs(mm_segment_t x)
21872 {
21873 - if (access_ok(VERIFY_WRITE, to, n))
21874 - n = __copy_to_user(to, from, n);
21875 - return n;
21876 + switch (x.seg) {
21877 + case 0:
21878 + loadsegment(gs, 0);
21879 + break;
21880 + case TASK_SIZE_MAX:
21881 + loadsegment(gs, __USER_DS);
21882 + break;
21883 + case -1UL:
21884 + loadsegment(gs, __KERNEL_DS);
21885 + break;
21886 + default:
21887 + BUG();
21888 + }
21889 + return;
21890 }
21891 -EXPORT_SYMBOL(copy_to_user);
21892 +EXPORT_SYMBOL(__set_fs);
21893
21894 -/**
21895 - * copy_from_user: - Copy a block of data from user space.
21896 - * @to: Destination address, in kernel space.
21897 - * @from: Source address, in user space.
21898 - * @n: Number of bytes to copy.
21899 - *
21900 - * Context: User context only. This function may sleep.
21901 - *
21902 - * Copy data from user space to kernel space.
21903 - *
21904 - * Returns number of bytes that could not be copied.
21905 - * On success, this will be zero.
21906 - *
21907 - * If some data could not be copied, this function will pad the copied
21908 - * data to the requested size using zero bytes.
21909 - */
21910 -unsigned long
21911 -copy_from_user(void *to, const void __user *from, unsigned long n)
21912 +void set_fs(mm_segment_t x)
21913 {
21914 - if (access_ok(VERIFY_READ, from, n))
21915 - n = __copy_from_user(to, from, n);
21916 - else
21917 - memset(to, 0, n);
21918 - return n;
21919 + current_thread_info()->addr_limit = x;
21920 + __set_fs(x);
21921 }
21922 -EXPORT_SYMBOL(copy_from_user);
21923 +EXPORT_SYMBOL(set_fs);
21924 +#endif
21925 diff -urNp linux-2.6.32.46/arch/x86/lib/usercopy_64.c linux-2.6.32.46/arch/x86/lib/usercopy_64.c
21926 --- linux-2.6.32.46/arch/x86/lib/usercopy_64.c 2011-03-27 14:31:47.000000000 -0400
21927 +++ linux-2.6.32.46/arch/x86/lib/usercopy_64.c 2011-10-06 09:37:08.000000000 -0400
21928 @@ -42,6 +42,12 @@ long
21929 __strncpy_from_user(char *dst, const char __user *src, long count)
21930 {
21931 long res;
21932 +
21933 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21934 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21935 + src += PAX_USER_SHADOW_BASE;
21936 +#endif
21937 +
21938 __do_strncpy_from_user(dst, src, count, res);
21939 return res;
21940 }
21941 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
21942 {
21943 long __d0;
21944 might_fault();
21945 +
21946 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21947 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
21948 + addr += PAX_USER_SHADOW_BASE;
21949 +#endif
21950 +
21951 /* no memory constraint because it doesn't change any memory gcc knows
21952 about */
21953 asm volatile(
21954 @@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
21955
21956 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
21957 {
21958 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21959 - return copy_user_generic((__force void *)to, (__force void *)from, len);
21960 - }
21961 - return len;
21962 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21963 +
21964 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21965 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
21966 + to += PAX_USER_SHADOW_BASE;
21967 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
21968 + from += PAX_USER_SHADOW_BASE;
21969 +#endif
21970 +
21971 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
21972 + }
21973 + return len;
21974 }
21975 EXPORT_SYMBOL(copy_in_user);
21976
21977 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
21978 * it is not necessary to optimize tail handling.
21979 */
21980 unsigned long
21981 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
21982 +copy_user_handle_tail(char __user *to, char __user *from, unsigned len, unsigned zerorest)
21983 {
21984 char c;
21985 unsigned zero_len;
21986 diff -urNp linux-2.6.32.46/arch/x86/mm/extable.c linux-2.6.32.46/arch/x86/mm/extable.c
21987 --- linux-2.6.32.46/arch/x86/mm/extable.c 2011-03-27 14:31:47.000000000 -0400
21988 +++ linux-2.6.32.46/arch/x86/mm/extable.c 2011-04-17 15:56:46.000000000 -0400
21989 @@ -1,14 +1,71 @@
21990 #include <linux/module.h>
21991 #include <linux/spinlock.h>
21992 +#include <linux/sort.h>
21993 #include <asm/uaccess.h>
21994 +#include <asm/pgtable.h>
21995
21996 +/*
21997 + * The exception table needs to be sorted so that the binary
21998 + * search that we use to find entries in it works properly.
21999 + * This is used both for the kernel exception table and for
22000 + * the exception tables of modules that get loaded.
22001 + */
22002 +static int cmp_ex(const void *a, const void *b)
22003 +{
22004 + const struct exception_table_entry *x = a, *y = b;
22005 +
22006 + /* avoid overflow */
22007 + if (x->insn > y->insn)
22008 + return 1;
22009 + if (x->insn < y->insn)
22010 + return -1;
22011 + return 0;
22012 +}
22013 +
22014 +static void swap_ex(void *a, void *b, int size)
22015 +{
22016 + struct exception_table_entry t, *x = a, *y = b;
22017 +
22018 + t = *x;
22019 +
22020 + pax_open_kernel();
22021 + *x = *y;
22022 + *y = t;
22023 + pax_close_kernel();
22024 +}
22025 +
22026 +void sort_extable(struct exception_table_entry *start,
22027 + struct exception_table_entry *finish)
22028 +{
22029 + sort(start, finish - start, sizeof(struct exception_table_entry),
22030 + cmp_ex, swap_ex);
22031 +}
22032 +
22033 +#ifdef CONFIG_MODULES
22034 +/*
22035 + * If the exception table is sorted, any referring to the module init
22036 + * will be at the beginning or the end.
22037 + */
22038 +void trim_init_extable(struct module *m)
22039 +{
22040 + /*trim the beginning*/
22041 + while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
22042 + m->extable++;
22043 + m->num_exentries--;
22044 + }
22045 + /*trim the end*/
22046 + while (m->num_exentries &&
22047 + within_module_init(m->extable[m->num_exentries-1].insn, m))
22048 + m->num_exentries--;
22049 +}
22050 +#endif /* CONFIG_MODULES */
22051
22052 int fixup_exception(struct pt_regs *regs)
22053 {
22054 const struct exception_table_entry *fixup;
22055
22056 #ifdef CONFIG_PNPBIOS
22057 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
22058 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
22059 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
22060 extern u32 pnp_bios_is_utter_crap;
22061 pnp_bios_is_utter_crap = 1;
22062 diff -urNp linux-2.6.32.46/arch/x86/mm/fault.c linux-2.6.32.46/arch/x86/mm/fault.c
22063 --- linux-2.6.32.46/arch/x86/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
22064 +++ linux-2.6.32.46/arch/x86/mm/fault.c 2011-10-06 09:37:08.000000000 -0400
22065 @@ -11,10 +11,19 @@
22066 #include <linux/kprobes.h> /* __kprobes, ... */
22067 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
22068 #include <linux/perf_event.h> /* perf_sw_event */
22069 +#include <linux/unistd.h>
22070 +#include <linux/compiler.h>
22071
22072 #include <asm/traps.h> /* dotraplinkage, ... */
22073 #include <asm/pgalloc.h> /* pgd_*(), ... */
22074 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
22075 +#include <asm/vsyscall.h>
22076 +#include <asm/tlbflush.h>
22077 +
22078 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22079 +#include <asm/stacktrace.h>
22080 +#include "../kernel/dumpstack.h"
22081 +#endif
22082
22083 /*
22084 * Page fault error code bits:
22085 @@ -51,7 +60,7 @@ static inline int notify_page_fault(stru
22086 int ret = 0;
22087
22088 /* kprobe_running() needs smp_processor_id() */
22089 - if (kprobes_built_in() && !user_mode_vm(regs)) {
22090 + if (kprobes_built_in() && !user_mode(regs)) {
22091 preempt_disable();
22092 if (kprobe_running() && kprobe_fault_handler(regs, 14))
22093 ret = 1;
22094 @@ -112,7 +121,10 @@ check_prefetch_opcode(struct pt_regs *re
22095 return !instr_lo || (instr_lo>>1) == 1;
22096 case 0x00:
22097 /* Prefetch instruction is 0x0F0D or 0x0F18 */
22098 - if (probe_kernel_address(instr, opcode))
22099 + if (user_mode(regs)) {
22100 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22101 + return 0;
22102 + } else if (probe_kernel_address(instr, opcode))
22103 return 0;
22104
22105 *prefetch = (instr_lo == 0xF) &&
22106 @@ -146,7 +158,10 @@ is_prefetch(struct pt_regs *regs, unsign
22107 while (instr < max_instr) {
22108 unsigned char opcode;
22109
22110 - if (probe_kernel_address(instr, opcode))
22111 + if (user_mode(regs)) {
22112 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22113 + break;
22114 + } else if (probe_kernel_address(instr, opcode))
22115 break;
22116
22117 instr++;
22118 @@ -172,6 +187,30 @@ force_sig_info_fault(int si_signo, int s
22119 force_sig_info(si_signo, &info, tsk);
22120 }
22121
22122 +#ifdef CONFIG_PAX_EMUTRAMP
22123 +static int pax_handle_fetch_fault(struct pt_regs *regs);
22124 +#endif
22125 +
22126 +#ifdef CONFIG_PAX_PAGEEXEC
22127 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
22128 +{
22129 + pgd_t *pgd;
22130 + pud_t *pud;
22131 + pmd_t *pmd;
22132 +
22133 + pgd = pgd_offset(mm, address);
22134 + if (!pgd_present(*pgd))
22135 + return NULL;
22136 + pud = pud_offset(pgd, address);
22137 + if (!pud_present(*pud))
22138 + return NULL;
22139 + pmd = pmd_offset(pud, address);
22140 + if (!pmd_present(*pmd))
22141 + return NULL;
22142 + return pmd;
22143 +}
22144 +#endif
22145 +
22146 DEFINE_SPINLOCK(pgd_lock);
22147 LIST_HEAD(pgd_list);
22148
22149 @@ -224,11 +263,24 @@ void vmalloc_sync_all(void)
22150 address += PMD_SIZE) {
22151
22152 unsigned long flags;
22153 +
22154 +#ifdef CONFIG_PAX_PER_CPU_PGD
22155 + unsigned long cpu;
22156 +#else
22157 struct page *page;
22158 +#endif
22159
22160 spin_lock_irqsave(&pgd_lock, flags);
22161 +
22162 +#ifdef CONFIG_PAX_PER_CPU_PGD
22163 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22164 + pgd_t *pgd = get_cpu_pgd(cpu);
22165 +#else
22166 list_for_each_entry(page, &pgd_list, lru) {
22167 - if (!vmalloc_sync_one(page_address(page), address))
22168 + pgd_t *pgd = page_address(page);
22169 +#endif
22170 +
22171 + if (!vmalloc_sync_one(pgd, address))
22172 break;
22173 }
22174 spin_unlock_irqrestore(&pgd_lock, flags);
22175 @@ -258,6 +310,11 @@ static noinline int vmalloc_fault(unsign
22176 * an interrupt in the middle of a task switch..
22177 */
22178 pgd_paddr = read_cr3();
22179 +
22180 +#ifdef CONFIG_PAX_PER_CPU_PGD
22181 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
22182 +#endif
22183 +
22184 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
22185 if (!pmd_k)
22186 return -1;
22187 @@ -332,15 +389,27 @@ void vmalloc_sync_all(void)
22188
22189 const pgd_t *pgd_ref = pgd_offset_k(address);
22190 unsigned long flags;
22191 +
22192 +#ifdef CONFIG_PAX_PER_CPU_PGD
22193 + unsigned long cpu;
22194 +#else
22195 struct page *page;
22196 +#endif
22197
22198 if (pgd_none(*pgd_ref))
22199 continue;
22200
22201 spin_lock_irqsave(&pgd_lock, flags);
22202 +
22203 +#ifdef CONFIG_PAX_PER_CPU_PGD
22204 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22205 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
22206 +#else
22207 list_for_each_entry(page, &pgd_list, lru) {
22208 pgd_t *pgd;
22209 pgd = (pgd_t *)page_address(page) + pgd_index(address);
22210 +#endif
22211 +
22212 if (pgd_none(*pgd))
22213 set_pgd(pgd, *pgd_ref);
22214 else
22215 @@ -373,7 +442,14 @@ static noinline int vmalloc_fault(unsign
22216 * happen within a race in page table update. In the later
22217 * case just flush:
22218 */
22219 +
22220 +#ifdef CONFIG_PAX_PER_CPU_PGD
22221 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
22222 + pgd = pgd_offset_cpu(smp_processor_id(), address);
22223 +#else
22224 pgd = pgd_offset(current->active_mm, address);
22225 +#endif
22226 +
22227 pgd_ref = pgd_offset_k(address);
22228 if (pgd_none(*pgd_ref))
22229 return -1;
22230 @@ -535,7 +611,7 @@ static int is_errata93(struct pt_regs *r
22231 static int is_errata100(struct pt_regs *regs, unsigned long address)
22232 {
22233 #ifdef CONFIG_X86_64
22234 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
22235 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
22236 return 1;
22237 #endif
22238 return 0;
22239 @@ -562,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *r
22240 }
22241
22242 static const char nx_warning[] = KERN_CRIT
22243 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
22244 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
22245
22246 static void
22247 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
22248 @@ -571,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, un
22249 if (!oops_may_print())
22250 return;
22251
22252 - if (error_code & PF_INSTR) {
22253 + if (nx_enabled && (error_code & PF_INSTR)) {
22254 unsigned int level;
22255
22256 pte_t *pte = lookup_address(address, &level);
22257
22258 if (pte && pte_present(*pte) && !pte_exec(*pte))
22259 - printk(nx_warning, current_uid());
22260 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
22261 }
22262
22263 +#ifdef CONFIG_PAX_KERNEXEC
22264 + if (init_mm.start_code <= address && address < init_mm.end_code) {
22265 + if (current->signal->curr_ip)
22266 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
22267 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
22268 + else
22269 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
22270 + current->comm, task_pid_nr(current), current_uid(), current_euid());
22271 + }
22272 +#endif
22273 +
22274 printk(KERN_ALERT "BUG: unable to handle kernel ");
22275 if (address < PAGE_SIZE)
22276 printk(KERN_CONT "NULL pointer dereference");
22277 @@ -704,6 +791,70 @@ __bad_area_nosemaphore(struct pt_regs *r
22278 unsigned long address, int si_code)
22279 {
22280 struct task_struct *tsk = current;
22281 +#if defined(CONFIG_X86_64) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22282 + struct mm_struct *mm = tsk->mm;
22283 +#endif
22284 +
22285 +#ifdef CONFIG_X86_64
22286 + if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
22287 + if (regs->ip == (unsigned long)vgettimeofday) {
22288 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
22289 + return;
22290 + } else if (regs->ip == (unsigned long)vtime) {
22291 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
22292 + return;
22293 + } else if (regs->ip == (unsigned long)vgetcpu) {
22294 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
22295 + return;
22296 + }
22297 + }
22298 +#endif
22299 +
22300 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22301 + if (mm && (error_code & PF_USER)) {
22302 + unsigned long ip = regs->ip;
22303 +
22304 + if (v8086_mode(regs))
22305 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
22306 +
22307 + /*
22308 + * It's possible to have interrupts off here:
22309 + */
22310 + local_irq_enable();
22311 +
22312 +#ifdef CONFIG_PAX_PAGEEXEC
22313 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
22314 + ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
22315 +
22316 +#ifdef CONFIG_PAX_EMUTRAMP
22317 + switch (pax_handle_fetch_fault(regs)) {
22318 + case 2:
22319 + return;
22320 + }
22321 +#endif
22322 +
22323 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
22324 + do_group_exit(SIGKILL);
22325 + }
22326 +#endif
22327 +
22328 +#ifdef CONFIG_PAX_SEGMEXEC
22329 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
22330 +
22331 +#ifdef CONFIG_PAX_EMUTRAMP
22332 + switch (pax_handle_fetch_fault(regs)) {
22333 + case 2:
22334 + return;
22335 + }
22336 +#endif
22337 +
22338 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
22339 + do_group_exit(SIGKILL);
22340 + }
22341 +#endif
22342 +
22343 + }
22344 +#endif
22345
22346 /* User mode accesses just cause a SIGSEGV */
22347 if (error_code & PF_USER) {
22348 @@ -857,6 +1008,99 @@ static int spurious_fault_check(unsigned
22349 return 1;
22350 }
22351
22352 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22353 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
22354 +{
22355 + pte_t *pte;
22356 + pmd_t *pmd;
22357 + spinlock_t *ptl;
22358 + unsigned char pte_mask;
22359 +
22360 + if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
22361 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
22362 + return 0;
22363 +
22364 + /* PaX: it's our fault, let's handle it if we can */
22365 +
22366 + /* PaX: take a look at read faults before acquiring any locks */
22367 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
22368 + /* instruction fetch attempt from a protected page in user mode */
22369 + up_read(&mm->mmap_sem);
22370 +
22371 +#ifdef CONFIG_PAX_EMUTRAMP
22372 + switch (pax_handle_fetch_fault(regs)) {
22373 + case 2:
22374 + return 1;
22375 + }
22376 +#endif
22377 +
22378 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
22379 + do_group_exit(SIGKILL);
22380 + }
22381 +
22382 + pmd = pax_get_pmd(mm, address);
22383 + if (unlikely(!pmd))
22384 + return 0;
22385 +
22386 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
22387 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
22388 + pte_unmap_unlock(pte, ptl);
22389 + return 0;
22390 + }
22391 +
22392 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
22393 + /* write attempt to a protected page in user mode */
22394 + pte_unmap_unlock(pte, ptl);
22395 + return 0;
22396 + }
22397 +
22398 +#ifdef CONFIG_SMP
22399 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
22400 +#else
22401 + if (likely(address > get_limit(regs->cs)))
22402 +#endif
22403 + {
22404 + set_pte(pte, pte_mkread(*pte));
22405 + __flush_tlb_one(address);
22406 + pte_unmap_unlock(pte, ptl);
22407 + up_read(&mm->mmap_sem);
22408 + return 1;
22409 + }
22410 +
22411 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
22412 +
22413 + /*
22414 + * PaX: fill DTLB with user rights and retry
22415 + */
22416 + __asm__ __volatile__ (
22417 + "orb %2,(%1)\n"
22418 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
22419 +/*
22420 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
22421 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
22422 + * page fault when examined during a TLB load attempt. this is true not only
22423 + * for PTEs holding a non-present entry but also present entries that will
22424 + * raise a page fault (such as those set up by PaX, or the copy-on-write
22425 + * mechanism). in effect it means that we do *not* need to flush the TLBs
22426 + * for our target pages since their PTEs are simply not in the TLBs at all.
22427 +
22428 + * the best thing in omitting it is that we gain around 15-20% speed in the
22429 + * fast path of the page fault handler and can get rid of tracing since we
22430 + * can no longer flush unintended entries.
22431 + */
22432 + "invlpg (%0)\n"
22433 +#endif
22434 + __copyuser_seg"testb $0,(%0)\n"
22435 + "xorb %3,(%1)\n"
22436 + :
22437 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
22438 + : "memory", "cc");
22439 + pte_unmap_unlock(pte, ptl);
22440 + up_read(&mm->mmap_sem);
22441 + return 1;
22442 +}
22443 +#endif
22444 +
22445 /*
22446 * Handle a spurious fault caused by a stale TLB entry.
22447 *
22448 @@ -923,6 +1167,9 @@ int show_unhandled_signals = 1;
22449 static inline int
22450 access_error(unsigned long error_code, int write, struct vm_area_struct *vma)
22451 {
22452 + if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
22453 + return 1;
22454 +
22455 if (write) {
22456 /* write, present and write, not present: */
22457 if (unlikely(!(vma->vm_flags & VM_WRITE)))
22458 @@ -956,17 +1203,31 @@ do_page_fault(struct pt_regs *regs, unsi
22459 {
22460 struct vm_area_struct *vma;
22461 struct task_struct *tsk;
22462 - unsigned long address;
22463 struct mm_struct *mm;
22464 int write;
22465 int fault;
22466
22467 + /* Get the faulting address: */
22468 + unsigned long address = read_cr2();
22469 +
22470 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22471 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
22472 + if (!search_exception_tables(regs->ip)) {
22473 + bad_area_nosemaphore(regs, error_code, address);
22474 + return;
22475 + }
22476 + if (address < PAX_USER_SHADOW_BASE) {
22477 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
22478 + printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
22479 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
22480 + } else
22481 + address -= PAX_USER_SHADOW_BASE;
22482 + }
22483 +#endif
22484 +
22485 tsk = current;
22486 mm = tsk->mm;
22487
22488 - /* Get the faulting address: */
22489 - address = read_cr2();
22490 -
22491 /*
22492 * Detect and handle instructions that would cause a page fault for
22493 * both a tracked kernel page and a userspace page.
22494 @@ -1026,7 +1287,7 @@ do_page_fault(struct pt_regs *regs, unsi
22495 * User-mode registers count as a user access even for any
22496 * potential system fault or CPU buglet:
22497 */
22498 - if (user_mode_vm(regs)) {
22499 + if (user_mode(regs)) {
22500 local_irq_enable();
22501 error_code |= PF_USER;
22502 } else {
22503 @@ -1080,6 +1341,11 @@ do_page_fault(struct pt_regs *regs, unsi
22504 might_sleep();
22505 }
22506
22507 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22508 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
22509 + return;
22510 +#endif
22511 +
22512 vma = find_vma(mm, address);
22513 if (unlikely(!vma)) {
22514 bad_area(regs, error_code, address);
22515 @@ -1091,18 +1357,24 @@ do_page_fault(struct pt_regs *regs, unsi
22516 bad_area(regs, error_code, address);
22517 return;
22518 }
22519 - if (error_code & PF_USER) {
22520 - /*
22521 - * Accessing the stack below %sp is always a bug.
22522 - * The large cushion allows instructions like enter
22523 - * and pusha to work. ("enter $65535, $31" pushes
22524 - * 32 pointers and then decrements %sp by 65535.)
22525 - */
22526 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
22527 - bad_area(regs, error_code, address);
22528 - return;
22529 - }
22530 + /*
22531 + * Accessing the stack below %sp is always a bug.
22532 + * The large cushion allows instructions like enter
22533 + * and pusha to work. ("enter $65535, $31" pushes
22534 + * 32 pointers and then decrements %sp by 65535.)
22535 + */
22536 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
22537 + bad_area(regs, error_code, address);
22538 + return;
22539 }
22540 +
22541 +#ifdef CONFIG_PAX_SEGMEXEC
22542 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
22543 + bad_area(regs, error_code, address);
22544 + return;
22545 + }
22546 +#endif
22547 +
22548 if (unlikely(expand_stack(vma, address))) {
22549 bad_area(regs, error_code, address);
22550 return;
22551 @@ -1146,3 +1418,199 @@ good_area:
22552
22553 up_read(&mm->mmap_sem);
22554 }
22555 +
22556 +#ifdef CONFIG_PAX_EMUTRAMP
22557 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
22558 +{
22559 + int err;
22560 +
22561 + do { /* PaX: gcc trampoline emulation #1 */
22562 + unsigned char mov1, mov2;
22563 + unsigned short jmp;
22564 + unsigned int addr1, addr2;
22565 +
22566 +#ifdef CONFIG_X86_64
22567 + if ((regs->ip + 11) >> 32)
22568 + break;
22569 +#endif
22570 +
22571 + err = get_user(mov1, (unsigned char __user *)regs->ip);
22572 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
22573 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
22574 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
22575 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
22576 +
22577 + if (err)
22578 + break;
22579 +
22580 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
22581 + regs->cx = addr1;
22582 + regs->ax = addr2;
22583 + regs->ip = addr2;
22584 + return 2;
22585 + }
22586 + } while (0);
22587 +
22588 + do { /* PaX: gcc trampoline emulation #2 */
22589 + unsigned char mov, jmp;
22590 + unsigned int addr1, addr2;
22591 +
22592 +#ifdef CONFIG_X86_64
22593 + if ((regs->ip + 9) >> 32)
22594 + break;
22595 +#endif
22596 +
22597 + err = get_user(mov, (unsigned char __user *)regs->ip);
22598 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
22599 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
22600 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
22601 +
22602 + if (err)
22603 + break;
22604 +
22605 + if (mov == 0xB9 && jmp == 0xE9) {
22606 + regs->cx = addr1;
22607 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
22608 + return 2;
22609 + }
22610 + } while (0);
22611 +
22612 + return 1; /* PaX in action */
22613 +}
22614 +
22615 +#ifdef CONFIG_X86_64
22616 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
22617 +{
22618 + int err;
22619 +
22620 + do { /* PaX: gcc trampoline emulation #1 */
22621 + unsigned short mov1, mov2, jmp1;
22622 + unsigned char jmp2;
22623 + unsigned int addr1;
22624 + unsigned long addr2;
22625 +
22626 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22627 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
22628 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
22629 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
22630 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
22631 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
22632 +
22633 + if (err)
22634 + break;
22635 +
22636 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22637 + regs->r11 = addr1;
22638 + regs->r10 = addr2;
22639 + regs->ip = addr1;
22640 + return 2;
22641 + }
22642 + } while (0);
22643 +
22644 + do { /* PaX: gcc trampoline emulation #2 */
22645 + unsigned short mov1, mov2, jmp1;
22646 + unsigned char jmp2;
22647 + unsigned long addr1, addr2;
22648 +
22649 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22650 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
22651 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
22652 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
22653 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
22654 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
22655 +
22656 + if (err)
22657 + break;
22658 +
22659 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22660 + regs->r11 = addr1;
22661 + regs->r10 = addr2;
22662 + regs->ip = addr1;
22663 + return 2;
22664 + }
22665 + } while (0);
22666 +
22667 + return 1; /* PaX in action */
22668 +}
22669 +#endif
22670 +
22671 +/*
22672 + * PaX: decide what to do with offenders (regs->ip = fault address)
22673 + *
22674 + * returns 1 when task should be killed
22675 + * 2 when gcc trampoline was detected
22676 + */
22677 +static int pax_handle_fetch_fault(struct pt_regs *regs)
22678 +{
22679 + if (v8086_mode(regs))
22680 + return 1;
22681 +
22682 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
22683 + return 1;
22684 +
22685 +#ifdef CONFIG_X86_32
22686 + return pax_handle_fetch_fault_32(regs);
22687 +#else
22688 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
22689 + return pax_handle_fetch_fault_32(regs);
22690 + else
22691 + return pax_handle_fetch_fault_64(regs);
22692 +#endif
22693 +}
22694 +#endif
22695 +
22696 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22697 +void pax_report_insns(void *pc, void *sp)
22698 +{
22699 + long i;
22700 +
22701 + printk(KERN_ERR "PAX: bytes at PC: ");
22702 + for (i = 0; i < 20; i++) {
22703 + unsigned char c;
22704 + if (get_user(c, (unsigned char __force_user *)pc+i))
22705 + printk(KERN_CONT "?? ");
22706 + else
22707 + printk(KERN_CONT "%02x ", c);
22708 + }
22709 + printk("\n");
22710 +
22711 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
22712 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
22713 + unsigned long c;
22714 + if (get_user(c, (unsigned long __force_user *)sp+i))
22715 +#ifdef CONFIG_X86_32
22716 + printk(KERN_CONT "???????? ");
22717 +#else
22718 + printk(KERN_CONT "???????????????? ");
22719 +#endif
22720 + else
22721 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
22722 + }
22723 + printk("\n");
22724 +}
22725 +#endif
22726 +
22727 +/**
22728 + * probe_kernel_write(): safely attempt to write to a location
22729 + * @dst: address to write to
22730 + * @src: pointer to the data that shall be written
22731 + * @size: size of the data chunk
22732 + *
22733 + * Safely write to address @dst from the buffer at @src. If a kernel fault
22734 + * happens, handle that and return -EFAULT.
22735 + */
22736 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
22737 +{
22738 + long ret;
22739 + mm_segment_t old_fs = get_fs();
22740 +
22741 + set_fs(KERNEL_DS);
22742 + pagefault_disable();
22743 + pax_open_kernel();
22744 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
22745 + pax_close_kernel();
22746 + pagefault_enable();
22747 + set_fs(old_fs);
22748 +
22749 + return ret ? -EFAULT : 0;
22750 +}
22751 diff -urNp linux-2.6.32.46/arch/x86/mm/gup.c linux-2.6.32.46/arch/x86/mm/gup.c
22752 --- linux-2.6.32.46/arch/x86/mm/gup.c 2011-03-27 14:31:47.000000000 -0400
22753 +++ linux-2.6.32.46/arch/x86/mm/gup.c 2011-04-17 15:56:46.000000000 -0400
22754 @@ -237,7 +237,7 @@ int __get_user_pages_fast(unsigned long
22755 addr = start;
22756 len = (unsigned long) nr_pages << PAGE_SHIFT;
22757 end = start + len;
22758 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22759 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22760 (void __user *)start, len)))
22761 return 0;
22762
22763 diff -urNp linux-2.6.32.46/arch/x86/mm/highmem_32.c linux-2.6.32.46/arch/x86/mm/highmem_32.c
22764 --- linux-2.6.32.46/arch/x86/mm/highmem_32.c 2011-03-27 14:31:47.000000000 -0400
22765 +++ linux-2.6.32.46/arch/x86/mm/highmem_32.c 2011-04-17 15:56:46.000000000 -0400
22766 @@ -43,7 +43,10 @@ void *kmap_atomic_prot(struct page *page
22767 idx = type + KM_TYPE_NR*smp_processor_id();
22768 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22769 BUG_ON(!pte_none(*(kmap_pte-idx)));
22770 +
22771 + pax_open_kernel();
22772 set_pte(kmap_pte-idx, mk_pte(page, prot));
22773 + pax_close_kernel();
22774
22775 return (void *)vaddr;
22776 }
22777 diff -urNp linux-2.6.32.46/arch/x86/mm/hugetlbpage.c linux-2.6.32.46/arch/x86/mm/hugetlbpage.c
22778 --- linux-2.6.32.46/arch/x86/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
22779 +++ linux-2.6.32.46/arch/x86/mm/hugetlbpage.c 2011-04-17 15:56:46.000000000 -0400
22780 @@ -267,13 +267,20 @@ static unsigned long hugetlb_get_unmappe
22781 struct hstate *h = hstate_file(file);
22782 struct mm_struct *mm = current->mm;
22783 struct vm_area_struct *vma;
22784 - unsigned long start_addr;
22785 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22786 +
22787 +#ifdef CONFIG_PAX_SEGMEXEC
22788 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22789 + pax_task_size = SEGMEXEC_TASK_SIZE;
22790 +#endif
22791 +
22792 + pax_task_size -= PAGE_SIZE;
22793
22794 if (len > mm->cached_hole_size) {
22795 - start_addr = mm->free_area_cache;
22796 + start_addr = mm->free_area_cache;
22797 } else {
22798 - start_addr = TASK_UNMAPPED_BASE;
22799 - mm->cached_hole_size = 0;
22800 + start_addr = mm->mmap_base;
22801 + mm->cached_hole_size = 0;
22802 }
22803
22804 full_search:
22805 @@ -281,26 +288,27 @@ full_search:
22806
22807 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22808 /* At this point: (!vma || addr < vma->vm_end). */
22809 - if (TASK_SIZE - len < addr) {
22810 + if (pax_task_size - len < addr) {
22811 /*
22812 * Start a new search - just in case we missed
22813 * some holes.
22814 */
22815 - if (start_addr != TASK_UNMAPPED_BASE) {
22816 - start_addr = TASK_UNMAPPED_BASE;
22817 + if (start_addr != mm->mmap_base) {
22818 + start_addr = mm->mmap_base;
22819 mm->cached_hole_size = 0;
22820 goto full_search;
22821 }
22822 return -ENOMEM;
22823 }
22824 - if (!vma || addr + len <= vma->vm_start) {
22825 - mm->free_area_cache = addr + len;
22826 - return addr;
22827 - }
22828 + if (check_heap_stack_gap(vma, addr, len))
22829 + break;
22830 if (addr + mm->cached_hole_size < vma->vm_start)
22831 mm->cached_hole_size = vma->vm_start - addr;
22832 addr = ALIGN(vma->vm_end, huge_page_size(h));
22833 }
22834 +
22835 + mm->free_area_cache = addr + len;
22836 + return addr;
22837 }
22838
22839 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22840 @@ -309,10 +317,9 @@ static unsigned long hugetlb_get_unmappe
22841 {
22842 struct hstate *h = hstate_file(file);
22843 struct mm_struct *mm = current->mm;
22844 - struct vm_area_struct *vma, *prev_vma;
22845 - unsigned long base = mm->mmap_base, addr = addr0;
22846 + struct vm_area_struct *vma;
22847 + unsigned long base = mm->mmap_base, addr;
22848 unsigned long largest_hole = mm->cached_hole_size;
22849 - int first_time = 1;
22850
22851 /* don't allow allocations above current base */
22852 if (mm->free_area_cache > base)
22853 @@ -322,64 +329,63 @@ static unsigned long hugetlb_get_unmappe
22854 largest_hole = 0;
22855 mm->free_area_cache = base;
22856 }
22857 -try_again:
22858 +
22859 /* make sure it can fit in the remaining address space */
22860 if (mm->free_area_cache < len)
22861 goto fail;
22862
22863 /* either no address requested or cant fit in requested address hole */
22864 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
22865 + addr = (mm->free_area_cache - len);
22866 do {
22867 + addr &= huge_page_mask(h);
22868 + vma = find_vma(mm, addr);
22869 /*
22870 * Lookup failure means no vma is above this address,
22871 * i.e. return with success:
22872 - */
22873 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
22874 - return addr;
22875 -
22876 - /*
22877 * new region fits between prev_vma->vm_end and
22878 * vma->vm_start, use it:
22879 */
22880 - if (addr + len <= vma->vm_start &&
22881 - (!prev_vma || (addr >= prev_vma->vm_end))) {
22882 + if (check_heap_stack_gap(vma, addr, len)) {
22883 /* remember the address as a hint for next time */
22884 - mm->cached_hole_size = largest_hole;
22885 - return (mm->free_area_cache = addr);
22886 - } else {
22887 - /* pull free_area_cache down to the first hole */
22888 - if (mm->free_area_cache == vma->vm_end) {
22889 - mm->free_area_cache = vma->vm_start;
22890 - mm->cached_hole_size = largest_hole;
22891 - }
22892 + mm->cached_hole_size = largest_hole;
22893 + return (mm->free_area_cache = addr);
22894 + }
22895 + /* pull free_area_cache down to the first hole */
22896 + if (mm->free_area_cache == vma->vm_end) {
22897 + mm->free_area_cache = vma->vm_start;
22898 + mm->cached_hole_size = largest_hole;
22899 }
22900
22901 /* remember the largest hole we saw so far */
22902 if (addr + largest_hole < vma->vm_start)
22903 - largest_hole = vma->vm_start - addr;
22904 + largest_hole = vma->vm_start - addr;
22905
22906 /* try just below the current vma->vm_start */
22907 - addr = (vma->vm_start - len) & huge_page_mask(h);
22908 - } while (len <= vma->vm_start);
22909 + addr = skip_heap_stack_gap(vma, len);
22910 + } while (!IS_ERR_VALUE(addr));
22911
22912 fail:
22913 /*
22914 - * if hint left us with no space for the requested
22915 - * mapping then try again:
22916 - */
22917 - if (first_time) {
22918 - mm->free_area_cache = base;
22919 - largest_hole = 0;
22920 - first_time = 0;
22921 - goto try_again;
22922 - }
22923 - /*
22924 * A failed mmap() very likely causes application failure,
22925 * so fall back to the bottom-up function here. This scenario
22926 * can happen with large stack limits and large mmap()
22927 * allocations.
22928 */
22929 - mm->free_area_cache = TASK_UNMAPPED_BASE;
22930 +
22931 +#ifdef CONFIG_PAX_SEGMEXEC
22932 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22933 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22934 + else
22935 +#endif
22936 +
22937 + mm->mmap_base = TASK_UNMAPPED_BASE;
22938 +
22939 +#ifdef CONFIG_PAX_RANDMMAP
22940 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22941 + mm->mmap_base += mm->delta_mmap;
22942 +#endif
22943 +
22944 + mm->free_area_cache = mm->mmap_base;
22945 mm->cached_hole_size = ~0UL;
22946 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
22947 len, pgoff, flags);
22948 @@ -387,6 +393,7 @@ fail:
22949 /*
22950 * Restore the topdown base:
22951 */
22952 + mm->mmap_base = base;
22953 mm->free_area_cache = base;
22954 mm->cached_hole_size = ~0UL;
22955
22956 @@ -400,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *f
22957 struct hstate *h = hstate_file(file);
22958 struct mm_struct *mm = current->mm;
22959 struct vm_area_struct *vma;
22960 + unsigned long pax_task_size = TASK_SIZE;
22961
22962 if (len & ~huge_page_mask(h))
22963 return -EINVAL;
22964 - if (len > TASK_SIZE)
22965 +
22966 +#ifdef CONFIG_PAX_SEGMEXEC
22967 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22968 + pax_task_size = SEGMEXEC_TASK_SIZE;
22969 +#endif
22970 +
22971 + pax_task_size -= PAGE_SIZE;
22972 +
22973 + if (len > pax_task_size)
22974 return -ENOMEM;
22975
22976 if (flags & MAP_FIXED) {
22977 @@ -415,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *f
22978 if (addr) {
22979 addr = ALIGN(addr, huge_page_size(h));
22980 vma = find_vma(mm, addr);
22981 - if (TASK_SIZE - len >= addr &&
22982 - (!vma || addr + len <= vma->vm_start))
22983 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
22984 return addr;
22985 }
22986 if (mm->get_unmapped_area == arch_get_unmapped_area)
22987 diff -urNp linux-2.6.32.46/arch/x86/mm/init.c linux-2.6.32.46/arch/x86/mm/init.c
22988 --- linux-2.6.32.46/arch/x86/mm/init.c 2011-04-17 17:00:52.000000000 -0400
22989 +++ linux-2.6.32.46/arch/x86/mm/init.c 2011-06-07 19:06:09.000000000 -0400
22990 @@ -69,11 +69,7 @@ static void __init find_early_table_spac
22991 * cause a hotspot and fill up ZONE_DMA. The page tables
22992 * need roughly 0.5KB per GB.
22993 */
22994 -#ifdef CONFIG_X86_32
22995 - start = 0x7000;
22996 -#else
22997 - start = 0x8000;
22998 -#endif
22999 + start = 0x100000;
23000 e820_table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
23001 tables, PAGE_SIZE);
23002 if (e820_table_start == -1UL)
23003 @@ -147,7 +143,7 @@ unsigned long __init_refok init_memory_m
23004 #endif
23005
23006 set_nx();
23007 - if (nx_enabled)
23008 + if (nx_enabled && cpu_has_nx)
23009 printk(KERN_INFO "NX (Execute Disable) protection: active\n");
23010
23011 /* Enable PSE if available */
23012 @@ -329,10 +325,27 @@ unsigned long __init_refok init_memory_m
23013 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
23014 * mmio resources as well as potential bios/acpi data regions.
23015 */
23016 +
23017 int devmem_is_allowed(unsigned long pagenr)
23018 {
23019 +#ifdef CONFIG_GRKERNSEC_KMEM
23020 + /* allow BDA */
23021 + if (!pagenr)
23022 + return 1;
23023 + /* allow EBDA */
23024 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
23025 + return 1;
23026 + /* allow ISA/video mem */
23027 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
23028 + return 1;
23029 + /* throw out everything else below 1MB */
23030 + if (pagenr <= 256)
23031 + return 0;
23032 +#else
23033 if (pagenr <= 256)
23034 return 1;
23035 +#endif
23036 +
23037 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
23038 return 0;
23039 if (!page_is_ram(pagenr))
23040 @@ -379,6 +392,86 @@ void free_init_pages(char *what, unsigne
23041
23042 void free_initmem(void)
23043 {
23044 +
23045 +#ifdef CONFIG_PAX_KERNEXEC
23046 +#ifdef CONFIG_X86_32
23047 + /* PaX: limit KERNEL_CS to actual size */
23048 + unsigned long addr, limit;
23049 + struct desc_struct d;
23050 + int cpu;
23051 +
23052 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
23053 + limit = (limit - 1UL) >> PAGE_SHIFT;
23054 +
23055 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
23056 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
23057 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
23058 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
23059 + }
23060 +
23061 + /* PaX: make KERNEL_CS read-only */
23062 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
23063 + if (!paravirt_enabled())
23064 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
23065 +/*
23066 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
23067 + pgd = pgd_offset_k(addr);
23068 + pud = pud_offset(pgd, addr);
23069 + pmd = pmd_offset(pud, addr);
23070 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23071 + }
23072 +*/
23073 +#ifdef CONFIG_X86_PAE
23074 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
23075 +/*
23076 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
23077 + pgd = pgd_offset_k(addr);
23078 + pud = pud_offset(pgd, addr);
23079 + pmd = pmd_offset(pud, addr);
23080 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
23081 + }
23082 +*/
23083 +#endif
23084 +
23085 +#ifdef CONFIG_MODULES
23086 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
23087 +#endif
23088 +
23089 +#else
23090 + pgd_t *pgd;
23091 + pud_t *pud;
23092 + pmd_t *pmd;
23093 + unsigned long addr, end;
23094 +
23095 + /* PaX: make kernel code/rodata read-only, rest non-executable */
23096 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
23097 + pgd = pgd_offset_k(addr);
23098 + pud = pud_offset(pgd, addr);
23099 + pmd = pmd_offset(pud, addr);
23100 + if (!pmd_present(*pmd))
23101 + continue;
23102 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
23103 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23104 + else
23105 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
23106 + }
23107 +
23108 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
23109 + end = addr + KERNEL_IMAGE_SIZE;
23110 + for (; addr < end; addr += PMD_SIZE) {
23111 + pgd = pgd_offset_k(addr);
23112 + pud = pud_offset(pgd, addr);
23113 + pmd = pmd_offset(pud, addr);
23114 + if (!pmd_present(*pmd))
23115 + continue;
23116 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
23117 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23118 + }
23119 +#endif
23120 +
23121 + flush_tlb_all();
23122 +#endif
23123 +
23124 free_init_pages("unused kernel memory",
23125 (unsigned long)(&__init_begin),
23126 (unsigned long)(&__init_end));
23127 diff -urNp linux-2.6.32.46/arch/x86/mm/init_32.c linux-2.6.32.46/arch/x86/mm/init_32.c
23128 --- linux-2.6.32.46/arch/x86/mm/init_32.c 2011-03-27 14:31:47.000000000 -0400
23129 +++ linux-2.6.32.46/arch/x86/mm/init_32.c 2011-04-17 15:56:46.000000000 -0400
23130 @@ -72,36 +72,6 @@ static __init void *alloc_low_page(void)
23131 }
23132
23133 /*
23134 - * Creates a middle page table and puts a pointer to it in the
23135 - * given global directory entry. This only returns the gd entry
23136 - * in non-PAE compilation mode, since the middle layer is folded.
23137 - */
23138 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
23139 -{
23140 - pud_t *pud;
23141 - pmd_t *pmd_table;
23142 -
23143 -#ifdef CONFIG_X86_PAE
23144 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
23145 - if (after_bootmem)
23146 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
23147 - else
23148 - pmd_table = (pmd_t *)alloc_low_page();
23149 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
23150 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
23151 - pud = pud_offset(pgd, 0);
23152 - BUG_ON(pmd_table != pmd_offset(pud, 0));
23153 -
23154 - return pmd_table;
23155 - }
23156 -#endif
23157 - pud = pud_offset(pgd, 0);
23158 - pmd_table = pmd_offset(pud, 0);
23159 -
23160 - return pmd_table;
23161 -}
23162 -
23163 -/*
23164 * Create a page table and place a pointer to it in a middle page
23165 * directory entry:
23166 */
23167 @@ -121,13 +91,28 @@ static pte_t * __init one_page_table_ini
23168 page_table = (pte_t *)alloc_low_page();
23169
23170 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
23171 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23172 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
23173 +#else
23174 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
23175 +#endif
23176 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
23177 }
23178
23179 return pte_offset_kernel(pmd, 0);
23180 }
23181
23182 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
23183 +{
23184 + pud_t *pud;
23185 + pmd_t *pmd_table;
23186 +
23187 + pud = pud_offset(pgd, 0);
23188 + pmd_table = pmd_offset(pud, 0);
23189 +
23190 + return pmd_table;
23191 +}
23192 +
23193 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
23194 {
23195 int pgd_idx = pgd_index(vaddr);
23196 @@ -201,6 +186,7 @@ page_table_range_init(unsigned long star
23197 int pgd_idx, pmd_idx;
23198 unsigned long vaddr;
23199 pgd_t *pgd;
23200 + pud_t *pud;
23201 pmd_t *pmd;
23202 pte_t *pte = NULL;
23203
23204 @@ -210,8 +196,13 @@ page_table_range_init(unsigned long star
23205 pgd = pgd_base + pgd_idx;
23206
23207 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
23208 - pmd = one_md_table_init(pgd);
23209 - pmd = pmd + pmd_index(vaddr);
23210 + pud = pud_offset(pgd, vaddr);
23211 + pmd = pmd_offset(pud, vaddr);
23212 +
23213 +#ifdef CONFIG_X86_PAE
23214 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
23215 +#endif
23216 +
23217 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
23218 pmd++, pmd_idx++) {
23219 pte = page_table_kmap_check(one_page_table_init(pmd),
23220 @@ -223,11 +214,20 @@ page_table_range_init(unsigned long star
23221 }
23222 }
23223
23224 -static inline int is_kernel_text(unsigned long addr)
23225 +static inline int is_kernel_text(unsigned long start, unsigned long end)
23226 {
23227 - if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
23228 - return 1;
23229 - return 0;
23230 + if ((start > ktla_ktva((unsigned long)_etext) ||
23231 + end <= ktla_ktva((unsigned long)_stext)) &&
23232 + (start > ktla_ktva((unsigned long)_einittext) ||
23233 + end <= ktla_ktva((unsigned long)_sinittext)) &&
23234 +
23235 +#ifdef CONFIG_ACPI_SLEEP
23236 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
23237 +#endif
23238 +
23239 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
23240 + return 0;
23241 + return 1;
23242 }
23243
23244 /*
23245 @@ -243,9 +243,10 @@ kernel_physical_mapping_init(unsigned lo
23246 int use_pse = page_size_mask == (1<<PG_LEVEL_2M);
23247 unsigned long start_pfn, end_pfn;
23248 pgd_t *pgd_base = swapper_pg_dir;
23249 - int pgd_idx, pmd_idx, pte_ofs;
23250 + unsigned int pgd_idx, pmd_idx, pte_ofs;
23251 unsigned long pfn;
23252 pgd_t *pgd;
23253 + pud_t *pud;
23254 pmd_t *pmd;
23255 pte_t *pte;
23256 unsigned pages_2m, pages_4k;
23257 @@ -278,8 +279,13 @@ repeat:
23258 pfn = start_pfn;
23259 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
23260 pgd = pgd_base + pgd_idx;
23261 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
23262 - pmd = one_md_table_init(pgd);
23263 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
23264 + pud = pud_offset(pgd, 0);
23265 + pmd = pmd_offset(pud, 0);
23266 +
23267 +#ifdef CONFIG_X86_PAE
23268 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
23269 +#endif
23270
23271 if (pfn >= end_pfn)
23272 continue;
23273 @@ -291,14 +297,13 @@ repeat:
23274 #endif
23275 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
23276 pmd++, pmd_idx++) {
23277 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
23278 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
23279
23280 /*
23281 * Map with big pages if possible, otherwise
23282 * create normal page tables:
23283 */
23284 if (use_pse) {
23285 - unsigned int addr2;
23286 pgprot_t prot = PAGE_KERNEL_LARGE;
23287 /*
23288 * first pass will use the same initial
23289 @@ -308,11 +313,7 @@ repeat:
23290 __pgprot(PTE_IDENT_ATTR |
23291 _PAGE_PSE);
23292
23293 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
23294 - PAGE_OFFSET + PAGE_SIZE-1;
23295 -
23296 - if (is_kernel_text(addr) ||
23297 - is_kernel_text(addr2))
23298 + if (is_kernel_text(address, address + PMD_SIZE))
23299 prot = PAGE_KERNEL_LARGE_EXEC;
23300
23301 pages_2m++;
23302 @@ -329,7 +330,7 @@ repeat:
23303 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
23304 pte += pte_ofs;
23305 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
23306 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
23307 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
23308 pgprot_t prot = PAGE_KERNEL;
23309 /*
23310 * first pass will use the same initial
23311 @@ -337,7 +338,7 @@ repeat:
23312 */
23313 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
23314
23315 - if (is_kernel_text(addr))
23316 + if (is_kernel_text(address, address + PAGE_SIZE))
23317 prot = PAGE_KERNEL_EXEC;
23318
23319 pages_4k++;
23320 @@ -489,7 +490,7 @@ void __init native_pagetable_setup_start
23321
23322 pud = pud_offset(pgd, va);
23323 pmd = pmd_offset(pud, va);
23324 - if (!pmd_present(*pmd))
23325 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
23326 break;
23327
23328 pte = pte_offset_kernel(pmd, va);
23329 @@ -541,9 +542,7 @@ void __init early_ioremap_page_table_ran
23330
23331 static void __init pagetable_init(void)
23332 {
23333 - pgd_t *pgd_base = swapper_pg_dir;
23334 -
23335 - permanent_kmaps_init(pgd_base);
23336 + permanent_kmaps_init(swapper_pg_dir);
23337 }
23338
23339 #ifdef CONFIG_ACPI_SLEEP
23340 @@ -551,12 +550,12 @@ static void __init pagetable_init(void)
23341 * ACPI suspend needs this for resume, because things like the intel-agp
23342 * driver might have split up a kernel 4MB mapping.
23343 */
23344 -char swsusp_pg_dir[PAGE_SIZE]
23345 +pgd_t swsusp_pg_dir[PTRS_PER_PGD]
23346 __attribute__ ((aligned(PAGE_SIZE)));
23347
23348 static inline void save_pg_dir(void)
23349 {
23350 - memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
23351 + clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
23352 }
23353 #else /* !CONFIG_ACPI_SLEEP */
23354 static inline void save_pg_dir(void)
23355 @@ -588,7 +587,7 @@ void zap_low_mappings(bool early)
23356 flush_tlb_all();
23357 }
23358
23359 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
23360 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
23361 EXPORT_SYMBOL_GPL(__supported_pte_mask);
23362
23363 /* user-defined highmem size */
23364 @@ -777,7 +776,7 @@ void __init setup_bootmem_allocator(void
23365 * Initialize the boot-time allocator (with low memory only):
23366 */
23367 bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
23368 - bootmap = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
23369 + bootmap = find_e820_area(0x100000, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
23370 PAGE_SIZE);
23371 if (bootmap == -1L)
23372 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
23373 @@ -864,6 +863,12 @@ void __init mem_init(void)
23374
23375 pci_iommu_alloc();
23376
23377 +#ifdef CONFIG_PAX_PER_CPU_PGD
23378 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
23379 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23380 + KERNEL_PGD_PTRS);
23381 +#endif
23382 +
23383 #ifdef CONFIG_FLATMEM
23384 BUG_ON(!mem_map);
23385 #endif
23386 @@ -881,7 +886,7 @@ void __init mem_init(void)
23387 set_highmem_pages_init();
23388
23389 codesize = (unsigned long) &_etext - (unsigned long) &_text;
23390 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
23391 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
23392 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
23393
23394 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
23395 @@ -923,10 +928,10 @@ void __init mem_init(void)
23396 ((unsigned long)&__init_end -
23397 (unsigned long)&__init_begin) >> 10,
23398
23399 - (unsigned long)&_etext, (unsigned long)&_edata,
23400 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
23401 + (unsigned long)&_sdata, (unsigned long)&_edata,
23402 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
23403
23404 - (unsigned long)&_text, (unsigned long)&_etext,
23405 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
23406 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
23407
23408 /*
23409 @@ -1007,6 +1012,7 @@ void set_kernel_text_rw(void)
23410 if (!kernel_set_to_readonly)
23411 return;
23412
23413 + start = ktla_ktva(start);
23414 pr_debug("Set kernel text: %lx - %lx for read write\n",
23415 start, start+size);
23416
23417 @@ -1021,6 +1027,7 @@ void set_kernel_text_ro(void)
23418 if (!kernel_set_to_readonly)
23419 return;
23420
23421 + start = ktla_ktva(start);
23422 pr_debug("Set kernel text: %lx - %lx for read only\n",
23423 start, start+size);
23424
23425 @@ -1032,6 +1039,7 @@ void mark_rodata_ro(void)
23426 unsigned long start = PFN_ALIGN(_text);
23427 unsigned long size = PFN_ALIGN(_etext) - start;
23428
23429 + start = ktla_ktva(start);
23430 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
23431 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
23432 size >> 10);
23433 diff -urNp linux-2.6.32.46/arch/x86/mm/init_64.c linux-2.6.32.46/arch/x86/mm/init_64.c
23434 --- linux-2.6.32.46/arch/x86/mm/init_64.c 2011-04-17 17:00:52.000000000 -0400
23435 +++ linux-2.6.32.46/arch/x86/mm/init_64.c 2011-04-17 17:03:05.000000000 -0400
23436 @@ -164,7 +164,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
23437 pmd = fill_pmd(pud, vaddr);
23438 pte = fill_pte(pmd, vaddr);
23439
23440 + pax_open_kernel();
23441 set_pte(pte, new_pte);
23442 + pax_close_kernel();
23443
23444 /*
23445 * It's enough to flush this one mapping.
23446 @@ -223,14 +225,12 @@ static void __init __init_extra_mapping(
23447 pgd = pgd_offset_k((unsigned long)__va(phys));
23448 if (pgd_none(*pgd)) {
23449 pud = (pud_t *) spp_getpage();
23450 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
23451 - _PAGE_USER));
23452 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
23453 }
23454 pud = pud_offset(pgd, (unsigned long)__va(phys));
23455 if (pud_none(*pud)) {
23456 pmd = (pmd_t *) spp_getpage();
23457 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
23458 - _PAGE_USER));
23459 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
23460 }
23461 pmd = pmd_offset(pud, phys);
23462 BUG_ON(!pmd_none(*pmd));
23463 @@ -675,6 +675,12 @@ void __init mem_init(void)
23464
23465 pci_iommu_alloc();
23466
23467 +#ifdef CONFIG_PAX_PER_CPU_PGD
23468 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
23469 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23470 + KERNEL_PGD_PTRS);
23471 +#endif
23472 +
23473 /* clear_bss() already clear the empty_zero_page */
23474
23475 reservedpages = 0;
23476 @@ -861,8 +867,8 @@ int kern_addr_valid(unsigned long addr)
23477 static struct vm_area_struct gate_vma = {
23478 .vm_start = VSYSCALL_START,
23479 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
23480 - .vm_page_prot = PAGE_READONLY_EXEC,
23481 - .vm_flags = VM_READ | VM_EXEC
23482 + .vm_page_prot = PAGE_READONLY,
23483 + .vm_flags = VM_READ
23484 };
23485
23486 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
23487 @@ -896,7 +902,7 @@ int in_gate_area_no_task(unsigned long a
23488
23489 const char *arch_vma_name(struct vm_area_struct *vma)
23490 {
23491 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
23492 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
23493 return "[vdso]";
23494 if (vma == &gate_vma)
23495 return "[vsyscall]";
23496 diff -urNp linux-2.6.32.46/arch/x86/mm/iomap_32.c linux-2.6.32.46/arch/x86/mm/iomap_32.c
23497 --- linux-2.6.32.46/arch/x86/mm/iomap_32.c 2011-03-27 14:31:47.000000000 -0400
23498 +++ linux-2.6.32.46/arch/x86/mm/iomap_32.c 2011-04-17 15:56:46.000000000 -0400
23499 @@ -65,7 +65,11 @@ void *kmap_atomic_prot_pfn(unsigned long
23500 debug_kmap_atomic(type);
23501 idx = type + KM_TYPE_NR * smp_processor_id();
23502 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
23503 +
23504 + pax_open_kernel();
23505 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
23506 + pax_close_kernel();
23507 +
23508 arch_flush_lazy_mmu_mode();
23509
23510 return (void *)vaddr;
23511 diff -urNp linux-2.6.32.46/arch/x86/mm/ioremap.c linux-2.6.32.46/arch/x86/mm/ioremap.c
23512 --- linux-2.6.32.46/arch/x86/mm/ioremap.c 2011-03-27 14:31:47.000000000 -0400
23513 +++ linux-2.6.32.46/arch/x86/mm/ioremap.c 2011-04-17 15:56:46.000000000 -0400
23514 @@ -41,8 +41,8 @@ int page_is_ram(unsigned long pagenr)
23515 * Second special case: Some BIOSen report the PC BIOS
23516 * area (640->1Mb) as ram even though it is not.
23517 */
23518 - if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
23519 - pagenr < (BIOS_END >> PAGE_SHIFT))
23520 + if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
23521 + pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
23522 return 0;
23523
23524 for (i = 0; i < e820.nr_map; i++) {
23525 @@ -137,13 +137,10 @@ static void __iomem *__ioremap_caller(re
23526 /*
23527 * Don't allow anybody to remap normal RAM that we're using..
23528 */
23529 - for (pfn = phys_addr >> PAGE_SHIFT;
23530 - (pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK);
23531 - pfn++) {
23532 -
23533 + for (pfn = phys_addr >> PAGE_SHIFT; ((resource_size_t)pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK); pfn++) {
23534 int is_ram = page_is_ram(pfn);
23535
23536 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
23537 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
23538 return NULL;
23539 WARN_ON_ONCE(is_ram);
23540 }
23541 @@ -407,7 +404,7 @@ static int __init early_ioremap_debug_se
23542 early_param("early_ioremap_debug", early_ioremap_debug_setup);
23543
23544 static __initdata int after_paging_init;
23545 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
23546 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
23547
23548 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
23549 {
23550 @@ -439,8 +436,7 @@ void __init early_ioremap_init(void)
23551 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
23552
23553 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
23554 - memset(bm_pte, 0, sizeof(bm_pte));
23555 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
23556 + pmd_populate_user(&init_mm, pmd, bm_pte);
23557
23558 /*
23559 * The boot-ioremap range spans multiple pmds, for which
23560 diff -urNp linux-2.6.32.46/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.32.46/arch/x86/mm/kmemcheck/kmemcheck.c
23561 --- linux-2.6.32.46/arch/x86/mm/kmemcheck/kmemcheck.c 2011-03-27 14:31:47.000000000 -0400
23562 +++ linux-2.6.32.46/arch/x86/mm/kmemcheck/kmemcheck.c 2011-04-17 15:56:46.000000000 -0400
23563 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
23564 * memory (e.g. tracked pages)? For now, we need this to avoid
23565 * invoking kmemcheck for PnP BIOS calls.
23566 */
23567 - if (regs->flags & X86_VM_MASK)
23568 + if (v8086_mode(regs))
23569 return false;
23570 - if (regs->cs != __KERNEL_CS)
23571 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
23572 return false;
23573
23574 pte = kmemcheck_pte_lookup(address);
23575 diff -urNp linux-2.6.32.46/arch/x86/mm/mmap.c linux-2.6.32.46/arch/x86/mm/mmap.c
23576 --- linux-2.6.32.46/arch/x86/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
23577 +++ linux-2.6.32.46/arch/x86/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
23578 @@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
23579 * Leave an at least ~128 MB hole with possible stack randomization.
23580 */
23581 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
23582 -#define MAX_GAP (TASK_SIZE/6*5)
23583 +#define MAX_GAP (pax_task_size/6*5)
23584
23585 /*
23586 * True on X86_32 or when emulating IA32 on X86_64
23587 @@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
23588 return rnd << PAGE_SHIFT;
23589 }
23590
23591 -static unsigned long mmap_base(void)
23592 +static unsigned long mmap_base(struct mm_struct *mm)
23593 {
23594 unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
23595 + unsigned long pax_task_size = TASK_SIZE;
23596 +
23597 +#ifdef CONFIG_PAX_SEGMEXEC
23598 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23599 + pax_task_size = SEGMEXEC_TASK_SIZE;
23600 +#endif
23601
23602 if (gap < MIN_GAP)
23603 gap = MIN_GAP;
23604 else if (gap > MAX_GAP)
23605 gap = MAX_GAP;
23606
23607 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
23608 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
23609 }
23610
23611 /*
23612 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
23613 * does, but not when emulating X86_32
23614 */
23615 -static unsigned long mmap_legacy_base(void)
23616 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
23617 {
23618 - if (mmap_is_ia32())
23619 + if (mmap_is_ia32()) {
23620 +
23621 +#ifdef CONFIG_PAX_SEGMEXEC
23622 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23623 + return SEGMEXEC_TASK_UNMAPPED_BASE;
23624 + else
23625 +#endif
23626 +
23627 return TASK_UNMAPPED_BASE;
23628 - else
23629 + } else
23630 return TASK_UNMAPPED_BASE + mmap_rnd();
23631 }
23632
23633 @@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
23634 void arch_pick_mmap_layout(struct mm_struct *mm)
23635 {
23636 if (mmap_is_legacy()) {
23637 - mm->mmap_base = mmap_legacy_base();
23638 + mm->mmap_base = mmap_legacy_base(mm);
23639 +
23640 +#ifdef CONFIG_PAX_RANDMMAP
23641 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23642 + mm->mmap_base += mm->delta_mmap;
23643 +#endif
23644 +
23645 mm->get_unmapped_area = arch_get_unmapped_area;
23646 mm->unmap_area = arch_unmap_area;
23647 } else {
23648 - mm->mmap_base = mmap_base();
23649 + mm->mmap_base = mmap_base(mm);
23650 +
23651 +#ifdef CONFIG_PAX_RANDMMAP
23652 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23653 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
23654 +#endif
23655 +
23656 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
23657 mm->unmap_area = arch_unmap_area_topdown;
23658 }
23659 diff -urNp linux-2.6.32.46/arch/x86/mm/mmio-mod.c linux-2.6.32.46/arch/x86/mm/mmio-mod.c
23660 --- linux-2.6.32.46/arch/x86/mm/mmio-mod.c 2011-03-27 14:31:47.000000000 -0400
23661 +++ linux-2.6.32.46/arch/x86/mm/mmio-mod.c 2011-07-06 19:53:33.000000000 -0400
23662 @@ -193,7 +193,7 @@ static void pre(struct kmmio_probe *p, s
23663 break;
23664 default:
23665 {
23666 - unsigned char *ip = (unsigned char *)instptr;
23667 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
23668 my_trace->opcode = MMIO_UNKNOWN_OP;
23669 my_trace->width = 0;
23670 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
23671 @@ -233,7 +233,7 @@ static void post(struct kmmio_probe *p,
23672 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23673 void __iomem *addr)
23674 {
23675 - static atomic_t next_id;
23676 + static atomic_unchecked_t next_id;
23677 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
23678 /* These are page-unaligned. */
23679 struct mmiotrace_map map = {
23680 @@ -257,7 +257,7 @@ static void ioremap_trace_core(resource_
23681 .private = trace
23682 },
23683 .phys = offset,
23684 - .id = atomic_inc_return(&next_id)
23685 + .id = atomic_inc_return_unchecked(&next_id)
23686 };
23687 map.map_id = trace->id;
23688
23689 diff -urNp linux-2.6.32.46/arch/x86/mm/numa_32.c linux-2.6.32.46/arch/x86/mm/numa_32.c
23690 --- linux-2.6.32.46/arch/x86/mm/numa_32.c 2011-03-27 14:31:47.000000000 -0400
23691 +++ linux-2.6.32.46/arch/x86/mm/numa_32.c 2011-04-17 15:56:46.000000000 -0400
23692 @@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int
23693 }
23694 #endif
23695
23696 -extern unsigned long find_max_low_pfn(void);
23697 extern unsigned long highend_pfn, highstart_pfn;
23698
23699 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
23700 diff -urNp linux-2.6.32.46/arch/x86/mm/pageattr-test.c linux-2.6.32.46/arch/x86/mm/pageattr-test.c
23701 --- linux-2.6.32.46/arch/x86/mm/pageattr-test.c 2011-03-27 14:31:47.000000000 -0400
23702 +++ linux-2.6.32.46/arch/x86/mm/pageattr-test.c 2011-04-17 15:56:46.000000000 -0400
23703 @@ -36,7 +36,7 @@ enum {
23704
23705 static int pte_testbit(pte_t pte)
23706 {
23707 - return pte_flags(pte) & _PAGE_UNUSED1;
23708 + return pte_flags(pte) & _PAGE_CPA_TEST;
23709 }
23710
23711 struct split_state {
23712 diff -urNp linux-2.6.32.46/arch/x86/mm/pageattr.c linux-2.6.32.46/arch/x86/mm/pageattr.c
23713 --- linux-2.6.32.46/arch/x86/mm/pageattr.c 2011-03-27 14:31:47.000000000 -0400
23714 +++ linux-2.6.32.46/arch/x86/mm/pageattr.c 2011-04-17 15:56:46.000000000 -0400
23715 @@ -261,16 +261,17 @@ static inline pgprot_t static_protection
23716 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
23717 */
23718 if (within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
23719 - pgprot_val(forbidden) |= _PAGE_NX;
23720 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23721
23722 /*
23723 * The kernel text needs to be executable for obvious reasons
23724 * Does not cover __inittext since that is gone later on. On
23725 * 64bit we do not enforce !NX on the low mapping
23726 */
23727 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
23728 - pgprot_val(forbidden) |= _PAGE_NX;
23729 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
23730 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23731
23732 +#ifdef CONFIG_DEBUG_RODATA
23733 /*
23734 * The .rodata section needs to be read-only. Using the pfn
23735 * catches all aliases.
23736 @@ -278,6 +279,14 @@ static inline pgprot_t static_protection
23737 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
23738 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
23739 pgprot_val(forbidden) |= _PAGE_RW;
23740 +#endif
23741 +
23742 +#ifdef CONFIG_PAX_KERNEXEC
23743 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
23744 + pgprot_val(forbidden) |= _PAGE_RW;
23745 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23746 + }
23747 +#endif
23748
23749 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
23750
23751 @@ -331,23 +340,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
23752 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
23753 {
23754 /* change init_mm */
23755 + pax_open_kernel();
23756 set_pte_atomic(kpte, pte);
23757 +
23758 #ifdef CONFIG_X86_32
23759 if (!SHARED_KERNEL_PMD) {
23760 +
23761 +#ifdef CONFIG_PAX_PER_CPU_PGD
23762 + unsigned long cpu;
23763 +#else
23764 struct page *page;
23765 +#endif
23766
23767 +#ifdef CONFIG_PAX_PER_CPU_PGD
23768 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
23769 + pgd_t *pgd = get_cpu_pgd(cpu);
23770 +#else
23771 list_for_each_entry(page, &pgd_list, lru) {
23772 - pgd_t *pgd;
23773 + pgd_t *pgd = (pgd_t *)page_address(page);
23774 +#endif
23775 +
23776 pud_t *pud;
23777 pmd_t *pmd;
23778
23779 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
23780 + pgd += pgd_index(address);
23781 pud = pud_offset(pgd, address);
23782 pmd = pmd_offset(pud, address);
23783 set_pte_atomic((pte_t *)pmd, pte);
23784 }
23785 }
23786 #endif
23787 + pax_close_kernel();
23788 }
23789
23790 static int
23791 diff -urNp linux-2.6.32.46/arch/x86/mm/pat.c linux-2.6.32.46/arch/x86/mm/pat.c
23792 --- linux-2.6.32.46/arch/x86/mm/pat.c 2011-03-27 14:31:47.000000000 -0400
23793 +++ linux-2.6.32.46/arch/x86/mm/pat.c 2011-04-17 15:56:46.000000000 -0400
23794 @@ -258,7 +258,7 @@ chk_conflict(struct memtype *new, struct
23795
23796 conflict:
23797 printk(KERN_INFO "%s:%d conflicting memory types "
23798 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start,
23799 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), new->start,
23800 new->end, cattr_name(new->type), cattr_name(entry->type));
23801 return -EBUSY;
23802 }
23803 @@ -559,7 +559,7 @@ unlock_ret:
23804
23805 if (err) {
23806 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
23807 - current->comm, current->pid, start, end);
23808 + current->comm, task_pid_nr(current), start, end);
23809 }
23810
23811 dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
23812 @@ -689,8 +689,8 @@ static inline int range_is_allowed(unsig
23813 while (cursor < to) {
23814 if (!devmem_is_allowed(pfn)) {
23815 printk(KERN_INFO
23816 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
23817 - current->comm, from, to);
23818 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
23819 + current->comm, from, to, cursor);
23820 return 0;
23821 }
23822 cursor += PAGE_SIZE;
23823 @@ -755,7 +755,7 @@ int kernel_map_sync_memtype(u64 base, un
23824 printk(KERN_INFO
23825 "%s:%d ioremap_change_attr failed %s "
23826 "for %Lx-%Lx\n",
23827 - current->comm, current->pid,
23828 + current->comm, task_pid_nr(current),
23829 cattr_name(flags),
23830 base, (unsigned long long)(base + size));
23831 return -EINVAL;
23832 @@ -813,7 +813,7 @@ static int reserve_pfn_range(u64 paddr,
23833 free_memtype(paddr, paddr + size);
23834 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
23835 " for %Lx-%Lx, got %s\n",
23836 - current->comm, current->pid,
23837 + current->comm, task_pid_nr(current),
23838 cattr_name(want_flags),
23839 (unsigned long long)paddr,
23840 (unsigned long long)(paddr + size),
23841 diff -urNp linux-2.6.32.46/arch/x86/mm/pf_in.c linux-2.6.32.46/arch/x86/mm/pf_in.c
23842 --- linux-2.6.32.46/arch/x86/mm/pf_in.c 2011-03-27 14:31:47.000000000 -0400
23843 +++ linux-2.6.32.46/arch/x86/mm/pf_in.c 2011-07-06 19:53:33.000000000 -0400
23844 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned l
23845 int i;
23846 enum reason_type rv = OTHERS;
23847
23848 - p = (unsigned char *)ins_addr;
23849 + p = (unsigned char *)ktla_ktva(ins_addr);
23850 p += skip_prefix(p, &prf);
23851 p += get_opcode(p, &opcode);
23852
23853 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(un
23854 struct prefix_bits prf;
23855 int i;
23856
23857 - p = (unsigned char *)ins_addr;
23858 + p = (unsigned char *)ktla_ktva(ins_addr);
23859 p += skip_prefix(p, &prf);
23860 p += get_opcode(p, &opcode);
23861
23862 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned
23863 struct prefix_bits prf;
23864 int i;
23865
23866 - p = (unsigned char *)ins_addr;
23867 + p = (unsigned char *)ktla_ktva(ins_addr);
23868 p += skip_prefix(p, &prf);
23869 p += get_opcode(p, &opcode);
23870
23871 @@ -417,7 +417,7 @@ unsigned long get_ins_reg_val(unsigned l
23872 int i;
23873 unsigned long rv;
23874
23875 - p = (unsigned char *)ins_addr;
23876 + p = (unsigned char *)ktla_ktva(ins_addr);
23877 p += skip_prefix(p, &prf);
23878 p += get_opcode(p, &opcode);
23879 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
23880 @@ -472,7 +472,7 @@ unsigned long get_ins_imm_val(unsigned l
23881 int i;
23882 unsigned long rv;
23883
23884 - p = (unsigned char *)ins_addr;
23885 + p = (unsigned char *)ktla_ktva(ins_addr);
23886 p += skip_prefix(p, &prf);
23887 p += get_opcode(p, &opcode);
23888 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
23889 diff -urNp linux-2.6.32.46/arch/x86/mm/pgtable.c linux-2.6.32.46/arch/x86/mm/pgtable.c
23890 --- linux-2.6.32.46/arch/x86/mm/pgtable.c 2011-03-27 14:31:47.000000000 -0400
23891 +++ linux-2.6.32.46/arch/x86/mm/pgtable.c 2011-05-11 18:25:15.000000000 -0400
23892 @@ -83,9 +83,52 @@ static inline void pgd_list_del(pgd_t *p
23893 list_del(&page->lru);
23894 }
23895
23896 -#define UNSHARED_PTRS_PER_PGD \
23897 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23898 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23899 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
23900
23901 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23902 +{
23903 + while (count--)
23904 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
23905 +}
23906 +#endif
23907 +
23908 +#ifdef CONFIG_PAX_PER_CPU_PGD
23909 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23910 +{
23911 + while (count--)
23912 +
23913 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23914 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
23915 +#else
23916 + *dst++ = *src++;
23917 +#endif
23918 +
23919 +}
23920 +#endif
23921 +
23922 +#ifdef CONFIG_X86_64
23923 +#define pxd_t pud_t
23924 +#define pyd_t pgd_t
23925 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
23926 +#define pxd_free(mm, pud) pud_free((mm), (pud))
23927 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
23928 +#define pyd_offset(mm ,address) pgd_offset((mm), (address))
23929 +#define PYD_SIZE PGDIR_SIZE
23930 +#else
23931 +#define pxd_t pmd_t
23932 +#define pyd_t pud_t
23933 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
23934 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
23935 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
23936 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
23937 +#define PYD_SIZE PUD_SIZE
23938 +#endif
23939 +
23940 +#ifdef CONFIG_PAX_PER_CPU_PGD
23941 +static inline void pgd_ctor(pgd_t *pgd) {}
23942 +static inline void pgd_dtor(pgd_t *pgd) {}
23943 +#else
23944 static void pgd_ctor(pgd_t *pgd)
23945 {
23946 /* If the pgd points to a shared pagetable level (either the
23947 @@ -119,6 +162,7 @@ static void pgd_dtor(pgd_t *pgd)
23948 pgd_list_del(pgd);
23949 spin_unlock_irqrestore(&pgd_lock, flags);
23950 }
23951 +#endif
23952
23953 /*
23954 * List of all pgd's needed for non-PAE so it can invalidate entries
23955 @@ -131,7 +175,7 @@ static void pgd_dtor(pgd_t *pgd)
23956 * -- wli
23957 */
23958
23959 -#ifdef CONFIG_X86_PAE
23960 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
23961 /*
23962 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
23963 * updating the top-level pagetable entries to guarantee the
23964 @@ -143,7 +187,7 @@ static void pgd_dtor(pgd_t *pgd)
23965 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
23966 * and initialize the kernel pmds here.
23967 */
23968 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
23969 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23970
23971 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23972 {
23973 @@ -161,36 +205,38 @@ void pud_populate(struct mm_struct *mm,
23974 */
23975 flush_tlb_mm(mm);
23976 }
23977 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
23978 +#define PREALLOCATED_PXDS USER_PGD_PTRS
23979 #else /* !CONFIG_X86_PAE */
23980
23981 /* No need to prepopulate any pagetable entries in non-PAE modes. */
23982 -#define PREALLOCATED_PMDS 0
23983 +#define PREALLOCATED_PXDS 0
23984
23985 #endif /* CONFIG_X86_PAE */
23986
23987 -static void free_pmds(pmd_t *pmds[])
23988 +static void free_pxds(pxd_t *pxds[])
23989 {
23990 int i;
23991
23992 - for(i = 0; i < PREALLOCATED_PMDS; i++)
23993 - if (pmds[i])
23994 - free_page((unsigned long)pmds[i]);
23995 + for(i = 0; i < PREALLOCATED_PXDS; i++)
23996 + if (pxds[i])
23997 + free_page((unsigned long)pxds[i]);
23998 }
23999
24000 -static int preallocate_pmds(pmd_t *pmds[])
24001 +static int preallocate_pxds(pxd_t *pxds[])
24002 {
24003 int i;
24004 bool failed = false;
24005
24006 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
24007 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
24008 - if (pmd == NULL)
24009 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
24010 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
24011 + if (pxd == NULL)
24012 failed = true;
24013 - pmds[i] = pmd;
24014 + pxds[i] = pxd;
24015 }
24016
24017 if (failed) {
24018 - free_pmds(pmds);
24019 + free_pxds(pxds);
24020 return -ENOMEM;
24021 }
24022
24023 @@ -203,51 +249,56 @@ static int preallocate_pmds(pmd_t *pmds[
24024 * preallocate which never got a corresponding vma will need to be
24025 * freed manually.
24026 */
24027 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
24028 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
24029 {
24030 int i;
24031
24032 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
24033 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
24034 pgd_t pgd = pgdp[i];
24035
24036 if (pgd_val(pgd) != 0) {
24037 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
24038 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
24039
24040 - pgdp[i] = native_make_pgd(0);
24041 + set_pgd(pgdp + i, native_make_pgd(0));
24042
24043 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
24044 - pmd_free(mm, pmd);
24045 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
24046 + pxd_free(mm, pxd);
24047 }
24048 }
24049 }
24050
24051 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
24052 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
24053 {
24054 - pud_t *pud;
24055 + pyd_t *pyd;
24056 unsigned long addr;
24057 int i;
24058
24059 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
24060 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
24061 return;
24062
24063 - pud = pud_offset(pgd, 0);
24064 +#ifdef CONFIG_X86_64
24065 + pyd = pyd_offset(mm, 0L);
24066 +#else
24067 + pyd = pyd_offset(pgd, 0L);
24068 +#endif
24069
24070 - for (addr = i = 0; i < PREALLOCATED_PMDS;
24071 - i++, pud++, addr += PUD_SIZE) {
24072 - pmd_t *pmd = pmds[i];
24073 + for (addr = i = 0; i < PREALLOCATED_PXDS;
24074 + i++, pyd++, addr += PYD_SIZE) {
24075 + pxd_t *pxd = pxds[i];
24076
24077 if (i >= KERNEL_PGD_BOUNDARY)
24078 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
24079 - sizeof(pmd_t) * PTRS_PER_PMD);
24080 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
24081 + sizeof(pxd_t) * PTRS_PER_PMD);
24082
24083 - pud_populate(mm, pud, pmd);
24084 + pyd_populate(mm, pyd, pxd);
24085 }
24086 }
24087
24088 pgd_t *pgd_alloc(struct mm_struct *mm)
24089 {
24090 pgd_t *pgd;
24091 - pmd_t *pmds[PREALLOCATED_PMDS];
24092 + pxd_t *pxds[PREALLOCATED_PXDS];
24093 +
24094 unsigned long flags;
24095
24096 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
24097 @@ -257,11 +308,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
24098
24099 mm->pgd = pgd;
24100
24101 - if (preallocate_pmds(pmds) != 0)
24102 + if (preallocate_pxds(pxds) != 0)
24103 goto out_free_pgd;
24104
24105 if (paravirt_pgd_alloc(mm) != 0)
24106 - goto out_free_pmds;
24107 + goto out_free_pxds;
24108
24109 /*
24110 * Make sure that pre-populating the pmds is atomic with
24111 @@ -271,14 +322,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
24112 spin_lock_irqsave(&pgd_lock, flags);
24113
24114 pgd_ctor(pgd);
24115 - pgd_prepopulate_pmd(mm, pgd, pmds);
24116 + pgd_prepopulate_pxd(mm, pgd, pxds);
24117
24118 spin_unlock_irqrestore(&pgd_lock, flags);
24119
24120 return pgd;
24121
24122 -out_free_pmds:
24123 - free_pmds(pmds);
24124 +out_free_pxds:
24125 + free_pxds(pxds);
24126 out_free_pgd:
24127 free_page((unsigned long)pgd);
24128 out:
24129 @@ -287,7 +338,7 @@ out:
24130
24131 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
24132 {
24133 - pgd_mop_up_pmds(mm, pgd);
24134 + pgd_mop_up_pxds(mm, pgd);
24135 pgd_dtor(pgd);
24136 paravirt_pgd_free(mm, pgd);
24137 free_page((unsigned long)pgd);
24138 diff -urNp linux-2.6.32.46/arch/x86/mm/pgtable_32.c linux-2.6.32.46/arch/x86/mm/pgtable_32.c
24139 --- linux-2.6.32.46/arch/x86/mm/pgtable_32.c 2011-03-27 14:31:47.000000000 -0400
24140 +++ linux-2.6.32.46/arch/x86/mm/pgtable_32.c 2011-04-17 15:56:46.000000000 -0400
24141 @@ -49,10 +49,13 @@ void set_pte_vaddr(unsigned long vaddr,
24142 return;
24143 }
24144 pte = pte_offset_kernel(pmd, vaddr);
24145 +
24146 + pax_open_kernel();
24147 if (pte_val(pteval))
24148 set_pte_at(&init_mm, vaddr, pte, pteval);
24149 else
24150 pte_clear(&init_mm, vaddr, pte);
24151 + pax_close_kernel();
24152
24153 /*
24154 * It's enough to flush this one mapping.
24155 diff -urNp linux-2.6.32.46/arch/x86/mm/setup_nx.c linux-2.6.32.46/arch/x86/mm/setup_nx.c
24156 --- linux-2.6.32.46/arch/x86/mm/setup_nx.c 2011-03-27 14:31:47.000000000 -0400
24157 +++ linux-2.6.32.46/arch/x86/mm/setup_nx.c 2011-04-17 15:56:46.000000000 -0400
24158 @@ -4,11 +4,10 @@
24159
24160 #include <asm/pgtable.h>
24161
24162 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24163 int nx_enabled;
24164
24165 -#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24166 -static int disable_nx __cpuinitdata;
24167 -
24168 +#ifndef CONFIG_PAX_PAGEEXEC
24169 /*
24170 * noexec = on|off
24171 *
24172 @@ -22,32 +21,26 @@ static int __init noexec_setup(char *str
24173 if (!str)
24174 return -EINVAL;
24175 if (!strncmp(str, "on", 2)) {
24176 - __supported_pte_mask |= _PAGE_NX;
24177 - disable_nx = 0;
24178 + nx_enabled = 1;
24179 } else if (!strncmp(str, "off", 3)) {
24180 - disable_nx = 1;
24181 - __supported_pte_mask &= ~_PAGE_NX;
24182 + nx_enabled = 0;
24183 }
24184 return 0;
24185 }
24186 early_param("noexec", noexec_setup);
24187 #endif
24188 +#endif
24189
24190 #ifdef CONFIG_X86_PAE
24191 void __init set_nx(void)
24192 {
24193 - unsigned int v[4], l, h;
24194 + if (!nx_enabled && cpu_has_nx) {
24195 + unsigned l, h;
24196
24197 - if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
24198 - cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
24199 -
24200 - if ((v[3] & (1 << 20)) && !disable_nx) {
24201 - rdmsr(MSR_EFER, l, h);
24202 - l |= EFER_NX;
24203 - wrmsr(MSR_EFER, l, h);
24204 - nx_enabled = 1;
24205 - __supported_pte_mask |= _PAGE_NX;
24206 - }
24207 + __supported_pte_mask &= ~_PAGE_NX;
24208 + rdmsr(MSR_EFER, l, h);
24209 + l &= ~EFER_NX;
24210 + wrmsr(MSR_EFER, l, h);
24211 }
24212 }
24213 #else
24214 @@ -62,7 +55,7 @@ void __cpuinit check_efer(void)
24215 unsigned long efer;
24216
24217 rdmsrl(MSR_EFER, efer);
24218 - if (!(efer & EFER_NX) || disable_nx)
24219 + if (!(efer & EFER_NX) || !nx_enabled)
24220 __supported_pte_mask &= ~_PAGE_NX;
24221 }
24222 #endif
24223 diff -urNp linux-2.6.32.46/arch/x86/mm/tlb.c linux-2.6.32.46/arch/x86/mm/tlb.c
24224 --- linux-2.6.32.46/arch/x86/mm/tlb.c 2011-03-27 14:31:47.000000000 -0400
24225 +++ linux-2.6.32.46/arch/x86/mm/tlb.c 2011-04-23 12:56:10.000000000 -0400
24226 @@ -61,7 +61,11 @@ void leave_mm(int cpu)
24227 BUG();
24228 cpumask_clear_cpu(cpu,
24229 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
24230 +
24231 +#ifndef CONFIG_PAX_PER_CPU_PGD
24232 load_cr3(swapper_pg_dir);
24233 +#endif
24234 +
24235 }
24236 EXPORT_SYMBOL_GPL(leave_mm);
24237
24238 diff -urNp linux-2.6.32.46/arch/x86/oprofile/backtrace.c linux-2.6.32.46/arch/x86/oprofile/backtrace.c
24239 --- linux-2.6.32.46/arch/x86/oprofile/backtrace.c 2011-03-27 14:31:47.000000000 -0400
24240 +++ linux-2.6.32.46/arch/x86/oprofile/backtrace.c 2011-04-17 15:56:46.000000000 -0400
24241 @@ -57,7 +57,7 @@ static struct frame_head *dump_user_back
24242 struct frame_head bufhead[2];
24243
24244 /* Also check accessibility of one struct frame_head beyond */
24245 - if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
24246 + if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
24247 return NULL;
24248 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
24249 return NULL;
24250 @@ -77,7 +77,7 @@ x86_backtrace(struct pt_regs * const reg
24251 {
24252 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
24253
24254 - if (!user_mode_vm(regs)) {
24255 + if (!user_mode(regs)) {
24256 unsigned long stack = kernel_stack_pointer(regs);
24257 if (depth)
24258 dump_trace(NULL, regs, (unsigned long *)stack, 0,
24259 diff -urNp linux-2.6.32.46/arch/x86/oprofile/op_model_p4.c linux-2.6.32.46/arch/x86/oprofile/op_model_p4.c
24260 --- linux-2.6.32.46/arch/x86/oprofile/op_model_p4.c 2011-03-27 14:31:47.000000000 -0400
24261 +++ linux-2.6.32.46/arch/x86/oprofile/op_model_p4.c 2011-04-17 15:56:46.000000000 -0400
24262 @@ -50,7 +50,7 @@ static inline void setup_num_counters(vo
24263 #endif
24264 }
24265
24266 -static int inline addr_increment(void)
24267 +static inline int addr_increment(void)
24268 {
24269 #ifdef CONFIG_SMP
24270 return smp_num_siblings == 2 ? 2 : 1;
24271 diff -urNp linux-2.6.32.46/arch/x86/pci/common.c linux-2.6.32.46/arch/x86/pci/common.c
24272 --- linux-2.6.32.46/arch/x86/pci/common.c 2011-03-27 14:31:47.000000000 -0400
24273 +++ linux-2.6.32.46/arch/x86/pci/common.c 2011-04-23 12:56:10.000000000 -0400
24274 @@ -31,8 +31,8 @@ int noioapicreroute = 1;
24275 int pcibios_last_bus = -1;
24276 unsigned long pirq_table_addr;
24277 struct pci_bus *pci_root_bus;
24278 -struct pci_raw_ops *raw_pci_ops;
24279 -struct pci_raw_ops *raw_pci_ext_ops;
24280 +const struct pci_raw_ops *raw_pci_ops;
24281 +const struct pci_raw_ops *raw_pci_ext_ops;
24282
24283 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
24284 int reg, int len, u32 *val)
24285 diff -urNp linux-2.6.32.46/arch/x86/pci/direct.c linux-2.6.32.46/arch/x86/pci/direct.c
24286 --- linux-2.6.32.46/arch/x86/pci/direct.c 2011-03-27 14:31:47.000000000 -0400
24287 +++ linux-2.6.32.46/arch/x86/pci/direct.c 2011-04-17 15:56:46.000000000 -0400
24288 @@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
24289
24290 #undef PCI_CONF1_ADDRESS
24291
24292 -struct pci_raw_ops pci_direct_conf1 = {
24293 +const struct pci_raw_ops pci_direct_conf1 = {
24294 .read = pci_conf1_read,
24295 .write = pci_conf1_write,
24296 };
24297 @@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
24298
24299 #undef PCI_CONF2_ADDRESS
24300
24301 -struct pci_raw_ops pci_direct_conf2 = {
24302 +const struct pci_raw_ops pci_direct_conf2 = {
24303 .read = pci_conf2_read,
24304 .write = pci_conf2_write,
24305 };
24306 @@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
24307 * This should be close to trivial, but it isn't, because there are buggy
24308 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
24309 */
24310 -static int __init pci_sanity_check(struct pci_raw_ops *o)
24311 +static int __init pci_sanity_check(const struct pci_raw_ops *o)
24312 {
24313 u32 x = 0;
24314 int year, devfn;
24315 diff -urNp linux-2.6.32.46/arch/x86/pci/mmconfig_32.c linux-2.6.32.46/arch/x86/pci/mmconfig_32.c
24316 --- linux-2.6.32.46/arch/x86/pci/mmconfig_32.c 2011-03-27 14:31:47.000000000 -0400
24317 +++ linux-2.6.32.46/arch/x86/pci/mmconfig_32.c 2011-04-17 15:56:46.000000000 -0400
24318 @@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int
24319 return 0;
24320 }
24321
24322 -static struct pci_raw_ops pci_mmcfg = {
24323 +static const struct pci_raw_ops pci_mmcfg = {
24324 .read = pci_mmcfg_read,
24325 .write = pci_mmcfg_write,
24326 };
24327 diff -urNp linux-2.6.32.46/arch/x86/pci/mmconfig_64.c linux-2.6.32.46/arch/x86/pci/mmconfig_64.c
24328 --- linux-2.6.32.46/arch/x86/pci/mmconfig_64.c 2011-03-27 14:31:47.000000000 -0400
24329 +++ linux-2.6.32.46/arch/x86/pci/mmconfig_64.c 2011-04-17 15:56:46.000000000 -0400
24330 @@ -104,7 +104,7 @@ static int pci_mmcfg_write(unsigned int
24331 return 0;
24332 }
24333
24334 -static struct pci_raw_ops pci_mmcfg = {
24335 +static const struct pci_raw_ops pci_mmcfg = {
24336 .read = pci_mmcfg_read,
24337 .write = pci_mmcfg_write,
24338 };
24339 diff -urNp linux-2.6.32.46/arch/x86/pci/numaq_32.c linux-2.6.32.46/arch/x86/pci/numaq_32.c
24340 --- linux-2.6.32.46/arch/x86/pci/numaq_32.c 2011-03-27 14:31:47.000000000 -0400
24341 +++ linux-2.6.32.46/arch/x86/pci/numaq_32.c 2011-04-17 15:56:46.000000000 -0400
24342 @@ -112,7 +112,7 @@ static int pci_conf1_mq_write(unsigned i
24343
24344 #undef PCI_CONF1_MQ_ADDRESS
24345
24346 -static struct pci_raw_ops pci_direct_conf1_mq = {
24347 +static const struct pci_raw_ops pci_direct_conf1_mq = {
24348 .read = pci_conf1_mq_read,
24349 .write = pci_conf1_mq_write
24350 };
24351 diff -urNp linux-2.6.32.46/arch/x86/pci/olpc.c linux-2.6.32.46/arch/x86/pci/olpc.c
24352 --- linux-2.6.32.46/arch/x86/pci/olpc.c 2011-03-27 14:31:47.000000000 -0400
24353 +++ linux-2.6.32.46/arch/x86/pci/olpc.c 2011-04-17 15:56:46.000000000 -0400
24354 @@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
24355 return 0;
24356 }
24357
24358 -static struct pci_raw_ops pci_olpc_conf = {
24359 +static const struct pci_raw_ops pci_olpc_conf = {
24360 .read = pci_olpc_read,
24361 .write = pci_olpc_write,
24362 };
24363 diff -urNp linux-2.6.32.46/arch/x86/pci/pcbios.c linux-2.6.32.46/arch/x86/pci/pcbios.c
24364 --- linux-2.6.32.46/arch/x86/pci/pcbios.c 2011-03-27 14:31:47.000000000 -0400
24365 +++ linux-2.6.32.46/arch/x86/pci/pcbios.c 2011-04-17 15:56:46.000000000 -0400
24366 @@ -56,50 +56,93 @@ union bios32 {
24367 static struct {
24368 unsigned long address;
24369 unsigned short segment;
24370 -} bios32_indirect = { 0, __KERNEL_CS };
24371 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
24372
24373 /*
24374 * Returns the entry point for the given service, NULL on error
24375 */
24376
24377 -static unsigned long bios32_service(unsigned long service)
24378 +static unsigned long __devinit bios32_service(unsigned long service)
24379 {
24380 unsigned char return_code; /* %al */
24381 unsigned long address; /* %ebx */
24382 unsigned long length; /* %ecx */
24383 unsigned long entry; /* %edx */
24384 unsigned long flags;
24385 + struct desc_struct d, *gdt;
24386
24387 local_irq_save(flags);
24388 - __asm__("lcall *(%%edi); cld"
24389 +
24390 + gdt = get_cpu_gdt_table(smp_processor_id());
24391 +
24392 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
24393 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
24394 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
24395 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
24396 +
24397 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
24398 : "=a" (return_code),
24399 "=b" (address),
24400 "=c" (length),
24401 "=d" (entry)
24402 : "0" (service),
24403 "1" (0),
24404 - "D" (&bios32_indirect));
24405 + "D" (&bios32_indirect),
24406 + "r"(__PCIBIOS_DS)
24407 + : "memory");
24408 +
24409 + pax_open_kernel();
24410 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
24411 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
24412 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
24413 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
24414 + pax_close_kernel();
24415 +
24416 local_irq_restore(flags);
24417
24418 switch (return_code) {
24419 - case 0:
24420 - return address + entry;
24421 - case 0x80: /* Not present */
24422 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
24423 - return 0;
24424 - default: /* Shouldn't happen */
24425 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
24426 - service, return_code);
24427 + case 0: {
24428 + int cpu;
24429 + unsigned char flags;
24430 +
24431 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
24432 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
24433 + printk(KERN_WARNING "bios32_service: not valid\n");
24434 return 0;
24435 + }
24436 + address = address + PAGE_OFFSET;
24437 + length += 16UL; /* some BIOSs underreport this... */
24438 + flags = 4;
24439 + if (length >= 64*1024*1024) {
24440 + length >>= PAGE_SHIFT;
24441 + flags |= 8;
24442 + }
24443 +
24444 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
24445 + gdt = get_cpu_gdt_table(cpu);
24446 + pack_descriptor(&d, address, length, 0x9b, flags);
24447 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
24448 + pack_descriptor(&d, address, length, 0x93, flags);
24449 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
24450 + }
24451 + return entry;
24452 + }
24453 + case 0x80: /* Not present */
24454 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
24455 + return 0;
24456 + default: /* Shouldn't happen */
24457 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
24458 + service, return_code);
24459 + return 0;
24460 }
24461 }
24462
24463 static struct {
24464 unsigned long address;
24465 unsigned short segment;
24466 -} pci_indirect = { 0, __KERNEL_CS };
24467 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
24468
24469 -static int pci_bios_present;
24470 +static int pci_bios_present __read_only;
24471
24472 static int __devinit check_pcibios(void)
24473 {
24474 @@ -108,11 +151,13 @@ static int __devinit check_pcibios(void)
24475 unsigned long flags, pcibios_entry;
24476
24477 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
24478 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
24479 + pci_indirect.address = pcibios_entry;
24480
24481 local_irq_save(flags);
24482 - __asm__(
24483 - "lcall *(%%edi); cld\n\t"
24484 + __asm__("movw %w6, %%ds\n\t"
24485 + "lcall *%%ss:(%%edi); cld\n\t"
24486 + "push %%ss\n\t"
24487 + "pop %%ds\n\t"
24488 "jc 1f\n\t"
24489 "xor %%ah, %%ah\n"
24490 "1:"
24491 @@ -121,7 +166,8 @@ static int __devinit check_pcibios(void)
24492 "=b" (ebx),
24493 "=c" (ecx)
24494 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
24495 - "D" (&pci_indirect)
24496 + "D" (&pci_indirect),
24497 + "r" (__PCIBIOS_DS)
24498 : "memory");
24499 local_irq_restore(flags);
24500
24501 @@ -165,7 +211,10 @@ static int pci_bios_read(unsigned int se
24502
24503 switch (len) {
24504 case 1:
24505 - __asm__("lcall *(%%esi); cld\n\t"
24506 + __asm__("movw %w6, %%ds\n\t"
24507 + "lcall *%%ss:(%%esi); cld\n\t"
24508 + "push %%ss\n\t"
24509 + "pop %%ds\n\t"
24510 "jc 1f\n\t"
24511 "xor %%ah, %%ah\n"
24512 "1:"
24513 @@ -174,7 +223,8 @@ static int pci_bios_read(unsigned int se
24514 : "1" (PCIBIOS_READ_CONFIG_BYTE),
24515 "b" (bx),
24516 "D" ((long)reg),
24517 - "S" (&pci_indirect));
24518 + "S" (&pci_indirect),
24519 + "r" (__PCIBIOS_DS));
24520 /*
24521 * Zero-extend the result beyond 8 bits, do not trust the
24522 * BIOS having done it:
24523 @@ -182,7 +232,10 @@ static int pci_bios_read(unsigned int se
24524 *value &= 0xff;
24525 break;
24526 case 2:
24527 - __asm__("lcall *(%%esi); cld\n\t"
24528 + __asm__("movw %w6, %%ds\n\t"
24529 + "lcall *%%ss:(%%esi); cld\n\t"
24530 + "push %%ss\n\t"
24531 + "pop %%ds\n\t"
24532 "jc 1f\n\t"
24533 "xor %%ah, %%ah\n"
24534 "1:"
24535 @@ -191,7 +244,8 @@ static int pci_bios_read(unsigned int se
24536 : "1" (PCIBIOS_READ_CONFIG_WORD),
24537 "b" (bx),
24538 "D" ((long)reg),
24539 - "S" (&pci_indirect));
24540 + "S" (&pci_indirect),
24541 + "r" (__PCIBIOS_DS));
24542 /*
24543 * Zero-extend the result beyond 16 bits, do not trust the
24544 * BIOS having done it:
24545 @@ -199,7 +253,10 @@ static int pci_bios_read(unsigned int se
24546 *value &= 0xffff;
24547 break;
24548 case 4:
24549 - __asm__("lcall *(%%esi); cld\n\t"
24550 + __asm__("movw %w6, %%ds\n\t"
24551 + "lcall *%%ss:(%%esi); cld\n\t"
24552 + "push %%ss\n\t"
24553 + "pop %%ds\n\t"
24554 "jc 1f\n\t"
24555 "xor %%ah, %%ah\n"
24556 "1:"
24557 @@ -208,7 +265,8 @@ static int pci_bios_read(unsigned int se
24558 : "1" (PCIBIOS_READ_CONFIG_DWORD),
24559 "b" (bx),
24560 "D" ((long)reg),
24561 - "S" (&pci_indirect));
24562 + "S" (&pci_indirect),
24563 + "r" (__PCIBIOS_DS));
24564 break;
24565 }
24566
24567 @@ -231,7 +289,10 @@ static int pci_bios_write(unsigned int s
24568
24569 switch (len) {
24570 case 1:
24571 - __asm__("lcall *(%%esi); cld\n\t"
24572 + __asm__("movw %w6, %%ds\n\t"
24573 + "lcall *%%ss:(%%esi); cld\n\t"
24574 + "push %%ss\n\t"
24575 + "pop %%ds\n\t"
24576 "jc 1f\n\t"
24577 "xor %%ah, %%ah\n"
24578 "1:"
24579 @@ -240,10 +301,14 @@ static int pci_bios_write(unsigned int s
24580 "c" (value),
24581 "b" (bx),
24582 "D" ((long)reg),
24583 - "S" (&pci_indirect));
24584 + "S" (&pci_indirect),
24585 + "r" (__PCIBIOS_DS));
24586 break;
24587 case 2:
24588 - __asm__("lcall *(%%esi); cld\n\t"
24589 + __asm__("movw %w6, %%ds\n\t"
24590 + "lcall *%%ss:(%%esi); cld\n\t"
24591 + "push %%ss\n\t"
24592 + "pop %%ds\n\t"
24593 "jc 1f\n\t"
24594 "xor %%ah, %%ah\n"
24595 "1:"
24596 @@ -252,10 +317,14 @@ static int pci_bios_write(unsigned int s
24597 "c" (value),
24598 "b" (bx),
24599 "D" ((long)reg),
24600 - "S" (&pci_indirect));
24601 + "S" (&pci_indirect),
24602 + "r" (__PCIBIOS_DS));
24603 break;
24604 case 4:
24605 - __asm__("lcall *(%%esi); cld\n\t"
24606 + __asm__("movw %w6, %%ds\n\t"
24607 + "lcall *%%ss:(%%esi); cld\n\t"
24608 + "push %%ss\n\t"
24609 + "pop %%ds\n\t"
24610 "jc 1f\n\t"
24611 "xor %%ah, %%ah\n"
24612 "1:"
24613 @@ -264,7 +333,8 @@ static int pci_bios_write(unsigned int s
24614 "c" (value),
24615 "b" (bx),
24616 "D" ((long)reg),
24617 - "S" (&pci_indirect));
24618 + "S" (&pci_indirect),
24619 + "r" (__PCIBIOS_DS));
24620 break;
24621 }
24622
24623 @@ -278,7 +348,7 @@ static int pci_bios_write(unsigned int s
24624 * Function table for BIOS32 access
24625 */
24626
24627 -static struct pci_raw_ops pci_bios_access = {
24628 +static const struct pci_raw_ops pci_bios_access = {
24629 .read = pci_bios_read,
24630 .write = pci_bios_write
24631 };
24632 @@ -287,7 +357,7 @@ static struct pci_raw_ops pci_bios_acces
24633 * Try to find PCI BIOS.
24634 */
24635
24636 -static struct pci_raw_ops * __devinit pci_find_bios(void)
24637 +static const struct pci_raw_ops * __devinit pci_find_bios(void)
24638 {
24639 union bios32 *check;
24640 unsigned char sum;
24641 @@ -368,10 +438,13 @@ struct irq_routing_table * pcibios_get_i
24642
24643 DBG("PCI: Fetching IRQ routing table... ");
24644 __asm__("push %%es\n\t"
24645 + "movw %w8, %%ds\n\t"
24646 "push %%ds\n\t"
24647 "pop %%es\n\t"
24648 - "lcall *(%%esi); cld\n\t"
24649 + "lcall *%%ss:(%%esi); cld\n\t"
24650 "pop %%es\n\t"
24651 + "push %%ss\n\t"
24652 + "pop %%ds\n"
24653 "jc 1f\n\t"
24654 "xor %%ah, %%ah\n"
24655 "1:"
24656 @@ -382,7 +455,8 @@ struct irq_routing_table * pcibios_get_i
24657 "1" (0),
24658 "D" ((long) &opt),
24659 "S" (&pci_indirect),
24660 - "m" (opt)
24661 + "m" (opt),
24662 + "r" (__PCIBIOS_DS)
24663 : "memory");
24664 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
24665 if (ret & 0xff00)
24666 @@ -406,7 +480,10 @@ int pcibios_set_irq_routing(struct pci_d
24667 {
24668 int ret;
24669
24670 - __asm__("lcall *(%%esi); cld\n\t"
24671 + __asm__("movw %w5, %%ds\n\t"
24672 + "lcall *%%ss:(%%esi); cld\n\t"
24673 + "push %%ss\n\t"
24674 + "pop %%ds\n"
24675 "jc 1f\n\t"
24676 "xor %%ah, %%ah\n"
24677 "1:"
24678 @@ -414,7 +491,8 @@ int pcibios_set_irq_routing(struct pci_d
24679 : "0" (PCIBIOS_SET_PCI_HW_INT),
24680 "b" ((dev->bus->number << 8) | dev->devfn),
24681 "c" ((irq << 8) | (pin + 10)),
24682 - "S" (&pci_indirect));
24683 + "S" (&pci_indirect),
24684 + "r" (__PCIBIOS_DS));
24685 return !(ret & 0xff00);
24686 }
24687 EXPORT_SYMBOL(pcibios_set_irq_routing);
24688 diff -urNp linux-2.6.32.46/arch/x86/power/cpu.c linux-2.6.32.46/arch/x86/power/cpu.c
24689 --- linux-2.6.32.46/arch/x86/power/cpu.c 2011-03-27 14:31:47.000000000 -0400
24690 +++ linux-2.6.32.46/arch/x86/power/cpu.c 2011-04-17 15:56:46.000000000 -0400
24691 @@ -129,7 +129,7 @@ static void do_fpu_end(void)
24692 static void fix_processor_context(void)
24693 {
24694 int cpu = smp_processor_id();
24695 - struct tss_struct *t = &per_cpu(init_tss, cpu);
24696 + struct tss_struct *t = init_tss + cpu;
24697
24698 set_tss_desc(cpu, t); /*
24699 * This just modifies memory; should not be
24700 @@ -139,7 +139,9 @@ static void fix_processor_context(void)
24701 */
24702
24703 #ifdef CONFIG_X86_64
24704 + pax_open_kernel();
24705 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
24706 + pax_close_kernel();
24707
24708 syscall_init(); /* This sets MSR_*STAR and related */
24709 #endif
24710 diff -urNp linux-2.6.32.46/arch/x86/vdso/Makefile linux-2.6.32.46/arch/x86/vdso/Makefile
24711 --- linux-2.6.32.46/arch/x86/vdso/Makefile 2011-03-27 14:31:47.000000000 -0400
24712 +++ linux-2.6.32.46/arch/x86/vdso/Makefile 2011-04-17 15:56:46.000000000 -0400
24713 @@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@
24714 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
24715 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
24716
24717 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24718 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24719 GCOV_PROFILE := n
24720
24721 #
24722 diff -urNp linux-2.6.32.46/arch/x86/vdso/vclock_gettime.c linux-2.6.32.46/arch/x86/vdso/vclock_gettime.c
24723 --- linux-2.6.32.46/arch/x86/vdso/vclock_gettime.c 2011-03-27 14:31:47.000000000 -0400
24724 +++ linux-2.6.32.46/arch/x86/vdso/vclock_gettime.c 2011-04-17 15:56:46.000000000 -0400
24725 @@ -22,24 +22,48 @@
24726 #include <asm/hpet.h>
24727 #include <asm/unistd.h>
24728 #include <asm/io.h>
24729 +#include <asm/fixmap.h>
24730 #include "vextern.h"
24731
24732 #define gtod vdso_vsyscall_gtod_data
24733
24734 +notrace noinline long __vdso_fallback_time(long *t)
24735 +{
24736 + long secs;
24737 + asm volatile("syscall"
24738 + : "=a" (secs)
24739 + : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
24740 + return secs;
24741 +}
24742 +
24743 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
24744 {
24745 long ret;
24746 asm("syscall" : "=a" (ret) :
24747 - "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
24748 + "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
24749 return ret;
24750 }
24751
24752 +notrace static inline cycle_t __vdso_vread_hpet(void)
24753 +{
24754 + return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
24755 +}
24756 +
24757 +notrace static inline cycle_t __vdso_vread_tsc(void)
24758 +{
24759 + cycle_t ret = (cycle_t)vget_cycles();
24760 +
24761 + return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
24762 +}
24763 +
24764 notrace static inline long vgetns(void)
24765 {
24766 long v;
24767 - cycles_t (*vread)(void);
24768 - vread = gtod->clock.vread;
24769 - v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
24770 + if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
24771 + v = __vdso_vread_tsc();
24772 + else
24773 + v = __vdso_vread_hpet();
24774 + v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
24775 return (v * gtod->clock.mult) >> gtod->clock.shift;
24776 }
24777
24778 @@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
24779
24780 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
24781 {
24782 - if (likely(gtod->sysctl_enabled))
24783 + if (likely(gtod->sysctl_enabled &&
24784 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
24785 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
24786 switch (clock) {
24787 case CLOCK_REALTIME:
24788 if (likely(gtod->clock.vread))
24789 @@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
24790 int clock_gettime(clockid_t, struct timespec *)
24791 __attribute__((weak, alias("__vdso_clock_gettime")));
24792
24793 -notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
24794 +notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
24795 {
24796 long ret;
24797 - if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
24798 + asm("syscall" : "=a" (ret) :
24799 + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
24800 + return ret;
24801 +}
24802 +
24803 +notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
24804 +{
24805 + if (likely(gtod->sysctl_enabled &&
24806 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
24807 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
24808 + {
24809 if (likely(tv != NULL)) {
24810 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
24811 offsetof(struct timespec, tv_nsec) ||
24812 @@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
24813 }
24814 return 0;
24815 }
24816 - asm("syscall" : "=a" (ret) :
24817 - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
24818 - return ret;
24819 + return __vdso_fallback_gettimeofday(tv, tz);
24820 }
24821 int gettimeofday(struct timeval *, struct timezone *)
24822 __attribute__((weak, alias("__vdso_gettimeofday")));
24823 diff -urNp linux-2.6.32.46/arch/x86/vdso/vdso.lds.S linux-2.6.32.46/arch/x86/vdso/vdso.lds.S
24824 --- linux-2.6.32.46/arch/x86/vdso/vdso.lds.S 2011-03-27 14:31:47.000000000 -0400
24825 +++ linux-2.6.32.46/arch/x86/vdso/vdso.lds.S 2011-06-06 17:35:35.000000000 -0400
24826 @@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
24827 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
24828 #include "vextern.h"
24829 #undef VEXTERN
24830 +
24831 +#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
24832 +VEXTERN(fallback_gettimeofday)
24833 +VEXTERN(fallback_time)
24834 +VEXTERN(getcpu)
24835 +#undef VEXTERN
24836 diff -urNp linux-2.6.32.46/arch/x86/vdso/vdso32-setup.c linux-2.6.32.46/arch/x86/vdso/vdso32-setup.c
24837 --- linux-2.6.32.46/arch/x86/vdso/vdso32-setup.c 2011-03-27 14:31:47.000000000 -0400
24838 +++ linux-2.6.32.46/arch/x86/vdso/vdso32-setup.c 2011-04-23 12:56:10.000000000 -0400
24839 @@ -25,6 +25,7 @@
24840 #include <asm/tlbflush.h>
24841 #include <asm/vdso.h>
24842 #include <asm/proto.h>
24843 +#include <asm/mman.h>
24844
24845 enum {
24846 VDSO_DISABLED = 0,
24847 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
24848 void enable_sep_cpu(void)
24849 {
24850 int cpu = get_cpu();
24851 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
24852 + struct tss_struct *tss = init_tss + cpu;
24853
24854 if (!boot_cpu_has(X86_FEATURE_SEP)) {
24855 put_cpu();
24856 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
24857 gate_vma.vm_start = FIXADDR_USER_START;
24858 gate_vma.vm_end = FIXADDR_USER_END;
24859 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
24860 - gate_vma.vm_page_prot = __P101;
24861 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
24862 /*
24863 * Make sure the vDSO gets into every core dump.
24864 * Dumping its contents makes post-mortem fully interpretable later
24865 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
24866 if (compat)
24867 addr = VDSO_HIGH_BASE;
24868 else {
24869 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
24870 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
24871 if (IS_ERR_VALUE(addr)) {
24872 ret = addr;
24873 goto up_fail;
24874 }
24875 }
24876
24877 - current->mm->context.vdso = (void *)addr;
24878 + current->mm->context.vdso = addr;
24879
24880 if (compat_uses_vma || !compat) {
24881 /*
24882 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
24883 }
24884
24885 current_thread_info()->sysenter_return =
24886 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24887 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24888
24889 up_fail:
24890 if (ret)
24891 - current->mm->context.vdso = NULL;
24892 + current->mm->context.vdso = 0;
24893
24894 up_write(&mm->mmap_sem);
24895
24896 @@ -413,8 +414,14 @@ __initcall(ia32_binfmt_init);
24897
24898 const char *arch_vma_name(struct vm_area_struct *vma)
24899 {
24900 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24901 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24902 return "[vdso]";
24903 +
24904 +#ifdef CONFIG_PAX_SEGMEXEC
24905 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
24906 + return "[vdso]";
24907 +#endif
24908 +
24909 return NULL;
24910 }
24911
24912 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
24913 struct mm_struct *mm = tsk->mm;
24914
24915 /* Check to see if this task was created in compat vdso mode */
24916 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
24917 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
24918 return &gate_vma;
24919 return NULL;
24920 }
24921 diff -urNp linux-2.6.32.46/arch/x86/vdso/vextern.h linux-2.6.32.46/arch/x86/vdso/vextern.h
24922 --- linux-2.6.32.46/arch/x86/vdso/vextern.h 2011-03-27 14:31:47.000000000 -0400
24923 +++ linux-2.6.32.46/arch/x86/vdso/vextern.h 2011-04-17 15:56:46.000000000 -0400
24924 @@ -11,6 +11,5 @@
24925 put into vextern.h and be referenced as a pointer with vdso prefix.
24926 The main kernel later fills in the values. */
24927
24928 -VEXTERN(jiffies)
24929 VEXTERN(vgetcpu_mode)
24930 VEXTERN(vsyscall_gtod_data)
24931 diff -urNp linux-2.6.32.46/arch/x86/vdso/vma.c linux-2.6.32.46/arch/x86/vdso/vma.c
24932 --- linux-2.6.32.46/arch/x86/vdso/vma.c 2011-03-27 14:31:47.000000000 -0400
24933 +++ linux-2.6.32.46/arch/x86/vdso/vma.c 2011-08-23 20:24:19.000000000 -0400
24934 @@ -17,8 +17,6 @@
24935 #include "vextern.h" /* Just for VMAGIC. */
24936 #undef VEXTERN
24937
24938 -unsigned int __read_mostly vdso_enabled = 1;
24939 -
24940 extern char vdso_start[], vdso_end[];
24941 extern unsigned short vdso_sync_cpuid;
24942
24943 @@ -27,10 +25,8 @@ static unsigned vdso_size;
24944
24945 static inline void *var_ref(void *p, char *name)
24946 {
24947 - if (*(void **)p != (void *)VMAGIC) {
24948 - printk("VDSO: variable %s broken\n", name);
24949 - vdso_enabled = 0;
24950 - }
24951 + if (*(void **)p != (void *)VMAGIC)
24952 + panic("VDSO: variable %s broken\n", name);
24953 return p;
24954 }
24955
24956 @@ -57,21 +53,18 @@ static int __init init_vdso_vars(void)
24957 if (!vbase)
24958 goto oom;
24959
24960 - if (memcmp(vbase, "\177ELF", 4)) {
24961 - printk("VDSO: I'm broken; not ELF\n");
24962 - vdso_enabled = 0;
24963 - }
24964 + if (memcmp(vbase, ELFMAG, SELFMAG))
24965 + panic("VDSO: I'm broken; not ELF\n");
24966
24967 #define VEXTERN(x) \
24968 *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x;
24969 #include "vextern.h"
24970 #undef VEXTERN
24971 + vunmap(vbase);
24972 return 0;
24973
24974 oom:
24975 - printk("Cannot allocate vdso\n");
24976 - vdso_enabled = 0;
24977 - return -ENOMEM;
24978 + panic("Cannot allocate vdso\n");
24979 }
24980 __initcall(init_vdso_vars);
24981
24982 @@ -105,9 +98,6 @@ int arch_setup_additional_pages(struct l
24983 unsigned long addr;
24984 int ret;
24985
24986 - if (!vdso_enabled)
24987 - return 0;
24988 -
24989 down_write(&mm->mmap_sem);
24990 addr = vdso_addr(mm->start_stack, vdso_size);
24991 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
24992 @@ -116,7 +106,7 @@ int arch_setup_additional_pages(struct l
24993 goto up_fail;
24994 }
24995
24996 - current->mm->context.vdso = (void *)addr;
24997 + current->mm->context.vdso = addr;
24998
24999 ret = install_special_mapping(mm, addr, vdso_size,
25000 VM_READ|VM_EXEC|
25001 @@ -124,7 +114,7 @@ int arch_setup_additional_pages(struct l
25002 VM_ALWAYSDUMP,
25003 vdso_pages);
25004 if (ret) {
25005 - current->mm->context.vdso = NULL;
25006 + current->mm->context.vdso = 0;
25007 goto up_fail;
25008 }
25009
25010 @@ -132,10 +122,3 @@ up_fail:
25011 up_write(&mm->mmap_sem);
25012 return ret;
25013 }
25014 -
25015 -static __init int vdso_setup(char *s)
25016 -{
25017 - vdso_enabled = simple_strtoul(s, NULL, 0);
25018 - return 0;
25019 -}
25020 -__setup("vdso=", vdso_setup);
25021 diff -urNp linux-2.6.32.46/arch/x86/xen/enlighten.c linux-2.6.32.46/arch/x86/xen/enlighten.c
25022 --- linux-2.6.32.46/arch/x86/xen/enlighten.c 2011-03-27 14:31:47.000000000 -0400
25023 +++ linux-2.6.32.46/arch/x86/xen/enlighten.c 2011-05-22 23:02:03.000000000 -0400
25024 @@ -71,8 +71,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
25025
25026 struct shared_info xen_dummy_shared_info;
25027
25028 -void *xen_initial_gdt;
25029 -
25030 /*
25031 * Point at some empty memory to start with. We map the real shared_info
25032 * page as soon as fixmap is up and running.
25033 @@ -548,7 +546,7 @@ static void xen_write_idt_entry(gate_des
25034
25035 preempt_disable();
25036
25037 - start = __get_cpu_var(idt_desc).address;
25038 + start = (unsigned long)__get_cpu_var(idt_desc).address;
25039 end = start + __get_cpu_var(idt_desc).size + 1;
25040
25041 xen_mc_flush();
25042 @@ -993,7 +991,7 @@ static const struct pv_apic_ops xen_apic
25043 #endif
25044 };
25045
25046 -static void xen_reboot(int reason)
25047 +static __noreturn void xen_reboot(int reason)
25048 {
25049 struct sched_shutdown r = { .reason = reason };
25050
25051 @@ -1001,17 +999,17 @@ static void xen_reboot(int reason)
25052 BUG();
25053 }
25054
25055 -static void xen_restart(char *msg)
25056 +static __noreturn void xen_restart(char *msg)
25057 {
25058 xen_reboot(SHUTDOWN_reboot);
25059 }
25060
25061 -static void xen_emergency_restart(void)
25062 +static __noreturn void xen_emergency_restart(void)
25063 {
25064 xen_reboot(SHUTDOWN_reboot);
25065 }
25066
25067 -static void xen_machine_halt(void)
25068 +static __noreturn void xen_machine_halt(void)
25069 {
25070 xen_reboot(SHUTDOWN_poweroff);
25071 }
25072 @@ -1095,9 +1093,20 @@ asmlinkage void __init xen_start_kernel(
25073 */
25074 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
25075
25076 -#ifdef CONFIG_X86_64
25077 /* Work out if we support NX */
25078 - check_efer();
25079 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25080 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
25081 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
25082 + unsigned l, h;
25083 +
25084 +#ifdef CONFIG_X86_PAE
25085 + nx_enabled = 1;
25086 +#endif
25087 + __supported_pte_mask |= _PAGE_NX;
25088 + rdmsr(MSR_EFER, l, h);
25089 + l |= EFER_NX;
25090 + wrmsr(MSR_EFER, l, h);
25091 + }
25092 #endif
25093
25094 xen_setup_features();
25095 @@ -1129,13 +1138,6 @@ asmlinkage void __init xen_start_kernel(
25096
25097 machine_ops = xen_machine_ops;
25098
25099 - /*
25100 - * The only reliable way to retain the initial address of the
25101 - * percpu gdt_page is to remember it here, so we can go and
25102 - * mark it RW later, when the initial percpu area is freed.
25103 - */
25104 - xen_initial_gdt = &per_cpu(gdt_page, 0);
25105 -
25106 xen_smp_init();
25107
25108 pgd = (pgd_t *)xen_start_info->pt_base;
25109 diff -urNp linux-2.6.32.46/arch/x86/xen/mmu.c linux-2.6.32.46/arch/x86/xen/mmu.c
25110 --- linux-2.6.32.46/arch/x86/xen/mmu.c 2011-07-13 17:23:04.000000000 -0400
25111 +++ linux-2.6.32.46/arch/x86/xen/mmu.c 2011-08-24 18:35:52.000000000 -0400
25112 @@ -1719,6 +1719,8 @@ __init pgd_t *xen_setup_kernel_pagetable
25113 convert_pfn_mfn(init_level4_pgt);
25114 convert_pfn_mfn(level3_ident_pgt);
25115 convert_pfn_mfn(level3_kernel_pgt);
25116 + convert_pfn_mfn(level3_vmalloc_pgt);
25117 + convert_pfn_mfn(level3_vmemmap_pgt);
25118
25119 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
25120 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
25121 @@ -1737,7 +1739,10 @@ __init pgd_t *xen_setup_kernel_pagetable
25122 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
25123 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
25124 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
25125 + set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
25126 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
25127 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
25128 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
25129 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
25130 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
25131
25132 @@ -1860,6 +1865,7 @@ static __init void xen_post_allocator_in
25133 pv_mmu_ops.set_pud = xen_set_pud;
25134 #if PAGETABLE_LEVELS == 4
25135 pv_mmu_ops.set_pgd = xen_set_pgd;
25136 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
25137 #endif
25138
25139 /* This will work as long as patching hasn't happened yet
25140 @@ -1946,6 +1952,7 @@ static const struct pv_mmu_ops xen_mmu_o
25141 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
25142 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
25143 .set_pgd = xen_set_pgd_hyper,
25144 + .set_pgd_batched = xen_set_pgd_hyper,
25145
25146 .alloc_pud = xen_alloc_pmd_init,
25147 .release_pud = xen_release_pmd_init,
25148 diff -urNp linux-2.6.32.46/arch/x86/xen/smp.c linux-2.6.32.46/arch/x86/xen/smp.c
25149 --- linux-2.6.32.46/arch/x86/xen/smp.c 2011-03-27 14:31:47.000000000 -0400
25150 +++ linux-2.6.32.46/arch/x86/xen/smp.c 2011-05-11 18:25:15.000000000 -0400
25151 @@ -167,11 +167,6 @@ static void __init xen_smp_prepare_boot_
25152 {
25153 BUG_ON(smp_processor_id() != 0);
25154 native_smp_prepare_boot_cpu();
25155 -
25156 - /* We've switched to the "real" per-cpu gdt, so make sure the
25157 - old memory can be recycled */
25158 - make_lowmem_page_readwrite(xen_initial_gdt);
25159 -
25160 xen_setup_vcpu_info_placement();
25161 }
25162
25163 @@ -231,12 +226,12 @@ cpu_initialize_context(unsigned int cpu,
25164 gdt = get_cpu_gdt_table(cpu);
25165
25166 ctxt->flags = VGCF_IN_KERNEL;
25167 - ctxt->user_regs.ds = __USER_DS;
25168 - ctxt->user_regs.es = __USER_DS;
25169 + ctxt->user_regs.ds = __KERNEL_DS;
25170 + ctxt->user_regs.es = __KERNEL_DS;
25171 ctxt->user_regs.ss = __KERNEL_DS;
25172 #ifdef CONFIG_X86_32
25173 ctxt->user_regs.fs = __KERNEL_PERCPU;
25174 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
25175 + savesegment(gs, ctxt->user_regs.gs);
25176 #else
25177 ctxt->gs_base_kernel = per_cpu_offset(cpu);
25178 #endif
25179 @@ -287,13 +282,12 @@ static int __cpuinit xen_cpu_up(unsigned
25180 int rc;
25181
25182 per_cpu(current_task, cpu) = idle;
25183 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
25184 #ifdef CONFIG_X86_32
25185 irq_ctx_init(cpu);
25186 #else
25187 clear_tsk_thread_flag(idle, TIF_FORK);
25188 - per_cpu(kernel_stack, cpu) =
25189 - (unsigned long)task_stack_page(idle) -
25190 - KERNEL_STACK_OFFSET + THREAD_SIZE;
25191 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25192 #endif
25193 xen_setup_runstate_info(cpu);
25194 xen_setup_timer(cpu);
25195 diff -urNp linux-2.6.32.46/arch/x86/xen/xen-asm_32.S linux-2.6.32.46/arch/x86/xen/xen-asm_32.S
25196 --- linux-2.6.32.46/arch/x86/xen/xen-asm_32.S 2011-03-27 14:31:47.000000000 -0400
25197 +++ linux-2.6.32.46/arch/x86/xen/xen-asm_32.S 2011-04-22 19:13:13.000000000 -0400
25198 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
25199 ESP_OFFSET=4 # bytes pushed onto stack
25200
25201 /*
25202 - * Store vcpu_info pointer for easy access. Do it this way to
25203 - * avoid having to reload %fs
25204 + * Store vcpu_info pointer for easy access.
25205 */
25206 #ifdef CONFIG_SMP
25207 - GET_THREAD_INFO(%eax)
25208 - movl TI_cpu(%eax), %eax
25209 - movl __per_cpu_offset(,%eax,4), %eax
25210 - mov per_cpu__xen_vcpu(%eax), %eax
25211 + push %fs
25212 + mov $(__KERNEL_PERCPU), %eax
25213 + mov %eax, %fs
25214 + mov PER_CPU_VAR(xen_vcpu), %eax
25215 + pop %fs
25216 #else
25217 movl per_cpu__xen_vcpu, %eax
25218 #endif
25219 diff -urNp linux-2.6.32.46/arch/x86/xen/xen-head.S linux-2.6.32.46/arch/x86/xen/xen-head.S
25220 --- linux-2.6.32.46/arch/x86/xen/xen-head.S 2011-03-27 14:31:47.000000000 -0400
25221 +++ linux-2.6.32.46/arch/x86/xen/xen-head.S 2011-04-17 15:56:46.000000000 -0400
25222 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
25223 #ifdef CONFIG_X86_32
25224 mov %esi,xen_start_info
25225 mov $init_thread_union+THREAD_SIZE,%esp
25226 +#ifdef CONFIG_SMP
25227 + movl $cpu_gdt_table,%edi
25228 + movl $__per_cpu_load,%eax
25229 + movw %ax,__KERNEL_PERCPU + 2(%edi)
25230 + rorl $16,%eax
25231 + movb %al,__KERNEL_PERCPU + 4(%edi)
25232 + movb %ah,__KERNEL_PERCPU + 7(%edi)
25233 + movl $__per_cpu_end - 1,%eax
25234 + subl $__per_cpu_start,%eax
25235 + movw %ax,__KERNEL_PERCPU + 0(%edi)
25236 +#endif
25237 #else
25238 mov %rsi,xen_start_info
25239 mov $init_thread_union+THREAD_SIZE,%rsp
25240 diff -urNp linux-2.6.32.46/arch/x86/xen/xen-ops.h linux-2.6.32.46/arch/x86/xen/xen-ops.h
25241 --- linux-2.6.32.46/arch/x86/xen/xen-ops.h 2011-03-27 14:31:47.000000000 -0400
25242 +++ linux-2.6.32.46/arch/x86/xen/xen-ops.h 2011-04-17 15:56:46.000000000 -0400
25243 @@ -10,8 +10,6 @@
25244 extern const char xen_hypervisor_callback[];
25245 extern const char xen_failsafe_callback[];
25246
25247 -extern void *xen_initial_gdt;
25248 -
25249 struct trap_info;
25250 void xen_copy_trap_info(struct trap_info *traps);
25251
25252 diff -urNp linux-2.6.32.46/block/blk-integrity.c linux-2.6.32.46/block/blk-integrity.c
25253 --- linux-2.6.32.46/block/blk-integrity.c 2011-03-27 14:31:47.000000000 -0400
25254 +++ linux-2.6.32.46/block/blk-integrity.c 2011-04-17 15:56:46.000000000 -0400
25255 @@ -278,7 +278,7 @@ static struct attribute *integrity_attrs
25256 NULL,
25257 };
25258
25259 -static struct sysfs_ops integrity_ops = {
25260 +static const struct sysfs_ops integrity_ops = {
25261 .show = &integrity_attr_show,
25262 .store = &integrity_attr_store,
25263 };
25264 diff -urNp linux-2.6.32.46/block/blk-iopoll.c linux-2.6.32.46/block/blk-iopoll.c
25265 --- linux-2.6.32.46/block/blk-iopoll.c 2011-03-27 14:31:47.000000000 -0400
25266 +++ linux-2.6.32.46/block/blk-iopoll.c 2011-04-17 15:56:46.000000000 -0400
25267 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
25268 }
25269 EXPORT_SYMBOL(blk_iopoll_complete);
25270
25271 -static void blk_iopoll_softirq(struct softirq_action *h)
25272 +static void blk_iopoll_softirq(void)
25273 {
25274 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
25275 int rearm = 0, budget = blk_iopoll_budget;
25276 diff -urNp linux-2.6.32.46/block/blk-map.c linux-2.6.32.46/block/blk-map.c
25277 --- linux-2.6.32.46/block/blk-map.c 2011-03-27 14:31:47.000000000 -0400
25278 +++ linux-2.6.32.46/block/blk-map.c 2011-04-18 16:57:33.000000000 -0400
25279 @@ -54,7 +54,7 @@ static int __blk_rq_map_user(struct requ
25280 * direct dma. else, set up kernel bounce buffers
25281 */
25282 uaddr = (unsigned long) ubuf;
25283 - if (blk_rq_aligned(q, ubuf, len) && !map_data)
25284 + if (blk_rq_aligned(q, (__force void *)ubuf, len) && !map_data)
25285 bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
25286 else
25287 bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
25288 @@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_q
25289 for (i = 0; i < iov_count; i++) {
25290 unsigned long uaddr = (unsigned long)iov[i].iov_base;
25291
25292 + if (!iov[i].iov_len)
25293 + return -EINVAL;
25294 +
25295 if (uaddr & queue_dma_alignment(q)) {
25296 unaligned = 1;
25297 break;
25298 }
25299 - if (!iov[i].iov_len)
25300 - return -EINVAL;
25301 }
25302
25303 if (unaligned || (q->dma_pad_mask & len) || map_data)
25304 @@ -299,7 +300,7 @@ int blk_rq_map_kern(struct request_queue
25305 if (!len || !kbuf)
25306 return -EINVAL;
25307
25308 - do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
25309 + do_copy = !blk_rq_aligned(q, kbuf, len) || object_starts_on_stack(kbuf);
25310 if (do_copy)
25311 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
25312 else
25313 diff -urNp linux-2.6.32.46/block/blk-softirq.c linux-2.6.32.46/block/blk-softirq.c
25314 --- linux-2.6.32.46/block/blk-softirq.c 2011-03-27 14:31:47.000000000 -0400
25315 +++ linux-2.6.32.46/block/blk-softirq.c 2011-04-17 15:56:46.000000000 -0400
25316 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
25317 * Softirq action handler - move entries to local list and loop over them
25318 * while passing them to the queue registered handler.
25319 */
25320 -static void blk_done_softirq(struct softirq_action *h)
25321 +static void blk_done_softirq(void)
25322 {
25323 struct list_head *cpu_list, local_list;
25324
25325 diff -urNp linux-2.6.32.46/block/blk-sysfs.c linux-2.6.32.46/block/blk-sysfs.c
25326 --- linux-2.6.32.46/block/blk-sysfs.c 2011-05-10 22:12:01.000000000 -0400
25327 +++ linux-2.6.32.46/block/blk-sysfs.c 2011-05-10 22:12:26.000000000 -0400
25328 @@ -414,7 +414,7 @@ static void blk_release_queue(struct kob
25329 kmem_cache_free(blk_requestq_cachep, q);
25330 }
25331
25332 -static struct sysfs_ops queue_sysfs_ops = {
25333 +static const struct sysfs_ops queue_sysfs_ops = {
25334 .show = queue_attr_show,
25335 .store = queue_attr_store,
25336 };
25337 diff -urNp linux-2.6.32.46/block/bsg.c linux-2.6.32.46/block/bsg.c
25338 --- linux-2.6.32.46/block/bsg.c 2011-03-27 14:31:47.000000000 -0400
25339 +++ linux-2.6.32.46/block/bsg.c 2011-10-06 09:37:08.000000000 -0400
25340 @@ -175,16 +175,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
25341 struct sg_io_v4 *hdr, struct bsg_device *bd,
25342 fmode_t has_write_perm)
25343 {
25344 + unsigned char tmpcmd[sizeof(rq->__cmd)];
25345 + unsigned char *cmdptr;
25346 +
25347 if (hdr->request_len > BLK_MAX_CDB) {
25348 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
25349 if (!rq->cmd)
25350 return -ENOMEM;
25351 - }
25352 + cmdptr = rq->cmd;
25353 + } else
25354 + cmdptr = tmpcmd;
25355
25356 - if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
25357 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
25358 hdr->request_len))
25359 return -EFAULT;
25360
25361 + if (cmdptr != rq->cmd)
25362 + memcpy(rq->cmd, cmdptr, hdr->request_len);
25363 +
25364 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
25365 if (blk_verify_command(rq->cmd, has_write_perm))
25366 return -EPERM;
25367 @@ -282,7 +290,7 @@ bsg_map_hdr(struct bsg_device *bd, struc
25368 rq->next_rq = next_rq;
25369 next_rq->cmd_type = rq->cmd_type;
25370
25371 - dxferp = (void*)(unsigned long)hdr->din_xferp;
25372 + dxferp = (void __user *)(unsigned long)hdr->din_xferp;
25373 ret = blk_rq_map_user(q, next_rq, NULL, dxferp,
25374 hdr->din_xfer_len, GFP_KERNEL);
25375 if (ret)
25376 @@ -291,10 +299,10 @@ bsg_map_hdr(struct bsg_device *bd, struc
25377
25378 if (hdr->dout_xfer_len) {
25379 dxfer_len = hdr->dout_xfer_len;
25380 - dxferp = (void*)(unsigned long)hdr->dout_xferp;
25381 + dxferp = (void __user *)(unsigned long)hdr->dout_xferp;
25382 } else if (hdr->din_xfer_len) {
25383 dxfer_len = hdr->din_xfer_len;
25384 - dxferp = (void*)(unsigned long)hdr->din_xferp;
25385 + dxferp = (void __user *)(unsigned long)hdr->din_xferp;
25386 } else
25387 dxfer_len = 0;
25388
25389 @@ -436,7 +444,7 @@ static int blk_complete_sgv4_hdr_rq(stru
25390 int len = min_t(unsigned int, hdr->max_response_len,
25391 rq->sense_len);
25392
25393 - ret = copy_to_user((void*)(unsigned long)hdr->response,
25394 + ret = copy_to_user((void __user *)(unsigned long)hdr->response,
25395 rq->sense, len);
25396 if (!ret)
25397 hdr->response_len = len;
25398 diff -urNp linux-2.6.32.46/block/compat_ioctl.c linux-2.6.32.46/block/compat_ioctl.c
25399 --- linux-2.6.32.46/block/compat_ioctl.c 2011-03-27 14:31:47.000000000 -0400
25400 +++ linux-2.6.32.46/block/compat_ioctl.c 2011-10-06 09:37:14.000000000 -0400
25401 @@ -354,7 +354,7 @@ static int compat_fd_ioctl(struct block_
25402 err |= __get_user(f->spec1, &uf->spec1);
25403 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
25404 err |= __get_user(name, &uf->name);
25405 - f->name = compat_ptr(name);
25406 + f->name = (void __force_kernel *)compat_ptr(name);
25407 if (err) {
25408 err = -EFAULT;
25409 goto out;
25410 diff -urNp linux-2.6.32.46/block/elevator.c linux-2.6.32.46/block/elevator.c
25411 --- linux-2.6.32.46/block/elevator.c 2011-03-27 14:31:47.000000000 -0400
25412 +++ linux-2.6.32.46/block/elevator.c 2011-04-17 15:56:46.000000000 -0400
25413 @@ -889,7 +889,7 @@ elv_attr_store(struct kobject *kobj, str
25414 return error;
25415 }
25416
25417 -static struct sysfs_ops elv_sysfs_ops = {
25418 +static const struct sysfs_ops elv_sysfs_ops = {
25419 .show = elv_attr_show,
25420 .store = elv_attr_store,
25421 };
25422 diff -urNp linux-2.6.32.46/block/scsi_ioctl.c linux-2.6.32.46/block/scsi_ioctl.c
25423 --- linux-2.6.32.46/block/scsi_ioctl.c 2011-03-27 14:31:47.000000000 -0400
25424 +++ linux-2.6.32.46/block/scsi_ioctl.c 2011-04-23 13:28:22.000000000 -0400
25425 @@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
25426 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
25427 struct sg_io_hdr *hdr, fmode_t mode)
25428 {
25429 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
25430 + unsigned char tmpcmd[sizeof(rq->__cmd)];
25431 + unsigned char *cmdptr;
25432 +
25433 + if (rq->cmd != rq->__cmd)
25434 + cmdptr = rq->cmd;
25435 + else
25436 + cmdptr = tmpcmd;
25437 +
25438 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
25439 return -EFAULT;
25440 +
25441 + if (cmdptr != rq->cmd)
25442 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
25443 +
25444 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
25445 return -EPERM;
25446
25447 @@ -430,6 +442,8 @@ int sg_scsi_ioctl(struct request_queue *
25448 int err;
25449 unsigned int in_len, out_len, bytes, opcode, cmdlen;
25450 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
25451 + unsigned char tmpcmd[sizeof(rq->__cmd)];
25452 + unsigned char *cmdptr;
25453
25454 if (!sic)
25455 return -EINVAL;
25456 @@ -463,9 +477,18 @@ int sg_scsi_ioctl(struct request_queue *
25457 */
25458 err = -EFAULT;
25459 rq->cmd_len = cmdlen;
25460 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
25461 +
25462 + if (rq->cmd != rq->__cmd)
25463 + cmdptr = rq->cmd;
25464 + else
25465 + cmdptr = tmpcmd;
25466 +
25467 + if (copy_from_user(cmdptr, sic->data, cmdlen))
25468 goto error;
25469
25470 + if (rq->cmd != cmdptr)
25471 + memcpy(rq->cmd, cmdptr, cmdlen);
25472 +
25473 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
25474 goto error;
25475
25476 diff -urNp linux-2.6.32.46/crypto/cryptd.c linux-2.6.32.46/crypto/cryptd.c
25477 --- linux-2.6.32.46/crypto/cryptd.c 2011-03-27 14:31:47.000000000 -0400
25478 +++ linux-2.6.32.46/crypto/cryptd.c 2011-08-23 21:22:32.000000000 -0400
25479 @@ -50,7 +50,7 @@ struct cryptd_blkcipher_ctx {
25480
25481 struct cryptd_blkcipher_request_ctx {
25482 crypto_completion_t complete;
25483 -};
25484 +} __no_const;
25485
25486 struct cryptd_hash_ctx {
25487 struct crypto_shash *child;
25488 diff -urNp linux-2.6.32.46/crypto/gf128mul.c linux-2.6.32.46/crypto/gf128mul.c
25489 --- linux-2.6.32.46/crypto/gf128mul.c 2011-03-27 14:31:47.000000000 -0400
25490 +++ linux-2.6.32.46/crypto/gf128mul.c 2011-07-06 19:53:33.000000000 -0400
25491 @@ -182,7 +182,7 @@ void gf128mul_lle(be128 *r, const be128
25492 for (i = 0; i < 7; ++i)
25493 gf128mul_x_lle(&p[i + 1], &p[i]);
25494
25495 - memset(r, 0, sizeof(r));
25496 + memset(r, 0, sizeof(*r));
25497 for (i = 0;;) {
25498 u8 ch = ((u8 *)b)[15 - i];
25499
25500 @@ -220,7 +220,7 @@ void gf128mul_bbe(be128 *r, const be128
25501 for (i = 0; i < 7; ++i)
25502 gf128mul_x_bbe(&p[i + 1], &p[i]);
25503
25504 - memset(r, 0, sizeof(r));
25505 + memset(r, 0, sizeof(*r));
25506 for (i = 0;;) {
25507 u8 ch = ((u8 *)b)[i];
25508
25509 diff -urNp linux-2.6.32.46/crypto/serpent.c linux-2.6.32.46/crypto/serpent.c
25510 --- linux-2.6.32.46/crypto/serpent.c 2011-03-27 14:31:47.000000000 -0400
25511 +++ linux-2.6.32.46/crypto/serpent.c 2011-08-18 23:59:56.000000000 -0400
25512 @@ -21,6 +21,7 @@
25513 #include <asm/byteorder.h>
25514 #include <linux/crypto.h>
25515 #include <linux/types.h>
25516 +#include <linux/sched.h>
25517
25518 /* Key is padded to the maximum of 256 bits before round key generation.
25519 * Any key length <= 256 bits (32 bytes) is allowed by the algorithm.
25520 @@ -224,6 +225,8 @@ static int serpent_setkey(struct crypto_
25521 u32 r0,r1,r2,r3,r4;
25522 int i;
25523
25524 + pax_track_stack();
25525 +
25526 /* Copy key, add padding */
25527
25528 for (i = 0; i < keylen; ++i)
25529 diff -urNp linux-2.6.32.46/drivers/acpi/acpi_pad.c linux-2.6.32.46/drivers/acpi/acpi_pad.c
25530 --- linux-2.6.32.46/drivers/acpi/acpi_pad.c 2011-03-27 14:31:47.000000000 -0400
25531 +++ linux-2.6.32.46/drivers/acpi/acpi_pad.c 2011-04-17 15:56:46.000000000 -0400
25532 @@ -30,7 +30,7 @@
25533 #include <acpi/acpi_bus.h>
25534 #include <acpi/acpi_drivers.h>
25535
25536 -#define ACPI_PROCESSOR_AGGREGATOR_CLASS "processor_aggregator"
25537 +#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
25538 #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
25539 #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
25540 static DEFINE_MUTEX(isolated_cpus_lock);
25541 diff -urNp linux-2.6.32.46/drivers/acpi/battery.c linux-2.6.32.46/drivers/acpi/battery.c
25542 --- linux-2.6.32.46/drivers/acpi/battery.c 2011-03-27 14:31:47.000000000 -0400
25543 +++ linux-2.6.32.46/drivers/acpi/battery.c 2011-04-17 15:56:46.000000000 -0400
25544 @@ -763,7 +763,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
25545 }
25546
25547 static struct battery_file {
25548 - struct file_operations ops;
25549 + const struct file_operations ops;
25550 mode_t mode;
25551 const char *name;
25552 } acpi_battery_file[] = {
25553 diff -urNp linux-2.6.32.46/drivers/acpi/dock.c linux-2.6.32.46/drivers/acpi/dock.c
25554 --- linux-2.6.32.46/drivers/acpi/dock.c 2011-03-27 14:31:47.000000000 -0400
25555 +++ linux-2.6.32.46/drivers/acpi/dock.c 2011-04-17 15:56:46.000000000 -0400
25556 @@ -77,7 +77,7 @@ struct dock_dependent_device {
25557 struct list_head list;
25558 struct list_head hotplug_list;
25559 acpi_handle handle;
25560 - struct acpi_dock_ops *ops;
25561 + const struct acpi_dock_ops *ops;
25562 void *context;
25563 };
25564
25565 @@ -605,7 +605,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
25566 * the dock driver after _DCK is executed.
25567 */
25568 int
25569 -register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
25570 +register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
25571 void *context)
25572 {
25573 struct dock_dependent_device *dd;
25574 diff -urNp linux-2.6.32.46/drivers/acpi/osl.c linux-2.6.32.46/drivers/acpi/osl.c
25575 --- linux-2.6.32.46/drivers/acpi/osl.c 2011-03-27 14:31:47.000000000 -0400
25576 +++ linux-2.6.32.46/drivers/acpi/osl.c 2011-04-17 15:56:46.000000000 -0400
25577 @@ -523,6 +523,8 @@ acpi_os_read_memory(acpi_physical_addres
25578 void __iomem *virt_addr;
25579
25580 virt_addr = ioremap(phys_addr, width);
25581 + if (!virt_addr)
25582 + return AE_NO_MEMORY;
25583 if (!value)
25584 value = &dummy;
25585
25586 @@ -551,6 +553,8 @@ acpi_os_write_memory(acpi_physical_addre
25587 void __iomem *virt_addr;
25588
25589 virt_addr = ioremap(phys_addr, width);
25590 + if (!virt_addr)
25591 + return AE_NO_MEMORY;
25592
25593 switch (width) {
25594 case 8:
25595 diff -urNp linux-2.6.32.46/drivers/acpi/power_meter.c linux-2.6.32.46/drivers/acpi/power_meter.c
25596 --- linux-2.6.32.46/drivers/acpi/power_meter.c 2011-03-27 14:31:47.000000000 -0400
25597 +++ linux-2.6.32.46/drivers/acpi/power_meter.c 2011-04-17 15:56:46.000000000 -0400
25598 @@ -315,8 +315,6 @@ static ssize_t set_trip(struct device *d
25599 return res;
25600
25601 temp /= 1000;
25602 - if (temp < 0)
25603 - return -EINVAL;
25604
25605 mutex_lock(&resource->lock);
25606 resource->trip[attr->index - 7] = temp;
25607 diff -urNp linux-2.6.32.46/drivers/acpi/proc.c linux-2.6.32.46/drivers/acpi/proc.c
25608 --- linux-2.6.32.46/drivers/acpi/proc.c 2011-03-27 14:31:47.000000000 -0400
25609 +++ linux-2.6.32.46/drivers/acpi/proc.c 2011-04-17 15:56:46.000000000 -0400
25610 @@ -391,20 +391,15 @@ acpi_system_write_wakeup_device(struct f
25611 size_t count, loff_t * ppos)
25612 {
25613 struct list_head *node, *next;
25614 - char strbuf[5];
25615 - char str[5] = "";
25616 - unsigned int len = count;
25617 + char strbuf[5] = {0};
25618 struct acpi_device *found_dev = NULL;
25619
25620 - if (len > 4)
25621 - len = 4;
25622 - if (len < 0)
25623 - return -EFAULT;
25624 + if (count > 4)
25625 + count = 4;
25626
25627 - if (copy_from_user(strbuf, buffer, len))
25628 + if (copy_from_user(strbuf, buffer, count))
25629 return -EFAULT;
25630 - strbuf[len] = '\0';
25631 - sscanf(strbuf, "%s", str);
25632 + strbuf[count] = '\0';
25633
25634 mutex_lock(&acpi_device_lock);
25635 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
25636 @@ -413,7 +408,7 @@ acpi_system_write_wakeup_device(struct f
25637 if (!dev->wakeup.flags.valid)
25638 continue;
25639
25640 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
25641 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
25642 dev->wakeup.state.enabled =
25643 dev->wakeup.state.enabled ? 0 : 1;
25644 found_dev = dev;
25645 diff -urNp linux-2.6.32.46/drivers/acpi/processor_core.c linux-2.6.32.46/drivers/acpi/processor_core.c
25646 --- linux-2.6.32.46/drivers/acpi/processor_core.c 2011-03-27 14:31:47.000000000 -0400
25647 +++ linux-2.6.32.46/drivers/acpi/processor_core.c 2011-04-17 15:56:46.000000000 -0400
25648 @@ -790,7 +790,7 @@ static int __cpuinit acpi_processor_add(
25649 return 0;
25650 }
25651
25652 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
25653 + BUG_ON(pr->id >= nr_cpu_ids);
25654
25655 /*
25656 * Buggy BIOS check
25657 diff -urNp linux-2.6.32.46/drivers/acpi/sbshc.c linux-2.6.32.46/drivers/acpi/sbshc.c
25658 --- linux-2.6.32.46/drivers/acpi/sbshc.c 2011-03-27 14:31:47.000000000 -0400
25659 +++ linux-2.6.32.46/drivers/acpi/sbshc.c 2011-04-17 15:56:46.000000000 -0400
25660 @@ -17,7 +17,7 @@
25661
25662 #define PREFIX "ACPI: "
25663
25664 -#define ACPI_SMB_HC_CLASS "smbus_host_controller"
25665 +#define ACPI_SMB_HC_CLASS "smbus_host_ctl"
25666 #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC"
25667
25668 struct acpi_smb_hc {
25669 diff -urNp linux-2.6.32.46/drivers/acpi/sleep.c linux-2.6.32.46/drivers/acpi/sleep.c
25670 --- linux-2.6.32.46/drivers/acpi/sleep.c 2011-03-27 14:31:47.000000000 -0400
25671 +++ linux-2.6.32.46/drivers/acpi/sleep.c 2011-04-17 15:56:46.000000000 -0400
25672 @@ -283,7 +283,7 @@ static int acpi_suspend_state_valid(susp
25673 }
25674 }
25675
25676 -static struct platform_suspend_ops acpi_suspend_ops = {
25677 +static const struct platform_suspend_ops acpi_suspend_ops = {
25678 .valid = acpi_suspend_state_valid,
25679 .begin = acpi_suspend_begin,
25680 .prepare_late = acpi_pm_prepare,
25681 @@ -311,7 +311,7 @@ static int acpi_suspend_begin_old(suspen
25682 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
25683 * been requested.
25684 */
25685 -static struct platform_suspend_ops acpi_suspend_ops_old = {
25686 +static const struct platform_suspend_ops acpi_suspend_ops_old = {
25687 .valid = acpi_suspend_state_valid,
25688 .begin = acpi_suspend_begin_old,
25689 .prepare_late = acpi_pm_disable_gpes,
25690 @@ -460,7 +460,7 @@ static void acpi_pm_enable_gpes(void)
25691 acpi_enable_all_runtime_gpes();
25692 }
25693
25694 -static struct platform_hibernation_ops acpi_hibernation_ops = {
25695 +static const struct platform_hibernation_ops acpi_hibernation_ops = {
25696 .begin = acpi_hibernation_begin,
25697 .end = acpi_pm_end,
25698 .pre_snapshot = acpi_hibernation_pre_snapshot,
25699 @@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot
25700 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
25701 * been requested.
25702 */
25703 -static struct platform_hibernation_ops acpi_hibernation_ops_old = {
25704 +static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
25705 .begin = acpi_hibernation_begin_old,
25706 .end = acpi_pm_end,
25707 .pre_snapshot = acpi_hibernation_pre_snapshot_old,
25708 diff -urNp linux-2.6.32.46/drivers/acpi/video.c linux-2.6.32.46/drivers/acpi/video.c
25709 --- linux-2.6.32.46/drivers/acpi/video.c 2011-03-27 14:31:47.000000000 -0400
25710 +++ linux-2.6.32.46/drivers/acpi/video.c 2011-04-17 15:56:46.000000000 -0400
25711 @@ -359,7 +359,7 @@ static int acpi_video_set_brightness(str
25712 vd->brightness->levels[request_level]);
25713 }
25714
25715 -static struct backlight_ops acpi_backlight_ops = {
25716 +static const struct backlight_ops acpi_backlight_ops = {
25717 .get_brightness = acpi_video_get_brightness,
25718 .update_status = acpi_video_set_brightness,
25719 };
25720 diff -urNp linux-2.6.32.46/drivers/ata/ahci.c linux-2.6.32.46/drivers/ata/ahci.c
25721 --- linux-2.6.32.46/drivers/ata/ahci.c 2011-03-27 14:31:47.000000000 -0400
25722 +++ linux-2.6.32.46/drivers/ata/ahci.c 2011-04-23 12:56:10.000000000 -0400
25723 @@ -387,7 +387,7 @@ static struct scsi_host_template ahci_sh
25724 .sdev_attrs = ahci_sdev_attrs,
25725 };
25726
25727 -static struct ata_port_operations ahci_ops = {
25728 +static const struct ata_port_operations ahci_ops = {
25729 .inherits = &sata_pmp_port_ops,
25730
25731 .qc_defer = sata_pmp_qc_defer_cmd_switch,
25732 @@ -424,17 +424,17 @@ static struct ata_port_operations ahci_o
25733 .port_stop = ahci_port_stop,
25734 };
25735
25736 -static struct ata_port_operations ahci_vt8251_ops = {
25737 +static const struct ata_port_operations ahci_vt8251_ops = {
25738 .inherits = &ahci_ops,
25739 .hardreset = ahci_vt8251_hardreset,
25740 };
25741
25742 -static struct ata_port_operations ahci_p5wdh_ops = {
25743 +static const struct ata_port_operations ahci_p5wdh_ops = {
25744 .inherits = &ahci_ops,
25745 .hardreset = ahci_p5wdh_hardreset,
25746 };
25747
25748 -static struct ata_port_operations ahci_sb600_ops = {
25749 +static const struct ata_port_operations ahci_sb600_ops = {
25750 .inherits = &ahci_ops,
25751 .softreset = ahci_sb600_softreset,
25752 .pmp_softreset = ahci_sb600_softreset,
25753 diff -urNp linux-2.6.32.46/drivers/ata/ata_generic.c linux-2.6.32.46/drivers/ata/ata_generic.c
25754 --- linux-2.6.32.46/drivers/ata/ata_generic.c 2011-03-27 14:31:47.000000000 -0400
25755 +++ linux-2.6.32.46/drivers/ata/ata_generic.c 2011-04-17 15:56:46.000000000 -0400
25756 @@ -104,7 +104,7 @@ static struct scsi_host_template generic
25757 ATA_BMDMA_SHT(DRV_NAME),
25758 };
25759
25760 -static struct ata_port_operations generic_port_ops = {
25761 +static const struct ata_port_operations generic_port_ops = {
25762 .inherits = &ata_bmdma_port_ops,
25763 .cable_detect = ata_cable_unknown,
25764 .set_mode = generic_set_mode,
25765 diff -urNp linux-2.6.32.46/drivers/ata/ata_piix.c linux-2.6.32.46/drivers/ata/ata_piix.c
25766 --- linux-2.6.32.46/drivers/ata/ata_piix.c 2011-03-27 14:31:47.000000000 -0400
25767 +++ linux-2.6.32.46/drivers/ata/ata_piix.c 2011-04-23 12:56:10.000000000 -0400
25768 @@ -318,7 +318,7 @@ static struct scsi_host_template piix_sh
25769 ATA_BMDMA_SHT(DRV_NAME),
25770 };
25771
25772 -static struct ata_port_operations piix_pata_ops = {
25773 +static const struct ata_port_operations piix_pata_ops = {
25774 .inherits = &ata_bmdma32_port_ops,
25775 .cable_detect = ata_cable_40wire,
25776 .set_piomode = piix_set_piomode,
25777 @@ -326,22 +326,22 @@ static struct ata_port_operations piix_p
25778 .prereset = piix_pata_prereset,
25779 };
25780
25781 -static struct ata_port_operations piix_vmw_ops = {
25782 +static const struct ata_port_operations piix_vmw_ops = {
25783 .inherits = &piix_pata_ops,
25784 .bmdma_status = piix_vmw_bmdma_status,
25785 };
25786
25787 -static struct ata_port_operations ich_pata_ops = {
25788 +static const struct ata_port_operations ich_pata_ops = {
25789 .inherits = &piix_pata_ops,
25790 .cable_detect = ich_pata_cable_detect,
25791 .set_dmamode = ich_set_dmamode,
25792 };
25793
25794 -static struct ata_port_operations piix_sata_ops = {
25795 +static const struct ata_port_operations piix_sata_ops = {
25796 .inherits = &ata_bmdma_port_ops,
25797 };
25798
25799 -static struct ata_port_operations piix_sidpr_sata_ops = {
25800 +static const struct ata_port_operations piix_sidpr_sata_ops = {
25801 .inherits = &piix_sata_ops,
25802 .hardreset = sata_std_hardreset,
25803 .scr_read = piix_sidpr_scr_read,
25804 diff -urNp linux-2.6.32.46/drivers/ata/libata-acpi.c linux-2.6.32.46/drivers/ata/libata-acpi.c
25805 --- linux-2.6.32.46/drivers/ata/libata-acpi.c 2011-03-27 14:31:47.000000000 -0400
25806 +++ linux-2.6.32.46/drivers/ata/libata-acpi.c 2011-04-17 15:56:46.000000000 -0400
25807 @@ -223,12 +223,12 @@ static void ata_acpi_dev_uevent(acpi_han
25808 ata_acpi_uevent(dev->link->ap, dev, event);
25809 }
25810
25811 -static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
25812 +static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
25813 .handler = ata_acpi_dev_notify_dock,
25814 .uevent = ata_acpi_dev_uevent,
25815 };
25816
25817 -static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
25818 +static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
25819 .handler = ata_acpi_ap_notify_dock,
25820 .uevent = ata_acpi_ap_uevent,
25821 };
25822 diff -urNp linux-2.6.32.46/drivers/ata/libata-core.c linux-2.6.32.46/drivers/ata/libata-core.c
25823 --- linux-2.6.32.46/drivers/ata/libata-core.c 2011-03-27 14:31:47.000000000 -0400
25824 +++ linux-2.6.32.46/drivers/ata/libata-core.c 2011-08-05 20:33:55.000000000 -0400
25825 @@ -4954,7 +4954,7 @@ void ata_qc_free(struct ata_queued_cmd *
25826 struct ata_port *ap;
25827 unsigned int tag;
25828
25829 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25830 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25831 ap = qc->ap;
25832
25833 qc->flags = 0;
25834 @@ -4970,7 +4970,7 @@ void __ata_qc_complete(struct ata_queued
25835 struct ata_port *ap;
25836 struct ata_link *link;
25837
25838 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25839 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25840 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
25841 ap = qc->ap;
25842 link = qc->dev->link;
25843 @@ -5987,7 +5987,7 @@ static void ata_host_stop(struct device
25844 * LOCKING:
25845 * None.
25846 */
25847 -static void ata_finalize_port_ops(struct ata_port_operations *ops)
25848 +static void ata_finalize_port_ops(const struct ata_port_operations *ops)
25849 {
25850 static DEFINE_SPINLOCK(lock);
25851 const struct ata_port_operations *cur;
25852 @@ -5999,6 +5999,7 @@ static void ata_finalize_port_ops(struct
25853 return;
25854
25855 spin_lock(&lock);
25856 + pax_open_kernel();
25857
25858 for (cur = ops->inherits; cur; cur = cur->inherits) {
25859 void **inherit = (void **)cur;
25860 @@ -6012,8 +6013,9 @@ static void ata_finalize_port_ops(struct
25861 if (IS_ERR(*pp))
25862 *pp = NULL;
25863
25864 - ops->inherits = NULL;
25865 + *(struct ata_port_operations **)&ops->inherits = NULL;
25866
25867 + pax_close_kernel();
25868 spin_unlock(&lock);
25869 }
25870
25871 @@ -6110,7 +6112,7 @@ int ata_host_start(struct ata_host *host
25872 */
25873 /* KILLME - the only user left is ipr */
25874 void ata_host_init(struct ata_host *host, struct device *dev,
25875 - unsigned long flags, struct ata_port_operations *ops)
25876 + unsigned long flags, const struct ata_port_operations *ops)
25877 {
25878 spin_lock_init(&host->lock);
25879 host->dev = dev;
25880 @@ -6773,7 +6775,7 @@ static void ata_dummy_error_handler(stru
25881 /* truly dummy */
25882 }
25883
25884 -struct ata_port_operations ata_dummy_port_ops = {
25885 +const struct ata_port_operations ata_dummy_port_ops = {
25886 .qc_prep = ata_noop_qc_prep,
25887 .qc_issue = ata_dummy_qc_issue,
25888 .error_handler = ata_dummy_error_handler,
25889 diff -urNp linux-2.6.32.46/drivers/ata/libata-eh.c linux-2.6.32.46/drivers/ata/libata-eh.c
25890 --- linux-2.6.32.46/drivers/ata/libata-eh.c 2011-08-09 18:35:28.000000000 -0400
25891 +++ linux-2.6.32.46/drivers/ata/libata-eh.c 2011-08-09 18:33:59.000000000 -0400
25892 @@ -2423,6 +2423,8 @@ void ata_eh_report(struct ata_port *ap)
25893 {
25894 struct ata_link *link;
25895
25896 + pax_track_stack();
25897 +
25898 ata_for_each_link(link, ap, HOST_FIRST)
25899 ata_eh_link_report(link);
25900 }
25901 @@ -3594,7 +3596,7 @@ void ata_do_eh(struct ata_port *ap, ata_
25902 */
25903 void ata_std_error_handler(struct ata_port *ap)
25904 {
25905 - struct ata_port_operations *ops = ap->ops;
25906 + const struct ata_port_operations *ops = ap->ops;
25907 ata_reset_fn_t hardreset = ops->hardreset;
25908
25909 /* ignore built-in hardreset if SCR access is not available */
25910 diff -urNp linux-2.6.32.46/drivers/ata/libata-pmp.c linux-2.6.32.46/drivers/ata/libata-pmp.c
25911 --- linux-2.6.32.46/drivers/ata/libata-pmp.c 2011-03-27 14:31:47.000000000 -0400
25912 +++ linux-2.6.32.46/drivers/ata/libata-pmp.c 2011-04-17 15:56:46.000000000 -0400
25913 @@ -841,7 +841,7 @@ static int sata_pmp_handle_link_fail(str
25914 */
25915 static int sata_pmp_eh_recover(struct ata_port *ap)
25916 {
25917 - struct ata_port_operations *ops = ap->ops;
25918 + const struct ata_port_operations *ops = ap->ops;
25919 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
25920 struct ata_link *pmp_link = &ap->link;
25921 struct ata_device *pmp_dev = pmp_link->device;
25922 diff -urNp linux-2.6.32.46/drivers/ata/pata_acpi.c linux-2.6.32.46/drivers/ata/pata_acpi.c
25923 --- linux-2.6.32.46/drivers/ata/pata_acpi.c 2011-03-27 14:31:47.000000000 -0400
25924 +++ linux-2.6.32.46/drivers/ata/pata_acpi.c 2011-04-17 15:56:46.000000000 -0400
25925 @@ -215,7 +215,7 @@ static struct scsi_host_template pacpi_s
25926 ATA_BMDMA_SHT(DRV_NAME),
25927 };
25928
25929 -static struct ata_port_operations pacpi_ops = {
25930 +static const struct ata_port_operations pacpi_ops = {
25931 .inherits = &ata_bmdma_port_ops,
25932 .qc_issue = pacpi_qc_issue,
25933 .cable_detect = pacpi_cable_detect,
25934 diff -urNp linux-2.6.32.46/drivers/ata/pata_ali.c linux-2.6.32.46/drivers/ata/pata_ali.c
25935 --- linux-2.6.32.46/drivers/ata/pata_ali.c 2011-03-27 14:31:47.000000000 -0400
25936 +++ linux-2.6.32.46/drivers/ata/pata_ali.c 2011-04-17 15:56:46.000000000 -0400
25937 @@ -365,7 +365,7 @@ static struct scsi_host_template ali_sht
25938 * Port operations for PIO only ALi
25939 */
25940
25941 -static struct ata_port_operations ali_early_port_ops = {
25942 +static const struct ata_port_operations ali_early_port_ops = {
25943 .inherits = &ata_sff_port_ops,
25944 .cable_detect = ata_cable_40wire,
25945 .set_piomode = ali_set_piomode,
25946 @@ -382,7 +382,7 @@ static const struct ata_port_operations
25947 * Port operations for DMA capable ALi without cable
25948 * detect
25949 */
25950 -static struct ata_port_operations ali_20_port_ops = {
25951 +static const struct ata_port_operations ali_20_port_ops = {
25952 .inherits = &ali_dma_base_ops,
25953 .cable_detect = ata_cable_40wire,
25954 .mode_filter = ali_20_filter,
25955 @@ -393,7 +393,7 @@ static struct ata_port_operations ali_20
25956 /*
25957 * Port operations for DMA capable ALi with cable detect
25958 */
25959 -static struct ata_port_operations ali_c2_port_ops = {
25960 +static const struct ata_port_operations ali_c2_port_ops = {
25961 .inherits = &ali_dma_base_ops,
25962 .check_atapi_dma = ali_check_atapi_dma,
25963 .cable_detect = ali_c2_cable_detect,
25964 @@ -404,7 +404,7 @@ static struct ata_port_operations ali_c2
25965 /*
25966 * Port operations for DMA capable ALi with cable detect
25967 */
25968 -static struct ata_port_operations ali_c4_port_ops = {
25969 +static const struct ata_port_operations ali_c4_port_ops = {
25970 .inherits = &ali_dma_base_ops,
25971 .check_atapi_dma = ali_check_atapi_dma,
25972 .cable_detect = ali_c2_cable_detect,
25973 @@ -414,7 +414,7 @@ static struct ata_port_operations ali_c4
25974 /*
25975 * Port operations for DMA capable ALi with cable detect and LBA48
25976 */
25977 -static struct ata_port_operations ali_c5_port_ops = {
25978 +static const struct ata_port_operations ali_c5_port_ops = {
25979 .inherits = &ali_dma_base_ops,
25980 .check_atapi_dma = ali_check_atapi_dma,
25981 .dev_config = ali_warn_atapi_dma,
25982 diff -urNp linux-2.6.32.46/drivers/ata/pata_amd.c linux-2.6.32.46/drivers/ata/pata_amd.c
25983 --- linux-2.6.32.46/drivers/ata/pata_amd.c 2011-03-27 14:31:47.000000000 -0400
25984 +++ linux-2.6.32.46/drivers/ata/pata_amd.c 2011-04-17 15:56:46.000000000 -0400
25985 @@ -397,28 +397,28 @@ static const struct ata_port_operations
25986 .prereset = amd_pre_reset,
25987 };
25988
25989 -static struct ata_port_operations amd33_port_ops = {
25990 +static const struct ata_port_operations amd33_port_ops = {
25991 .inherits = &amd_base_port_ops,
25992 .cable_detect = ata_cable_40wire,
25993 .set_piomode = amd33_set_piomode,
25994 .set_dmamode = amd33_set_dmamode,
25995 };
25996
25997 -static struct ata_port_operations amd66_port_ops = {
25998 +static const struct ata_port_operations amd66_port_ops = {
25999 .inherits = &amd_base_port_ops,
26000 .cable_detect = ata_cable_unknown,
26001 .set_piomode = amd66_set_piomode,
26002 .set_dmamode = amd66_set_dmamode,
26003 };
26004
26005 -static struct ata_port_operations amd100_port_ops = {
26006 +static const struct ata_port_operations amd100_port_ops = {
26007 .inherits = &amd_base_port_ops,
26008 .cable_detect = ata_cable_unknown,
26009 .set_piomode = amd100_set_piomode,
26010 .set_dmamode = amd100_set_dmamode,
26011 };
26012
26013 -static struct ata_port_operations amd133_port_ops = {
26014 +static const struct ata_port_operations amd133_port_ops = {
26015 .inherits = &amd_base_port_ops,
26016 .cable_detect = amd_cable_detect,
26017 .set_piomode = amd133_set_piomode,
26018 @@ -433,13 +433,13 @@ static const struct ata_port_operations
26019 .host_stop = nv_host_stop,
26020 };
26021
26022 -static struct ata_port_operations nv100_port_ops = {
26023 +static const struct ata_port_operations nv100_port_ops = {
26024 .inherits = &nv_base_port_ops,
26025 .set_piomode = nv100_set_piomode,
26026 .set_dmamode = nv100_set_dmamode,
26027 };
26028
26029 -static struct ata_port_operations nv133_port_ops = {
26030 +static const struct ata_port_operations nv133_port_ops = {
26031 .inherits = &nv_base_port_ops,
26032 .set_piomode = nv133_set_piomode,
26033 .set_dmamode = nv133_set_dmamode,
26034 diff -urNp linux-2.6.32.46/drivers/ata/pata_artop.c linux-2.6.32.46/drivers/ata/pata_artop.c
26035 --- linux-2.6.32.46/drivers/ata/pata_artop.c 2011-03-27 14:31:47.000000000 -0400
26036 +++ linux-2.6.32.46/drivers/ata/pata_artop.c 2011-04-17 15:56:46.000000000 -0400
26037 @@ -311,7 +311,7 @@ static struct scsi_host_template artop_s
26038 ATA_BMDMA_SHT(DRV_NAME),
26039 };
26040
26041 -static struct ata_port_operations artop6210_ops = {
26042 +static const struct ata_port_operations artop6210_ops = {
26043 .inherits = &ata_bmdma_port_ops,
26044 .cable_detect = ata_cable_40wire,
26045 .set_piomode = artop6210_set_piomode,
26046 @@ -320,7 +320,7 @@ static struct ata_port_operations artop6
26047 .qc_defer = artop6210_qc_defer,
26048 };
26049
26050 -static struct ata_port_operations artop6260_ops = {
26051 +static const struct ata_port_operations artop6260_ops = {
26052 .inherits = &ata_bmdma_port_ops,
26053 .cable_detect = artop6260_cable_detect,
26054 .set_piomode = artop6260_set_piomode,
26055 diff -urNp linux-2.6.32.46/drivers/ata/pata_at32.c linux-2.6.32.46/drivers/ata/pata_at32.c
26056 --- linux-2.6.32.46/drivers/ata/pata_at32.c 2011-03-27 14:31:47.000000000 -0400
26057 +++ linux-2.6.32.46/drivers/ata/pata_at32.c 2011-04-17 15:56:46.000000000 -0400
26058 @@ -172,7 +172,7 @@ static struct scsi_host_template at32_sh
26059 ATA_PIO_SHT(DRV_NAME),
26060 };
26061
26062 -static struct ata_port_operations at32_port_ops = {
26063 +static const struct ata_port_operations at32_port_ops = {
26064 .inherits = &ata_sff_port_ops,
26065 .cable_detect = ata_cable_40wire,
26066 .set_piomode = pata_at32_set_piomode,
26067 diff -urNp linux-2.6.32.46/drivers/ata/pata_at91.c linux-2.6.32.46/drivers/ata/pata_at91.c
26068 --- linux-2.6.32.46/drivers/ata/pata_at91.c 2011-03-27 14:31:47.000000000 -0400
26069 +++ linux-2.6.32.46/drivers/ata/pata_at91.c 2011-04-17 15:56:46.000000000 -0400
26070 @@ -195,7 +195,7 @@ static struct scsi_host_template pata_at
26071 ATA_PIO_SHT(DRV_NAME),
26072 };
26073
26074 -static struct ata_port_operations pata_at91_port_ops = {
26075 +static const struct ata_port_operations pata_at91_port_ops = {
26076 .inherits = &ata_sff_port_ops,
26077
26078 .sff_data_xfer = pata_at91_data_xfer_noirq,
26079 diff -urNp linux-2.6.32.46/drivers/ata/pata_atiixp.c linux-2.6.32.46/drivers/ata/pata_atiixp.c
26080 --- linux-2.6.32.46/drivers/ata/pata_atiixp.c 2011-03-27 14:31:47.000000000 -0400
26081 +++ linux-2.6.32.46/drivers/ata/pata_atiixp.c 2011-04-17 15:56:46.000000000 -0400
26082 @@ -205,7 +205,7 @@ static struct scsi_host_template atiixp_
26083 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
26084 };
26085
26086 -static struct ata_port_operations atiixp_port_ops = {
26087 +static const struct ata_port_operations atiixp_port_ops = {
26088 .inherits = &ata_bmdma_port_ops,
26089
26090 .qc_prep = ata_sff_dumb_qc_prep,
26091 diff -urNp linux-2.6.32.46/drivers/ata/pata_atp867x.c linux-2.6.32.46/drivers/ata/pata_atp867x.c
26092 --- linux-2.6.32.46/drivers/ata/pata_atp867x.c 2011-03-27 14:31:47.000000000 -0400
26093 +++ linux-2.6.32.46/drivers/ata/pata_atp867x.c 2011-04-17 15:56:46.000000000 -0400
26094 @@ -274,7 +274,7 @@ static struct scsi_host_template atp867x
26095 ATA_BMDMA_SHT(DRV_NAME),
26096 };
26097
26098 -static struct ata_port_operations atp867x_ops = {
26099 +static const struct ata_port_operations atp867x_ops = {
26100 .inherits = &ata_bmdma_port_ops,
26101 .cable_detect = atp867x_cable_detect,
26102 .set_piomode = atp867x_set_piomode,
26103 diff -urNp linux-2.6.32.46/drivers/ata/pata_bf54x.c linux-2.6.32.46/drivers/ata/pata_bf54x.c
26104 --- linux-2.6.32.46/drivers/ata/pata_bf54x.c 2011-03-27 14:31:47.000000000 -0400
26105 +++ linux-2.6.32.46/drivers/ata/pata_bf54x.c 2011-04-17 15:56:46.000000000 -0400
26106 @@ -1464,7 +1464,7 @@ static struct scsi_host_template bfin_sh
26107 .dma_boundary = ATA_DMA_BOUNDARY,
26108 };
26109
26110 -static struct ata_port_operations bfin_pata_ops = {
26111 +static const struct ata_port_operations bfin_pata_ops = {
26112 .inherits = &ata_sff_port_ops,
26113
26114 .set_piomode = bfin_set_piomode,
26115 diff -urNp linux-2.6.32.46/drivers/ata/pata_cmd640.c linux-2.6.32.46/drivers/ata/pata_cmd640.c
26116 --- linux-2.6.32.46/drivers/ata/pata_cmd640.c 2011-03-27 14:31:47.000000000 -0400
26117 +++ linux-2.6.32.46/drivers/ata/pata_cmd640.c 2011-04-17 15:56:46.000000000 -0400
26118 @@ -168,7 +168,7 @@ static struct scsi_host_template cmd640_
26119 ATA_BMDMA_SHT(DRV_NAME),
26120 };
26121
26122 -static struct ata_port_operations cmd640_port_ops = {
26123 +static const struct ata_port_operations cmd640_port_ops = {
26124 .inherits = &ata_bmdma_port_ops,
26125 /* In theory xfer_noirq is not needed once we kill the prefetcher */
26126 .sff_data_xfer = ata_sff_data_xfer_noirq,
26127 diff -urNp linux-2.6.32.46/drivers/ata/pata_cmd64x.c linux-2.6.32.46/drivers/ata/pata_cmd64x.c
26128 --- linux-2.6.32.46/drivers/ata/pata_cmd64x.c 2011-06-25 12:55:34.000000000 -0400
26129 +++ linux-2.6.32.46/drivers/ata/pata_cmd64x.c 2011-06-25 12:56:37.000000000 -0400
26130 @@ -271,18 +271,18 @@ static const struct ata_port_operations
26131 .set_dmamode = cmd64x_set_dmamode,
26132 };
26133
26134 -static struct ata_port_operations cmd64x_port_ops = {
26135 +static const struct ata_port_operations cmd64x_port_ops = {
26136 .inherits = &cmd64x_base_ops,
26137 .cable_detect = ata_cable_40wire,
26138 };
26139
26140 -static struct ata_port_operations cmd646r1_port_ops = {
26141 +static const struct ata_port_operations cmd646r1_port_ops = {
26142 .inherits = &cmd64x_base_ops,
26143 .bmdma_stop = cmd646r1_bmdma_stop,
26144 .cable_detect = ata_cable_40wire,
26145 };
26146
26147 -static struct ata_port_operations cmd648_port_ops = {
26148 +static const struct ata_port_operations cmd648_port_ops = {
26149 .inherits = &cmd64x_base_ops,
26150 .bmdma_stop = cmd648_bmdma_stop,
26151 .cable_detect = cmd648_cable_detect,
26152 diff -urNp linux-2.6.32.46/drivers/ata/pata_cs5520.c linux-2.6.32.46/drivers/ata/pata_cs5520.c
26153 --- linux-2.6.32.46/drivers/ata/pata_cs5520.c 2011-03-27 14:31:47.000000000 -0400
26154 +++ linux-2.6.32.46/drivers/ata/pata_cs5520.c 2011-04-17 15:56:46.000000000 -0400
26155 @@ -144,7 +144,7 @@ static struct scsi_host_template cs5520_
26156 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
26157 };
26158
26159 -static struct ata_port_operations cs5520_port_ops = {
26160 +static const struct ata_port_operations cs5520_port_ops = {
26161 .inherits = &ata_bmdma_port_ops,
26162 .qc_prep = ata_sff_dumb_qc_prep,
26163 .cable_detect = ata_cable_40wire,
26164 diff -urNp linux-2.6.32.46/drivers/ata/pata_cs5530.c linux-2.6.32.46/drivers/ata/pata_cs5530.c
26165 --- linux-2.6.32.46/drivers/ata/pata_cs5530.c 2011-03-27 14:31:47.000000000 -0400
26166 +++ linux-2.6.32.46/drivers/ata/pata_cs5530.c 2011-04-17 15:56:46.000000000 -0400
26167 @@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
26168 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
26169 };
26170
26171 -static struct ata_port_operations cs5530_port_ops = {
26172 +static const struct ata_port_operations cs5530_port_ops = {
26173 .inherits = &ata_bmdma_port_ops,
26174
26175 .qc_prep = ata_sff_dumb_qc_prep,
26176 diff -urNp linux-2.6.32.46/drivers/ata/pata_cs5535.c linux-2.6.32.46/drivers/ata/pata_cs5535.c
26177 --- linux-2.6.32.46/drivers/ata/pata_cs5535.c 2011-03-27 14:31:47.000000000 -0400
26178 +++ linux-2.6.32.46/drivers/ata/pata_cs5535.c 2011-04-17 15:56:46.000000000 -0400
26179 @@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
26180 ATA_BMDMA_SHT(DRV_NAME),
26181 };
26182
26183 -static struct ata_port_operations cs5535_port_ops = {
26184 +static const struct ata_port_operations cs5535_port_ops = {
26185 .inherits = &ata_bmdma_port_ops,
26186 .cable_detect = cs5535_cable_detect,
26187 .set_piomode = cs5535_set_piomode,
26188 diff -urNp linux-2.6.32.46/drivers/ata/pata_cs5536.c linux-2.6.32.46/drivers/ata/pata_cs5536.c
26189 --- linux-2.6.32.46/drivers/ata/pata_cs5536.c 2011-03-27 14:31:47.000000000 -0400
26190 +++ linux-2.6.32.46/drivers/ata/pata_cs5536.c 2011-04-17 15:56:46.000000000 -0400
26191 @@ -223,7 +223,7 @@ static struct scsi_host_template cs5536_
26192 ATA_BMDMA_SHT(DRV_NAME),
26193 };
26194
26195 -static struct ata_port_operations cs5536_port_ops = {
26196 +static const struct ata_port_operations cs5536_port_ops = {
26197 .inherits = &ata_bmdma_port_ops,
26198 .cable_detect = cs5536_cable_detect,
26199 .set_piomode = cs5536_set_piomode,
26200 diff -urNp linux-2.6.32.46/drivers/ata/pata_cypress.c linux-2.6.32.46/drivers/ata/pata_cypress.c
26201 --- linux-2.6.32.46/drivers/ata/pata_cypress.c 2011-03-27 14:31:47.000000000 -0400
26202 +++ linux-2.6.32.46/drivers/ata/pata_cypress.c 2011-04-17 15:56:46.000000000 -0400
26203 @@ -113,7 +113,7 @@ static struct scsi_host_template cy82c69
26204 ATA_BMDMA_SHT(DRV_NAME),
26205 };
26206
26207 -static struct ata_port_operations cy82c693_port_ops = {
26208 +static const struct ata_port_operations cy82c693_port_ops = {
26209 .inherits = &ata_bmdma_port_ops,
26210 .cable_detect = ata_cable_40wire,
26211 .set_piomode = cy82c693_set_piomode,
26212 diff -urNp linux-2.6.32.46/drivers/ata/pata_efar.c linux-2.6.32.46/drivers/ata/pata_efar.c
26213 --- linux-2.6.32.46/drivers/ata/pata_efar.c 2011-03-27 14:31:47.000000000 -0400
26214 +++ linux-2.6.32.46/drivers/ata/pata_efar.c 2011-04-17 15:56:46.000000000 -0400
26215 @@ -222,7 +222,7 @@ static struct scsi_host_template efar_sh
26216 ATA_BMDMA_SHT(DRV_NAME),
26217 };
26218
26219 -static struct ata_port_operations efar_ops = {
26220 +static const struct ata_port_operations efar_ops = {
26221 .inherits = &ata_bmdma_port_ops,
26222 .cable_detect = efar_cable_detect,
26223 .set_piomode = efar_set_piomode,
26224 diff -urNp linux-2.6.32.46/drivers/ata/pata_hpt366.c linux-2.6.32.46/drivers/ata/pata_hpt366.c
26225 --- linux-2.6.32.46/drivers/ata/pata_hpt366.c 2011-06-25 12:55:34.000000000 -0400
26226 +++ linux-2.6.32.46/drivers/ata/pata_hpt366.c 2011-06-25 12:56:37.000000000 -0400
26227 @@ -282,7 +282,7 @@ static struct scsi_host_template hpt36x_
26228 * Configuration for HPT366/68
26229 */
26230
26231 -static struct ata_port_operations hpt366_port_ops = {
26232 +static const struct ata_port_operations hpt366_port_ops = {
26233 .inherits = &ata_bmdma_port_ops,
26234 .cable_detect = hpt36x_cable_detect,
26235 .mode_filter = hpt366_filter,
26236 diff -urNp linux-2.6.32.46/drivers/ata/pata_hpt37x.c linux-2.6.32.46/drivers/ata/pata_hpt37x.c
26237 --- linux-2.6.32.46/drivers/ata/pata_hpt37x.c 2011-06-25 12:55:34.000000000 -0400
26238 +++ linux-2.6.32.46/drivers/ata/pata_hpt37x.c 2011-06-25 12:56:37.000000000 -0400
26239 @@ -576,7 +576,7 @@ static struct scsi_host_template hpt37x_
26240 * Configuration for HPT370
26241 */
26242
26243 -static struct ata_port_operations hpt370_port_ops = {
26244 +static const struct ata_port_operations hpt370_port_ops = {
26245 .inherits = &ata_bmdma_port_ops,
26246
26247 .bmdma_stop = hpt370_bmdma_stop,
26248 @@ -591,7 +591,7 @@ static struct ata_port_operations hpt370
26249 * Configuration for HPT370A. Close to 370 but less filters
26250 */
26251
26252 -static struct ata_port_operations hpt370a_port_ops = {
26253 +static const struct ata_port_operations hpt370a_port_ops = {
26254 .inherits = &hpt370_port_ops,
26255 .mode_filter = hpt370a_filter,
26256 };
26257 @@ -601,7 +601,7 @@ static struct ata_port_operations hpt370
26258 * and DMA mode setting functionality.
26259 */
26260
26261 -static struct ata_port_operations hpt372_port_ops = {
26262 +static const struct ata_port_operations hpt372_port_ops = {
26263 .inherits = &ata_bmdma_port_ops,
26264
26265 .bmdma_stop = hpt37x_bmdma_stop,
26266 @@ -616,7 +616,7 @@ static struct ata_port_operations hpt372
26267 * but we have a different cable detection procedure for function 1.
26268 */
26269
26270 -static struct ata_port_operations hpt374_fn1_port_ops = {
26271 +static const struct ata_port_operations hpt374_fn1_port_ops = {
26272 .inherits = &hpt372_port_ops,
26273 .prereset = hpt374_fn1_pre_reset,
26274 };
26275 diff -urNp linux-2.6.32.46/drivers/ata/pata_hpt3x2n.c linux-2.6.32.46/drivers/ata/pata_hpt3x2n.c
26276 --- linux-2.6.32.46/drivers/ata/pata_hpt3x2n.c 2011-06-25 12:55:34.000000000 -0400
26277 +++ linux-2.6.32.46/drivers/ata/pata_hpt3x2n.c 2011-06-25 12:56:37.000000000 -0400
26278 @@ -337,7 +337,7 @@ static struct scsi_host_template hpt3x2n
26279 * Configuration for HPT3x2n.
26280 */
26281
26282 -static struct ata_port_operations hpt3x2n_port_ops = {
26283 +static const struct ata_port_operations hpt3x2n_port_ops = {
26284 .inherits = &ata_bmdma_port_ops,
26285
26286 .bmdma_stop = hpt3x2n_bmdma_stop,
26287 diff -urNp linux-2.6.32.46/drivers/ata/pata_hpt3x3.c linux-2.6.32.46/drivers/ata/pata_hpt3x3.c
26288 --- linux-2.6.32.46/drivers/ata/pata_hpt3x3.c 2011-03-27 14:31:47.000000000 -0400
26289 +++ linux-2.6.32.46/drivers/ata/pata_hpt3x3.c 2011-04-17 15:56:46.000000000 -0400
26290 @@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
26291 ATA_BMDMA_SHT(DRV_NAME),
26292 };
26293
26294 -static struct ata_port_operations hpt3x3_port_ops = {
26295 +static const struct ata_port_operations hpt3x3_port_ops = {
26296 .inherits = &ata_bmdma_port_ops,
26297 .cable_detect = ata_cable_40wire,
26298 .set_piomode = hpt3x3_set_piomode,
26299 diff -urNp linux-2.6.32.46/drivers/ata/pata_icside.c linux-2.6.32.46/drivers/ata/pata_icside.c
26300 --- linux-2.6.32.46/drivers/ata/pata_icside.c 2011-03-27 14:31:47.000000000 -0400
26301 +++ linux-2.6.32.46/drivers/ata/pata_icside.c 2011-04-17 15:56:46.000000000 -0400
26302 @@ -319,7 +319,7 @@ static void pata_icside_postreset(struct
26303 }
26304 }
26305
26306 -static struct ata_port_operations pata_icside_port_ops = {
26307 +static const struct ata_port_operations pata_icside_port_ops = {
26308 .inherits = &ata_sff_port_ops,
26309 /* no need to build any PRD tables for DMA */
26310 .qc_prep = ata_noop_qc_prep,
26311 diff -urNp linux-2.6.32.46/drivers/ata/pata_isapnp.c linux-2.6.32.46/drivers/ata/pata_isapnp.c
26312 --- linux-2.6.32.46/drivers/ata/pata_isapnp.c 2011-03-27 14:31:47.000000000 -0400
26313 +++ linux-2.6.32.46/drivers/ata/pata_isapnp.c 2011-04-17 15:56:46.000000000 -0400
26314 @@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
26315 ATA_PIO_SHT(DRV_NAME),
26316 };
26317
26318 -static struct ata_port_operations isapnp_port_ops = {
26319 +static const struct ata_port_operations isapnp_port_ops = {
26320 .inherits = &ata_sff_port_ops,
26321 .cable_detect = ata_cable_40wire,
26322 };
26323
26324 -static struct ata_port_operations isapnp_noalt_port_ops = {
26325 +static const struct ata_port_operations isapnp_noalt_port_ops = {
26326 .inherits = &ata_sff_port_ops,
26327 .cable_detect = ata_cable_40wire,
26328 /* No altstatus so we don't want to use the lost interrupt poll */
26329 diff -urNp linux-2.6.32.46/drivers/ata/pata_it8213.c linux-2.6.32.46/drivers/ata/pata_it8213.c
26330 --- linux-2.6.32.46/drivers/ata/pata_it8213.c 2011-03-27 14:31:47.000000000 -0400
26331 +++ linux-2.6.32.46/drivers/ata/pata_it8213.c 2011-04-17 15:56:46.000000000 -0400
26332 @@ -234,7 +234,7 @@ static struct scsi_host_template it8213_
26333 };
26334
26335
26336 -static struct ata_port_operations it8213_ops = {
26337 +static const struct ata_port_operations it8213_ops = {
26338 .inherits = &ata_bmdma_port_ops,
26339 .cable_detect = it8213_cable_detect,
26340 .set_piomode = it8213_set_piomode,
26341 diff -urNp linux-2.6.32.46/drivers/ata/pata_it821x.c linux-2.6.32.46/drivers/ata/pata_it821x.c
26342 --- linux-2.6.32.46/drivers/ata/pata_it821x.c 2011-03-27 14:31:47.000000000 -0400
26343 +++ linux-2.6.32.46/drivers/ata/pata_it821x.c 2011-04-17 15:56:46.000000000 -0400
26344 @@ -800,7 +800,7 @@ static struct scsi_host_template it821x_
26345 ATA_BMDMA_SHT(DRV_NAME),
26346 };
26347
26348 -static struct ata_port_operations it821x_smart_port_ops = {
26349 +static const struct ata_port_operations it821x_smart_port_ops = {
26350 .inherits = &ata_bmdma_port_ops,
26351
26352 .check_atapi_dma= it821x_check_atapi_dma,
26353 @@ -814,7 +814,7 @@ static struct ata_port_operations it821x
26354 .port_start = it821x_port_start,
26355 };
26356
26357 -static struct ata_port_operations it821x_passthru_port_ops = {
26358 +static const struct ata_port_operations it821x_passthru_port_ops = {
26359 .inherits = &ata_bmdma_port_ops,
26360
26361 .check_atapi_dma= it821x_check_atapi_dma,
26362 @@ -830,7 +830,7 @@ static struct ata_port_operations it821x
26363 .port_start = it821x_port_start,
26364 };
26365
26366 -static struct ata_port_operations it821x_rdc_port_ops = {
26367 +static const struct ata_port_operations it821x_rdc_port_ops = {
26368 .inherits = &ata_bmdma_port_ops,
26369
26370 .check_atapi_dma= it821x_check_atapi_dma,
26371 diff -urNp linux-2.6.32.46/drivers/ata/pata_ixp4xx_cf.c linux-2.6.32.46/drivers/ata/pata_ixp4xx_cf.c
26372 --- linux-2.6.32.46/drivers/ata/pata_ixp4xx_cf.c 2011-03-27 14:31:47.000000000 -0400
26373 +++ linux-2.6.32.46/drivers/ata/pata_ixp4xx_cf.c 2011-04-17 15:56:46.000000000 -0400
26374 @@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
26375 ATA_PIO_SHT(DRV_NAME),
26376 };
26377
26378 -static struct ata_port_operations ixp4xx_port_ops = {
26379 +static const struct ata_port_operations ixp4xx_port_ops = {
26380 .inherits = &ata_sff_port_ops,
26381 .sff_data_xfer = ixp4xx_mmio_data_xfer,
26382 .cable_detect = ata_cable_40wire,
26383 diff -urNp linux-2.6.32.46/drivers/ata/pata_jmicron.c linux-2.6.32.46/drivers/ata/pata_jmicron.c
26384 --- linux-2.6.32.46/drivers/ata/pata_jmicron.c 2011-03-27 14:31:47.000000000 -0400
26385 +++ linux-2.6.32.46/drivers/ata/pata_jmicron.c 2011-04-17 15:56:46.000000000 -0400
26386 @@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
26387 ATA_BMDMA_SHT(DRV_NAME),
26388 };
26389
26390 -static struct ata_port_operations jmicron_ops = {
26391 +static const struct ata_port_operations jmicron_ops = {
26392 .inherits = &ata_bmdma_port_ops,
26393 .prereset = jmicron_pre_reset,
26394 };
26395 diff -urNp linux-2.6.32.46/drivers/ata/pata_legacy.c linux-2.6.32.46/drivers/ata/pata_legacy.c
26396 --- linux-2.6.32.46/drivers/ata/pata_legacy.c 2011-03-27 14:31:47.000000000 -0400
26397 +++ linux-2.6.32.46/drivers/ata/pata_legacy.c 2011-04-17 15:56:46.000000000 -0400
26398 @@ -106,7 +106,7 @@ struct legacy_probe {
26399
26400 struct legacy_controller {
26401 const char *name;
26402 - struct ata_port_operations *ops;
26403 + const struct ata_port_operations *ops;
26404 unsigned int pio_mask;
26405 unsigned int flags;
26406 unsigned int pflags;
26407 @@ -223,12 +223,12 @@ static const struct ata_port_operations
26408 * pio_mask as well.
26409 */
26410
26411 -static struct ata_port_operations simple_port_ops = {
26412 +static const struct ata_port_operations simple_port_ops = {
26413 .inherits = &legacy_base_port_ops,
26414 .sff_data_xfer = ata_sff_data_xfer_noirq,
26415 };
26416
26417 -static struct ata_port_operations legacy_port_ops = {
26418 +static const struct ata_port_operations legacy_port_ops = {
26419 .inherits = &legacy_base_port_ops,
26420 .sff_data_xfer = ata_sff_data_xfer_noirq,
26421 .set_mode = legacy_set_mode,
26422 @@ -324,7 +324,7 @@ static unsigned int pdc_data_xfer_vlb(st
26423 return buflen;
26424 }
26425
26426 -static struct ata_port_operations pdc20230_port_ops = {
26427 +static const struct ata_port_operations pdc20230_port_ops = {
26428 .inherits = &legacy_base_port_ops,
26429 .set_piomode = pdc20230_set_piomode,
26430 .sff_data_xfer = pdc_data_xfer_vlb,
26431 @@ -357,7 +357,7 @@ static void ht6560a_set_piomode(struct a
26432 ioread8(ap->ioaddr.status_addr);
26433 }
26434
26435 -static struct ata_port_operations ht6560a_port_ops = {
26436 +static const struct ata_port_operations ht6560a_port_ops = {
26437 .inherits = &legacy_base_port_ops,
26438 .set_piomode = ht6560a_set_piomode,
26439 };
26440 @@ -400,7 +400,7 @@ static void ht6560b_set_piomode(struct a
26441 ioread8(ap->ioaddr.status_addr);
26442 }
26443
26444 -static struct ata_port_operations ht6560b_port_ops = {
26445 +static const struct ata_port_operations ht6560b_port_ops = {
26446 .inherits = &legacy_base_port_ops,
26447 .set_piomode = ht6560b_set_piomode,
26448 };
26449 @@ -499,7 +499,7 @@ static void opti82c611a_set_piomode(stru
26450 }
26451
26452
26453 -static struct ata_port_operations opti82c611a_port_ops = {
26454 +static const struct ata_port_operations opti82c611a_port_ops = {
26455 .inherits = &legacy_base_port_ops,
26456 .set_piomode = opti82c611a_set_piomode,
26457 };
26458 @@ -609,7 +609,7 @@ static unsigned int opti82c46x_qc_issue(
26459 return ata_sff_qc_issue(qc);
26460 }
26461
26462 -static struct ata_port_operations opti82c46x_port_ops = {
26463 +static const struct ata_port_operations opti82c46x_port_ops = {
26464 .inherits = &legacy_base_port_ops,
26465 .set_piomode = opti82c46x_set_piomode,
26466 .qc_issue = opti82c46x_qc_issue,
26467 @@ -771,20 +771,20 @@ static int qdi_port(struct platform_devi
26468 return 0;
26469 }
26470
26471 -static struct ata_port_operations qdi6500_port_ops = {
26472 +static const struct ata_port_operations qdi6500_port_ops = {
26473 .inherits = &legacy_base_port_ops,
26474 .set_piomode = qdi6500_set_piomode,
26475 .qc_issue = qdi_qc_issue,
26476 .sff_data_xfer = vlb32_data_xfer,
26477 };
26478
26479 -static struct ata_port_operations qdi6580_port_ops = {
26480 +static const struct ata_port_operations qdi6580_port_ops = {
26481 .inherits = &legacy_base_port_ops,
26482 .set_piomode = qdi6580_set_piomode,
26483 .sff_data_xfer = vlb32_data_xfer,
26484 };
26485
26486 -static struct ata_port_operations qdi6580dp_port_ops = {
26487 +static const struct ata_port_operations qdi6580dp_port_ops = {
26488 .inherits = &legacy_base_port_ops,
26489 .set_piomode = qdi6580dp_set_piomode,
26490 .sff_data_xfer = vlb32_data_xfer,
26491 @@ -855,7 +855,7 @@ static int winbond_port(struct platform_
26492 return 0;
26493 }
26494
26495 -static struct ata_port_operations winbond_port_ops = {
26496 +static const struct ata_port_operations winbond_port_ops = {
26497 .inherits = &legacy_base_port_ops,
26498 .set_piomode = winbond_set_piomode,
26499 .sff_data_xfer = vlb32_data_xfer,
26500 @@ -978,7 +978,7 @@ static __init int legacy_init_one(struct
26501 int pio_modes = controller->pio_mask;
26502 unsigned long io = probe->port;
26503 u32 mask = (1 << probe->slot);
26504 - struct ata_port_operations *ops = controller->ops;
26505 + const struct ata_port_operations *ops = controller->ops;
26506 struct legacy_data *ld = &legacy_data[probe->slot];
26507 struct ata_host *host = NULL;
26508 struct ata_port *ap;
26509 diff -urNp linux-2.6.32.46/drivers/ata/pata_marvell.c linux-2.6.32.46/drivers/ata/pata_marvell.c
26510 --- linux-2.6.32.46/drivers/ata/pata_marvell.c 2011-03-27 14:31:47.000000000 -0400
26511 +++ linux-2.6.32.46/drivers/ata/pata_marvell.c 2011-04-17 15:56:46.000000000 -0400
26512 @@ -100,7 +100,7 @@ static struct scsi_host_template marvell
26513 ATA_BMDMA_SHT(DRV_NAME),
26514 };
26515
26516 -static struct ata_port_operations marvell_ops = {
26517 +static const struct ata_port_operations marvell_ops = {
26518 .inherits = &ata_bmdma_port_ops,
26519 .cable_detect = marvell_cable_detect,
26520 .prereset = marvell_pre_reset,
26521 diff -urNp linux-2.6.32.46/drivers/ata/pata_mpc52xx.c linux-2.6.32.46/drivers/ata/pata_mpc52xx.c
26522 --- linux-2.6.32.46/drivers/ata/pata_mpc52xx.c 2011-03-27 14:31:47.000000000 -0400
26523 +++ linux-2.6.32.46/drivers/ata/pata_mpc52xx.c 2011-04-17 15:56:46.000000000 -0400
26524 @@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
26525 ATA_PIO_SHT(DRV_NAME),
26526 };
26527
26528 -static struct ata_port_operations mpc52xx_ata_port_ops = {
26529 +static const struct ata_port_operations mpc52xx_ata_port_ops = {
26530 .inherits = &ata_bmdma_port_ops,
26531 .sff_dev_select = mpc52xx_ata_dev_select,
26532 .set_piomode = mpc52xx_ata_set_piomode,
26533 diff -urNp linux-2.6.32.46/drivers/ata/pata_mpiix.c linux-2.6.32.46/drivers/ata/pata_mpiix.c
26534 --- linux-2.6.32.46/drivers/ata/pata_mpiix.c 2011-03-27 14:31:47.000000000 -0400
26535 +++ linux-2.6.32.46/drivers/ata/pata_mpiix.c 2011-04-17 15:56:46.000000000 -0400
26536 @@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
26537 ATA_PIO_SHT(DRV_NAME),
26538 };
26539
26540 -static struct ata_port_operations mpiix_port_ops = {
26541 +static const struct ata_port_operations mpiix_port_ops = {
26542 .inherits = &ata_sff_port_ops,
26543 .qc_issue = mpiix_qc_issue,
26544 .cable_detect = ata_cable_40wire,
26545 diff -urNp linux-2.6.32.46/drivers/ata/pata_netcell.c linux-2.6.32.46/drivers/ata/pata_netcell.c
26546 --- linux-2.6.32.46/drivers/ata/pata_netcell.c 2011-03-27 14:31:47.000000000 -0400
26547 +++ linux-2.6.32.46/drivers/ata/pata_netcell.c 2011-04-17 15:56:46.000000000 -0400
26548 @@ -34,7 +34,7 @@ static struct scsi_host_template netcell
26549 ATA_BMDMA_SHT(DRV_NAME),
26550 };
26551
26552 -static struct ata_port_operations netcell_ops = {
26553 +static const struct ata_port_operations netcell_ops = {
26554 .inherits = &ata_bmdma_port_ops,
26555 .cable_detect = ata_cable_80wire,
26556 .read_id = netcell_read_id,
26557 diff -urNp linux-2.6.32.46/drivers/ata/pata_ninja32.c linux-2.6.32.46/drivers/ata/pata_ninja32.c
26558 --- linux-2.6.32.46/drivers/ata/pata_ninja32.c 2011-03-27 14:31:47.000000000 -0400
26559 +++ linux-2.6.32.46/drivers/ata/pata_ninja32.c 2011-04-17 15:56:46.000000000 -0400
26560 @@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
26561 ATA_BMDMA_SHT(DRV_NAME),
26562 };
26563
26564 -static struct ata_port_operations ninja32_port_ops = {
26565 +static const struct ata_port_operations ninja32_port_ops = {
26566 .inherits = &ata_bmdma_port_ops,
26567 .sff_dev_select = ninja32_dev_select,
26568 .cable_detect = ata_cable_40wire,
26569 diff -urNp linux-2.6.32.46/drivers/ata/pata_ns87410.c linux-2.6.32.46/drivers/ata/pata_ns87410.c
26570 --- linux-2.6.32.46/drivers/ata/pata_ns87410.c 2011-03-27 14:31:47.000000000 -0400
26571 +++ linux-2.6.32.46/drivers/ata/pata_ns87410.c 2011-04-17 15:56:46.000000000 -0400
26572 @@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
26573 ATA_PIO_SHT(DRV_NAME),
26574 };
26575
26576 -static struct ata_port_operations ns87410_port_ops = {
26577 +static const struct ata_port_operations ns87410_port_ops = {
26578 .inherits = &ata_sff_port_ops,
26579 .qc_issue = ns87410_qc_issue,
26580 .cable_detect = ata_cable_40wire,
26581 diff -urNp linux-2.6.32.46/drivers/ata/pata_ns87415.c linux-2.6.32.46/drivers/ata/pata_ns87415.c
26582 --- linux-2.6.32.46/drivers/ata/pata_ns87415.c 2011-03-27 14:31:47.000000000 -0400
26583 +++ linux-2.6.32.46/drivers/ata/pata_ns87415.c 2011-04-17 15:56:46.000000000 -0400
26584 @@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
26585 }
26586 #endif /* 87560 SuperIO Support */
26587
26588 -static struct ata_port_operations ns87415_pata_ops = {
26589 +static const struct ata_port_operations ns87415_pata_ops = {
26590 .inherits = &ata_bmdma_port_ops,
26591
26592 .check_atapi_dma = ns87415_check_atapi_dma,
26593 @@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
26594 };
26595
26596 #if defined(CONFIG_SUPERIO)
26597 -static struct ata_port_operations ns87560_pata_ops = {
26598 +static const struct ata_port_operations ns87560_pata_ops = {
26599 .inherits = &ns87415_pata_ops,
26600 .sff_tf_read = ns87560_tf_read,
26601 .sff_check_status = ns87560_check_status,
26602 diff -urNp linux-2.6.32.46/drivers/ata/pata_octeon_cf.c linux-2.6.32.46/drivers/ata/pata_octeon_cf.c
26603 --- linux-2.6.32.46/drivers/ata/pata_octeon_cf.c 2011-03-27 14:31:47.000000000 -0400
26604 +++ linux-2.6.32.46/drivers/ata/pata_octeon_cf.c 2011-04-17 15:56:46.000000000 -0400
26605 @@ -801,6 +801,7 @@ static unsigned int octeon_cf_qc_issue(s
26606 return 0;
26607 }
26608
26609 +/* cannot be const */
26610 static struct ata_port_operations octeon_cf_ops = {
26611 .inherits = &ata_sff_port_ops,
26612 .check_atapi_dma = octeon_cf_check_atapi_dma,
26613 diff -urNp linux-2.6.32.46/drivers/ata/pata_oldpiix.c linux-2.6.32.46/drivers/ata/pata_oldpiix.c
26614 --- linux-2.6.32.46/drivers/ata/pata_oldpiix.c 2011-03-27 14:31:47.000000000 -0400
26615 +++ linux-2.6.32.46/drivers/ata/pata_oldpiix.c 2011-04-17 15:56:46.000000000 -0400
26616 @@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
26617 ATA_BMDMA_SHT(DRV_NAME),
26618 };
26619
26620 -static struct ata_port_operations oldpiix_pata_ops = {
26621 +static const struct ata_port_operations oldpiix_pata_ops = {
26622 .inherits = &ata_bmdma_port_ops,
26623 .qc_issue = oldpiix_qc_issue,
26624 .cable_detect = ata_cable_40wire,
26625 diff -urNp linux-2.6.32.46/drivers/ata/pata_opti.c linux-2.6.32.46/drivers/ata/pata_opti.c
26626 --- linux-2.6.32.46/drivers/ata/pata_opti.c 2011-03-27 14:31:47.000000000 -0400
26627 +++ linux-2.6.32.46/drivers/ata/pata_opti.c 2011-04-17 15:56:46.000000000 -0400
26628 @@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
26629 ATA_PIO_SHT(DRV_NAME),
26630 };
26631
26632 -static struct ata_port_operations opti_port_ops = {
26633 +static const struct ata_port_operations opti_port_ops = {
26634 .inherits = &ata_sff_port_ops,
26635 .cable_detect = ata_cable_40wire,
26636 .set_piomode = opti_set_piomode,
26637 diff -urNp linux-2.6.32.46/drivers/ata/pata_optidma.c linux-2.6.32.46/drivers/ata/pata_optidma.c
26638 --- linux-2.6.32.46/drivers/ata/pata_optidma.c 2011-03-27 14:31:47.000000000 -0400
26639 +++ linux-2.6.32.46/drivers/ata/pata_optidma.c 2011-04-17 15:56:46.000000000 -0400
26640 @@ -337,7 +337,7 @@ static struct scsi_host_template optidma
26641 ATA_BMDMA_SHT(DRV_NAME),
26642 };
26643
26644 -static struct ata_port_operations optidma_port_ops = {
26645 +static const struct ata_port_operations optidma_port_ops = {
26646 .inherits = &ata_bmdma_port_ops,
26647 .cable_detect = ata_cable_40wire,
26648 .set_piomode = optidma_set_pio_mode,
26649 @@ -346,7 +346,7 @@ static struct ata_port_operations optidm
26650 .prereset = optidma_pre_reset,
26651 };
26652
26653 -static struct ata_port_operations optiplus_port_ops = {
26654 +static const struct ata_port_operations optiplus_port_ops = {
26655 .inherits = &optidma_port_ops,
26656 .set_piomode = optiplus_set_pio_mode,
26657 .set_dmamode = optiplus_set_dma_mode,
26658 diff -urNp linux-2.6.32.46/drivers/ata/pata_palmld.c linux-2.6.32.46/drivers/ata/pata_palmld.c
26659 --- linux-2.6.32.46/drivers/ata/pata_palmld.c 2011-03-27 14:31:47.000000000 -0400
26660 +++ linux-2.6.32.46/drivers/ata/pata_palmld.c 2011-04-17 15:56:46.000000000 -0400
26661 @@ -37,7 +37,7 @@ static struct scsi_host_template palmld_
26662 ATA_PIO_SHT(DRV_NAME),
26663 };
26664
26665 -static struct ata_port_operations palmld_port_ops = {
26666 +static const struct ata_port_operations palmld_port_ops = {
26667 .inherits = &ata_sff_port_ops,
26668 .sff_data_xfer = ata_sff_data_xfer_noirq,
26669 .cable_detect = ata_cable_40wire,
26670 diff -urNp linux-2.6.32.46/drivers/ata/pata_pcmcia.c linux-2.6.32.46/drivers/ata/pata_pcmcia.c
26671 --- linux-2.6.32.46/drivers/ata/pata_pcmcia.c 2011-03-27 14:31:47.000000000 -0400
26672 +++ linux-2.6.32.46/drivers/ata/pata_pcmcia.c 2011-04-17 15:56:46.000000000 -0400
26673 @@ -162,14 +162,14 @@ static struct scsi_host_template pcmcia_
26674 ATA_PIO_SHT(DRV_NAME),
26675 };
26676
26677 -static struct ata_port_operations pcmcia_port_ops = {
26678 +static const struct ata_port_operations pcmcia_port_ops = {
26679 .inherits = &ata_sff_port_ops,
26680 .sff_data_xfer = ata_sff_data_xfer_noirq,
26681 .cable_detect = ata_cable_40wire,
26682 .set_mode = pcmcia_set_mode,
26683 };
26684
26685 -static struct ata_port_operations pcmcia_8bit_port_ops = {
26686 +static const struct ata_port_operations pcmcia_8bit_port_ops = {
26687 .inherits = &ata_sff_port_ops,
26688 .sff_data_xfer = ata_data_xfer_8bit,
26689 .cable_detect = ata_cable_40wire,
26690 @@ -256,7 +256,7 @@ static int pcmcia_init_one(struct pcmcia
26691 unsigned long io_base, ctl_base;
26692 void __iomem *io_addr, *ctl_addr;
26693 int n_ports = 1;
26694 - struct ata_port_operations *ops = &pcmcia_port_ops;
26695 + const struct ata_port_operations *ops = &pcmcia_port_ops;
26696
26697 info = kzalloc(sizeof(*info), GFP_KERNEL);
26698 if (info == NULL)
26699 diff -urNp linux-2.6.32.46/drivers/ata/pata_pdc2027x.c linux-2.6.32.46/drivers/ata/pata_pdc2027x.c
26700 --- linux-2.6.32.46/drivers/ata/pata_pdc2027x.c 2011-03-27 14:31:47.000000000 -0400
26701 +++ linux-2.6.32.46/drivers/ata/pata_pdc2027x.c 2011-04-17 15:56:46.000000000 -0400
26702 @@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
26703 ATA_BMDMA_SHT(DRV_NAME),
26704 };
26705
26706 -static struct ata_port_operations pdc2027x_pata100_ops = {
26707 +static const struct ata_port_operations pdc2027x_pata100_ops = {
26708 .inherits = &ata_bmdma_port_ops,
26709 .check_atapi_dma = pdc2027x_check_atapi_dma,
26710 .cable_detect = pdc2027x_cable_detect,
26711 .prereset = pdc2027x_prereset,
26712 };
26713
26714 -static struct ata_port_operations pdc2027x_pata133_ops = {
26715 +static const struct ata_port_operations pdc2027x_pata133_ops = {
26716 .inherits = &pdc2027x_pata100_ops,
26717 .mode_filter = pdc2027x_mode_filter,
26718 .set_piomode = pdc2027x_set_piomode,
26719 diff -urNp linux-2.6.32.46/drivers/ata/pata_pdc202xx_old.c linux-2.6.32.46/drivers/ata/pata_pdc202xx_old.c
26720 --- linux-2.6.32.46/drivers/ata/pata_pdc202xx_old.c 2011-03-27 14:31:47.000000000 -0400
26721 +++ linux-2.6.32.46/drivers/ata/pata_pdc202xx_old.c 2011-04-17 15:56:46.000000000 -0400
26722 @@ -274,7 +274,7 @@ static struct scsi_host_template pdc202x
26723 ATA_BMDMA_SHT(DRV_NAME),
26724 };
26725
26726 -static struct ata_port_operations pdc2024x_port_ops = {
26727 +static const struct ata_port_operations pdc2024x_port_ops = {
26728 .inherits = &ata_bmdma_port_ops,
26729
26730 .cable_detect = ata_cable_40wire,
26731 @@ -284,7 +284,7 @@ static struct ata_port_operations pdc202
26732 .sff_exec_command = pdc202xx_exec_command,
26733 };
26734
26735 -static struct ata_port_operations pdc2026x_port_ops = {
26736 +static const struct ata_port_operations pdc2026x_port_ops = {
26737 .inherits = &pdc2024x_port_ops,
26738
26739 .check_atapi_dma = pdc2026x_check_atapi_dma,
26740 diff -urNp linux-2.6.32.46/drivers/ata/pata_platform.c linux-2.6.32.46/drivers/ata/pata_platform.c
26741 --- linux-2.6.32.46/drivers/ata/pata_platform.c 2011-03-27 14:31:47.000000000 -0400
26742 +++ linux-2.6.32.46/drivers/ata/pata_platform.c 2011-04-17 15:56:46.000000000 -0400
26743 @@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
26744 ATA_PIO_SHT(DRV_NAME),
26745 };
26746
26747 -static struct ata_port_operations pata_platform_port_ops = {
26748 +static const struct ata_port_operations pata_platform_port_ops = {
26749 .inherits = &ata_sff_port_ops,
26750 .sff_data_xfer = ata_sff_data_xfer_noirq,
26751 .cable_detect = ata_cable_unknown,
26752 diff -urNp linux-2.6.32.46/drivers/ata/pata_qdi.c linux-2.6.32.46/drivers/ata/pata_qdi.c
26753 --- linux-2.6.32.46/drivers/ata/pata_qdi.c 2011-03-27 14:31:47.000000000 -0400
26754 +++ linux-2.6.32.46/drivers/ata/pata_qdi.c 2011-04-17 15:56:46.000000000 -0400
26755 @@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
26756 ATA_PIO_SHT(DRV_NAME),
26757 };
26758
26759 -static struct ata_port_operations qdi6500_port_ops = {
26760 +static const struct ata_port_operations qdi6500_port_ops = {
26761 .inherits = &ata_sff_port_ops,
26762 .qc_issue = qdi_qc_issue,
26763 .sff_data_xfer = qdi_data_xfer,
26764 @@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
26765 .set_piomode = qdi6500_set_piomode,
26766 };
26767
26768 -static struct ata_port_operations qdi6580_port_ops = {
26769 +static const struct ata_port_operations qdi6580_port_ops = {
26770 .inherits = &qdi6500_port_ops,
26771 .set_piomode = qdi6580_set_piomode,
26772 };
26773 diff -urNp linux-2.6.32.46/drivers/ata/pata_radisys.c linux-2.6.32.46/drivers/ata/pata_radisys.c
26774 --- linux-2.6.32.46/drivers/ata/pata_radisys.c 2011-03-27 14:31:47.000000000 -0400
26775 +++ linux-2.6.32.46/drivers/ata/pata_radisys.c 2011-04-17 15:56:46.000000000 -0400
26776 @@ -187,7 +187,7 @@ static struct scsi_host_template radisys
26777 ATA_BMDMA_SHT(DRV_NAME),
26778 };
26779
26780 -static struct ata_port_operations radisys_pata_ops = {
26781 +static const struct ata_port_operations radisys_pata_ops = {
26782 .inherits = &ata_bmdma_port_ops,
26783 .qc_issue = radisys_qc_issue,
26784 .cable_detect = ata_cable_unknown,
26785 diff -urNp linux-2.6.32.46/drivers/ata/pata_rb532_cf.c linux-2.6.32.46/drivers/ata/pata_rb532_cf.c
26786 --- linux-2.6.32.46/drivers/ata/pata_rb532_cf.c 2011-03-27 14:31:47.000000000 -0400
26787 +++ linux-2.6.32.46/drivers/ata/pata_rb532_cf.c 2011-04-17 15:56:46.000000000 -0400
26788 @@ -68,7 +68,7 @@ static irqreturn_t rb532_pata_irq_handle
26789 return IRQ_HANDLED;
26790 }
26791
26792 -static struct ata_port_operations rb532_pata_port_ops = {
26793 +static const struct ata_port_operations rb532_pata_port_ops = {
26794 .inherits = &ata_sff_port_ops,
26795 .sff_data_xfer = ata_sff_data_xfer32,
26796 };
26797 diff -urNp linux-2.6.32.46/drivers/ata/pata_rdc.c linux-2.6.32.46/drivers/ata/pata_rdc.c
26798 --- linux-2.6.32.46/drivers/ata/pata_rdc.c 2011-03-27 14:31:47.000000000 -0400
26799 +++ linux-2.6.32.46/drivers/ata/pata_rdc.c 2011-04-17 15:56:46.000000000 -0400
26800 @@ -272,7 +272,7 @@ static void rdc_set_dmamode(struct ata_p
26801 pci_write_config_byte(dev, 0x48, udma_enable);
26802 }
26803
26804 -static struct ata_port_operations rdc_pata_ops = {
26805 +static const struct ata_port_operations rdc_pata_ops = {
26806 .inherits = &ata_bmdma32_port_ops,
26807 .cable_detect = rdc_pata_cable_detect,
26808 .set_piomode = rdc_set_piomode,
26809 diff -urNp linux-2.6.32.46/drivers/ata/pata_rz1000.c linux-2.6.32.46/drivers/ata/pata_rz1000.c
26810 --- linux-2.6.32.46/drivers/ata/pata_rz1000.c 2011-03-27 14:31:47.000000000 -0400
26811 +++ linux-2.6.32.46/drivers/ata/pata_rz1000.c 2011-04-17 15:56:46.000000000 -0400
26812 @@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
26813 ATA_PIO_SHT(DRV_NAME),
26814 };
26815
26816 -static struct ata_port_operations rz1000_port_ops = {
26817 +static const struct ata_port_operations rz1000_port_ops = {
26818 .inherits = &ata_sff_port_ops,
26819 .cable_detect = ata_cable_40wire,
26820 .set_mode = rz1000_set_mode,
26821 diff -urNp linux-2.6.32.46/drivers/ata/pata_sc1200.c linux-2.6.32.46/drivers/ata/pata_sc1200.c
26822 --- linux-2.6.32.46/drivers/ata/pata_sc1200.c 2011-03-27 14:31:47.000000000 -0400
26823 +++ linux-2.6.32.46/drivers/ata/pata_sc1200.c 2011-04-17 15:56:46.000000000 -0400
26824 @@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
26825 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
26826 };
26827
26828 -static struct ata_port_operations sc1200_port_ops = {
26829 +static const struct ata_port_operations sc1200_port_ops = {
26830 .inherits = &ata_bmdma_port_ops,
26831 .qc_prep = ata_sff_dumb_qc_prep,
26832 .qc_issue = sc1200_qc_issue,
26833 diff -urNp linux-2.6.32.46/drivers/ata/pata_scc.c linux-2.6.32.46/drivers/ata/pata_scc.c
26834 --- linux-2.6.32.46/drivers/ata/pata_scc.c 2011-03-27 14:31:47.000000000 -0400
26835 +++ linux-2.6.32.46/drivers/ata/pata_scc.c 2011-04-17 15:56:46.000000000 -0400
26836 @@ -965,7 +965,7 @@ static struct scsi_host_template scc_sht
26837 ATA_BMDMA_SHT(DRV_NAME),
26838 };
26839
26840 -static struct ata_port_operations scc_pata_ops = {
26841 +static const struct ata_port_operations scc_pata_ops = {
26842 .inherits = &ata_bmdma_port_ops,
26843
26844 .set_piomode = scc_set_piomode,
26845 diff -urNp linux-2.6.32.46/drivers/ata/pata_sch.c linux-2.6.32.46/drivers/ata/pata_sch.c
26846 --- linux-2.6.32.46/drivers/ata/pata_sch.c 2011-03-27 14:31:47.000000000 -0400
26847 +++ linux-2.6.32.46/drivers/ata/pata_sch.c 2011-04-17 15:56:46.000000000 -0400
26848 @@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
26849 ATA_BMDMA_SHT(DRV_NAME),
26850 };
26851
26852 -static struct ata_port_operations sch_pata_ops = {
26853 +static const struct ata_port_operations sch_pata_ops = {
26854 .inherits = &ata_bmdma_port_ops,
26855 .cable_detect = ata_cable_unknown,
26856 .set_piomode = sch_set_piomode,
26857 diff -urNp linux-2.6.32.46/drivers/ata/pata_serverworks.c linux-2.6.32.46/drivers/ata/pata_serverworks.c
26858 --- linux-2.6.32.46/drivers/ata/pata_serverworks.c 2011-03-27 14:31:47.000000000 -0400
26859 +++ linux-2.6.32.46/drivers/ata/pata_serverworks.c 2011-04-17 15:56:46.000000000 -0400
26860 @@ -299,7 +299,7 @@ static struct scsi_host_template serverw
26861 ATA_BMDMA_SHT(DRV_NAME),
26862 };
26863
26864 -static struct ata_port_operations serverworks_osb4_port_ops = {
26865 +static const struct ata_port_operations serverworks_osb4_port_ops = {
26866 .inherits = &ata_bmdma_port_ops,
26867 .cable_detect = serverworks_cable_detect,
26868 .mode_filter = serverworks_osb4_filter,
26869 @@ -307,7 +307,7 @@ static struct ata_port_operations server
26870 .set_dmamode = serverworks_set_dmamode,
26871 };
26872
26873 -static struct ata_port_operations serverworks_csb_port_ops = {
26874 +static const struct ata_port_operations serverworks_csb_port_ops = {
26875 .inherits = &serverworks_osb4_port_ops,
26876 .mode_filter = serverworks_csb_filter,
26877 };
26878 diff -urNp linux-2.6.32.46/drivers/ata/pata_sil680.c linux-2.6.32.46/drivers/ata/pata_sil680.c
26879 --- linux-2.6.32.46/drivers/ata/pata_sil680.c 2011-06-25 12:55:34.000000000 -0400
26880 +++ linux-2.6.32.46/drivers/ata/pata_sil680.c 2011-06-25 12:56:37.000000000 -0400
26881 @@ -194,7 +194,7 @@ static struct scsi_host_template sil680_
26882 ATA_BMDMA_SHT(DRV_NAME),
26883 };
26884
26885 -static struct ata_port_operations sil680_port_ops = {
26886 +static const struct ata_port_operations sil680_port_ops = {
26887 .inherits = &ata_bmdma32_port_ops,
26888 .cable_detect = sil680_cable_detect,
26889 .set_piomode = sil680_set_piomode,
26890 diff -urNp linux-2.6.32.46/drivers/ata/pata_sis.c linux-2.6.32.46/drivers/ata/pata_sis.c
26891 --- linux-2.6.32.46/drivers/ata/pata_sis.c 2011-03-27 14:31:47.000000000 -0400
26892 +++ linux-2.6.32.46/drivers/ata/pata_sis.c 2011-04-17 15:56:46.000000000 -0400
26893 @@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
26894 ATA_BMDMA_SHT(DRV_NAME),
26895 };
26896
26897 -static struct ata_port_operations sis_133_for_sata_ops = {
26898 +static const struct ata_port_operations sis_133_for_sata_ops = {
26899 .inherits = &ata_bmdma_port_ops,
26900 .set_piomode = sis_133_set_piomode,
26901 .set_dmamode = sis_133_set_dmamode,
26902 .cable_detect = sis_133_cable_detect,
26903 };
26904
26905 -static struct ata_port_operations sis_base_ops = {
26906 +static const struct ata_port_operations sis_base_ops = {
26907 .inherits = &ata_bmdma_port_ops,
26908 .prereset = sis_pre_reset,
26909 };
26910
26911 -static struct ata_port_operations sis_133_ops = {
26912 +static const struct ata_port_operations sis_133_ops = {
26913 .inherits = &sis_base_ops,
26914 .set_piomode = sis_133_set_piomode,
26915 .set_dmamode = sis_133_set_dmamode,
26916 .cable_detect = sis_133_cable_detect,
26917 };
26918
26919 -static struct ata_port_operations sis_133_early_ops = {
26920 +static const struct ata_port_operations sis_133_early_ops = {
26921 .inherits = &sis_base_ops,
26922 .set_piomode = sis_100_set_piomode,
26923 .set_dmamode = sis_133_early_set_dmamode,
26924 .cable_detect = sis_66_cable_detect,
26925 };
26926
26927 -static struct ata_port_operations sis_100_ops = {
26928 +static const struct ata_port_operations sis_100_ops = {
26929 .inherits = &sis_base_ops,
26930 .set_piomode = sis_100_set_piomode,
26931 .set_dmamode = sis_100_set_dmamode,
26932 .cable_detect = sis_66_cable_detect,
26933 };
26934
26935 -static struct ata_port_operations sis_66_ops = {
26936 +static const struct ata_port_operations sis_66_ops = {
26937 .inherits = &sis_base_ops,
26938 .set_piomode = sis_old_set_piomode,
26939 .set_dmamode = sis_66_set_dmamode,
26940 .cable_detect = sis_66_cable_detect,
26941 };
26942
26943 -static struct ata_port_operations sis_old_ops = {
26944 +static const struct ata_port_operations sis_old_ops = {
26945 .inherits = &sis_base_ops,
26946 .set_piomode = sis_old_set_piomode,
26947 .set_dmamode = sis_old_set_dmamode,
26948 diff -urNp linux-2.6.32.46/drivers/ata/pata_sl82c105.c linux-2.6.32.46/drivers/ata/pata_sl82c105.c
26949 --- linux-2.6.32.46/drivers/ata/pata_sl82c105.c 2011-03-27 14:31:47.000000000 -0400
26950 +++ linux-2.6.32.46/drivers/ata/pata_sl82c105.c 2011-04-17 15:56:46.000000000 -0400
26951 @@ -231,7 +231,7 @@ static struct scsi_host_template sl82c10
26952 ATA_BMDMA_SHT(DRV_NAME),
26953 };
26954
26955 -static struct ata_port_operations sl82c105_port_ops = {
26956 +static const struct ata_port_operations sl82c105_port_ops = {
26957 .inherits = &ata_bmdma_port_ops,
26958 .qc_defer = sl82c105_qc_defer,
26959 .bmdma_start = sl82c105_bmdma_start,
26960 diff -urNp linux-2.6.32.46/drivers/ata/pata_triflex.c linux-2.6.32.46/drivers/ata/pata_triflex.c
26961 --- linux-2.6.32.46/drivers/ata/pata_triflex.c 2011-03-27 14:31:47.000000000 -0400
26962 +++ linux-2.6.32.46/drivers/ata/pata_triflex.c 2011-04-17 15:56:46.000000000 -0400
26963 @@ -178,7 +178,7 @@ static struct scsi_host_template triflex
26964 ATA_BMDMA_SHT(DRV_NAME),
26965 };
26966
26967 -static struct ata_port_operations triflex_port_ops = {
26968 +static const struct ata_port_operations triflex_port_ops = {
26969 .inherits = &ata_bmdma_port_ops,
26970 .bmdma_start = triflex_bmdma_start,
26971 .bmdma_stop = triflex_bmdma_stop,
26972 diff -urNp linux-2.6.32.46/drivers/ata/pata_via.c linux-2.6.32.46/drivers/ata/pata_via.c
26973 --- linux-2.6.32.46/drivers/ata/pata_via.c 2011-03-27 14:31:47.000000000 -0400
26974 +++ linux-2.6.32.46/drivers/ata/pata_via.c 2011-04-17 15:56:46.000000000 -0400
26975 @@ -419,7 +419,7 @@ static struct scsi_host_template via_sht
26976 ATA_BMDMA_SHT(DRV_NAME),
26977 };
26978
26979 -static struct ata_port_operations via_port_ops = {
26980 +static const struct ata_port_operations via_port_ops = {
26981 .inherits = &ata_bmdma_port_ops,
26982 .cable_detect = via_cable_detect,
26983 .set_piomode = via_set_piomode,
26984 @@ -429,7 +429,7 @@ static struct ata_port_operations via_po
26985 .port_start = via_port_start,
26986 };
26987
26988 -static struct ata_port_operations via_port_ops_noirq = {
26989 +static const struct ata_port_operations via_port_ops_noirq = {
26990 .inherits = &via_port_ops,
26991 .sff_data_xfer = ata_sff_data_xfer_noirq,
26992 };
26993 diff -urNp linux-2.6.32.46/drivers/ata/pata_winbond.c linux-2.6.32.46/drivers/ata/pata_winbond.c
26994 --- linux-2.6.32.46/drivers/ata/pata_winbond.c 2011-03-27 14:31:47.000000000 -0400
26995 +++ linux-2.6.32.46/drivers/ata/pata_winbond.c 2011-04-17 15:56:46.000000000 -0400
26996 @@ -125,7 +125,7 @@ static struct scsi_host_template winbond
26997 ATA_PIO_SHT(DRV_NAME),
26998 };
26999
27000 -static struct ata_port_operations winbond_port_ops = {
27001 +static const struct ata_port_operations winbond_port_ops = {
27002 .inherits = &ata_sff_port_ops,
27003 .sff_data_xfer = winbond_data_xfer,
27004 .cable_detect = ata_cable_40wire,
27005 diff -urNp linux-2.6.32.46/drivers/ata/pdc_adma.c linux-2.6.32.46/drivers/ata/pdc_adma.c
27006 --- linux-2.6.32.46/drivers/ata/pdc_adma.c 2011-03-27 14:31:47.000000000 -0400
27007 +++ linux-2.6.32.46/drivers/ata/pdc_adma.c 2011-04-17 15:56:46.000000000 -0400
27008 @@ -145,7 +145,7 @@ static struct scsi_host_template adma_at
27009 .dma_boundary = ADMA_DMA_BOUNDARY,
27010 };
27011
27012 -static struct ata_port_operations adma_ata_ops = {
27013 +static const struct ata_port_operations adma_ata_ops = {
27014 .inherits = &ata_sff_port_ops,
27015
27016 .lost_interrupt = ATA_OP_NULL,
27017 diff -urNp linux-2.6.32.46/drivers/ata/sata_fsl.c linux-2.6.32.46/drivers/ata/sata_fsl.c
27018 --- linux-2.6.32.46/drivers/ata/sata_fsl.c 2011-03-27 14:31:47.000000000 -0400
27019 +++ linux-2.6.32.46/drivers/ata/sata_fsl.c 2011-04-17 15:56:46.000000000 -0400
27020 @@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fs
27021 .dma_boundary = ATA_DMA_BOUNDARY,
27022 };
27023
27024 -static struct ata_port_operations sata_fsl_ops = {
27025 +static const struct ata_port_operations sata_fsl_ops = {
27026 .inherits = &sata_pmp_port_ops,
27027
27028 .qc_defer = ata_std_qc_defer,
27029 diff -urNp linux-2.6.32.46/drivers/ata/sata_inic162x.c linux-2.6.32.46/drivers/ata/sata_inic162x.c
27030 --- linux-2.6.32.46/drivers/ata/sata_inic162x.c 2011-03-27 14:31:47.000000000 -0400
27031 +++ linux-2.6.32.46/drivers/ata/sata_inic162x.c 2011-04-17 15:56:46.000000000 -0400
27032 @@ -721,7 +721,7 @@ static int inic_port_start(struct ata_po
27033 return 0;
27034 }
27035
27036 -static struct ata_port_operations inic_port_ops = {
27037 +static const struct ata_port_operations inic_port_ops = {
27038 .inherits = &sata_port_ops,
27039
27040 .check_atapi_dma = inic_check_atapi_dma,
27041 diff -urNp linux-2.6.32.46/drivers/ata/sata_mv.c linux-2.6.32.46/drivers/ata/sata_mv.c
27042 --- linux-2.6.32.46/drivers/ata/sata_mv.c 2011-03-27 14:31:47.000000000 -0400
27043 +++ linux-2.6.32.46/drivers/ata/sata_mv.c 2011-04-17 15:56:46.000000000 -0400
27044 @@ -656,7 +656,7 @@ static struct scsi_host_template mv6_sht
27045 .dma_boundary = MV_DMA_BOUNDARY,
27046 };
27047
27048 -static struct ata_port_operations mv5_ops = {
27049 +static const struct ata_port_operations mv5_ops = {
27050 .inherits = &ata_sff_port_ops,
27051
27052 .lost_interrupt = ATA_OP_NULL,
27053 @@ -678,7 +678,7 @@ static struct ata_port_operations mv5_op
27054 .port_stop = mv_port_stop,
27055 };
27056
27057 -static struct ata_port_operations mv6_ops = {
27058 +static const struct ata_port_operations mv6_ops = {
27059 .inherits = &mv5_ops,
27060 .dev_config = mv6_dev_config,
27061 .scr_read = mv_scr_read,
27062 @@ -698,7 +698,7 @@ static struct ata_port_operations mv6_op
27063 .bmdma_status = mv_bmdma_status,
27064 };
27065
27066 -static struct ata_port_operations mv_iie_ops = {
27067 +static const struct ata_port_operations mv_iie_ops = {
27068 .inherits = &mv6_ops,
27069 .dev_config = ATA_OP_NULL,
27070 .qc_prep = mv_qc_prep_iie,
27071 diff -urNp linux-2.6.32.46/drivers/ata/sata_nv.c linux-2.6.32.46/drivers/ata/sata_nv.c
27072 --- linux-2.6.32.46/drivers/ata/sata_nv.c 2011-03-27 14:31:47.000000000 -0400
27073 +++ linux-2.6.32.46/drivers/ata/sata_nv.c 2011-04-17 15:56:46.000000000 -0400
27074 @@ -464,7 +464,7 @@ static struct scsi_host_template nv_swnc
27075 * cases. Define nv_hardreset() which only kicks in for post-boot
27076 * probing and use it for all variants.
27077 */
27078 -static struct ata_port_operations nv_generic_ops = {
27079 +static const struct ata_port_operations nv_generic_ops = {
27080 .inherits = &ata_bmdma_port_ops,
27081 .lost_interrupt = ATA_OP_NULL,
27082 .scr_read = nv_scr_read,
27083 @@ -472,20 +472,20 @@ static struct ata_port_operations nv_gen
27084 .hardreset = nv_hardreset,
27085 };
27086
27087 -static struct ata_port_operations nv_nf2_ops = {
27088 +static const struct ata_port_operations nv_nf2_ops = {
27089 .inherits = &nv_generic_ops,
27090 .freeze = nv_nf2_freeze,
27091 .thaw = nv_nf2_thaw,
27092 };
27093
27094 -static struct ata_port_operations nv_ck804_ops = {
27095 +static const struct ata_port_operations nv_ck804_ops = {
27096 .inherits = &nv_generic_ops,
27097 .freeze = nv_ck804_freeze,
27098 .thaw = nv_ck804_thaw,
27099 .host_stop = nv_ck804_host_stop,
27100 };
27101
27102 -static struct ata_port_operations nv_adma_ops = {
27103 +static const struct ata_port_operations nv_adma_ops = {
27104 .inherits = &nv_ck804_ops,
27105
27106 .check_atapi_dma = nv_adma_check_atapi_dma,
27107 @@ -509,7 +509,7 @@ static struct ata_port_operations nv_adm
27108 .host_stop = nv_adma_host_stop,
27109 };
27110
27111 -static struct ata_port_operations nv_swncq_ops = {
27112 +static const struct ata_port_operations nv_swncq_ops = {
27113 .inherits = &nv_generic_ops,
27114
27115 .qc_defer = ata_std_qc_defer,
27116 diff -urNp linux-2.6.32.46/drivers/ata/sata_promise.c linux-2.6.32.46/drivers/ata/sata_promise.c
27117 --- linux-2.6.32.46/drivers/ata/sata_promise.c 2011-03-27 14:31:47.000000000 -0400
27118 +++ linux-2.6.32.46/drivers/ata/sata_promise.c 2011-04-17 15:56:46.000000000 -0400
27119 @@ -195,7 +195,7 @@ static const struct ata_port_operations
27120 .error_handler = pdc_error_handler,
27121 };
27122
27123 -static struct ata_port_operations pdc_sata_ops = {
27124 +static const struct ata_port_operations pdc_sata_ops = {
27125 .inherits = &pdc_common_ops,
27126 .cable_detect = pdc_sata_cable_detect,
27127 .freeze = pdc_sata_freeze,
27128 @@ -208,14 +208,14 @@ static struct ata_port_operations pdc_sa
27129
27130 /* First-generation chips need a more restrictive ->check_atapi_dma op,
27131 and ->freeze/thaw that ignore the hotplug controls. */
27132 -static struct ata_port_operations pdc_old_sata_ops = {
27133 +static const struct ata_port_operations pdc_old_sata_ops = {
27134 .inherits = &pdc_sata_ops,
27135 .freeze = pdc_freeze,
27136 .thaw = pdc_thaw,
27137 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
27138 };
27139
27140 -static struct ata_port_operations pdc_pata_ops = {
27141 +static const struct ata_port_operations pdc_pata_ops = {
27142 .inherits = &pdc_common_ops,
27143 .cable_detect = pdc_pata_cable_detect,
27144 .freeze = pdc_freeze,
27145 diff -urNp linux-2.6.32.46/drivers/ata/sata_qstor.c linux-2.6.32.46/drivers/ata/sata_qstor.c
27146 --- linux-2.6.32.46/drivers/ata/sata_qstor.c 2011-03-27 14:31:47.000000000 -0400
27147 +++ linux-2.6.32.46/drivers/ata/sata_qstor.c 2011-04-17 15:56:46.000000000 -0400
27148 @@ -132,7 +132,7 @@ static struct scsi_host_template qs_ata_
27149 .dma_boundary = QS_DMA_BOUNDARY,
27150 };
27151
27152 -static struct ata_port_operations qs_ata_ops = {
27153 +static const struct ata_port_operations qs_ata_ops = {
27154 .inherits = &ata_sff_port_ops,
27155
27156 .check_atapi_dma = qs_check_atapi_dma,
27157 diff -urNp linux-2.6.32.46/drivers/ata/sata_sil.c linux-2.6.32.46/drivers/ata/sata_sil.c
27158 --- linux-2.6.32.46/drivers/ata/sata_sil.c 2011-03-27 14:31:47.000000000 -0400
27159 +++ linux-2.6.32.46/drivers/ata/sata_sil.c 2011-04-17 15:56:46.000000000 -0400
27160 @@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht
27161 .sg_tablesize = ATA_MAX_PRD
27162 };
27163
27164 -static struct ata_port_operations sil_ops = {
27165 +static const struct ata_port_operations sil_ops = {
27166 .inherits = &ata_bmdma32_port_ops,
27167 .dev_config = sil_dev_config,
27168 .set_mode = sil_set_mode,
27169 diff -urNp linux-2.6.32.46/drivers/ata/sata_sil24.c linux-2.6.32.46/drivers/ata/sata_sil24.c
27170 --- linux-2.6.32.46/drivers/ata/sata_sil24.c 2011-03-27 14:31:47.000000000 -0400
27171 +++ linux-2.6.32.46/drivers/ata/sata_sil24.c 2011-04-17 15:56:46.000000000 -0400
27172 @@ -388,7 +388,7 @@ static struct scsi_host_template sil24_s
27173 .dma_boundary = ATA_DMA_BOUNDARY,
27174 };
27175
27176 -static struct ata_port_operations sil24_ops = {
27177 +static const struct ata_port_operations sil24_ops = {
27178 .inherits = &sata_pmp_port_ops,
27179
27180 .qc_defer = sil24_qc_defer,
27181 diff -urNp linux-2.6.32.46/drivers/ata/sata_sis.c linux-2.6.32.46/drivers/ata/sata_sis.c
27182 --- linux-2.6.32.46/drivers/ata/sata_sis.c 2011-03-27 14:31:47.000000000 -0400
27183 +++ linux-2.6.32.46/drivers/ata/sata_sis.c 2011-04-17 15:56:46.000000000 -0400
27184 @@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
27185 ATA_BMDMA_SHT(DRV_NAME),
27186 };
27187
27188 -static struct ata_port_operations sis_ops = {
27189 +static const struct ata_port_operations sis_ops = {
27190 .inherits = &ata_bmdma_port_ops,
27191 .scr_read = sis_scr_read,
27192 .scr_write = sis_scr_write,
27193 diff -urNp linux-2.6.32.46/drivers/ata/sata_svw.c linux-2.6.32.46/drivers/ata/sata_svw.c
27194 --- linux-2.6.32.46/drivers/ata/sata_svw.c 2011-03-27 14:31:47.000000000 -0400
27195 +++ linux-2.6.32.46/drivers/ata/sata_svw.c 2011-04-17 15:56:46.000000000 -0400
27196 @@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
27197 };
27198
27199
27200 -static struct ata_port_operations k2_sata_ops = {
27201 +static const struct ata_port_operations k2_sata_ops = {
27202 .inherits = &ata_bmdma_port_ops,
27203 .sff_tf_load = k2_sata_tf_load,
27204 .sff_tf_read = k2_sata_tf_read,
27205 diff -urNp linux-2.6.32.46/drivers/ata/sata_sx4.c linux-2.6.32.46/drivers/ata/sata_sx4.c
27206 --- linux-2.6.32.46/drivers/ata/sata_sx4.c 2011-03-27 14:31:47.000000000 -0400
27207 +++ linux-2.6.32.46/drivers/ata/sata_sx4.c 2011-04-17 15:56:46.000000000 -0400
27208 @@ -248,7 +248,7 @@ static struct scsi_host_template pdc_sat
27209 };
27210
27211 /* TODO: inherit from base port_ops after converting to new EH */
27212 -static struct ata_port_operations pdc_20621_ops = {
27213 +static const struct ata_port_operations pdc_20621_ops = {
27214 .inherits = &ata_sff_port_ops,
27215
27216 .check_atapi_dma = pdc_check_atapi_dma,
27217 diff -urNp linux-2.6.32.46/drivers/ata/sata_uli.c linux-2.6.32.46/drivers/ata/sata_uli.c
27218 --- linux-2.6.32.46/drivers/ata/sata_uli.c 2011-03-27 14:31:47.000000000 -0400
27219 +++ linux-2.6.32.46/drivers/ata/sata_uli.c 2011-04-17 15:56:46.000000000 -0400
27220 @@ -79,7 +79,7 @@ static struct scsi_host_template uli_sht
27221 ATA_BMDMA_SHT(DRV_NAME),
27222 };
27223
27224 -static struct ata_port_operations uli_ops = {
27225 +static const struct ata_port_operations uli_ops = {
27226 .inherits = &ata_bmdma_port_ops,
27227 .scr_read = uli_scr_read,
27228 .scr_write = uli_scr_write,
27229 diff -urNp linux-2.6.32.46/drivers/ata/sata_via.c linux-2.6.32.46/drivers/ata/sata_via.c
27230 --- linux-2.6.32.46/drivers/ata/sata_via.c 2011-05-10 22:12:01.000000000 -0400
27231 +++ linux-2.6.32.46/drivers/ata/sata_via.c 2011-05-10 22:15:08.000000000 -0400
27232 @@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
27233 ATA_BMDMA_SHT(DRV_NAME),
27234 };
27235
27236 -static struct ata_port_operations svia_base_ops = {
27237 +static const struct ata_port_operations svia_base_ops = {
27238 .inherits = &ata_bmdma_port_ops,
27239 .sff_tf_load = svia_tf_load,
27240 };
27241
27242 -static struct ata_port_operations vt6420_sata_ops = {
27243 +static const struct ata_port_operations vt6420_sata_ops = {
27244 .inherits = &svia_base_ops,
27245 .freeze = svia_noop_freeze,
27246 .prereset = vt6420_prereset,
27247 .bmdma_start = vt6420_bmdma_start,
27248 };
27249
27250 -static struct ata_port_operations vt6421_pata_ops = {
27251 +static const struct ata_port_operations vt6421_pata_ops = {
27252 .inherits = &svia_base_ops,
27253 .cable_detect = vt6421_pata_cable_detect,
27254 .set_piomode = vt6421_set_pio_mode,
27255 .set_dmamode = vt6421_set_dma_mode,
27256 };
27257
27258 -static struct ata_port_operations vt6421_sata_ops = {
27259 +static const struct ata_port_operations vt6421_sata_ops = {
27260 .inherits = &svia_base_ops,
27261 .scr_read = svia_scr_read,
27262 .scr_write = svia_scr_write,
27263 };
27264
27265 -static struct ata_port_operations vt8251_ops = {
27266 +static const struct ata_port_operations vt8251_ops = {
27267 .inherits = &svia_base_ops,
27268 .hardreset = sata_std_hardreset,
27269 .scr_read = vt8251_scr_read,
27270 diff -urNp linux-2.6.32.46/drivers/ata/sata_vsc.c linux-2.6.32.46/drivers/ata/sata_vsc.c
27271 --- linux-2.6.32.46/drivers/ata/sata_vsc.c 2011-03-27 14:31:47.000000000 -0400
27272 +++ linux-2.6.32.46/drivers/ata/sata_vsc.c 2011-04-17 15:56:46.000000000 -0400
27273 @@ -306,7 +306,7 @@ static struct scsi_host_template vsc_sat
27274 };
27275
27276
27277 -static struct ata_port_operations vsc_sata_ops = {
27278 +static const struct ata_port_operations vsc_sata_ops = {
27279 .inherits = &ata_bmdma_port_ops,
27280 /* The IRQ handling is not quite standard SFF behaviour so we
27281 cannot use the default lost interrupt handler */
27282 diff -urNp linux-2.6.32.46/drivers/atm/adummy.c linux-2.6.32.46/drivers/atm/adummy.c
27283 --- linux-2.6.32.46/drivers/atm/adummy.c 2011-03-27 14:31:47.000000000 -0400
27284 +++ linux-2.6.32.46/drivers/atm/adummy.c 2011-04-17 15:56:46.000000000 -0400
27285 @@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct
27286 vcc->pop(vcc, skb);
27287 else
27288 dev_kfree_skb_any(skb);
27289 - atomic_inc(&vcc->stats->tx);
27290 + atomic_inc_unchecked(&vcc->stats->tx);
27291
27292 return 0;
27293 }
27294 diff -urNp linux-2.6.32.46/drivers/atm/ambassador.c linux-2.6.32.46/drivers/atm/ambassador.c
27295 --- linux-2.6.32.46/drivers/atm/ambassador.c 2011-03-27 14:31:47.000000000 -0400
27296 +++ linux-2.6.32.46/drivers/atm/ambassador.c 2011-04-17 15:56:46.000000000 -0400
27297 @@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev,
27298 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27299
27300 // VC layer stats
27301 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27302 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27303
27304 // free the descriptor
27305 kfree (tx_descr);
27306 @@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev,
27307 dump_skb ("<<<", vc, skb);
27308
27309 // VC layer stats
27310 - atomic_inc(&atm_vcc->stats->rx);
27311 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27312 __net_timestamp(skb);
27313 // end of our responsability
27314 atm_vcc->push (atm_vcc, skb);
27315 @@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev,
27316 } else {
27317 PRINTK (KERN_INFO, "dropped over-size frame");
27318 // should we count this?
27319 - atomic_inc(&atm_vcc->stats->rx_drop);
27320 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27321 }
27322
27323 } else {
27324 @@ -1341,7 +1341,7 @@ static int amb_send (struct atm_vcc * at
27325 }
27326
27327 if (check_area (skb->data, skb->len)) {
27328 - atomic_inc(&atm_vcc->stats->tx_err);
27329 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27330 return -ENOMEM; // ?
27331 }
27332
27333 diff -urNp linux-2.6.32.46/drivers/atm/atmtcp.c linux-2.6.32.46/drivers/atm/atmtcp.c
27334 --- linux-2.6.32.46/drivers/atm/atmtcp.c 2011-03-27 14:31:47.000000000 -0400
27335 +++ linux-2.6.32.46/drivers/atm/atmtcp.c 2011-04-17 15:56:46.000000000 -0400
27336 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc
27337 if (vcc->pop) vcc->pop(vcc,skb);
27338 else dev_kfree_skb(skb);
27339 if (dev_data) return 0;
27340 - atomic_inc(&vcc->stats->tx_err);
27341 + atomic_inc_unchecked(&vcc->stats->tx_err);
27342 return -ENOLINK;
27343 }
27344 size = skb->len+sizeof(struct atmtcp_hdr);
27345 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc
27346 if (!new_skb) {
27347 if (vcc->pop) vcc->pop(vcc,skb);
27348 else dev_kfree_skb(skb);
27349 - atomic_inc(&vcc->stats->tx_err);
27350 + atomic_inc_unchecked(&vcc->stats->tx_err);
27351 return -ENOBUFS;
27352 }
27353 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27354 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc
27355 if (vcc->pop) vcc->pop(vcc,skb);
27356 else dev_kfree_skb(skb);
27357 out_vcc->push(out_vcc,new_skb);
27358 - atomic_inc(&vcc->stats->tx);
27359 - atomic_inc(&out_vcc->stats->rx);
27360 + atomic_inc_unchecked(&vcc->stats->tx);
27361 + atomic_inc_unchecked(&out_vcc->stats->rx);
27362 return 0;
27363 }
27364
27365 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc
27366 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27367 read_unlock(&vcc_sklist_lock);
27368 if (!out_vcc) {
27369 - atomic_inc(&vcc->stats->tx_err);
27370 + atomic_inc_unchecked(&vcc->stats->tx_err);
27371 goto done;
27372 }
27373 skb_pull(skb,sizeof(struct atmtcp_hdr));
27374 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc
27375 __net_timestamp(new_skb);
27376 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27377 out_vcc->push(out_vcc,new_skb);
27378 - atomic_inc(&vcc->stats->tx);
27379 - atomic_inc(&out_vcc->stats->rx);
27380 + atomic_inc_unchecked(&vcc->stats->tx);
27381 + atomic_inc_unchecked(&out_vcc->stats->rx);
27382 done:
27383 if (vcc->pop) vcc->pop(vcc,skb);
27384 else dev_kfree_skb(skb);
27385 diff -urNp linux-2.6.32.46/drivers/atm/eni.c linux-2.6.32.46/drivers/atm/eni.c
27386 --- linux-2.6.32.46/drivers/atm/eni.c 2011-03-27 14:31:47.000000000 -0400
27387 +++ linux-2.6.32.46/drivers/atm/eni.c 2011-04-17 15:56:46.000000000 -0400
27388 @@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27389 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27390 vcc->dev->number);
27391 length = 0;
27392 - atomic_inc(&vcc->stats->rx_err);
27393 + atomic_inc_unchecked(&vcc->stats->rx_err);
27394 }
27395 else {
27396 length = ATM_CELL_SIZE-1; /* no HEC */
27397 @@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27398 size);
27399 }
27400 eff = length = 0;
27401 - atomic_inc(&vcc->stats->rx_err);
27402 + atomic_inc_unchecked(&vcc->stats->rx_err);
27403 }
27404 else {
27405 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27406 @@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27407 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27408 vcc->dev->number,vcc->vci,length,size << 2,descr);
27409 length = eff = 0;
27410 - atomic_inc(&vcc->stats->rx_err);
27411 + atomic_inc_unchecked(&vcc->stats->rx_err);
27412 }
27413 }
27414 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27415 @@ -770,7 +770,7 @@ rx_dequeued++;
27416 vcc->push(vcc,skb);
27417 pushed++;
27418 }
27419 - atomic_inc(&vcc->stats->rx);
27420 + atomic_inc_unchecked(&vcc->stats->rx);
27421 }
27422 wake_up(&eni_dev->rx_wait);
27423 }
27424 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *d
27425 PCI_DMA_TODEVICE);
27426 if (vcc->pop) vcc->pop(vcc,skb);
27427 else dev_kfree_skb_irq(skb);
27428 - atomic_inc(&vcc->stats->tx);
27429 + atomic_inc_unchecked(&vcc->stats->tx);
27430 wake_up(&eni_dev->tx_wait);
27431 dma_complete++;
27432 }
27433 diff -urNp linux-2.6.32.46/drivers/atm/firestream.c linux-2.6.32.46/drivers/atm/firestream.c
27434 --- linux-2.6.32.46/drivers/atm/firestream.c 2011-03-27 14:31:47.000000000 -0400
27435 +++ linux-2.6.32.46/drivers/atm/firestream.c 2011-04-17 15:56:46.000000000 -0400
27436 @@ -748,7 +748,7 @@ static void process_txdone_queue (struct
27437 }
27438 }
27439
27440 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27441 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27442
27443 fs_dprintk (FS_DEBUG_TXMEM, "i");
27444 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27445 @@ -815,7 +815,7 @@ static void process_incoming (struct fs_
27446 #endif
27447 skb_put (skb, qe->p1 & 0xffff);
27448 ATM_SKB(skb)->vcc = atm_vcc;
27449 - atomic_inc(&atm_vcc->stats->rx);
27450 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27451 __net_timestamp(skb);
27452 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27453 atm_vcc->push (atm_vcc, skb);
27454 @@ -836,12 +836,12 @@ static void process_incoming (struct fs_
27455 kfree (pe);
27456 }
27457 if (atm_vcc)
27458 - atomic_inc(&atm_vcc->stats->rx_drop);
27459 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27460 break;
27461 case 0x1f: /* Reassembly abort: no buffers. */
27462 /* Silently increment error counter. */
27463 if (atm_vcc)
27464 - atomic_inc(&atm_vcc->stats->rx_drop);
27465 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27466 break;
27467 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27468 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27469 diff -urNp linux-2.6.32.46/drivers/atm/fore200e.c linux-2.6.32.46/drivers/atm/fore200e.c
27470 --- linux-2.6.32.46/drivers/atm/fore200e.c 2011-03-27 14:31:47.000000000 -0400
27471 +++ linux-2.6.32.46/drivers/atm/fore200e.c 2011-04-17 15:56:46.000000000 -0400
27472 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200
27473 #endif
27474 /* check error condition */
27475 if (*entry->status & STATUS_ERROR)
27476 - atomic_inc(&vcc->stats->tx_err);
27477 + atomic_inc_unchecked(&vcc->stats->tx_err);
27478 else
27479 - atomic_inc(&vcc->stats->tx);
27480 + atomic_inc_unchecked(&vcc->stats->tx);
27481 }
27482 }
27483
27484 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore2
27485 if (skb == NULL) {
27486 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27487
27488 - atomic_inc(&vcc->stats->rx_drop);
27489 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27490 return -ENOMEM;
27491 }
27492
27493 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore2
27494
27495 dev_kfree_skb_any(skb);
27496
27497 - atomic_inc(&vcc->stats->rx_drop);
27498 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27499 return -ENOMEM;
27500 }
27501
27502 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27503
27504 vcc->push(vcc, skb);
27505 - atomic_inc(&vcc->stats->rx);
27506 + atomic_inc_unchecked(&vcc->stats->rx);
27507
27508 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27509
27510 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200
27511 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27512 fore200e->atm_dev->number,
27513 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27514 - atomic_inc(&vcc->stats->rx_err);
27515 + atomic_inc_unchecked(&vcc->stats->rx_err);
27516 }
27517 }
27518
27519 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struc
27520 goto retry_here;
27521 }
27522
27523 - atomic_inc(&vcc->stats->tx_err);
27524 + atomic_inc_unchecked(&vcc->stats->tx_err);
27525
27526 fore200e->tx_sat++;
27527 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27528 diff -urNp linux-2.6.32.46/drivers/atm/he.c linux-2.6.32.46/drivers/atm/he.c
27529 --- linux-2.6.32.46/drivers/atm/he.c 2011-03-27 14:31:47.000000000 -0400
27530 +++ linux-2.6.32.46/drivers/atm/he.c 2011-04-17 15:56:46.000000000 -0400
27531 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, i
27532
27533 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27534 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27535 - atomic_inc(&vcc->stats->rx_drop);
27536 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27537 goto return_host_buffers;
27538 }
27539
27540 @@ -1802,7 +1802,7 @@ he_service_rbrq(struct he_dev *he_dev, i
27541 RBRQ_LEN_ERR(he_dev->rbrq_head)
27542 ? "LEN_ERR" : "",
27543 vcc->vpi, vcc->vci);
27544 - atomic_inc(&vcc->stats->rx_err);
27545 + atomic_inc_unchecked(&vcc->stats->rx_err);
27546 goto return_host_buffers;
27547 }
27548
27549 @@ -1861,7 +1861,7 @@ he_service_rbrq(struct he_dev *he_dev, i
27550 vcc->push(vcc, skb);
27551 spin_lock(&he_dev->global_lock);
27552
27553 - atomic_inc(&vcc->stats->rx);
27554 + atomic_inc_unchecked(&vcc->stats->rx);
27555
27556 return_host_buffers:
27557 ++pdus_assembled;
27558 @@ -2206,7 +2206,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
27559 tpd->vcc->pop(tpd->vcc, tpd->skb);
27560 else
27561 dev_kfree_skb_any(tpd->skb);
27562 - atomic_inc(&tpd->vcc->stats->tx_err);
27563 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27564 }
27565 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27566 return;
27567 @@ -2618,7 +2618,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
27568 vcc->pop(vcc, skb);
27569 else
27570 dev_kfree_skb_any(skb);
27571 - atomic_inc(&vcc->stats->tx_err);
27572 + atomic_inc_unchecked(&vcc->stats->tx_err);
27573 return -EINVAL;
27574 }
27575
27576 @@ -2629,7 +2629,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
27577 vcc->pop(vcc, skb);
27578 else
27579 dev_kfree_skb_any(skb);
27580 - atomic_inc(&vcc->stats->tx_err);
27581 + atomic_inc_unchecked(&vcc->stats->tx_err);
27582 return -EINVAL;
27583 }
27584 #endif
27585 @@ -2641,7 +2641,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
27586 vcc->pop(vcc, skb);
27587 else
27588 dev_kfree_skb_any(skb);
27589 - atomic_inc(&vcc->stats->tx_err);
27590 + atomic_inc_unchecked(&vcc->stats->tx_err);
27591 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27592 return -ENOMEM;
27593 }
27594 @@ -2683,7 +2683,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
27595 vcc->pop(vcc, skb);
27596 else
27597 dev_kfree_skb_any(skb);
27598 - atomic_inc(&vcc->stats->tx_err);
27599 + atomic_inc_unchecked(&vcc->stats->tx_err);
27600 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27601 return -ENOMEM;
27602 }
27603 @@ -2714,7 +2714,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
27604 __enqueue_tpd(he_dev, tpd, cid);
27605 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27606
27607 - atomic_inc(&vcc->stats->tx);
27608 + atomic_inc_unchecked(&vcc->stats->tx);
27609
27610 return 0;
27611 }
27612 diff -urNp linux-2.6.32.46/drivers/atm/horizon.c linux-2.6.32.46/drivers/atm/horizon.c
27613 --- linux-2.6.32.46/drivers/atm/horizon.c 2011-03-27 14:31:47.000000000 -0400
27614 +++ linux-2.6.32.46/drivers/atm/horizon.c 2011-04-17 15:56:46.000000000 -0400
27615 @@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev,
27616 {
27617 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27618 // VC layer stats
27619 - atomic_inc(&vcc->stats->rx);
27620 + atomic_inc_unchecked(&vcc->stats->rx);
27621 __net_timestamp(skb);
27622 // end of our responsability
27623 vcc->push (vcc, skb);
27624 @@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const
27625 dev->tx_iovec = NULL;
27626
27627 // VC layer stats
27628 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27629 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27630
27631 // free the skb
27632 hrz_kfree_skb (skb);
27633 diff -urNp linux-2.6.32.46/drivers/atm/idt77252.c linux-2.6.32.46/drivers/atm/idt77252.c
27634 --- linux-2.6.32.46/drivers/atm/idt77252.c 2011-03-27 14:31:47.000000000 -0400
27635 +++ linux-2.6.32.46/drivers/atm/idt77252.c 2011-04-17 15:56:46.000000000 -0400
27636 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, str
27637 else
27638 dev_kfree_skb(skb);
27639
27640 - atomic_inc(&vcc->stats->tx);
27641 + atomic_inc_unchecked(&vcc->stats->tx);
27642 }
27643
27644 atomic_dec(&scq->used);
27645 @@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, st
27646 if ((sb = dev_alloc_skb(64)) == NULL) {
27647 printk("%s: Can't allocate buffers for aal0.\n",
27648 card->name);
27649 - atomic_add(i, &vcc->stats->rx_drop);
27650 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27651 break;
27652 }
27653 if (!atm_charge(vcc, sb->truesize)) {
27654 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
27655 card->name);
27656 - atomic_add(i - 1, &vcc->stats->rx_drop);
27657 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
27658 dev_kfree_skb(sb);
27659 break;
27660 }
27661 @@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, st
27662 ATM_SKB(sb)->vcc = vcc;
27663 __net_timestamp(sb);
27664 vcc->push(vcc, sb);
27665 - atomic_inc(&vcc->stats->rx);
27666 + atomic_inc_unchecked(&vcc->stats->rx);
27667
27668 cell += ATM_CELL_PAYLOAD;
27669 }
27670 @@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, st
27671 "(CDC: %08x)\n",
27672 card->name, len, rpp->len, readl(SAR_REG_CDC));
27673 recycle_rx_pool_skb(card, rpp);
27674 - atomic_inc(&vcc->stats->rx_err);
27675 + atomic_inc_unchecked(&vcc->stats->rx_err);
27676 return;
27677 }
27678 if (stat & SAR_RSQE_CRC) {
27679 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
27680 recycle_rx_pool_skb(card, rpp);
27681 - atomic_inc(&vcc->stats->rx_err);
27682 + atomic_inc_unchecked(&vcc->stats->rx_err);
27683 return;
27684 }
27685 if (skb_queue_len(&rpp->queue) > 1) {
27686 @@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, st
27687 RXPRINTK("%s: Can't alloc RX skb.\n",
27688 card->name);
27689 recycle_rx_pool_skb(card, rpp);
27690 - atomic_inc(&vcc->stats->rx_err);
27691 + atomic_inc_unchecked(&vcc->stats->rx_err);
27692 return;
27693 }
27694 if (!atm_charge(vcc, skb->truesize)) {
27695 @@ -1169,7 +1169,7 @@ dequeue_rx(struct idt77252_dev *card, st
27696 __net_timestamp(skb);
27697
27698 vcc->push(vcc, skb);
27699 - atomic_inc(&vcc->stats->rx);
27700 + atomic_inc_unchecked(&vcc->stats->rx);
27701
27702 return;
27703 }
27704 @@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, st
27705 __net_timestamp(skb);
27706
27707 vcc->push(vcc, skb);
27708 - atomic_inc(&vcc->stats->rx);
27709 + atomic_inc_unchecked(&vcc->stats->rx);
27710
27711 if (skb->truesize > SAR_FB_SIZE_3)
27712 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
27713 @@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *car
27714 if (vcc->qos.aal != ATM_AAL0) {
27715 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
27716 card->name, vpi, vci);
27717 - atomic_inc(&vcc->stats->rx_drop);
27718 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27719 goto drop;
27720 }
27721
27722 if ((sb = dev_alloc_skb(64)) == NULL) {
27723 printk("%s: Can't allocate buffers for AAL0.\n",
27724 card->name);
27725 - atomic_inc(&vcc->stats->rx_err);
27726 + atomic_inc_unchecked(&vcc->stats->rx_err);
27727 goto drop;
27728 }
27729
27730 @@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *car
27731 ATM_SKB(sb)->vcc = vcc;
27732 __net_timestamp(sb);
27733 vcc->push(vcc, sb);
27734 - atomic_inc(&vcc->stats->rx);
27735 + atomic_inc_unchecked(&vcc->stats->rx);
27736
27737 drop:
27738 skb_pull(queue, 64);
27739 @@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
27740
27741 if (vc == NULL) {
27742 printk("%s: NULL connection in send().\n", card->name);
27743 - atomic_inc(&vcc->stats->tx_err);
27744 + atomic_inc_unchecked(&vcc->stats->tx_err);
27745 dev_kfree_skb(skb);
27746 return -EINVAL;
27747 }
27748 if (!test_bit(VCF_TX, &vc->flags)) {
27749 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
27750 - atomic_inc(&vcc->stats->tx_err);
27751 + atomic_inc_unchecked(&vcc->stats->tx_err);
27752 dev_kfree_skb(skb);
27753 return -EINVAL;
27754 }
27755 @@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
27756 break;
27757 default:
27758 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27759 - atomic_inc(&vcc->stats->tx_err);
27760 + atomic_inc_unchecked(&vcc->stats->tx_err);
27761 dev_kfree_skb(skb);
27762 return -EINVAL;
27763 }
27764
27765 if (skb_shinfo(skb)->nr_frags != 0) {
27766 printk("%s: No scatter-gather yet.\n", card->name);
27767 - atomic_inc(&vcc->stats->tx_err);
27768 + atomic_inc_unchecked(&vcc->stats->tx_err);
27769 dev_kfree_skb(skb);
27770 return -EINVAL;
27771 }
27772 @@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
27773
27774 err = queue_skb(card, vc, skb, oam);
27775 if (err) {
27776 - atomic_inc(&vcc->stats->tx_err);
27777 + atomic_inc_unchecked(&vcc->stats->tx_err);
27778 dev_kfree_skb(skb);
27779 return err;
27780 }
27781 @@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
27782 skb = dev_alloc_skb(64);
27783 if (!skb) {
27784 printk("%s: Out of memory in send_oam().\n", card->name);
27785 - atomic_inc(&vcc->stats->tx_err);
27786 + atomic_inc_unchecked(&vcc->stats->tx_err);
27787 return -ENOMEM;
27788 }
27789 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27790 diff -urNp linux-2.6.32.46/drivers/atm/iphase.c linux-2.6.32.46/drivers/atm/iphase.c
27791 --- linux-2.6.32.46/drivers/atm/iphase.c 2011-03-27 14:31:47.000000000 -0400
27792 +++ linux-2.6.32.46/drivers/atm/iphase.c 2011-04-17 15:56:46.000000000 -0400
27793 @@ -1123,7 +1123,7 @@ static int rx_pkt(struct atm_dev *dev)
27794 status = (u_short) (buf_desc_ptr->desc_mode);
27795 if (status & (RX_CER | RX_PTE | RX_OFL))
27796 {
27797 - atomic_inc(&vcc->stats->rx_err);
27798 + atomic_inc_unchecked(&vcc->stats->rx_err);
27799 IF_ERR(printk("IA: bad packet, dropping it");)
27800 if (status & RX_CER) {
27801 IF_ERR(printk(" cause: packet CRC error\n");)
27802 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
27803 len = dma_addr - buf_addr;
27804 if (len > iadev->rx_buf_sz) {
27805 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27806 - atomic_inc(&vcc->stats->rx_err);
27807 + atomic_inc_unchecked(&vcc->stats->rx_err);
27808 goto out_free_desc;
27809 }
27810
27811 @@ -1296,7 +1296,7 @@ static void rx_dle_intr(struct atm_dev *
27812 ia_vcc = INPH_IA_VCC(vcc);
27813 if (ia_vcc == NULL)
27814 {
27815 - atomic_inc(&vcc->stats->rx_err);
27816 + atomic_inc_unchecked(&vcc->stats->rx_err);
27817 dev_kfree_skb_any(skb);
27818 atm_return(vcc, atm_guess_pdu2truesize(len));
27819 goto INCR_DLE;
27820 @@ -1308,7 +1308,7 @@ static void rx_dle_intr(struct atm_dev *
27821 if ((length > iadev->rx_buf_sz) || (length >
27822 (skb->len - sizeof(struct cpcs_trailer))))
27823 {
27824 - atomic_inc(&vcc->stats->rx_err);
27825 + atomic_inc_unchecked(&vcc->stats->rx_err);
27826 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27827 length, skb->len);)
27828 dev_kfree_skb_any(skb);
27829 @@ -1324,7 +1324,7 @@ static void rx_dle_intr(struct atm_dev *
27830
27831 IF_RX(printk("rx_dle_intr: skb push");)
27832 vcc->push(vcc,skb);
27833 - atomic_inc(&vcc->stats->rx);
27834 + atomic_inc_unchecked(&vcc->stats->rx);
27835 iadev->rx_pkt_cnt++;
27836 }
27837 INCR_DLE:
27838 @@ -2806,15 +2806,15 @@ static int ia_ioctl(struct atm_dev *dev,
27839 {
27840 struct k_sonet_stats *stats;
27841 stats = &PRIV(_ia_dev[board])->sonet_stats;
27842 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27843 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27844 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27845 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27846 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27847 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27848 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27849 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27850 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27851 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27852 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27853 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27854 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27855 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27856 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27857 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27858 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27859 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
27860 }
27861 ia_cmds.status = 0;
27862 break;
27863 @@ -2919,7 +2919,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
27864 if ((desc == 0) || (desc > iadev->num_tx_desc))
27865 {
27866 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
27867 - atomic_inc(&vcc->stats->tx);
27868 + atomic_inc_unchecked(&vcc->stats->tx);
27869 if (vcc->pop)
27870 vcc->pop(vcc, skb);
27871 else
27872 @@ -3024,14 +3024,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
27873 ATM_DESC(skb) = vcc->vci;
27874 skb_queue_tail(&iadev->tx_dma_q, skb);
27875
27876 - atomic_inc(&vcc->stats->tx);
27877 + atomic_inc_unchecked(&vcc->stats->tx);
27878 iadev->tx_pkt_cnt++;
27879 /* Increment transaction counter */
27880 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
27881
27882 #if 0
27883 /* add flow control logic */
27884 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27885 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27886 if (iavcc->vc_desc_cnt > 10) {
27887 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27888 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27889 diff -urNp linux-2.6.32.46/drivers/atm/lanai.c linux-2.6.32.46/drivers/atm/lanai.c
27890 --- linux-2.6.32.46/drivers/atm/lanai.c 2011-03-27 14:31:47.000000000 -0400
27891 +++ linux-2.6.32.46/drivers/atm/lanai.c 2011-04-17 15:56:46.000000000 -0400
27892 @@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct l
27893 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27894 lanai_endtx(lanai, lvcc);
27895 lanai_free_skb(lvcc->tx.atmvcc, skb);
27896 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
27897 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
27898 }
27899
27900 /* Try to fill the buffer - don't call unless there is backlog */
27901 @@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc
27902 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
27903 __net_timestamp(skb);
27904 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
27905 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
27906 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
27907 out:
27908 lvcc->rx.buf.ptr = end;
27909 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
27910 @@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_d
27911 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27912 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27913 lanai->stats.service_rxnotaal5++;
27914 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27915 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27916 return 0;
27917 }
27918 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27919 @@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_d
27920 int bytes;
27921 read_unlock(&vcc_sklist_lock);
27922 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27923 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27924 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27925 lvcc->stats.x.aal5.service_trash++;
27926 bytes = (SERVICE_GET_END(s) * 16) -
27927 (((unsigned long) lvcc->rx.buf.ptr) -
27928 @@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_d
27929 }
27930 if (s & SERVICE_STREAM) {
27931 read_unlock(&vcc_sklist_lock);
27932 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27933 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27934 lvcc->stats.x.aal5.service_stream++;
27935 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27936 "PDU on VCI %d!\n", lanai->number, vci);
27937 @@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_d
27938 return 0;
27939 }
27940 DPRINTK("got rx crc error on vci %d\n", vci);
27941 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27942 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27943 lvcc->stats.x.aal5.service_rxcrc++;
27944 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27945 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27946 diff -urNp linux-2.6.32.46/drivers/atm/nicstar.c linux-2.6.32.46/drivers/atm/nicstar.c
27947 --- linux-2.6.32.46/drivers/atm/nicstar.c 2011-03-27 14:31:47.000000000 -0400
27948 +++ linux-2.6.32.46/drivers/atm/nicstar.c 2011-04-17 15:56:46.000000000 -0400
27949 @@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc,
27950 if ((vc = (vc_map *) vcc->dev_data) == NULL)
27951 {
27952 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card->index);
27953 - atomic_inc(&vcc->stats->tx_err);
27954 + atomic_inc_unchecked(&vcc->stats->tx_err);
27955 dev_kfree_skb_any(skb);
27956 return -EINVAL;
27957 }
27958 @@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc,
27959 if (!vc->tx)
27960 {
27961 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card->index);
27962 - atomic_inc(&vcc->stats->tx_err);
27963 + atomic_inc_unchecked(&vcc->stats->tx_err);
27964 dev_kfree_skb_any(skb);
27965 return -EINVAL;
27966 }
27967 @@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc,
27968 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0)
27969 {
27970 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card->index);
27971 - atomic_inc(&vcc->stats->tx_err);
27972 + atomic_inc_unchecked(&vcc->stats->tx_err);
27973 dev_kfree_skb_any(skb);
27974 return -EINVAL;
27975 }
27976 @@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc,
27977 if (skb_shinfo(skb)->nr_frags != 0)
27978 {
27979 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27980 - atomic_inc(&vcc->stats->tx_err);
27981 + atomic_inc_unchecked(&vcc->stats->tx_err);
27982 dev_kfree_skb_any(skb);
27983 return -EINVAL;
27984 }
27985 @@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc,
27986
27987 if (push_scqe(card, vc, scq, &scqe, skb) != 0)
27988 {
27989 - atomic_inc(&vcc->stats->tx_err);
27990 + atomic_inc_unchecked(&vcc->stats->tx_err);
27991 dev_kfree_skb_any(skb);
27992 return -EIO;
27993 }
27994 - atomic_inc(&vcc->stats->tx);
27995 + atomic_inc_unchecked(&vcc->stats->tx);
27996
27997 return 0;
27998 }
27999 @@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_
28000 {
28001 printk("nicstar%d: Can't allocate buffers for aal0.\n",
28002 card->index);
28003 - atomic_add(i,&vcc->stats->rx_drop);
28004 + atomic_add_unchecked(i,&vcc->stats->rx_drop);
28005 break;
28006 }
28007 if (!atm_charge(vcc, sb->truesize))
28008 {
28009 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
28010 card->index);
28011 - atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
28012 + atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
28013 dev_kfree_skb_any(sb);
28014 break;
28015 }
28016 @@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_
28017 ATM_SKB(sb)->vcc = vcc;
28018 __net_timestamp(sb);
28019 vcc->push(vcc, sb);
28020 - atomic_inc(&vcc->stats->rx);
28021 + atomic_inc_unchecked(&vcc->stats->rx);
28022 cell += ATM_CELL_PAYLOAD;
28023 }
28024
28025 @@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_
28026 if (iovb == NULL)
28027 {
28028 printk("nicstar%d: Out of iovec buffers.\n", card->index);
28029 - atomic_inc(&vcc->stats->rx_drop);
28030 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28031 recycle_rx_buf(card, skb);
28032 return;
28033 }
28034 @@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_
28035 else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS)
28036 {
28037 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28038 - atomic_inc(&vcc->stats->rx_err);
28039 + atomic_inc_unchecked(&vcc->stats->rx_err);
28040 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS);
28041 NS_SKB(iovb)->iovcnt = 0;
28042 iovb->len = 0;
28043 @@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_
28044 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
28045 card->index);
28046 which_list(card, skb);
28047 - atomic_inc(&vcc->stats->rx_err);
28048 + atomic_inc_unchecked(&vcc->stats->rx_err);
28049 recycle_rx_buf(card, skb);
28050 vc->rx_iov = NULL;
28051 recycle_iov_buf(card, iovb);
28052 @@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_
28053 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
28054 card->index);
28055 which_list(card, skb);
28056 - atomic_inc(&vcc->stats->rx_err);
28057 + atomic_inc_unchecked(&vcc->stats->rx_err);
28058 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
28059 NS_SKB(iovb)->iovcnt);
28060 vc->rx_iov = NULL;
28061 @@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_
28062 printk(" - PDU size mismatch.\n");
28063 else
28064 printk(".\n");
28065 - atomic_inc(&vcc->stats->rx_err);
28066 + atomic_inc_unchecked(&vcc->stats->rx_err);
28067 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
28068 NS_SKB(iovb)->iovcnt);
28069 vc->rx_iov = NULL;
28070 @@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_
28071 if (!atm_charge(vcc, skb->truesize))
28072 {
28073 push_rxbufs(card, skb);
28074 - atomic_inc(&vcc->stats->rx_drop);
28075 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28076 }
28077 else
28078 {
28079 @@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_
28080 ATM_SKB(skb)->vcc = vcc;
28081 __net_timestamp(skb);
28082 vcc->push(vcc, skb);
28083 - atomic_inc(&vcc->stats->rx);
28084 + atomic_inc_unchecked(&vcc->stats->rx);
28085 }
28086 }
28087 else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */
28088 @@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_
28089 if (!atm_charge(vcc, sb->truesize))
28090 {
28091 push_rxbufs(card, sb);
28092 - atomic_inc(&vcc->stats->rx_drop);
28093 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28094 }
28095 else
28096 {
28097 @@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_
28098 ATM_SKB(sb)->vcc = vcc;
28099 __net_timestamp(sb);
28100 vcc->push(vcc, sb);
28101 - atomic_inc(&vcc->stats->rx);
28102 + atomic_inc_unchecked(&vcc->stats->rx);
28103 }
28104
28105 push_rxbufs(card, skb);
28106 @@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_
28107 if (!atm_charge(vcc, skb->truesize))
28108 {
28109 push_rxbufs(card, skb);
28110 - atomic_inc(&vcc->stats->rx_drop);
28111 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28112 }
28113 else
28114 {
28115 @@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_
28116 ATM_SKB(skb)->vcc = vcc;
28117 __net_timestamp(skb);
28118 vcc->push(vcc, skb);
28119 - atomic_inc(&vcc->stats->rx);
28120 + atomic_inc_unchecked(&vcc->stats->rx);
28121 }
28122
28123 push_rxbufs(card, sb);
28124 @@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_
28125 if (hb == NULL)
28126 {
28127 printk("nicstar%d: Out of huge buffers.\n", card->index);
28128 - atomic_inc(&vcc->stats->rx_drop);
28129 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28130 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
28131 NS_SKB(iovb)->iovcnt);
28132 vc->rx_iov = NULL;
28133 @@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_
28134 }
28135 else
28136 dev_kfree_skb_any(hb);
28137 - atomic_inc(&vcc->stats->rx_drop);
28138 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28139 }
28140 else
28141 {
28142 @@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_
28143 #endif /* NS_USE_DESTRUCTORS */
28144 __net_timestamp(hb);
28145 vcc->push(vcc, hb);
28146 - atomic_inc(&vcc->stats->rx);
28147 + atomic_inc_unchecked(&vcc->stats->rx);
28148 }
28149 }
28150
28151 diff -urNp linux-2.6.32.46/drivers/atm/solos-pci.c linux-2.6.32.46/drivers/atm/solos-pci.c
28152 --- linux-2.6.32.46/drivers/atm/solos-pci.c 2011-04-17 17:00:52.000000000 -0400
28153 +++ linux-2.6.32.46/drivers/atm/solos-pci.c 2011-05-16 21:46:57.000000000 -0400
28154 @@ -708,7 +708,7 @@ void solos_bh(unsigned long card_arg)
28155 }
28156 atm_charge(vcc, skb->truesize);
28157 vcc->push(vcc, skb);
28158 - atomic_inc(&vcc->stats->rx);
28159 + atomic_inc_unchecked(&vcc->stats->rx);
28160 break;
28161
28162 case PKT_STATUS:
28163 @@ -914,6 +914,8 @@ static int print_buffer(struct sk_buff *
28164 char msg[500];
28165 char item[10];
28166
28167 + pax_track_stack();
28168 +
28169 len = buf->len;
28170 for (i = 0; i < len; i++){
28171 if(i % 8 == 0)
28172 @@ -1023,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_car
28173 vcc = SKB_CB(oldskb)->vcc;
28174
28175 if (vcc) {
28176 - atomic_inc(&vcc->stats->tx);
28177 + atomic_inc_unchecked(&vcc->stats->tx);
28178 solos_pop(vcc, oldskb);
28179 } else
28180 dev_kfree_skb_irq(oldskb);
28181 diff -urNp linux-2.6.32.46/drivers/atm/suni.c linux-2.6.32.46/drivers/atm/suni.c
28182 --- linux-2.6.32.46/drivers/atm/suni.c 2011-03-27 14:31:47.000000000 -0400
28183 +++ linux-2.6.32.46/drivers/atm/suni.c 2011-04-17 15:56:46.000000000 -0400
28184 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28185
28186
28187 #define ADD_LIMITED(s,v) \
28188 - atomic_add((v),&stats->s); \
28189 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28190 + atomic_add_unchecked((v),&stats->s); \
28191 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28192
28193
28194 static void suni_hz(unsigned long from_timer)
28195 diff -urNp linux-2.6.32.46/drivers/atm/uPD98402.c linux-2.6.32.46/drivers/atm/uPD98402.c
28196 --- linux-2.6.32.46/drivers/atm/uPD98402.c 2011-03-27 14:31:47.000000000 -0400
28197 +++ linux-2.6.32.46/drivers/atm/uPD98402.c 2011-04-17 15:56:46.000000000 -0400
28198 @@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *d
28199 struct sonet_stats tmp;
28200 int error = 0;
28201
28202 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28203 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28204 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28205 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28206 if (zero && !error) {
28207 @@ -160,9 +160,9 @@ static int uPD98402_ioctl(struct atm_dev
28208
28209
28210 #define ADD_LIMITED(s,v) \
28211 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28212 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28213 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28214 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28215 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28216 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28217
28218
28219 static void stat_event(struct atm_dev *dev)
28220 @@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev
28221 if (reason & uPD98402_INT_PFM) stat_event(dev);
28222 if (reason & uPD98402_INT_PCO) {
28223 (void) GET(PCOCR); /* clear interrupt cause */
28224 - atomic_add(GET(HECCT),
28225 + atomic_add_unchecked(GET(HECCT),
28226 &PRIV(dev)->sonet_stats.uncorr_hcs);
28227 }
28228 if ((reason & uPD98402_INT_RFO) &&
28229 @@ -221,9 +221,9 @@ static int uPD98402_start(struct atm_dev
28230 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28231 uPD98402_INT_LOS),PIMR); /* enable them */
28232 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28233 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28234 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28235 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28236 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28237 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28238 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28239 return 0;
28240 }
28241
28242 diff -urNp linux-2.6.32.46/drivers/atm/zatm.c linux-2.6.32.46/drivers/atm/zatm.c
28243 --- linux-2.6.32.46/drivers/atm/zatm.c 2011-03-27 14:31:47.000000000 -0400
28244 +++ linux-2.6.32.46/drivers/atm/zatm.c 2011-04-17 15:56:46.000000000 -0400
28245 @@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
28246 }
28247 if (!size) {
28248 dev_kfree_skb_irq(skb);
28249 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28250 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28251 continue;
28252 }
28253 if (!atm_charge(vcc,skb->truesize)) {
28254 @@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
28255 skb->len = size;
28256 ATM_SKB(skb)->vcc = vcc;
28257 vcc->push(vcc,skb);
28258 - atomic_inc(&vcc->stats->rx);
28259 + atomic_inc_unchecked(&vcc->stats->rx);
28260 }
28261 zout(pos & 0xffff,MTA(mbx));
28262 #if 0 /* probably a stupid idea */
28263 @@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
28264 skb_queue_head(&zatm_vcc->backlog,skb);
28265 break;
28266 }
28267 - atomic_inc(&vcc->stats->tx);
28268 + atomic_inc_unchecked(&vcc->stats->tx);
28269 wake_up(&zatm_vcc->tx_wait);
28270 }
28271
28272 diff -urNp linux-2.6.32.46/drivers/base/bus.c linux-2.6.32.46/drivers/base/bus.c
28273 --- linux-2.6.32.46/drivers/base/bus.c 2011-03-27 14:31:47.000000000 -0400
28274 +++ linux-2.6.32.46/drivers/base/bus.c 2011-04-17 15:56:46.000000000 -0400
28275 @@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kob
28276 return ret;
28277 }
28278
28279 -static struct sysfs_ops driver_sysfs_ops = {
28280 +static const struct sysfs_ops driver_sysfs_ops = {
28281 .show = drv_attr_show,
28282 .store = drv_attr_store,
28283 };
28284 @@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kob
28285 return ret;
28286 }
28287
28288 -static struct sysfs_ops bus_sysfs_ops = {
28289 +static const struct sysfs_ops bus_sysfs_ops = {
28290 .show = bus_attr_show,
28291 .store = bus_attr_store,
28292 };
28293 @@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset
28294 return 0;
28295 }
28296
28297 -static struct kset_uevent_ops bus_uevent_ops = {
28298 +static const struct kset_uevent_ops bus_uevent_ops = {
28299 .filter = bus_uevent_filter,
28300 };
28301
28302 diff -urNp linux-2.6.32.46/drivers/base/class.c linux-2.6.32.46/drivers/base/class.c
28303 --- linux-2.6.32.46/drivers/base/class.c 2011-03-27 14:31:47.000000000 -0400
28304 +++ linux-2.6.32.46/drivers/base/class.c 2011-04-17 15:56:46.000000000 -0400
28305 @@ -63,7 +63,7 @@ static void class_release(struct kobject
28306 kfree(cp);
28307 }
28308
28309 -static struct sysfs_ops class_sysfs_ops = {
28310 +static const struct sysfs_ops class_sysfs_ops = {
28311 .show = class_attr_show,
28312 .store = class_attr_store,
28313 };
28314 diff -urNp linux-2.6.32.46/drivers/base/core.c linux-2.6.32.46/drivers/base/core.c
28315 --- linux-2.6.32.46/drivers/base/core.c 2011-03-27 14:31:47.000000000 -0400
28316 +++ linux-2.6.32.46/drivers/base/core.c 2011-04-17 15:56:46.000000000 -0400
28317 @@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kob
28318 return ret;
28319 }
28320
28321 -static struct sysfs_ops dev_sysfs_ops = {
28322 +static const struct sysfs_ops dev_sysfs_ops = {
28323 .show = dev_attr_show,
28324 .store = dev_attr_store,
28325 };
28326 @@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset,
28327 return retval;
28328 }
28329
28330 -static struct kset_uevent_ops device_uevent_ops = {
28331 +static const struct kset_uevent_ops device_uevent_ops = {
28332 .filter = dev_uevent_filter,
28333 .name = dev_uevent_name,
28334 .uevent = dev_uevent,
28335 diff -urNp linux-2.6.32.46/drivers/base/memory.c linux-2.6.32.46/drivers/base/memory.c
28336 --- linux-2.6.32.46/drivers/base/memory.c 2011-03-27 14:31:47.000000000 -0400
28337 +++ linux-2.6.32.46/drivers/base/memory.c 2011-04-17 15:56:46.000000000 -0400
28338 @@ -44,7 +44,7 @@ static int memory_uevent(struct kset *ks
28339 return retval;
28340 }
28341
28342 -static struct kset_uevent_ops memory_uevent_ops = {
28343 +static const struct kset_uevent_ops memory_uevent_ops = {
28344 .name = memory_uevent_name,
28345 .uevent = memory_uevent,
28346 };
28347 diff -urNp linux-2.6.32.46/drivers/base/sys.c linux-2.6.32.46/drivers/base/sys.c
28348 --- linux-2.6.32.46/drivers/base/sys.c 2011-03-27 14:31:47.000000000 -0400
28349 +++ linux-2.6.32.46/drivers/base/sys.c 2011-04-17 15:56:46.000000000 -0400
28350 @@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struc
28351 return -EIO;
28352 }
28353
28354 -static struct sysfs_ops sysfs_ops = {
28355 +static const struct sysfs_ops sysfs_ops = {
28356 .show = sysdev_show,
28357 .store = sysdev_store,
28358 };
28359 @@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct
28360 return -EIO;
28361 }
28362
28363 -static struct sysfs_ops sysfs_class_ops = {
28364 +static const struct sysfs_ops sysfs_class_ops = {
28365 .show = sysdev_class_show,
28366 .store = sysdev_class_store,
28367 };
28368 diff -urNp linux-2.6.32.46/drivers/block/DAC960.c linux-2.6.32.46/drivers/block/DAC960.c
28369 --- linux-2.6.32.46/drivers/block/DAC960.c 2011-03-27 14:31:47.000000000 -0400
28370 +++ linux-2.6.32.46/drivers/block/DAC960.c 2011-05-16 21:46:57.000000000 -0400
28371 @@ -1973,6 +1973,8 @@ static bool DAC960_V1_ReadDeviceConfigur
28372 unsigned long flags;
28373 int Channel, TargetID;
28374
28375 + pax_track_stack();
28376 +
28377 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
28378 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
28379 sizeof(DAC960_SCSI_Inquiry_T) +
28380 diff -urNp linux-2.6.32.46/drivers/block/cciss.c linux-2.6.32.46/drivers/block/cciss.c
28381 --- linux-2.6.32.46/drivers/block/cciss.c 2011-03-27 14:31:47.000000000 -0400
28382 +++ linux-2.6.32.46/drivers/block/cciss.c 2011-08-05 20:33:55.000000000 -0400
28383 @@ -1011,6 +1011,8 @@ static int cciss_ioctl32_passthru(struct
28384 int err;
28385 u32 cp;
28386
28387 + memset(&arg64, 0, sizeof(arg64));
28388 +
28389 err = 0;
28390 err |=
28391 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28392 @@ -2852,7 +2854,7 @@ static unsigned long pollcomplete(int ct
28393 /* Wait (up to 20 seconds) for a command to complete */
28394
28395 for (i = 20 * HZ; i > 0; i--) {
28396 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28397 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28398 if (done == FIFO_EMPTY)
28399 schedule_timeout_uninterruptible(1);
28400 else
28401 @@ -2876,7 +2878,7 @@ static int sendcmd_core(ctlr_info_t *h,
28402 resend_cmd1:
28403
28404 /* Disable interrupt on the board. */
28405 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28406 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28407
28408 /* Make sure there is room in the command FIFO */
28409 /* Actually it should be completely empty at this time */
28410 @@ -2884,13 +2886,13 @@ resend_cmd1:
28411 /* tape side of the driver. */
28412 for (i = 200000; i > 0; i--) {
28413 /* if fifo isn't full go */
28414 - if (!(h->access.fifo_full(h)))
28415 + if (!(h->access->fifo_full(h)))
28416 break;
28417 udelay(10);
28418 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
28419 " waiting!\n", h->ctlr);
28420 }
28421 - h->access.submit_command(h, c); /* Send the cmd */
28422 + h->access->submit_command(h, c); /* Send the cmd */
28423 do {
28424 complete = pollcomplete(h->ctlr);
28425
28426 @@ -3023,7 +3025,7 @@ static void start_io(ctlr_info_t *h)
28427 while (!hlist_empty(&h->reqQ)) {
28428 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
28429 /* can't do anything if fifo is full */
28430 - if ((h->access.fifo_full(h))) {
28431 + if ((h->access->fifo_full(h))) {
28432 printk(KERN_WARNING "cciss: fifo full\n");
28433 break;
28434 }
28435 @@ -3033,7 +3035,7 @@ static void start_io(ctlr_info_t *h)
28436 h->Qdepth--;
28437
28438 /* Tell the controller execute command */
28439 - h->access.submit_command(h, c);
28440 + h->access->submit_command(h, c);
28441
28442 /* Put job onto the completed Q */
28443 addQ(&h->cmpQ, c);
28444 @@ -3393,17 +3395,17 @@ startio:
28445
28446 static inline unsigned long get_next_completion(ctlr_info_t *h)
28447 {
28448 - return h->access.command_completed(h);
28449 + return h->access->command_completed(h);
28450 }
28451
28452 static inline int interrupt_pending(ctlr_info_t *h)
28453 {
28454 - return h->access.intr_pending(h);
28455 + return h->access->intr_pending(h);
28456 }
28457
28458 static inline long interrupt_not_for_us(ctlr_info_t *h)
28459 {
28460 - return (((h->access.intr_pending(h) == 0) ||
28461 + return (((h->access->intr_pending(h) == 0) ||
28462 (h->interrupts_enabled == 0)));
28463 }
28464
28465 @@ -3892,7 +3894,7 @@ static int __devinit cciss_pci_init(ctlr
28466 */
28467 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
28468 c->product_name = products[prod_index].product_name;
28469 - c->access = *(products[prod_index].access);
28470 + c->access = products[prod_index].access;
28471 c->nr_cmds = c->max_commands - 4;
28472 if ((readb(&c->cfgtable->Signature[0]) != 'C') ||
28473 (readb(&c->cfgtable->Signature[1]) != 'I') ||
28474 @@ -4291,7 +4293,7 @@ static int __devinit cciss_init_one(stru
28475 }
28476
28477 /* make sure the board interrupts are off */
28478 - hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
28479 + hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_OFF);
28480 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
28481 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) {
28482 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
28483 @@ -4341,7 +4343,7 @@ static int __devinit cciss_init_one(stru
28484 cciss_scsi_setup(i);
28485
28486 /* Turn the interrupts on so we can service requests */
28487 - hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
28488 + hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_ON);
28489
28490 /* Get the firmware version */
28491 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28492 diff -urNp linux-2.6.32.46/drivers/block/cciss.h linux-2.6.32.46/drivers/block/cciss.h
28493 --- linux-2.6.32.46/drivers/block/cciss.h 2011-08-09 18:35:28.000000000 -0400
28494 +++ linux-2.6.32.46/drivers/block/cciss.h 2011-08-09 18:33:59.000000000 -0400
28495 @@ -90,7 +90,7 @@ struct ctlr_info
28496 // information about each logical volume
28497 drive_info_struct *drv[CISS_MAX_LUN];
28498
28499 - struct access_method access;
28500 + struct access_method *access;
28501
28502 /* queue and queue Info */
28503 struct hlist_head reqQ;
28504 diff -urNp linux-2.6.32.46/drivers/block/cpqarray.c linux-2.6.32.46/drivers/block/cpqarray.c
28505 --- linux-2.6.32.46/drivers/block/cpqarray.c 2011-03-27 14:31:47.000000000 -0400
28506 +++ linux-2.6.32.46/drivers/block/cpqarray.c 2011-08-05 20:33:55.000000000 -0400
28507 @@ -402,7 +402,7 @@ static int __init cpqarray_register_ctlr
28508 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28509 goto Enomem4;
28510 }
28511 - hba[i]->access.set_intr_mask(hba[i], 0);
28512 + hba[i]->access->set_intr_mask(hba[i], 0);
28513 if (request_irq(hba[i]->intr, do_ida_intr,
28514 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28515 {
28516 @@ -460,7 +460,7 @@ static int __init cpqarray_register_ctlr
28517 add_timer(&hba[i]->timer);
28518
28519 /* Enable IRQ now that spinlock and rate limit timer are set up */
28520 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28521 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28522
28523 for(j=0; j<NWD; j++) {
28524 struct gendisk *disk = ida_gendisk[i][j];
28525 @@ -695,7 +695,7 @@ DBGINFO(
28526 for(i=0; i<NR_PRODUCTS; i++) {
28527 if (board_id == products[i].board_id) {
28528 c->product_name = products[i].product_name;
28529 - c->access = *(products[i].access);
28530 + c->access = products[i].access;
28531 break;
28532 }
28533 }
28534 @@ -793,7 +793,7 @@ static int __init cpqarray_eisa_detect(v
28535 hba[ctlr]->intr = intr;
28536 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28537 hba[ctlr]->product_name = products[j].product_name;
28538 - hba[ctlr]->access = *(products[j].access);
28539 + hba[ctlr]->access = products[j].access;
28540 hba[ctlr]->ctlr = ctlr;
28541 hba[ctlr]->board_id = board_id;
28542 hba[ctlr]->pci_dev = NULL; /* not PCI */
28543 @@ -896,6 +896,8 @@ static void do_ida_request(struct reques
28544 struct scatterlist tmp_sg[SG_MAX];
28545 int i, dir, seg;
28546
28547 + pax_track_stack();
28548 +
28549 if (blk_queue_plugged(q))
28550 goto startio;
28551
28552 @@ -968,7 +970,7 @@ static void start_io(ctlr_info_t *h)
28553
28554 while((c = h->reqQ) != NULL) {
28555 /* Can't do anything if we're busy */
28556 - if (h->access.fifo_full(h) == 0)
28557 + if (h->access->fifo_full(h) == 0)
28558 return;
28559
28560 /* Get the first entry from the request Q */
28561 @@ -976,7 +978,7 @@ static void start_io(ctlr_info_t *h)
28562 h->Qdepth--;
28563
28564 /* Tell the controller to do our bidding */
28565 - h->access.submit_command(h, c);
28566 + h->access->submit_command(h, c);
28567
28568 /* Get onto the completion Q */
28569 addQ(&h->cmpQ, c);
28570 @@ -1038,7 +1040,7 @@ static irqreturn_t do_ida_intr(int irq,
28571 unsigned long flags;
28572 __u32 a,a1;
28573
28574 - istat = h->access.intr_pending(h);
28575 + istat = h->access->intr_pending(h);
28576 /* Is this interrupt for us? */
28577 if (istat == 0)
28578 return IRQ_NONE;
28579 @@ -1049,7 +1051,7 @@ static irqreturn_t do_ida_intr(int irq,
28580 */
28581 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28582 if (istat & FIFO_NOT_EMPTY) {
28583 - while((a = h->access.command_completed(h))) {
28584 + while((a = h->access->command_completed(h))) {
28585 a1 = a; a &= ~3;
28586 if ((c = h->cmpQ) == NULL)
28587 {
28588 @@ -1434,11 +1436,11 @@ static int sendcmd(
28589 /*
28590 * Disable interrupt
28591 */
28592 - info_p->access.set_intr_mask(info_p, 0);
28593 + info_p->access->set_intr_mask(info_p, 0);
28594 /* Make sure there is room in the command FIFO */
28595 /* Actually it should be completely empty at this time. */
28596 for (i = 200000; i > 0; i--) {
28597 - temp = info_p->access.fifo_full(info_p);
28598 + temp = info_p->access->fifo_full(info_p);
28599 if (temp != 0) {
28600 break;
28601 }
28602 @@ -1451,7 +1453,7 @@ DBG(
28603 /*
28604 * Send the cmd
28605 */
28606 - info_p->access.submit_command(info_p, c);
28607 + info_p->access->submit_command(info_p, c);
28608 complete = pollcomplete(ctlr);
28609
28610 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28611 @@ -1534,9 +1536,9 @@ static int revalidate_allvol(ctlr_info_t
28612 * we check the new geometry. Then turn interrupts back on when
28613 * we're done.
28614 */
28615 - host->access.set_intr_mask(host, 0);
28616 + host->access->set_intr_mask(host, 0);
28617 getgeometry(ctlr);
28618 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28619 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28620
28621 for(i=0; i<NWD; i++) {
28622 struct gendisk *disk = ida_gendisk[ctlr][i];
28623 @@ -1576,7 +1578,7 @@ static int pollcomplete(int ctlr)
28624 /* Wait (up to 2 seconds) for a command to complete */
28625
28626 for (i = 200000; i > 0; i--) {
28627 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28628 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28629 if (done == 0) {
28630 udelay(10); /* a short fixed delay */
28631 } else
28632 diff -urNp linux-2.6.32.46/drivers/block/cpqarray.h linux-2.6.32.46/drivers/block/cpqarray.h
28633 --- linux-2.6.32.46/drivers/block/cpqarray.h 2011-03-27 14:31:47.000000000 -0400
28634 +++ linux-2.6.32.46/drivers/block/cpqarray.h 2011-08-05 20:33:55.000000000 -0400
28635 @@ -99,7 +99,7 @@ struct ctlr_info {
28636 drv_info_t drv[NWD];
28637 struct proc_dir_entry *proc;
28638
28639 - struct access_method access;
28640 + struct access_method *access;
28641
28642 cmdlist_t *reqQ;
28643 cmdlist_t *cmpQ;
28644 diff -urNp linux-2.6.32.46/drivers/block/loop.c linux-2.6.32.46/drivers/block/loop.c
28645 --- linux-2.6.32.46/drivers/block/loop.c 2011-06-25 12:55:34.000000000 -0400
28646 +++ linux-2.6.32.46/drivers/block/loop.c 2011-10-06 09:37:14.000000000 -0400
28647 @@ -282,7 +282,7 @@ static int __do_lo_send_write(struct fil
28648 mm_segment_t old_fs = get_fs();
28649
28650 set_fs(get_ds());
28651 - bw = file->f_op->write(file, buf, len, &pos);
28652 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
28653 set_fs(old_fs);
28654 if (likely(bw == len))
28655 return 0;
28656 diff -urNp linux-2.6.32.46/drivers/block/nbd.c linux-2.6.32.46/drivers/block/nbd.c
28657 --- linux-2.6.32.46/drivers/block/nbd.c 2011-06-25 12:55:34.000000000 -0400
28658 +++ linux-2.6.32.46/drivers/block/nbd.c 2011-06-25 12:56:37.000000000 -0400
28659 @@ -155,6 +155,8 @@ static int sock_xmit(struct nbd_device *
28660 struct kvec iov;
28661 sigset_t blocked, oldset;
28662
28663 + pax_track_stack();
28664 +
28665 if (unlikely(!sock)) {
28666 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
28667 lo->disk->disk_name, (send ? "send" : "recv"));
28668 @@ -569,6 +571,8 @@ static void do_nbd_request(struct reques
28669 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
28670 unsigned int cmd, unsigned long arg)
28671 {
28672 + pax_track_stack();
28673 +
28674 switch (cmd) {
28675 case NBD_DISCONNECT: {
28676 struct request sreq;
28677 diff -urNp linux-2.6.32.46/drivers/block/pktcdvd.c linux-2.6.32.46/drivers/block/pktcdvd.c
28678 --- linux-2.6.32.46/drivers/block/pktcdvd.c 2011-03-27 14:31:47.000000000 -0400
28679 +++ linux-2.6.32.46/drivers/block/pktcdvd.c 2011-04-17 15:56:46.000000000 -0400
28680 @@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kob
28681 return len;
28682 }
28683
28684 -static struct sysfs_ops kobj_pkt_ops = {
28685 +static const struct sysfs_ops kobj_pkt_ops = {
28686 .show = kobj_pkt_show,
28687 .store = kobj_pkt_store
28688 };
28689 diff -urNp linux-2.6.32.46/drivers/char/Kconfig linux-2.6.32.46/drivers/char/Kconfig
28690 --- linux-2.6.32.46/drivers/char/Kconfig 2011-03-27 14:31:47.000000000 -0400
28691 +++ linux-2.6.32.46/drivers/char/Kconfig 2011-04-18 19:20:15.000000000 -0400
28692 @@ -90,7 +90,8 @@ config VT_HW_CONSOLE_BINDING
28693
28694 config DEVKMEM
28695 bool "/dev/kmem virtual device support"
28696 - default y
28697 + default n
28698 + depends on !GRKERNSEC_KMEM
28699 help
28700 Say Y here if you want to support the /dev/kmem device. The
28701 /dev/kmem device is rarely used, but can be used for certain
28702 @@ -1114,6 +1115,7 @@ config DEVPORT
28703 bool
28704 depends on !M68K
28705 depends on ISA || PCI
28706 + depends on !GRKERNSEC_KMEM
28707 default y
28708
28709 source "drivers/s390/char/Kconfig"
28710 diff -urNp linux-2.6.32.46/drivers/char/agp/frontend.c linux-2.6.32.46/drivers/char/agp/frontend.c
28711 --- linux-2.6.32.46/drivers/char/agp/frontend.c 2011-03-27 14:31:47.000000000 -0400
28712 +++ linux-2.6.32.46/drivers/char/agp/frontend.c 2011-04-17 15:56:46.000000000 -0400
28713 @@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag
28714 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
28715 return -EFAULT;
28716
28717 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
28718 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
28719 return -EFAULT;
28720
28721 client = agp_find_client_by_pid(reserve.pid);
28722 diff -urNp linux-2.6.32.46/drivers/char/briq_panel.c linux-2.6.32.46/drivers/char/briq_panel.c
28723 --- linux-2.6.32.46/drivers/char/briq_panel.c 2011-03-27 14:31:47.000000000 -0400
28724 +++ linux-2.6.32.46/drivers/char/briq_panel.c 2011-04-18 19:48:57.000000000 -0400
28725 @@ -10,6 +10,7 @@
28726 #include <linux/types.h>
28727 #include <linux/errno.h>
28728 #include <linux/tty.h>
28729 +#include <linux/mutex.h>
28730 #include <linux/timer.h>
28731 #include <linux/kernel.h>
28732 #include <linux/wait.h>
28733 @@ -36,6 +37,7 @@ static int vfd_is_open;
28734 static unsigned char vfd[40];
28735 static int vfd_cursor;
28736 static unsigned char ledpb, led;
28737 +static DEFINE_MUTEX(vfd_mutex);
28738
28739 static void update_vfd(void)
28740 {
28741 @@ -142,12 +144,15 @@ static ssize_t briq_panel_write(struct f
28742 if (!vfd_is_open)
28743 return -EBUSY;
28744
28745 + mutex_lock(&vfd_mutex);
28746 for (;;) {
28747 char c;
28748 if (!indx)
28749 break;
28750 - if (get_user(c, buf))
28751 + if (get_user(c, buf)) {
28752 + mutex_unlock(&vfd_mutex);
28753 return -EFAULT;
28754 + }
28755 if (esc) {
28756 set_led(c);
28757 esc = 0;
28758 @@ -177,6 +182,7 @@ static ssize_t briq_panel_write(struct f
28759 buf++;
28760 }
28761 update_vfd();
28762 + mutex_unlock(&vfd_mutex);
28763
28764 return len;
28765 }
28766 diff -urNp linux-2.6.32.46/drivers/char/genrtc.c linux-2.6.32.46/drivers/char/genrtc.c
28767 --- linux-2.6.32.46/drivers/char/genrtc.c 2011-03-27 14:31:47.000000000 -0400
28768 +++ linux-2.6.32.46/drivers/char/genrtc.c 2011-04-18 19:45:42.000000000 -0400
28769 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct inode *i
28770 switch (cmd) {
28771
28772 case RTC_PLL_GET:
28773 + memset(&pll, 0, sizeof(pll));
28774 if (get_rtc_pll(&pll))
28775 return -EINVAL;
28776 else
28777 diff -urNp linux-2.6.32.46/drivers/char/hpet.c linux-2.6.32.46/drivers/char/hpet.c
28778 --- linux-2.6.32.46/drivers/char/hpet.c 2011-03-27 14:31:47.000000000 -0400
28779 +++ linux-2.6.32.46/drivers/char/hpet.c 2011-04-23 12:56:11.000000000 -0400
28780 @@ -430,7 +430,7 @@ static int hpet_release(struct inode *in
28781 return 0;
28782 }
28783
28784 -static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
28785 +static int hpet_ioctl_common(struct hpet_dev *, unsigned int, unsigned long, int);
28786
28787 static int
28788 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
28789 @@ -565,7 +565,7 @@ static inline unsigned long hpet_time_di
28790 }
28791
28792 static int
28793 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
28794 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, int kernel)
28795 {
28796 struct hpet_timer __iomem *timer;
28797 struct hpet __iomem *hpet;
28798 @@ -608,11 +608,11 @@ hpet_ioctl_common(struct hpet_dev *devp,
28799 {
28800 struct hpet_info info;
28801
28802 + memset(&info, 0, sizeof(info));
28803 +
28804 if (devp->hd_ireqfreq)
28805 info.hi_ireqfreq =
28806 hpet_time_div(hpetp, devp->hd_ireqfreq);
28807 - else
28808 - info.hi_ireqfreq = 0;
28809 info.hi_flags =
28810 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
28811 info.hi_hpet = hpetp->hp_which;
28812 diff -urNp linux-2.6.32.46/drivers/char/hvc_beat.c linux-2.6.32.46/drivers/char/hvc_beat.c
28813 --- linux-2.6.32.46/drivers/char/hvc_beat.c 2011-03-27 14:31:47.000000000 -0400
28814 +++ linux-2.6.32.46/drivers/char/hvc_beat.c 2011-04-17 15:56:46.000000000 -0400
28815 @@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t v
28816 return cnt;
28817 }
28818
28819 -static struct hv_ops hvc_beat_get_put_ops = {
28820 +static const struct hv_ops hvc_beat_get_put_ops = {
28821 .get_chars = hvc_beat_get_chars,
28822 .put_chars = hvc_beat_put_chars,
28823 };
28824 diff -urNp linux-2.6.32.46/drivers/char/hvc_console.c linux-2.6.32.46/drivers/char/hvc_console.c
28825 --- linux-2.6.32.46/drivers/char/hvc_console.c 2011-03-27 14:31:47.000000000 -0400
28826 +++ linux-2.6.32.46/drivers/char/hvc_console.c 2011-04-17 15:56:46.000000000 -0400
28827 @@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_ind
28828 * console interfaces but can still be used as a tty device. This has to be
28829 * static because kmalloc will not work during early console init.
28830 */
28831 -static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
28832 +static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
28833 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
28834 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
28835
28836 @@ -247,7 +247,7 @@ static void destroy_hvc_struct(struct kr
28837 * vty adapters do NOT get an hvc_instantiate() callback since they
28838 * appear after early console init.
28839 */
28840 -int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
28841 +int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
28842 {
28843 struct hvc_struct *hp;
28844
28845 @@ -756,7 +756,7 @@ static const struct tty_operations hvc_o
28846 };
28847
28848 struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
28849 - struct hv_ops *ops, int outbuf_size)
28850 + const struct hv_ops *ops, int outbuf_size)
28851 {
28852 struct hvc_struct *hp;
28853 int i;
28854 diff -urNp linux-2.6.32.46/drivers/char/hvc_console.h linux-2.6.32.46/drivers/char/hvc_console.h
28855 --- linux-2.6.32.46/drivers/char/hvc_console.h 2011-03-27 14:31:47.000000000 -0400
28856 +++ linux-2.6.32.46/drivers/char/hvc_console.h 2011-04-17 15:56:46.000000000 -0400
28857 @@ -55,7 +55,7 @@ struct hvc_struct {
28858 int outbuf_size;
28859 int n_outbuf;
28860 uint32_t vtermno;
28861 - struct hv_ops *ops;
28862 + const struct hv_ops *ops;
28863 int irq_requested;
28864 int data;
28865 struct winsize ws;
28866 @@ -76,11 +76,11 @@ struct hv_ops {
28867 };
28868
28869 /* Register a vterm and a slot index for use as a console (console_init) */
28870 -extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
28871 +extern int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops);
28872
28873 /* register a vterm for hvc tty operation (module_init or hotplug add) */
28874 extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
28875 - struct hv_ops *ops, int outbuf_size);
28876 + const struct hv_ops *ops, int outbuf_size);
28877 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
28878 extern int hvc_remove(struct hvc_struct *hp);
28879
28880 diff -urNp linux-2.6.32.46/drivers/char/hvc_iseries.c linux-2.6.32.46/drivers/char/hvc_iseries.c
28881 --- linux-2.6.32.46/drivers/char/hvc_iseries.c 2011-03-27 14:31:47.000000000 -0400
28882 +++ linux-2.6.32.46/drivers/char/hvc_iseries.c 2011-04-17 15:56:46.000000000 -0400
28883 @@ -197,7 +197,7 @@ done:
28884 return sent;
28885 }
28886
28887 -static struct hv_ops hvc_get_put_ops = {
28888 +static const struct hv_ops hvc_get_put_ops = {
28889 .get_chars = get_chars,
28890 .put_chars = put_chars,
28891 .notifier_add = notifier_add_irq,
28892 diff -urNp linux-2.6.32.46/drivers/char/hvc_iucv.c linux-2.6.32.46/drivers/char/hvc_iucv.c
28893 --- linux-2.6.32.46/drivers/char/hvc_iucv.c 2011-03-27 14:31:47.000000000 -0400
28894 +++ linux-2.6.32.46/drivers/char/hvc_iucv.c 2011-04-17 15:56:46.000000000 -0400
28895 @@ -924,7 +924,7 @@ static int hvc_iucv_pm_restore_thaw(stru
28896
28897
28898 /* HVC operations */
28899 -static struct hv_ops hvc_iucv_ops = {
28900 +static const struct hv_ops hvc_iucv_ops = {
28901 .get_chars = hvc_iucv_get_chars,
28902 .put_chars = hvc_iucv_put_chars,
28903 .notifier_add = hvc_iucv_notifier_add,
28904 diff -urNp linux-2.6.32.46/drivers/char/hvc_rtas.c linux-2.6.32.46/drivers/char/hvc_rtas.c
28905 --- linux-2.6.32.46/drivers/char/hvc_rtas.c 2011-03-27 14:31:47.000000000 -0400
28906 +++ linux-2.6.32.46/drivers/char/hvc_rtas.c 2011-04-17 15:56:46.000000000 -0400
28907 @@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_
28908 return i;
28909 }
28910
28911 -static struct hv_ops hvc_rtas_get_put_ops = {
28912 +static const struct hv_ops hvc_rtas_get_put_ops = {
28913 .get_chars = hvc_rtas_read_console,
28914 .put_chars = hvc_rtas_write_console,
28915 };
28916 diff -urNp linux-2.6.32.46/drivers/char/hvc_udbg.c linux-2.6.32.46/drivers/char/hvc_udbg.c
28917 --- linux-2.6.32.46/drivers/char/hvc_udbg.c 2011-03-27 14:31:47.000000000 -0400
28918 +++ linux-2.6.32.46/drivers/char/hvc_udbg.c 2011-04-17 15:56:46.000000000 -0400
28919 @@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno
28920 return i;
28921 }
28922
28923 -static struct hv_ops hvc_udbg_ops = {
28924 +static const struct hv_ops hvc_udbg_ops = {
28925 .get_chars = hvc_udbg_get,
28926 .put_chars = hvc_udbg_put,
28927 };
28928 diff -urNp linux-2.6.32.46/drivers/char/hvc_vio.c linux-2.6.32.46/drivers/char/hvc_vio.c
28929 --- linux-2.6.32.46/drivers/char/hvc_vio.c 2011-03-27 14:31:47.000000000 -0400
28930 +++ linux-2.6.32.46/drivers/char/hvc_vio.c 2011-04-17 15:56:46.000000000 -0400
28931 @@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t v
28932 return got;
28933 }
28934
28935 -static struct hv_ops hvc_get_put_ops = {
28936 +static const struct hv_ops hvc_get_put_ops = {
28937 .get_chars = filtered_get_chars,
28938 .put_chars = hvc_put_chars,
28939 .notifier_add = notifier_add_irq,
28940 diff -urNp linux-2.6.32.46/drivers/char/hvc_xen.c linux-2.6.32.46/drivers/char/hvc_xen.c
28941 --- linux-2.6.32.46/drivers/char/hvc_xen.c 2011-03-27 14:31:47.000000000 -0400
28942 +++ linux-2.6.32.46/drivers/char/hvc_xen.c 2011-04-17 15:56:46.000000000 -0400
28943 @@ -120,7 +120,7 @@ static int read_console(uint32_t vtermno
28944 return recv;
28945 }
28946
28947 -static struct hv_ops hvc_ops = {
28948 +static const struct hv_ops hvc_ops = {
28949 .get_chars = read_console,
28950 .put_chars = write_console,
28951 .notifier_add = notifier_add_irq,
28952 diff -urNp linux-2.6.32.46/drivers/char/hvcs.c linux-2.6.32.46/drivers/char/hvcs.c
28953 --- linux-2.6.32.46/drivers/char/hvcs.c 2011-03-27 14:31:47.000000000 -0400
28954 +++ linux-2.6.32.46/drivers/char/hvcs.c 2011-04-17 15:56:46.000000000 -0400
28955 @@ -82,6 +82,7 @@
28956 #include <asm/hvcserver.h>
28957 #include <asm/uaccess.h>
28958 #include <asm/vio.h>
28959 +#include <asm/local.h>
28960
28961 /*
28962 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
28963 @@ -269,7 +270,7 @@ struct hvcs_struct {
28964 unsigned int index;
28965
28966 struct tty_struct *tty;
28967 - int open_count;
28968 + local_t open_count;
28969
28970 /*
28971 * Used to tell the driver kernel_thread what operations need to take
28972 @@ -419,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(st
28973
28974 spin_lock_irqsave(&hvcsd->lock, flags);
28975
28976 - if (hvcsd->open_count > 0) {
28977 + if (local_read(&hvcsd->open_count) > 0) {
28978 spin_unlock_irqrestore(&hvcsd->lock, flags);
28979 printk(KERN_INFO "HVCS: vterm state unchanged. "
28980 "The hvcs device node is still in use.\n");
28981 @@ -1135,7 +1136,7 @@ static int hvcs_open(struct tty_struct *
28982 if ((retval = hvcs_partner_connect(hvcsd)))
28983 goto error_release;
28984
28985 - hvcsd->open_count = 1;
28986 + local_set(&hvcsd->open_count, 1);
28987 hvcsd->tty = tty;
28988 tty->driver_data = hvcsd;
28989
28990 @@ -1169,7 +1170,7 @@ fast_open:
28991
28992 spin_lock_irqsave(&hvcsd->lock, flags);
28993 kref_get(&hvcsd->kref);
28994 - hvcsd->open_count++;
28995 + local_inc(&hvcsd->open_count);
28996 hvcsd->todo_mask |= HVCS_SCHED_READ;
28997 spin_unlock_irqrestore(&hvcsd->lock, flags);
28998
28999 @@ -1213,7 +1214,7 @@ static void hvcs_close(struct tty_struct
29000 hvcsd = tty->driver_data;
29001
29002 spin_lock_irqsave(&hvcsd->lock, flags);
29003 - if (--hvcsd->open_count == 0) {
29004 + if (local_dec_and_test(&hvcsd->open_count)) {
29005
29006 vio_disable_interrupts(hvcsd->vdev);
29007
29008 @@ -1239,10 +1240,10 @@ static void hvcs_close(struct tty_struct
29009 free_irq(irq, hvcsd);
29010 kref_put(&hvcsd->kref, destroy_hvcs_struct);
29011 return;
29012 - } else if (hvcsd->open_count < 0) {
29013 + } else if (local_read(&hvcsd->open_count) < 0) {
29014 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
29015 " is missmanaged.\n",
29016 - hvcsd->vdev->unit_address, hvcsd->open_count);
29017 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
29018 }
29019
29020 spin_unlock_irqrestore(&hvcsd->lock, flags);
29021 @@ -1258,7 +1259,7 @@ static void hvcs_hangup(struct tty_struc
29022
29023 spin_lock_irqsave(&hvcsd->lock, flags);
29024 /* Preserve this so that we know how many kref refs to put */
29025 - temp_open_count = hvcsd->open_count;
29026 + temp_open_count = local_read(&hvcsd->open_count);
29027
29028 /*
29029 * Don't kref put inside the spinlock because the destruction
29030 @@ -1273,7 +1274,7 @@ static void hvcs_hangup(struct tty_struc
29031 hvcsd->tty->driver_data = NULL;
29032 hvcsd->tty = NULL;
29033
29034 - hvcsd->open_count = 0;
29035 + local_set(&hvcsd->open_count, 0);
29036
29037 /* This will drop any buffered data on the floor which is OK in a hangup
29038 * scenario. */
29039 @@ -1344,7 +1345,7 @@ static int hvcs_write(struct tty_struct
29040 * the middle of a write operation? This is a crummy place to do this
29041 * but we want to keep it all in the spinlock.
29042 */
29043 - if (hvcsd->open_count <= 0) {
29044 + if (local_read(&hvcsd->open_count) <= 0) {
29045 spin_unlock_irqrestore(&hvcsd->lock, flags);
29046 return -ENODEV;
29047 }
29048 @@ -1418,7 +1419,7 @@ static int hvcs_write_room(struct tty_st
29049 {
29050 struct hvcs_struct *hvcsd = tty->driver_data;
29051
29052 - if (!hvcsd || hvcsd->open_count <= 0)
29053 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
29054 return 0;
29055
29056 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
29057 diff -urNp linux-2.6.32.46/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.32.46/drivers/char/ipmi/ipmi_msghandler.c
29058 --- linux-2.6.32.46/drivers/char/ipmi/ipmi_msghandler.c 2011-03-27 14:31:47.000000000 -0400
29059 +++ linux-2.6.32.46/drivers/char/ipmi/ipmi_msghandler.c 2011-05-16 21:46:57.000000000 -0400
29060 @@ -414,7 +414,7 @@ struct ipmi_smi {
29061 struct proc_dir_entry *proc_dir;
29062 char proc_dir_name[10];
29063
29064 - atomic_t stats[IPMI_NUM_STATS];
29065 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29066
29067 /*
29068 * run_to_completion duplicate of smb_info, smi_info
29069 @@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29070
29071
29072 #define ipmi_inc_stat(intf, stat) \
29073 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29074 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29075 #define ipmi_get_stat(intf, stat) \
29076 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29077 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29078
29079 static int is_lan_addr(struct ipmi_addr *addr)
29080 {
29081 @@ -2808,7 +2808,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
29082 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29083 init_waitqueue_head(&intf->waitq);
29084 for (i = 0; i < IPMI_NUM_STATS; i++)
29085 - atomic_set(&intf->stats[i], 0);
29086 + atomic_set_unchecked(&intf->stats[i], 0);
29087
29088 intf->proc_dir = NULL;
29089
29090 @@ -4160,6 +4160,8 @@ static void send_panic_events(char *str)
29091 struct ipmi_smi_msg smi_msg;
29092 struct ipmi_recv_msg recv_msg;
29093
29094 + pax_track_stack();
29095 +
29096 si = (struct ipmi_system_interface_addr *) &addr;
29097 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
29098 si->channel = IPMI_BMC_CHANNEL;
29099 diff -urNp linux-2.6.32.46/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.32.46/drivers/char/ipmi/ipmi_si_intf.c
29100 --- linux-2.6.32.46/drivers/char/ipmi/ipmi_si_intf.c 2011-03-27 14:31:47.000000000 -0400
29101 +++ linux-2.6.32.46/drivers/char/ipmi/ipmi_si_intf.c 2011-04-17 15:56:46.000000000 -0400
29102 @@ -277,7 +277,7 @@ struct smi_info {
29103 unsigned char slave_addr;
29104
29105 /* Counters and things for the proc filesystem. */
29106 - atomic_t stats[SI_NUM_STATS];
29107 + atomic_unchecked_t stats[SI_NUM_STATS];
29108
29109 struct task_struct *thread;
29110
29111 @@ -285,9 +285,9 @@ struct smi_info {
29112 };
29113
29114 #define smi_inc_stat(smi, stat) \
29115 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29116 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29117 #define smi_get_stat(smi, stat) \
29118 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29119 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29120
29121 #define SI_MAX_PARMS 4
29122
29123 @@ -2931,7 +2931,7 @@ static int try_smi_init(struct smi_info
29124 atomic_set(&new_smi->req_events, 0);
29125 new_smi->run_to_completion = 0;
29126 for (i = 0; i < SI_NUM_STATS; i++)
29127 - atomic_set(&new_smi->stats[i], 0);
29128 + atomic_set_unchecked(&new_smi->stats[i], 0);
29129
29130 new_smi->interrupt_disabled = 0;
29131 atomic_set(&new_smi->stop_operation, 0);
29132 diff -urNp linux-2.6.32.46/drivers/char/istallion.c linux-2.6.32.46/drivers/char/istallion.c
29133 --- linux-2.6.32.46/drivers/char/istallion.c 2011-03-27 14:31:47.000000000 -0400
29134 +++ linux-2.6.32.46/drivers/char/istallion.c 2011-05-16 21:46:57.000000000 -0400
29135 @@ -187,7 +187,6 @@ static struct ktermios stli_deftermios
29136 * re-used for each stats call.
29137 */
29138 static comstats_t stli_comstats;
29139 -static combrd_t stli_brdstats;
29140 static struct asystats stli_cdkstats;
29141
29142 /*****************************************************************************/
29143 @@ -4058,6 +4057,7 @@ static int stli_getbrdstats(combrd_t __u
29144 {
29145 struct stlibrd *brdp;
29146 unsigned int i;
29147 + combrd_t stli_brdstats;
29148
29149 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
29150 return -EFAULT;
29151 @@ -4269,6 +4269,8 @@ static int stli_getportstruct(struct stl
29152 struct stliport stli_dummyport;
29153 struct stliport *portp;
29154
29155 + pax_track_stack();
29156 +
29157 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
29158 return -EFAULT;
29159 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
29160 @@ -4291,6 +4293,8 @@ static int stli_getbrdstruct(struct stli
29161 struct stlibrd stli_dummybrd;
29162 struct stlibrd *brdp;
29163
29164 + pax_track_stack();
29165 +
29166 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
29167 return -EFAULT;
29168 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
29169 diff -urNp linux-2.6.32.46/drivers/char/keyboard.c linux-2.6.32.46/drivers/char/keyboard.c
29170 --- linux-2.6.32.46/drivers/char/keyboard.c 2011-03-27 14:31:47.000000000 -0400
29171 +++ linux-2.6.32.46/drivers/char/keyboard.c 2011-04-17 15:56:46.000000000 -0400
29172 @@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u
29173 kbd->kbdmode == VC_MEDIUMRAW) &&
29174 value != KVAL(K_SAK))
29175 return; /* SAK is allowed even in raw mode */
29176 +
29177 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
29178 + {
29179 + void *func = fn_handler[value];
29180 + if (func == fn_show_state || func == fn_show_ptregs ||
29181 + func == fn_show_mem)
29182 + return;
29183 + }
29184 +#endif
29185 +
29186 fn_handler[value](vc);
29187 }
29188
29189 @@ -1386,7 +1396,7 @@ static const struct input_device_id kbd_
29190 .evbit = { BIT_MASK(EV_SND) },
29191 },
29192
29193 - { }, /* Terminating entry */
29194 + { 0 }, /* Terminating entry */
29195 };
29196
29197 MODULE_DEVICE_TABLE(input, kbd_ids);
29198 diff -urNp linux-2.6.32.46/drivers/char/mem.c linux-2.6.32.46/drivers/char/mem.c
29199 --- linux-2.6.32.46/drivers/char/mem.c 2011-03-27 14:31:47.000000000 -0400
29200 +++ linux-2.6.32.46/drivers/char/mem.c 2011-04-17 15:56:46.000000000 -0400
29201 @@ -18,6 +18,7 @@
29202 #include <linux/raw.h>
29203 #include <linux/tty.h>
29204 #include <linux/capability.h>
29205 +#include <linux/security.h>
29206 #include <linux/ptrace.h>
29207 #include <linux/device.h>
29208 #include <linux/highmem.h>
29209 @@ -35,6 +36,10 @@
29210 # include <linux/efi.h>
29211 #endif
29212
29213 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29214 +extern struct file_operations grsec_fops;
29215 +#endif
29216 +
29217 static inline unsigned long size_inside_page(unsigned long start,
29218 unsigned long size)
29219 {
29220 @@ -102,9 +107,13 @@ static inline int range_is_allowed(unsig
29221
29222 while (cursor < to) {
29223 if (!devmem_is_allowed(pfn)) {
29224 +#ifdef CONFIG_GRKERNSEC_KMEM
29225 + gr_handle_mem_readwrite(from, to);
29226 +#else
29227 printk(KERN_INFO
29228 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29229 current->comm, from, to);
29230 +#endif
29231 return 0;
29232 }
29233 cursor += PAGE_SIZE;
29234 @@ -112,6 +121,11 @@ static inline int range_is_allowed(unsig
29235 }
29236 return 1;
29237 }
29238 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29239 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29240 +{
29241 + return 0;
29242 +}
29243 #else
29244 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29245 {
29246 @@ -155,6 +169,8 @@ static ssize_t read_mem(struct file * fi
29247 #endif
29248
29249 while (count > 0) {
29250 + char *temp;
29251 +
29252 /*
29253 * Handle first page in case it's not aligned
29254 */
29255 @@ -177,11 +193,31 @@ static ssize_t read_mem(struct file * fi
29256 if (!ptr)
29257 return -EFAULT;
29258
29259 - if (copy_to_user(buf, ptr, sz)) {
29260 +#ifdef CONFIG_PAX_USERCOPY
29261 + temp = kmalloc(sz, GFP_KERNEL);
29262 + if (!temp) {
29263 + unxlate_dev_mem_ptr(p, ptr);
29264 + return -ENOMEM;
29265 + }
29266 + memcpy(temp, ptr, sz);
29267 +#else
29268 + temp = ptr;
29269 +#endif
29270 +
29271 + if (copy_to_user(buf, temp, sz)) {
29272 +
29273 +#ifdef CONFIG_PAX_USERCOPY
29274 + kfree(temp);
29275 +#endif
29276 +
29277 unxlate_dev_mem_ptr(p, ptr);
29278 return -EFAULT;
29279 }
29280
29281 +#ifdef CONFIG_PAX_USERCOPY
29282 + kfree(temp);
29283 +#endif
29284 +
29285 unxlate_dev_mem_ptr(p, ptr);
29286
29287 buf += sz;
29288 @@ -419,9 +455,8 @@ static ssize_t read_kmem(struct file *fi
29289 size_t count, loff_t *ppos)
29290 {
29291 unsigned long p = *ppos;
29292 - ssize_t low_count, read, sz;
29293 + ssize_t low_count, read, sz, err = 0;
29294 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29295 - int err = 0;
29296
29297 read = 0;
29298 if (p < (unsigned long) high_memory) {
29299 @@ -444,6 +479,8 @@ static ssize_t read_kmem(struct file *fi
29300 }
29301 #endif
29302 while (low_count > 0) {
29303 + char *temp;
29304 +
29305 sz = size_inside_page(p, low_count);
29306
29307 /*
29308 @@ -453,7 +490,22 @@ static ssize_t read_kmem(struct file *fi
29309 */
29310 kbuf = xlate_dev_kmem_ptr((char *)p);
29311
29312 - if (copy_to_user(buf, kbuf, sz))
29313 +#ifdef CONFIG_PAX_USERCOPY
29314 + temp = kmalloc(sz, GFP_KERNEL);
29315 + if (!temp)
29316 + return -ENOMEM;
29317 + memcpy(temp, kbuf, sz);
29318 +#else
29319 + temp = kbuf;
29320 +#endif
29321 +
29322 + err = copy_to_user(buf, temp, sz);
29323 +
29324 +#ifdef CONFIG_PAX_USERCOPY
29325 + kfree(temp);
29326 +#endif
29327 +
29328 + if (err)
29329 return -EFAULT;
29330 buf += sz;
29331 p += sz;
29332 @@ -889,6 +941,9 @@ static const struct memdev {
29333 #ifdef CONFIG_CRASH_DUMP
29334 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29335 #endif
29336 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29337 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29338 +#endif
29339 };
29340
29341 static int memory_open(struct inode *inode, struct file *filp)
29342 diff -urNp linux-2.6.32.46/drivers/char/pcmcia/ipwireless/tty.c linux-2.6.32.46/drivers/char/pcmcia/ipwireless/tty.c
29343 --- linux-2.6.32.46/drivers/char/pcmcia/ipwireless/tty.c 2011-03-27 14:31:47.000000000 -0400
29344 +++ linux-2.6.32.46/drivers/char/pcmcia/ipwireless/tty.c 2011-04-17 15:56:46.000000000 -0400
29345 @@ -29,6 +29,7 @@
29346 #include <linux/tty_driver.h>
29347 #include <linux/tty_flip.h>
29348 #include <linux/uaccess.h>
29349 +#include <asm/local.h>
29350
29351 #include "tty.h"
29352 #include "network.h"
29353 @@ -51,7 +52,7 @@ struct ipw_tty {
29354 int tty_type;
29355 struct ipw_network *network;
29356 struct tty_struct *linux_tty;
29357 - int open_count;
29358 + local_t open_count;
29359 unsigned int control_lines;
29360 struct mutex ipw_tty_mutex;
29361 int tx_bytes_queued;
29362 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
29363 mutex_unlock(&tty->ipw_tty_mutex);
29364 return -ENODEV;
29365 }
29366 - if (tty->open_count == 0)
29367 + if (local_read(&tty->open_count) == 0)
29368 tty->tx_bytes_queued = 0;
29369
29370 - tty->open_count++;
29371 + local_inc(&tty->open_count);
29372
29373 tty->linux_tty = linux_tty;
29374 linux_tty->driver_data = tty;
29375 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
29376
29377 static void do_ipw_close(struct ipw_tty *tty)
29378 {
29379 - tty->open_count--;
29380 -
29381 - if (tty->open_count == 0) {
29382 + if (local_dec_return(&tty->open_count) == 0) {
29383 struct tty_struct *linux_tty = tty->linux_tty;
29384
29385 if (linux_tty != NULL) {
29386 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
29387 return;
29388
29389 mutex_lock(&tty->ipw_tty_mutex);
29390 - if (tty->open_count == 0) {
29391 + if (local_read(&tty->open_count) == 0) {
29392 mutex_unlock(&tty->ipw_tty_mutex);
29393 return;
29394 }
29395 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
29396 return;
29397 }
29398
29399 - if (!tty->open_count) {
29400 + if (!local_read(&tty->open_count)) {
29401 mutex_unlock(&tty->ipw_tty_mutex);
29402 return;
29403 }
29404 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
29405 return -ENODEV;
29406
29407 mutex_lock(&tty->ipw_tty_mutex);
29408 - if (!tty->open_count) {
29409 + if (!local_read(&tty->open_count)) {
29410 mutex_unlock(&tty->ipw_tty_mutex);
29411 return -EINVAL;
29412 }
29413 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
29414 if (!tty)
29415 return -ENODEV;
29416
29417 - if (!tty->open_count)
29418 + if (!local_read(&tty->open_count))
29419 return -EINVAL;
29420
29421 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
29422 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
29423 if (!tty)
29424 return 0;
29425
29426 - if (!tty->open_count)
29427 + if (!local_read(&tty->open_count))
29428 return 0;
29429
29430 return tty->tx_bytes_queued;
29431 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
29432 if (!tty)
29433 return -ENODEV;
29434
29435 - if (!tty->open_count)
29436 + if (!local_read(&tty->open_count))
29437 return -EINVAL;
29438
29439 return get_control_lines(tty);
29440 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
29441 if (!tty)
29442 return -ENODEV;
29443
29444 - if (!tty->open_count)
29445 + if (!local_read(&tty->open_count))
29446 return -EINVAL;
29447
29448 return set_control_lines(tty, set, clear);
29449 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
29450 if (!tty)
29451 return -ENODEV;
29452
29453 - if (!tty->open_count)
29454 + if (!local_read(&tty->open_count))
29455 return -EINVAL;
29456
29457 /* FIXME: Exactly how is the tty object locked here .. */
29458 @@ -591,7 +590,7 @@ void ipwireless_tty_free(struct ipw_tty
29459 against a parallel ioctl etc */
29460 mutex_lock(&ttyj->ipw_tty_mutex);
29461 }
29462 - while (ttyj->open_count)
29463 + while (local_read(&ttyj->open_count))
29464 do_ipw_close(ttyj);
29465 ipwireless_disassociate_network_ttys(network,
29466 ttyj->channel_idx);
29467 diff -urNp linux-2.6.32.46/drivers/char/pty.c linux-2.6.32.46/drivers/char/pty.c
29468 --- linux-2.6.32.46/drivers/char/pty.c 2011-03-27 14:31:47.000000000 -0400
29469 +++ linux-2.6.32.46/drivers/char/pty.c 2011-08-05 20:33:55.000000000 -0400
29470 @@ -736,8 +736,10 @@ static void __init unix98_pty_init(void)
29471 register_sysctl_table(pty_root_table);
29472
29473 /* Now create the /dev/ptmx special device */
29474 + pax_open_kernel();
29475 tty_default_fops(&ptmx_fops);
29476 - ptmx_fops.open = ptmx_open;
29477 + *(void **)&ptmx_fops.open = ptmx_open;
29478 + pax_close_kernel();
29479
29480 cdev_init(&ptmx_cdev, &ptmx_fops);
29481 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
29482 diff -urNp linux-2.6.32.46/drivers/char/random.c linux-2.6.32.46/drivers/char/random.c
29483 --- linux-2.6.32.46/drivers/char/random.c 2011-08-16 20:37:25.000000000 -0400
29484 +++ linux-2.6.32.46/drivers/char/random.c 2011-08-16 20:43:23.000000000 -0400
29485 @@ -254,8 +254,13 @@
29486 /*
29487 * Configuration information
29488 */
29489 +#ifdef CONFIG_GRKERNSEC_RANDNET
29490 +#define INPUT_POOL_WORDS 512
29491 +#define OUTPUT_POOL_WORDS 128
29492 +#else
29493 #define INPUT_POOL_WORDS 128
29494 #define OUTPUT_POOL_WORDS 32
29495 +#endif
29496 #define SEC_XFER_SIZE 512
29497
29498 /*
29499 @@ -292,10 +297,17 @@ static struct poolinfo {
29500 int poolwords;
29501 int tap1, tap2, tap3, tap4, tap5;
29502 } poolinfo_table[] = {
29503 +#ifdef CONFIG_GRKERNSEC_RANDNET
29504 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29505 + { 512, 411, 308, 208, 104, 1 },
29506 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29507 + { 128, 103, 76, 51, 25, 1 },
29508 +#else
29509 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29510 { 128, 103, 76, 51, 25, 1 },
29511 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29512 { 32, 26, 20, 14, 7, 1 },
29513 +#endif
29514 #if 0
29515 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29516 { 2048, 1638, 1231, 819, 411, 1 },
29517 @@ -1209,7 +1221,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29518 #include <linux/sysctl.h>
29519
29520 static int min_read_thresh = 8, min_write_thresh;
29521 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29522 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29523 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29524 static char sysctl_bootid[16];
29525
29526 diff -urNp linux-2.6.32.46/drivers/char/rocket.c linux-2.6.32.46/drivers/char/rocket.c
29527 --- linux-2.6.32.46/drivers/char/rocket.c 2011-03-27 14:31:47.000000000 -0400
29528 +++ linux-2.6.32.46/drivers/char/rocket.c 2011-05-16 21:46:57.000000000 -0400
29529 @@ -1266,6 +1266,8 @@ static int get_ports(struct r_port *info
29530 struct rocket_ports tmp;
29531 int board;
29532
29533 + pax_track_stack();
29534 +
29535 if (!retports)
29536 return -EFAULT;
29537 memset(&tmp, 0, sizeof (tmp));
29538 diff -urNp linux-2.6.32.46/drivers/char/sonypi.c linux-2.6.32.46/drivers/char/sonypi.c
29539 --- linux-2.6.32.46/drivers/char/sonypi.c 2011-03-27 14:31:47.000000000 -0400
29540 +++ linux-2.6.32.46/drivers/char/sonypi.c 2011-04-17 15:56:46.000000000 -0400
29541 @@ -55,6 +55,7 @@
29542 #include <asm/uaccess.h>
29543 #include <asm/io.h>
29544 #include <asm/system.h>
29545 +#include <asm/local.h>
29546
29547 #include <linux/sonypi.h>
29548
29549 @@ -491,7 +492,7 @@ static struct sonypi_device {
29550 spinlock_t fifo_lock;
29551 wait_queue_head_t fifo_proc_list;
29552 struct fasync_struct *fifo_async;
29553 - int open_count;
29554 + local_t open_count;
29555 int model;
29556 struct input_dev *input_jog_dev;
29557 struct input_dev *input_key_dev;
29558 @@ -895,7 +896,7 @@ static int sonypi_misc_fasync(int fd, st
29559 static int sonypi_misc_release(struct inode *inode, struct file *file)
29560 {
29561 mutex_lock(&sonypi_device.lock);
29562 - sonypi_device.open_count--;
29563 + local_dec(&sonypi_device.open_count);
29564 mutex_unlock(&sonypi_device.lock);
29565 return 0;
29566 }
29567 @@ -905,9 +906,9 @@ static int sonypi_misc_open(struct inode
29568 lock_kernel();
29569 mutex_lock(&sonypi_device.lock);
29570 /* Flush input queue on first open */
29571 - if (!sonypi_device.open_count)
29572 + if (!local_read(&sonypi_device.open_count))
29573 kfifo_reset(sonypi_device.fifo);
29574 - sonypi_device.open_count++;
29575 + local_inc(&sonypi_device.open_count);
29576 mutex_unlock(&sonypi_device.lock);
29577 unlock_kernel();
29578 return 0;
29579 diff -urNp linux-2.6.32.46/drivers/char/stallion.c linux-2.6.32.46/drivers/char/stallion.c
29580 --- linux-2.6.32.46/drivers/char/stallion.c 2011-03-27 14:31:47.000000000 -0400
29581 +++ linux-2.6.32.46/drivers/char/stallion.c 2011-05-16 21:46:57.000000000 -0400
29582 @@ -2448,6 +2448,8 @@ static int stl_getportstruct(struct stlp
29583 struct stlport stl_dummyport;
29584 struct stlport *portp;
29585
29586 + pax_track_stack();
29587 +
29588 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
29589 return -EFAULT;
29590 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
29591 diff -urNp linux-2.6.32.46/drivers/char/tpm/tpm.c linux-2.6.32.46/drivers/char/tpm/tpm.c
29592 --- linux-2.6.32.46/drivers/char/tpm/tpm.c 2011-04-17 17:00:52.000000000 -0400
29593 +++ linux-2.6.32.46/drivers/char/tpm/tpm.c 2011-10-17 02:49:00.000000000 -0400
29594 @@ -374,6 +374,9 @@ static ssize_t tpm_transmit(struct tpm_c
29595 u32 count, ordinal;
29596 unsigned long stop;
29597
29598 + if (bufsiz > TPM_BUFSIZE)
29599 + bufsiz = TPM_BUFSIZE;
29600 +
29601 count = be32_to_cpu(*((__be32 *) (buf + 2)));
29602 ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
29603 if (count == 0)
29604 @@ -402,7 +405,7 @@ static ssize_t tpm_transmit(struct tpm_c
29605 chip->vendor.req_complete_val)
29606 goto out_recv;
29607
29608 - if ((status == chip->vendor.req_canceled)) {
29609 + if (status == chip->vendor.req_canceled) {
29610 dev_err(chip->dev, "Operation Canceled\n");
29611 rc = -ECANCELED;
29612 goto out;
29613 @@ -821,6 +824,8 @@ ssize_t tpm_show_pubek(struct device *de
29614
29615 struct tpm_chip *chip = dev_get_drvdata(dev);
29616
29617 + pax_track_stack();
29618 +
29619 tpm_cmd.header.in = tpm_readpubek_header;
29620 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
29621 "attempting to read the PUBEK");
29622 @@ -1041,6 +1046,7 @@ ssize_t tpm_read(struct file *file, char
29623 {
29624 struct tpm_chip *chip = file->private_data;
29625 ssize_t ret_size;
29626 + int rc;
29627
29628 del_singleshot_timer_sync(&chip->user_read_timer);
29629 flush_scheduled_work();
29630 @@ -1051,8 +1057,11 @@ ssize_t tpm_read(struct file *file, char
29631 ret_size = size;
29632
29633 mutex_lock(&chip->buffer_mutex);
29634 - if (copy_to_user(buf, chip->data_buffer, ret_size))
29635 + rc = copy_to_user(buf, chip->data_buffer, ret_size);
29636 + memset(chip->data_buffer, 0, ret_size);
29637 + if (rc)
29638 ret_size = -EFAULT;
29639 +
29640 mutex_unlock(&chip->buffer_mutex);
29641 }
29642
29643 diff -urNp linux-2.6.32.46/drivers/char/tpm/tpm_bios.c linux-2.6.32.46/drivers/char/tpm/tpm_bios.c
29644 --- linux-2.6.32.46/drivers/char/tpm/tpm_bios.c 2011-03-27 14:31:47.000000000 -0400
29645 +++ linux-2.6.32.46/drivers/char/tpm/tpm_bios.c 2011-10-06 09:37:08.000000000 -0400
29646 @@ -172,7 +172,7 @@ static void *tpm_bios_measurements_start
29647 event = addr;
29648
29649 if ((event->event_type == 0 && event->event_size == 0) ||
29650 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29651 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29652 return NULL;
29653
29654 return addr;
29655 @@ -197,7 +197,7 @@ static void *tpm_bios_measurements_next(
29656 return NULL;
29657
29658 if ((event->event_type == 0 && event->event_size == 0) ||
29659 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29660 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29661 return NULL;
29662
29663 (*pos)++;
29664 @@ -290,7 +290,8 @@ static int tpm_binary_bios_measurements_
29665 int i;
29666
29667 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29668 - seq_putc(m, data[i]);
29669 + if (!seq_putc(m, data[i]))
29670 + return -EFAULT;
29671
29672 return 0;
29673 }
29674 @@ -409,8 +410,13 @@ static int read_log(struct tpm_bios_log
29675 log->bios_event_log_end = log->bios_event_log + len;
29676
29677 virt = acpi_os_map_memory(start, len);
29678 + if (!virt) {
29679 + kfree(log->bios_event_log);
29680 + log->bios_event_log = NULL;
29681 + return -EFAULT;
29682 + }
29683
29684 - memcpy(log->bios_event_log, virt, len);
29685 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29686
29687 acpi_os_unmap_memory(virt, len);
29688 return 0;
29689 diff -urNp linux-2.6.32.46/drivers/char/tty_io.c linux-2.6.32.46/drivers/char/tty_io.c
29690 --- linux-2.6.32.46/drivers/char/tty_io.c 2011-03-27 14:31:47.000000000 -0400
29691 +++ linux-2.6.32.46/drivers/char/tty_io.c 2011-08-05 20:33:55.000000000 -0400
29692 @@ -2582,8 +2582,10 @@ long tty_ioctl(struct file *file, unsign
29693 return retval;
29694 }
29695
29696 +EXPORT_SYMBOL(tty_ioctl);
29697 +
29698 #ifdef CONFIG_COMPAT
29699 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
29700 +long tty_compat_ioctl(struct file *file, unsigned int cmd,
29701 unsigned long arg)
29702 {
29703 struct inode *inode = file->f_dentry->d_inode;
29704 @@ -2607,6 +2609,8 @@ static long tty_compat_ioctl(struct file
29705
29706 return retval;
29707 }
29708 +
29709 +EXPORT_SYMBOL(tty_compat_ioctl);
29710 #endif
29711
29712 /*
29713 @@ -3052,7 +3056,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
29714
29715 void tty_default_fops(struct file_operations *fops)
29716 {
29717 - *fops = tty_fops;
29718 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
29719 }
29720
29721 /*
29722 diff -urNp linux-2.6.32.46/drivers/char/tty_ldisc.c linux-2.6.32.46/drivers/char/tty_ldisc.c
29723 --- linux-2.6.32.46/drivers/char/tty_ldisc.c 2011-07-13 17:23:04.000000000 -0400
29724 +++ linux-2.6.32.46/drivers/char/tty_ldisc.c 2011-07-13 17:23:18.000000000 -0400
29725 @@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
29726 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
29727 struct tty_ldisc_ops *ldo = ld->ops;
29728
29729 - ldo->refcount--;
29730 + atomic_dec(&ldo->refcount);
29731 module_put(ldo->owner);
29732 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
29733
29734 @@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
29735 spin_lock_irqsave(&tty_ldisc_lock, flags);
29736 tty_ldiscs[disc] = new_ldisc;
29737 new_ldisc->num = disc;
29738 - new_ldisc->refcount = 0;
29739 + atomic_set(&new_ldisc->refcount, 0);
29740 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
29741
29742 return ret;
29743 @@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
29744 return -EINVAL;
29745
29746 spin_lock_irqsave(&tty_ldisc_lock, flags);
29747 - if (tty_ldiscs[disc]->refcount)
29748 + if (atomic_read(&tty_ldiscs[disc]->refcount))
29749 ret = -EBUSY;
29750 else
29751 tty_ldiscs[disc] = NULL;
29752 @@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
29753 if (ldops) {
29754 ret = ERR_PTR(-EAGAIN);
29755 if (try_module_get(ldops->owner)) {
29756 - ldops->refcount++;
29757 + atomic_inc(&ldops->refcount);
29758 ret = ldops;
29759 }
29760 }
29761 @@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
29762 unsigned long flags;
29763
29764 spin_lock_irqsave(&tty_ldisc_lock, flags);
29765 - ldops->refcount--;
29766 + atomic_dec(&ldops->refcount);
29767 module_put(ldops->owner);
29768 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
29769 }
29770 diff -urNp linux-2.6.32.46/drivers/char/virtio_console.c linux-2.6.32.46/drivers/char/virtio_console.c
29771 --- linux-2.6.32.46/drivers/char/virtio_console.c 2011-03-27 14:31:47.000000000 -0400
29772 +++ linux-2.6.32.46/drivers/char/virtio_console.c 2011-08-05 20:33:55.000000000 -0400
29773 @@ -133,7 +133,9 @@ static int get_chars(u32 vtermno, char *
29774 * virtqueue, so we let the drivers do some boutique early-output thing. */
29775 int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
29776 {
29777 - virtio_cons.put_chars = put_chars;
29778 + pax_open_kernel();
29779 + *(void **)&virtio_cons.put_chars = put_chars;
29780 + pax_close_kernel();
29781 return hvc_instantiate(0, 0, &virtio_cons);
29782 }
29783
29784 @@ -213,11 +215,13 @@ static int __devinit virtcons_probe(stru
29785 out_vq = vqs[1];
29786
29787 /* Start using the new console output. */
29788 - virtio_cons.get_chars = get_chars;
29789 - virtio_cons.put_chars = put_chars;
29790 - virtio_cons.notifier_add = notifier_add_vio;
29791 - virtio_cons.notifier_del = notifier_del_vio;
29792 - virtio_cons.notifier_hangup = notifier_del_vio;
29793 + pax_open_kernel();
29794 + *(void **)&virtio_cons.get_chars = get_chars;
29795 + *(void **)&virtio_cons.put_chars = put_chars;
29796 + *(void **)&virtio_cons.notifier_add = notifier_add_vio;
29797 + *(void **)&virtio_cons.notifier_del = notifier_del_vio;
29798 + *(void **)&virtio_cons.notifier_hangup = notifier_del_vio;
29799 + pax_close_kernel();
29800
29801 /* The first argument of hvc_alloc() is the virtual console number, so
29802 * we use zero. The second argument is the parameter for the
29803 diff -urNp linux-2.6.32.46/drivers/char/vt.c linux-2.6.32.46/drivers/char/vt.c
29804 --- linux-2.6.32.46/drivers/char/vt.c 2011-03-27 14:31:47.000000000 -0400
29805 +++ linux-2.6.32.46/drivers/char/vt.c 2011-04-17 15:56:46.000000000 -0400
29806 @@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
29807
29808 static void notify_write(struct vc_data *vc, unsigned int unicode)
29809 {
29810 - struct vt_notifier_param param = { .vc = vc, unicode = unicode };
29811 + struct vt_notifier_param param = { .vc = vc, .c = unicode };
29812 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
29813 }
29814
29815 diff -urNp linux-2.6.32.46/drivers/char/vt_ioctl.c linux-2.6.32.46/drivers/char/vt_ioctl.c
29816 --- linux-2.6.32.46/drivers/char/vt_ioctl.c 2011-03-27 14:31:47.000000000 -0400
29817 +++ linux-2.6.32.46/drivers/char/vt_ioctl.c 2011-04-17 15:56:46.000000000 -0400
29818 @@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
29819 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
29820 return -EFAULT;
29821
29822 - if (!capable(CAP_SYS_TTY_CONFIG))
29823 - perm = 0;
29824 -
29825 switch (cmd) {
29826 case KDGKBENT:
29827 key_map = key_maps[s];
29828 @@ -224,8 +221,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __
29829 val = (i ? K_HOLE : K_NOSUCHMAP);
29830 return put_user(val, &user_kbe->kb_value);
29831 case KDSKBENT:
29832 + if (!capable(CAP_SYS_TTY_CONFIG))
29833 + perm = 0;
29834 +
29835 if (!perm)
29836 return -EPERM;
29837 +
29838 if (!i && v == K_NOSUCHMAP) {
29839 /* deallocate map */
29840 key_map = key_maps[s];
29841 @@ -325,9 +326,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
29842 int i, j, k;
29843 int ret;
29844
29845 - if (!capable(CAP_SYS_TTY_CONFIG))
29846 - perm = 0;
29847 -
29848 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
29849 if (!kbs) {
29850 ret = -ENOMEM;
29851 @@ -361,6 +359,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
29852 kfree(kbs);
29853 return ((p && *p) ? -EOVERFLOW : 0);
29854 case KDSKBSENT:
29855 + if (!capable(CAP_SYS_TTY_CONFIG))
29856 + perm = 0;
29857 +
29858 if (!perm) {
29859 ret = -EPERM;
29860 goto reterr;
29861 diff -urNp linux-2.6.32.46/drivers/cpufreq/cpufreq.c linux-2.6.32.46/drivers/cpufreq/cpufreq.c
29862 --- linux-2.6.32.46/drivers/cpufreq/cpufreq.c 2011-06-25 12:55:34.000000000 -0400
29863 +++ linux-2.6.32.46/drivers/cpufreq/cpufreq.c 2011-06-25 12:56:37.000000000 -0400
29864 @@ -750,7 +750,7 @@ static void cpufreq_sysfs_release(struct
29865 complete(&policy->kobj_unregister);
29866 }
29867
29868 -static struct sysfs_ops sysfs_ops = {
29869 +static const struct sysfs_ops sysfs_ops = {
29870 .show = show,
29871 .store = store,
29872 };
29873 diff -urNp linux-2.6.32.46/drivers/cpuidle/sysfs.c linux-2.6.32.46/drivers/cpuidle/sysfs.c
29874 --- linux-2.6.32.46/drivers/cpuidle/sysfs.c 2011-03-27 14:31:47.000000000 -0400
29875 +++ linux-2.6.32.46/drivers/cpuidle/sysfs.c 2011-04-17 15:56:46.000000000 -0400
29876 @@ -191,7 +191,7 @@ static ssize_t cpuidle_store(struct kobj
29877 return ret;
29878 }
29879
29880 -static struct sysfs_ops cpuidle_sysfs_ops = {
29881 +static const struct sysfs_ops cpuidle_sysfs_ops = {
29882 .show = cpuidle_show,
29883 .store = cpuidle_store,
29884 };
29885 @@ -277,7 +277,7 @@ static ssize_t cpuidle_state_show(struct
29886 return ret;
29887 }
29888
29889 -static struct sysfs_ops cpuidle_state_sysfs_ops = {
29890 +static const struct sysfs_ops cpuidle_state_sysfs_ops = {
29891 .show = cpuidle_state_show,
29892 };
29893
29894 @@ -294,7 +294,7 @@ static struct kobj_type ktype_state_cpui
29895 .release = cpuidle_state_sysfs_release,
29896 };
29897
29898 -static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
29899 +static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
29900 {
29901 kobject_put(&device->kobjs[i]->kobj);
29902 wait_for_completion(&device->kobjs[i]->kobj_unregister);
29903 diff -urNp linux-2.6.32.46/drivers/crypto/hifn_795x.c linux-2.6.32.46/drivers/crypto/hifn_795x.c
29904 --- linux-2.6.32.46/drivers/crypto/hifn_795x.c 2011-03-27 14:31:47.000000000 -0400
29905 +++ linux-2.6.32.46/drivers/crypto/hifn_795x.c 2011-05-16 21:46:57.000000000 -0400
29906 @@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
29907 0xCA, 0x34, 0x2B, 0x2E};
29908 struct scatterlist sg;
29909
29910 + pax_track_stack();
29911 +
29912 memset(src, 0, sizeof(src));
29913 memset(ctx.key, 0, sizeof(ctx.key));
29914
29915 diff -urNp linux-2.6.32.46/drivers/crypto/padlock-aes.c linux-2.6.32.46/drivers/crypto/padlock-aes.c
29916 --- linux-2.6.32.46/drivers/crypto/padlock-aes.c 2011-03-27 14:31:47.000000000 -0400
29917 +++ linux-2.6.32.46/drivers/crypto/padlock-aes.c 2011-05-16 21:46:57.000000000 -0400
29918 @@ -108,6 +108,8 @@ static int aes_set_key(struct crypto_tfm
29919 struct crypto_aes_ctx gen_aes;
29920 int cpu;
29921
29922 + pax_track_stack();
29923 +
29924 if (key_len % 8) {
29925 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
29926 return -EINVAL;
29927 diff -urNp linux-2.6.32.46/drivers/dma/ioat/dma.c linux-2.6.32.46/drivers/dma/ioat/dma.c
29928 --- linux-2.6.32.46/drivers/dma/ioat/dma.c 2011-03-27 14:31:47.000000000 -0400
29929 +++ linux-2.6.32.46/drivers/dma/ioat/dma.c 2011-04-17 15:56:46.000000000 -0400
29930 @@ -1146,7 +1146,7 @@ ioat_attr_show(struct kobject *kobj, str
29931 return entry->show(&chan->common, page);
29932 }
29933
29934 -struct sysfs_ops ioat_sysfs_ops = {
29935 +const struct sysfs_ops ioat_sysfs_ops = {
29936 .show = ioat_attr_show,
29937 };
29938
29939 diff -urNp linux-2.6.32.46/drivers/dma/ioat/dma.h linux-2.6.32.46/drivers/dma/ioat/dma.h
29940 --- linux-2.6.32.46/drivers/dma/ioat/dma.h 2011-03-27 14:31:47.000000000 -0400
29941 +++ linux-2.6.32.46/drivers/dma/ioat/dma.h 2011-04-17 15:56:46.000000000 -0400
29942 @@ -347,7 +347,7 @@ bool ioat_cleanup_preamble(struct ioat_c
29943 unsigned long *phys_complete);
29944 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
29945 void ioat_kobject_del(struct ioatdma_device *device);
29946 -extern struct sysfs_ops ioat_sysfs_ops;
29947 +extern const struct sysfs_ops ioat_sysfs_ops;
29948 extern struct ioat_sysfs_entry ioat_version_attr;
29949 extern struct ioat_sysfs_entry ioat_cap_attr;
29950 #endif /* IOATDMA_H */
29951 diff -urNp linux-2.6.32.46/drivers/edac/edac_device_sysfs.c linux-2.6.32.46/drivers/edac/edac_device_sysfs.c
29952 --- linux-2.6.32.46/drivers/edac/edac_device_sysfs.c 2011-03-27 14:31:47.000000000 -0400
29953 +++ linux-2.6.32.46/drivers/edac/edac_device_sysfs.c 2011-04-17 15:56:46.000000000 -0400
29954 @@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(s
29955 }
29956
29957 /* edac_dev file operations for an 'ctl_info' */
29958 -static struct sysfs_ops device_ctl_info_ops = {
29959 +static const struct sysfs_ops device_ctl_info_ops = {
29960 .show = edac_dev_ctl_info_show,
29961 .store = edac_dev_ctl_info_store
29962 };
29963 @@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(s
29964 }
29965
29966 /* edac_dev file operations for an 'instance' */
29967 -static struct sysfs_ops device_instance_ops = {
29968 +static const struct sysfs_ops device_instance_ops = {
29969 .show = edac_dev_instance_show,
29970 .store = edac_dev_instance_store
29971 };
29972 @@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(stru
29973 }
29974
29975 /* edac_dev file operations for a 'block' */
29976 -static struct sysfs_ops device_block_ops = {
29977 +static const struct sysfs_ops device_block_ops = {
29978 .show = edac_dev_block_show,
29979 .store = edac_dev_block_store
29980 };
29981 diff -urNp linux-2.6.32.46/drivers/edac/edac_mc_sysfs.c linux-2.6.32.46/drivers/edac/edac_mc_sysfs.c
29982 --- linux-2.6.32.46/drivers/edac/edac_mc_sysfs.c 2011-03-27 14:31:47.000000000 -0400
29983 +++ linux-2.6.32.46/drivers/edac/edac_mc_sysfs.c 2011-04-17 15:56:46.000000000 -0400
29984 @@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kob
29985 return -EIO;
29986 }
29987
29988 -static struct sysfs_ops csrowfs_ops = {
29989 +static const struct sysfs_ops csrowfs_ops = {
29990 .show = csrowdev_show,
29991 .store = csrowdev_store
29992 };
29993 @@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobje
29994 }
29995
29996 /* Intermediate show/store table */
29997 -static struct sysfs_ops mci_ops = {
29998 +static const struct sysfs_ops mci_ops = {
29999 .show = mcidev_show,
30000 .store = mcidev_store
30001 };
30002 diff -urNp linux-2.6.32.46/drivers/edac/edac_pci_sysfs.c linux-2.6.32.46/drivers/edac/edac_pci_sysfs.c
30003 --- linux-2.6.32.46/drivers/edac/edac_pci_sysfs.c 2011-03-27 14:31:47.000000000 -0400
30004 +++ linux-2.6.32.46/drivers/edac/edac_pci_sysfs.c 2011-05-04 17:56:20.000000000 -0400
30005 @@ -25,8 +25,8 @@ static int edac_pci_log_pe = 1; /* log
30006 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30007 static int edac_pci_poll_msec = 1000; /* one second workq period */
30008
30009 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30010 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30011 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30012 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30013
30014 static struct kobject *edac_pci_top_main_kobj;
30015 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30016 @@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(s
30017 }
30018
30019 /* fs_ops table */
30020 -static struct sysfs_ops pci_instance_ops = {
30021 +static const struct sysfs_ops pci_instance_ops = {
30022 .show = edac_pci_instance_show,
30023 .store = edac_pci_instance_store
30024 };
30025 @@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct
30026 return -EIO;
30027 }
30028
30029 -static struct sysfs_ops edac_pci_sysfs_ops = {
30030 +static const struct sysfs_ops edac_pci_sysfs_ops = {
30031 .show = edac_pci_dev_show,
30032 .store = edac_pci_dev_store
30033 };
30034 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(str
30035 edac_printk(KERN_CRIT, EDAC_PCI,
30036 "Signaled System Error on %s\n",
30037 pci_name(dev));
30038 - atomic_inc(&pci_nonparity_count);
30039 + atomic_inc_unchecked(&pci_nonparity_count);
30040 }
30041
30042 if (status & (PCI_STATUS_PARITY)) {
30043 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(str
30044 "Master Data Parity Error on %s\n",
30045 pci_name(dev));
30046
30047 - atomic_inc(&pci_parity_count);
30048 + atomic_inc_unchecked(&pci_parity_count);
30049 }
30050
30051 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30052 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(str
30053 "Detected Parity Error on %s\n",
30054 pci_name(dev));
30055
30056 - atomic_inc(&pci_parity_count);
30057 + atomic_inc_unchecked(&pci_parity_count);
30058 }
30059 }
30060
30061 @@ -616,7 +616,7 @@ static void edac_pci_dev_parity_test(str
30062 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30063 "Signaled System Error on %s\n",
30064 pci_name(dev));
30065 - atomic_inc(&pci_nonparity_count);
30066 + atomic_inc_unchecked(&pci_nonparity_count);
30067 }
30068
30069 if (status & (PCI_STATUS_PARITY)) {
30070 @@ -624,7 +624,7 @@ static void edac_pci_dev_parity_test(str
30071 "Master Data Parity Error on "
30072 "%s\n", pci_name(dev));
30073
30074 - atomic_inc(&pci_parity_count);
30075 + atomic_inc_unchecked(&pci_parity_count);
30076 }
30077
30078 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30079 @@ -632,7 +632,7 @@ static void edac_pci_dev_parity_test(str
30080 "Detected Parity Error on %s\n",
30081 pci_name(dev));
30082
30083 - atomic_inc(&pci_parity_count);
30084 + atomic_inc_unchecked(&pci_parity_count);
30085 }
30086 }
30087 }
30088 @@ -674,7 +674,7 @@ void edac_pci_do_parity_check(void)
30089 if (!check_pci_errors)
30090 return;
30091
30092 - before_count = atomic_read(&pci_parity_count);
30093 + before_count = atomic_read_unchecked(&pci_parity_count);
30094
30095 /* scan all PCI devices looking for a Parity Error on devices and
30096 * bridges.
30097 @@ -686,7 +686,7 @@ void edac_pci_do_parity_check(void)
30098 /* Only if operator has selected panic on PCI Error */
30099 if (edac_pci_get_panic_on_pe()) {
30100 /* If the count is different 'after' from 'before' */
30101 - if (before_count != atomic_read(&pci_parity_count))
30102 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30103 panic("EDAC: PCI Parity Error");
30104 }
30105 }
30106 diff -urNp linux-2.6.32.46/drivers/firewire/core-card.c linux-2.6.32.46/drivers/firewire/core-card.c
30107 --- linux-2.6.32.46/drivers/firewire/core-card.c 2011-03-27 14:31:47.000000000 -0400
30108 +++ linux-2.6.32.46/drivers/firewire/core-card.c 2011-08-23 21:22:32.000000000 -0400
30109 @@ -558,7 +558,7 @@ void fw_card_release(struct kref *kref)
30110
30111 void fw_core_remove_card(struct fw_card *card)
30112 {
30113 - struct fw_card_driver dummy_driver = dummy_driver_template;
30114 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30115
30116 card->driver->update_phy_reg(card, 4,
30117 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30118 diff -urNp linux-2.6.32.46/drivers/firewire/core-cdev.c linux-2.6.32.46/drivers/firewire/core-cdev.c
30119 --- linux-2.6.32.46/drivers/firewire/core-cdev.c 2011-03-27 14:31:47.000000000 -0400
30120 +++ linux-2.6.32.46/drivers/firewire/core-cdev.c 2011-04-17 15:56:46.000000000 -0400
30121 @@ -1141,8 +1141,7 @@ static int init_iso_resource(struct clie
30122 int ret;
30123
30124 if ((request->channels == 0 && request->bandwidth == 0) ||
30125 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30126 - request->bandwidth < 0)
30127 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30128 return -EINVAL;
30129
30130 r = kmalloc(sizeof(*r), GFP_KERNEL);
30131 diff -urNp linux-2.6.32.46/drivers/firewire/core-transaction.c linux-2.6.32.46/drivers/firewire/core-transaction.c
30132 --- linux-2.6.32.46/drivers/firewire/core-transaction.c 2011-03-27 14:31:47.000000000 -0400
30133 +++ linux-2.6.32.46/drivers/firewire/core-transaction.c 2011-05-16 21:46:57.000000000 -0400
30134 @@ -36,6 +36,7 @@
30135 #include <linux/string.h>
30136 #include <linux/timer.h>
30137 #include <linux/types.h>
30138 +#include <linux/sched.h>
30139
30140 #include <asm/byteorder.h>
30141
30142 @@ -344,6 +345,8 @@ int fw_run_transaction(struct fw_card *c
30143 struct transaction_callback_data d;
30144 struct fw_transaction t;
30145
30146 + pax_track_stack();
30147 +
30148 init_completion(&d.done);
30149 d.payload = payload;
30150 fw_send_request(card, &t, tcode, destination_id, generation, speed,
30151 diff -urNp linux-2.6.32.46/drivers/firewire/core.h linux-2.6.32.46/drivers/firewire/core.h
30152 --- linux-2.6.32.46/drivers/firewire/core.h 2011-03-27 14:31:47.000000000 -0400
30153 +++ linux-2.6.32.46/drivers/firewire/core.h 2011-08-23 20:24:26.000000000 -0400
30154 @@ -86,6 +86,7 @@ struct fw_card_driver {
30155
30156 int (*stop_iso)(struct fw_iso_context *ctx);
30157 };
30158 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30159
30160 void fw_card_initialize(struct fw_card *card,
30161 const struct fw_card_driver *driver, struct device *device);
30162 diff -urNp linux-2.6.32.46/drivers/firmware/dmi_scan.c linux-2.6.32.46/drivers/firmware/dmi_scan.c
30163 --- linux-2.6.32.46/drivers/firmware/dmi_scan.c 2011-03-27 14:31:47.000000000 -0400
30164 +++ linux-2.6.32.46/drivers/firmware/dmi_scan.c 2011-10-06 09:37:08.000000000 -0400
30165 @@ -391,11 +391,6 @@ void __init dmi_scan_machine(void)
30166 }
30167 }
30168 else {
30169 - /*
30170 - * no iounmap() for that ioremap(); it would be a no-op, but
30171 - * it's so early in setup that sucker gets confused into doing
30172 - * what it shouldn't if we actually call it.
30173 - */
30174 p = dmi_ioremap(0xF0000, 0x10000);
30175 if (p == NULL)
30176 goto error;
30177 @@ -667,7 +662,7 @@ int dmi_walk(void (*decode)(const struct
30178 if (buf == NULL)
30179 return -1;
30180
30181 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30182 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30183
30184 iounmap(buf);
30185 return 0;
30186 diff -urNp linux-2.6.32.46/drivers/firmware/edd.c linux-2.6.32.46/drivers/firmware/edd.c
30187 --- linux-2.6.32.46/drivers/firmware/edd.c 2011-03-27 14:31:47.000000000 -0400
30188 +++ linux-2.6.32.46/drivers/firmware/edd.c 2011-04-17 15:56:46.000000000 -0400
30189 @@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, str
30190 return ret;
30191 }
30192
30193 -static struct sysfs_ops edd_attr_ops = {
30194 +static const struct sysfs_ops edd_attr_ops = {
30195 .show = edd_attr_show,
30196 };
30197
30198 diff -urNp linux-2.6.32.46/drivers/firmware/efivars.c linux-2.6.32.46/drivers/firmware/efivars.c
30199 --- linux-2.6.32.46/drivers/firmware/efivars.c 2011-03-27 14:31:47.000000000 -0400
30200 +++ linux-2.6.32.46/drivers/firmware/efivars.c 2011-04-17 15:56:46.000000000 -0400
30201 @@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct
30202 return ret;
30203 }
30204
30205 -static struct sysfs_ops efivar_attr_ops = {
30206 +static const struct sysfs_ops efivar_attr_ops = {
30207 .show = efivar_attr_show,
30208 .store = efivar_attr_store,
30209 };
30210 diff -urNp linux-2.6.32.46/drivers/firmware/iscsi_ibft.c linux-2.6.32.46/drivers/firmware/iscsi_ibft.c
30211 --- linux-2.6.32.46/drivers/firmware/iscsi_ibft.c 2011-03-27 14:31:47.000000000 -0400
30212 +++ linux-2.6.32.46/drivers/firmware/iscsi_ibft.c 2011-04-17 15:56:46.000000000 -0400
30213 @@ -525,7 +525,7 @@ static ssize_t ibft_show_attribute(struc
30214 return ret;
30215 }
30216
30217 -static struct sysfs_ops ibft_attr_ops = {
30218 +static const struct sysfs_ops ibft_attr_ops = {
30219 .show = ibft_show_attribute,
30220 };
30221
30222 diff -urNp linux-2.6.32.46/drivers/firmware/memmap.c linux-2.6.32.46/drivers/firmware/memmap.c
30223 --- linux-2.6.32.46/drivers/firmware/memmap.c 2011-03-27 14:31:47.000000000 -0400
30224 +++ linux-2.6.32.46/drivers/firmware/memmap.c 2011-04-17 15:56:46.000000000 -0400
30225 @@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
30226 NULL
30227 };
30228
30229 -static struct sysfs_ops memmap_attr_ops = {
30230 +static const struct sysfs_ops memmap_attr_ops = {
30231 .show = memmap_attr_show,
30232 };
30233
30234 diff -urNp linux-2.6.32.46/drivers/gpio/vr41xx_giu.c linux-2.6.32.46/drivers/gpio/vr41xx_giu.c
30235 --- linux-2.6.32.46/drivers/gpio/vr41xx_giu.c 2011-03-27 14:31:47.000000000 -0400
30236 +++ linux-2.6.32.46/drivers/gpio/vr41xx_giu.c 2011-05-04 17:56:28.000000000 -0400
30237 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30238 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30239 maskl, pendl, maskh, pendh);
30240
30241 - atomic_inc(&irq_err_count);
30242 + atomic_inc_unchecked(&irq_err_count);
30243
30244 return -EINVAL;
30245 }
30246 diff -urNp linux-2.6.32.46/drivers/gpu/drm/drm_crtc.c linux-2.6.32.46/drivers/gpu/drm/drm_crtc.c
30247 --- linux-2.6.32.46/drivers/gpu/drm/drm_crtc.c 2011-03-27 14:31:47.000000000 -0400
30248 +++ linux-2.6.32.46/drivers/gpu/drm/drm_crtc.c 2011-10-06 09:37:14.000000000 -0400
30249 @@ -1323,7 +1323,7 @@ int drm_mode_getconnector(struct drm_dev
30250 */
30251 if ((out_resp->count_modes >= mode_count) && mode_count) {
30252 copied = 0;
30253 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
30254 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
30255 list_for_each_entry(mode, &connector->modes, head) {
30256 drm_crtc_convert_to_umode(&u_mode, mode);
30257 if (copy_to_user(mode_ptr + copied,
30258 @@ -1338,8 +1338,8 @@ int drm_mode_getconnector(struct drm_dev
30259
30260 if ((out_resp->count_props >= props_count) && props_count) {
30261 copied = 0;
30262 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
30263 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
30264 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
30265 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
30266 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
30267 if (connector->property_ids[i] != 0) {
30268 if (put_user(connector->property_ids[i],
30269 @@ -1361,7 +1361,7 @@ int drm_mode_getconnector(struct drm_dev
30270
30271 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
30272 copied = 0;
30273 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
30274 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
30275 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
30276 if (connector->encoder_ids[i] != 0) {
30277 if (put_user(connector->encoder_ids[i],
30278 @@ -1513,7 +1513,7 @@ int drm_mode_setcrtc(struct drm_device *
30279 }
30280
30281 for (i = 0; i < crtc_req->count_connectors; i++) {
30282 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
30283 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
30284 if (get_user(out_id, &set_connectors_ptr[i])) {
30285 ret = -EFAULT;
30286 goto out;
30287 @@ -2118,7 +2118,7 @@ int drm_mode_getproperty_ioctl(struct dr
30288 out_resp->flags = property->flags;
30289
30290 if ((out_resp->count_values >= value_count) && value_count) {
30291 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
30292 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
30293 for (i = 0; i < value_count; i++) {
30294 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
30295 ret = -EFAULT;
30296 @@ -2131,7 +2131,7 @@ int drm_mode_getproperty_ioctl(struct dr
30297 if (property->flags & DRM_MODE_PROP_ENUM) {
30298 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
30299 copied = 0;
30300 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
30301 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
30302 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
30303
30304 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
30305 @@ -2154,7 +2154,7 @@ int drm_mode_getproperty_ioctl(struct dr
30306 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
30307 copied = 0;
30308 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
30309 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
30310 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
30311
30312 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
30313 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
30314 @@ -2226,7 +2226,7 @@ int drm_mode_getblob_ioctl(struct drm_de
30315 blob = obj_to_blob(obj);
30316
30317 if (out_resp->length == blob->length) {
30318 - blob_ptr = (void *)(unsigned long)out_resp->data;
30319 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
30320 if (copy_to_user(blob_ptr, blob->data, blob->length)){
30321 ret = -EFAULT;
30322 goto done;
30323 diff -urNp linux-2.6.32.46/drivers/gpu/drm/drm_crtc_helper.c linux-2.6.32.46/drivers/gpu/drm/drm_crtc_helper.c
30324 --- linux-2.6.32.46/drivers/gpu/drm/drm_crtc_helper.c 2011-03-27 14:31:47.000000000 -0400
30325 +++ linux-2.6.32.46/drivers/gpu/drm/drm_crtc_helper.c 2011-05-16 21:46:57.000000000 -0400
30326 @@ -573,7 +573,7 @@ static bool drm_encoder_crtc_ok(struct d
30327 struct drm_crtc *tmp;
30328 int crtc_mask = 1;
30329
30330 - WARN(!crtc, "checking null crtc?");
30331 + BUG_ON(!crtc);
30332
30333 dev = crtc->dev;
30334
30335 @@ -642,6 +642,8 @@ bool drm_crtc_helper_set_mode(struct drm
30336
30337 adjusted_mode = drm_mode_duplicate(dev, mode);
30338
30339 + pax_track_stack();
30340 +
30341 crtc->enabled = drm_helper_crtc_in_use(crtc);
30342
30343 if (!crtc->enabled)
30344 diff -urNp linux-2.6.32.46/drivers/gpu/drm/drm_drv.c linux-2.6.32.46/drivers/gpu/drm/drm_drv.c
30345 --- linux-2.6.32.46/drivers/gpu/drm/drm_drv.c 2011-03-27 14:31:47.000000000 -0400
30346 +++ linux-2.6.32.46/drivers/gpu/drm/drm_drv.c 2011-04-17 15:56:46.000000000 -0400
30347 @@ -417,7 +417,7 @@ int drm_ioctl(struct inode *inode, struc
30348 char *kdata = NULL;
30349
30350 atomic_inc(&dev->ioctl_count);
30351 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30352 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30353 ++file_priv->ioctl_count;
30354
30355 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30356 diff -urNp linux-2.6.32.46/drivers/gpu/drm/drm_fops.c linux-2.6.32.46/drivers/gpu/drm/drm_fops.c
30357 --- linux-2.6.32.46/drivers/gpu/drm/drm_fops.c 2011-03-27 14:31:47.000000000 -0400
30358 +++ linux-2.6.32.46/drivers/gpu/drm/drm_fops.c 2011-04-17 15:56:46.000000000 -0400
30359 @@ -66,7 +66,7 @@ static int drm_setup(struct drm_device *
30360 }
30361
30362 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30363 - atomic_set(&dev->counts[i], 0);
30364 + atomic_set_unchecked(&dev->counts[i], 0);
30365
30366 dev->sigdata.lock = NULL;
30367
30368 @@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct
30369
30370 retcode = drm_open_helper(inode, filp, dev);
30371 if (!retcode) {
30372 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30373 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30374 spin_lock(&dev->count_lock);
30375 - if (!dev->open_count++) {
30376 + if (local_inc_return(&dev->open_count) == 1) {
30377 spin_unlock(&dev->count_lock);
30378 retcode = drm_setup(dev);
30379 goto out;
30380 @@ -435,7 +435,7 @@ int drm_release(struct inode *inode, str
30381
30382 lock_kernel();
30383
30384 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30385 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
30386
30387 if (dev->driver->preclose)
30388 dev->driver->preclose(dev, file_priv);
30389 @@ -447,7 +447,7 @@ int drm_release(struct inode *inode, str
30390 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30391 task_pid_nr(current),
30392 (long)old_encode_dev(file_priv->minor->device),
30393 - dev->open_count);
30394 + local_read(&dev->open_count));
30395
30396 /* if the master has gone away we can't do anything with the lock */
30397 if (file_priv->minor->master)
30398 @@ -524,9 +524,9 @@ int drm_release(struct inode *inode, str
30399 * End inline drm_release
30400 */
30401
30402 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30403 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30404 spin_lock(&dev->count_lock);
30405 - if (!--dev->open_count) {
30406 + if (local_dec_and_test(&dev->open_count)) {
30407 if (atomic_read(&dev->ioctl_count)) {
30408 DRM_ERROR("Device busy: %d\n",
30409 atomic_read(&dev->ioctl_count));
30410 diff -urNp linux-2.6.32.46/drivers/gpu/drm/drm_gem.c linux-2.6.32.46/drivers/gpu/drm/drm_gem.c
30411 --- linux-2.6.32.46/drivers/gpu/drm/drm_gem.c 2011-03-27 14:31:47.000000000 -0400
30412 +++ linux-2.6.32.46/drivers/gpu/drm/drm_gem.c 2011-04-17 15:56:46.000000000 -0400
30413 @@ -83,11 +83,11 @@ drm_gem_init(struct drm_device *dev)
30414 spin_lock_init(&dev->object_name_lock);
30415 idr_init(&dev->object_name_idr);
30416 atomic_set(&dev->object_count, 0);
30417 - atomic_set(&dev->object_memory, 0);
30418 + atomic_set_unchecked(&dev->object_memory, 0);
30419 atomic_set(&dev->pin_count, 0);
30420 - atomic_set(&dev->pin_memory, 0);
30421 + atomic_set_unchecked(&dev->pin_memory, 0);
30422 atomic_set(&dev->gtt_count, 0);
30423 - atomic_set(&dev->gtt_memory, 0);
30424 + atomic_set_unchecked(&dev->gtt_memory, 0);
30425
30426 mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
30427 if (!mm) {
30428 @@ -150,7 +150,7 @@ drm_gem_object_alloc(struct drm_device *
30429 goto fput;
30430 }
30431 atomic_inc(&dev->object_count);
30432 - atomic_add(obj->size, &dev->object_memory);
30433 + atomic_add_unchecked(obj->size, &dev->object_memory);
30434 return obj;
30435 fput:
30436 fput(obj->filp);
30437 @@ -429,7 +429,7 @@ drm_gem_object_free(struct kref *kref)
30438
30439 fput(obj->filp);
30440 atomic_dec(&dev->object_count);
30441 - atomic_sub(obj->size, &dev->object_memory);
30442 + atomic_sub_unchecked(obj->size, &dev->object_memory);
30443 kfree(obj);
30444 }
30445 EXPORT_SYMBOL(drm_gem_object_free);
30446 diff -urNp linux-2.6.32.46/drivers/gpu/drm/drm_info.c linux-2.6.32.46/drivers/gpu/drm/drm_info.c
30447 --- linux-2.6.32.46/drivers/gpu/drm/drm_info.c 2011-03-27 14:31:47.000000000 -0400
30448 +++ linux-2.6.32.46/drivers/gpu/drm/drm_info.c 2011-04-17 15:56:46.000000000 -0400
30449 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
30450 struct drm_local_map *map;
30451 struct drm_map_list *r_list;
30452
30453 - /* Hardcoded from _DRM_FRAME_BUFFER,
30454 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30455 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30456 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30457 + static const char * const types[] = {
30458 + [_DRM_FRAME_BUFFER] = "FB",
30459 + [_DRM_REGISTERS] = "REG",
30460 + [_DRM_SHM] = "SHM",
30461 + [_DRM_AGP] = "AGP",
30462 + [_DRM_SCATTER_GATHER] = "SG",
30463 + [_DRM_CONSISTENT] = "PCI",
30464 + [_DRM_GEM] = "GEM" };
30465 const char *type;
30466 int i;
30467
30468 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
30469 map = r_list->map;
30470 if (!map)
30471 continue;
30472 - if (map->type < 0 || map->type > 5)
30473 + if (map->type >= ARRAY_SIZE(types))
30474 type = "??";
30475 else
30476 type = types[map->type];
30477 @@ -265,10 +269,10 @@ int drm_gem_object_info(struct seq_file
30478 struct drm_device *dev = node->minor->dev;
30479
30480 seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
30481 - seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
30482 + seq_printf(m, "%d object bytes\n", atomic_read_unchecked(&dev->object_memory));
30483 seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
30484 - seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
30485 - seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
30486 + seq_printf(m, "%d pin bytes\n", atomic_read_unchecked(&dev->pin_memory));
30487 + seq_printf(m, "%d gtt bytes\n", atomic_read_unchecked(&dev->gtt_memory));
30488 seq_printf(m, "%d gtt total\n", dev->gtt_total);
30489 return 0;
30490 }
30491 @@ -288,7 +292,11 @@ int drm_vma_info(struct seq_file *m, voi
30492 mutex_lock(&dev->struct_mutex);
30493 seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
30494 atomic_read(&dev->vma_count),
30495 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30496 + NULL, 0);
30497 +#else
30498 high_memory, (u64)virt_to_phys(high_memory));
30499 +#endif
30500
30501 list_for_each_entry(pt, &dev->vmalist, head) {
30502 vma = pt->vma;
30503 @@ -296,14 +304,23 @@ int drm_vma_info(struct seq_file *m, voi
30504 continue;
30505 seq_printf(m,
30506 "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
30507 - pt->pid, vma->vm_start, vma->vm_end,
30508 + pt->pid,
30509 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30510 + 0, 0,
30511 +#else
30512 + vma->vm_start, vma->vm_end,
30513 +#endif
30514 vma->vm_flags & VM_READ ? 'r' : '-',
30515 vma->vm_flags & VM_WRITE ? 'w' : '-',
30516 vma->vm_flags & VM_EXEC ? 'x' : '-',
30517 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30518 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30519 vma->vm_flags & VM_IO ? 'i' : '-',
30520 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30521 + 0);
30522 +#else
30523 vma->vm_pgoff);
30524 +#endif
30525
30526 #if defined(__i386__)
30527 pgprot = pgprot_val(vma->vm_page_prot);
30528 diff -urNp linux-2.6.32.46/drivers/gpu/drm/drm_ioc32.c linux-2.6.32.46/drivers/gpu/drm/drm_ioc32.c
30529 --- linux-2.6.32.46/drivers/gpu/drm/drm_ioc32.c 2011-03-27 14:31:47.000000000 -0400
30530 +++ linux-2.6.32.46/drivers/gpu/drm/drm_ioc32.c 2011-10-06 09:37:14.000000000 -0400
30531 @@ -463,7 +463,7 @@ static int compat_drm_infobufs(struct fi
30532 request = compat_alloc_user_space(nbytes);
30533 if (!access_ok(VERIFY_WRITE, request, nbytes))
30534 return -EFAULT;
30535 - list = (struct drm_buf_desc *) (request + 1);
30536 + list = (struct drm_buf_desc __user *) (request + 1);
30537
30538 if (__put_user(count, &request->count)
30539 || __put_user(list, &request->list))
30540 @@ -525,7 +525,7 @@ static int compat_drm_mapbufs(struct fil
30541 request = compat_alloc_user_space(nbytes);
30542 if (!access_ok(VERIFY_WRITE, request, nbytes))
30543 return -EFAULT;
30544 - list = (struct drm_buf_pub *) (request + 1);
30545 + list = (struct drm_buf_pub __user *) (request + 1);
30546
30547 if (__put_user(count, &request->count)
30548 || __put_user(list, &request->list))
30549 diff -urNp linux-2.6.32.46/drivers/gpu/drm/drm_ioctl.c linux-2.6.32.46/drivers/gpu/drm/drm_ioctl.c
30550 --- linux-2.6.32.46/drivers/gpu/drm/drm_ioctl.c 2011-03-27 14:31:47.000000000 -0400
30551 +++ linux-2.6.32.46/drivers/gpu/drm/drm_ioctl.c 2011-04-17 15:56:46.000000000 -0400
30552 @@ -283,7 +283,7 @@ int drm_getstats(struct drm_device *dev,
30553 stats->data[i].value =
30554 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30555 else
30556 - stats->data[i].value = atomic_read(&dev->counts[i]);
30557 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30558 stats->data[i].type = dev->types[i];
30559 }
30560
30561 diff -urNp linux-2.6.32.46/drivers/gpu/drm/drm_lock.c linux-2.6.32.46/drivers/gpu/drm/drm_lock.c
30562 --- linux-2.6.32.46/drivers/gpu/drm/drm_lock.c 2011-03-27 14:31:47.000000000 -0400
30563 +++ linux-2.6.32.46/drivers/gpu/drm/drm_lock.c 2011-04-17 15:56:46.000000000 -0400
30564 @@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, voi
30565 if (drm_lock_take(&master->lock, lock->context)) {
30566 master->lock.file_priv = file_priv;
30567 master->lock.lock_time = jiffies;
30568 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30569 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30570 break; /* Got lock */
30571 }
30572
30573 @@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, v
30574 return -EINVAL;
30575 }
30576
30577 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30578 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30579
30580 /* kernel_context_switch isn't used by any of the x86 drm
30581 * modules but is required by the Sparc driver.
30582 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i810/i810_dma.c linux-2.6.32.46/drivers/gpu/drm/i810/i810_dma.c
30583 --- linux-2.6.32.46/drivers/gpu/drm/i810/i810_dma.c 2011-03-27 14:31:47.000000000 -0400
30584 +++ linux-2.6.32.46/drivers/gpu/drm/i810/i810_dma.c 2011-04-17 15:56:46.000000000 -0400
30585 @@ -952,8 +952,8 @@ static int i810_dma_vertex(struct drm_de
30586 dma->buflist[vertex->idx],
30587 vertex->discard, vertex->used);
30588
30589 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30590 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30591 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30592 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30593 sarea_priv->last_enqueue = dev_priv->counter - 1;
30594 sarea_priv->last_dispatch = (int)hw_status[5];
30595
30596 @@ -1115,8 +1115,8 @@ static int i810_dma_mc(struct drm_device
30597 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30598 mc->last_render);
30599
30600 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30601 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30602 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30603 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30604 sarea_priv->last_enqueue = dev_priv->counter - 1;
30605 sarea_priv->last_dispatch = (int)hw_status[5];
30606
30607 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i810/i810_drv.h linux-2.6.32.46/drivers/gpu/drm/i810/i810_drv.h
30608 --- linux-2.6.32.46/drivers/gpu/drm/i810/i810_drv.h 2011-03-27 14:31:47.000000000 -0400
30609 +++ linux-2.6.32.46/drivers/gpu/drm/i810/i810_drv.h 2011-05-04 17:56:28.000000000 -0400
30610 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30611 int page_flipping;
30612
30613 wait_queue_head_t irq_queue;
30614 - atomic_t irq_received;
30615 - atomic_t irq_emitted;
30616 + atomic_unchecked_t irq_received;
30617 + atomic_unchecked_t irq_emitted;
30618
30619 int front_offset;
30620 } drm_i810_private_t;
30621 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i830/i830_drv.h linux-2.6.32.46/drivers/gpu/drm/i830/i830_drv.h
30622 --- linux-2.6.32.46/drivers/gpu/drm/i830/i830_drv.h 2011-03-27 14:31:47.000000000 -0400
30623 +++ linux-2.6.32.46/drivers/gpu/drm/i830/i830_drv.h 2011-05-04 17:56:28.000000000 -0400
30624 @@ -115,8 +115,8 @@ typedef struct drm_i830_private {
30625 int page_flipping;
30626
30627 wait_queue_head_t irq_queue;
30628 - atomic_t irq_received;
30629 - atomic_t irq_emitted;
30630 + atomic_unchecked_t irq_received;
30631 + atomic_unchecked_t irq_emitted;
30632
30633 int use_mi_batchbuffer_start;
30634
30635 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i830/i830_irq.c linux-2.6.32.46/drivers/gpu/drm/i830/i830_irq.c
30636 --- linux-2.6.32.46/drivers/gpu/drm/i830/i830_irq.c 2011-03-27 14:31:47.000000000 -0400
30637 +++ linux-2.6.32.46/drivers/gpu/drm/i830/i830_irq.c 2011-05-04 17:56:28.000000000 -0400
30638 @@ -47,7 +47,7 @@ irqreturn_t i830_driver_irq_handler(DRM_
30639
30640 I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
30641
30642 - atomic_inc(&dev_priv->irq_received);
30643 + atomic_inc_unchecked(&dev_priv->irq_received);
30644 wake_up_interruptible(&dev_priv->irq_queue);
30645
30646 return IRQ_HANDLED;
30647 @@ -60,14 +60,14 @@ static int i830_emit_irq(struct drm_devi
30648
30649 DRM_DEBUG("%s\n", __func__);
30650
30651 - atomic_inc(&dev_priv->irq_emitted);
30652 + atomic_inc_unchecked(&dev_priv->irq_emitted);
30653
30654 BEGIN_LP_RING(2);
30655 OUT_RING(0);
30656 OUT_RING(GFX_OP_USER_INTERRUPT);
30657 ADVANCE_LP_RING();
30658
30659 - return atomic_read(&dev_priv->irq_emitted);
30660 + return atomic_read_unchecked(&dev_priv->irq_emitted);
30661 }
30662
30663 static int i830_wait_irq(struct drm_device * dev, int irq_nr)
30664 @@ -79,7 +79,7 @@ static int i830_wait_irq(struct drm_devi
30665
30666 DRM_DEBUG("%s\n", __func__);
30667
30668 - if (atomic_read(&dev_priv->irq_received) >= irq_nr)
30669 + if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
30670 return 0;
30671
30672 dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
30673 @@ -88,7 +88,7 @@ static int i830_wait_irq(struct drm_devi
30674
30675 for (;;) {
30676 __set_current_state(TASK_INTERRUPTIBLE);
30677 - if (atomic_read(&dev_priv->irq_received) >= irq_nr)
30678 + if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
30679 break;
30680 if ((signed)(end - jiffies) <= 0) {
30681 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
30682 @@ -163,8 +163,8 @@ void i830_driver_irq_preinstall(struct d
30683 I830_WRITE16(I830REG_HWSTAM, 0xffff);
30684 I830_WRITE16(I830REG_INT_MASK_R, 0x0);
30685 I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
30686 - atomic_set(&dev_priv->irq_received, 0);
30687 - atomic_set(&dev_priv->irq_emitted, 0);
30688 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30689 + atomic_set_unchecked(&dev_priv->irq_emitted, 0);
30690 init_waitqueue_head(&dev_priv->irq_queue);
30691 }
30692
30693 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/dvo.h linux-2.6.32.46/drivers/gpu/drm/i915/dvo.h
30694 --- linux-2.6.32.46/drivers/gpu/drm/i915/dvo.h 2011-03-27 14:31:47.000000000 -0400
30695 +++ linux-2.6.32.46/drivers/gpu/drm/i915/dvo.h 2011-04-17 15:56:46.000000000 -0400
30696 @@ -135,23 +135,23 @@ struct intel_dvo_dev_ops {
30697 *
30698 * \return singly-linked list of modes or NULL if no modes found.
30699 */
30700 - struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
30701 + struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
30702
30703 /**
30704 * Clean up driver-specific bits of the output
30705 */
30706 - void (*destroy) (struct intel_dvo_device *dvo);
30707 + void (* const destroy) (struct intel_dvo_device *dvo);
30708
30709 /**
30710 * Debugging hook to dump device registers to log file
30711 */
30712 - void (*dump_regs)(struct intel_dvo_device *dvo);
30713 + void (* const dump_regs)(struct intel_dvo_device *dvo);
30714 };
30715
30716 -extern struct intel_dvo_dev_ops sil164_ops;
30717 -extern struct intel_dvo_dev_ops ch7xxx_ops;
30718 -extern struct intel_dvo_dev_ops ivch_ops;
30719 -extern struct intel_dvo_dev_ops tfp410_ops;
30720 -extern struct intel_dvo_dev_ops ch7017_ops;
30721 +extern const struct intel_dvo_dev_ops sil164_ops;
30722 +extern const struct intel_dvo_dev_ops ch7xxx_ops;
30723 +extern const struct intel_dvo_dev_ops ivch_ops;
30724 +extern const struct intel_dvo_dev_ops tfp410_ops;
30725 +extern const struct intel_dvo_dev_ops ch7017_ops;
30726
30727 #endif /* _INTEL_DVO_H */
30728 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ch7017.c linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ch7017.c
30729 --- linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ch7017.c 2011-03-27 14:31:47.000000000 -0400
30730 +++ linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ch7017.c 2011-04-17 15:56:46.000000000 -0400
30731 @@ -443,7 +443,7 @@ static void ch7017_destroy(struct intel_
30732 }
30733 }
30734
30735 -struct intel_dvo_dev_ops ch7017_ops = {
30736 +const struct intel_dvo_dev_ops ch7017_ops = {
30737 .init = ch7017_init,
30738 .detect = ch7017_detect,
30739 .mode_valid = ch7017_mode_valid,
30740 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ch7xxx.c linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ch7xxx.c
30741 --- linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-03-27 14:31:47.000000000 -0400
30742 +++ linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-04-17 15:56:46.000000000 -0400
30743 @@ -356,7 +356,7 @@ static void ch7xxx_destroy(struct intel_
30744 }
30745 }
30746
30747 -struct intel_dvo_dev_ops ch7xxx_ops = {
30748 +const struct intel_dvo_dev_ops ch7xxx_ops = {
30749 .init = ch7xxx_init,
30750 .detect = ch7xxx_detect,
30751 .mode_valid = ch7xxx_mode_valid,
30752 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ivch.c linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ivch.c
30753 --- linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ivch.c 2011-03-27 14:31:47.000000000 -0400
30754 +++ linux-2.6.32.46/drivers/gpu/drm/i915/dvo_ivch.c 2011-04-17 15:56:46.000000000 -0400
30755 @@ -430,7 +430,7 @@ static void ivch_destroy(struct intel_dv
30756 }
30757 }
30758
30759 -struct intel_dvo_dev_ops ivch_ops= {
30760 +const struct intel_dvo_dev_ops ivch_ops= {
30761 .init = ivch_init,
30762 .dpms = ivch_dpms,
30763 .save = ivch_save,
30764 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/dvo_sil164.c linux-2.6.32.46/drivers/gpu/drm/i915/dvo_sil164.c
30765 --- linux-2.6.32.46/drivers/gpu/drm/i915/dvo_sil164.c 2011-03-27 14:31:47.000000000 -0400
30766 +++ linux-2.6.32.46/drivers/gpu/drm/i915/dvo_sil164.c 2011-04-17 15:56:46.000000000 -0400
30767 @@ -290,7 +290,7 @@ static void sil164_destroy(struct intel_
30768 }
30769 }
30770
30771 -struct intel_dvo_dev_ops sil164_ops = {
30772 +const struct intel_dvo_dev_ops sil164_ops = {
30773 .init = sil164_init,
30774 .detect = sil164_detect,
30775 .mode_valid = sil164_mode_valid,
30776 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/dvo_tfp410.c linux-2.6.32.46/drivers/gpu/drm/i915/dvo_tfp410.c
30777 --- linux-2.6.32.46/drivers/gpu/drm/i915/dvo_tfp410.c 2011-03-27 14:31:47.000000000 -0400
30778 +++ linux-2.6.32.46/drivers/gpu/drm/i915/dvo_tfp410.c 2011-04-17 15:56:46.000000000 -0400
30779 @@ -323,7 +323,7 @@ static void tfp410_destroy(struct intel_
30780 }
30781 }
30782
30783 -struct intel_dvo_dev_ops tfp410_ops = {
30784 +const struct intel_dvo_dev_ops tfp410_ops = {
30785 .init = tfp410_init,
30786 .detect = tfp410_detect,
30787 .mode_valid = tfp410_mode_valid,
30788 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/i915_debugfs.c linux-2.6.32.46/drivers/gpu/drm/i915/i915_debugfs.c
30789 --- linux-2.6.32.46/drivers/gpu/drm/i915/i915_debugfs.c 2011-03-27 14:31:47.000000000 -0400
30790 +++ linux-2.6.32.46/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-04 17:56:28.000000000 -0400
30791 @@ -192,7 +192,7 @@ static int i915_interrupt_info(struct se
30792 I915_READ(GTIMR));
30793 }
30794 seq_printf(m, "Interrupts received: %d\n",
30795 - atomic_read(&dev_priv->irq_received));
30796 + atomic_read_unchecked(&dev_priv->irq_received));
30797 if (dev_priv->hw_status_page != NULL) {
30798 seq_printf(m, "Current sequence: %d\n",
30799 i915_get_gem_seqno(dev));
30800 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/i915_drv.c linux-2.6.32.46/drivers/gpu/drm/i915/i915_drv.c
30801 --- linux-2.6.32.46/drivers/gpu/drm/i915/i915_drv.c 2011-03-27 14:31:47.000000000 -0400
30802 +++ linux-2.6.32.46/drivers/gpu/drm/i915/i915_drv.c 2011-04-17 15:56:46.000000000 -0400
30803 @@ -285,7 +285,7 @@ i915_pci_resume(struct pci_dev *pdev)
30804 return i915_resume(dev);
30805 }
30806
30807 -static struct vm_operations_struct i915_gem_vm_ops = {
30808 +static const struct vm_operations_struct i915_gem_vm_ops = {
30809 .fault = i915_gem_fault,
30810 .open = drm_gem_vm_open,
30811 .close = drm_gem_vm_close,
30812 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/i915_drv.h linux-2.6.32.46/drivers/gpu/drm/i915/i915_drv.h
30813 --- linux-2.6.32.46/drivers/gpu/drm/i915/i915_drv.h 2011-03-27 14:31:47.000000000 -0400
30814 +++ linux-2.6.32.46/drivers/gpu/drm/i915/i915_drv.h 2011-08-05 20:33:55.000000000 -0400
30815 @@ -168,7 +168,7 @@ struct drm_i915_display_funcs {
30816 /* display clock increase/decrease */
30817 /* pll clock increase/decrease */
30818 /* clock gating init */
30819 -};
30820 +} __no_const;
30821
30822 typedef struct drm_i915_private {
30823 struct drm_device *dev;
30824 @@ -197,7 +197,7 @@ typedef struct drm_i915_private {
30825 int page_flipping;
30826
30827 wait_queue_head_t irq_queue;
30828 - atomic_t irq_received;
30829 + atomic_unchecked_t irq_received;
30830 /** Protects user_irq_refcount and irq_mask_reg */
30831 spinlock_t user_irq_lock;
30832 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
30833 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/i915_gem.c linux-2.6.32.46/drivers/gpu/drm/i915/i915_gem.c
30834 --- linux-2.6.32.46/drivers/gpu/drm/i915/i915_gem.c 2011-03-27 14:31:47.000000000 -0400
30835 +++ linux-2.6.32.46/drivers/gpu/drm/i915/i915_gem.c 2011-04-17 15:56:46.000000000 -0400
30836 @@ -102,7 +102,7 @@ i915_gem_get_aperture_ioctl(struct drm_d
30837
30838 args->aper_size = dev->gtt_total;
30839 args->aper_available_size = (args->aper_size -
30840 - atomic_read(&dev->pin_memory));
30841 + atomic_read_unchecked(&dev->pin_memory));
30842
30843 return 0;
30844 }
30845 @@ -492,6 +492,11 @@ i915_gem_pread_ioctl(struct drm_device *
30846 return -EINVAL;
30847 }
30848
30849 + if (!access_ok(VERIFY_WRITE, (char __user *) (uintptr_t)args->data_ptr, args->size)) {
30850 + drm_gem_object_unreference(obj);
30851 + return -EFAULT;
30852 + }
30853 +
30854 if (i915_gem_object_needs_bit17_swizzle(obj)) {
30855 ret = i915_gem_shmem_pread_slow(dev, obj, args, file_priv);
30856 } else {
30857 @@ -965,6 +970,11 @@ i915_gem_pwrite_ioctl(struct drm_device
30858 return -EINVAL;
30859 }
30860
30861 + if (!access_ok(VERIFY_READ, (char __user *) (uintptr_t)args->data_ptr, args->size)) {
30862 + drm_gem_object_unreference(obj);
30863 + return -EFAULT;
30864 + }
30865 +
30866 /* We can only do the GTT pwrite on untiled buffers, as otherwise
30867 * it would end up going through the fenced access, and we'll get
30868 * different detiling behavior between reading and writing.
30869 @@ -2054,7 +2064,7 @@ i915_gem_object_unbind(struct drm_gem_ob
30870
30871 if (obj_priv->gtt_space) {
30872 atomic_dec(&dev->gtt_count);
30873 - atomic_sub(obj->size, &dev->gtt_memory);
30874 + atomic_sub_unchecked(obj->size, &dev->gtt_memory);
30875
30876 drm_mm_put_block(obj_priv->gtt_space);
30877 obj_priv->gtt_space = NULL;
30878 @@ -2697,7 +2707,7 @@ i915_gem_object_bind_to_gtt(struct drm_g
30879 goto search_free;
30880 }
30881 atomic_inc(&dev->gtt_count);
30882 - atomic_add(obj->size, &dev->gtt_memory);
30883 + atomic_add_unchecked(obj->size, &dev->gtt_memory);
30884
30885 /* Assert that the object is not currently in any GPU domain. As it
30886 * wasn't in the GTT, there shouldn't be any way it could have been in
30887 @@ -3751,9 +3761,9 @@ i915_gem_execbuffer(struct drm_device *d
30888 "%d/%d gtt bytes\n",
30889 atomic_read(&dev->object_count),
30890 atomic_read(&dev->pin_count),
30891 - atomic_read(&dev->object_memory),
30892 - atomic_read(&dev->pin_memory),
30893 - atomic_read(&dev->gtt_memory),
30894 + atomic_read_unchecked(&dev->object_memory),
30895 + atomic_read_unchecked(&dev->pin_memory),
30896 + atomic_read_unchecked(&dev->gtt_memory),
30897 dev->gtt_total);
30898 }
30899 goto err;
30900 @@ -3985,7 +3995,7 @@ i915_gem_object_pin(struct drm_gem_objec
30901 */
30902 if (obj_priv->pin_count == 1) {
30903 atomic_inc(&dev->pin_count);
30904 - atomic_add(obj->size, &dev->pin_memory);
30905 + atomic_add_unchecked(obj->size, &dev->pin_memory);
30906 if (!obj_priv->active &&
30907 (obj->write_domain & I915_GEM_GPU_DOMAINS) == 0 &&
30908 !list_empty(&obj_priv->list))
30909 @@ -4018,7 +4028,7 @@ i915_gem_object_unpin(struct drm_gem_obj
30910 list_move_tail(&obj_priv->list,
30911 &dev_priv->mm.inactive_list);
30912 atomic_dec(&dev->pin_count);
30913 - atomic_sub(obj->size, &dev->pin_memory);
30914 + atomic_sub_unchecked(obj->size, &dev->pin_memory);
30915 }
30916 i915_verify_inactive(dev, __FILE__, __LINE__);
30917 }
30918 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/i915_irq.c linux-2.6.32.46/drivers/gpu/drm/i915/i915_irq.c
30919 --- linux-2.6.32.46/drivers/gpu/drm/i915/i915_irq.c 2011-03-27 14:31:47.000000000 -0400
30920 +++ linux-2.6.32.46/drivers/gpu/drm/i915/i915_irq.c 2011-05-04 17:56:28.000000000 -0400
30921 @@ -528,7 +528,7 @@ irqreturn_t i915_driver_irq_handler(DRM_
30922 int irq_received;
30923 int ret = IRQ_NONE;
30924
30925 - atomic_inc(&dev_priv->irq_received);
30926 + atomic_inc_unchecked(&dev_priv->irq_received);
30927
30928 if (IS_IGDNG(dev))
30929 return igdng_irq_handler(dev);
30930 @@ -1021,7 +1021,7 @@ void i915_driver_irq_preinstall(struct d
30931 {
30932 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30933
30934 - atomic_set(&dev_priv->irq_received, 0);
30935 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30936
30937 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30938 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30939 diff -urNp linux-2.6.32.46/drivers/gpu/drm/i915/intel_sdvo.c linux-2.6.32.46/drivers/gpu/drm/i915/intel_sdvo.c
30940 --- linux-2.6.32.46/drivers/gpu/drm/i915/intel_sdvo.c 2011-03-27 14:31:47.000000000 -0400
30941 +++ linux-2.6.32.46/drivers/gpu/drm/i915/intel_sdvo.c 2011-08-05 20:33:55.000000000 -0400
30942 @@ -2795,7 +2795,9 @@ bool intel_sdvo_init(struct drm_device *
30943 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
30944
30945 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
30946 - intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
30947 + pax_open_kernel();
30948 + *(void **)&intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
30949 + pax_close_kernel();
30950
30951 /* Read the regs to test if we can talk to the device */
30952 for (i = 0; i < 0x40; i++) {
30953 diff -urNp linux-2.6.32.46/drivers/gpu/drm/mga/mga_drv.h linux-2.6.32.46/drivers/gpu/drm/mga/mga_drv.h
30954 --- linux-2.6.32.46/drivers/gpu/drm/mga/mga_drv.h 2011-03-27 14:31:47.000000000 -0400
30955 +++ linux-2.6.32.46/drivers/gpu/drm/mga/mga_drv.h 2011-05-04 17:56:28.000000000 -0400
30956 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30957 u32 clear_cmd;
30958 u32 maccess;
30959
30960 - atomic_t vbl_received; /**< Number of vblanks received. */
30961 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30962 wait_queue_head_t fence_queue;
30963 - atomic_t last_fence_retired;
30964 + atomic_unchecked_t last_fence_retired;
30965 u32 next_fence_to_post;
30966
30967 unsigned int fb_cpp;
30968 diff -urNp linux-2.6.32.46/drivers/gpu/drm/mga/mga_irq.c linux-2.6.32.46/drivers/gpu/drm/mga/mga_irq.c
30969 --- linux-2.6.32.46/drivers/gpu/drm/mga/mga_irq.c 2011-03-27 14:31:47.000000000 -0400
30970 +++ linux-2.6.32.46/drivers/gpu/drm/mga/mga_irq.c 2011-05-04 17:56:28.000000000 -0400
30971 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
30972 if (crtc != 0)
30973 return 0;
30974
30975 - return atomic_read(&dev_priv->vbl_received);
30976 + return atomic_read_unchecked(&dev_priv->vbl_received);
30977 }
30978
30979
30980 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
30981 /* VBLANK interrupt */
30982 if (status & MGA_VLINEPEN) {
30983 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30984 - atomic_inc(&dev_priv->vbl_received);
30985 + atomic_inc_unchecked(&dev_priv->vbl_received);
30986 drm_handle_vblank(dev, 0);
30987 handled = 1;
30988 }
30989 @@ -80,7 +80,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
30990 MGA_WRITE(MGA_PRIMEND, prim_end);
30991 }
30992
30993 - atomic_inc(&dev_priv->last_fence_retired);
30994 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30995 DRM_WAKEUP(&dev_priv->fence_queue);
30996 handled = 1;
30997 }
30998 @@ -131,7 +131,7 @@ int mga_driver_fence_wait(struct drm_dev
30999 * using fences.
31000 */
31001 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31002 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31003 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31004 - *sequence) <= (1 << 23)));
31005
31006 *sequence = cur_fence;
31007 diff -urNp linux-2.6.32.46/drivers/gpu/drm/r128/r128_cce.c linux-2.6.32.46/drivers/gpu/drm/r128/r128_cce.c
31008 --- linux-2.6.32.46/drivers/gpu/drm/r128/r128_cce.c 2011-03-27 14:31:47.000000000 -0400
31009 +++ linux-2.6.32.46/drivers/gpu/drm/r128/r128_cce.c 2011-05-04 17:56:28.000000000 -0400
31010 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
31011
31012 /* GH: Simple idle check.
31013 */
31014 - atomic_set(&dev_priv->idle_count, 0);
31015 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31016
31017 /* We don't support anything other than bus-mastering ring mode,
31018 * but the ring can be in either AGP or PCI space for the ring
31019 diff -urNp linux-2.6.32.46/drivers/gpu/drm/r128/r128_drv.h linux-2.6.32.46/drivers/gpu/drm/r128/r128_drv.h
31020 --- linux-2.6.32.46/drivers/gpu/drm/r128/r128_drv.h 2011-03-27 14:31:47.000000000 -0400
31021 +++ linux-2.6.32.46/drivers/gpu/drm/r128/r128_drv.h 2011-05-04 17:56:28.000000000 -0400
31022 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31023 int is_pci;
31024 unsigned long cce_buffers_offset;
31025
31026 - atomic_t idle_count;
31027 + atomic_unchecked_t idle_count;
31028
31029 int page_flipping;
31030 int current_page;
31031 u32 crtc_offset;
31032 u32 crtc_offset_cntl;
31033
31034 - atomic_t vbl_received;
31035 + atomic_unchecked_t vbl_received;
31036
31037 u32 color_fmt;
31038 unsigned int front_offset;
31039 diff -urNp linux-2.6.32.46/drivers/gpu/drm/r128/r128_irq.c linux-2.6.32.46/drivers/gpu/drm/r128/r128_irq.c
31040 --- linux-2.6.32.46/drivers/gpu/drm/r128/r128_irq.c 2011-03-27 14:31:47.000000000 -0400
31041 +++ linux-2.6.32.46/drivers/gpu/drm/r128/r128_irq.c 2011-05-04 17:56:28.000000000 -0400
31042 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
31043 if (crtc != 0)
31044 return 0;
31045
31046 - return atomic_read(&dev_priv->vbl_received);
31047 + return atomic_read_unchecked(&dev_priv->vbl_received);
31048 }
31049
31050 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31051 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
31052 /* VBLANK interrupt */
31053 if (status & R128_CRTC_VBLANK_INT) {
31054 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31055 - atomic_inc(&dev_priv->vbl_received);
31056 + atomic_inc_unchecked(&dev_priv->vbl_received);
31057 drm_handle_vblank(dev, 0);
31058 return IRQ_HANDLED;
31059 }
31060 diff -urNp linux-2.6.32.46/drivers/gpu/drm/r128/r128_state.c linux-2.6.32.46/drivers/gpu/drm/r128/r128_state.c
31061 --- linux-2.6.32.46/drivers/gpu/drm/r128/r128_state.c 2011-03-27 14:31:47.000000000 -0400
31062 +++ linux-2.6.32.46/drivers/gpu/drm/r128/r128_state.c 2011-05-04 17:56:28.000000000 -0400
31063 @@ -323,10 +323,10 @@ static void r128_clear_box(drm_r128_priv
31064
31065 static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
31066 {
31067 - if (atomic_read(&dev_priv->idle_count) == 0) {
31068 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0) {
31069 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31070 } else {
31071 - atomic_set(&dev_priv->idle_count, 0);
31072 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31073 }
31074 }
31075
31076 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/atom.c linux-2.6.32.46/drivers/gpu/drm/radeon/atom.c
31077 --- linux-2.6.32.46/drivers/gpu/drm/radeon/atom.c 2011-05-10 22:12:01.000000000 -0400
31078 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/atom.c 2011-05-16 21:46:57.000000000 -0400
31079 @@ -1115,6 +1115,8 @@ struct atom_context *atom_parse(struct c
31080 char name[512];
31081 int i;
31082
31083 + pax_track_stack();
31084 +
31085 ctx->card = card;
31086 ctx->bios = bios;
31087
31088 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.32.46/drivers/gpu/drm/radeon/mkregtable.c
31089 --- linux-2.6.32.46/drivers/gpu/drm/radeon/mkregtable.c 2011-03-27 14:31:47.000000000 -0400
31090 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/mkregtable.c 2011-04-17 15:56:46.000000000 -0400
31091 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
31092 regex_t mask_rex;
31093 regmatch_t match[4];
31094 char buf[1024];
31095 - size_t end;
31096 + long end;
31097 int len;
31098 int done = 0;
31099 int r;
31100 unsigned o;
31101 struct offset *offset;
31102 char last_reg_s[10];
31103 - int last_reg;
31104 + unsigned long last_reg;
31105
31106 if (regcomp
31107 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31108 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/radeon.h linux-2.6.32.46/drivers/gpu/drm/radeon/radeon.h
31109 --- linux-2.6.32.46/drivers/gpu/drm/radeon/radeon.h 2011-03-27 14:31:47.000000000 -0400
31110 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/radeon.h 2011-08-05 20:33:55.000000000 -0400
31111 @@ -149,7 +149,7 @@ int radeon_pm_init(struct radeon_device
31112 */
31113 struct radeon_fence_driver {
31114 uint32_t scratch_reg;
31115 - atomic_t seq;
31116 + atomic_unchecked_t seq;
31117 uint32_t last_seq;
31118 unsigned long count_timeout;
31119 wait_queue_head_t queue;
31120 @@ -640,7 +640,7 @@ struct radeon_asic {
31121 uint32_t offset, uint32_t obj_size);
31122 int (*clear_surface_reg)(struct radeon_device *rdev, int reg);
31123 void (*bandwidth_update)(struct radeon_device *rdev);
31124 -};
31125 +} __no_const;
31126
31127 /*
31128 * Asic structures
31129 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_atombios.c linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_atombios.c
31130 --- linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_atombios.c 2011-03-27 14:31:47.000000000 -0400
31131 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-16 21:46:57.000000000 -0400
31132 @@ -275,6 +275,8 @@ bool radeon_get_atom_connector_info_from
31133 bool linkb;
31134 struct radeon_i2c_bus_rec ddc_bus;
31135
31136 + pax_track_stack();
31137 +
31138 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
31139
31140 if (data_offset == 0)
31141 @@ -520,13 +522,13 @@ static uint16_t atombios_get_connector_o
31142 }
31143 }
31144
31145 -struct bios_connector {
31146 +static struct bios_connector {
31147 bool valid;
31148 uint16_t line_mux;
31149 uint16_t devices;
31150 int connector_type;
31151 struct radeon_i2c_bus_rec ddc_bus;
31152 -};
31153 +} bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
31154
31155 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
31156 drm_device
31157 @@ -542,7 +544,6 @@ bool radeon_get_atom_connector_info_from
31158 uint8_t dac;
31159 union atom_supported_devices *supported_devices;
31160 int i, j;
31161 - struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
31162
31163 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
31164
31165 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_display.c linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_display.c
31166 --- linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_display.c 2011-03-27 14:31:47.000000000 -0400
31167 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_display.c 2011-04-17 15:56:46.000000000 -0400
31168 @@ -482,7 +482,7 @@ void radeon_compute_pll(struct radeon_pl
31169
31170 if (flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
31171 error = freq - current_freq;
31172 - error = error < 0 ? 0xffffffff : error;
31173 + error = (int32_t)error < 0 ? 0xffffffff : error;
31174 } else
31175 error = abs(current_freq - freq);
31176 vco_diff = abs(vco - best_vco);
31177 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_drv.h linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_drv.h
31178 --- linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_drv.h 2011-03-27 14:31:47.000000000 -0400
31179 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-04 17:56:28.000000000 -0400
31180 @@ -253,7 +253,7 @@ typedef struct drm_radeon_private {
31181
31182 /* SW interrupt */
31183 wait_queue_head_t swi_queue;
31184 - atomic_t swi_emitted;
31185 + atomic_unchecked_t swi_emitted;
31186 int vblank_crtc;
31187 uint32_t irq_enable_reg;
31188 uint32_t r500_disp_irq_reg;
31189 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_fence.c linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_fence.c
31190 --- linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_fence.c 2011-03-27 14:31:47.000000000 -0400
31191 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-04 17:56:28.000000000 -0400
31192 @@ -47,7 +47,7 @@ int radeon_fence_emit(struct radeon_devi
31193 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
31194 return 0;
31195 }
31196 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
31197 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
31198 if (!rdev->cp.ready) {
31199 /* FIXME: cp is not running assume everythings is done right
31200 * away
31201 @@ -364,7 +364,7 @@ int radeon_fence_driver_init(struct rade
31202 return r;
31203 }
31204 WREG32(rdev->fence_drv.scratch_reg, 0);
31205 - atomic_set(&rdev->fence_drv.seq, 0);
31206 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
31207 INIT_LIST_HEAD(&rdev->fence_drv.created);
31208 INIT_LIST_HEAD(&rdev->fence_drv.emited);
31209 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
31210 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_ioc32.c linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_ioc32.c
31211 --- linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-03-27 14:31:47.000000000 -0400
31212 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-04-23 13:57:24.000000000 -0400
31213 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(str
31214 request = compat_alloc_user_space(sizeof(*request));
31215 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31216 || __put_user(req32.param, &request->param)
31217 - || __put_user((void __user *)(unsigned long)req32.value,
31218 + || __put_user((unsigned long)req32.value,
31219 &request->value))
31220 return -EFAULT;
31221
31222 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_irq.c linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_irq.c
31223 --- linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_irq.c 2011-03-27 14:31:47.000000000 -0400
31224 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-04 17:56:28.000000000 -0400
31225 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
31226 unsigned int ret;
31227 RING_LOCALS;
31228
31229 - atomic_inc(&dev_priv->swi_emitted);
31230 - ret = atomic_read(&dev_priv->swi_emitted);
31231 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31232 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31233
31234 BEGIN_RING(4);
31235 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31236 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
31237 drm_radeon_private_t *dev_priv =
31238 (drm_radeon_private_t *) dev->dev_private;
31239
31240 - atomic_set(&dev_priv->swi_emitted, 0);
31241 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31242 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31243
31244 dev->max_vblank_count = 0x001fffff;
31245 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_state.c linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_state.c
31246 --- linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_state.c 2011-03-27 14:31:47.000000000 -0400
31247 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_state.c 2011-04-17 15:56:46.000000000 -0400
31248 @@ -3021,7 +3021,7 @@ static int radeon_cp_getparam(struct drm
31249 {
31250 drm_radeon_private_t *dev_priv = dev->dev_private;
31251 drm_radeon_getparam_t *param = data;
31252 - int value;
31253 + int value = 0;
31254
31255 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31256
31257 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_ttm.c linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_ttm.c
31258 --- linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_ttm.c 2011-03-27 14:31:47.000000000 -0400
31259 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/radeon_ttm.c 2011-04-17 15:56:46.000000000 -0400
31260 @@ -535,27 +535,10 @@ void radeon_ttm_fini(struct radeon_devic
31261 DRM_INFO("radeon: ttm finalized\n");
31262 }
31263
31264 -static struct vm_operations_struct radeon_ttm_vm_ops;
31265 -static const struct vm_operations_struct *ttm_vm_ops = NULL;
31266 -
31267 -static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
31268 -{
31269 - struct ttm_buffer_object *bo;
31270 - int r;
31271 -
31272 - bo = (struct ttm_buffer_object *)vma->vm_private_data;
31273 - if (bo == NULL) {
31274 - return VM_FAULT_NOPAGE;
31275 - }
31276 - r = ttm_vm_ops->fault(vma, vmf);
31277 - return r;
31278 -}
31279 -
31280 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31281 {
31282 struct drm_file *file_priv;
31283 struct radeon_device *rdev;
31284 - int r;
31285
31286 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) {
31287 return drm_mmap(filp, vma);
31288 @@ -563,20 +546,9 @@ int radeon_mmap(struct file *filp, struc
31289
31290 file_priv = (struct drm_file *)filp->private_data;
31291 rdev = file_priv->minor->dev->dev_private;
31292 - if (rdev == NULL) {
31293 + if (!rdev)
31294 return -EINVAL;
31295 - }
31296 - r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
31297 - if (unlikely(r != 0)) {
31298 - return r;
31299 - }
31300 - if (unlikely(ttm_vm_ops == NULL)) {
31301 - ttm_vm_ops = vma->vm_ops;
31302 - radeon_ttm_vm_ops = *ttm_vm_ops;
31303 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31304 - }
31305 - vma->vm_ops = &radeon_ttm_vm_ops;
31306 - return 0;
31307 + return ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
31308 }
31309
31310
31311 diff -urNp linux-2.6.32.46/drivers/gpu/drm/radeon/rs690.c linux-2.6.32.46/drivers/gpu/drm/radeon/rs690.c
31312 --- linux-2.6.32.46/drivers/gpu/drm/radeon/rs690.c 2011-03-27 14:31:47.000000000 -0400
31313 +++ linux-2.6.32.46/drivers/gpu/drm/radeon/rs690.c 2011-04-17 15:56:46.000000000 -0400
31314 @@ -302,9 +302,11 @@ void rs690_crtc_bandwidth_compute(struct
31315 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31316 rdev->pm.sideport_bandwidth.full)
31317 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31318 - read_delay_latency.full = rfixed_const(370 * 800 * 1000);
31319 + read_delay_latency.full = rfixed_const(800 * 1000);
31320 read_delay_latency.full = rfixed_div(read_delay_latency,
31321 rdev->pm.igp_sideport_mclk);
31322 + a.full = rfixed_const(370);
31323 + read_delay_latency.full = rfixed_mul(read_delay_latency, a);
31324 } else {
31325 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31326 rdev->pm.k8_bandwidth.full)
31327 diff -urNp linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_bo.c linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_bo.c
31328 --- linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_bo.c 2011-08-29 22:24:44.000000000 -0400
31329 +++ linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_bo.c 2011-08-29 22:25:07.000000000 -0400
31330 @@ -67,7 +67,7 @@ static struct attribute *ttm_bo_global_a
31331 NULL
31332 };
31333
31334 -static struct sysfs_ops ttm_bo_global_ops = {
31335 +static const struct sysfs_ops ttm_bo_global_ops = {
31336 .show = &ttm_bo_global_show
31337 };
31338
31339 diff -urNp linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_bo_vm.c linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_bo_vm.c
31340 --- linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-03-27 14:31:47.000000000 -0400
31341 +++ linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-04-17 15:56:46.000000000 -0400
31342 @@ -73,7 +73,7 @@ static int ttm_bo_vm_fault(struct vm_are
31343 {
31344 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
31345 vma->vm_private_data;
31346 - struct ttm_bo_device *bdev = bo->bdev;
31347 + struct ttm_bo_device *bdev;
31348 unsigned long bus_base;
31349 unsigned long bus_offset;
31350 unsigned long bus_size;
31351 @@ -88,6 +88,10 @@ static int ttm_bo_vm_fault(struct vm_are
31352 unsigned long address = (unsigned long)vmf->virtual_address;
31353 int retval = VM_FAULT_NOPAGE;
31354
31355 + if (!bo)
31356 + return VM_FAULT_NOPAGE;
31357 + bdev = bo->bdev;
31358 +
31359 /*
31360 * Work around locking order reversal in fault / nopfn
31361 * between mmap_sem and bo_reserve: Perform a trylock operation
31362 diff -urNp linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_global.c linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_global.c
31363 --- linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_global.c 2011-03-27 14:31:47.000000000 -0400
31364 +++ linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_global.c 2011-04-17 15:56:46.000000000 -0400
31365 @@ -36,7 +36,7 @@
31366 struct ttm_global_item {
31367 struct mutex mutex;
31368 void *object;
31369 - int refcount;
31370 + atomic_t refcount;
31371 };
31372
31373 static struct ttm_global_item glob[TTM_GLOBAL_NUM];
31374 @@ -49,7 +49,7 @@ void ttm_global_init(void)
31375 struct ttm_global_item *item = &glob[i];
31376 mutex_init(&item->mutex);
31377 item->object = NULL;
31378 - item->refcount = 0;
31379 + atomic_set(&item->refcount, 0);
31380 }
31381 }
31382
31383 @@ -59,7 +59,7 @@ void ttm_global_release(void)
31384 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
31385 struct ttm_global_item *item = &glob[i];
31386 BUG_ON(item->object != NULL);
31387 - BUG_ON(item->refcount != 0);
31388 + BUG_ON(atomic_read(&item->refcount) != 0);
31389 }
31390 }
31391
31392 @@ -70,7 +70,7 @@ int ttm_global_item_ref(struct ttm_globa
31393 void *object;
31394
31395 mutex_lock(&item->mutex);
31396 - if (item->refcount == 0) {
31397 + if (atomic_read(&item->refcount) == 0) {
31398 item->object = kzalloc(ref->size, GFP_KERNEL);
31399 if (unlikely(item->object == NULL)) {
31400 ret = -ENOMEM;
31401 @@ -83,7 +83,7 @@ int ttm_global_item_ref(struct ttm_globa
31402 goto out_err;
31403
31404 }
31405 - ++item->refcount;
31406 + atomic_inc(&item->refcount);
31407 ref->object = item->object;
31408 object = item->object;
31409 mutex_unlock(&item->mutex);
31410 @@ -100,9 +100,9 @@ void ttm_global_item_unref(struct ttm_gl
31411 struct ttm_global_item *item = &glob[ref->global_type];
31412
31413 mutex_lock(&item->mutex);
31414 - BUG_ON(item->refcount == 0);
31415 + BUG_ON(atomic_read(&item->refcount) == 0);
31416 BUG_ON(ref->object != item->object);
31417 - if (--item->refcount == 0) {
31418 + if (atomic_dec_and_test(&item->refcount)) {
31419 ref->release(ref);
31420 item->object = NULL;
31421 }
31422 diff -urNp linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_memory.c linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_memory.c
31423 --- linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_memory.c 2011-03-27 14:31:47.000000000 -0400
31424 +++ linux-2.6.32.46/drivers/gpu/drm/ttm/ttm_memory.c 2011-04-17 15:56:46.000000000 -0400
31425 @@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_at
31426 NULL
31427 };
31428
31429 -static struct sysfs_ops ttm_mem_zone_ops = {
31430 +static const struct sysfs_ops ttm_mem_zone_ops = {
31431 .show = &ttm_mem_zone_show,
31432 .store = &ttm_mem_zone_store
31433 };
31434 diff -urNp linux-2.6.32.46/drivers/gpu/drm/via/via_drv.h linux-2.6.32.46/drivers/gpu/drm/via/via_drv.h
31435 --- linux-2.6.32.46/drivers/gpu/drm/via/via_drv.h 2011-03-27 14:31:47.000000000 -0400
31436 +++ linux-2.6.32.46/drivers/gpu/drm/via/via_drv.h 2011-05-04 17:56:28.000000000 -0400
31437 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31438 typedef uint32_t maskarray_t[5];
31439
31440 typedef struct drm_via_irq {
31441 - atomic_t irq_received;
31442 + atomic_unchecked_t irq_received;
31443 uint32_t pending_mask;
31444 uint32_t enable_mask;
31445 wait_queue_head_t irq_queue;
31446 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31447 struct timeval last_vblank;
31448 int last_vblank_valid;
31449 unsigned usec_per_vblank;
31450 - atomic_t vbl_received;
31451 + atomic_unchecked_t vbl_received;
31452 drm_via_state_t hc_state;
31453 char pci_buf[VIA_PCI_BUF_SIZE];
31454 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31455 diff -urNp linux-2.6.32.46/drivers/gpu/drm/via/via_irq.c linux-2.6.32.46/drivers/gpu/drm/via/via_irq.c
31456 --- linux-2.6.32.46/drivers/gpu/drm/via/via_irq.c 2011-03-27 14:31:47.000000000 -0400
31457 +++ linux-2.6.32.46/drivers/gpu/drm/via/via_irq.c 2011-05-04 17:56:28.000000000 -0400
31458 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
31459 if (crtc != 0)
31460 return 0;
31461
31462 - return atomic_read(&dev_priv->vbl_received);
31463 + return atomic_read_unchecked(&dev_priv->vbl_received);
31464 }
31465
31466 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31467 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
31468
31469 status = VIA_READ(VIA_REG_INTERRUPT);
31470 if (status & VIA_IRQ_VBLANK_PENDING) {
31471 - atomic_inc(&dev_priv->vbl_received);
31472 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31473 + atomic_inc_unchecked(&dev_priv->vbl_received);
31474 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31475 do_gettimeofday(&cur_vblank);
31476 if (dev_priv->last_vblank_valid) {
31477 dev_priv->usec_per_vblank =
31478 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
31479 dev_priv->last_vblank = cur_vblank;
31480 dev_priv->last_vblank_valid = 1;
31481 }
31482 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31483 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31484 DRM_DEBUG("US per vblank is: %u\n",
31485 dev_priv->usec_per_vblank);
31486 }
31487 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
31488
31489 for (i = 0; i < dev_priv->num_irqs; ++i) {
31490 if (status & cur_irq->pending_mask) {
31491 - atomic_inc(&cur_irq->irq_received);
31492 + atomic_inc_unchecked(&cur_irq->irq_received);
31493 DRM_WAKEUP(&cur_irq->irq_queue);
31494 handled = 1;
31495 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
31496 @@ -244,11 +244,11 @@ via_driver_irq_wait(struct drm_device *
31497 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31498 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31499 masks[irq][4]));
31500 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31501 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31502 } else {
31503 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31504 (((cur_irq_sequence =
31505 - atomic_read(&cur_irq->irq_received)) -
31506 + atomic_read_unchecked(&cur_irq->irq_received)) -
31507 *sequence) <= (1 << 23)));
31508 }
31509 *sequence = cur_irq_sequence;
31510 @@ -286,7 +286,7 @@ void via_driver_irq_preinstall(struct dr
31511 }
31512
31513 for (i = 0; i < dev_priv->num_irqs; ++i) {
31514 - atomic_set(&cur_irq->irq_received, 0);
31515 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31516 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31517 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31518 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31519 @@ -368,7 +368,7 @@ int via_wait_irq(struct drm_device *dev,
31520 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31521 case VIA_IRQ_RELATIVE:
31522 irqwait->request.sequence +=
31523 - atomic_read(&cur_irq->irq_received);
31524 + atomic_read_unchecked(&cur_irq->irq_received);
31525 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31526 case VIA_IRQ_ABSOLUTE:
31527 break;
31528 diff -urNp linux-2.6.32.46/drivers/hid/hid-core.c linux-2.6.32.46/drivers/hid/hid-core.c
31529 --- linux-2.6.32.46/drivers/hid/hid-core.c 2011-05-10 22:12:01.000000000 -0400
31530 +++ linux-2.6.32.46/drivers/hid/hid-core.c 2011-05-10 22:12:32.000000000 -0400
31531 @@ -1752,7 +1752,7 @@ static bool hid_ignore(struct hid_device
31532
31533 int hid_add_device(struct hid_device *hdev)
31534 {
31535 - static atomic_t id = ATOMIC_INIT(0);
31536 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31537 int ret;
31538
31539 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31540 @@ -1766,7 +1766,7 @@ int hid_add_device(struct hid_device *hd
31541 /* XXX hack, any other cleaner solution after the driver core
31542 * is converted to allow more than 20 bytes as the device name? */
31543 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31544 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31545 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31546
31547 ret = device_add(&hdev->dev);
31548 if (!ret)
31549 diff -urNp linux-2.6.32.46/drivers/hid/usbhid/hiddev.c linux-2.6.32.46/drivers/hid/usbhid/hiddev.c
31550 --- linux-2.6.32.46/drivers/hid/usbhid/hiddev.c 2011-03-27 14:31:47.000000000 -0400
31551 +++ linux-2.6.32.46/drivers/hid/usbhid/hiddev.c 2011-04-17 15:56:46.000000000 -0400
31552 @@ -617,7 +617,7 @@ static long hiddev_ioctl(struct file *fi
31553 return put_user(HID_VERSION, (int __user *)arg);
31554
31555 case HIDIOCAPPLICATION:
31556 - if (arg < 0 || arg >= hid->maxapplication)
31557 + if (arg >= hid->maxapplication)
31558 return -EINVAL;
31559
31560 for (i = 0; i < hid->maxcollection; i++)
31561 diff -urNp linux-2.6.32.46/drivers/hwmon/lis3lv02d.c linux-2.6.32.46/drivers/hwmon/lis3lv02d.c
31562 --- linux-2.6.32.46/drivers/hwmon/lis3lv02d.c 2011-03-27 14:31:47.000000000 -0400
31563 +++ linux-2.6.32.46/drivers/hwmon/lis3lv02d.c 2011-05-04 17:56:28.000000000 -0400
31564 @@ -146,7 +146,7 @@ static irqreturn_t lis302dl_interrupt(in
31565 * the lid is closed. This leads to interrupts as soon as a little move
31566 * is done.
31567 */
31568 - atomic_inc(&lis3_dev.count);
31569 + atomic_inc_unchecked(&lis3_dev.count);
31570
31571 wake_up_interruptible(&lis3_dev.misc_wait);
31572 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
31573 @@ -160,7 +160,7 @@ static int lis3lv02d_misc_open(struct in
31574 if (test_and_set_bit(0, &lis3_dev.misc_opened))
31575 return -EBUSY; /* already open */
31576
31577 - atomic_set(&lis3_dev.count, 0);
31578 + atomic_set_unchecked(&lis3_dev.count, 0);
31579
31580 /*
31581 * The sensor can generate interrupts for free-fall and direction
31582 @@ -206,7 +206,7 @@ static ssize_t lis3lv02d_misc_read(struc
31583 add_wait_queue(&lis3_dev.misc_wait, &wait);
31584 while (true) {
31585 set_current_state(TASK_INTERRUPTIBLE);
31586 - data = atomic_xchg(&lis3_dev.count, 0);
31587 + data = atomic_xchg_unchecked(&lis3_dev.count, 0);
31588 if (data)
31589 break;
31590
31591 @@ -244,7 +244,7 @@ out:
31592 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
31593 {
31594 poll_wait(file, &lis3_dev.misc_wait, wait);
31595 - if (atomic_read(&lis3_dev.count))
31596 + if (atomic_read_unchecked(&lis3_dev.count))
31597 return POLLIN | POLLRDNORM;
31598 return 0;
31599 }
31600 diff -urNp linux-2.6.32.46/drivers/hwmon/lis3lv02d.h linux-2.6.32.46/drivers/hwmon/lis3lv02d.h
31601 --- linux-2.6.32.46/drivers/hwmon/lis3lv02d.h 2011-03-27 14:31:47.000000000 -0400
31602 +++ linux-2.6.32.46/drivers/hwmon/lis3lv02d.h 2011-05-04 17:56:28.000000000 -0400
31603 @@ -201,7 +201,7 @@ struct lis3lv02d {
31604
31605 struct input_polled_dev *idev; /* input device */
31606 struct platform_device *pdev; /* platform device */
31607 - atomic_t count; /* interrupt count after last read */
31608 + atomic_unchecked_t count; /* interrupt count after last read */
31609 int xcalib; /* calibrated null value for x */
31610 int ycalib; /* calibrated null value for y */
31611 int zcalib; /* calibrated null value for z */
31612 diff -urNp linux-2.6.32.46/drivers/hwmon/sht15.c linux-2.6.32.46/drivers/hwmon/sht15.c
31613 --- linux-2.6.32.46/drivers/hwmon/sht15.c 2011-03-27 14:31:47.000000000 -0400
31614 +++ linux-2.6.32.46/drivers/hwmon/sht15.c 2011-05-04 17:56:28.000000000 -0400
31615 @@ -112,7 +112,7 @@ struct sht15_data {
31616 int supply_uV;
31617 int supply_uV_valid;
31618 struct work_struct update_supply_work;
31619 - atomic_t interrupt_handled;
31620 + atomic_unchecked_t interrupt_handled;
31621 };
31622
31623 /**
31624 @@ -245,13 +245,13 @@ static inline int sht15_update_single_va
31625 return ret;
31626
31627 gpio_direction_input(data->pdata->gpio_data);
31628 - atomic_set(&data->interrupt_handled, 0);
31629 + atomic_set_unchecked(&data->interrupt_handled, 0);
31630
31631 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31632 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31633 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31634 /* Only relevant if the interrupt hasn't occured. */
31635 - if (!atomic_read(&data->interrupt_handled))
31636 + if (!atomic_read_unchecked(&data->interrupt_handled))
31637 schedule_work(&data->read_work);
31638 }
31639 ret = wait_event_timeout(data->wait_queue,
31640 @@ -398,7 +398,7 @@ static irqreturn_t sht15_interrupt_fired
31641 struct sht15_data *data = d;
31642 /* First disable the interrupt */
31643 disable_irq_nosync(irq);
31644 - atomic_inc(&data->interrupt_handled);
31645 + atomic_inc_unchecked(&data->interrupt_handled);
31646 /* Then schedule a reading work struct */
31647 if (data->flag != SHT15_READING_NOTHING)
31648 schedule_work(&data->read_work);
31649 @@ -449,11 +449,11 @@ static void sht15_bh_read_data(struct wo
31650 here as could have gone low in meantime so verify
31651 it hasn't!
31652 */
31653 - atomic_set(&data->interrupt_handled, 0);
31654 + atomic_set_unchecked(&data->interrupt_handled, 0);
31655 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31656 /* If still not occured or another handler has been scheduled */
31657 if (gpio_get_value(data->pdata->gpio_data)
31658 - || atomic_read(&data->interrupt_handled))
31659 + || atomic_read_unchecked(&data->interrupt_handled))
31660 return;
31661 }
31662 /* Read the data back from the device */
31663 diff -urNp linux-2.6.32.46/drivers/hwmon/w83791d.c linux-2.6.32.46/drivers/hwmon/w83791d.c
31664 --- linux-2.6.32.46/drivers/hwmon/w83791d.c 2011-03-27 14:31:47.000000000 -0400
31665 +++ linux-2.6.32.46/drivers/hwmon/w83791d.c 2011-04-17 15:56:46.000000000 -0400
31666 @@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_cli
31667 struct i2c_board_info *info);
31668 static int w83791d_remove(struct i2c_client *client);
31669
31670 -static int w83791d_read(struct i2c_client *client, u8 register);
31671 -static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
31672 +static int w83791d_read(struct i2c_client *client, u8 reg);
31673 +static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
31674 static struct w83791d_data *w83791d_update_device(struct device *dev);
31675
31676 #ifdef DEBUG
31677 diff -urNp linux-2.6.32.46/drivers/i2c/busses/i2c-amd756-s4882.c linux-2.6.32.46/drivers/i2c/busses/i2c-amd756-s4882.c
31678 --- linux-2.6.32.46/drivers/i2c/busses/i2c-amd756-s4882.c 2011-03-27 14:31:47.000000000 -0400
31679 +++ linux-2.6.32.46/drivers/i2c/busses/i2c-amd756-s4882.c 2011-08-23 21:22:32.000000000 -0400
31680 @@ -43,7 +43,7 @@
31681 extern struct i2c_adapter amd756_smbus;
31682
31683 static struct i2c_adapter *s4882_adapter;
31684 -static struct i2c_algorithm *s4882_algo;
31685 +static i2c_algorithm_no_const *s4882_algo;
31686
31687 /* Wrapper access functions for multiplexed SMBus */
31688 static DEFINE_MUTEX(amd756_lock);
31689 diff -urNp linux-2.6.32.46/drivers/i2c/busses/i2c-nforce2-s4985.c linux-2.6.32.46/drivers/i2c/busses/i2c-nforce2-s4985.c
31690 --- linux-2.6.32.46/drivers/i2c/busses/i2c-nforce2-s4985.c 2011-03-27 14:31:47.000000000 -0400
31691 +++ linux-2.6.32.46/drivers/i2c/busses/i2c-nforce2-s4985.c 2011-08-23 21:22:32.000000000 -0400
31692 @@ -41,7 +41,7 @@
31693 extern struct i2c_adapter *nforce2_smbus;
31694
31695 static struct i2c_adapter *s4985_adapter;
31696 -static struct i2c_algorithm *s4985_algo;
31697 +static i2c_algorithm_no_const *s4985_algo;
31698
31699 /* Wrapper access functions for multiplexed SMBus */
31700 static DEFINE_MUTEX(nforce2_lock);
31701 diff -urNp linux-2.6.32.46/drivers/ide/ide-cd.c linux-2.6.32.46/drivers/ide/ide-cd.c
31702 --- linux-2.6.32.46/drivers/ide/ide-cd.c 2011-03-27 14:31:47.000000000 -0400
31703 +++ linux-2.6.32.46/drivers/ide/ide-cd.c 2011-04-17 15:56:46.000000000 -0400
31704 @@ -774,7 +774,7 @@ static void cdrom_do_block_pc(ide_drive_
31705 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31706 if ((unsigned long)buf & alignment
31707 || blk_rq_bytes(rq) & q->dma_pad_mask
31708 - || object_is_on_stack(buf))
31709 + || object_starts_on_stack(buf))
31710 drive->dma = 0;
31711 }
31712 }
31713 diff -urNp linux-2.6.32.46/drivers/ide/ide-floppy.c linux-2.6.32.46/drivers/ide/ide-floppy.c
31714 --- linux-2.6.32.46/drivers/ide/ide-floppy.c 2011-03-27 14:31:47.000000000 -0400
31715 +++ linux-2.6.32.46/drivers/ide/ide-floppy.c 2011-05-16 21:46:57.000000000 -0400
31716 @@ -373,6 +373,8 @@ static int ide_floppy_get_capacity(ide_d
31717 u8 pc_buf[256], header_len, desc_cnt;
31718 int i, rc = 1, blocks, length;
31719
31720 + pax_track_stack();
31721 +
31722 ide_debug_log(IDE_DBG_FUNC, "enter");
31723
31724 drive->bios_cyl = 0;
31725 diff -urNp linux-2.6.32.46/drivers/ide/setup-pci.c linux-2.6.32.46/drivers/ide/setup-pci.c
31726 --- linux-2.6.32.46/drivers/ide/setup-pci.c 2011-03-27 14:31:47.000000000 -0400
31727 +++ linux-2.6.32.46/drivers/ide/setup-pci.c 2011-05-16 21:46:57.000000000 -0400
31728 @@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
31729 int ret, i, n_ports = dev2 ? 4 : 2;
31730 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
31731
31732 + pax_track_stack();
31733 +
31734 for (i = 0; i < n_ports / 2; i++) {
31735 ret = ide_setup_pci_controller(pdev[i], d, !i);
31736 if (ret < 0)
31737 diff -urNp linux-2.6.32.46/drivers/ieee1394/dv1394.c linux-2.6.32.46/drivers/ieee1394/dv1394.c
31738 --- linux-2.6.32.46/drivers/ieee1394/dv1394.c 2011-03-27 14:31:47.000000000 -0400
31739 +++ linux-2.6.32.46/drivers/ieee1394/dv1394.c 2011-04-23 12:56:11.000000000 -0400
31740 @@ -739,7 +739,7 @@ static void frame_prepare(struct video_c
31741 based upon DIF section and sequence
31742 */
31743
31744 -static void inline
31745 +static inline void
31746 frame_put_packet (struct frame *f, struct packet *p)
31747 {
31748 int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
31749 diff -urNp linux-2.6.32.46/drivers/ieee1394/hosts.c linux-2.6.32.46/drivers/ieee1394/hosts.c
31750 --- linux-2.6.32.46/drivers/ieee1394/hosts.c 2011-03-27 14:31:47.000000000 -0400
31751 +++ linux-2.6.32.46/drivers/ieee1394/hosts.c 2011-04-17 15:56:46.000000000 -0400
31752 @@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso
31753 }
31754
31755 static struct hpsb_host_driver dummy_driver = {
31756 + .name = "dummy",
31757 .transmit_packet = dummy_transmit_packet,
31758 .devctl = dummy_devctl,
31759 .isoctl = dummy_isoctl
31760 diff -urNp linux-2.6.32.46/drivers/ieee1394/init_ohci1394_dma.c linux-2.6.32.46/drivers/ieee1394/init_ohci1394_dma.c
31761 --- linux-2.6.32.46/drivers/ieee1394/init_ohci1394_dma.c 2011-03-27 14:31:47.000000000 -0400
31762 +++ linux-2.6.32.46/drivers/ieee1394/init_ohci1394_dma.c 2011-04-17 15:56:46.000000000 -0400
31763 @@ -257,7 +257,7 @@ void __init init_ohci1394_dma_on_all_con
31764 for (func = 0; func < 8; func++) {
31765 u32 class = read_pci_config(num,slot,func,
31766 PCI_CLASS_REVISION);
31767 - if ((class == 0xffffffff))
31768 + if (class == 0xffffffff)
31769 continue; /* No device at this func */
31770
31771 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
31772 diff -urNp linux-2.6.32.46/drivers/ieee1394/ohci1394.c linux-2.6.32.46/drivers/ieee1394/ohci1394.c
31773 --- linux-2.6.32.46/drivers/ieee1394/ohci1394.c 2011-03-27 14:31:47.000000000 -0400
31774 +++ linux-2.6.32.46/drivers/ieee1394/ohci1394.c 2011-04-23 12:56:11.000000000 -0400
31775 @@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_
31776 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
31777
31778 /* Module Parameters */
31779 -static int phys_dma = 1;
31780 +static int phys_dma;
31781 module_param(phys_dma, int, 0444);
31782 -MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
31783 +MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
31784
31785 static void dma_trm_tasklet(unsigned long data);
31786 static void dma_trm_reset(struct dma_trm_ctx *d);
31787 diff -urNp linux-2.6.32.46/drivers/ieee1394/sbp2.c linux-2.6.32.46/drivers/ieee1394/sbp2.c
31788 --- linux-2.6.32.46/drivers/ieee1394/sbp2.c 2011-03-27 14:31:47.000000000 -0400
31789 +++ linux-2.6.32.46/drivers/ieee1394/sbp2.c 2011-04-23 12:56:11.000000000 -0400
31790 @@ -2111,7 +2111,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot
31791 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
31792 MODULE_LICENSE("GPL");
31793
31794 -static int sbp2_module_init(void)
31795 +static int __init sbp2_module_init(void)
31796 {
31797 int ret;
31798
31799 diff -urNp linux-2.6.32.46/drivers/infiniband/core/cm.c linux-2.6.32.46/drivers/infiniband/core/cm.c
31800 --- linux-2.6.32.46/drivers/infiniband/core/cm.c 2011-03-27 14:31:47.000000000 -0400
31801 +++ linux-2.6.32.46/drivers/infiniband/core/cm.c 2011-04-17 15:56:46.000000000 -0400
31802 @@ -112,7 +112,7 @@ static char const counter_group_names[CM
31803
31804 struct cm_counter_group {
31805 struct kobject obj;
31806 - atomic_long_t counter[CM_ATTR_COUNT];
31807 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31808 };
31809
31810 struct cm_counter_attribute {
31811 @@ -1386,7 +1386,7 @@ static void cm_dup_req_handler(struct cm
31812 struct ib_mad_send_buf *msg = NULL;
31813 int ret;
31814
31815 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31816 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31817 counter[CM_REQ_COUNTER]);
31818
31819 /* Quick state check to discard duplicate REQs. */
31820 @@ -1764,7 +1764,7 @@ static void cm_dup_rep_handler(struct cm
31821 if (!cm_id_priv)
31822 return;
31823
31824 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31825 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31826 counter[CM_REP_COUNTER]);
31827 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31828 if (ret)
31829 @@ -1931,7 +1931,7 @@ static int cm_rtu_handler(struct cm_work
31830 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31831 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31832 spin_unlock_irq(&cm_id_priv->lock);
31833 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31834 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31835 counter[CM_RTU_COUNTER]);
31836 goto out;
31837 }
31838 @@ -2110,7 +2110,7 @@ static int cm_dreq_handler(struct cm_wor
31839 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31840 dreq_msg->local_comm_id);
31841 if (!cm_id_priv) {
31842 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31843 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31844 counter[CM_DREQ_COUNTER]);
31845 cm_issue_drep(work->port, work->mad_recv_wc);
31846 return -EINVAL;
31847 @@ -2131,7 +2131,7 @@ static int cm_dreq_handler(struct cm_wor
31848 case IB_CM_MRA_REP_RCVD:
31849 break;
31850 case IB_CM_TIMEWAIT:
31851 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31852 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31853 counter[CM_DREQ_COUNTER]);
31854 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31855 goto unlock;
31856 @@ -2145,7 +2145,7 @@ static int cm_dreq_handler(struct cm_wor
31857 cm_free_msg(msg);
31858 goto deref;
31859 case IB_CM_DREQ_RCVD:
31860 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31861 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31862 counter[CM_DREQ_COUNTER]);
31863 goto unlock;
31864 default:
31865 @@ -2501,7 +2501,7 @@ static int cm_mra_handler(struct cm_work
31866 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31867 cm_id_priv->msg, timeout)) {
31868 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31869 - atomic_long_inc(&work->port->
31870 + atomic_long_inc_unchecked(&work->port->
31871 counter_group[CM_RECV_DUPLICATES].
31872 counter[CM_MRA_COUNTER]);
31873 goto out;
31874 @@ -2510,7 +2510,7 @@ static int cm_mra_handler(struct cm_work
31875 break;
31876 case IB_CM_MRA_REQ_RCVD:
31877 case IB_CM_MRA_REP_RCVD:
31878 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31879 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31880 counter[CM_MRA_COUNTER]);
31881 /* fall through */
31882 default:
31883 @@ -2672,7 +2672,7 @@ static int cm_lap_handler(struct cm_work
31884 case IB_CM_LAP_IDLE:
31885 break;
31886 case IB_CM_MRA_LAP_SENT:
31887 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31888 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31889 counter[CM_LAP_COUNTER]);
31890 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31891 goto unlock;
31892 @@ -2688,7 +2688,7 @@ static int cm_lap_handler(struct cm_work
31893 cm_free_msg(msg);
31894 goto deref;
31895 case IB_CM_LAP_RCVD:
31896 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31897 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31898 counter[CM_LAP_COUNTER]);
31899 goto unlock;
31900 default:
31901 @@ -2972,7 +2972,7 @@ static int cm_sidr_req_handler(struct cm
31902 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31903 if (cur_cm_id_priv) {
31904 spin_unlock_irq(&cm.lock);
31905 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31906 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31907 counter[CM_SIDR_REQ_COUNTER]);
31908 goto out; /* Duplicate message. */
31909 }
31910 @@ -3184,10 +3184,10 @@ static void cm_send_handler(struct ib_ma
31911 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31912 msg->retries = 1;
31913
31914 - atomic_long_add(1 + msg->retries,
31915 + atomic_long_add_unchecked(1 + msg->retries,
31916 &port->counter_group[CM_XMIT].counter[attr_index]);
31917 if (msg->retries)
31918 - atomic_long_add(msg->retries,
31919 + atomic_long_add_unchecked(msg->retries,
31920 &port->counter_group[CM_XMIT_RETRIES].
31921 counter[attr_index]);
31922
31923 @@ -3397,7 +3397,7 @@ static void cm_recv_handler(struct ib_ma
31924 }
31925
31926 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
31927 - atomic_long_inc(&port->counter_group[CM_RECV].
31928 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
31929 counter[attr_id - CM_ATTR_ID_OFFSET]);
31930
31931 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
31932 @@ -3595,10 +3595,10 @@ static ssize_t cm_show_counter(struct ko
31933 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
31934
31935 return sprintf(buf, "%ld\n",
31936 - atomic_long_read(&group->counter[cm_attr->index]));
31937 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
31938 }
31939
31940 -static struct sysfs_ops cm_counter_ops = {
31941 +static const struct sysfs_ops cm_counter_ops = {
31942 .show = cm_show_counter
31943 };
31944
31945 diff -urNp linux-2.6.32.46/drivers/infiniband/core/fmr_pool.c linux-2.6.32.46/drivers/infiniband/core/fmr_pool.c
31946 --- linux-2.6.32.46/drivers/infiniband/core/fmr_pool.c 2011-03-27 14:31:47.000000000 -0400
31947 +++ linux-2.6.32.46/drivers/infiniband/core/fmr_pool.c 2011-05-04 17:56:28.000000000 -0400
31948 @@ -97,8 +97,8 @@ struct ib_fmr_pool {
31949
31950 struct task_struct *thread;
31951
31952 - atomic_t req_ser;
31953 - atomic_t flush_ser;
31954 + atomic_unchecked_t req_ser;
31955 + atomic_unchecked_t flush_ser;
31956
31957 wait_queue_head_t force_wait;
31958 };
31959 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
31960 struct ib_fmr_pool *pool = pool_ptr;
31961
31962 do {
31963 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
31964 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
31965 ib_fmr_batch_release(pool);
31966
31967 - atomic_inc(&pool->flush_ser);
31968 + atomic_inc_unchecked(&pool->flush_ser);
31969 wake_up_interruptible(&pool->force_wait);
31970
31971 if (pool->flush_function)
31972 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
31973 }
31974
31975 set_current_state(TASK_INTERRUPTIBLE);
31976 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
31977 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
31978 !kthread_should_stop())
31979 schedule();
31980 __set_current_state(TASK_RUNNING);
31981 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
31982 pool->dirty_watermark = params->dirty_watermark;
31983 pool->dirty_len = 0;
31984 spin_lock_init(&pool->pool_lock);
31985 - atomic_set(&pool->req_ser, 0);
31986 - atomic_set(&pool->flush_ser, 0);
31987 + atomic_set_unchecked(&pool->req_ser, 0);
31988 + atomic_set_unchecked(&pool->flush_ser, 0);
31989 init_waitqueue_head(&pool->force_wait);
31990
31991 pool->thread = kthread_run(ib_fmr_cleanup_thread,
31992 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
31993 }
31994 spin_unlock_irq(&pool->pool_lock);
31995
31996 - serial = atomic_inc_return(&pool->req_ser);
31997 + serial = atomic_inc_return_unchecked(&pool->req_ser);
31998 wake_up_process(pool->thread);
31999
32000 if (wait_event_interruptible(pool->force_wait,
32001 - atomic_read(&pool->flush_ser) - serial >= 0))
32002 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32003 return -EINTR;
32004
32005 return 0;
32006 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
32007 } else {
32008 list_add_tail(&fmr->list, &pool->dirty_list);
32009 if (++pool->dirty_len >= pool->dirty_watermark) {
32010 - atomic_inc(&pool->req_ser);
32011 + atomic_inc_unchecked(&pool->req_ser);
32012 wake_up_process(pool->thread);
32013 }
32014 }
32015 diff -urNp linux-2.6.32.46/drivers/infiniband/core/sysfs.c linux-2.6.32.46/drivers/infiniband/core/sysfs.c
32016 --- linux-2.6.32.46/drivers/infiniband/core/sysfs.c 2011-03-27 14:31:47.000000000 -0400
32017 +++ linux-2.6.32.46/drivers/infiniband/core/sysfs.c 2011-04-17 15:56:46.000000000 -0400
32018 @@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kob
32019 return port_attr->show(p, port_attr, buf);
32020 }
32021
32022 -static struct sysfs_ops port_sysfs_ops = {
32023 +static const struct sysfs_ops port_sysfs_ops = {
32024 .show = port_attr_show
32025 };
32026
32027 diff -urNp linux-2.6.32.46/drivers/infiniband/core/uverbs_marshall.c linux-2.6.32.46/drivers/infiniband/core/uverbs_marshall.c
32028 --- linux-2.6.32.46/drivers/infiniband/core/uverbs_marshall.c 2011-03-27 14:31:47.000000000 -0400
32029 +++ linux-2.6.32.46/drivers/infiniband/core/uverbs_marshall.c 2011-04-17 15:56:46.000000000 -0400
32030 @@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_u
32031 dst->grh.sgid_index = src->grh.sgid_index;
32032 dst->grh.hop_limit = src->grh.hop_limit;
32033 dst->grh.traffic_class = src->grh.traffic_class;
32034 + memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
32035 dst->dlid = src->dlid;
32036 dst->sl = src->sl;
32037 dst->src_path_bits = src->src_path_bits;
32038 dst->static_rate = src->static_rate;
32039 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
32040 dst->port_num = src->port_num;
32041 + dst->reserved = 0;
32042 }
32043 EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
32044
32045 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
32046 struct ib_qp_attr *src)
32047 {
32048 + dst->qp_state = src->qp_state;
32049 dst->cur_qp_state = src->cur_qp_state;
32050 dst->path_mtu = src->path_mtu;
32051 dst->path_mig_state = src->path_mig_state;
32052 @@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_u
32053 dst->rnr_retry = src->rnr_retry;
32054 dst->alt_port_num = src->alt_port_num;
32055 dst->alt_timeout = src->alt_timeout;
32056 + memset(dst->reserved, 0, sizeof(dst->reserved));
32057 }
32058 EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
32059
32060 diff -urNp linux-2.6.32.46/drivers/infiniband/hw/ipath/ipath_fs.c linux-2.6.32.46/drivers/infiniband/hw/ipath/ipath_fs.c
32061 --- linux-2.6.32.46/drivers/infiniband/hw/ipath/ipath_fs.c 2011-03-27 14:31:47.000000000 -0400
32062 +++ linux-2.6.32.46/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-16 21:46:57.000000000 -0400
32063 @@ -110,6 +110,8 @@ static ssize_t atomic_counters_read(stru
32064 struct infinipath_counters counters;
32065 struct ipath_devdata *dd;
32066
32067 + pax_track_stack();
32068 +
32069 dd = file->f_path.dentry->d_inode->i_private;
32070 dd->ipath_f_read_counters(dd, &counters);
32071
32072 diff -urNp linux-2.6.32.46/drivers/infiniband/hw/nes/nes.c linux-2.6.32.46/drivers/infiniband/hw/nes/nes.c
32073 --- linux-2.6.32.46/drivers/infiniband/hw/nes/nes.c 2011-03-27 14:31:47.000000000 -0400
32074 +++ linux-2.6.32.46/drivers/infiniband/hw/nes/nes.c 2011-05-04 17:56:28.000000000 -0400
32075 @@ -102,7 +102,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
32076 LIST_HEAD(nes_adapter_list);
32077 static LIST_HEAD(nes_dev_list);
32078
32079 -atomic_t qps_destroyed;
32080 +atomic_unchecked_t qps_destroyed;
32081
32082 static unsigned int ee_flsh_adapter;
32083 static unsigned int sysfs_nonidx_addr;
32084 @@ -259,7 +259,7 @@ static void nes_cqp_rem_ref_callback(str
32085 struct nes_adapter *nesadapter = nesdev->nesadapter;
32086 u32 qp_id;
32087
32088 - atomic_inc(&qps_destroyed);
32089 + atomic_inc_unchecked(&qps_destroyed);
32090
32091 /* Free the control structures */
32092
32093 diff -urNp linux-2.6.32.46/drivers/infiniband/hw/nes/nes.h linux-2.6.32.46/drivers/infiniband/hw/nes/nes.h
32094 --- linux-2.6.32.46/drivers/infiniband/hw/nes/nes.h 2011-03-27 14:31:47.000000000 -0400
32095 +++ linux-2.6.32.46/drivers/infiniband/hw/nes/nes.h 2011-05-04 17:56:28.000000000 -0400
32096 @@ -174,17 +174,17 @@ extern unsigned int nes_debug_level;
32097 extern unsigned int wqm_quanta;
32098 extern struct list_head nes_adapter_list;
32099
32100 -extern atomic_t cm_connects;
32101 -extern atomic_t cm_accepts;
32102 -extern atomic_t cm_disconnects;
32103 -extern atomic_t cm_closes;
32104 -extern atomic_t cm_connecteds;
32105 -extern atomic_t cm_connect_reqs;
32106 -extern atomic_t cm_rejects;
32107 -extern atomic_t mod_qp_timouts;
32108 -extern atomic_t qps_created;
32109 -extern atomic_t qps_destroyed;
32110 -extern atomic_t sw_qps_destroyed;
32111 +extern atomic_unchecked_t cm_connects;
32112 +extern atomic_unchecked_t cm_accepts;
32113 +extern atomic_unchecked_t cm_disconnects;
32114 +extern atomic_unchecked_t cm_closes;
32115 +extern atomic_unchecked_t cm_connecteds;
32116 +extern atomic_unchecked_t cm_connect_reqs;
32117 +extern atomic_unchecked_t cm_rejects;
32118 +extern atomic_unchecked_t mod_qp_timouts;
32119 +extern atomic_unchecked_t qps_created;
32120 +extern atomic_unchecked_t qps_destroyed;
32121 +extern atomic_unchecked_t sw_qps_destroyed;
32122 extern u32 mh_detected;
32123 extern u32 mh_pauses_sent;
32124 extern u32 cm_packets_sent;
32125 @@ -196,11 +196,11 @@ extern u32 cm_packets_retrans;
32126 extern u32 cm_listens_created;
32127 extern u32 cm_listens_destroyed;
32128 extern u32 cm_backlog_drops;
32129 -extern atomic_t cm_loopbacks;
32130 -extern atomic_t cm_nodes_created;
32131 -extern atomic_t cm_nodes_destroyed;
32132 -extern atomic_t cm_accel_dropped_pkts;
32133 -extern atomic_t cm_resets_recvd;
32134 +extern atomic_unchecked_t cm_loopbacks;
32135 +extern atomic_unchecked_t cm_nodes_created;
32136 +extern atomic_unchecked_t cm_nodes_destroyed;
32137 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32138 +extern atomic_unchecked_t cm_resets_recvd;
32139
32140 extern u32 int_mod_timer_init;
32141 extern u32 int_mod_cq_depth_256;
32142 diff -urNp linux-2.6.32.46/drivers/infiniband/hw/nes/nes_cm.c linux-2.6.32.46/drivers/infiniband/hw/nes/nes_cm.c
32143 --- linux-2.6.32.46/drivers/infiniband/hw/nes/nes_cm.c 2011-03-27 14:31:47.000000000 -0400
32144 +++ linux-2.6.32.46/drivers/infiniband/hw/nes/nes_cm.c 2011-05-04 17:56:28.000000000 -0400
32145 @@ -69,11 +69,11 @@ u32 cm_packets_received;
32146 u32 cm_listens_created;
32147 u32 cm_listens_destroyed;
32148 u32 cm_backlog_drops;
32149 -atomic_t cm_loopbacks;
32150 -atomic_t cm_nodes_created;
32151 -atomic_t cm_nodes_destroyed;
32152 -atomic_t cm_accel_dropped_pkts;
32153 -atomic_t cm_resets_recvd;
32154 +atomic_unchecked_t cm_loopbacks;
32155 +atomic_unchecked_t cm_nodes_created;
32156 +atomic_unchecked_t cm_nodes_destroyed;
32157 +atomic_unchecked_t cm_accel_dropped_pkts;
32158 +atomic_unchecked_t cm_resets_recvd;
32159
32160 static inline int mini_cm_accelerated(struct nes_cm_core *,
32161 struct nes_cm_node *);
32162 @@ -149,13 +149,13 @@ static struct nes_cm_ops nes_cm_api = {
32163
32164 static struct nes_cm_core *g_cm_core;
32165
32166 -atomic_t cm_connects;
32167 -atomic_t cm_accepts;
32168 -atomic_t cm_disconnects;
32169 -atomic_t cm_closes;
32170 -atomic_t cm_connecteds;
32171 -atomic_t cm_connect_reqs;
32172 -atomic_t cm_rejects;
32173 +atomic_unchecked_t cm_connects;
32174 +atomic_unchecked_t cm_accepts;
32175 +atomic_unchecked_t cm_disconnects;
32176 +atomic_unchecked_t cm_closes;
32177 +atomic_unchecked_t cm_connecteds;
32178 +atomic_unchecked_t cm_connect_reqs;
32179 +atomic_unchecked_t cm_rejects;
32180
32181
32182 /**
32183 @@ -1195,7 +1195,7 @@ static struct nes_cm_node *make_cm_node(
32184 cm_node->rem_mac);
32185
32186 add_hte_node(cm_core, cm_node);
32187 - atomic_inc(&cm_nodes_created);
32188 + atomic_inc_unchecked(&cm_nodes_created);
32189
32190 return cm_node;
32191 }
32192 @@ -1253,7 +1253,7 @@ static int rem_ref_cm_node(struct nes_cm
32193 }
32194
32195 atomic_dec(&cm_core->node_cnt);
32196 - atomic_inc(&cm_nodes_destroyed);
32197 + atomic_inc_unchecked(&cm_nodes_destroyed);
32198 nesqp = cm_node->nesqp;
32199 if (nesqp) {
32200 nesqp->cm_node = NULL;
32201 @@ -1320,7 +1320,7 @@ static int process_options(struct nes_cm
32202
32203 static void drop_packet(struct sk_buff *skb)
32204 {
32205 - atomic_inc(&cm_accel_dropped_pkts);
32206 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32207 dev_kfree_skb_any(skb);
32208 }
32209
32210 @@ -1377,7 +1377,7 @@ static void handle_rst_pkt(struct nes_cm
32211
32212 int reset = 0; /* whether to send reset in case of err.. */
32213 int passive_state;
32214 - atomic_inc(&cm_resets_recvd);
32215 + atomic_inc_unchecked(&cm_resets_recvd);
32216 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32217 " refcnt=%d\n", cm_node, cm_node->state,
32218 atomic_read(&cm_node->ref_count));
32219 @@ -2000,7 +2000,7 @@ static struct nes_cm_node *mini_cm_conne
32220 rem_ref_cm_node(cm_node->cm_core, cm_node);
32221 return NULL;
32222 }
32223 - atomic_inc(&cm_loopbacks);
32224 + atomic_inc_unchecked(&cm_loopbacks);
32225 loopbackremotenode->loopbackpartner = cm_node;
32226 loopbackremotenode->tcp_cntxt.rcv_wscale =
32227 NES_CM_DEFAULT_RCV_WND_SCALE;
32228 @@ -2262,7 +2262,7 @@ static int mini_cm_recv_pkt(struct nes_c
32229 add_ref_cm_node(cm_node);
32230 } else if (cm_node->state == NES_CM_STATE_TSA) {
32231 rem_ref_cm_node(cm_core, cm_node);
32232 - atomic_inc(&cm_accel_dropped_pkts);
32233 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32234 dev_kfree_skb_any(skb);
32235 break;
32236 }
32237 @@ -2568,7 +2568,7 @@ static int nes_cm_disconn_true(struct ne
32238
32239 if ((cm_id) && (cm_id->event_handler)) {
32240 if (issue_disconn) {
32241 - atomic_inc(&cm_disconnects);
32242 + atomic_inc_unchecked(&cm_disconnects);
32243 cm_event.event = IW_CM_EVENT_DISCONNECT;
32244 cm_event.status = disconn_status;
32245 cm_event.local_addr = cm_id->local_addr;
32246 @@ -2590,7 +2590,7 @@ static int nes_cm_disconn_true(struct ne
32247 }
32248
32249 if (issue_close) {
32250 - atomic_inc(&cm_closes);
32251 + atomic_inc_unchecked(&cm_closes);
32252 nes_disconnect(nesqp, 1);
32253
32254 cm_id->provider_data = nesqp;
32255 @@ -2710,7 +2710,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
32256
32257 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32258 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32259 - atomic_inc(&cm_accepts);
32260 + atomic_inc_unchecked(&cm_accepts);
32261
32262 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32263 atomic_read(&nesvnic->netdev->refcnt));
32264 @@ -2919,7 +2919,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
32265
32266 struct nes_cm_core *cm_core;
32267
32268 - atomic_inc(&cm_rejects);
32269 + atomic_inc_unchecked(&cm_rejects);
32270 cm_node = (struct nes_cm_node *) cm_id->provider_data;
32271 loopback = cm_node->loopbackpartner;
32272 cm_core = cm_node->cm_core;
32273 @@ -2982,7 +2982,7 @@ int nes_connect(struct iw_cm_id *cm_id,
32274 ntohl(cm_id->local_addr.sin_addr.s_addr),
32275 ntohs(cm_id->local_addr.sin_port));
32276
32277 - atomic_inc(&cm_connects);
32278 + atomic_inc_unchecked(&cm_connects);
32279 nesqp->active_conn = 1;
32280
32281 /* cache the cm_id in the qp */
32282 @@ -3195,7 +3195,7 @@ static void cm_event_connected(struct ne
32283 if (nesqp->destroyed) {
32284 return;
32285 }
32286 - atomic_inc(&cm_connecteds);
32287 + atomic_inc_unchecked(&cm_connecteds);
32288 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32289 " local port 0x%04X. jiffies = %lu.\n",
32290 nesqp->hwqp.qp_id,
32291 @@ -3403,7 +3403,7 @@ static void cm_event_reset(struct nes_cm
32292
32293 ret = cm_id->event_handler(cm_id, &cm_event);
32294 cm_id->add_ref(cm_id);
32295 - atomic_inc(&cm_closes);
32296 + atomic_inc_unchecked(&cm_closes);
32297 cm_event.event = IW_CM_EVENT_CLOSE;
32298 cm_event.status = IW_CM_EVENT_STATUS_OK;
32299 cm_event.provider_data = cm_id->provider_data;
32300 @@ -3439,7 +3439,7 @@ static void cm_event_mpa_req(struct nes_
32301 return;
32302 cm_id = cm_node->cm_id;
32303
32304 - atomic_inc(&cm_connect_reqs);
32305 + atomic_inc_unchecked(&cm_connect_reqs);
32306 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32307 cm_node, cm_id, jiffies);
32308
32309 @@ -3477,7 +3477,7 @@ static void cm_event_mpa_reject(struct n
32310 return;
32311 cm_id = cm_node->cm_id;
32312
32313 - atomic_inc(&cm_connect_reqs);
32314 + atomic_inc_unchecked(&cm_connect_reqs);
32315 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32316 cm_node, cm_id, jiffies);
32317
32318 diff -urNp linux-2.6.32.46/drivers/infiniband/hw/nes/nes_nic.c linux-2.6.32.46/drivers/infiniband/hw/nes/nes_nic.c
32319 --- linux-2.6.32.46/drivers/infiniband/hw/nes/nes_nic.c 2011-03-27 14:31:47.000000000 -0400
32320 +++ linux-2.6.32.46/drivers/infiniband/hw/nes/nes_nic.c 2011-05-04 17:56:28.000000000 -0400
32321 @@ -1210,17 +1210,17 @@ static void nes_netdev_get_ethtool_stats
32322 target_stat_values[++index] = mh_detected;
32323 target_stat_values[++index] = mh_pauses_sent;
32324 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32325 - target_stat_values[++index] = atomic_read(&cm_connects);
32326 - target_stat_values[++index] = atomic_read(&cm_accepts);
32327 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32328 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32329 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32330 - target_stat_values[++index] = atomic_read(&cm_rejects);
32331 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32332 - target_stat_values[++index] = atomic_read(&qps_created);
32333 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32334 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32335 - target_stat_values[++index] = atomic_read(&cm_closes);
32336 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32337 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32338 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32339 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32340 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32341 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32342 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32343 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32344 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32345 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32346 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32347 target_stat_values[++index] = cm_packets_sent;
32348 target_stat_values[++index] = cm_packets_bounced;
32349 target_stat_values[++index] = cm_packets_created;
32350 @@ -1230,11 +1230,11 @@ static void nes_netdev_get_ethtool_stats
32351 target_stat_values[++index] = cm_listens_created;
32352 target_stat_values[++index] = cm_listens_destroyed;
32353 target_stat_values[++index] = cm_backlog_drops;
32354 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32355 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32356 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32357 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32358 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32359 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32360 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32361 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32362 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32363 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32364 target_stat_values[++index] = int_mod_timer_init;
32365 target_stat_values[++index] = int_mod_cq_depth_1;
32366 target_stat_values[++index] = int_mod_cq_depth_4;
32367 diff -urNp linux-2.6.32.46/drivers/infiniband/hw/nes/nes_verbs.c linux-2.6.32.46/drivers/infiniband/hw/nes/nes_verbs.c
32368 --- linux-2.6.32.46/drivers/infiniband/hw/nes/nes_verbs.c 2011-03-27 14:31:47.000000000 -0400
32369 +++ linux-2.6.32.46/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-04 17:56:28.000000000 -0400
32370 @@ -45,9 +45,9 @@
32371
32372 #include <rdma/ib_umem.h>
32373
32374 -atomic_t mod_qp_timouts;
32375 -atomic_t qps_created;
32376 -atomic_t sw_qps_destroyed;
32377 +atomic_unchecked_t mod_qp_timouts;
32378 +atomic_unchecked_t qps_created;
32379 +atomic_unchecked_t sw_qps_destroyed;
32380
32381 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32382
32383 @@ -1240,7 +1240,7 @@ static struct ib_qp *nes_create_qp(struc
32384 if (init_attr->create_flags)
32385 return ERR_PTR(-EINVAL);
32386
32387 - atomic_inc(&qps_created);
32388 + atomic_inc_unchecked(&qps_created);
32389 switch (init_attr->qp_type) {
32390 case IB_QPT_RC:
32391 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32392 @@ -1568,7 +1568,7 @@ static int nes_destroy_qp(struct ib_qp *
32393 struct iw_cm_event cm_event;
32394 int ret;
32395
32396 - atomic_inc(&sw_qps_destroyed);
32397 + atomic_inc_unchecked(&sw_qps_destroyed);
32398 nesqp->destroyed = 1;
32399
32400 /* Blow away the connection if it exists. */
32401 diff -urNp linux-2.6.32.46/drivers/input/gameport/gameport.c linux-2.6.32.46/drivers/input/gameport/gameport.c
32402 --- linux-2.6.32.46/drivers/input/gameport/gameport.c 2011-03-27 14:31:47.000000000 -0400
32403 +++ linux-2.6.32.46/drivers/input/gameport/gameport.c 2011-05-04 17:56:28.000000000 -0400
32404 @@ -515,13 +515,13 @@ EXPORT_SYMBOL(gameport_set_phys);
32405 */
32406 static void gameport_init_port(struct gameport *gameport)
32407 {
32408 - static atomic_t gameport_no = ATOMIC_INIT(0);
32409 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32410
32411 __module_get(THIS_MODULE);
32412
32413 mutex_init(&gameport->drv_mutex);
32414 device_initialize(&gameport->dev);
32415 - dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
32416 + dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32417 gameport->dev.bus = &gameport_bus;
32418 gameport->dev.release = gameport_release_port;
32419 if (gameport->parent)
32420 diff -urNp linux-2.6.32.46/drivers/input/input.c linux-2.6.32.46/drivers/input/input.c
32421 --- linux-2.6.32.46/drivers/input/input.c 2011-03-27 14:31:47.000000000 -0400
32422 +++ linux-2.6.32.46/drivers/input/input.c 2011-05-04 17:56:28.000000000 -0400
32423 @@ -1558,7 +1558,7 @@ EXPORT_SYMBOL(input_set_capability);
32424 */
32425 int input_register_device(struct input_dev *dev)
32426 {
32427 - static atomic_t input_no = ATOMIC_INIT(0);
32428 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32429 struct input_handler *handler;
32430 const char *path;
32431 int error;
32432 @@ -1585,7 +1585,7 @@ int input_register_device(struct input_d
32433 dev->setkeycode = input_default_setkeycode;
32434
32435 dev_set_name(&dev->dev, "input%ld",
32436 - (unsigned long) atomic_inc_return(&input_no) - 1);
32437 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32438
32439 error = device_add(&dev->dev);
32440 if (error)
32441 diff -urNp linux-2.6.32.46/drivers/input/joystick/sidewinder.c linux-2.6.32.46/drivers/input/joystick/sidewinder.c
32442 --- linux-2.6.32.46/drivers/input/joystick/sidewinder.c 2011-03-27 14:31:47.000000000 -0400
32443 +++ linux-2.6.32.46/drivers/input/joystick/sidewinder.c 2011-05-18 20:09:36.000000000 -0400
32444 @@ -30,6 +30,7 @@
32445 #include <linux/kernel.h>
32446 #include <linux/module.h>
32447 #include <linux/slab.h>
32448 +#include <linux/sched.h>
32449 #include <linux/init.h>
32450 #include <linux/input.h>
32451 #include <linux/gameport.h>
32452 @@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
32453 unsigned char buf[SW_LENGTH];
32454 int i;
32455
32456 + pax_track_stack();
32457 +
32458 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
32459
32460 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
32461 diff -urNp linux-2.6.32.46/drivers/input/joystick/xpad.c linux-2.6.32.46/drivers/input/joystick/xpad.c
32462 --- linux-2.6.32.46/drivers/input/joystick/xpad.c 2011-03-27 14:31:47.000000000 -0400
32463 +++ linux-2.6.32.46/drivers/input/joystick/xpad.c 2011-05-04 17:56:28.000000000 -0400
32464 @@ -621,7 +621,7 @@ static void xpad_led_set(struct led_clas
32465
32466 static int xpad_led_probe(struct usb_xpad *xpad)
32467 {
32468 - static atomic_t led_seq = ATOMIC_INIT(0);
32469 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32470 long led_no;
32471 struct xpad_led *led;
32472 struct led_classdev *led_cdev;
32473 @@ -634,7 +634,7 @@ static int xpad_led_probe(struct usb_xpa
32474 if (!led)
32475 return -ENOMEM;
32476
32477 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32478 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32479
32480 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32481 led->xpad = xpad;
32482 diff -urNp linux-2.6.32.46/drivers/input/serio/serio.c linux-2.6.32.46/drivers/input/serio/serio.c
32483 --- linux-2.6.32.46/drivers/input/serio/serio.c 2011-03-27 14:31:47.000000000 -0400
32484 +++ linux-2.6.32.46/drivers/input/serio/serio.c 2011-05-04 17:56:28.000000000 -0400
32485 @@ -527,7 +527,7 @@ static void serio_release_port(struct de
32486 */
32487 static void serio_init_port(struct serio *serio)
32488 {
32489 - static atomic_t serio_no = ATOMIC_INIT(0);
32490 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32491
32492 __module_get(THIS_MODULE);
32493
32494 @@ -536,7 +536,7 @@ static void serio_init_port(struct serio
32495 mutex_init(&serio->drv_mutex);
32496 device_initialize(&serio->dev);
32497 dev_set_name(&serio->dev, "serio%ld",
32498 - (long)atomic_inc_return(&serio_no) - 1);
32499 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32500 serio->dev.bus = &serio_bus;
32501 serio->dev.release = serio_release_port;
32502 if (serio->parent) {
32503 diff -urNp linux-2.6.32.46/drivers/isdn/gigaset/common.c linux-2.6.32.46/drivers/isdn/gigaset/common.c
32504 --- linux-2.6.32.46/drivers/isdn/gigaset/common.c 2011-03-27 14:31:47.000000000 -0400
32505 +++ linux-2.6.32.46/drivers/isdn/gigaset/common.c 2011-04-17 15:56:46.000000000 -0400
32506 @@ -712,7 +712,7 @@ struct cardstate *gigaset_initcs(struct
32507 cs->commands_pending = 0;
32508 cs->cur_at_seq = 0;
32509 cs->gotfwver = -1;
32510 - cs->open_count = 0;
32511 + local_set(&cs->open_count, 0);
32512 cs->dev = NULL;
32513 cs->tty = NULL;
32514 cs->tty_dev = NULL;
32515 diff -urNp linux-2.6.32.46/drivers/isdn/gigaset/gigaset.h linux-2.6.32.46/drivers/isdn/gigaset/gigaset.h
32516 --- linux-2.6.32.46/drivers/isdn/gigaset/gigaset.h 2011-03-27 14:31:47.000000000 -0400
32517 +++ linux-2.6.32.46/drivers/isdn/gigaset/gigaset.h 2011-04-17 15:56:46.000000000 -0400
32518 @@ -34,6 +34,7 @@
32519 #include <linux/tty_driver.h>
32520 #include <linux/list.h>
32521 #include <asm/atomic.h>
32522 +#include <asm/local.h>
32523
32524 #define GIG_VERSION {0,5,0,0}
32525 #define GIG_COMPAT {0,4,0,0}
32526 @@ -446,7 +447,7 @@ struct cardstate {
32527 spinlock_t cmdlock;
32528 unsigned curlen, cmdbytes;
32529
32530 - unsigned open_count;
32531 + local_t open_count;
32532 struct tty_struct *tty;
32533 struct tasklet_struct if_wake_tasklet;
32534 unsigned control_state;
32535 diff -urNp linux-2.6.32.46/drivers/isdn/gigaset/interface.c linux-2.6.32.46/drivers/isdn/gigaset/interface.c
32536 --- linux-2.6.32.46/drivers/isdn/gigaset/interface.c 2011-03-27 14:31:47.000000000 -0400
32537 +++ linux-2.6.32.46/drivers/isdn/gigaset/interface.c 2011-04-17 15:56:46.000000000 -0400
32538 @@ -165,9 +165,7 @@ static int if_open(struct tty_struct *tt
32539 return -ERESTARTSYS; // FIXME -EINTR?
32540 tty->driver_data = cs;
32541
32542 - ++cs->open_count;
32543 -
32544 - if (cs->open_count == 1) {
32545 + if (local_inc_return(&cs->open_count) == 1) {
32546 spin_lock_irqsave(&cs->lock, flags);
32547 cs->tty = tty;
32548 spin_unlock_irqrestore(&cs->lock, flags);
32549 @@ -195,10 +193,10 @@ static void if_close(struct tty_struct *
32550
32551 if (!cs->connected)
32552 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32553 - else if (!cs->open_count)
32554 + else if (!local_read(&cs->open_count))
32555 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32556 else {
32557 - if (!--cs->open_count) {
32558 + if (!local_dec_return(&cs->open_count)) {
32559 spin_lock_irqsave(&cs->lock, flags);
32560 cs->tty = NULL;
32561 spin_unlock_irqrestore(&cs->lock, flags);
32562 @@ -233,7 +231,7 @@ static int if_ioctl(struct tty_struct *t
32563 if (!cs->connected) {
32564 gig_dbg(DEBUG_IF, "not connected");
32565 retval = -ENODEV;
32566 - } else if (!cs->open_count)
32567 + } else if (!local_read(&cs->open_count))
32568 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32569 else {
32570 retval = 0;
32571 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *t
32572 if (!cs->connected) {
32573 gig_dbg(DEBUG_IF, "not connected");
32574 retval = -ENODEV;
32575 - } else if (!cs->open_count)
32576 + } else if (!local_read(&cs->open_count))
32577 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32578 else if (cs->mstate != MS_LOCKED) {
32579 dev_warn(cs->dev, "can't write to unlocked device\n");
32580 @@ -395,7 +393,7 @@ static int if_write_room(struct tty_stru
32581 if (!cs->connected) {
32582 gig_dbg(DEBUG_IF, "not connected");
32583 retval = -ENODEV;
32584 - } else if (!cs->open_count)
32585 + } else if (!local_read(&cs->open_count))
32586 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32587 else if (cs->mstate != MS_LOCKED) {
32588 dev_warn(cs->dev, "can't write to unlocked device\n");
32589 @@ -425,7 +423,7 @@ static int if_chars_in_buffer(struct tty
32590
32591 if (!cs->connected)
32592 gig_dbg(DEBUG_IF, "not connected");
32593 - else if (!cs->open_count)
32594 + else if (!local_read(&cs->open_count))
32595 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32596 else if (cs->mstate != MS_LOCKED)
32597 dev_warn(cs->dev, "can't write to unlocked device\n");
32598 @@ -453,7 +451,7 @@ static void if_throttle(struct tty_struc
32599
32600 if (!cs->connected)
32601 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32602 - else if (!cs->open_count)
32603 + else if (!local_read(&cs->open_count))
32604 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32605 else {
32606 //FIXME
32607 @@ -478,7 +476,7 @@ static void if_unthrottle(struct tty_str
32608
32609 if (!cs->connected)
32610 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32611 - else if (!cs->open_count)
32612 + else if (!local_read(&cs->open_count))
32613 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32614 else {
32615 //FIXME
32616 @@ -510,7 +508,7 @@ static void if_set_termios(struct tty_st
32617 goto out;
32618 }
32619
32620 - if (!cs->open_count) {
32621 + if (!local_read(&cs->open_count)) {
32622 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32623 goto out;
32624 }
32625 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/avm/b1.c linux-2.6.32.46/drivers/isdn/hardware/avm/b1.c
32626 --- linux-2.6.32.46/drivers/isdn/hardware/avm/b1.c 2011-03-27 14:31:47.000000000 -0400
32627 +++ linux-2.6.32.46/drivers/isdn/hardware/avm/b1.c 2011-04-17 15:56:46.000000000 -0400
32628 @@ -173,7 +173,7 @@ int b1_load_t4file(avmcard *card, capilo
32629 }
32630 if (left) {
32631 if (t4file->user) {
32632 - if (copy_from_user(buf, dp, left))
32633 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32634 return -EFAULT;
32635 } else {
32636 memcpy(buf, dp, left);
32637 @@ -221,7 +221,7 @@ int b1_load_config(avmcard *card, capilo
32638 }
32639 if (left) {
32640 if (config->user) {
32641 - if (copy_from_user(buf, dp, left))
32642 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32643 return -EFAULT;
32644 } else {
32645 memcpy(buf, dp, left);
32646 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/eicon/capidtmf.c linux-2.6.32.46/drivers/isdn/hardware/eicon/capidtmf.c
32647 --- linux-2.6.32.46/drivers/isdn/hardware/eicon/capidtmf.c 2011-03-27 14:31:47.000000000 -0400
32648 +++ linux-2.6.32.46/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-16 21:46:57.000000000 -0400
32649 @@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
32650 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
32651 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
32652
32653 + pax_track_stack();
32654
32655 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
32656 {
32657 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/eicon/capifunc.c linux-2.6.32.46/drivers/isdn/hardware/eicon/capifunc.c
32658 --- linux-2.6.32.46/drivers/isdn/hardware/eicon/capifunc.c 2011-03-27 14:31:47.000000000 -0400
32659 +++ linux-2.6.32.46/drivers/isdn/hardware/eicon/capifunc.c 2011-05-16 21:46:57.000000000 -0400
32660 @@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
32661 IDI_SYNC_REQ req;
32662 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
32663
32664 + pax_track_stack();
32665 +
32666 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
32667
32668 for (x = 0; x < MAX_DESCRIPTORS; x++) {
32669 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/eicon/diddfunc.c linux-2.6.32.46/drivers/isdn/hardware/eicon/diddfunc.c
32670 --- linux-2.6.32.46/drivers/isdn/hardware/eicon/diddfunc.c 2011-03-27 14:31:47.000000000 -0400
32671 +++ linux-2.6.32.46/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-16 21:46:57.000000000 -0400
32672 @@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
32673 IDI_SYNC_REQ req;
32674 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
32675
32676 + pax_track_stack();
32677 +
32678 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
32679
32680 for (x = 0; x < MAX_DESCRIPTORS; x++) {
32681 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/eicon/divasfunc.c linux-2.6.32.46/drivers/isdn/hardware/eicon/divasfunc.c
32682 --- linux-2.6.32.46/drivers/isdn/hardware/eicon/divasfunc.c 2011-03-27 14:31:47.000000000 -0400
32683 +++ linux-2.6.32.46/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-16 21:46:57.000000000 -0400
32684 @@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_di
32685 IDI_SYNC_REQ req;
32686 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
32687
32688 + pax_track_stack();
32689 +
32690 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
32691
32692 for (x = 0; x < MAX_DESCRIPTORS; x++) {
32693 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/eicon/divasync.h linux-2.6.32.46/drivers/isdn/hardware/eicon/divasync.h
32694 --- linux-2.6.32.46/drivers/isdn/hardware/eicon/divasync.h 2011-03-27 14:31:47.000000000 -0400
32695 +++ linux-2.6.32.46/drivers/isdn/hardware/eicon/divasync.h 2011-08-05 20:33:55.000000000 -0400
32696 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32697 } diva_didd_add_adapter_t;
32698 typedef struct _diva_didd_remove_adapter {
32699 IDI_CALL p_request;
32700 -} diva_didd_remove_adapter_t;
32701 +} __no_const diva_didd_remove_adapter_t;
32702 typedef struct _diva_didd_read_adapter_array {
32703 void * buffer;
32704 dword length;
32705 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/eicon/idifunc.c linux-2.6.32.46/drivers/isdn/hardware/eicon/idifunc.c
32706 --- linux-2.6.32.46/drivers/isdn/hardware/eicon/idifunc.c 2011-03-27 14:31:47.000000000 -0400
32707 +++ linux-2.6.32.46/drivers/isdn/hardware/eicon/idifunc.c 2011-05-16 21:46:57.000000000 -0400
32708 @@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
32709 IDI_SYNC_REQ req;
32710 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
32711
32712 + pax_track_stack();
32713 +
32714 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
32715
32716 for (x = 0; x < MAX_DESCRIPTORS; x++) {
32717 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/eicon/message.c linux-2.6.32.46/drivers/isdn/hardware/eicon/message.c
32718 --- linux-2.6.32.46/drivers/isdn/hardware/eicon/message.c 2011-03-27 14:31:47.000000000 -0400
32719 +++ linux-2.6.32.46/drivers/isdn/hardware/eicon/message.c 2011-05-16 21:46:57.000000000 -0400
32720 @@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
32721 dword d;
32722 word w;
32723
32724 + pax_track_stack();
32725 +
32726 a = plci->adapter;
32727 Id = ((word)plci->Id<<8)|a->Id;
32728 PUT_WORD(&SS_Ind[4],0x0000);
32729 @@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE
32730 word j, n, w;
32731 dword d;
32732
32733 + pax_track_stack();
32734 +
32735
32736 for(i=0;i<8;i++) bp_parms[i].length = 0;
32737 for(i=0;i<2;i++) global_config[i].length = 0;
32738 @@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARS
32739 const byte llc3[] = {4,3,2,2,6,6,0};
32740 const byte header[] = {0,2,3,3,0,0,0};
32741
32742 + pax_track_stack();
32743 +
32744 for(i=0;i<8;i++) bp_parms[i].length = 0;
32745 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
32746 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
32747 @@ -14761,6 +14767,8 @@ static void group_optimization(DIVA_CAPI
32748 word appl_number_group_type[MAX_APPL];
32749 PLCI *auxplci;
32750
32751 + pax_track_stack();
32752 +
32753 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
32754
32755 if(!a->group_optimization_enabled)
32756 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/eicon/mntfunc.c linux-2.6.32.46/drivers/isdn/hardware/eicon/mntfunc.c
32757 --- linux-2.6.32.46/drivers/isdn/hardware/eicon/mntfunc.c 2011-03-27 14:31:47.000000000 -0400
32758 +++ linux-2.6.32.46/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-16 21:46:57.000000000 -0400
32759 @@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
32760 IDI_SYNC_REQ req;
32761 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
32762
32763 + pax_track_stack();
32764 +
32765 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
32766
32767 for (x = 0; x < MAX_DESCRIPTORS; x++) {
32768 diff -urNp linux-2.6.32.46/drivers/isdn/hardware/eicon/xdi_adapter.h linux-2.6.32.46/drivers/isdn/hardware/eicon/xdi_adapter.h
32769 --- linux-2.6.32.46/drivers/isdn/hardware/eicon/xdi_adapter.h 2011-03-27 14:31:47.000000000 -0400
32770 +++ linux-2.6.32.46/drivers/isdn/hardware/eicon/xdi_adapter.h 2011-08-05 20:33:55.000000000 -0400
32771 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32772 typedef struct _diva_os_idi_adapter_interface {
32773 diva_init_card_proc_t cleanup_adapter_proc;
32774 diva_cmd_card_proc_t cmd_proc;
32775 -} diva_os_idi_adapter_interface_t;
32776 +} __no_const diva_os_idi_adapter_interface_t;
32777
32778 typedef struct _diva_os_xdi_adapter {
32779 struct list_head link;
32780 diff -urNp linux-2.6.32.46/drivers/isdn/i4l/isdn_common.c linux-2.6.32.46/drivers/isdn/i4l/isdn_common.c
32781 --- linux-2.6.32.46/drivers/isdn/i4l/isdn_common.c 2011-03-27 14:31:47.000000000 -0400
32782 +++ linux-2.6.32.46/drivers/isdn/i4l/isdn_common.c 2011-05-16 21:46:57.000000000 -0400
32783 @@ -1290,6 +1290,8 @@ isdn_ioctl(struct inode *inode, struct f
32784 } iocpar;
32785 void __user *argp = (void __user *)arg;
32786
32787 + pax_track_stack();
32788 +
32789 #define name iocpar.name
32790 #define bname iocpar.bname
32791 #define iocts iocpar.iocts
32792 diff -urNp linux-2.6.32.46/drivers/isdn/icn/icn.c linux-2.6.32.46/drivers/isdn/icn/icn.c
32793 --- linux-2.6.32.46/drivers/isdn/icn/icn.c 2011-03-27 14:31:47.000000000 -0400
32794 +++ linux-2.6.32.46/drivers/isdn/icn/icn.c 2011-04-17 15:56:46.000000000 -0400
32795 @@ -1044,7 +1044,7 @@ icn_writecmd(const u_char * buf, int len
32796 if (count > len)
32797 count = len;
32798 if (user) {
32799 - if (copy_from_user(msg, buf, count))
32800 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32801 return -EFAULT;
32802 } else
32803 memcpy(msg, buf, count);
32804 diff -urNp linux-2.6.32.46/drivers/isdn/mISDN/socket.c linux-2.6.32.46/drivers/isdn/mISDN/socket.c
32805 --- linux-2.6.32.46/drivers/isdn/mISDN/socket.c 2011-03-27 14:31:47.000000000 -0400
32806 +++ linux-2.6.32.46/drivers/isdn/mISDN/socket.c 2011-04-17 15:56:46.000000000 -0400
32807 @@ -391,6 +391,7 @@ data_sock_ioctl(struct socket *sock, uns
32808 if (dev) {
32809 struct mISDN_devinfo di;
32810
32811 + memset(&di, 0, sizeof(di));
32812 di.id = dev->id;
32813 di.Dprotocols = dev->Dprotocols;
32814 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
32815 @@ -671,6 +672,7 @@ base_sock_ioctl(struct socket *sock, uns
32816 if (dev) {
32817 struct mISDN_devinfo di;
32818
32819 + memset(&di, 0, sizeof(di));
32820 di.id = dev->id;
32821 di.Dprotocols = dev->Dprotocols;
32822 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
32823 diff -urNp linux-2.6.32.46/drivers/isdn/sc/interrupt.c linux-2.6.32.46/drivers/isdn/sc/interrupt.c
32824 --- linux-2.6.32.46/drivers/isdn/sc/interrupt.c 2011-03-27 14:31:47.000000000 -0400
32825 +++ linux-2.6.32.46/drivers/isdn/sc/interrupt.c 2011-04-17 15:56:46.000000000 -0400
32826 @@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy,
32827 }
32828 else if(callid>=0x0000 && callid<=0x7FFF)
32829 {
32830 + int len;
32831 +
32832 pr_debug("%s: Got Incoming Call\n",
32833 sc_adapter[card]->devicename);
32834 - strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
32835 - strcpy(setup.eazmsn,
32836 - sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
32837 + len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
32838 + sizeof(setup.phone));
32839 + if (len >= sizeof(setup.phone))
32840 + continue;
32841 + len = strlcpy(setup.eazmsn,
32842 + sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
32843 + sizeof(setup.eazmsn));
32844 + if (len >= sizeof(setup.eazmsn))
32845 + continue;
32846 setup.si1 = 7;
32847 setup.si2 = 0;
32848 setup.plan = 0;
32849 @@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy,
32850 * Handle a GetMyNumber Rsp
32851 */
32852 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
32853 - strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
32854 + strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
32855 + rcvmsg.msg_data.byte_array,
32856 + sizeof(rcvmsg.msg_data.byte_array));
32857 continue;
32858 }
32859
32860 diff -urNp linux-2.6.32.46/drivers/lguest/core.c linux-2.6.32.46/drivers/lguest/core.c
32861 --- linux-2.6.32.46/drivers/lguest/core.c 2011-03-27 14:31:47.000000000 -0400
32862 +++ linux-2.6.32.46/drivers/lguest/core.c 2011-04-17 15:56:46.000000000 -0400
32863 @@ -91,9 +91,17 @@ static __init int map_switcher(void)
32864 * it's worked so far. The end address needs +1 because __get_vm_area
32865 * allocates an extra guard page, so we need space for that.
32866 */
32867 +
32868 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32869 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32870 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32871 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32872 +#else
32873 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32874 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32875 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32876 +#endif
32877 +
32878 if (!switcher_vma) {
32879 err = -ENOMEM;
32880 printk("lguest: could not map switcher pages high\n");
32881 @@ -118,7 +126,7 @@ static __init int map_switcher(void)
32882 * Now the Switcher is mapped at the right address, we can't fail!
32883 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
32884 */
32885 - memcpy(switcher_vma->addr, start_switcher_text,
32886 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32887 end_switcher_text - start_switcher_text);
32888
32889 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32890 diff -urNp linux-2.6.32.46/drivers/lguest/x86/core.c linux-2.6.32.46/drivers/lguest/x86/core.c
32891 --- linux-2.6.32.46/drivers/lguest/x86/core.c 2011-03-27 14:31:47.000000000 -0400
32892 +++ linux-2.6.32.46/drivers/lguest/x86/core.c 2011-04-17 15:56:46.000000000 -0400
32893 @@ -59,7 +59,7 @@ static struct {
32894 /* Offset from where switcher.S was compiled to where we've copied it */
32895 static unsigned long switcher_offset(void)
32896 {
32897 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32898 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32899 }
32900
32901 /* This cpu's struct lguest_pages. */
32902 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
32903 * These copies are pretty cheap, so we do them unconditionally: */
32904 /* Save the current Host top-level page directory.
32905 */
32906 +
32907 +#ifdef CONFIG_PAX_PER_CPU_PGD
32908 + pages->state.host_cr3 = read_cr3();
32909 +#else
32910 pages->state.host_cr3 = __pa(current->mm->pgd);
32911 +#endif
32912 +
32913 /*
32914 * Set up the Guest's page tables to see this CPU's pages (and no
32915 * other CPU's pages).
32916 @@ -535,7 +541,7 @@ void __init lguest_arch_host_init(void)
32917 * compiled-in switcher code and the high-mapped copy we just made.
32918 */
32919 for (i = 0; i < IDT_ENTRIES; i++)
32920 - default_idt_entries[i] += switcher_offset();
32921 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32922
32923 /*
32924 * Set up the Switcher's per-cpu areas.
32925 @@ -618,7 +624,7 @@ void __init lguest_arch_host_init(void)
32926 * it will be undisturbed when we switch. To change %cs and jump we
32927 * need this structure to feed to Intel's "lcall" instruction.
32928 */
32929 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32930 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32931 lguest_entry.segment = LGUEST_CS;
32932
32933 /*
32934 diff -urNp linux-2.6.32.46/drivers/lguest/x86/switcher_32.S linux-2.6.32.46/drivers/lguest/x86/switcher_32.S
32935 --- linux-2.6.32.46/drivers/lguest/x86/switcher_32.S 2011-03-27 14:31:47.000000000 -0400
32936 +++ linux-2.6.32.46/drivers/lguest/x86/switcher_32.S 2011-04-17 15:56:46.000000000 -0400
32937 @@ -87,6 +87,7 @@
32938 #include <asm/page.h>
32939 #include <asm/segment.h>
32940 #include <asm/lguest.h>
32941 +#include <asm/processor-flags.h>
32942
32943 // We mark the start of the code to copy
32944 // It's placed in .text tho it's never run here
32945 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
32946 // Changes type when we load it: damn Intel!
32947 // For after we switch over our page tables
32948 // That entry will be read-only: we'd crash.
32949 +
32950 +#ifdef CONFIG_PAX_KERNEXEC
32951 + mov %cr0, %edx
32952 + xor $X86_CR0_WP, %edx
32953 + mov %edx, %cr0
32954 +#endif
32955 +
32956 movl $(GDT_ENTRY_TSS*8), %edx
32957 ltr %dx
32958
32959 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
32960 // Let's clear it again for our return.
32961 // The GDT descriptor of the Host
32962 // Points to the table after two "size" bytes
32963 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
32964 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
32965 // Clear "used" from type field (byte 5, bit 2)
32966 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
32967 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
32968 +
32969 +#ifdef CONFIG_PAX_KERNEXEC
32970 + mov %cr0, %eax
32971 + xor $X86_CR0_WP, %eax
32972 + mov %eax, %cr0
32973 +#endif
32974
32975 // Once our page table's switched, the Guest is live!
32976 // The Host fades as we run this final step.
32977 @@ -295,13 +309,12 @@ deliver_to_host:
32978 // I consulted gcc, and it gave
32979 // These instructions, which I gladly credit:
32980 leal (%edx,%ebx,8), %eax
32981 - movzwl (%eax),%edx
32982 - movl 4(%eax), %eax
32983 - xorw %ax, %ax
32984 - orl %eax, %edx
32985 + movl 4(%eax), %edx
32986 + movw (%eax), %dx
32987 // Now the address of the handler's in %edx
32988 // We call it now: its "iret" drops us home.
32989 - jmp *%edx
32990 + ljmp $__KERNEL_CS, $1f
32991 +1: jmp *%edx
32992
32993 // Every interrupt can come to us here
32994 // But we must truly tell each apart.
32995 diff -urNp linux-2.6.32.46/drivers/macintosh/via-pmu-backlight.c linux-2.6.32.46/drivers/macintosh/via-pmu-backlight.c
32996 --- linux-2.6.32.46/drivers/macintosh/via-pmu-backlight.c 2011-03-27 14:31:47.000000000 -0400
32997 +++ linux-2.6.32.46/drivers/macintosh/via-pmu-backlight.c 2011-04-17 15:56:46.000000000 -0400
32998 @@ -15,7 +15,7 @@
32999
33000 #define MAX_PMU_LEVEL 0xFF
33001
33002 -static struct backlight_ops pmu_backlight_data;
33003 +static const struct backlight_ops pmu_backlight_data;
33004 static DEFINE_SPINLOCK(pmu_backlight_lock);
33005 static int sleeping, uses_pmu_bl;
33006 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
33007 @@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(
33008 return bd->props.brightness;
33009 }
33010
33011 -static struct backlight_ops pmu_backlight_data = {
33012 +static const struct backlight_ops pmu_backlight_data = {
33013 .get_brightness = pmu_backlight_get_brightness,
33014 .update_status = pmu_backlight_update_status,
33015
33016 diff -urNp linux-2.6.32.46/drivers/macintosh/via-pmu.c linux-2.6.32.46/drivers/macintosh/via-pmu.c
33017 --- linux-2.6.32.46/drivers/macintosh/via-pmu.c 2011-03-27 14:31:47.000000000 -0400
33018 +++ linux-2.6.32.46/drivers/macintosh/via-pmu.c 2011-04-17 15:56:46.000000000 -0400
33019 @@ -2232,7 +2232,7 @@ static int pmu_sleep_valid(suspend_state
33020 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
33021 }
33022
33023 -static struct platform_suspend_ops pmu_pm_ops = {
33024 +static const struct platform_suspend_ops pmu_pm_ops = {
33025 .enter = powerbook_sleep,
33026 .valid = pmu_sleep_valid,
33027 };
33028 diff -urNp linux-2.6.32.46/drivers/md/dm-ioctl.c linux-2.6.32.46/drivers/md/dm-ioctl.c
33029 --- linux-2.6.32.46/drivers/md/dm-ioctl.c 2011-03-27 14:31:47.000000000 -0400
33030 +++ linux-2.6.32.46/drivers/md/dm-ioctl.c 2011-04-17 15:56:46.000000000 -0400
33031 @@ -1437,7 +1437,7 @@ static int validate_params(uint cmd, str
33032 cmd == DM_LIST_VERSIONS_CMD)
33033 return 0;
33034
33035 - if ((cmd == DM_DEV_CREATE_CMD)) {
33036 + if (cmd == DM_DEV_CREATE_CMD) {
33037 if (!*param->name) {
33038 DMWARN("name not supplied when creating device");
33039 return -EINVAL;
33040 diff -urNp linux-2.6.32.46/drivers/md/dm-raid1.c linux-2.6.32.46/drivers/md/dm-raid1.c
33041 --- linux-2.6.32.46/drivers/md/dm-raid1.c 2011-03-27 14:31:47.000000000 -0400
33042 +++ linux-2.6.32.46/drivers/md/dm-raid1.c 2011-05-04 17:56:28.000000000 -0400
33043 @@ -41,7 +41,7 @@ enum dm_raid1_error {
33044
33045 struct mirror {
33046 struct mirror_set *ms;
33047 - atomic_t error_count;
33048 + atomic_unchecked_t error_count;
33049 unsigned long error_type;
33050 struct dm_dev *dev;
33051 sector_t offset;
33052 @@ -203,7 +203,7 @@ static void fail_mirror(struct mirror *m
33053 * simple way to tell if a device has encountered
33054 * errors.
33055 */
33056 - atomic_inc(&m->error_count);
33057 + atomic_inc_unchecked(&m->error_count);
33058
33059 if (test_and_set_bit(error_type, &m->error_type))
33060 return;
33061 @@ -225,7 +225,7 @@ static void fail_mirror(struct mirror *m
33062 }
33063
33064 for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
33065 - if (!atomic_read(&new->error_count)) {
33066 + if (!atomic_read_unchecked(&new->error_count)) {
33067 set_default_mirror(new);
33068 break;
33069 }
33070 @@ -363,7 +363,7 @@ static struct mirror *choose_mirror(stru
33071 struct mirror *m = get_default_mirror(ms);
33072
33073 do {
33074 - if (likely(!atomic_read(&m->error_count)))
33075 + if (likely(!atomic_read_unchecked(&m->error_count)))
33076 return m;
33077
33078 if (m-- == ms->mirror)
33079 @@ -377,7 +377,7 @@ static int default_ok(struct mirror *m)
33080 {
33081 struct mirror *default_mirror = get_default_mirror(m->ms);
33082
33083 - return !atomic_read(&default_mirror->error_count);
33084 + return !atomic_read_unchecked(&default_mirror->error_count);
33085 }
33086
33087 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33088 @@ -484,7 +484,7 @@ static void do_reads(struct mirror_set *
33089 */
33090 if (likely(region_in_sync(ms, region, 1)))
33091 m = choose_mirror(ms, bio->bi_sector);
33092 - else if (m && atomic_read(&m->error_count))
33093 + else if (m && atomic_read_unchecked(&m->error_count))
33094 m = NULL;
33095
33096 if (likely(m))
33097 @@ -855,7 +855,7 @@ static int get_mirror(struct mirror_set
33098 }
33099
33100 ms->mirror[mirror].ms = ms;
33101 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33102 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33103 ms->mirror[mirror].error_type = 0;
33104 ms->mirror[mirror].offset = offset;
33105
33106 @@ -1241,7 +1241,7 @@ static void mirror_resume(struct dm_targ
33107 */
33108 static char device_status_char(struct mirror *m)
33109 {
33110 - if (!atomic_read(&(m->error_count)))
33111 + if (!atomic_read_unchecked(&(m->error_count)))
33112 return 'A';
33113
33114 return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
33115 diff -urNp linux-2.6.32.46/drivers/md/dm-stripe.c linux-2.6.32.46/drivers/md/dm-stripe.c
33116 --- linux-2.6.32.46/drivers/md/dm-stripe.c 2011-03-27 14:31:47.000000000 -0400
33117 +++ linux-2.6.32.46/drivers/md/dm-stripe.c 2011-05-04 17:56:28.000000000 -0400
33118 @@ -20,7 +20,7 @@ struct stripe {
33119 struct dm_dev *dev;
33120 sector_t physical_start;
33121
33122 - atomic_t error_count;
33123 + atomic_unchecked_t error_count;
33124 };
33125
33126 struct stripe_c {
33127 @@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *
33128 kfree(sc);
33129 return r;
33130 }
33131 - atomic_set(&(sc->stripe[i].error_count), 0);
33132 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33133 }
33134
33135 ti->private = sc;
33136 @@ -257,7 +257,7 @@ static int stripe_status(struct dm_targe
33137 DMEMIT("%d ", sc->stripes);
33138 for (i = 0; i < sc->stripes; i++) {
33139 DMEMIT("%s ", sc->stripe[i].dev->name);
33140 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33141 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33142 'D' : 'A';
33143 }
33144 buffer[i] = '\0';
33145 @@ -304,8 +304,8 @@ static int stripe_end_io(struct dm_targe
33146 */
33147 for (i = 0; i < sc->stripes; i++)
33148 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33149 - atomic_inc(&(sc->stripe[i].error_count));
33150 - if (atomic_read(&(sc->stripe[i].error_count)) <
33151 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33152 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33153 DM_IO_ERROR_THRESHOLD)
33154 queue_work(kstriped, &sc->kstriped_ws);
33155 }
33156 diff -urNp linux-2.6.32.46/drivers/md/dm-sysfs.c linux-2.6.32.46/drivers/md/dm-sysfs.c
33157 --- linux-2.6.32.46/drivers/md/dm-sysfs.c 2011-03-27 14:31:47.000000000 -0400
33158 +++ linux-2.6.32.46/drivers/md/dm-sysfs.c 2011-04-17 15:56:46.000000000 -0400
33159 @@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
33160 NULL,
33161 };
33162
33163 -static struct sysfs_ops dm_sysfs_ops = {
33164 +static const struct sysfs_ops dm_sysfs_ops = {
33165 .show = dm_attr_show,
33166 };
33167
33168 diff -urNp linux-2.6.32.46/drivers/md/dm-table.c linux-2.6.32.46/drivers/md/dm-table.c
33169 --- linux-2.6.32.46/drivers/md/dm-table.c 2011-06-25 12:55:34.000000000 -0400
33170 +++ linux-2.6.32.46/drivers/md/dm-table.c 2011-06-25 12:56:37.000000000 -0400
33171 @@ -376,7 +376,7 @@ static int device_area_is_invalid(struct
33172 if (!dev_size)
33173 return 0;
33174
33175 - if ((start >= dev_size) || (start + len > dev_size)) {
33176 + if ((start >= dev_size) || (len > dev_size - start)) {
33177 DMWARN("%s: %s too small for target: "
33178 "start=%llu, len=%llu, dev_size=%llu",
33179 dm_device_name(ti->table->md), bdevname(bdev, b),
33180 diff -urNp linux-2.6.32.46/drivers/md/dm.c linux-2.6.32.46/drivers/md/dm.c
33181 --- linux-2.6.32.46/drivers/md/dm.c 2011-08-09 18:35:29.000000000 -0400
33182 +++ linux-2.6.32.46/drivers/md/dm.c 2011-08-09 18:33:59.000000000 -0400
33183 @@ -165,9 +165,9 @@ struct mapped_device {
33184 /*
33185 * Event handling.
33186 */
33187 - atomic_t event_nr;
33188 + atomic_unchecked_t event_nr;
33189 wait_queue_head_t eventq;
33190 - atomic_t uevent_seq;
33191 + atomic_unchecked_t uevent_seq;
33192 struct list_head uevent_list;
33193 spinlock_t uevent_lock; /* Protect access to uevent_list */
33194
33195 @@ -1776,8 +1776,8 @@ static struct mapped_device *alloc_dev(i
33196 rwlock_init(&md->map_lock);
33197 atomic_set(&md->holders, 1);
33198 atomic_set(&md->open_count, 0);
33199 - atomic_set(&md->event_nr, 0);
33200 - atomic_set(&md->uevent_seq, 0);
33201 + atomic_set_unchecked(&md->event_nr, 0);
33202 + atomic_set_unchecked(&md->uevent_seq, 0);
33203 INIT_LIST_HEAD(&md->uevent_list);
33204 spin_lock_init(&md->uevent_lock);
33205
33206 @@ -1927,7 +1927,7 @@ static void event_callback(void *context
33207
33208 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33209
33210 - atomic_inc(&md->event_nr);
33211 + atomic_inc_unchecked(&md->event_nr);
33212 wake_up(&md->eventq);
33213 }
33214
33215 @@ -2562,18 +2562,18 @@ void dm_kobject_uevent(struct mapped_dev
33216
33217 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33218 {
33219 - return atomic_add_return(1, &md->uevent_seq);
33220 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33221 }
33222
33223 uint32_t dm_get_event_nr(struct mapped_device *md)
33224 {
33225 - return atomic_read(&md->event_nr);
33226 + return atomic_read_unchecked(&md->event_nr);
33227 }
33228
33229 int dm_wait_event(struct mapped_device *md, int event_nr)
33230 {
33231 return wait_event_interruptible(md->eventq,
33232 - (event_nr != atomic_read(&md->event_nr)));
33233 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33234 }
33235
33236 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33237 diff -urNp linux-2.6.32.46/drivers/md/md.c linux-2.6.32.46/drivers/md/md.c
33238 --- linux-2.6.32.46/drivers/md/md.c 2011-07-13 17:23:04.000000000 -0400
33239 +++ linux-2.6.32.46/drivers/md/md.c 2011-07-13 17:23:18.000000000 -0400
33240 @@ -153,10 +153,10 @@ static int start_readonly;
33241 * start build, activate spare
33242 */
33243 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33244 -static atomic_t md_event_count;
33245 +static atomic_unchecked_t md_event_count;
33246 void md_new_event(mddev_t *mddev)
33247 {
33248 - atomic_inc(&md_event_count);
33249 + atomic_inc_unchecked(&md_event_count);
33250 wake_up(&md_event_waiters);
33251 }
33252 EXPORT_SYMBOL_GPL(md_new_event);
33253 @@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33254 */
33255 static void md_new_event_inintr(mddev_t *mddev)
33256 {
33257 - atomic_inc(&md_event_count);
33258 + atomic_inc_unchecked(&md_event_count);
33259 wake_up(&md_event_waiters);
33260 }
33261
33262 @@ -1218,7 +1218,7 @@ static int super_1_load(mdk_rdev_t *rdev
33263
33264 rdev->preferred_minor = 0xffff;
33265 rdev->data_offset = le64_to_cpu(sb->data_offset);
33266 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33267 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33268
33269 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33270 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33271 @@ -1392,7 +1392,7 @@ static void super_1_sync(mddev_t *mddev,
33272 else
33273 sb->resync_offset = cpu_to_le64(0);
33274
33275 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33276 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33277
33278 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33279 sb->size = cpu_to_le64(mddev->dev_sectors);
33280 @@ -2214,7 +2214,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
33281 static ssize_t
33282 errors_show(mdk_rdev_t *rdev, char *page)
33283 {
33284 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33285 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33286 }
33287
33288 static ssize_t
33289 @@ -2223,7 +2223,7 @@ errors_store(mdk_rdev_t *rdev, const cha
33290 char *e;
33291 unsigned long n = simple_strtoul(buf, &e, 10);
33292 if (*buf && (*e == 0 || *e == '\n')) {
33293 - atomic_set(&rdev->corrected_errors, n);
33294 + atomic_set_unchecked(&rdev->corrected_errors, n);
33295 return len;
33296 }
33297 return -EINVAL;
33298 @@ -2517,7 +2517,7 @@ static void rdev_free(struct kobject *ko
33299 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
33300 kfree(rdev);
33301 }
33302 -static struct sysfs_ops rdev_sysfs_ops = {
33303 +static const struct sysfs_ops rdev_sysfs_ops = {
33304 .show = rdev_attr_show,
33305 .store = rdev_attr_store,
33306 };
33307 @@ -2566,8 +2566,8 @@ static mdk_rdev_t *md_import_device(dev_
33308 rdev->data_offset = 0;
33309 rdev->sb_events = 0;
33310 atomic_set(&rdev->nr_pending, 0);
33311 - atomic_set(&rdev->read_errors, 0);
33312 - atomic_set(&rdev->corrected_errors, 0);
33313 + atomic_set_unchecked(&rdev->read_errors, 0);
33314 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33315
33316 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
33317 if (!size) {
33318 @@ -3887,7 +3887,7 @@ static void md_free(struct kobject *ko)
33319 kfree(mddev);
33320 }
33321
33322 -static struct sysfs_ops md_sysfs_ops = {
33323 +static const struct sysfs_ops md_sysfs_ops = {
33324 .show = md_attr_show,
33325 .store = md_attr_store,
33326 };
33327 @@ -4474,7 +4474,8 @@ out:
33328 err = 0;
33329 blk_integrity_unregister(disk);
33330 md_new_event(mddev);
33331 - sysfs_notify_dirent(mddev->sysfs_state);
33332 + if (mddev->sysfs_state)
33333 + sysfs_notify_dirent(mddev->sysfs_state);
33334 return err;
33335 }
33336
33337 @@ -5954,7 +5955,7 @@ static int md_seq_show(struct seq_file *
33338
33339 spin_unlock(&pers_lock);
33340 seq_printf(seq, "\n");
33341 - mi->event = atomic_read(&md_event_count);
33342 + mi->event = atomic_read_unchecked(&md_event_count);
33343 return 0;
33344 }
33345 if (v == (void*)2) {
33346 @@ -6043,7 +6044,7 @@ static int md_seq_show(struct seq_file *
33347 chunk_kb ? "KB" : "B");
33348 if (bitmap->file) {
33349 seq_printf(seq, ", file: ");
33350 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33351 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33352 }
33353
33354 seq_printf(seq, "\n");
33355 @@ -6077,7 +6078,7 @@ static int md_seq_open(struct inode *ino
33356 else {
33357 struct seq_file *p = file->private_data;
33358 p->private = mi;
33359 - mi->event = atomic_read(&md_event_count);
33360 + mi->event = atomic_read_unchecked(&md_event_count);
33361 }
33362 return error;
33363 }
33364 @@ -6093,7 +6094,7 @@ static unsigned int mdstat_poll(struct f
33365 /* always allow read */
33366 mask = POLLIN | POLLRDNORM;
33367
33368 - if (mi->event != atomic_read(&md_event_count))
33369 + if (mi->event != atomic_read_unchecked(&md_event_count))
33370 mask |= POLLERR | POLLPRI;
33371 return mask;
33372 }
33373 @@ -6137,7 +6138,7 @@ static int is_mddev_idle(mddev_t *mddev,
33374 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33375 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33376 (int)part_stat_read(&disk->part0, sectors[1]) -
33377 - atomic_read(&disk->sync_io);
33378 + atomic_read_unchecked(&disk->sync_io);
33379 /* sync IO will cause sync_io to increase before the disk_stats
33380 * as sync_io is counted when a request starts, and
33381 * disk_stats is counted when it completes.
33382 diff -urNp linux-2.6.32.46/drivers/md/md.h linux-2.6.32.46/drivers/md/md.h
33383 --- linux-2.6.32.46/drivers/md/md.h 2011-03-27 14:31:47.000000000 -0400
33384 +++ linux-2.6.32.46/drivers/md/md.h 2011-05-04 17:56:20.000000000 -0400
33385 @@ -94,10 +94,10 @@ struct mdk_rdev_s
33386 * only maintained for arrays that
33387 * support hot removal
33388 */
33389 - atomic_t read_errors; /* number of consecutive read errors that
33390 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33391 * we have tried to ignore.
33392 */
33393 - atomic_t corrected_errors; /* number of corrected read errors,
33394 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33395 * for reporting to userspace and storing
33396 * in superblock.
33397 */
33398 @@ -304,7 +304,7 @@ static inline void rdev_dec_pending(mdk_
33399
33400 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33401 {
33402 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33403 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33404 }
33405
33406 struct mdk_personality
33407 diff -urNp linux-2.6.32.46/drivers/md/raid1.c linux-2.6.32.46/drivers/md/raid1.c
33408 --- linux-2.6.32.46/drivers/md/raid1.c 2011-03-27 14:31:47.000000000 -0400
33409 +++ linux-2.6.32.46/drivers/md/raid1.c 2011-05-04 17:56:28.000000000 -0400
33410 @@ -1415,7 +1415,7 @@ static void sync_request_write(mddev_t *
33411 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
33412 continue;
33413 rdev = conf->mirrors[d].rdev;
33414 - atomic_add(s, &rdev->corrected_errors);
33415 + atomic_add_unchecked(s, &rdev->corrected_errors);
33416 if (sync_page_io(rdev->bdev,
33417 sect + rdev->data_offset,
33418 s<<9,
33419 @@ -1564,7 +1564,7 @@ static void fix_read_error(conf_t *conf,
33420 /* Well, this device is dead */
33421 md_error(mddev, rdev);
33422 else {
33423 - atomic_add(s, &rdev->corrected_errors);
33424 + atomic_add_unchecked(s, &rdev->corrected_errors);
33425 printk(KERN_INFO
33426 "raid1:%s: read error corrected "
33427 "(%d sectors at %llu on %s)\n",
33428 diff -urNp linux-2.6.32.46/drivers/md/raid10.c linux-2.6.32.46/drivers/md/raid10.c
33429 --- linux-2.6.32.46/drivers/md/raid10.c 2011-03-27 14:31:47.000000000 -0400
33430 +++ linux-2.6.32.46/drivers/md/raid10.c 2011-05-04 17:56:28.000000000 -0400
33431 @@ -1255,7 +1255,7 @@ static void end_sync_read(struct bio *bi
33432 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
33433 set_bit(R10BIO_Uptodate, &r10_bio->state);
33434 else {
33435 - atomic_add(r10_bio->sectors,
33436 + atomic_add_unchecked(r10_bio->sectors,
33437 &conf->mirrors[d].rdev->corrected_errors);
33438 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
33439 md_error(r10_bio->mddev,
33440 @@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf,
33441 test_bit(In_sync, &rdev->flags)) {
33442 atomic_inc(&rdev->nr_pending);
33443 rcu_read_unlock();
33444 - atomic_add(s, &rdev->corrected_errors);
33445 + atomic_add_unchecked(s, &rdev->corrected_errors);
33446 if (sync_page_io(rdev->bdev,
33447 r10_bio->devs[sl].addr +
33448 sect + rdev->data_offset,
33449 diff -urNp linux-2.6.32.46/drivers/md/raid5.c linux-2.6.32.46/drivers/md/raid5.c
33450 --- linux-2.6.32.46/drivers/md/raid5.c 2011-06-25 12:55:34.000000000 -0400
33451 +++ linux-2.6.32.46/drivers/md/raid5.c 2011-06-25 12:58:39.000000000 -0400
33452 @@ -482,7 +482,7 @@ static void ops_run_io(struct stripe_hea
33453 bi->bi_next = NULL;
33454 if ((rw & WRITE) &&
33455 test_bit(R5_ReWrite, &sh->dev[i].flags))
33456 - atomic_add(STRIPE_SECTORS,
33457 + atomic_add_unchecked(STRIPE_SECTORS,
33458 &rdev->corrected_errors);
33459 generic_make_request(bi);
33460 } else {
33461 @@ -1517,15 +1517,15 @@ static void raid5_end_read_request(struc
33462 clear_bit(R5_ReadError, &sh->dev[i].flags);
33463 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33464 }
33465 - if (atomic_read(&conf->disks[i].rdev->read_errors))
33466 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
33467 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
33468 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
33469 } else {
33470 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
33471 int retry = 0;
33472 rdev = conf->disks[i].rdev;
33473
33474 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33475 - atomic_inc(&rdev->read_errors);
33476 + atomic_inc_unchecked(&rdev->read_errors);
33477 if (conf->mddev->degraded >= conf->max_degraded)
33478 printk_rl(KERN_WARNING
33479 "raid5:%s: read error not correctable "
33480 @@ -1543,7 +1543,7 @@ static void raid5_end_read_request(struc
33481 (unsigned long long)(sh->sector
33482 + rdev->data_offset),
33483 bdn);
33484 - else if (atomic_read(&rdev->read_errors)
33485 + else if (atomic_read_unchecked(&rdev->read_errors)
33486 > conf->max_nr_stripes)
33487 printk(KERN_WARNING
33488 "raid5:%s: Too many read errors, failing device %s.\n",
33489 @@ -1870,6 +1870,7 @@ static sector_t compute_blocknr(struct s
33490 sector_t r_sector;
33491 struct stripe_head sh2;
33492
33493 + pax_track_stack();
33494
33495 chunk_offset = sector_div(new_sector, sectors_per_chunk);
33496 stripe = new_sector;
33497 diff -urNp linux-2.6.32.46/drivers/media/common/saa7146_hlp.c linux-2.6.32.46/drivers/media/common/saa7146_hlp.c
33498 --- linux-2.6.32.46/drivers/media/common/saa7146_hlp.c 2011-03-27 14:31:47.000000000 -0400
33499 +++ linux-2.6.32.46/drivers/media/common/saa7146_hlp.c 2011-05-16 21:46:57.000000000 -0400
33500 @@ -353,6 +353,8 @@ static void calculate_clipping_registers
33501
33502 int x[32], y[32], w[32], h[32];
33503
33504 + pax_track_stack();
33505 +
33506 /* clear out memory */
33507 memset(&line_list[0], 0x00, sizeof(u32)*32);
33508 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
33509 diff -urNp linux-2.6.32.46/drivers/media/dvb/dvb-core/dvb_ca_en50221.c linux-2.6.32.46/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
33510 --- linux-2.6.32.46/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-03-27 14:31:47.000000000 -0400
33511 +++ linux-2.6.32.46/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-16 21:46:57.000000000 -0400
33512 @@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
33513 u8 buf[HOST_LINK_BUF_SIZE];
33514 int i;
33515
33516 + pax_track_stack();
33517 +
33518 dprintk("%s\n", __func__);
33519
33520 /* check if we have space for a link buf in the rx_buffer */
33521 @@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
33522 unsigned long timeout;
33523 int written;
33524
33525 + pax_track_stack();
33526 +
33527 dprintk("%s\n", __func__);
33528
33529 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
33530 diff -urNp linux-2.6.32.46/drivers/media/dvb/dvb-core/dvb_demux.h linux-2.6.32.46/drivers/media/dvb/dvb-core/dvb_demux.h
33531 --- linux-2.6.32.46/drivers/media/dvb/dvb-core/dvb_demux.h 2011-03-27 14:31:47.000000000 -0400
33532 +++ linux-2.6.32.46/drivers/media/dvb/dvb-core/dvb_demux.h 2011-08-05 20:33:55.000000000 -0400
33533 @@ -71,7 +71,7 @@ struct dvb_demux_feed {
33534 union {
33535 dmx_ts_cb ts;
33536 dmx_section_cb sec;
33537 - } cb;
33538 + } __no_const cb;
33539
33540 struct dvb_demux *demux;
33541 void *priv;
33542 diff -urNp linux-2.6.32.46/drivers/media/dvb/dvb-core/dvbdev.c linux-2.6.32.46/drivers/media/dvb/dvb-core/dvbdev.c
33543 --- linux-2.6.32.46/drivers/media/dvb/dvb-core/dvbdev.c 2011-03-27 14:31:47.000000000 -0400
33544 +++ linux-2.6.32.46/drivers/media/dvb/dvb-core/dvbdev.c 2011-08-23 21:22:32.000000000 -0400
33545 @@ -191,7 +191,7 @@ int dvb_register_device(struct dvb_adapt
33546 const struct dvb_device *template, void *priv, int type)
33547 {
33548 struct dvb_device *dvbdev;
33549 - struct file_operations *dvbdevfops;
33550 + file_operations_no_const *dvbdevfops;
33551 struct device *clsdev;
33552 int minor;
33553 int id;
33554 diff -urNp linux-2.6.32.46/drivers/media/dvb/dvb-usb/cxusb.c linux-2.6.32.46/drivers/media/dvb/dvb-usb/cxusb.c
33555 --- linux-2.6.32.46/drivers/media/dvb/dvb-usb/cxusb.c 2011-03-27 14:31:47.000000000 -0400
33556 +++ linux-2.6.32.46/drivers/media/dvb/dvb-usb/cxusb.c 2011-08-05 20:33:55.000000000 -0400
33557 @@ -1040,7 +1040,7 @@ static struct dib0070_config dib7070p_di
33558 struct dib0700_adapter_state {
33559 int (*set_param_save) (struct dvb_frontend *,
33560 struct dvb_frontend_parameters *);
33561 -};
33562 +} __no_const;
33563
33564 static int dib7070_set_param_override(struct dvb_frontend *fe,
33565 struct dvb_frontend_parameters *fep)
33566 diff -urNp linux-2.6.32.46/drivers/media/dvb/dvb-usb/dib0700_core.c linux-2.6.32.46/drivers/media/dvb/dvb-usb/dib0700_core.c
33567 --- linux-2.6.32.46/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-03-27 14:31:47.000000000 -0400
33568 +++ linux-2.6.32.46/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-16 21:46:57.000000000 -0400
33569 @@ -332,6 +332,8 @@ int dib0700_download_firmware(struct usb
33570
33571 u8 buf[260];
33572
33573 + pax_track_stack();
33574 +
33575 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
33576 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk);
33577
33578 diff -urNp linux-2.6.32.46/drivers/media/dvb/dvb-usb/dib0700_devices.c linux-2.6.32.46/drivers/media/dvb/dvb-usb/dib0700_devices.c
33579 --- linux-2.6.32.46/drivers/media/dvb/dvb-usb/dib0700_devices.c 2011-05-10 22:12:01.000000000 -0400
33580 +++ linux-2.6.32.46/drivers/media/dvb/dvb-usb/dib0700_devices.c 2011-08-05 20:33:55.000000000 -0400
33581 @@ -28,7 +28,7 @@ MODULE_PARM_DESC(force_lna_activation, "
33582
33583 struct dib0700_adapter_state {
33584 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
33585 -};
33586 +} __no_const;
33587
33588 /* Hauppauge Nova-T 500 (aka Bristol)
33589 * has a LNA on GPIO0 which is enabled by setting 1 */
33590 diff -urNp linux-2.6.32.46/drivers/media/dvb/frontends/dib3000.h linux-2.6.32.46/drivers/media/dvb/frontends/dib3000.h
33591 --- linux-2.6.32.46/drivers/media/dvb/frontends/dib3000.h 2011-03-27 14:31:47.000000000 -0400
33592 +++ linux-2.6.32.46/drivers/media/dvb/frontends/dib3000.h 2011-08-05 20:33:55.000000000 -0400
33593 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33594 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33595 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33596 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33597 -};
33598 +} __no_const;
33599
33600 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33601 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33602 diff -urNp linux-2.6.32.46/drivers/media/dvb/frontends/or51211.c linux-2.6.32.46/drivers/media/dvb/frontends/or51211.c
33603 --- linux-2.6.32.46/drivers/media/dvb/frontends/or51211.c 2011-03-27 14:31:47.000000000 -0400
33604 +++ linux-2.6.32.46/drivers/media/dvb/frontends/or51211.c 2011-05-16 21:46:57.000000000 -0400
33605 @@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
33606 u8 tudata[585];
33607 int i;
33608
33609 + pax_track_stack();
33610 +
33611 dprintk("Firmware is %zd bytes\n",fw->size);
33612
33613 /* Get eprom data */
33614 diff -urNp linux-2.6.32.46/drivers/media/radio/radio-cadet.c linux-2.6.32.46/drivers/media/radio/radio-cadet.c
33615 --- linux-2.6.32.46/drivers/media/radio/radio-cadet.c 2011-03-27 14:31:47.000000000 -0400
33616 +++ linux-2.6.32.46/drivers/media/radio/radio-cadet.c 2011-04-17 15:56:46.000000000 -0400
33617 @@ -347,7 +347,7 @@ static ssize_t cadet_read(struct file *f
33618 while (i < count && dev->rdsin != dev->rdsout)
33619 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33620
33621 - if (copy_to_user(data, readbuf, i))
33622 + if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
33623 return -EFAULT;
33624 return i;
33625 }
33626 diff -urNp linux-2.6.32.46/drivers/media/video/cx18/cx18-driver.c linux-2.6.32.46/drivers/media/video/cx18/cx18-driver.c
33627 --- linux-2.6.32.46/drivers/media/video/cx18/cx18-driver.c 2011-03-27 14:31:47.000000000 -0400
33628 +++ linux-2.6.32.46/drivers/media/video/cx18/cx18-driver.c 2011-05-16 21:46:57.000000000 -0400
33629 @@ -56,7 +56,7 @@ static struct pci_device_id cx18_pci_tbl
33630
33631 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
33632
33633 -static atomic_t cx18_instance = ATOMIC_INIT(0);
33634 +static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
33635
33636 /* Parameter declarations */
33637 static int cardtype[CX18_MAX_CARDS];
33638 @@ -288,6 +288,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
33639 struct i2c_client c;
33640 u8 eedata[256];
33641
33642 + pax_track_stack();
33643 +
33644 memset(&c, 0, sizeof(c));
33645 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
33646 c.adapter = &cx->i2c_adap[0];
33647 @@ -800,7 +802,7 @@ static int __devinit cx18_probe(struct p
33648 struct cx18 *cx;
33649
33650 /* FIXME - module parameter arrays constrain max instances */
33651 - i = atomic_inc_return(&cx18_instance) - 1;
33652 + i = atomic_inc_return_unchecked(&cx18_instance) - 1;
33653 if (i >= CX18_MAX_CARDS) {
33654 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
33655 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
33656 diff -urNp linux-2.6.32.46/drivers/media/video/ivtv/ivtv-driver.c linux-2.6.32.46/drivers/media/video/ivtv/ivtv-driver.c
33657 --- linux-2.6.32.46/drivers/media/video/ivtv/ivtv-driver.c 2011-03-27 14:31:47.000000000 -0400
33658 +++ linux-2.6.32.46/drivers/media/video/ivtv/ivtv-driver.c 2011-05-04 17:56:28.000000000 -0400
33659 @@ -79,7 +79,7 @@ static struct pci_device_id ivtv_pci_tbl
33660 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
33661
33662 /* ivtv instance counter */
33663 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
33664 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
33665
33666 /* Parameter declarations */
33667 static int cardtype[IVTV_MAX_CARDS];
33668 diff -urNp linux-2.6.32.46/drivers/media/video/omap24xxcam.c linux-2.6.32.46/drivers/media/video/omap24xxcam.c
33669 --- linux-2.6.32.46/drivers/media/video/omap24xxcam.c 2011-03-27 14:31:47.000000000 -0400
33670 +++ linux-2.6.32.46/drivers/media/video/omap24xxcam.c 2011-05-04 17:56:28.000000000 -0400
33671 @@ -401,7 +401,7 @@ static void omap24xxcam_vbq_complete(str
33672 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
33673
33674 do_gettimeofday(&vb->ts);
33675 - vb->field_count = atomic_add_return(2, &fh->field_count);
33676 + vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
33677 if (csr & csr_error) {
33678 vb->state = VIDEOBUF_ERROR;
33679 if (!atomic_read(&fh->cam->in_reset)) {
33680 diff -urNp linux-2.6.32.46/drivers/media/video/omap24xxcam.h linux-2.6.32.46/drivers/media/video/omap24xxcam.h
33681 --- linux-2.6.32.46/drivers/media/video/omap24xxcam.h 2011-03-27 14:31:47.000000000 -0400
33682 +++ linux-2.6.32.46/drivers/media/video/omap24xxcam.h 2011-05-04 17:56:28.000000000 -0400
33683 @@ -533,7 +533,7 @@ struct omap24xxcam_fh {
33684 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
33685 struct videobuf_queue vbq;
33686 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
33687 - atomic_t field_count; /* field counter for videobuf_buffer */
33688 + atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
33689 /* accessing cam here doesn't need serialisation: it's constant */
33690 struct omap24xxcam_device *cam;
33691 };
33692 diff -urNp linux-2.6.32.46/drivers/media/video/pvrusb2/pvrusb2-eeprom.c linux-2.6.32.46/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
33693 --- linux-2.6.32.46/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-03-27 14:31:47.000000000 -0400
33694 +++ linux-2.6.32.46/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-16 21:46:57.000000000 -0400
33695 @@ -119,6 +119,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
33696 u8 *eeprom;
33697 struct tveeprom tvdata;
33698
33699 + pax_track_stack();
33700 +
33701 memset(&tvdata,0,sizeof(tvdata));
33702
33703 eeprom = pvr2_eeprom_fetch(hdw);
33704 diff -urNp linux-2.6.32.46/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h linux-2.6.32.46/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33705 --- linux-2.6.32.46/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h 2011-03-27 14:31:47.000000000 -0400
33706 +++ linux-2.6.32.46/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h 2011-08-23 21:22:38.000000000 -0400
33707 @@ -195,7 +195,7 @@ struct pvr2_hdw {
33708
33709 /* I2C stuff */
33710 struct i2c_adapter i2c_adap;
33711 - struct i2c_algorithm i2c_algo;
33712 + i2c_algorithm_no_const i2c_algo;
33713 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33714 int i2c_cx25840_hack_state;
33715 int i2c_linked;
33716 diff -urNp linux-2.6.32.46/drivers/media/video/saa7134/saa6752hs.c linux-2.6.32.46/drivers/media/video/saa7134/saa6752hs.c
33717 --- linux-2.6.32.46/drivers/media/video/saa7134/saa6752hs.c 2011-03-27 14:31:47.000000000 -0400
33718 +++ linux-2.6.32.46/drivers/media/video/saa7134/saa6752hs.c 2011-05-16 21:46:57.000000000 -0400
33719 @@ -683,6 +683,8 @@ static int saa6752hs_init(struct v4l2_su
33720 unsigned char localPAT[256];
33721 unsigned char localPMT[256];
33722
33723 + pax_track_stack();
33724 +
33725 /* Set video format - must be done first as it resets other settings */
33726 set_reg8(client, 0x41, h->video_format);
33727
33728 diff -urNp linux-2.6.32.46/drivers/media/video/saa7164/saa7164-cmd.c linux-2.6.32.46/drivers/media/video/saa7164/saa7164-cmd.c
33729 --- linux-2.6.32.46/drivers/media/video/saa7164/saa7164-cmd.c 2011-03-27 14:31:47.000000000 -0400
33730 +++ linux-2.6.32.46/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-16 21:46:57.000000000 -0400
33731 @@ -87,6 +87,8 @@ int saa7164_irq_dequeue(struct saa7164_d
33732 wait_queue_head_t *q = 0;
33733 dprintk(DBGLVL_CMD, "%s()\n", __func__);
33734
33735 + pax_track_stack();
33736 +
33737 /* While any outstand message on the bus exists... */
33738 do {
33739
33740 @@ -126,6 +128,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
33741 u8 tmp[512];
33742 dprintk(DBGLVL_CMD, "%s()\n", __func__);
33743
33744 + pax_track_stack();
33745 +
33746 while (loop) {
33747
33748 tmComResInfo_t tRsp = { 0, 0, 0, 0, 0, 0 };
33749 diff -urNp linux-2.6.32.46/drivers/media/video/usbvideo/ibmcam.c linux-2.6.32.46/drivers/media/video/usbvideo/ibmcam.c
33750 --- linux-2.6.32.46/drivers/media/video/usbvideo/ibmcam.c 2011-03-27 14:31:47.000000000 -0400
33751 +++ linux-2.6.32.46/drivers/media/video/usbvideo/ibmcam.c 2011-08-05 20:33:55.000000000 -0400
33752 @@ -3947,15 +3947,15 @@ static struct usb_device_id id_table[] =
33753 static int __init ibmcam_init(void)
33754 {
33755 struct usbvideo_cb cbTbl;
33756 - memset(&cbTbl, 0, sizeof(cbTbl));
33757 - cbTbl.probe = ibmcam_probe;
33758 - cbTbl.setupOnOpen = ibmcam_setup_on_open;
33759 - cbTbl.videoStart = ibmcam_video_start;
33760 - cbTbl.videoStop = ibmcam_video_stop;
33761 - cbTbl.processData = ibmcam_ProcessIsocData;
33762 - cbTbl.postProcess = usbvideo_DeinterlaceFrame;
33763 - cbTbl.adjustPicture = ibmcam_adjust_picture;
33764 - cbTbl.getFPS = ibmcam_calculate_fps;
33765 + memset((void *)&cbTbl, 0, sizeof(cbTbl));
33766 + *(void **)&cbTbl.probe = ibmcam_probe;
33767 + *(void **)&cbTbl.setupOnOpen = ibmcam_setup_on_open;
33768 + *(void **)&cbTbl.videoStart = ibmcam_video_start;
33769 + *(void **)&cbTbl.videoStop = ibmcam_video_stop;
33770 + *(void **)&cbTbl.processData = ibmcam_ProcessIsocData;
33771 + *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
33772 + *(void **)&cbTbl.adjustPicture = ibmcam_adjust_picture;
33773 + *(void **)&cbTbl.getFPS = ibmcam_calculate_fps;
33774 return usbvideo_register(
33775 &cams,
33776 MAX_IBMCAM,
33777 diff -urNp linux-2.6.32.46/drivers/media/video/usbvideo/konicawc.c linux-2.6.32.46/drivers/media/video/usbvideo/konicawc.c
33778 --- linux-2.6.32.46/drivers/media/video/usbvideo/konicawc.c 2011-03-27 14:31:47.000000000 -0400
33779 +++ linux-2.6.32.46/drivers/media/video/usbvideo/konicawc.c 2011-08-05 20:33:55.000000000 -0400
33780 @@ -225,7 +225,7 @@ static void konicawc_register_input(stru
33781 int error;
33782
33783 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
33784 - strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
33785 + strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
33786
33787 cam->input = input_dev = input_allocate_device();
33788 if (!input_dev) {
33789 @@ -935,16 +935,16 @@ static int __init konicawc_init(void)
33790 struct usbvideo_cb cbTbl;
33791 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
33792 DRIVER_DESC "\n");
33793 - memset(&cbTbl, 0, sizeof(cbTbl));
33794 - cbTbl.probe = konicawc_probe;
33795 - cbTbl.setupOnOpen = konicawc_setup_on_open;
33796 - cbTbl.processData = konicawc_process_isoc;
33797 - cbTbl.getFPS = konicawc_calculate_fps;
33798 - cbTbl.setVideoMode = konicawc_set_video_mode;
33799 - cbTbl.startDataPump = konicawc_start_data;
33800 - cbTbl.stopDataPump = konicawc_stop_data;
33801 - cbTbl.adjustPicture = konicawc_adjust_picture;
33802 - cbTbl.userFree = konicawc_free_uvd;
33803 + memset((void * )&cbTbl, 0, sizeof(cbTbl));
33804 + *(void **)&cbTbl.probe = konicawc_probe;
33805 + *(void **)&cbTbl.setupOnOpen = konicawc_setup_on_open;
33806 + *(void **)&cbTbl.processData = konicawc_process_isoc;
33807 + *(void **)&cbTbl.getFPS = konicawc_calculate_fps;
33808 + *(void **)&cbTbl.setVideoMode = konicawc_set_video_mode;
33809 + *(void **)&cbTbl.startDataPump = konicawc_start_data;
33810 + *(void **)&cbTbl.stopDataPump = konicawc_stop_data;
33811 + *(void **)&cbTbl.adjustPicture = konicawc_adjust_picture;
33812 + *(void **)&cbTbl.userFree = konicawc_free_uvd;
33813 return usbvideo_register(
33814 &cams,
33815 MAX_CAMERAS,
33816 diff -urNp linux-2.6.32.46/drivers/media/video/usbvideo/quickcam_messenger.c linux-2.6.32.46/drivers/media/video/usbvideo/quickcam_messenger.c
33817 --- linux-2.6.32.46/drivers/media/video/usbvideo/quickcam_messenger.c 2011-03-27 14:31:47.000000000 -0400
33818 +++ linux-2.6.32.46/drivers/media/video/usbvideo/quickcam_messenger.c 2011-04-17 15:56:46.000000000 -0400
33819 @@ -89,7 +89,7 @@ static void qcm_register_input(struct qc
33820 int error;
33821
33822 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
33823 - strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
33824 + strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
33825
33826 cam->input = input_dev = input_allocate_device();
33827 if (!input_dev) {
33828 diff -urNp linux-2.6.32.46/drivers/media/video/usbvideo/ultracam.c linux-2.6.32.46/drivers/media/video/usbvideo/ultracam.c
33829 --- linux-2.6.32.46/drivers/media/video/usbvideo/ultracam.c 2011-03-27 14:31:47.000000000 -0400
33830 +++ linux-2.6.32.46/drivers/media/video/usbvideo/ultracam.c 2011-08-05 20:33:55.000000000 -0400
33831 @@ -655,14 +655,14 @@ static int __init ultracam_init(void)
33832 {
33833 struct usbvideo_cb cbTbl;
33834 memset(&cbTbl, 0, sizeof(cbTbl));
33835 - cbTbl.probe = ultracam_probe;
33836 - cbTbl.setupOnOpen = ultracam_setup_on_open;
33837 - cbTbl.videoStart = ultracam_video_start;
33838 - cbTbl.videoStop = ultracam_video_stop;
33839 - cbTbl.processData = ultracam_ProcessIsocData;
33840 - cbTbl.postProcess = usbvideo_DeinterlaceFrame;
33841 - cbTbl.adjustPicture = ultracam_adjust_picture;
33842 - cbTbl.getFPS = ultracam_calculate_fps;
33843 + *(void **)&cbTbl.probe = ultracam_probe;
33844 + *(void **)&cbTbl.setupOnOpen = ultracam_setup_on_open;
33845 + *(void **)&cbTbl.videoStart = ultracam_video_start;
33846 + *(void **)&cbTbl.videoStop = ultracam_video_stop;
33847 + *(void **)&cbTbl.processData = ultracam_ProcessIsocData;
33848 + *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
33849 + *(void **)&cbTbl.adjustPicture = ultracam_adjust_picture;
33850 + *(void **)&cbTbl.getFPS = ultracam_calculate_fps;
33851 return usbvideo_register(
33852 &cams,
33853 MAX_CAMERAS,
33854 diff -urNp linux-2.6.32.46/drivers/media/video/usbvideo/usbvideo.c linux-2.6.32.46/drivers/media/video/usbvideo/usbvideo.c
33855 --- linux-2.6.32.46/drivers/media/video/usbvideo/usbvideo.c 2011-03-27 14:31:47.000000000 -0400
33856 +++ linux-2.6.32.46/drivers/media/video/usbvideo/usbvideo.c 2011-08-05 20:33:55.000000000 -0400
33857 @@ -697,15 +697,15 @@ int usbvideo_register(
33858 __func__, cams, base_size, num_cams);
33859
33860 /* Copy callbacks, apply defaults for those that are not set */
33861 - memmove(&cams->cb, cbTbl, sizeof(cams->cb));
33862 + memmove((void *)&cams->cb, cbTbl, sizeof(cams->cb));
33863 if (cams->cb.getFrame == NULL)
33864 - cams->cb.getFrame = usbvideo_GetFrame;
33865 + *(void **)&cams->cb.getFrame = usbvideo_GetFrame;
33866 if (cams->cb.disconnect == NULL)
33867 - cams->cb.disconnect = usbvideo_Disconnect;
33868 + *(void **)&cams->cb.disconnect = usbvideo_Disconnect;
33869 if (cams->cb.startDataPump == NULL)
33870 - cams->cb.startDataPump = usbvideo_StartDataPump;
33871 + *(void **)&cams->cb.startDataPump = usbvideo_StartDataPump;
33872 if (cams->cb.stopDataPump == NULL)
33873 - cams->cb.stopDataPump = usbvideo_StopDataPump;
33874 + *(void **)&cams->cb.stopDataPump = usbvideo_StopDataPump;
33875
33876 cams->num_cameras = num_cams;
33877 cams->cam = (struct uvd *) &cams[1];
33878 diff -urNp linux-2.6.32.46/drivers/media/video/usbvideo/usbvideo.h linux-2.6.32.46/drivers/media/video/usbvideo/usbvideo.h
33879 --- linux-2.6.32.46/drivers/media/video/usbvideo/usbvideo.h 2011-03-27 14:31:47.000000000 -0400
33880 +++ linux-2.6.32.46/drivers/media/video/usbvideo/usbvideo.h 2011-08-30 18:20:06.000000000 -0400
33881 @@ -268,7 +268,7 @@ struct usbvideo_cb {
33882 int (*startDataPump)(struct uvd *uvd);
33883 void (*stopDataPump)(struct uvd *uvd);
33884 int (*setVideoMode)(struct uvd *uvd, struct video_window *vw);
33885 -};
33886 +} __no_const;
33887
33888 struct usbvideo {
33889 int num_cameras; /* As allocated */
33890 diff -urNp linux-2.6.32.46/drivers/media/video/usbvision/usbvision-core.c linux-2.6.32.46/drivers/media/video/usbvision/usbvision-core.c
33891 --- linux-2.6.32.46/drivers/media/video/usbvision/usbvision-core.c 2011-03-27 14:31:47.000000000 -0400
33892 +++ linux-2.6.32.46/drivers/media/video/usbvision/usbvision-core.c 2011-05-16 21:46:57.000000000 -0400
33893 @@ -820,6 +820,8 @@ static enum ParseState usbvision_parse_c
33894 unsigned char rv, gv, bv;
33895 static unsigned char *Y, *U, *V;
33896
33897 + pax_track_stack();
33898 +
33899 frame = usbvision->curFrame;
33900 imageSize = frame->frmwidth * frame->frmheight;
33901 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
33902 diff -urNp linux-2.6.32.46/drivers/media/video/v4l2-device.c linux-2.6.32.46/drivers/media/video/v4l2-device.c
33903 --- linux-2.6.32.46/drivers/media/video/v4l2-device.c 2011-03-27 14:31:47.000000000 -0400
33904 +++ linux-2.6.32.46/drivers/media/video/v4l2-device.c 2011-05-04 17:56:28.000000000 -0400
33905 @@ -50,9 +50,9 @@ int v4l2_device_register(struct device *
33906 EXPORT_SYMBOL_GPL(v4l2_device_register);
33907
33908 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
33909 - atomic_t *instance)
33910 + atomic_unchecked_t *instance)
33911 {
33912 - int num = atomic_inc_return(instance) - 1;
33913 + int num = atomic_inc_return_unchecked(instance) - 1;
33914 int len = strlen(basename);
33915
33916 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
33917 diff -urNp linux-2.6.32.46/drivers/media/video/videobuf-dma-sg.c linux-2.6.32.46/drivers/media/video/videobuf-dma-sg.c
33918 --- linux-2.6.32.46/drivers/media/video/videobuf-dma-sg.c 2011-03-27 14:31:47.000000000 -0400
33919 +++ linux-2.6.32.46/drivers/media/video/videobuf-dma-sg.c 2011-05-16 21:46:57.000000000 -0400
33920 @@ -693,6 +693,8 @@ void *videobuf_sg_alloc(size_t size)
33921 {
33922 struct videobuf_queue q;
33923
33924 + pax_track_stack();
33925 +
33926 /* Required to make generic handler to call __videobuf_alloc */
33927 q.int_ops = &sg_ops;
33928
33929 diff -urNp linux-2.6.32.46/drivers/message/fusion/mptbase.c linux-2.6.32.46/drivers/message/fusion/mptbase.c
33930 --- linux-2.6.32.46/drivers/message/fusion/mptbase.c 2011-03-27 14:31:47.000000000 -0400
33931 +++ linux-2.6.32.46/drivers/message/fusion/mptbase.c 2011-04-17 15:56:46.000000000 -0400
33932 @@ -6709,8 +6709,14 @@ procmpt_iocinfo_read(char *buf, char **s
33933 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33934 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33935
33936 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33937 + len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33938 + NULL, NULL);
33939 +#else
33940 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33941 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33942 +#endif
33943 +
33944 /*
33945 * Rounding UP to nearest 4-kB boundary here...
33946 */
33947 diff -urNp linux-2.6.32.46/drivers/message/fusion/mptsas.c linux-2.6.32.46/drivers/message/fusion/mptsas.c
33948 --- linux-2.6.32.46/drivers/message/fusion/mptsas.c 2011-03-27 14:31:47.000000000 -0400
33949 +++ linux-2.6.32.46/drivers/message/fusion/mptsas.c 2011-04-17 15:56:46.000000000 -0400
33950 @@ -436,6 +436,23 @@ mptsas_is_end_device(struct mptsas_devin
33951 return 0;
33952 }
33953
33954 +static inline void
33955 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33956 +{
33957 + if (phy_info->port_details) {
33958 + phy_info->port_details->rphy = rphy;
33959 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33960 + ioc->name, rphy));
33961 + }
33962 +
33963 + if (rphy) {
33964 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33965 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33966 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33967 + ioc->name, rphy, rphy->dev.release));
33968 + }
33969 +}
33970 +
33971 /* no mutex */
33972 static void
33973 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33974 @@ -474,23 +491,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
33975 return NULL;
33976 }
33977
33978 -static inline void
33979 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33980 -{
33981 - if (phy_info->port_details) {
33982 - phy_info->port_details->rphy = rphy;
33983 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33984 - ioc->name, rphy));
33985 - }
33986 -
33987 - if (rphy) {
33988 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33989 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33990 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33991 - ioc->name, rphy, rphy->dev.release));
33992 - }
33993 -}
33994 -
33995 static inline struct sas_port *
33996 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33997 {
33998 diff -urNp linux-2.6.32.46/drivers/message/fusion/mptscsih.c linux-2.6.32.46/drivers/message/fusion/mptscsih.c
33999 --- linux-2.6.32.46/drivers/message/fusion/mptscsih.c 2011-03-27 14:31:47.000000000 -0400
34000 +++ linux-2.6.32.46/drivers/message/fusion/mptscsih.c 2011-04-17 15:56:46.000000000 -0400
34001 @@ -1248,15 +1248,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34002
34003 h = shost_priv(SChost);
34004
34005 - if (h) {
34006 - if (h->info_kbuf == NULL)
34007 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34008 - return h->info_kbuf;
34009 - h->info_kbuf[0] = '\0';
34010 + if (!h)
34011 + return NULL;
34012
34013 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34014 - h->info_kbuf[size-1] = '\0';
34015 - }
34016 + if (h->info_kbuf == NULL)
34017 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34018 + return h->info_kbuf;
34019 + h->info_kbuf[0] = '\0';
34020 +
34021 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34022 + h->info_kbuf[size-1] = '\0';
34023
34024 return h->info_kbuf;
34025 }
34026 diff -urNp linux-2.6.32.46/drivers/message/i2o/i2o_config.c linux-2.6.32.46/drivers/message/i2o/i2o_config.c
34027 --- linux-2.6.32.46/drivers/message/i2o/i2o_config.c 2011-03-27 14:31:47.000000000 -0400
34028 +++ linux-2.6.32.46/drivers/message/i2o/i2o_config.c 2011-05-16 21:46:57.000000000 -0400
34029 @@ -787,6 +787,8 @@ static int i2o_cfg_passthru(unsigned lon
34030 struct i2o_message *msg;
34031 unsigned int iop;
34032
34033 + pax_track_stack();
34034 +
34035 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
34036 return -EFAULT;
34037
34038 diff -urNp linux-2.6.32.46/drivers/message/i2o/i2o_proc.c linux-2.6.32.46/drivers/message/i2o/i2o_proc.c
34039 --- linux-2.6.32.46/drivers/message/i2o/i2o_proc.c 2011-03-27 14:31:47.000000000 -0400
34040 +++ linux-2.6.32.46/drivers/message/i2o/i2o_proc.c 2011-04-17 15:56:46.000000000 -0400
34041 @@ -259,13 +259,6 @@ static char *scsi_devices[] = {
34042 "Array Controller Device"
34043 };
34044
34045 -static char *chtostr(u8 * chars, int n)
34046 -{
34047 - char tmp[256];
34048 - tmp[0] = 0;
34049 - return strncat(tmp, (char *)chars, n);
34050 -}
34051 -
34052 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34053 char *group)
34054 {
34055 @@ -842,8 +835,7 @@ static int i2o_seq_show_ddm_table(struct
34056
34057 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34058 seq_printf(seq, "%-#8x", ddm_table.module_id);
34059 - seq_printf(seq, "%-29s",
34060 - chtostr(ddm_table.module_name_version, 28));
34061 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34062 seq_printf(seq, "%9d ", ddm_table.data_size);
34063 seq_printf(seq, "%8d", ddm_table.code_size);
34064
34065 @@ -944,8 +936,8 @@ static int i2o_seq_show_drivers_stored(s
34066
34067 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34068 seq_printf(seq, "%-#8x", dst->module_id);
34069 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34070 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34071 + seq_printf(seq, "%-.28s", dst->module_name_version);
34072 + seq_printf(seq, "%-.8s", dst->date);
34073 seq_printf(seq, "%8d ", dst->module_size);
34074 seq_printf(seq, "%8d ", dst->mpb_size);
34075 seq_printf(seq, "0x%04x", dst->module_flags);
34076 @@ -1276,14 +1268,10 @@ static int i2o_seq_show_dev_identity(str
34077 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34078 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34079 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34080 - seq_printf(seq, "Vendor info : %s\n",
34081 - chtostr((u8 *) (work32 + 2), 16));
34082 - seq_printf(seq, "Product info : %s\n",
34083 - chtostr((u8 *) (work32 + 6), 16));
34084 - seq_printf(seq, "Description : %s\n",
34085 - chtostr((u8 *) (work32 + 10), 16));
34086 - seq_printf(seq, "Product rev. : %s\n",
34087 - chtostr((u8 *) (work32 + 14), 8));
34088 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34089 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34090 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34091 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34092
34093 seq_printf(seq, "Serial number : ");
34094 print_serial_number(seq, (u8 *) (work32 + 16),
34095 @@ -1328,10 +1316,8 @@ static int i2o_seq_show_ddm_identity(str
34096 }
34097
34098 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34099 - seq_printf(seq, "Module name : %s\n",
34100 - chtostr(result.module_name, 24));
34101 - seq_printf(seq, "Module revision : %s\n",
34102 - chtostr(result.module_rev, 8));
34103 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34104 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34105
34106 seq_printf(seq, "Serial number : ");
34107 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34108 @@ -1362,14 +1348,10 @@ static int i2o_seq_show_uinfo(struct seq
34109 return 0;
34110 }
34111
34112 - seq_printf(seq, "Device name : %s\n",
34113 - chtostr(result.device_name, 64));
34114 - seq_printf(seq, "Service name : %s\n",
34115 - chtostr(result.service_name, 64));
34116 - seq_printf(seq, "Physical name : %s\n",
34117 - chtostr(result.physical_location, 64));
34118 - seq_printf(seq, "Instance number : %s\n",
34119 - chtostr(result.instance_number, 4));
34120 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34121 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34122 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34123 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34124
34125 return 0;
34126 }
34127 diff -urNp linux-2.6.32.46/drivers/message/i2o/iop.c linux-2.6.32.46/drivers/message/i2o/iop.c
34128 --- linux-2.6.32.46/drivers/message/i2o/iop.c 2011-03-27 14:31:47.000000000 -0400
34129 +++ linux-2.6.32.46/drivers/message/i2o/iop.c 2011-05-04 17:56:28.000000000 -0400
34130 @@ -110,10 +110,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
34131
34132 spin_lock_irqsave(&c->context_list_lock, flags);
34133
34134 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34135 - atomic_inc(&c->context_list_counter);
34136 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34137 + atomic_inc_unchecked(&c->context_list_counter);
34138
34139 - entry->context = atomic_read(&c->context_list_counter);
34140 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34141
34142 list_add(&entry->list, &c->context_list);
34143
34144 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(voi
34145
34146 #if BITS_PER_LONG == 64
34147 spin_lock_init(&c->context_list_lock);
34148 - atomic_set(&c->context_list_counter, 0);
34149 + atomic_set_unchecked(&c->context_list_counter, 0);
34150 INIT_LIST_HEAD(&c->context_list);
34151 #endif
34152
34153 diff -urNp linux-2.6.32.46/drivers/mfd/wm8350-i2c.c linux-2.6.32.46/drivers/mfd/wm8350-i2c.c
34154 --- linux-2.6.32.46/drivers/mfd/wm8350-i2c.c 2011-03-27 14:31:47.000000000 -0400
34155 +++ linux-2.6.32.46/drivers/mfd/wm8350-i2c.c 2011-05-16 21:46:57.000000000 -0400
34156 @@ -43,6 +43,8 @@ static int wm8350_i2c_write_device(struc
34157 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
34158 int ret;
34159
34160 + pax_track_stack();
34161 +
34162 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
34163 return -EINVAL;
34164
34165 diff -urNp linux-2.6.32.46/drivers/misc/kgdbts.c linux-2.6.32.46/drivers/misc/kgdbts.c
34166 --- linux-2.6.32.46/drivers/misc/kgdbts.c 2011-03-27 14:31:47.000000000 -0400
34167 +++ linux-2.6.32.46/drivers/misc/kgdbts.c 2011-04-17 15:56:46.000000000 -0400
34168 @@ -118,7 +118,7 @@
34169 } while (0)
34170 #define MAX_CONFIG_LEN 40
34171
34172 -static struct kgdb_io kgdbts_io_ops;
34173 +static const struct kgdb_io kgdbts_io_ops;
34174 static char get_buf[BUFMAX];
34175 static int get_buf_cnt;
34176 static char put_buf[BUFMAX];
34177 @@ -1102,7 +1102,7 @@ static void kgdbts_post_exp_handler(void
34178 module_put(THIS_MODULE);
34179 }
34180
34181 -static struct kgdb_io kgdbts_io_ops = {
34182 +static const struct kgdb_io kgdbts_io_ops = {
34183 .name = "kgdbts",
34184 .read_char = kgdbts_get_char,
34185 .write_char = kgdbts_put_char,
34186 diff -urNp linux-2.6.32.46/drivers/misc/sgi-gru/gruhandles.c linux-2.6.32.46/drivers/misc/sgi-gru/gruhandles.c
34187 --- linux-2.6.32.46/drivers/misc/sgi-gru/gruhandles.c 2011-03-27 14:31:47.000000000 -0400
34188 +++ linux-2.6.32.46/drivers/misc/sgi-gru/gruhandles.c 2011-04-17 15:56:46.000000000 -0400
34189 @@ -39,8 +39,8 @@ struct mcs_op_statistic mcs_op_statistic
34190
34191 static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34192 {
34193 - atomic_long_inc(&mcs_op_statistics[op].count);
34194 - atomic_long_add(clks, &mcs_op_statistics[op].total);
34195 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34196 + atomic_long_add_unchecked(clks, &mcs_op_statistics[op].total);
34197 if (mcs_op_statistics[op].max < clks)
34198 mcs_op_statistics[op].max = clks;
34199 }
34200 diff -urNp linux-2.6.32.46/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.32.46/drivers/misc/sgi-gru/gruprocfs.c
34201 --- linux-2.6.32.46/drivers/misc/sgi-gru/gruprocfs.c 2011-03-27 14:31:47.000000000 -0400
34202 +++ linux-2.6.32.46/drivers/misc/sgi-gru/gruprocfs.c 2011-04-17 15:56:46.000000000 -0400
34203 @@ -32,9 +32,9 @@
34204
34205 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34206
34207 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34208 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34209 {
34210 - unsigned long val = atomic_long_read(v);
34211 + unsigned long val = atomic_long_read_unchecked(v);
34212
34213 if (val)
34214 seq_printf(s, "%16lu %s\n", val, id);
34215 @@ -136,8 +136,8 @@ static int mcs_statistics_show(struct se
34216 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
34217
34218 for (op = 0; op < mcsop_last; op++) {
34219 - count = atomic_long_read(&mcs_op_statistics[op].count);
34220 - total = atomic_long_read(&mcs_op_statistics[op].total);
34221 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34222 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34223 max = mcs_op_statistics[op].max;
34224 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34225 count ? total / count : 0, max);
34226 diff -urNp linux-2.6.32.46/drivers/misc/sgi-gru/grutables.h linux-2.6.32.46/drivers/misc/sgi-gru/grutables.h
34227 --- linux-2.6.32.46/drivers/misc/sgi-gru/grutables.h 2011-03-27 14:31:47.000000000 -0400
34228 +++ linux-2.6.32.46/drivers/misc/sgi-gru/grutables.h 2011-04-17 15:56:46.000000000 -0400
34229 @@ -167,84 +167,84 @@ extern unsigned int gru_max_gids;
34230 * GRU statistics.
34231 */
34232 struct gru_stats_s {
34233 - atomic_long_t vdata_alloc;
34234 - atomic_long_t vdata_free;
34235 - atomic_long_t gts_alloc;
34236 - atomic_long_t gts_free;
34237 - atomic_long_t vdata_double_alloc;
34238 - atomic_long_t gts_double_allocate;
34239 - atomic_long_t assign_context;
34240 - atomic_long_t assign_context_failed;
34241 - atomic_long_t free_context;
34242 - atomic_long_t load_user_context;
34243 - atomic_long_t load_kernel_context;
34244 - atomic_long_t lock_kernel_context;
34245 - atomic_long_t unlock_kernel_context;
34246 - atomic_long_t steal_user_context;
34247 - atomic_long_t steal_kernel_context;
34248 - atomic_long_t steal_context_failed;
34249 - atomic_long_t nopfn;
34250 - atomic_long_t break_cow;
34251 - atomic_long_t asid_new;
34252 - atomic_long_t asid_next;
34253 - atomic_long_t asid_wrap;
34254 - atomic_long_t asid_reuse;
34255 - atomic_long_t intr;
34256 - atomic_long_t intr_mm_lock_failed;
34257 - atomic_long_t call_os;
34258 - atomic_long_t call_os_offnode_reference;
34259 - atomic_long_t call_os_check_for_bug;
34260 - atomic_long_t call_os_wait_queue;
34261 - atomic_long_t user_flush_tlb;
34262 - atomic_long_t user_unload_context;
34263 - atomic_long_t user_exception;
34264 - atomic_long_t set_context_option;
34265 - atomic_long_t migrate_check;
34266 - atomic_long_t migrated_retarget;
34267 - atomic_long_t migrated_unload;
34268 - atomic_long_t migrated_unload_delay;
34269 - atomic_long_t migrated_nopfn_retarget;
34270 - atomic_long_t migrated_nopfn_unload;
34271 - atomic_long_t tlb_dropin;
34272 - atomic_long_t tlb_dropin_fail_no_asid;
34273 - atomic_long_t tlb_dropin_fail_upm;
34274 - atomic_long_t tlb_dropin_fail_invalid;
34275 - atomic_long_t tlb_dropin_fail_range_active;
34276 - atomic_long_t tlb_dropin_fail_idle;
34277 - atomic_long_t tlb_dropin_fail_fmm;
34278 - atomic_long_t tlb_dropin_fail_no_exception;
34279 - atomic_long_t tlb_dropin_fail_no_exception_war;
34280 - atomic_long_t tfh_stale_on_fault;
34281 - atomic_long_t mmu_invalidate_range;
34282 - atomic_long_t mmu_invalidate_page;
34283 - atomic_long_t mmu_clear_flush_young;
34284 - atomic_long_t flush_tlb;
34285 - atomic_long_t flush_tlb_gru;
34286 - atomic_long_t flush_tlb_gru_tgh;
34287 - atomic_long_t flush_tlb_gru_zero_asid;
34288 -
34289 - atomic_long_t copy_gpa;
34290 -
34291 - atomic_long_t mesq_receive;
34292 - atomic_long_t mesq_receive_none;
34293 - atomic_long_t mesq_send;
34294 - atomic_long_t mesq_send_failed;
34295 - atomic_long_t mesq_noop;
34296 - atomic_long_t mesq_send_unexpected_error;
34297 - atomic_long_t mesq_send_lb_overflow;
34298 - atomic_long_t mesq_send_qlimit_reached;
34299 - atomic_long_t mesq_send_amo_nacked;
34300 - atomic_long_t mesq_send_put_nacked;
34301 - atomic_long_t mesq_qf_not_full;
34302 - atomic_long_t mesq_qf_locked;
34303 - atomic_long_t mesq_qf_noop_not_full;
34304 - atomic_long_t mesq_qf_switch_head_failed;
34305 - atomic_long_t mesq_qf_unexpected_error;
34306 - atomic_long_t mesq_noop_unexpected_error;
34307 - atomic_long_t mesq_noop_lb_overflow;
34308 - atomic_long_t mesq_noop_qlimit_reached;
34309 - atomic_long_t mesq_noop_amo_nacked;
34310 - atomic_long_t mesq_noop_put_nacked;
34311 + atomic_long_unchecked_t vdata_alloc;
34312 + atomic_long_unchecked_t vdata_free;
34313 + atomic_long_unchecked_t gts_alloc;
34314 + atomic_long_unchecked_t gts_free;
34315 + atomic_long_unchecked_t vdata_double_alloc;
34316 + atomic_long_unchecked_t gts_double_allocate;
34317 + atomic_long_unchecked_t assign_context;
34318 + atomic_long_unchecked_t assign_context_failed;
34319 + atomic_long_unchecked_t free_context;
34320 + atomic_long_unchecked_t load_user_context;
34321 + atomic_long_unchecked_t load_kernel_context;
34322 + atomic_long_unchecked_t lock_kernel_context;
34323 + atomic_long_unchecked_t unlock_kernel_context;
34324 + atomic_long_unchecked_t steal_user_context;
34325 + atomic_long_unchecked_t steal_kernel_context;
34326 + atomic_long_unchecked_t steal_context_failed;
34327 + atomic_long_unchecked_t nopfn;
34328 + atomic_long_unchecked_t break_cow;
34329 + atomic_long_unchecked_t asid_new;
34330 + atomic_long_unchecked_t asid_next;
34331 + atomic_long_unchecked_t asid_wrap;
34332 + atomic_long_unchecked_t asid_reuse;
34333 + atomic_long_unchecked_t intr;
34334 + atomic_long_unchecked_t intr_mm_lock_failed;
34335 + atomic_long_unchecked_t call_os;
34336 + atomic_long_unchecked_t call_os_offnode_reference;
34337 + atomic_long_unchecked_t call_os_check_for_bug;
34338 + atomic_long_unchecked_t call_os_wait_queue;
34339 + atomic_long_unchecked_t user_flush_tlb;
34340 + atomic_long_unchecked_t user_unload_context;
34341 + atomic_long_unchecked_t user_exception;
34342 + atomic_long_unchecked_t set_context_option;
34343 + atomic_long_unchecked_t migrate_check;
34344 + atomic_long_unchecked_t migrated_retarget;
34345 + atomic_long_unchecked_t migrated_unload;
34346 + atomic_long_unchecked_t migrated_unload_delay;
34347 + atomic_long_unchecked_t migrated_nopfn_retarget;
34348 + atomic_long_unchecked_t migrated_nopfn_unload;
34349 + atomic_long_unchecked_t tlb_dropin;
34350 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34351 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34352 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34353 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34354 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34355 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34356 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34357 + atomic_long_unchecked_t tlb_dropin_fail_no_exception_war;
34358 + atomic_long_unchecked_t tfh_stale_on_fault;
34359 + atomic_long_unchecked_t mmu_invalidate_range;
34360 + atomic_long_unchecked_t mmu_invalidate_page;
34361 + atomic_long_unchecked_t mmu_clear_flush_young;
34362 + atomic_long_unchecked_t flush_tlb;
34363 + atomic_long_unchecked_t flush_tlb_gru;
34364 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34365 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34366 +
34367 + atomic_long_unchecked_t copy_gpa;
34368 +
34369 + atomic_long_unchecked_t mesq_receive;
34370 + atomic_long_unchecked_t mesq_receive_none;
34371 + atomic_long_unchecked_t mesq_send;
34372 + atomic_long_unchecked_t mesq_send_failed;
34373 + atomic_long_unchecked_t mesq_noop;
34374 + atomic_long_unchecked_t mesq_send_unexpected_error;
34375 + atomic_long_unchecked_t mesq_send_lb_overflow;
34376 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34377 + atomic_long_unchecked_t mesq_send_amo_nacked;
34378 + atomic_long_unchecked_t mesq_send_put_nacked;
34379 + atomic_long_unchecked_t mesq_qf_not_full;
34380 + atomic_long_unchecked_t mesq_qf_locked;
34381 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34382 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34383 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34384 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34385 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34386 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34387 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34388 + atomic_long_unchecked_t mesq_noop_put_nacked;
34389
34390 };
34391
34392 @@ -252,8 +252,8 @@ enum mcs_op {cchop_allocate, cchop_start
34393 cchop_deallocate, tghop_invalidate, mcsop_last};
34394
34395 struct mcs_op_statistic {
34396 - atomic_long_t count;
34397 - atomic_long_t total;
34398 + atomic_long_unchecked_t count;
34399 + atomic_long_unchecked_t total;
34400 unsigned long max;
34401 };
34402
34403 @@ -276,7 +276,7 @@ extern struct mcs_op_statistic mcs_op_st
34404
34405 #define STAT(id) do { \
34406 if (gru_options & OPT_STATS) \
34407 - atomic_long_inc(&gru_stats.id); \
34408 + atomic_long_inc_unchecked(&gru_stats.id); \
34409 } while (0)
34410
34411 #ifdef CONFIG_SGI_GRU_DEBUG
34412 diff -urNp linux-2.6.32.46/drivers/misc/sgi-xp/xp.h linux-2.6.32.46/drivers/misc/sgi-xp/xp.h
34413 --- linux-2.6.32.46/drivers/misc/sgi-xp/xp.h 2011-03-27 14:31:47.000000000 -0400
34414 +++ linux-2.6.32.46/drivers/misc/sgi-xp/xp.h 2011-08-05 20:33:55.000000000 -0400
34415 @@ -289,7 +289,7 @@ struct xpc_interface {
34416 xpc_notify_func, void *);
34417 void (*received) (short, int, void *);
34418 enum xp_retval (*partid_to_nasids) (short, void *);
34419 -};
34420 +} __no_const;
34421
34422 extern struct xpc_interface xpc_interface;
34423
34424 diff -urNp linux-2.6.32.46/drivers/misc/sgi-xp/xpc.h linux-2.6.32.46/drivers/misc/sgi-xp/xpc.h
34425 --- linux-2.6.32.46/drivers/misc/sgi-xp/xpc.h 2011-03-27 14:31:47.000000000 -0400
34426 +++ linux-2.6.32.46/drivers/misc/sgi-xp/xpc.h 2011-08-05 20:33:55.000000000 -0400
34427 @@ -876,7 +876,7 @@ extern struct xpc_registration xpc_regis
34428 /* found in xpc_main.c */
34429 extern struct device *xpc_part;
34430 extern struct device *xpc_chan;
34431 -extern struct xpc_arch_operations xpc_arch_ops;
34432 +extern const struct xpc_arch_operations xpc_arch_ops;
34433 extern int xpc_disengage_timelimit;
34434 extern int xpc_disengage_timedout;
34435 extern int xpc_activate_IRQ_rcvd;
34436 diff -urNp linux-2.6.32.46/drivers/misc/sgi-xp/xpc_main.c linux-2.6.32.46/drivers/misc/sgi-xp/xpc_main.c
34437 --- linux-2.6.32.46/drivers/misc/sgi-xp/xpc_main.c 2011-03-27 14:31:47.000000000 -0400
34438 +++ linux-2.6.32.46/drivers/misc/sgi-xp/xpc_main.c 2011-08-05 20:33:55.000000000 -0400
34439 @@ -169,7 +169,7 @@ static struct notifier_block xpc_die_not
34440 .notifier_call = xpc_system_die,
34441 };
34442
34443 -struct xpc_arch_operations xpc_arch_ops;
34444 +const struct xpc_arch_operations xpc_arch_ops;
34445
34446 /*
34447 * Timer function to enforce the timelimit on the partition disengage.
34448 diff -urNp linux-2.6.32.46/drivers/misc/sgi-xp/xpc_sn2.c linux-2.6.32.46/drivers/misc/sgi-xp/xpc_sn2.c
34449 --- linux-2.6.32.46/drivers/misc/sgi-xp/xpc_sn2.c 2011-03-27 14:31:47.000000000 -0400
34450 +++ linux-2.6.32.46/drivers/misc/sgi-xp/xpc_sn2.c 2011-08-05 20:33:55.000000000 -0400
34451 @@ -2350,7 +2350,7 @@ xpc_received_payload_sn2(struct xpc_chan
34452 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
34453 }
34454
34455 -static struct xpc_arch_operations xpc_arch_ops_sn2 = {
34456 +static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
34457 .setup_partitions = xpc_setup_partitions_sn2,
34458 .teardown_partitions = xpc_teardown_partitions_sn2,
34459 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
34460 @@ -2413,7 +2413,9 @@ xpc_init_sn2(void)
34461 int ret;
34462 size_t buf_size;
34463
34464 - xpc_arch_ops = xpc_arch_ops_sn2;
34465 + pax_open_kernel();
34466 + memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_sn2, sizeof(xpc_arch_ops_sn2));
34467 + pax_close_kernel();
34468
34469 if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) {
34470 dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is "
34471 diff -urNp linux-2.6.32.46/drivers/misc/sgi-xp/xpc_uv.c linux-2.6.32.46/drivers/misc/sgi-xp/xpc_uv.c
34472 --- linux-2.6.32.46/drivers/misc/sgi-xp/xpc_uv.c 2011-03-27 14:31:47.000000000 -0400
34473 +++ linux-2.6.32.46/drivers/misc/sgi-xp/xpc_uv.c 2011-08-05 20:33:55.000000000 -0400
34474 @@ -1669,7 +1669,7 @@ xpc_received_payload_uv(struct xpc_chann
34475 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
34476 }
34477
34478 -static struct xpc_arch_operations xpc_arch_ops_uv = {
34479 +static const struct xpc_arch_operations xpc_arch_ops_uv = {
34480 .setup_partitions = xpc_setup_partitions_uv,
34481 .teardown_partitions = xpc_teardown_partitions_uv,
34482 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
34483 @@ -1729,7 +1729,9 @@ static struct xpc_arch_operations xpc_ar
34484 int
34485 xpc_init_uv(void)
34486 {
34487 - xpc_arch_ops = xpc_arch_ops_uv;
34488 + pax_open_kernel();
34489 + memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_uv, sizeof(xpc_arch_ops_uv));
34490 + pax_close_kernel();
34491
34492 if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
34493 dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
34494 diff -urNp linux-2.6.32.46/drivers/mtd/chips/cfi_cmdset_0001.c linux-2.6.32.46/drivers/mtd/chips/cfi_cmdset_0001.c
34495 --- linux-2.6.32.46/drivers/mtd/chips/cfi_cmdset_0001.c 2011-03-27 14:31:47.000000000 -0400
34496 +++ linux-2.6.32.46/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-16 21:46:57.000000000 -0400
34497 @@ -743,6 +743,8 @@ static int chip_ready (struct map_info *
34498 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
34499 unsigned long timeo = jiffies + HZ;
34500
34501 + pax_track_stack();
34502 +
34503 /* Prevent setting state FL_SYNCING for chip in suspended state. */
34504 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
34505 goto sleep;
34506 @@ -1642,6 +1644,8 @@ static int __xipram do_write_buffer(stru
34507 unsigned long initial_adr;
34508 int initial_len = len;
34509
34510 + pax_track_stack();
34511 +
34512 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
34513 adr += chip->start;
34514 initial_adr = adr;
34515 @@ -1860,6 +1864,8 @@ static int __xipram do_erase_oneblock(st
34516 int retries = 3;
34517 int ret;
34518
34519 + pax_track_stack();
34520 +
34521 adr += chip->start;
34522
34523 retry:
34524 diff -urNp linux-2.6.32.46/drivers/mtd/chips/cfi_cmdset_0020.c linux-2.6.32.46/drivers/mtd/chips/cfi_cmdset_0020.c
34525 --- linux-2.6.32.46/drivers/mtd/chips/cfi_cmdset_0020.c 2011-03-27 14:31:47.000000000 -0400
34526 +++ linux-2.6.32.46/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-16 21:46:57.000000000 -0400
34527 @@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
34528 unsigned long cmd_addr;
34529 struct cfi_private *cfi = map->fldrv_priv;
34530
34531 + pax_track_stack();
34532 +
34533 adr += chip->start;
34534
34535 /* Ensure cmd read/writes are aligned. */
34536 @@ -428,6 +430,8 @@ static inline int do_write_buffer(struct
34537 DECLARE_WAITQUEUE(wait, current);
34538 int wbufsize, z;
34539
34540 + pax_track_stack();
34541 +
34542 /* M58LW064A requires bus alignment for buffer wriets -- saw */
34543 if (adr & (map_bankwidth(map)-1))
34544 return -EINVAL;
34545 @@ -742,6 +746,8 @@ static inline int do_erase_oneblock(stru
34546 DECLARE_WAITQUEUE(wait, current);
34547 int ret = 0;
34548
34549 + pax_track_stack();
34550 +
34551 adr += chip->start;
34552
34553 /* Let's determine this according to the interleave only once */
34554 @@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struc
34555 unsigned long timeo = jiffies + HZ;
34556 DECLARE_WAITQUEUE(wait, current);
34557
34558 + pax_track_stack();
34559 +
34560 adr += chip->start;
34561
34562 /* Let's determine this according to the interleave only once */
34563 @@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(str
34564 unsigned long timeo = jiffies + HZ;
34565 DECLARE_WAITQUEUE(wait, current);
34566
34567 + pax_track_stack();
34568 +
34569 adr += chip->start;
34570
34571 /* Let's determine this according to the interleave only once */
34572 diff -urNp linux-2.6.32.46/drivers/mtd/devices/doc2000.c linux-2.6.32.46/drivers/mtd/devices/doc2000.c
34573 --- linux-2.6.32.46/drivers/mtd/devices/doc2000.c 2011-03-27 14:31:47.000000000 -0400
34574 +++ linux-2.6.32.46/drivers/mtd/devices/doc2000.c 2011-04-17 15:56:46.000000000 -0400
34575 @@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
34576
34577 /* The ECC will not be calculated correctly if less than 512 is written */
34578 /* DBB-
34579 - if (len != 0x200 && eccbuf)
34580 + if (len != 0x200)
34581 printk(KERN_WARNING
34582 "ECC needs a full sector write (adr: %lx size %lx)\n",
34583 (long) to, (long) len);
34584 diff -urNp linux-2.6.32.46/drivers/mtd/devices/doc2001.c linux-2.6.32.46/drivers/mtd/devices/doc2001.c
34585 --- linux-2.6.32.46/drivers/mtd/devices/doc2001.c 2011-03-27 14:31:47.000000000 -0400
34586 +++ linux-2.6.32.46/drivers/mtd/devices/doc2001.c 2011-04-17 15:56:46.000000000 -0400
34587 @@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
34588 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34589
34590 /* Don't allow read past end of device */
34591 - if (from >= this->totlen)
34592 + if (from >= this->totlen || !len)
34593 return -EINVAL;
34594
34595 /* Don't allow a single read to cross a 512-byte block boundary */
34596 diff -urNp linux-2.6.32.46/drivers/mtd/ftl.c linux-2.6.32.46/drivers/mtd/ftl.c
34597 --- linux-2.6.32.46/drivers/mtd/ftl.c 2011-03-27 14:31:47.000000000 -0400
34598 +++ linux-2.6.32.46/drivers/mtd/ftl.c 2011-05-16 21:46:57.000000000 -0400
34599 @@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
34600 loff_t offset;
34601 uint16_t srcunitswap = cpu_to_le16(srcunit);
34602
34603 + pax_track_stack();
34604 +
34605 eun = &part->EUNInfo[srcunit];
34606 xfer = &part->XferInfo[xferunit];
34607 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
34608 diff -urNp linux-2.6.32.46/drivers/mtd/inftlcore.c linux-2.6.32.46/drivers/mtd/inftlcore.c
34609 --- linux-2.6.32.46/drivers/mtd/inftlcore.c 2011-03-27 14:31:47.000000000 -0400
34610 +++ linux-2.6.32.46/drivers/mtd/inftlcore.c 2011-05-16 21:46:57.000000000 -0400
34611 @@ -260,6 +260,8 @@ static u16 INFTL_foldchain(struct INFTLr
34612 struct inftl_oob oob;
34613 size_t retlen;
34614
34615 + pax_track_stack();
34616 +
34617 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
34618 "pending=%d)\n", inftl, thisVUC, pendingblock);
34619
34620 diff -urNp linux-2.6.32.46/drivers/mtd/inftlmount.c linux-2.6.32.46/drivers/mtd/inftlmount.c
34621 --- linux-2.6.32.46/drivers/mtd/inftlmount.c 2011-03-27 14:31:47.000000000 -0400
34622 +++ linux-2.6.32.46/drivers/mtd/inftlmount.c 2011-05-16 21:46:57.000000000 -0400
34623 @@ -54,6 +54,8 @@ static int find_boot_record(struct INFTL
34624 struct INFTLPartition *ip;
34625 size_t retlen;
34626
34627 + pax_track_stack();
34628 +
34629 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
34630
34631 /*
34632 diff -urNp linux-2.6.32.46/drivers/mtd/lpddr/qinfo_probe.c linux-2.6.32.46/drivers/mtd/lpddr/qinfo_probe.c
34633 --- linux-2.6.32.46/drivers/mtd/lpddr/qinfo_probe.c 2011-03-27 14:31:47.000000000 -0400
34634 +++ linux-2.6.32.46/drivers/mtd/lpddr/qinfo_probe.c 2011-05-16 21:46:57.000000000 -0400
34635 @@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
34636 {
34637 map_word pfow_val[4];
34638
34639 + pax_track_stack();
34640 +
34641 /* Check identification string */
34642 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
34643 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
34644 diff -urNp linux-2.6.32.46/drivers/mtd/mtdchar.c linux-2.6.32.46/drivers/mtd/mtdchar.c
34645 --- linux-2.6.32.46/drivers/mtd/mtdchar.c 2011-03-27 14:31:47.000000000 -0400
34646 +++ linux-2.6.32.46/drivers/mtd/mtdchar.c 2011-05-16 21:46:57.000000000 -0400
34647 @@ -460,6 +460,8 @@ static int mtd_ioctl(struct inode *inode
34648 u_long size;
34649 struct mtd_info_user info;
34650
34651 + pax_track_stack();
34652 +
34653 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
34654
34655 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
34656 diff -urNp linux-2.6.32.46/drivers/mtd/nftlcore.c linux-2.6.32.46/drivers/mtd/nftlcore.c
34657 --- linux-2.6.32.46/drivers/mtd/nftlcore.c 2011-03-27 14:31:47.000000000 -0400
34658 +++ linux-2.6.32.46/drivers/mtd/nftlcore.c 2011-05-16 21:46:57.000000000 -0400
34659 @@ -254,6 +254,8 @@ static u16 NFTL_foldchain (struct NFTLre
34660 int inplace = 1;
34661 size_t retlen;
34662
34663 + pax_track_stack();
34664 +
34665 memset(BlockMap, 0xff, sizeof(BlockMap));
34666 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
34667
34668 diff -urNp linux-2.6.32.46/drivers/mtd/nftlmount.c linux-2.6.32.46/drivers/mtd/nftlmount.c
34669 --- linux-2.6.32.46/drivers/mtd/nftlmount.c 2011-03-27 14:31:47.000000000 -0400
34670 +++ linux-2.6.32.46/drivers/mtd/nftlmount.c 2011-05-18 20:09:37.000000000 -0400
34671 @@ -23,6 +23,7 @@
34672 #include <asm/errno.h>
34673 #include <linux/delay.h>
34674 #include <linux/slab.h>
34675 +#include <linux/sched.h>
34676 #include <linux/mtd/mtd.h>
34677 #include <linux/mtd/nand.h>
34678 #include <linux/mtd/nftl.h>
34679 @@ -44,6 +45,8 @@ static int find_boot_record(struct NFTLr
34680 struct mtd_info *mtd = nftl->mbd.mtd;
34681 unsigned int i;
34682
34683 + pax_track_stack();
34684 +
34685 /* Assume logical EraseSize == physical erasesize for starting the scan.
34686 We'll sort it out later if we find a MediaHeader which says otherwise */
34687 /* Actually, we won't. The new DiskOnChip driver has already scanned
34688 diff -urNp linux-2.6.32.46/drivers/mtd/ubi/build.c linux-2.6.32.46/drivers/mtd/ubi/build.c
34689 --- linux-2.6.32.46/drivers/mtd/ubi/build.c 2011-03-27 14:31:47.000000000 -0400
34690 +++ linux-2.6.32.46/drivers/mtd/ubi/build.c 2011-04-17 15:56:46.000000000 -0400
34691 @@ -1255,7 +1255,7 @@ module_exit(ubi_exit);
34692 static int __init bytes_str_to_int(const char *str)
34693 {
34694 char *endp;
34695 - unsigned long result;
34696 + unsigned long result, scale = 1;
34697
34698 result = simple_strtoul(str, &endp, 0);
34699 if (str == endp || result >= INT_MAX) {
34700 @@ -1266,11 +1266,11 @@ static int __init bytes_str_to_int(const
34701
34702 switch (*endp) {
34703 case 'G':
34704 - result *= 1024;
34705 + scale *= 1024;
34706 case 'M':
34707 - result *= 1024;
34708 + scale *= 1024;
34709 case 'K':
34710 - result *= 1024;
34711 + scale *= 1024;
34712 if (endp[1] == 'i' && endp[2] == 'B')
34713 endp += 2;
34714 case '\0':
34715 @@ -1281,7 +1281,13 @@ static int __init bytes_str_to_int(const
34716 return -EINVAL;
34717 }
34718
34719 - return result;
34720 + if ((intoverflow_t)result*scale >= INT_MAX) {
34721 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
34722 + str);
34723 + return -EINVAL;
34724 + }
34725 +
34726 + return result*scale;
34727 }
34728
34729 /**
34730 diff -urNp linux-2.6.32.46/drivers/net/bnx2.c linux-2.6.32.46/drivers/net/bnx2.c
34731 --- linux-2.6.32.46/drivers/net/bnx2.c 2011-03-27 14:31:47.000000000 -0400
34732 +++ linux-2.6.32.46/drivers/net/bnx2.c 2011-05-16 21:46:57.000000000 -0400
34733 @@ -5809,6 +5809,8 @@ bnx2_test_nvram(struct bnx2 *bp)
34734 int rc = 0;
34735 u32 magic, csum;
34736
34737 + pax_track_stack();
34738 +
34739 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
34740 goto test_nvram_done;
34741
34742 diff -urNp linux-2.6.32.46/drivers/net/cxgb3/l2t.h linux-2.6.32.46/drivers/net/cxgb3/l2t.h
34743 --- linux-2.6.32.46/drivers/net/cxgb3/l2t.h 2011-03-27 14:31:47.000000000 -0400
34744 +++ linux-2.6.32.46/drivers/net/cxgb3/l2t.h 2011-08-05 20:33:55.000000000 -0400
34745 @@ -86,7 +86,7 @@ typedef void (*arp_failure_handler_func)
34746 */
34747 struct l2t_skb_cb {
34748 arp_failure_handler_func arp_failure_handler;
34749 -};
34750 +} __no_const;
34751
34752 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34753
34754 diff -urNp linux-2.6.32.46/drivers/net/cxgb3/t3_hw.c linux-2.6.32.46/drivers/net/cxgb3/t3_hw.c
34755 --- linux-2.6.32.46/drivers/net/cxgb3/t3_hw.c 2011-03-27 14:31:47.000000000 -0400
34756 +++ linux-2.6.32.46/drivers/net/cxgb3/t3_hw.c 2011-05-16 21:46:57.000000000 -0400
34757 @@ -699,6 +699,8 @@ static int get_vpd_params(struct adapter
34758 int i, addr, ret;
34759 struct t3_vpd vpd;
34760
34761 + pax_track_stack();
34762 +
34763 /*
34764 * Card information is normally at VPD_BASE but some early cards had
34765 * it at 0.
34766 diff -urNp linux-2.6.32.46/drivers/net/e1000e/82571.c linux-2.6.32.46/drivers/net/e1000e/82571.c
34767 --- linux-2.6.32.46/drivers/net/e1000e/82571.c 2011-03-27 14:31:47.000000000 -0400
34768 +++ linux-2.6.32.46/drivers/net/e1000e/82571.c 2011-08-23 21:22:32.000000000 -0400
34769 @@ -212,7 +212,7 @@ static s32 e1000_init_mac_params_82571(s
34770 {
34771 struct e1000_hw *hw = &adapter->hw;
34772 struct e1000_mac_info *mac = &hw->mac;
34773 - struct e1000_mac_operations *func = &mac->ops;
34774 + e1000_mac_operations_no_const *func = &mac->ops;
34775 u32 swsm = 0;
34776 u32 swsm2 = 0;
34777 bool force_clear_smbi = false;
34778 @@ -1656,7 +1656,7 @@ static void e1000_clear_hw_cntrs_82571(s
34779 temp = er32(ICRXDMTC);
34780 }
34781
34782 -static struct e1000_mac_operations e82571_mac_ops = {
34783 +static const struct e1000_mac_operations e82571_mac_ops = {
34784 /* .check_mng_mode: mac type dependent */
34785 /* .check_for_link: media type dependent */
34786 .id_led_init = e1000e_id_led_init,
34787 @@ -1674,7 +1674,7 @@ static struct e1000_mac_operations e8257
34788 .setup_led = e1000e_setup_led_generic,
34789 };
34790
34791 -static struct e1000_phy_operations e82_phy_ops_igp = {
34792 +static const struct e1000_phy_operations e82_phy_ops_igp = {
34793 .acquire_phy = e1000_get_hw_semaphore_82571,
34794 .check_reset_block = e1000e_check_reset_block_generic,
34795 .commit_phy = NULL,
34796 @@ -1691,7 +1691,7 @@ static struct e1000_phy_operations e82_p
34797 .cfg_on_link_up = NULL,
34798 };
34799
34800 -static struct e1000_phy_operations e82_phy_ops_m88 = {
34801 +static const struct e1000_phy_operations e82_phy_ops_m88 = {
34802 .acquire_phy = e1000_get_hw_semaphore_82571,
34803 .check_reset_block = e1000e_check_reset_block_generic,
34804 .commit_phy = e1000e_phy_sw_reset,
34805 @@ -1708,7 +1708,7 @@ static struct e1000_phy_operations e82_p
34806 .cfg_on_link_up = NULL,
34807 };
34808
34809 -static struct e1000_phy_operations e82_phy_ops_bm = {
34810 +static const struct e1000_phy_operations e82_phy_ops_bm = {
34811 .acquire_phy = e1000_get_hw_semaphore_82571,
34812 .check_reset_block = e1000e_check_reset_block_generic,
34813 .commit_phy = e1000e_phy_sw_reset,
34814 @@ -1725,7 +1725,7 @@ static struct e1000_phy_operations e82_p
34815 .cfg_on_link_up = NULL,
34816 };
34817
34818 -static struct e1000_nvm_operations e82571_nvm_ops = {
34819 +static const struct e1000_nvm_operations e82571_nvm_ops = {
34820 .acquire_nvm = e1000_acquire_nvm_82571,
34821 .read_nvm = e1000e_read_nvm_eerd,
34822 .release_nvm = e1000_release_nvm_82571,
34823 diff -urNp linux-2.6.32.46/drivers/net/e1000e/e1000.h linux-2.6.32.46/drivers/net/e1000e/e1000.h
34824 --- linux-2.6.32.46/drivers/net/e1000e/e1000.h 2011-03-27 14:31:47.000000000 -0400
34825 +++ linux-2.6.32.46/drivers/net/e1000e/e1000.h 2011-04-17 15:56:46.000000000 -0400
34826 @@ -375,9 +375,9 @@ struct e1000_info {
34827 u32 pba;
34828 u32 max_hw_frame_size;
34829 s32 (*get_variants)(struct e1000_adapter *);
34830 - struct e1000_mac_operations *mac_ops;
34831 - struct e1000_phy_operations *phy_ops;
34832 - struct e1000_nvm_operations *nvm_ops;
34833 + const struct e1000_mac_operations *mac_ops;
34834 + const struct e1000_phy_operations *phy_ops;
34835 + const struct e1000_nvm_operations *nvm_ops;
34836 };
34837
34838 /* hardware capability, feature, and workaround flags */
34839 diff -urNp linux-2.6.32.46/drivers/net/e1000e/es2lan.c linux-2.6.32.46/drivers/net/e1000e/es2lan.c
34840 --- linux-2.6.32.46/drivers/net/e1000e/es2lan.c 2011-03-27 14:31:47.000000000 -0400
34841 +++ linux-2.6.32.46/drivers/net/e1000e/es2lan.c 2011-08-23 21:22:32.000000000 -0400
34842 @@ -207,7 +207,7 @@ static s32 e1000_init_mac_params_80003es
34843 {
34844 struct e1000_hw *hw = &adapter->hw;
34845 struct e1000_mac_info *mac = &hw->mac;
34846 - struct e1000_mac_operations *func = &mac->ops;
34847 + e1000_mac_operations_no_const *func = &mac->ops;
34848
34849 /* Set media type */
34850 switch (adapter->pdev->device) {
34851 @@ -1365,7 +1365,7 @@ static void e1000_clear_hw_cntrs_80003es
34852 temp = er32(ICRXDMTC);
34853 }
34854
34855 -static struct e1000_mac_operations es2_mac_ops = {
34856 +static const struct e1000_mac_operations es2_mac_ops = {
34857 .id_led_init = e1000e_id_led_init,
34858 .check_mng_mode = e1000e_check_mng_mode_generic,
34859 /* check_for_link dependent on media type */
34860 @@ -1383,7 +1383,7 @@ static struct e1000_mac_operations es2_m
34861 .setup_led = e1000e_setup_led_generic,
34862 };
34863
34864 -static struct e1000_phy_operations es2_phy_ops = {
34865 +static const struct e1000_phy_operations es2_phy_ops = {
34866 .acquire_phy = e1000_acquire_phy_80003es2lan,
34867 .check_reset_block = e1000e_check_reset_block_generic,
34868 .commit_phy = e1000e_phy_sw_reset,
34869 @@ -1400,7 +1400,7 @@ static struct e1000_phy_operations es2_p
34870 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
34871 };
34872
34873 -static struct e1000_nvm_operations es2_nvm_ops = {
34874 +static const struct e1000_nvm_operations es2_nvm_ops = {
34875 .acquire_nvm = e1000_acquire_nvm_80003es2lan,
34876 .read_nvm = e1000e_read_nvm_eerd,
34877 .release_nvm = e1000_release_nvm_80003es2lan,
34878 diff -urNp linux-2.6.32.46/drivers/net/e1000e/hw.h linux-2.6.32.46/drivers/net/e1000e/hw.h
34879 --- linux-2.6.32.46/drivers/net/e1000e/hw.h 2011-03-27 14:31:47.000000000 -0400
34880 +++ linux-2.6.32.46/drivers/net/e1000e/hw.h 2011-08-23 21:27:38.000000000 -0400
34881 @@ -753,6 +753,7 @@ struct e1000_mac_operations {
34882 s32 (*setup_physical_interface)(struct e1000_hw *);
34883 s32 (*setup_led)(struct e1000_hw *);
34884 };
34885 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34886
34887 /* Function pointers for the PHY. */
34888 struct e1000_phy_operations {
34889 @@ -774,6 +775,7 @@ struct e1000_phy_operations {
34890 s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
34891 s32 (*cfg_on_link_up)(struct e1000_hw *);
34892 };
34893 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34894
34895 /* Function pointers for the NVM. */
34896 struct e1000_nvm_operations {
34897 @@ -785,9 +787,10 @@ struct e1000_nvm_operations {
34898 s32 (*validate_nvm)(struct e1000_hw *);
34899 s32 (*write_nvm)(struct e1000_hw *, u16, u16, u16 *);
34900 };
34901 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34902
34903 struct e1000_mac_info {
34904 - struct e1000_mac_operations ops;
34905 + e1000_mac_operations_no_const ops;
34906
34907 u8 addr[6];
34908 u8 perm_addr[6];
34909 @@ -823,7 +826,7 @@ struct e1000_mac_info {
34910 };
34911
34912 struct e1000_phy_info {
34913 - struct e1000_phy_operations ops;
34914 + e1000_phy_operations_no_const ops;
34915
34916 enum e1000_phy_type type;
34917
34918 @@ -857,7 +860,7 @@ struct e1000_phy_info {
34919 };
34920
34921 struct e1000_nvm_info {
34922 - struct e1000_nvm_operations ops;
34923 + e1000_nvm_operations_no_const ops;
34924
34925 enum e1000_nvm_type type;
34926 enum e1000_nvm_override override;
34927 diff -urNp linux-2.6.32.46/drivers/net/e1000e/ich8lan.c linux-2.6.32.46/drivers/net/e1000e/ich8lan.c
34928 --- linux-2.6.32.46/drivers/net/e1000e/ich8lan.c 2011-05-10 22:12:01.000000000 -0400
34929 +++ linux-2.6.32.46/drivers/net/e1000e/ich8lan.c 2011-08-23 21:22:32.000000000 -0400
34930 @@ -3463,7 +3463,7 @@ static void e1000_clear_hw_cntrs_ich8lan
34931 }
34932 }
34933
34934 -static struct e1000_mac_operations ich8_mac_ops = {
34935 +static const struct e1000_mac_operations ich8_mac_ops = {
34936 .id_led_init = e1000e_id_led_init,
34937 .check_mng_mode = e1000_check_mng_mode_ich8lan,
34938 .check_for_link = e1000_check_for_copper_link_ich8lan,
34939 @@ -3481,7 +3481,7 @@ static struct e1000_mac_operations ich8_
34940 /* id_led_init dependent on mac type */
34941 };
34942
34943 -static struct e1000_phy_operations ich8_phy_ops = {
34944 +static const struct e1000_phy_operations ich8_phy_ops = {
34945 .acquire_phy = e1000_acquire_swflag_ich8lan,
34946 .check_reset_block = e1000_check_reset_block_ich8lan,
34947 .commit_phy = NULL,
34948 @@ -3497,7 +3497,7 @@ static struct e1000_phy_operations ich8_
34949 .write_phy_reg = e1000e_write_phy_reg_igp,
34950 };
34951
34952 -static struct e1000_nvm_operations ich8_nvm_ops = {
34953 +static const struct e1000_nvm_operations ich8_nvm_ops = {
34954 .acquire_nvm = e1000_acquire_nvm_ich8lan,
34955 .read_nvm = e1000_read_nvm_ich8lan,
34956 .release_nvm = e1000_release_nvm_ich8lan,
34957 diff -urNp linux-2.6.32.46/drivers/net/hamradio/6pack.c linux-2.6.32.46/drivers/net/hamradio/6pack.c
34958 --- linux-2.6.32.46/drivers/net/hamradio/6pack.c 2011-07-13 17:23:04.000000000 -0400
34959 +++ linux-2.6.32.46/drivers/net/hamradio/6pack.c 2011-07-13 17:23:18.000000000 -0400
34960 @@ -461,6 +461,8 @@ static void sixpack_receive_buf(struct t
34961 unsigned char buf[512];
34962 int count1;
34963
34964 + pax_track_stack();
34965 +
34966 if (!count)
34967 return;
34968
34969 diff -urNp linux-2.6.32.46/drivers/net/ibmveth.c linux-2.6.32.46/drivers/net/ibmveth.c
34970 --- linux-2.6.32.46/drivers/net/ibmveth.c 2011-03-27 14:31:47.000000000 -0400
34971 +++ linux-2.6.32.46/drivers/net/ibmveth.c 2011-04-17 15:56:46.000000000 -0400
34972 @@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attr
34973 NULL,
34974 };
34975
34976 -static struct sysfs_ops veth_pool_ops = {
34977 +static const struct sysfs_ops veth_pool_ops = {
34978 .show = veth_pool_show,
34979 .store = veth_pool_store,
34980 };
34981 diff -urNp linux-2.6.32.46/drivers/net/igb/e1000_82575.c linux-2.6.32.46/drivers/net/igb/e1000_82575.c
34982 --- linux-2.6.32.46/drivers/net/igb/e1000_82575.c 2011-08-29 22:24:44.000000000 -0400
34983 +++ linux-2.6.32.46/drivers/net/igb/e1000_82575.c 2011-08-29 22:25:07.000000000 -0400
34984 @@ -1411,7 +1411,7 @@ void igb_vmdq_set_replication_pf(struct
34985 wr32(E1000_VT_CTL, vt_ctl);
34986 }
34987
34988 -static struct e1000_mac_operations e1000_mac_ops_82575 = {
34989 +static const struct e1000_mac_operations e1000_mac_ops_82575 = {
34990 .reset_hw = igb_reset_hw_82575,
34991 .init_hw = igb_init_hw_82575,
34992 .check_for_link = igb_check_for_link_82575,
34993 @@ -1420,13 +1420,13 @@ static struct e1000_mac_operations e1000
34994 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
34995 };
34996
34997 -static struct e1000_phy_operations e1000_phy_ops_82575 = {
34998 +static const struct e1000_phy_operations e1000_phy_ops_82575 = {
34999 .acquire = igb_acquire_phy_82575,
35000 .get_cfg_done = igb_get_cfg_done_82575,
35001 .release = igb_release_phy_82575,
35002 };
35003
35004 -static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
35005 +static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
35006 .acquire = igb_acquire_nvm_82575,
35007 .read = igb_read_nvm_eerd,
35008 .release = igb_release_nvm_82575,
35009 diff -urNp linux-2.6.32.46/drivers/net/igb/e1000_hw.h linux-2.6.32.46/drivers/net/igb/e1000_hw.h
35010 --- linux-2.6.32.46/drivers/net/igb/e1000_hw.h 2011-03-27 14:31:47.000000000 -0400
35011 +++ linux-2.6.32.46/drivers/net/igb/e1000_hw.h 2011-08-23 21:28:01.000000000 -0400
35012 @@ -288,6 +288,7 @@ struct e1000_mac_operations {
35013 s32 (*read_mac_addr)(struct e1000_hw *);
35014 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
35015 };
35016 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35017
35018 struct e1000_phy_operations {
35019 s32 (*acquire)(struct e1000_hw *);
35020 @@ -303,6 +304,7 @@ struct e1000_phy_operations {
35021 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35022 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35023 };
35024 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35025
35026 struct e1000_nvm_operations {
35027 s32 (*acquire)(struct e1000_hw *);
35028 @@ -310,6 +312,7 @@ struct e1000_nvm_operations {
35029 void (*release)(struct e1000_hw *);
35030 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35031 };
35032 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35033
35034 struct e1000_info {
35035 s32 (*get_invariants)(struct e1000_hw *);
35036 @@ -321,7 +324,7 @@ struct e1000_info {
35037 extern const struct e1000_info e1000_82575_info;
35038
35039 struct e1000_mac_info {
35040 - struct e1000_mac_operations ops;
35041 + e1000_mac_operations_no_const ops;
35042
35043 u8 addr[6];
35044 u8 perm_addr[6];
35045 @@ -365,7 +368,7 @@ struct e1000_mac_info {
35046 };
35047
35048 struct e1000_phy_info {
35049 - struct e1000_phy_operations ops;
35050 + e1000_phy_operations_no_const ops;
35051
35052 enum e1000_phy_type type;
35053
35054 @@ -400,7 +403,7 @@ struct e1000_phy_info {
35055 };
35056
35057 struct e1000_nvm_info {
35058 - struct e1000_nvm_operations ops;
35059 + e1000_nvm_operations_no_const ops;
35060
35061 enum e1000_nvm_type type;
35062 enum e1000_nvm_override override;
35063 @@ -446,6 +449,7 @@ struct e1000_mbx_operations {
35064 s32 (*check_for_ack)(struct e1000_hw *, u16);
35065 s32 (*check_for_rst)(struct e1000_hw *, u16);
35066 };
35067 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35068
35069 struct e1000_mbx_stats {
35070 u32 msgs_tx;
35071 @@ -457,7 +461,7 @@ struct e1000_mbx_stats {
35072 };
35073
35074 struct e1000_mbx_info {
35075 - struct e1000_mbx_operations ops;
35076 + e1000_mbx_operations_no_const ops;
35077 struct e1000_mbx_stats stats;
35078 u32 timeout;
35079 u32 usec_delay;
35080 diff -urNp linux-2.6.32.46/drivers/net/igbvf/vf.h linux-2.6.32.46/drivers/net/igbvf/vf.h
35081 --- linux-2.6.32.46/drivers/net/igbvf/vf.h 2011-03-27 14:31:47.000000000 -0400
35082 +++ linux-2.6.32.46/drivers/net/igbvf/vf.h 2011-08-23 21:22:38.000000000 -0400
35083 @@ -187,9 +187,10 @@ struct e1000_mac_operations {
35084 s32 (*read_mac_addr)(struct e1000_hw *);
35085 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35086 };
35087 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35088
35089 struct e1000_mac_info {
35090 - struct e1000_mac_operations ops;
35091 + e1000_mac_operations_no_const ops;
35092 u8 addr[6];
35093 u8 perm_addr[6];
35094
35095 @@ -211,6 +212,7 @@ struct e1000_mbx_operations {
35096 s32 (*check_for_ack)(struct e1000_hw *);
35097 s32 (*check_for_rst)(struct e1000_hw *);
35098 };
35099 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35100
35101 struct e1000_mbx_stats {
35102 u32 msgs_tx;
35103 @@ -222,7 +224,7 @@ struct e1000_mbx_stats {
35104 };
35105
35106 struct e1000_mbx_info {
35107 - struct e1000_mbx_operations ops;
35108 + e1000_mbx_operations_no_const ops;
35109 struct e1000_mbx_stats stats;
35110 u32 timeout;
35111 u32 usec_delay;
35112 diff -urNp linux-2.6.32.46/drivers/net/iseries_veth.c linux-2.6.32.46/drivers/net/iseries_veth.c
35113 --- linux-2.6.32.46/drivers/net/iseries_veth.c 2011-03-27 14:31:47.000000000 -0400
35114 +++ linux-2.6.32.46/drivers/net/iseries_veth.c 2011-04-17 15:56:46.000000000 -0400
35115 @@ -384,7 +384,7 @@ static struct attribute *veth_cnx_defaul
35116 NULL
35117 };
35118
35119 -static struct sysfs_ops veth_cnx_sysfs_ops = {
35120 +static const struct sysfs_ops veth_cnx_sysfs_ops = {
35121 .show = veth_cnx_attribute_show
35122 };
35123
35124 @@ -441,7 +441,7 @@ static struct attribute *veth_port_defau
35125 NULL
35126 };
35127
35128 -static struct sysfs_ops veth_port_sysfs_ops = {
35129 +static const struct sysfs_ops veth_port_sysfs_ops = {
35130 .show = veth_port_attribute_show
35131 };
35132
35133 diff -urNp linux-2.6.32.46/drivers/net/ixgb/ixgb_main.c linux-2.6.32.46/drivers/net/ixgb/ixgb_main.c
35134 --- linux-2.6.32.46/drivers/net/ixgb/ixgb_main.c 2011-03-27 14:31:47.000000000 -0400
35135 +++ linux-2.6.32.46/drivers/net/ixgb/ixgb_main.c 2011-05-16 21:46:57.000000000 -0400
35136 @@ -1052,6 +1052,8 @@ ixgb_set_multi(struct net_device *netdev
35137 u32 rctl;
35138 int i;
35139
35140 + pax_track_stack();
35141 +
35142 /* Check for Promiscuous and All Multicast modes */
35143
35144 rctl = IXGB_READ_REG(hw, RCTL);
35145 diff -urNp linux-2.6.32.46/drivers/net/ixgb/ixgb_param.c linux-2.6.32.46/drivers/net/ixgb/ixgb_param.c
35146 --- linux-2.6.32.46/drivers/net/ixgb/ixgb_param.c 2011-03-27 14:31:47.000000000 -0400
35147 +++ linux-2.6.32.46/drivers/net/ixgb/ixgb_param.c 2011-05-16 21:46:57.000000000 -0400
35148 @@ -260,6 +260,9 @@ void __devinit
35149 ixgb_check_options(struct ixgb_adapter *adapter)
35150 {
35151 int bd = adapter->bd_number;
35152 +
35153 + pax_track_stack();
35154 +
35155 if (bd >= IXGB_MAX_NIC) {
35156 printk(KERN_NOTICE
35157 "Warning: no configuration for board #%i\n", bd);
35158 diff -urNp linux-2.6.32.46/drivers/net/ixgbe/ixgbe_type.h linux-2.6.32.46/drivers/net/ixgbe/ixgbe_type.h
35159 --- linux-2.6.32.46/drivers/net/ixgbe/ixgbe_type.h 2011-03-27 14:31:47.000000000 -0400
35160 +++ linux-2.6.32.46/drivers/net/ixgbe/ixgbe_type.h 2011-08-23 21:22:38.000000000 -0400
35161 @@ -2327,6 +2327,7 @@ struct ixgbe_eeprom_operations {
35162 s32 (*validate_checksum)(struct ixgbe_hw *, u16 *);
35163 s32 (*update_checksum)(struct ixgbe_hw *);
35164 };
35165 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35166
35167 struct ixgbe_mac_operations {
35168 s32 (*init_hw)(struct ixgbe_hw *);
35169 @@ -2376,6 +2377,7 @@ struct ixgbe_mac_operations {
35170 /* Flow Control */
35171 s32 (*fc_enable)(struct ixgbe_hw *, s32);
35172 };
35173 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35174
35175 struct ixgbe_phy_operations {
35176 s32 (*identify)(struct ixgbe_hw *);
35177 @@ -2394,9 +2396,10 @@ struct ixgbe_phy_operations {
35178 s32 (*read_i2c_eeprom)(struct ixgbe_hw *, u8 , u8 *);
35179 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35180 };
35181 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35182
35183 struct ixgbe_eeprom_info {
35184 - struct ixgbe_eeprom_operations ops;
35185 + ixgbe_eeprom_operations_no_const ops;
35186 enum ixgbe_eeprom_type type;
35187 u32 semaphore_delay;
35188 u16 word_size;
35189 @@ -2404,7 +2407,7 @@ struct ixgbe_eeprom_info {
35190 };
35191
35192 struct ixgbe_mac_info {
35193 - struct ixgbe_mac_operations ops;
35194 + ixgbe_mac_operations_no_const ops;
35195 enum ixgbe_mac_type type;
35196 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
35197 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
35198 @@ -2423,7 +2426,7 @@ struct ixgbe_mac_info {
35199 };
35200
35201 struct ixgbe_phy_info {
35202 - struct ixgbe_phy_operations ops;
35203 + ixgbe_phy_operations_no_const ops;
35204 struct mdio_if_info mdio;
35205 enum ixgbe_phy_type type;
35206 u32 id;
35207 diff -urNp linux-2.6.32.46/drivers/net/mlx4/main.c linux-2.6.32.46/drivers/net/mlx4/main.c
35208 --- linux-2.6.32.46/drivers/net/mlx4/main.c 2011-03-27 14:31:47.000000000 -0400
35209 +++ linux-2.6.32.46/drivers/net/mlx4/main.c 2011-05-18 20:09:37.000000000 -0400
35210 @@ -38,6 +38,7 @@
35211 #include <linux/errno.h>
35212 #include <linux/pci.h>
35213 #include <linux/dma-mapping.h>
35214 +#include <linux/sched.h>
35215
35216 #include <linux/mlx4/device.h>
35217 #include <linux/mlx4/doorbell.h>
35218 @@ -730,6 +731,8 @@ static int mlx4_init_hca(struct mlx4_dev
35219 u64 icm_size;
35220 int err;
35221
35222 + pax_track_stack();
35223 +
35224 err = mlx4_QUERY_FW(dev);
35225 if (err) {
35226 if (err == -EACCES)
35227 diff -urNp linux-2.6.32.46/drivers/net/niu.c linux-2.6.32.46/drivers/net/niu.c
35228 --- linux-2.6.32.46/drivers/net/niu.c 2011-05-10 22:12:01.000000000 -0400
35229 +++ linux-2.6.32.46/drivers/net/niu.c 2011-05-16 21:46:57.000000000 -0400
35230 @@ -9128,6 +9128,8 @@ static void __devinit niu_try_msix(struc
35231 int i, num_irqs, err;
35232 u8 first_ldg;
35233
35234 + pax_track_stack();
35235 +
35236 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
35237 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
35238 ldg_num_map[i] = first_ldg + i;
35239 diff -urNp linux-2.6.32.46/drivers/net/pcnet32.c linux-2.6.32.46/drivers/net/pcnet32.c
35240 --- linux-2.6.32.46/drivers/net/pcnet32.c 2011-03-27 14:31:47.000000000 -0400
35241 +++ linux-2.6.32.46/drivers/net/pcnet32.c 2011-08-05 20:33:55.000000000 -0400
35242 @@ -79,7 +79,7 @@ static int cards_found;
35243 /*
35244 * VLB I/O addresses
35245 */
35246 -static unsigned int pcnet32_portlist[] __initdata =
35247 +static unsigned int pcnet32_portlist[] __devinitdata =
35248 { 0x300, 0x320, 0x340, 0x360, 0 };
35249
35250 static int pcnet32_debug = 0;
35251 @@ -267,7 +267,7 @@ struct pcnet32_private {
35252 struct sk_buff **rx_skbuff;
35253 dma_addr_t *tx_dma_addr;
35254 dma_addr_t *rx_dma_addr;
35255 - struct pcnet32_access a;
35256 + struct pcnet32_access *a;
35257 spinlock_t lock; /* Guard lock */
35258 unsigned int cur_rx, cur_tx; /* The next free ring entry */
35259 unsigned int rx_ring_size; /* current rx ring size */
35260 @@ -457,9 +457,9 @@ static void pcnet32_netif_start(struct n
35261 u16 val;
35262
35263 netif_wake_queue(dev);
35264 - val = lp->a.read_csr(ioaddr, CSR3);
35265 + val = lp->a->read_csr(ioaddr, CSR3);
35266 val &= 0x00ff;
35267 - lp->a.write_csr(ioaddr, CSR3, val);
35268 + lp->a->write_csr(ioaddr, CSR3, val);
35269 napi_enable(&lp->napi);
35270 }
35271
35272 @@ -744,7 +744,7 @@ static u32 pcnet32_get_link(struct net_d
35273 r = mii_link_ok(&lp->mii_if);
35274 } else if (lp->chip_version >= PCNET32_79C970A) {
35275 ulong ioaddr = dev->base_addr; /* card base I/O address */
35276 - r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
35277 + r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
35278 } else { /* can not detect link on really old chips */
35279 r = 1;
35280 }
35281 @@ -806,7 +806,7 @@ static int pcnet32_set_ringparam(struct
35282 pcnet32_netif_stop(dev);
35283
35284 spin_lock_irqsave(&lp->lock, flags);
35285 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
35286 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
35287
35288 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
35289
35290 @@ -886,7 +886,7 @@ static void pcnet32_ethtool_test(struct
35291 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
35292 {
35293 struct pcnet32_private *lp = netdev_priv(dev);
35294 - struct pcnet32_access *a = &lp->a; /* access to registers */
35295 + struct pcnet32_access *a = lp->a; /* access to registers */
35296 ulong ioaddr = dev->base_addr; /* card base I/O address */
35297 struct sk_buff *skb; /* sk buff */
35298 int x, i; /* counters */
35299 @@ -906,21 +906,21 @@ static int pcnet32_loopback_test(struct
35300 pcnet32_netif_stop(dev);
35301
35302 spin_lock_irqsave(&lp->lock, flags);
35303 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
35304 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
35305
35306 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
35307
35308 /* Reset the PCNET32 */
35309 - lp->a.reset(ioaddr);
35310 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
35311 + lp->a->reset(ioaddr);
35312 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
35313
35314 /* switch pcnet32 to 32bit mode */
35315 - lp->a.write_bcr(ioaddr, 20, 2);
35316 + lp->a->write_bcr(ioaddr, 20, 2);
35317
35318 /* purge & init rings but don't actually restart */
35319 pcnet32_restart(dev, 0x0000);
35320
35321 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
35322 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
35323
35324 /* Initialize Transmit buffers. */
35325 size = data_len + 15;
35326 @@ -966,10 +966,10 @@ static int pcnet32_loopback_test(struct
35327
35328 /* set int loopback in CSR15 */
35329 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
35330 - lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
35331 + lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
35332
35333 teststatus = cpu_to_le16(0x8000);
35334 - lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
35335 + lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
35336
35337 /* Check status of descriptors */
35338 for (x = 0; x < numbuffs; x++) {
35339 @@ -990,7 +990,7 @@ static int pcnet32_loopback_test(struct
35340 }
35341 }
35342
35343 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
35344 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
35345 wmb();
35346 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
35347 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
35348 @@ -1039,7 +1039,7 @@ static int pcnet32_loopback_test(struct
35349 pcnet32_restart(dev, CSR0_NORMAL);
35350 } else {
35351 pcnet32_purge_rx_ring(dev);
35352 - lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
35353 + lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
35354 }
35355 spin_unlock_irqrestore(&lp->lock, flags);
35356
35357 @@ -1049,7 +1049,7 @@ static int pcnet32_loopback_test(struct
35358 static void pcnet32_led_blink_callback(struct net_device *dev)
35359 {
35360 struct pcnet32_private *lp = netdev_priv(dev);
35361 - struct pcnet32_access *a = &lp->a;
35362 + struct pcnet32_access *a = lp->a;
35363 ulong ioaddr = dev->base_addr;
35364 unsigned long flags;
35365 int i;
35366 @@ -1066,7 +1066,7 @@ static void pcnet32_led_blink_callback(s
35367 static int pcnet32_phys_id(struct net_device *dev, u32 data)
35368 {
35369 struct pcnet32_private *lp = netdev_priv(dev);
35370 - struct pcnet32_access *a = &lp->a;
35371 + struct pcnet32_access *a = lp->a;
35372 ulong ioaddr = dev->base_addr;
35373 unsigned long flags;
35374 int i, regs[4];
35375 @@ -1112,7 +1112,7 @@ static int pcnet32_suspend(struct net_de
35376 {
35377 int csr5;
35378 struct pcnet32_private *lp = netdev_priv(dev);
35379 - struct pcnet32_access *a = &lp->a;
35380 + struct pcnet32_access *a = lp->a;
35381 ulong ioaddr = dev->base_addr;
35382 int ticks;
35383
35384 @@ -1388,8 +1388,8 @@ static int pcnet32_poll(struct napi_stru
35385 spin_lock_irqsave(&lp->lock, flags);
35386 if (pcnet32_tx(dev)) {
35387 /* reset the chip to clear the error condition, then restart */
35388 - lp->a.reset(ioaddr);
35389 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
35390 + lp->a->reset(ioaddr);
35391 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
35392 pcnet32_restart(dev, CSR0_START);
35393 netif_wake_queue(dev);
35394 }
35395 @@ -1401,12 +1401,12 @@ static int pcnet32_poll(struct napi_stru
35396 __napi_complete(napi);
35397
35398 /* clear interrupt masks */
35399 - val = lp->a.read_csr(ioaddr, CSR3);
35400 + val = lp->a->read_csr(ioaddr, CSR3);
35401 val &= 0x00ff;
35402 - lp->a.write_csr(ioaddr, CSR3, val);
35403 + lp->a->write_csr(ioaddr, CSR3, val);
35404
35405 /* Set interrupt enable. */
35406 - lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
35407 + lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
35408
35409 spin_unlock_irqrestore(&lp->lock, flags);
35410 }
35411 @@ -1429,7 +1429,7 @@ static void pcnet32_get_regs(struct net_
35412 int i, csr0;
35413 u16 *buff = ptr;
35414 struct pcnet32_private *lp = netdev_priv(dev);
35415 - struct pcnet32_access *a = &lp->a;
35416 + struct pcnet32_access *a = lp->a;
35417 ulong ioaddr = dev->base_addr;
35418 unsigned long flags;
35419
35420 @@ -1466,9 +1466,9 @@ static void pcnet32_get_regs(struct net_
35421 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
35422 if (lp->phymask & (1 << j)) {
35423 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
35424 - lp->a.write_bcr(ioaddr, 33,
35425 + lp->a->write_bcr(ioaddr, 33,
35426 (j << 5) | i);
35427 - *buff++ = lp->a.read_bcr(ioaddr, 34);
35428 + *buff++ = lp->a->read_bcr(ioaddr, 34);
35429 }
35430 }
35431 }
35432 @@ -1858,7 +1858,7 @@ pcnet32_probe1(unsigned long ioaddr, int
35433 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
35434 lp->options |= PCNET32_PORT_FD;
35435
35436 - lp->a = *a;
35437 + lp->a = a;
35438
35439 /* prior to register_netdev, dev->name is not yet correct */
35440 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
35441 @@ -1917,7 +1917,7 @@ pcnet32_probe1(unsigned long ioaddr, int
35442 if (lp->mii) {
35443 /* lp->phycount and lp->phymask are set to 0 by memset above */
35444
35445 - lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
35446 + lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
35447 /* scan for PHYs */
35448 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
35449 unsigned short id1, id2;
35450 @@ -1938,7 +1938,7 @@ pcnet32_probe1(unsigned long ioaddr, int
35451 "Found PHY %04x:%04x at address %d.\n",
35452 id1, id2, i);
35453 }
35454 - lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
35455 + lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
35456 if (lp->phycount > 1) {
35457 lp->options |= PCNET32_PORT_MII;
35458 }
35459 @@ -2109,10 +2109,10 @@ static int pcnet32_open(struct net_devic
35460 }
35461
35462 /* Reset the PCNET32 */
35463 - lp->a.reset(ioaddr);
35464 + lp->a->reset(ioaddr);
35465
35466 /* switch pcnet32 to 32bit mode */
35467 - lp->a.write_bcr(ioaddr, 20, 2);
35468 + lp->a->write_bcr(ioaddr, 20, 2);
35469
35470 if (netif_msg_ifup(lp))
35471 printk(KERN_DEBUG
35472 @@ -2122,14 +2122,14 @@ static int pcnet32_open(struct net_devic
35473 (u32) (lp->init_dma_addr));
35474
35475 /* set/reset autoselect bit */
35476 - val = lp->a.read_bcr(ioaddr, 2) & ~2;
35477 + val = lp->a->read_bcr(ioaddr, 2) & ~2;
35478 if (lp->options & PCNET32_PORT_ASEL)
35479 val |= 2;
35480 - lp->a.write_bcr(ioaddr, 2, val);
35481 + lp->a->write_bcr(ioaddr, 2, val);
35482
35483 /* handle full duplex setting */
35484 if (lp->mii_if.full_duplex) {
35485 - val = lp->a.read_bcr(ioaddr, 9) & ~3;
35486 + val = lp->a->read_bcr(ioaddr, 9) & ~3;
35487 if (lp->options & PCNET32_PORT_FD) {
35488 val |= 1;
35489 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
35490 @@ -2139,14 +2139,14 @@ static int pcnet32_open(struct net_devic
35491 if (lp->chip_version == 0x2627)
35492 val |= 3;
35493 }
35494 - lp->a.write_bcr(ioaddr, 9, val);
35495 + lp->a->write_bcr(ioaddr, 9, val);
35496 }
35497
35498 /* set/reset GPSI bit in test register */
35499 - val = lp->a.read_csr(ioaddr, 124) & ~0x10;
35500 + val = lp->a->read_csr(ioaddr, 124) & ~0x10;
35501 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
35502 val |= 0x10;
35503 - lp->a.write_csr(ioaddr, 124, val);
35504 + lp->a->write_csr(ioaddr, 124, val);
35505
35506 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
35507 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
35508 @@ -2167,24 +2167,24 @@ static int pcnet32_open(struct net_devic
35509 * duplex, and/or enable auto negotiation, and clear DANAS
35510 */
35511 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
35512 - lp->a.write_bcr(ioaddr, 32,
35513 - lp->a.read_bcr(ioaddr, 32) | 0x0080);
35514 + lp->a->write_bcr(ioaddr, 32,
35515 + lp->a->read_bcr(ioaddr, 32) | 0x0080);
35516 /* disable Auto Negotiation, set 10Mpbs, HD */
35517 - val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
35518 + val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
35519 if (lp->options & PCNET32_PORT_FD)
35520 val |= 0x10;
35521 if (lp->options & PCNET32_PORT_100)
35522 val |= 0x08;
35523 - lp->a.write_bcr(ioaddr, 32, val);
35524 + lp->a->write_bcr(ioaddr, 32, val);
35525 } else {
35526 if (lp->options & PCNET32_PORT_ASEL) {
35527 - lp->a.write_bcr(ioaddr, 32,
35528 - lp->a.read_bcr(ioaddr,
35529 + lp->a->write_bcr(ioaddr, 32,
35530 + lp->a->read_bcr(ioaddr,
35531 32) | 0x0080);
35532 /* enable auto negotiate, setup, disable fd */
35533 - val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
35534 + val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
35535 val |= 0x20;
35536 - lp->a.write_bcr(ioaddr, 32, val);
35537 + lp->a->write_bcr(ioaddr, 32, val);
35538 }
35539 }
35540 } else {
35541 @@ -2197,10 +2197,10 @@ static int pcnet32_open(struct net_devic
35542 * There is really no good other way to handle multiple PHYs
35543 * other than turning off all automatics
35544 */
35545 - val = lp->a.read_bcr(ioaddr, 2);
35546 - lp->a.write_bcr(ioaddr, 2, val & ~2);
35547 - val = lp->a.read_bcr(ioaddr, 32);
35548 - lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
35549 + val = lp->a->read_bcr(ioaddr, 2);
35550 + lp->a->write_bcr(ioaddr, 2, val & ~2);
35551 + val = lp->a->read_bcr(ioaddr, 32);
35552 + lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
35553
35554 if (!(lp->options & PCNET32_PORT_ASEL)) {
35555 /* setup ecmd */
35556 @@ -2210,7 +2210,7 @@ static int pcnet32_open(struct net_devic
35557 ecmd.speed =
35558 lp->
35559 options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
35560 - bcr9 = lp->a.read_bcr(ioaddr, 9);
35561 + bcr9 = lp->a->read_bcr(ioaddr, 9);
35562
35563 if (lp->options & PCNET32_PORT_FD) {
35564 ecmd.duplex = DUPLEX_FULL;
35565 @@ -2219,7 +2219,7 @@ static int pcnet32_open(struct net_devic
35566 ecmd.duplex = DUPLEX_HALF;
35567 bcr9 |= ~(1 << 0);
35568 }
35569 - lp->a.write_bcr(ioaddr, 9, bcr9);
35570 + lp->a->write_bcr(ioaddr, 9, bcr9);
35571 }
35572
35573 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
35574 @@ -2252,9 +2252,9 @@ static int pcnet32_open(struct net_devic
35575
35576 #ifdef DO_DXSUFLO
35577 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
35578 - val = lp->a.read_csr(ioaddr, CSR3);
35579 + val = lp->a->read_csr(ioaddr, CSR3);
35580 val |= 0x40;
35581 - lp->a.write_csr(ioaddr, CSR3, val);
35582 + lp->a->write_csr(ioaddr, CSR3, val);
35583 }
35584 #endif
35585
35586 @@ -2270,11 +2270,11 @@ static int pcnet32_open(struct net_devic
35587 napi_enable(&lp->napi);
35588
35589 /* Re-initialize the PCNET32, and start it when done. */
35590 - lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
35591 - lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
35592 + lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
35593 + lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
35594
35595 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
35596 - lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
35597 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
35598 + lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
35599
35600 netif_start_queue(dev);
35601
35602 @@ -2286,20 +2286,20 @@ static int pcnet32_open(struct net_devic
35603
35604 i = 0;
35605 while (i++ < 100)
35606 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
35607 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
35608 break;
35609 /*
35610 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
35611 * reports that doing so triggers a bug in the '974.
35612 */
35613 - lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
35614 + lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
35615
35616 if (netif_msg_ifup(lp))
35617 printk(KERN_DEBUG
35618 "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
35619 dev->name, i,
35620 (u32) (lp->init_dma_addr),
35621 - lp->a.read_csr(ioaddr, CSR0));
35622 + lp->a->read_csr(ioaddr, CSR0));
35623
35624 spin_unlock_irqrestore(&lp->lock, flags);
35625
35626 @@ -2313,7 +2313,7 @@ static int pcnet32_open(struct net_devic
35627 * Switch back to 16bit mode to avoid problems with dumb
35628 * DOS packet driver after a warm reboot
35629 */
35630 - lp->a.write_bcr(ioaddr, 20, 4);
35631 + lp->a->write_bcr(ioaddr, 20, 4);
35632
35633 err_free_irq:
35634 spin_unlock_irqrestore(&lp->lock, flags);
35635 @@ -2420,7 +2420,7 @@ static void pcnet32_restart(struct net_d
35636
35637 /* wait for stop */
35638 for (i = 0; i < 100; i++)
35639 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
35640 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
35641 break;
35642
35643 if (i >= 100 && netif_msg_drv(lp))
35644 @@ -2433,13 +2433,13 @@ static void pcnet32_restart(struct net_d
35645 return;
35646
35647 /* ReInit Ring */
35648 - lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
35649 + lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
35650 i = 0;
35651 while (i++ < 1000)
35652 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
35653 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
35654 break;
35655
35656 - lp->a.write_csr(ioaddr, CSR0, csr0_bits);
35657 + lp->a->write_csr(ioaddr, CSR0, csr0_bits);
35658 }
35659
35660 static void pcnet32_tx_timeout(struct net_device *dev)
35661 @@ -2452,8 +2452,8 @@ static void pcnet32_tx_timeout(struct ne
35662 if (pcnet32_debug & NETIF_MSG_DRV)
35663 printk(KERN_ERR
35664 "%s: transmit timed out, status %4.4x, resetting.\n",
35665 - dev->name, lp->a.read_csr(ioaddr, CSR0));
35666 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
35667 + dev->name, lp->a->read_csr(ioaddr, CSR0));
35668 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
35669 dev->stats.tx_errors++;
35670 if (netif_msg_tx_err(lp)) {
35671 int i;
35672 @@ -2497,7 +2497,7 @@ static netdev_tx_t pcnet32_start_xmit(st
35673 if (netif_msg_tx_queued(lp)) {
35674 printk(KERN_DEBUG
35675 "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
35676 - dev->name, lp->a.read_csr(ioaddr, CSR0));
35677 + dev->name, lp->a->read_csr(ioaddr, CSR0));
35678 }
35679
35680 /* Default status -- will not enable Successful-TxDone
35681 @@ -2528,7 +2528,7 @@ static netdev_tx_t pcnet32_start_xmit(st
35682 dev->stats.tx_bytes += skb->len;
35683
35684 /* Trigger an immediate send poll. */
35685 - lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
35686 + lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
35687
35688 dev->trans_start = jiffies;
35689
35690 @@ -2555,18 +2555,18 @@ pcnet32_interrupt(int irq, void *dev_id)
35691
35692 spin_lock(&lp->lock);
35693
35694 - csr0 = lp->a.read_csr(ioaddr, CSR0);
35695 + csr0 = lp->a->read_csr(ioaddr, CSR0);
35696 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
35697 if (csr0 == 0xffff) {
35698 break; /* PCMCIA remove happened */
35699 }
35700 /* Acknowledge all of the current interrupt sources ASAP. */
35701 - lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
35702 + lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
35703
35704 if (netif_msg_intr(lp))
35705 printk(KERN_DEBUG
35706 "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
35707 - dev->name, csr0, lp->a.read_csr(ioaddr, CSR0));
35708 + dev->name, csr0, lp->a->read_csr(ioaddr, CSR0));
35709
35710 /* Log misc errors. */
35711 if (csr0 & 0x4000)
35712 @@ -2595,19 +2595,19 @@ pcnet32_interrupt(int irq, void *dev_id)
35713 if (napi_schedule_prep(&lp->napi)) {
35714 u16 val;
35715 /* set interrupt masks */
35716 - val = lp->a.read_csr(ioaddr, CSR3);
35717 + val = lp->a->read_csr(ioaddr, CSR3);
35718 val |= 0x5f00;
35719 - lp->a.write_csr(ioaddr, CSR3, val);
35720 + lp->a->write_csr(ioaddr, CSR3, val);
35721
35722 __napi_schedule(&lp->napi);
35723 break;
35724 }
35725 - csr0 = lp->a.read_csr(ioaddr, CSR0);
35726 + csr0 = lp->a->read_csr(ioaddr, CSR0);
35727 }
35728
35729 if (netif_msg_intr(lp))
35730 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
35731 - dev->name, lp->a.read_csr(ioaddr, CSR0));
35732 + dev->name, lp->a->read_csr(ioaddr, CSR0));
35733
35734 spin_unlock(&lp->lock);
35735
35736 @@ -2627,21 +2627,21 @@ static int pcnet32_close(struct net_devi
35737
35738 spin_lock_irqsave(&lp->lock, flags);
35739
35740 - dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
35741 + dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
35742
35743 if (netif_msg_ifdown(lp))
35744 printk(KERN_DEBUG
35745 "%s: Shutting down ethercard, status was %2.2x.\n",
35746 - dev->name, lp->a.read_csr(ioaddr, CSR0));
35747 + dev->name, lp->a->read_csr(ioaddr, CSR0));
35748
35749 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
35750 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
35751 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
35752
35753 /*
35754 * Switch back to 16bit mode to avoid problems with dumb
35755 * DOS packet driver after a warm reboot
35756 */
35757 - lp->a.write_bcr(ioaddr, 20, 4);
35758 + lp->a->write_bcr(ioaddr, 20, 4);
35759
35760 spin_unlock_irqrestore(&lp->lock, flags);
35761
35762 @@ -2664,7 +2664,7 @@ static struct net_device_stats *pcnet32_
35763 unsigned long flags;
35764
35765 spin_lock_irqsave(&lp->lock, flags);
35766 - dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
35767 + dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
35768 spin_unlock_irqrestore(&lp->lock, flags);
35769
35770 return &dev->stats;
35771 @@ -2686,10 +2686,10 @@ static void pcnet32_load_multicast(struc
35772 if (dev->flags & IFF_ALLMULTI) {
35773 ib->filter[0] = cpu_to_le32(~0U);
35774 ib->filter[1] = cpu_to_le32(~0U);
35775 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
35776 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
35777 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
35778 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
35779 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
35780 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
35781 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
35782 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
35783 return;
35784 }
35785 /* clear the multicast filter */
35786 @@ -2710,7 +2710,7 @@ static void pcnet32_load_multicast(struc
35787 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
35788 }
35789 for (i = 0; i < 4; i++)
35790 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
35791 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
35792 le16_to_cpu(mcast_table[i]));
35793 return;
35794 }
35795 @@ -2726,7 +2726,7 @@ static void pcnet32_set_multicast_list(s
35796
35797 spin_lock_irqsave(&lp->lock, flags);
35798 suspended = pcnet32_suspend(dev, &flags, 0);
35799 - csr15 = lp->a.read_csr(ioaddr, CSR15);
35800 + csr15 = lp->a->read_csr(ioaddr, CSR15);
35801 if (dev->flags & IFF_PROMISC) {
35802 /* Log any net taps. */
35803 if (netif_msg_hw(lp))
35804 @@ -2735,21 +2735,21 @@ static void pcnet32_set_multicast_list(s
35805 lp->init_block->mode =
35806 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
35807 7);
35808 - lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
35809 + lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
35810 } else {
35811 lp->init_block->mode =
35812 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
35813 - lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
35814 + lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
35815 pcnet32_load_multicast(dev);
35816 }
35817
35818 if (suspended) {
35819 int csr5;
35820 /* clear SUSPEND (SPND) - CSR5 bit 0 */
35821 - csr5 = lp->a.read_csr(ioaddr, CSR5);
35822 - lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
35823 + csr5 = lp->a->read_csr(ioaddr, CSR5);
35824 + lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
35825 } else {
35826 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
35827 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
35828 pcnet32_restart(dev, CSR0_NORMAL);
35829 netif_wake_queue(dev);
35830 }
35831 @@ -2767,8 +2767,8 @@ static int mdio_read(struct net_device *
35832 if (!lp->mii)
35833 return 0;
35834
35835 - lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
35836 - val_out = lp->a.read_bcr(ioaddr, 34);
35837 + lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
35838 + val_out = lp->a->read_bcr(ioaddr, 34);
35839
35840 return val_out;
35841 }
35842 @@ -2782,8 +2782,8 @@ static void mdio_write(struct net_device
35843 if (!lp->mii)
35844 return;
35845
35846 - lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
35847 - lp->a.write_bcr(ioaddr, 34, val);
35848 + lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
35849 + lp->a->write_bcr(ioaddr, 34, val);
35850 }
35851
35852 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35853 @@ -2862,7 +2862,7 @@ static void pcnet32_check_media(struct n
35854 curr_link = mii_link_ok(&lp->mii_if);
35855 } else {
35856 ulong ioaddr = dev->base_addr; /* card base I/O address */
35857 - curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
35858 + curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
35859 }
35860 if (!curr_link) {
35861 if (prev_link || verbose) {
35862 @@ -2887,13 +2887,13 @@ static void pcnet32_check_media(struct n
35863 (ecmd.duplex ==
35864 DUPLEX_FULL) ? "full" : "half");
35865 }
35866 - bcr9 = lp->a.read_bcr(dev->base_addr, 9);
35867 + bcr9 = lp->a->read_bcr(dev->base_addr, 9);
35868 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
35869 if (lp->mii_if.full_duplex)
35870 bcr9 |= (1 << 0);
35871 else
35872 bcr9 &= ~(1 << 0);
35873 - lp->a.write_bcr(dev->base_addr, 9, bcr9);
35874 + lp->a->write_bcr(dev->base_addr, 9, bcr9);
35875 }
35876 } else {
35877 if (netif_msg_link(lp))
35878 diff -urNp linux-2.6.32.46/drivers/net/tg3.h linux-2.6.32.46/drivers/net/tg3.h
35879 --- linux-2.6.32.46/drivers/net/tg3.h 2011-03-27 14:31:47.000000000 -0400
35880 +++ linux-2.6.32.46/drivers/net/tg3.h 2011-04-17 15:56:46.000000000 -0400
35881 @@ -95,6 +95,7 @@
35882 #define CHIPREV_ID_5750_A0 0x4000
35883 #define CHIPREV_ID_5750_A1 0x4001
35884 #define CHIPREV_ID_5750_A3 0x4003
35885 +#define CHIPREV_ID_5750_C1 0x4201
35886 #define CHIPREV_ID_5750_C2 0x4202
35887 #define CHIPREV_ID_5752_A0_HW 0x5000
35888 #define CHIPREV_ID_5752_A0 0x6000
35889 diff -urNp linux-2.6.32.46/drivers/net/tokenring/abyss.c linux-2.6.32.46/drivers/net/tokenring/abyss.c
35890 --- linux-2.6.32.46/drivers/net/tokenring/abyss.c 2011-03-27 14:31:47.000000000 -0400
35891 +++ linux-2.6.32.46/drivers/net/tokenring/abyss.c 2011-08-05 20:33:55.000000000 -0400
35892 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver =
35893
35894 static int __init abyss_init (void)
35895 {
35896 - abyss_netdev_ops = tms380tr_netdev_ops;
35897 + pax_open_kernel();
35898 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35899
35900 - abyss_netdev_ops.ndo_open = abyss_open;
35901 - abyss_netdev_ops.ndo_stop = abyss_close;
35902 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35903 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35904 + pax_close_kernel();
35905
35906 return pci_register_driver(&abyss_driver);
35907 }
35908 diff -urNp linux-2.6.32.46/drivers/net/tokenring/madgemc.c linux-2.6.32.46/drivers/net/tokenring/madgemc.c
35909 --- linux-2.6.32.46/drivers/net/tokenring/madgemc.c 2011-03-27 14:31:47.000000000 -0400
35910 +++ linux-2.6.32.46/drivers/net/tokenring/madgemc.c 2011-08-05 20:33:55.000000000 -0400
35911 @@ -755,9 +755,11 @@ static struct mca_driver madgemc_driver
35912
35913 static int __init madgemc_init (void)
35914 {
35915 - madgemc_netdev_ops = tms380tr_netdev_ops;
35916 - madgemc_netdev_ops.ndo_open = madgemc_open;
35917 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35918 + pax_open_kernel();
35919 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35920 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35921 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35922 + pax_close_kernel();
35923
35924 return mca_register_driver (&madgemc_driver);
35925 }
35926 diff -urNp linux-2.6.32.46/drivers/net/tokenring/proteon.c linux-2.6.32.46/drivers/net/tokenring/proteon.c
35927 --- linux-2.6.32.46/drivers/net/tokenring/proteon.c 2011-03-27 14:31:47.000000000 -0400
35928 +++ linux-2.6.32.46/drivers/net/tokenring/proteon.c 2011-08-05 20:33:55.000000000 -0400
35929 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
35930 struct platform_device *pdev;
35931 int i, num = 0, err = 0;
35932
35933 - proteon_netdev_ops = tms380tr_netdev_ops;
35934 - proteon_netdev_ops.ndo_open = proteon_open;
35935 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35936 + pax_open_kernel();
35937 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35938 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35939 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35940 + pax_close_kernel();
35941
35942 err = platform_driver_register(&proteon_driver);
35943 if (err)
35944 diff -urNp linux-2.6.32.46/drivers/net/tokenring/skisa.c linux-2.6.32.46/drivers/net/tokenring/skisa.c
35945 --- linux-2.6.32.46/drivers/net/tokenring/skisa.c 2011-03-27 14:31:47.000000000 -0400
35946 +++ linux-2.6.32.46/drivers/net/tokenring/skisa.c 2011-08-05 20:33:55.000000000 -0400
35947 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35948 struct platform_device *pdev;
35949 int i, num = 0, err = 0;
35950
35951 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35952 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35953 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35954 + pax_open_kernel();
35955 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35956 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35957 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35958 + pax_close_kernel();
35959
35960 err = platform_driver_register(&sk_isa_driver);
35961 if (err)
35962 diff -urNp linux-2.6.32.46/drivers/net/tulip/de2104x.c linux-2.6.32.46/drivers/net/tulip/de2104x.c
35963 --- linux-2.6.32.46/drivers/net/tulip/de2104x.c 2011-03-27 14:31:47.000000000 -0400
35964 +++ linux-2.6.32.46/drivers/net/tulip/de2104x.c 2011-05-16 21:46:57.000000000 -0400
35965 @@ -1785,6 +1785,8 @@ static void __devinit de21041_get_srom_i
35966 struct de_srom_info_leaf *il;
35967 void *bufp;
35968
35969 + pax_track_stack();
35970 +
35971 /* download entire eeprom */
35972 for (i = 0; i < DE_EEPROM_WORDS; i++)
35973 ((__le16 *)ee_data)[i] =
35974 diff -urNp linux-2.6.32.46/drivers/net/tulip/de4x5.c linux-2.6.32.46/drivers/net/tulip/de4x5.c
35975 --- linux-2.6.32.46/drivers/net/tulip/de4x5.c 2011-03-27 14:31:47.000000000 -0400
35976 +++ linux-2.6.32.46/drivers/net/tulip/de4x5.c 2011-04-17 15:56:46.000000000 -0400
35977 @@ -5472,7 +5472,7 @@ de4x5_ioctl(struct net_device *dev, stru
35978 for (i=0; i<ETH_ALEN; i++) {
35979 tmp.addr[i] = dev->dev_addr[i];
35980 }
35981 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35982 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35983 break;
35984
35985 case DE4X5_SET_HWADDR: /* Set the hardware address */
35986 @@ -5512,7 +5512,7 @@ de4x5_ioctl(struct net_device *dev, stru
35987 spin_lock_irqsave(&lp->lock, flags);
35988 memcpy(&statbuf, &lp->pktStats, ioc->len);
35989 spin_unlock_irqrestore(&lp->lock, flags);
35990 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
35991 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35992 return -EFAULT;
35993 break;
35994 }
35995 diff -urNp linux-2.6.32.46/drivers/net/usb/hso.c linux-2.6.32.46/drivers/net/usb/hso.c
35996 --- linux-2.6.32.46/drivers/net/usb/hso.c 2011-03-27 14:31:47.000000000 -0400
35997 +++ linux-2.6.32.46/drivers/net/usb/hso.c 2011-04-17 15:56:46.000000000 -0400
35998 @@ -71,7 +71,7 @@
35999 #include <asm/byteorder.h>
36000 #include <linux/serial_core.h>
36001 #include <linux/serial.h>
36002 -
36003 +#include <asm/local.h>
36004
36005 #define DRIVER_VERSION "1.2"
36006 #define MOD_AUTHOR "Option Wireless"
36007 @@ -258,7 +258,7 @@ struct hso_serial {
36008
36009 /* from usb_serial_port */
36010 struct tty_struct *tty;
36011 - int open_count;
36012 + local_t open_count;
36013 spinlock_t serial_lock;
36014
36015 int (*write_data) (struct hso_serial *serial);
36016 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_
36017 struct urb *urb;
36018
36019 urb = serial->rx_urb[0];
36020 - if (serial->open_count > 0) {
36021 + if (local_read(&serial->open_count) > 0) {
36022 count = put_rxbuf_data(urb, serial);
36023 if (count == -1)
36024 return;
36025 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_cal
36026 DUMP1(urb->transfer_buffer, urb->actual_length);
36027
36028 /* Anyone listening? */
36029 - if (serial->open_count == 0)
36030 + if (local_read(&serial->open_count) == 0)
36031 return;
36032
36033 if (status == 0) {
36034 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
36035 spin_unlock_irq(&serial->serial_lock);
36036
36037 /* check for port already opened, if not set the termios */
36038 - serial->open_count++;
36039 - if (serial->open_count == 1) {
36040 + if (local_inc_return(&serial->open_count) == 1) {
36041 tty->low_latency = 1;
36042 serial->rx_state = RX_IDLE;
36043 /* Force default termio settings */
36044 @@ -1325,7 +1324,7 @@ static int hso_serial_open(struct tty_st
36045 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
36046 if (result) {
36047 hso_stop_serial_device(serial->parent);
36048 - serial->open_count--;
36049 + local_dec(&serial->open_count);
36050 kref_put(&serial->parent->ref, hso_serial_ref_free);
36051 }
36052 } else {
36053 @@ -1362,10 +1361,10 @@ static void hso_serial_close(struct tty_
36054
36055 /* reset the rts and dtr */
36056 /* do the actual close */
36057 - serial->open_count--;
36058 + local_dec(&serial->open_count);
36059
36060 - if (serial->open_count <= 0) {
36061 - serial->open_count = 0;
36062 + if (local_read(&serial->open_count) <= 0) {
36063 + local_set(&serial->open_count, 0);
36064 spin_lock_irq(&serial->serial_lock);
36065 if (serial->tty == tty) {
36066 serial->tty->driver_data = NULL;
36067 @@ -1447,7 +1446,7 @@ static void hso_serial_set_termios(struc
36068
36069 /* the actual setup */
36070 spin_lock_irqsave(&serial->serial_lock, flags);
36071 - if (serial->open_count)
36072 + if (local_read(&serial->open_count))
36073 _hso_serial_set_termios(tty, old);
36074 else
36075 tty->termios = old;
36076 @@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interfa
36077 /* Start all serial ports */
36078 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
36079 if (serial_table[i] && (serial_table[i]->interface == iface)) {
36080 - if (dev2ser(serial_table[i])->open_count) {
36081 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
36082 result =
36083 hso_start_serial_device(serial_table[i], GFP_NOIO);
36084 hso_kick_transmit(dev2ser(serial_table[i]));
36085 diff -urNp linux-2.6.32.46/drivers/net/vxge/vxge-config.h linux-2.6.32.46/drivers/net/vxge/vxge-config.h
36086 --- linux-2.6.32.46/drivers/net/vxge/vxge-config.h 2011-03-27 14:31:47.000000000 -0400
36087 +++ linux-2.6.32.46/drivers/net/vxge/vxge-config.h 2011-08-05 20:33:55.000000000 -0400
36088 @@ -474,7 +474,7 @@ struct vxge_hw_uld_cbs {
36089 void (*link_down)(struct __vxge_hw_device *devh);
36090 void (*crit_err)(struct __vxge_hw_device *devh,
36091 enum vxge_hw_event type, u64 ext_data);
36092 -};
36093 +} __no_const;
36094
36095 /*
36096 * struct __vxge_hw_blockpool_entry - Block private data structure
36097 diff -urNp linux-2.6.32.46/drivers/net/vxge/vxge-main.c linux-2.6.32.46/drivers/net/vxge/vxge-main.c
36098 --- linux-2.6.32.46/drivers/net/vxge/vxge-main.c 2011-03-27 14:31:47.000000000 -0400
36099 +++ linux-2.6.32.46/drivers/net/vxge/vxge-main.c 2011-05-16 21:46:57.000000000 -0400
36100 @@ -93,6 +93,8 @@ static inline void VXGE_COMPLETE_VPATH_T
36101 struct sk_buff *completed[NR_SKB_COMPLETED];
36102 int more;
36103
36104 + pax_track_stack();
36105 +
36106 do {
36107 more = 0;
36108 skb_ptr = completed;
36109 @@ -1779,6 +1781,8 @@ static enum vxge_hw_status vxge_rth_conf
36110 u8 mtable[256] = {0}; /* CPU to vpath mapping */
36111 int index;
36112
36113 + pax_track_stack();
36114 +
36115 /*
36116 * Filling
36117 * - itable with bucket numbers
36118 diff -urNp linux-2.6.32.46/drivers/net/vxge/vxge-traffic.h linux-2.6.32.46/drivers/net/vxge/vxge-traffic.h
36119 --- linux-2.6.32.46/drivers/net/vxge/vxge-traffic.h 2011-03-27 14:31:47.000000000 -0400
36120 +++ linux-2.6.32.46/drivers/net/vxge/vxge-traffic.h 2011-08-05 20:33:55.000000000 -0400
36121 @@ -2123,7 +2123,7 @@ struct vxge_hw_mempool_cbs {
36122 struct vxge_hw_mempool_dma *dma_object,
36123 u32 index,
36124 u32 is_last);
36125 -};
36126 +} __no_const;
36127
36128 void
36129 __vxge_hw_mempool_destroy(
36130 diff -urNp linux-2.6.32.46/drivers/net/wan/cycx_x25.c linux-2.6.32.46/drivers/net/wan/cycx_x25.c
36131 --- linux-2.6.32.46/drivers/net/wan/cycx_x25.c 2011-03-27 14:31:47.000000000 -0400
36132 +++ linux-2.6.32.46/drivers/net/wan/cycx_x25.c 2011-05-16 21:46:57.000000000 -0400
36133 @@ -1017,6 +1017,8 @@ static void hex_dump(char *msg, unsigned
36134 unsigned char hex[1024],
36135 * phex = hex;
36136
36137 + pax_track_stack();
36138 +
36139 if (len >= (sizeof(hex) / 2))
36140 len = (sizeof(hex) / 2) - 1;
36141
36142 diff -urNp linux-2.6.32.46/drivers/net/wan/hdlc_x25.c linux-2.6.32.46/drivers/net/wan/hdlc_x25.c
36143 --- linux-2.6.32.46/drivers/net/wan/hdlc_x25.c 2011-03-27 14:31:47.000000000 -0400
36144 +++ linux-2.6.32.46/drivers/net/wan/hdlc_x25.c 2011-08-05 20:33:55.000000000 -0400
36145 @@ -136,16 +136,16 @@ static netdev_tx_t x25_xmit(struct sk_bu
36146
36147 static int x25_open(struct net_device *dev)
36148 {
36149 - struct lapb_register_struct cb;
36150 + static struct lapb_register_struct cb = {
36151 + .connect_confirmation = x25_connected,
36152 + .connect_indication = x25_connected,
36153 + .disconnect_confirmation = x25_disconnected,
36154 + .disconnect_indication = x25_disconnected,
36155 + .data_indication = x25_data_indication,
36156 + .data_transmit = x25_data_transmit
36157 + };
36158 int result;
36159
36160 - cb.connect_confirmation = x25_connected;
36161 - cb.connect_indication = x25_connected;
36162 - cb.disconnect_confirmation = x25_disconnected;
36163 - cb.disconnect_indication = x25_disconnected;
36164 - cb.data_indication = x25_data_indication;
36165 - cb.data_transmit = x25_data_transmit;
36166 -
36167 result = lapb_register(dev, &cb);
36168 if (result != LAPB_OK)
36169 return result;
36170 diff -urNp linux-2.6.32.46/drivers/net/wimax/i2400m/usb-fw.c linux-2.6.32.46/drivers/net/wimax/i2400m/usb-fw.c
36171 --- linux-2.6.32.46/drivers/net/wimax/i2400m/usb-fw.c 2011-03-27 14:31:47.000000000 -0400
36172 +++ linux-2.6.32.46/drivers/net/wimax/i2400m/usb-fw.c 2011-05-16 21:46:57.000000000 -0400
36173 @@ -263,6 +263,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
36174 int do_autopm = 1;
36175 DECLARE_COMPLETION_ONSTACK(notif_completion);
36176
36177 + pax_track_stack();
36178 +
36179 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
36180 i2400m, ack, ack_size);
36181 BUG_ON(_ack == i2400m->bm_ack_buf);
36182 diff -urNp linux-2.6.32.46/drivers/net/wireless/airo.c linux-2.6.32.46/drivers/net/wireless/airo.c
36183 --- linux-2.6.32.46/drivers/net/wireless/airo.c 2011-03-27 14:31:47.000000000 -0400
36184 +++ linux-2.6.32.46/drivers/net/wireless/airo.c 2011-05-16 21:46:57.000000000 -0400
36185 @@ -3003,6 +3003,8 @@ static void airo_process_scan_results (s
36186 BSSListElement * loop_net;
36187 BSSListElement * tmp_net;
36188
36189 + pax_track_stack();
36190 +
36191 /* Blow away current list of scan results */
36192 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
36193 list_move_tail (&loop_net->list, &ai->network_free_list);
36194 @@ -3783,6 +3785,8 @@ static u16 setup_card(struct airo_info *
36195 WepKeyRid wkr;
36196 int rc;
36197
36198 + pax_track_stack();
36199 +
36200 memset( &mySsid, 0, sizeof( mySsid ) );
36201 kfree (ai->flash);
36202 ai->flash = NULL;
36203 @@ -4758,6 +4762,8 @@ static int proc_stats_rid_open( struct i
36204 __le32 *vals = stats.vals;
36205 int len;
36206
36207 + pax_track_stack();
36208 +
36209 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
36210 return -ENOMEM;
36211 data = (struct proc_data *)file->private_data;
36212 @@ -5487,6 +5493,8 @@ static int proc_BSSList_open( struct ino
36213 /* If doLoseSync is not 1, we won't do a Lose Sync */
36214 int doLoseSync = -1;
36215
36216 + pax_track_stack();
36217 +
36218 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
36219 return -ENOMEM;
36220 data = (struct proc_data *)file->private_data;
36221 @@ -7193,6 +7201,8 @@ static int airo_get_aplist(struct net_de
36222 int i;
36223 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
36224
36225 + pax_track_stack();
36226 +
36227 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
36228 if (!qual)
36229 return -ENOMEM;
36230 @@ -7753,6 +7763,8 @@ static void airo_read_wireless_stats(str
36231 CapabilityRid cap_rid;
36232 __le32 *vals = stats_rid.vals;
36233
36234 + pax_track_stack();
36235 +
36236 /* Get stats out of the card */
36237 clear_bit(JOB_WSTATS, &local->jobs);
36238 if (local->power.event) {
36239 diff -urNp linux-2.6.32.46/drivers/net/wireless/ath/ath5k/debug.c linux-2.6.32.46/drivers/net/wireless/ath/ath5k/debug.c
36240 --- linux-2.6.32.46/drivers/net/wireless/ath/ath5k/debug.c 2011-03-27 14:31:47.000000000 -0400
36241 +++ linux-2.6.32.46/drivers/net/wireless/ath/ath5k/debug.c 2011-05-16 21:46:57.000000000 -0400
36242 @@ -205,6 +205,8 @@ static ssize_t read_file_beacon(struct f
36243 unsigned int v;
36244 u64 tsf;
36245
36246 + pax_track_stack();
36247 +
36248 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
36249 len += snprintf(buf+len, sizeof(buf)-len,
36250 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
36251 @@ -318,6 +320,8 @@ static ssize_t read_file_debug(struct fi
36252 unsigned int len = 0;
36253 unsigned int i;
36254
36255 + pax_track_stack();
36256 +
36257 len += snprintf(buf+len, sizeof(buf)-len,
36258 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
36259
36260 diff -urNp linux-2.6.32.46/drivers/net/wireless/ath/ath9k/debug.c linux-2.6.32.46/drivers/net/wireless/ath/ath9k/debug.c
36261 --- linux-2.6.32.46/drivers/net/wireless/ath/ath9k/debug.c 2011-03-27 14:31:47.000000000 -0400
36262 +++ linux-2.6.32.46/drivers/net/wireless/ath/ath9k/debug.c 2011-05-16 21:46:57.000000000 -0400
36263 @@ -220,6 +220,8 @@ static ssize_t read_file_interrupt(struc
36264 char buf[512];
36265 unsigned int len = 0;
36266
36267 + pax_track_stack();
36268 +
36269 len += snprintf(buf + len, sizeof(buf) - len,
36270 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
36271 len += snprintf(buf + len, sizeof(buf) - len,
36272 @@ -360,6 +362,8 @@ static ssize_t read_file_wiphy(struct fi
36273 int i;
36274 u8 addr[ETH_ALEN];
36275
36276 + pax_track_stack();
36277 +
36278 len += snprintf(buf + len, sizeof(buf) - len,
36279 "primary: %s (%s chan=%d ht=%d)\n",
36280 wiphy_name(sc->pri_wiphy->hw->wiphy),
36281 diff -urNp linux-2.6.32.46/drivers/net/wireless/b43/debugfs.c linux-2.6.32.46/drivers/net/wireless/b43/debugfs.c
36282 --- linux-2.6.32.46/drivers/net/wireless/b43/debugfs.c 2011-03-27 14:31:47.000000000 -0400
36283 +++ linux-2.6.32.46/drivers/net/wireless/b43/debugfs.c 2011-04-17 15:56:46.000000000 -0400
36284 @@ -43,7 +43,7 @@ static struct dentry *rootdir;
36285 struct b43_debugfs_fops {
36286 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
36287 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
36288 - struct file_operations fops;
36289 + const struct file_operations fops;
36290 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
36291 size_t file_struct_offset;
36292 };
36293 diff -urNp linux-2.6.32.46/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.32.46/drivers/net/wireless/b43legacy/debugfs.c
36294 --- linux-2.6.32.46/drivers/net/wireless/b43legacy/debugfs.c 2011-03-27 14:31:47.000000000 -0400
36295 +++ linux-2.6.32.46/drivers/net/wireless/b43legacy/debugfs.c 2011-04-17 15:56:46.000000000 -0400
36296 @@ -44,7 +44,7 @@ static struct dentry *rootdir;
36297 struct b43legacy_debugfs_fops {
36298 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
36299 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
36300 - struct file_operations fops;
36301 + const struct file_operations fops;
36302 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
36303 size_t file_struct_offset;
36304 /* Take wl->irq_lock before calling read/write? */
36305 diff -urNp linux-2.6.32.46/drivers/net/wireless/ipw2x00/ipw2100.c linux-2.6.32.46/drivers/net/wireless/ipw2x00/ipw2100.c
36306 --- linux-2.6.32.46/drivers/net/wireless/ipw2x00/ipw2100.c 2011-03-27 14:31:47.000000000 -0400
36307 +++ linux-2.6.32.46/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-16 21:46:57.000000000 -0400
36308 @@ -2014,6 +2014,8 @@ static int ipw2100_set_essid(struct ipw2
36309 int err;
36310 DECLARE_SSID_BUF(ssid);
36311
36312 + pax_track_stack();
36313 +
36314 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
36315
36316 if (ssid_len)
36317 @@ -5380,6 +5382,8 @@ static int ipw2100_set_key(struct ipw210
36318 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
36319 int err;
36320
36321 + pax_track_stack();
36322 +
36323 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
36324 idx, keylen, len);
36325
36326 diff -urNp linux-2.6.32.46/drivers/net/wireless/ipw2x00/libipw_rx.c linux-2.6.32.46/drivers/net/wireless/ipw2x00/libipw_rx.c
36327 --- linux-2.6.32.46/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-03-27 14:31:47.000000000 -0400
36328 +++ linux-2.6.32.46/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-16 21:46:57.000000000 -0400
36329 @@ -1566,6 +1566,8 @@ static void libipw_process_probe_respons
36330 unsigned long flags;
36331 DECLARE_SSID_BUF(ssid);
36332
36333 + pax_track_stack();
36334 +
36335 LIBIPW_DEBUG_SCAN("'%s' (%pM"
36336 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
36337 print_ssid(ssid, info_element->data, info_element->len),
36338 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-1000.c linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-1000.c
36339 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-1000.c 2011-03-27 14:31:47.000000000 -0400
36340 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-1000.c 2011-04-17 15:56:46.000000000 -0400
36341 @@ -137,7 +137,7 @@ static struct iwl_lib_ops iwl1000_lib =
36342 },
36343 };
36344
36345 -static struct iwl_ops iwl1000_ops = {
36346 +static const struct iwl_ops iwl1000_ops = {
36347 .ucode = &iwl5000_ucode,
36348 .lib = &iwl1000_lib,
36349 .hcmd = &iwl5000_hcmd,
36350 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-3945.c linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-3945.c
36351 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-3945.c 2011-03-27 14:31:47.000000000 -0400
36352 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-3945.c 2011-04-17 15:56:46.000000000 -0400
36353 @@ -2874,7 +2874,7 @@ static struct iwl_hcmd_utils_ops iwl3945
36354 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
36355 };
36356
36357 -static struct iwl_ops iwl3945_ops = {
36358 +static const struct iwl_ops iwl3945_ops = {
36359 .ucode = &iwl3945_ucode,
36360 .lib = &iwl3945_lib,
36361 .hcmd = &iwl3945_hcmd,
36362 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-4965.c linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-4965.c
36363 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-4965.c 2011-03-27 14:31:47.000000000 -0400
36364 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-4965.c 2011-04-17 15:56:46.000000000 -0400
36365 @@ -2345,7 +2345,7 @@ static struct iwl_lib_ops iwl4965_lib =
36366 },
36367 };
36368
36369 -static struct iwl_ops iwl4965_ops = {
36370 +static const struct iwl_ops iwl4965_ops = {
36371 .ucode = &iwl4965_ucode,
36372 .lib = &iwl4965_lib,
36373 .hcmd = &iwl4965_hcmd,
36374 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-5000.c linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-5000.c
36375 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-5000.c 2011-06-25 12:55:34.000000000 -0400
36376 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-5000.c 2011-06-25 12:56:37.000000000 -0400
36377 @@ -1633,14 +1633,14 @@ static struct iwl_lib_ops iwl5150_lib =
36378 },
36379 };
36380
36381 -struct iwl_ops iwl5000_ops = {
36382 +const struct iwl_ops iwl5000_ops = {
36383 .ucode = &iwl5000_ucode,
36384 .lib = &iwl5000_lib,
36385 .hcmd = &iwl5000_hcmd,
36386 .utils = &iwl5000_hcmd_utils,
36387 };
36388
36389 -static struct iwl_ops iwl5150_ops = {
36390 +static const struct iwl_ops iwl5150_ops = {
36391 .ucode = &iwl5000_ucode,
36392 .lib = &iwl5150_lib,
36393 .hcmd = &iwl5000_hcmd,
36394 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-6000.c linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-6000.c
36395 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-03-27 14:31:47.000000000 -0400
36396 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-04-17 15:56:46.000000000 -0400
36397 @@ -146,7 +146,7 @@ static struct iwl_hcmd_utils_ops iwl6000
36398 .calc_rssi = iwl5000_calc_rssi,
36399 };
36400
36401 -static struct iwl_ops iwl6000_ops = {
36402 +static const struct iwl_ops iwl6000_ops = {
36403 .ucode = &iwl5000_ucode,
36404 .lib = &iwl6000_lib,
36405 .hcmd = &iwl5000_hcmd,
36406 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-agn-rs.c linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
36407 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-03-27 14:31:47.000000000 -0400
36408 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-16 21:46:57.000000000 -0400
36409 @@ -857,6 +857,8 @@ static void rs_tx_status(void *priv_r, s
36410 u8 active_index = 0;
36411 s32 tpt = 0;
36412
36413 + pax_track_stack();
36414 +
36415 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
36416
36417 if (!ieee80211_is_data(hdr->frame_control) ||
36418 @@ -2722,6 +2724,8 @@ static void rs_fill_link_cmd(struct iwl_
36419 u8 valid_tx_ant = 0;
36420 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
36421
36422 + pax_track_stack();
36423 +
36424 /* Override starting rate (index 0) if needed for debug purposes */
36425 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
36426
36427 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-agn.c linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-agn.c
36428 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-agn.c 2011-03-27 14:31:47.000000000 -0400
36429 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-agn.c 2011-08-05 20:33:55.000000000 -0400
36430 @@ -2911,7 +2911,9 @@ static int iwl_pci_probe(struct pci_dev
36431 if (iwl_debug_level & IWL_DL_INFO)
36432 dev_printk(KERN_DEBUG, &(pdev->dev),
36433 "Disabling hw_scan\n");
36434 - iwl_hw_ops.hw_scan = NULL;
36435 + pax_open_kernel();
36436 + *(void **)&iwl_hw_ops.hw_scan = NULL;
36437 + pax_close_kernel();
36438 }
36439
36440 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
36441 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-debug.h linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-debug.h
36442 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-03-27 14:31:47.000000000 -0400
36443 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-04-17 15:56:46.000000000 -0400
36444 @@ -118,8 +118,8 @@ void iwl_dbgfs_unregister(struct iwl_pri
36445 #endif
36446
36447 #else
36448 -#define IWL_DEBUG(__priv, level, fmt, args...)
36449 -#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
36450 +#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
36451 +#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
36452 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
36453 void *p, u32 len)
36454 {}
36455 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-debugfs.c linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-debugfs.c
36456 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-03-27 14:31:47.000000000 -0400
36457 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-16 21:46:57.000000000 -0400
36458 @@ -524,6 +524,8 @@ static ssize_t iwl_dbgfs_status_read(str
36459 int pos = 0;
36460 const size_t bufsz = sizeof(buf);
36461
36462 + pax_track_stack();
36463 +
36464 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
36465 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
36466 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
36467 @@ -658,6 +660,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
36468 const size_t bufsz = sizeof(buf);
36469 ssize_t ret;
36470
36471 + pax_track_stack();
36472 +
36473 for (i = 0; i < AC_NUM; i++) {
36474 pos += scnprintf(buf + pos, bufsz - pos,
36475 "\tcw_min\tcw_max\taifsn\ttxop\n");
36476 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-dev.h linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-dev.h
36477 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-dev.h 2011-03-27 14:31:47.000000000 -0400
36478 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl-dev.h 2011-04-17 15:56:46.000000000 -0400
36479 @@ -68,7 +68,7 @@ struct iwl_tx_queue;
36480
36481 /* shared structures from iwl-5000.c */
36482 extern struct iwl_mod_params iwl50_mod_params;
36483 -extern struct iwl_ops iwl5000_ops;
36484 +extern const struct iwl_ops iwl5000_ops;
36485 extern struct iwl_ucode_ops iwl5000_ucode;
36486 extern struct iwl_lib_ops iwl5000_lib;
36487 extern struct iwl_hcmd_ops iwl5000_hcmd;
36488 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl3945-base.c linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl3945-base.c
36489 --- linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl3945-base.c 2011-03-27 14:31:47.000000000 -0400
36490 +++ linux-2.6.32.46/drivers/net/wireless/iwlwifi/iwl3945-base.c 2011-08-05 20:33:55.000000000 -0400
36491 @@ -3927,7 +3927,9 @@ static int iwl3945_pci_probe(struct pci_
36492 */
36493 if (iwl3945_mod_params.disable_hw_scan) {
36494 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
36495 - iwl3945_hw_ops.hw_scan = NULL;
36496 + pax_open_kernel();
36497 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
36498 + pax_close_kernel();
36499 }
36500
36501
36502 diff -urNp linux-2.6.32.46/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-2.6.32.46/drivers/net/wireless/iwmc3200wifi/debugfs.c
36503 --- linux-2.6.32.46/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-03-27 14:31:47.000000000 -0400
36504 +++ linux-2.6.32.46/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-16 21:46:57.000000000 -0400
36505 @@ -299,6 +299,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
36506 int buf_len = 512;
36507 size_t len = 0;
36508
36509 + pax_track_stack();
36510 +
36511 if (*ppos != 0)
36512 return 0;
36513 if (count < sizeof(buf))
36514 diff -urNp linux-2.6.32.46/drivers/net/wireless/libertas/debugfs.c linux-2.6.32.46/drivers/net/wireless/libertas/debugfs.c
36515 --- linux-2.6.32.46/drivers/net/wireless/libertas/debugfs.c 2011-03-27 14:31:47.000000000 -0400
36516 +++ linux-2.6.32.46/drivers/net/wireless/libertas/debugfs.c 2011-04-17 15:56:46.000000000 -0400
36517 @@ -708,7 +708,7 @@ out_unlock:
36518 struct lbs_debugfs_files {
36519 const char *name;
36520 int perm;
36521 - struct file_operations fops;
36522 + const struct file_operations fops;
36523 };
36524
36525 static const struct lbs_debugfs_files debugfs_files[] = {
36526 diff -urNp linux-2.6.32.46/drivers/net/wireless/rndis_wlan.c linux-2.6.32.46/drivers/net/wireless/rndis_wlan.c
36527 --- linux-2.6.32.46/drivers/net/wireless/rndis_wlan.c 2011-03-27 14:31:47.000000000 -0400
36528 +++ linux-2.6.32.46/drivers/net/wireless/rndis_wlan.c 2011-04-17 15:56:46.000000000 -0400
36529 @@ -1176,7 +1176,7 @@ static int set_rts_threshold(struct usbn
36530
36531 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
36532
36533 - if (rts_threshold < 0 || rts_threshold > 2347)
36534 + if (rts_threshold > 2347)
36535 rts_threshold = 2347;
36536
36537 tmp = cpu_to_le32(rts_threshold);
36538 diff -urNp linux-2.6.32.46/drivers/oprofile/buffer_sync.c linux-2.6.32.46/drivers/oprofile/buffer_sync.c
36539 --- linux-2.6.32.46/drivers/oprofile/buffer_sync.c 2011-03-27 14:31:47.000000000 -0400
36540 +++ linux-2.6.32.46/drivers/oprofile/buffer_sync.c 2011-04-17 15:56:46.000000000 -0400
36541 @@ -341,7 +341,7 @@ static void add_data(struct op_entry *en
36542 if (cookie == NO_COOKIE)
36543 offset = pc;
36544 if (cookie == INVALID_COOKIE) {
36545 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36546 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36547 offset = pc;
36548 }
36549 if (cookie != last_cookie) {
36550 @@ -385,14 +385,14 @@ add_sample(struct mm_struct *mm, struct
36551 /* add userspace sample */
36552
36553 if (!mm) {
36554 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36555 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36556 return 0;
36557 }
36558
36559 cookie = lookup_dcookie(mm, s->eip, &offset);
36560
36561 if (cookie == INVALID_COOKIE) {
36562 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36563 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36564 return 0;
36565 }
36566
36567 @@ -561,7 +561,7 @@ void sync_buffer(int cpu)
36568 /* ignore backtraces if failed to add a sample */
36569 if (state == sb_bt_start) {
36570 state = sb_bt_ignore;
36571 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36572 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36573 }
36574 }
36575 release_mm(mm);
36576 diff -urNp linux-2.6.32.46/drivers/oprofile/event_buffer.c linux-2.6.32.46/drivers/oprofile/event_buffer.c
36577 --- linux-2.6.32.46/drivers/oprofile/event_buffer.c 2011-03-27 14:31:47.000000000 -0400
36578 +++ linux-2.6.32.46/drivers/oprofile/event_buffer.c 2011-04-17 15:56:46.000000000 -0400
36579 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
36580 }
36581
36582 if (buffer_pos == buffer_size) {
36583 - atomic_inc(&oprofile_stats.event_lost_overflow);
36584 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36585 return;
36586 }
36587
36588 diff -urNp linux-2.6.32.46/drivers/oprofile/oprof.c linux-2.6.32.46/drivers/oprofile/oprof.c
36589 --- linux-2.6.32.46/drivers/oprofile/oprof.c 2011-03-27 14:31:47.000000000 -0400
36590 +++ linux-2.6.32.46/drivers/oprofile/oprof.c 2011-04-17 15:56:46.000000000 -0400
36591 @@ -110,7 +110,7 @@ static void switch_worker(struct work_st
36592 if (oprofile_ops.switch_events())
36593 return;
36594
36595 - atomic_inc(&oprofile_stats.multiplex_counter);
36596 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36597 start_switch_worker();
36598 }
36599
36600 diff -urNp linux-2.6.32.46/drivers/oprofile/oprofile_stats.c linux-2.6.32.46/drivers/oprofile/oprofile_stats.c
36601 --- linux-2.6.32.46/drivers/oprofile/oprofile_stats.c 2011-03-27 14:31:47.000000000 -0400
36602 +++ linux-2.6.32.46/drivers/oprofile/oprofile_stats.c 2011-04-17 15:56:46.000000000 -0400
36603 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36604 cpu_buf->sample_invalid_eip = 0;
36605 }
36606
36607 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36608 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36609 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36610 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36611 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36612 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36613 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36614 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36615 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36616 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36617 }
36618
36619
36620 diff -urNp linux-2.6.32.46/drivers/oprofile/oprofile_stats.h linux-2.6.32.46/drivers/oprofile/oprofile_stats.h
36621 --- linux-2.6.32.46/drivers/oprofile/oprofile_stats.h 2011-03-27 14:31:47.000000000 -0400
36622 +++ linux-2.6.32.46/drivers/oprofile/oprofile_stats.h 2011-04-17 15:56:46.000000000 -0400
36623 @@ -13,11 +13,11 @@
36624 #include <asm/atomic.h>
36625
36626 struct oprofile_stat_struct {
36627 - atomic_t sample_lost_no_mm;
36628 - atomic_t sample_lost_no_mapping;
36629 - atomic_t bt_lost_no_mapping;
36630 - atomic_t event_lost_overflow;
36631 - atomic_t multiplex_counter;
36632 + atomic_unchecked_t sample_lost_no_mm;
36633 + atomic_unchecked_t sample_lost_no_mapping;
36634 + atomic_unchecked_t bt_lost_no_mapping;
36635 + atomic_unchecked_t event_lost_overflow;
36636 + atomic_unchecked_t multiplex_counter;
36637 };
36638
36639 extern struct oprofile_stat_struct oprofile_stats;
36640 diff -urNp linux-2.6.32.46/drivers/oprofile/oprofilefs.c linux-2.6.32.46/drivers/oprofile/oprofilefs.c
36641 --- linux-2.6.32.46/drivers/oprofile/oprofilefs.c 2011-03-27 14:31:47.000000000 -0400
36642 +++ linux-2.6.32.46/drivers/oprofile/oprofilefs.c 2011-04-17 15:56:46.000000000 -0400
36643 @@ -187,7 +187,7 @@ static const struct file_operations atom
36644
36645
36646 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36647 - char const *name, atomic_t *val)
36648 + char const *name, atomic_unchecked_t *val)
36649 {
36650 struct dentry *d = __oprofilefs_create_file(sb, root, name,
36651 &atomic_ro_fops, 0444);
36652 diff -urNp linux-2.6.32.46/drivers/parisc/pdc_stable.c linux-2.6.32.46/drivers/parisc/pdc_stable.c
36653 --- linux-2.6.32.46/drivers/parisc/pdc_stable.c 2011-03-27 14:31:47.000000000 -0400
36654 +++ linux-2.6.32.46/drivers/parisc/pdc_stable.c 2011-04-17 15:56:46.000000000 -0400
36655 @@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj
36656 return ret;
36657 }
36658
36659 -static struct sysfs_ops pdcspath_attr_ops = {
36660 +static const struct sysfs_ops pdcspath_attr_ops = {
36661 .show = pdcspath_attr_show,
36662 .store = pdcspath_attr_store,
36663 };
36664 diff -urNp linux-2.6.32.46/drivers/parport/procfs.c linux-2.6.32.46/drivers/parport/procfs.c
36665 --- linux-2.6.32.46/drivers/parport/procfs.c 2011-03-27 14:31:47.000000000 -0400
36666 +++ linux-2.6.32.46/drivers/parport/procfs.c 2011-04-17 15:56:46.000000000 -0400
36667 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
36668
36669 *ppos += len;
36670
36671 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36672 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36673 }
36674
36675 #ifdef CONFIG_PARPORT_1284
36676 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
36677
36678 *ppos += len;
36679
36680 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36681 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36682 }
36683 #endif /* IEEE1284.3 support. */
36684
36685 diff -urNp linux-2.6.32.46/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.32.46/drivers/pci/hotplug/acpiphp_glue.c
36686 --- linux-2.6.32.46/drivers/pci/hotplug/acpiphp_glue.c 2011-03-27 14:31:47.000000000 -0400
36687 +++ linux-2.6.32.46/drivers/pci/hotplug/acpiphp_glue.c 2011-04-17 15:56:46.000000000 -0400
36688 @@ -111,7 +111,7 @@ static int post_dock_fixups(struct notif
36689 }
36690
36691
36692 -static struct acpi_dock_ops acpiphp_dock_ops = {
36693 +static const struct acpi_dock_ops acpiphp_dock_ops = {
36694 .handler = handle_hotplug_event_func,
36695 };
36696
36697 diff -urNp linux-2.6.32.46/drivers/pci/hotplug/cpci_hotplug.h linux-2.6.32.46/drivers/pci/hotplug/cpci_hotplug.h
36698 --- linux-2.6.32.46/drivers/pci/hotplug/cpci_hotplug.h 2011-03-27 14:31:47.000000000 -0400
36699 +++ linux-2.6.32.46/drivers/pci/hotplug/cpci_hotplug.h 2011-08-05 20:33:55.000000000 -0400
36700 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36701 int (*hardware_test) (struct slot* slot, u32 value);
36702 u8 (*get_power) (struct slot* slot);
36703 int (*set_power) (struct slot* slot, int value);
36704 -};
36705 +} __no_const;
36706
36707 struct cpci_hp_controller {
36708 unsigned int irq;
36709 diff -urNp linux-2.6.32.46/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.32.46/drivers/pci/hotplug/cpqphp_nvram.c
36710 --- linux-2.6.32.46/drivers/pci/hotplug/cpqphp_nvram.c 2011-03-27 14:31:47.000000000 -0400
36711 +++ linux-2.6.32.46/drivers/pci/hotplug/cpqphp_nvram.c 2011-04-17 15:56:46.000000000 -0400
36712 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
36713
36714 void compaq_nvram_init (void __iomem *rom_start)
36715 {
36716 +
36717 +#ifndef CONFIG_PAX_KERNEXEC
36718 if (rom_start) {
36719 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36720 }
36721 +#endif
36722 +
36723 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36724
36725 /* initialize our int15 lock */
36726 diff -urNp linux-2.6.32.46/drivers/pci/hotplug/fakephp.c linux-2.6.32.46/drivers/pci/hotplug/fakephp.c
36727 --- linux-2.6.32.46/drivers/pci/hotplug/fakephp.c 2011-03-27 14:31:47.000000000 -0400
36728 +++ linux-2.6.32.46/drivers/pci/hotplug/fakephp.c 2011-04-17 15:56:46.000000000 -0400
36729 @@ -73,7 +73,7 @@ static void legacy_release(struct kobjec
36730 }
36731
36732 static struct kobj_type legacy_ktype = {
36733 - .sysfs_ops = &(struct sysfs_ops){
36734 + .sysfs_ops = &(const struct sysfs_ops){
36735 .store = legacy_store, .show = legacy_show
36736 },
36737 .release = &legacy_release,
36738 diff -urNp linux-2.6.32.46/drivers/pci/intel-iommu.c linux-2.6.32.46/drivers/pci/intel-iommu.c
36739 --- linux-2.6.32.46/drivers/pci/intel-iommu.c 2011-05-10 22:12:01.000000000 -0400
36740 +++ linux-2.6.32.46/drivers/pci/intel-iommu.c 2011-05-10 22:12:33.000000000 -0400
36741 @@ -2643,7 +2643,7 @@ error:
36742 return 0;
36743 }
36744
36745 -static dma_addr_t intel_map_page(struct device *dev, struct page *page,
36746 +dma_addr_t intel_map_page(struct device *dev, struct page *page,
36747 unsigned long offset, size_t size,
36748 enum dma_data_direction dir,
36749 struct dma_attrs *attrs)
36750 @@ -2719,7 +2719,7 @@ static void add_unmap(struct dmar_domain
36751 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
36752 }
36753
36754 -static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
36755 +void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
36756 size_t size, enum dma_data_direction dir,
36757 struct dma_attrs *attrs)
36758 {
36759 @@ -2768,7 +2768,7 @@ static void intel_unmap_page(struct devi
36760 }
36761 }
36762
36763 -static void *intel_alloc_coherent(struct device *hwdev, size_t size,
36764 +void *intel_alloc_coherent(struct device *hwdev, size_t size,
36765 dma_addr_t *dma_handle, gfp_t flags)
36766 {
36767 void *vaddr;
36768 @@ -2800,7 +2800,7 @@ static void *intel_alloc_coherent(struct
36769 return NULL;
36770 }
36771
36772 -static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
36773 +void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
36774 dma_addr_t dma_handle)
36775 {
36776 int order;
36777 @@ -2812,7 +2812,7 @@ static void intel_free_coherent(struct d
36778 free_pages((unsigned long)vaddr, order);
36779 }
36780
36781 -static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
36782 +void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
36783 int nelems, enum dma_data_direction dir,
36784 struct dma_attrs *attrs)
36785 {
36786 @@ -2872,7 +2872,7 @@ static int intel_nontranslate_map_sg(str
36787 return nelems;
36788 }
36789
36790 -static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
36791 +int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
36792 enum dma_data_direction dir, struct dma_attrs *attrs)
36793 {
36794 int i;
36795 @@ -2941,12 +2941,12 @@ static int intel_map_sg(struct device *h
36796 return nelems;
36797 }
36798
36799 -static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
36800 +int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
36801 {
36802 return !dma_addr;
36803 }
36804
36805 -struct dma_map_ops intel_dma_ops = {
36806 +const struct dma_map_ops intel_dma_ops = {
36807 .alloc_coherent = intel_alloc_coherent,
36808 .free_coherent = intel_free_coherent,
36809 .map_sg = intel_map_sg,
36810 diff -urNp linux-2.6.32.46/drivers/pci/pcie/aspm.c linux-2.6.32.46/drivers/pci/pcie/aspm.c
36811 --- linux-2.6.32.46/drivers/pci/pcie/aspm.c 2011-03-27 14:31:47.000000000 -0400
36812 +++ linux-2.6.32.46/drivers/pci/pcie/aspm.c 2011-04-17 15:56:46.000000000 -0400
36813 @@ -27,9 +27,9 @@
36814 #define MODULE_PARAM_PREFIX "pcie_aspm."
36815
36816 /* Note: those are not register definitions */
36817 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36818 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36819 -#define ASPM_STATE_L1 (4) /* L1 state */
36820 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36821 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36822 +#define ASPM_STATE_L1 (4U) /* L1 state */
36823 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36824 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36825
36826 diff -urNp linux-2.6.32.46/drivers/pci/probe.c linux-2.6.32.46/drivers/pci/probe.c
36827 --- linux-2.6.32.46/drivers/pci/probe.c 2011-03-27 14:31:47.000000000 -0400
36828 +++ linux-2.6.32.46/drivers/pci/probe.c 2011-04-17 15:56:46.000000000 -0400
36829 @@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
36830 return ret;
36831 }
36832
36833 -static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
36834 +static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
36835 struct device_attribute *attr,
36836 char *buf)
36837 {
36838 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
36839 }
36840
36841 -static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
36842 +static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
36843 struct device_attribute *attr,
36844 char *buf)
36845 {
36846 diff -urNp linux-2.6.32.46/drivers/pci/proc.c linux-2.6.32.46/drivers/pci/proc.c
36847 --- linux-2.6.32.46/drivers/pci/proc.c 2011-03-27 14:31:47.000000000 -0400
36848 +++ linux-2.6.32.46/drivers/pci/proc.c 2011-04-17 15:56:46.000000000 -0400
36849 @@ -480,7 +480,16 @@ static const struct file_operations proc
36850 static int __init pci_proc_init(void)
36851 {
36852 struct pci_dev *dev = NULL;
36853 +
36854 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36855 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36856 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36857 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36858 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36859 +#endif
36860 +#else
36861 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36862 +#endif
36863 proc_create("devices", 0, proc_bus_pci_dir,
36864 &proc_bus_pci_dev_operations);
36865 proc_initialized = 1;
36866 diff -urNp linux-2.6.32.46/drivers/pci/slot.c linux-2.6.32.46/drivers/pci/slot.c
36867 --- linux-2.6.32.46/drivers/pci/slot.c 2011-03-27 14:31:47.000000000 -0400
36868 +++ linux-2.6.32.46/drivers/pci/slot.c 2011-04-17 15:56:46.000000000 -0400
36869 @@ -29,7 +29,7 @@ static ssize_t pci_slot_attr_store(struc
36870 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
36871 }
36872
36873 -static struct sysfs_ops pci_slot_sysfs_ops = {
36874 +static const struct sysfs_ops pci_slot_sysfs_ops = {
36875 .show = pci_slot_attr_show,
36876 .store = pci_slot_attr_store,
36877 };
36878 diff -urNp linux-2.6.32.46/drivers/pcmcia/pcmcia_ioctl.c linux-2.6.32.46/drivers/pcmcia/pcmcia_ioctl.c
36879 --- linux-2.6.32.46/drivers/pcmcia/pcmcia_ioctl.c 2011-03-27 14:31:47.000000000 -0400
36880 +++ linux-2.6.32.46/drivers/pcmcia/pcmcia_ioctl.c 2011-04-17 15:56:46.000000000 -0400
36881 @@ -819,7 +819,7 @@ static int ds_ioctl(struct inode * inode
36882 return -EFAULT;
36883 }
36884 }
36885 - buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
36886 + buf = kzalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
36887 if (!buf)
36888 return -ENOMEM;
36889
36890 diff -urNp linux-2.6.32.46/drivers/platform/x86/acer-wmi.c linux-2.6.32.46/drivers/platform/x86/acer-wmi.c
36891 --- linux-2.6.32.46/drivers/platform/x86/acer-wmi.c 2011-03-27 14:31:47.000000000 -0400
36892 +++ linux-2.6.32.46/drivers/platform/x86/acer-wmi.c 2011-04-17 15:56:46.000000000 -0400
36893 @@ -918,7 +918,7 @@ static int update_bl_status(struct backl
36894 return 0;
36895 }
36896
36897 -static struct backlight_ops acer_bl_ops = {
36898 +static const struct backlight_ops acer_bl_ops = {
36899 .get_brightness = read_brightness,
36900 .update_status = update_bl_status,
36901 };
36902 diff -urNp linux-2.6.32.46/drivers/platform/x86/asus-laptop.c linux-2.6.32.46/drivers/platform/x86/asus-laptop.c
36903 --- linux-2.6.32.46/drivers/platform/x86/asus-laptop.c 2011-03-27 14:31:47.000000000 -0400
36904 +++ linux-2.6.32.46/drivers/platform/x86/asus-laptop.c 2011-04-17 15:56:46.000000000 -0400
36905 @@ -250,7 +250,7 @@ static struct backlight_device *asus_bac
36906 */
36907 static int read_brightness(struct backlight_device *bd);
36908 static int update_bl_status(struct backlight_device *bd);
36909 -static struct backlight_ops asusbl_ops = {
36910 +static const struct backlight_ops asusbl_ops = {
36911 .get_brightness = read_brightness,
36912 .update_status = update_bl_status,
36913 };
36914 diff -urNp linux-2.6.32.46/drivers/platform/x86/asus_acpi.c linux-2.6.32.46/drivers/platform/x86/asus_acpi.c
36915 --- linux-2.6.32.46/drivers/platform/x86/asus_acpi.c 2011-03-27 14:31:47.000000000 -0400
36916 +++ linux-2.6.32.46/drivers/platform/x86/asus_acpi.c 2011-04-17 15:56:46.000000000 -0400
36917 @@ -1396,7 +1396,7 @@ static int asus_hotk_remove(struct acpi_
36918 return 0;
36919 }
36920
36921 -static struct backlight_ops asus_backlight_data = {
36922 +static const struct backlight_ops asus_backlight_data = {
36923 .get_brightness = read_brightness,
36924 .update_status = set_brightness_status,
36925 };
36926 diff -urNp linux-2.6.32.46/drivers/platform/x86/compal-laptop.c linux-2.6.32.46/drivers/platform/x86/compal-laptop.c
36927 --- linux-2.6.32.46/drivers/platform/x86/compal-laptop.c 2011-03-27 14:31:47.000000000 -0400
36928 +++ linux-2.6.32.46/drivers/platform/x86/compal-laptop.c 2011-04-17 15:56:46.000000000 -0400
36929 @@ -163,7 +163,7 @@ static int bl_update_status(struct backl
36930 return set_lcd_level(b->props.brightness);
36931 }
36932
36933 -static struct backlight_ops compalbl_ops = {
36934 +static const struct backlight_ops compalbl_ops = {
36935 .get_brightness = bl_get_brightness,
36936 .update_status = bl_update_status,
36937 };
36938 diff -urNp linux-2.6.32.46/drivers/platform/x86/dell-laptop.c linux-2.6.32.46/drivers/platform/x86/dell-laptop.c
36939 --- linux-2.6.32.46/drivers/platform/x86/dell-laptop.c 2011-05-10 22:12:01.000000000 -0400
36940 +++ linux-2.6.32.46/drivers/platform/x86/dell-laptop.c 2011-05-10 22:12:33.000000000 -0400
36941 @@ -318,7 +318,7 @@ static int dell_get_intensity(struct bac
36942 return buffer.output[1];
36943 }
36944
36945 -static struct backlight_ops dell_ops = {
36946 +static const struct backlight_ops dell_ops = {
36947 .get_brightness = dell_get_intensity,
36948 .update_status = dell_send_intensity,
36949 };
36950 diff -urNp linux-2.6.32.46/drivers/platform/x86/eeepc-laptop.c linux-2.6.32.46/drivers/platform/x86/eeepc-laptop.c
36951 --- linux-2.6.32.46/drivers/platform/x86/eeepc-laptop.c 2011-03-27 14:31:47.000000000 -0400
36952 +++ linux-2.6.32.46/drivers/platform/x86/eeepc-laptop.c 2011-04-17 15:56:46.000000000 -0400
36953 @@ -245,7 +245,7 @@ static struct device *eeepc_hwmon_device
36954 */
36955 static int read_brightness(struct backlight_device *bd);
36956 static int update_bl_status(struct backlight_device *bd);
36957 -static struct backlight_ops eeepcbl_ops = {
36958 +static const struct backlight_ops eeepcbl_ops = {
36959 .get_brightness = read_brightness,
36960 .update_status = update_bl_status,
36961 };
36962 diff -urNp linux-2.6.32.46/drivers/platform/x86/fujitsu-laptop.c linux-2.6.32.46/drivers/platform/x86/fujitsu-laptop.c
36963 --- linux-2.6.32.46/drivers/platform/x86/fujitsu-laptop.c 2011-03-27 14:31:47.000000000 -0400
36964 +++ linux-2.6.32.46/drivers/platform/x86/fujitsu-laptop.c 2011-04-17 15:56:46.000000000 -0400
36965 @@ -436,7 +436,7 @@ static int bl_update_status(struct backl
36966 return ret;
36967 }
36968
36969 -static struct backlight_ops fujitsubl_ops = {
36970 +static const struct backlight_ops fujitsubl_ops = {
36971 .get_brightness = bl_get_brightness,
36972 .update_status = bl_update_status,
36973 };
36974 diff -urNp linux-2.6.32.46/drivers/platform/x86/msi-laptop.c linux-2.6.32.46/drivers/platform/x86/msi-laptop.c
36975 --- linux-2.6.32.46/drivers/platform/x86/msi-laptop.c 2011-03-27 14:31:47.000000000 -0400
36976 +++ linux-2.6.32.46/drivers/platform/x86/msi-laptop.c 2011-04-17 15:56:46.000000000 -0400
36977 @@ -161,7 +161,7 @@ static int bl_update_status(struct backl
36978 return set_lcd_level(b->props.brightness);
36979 }
36980
36981 -static struct backlight_ops msibl_ops = {
36982 +static const struct backlight_ops msibl_ops = {
36983 .get_brightness = bl_get_brightness,
36984 .update_status = bl_update_status,
36985 };
36986 diff -urNp linux-2.6.32.46/drivers/platform/x86/panasonic-laptop.c linux-2.6.32.46/drivers/platform/x86/panasonic-laptop.c
36987 --- linux-2.6.32.46/drivers/platform/x86/panasonic-laptop.c 2011-03-27 14:31:47.000000000 -0400
36988 +++ linux-2.6.32.46/drivers/platform/x86/panasonic-laptop.c 2011-04-17 15:56:46.000000000 -0400
36989 @@ -352,7 +352,7 @@ static int bl_set_status(struct backligh
36990 return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
36991 }
36992
36993 -static struct backlight_ops pcc_backlight_ops = {
36994 +static const struct backlight_ops pcc_backlight_ops = {
36995 .get_brightness = bl_get,
36996 .update_status = bl_set_status,
36997 };
36998 diff -urNp linux-2.6.32.46/drivers/platform/x86/sony-laptop.c linux-2.6.32.46/drivers/platform/x86/sony-laptop.c
36999 --- linux-2.6.32.46/drivers/platform/x86/sony-laptop.c 2011-03-27 14:31:47.000000000 -0400
37000 +++ linux-2.6.32.46/drivers/platform/x86/sony-laptop.c 2011-04-17 15:56:46.000000000 -0400
37001 @@ -850,7 +850,7 @@ static int sony_backlight_get_brightness
37002 }
37003
37004 static struct backlight_device *sony_backlight_device;
37005 -static struct backlight_ops sony_backlight_ops = {
37006 +static const struct backlight_ops sony_backlight_ops = {
37007 .update_status = sony_backlight_update_status,
37008 .get_brightness = sony_backlight_get_brightness,
37009 };
37010 diff -urNp linux-2.6.32.46/drivers/platform/x86/thinkpad_acpi.c linux-2.6.32.46/drivers/platform/x86/thinkpad_acpi.c
37011 --- linux-2.6.32.46/drivers/platform/x86/thinkpad_acpi.c 2011-03-27 14:31:47.000000000 -0400
37012 +++ linux-2.6.32.46/drivers/platform/x86/thinkpad_acpi.c 2011-08-05 20:33:55.000000000 -0400
37013 @@ -2137,7 +2137,7 @@ static int hotkey_mask_get(void)
37014 return 0;
37015 }
37016
37017 -void static hotkey_mask_warn_incomplete_mask(void)
37018 +static void hotkey_mask_warn_incomplete_mask(void)
37019 {
37020 /* log only what the user can fix... */
37021 const u32 wantedmask = hotkey_driver_mask &
37022 @@ -6122,7 +6122,7 @@ static void tpacpi_brightness_notify_cha
37023 BACKLIGHT_UPDATE_HOTKEY);
37024 }
37025
37026 -static struct backlight_ops ibm_backlight_data = {
37027 +static const struct backlight_ops ibm_backlight_data = {
37028 .get_brightness = brightness_get,
37029 .update_status = brightness_update_status,
37030 };
37031 diff -urNp linux-2.6.32.46/drivers/platform/x86/toshiba_acpi.c linux-2.6.32.46/drivers/platform/x86/toshiba_acpi.c
37032 --- linux-2.6.32.46/drivers/platform/x86/toshiba_acpi.c 2011-03-27 14:31:47.000000000 -0400
37033 +++ linux-2.6.32.46/drivers/platform/x86/toshiba_acpi.c 2011-04-17 15:56:46.000000000 -0400
37034 @@ -671,7 +671,7 @@ static acpi_status remove_device(void)
37035 return AE_OK;
37036 }
37037
37038 -static struct backlight_ops toshiba_backlight_data = {
37039 +static const struct backlight_ops toshiba_backlight_data = {
37040 .get_brightness = get_lcd,
37041 .update_status = set_lcd_status,
37042 };
37043 diff -urNp linux-2.6.32.46/drivers/pnp/pnpbios/bioscalls.c linux-2.6.32.46/drivers/pnp/pnpbios/bioscalls.c
37044 --- linux-2.6.32.46/drivers/pnp/pnpbios/bioscalls.c 2011-03-27 14:31:47.000000000 -0400
37045 +++ linux-2.6.32.46/drivers/pnp/pnpbios/bioscalls.c 2011-04-17 15:56:46.000000000 -0400
37046 @@ -60,7 +60,7 @@ do { \
37047 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37048 } while(0)
37049
37050 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37051 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37052 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37053
37054 /*
37055 @@ -97,7 +97,10 @@ static inline u16 call_pnp_bios(u16 func
37056
37057 cpu = get_cpu();
37058 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37059 +
37060 + pax_open_kernel();
37061 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37062 + pax_close_kernel();
37063
37064 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37065 spin_lock_irqsave(&pnp_bios_lock, flags);
37066 @@ -135,7 +138,10 @@ static inline u16 call_pnp_bios(u16 func
37067 :"memory");
37068 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37069
37070 + pax_open_kernel();
37071 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37072 + pax_close_kernel();
37073 +
37074 put_cpu();
37075
37076 /* If we get here and this is set then the PnP BIOS faulted on us. */
37077 @@ -469,7 +475,7 @@ int pnp_bios_read_escd(char *data, u32 n
37078 return status;
37079 }
37080
37081 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
37082 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37083 {
37084 int i;
37085
37086 @@ -477,6 +483,8 @@ void pnpbios_calls_init(union pnp_bios_i
37087 pnp_bios_callpoint.offset = header->fields.pm16offset;
37088 pnp_bios_callpoint.segment = PNP_CS16;
37089
37090 + pax_open_kernel();
37091 +
37092 for_each_possible_cpu(i) {
37093 struct desc_struct *gdt = get_cpu_gdt_table(i);
37094 if (!gdt)
37095 @@ -488,4 +496,6 @@ void pnpbios_calls_init(union pnp_bios_i
37096 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37097 (unsigned long)__va(header->fields.pm16dseg));
37098 }
37099 +
37100 + pax_close_kernel();
37101 }
37102 diff -urNp linux-2.6.32.46/drivers/pnp/resource.c linux-2.6.32.46/drivers/pnp/resource.c
37103 --- linux-2.6.32.46/drivers/pnp/resource.c 2011-03-27 14:31:47.000000000 -0400
37104 +++ linux-2.6.32.46/drivers/pnp/resource.c 2011-04-17 15:56:46.000000000 -0400
37105 @@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
37106 return 1;
37107
37108 /* check if the resource is valid */
37109 - if (*irq < 0 || *irq > 15)
37110 + if (*irq > 15)
37111 return 0;
37112
37113 /* check if the resource is reserved */
37114 @@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
37115 return 1;
37116
37117 /* check if the resource is valid */
37118 - if (*dma < 0 || *dma == 4 || *dma > 7)
37119 + if (*dma == 4 || *dma > 7)
37120 return 0;
37121
37122 /* check if the resource is reserved */
37123 diff -urNp linux-2.6.32.46/drivers/power/bq27x00_battery.c linux-2.6.32.46/drivers/power/bq27x00_battery.c
37124 --- linux-2.6.32.46/drivers/power/bq27x00_battery.c 2011-03-27 14:31:47.000000000 -0400
37125 +++ linux-2.6.32.46/drivers/power/bq27x00_battery.c 2011-08-05 20:33:55.000000000 -0400
37126 @@ -44,7 +44,7 @@ struct bq27x00_device_info;
37127 struct bq27x00_access_methods {
37128 int (*read)(u8 reg, int *rt_value, int b_single,
37129 struct bq27x00_device_info *di);
37130 -};
37131 +} __no_const;
37132
37133 struct bq27x00_device_info {
37134 struct device *dev;
37135 diff -urNp linux-2.6.32.46/drivers/rtc/rtc-dev.c linux-2.6.32.46/drivers/rtc/rtc-dev.c
37136 --- linux-2.6.32.46/drivers/rtc/rtc-dev.c 2011-03-27 14:31:47.000000000 -0400
37137 +++ linux-2.6.32.46/drivers/rtc/rtc-dev.c 2011-04-17 15:56:46.000000000 -0400
37138 @@ -14,6 +14,7 @@
37139 #include <linux/module.h>
37140 #include <linux/rtc.h>
37141 #include <linux/sched.h>
37142 +#include <linux/grsecurity.h>
37143 #include "rtc-core.h"
37144
37145 static dev_t rtc_devt;
37146 @@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *f
37147 if (copy_from_user(&tm, uarg, sizeof(tm)))
37148 return -EFAULT;
37149
37150 + gr_log_timechange();
37151 +
37152 return rtc_set_time(rtc, &tm);
37153
37154 case RTC_PIE_ON:
37155 diff -urNp linux-2.6.32.46/drivers/s390/cio/qdio_perf.c linux-2.6.32.46/drivers/s390/cio/qdio_perf.c
37156 --- linux-2.6.32.46/drivers/s390/cio/qdio_perf.c 2011-03-27 14:31:47.000000000 -0400
37157 +++ linux-2.6.32.46/drivers/s390/cio/qdio_perf.c 2011-04-17 15:56:46.000000000 -0400
37158 @@ -31,51 +31,51 @@ static struct proc_dir_entry *qdio_perf_
37159 static int qdio_perf_proc_show(struct seq_file *m, void *v)
37160 {
37161 seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
37162 - (long)atomic_long_read(&perf_stats.qdio_int));
37163 + (long)atomic_long_read_unchecked(&perf_stats.qdio_int));
37164 seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
37165 - (long)atomic_long_read(&perf_stats.pci_int));
37166 + (long)atomic_long_read_unchecked(&perf_stats.pci_int));
37167 seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
37168 - (long)atomic_long_read(&perf_stats.thin_int));
37169 + (long)atomic_long_read_unchecked(&perf_stats.thin_int));
37170 seq_printf(m, "\n");
37171 seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
37172 - (long)atomic_long_read(&perf_stats.tasklet_inbound));
37173 + (long)atomic_long_read_unchecked(&perf_stats.tasklet_inbound));
37174 seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
37175 - (long)atomic_long_read(&perf_stats.tasklet_outbound));
37176 + (long)atomic_long_read_unchecked(&perf_stats.tasklet_outbound));
37177 seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
37178 - (long)atomic_long_read(&perf_stats.tasklet_thinint),
37179 - (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
37180 + (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint),
37181 + (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint_loop));
37182 seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
37183 - (long)atomic_long_read(&perf_stats.thinint_inbound),
37184 - (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
37185 + (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound),
37186 + (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop));
37187 seq_printf(m, "\n");
37188 seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
37189 - (long)atomic_long_read(&perf_stats.siga_in));
37190 + (long)atomic_long_read_unchecked(&perf_stats.siga_in));
37191 seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
37192 - (long)atomic_long_read(&perf_stats.siga_out));
37193 + (long)atomic_long_read_unchecked(&perf_stats.siga_out));
37194 seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
37195 - (long)atomic_long_read(&perf_stats.siga_sync));
37196 + (long)atomic_long_read_unchecked(&perf_stats.siga_sync));
37197 seq_printf(m, "\n");
37198 seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
37199 - (long)atomic_long_read(&perf_stats.inbound_handler));
37200 + (long)atomic_long_read_unchecked(&perf_stats.inbound_handler));
37201 seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
37202 - (long)atomic_long_read(&perf_stats.outbound_handler));
37203 + (long)atomic_long_read_unchecked(&perf_stats.outbound_handler));
37204 seq_printf(m, "\n");
37205 seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
37206 - (long)atomic_long_read(&perf_stats.fast_requeue));
37207 + (long)atomic_long_read_unchecked(&perf_stats.fast_requeue));
37208 seq_printf(m, "Number of outbound target full condition\t: %li\n",
37209 - (long)atomic_long_read(&perf_stats.outbound_target_full));
37210 + (long)atomic_long_read_unchecked(&perf_stats.outbound_target_full));
37211 seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
37212 - (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
37213 + (long)atomic_long_read_unchecked(&perf_stats.debug_tl_out_timer));
37214 seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
37215 - (long)atomic_long_read(&perf_stats.debug_stop_polling));
37216 + (long)atomic_long_read_unchecked(&perf_stats.debug_stop_polling));
37217 seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
37218 - (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
37219 + (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop2));
37220 seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
37221 - (long)atomic_long_read(&perf_stats.debug_eqbs_all),
37222 - (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
37223 + (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_all),
37224 + (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_incomplete));
37225 seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
37226 - (long)atomic_long_read(&perf_stats.debug_sqbs_all),
37227 - (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
37228 + (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_all),
37229 + (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_incomplete));
37230 seq_printf(m, "\n");
37231 return 0;
37232 }
37233 diff -urNp linux-2.6.32.46/drivers/s390/cio/qdio_perf.h linux-2.6.32.46/drivers/s390/cio/qdio_perf.h
37234 --- linux-2.6.32.46/drivers/s390/cio/qdio_perf.h 2011-03-27 14:31:47.000000000 -0400
37235 +++ linux-2.6.32.46/drivers/s390/cio/qdio_perf.h 2011-04-17 15:56:46.000000000 -0400
37236 @@ -13,46 +13,46 @@
37237
37238 struct qdio_perf_stats {
37239 /* interrupt handler calls */
37240 - atomic_long_t qdio_int;
37241 - atomic_long_t pci_int;
37242 - atomic_long_t thin_int;
37243 + atomic_long_unchecked_t qdio_int;
37244 + atomic_long_unchecked_t pci_int;
37245 + atomic_long_unchecked_t thin_int;
37246
37247 /* tasklet runs */
37248 - atomic_long_t tasklet_inbound;
37249 - atomic_long_t tasklet_outbound;
37250 - atomic_long_t tasklet_thinint;
37251 - atomic_long_t tasklet_thinint_loop;
37252 - atomic_long_t thinint_inbound;
37253 - atomic_long_t thinint_inbound_loop;
37254 - atomic_long_t thinint_inbound_loop2;
37255 + atomic_long_unchecked_t tasklet_inbound;
37256 + atomic_long_unchecked_t tasklet_outbound;
37257 + atomic_long_unchecked_t tasklet_thinint;
37258 + atomic_long_unchecked_t tasklet_thinint_loop;
37259 + atomic_long_unchecked_t thinint_inbound;
37260 + atomic_long_unchecked_t thinint_inbound_loop;
37261 + atomic_long_unchecked_t thinint_inbound_loop2;
37262
37263 /* signal adapter calls */
37264 - atomic_long_t siga_out;
37265 - atomic_long_t siga_in;
37266 - atomic_long_t siga_sync;
37267 + atomic_long_unchecked_t siga_out;
37268 + atomic_long_unchecked_t siga_in;
37269 + atomic_long_unchecked_t siga_sync;
37270
37271 /* misc */
37272 - atomic_long_t inbound_handler;
37273 - atomic_long_t outbound_handler;
37274 - atomic_long_t fast_requeue;
37275 - atomic_long_t outbound_target_full;
37276 + atomic_long_unchecked_t inbound_handler;
37277 + atomic_long_unchecked_t outbound_handler;
37278 + atomic_long_unchecked_t fast_requeue;
37279 + atomic_long_unchecked_t outbound_target_full;
37280
37281 /* for debugging */
37282 - atomic_long_t debug_tl_out_timer;
37283 - atomic_long_t debug_stop_polling;
37284 - atomic_long_t debug_eqbs_all;
37285 - atomic_long_t debug_eqbs_incomplete;
37286 - atomic_long_t debug_sqbs_all;
37287 - atomic_long_t debug_sqbs_incomplete;
37288 + atomic_long_unchecked_t debug_tl_out_timer;
37289 + atomic_long_unchecked_t debug_stop_polling;
37290 + atomic_long_unchecked_t debug_eqbs_all;
37291 + atomic_long_unchecked_t debug_eqbs_incomplete;
37292 + atomic_long_unchecked_t debug_sqbs_all;
37293 + atomic_long_unchecked_t debug_sqbs_incomplete;
37294 };
37295
37296 extern struct qdio_perf_stats perf_stats;
37297 extern int qdio_performance_stats;
37298
37299 -static inline void qdio_perf_stat_inc(atomic_long_t *count)
37300 +static inline void qdio_perf_stat_inc(atomic_long_unchecked_t *count)
37301 {
37302 if (qdio_performance_stats)
37303 - atomic_long_inc(count);
37304 + atomic_long_inc_unchecked(count);
37305 }
37306
37307 int qdio_setup_perf_stats(void);
37308 diff -urNp linux-2.6.32.46/drivers/scsi/BusLogic.c linux-2.6.32.46/drivers/scsi/BusLogic.c
37309 --- linux-2.6.32.46/drivers/scsi/BusLogic.c 2011-03-27 14:31:47.000000000 -0400
37310 +++ linux-2.6.32.46/drivers/scsi/BusLogic.c 2011-05-16 21:46:57.000000000 -0400
37311 @@ -961,6 +961,8 @@ static int __init BusLogic_InitializeFla
37312 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
37313 *PrototypeHostAdapter)
37314 {
37315 + pax_track_stack();
37316 +
37317 /*
37318 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
37319 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
37320 diff -urNp linux-2.6.32.46/drivers/scsi/aacraid/aacraid.h linux-2.6.32.46/drivers/scsi/aacraid/aacraid.h
37321 --- linux-2.6.32.46/drivers/scsi/aacraid/aacraid.h 2011-03-27 14:31:47.000000000 -0400
37322 +++ linux-2.6.32.46/drivers/scsi/aacraid/aacraid.h 2011-08-05 20:33:55.000000000 -0400
37323 @@ -471,7 +471,7 @@ struct adapter_ops
37324 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
37325 /* Administrative operations */
37326 int (*adapter_comm)(struct aac_dev * dev, int comm);
37327 -};
37328 +} __no_const;
37329
37330 /*
37331 * Define which interrupt handler needs to be installed
37332 diff -urNp linux-2.6.32.46/drivers/scsi/aacraid/commctrl.c linux-2.6.32.46/drivers/scsi/aacraid/commctrl.c
37333 --- linux-2.6.32.46/drivers/scsi/aacraid/commctrl.c 2011-03-27 14:31:47.000000000 -0400
37334 +++ linux-2.6.32.46/drivers/scsi/aacraid/commctrl.c 2011-05-16 21:46:57.000000000 -0400
37335 @@ -481,6 +481,7 @@ static int aac_send_raw_srb(struct aac_d
37336 u32 actual_fibsize64, actual_fibsize = 0;
37337 int i;
37338
37339 + pax_track_stack();
37340
37341 if (dev->in_reset) {
37342 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
37343 diff -urNp linux-2.6.32.46/drivers/scsi/aic94xx/aic94xx_init.c linux-2.6.32.46/drivers/scsi/aic94xx/aic94xx_init.c
37344 --- linux-2.6.32.46/drivers/scsi/aic94xx/aic94xx_init.c 2011-03-27 14:31:47.000000000 -0400
37345 +++ linux-2.6.32.46/drivers/scsi/aic94xx/aic94xx_init.c 2011-04-17 15:56:46.000000000 -0400
37346 @@ -485,7 +485,7 @@ static ssize_t asd_show_update_bios(stru
37347 flash_error_table[i].reason);
37348 }
37349
37350 -static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
37351 +static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
37352 asd_show_update_bios, asd_store_update_bios);
37353
37354 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
37355 diff -urNp linux-2.6.32.46/drivers/scsi/bfa/bfa_ioc.h linux-2.6.32.46/drivers/scsi/bfa/bfa_ioc.h
37356 --- linux-2.6.32.46/drivers/scsi/bfa/bfa_ioc.h 2011-03-27 14:31:47.000000000 -0400
37357 +++ linux-2.6.32.46/drivers/scsi/bfa/bfa_ioc.h 2011-08-05 20:33:55.000000000 -0400
37358 @@ -127,7 +127,7 @@ struct bfa_ioc_cbfn_s {
37359 bfa_ioc_disable_cbfn_t disable_cbfn;
37360 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
37361 bfa_ioc_reset_cbfn_t reset_cbfn;
37362 -};
37363 +} __no_const;
37364
37365 /**
37366 * Heartbeat failure notification queue element.
37367 diff -urNp linux-2.6.32.46/drivers/scsi/bfa/bfa_iocfc.h linux-2.6.32.46/drivers/scsi/bfa/bfa_iocfc.h
37368 --- linux-2.6.32.46/drivers/scsi/bfa/bfa_iocfc.h 2011-03-27 14:31:47.000000000 -0400
37369 +++ linux-2.6.32.46/drivers/scsi/bfa/bfa_iocfc.h 2011-08-05 20:33:55.000000000 -0400
37370 @@ -61,7 +61,7 @@ struct bfa_hwif_s {
37371 void (*hw_isr_mode_set)(struct bfa_s *bfa, bfa_boolean_t msix);
37372 void (*hw_msix_getvecs)(struct bfa_s *bfa, u32 *vecmap,
37373 u32 *nvecs, u32 *maxvec);
37374 -};
37375 +} __no_const;
37376 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
37377
37378 struct bfa_iocfc_s {
37379 diff -urNp linux-2.6.32.46/drivers/scsi/dpt_i2o.c linux-2.6.32.46/drivers/scsi/dpt_i2o.c
37380 --- linux-2.6.32.46/drivers/scsi/dpt_i2o.c 2011-03-27 14:31:47.000000000 -0400
37381 +++ linux-2.6.32.46/drivers/scsi/dpt_i2o.c 2011-05-16 21:46:57.000000000 -0400
37382 @@ -1804,6 +1804,8 @@ static int adpt_i2o_passthru(adpt_hba* p
37383 dma_addr_t addr;
37384 ulong flags = 0;
37385
37386 + pax_track_stack();
37387 +
37388 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
37389 // get user msg size in u32s
37390 if(get_user(size, &user_msg[0])){
37391 @@ -2297,6 +2299,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
37392 s32 rcode;
37393 dma_addr_t addr;
37394
37395 + pax_track_stack();
37396 +
37397 memset(msg, 0 , sizeof(msg));
37398 len = scsi_bufflen(cmd);
37399 direction = 0x00000000;
37400 diff -urNp linux-2.6.32.46/drivers/scsi/eata.c linux-2.6.32.46/drivers/scsi/eata.c
37401 --- linux-2.6.32.46/drivers/scsi/eata.c 2011-03-27 14:31:47.000000000 -0400
37402 +++ linux-2.6.32.46/drivers/scsi/eata.c 2011-05-16 21:46:57.000000000 -0400
37403 @@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
37404 struct hostdata *ha;
37405 char name[16];
37406
37407 + pax_track_stack();
37408 +
37409 sprintf(name, "%s%d", driver_name, j);
37410
37411 if (!request_region(port_base, REGION_SIZE, driver_name)) {
37412 diff -urNp linux-2.6.32.46/drivers/scsi/fcoe/libfcoe.c linux-2.6.32.46/drivers/scsi/fcoe/libfcoe.c
37413 --- linux-2.6.32.46/drivers/scsi/fcoe/libfcoe.c 2011-03-27 14:31:47.000000000 -0400
37414 +++ linux-2.6.32.46/drivers/scsi/fcoe/libfcoe.c 2011-05-16 21:46:57.000000000 -0400
37415 @@ -809,6 +809,8 @@ static void fcoe_ctlr_recv_els(struct fc
37416 size_t rlen;
37417 size_t dlen;
37418
37419 + pax_track_stack();
37420 +
37421 fiph = (struct fip_header *)skb->data;
37422 sub = fiph->fip_subcode;
37423 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
37424 diff -urNp linux-2.6.32.46/drivers/scsi/fnic/fnic_main.c linux-2.6.32.46/drivers/scsi/fnic/fnic_main.c
37425 --- linux-2.6.32.46/drivers/scsi/fnic/fnic_main.c 2011-03-27 14:31:47.000000000 -0400
37426 +++ linux-2.6.32.46/drivers/scsi/fnic/fnic_main.c 2011-08-05 20:33:55.000000000 -0400
37427 @@ -669,7 +669,7 @@ static int __devinit fnic_probe(struct p
37428 /* Start local port initiatialization */
37429
37430 lp->link_up = 0;
37431 - lp->tt = fnic_transport_template;
37432 + memcpy((void *)&lp->tt, &fnic_transport_template, sizeof(fnic_transport_template));
37433
37434 lp->max_retry_count = fnic->config.flogi_retries;
37435 lp->max_rport_retry_count = fnic->config.plogi_retries;
37436 diff -urNp linux-2.6.32.46/drivers/scsi/gdth.c linux-2.6.32.46/drivers/scsi/gdth.c
37437 --- linux-2.6.32.46/drivers/scsi/gdth.c 2011-03-27 14:31:47.000000000 -0400
37438 +++ linux-2.6.32.46/drivers/scsi/gdth.c 2011-05-16 21:46:57.000000000 -0400
37439 @@ -4102,6 +4102,8 @@ static int ioc_lockdrv(void __user *arg)
37440 ulong flags;
37441 gdth_ha_str *ha;
37442
37443 + pax_track_stack();
37444 +
37445 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
37446 return -EFAULT;
37447 ha = gdth_find_ha(ldrv.ionode);
37448 @@ -4134,6 +4136,8 @@ static int ioc_resetdrv(void __user *arg
37449 gdth_ha_str *ha;
37450 int rval;
37451
37452 + pax_track_stack();
37453 +
37454 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
37455 res.number >= MAX_HDRIVES)
37456 return -EFAULT;
37457 @@ -4169,6 +4173,8 @@ static int ioc_general(void __user *arg,
37458 gdth_ha_str *ha;
37459 int rval;
37460
37461 + pax_track_stack();
37462 +
37463 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
37464 return -EFAULT;
37465 ha = gdth_find_ha(gen.ionode);
37466 @@ -4625,6 +4631,9 @@ static void gdth_flush(gdth_ha_str *ha)
37467 int i;
37468 gdth_cmd_str gdtcmd;
37469 char cmnd[MAX_COMMAND_SIZE];
37470 +
37471 + pax_track_stack();
37472 +
37473 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
37474
37475 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
37476 diff -urNp linux-2.6.32.46/drivers/scsi/gdth_proc.c linux-2.6.32.46/drivers/scsi/gdth_proc.c
37477 --- linux-2.6.32.46/drivers/scsi/gdth_proc.c 2011-03-27 14:31:47.000000000 -0400
37478 +++ linux-2.6.32.46/drivers/scsi/gdth_proc.c 2011-05-16 21:46:57.000000000 -0400
37479 @@ -46,6 +46,9 @@ static int gdth_set_asc_info(struct Scsi
37480 ulong64 paddr;
37481
37482 char cmnd[MAX_COMMAND_SIZE];
37483 +
37484 + pax_track_stack();
37485 +
37486 memset(cmnd, 0xff, 12);
37487 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
37488
37489 @@ -174,6 +177,8 @@ static int gdth_get_info(char *buffer,ch
37490 gdth_hget_str *phg;
37491 char cmnd[MAX_COMMAND_SIZE];
37492
37493 + pax_track_stack();
37494 +
37495 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
37496 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
37497 if (!gdtcmd || !estr)
37498 diff -urNp linux-2.6.32.46/drivers/scsi/hosts.c linux-2.6.32.46/drivers/scsi/hosts.c
37499 --- linux-2.6.32.46/drivers/scsi/hosts.c 2011-03-27 14:31:47.000000000 -0400
37500 +++ linux-2.6.32.46/drivers/scsi/hosts.c 2011-05-04 17:56:28.000000000 -0400
37501 @@ -40,7 +40,7 @@
37502 #include "scsi_logging.h"
37503
37504
37505 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
37506 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
37507
37508
37509 static void scsi_host_cls_release(struct device *dev)
37510 @@ -344,7 +344,7 @@ struct Scsi_Host *scsi_host_alloc(struct
37511 * subtract one because we increment first then return, but we need to
37512 * know what the next host number was before increment
37513 */
37514 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37515 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37516 shost->dma_channel = 0xff;
37517
37518 /* These three are default values which can be overridden */
37519 diff -urNp linux-2.6.32.46/drivers/scsi/ipr.c linux-2.6.32.46/drivers/scsi/ipr.c
37520 --- linux-2.6.32.46/drivers/scsi/ipr.c 2011-03-27 14:31:47.000000000 -0400
37521 +++ linux-2.6.32.46/drivers/scsi/ipr.c 2011-04-17 15:56:46.000000000 -0400
37522 @@ -5286,7 +5286,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
37523 return true;
37524 }
37525
37526 -static struct ata_port_operations ipr_sata_ops = {
37527 +static const struct ata_port_operations ipr_sata_ops = {
37528 .phy_reset = ipr_ata_phy_reset,
37529 .hardreset = ipr_sata_reset,
37530 .post_internal_cmd = ipr_ata_post_internal,
37531 diff -urNp linux-2.6.32.46/drivers/scsi/ips.h linux-2.6.32.46/drivers/scsi/ips.h
37532 --- linux-2.6.32.46/drivers/scsi/ips.h 2011-03-27 14:31:47.000000000 -0400
37533 +++ linux-2.6.32.46/drivers/scsi/ips.h 2011-08-05 20:33:55.000000000 -0400
37534 @@ -1027,7 +1027,7 @@ typedef struct {
37535 int (*intr)(struct ips_ha *);
37536 void (*enableint)(struct ips_ha *);
37537 uint32_t (*statupd)(struct ips_ha *);
37538 -} ips_hw_func_t;
37539 +} __no_const ips_hw_func_t;
37540
37541 typedef struct ips_ha {
37542 uint8_t ha_id[IPS_MAX_CHANNELS+1];
37543 diff -urNp linux-2.6.32.46/drivers/scsi/libfc/fc_exch.c linux-2.6.32.46/drivers/scsi/libfc/fc_exch.c
37544 --- linux-2.6.32.46/drivers/scsi/libfc/fc_exch.c 2011-03-27 14:31:47.000000000 -0400
37545 +++ linux-2.6.32.46/drivers/scsi/libfc/fc_exch.c 2011-08-23 21:22:32.000000000 -0400
37546 @@ -86,12 +86,12 @@ struct fc_exch_mgr {
37547 * all together if not used XXX
37548 */
37549 struct {
37550 - atomic_t no_free_exch;
37551 - atomic_t no_free_exch_xid;
37552 - atomic_t xid_not_found;
37553 - atomic_t xid_busy;
37554 - atomic_t seq_not_found;
37555 - atomic_t non_bls_resp;
37556 + atomic_unchecked_t no_free_exch;
37557 + atomic_unchecked_t no_free_exch_xid;
37558 + atomic_unchecked_t xid_not_found;
37559 + atomic_unchecked_t xid_busy;
37560 + atomic_unchecked_t seq_not_found;
37561 + atomic_unchecked_t non_bls_resp;
37562 } stats;
37563 };
37564 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
37565 @@ -510,7 +510,7 @@ static struct fc_exch *fc_exch_em_alloc(
37566 /* allocate memory for exchange */
37567 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37568 if (!ep) {
37569 - atomic_inc(&mp->stats.no_free_exch);
37570 + atomic_inc_unchecked(&mp->stats.no_free_exch);
37571 goto out;
37572 }
37573 memset(ep, 0, sizeof(*ep));
37574 @@ -557,7 +557,7 @@ out:
37575 return ep;
37576 err:
37577 spin_unlock_bh(&pool->lock);
37578 - atomic_inc(&mp->stats.no_free_exch_xid);
37579 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37580 mempool_free(ep, mp->ep_pool);
37581 return NULL;
37582 }
37583 @@ -690,7 +690,7 @@ static enum fc_pf_rjt_reason fc_seq_look
37584 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37585 ep = fc_exch_find(mp, xid);
37586 if (!ep) {
37587 - atomic_inc(&mp->stats.xid_not_found);
37588 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37589 reject = FC_RJT_OX_ID;
37590 goto out;
37591 }
37592 @@ -720,7 +720,7 @@ static enum fc_pf_rjt_reason fc_seq_look
37593 ep = fc_exch_find(mp, xid);
37594 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37595 if (ep) {
37596 - atomic_inc(&mp->stats.xid_busy);
37597 + atomic_inc_unchecked(&mp->stats.xid_busy);
37598 reject = FC_RJT_RX_ID;
37599 goto rel;
37600 }
37601 @@ -731,7 +731,7 @@ static enum fc_pf_rjt_reason fc_seq_look
37602 }
37603 xid = ep->xid; /* get our XID */
37604 } else if (!ep) {
37605 - atomic_inc(&mp->stats.xid_not_found);
37606 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37607 reject = FC_RJT_RX_ID; /* XID not found */
37608 goto out;
37609 }
37610 @@ -752,7 +752,7 @@ static enum fc_pf_rjt_reason fc_seq_look
37611 } else {
37612 sp = &ep->seq;
37613 if (sp->id != fh->fh_seq_id) {
37614 - atomic_inc(&mp->stats.seq_not_found);
37615 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37616 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
37617 goto rel;
37618 }
37619 @@ -1163,22 +1163,22 @@ static void fc_exch_recv_seq_resp(struct
37620
37621 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37622 if (!ep) {
37623 - atomic_inc(&mp->stats.xid_not_found);
37624 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37625 goto out;
37626 }
37627 if (ep->esb_stat & ESB_ST_COMPLETE) {
37628 - atomic_inc(&mp->stats.xid_not_found);
37629 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37630 goto out;
37631 }
37632 if (ep->rxid == FC_XID_UNKNOWN)
37633 ep->rxid = ntohs(fh->fh_rx_id);
37634 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37635 - atomic_inc(&mp->stats.xid_not_found);
37636 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37637 goto rel;
37638 }
37639 if (ep->did != ntoh24(fh->fh_s_id) &&
37640 ep->did != FC_FID_FLOGI) {
37641 - atomic_inc(&mp->stats.xid_not_found);
37642 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37643 goto rel;
37644 }
37645 sof = fr_sof(fp);
37646 @@ -1189,7 +1189,7 @@ static void fc_exch_recv_seq_resp(struct
37647 } else {
37648 sp = &ep->seq;
37649 if (sp->id != fh->fh_seq_id) {
37650 - atomic_inc(&mp->stats.seq_not_found);
37651 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37652 goto rel;
37653 }
37654 }
37655 @@ -1249,9 +1249,9 @@ static void fc_exch_recv_resp(struct fc_
37656 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37657
37658 if (!sp)
37659 - atomic_inc(&mp->stats.xid_not_found);
37660 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37661 else
37662 - atomic_inc(&mp->stats.non_bls_resp);
37663 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37664
37665 fc_frame_free(fp);
37666 }
37667 diff -urNp linux-2.6.32.46/drivers/scsi/libsas/sas_ata.c linux-2.6.32.46/drivers/scsi/libsas/sas_ata.c
37668 --- linux-2.6.32.46/drivers/scsi/libsas/sas_ata.c 2011-03-27 14:31:47.000000000 -0400
37669 +++ linux-2.6.32.46/drivers/scsi/libsas/sas_ata.c 2011-04-23 12:56:11.000000000 -0400
37670 @@ -343,7 +343,7 @@ static int sas_ata_scr_read(struct ata_l
37671 }
37672 }
37673
37674 -static struct ata_port_operations sas_sata_ops = {
37675 +static const struct ata_port_operations sas_sata_ops = {
37676 .phy_reset = sas_ata_phy_reset,
37677 .post_internal_cmd = sas_ata_post_internal,
37678 .qc_defer = ata_std_qc_defer,
37679 diff -urNp linux-2.6.32.46/drivers/scsi/lpfc/lpfc.h linux-2.6.32.46/drivers/scsi/lpfc/lpfc.h
37680 --- linux-2.6.32.46/drivers/scsi/lpfc/lpfc.h 2011-03-27 14:31:47.000000000 -0400
37681 +++ linux-2.6.32.46/drivers/scsi/lpfc/lpfc.h 2011-05-04 17:56:28.000000000 -0400
37682 @@ -400,7 +400,7 @@ struct lpfc_vport {
37683 struct dentry *debug_nodelist;
37684 struct dentry *vport_debugfs_root;
37685 struct lpfc_debugfs_trc *disc_trc;
37686 - atomic_t disc_trc_cnt;
37687 + atomic_unchecked_t disc_trc_cnt;
37688 #endif
37689 uint8_t stat_data_enabled;
37690 uint8_t stat_data_blocked;
37691 @@ -725,8 +725,8 @@ struct lpfc_hba {
37692 struct timer_list fabric_block_timer;
37693 unsigned long bit_flags;
37694 #define FABRIC_COMANDS_BLOCKED 0
37695 - atomic_t num_rsrc_err;
37696 - atomic_t num_cmd_success;
37697 + atomic_unchecked_t num_rsrc_err;
37698 + atomic_unchecked_t num_cmd_success;
37699 unsigned long last_rsrc_error_time;
37700 unsigned long last_ramp_down_time;
37701 unsigned long last_ramp_up_time;
37702 @@ -740,7 +740,7 @@ struct lpfc_hba {
37703 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
37704 struct dentry *debug_slow_ring_trc;
37705 struct lpfc_debugfs_trc *slow_ring_trc;
37706 - atomic_t slow_ring_trc_cnt;
37707 + atomic_unchecked_t slow_ring_trc_cnt;
37708 #endif
37709
37710 /* Used for deferred freeing of ELS data buffers */
37711 diff -urNp linux-2.6.32.46/drivers/scsi/lpfc/lpfc_debugfs.c linux-2.6.32.46/drivers/scsi/lpfc/lpfc_debugfs.c
37712 --- linux-2.6.32.46/drivers/scsi/lpfc/lpfc_debugfs.c 2011-03-27 14:31:47.000000000 -0400
37713 +++ linux-2.6.32.46/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-16 21:46:57.000000000 -0400
37714 @@ -124,7 +124,7 @@ struct lpfc_debug {
37715 int len;
37716 };
37717
37718 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37719 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37720 static unsigned long lpfc_debugfs_start_time = 0L;
37721
37722 /**
37723 @@ -158,7 +158,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
37724 lpfc_debugfs_enable = 0;
37725
37726 len = 0;
37727 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37728 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37729 (lpfc_debugfs_max_disc_trc - 1);
37730 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37731 dtp = vport->disc_trc + i;
37732 @@ -219,7 +219,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
37733 lpfc_debugfs_enable = 0;
37734
37735 len = 0;
37736 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37737 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37738 (lpfc_debugfs_max_slow_ring_trc - 1);
37739 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37740 dtp = phba->slow_ring_trc + i;
37741 @@ -397,6 +397,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
37742 uint32_t *ptr;
37743 char buffer[1024];
37744
37745 + pax_track_stack();
37746 +
37747 off = 0;
37748 spin_lock_irq(&phba->hbalock);
37749
37750 @@ -634,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
37751 !vport || !vport->disc_trc)
37752 return;
37753
37754 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37755 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37756 (lpfc_debugfs_max_disc_trc - 1);
37757 dtp = vport->disc_trc + index;
37758 dtp->fmt = fmt;
37759 dtp->data1 = data1;
37760 dtp->data2 = data2;
37761 dtp->data3 = data3;
37762 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37763 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37764 dtp->jif = jiffies;
37765 #endif
37766 return;
37767 @@ -672,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
37768 !phba || !phba->slow_ring_trc)
37769 return;
37770
37771 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37772 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37773 (lpfc_debugfs_max_slow_ring_trc - 1);
37774 dtp = phba->slow_ring_trc + index;
37775 dtp->fmt = fmt;
37776 dtp->data1 = data1;
37777 dtp->data2 = data2;
37778 dtp->data3 = data3;
37779 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37780 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37781 dtp->jif = jiffies;
37782 #endif
37783 return;
37784 @@ -1364,7 +1366,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
37785 "slow_ring buffer\n");
37786 goto debug_failed;
37787 }
37788 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37789 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37790 memset(phba->slow_ring_trc, 0,
37791 (sizeof(struct lpfc_debugfs_trc) *
37792 lpfc_debugfs_max_slow_ring_trc));
37793 @@ -1410,7 +1412,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
37794 "buffer\n");
37795 goto debug_failed;
37796 }
37797 - atomic_set(&vport->disc_trc_cnt, 0);
37798 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37799
37800 snprintf(name, sizeof(name), "discovery_trace");
37801 vport->debug_disc_trc =
37802 diff -urNp linux-2.6.32.46/drivers/scsi/lpfc/lpfc_init.c linux-2.6.32.46/drivers/scsi/lpfc/lpfc_init.c
37803 --- linux-2.6.32.46/drivers/scsi/lpfc/lpfc_init.c 2011-03-27 14:31:47.000000000 -0400
37804 +++ linux-2.6.32.46/drivers/scsi/lpfc/lpfc_init.c 2011-08-05 20:33:55.000000000 -0400
37805 @@ -8021,8 +8021,10 @@ lpfc_init(void)
37806 printk(LPFC_COPYRIGHT "\n");
37807
37808 if (lpfc_enable_npiv) {
37809 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37810 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37811 + pax_open_kernel();
37812 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37813 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37814 + pax_close_kernel();
37815 }
37816 lpfc_transport_template =
37817 fc_attach_transport(&lpfc_transport_functions);
37818 diff -urNp linux-2.6.32.46/drivers/scsi/lpfc/lpfc_scsi.c linux-2.6.32.46/drivers/scsi/lpfc/lpfc_scsi.c
37819 --- linux-2.6.32.46/drivers/scsi/lpfc/lpfc_scsi.c 2011-03-27 14:31:47.000000000 -0400
37820 +++ linux-2.6.32.46/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-04 17:56:28.000000000 -0400
37821 @@ -259,7 +259,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
37822 uint32_t evt_posted;
37823
37824 spin_lock_irqsave(&phba->hbalock, flags);
37825 - atomic_inc(&phba->num_rsrc_err);
37826 + atomic_inc_unchecked(&phba->num_rsrc_err);
37827 phba->last_rsrc_error_time = jiffies;
37828
37829 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37830 @@ -300,7 +300,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
37831 unsigned long flags;
37832 struct lpfc_hba *phba = vport->phba;
37833 uint32_t evt_posted;
37834 - atomic_inc(&phba->num_cmd_success);
37835 + atomic_inc_unchecked(&phba->num_cmd_success);
37836
37837 if (vport->cfg_lun_queue_depth <= queue_depth)
37838 return;
37839 @@ -343,8 +343,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
37840 int i;
37841 struct lpfc_rport_data *rdata;
37842
37843 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37844 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37845 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37846 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37847
37848 vports = lpfc_create_vport_work_array(phba);
37849 if (vports != NULL)
37850 @@ -378,8 +378,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
37851 }
37852 }
37853 lpfc_destroy_vport_work_array(phba, vports);
37854 - atomic_set(&phba->num_rsrc_err, 0);
37855 - atomic_set(&phba->num_cmd_success, 0);
37856 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37857 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37858 }
37859
37860 /**
37861 @@ -427,8 +427,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
37862 }
37863 }
37864 lpfc_destroy_vport_work_array(phba, vports);
37865 - atomic_set(&phba->num_rsrc_err, 0);
37866 - atomic_set(&phba->num_cmd_success, 0);
37867 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37868 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37869 }
37870
37871 /**
37872 diff -urNp linux-2.6.32.46/drivers/scsi/megaraid/megaraid_mbox.c linux-2.6.32.46/drivers/scsi/megaraid/megaraid_mbox.c
37873 --- linux-2.6.32.46/drivers/scsi/megaraid/megaraid_mbox.c 2011-03-27 14:31:47.000000000 -0400
37874 +++ linux-2.6.32.46/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-16 21:46:57.000000000 -0400
37875 @@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter
37876 int rval;
37877 int i;
37878
37879 + pax_track_stack();
37880 +
37881 // Allocate memory for the base list of scb for management module.
37882 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
37883
37884 diff -urNp linux-2.6.32.46/drivers/scsi/osd/osd_initiator.c linux-2.6.32.46/drivers/scsi/osd/osd_initiator.c
37885 --- linux-2.6.32.46/drivers/scsi/osd/osd_initiator.c 2011-03-27 14:31:47.000000000 -0400
37886 +++ linux-2.6.32.46/drivers/scsi/osd/osd_initiator.c 2011-05-16 21:46:57.000000000 -0400
37887 @@ -94,6 +94,8 @@ static int _osd_print_system_info(struct
37888 int nelem = ARRAY_SIZE(get_attrs), a = 0;
37889 int ret;
37890
37891 + pax_track_stack();
37892 +
37893 or = osd_start_request(od, GFP_KERNEL);
37894 if (!or)
37895 return -ENOMEM;
37896 diff -urNp linux-2.6.32.46/drivers/scsi/pmcraid.c linux-2.6.32.46/drivers/scsi/pmcraid.c
37897 --- linux-2.6.32.46/drivers/scsi/pmcraid.c 2011-08-09 18:35:29.000000000 -0400
37898 +++ linux-2.6.32.46/drivers/scsi/pmcraid.c 2011-08-09 18:33:59.000000000 -0400
37899 @@ -189,8 +189,8 @@ static int pmcraid_slave_alloc(struct sc
37900 res->scsi_dev = scsi_dev;
37901 scsi_dev->hostdata = res;
37902 res->change_detected = 0;
37903 - atomic_set(&res->read_failures, 0);
37904 - atomic_set(&res->write_failures, 0);
37905 + atomic_set_unchecked(&res->read_failures, 0);
37906 + atomic_set_unchecked(&res->write_failures, 0);
37907 rc = 0;
37908 }
37909 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37910 @@ -2396,9 +2396,9 @@ static int pmcraid_error_handler(struct
37911
37912 /* If this was a SCSI read/write command keep count of errors */
37913 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37914 - atomic_inc(&res->read_failures);
37915 + atomic_inc_unchecked(&res->read_failures);
37916 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37917 - atomic_inc(&res->write_failures);
37918 + atomic_inc_unchecked(&res->write_failures);
37919
37920 if (!RES_IS_GSCSI(res->cfg_entry) &&
37921 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37922 @@ -4116,7 +4116,7 @@ static void pmcraid_worker_function(stru
37923
37924 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37925 /* add resources only after host is added into system */
37926 - if (!atomic_read(&pinstance->expose_resources))
37927 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37928 return;
37929
37930 spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
37931 @@ -4850,7 +4850,7 @@ static int __devinit pmcraid_init_instan
37932 init_waitqueue_head(&pinstance->reset_wait_q);
37933
37934 atomic_set(&pinstance->outstanding_cmds, 0);
37935 - atomic_set(&pinstance->expose_resources, 0);
37936 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37937
37938 INIT_LIST_HEAD(&pinstance->free_res_q);
37939 INIT_LIST_HEAD(&pinstance->used_res_q);
37940 @@ -5502,7 +5502,7 @@ static int __devinit pmcraid_probe(
37941 /* Schedule worker thread to handle CCN and take care of adding and
37942 * removing devices to OS
37943 */
37944 - atomic_set(&pinstance->expose_resources, 1);
37945 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37946 schedule_work(&pinstance->worker_q);
37947 return rc;
37948
37949 diff -urNp linux-2.6.32.46/drivers/scsi/pmcraid.h linux-2.6.32.46/drivers/scsi/pmcraid.h
37950 --- linux-2.6.32.46/drivers/scsi/pmcraid.h 2011-03-27 14:31:47.000000000 -0400
37951 +++ linux-2.6.32.46/drivers/scsi/pmcraid.h 2011-05-04 17:56:28.000000000 -0400
37952 @@ -690,7 +690,7 @@ struct pmcraid_instance {
37953 atomic_t outstanding_cmds;
37954
37955 /* should add/delete resources to mid-layer now ?*/
37956 - atomic_t expose_resources;
37957 + atomic_unchecked_t expose_resources;
37958
37959 /* Tasklet to handle deferred processing */
37960 struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
37961 @@ -727,8 +727,8 @@ struct pmcraid_resource_entry {
37962 struct list_head queue; /* link to "to be exposed" resources */
37963 struct pmcraid_config_table_entry cfg_entry;
37964 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37965 - atomic_t read_failures; /* count of failed READ commands */
37966 - atomic_t write_failures; /* count of failed WRITE commands */
37967 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37968 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37969
37970 /* To indicate add/delete/modify during CCN */
37971 u8 change_detected;
37972 diff -urNp linux-2.6.32.46/drivers/scsi/qla2xxx/qla_def.h linux-2.6.32.46/drivers/scsi/qla2xxx/qla_def.h
37973 --- linux-2.6.32.46/drivers/scsi/qla2xxx/qla_def.h 2011-03-27 14:31:47.000000000 -0400
37974 +++ linux-2.6.32.46/drivers/scsi/qla2xxx/qla_def.h 2011-08-05 20:33:55.000000000 -0400
37975 @@ -2089,7 +2089,7 @@ struct isp_operations {
37976
37977 int (*get_flash_version) (struct scsi_qla_host *, void *);
37978 int (*start_scsi) (srb_t *);
37979 -};
37980 +} __no_const;
37981
37982 /* MSI-X Support *************************************************************/
37983
37984 diff -urNp linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_def.h linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_def.h
37985 --- linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_def.h 2011-03-27 14:31:47.000000000 -0400
37986 +++ linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_def.h 2011-05-04 17:56:28.000000000 -0400
37987 @@ -240,7 +240,7 @@ struct ddb_entry {
37988 atomic_t retry_relogin_timer; /* Min Time between relogins
37989 * (4000 only) */
37990 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
37991 - atomic_t relogin_retry_count; /* Num of times relogin has been
37992 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37993 * retried */
37994
37995 uint16_t port;
37996 diff -urNp linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_init.c linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_init.c
37997 --- linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_init.c 2011-03-27 14:31:47.000000000 -0400
37998 +++ linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_init.c 2011-05-04 17:56:28.000000000 -0400
37999 @@ -482,7 +482,7 @@ static struct ddb_entry * qla4xxx_alloc_
38000 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
38001 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38002 atomic_set(&ddb_entry->relogin_timer, 0);
38003 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38004 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38005 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38006 list_add_tail(&ddb_entry->list, &ha->ddb_list);
38007 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
38008 @@ -1308,7 +1308,7 @@ int qla4xxx_process_ddb_changed(struct s
38009 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38010 atomic_set(&ddb_entry->port_down_timer,
38011 ha->port_down_retry_count);
38012 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38013 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38014 atomic_set(&ddb_entry->relogin_timer, 0);
38015 clear_bit(DF_RELOGIN, &ddb_entry->flags);
38016 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
38017 diff -urNp linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_os.c linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_os.c
38018 --- linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_os.c 2011-03-27 14:31:47.000000000 -0400
38019 +++ linux-2.6.32.46/drivers/scsi/qla4xxx/ql4_os.c 2011-05-04 17:56:28.000000000 -0400
38020 @@ -641,13 +641,13 @@ static void qla4xxx_timer(struct scsi_ql
38021 ddb_entry->fw_ddb_device_state ==
38022 DDB_DS_SESSION_FAILED) {
38023 /* Reset retry relogin timer */
38024 - atomic_inc(&ddb_entry->relogin_retry_count);
38025 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38026 DEBUG2(printk("scsi%ld: index[%d] relogin"
38027 " timed out-retrying"
38028 " relogin (%d)\n",
38029 ha->host_no,
38030 ddb_entry->fw_ddb_index,
38031 - atomic_read(&ddb_entry->
38032 + atomic_read_unchecked(&ddb_entry->
38033 relogin_retry_count))
38034 );
38035 start_dpc++;
38036 diff -urNp linux-2.6.32.46/drivers/scsi/scsi.c linux-2.6.32.46/drivers/scsi/scsi.c
38037 --- linux-2.6.32.46/drivers/scsi/scsi.c 2011-03-27 14:31:47.000000000 -0400
38038 +++ linux-2.6.32.46/drivers/scsi/scsi.c 2011-05-04 17:56:28.000000000 -0400
38039 @@ -652,7 +652,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
38040 unsigned long timeout;
38041 int rtn = 0;
38042
38043 - atomic_inc(&cmd->device->iorequest_cnt);
38044 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38045
38046 /* check if the device is still usable */
38047 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38048 diff -urNp linux-2.6.32.46/drivers/scsi/scsi_debug.c linux-2.6.32.46/drivers/scsi/scsi_debug.c
38049 --- linux-2.6.32.46/drivers/scsi/scsi_debug.c 2011-03-27 14:31:47.000000000 -0400
38050 +++ linux-2.6.32.46/drivers/scsi/scsi_debug.c 2011-05-16 21:46:57.000000000 -0400
38051 @@ -1395,6 +1395,8 @@ static int resp_mode_select(struct scsi_
38052 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
38053 unsigned char *cmd = (unsigned char *)scp->cmnd;
38054
38055 + pax_track_stack();
38056 +
38057 if ((errsts = check_readiness(scp, 1, devip)))
38058 return errsts;
38059 memset(arr, 0, sizeof(arr));
38060 @@ -1492,6 +1494,8 @@ static int resp_log_sense(struct scsi_cm
38061 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
38062 unsigned char *cmd = (unsigned char *)scp->cmnd;
38063
38064 + pax_track_stack();
38065 +
38066 if ((errsts = check_readiness(scp, 1, devip)))
38067 return errsts;
38068 memset(arr, 0, sizeof(arr));
38069 diff -urNp linux-2.6.32.46/drivers/scsi/scsi_lib.c linux-2.6.32.46/drivers/scsi/scsi_lib.c
38070 --- linux-2.6.32.46/drivers/scsi/scsi_lib.c 2011-05-10 22:12:01.000000000 -0400
38071 +++ linux-2.6.32.46/drivers/scsi/scsi_lib.c 2011-05-10 22:12:33.000000000 -0400
38072 @@ -1384,7 +1384,7 @@ static void scsi_kill_request(struct req
38073
38074 scsi_init_cmd_errh(cmd);
38075 cmd->result = DID_NO_CONNECT << 16;
38076 - atomic_inc(&cmd->device->iorequest_cnt);
38077 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38078
38079 /*
38080 * SCSI request completion path will do scsi_device_unbusy(),
38081 @@ -1415,9 +1415,9 @@ static void scsi_softirq_done(struct req
38082 */
38083 cmd->serial_number = 0;
38084
38085 - atomic_inc(&cmd->device->iodone_cnt);
38086 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
38087 if (cmd->result)
38088 - atomic_inc(&cmd->device->ioerr_cnt);
38089 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38090
38091 disposition = scsi_decide_disposition(cmd);
38092 if (disposition != SUCCESS &&
38093 diff -urNp linux-2.6.32.46/drivers/scsi/scsi_sysfs.c linux-2.6.32.46/drivers/scsi/scsi_sysfs.c
38094 --- linux-2.6.32.46/drivers/scsi/scsi_sysfs.c 2011-06-25 12:55:34.000000000 -0400
38095 +++ linux-2.6.32.46/drivers/scsi/scsi_sysfs.c 2011-06-25 12:56:37.000000000 -0400
38096 @@ -662,7 +662,7 @@ show_iostat_##field(struct device *dev,
38097 char *buf) \
38098 { \
38099 struct scsi_device *sdev = to_scsi_device(dev); \
38100 - unsigned long long count = atomic_read(&sdev->field); \
38101 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
38102 return snprintf(buf, 20, "0x%llx\n", count); \
38103 } \
38104 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38105 diff -urNp linux-2.6.32.46/drivers/scsi/scsi_tgt_lib.c linux-2.6.32.46/drivers/scsi/scsi_tgt_lib.c
38106 --- linux-2.6.32.46/drivers/scsi/scsi_tgt_lib.c 2011-03-27 14:31:47.000000000 -0400
38107 +++ linux-2.6.32.46/drivers/scsi/scsi_tgt_lib.c 2011-10-06 09:37:14.000000000 -0400
38108 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct sc
38109 int err;
38110
38111 dprintk("%lx %u\n", uaddr, len);
38112 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
38113 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
38114 if (err) {
38115 /*
38116 * TODO: need to fixup sg_tablesize, max_segment_size,
38117 diff -urNp linux-2.6.32.46/drivers/scsi/scsi_transport_fc.c linux-2.6.32.46/drivers/scsi/scsi_transport_fc.c
38118 --- linux-2.6.32.46/drivers/scsi/scsi_transport_fc.c 2011-03-27 14:31:47.000000000 -0400
38119 +++ linux-2.6.32.46/drivers/scsi/scsi_transport_fc.c 2011-05-04 17:56:28.000000000 -0400
38120 @@ -480,7 +480,7 @@ MODULE_PARM_DESC(dev_loss_tmo,
38121 * Netlink Infrastructure
38122 */
38123
38124 -static atomic_t fc_event_seq;
38125 +static atomic_unchecked_t fc_event_seq;
38126
38127 /**
38128 * fc_get_event_number - Obtain the next sequential FC event number
38129 @@ -493,7 +493,7 @@ static atomic_t fc_event_seq;
38130 u32
38131 fc_get_event_number(void)
38132 {
38133 - return atomic_add_return(1, &fc_event_seq);
38134 + return atomic_add_return_unchecked(1, &fc_event_seq);
38135 }
38136 EXPORT_SYMBOL(fc_get_event_number);
38137
38138 @@ -641,7 +641,7 @@ static __init int fc_transport_init(void
38139 {
38140 int error;
38141
38142 - atomic_set(&fc_event_seq, 0);
38143 + atomic_set_unchecked(&fc_event_seq, 0);
38144
38145 error = transport_class_register(&fc_host_class);
38146 if (error)
38147 diff -urNp linux-2.6.32.46/drivers/scsi/scsi_transport_iscsi.c linux-2.6.32.46/drivers/scsi/scsi_transport_iscsi.c
38148 --- linux-2.6.32.46/drivers/scsi/scsi_transport_iscsi.c 2011-03-27 14:31:47.000000000 -0400
38149 +++ linux-2.6.32.46/drivers/scsi/scsi_transport_iscsi.c 2011-05-04 17:56:28.000000000 -0400
38150 @@ -81,7 +81,7 @@ struct iscsi_internal {
38151 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
38152 };
38153
38154 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
38155 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
38156 static struct workqueue_struct *iscsi_eh_timer_workq;
38157
38158 /*
38159 @@ -728,7 +728,7 @@ int iscsi_add_session(struct iscsi_cls_s
38160 int err;
38161
38162 ihost = shost->shost_data;
38163 - session->sid = atomic_add_return(1, &iscsi_session_nr);
38164 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
38165
38166 if (id == ISCSI_MAX_TARGET) {
38167 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
38168 @@ -2060,7 +2060,7 @@ static __init int iscsi_transport_init(v
38169 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
38170 ISCSI_TRANSPORT_VERSION);
38171
38172 - atomic_set(&iscsi_session_nr, 0);
38173 + atomic_set_unchecked(&iscsi_session_nr, 0);
38174
38175 err = class_register(&iscsi_transport_class);
38176 if (err)
38177 diff -urNp linux-2.6.32.46/drivers/scsi/scsi_transport_srp.c linux-2.6.32.46/drivers/scsi/scsi_transport_srp.c
38178 --- linux-2.6.32.46/drivers/scsi/scsi_transport_srp.c 2011-03-27 14:31:47.000000000 -0400
38179 +++ linux-2.6.32.46/drivers/scsi/scsi_transport_srp.c 2011-05-04 17:56:28.000000000 -0400
38180 @@ -33,7 +33,7 @@
38181 #include "scsi_transport_srp_internal.h"
38182
38183 struct srp_host_attrs {
38184 - atomic_t next_port_id;
38185 + atomic_unchecked_t next_port_id;
38186 };
38187 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
38188
38189 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
38190 struct Scsi_Host *shost = dev_to_shost(dev);
38191 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
38192
38193 - atomic_set(&srp_host->next_port_id, 0);
38194 + atomic_set_unchecked(&srp_host->next_port_id, 0);
38195 return 0;
38196 }
38197
38198 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
38199 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
38200 rport->roles = ids->roles;
38201
38202 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
38203 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
38204 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
38205
38206 transport_setup_device(&rport->dev);
38207 diff -urNp linux-2.6.32.46/drivers/scsi/sg.c linux-2.6.32.46/drivers/scsi/sg.c
38208 --- linux-2.6.32.46/drivers/scsi/sg.c 2011-03-27 14:31:47.000000000 -0400
38209 +++ linux-2.6.32.46/drivers/scsi/sg.c 2011-10-06 09:37:08.000000000 -0400
38210 @@ -1064,7 +1064,7 @@ sg_ioctl(struct inode *inode, struct fil
38211 sdp->disk->disk_name,
38212 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
38213 NULL,
38214 - (char *)arg);
38215 + (char __user *)arg);
38216 case BLKTRACESTART:
38217 return blk_trace_startstop(sdp->device->request_queue, 1);
38218 case BLKTRACESTOP:
38219 @@ -2292,7 +2292,7 @@ struct sg_proc_leaf {
38220 const struct file_operations * fops;
38221 };
38222
38223 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
38224 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
38225 {"allow_dio", &adio_fops},
38226 {"debug", &debug_fops},
38227 {"def_reserved_size", &dressz_fops},
38228 @@ -2307,7 +2307,7 @@ sg_proc_init(void)
38229 {
38230 int k, mask;
38231 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
38232 - struct sg_proc_leaf * leaf;
38233 + const struct sg_proc_leaf * leaf;
38234
38235 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
38236 if (!sg_proc_sgp)
38237 diff -urNp linux-2.6.32.46/drivers/scsi/sym53c8xx_2/sym_glue.c linux-2.6.32.46/drivers/scsi/sym53c8xx_2/sym_glue.c
38238 --- linux-2.6.32.46/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-03-27 14:31:47.000000000 -0400
38239 +++ linux-2.6.32.46/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-16 21:46:57.000000000 -0400
38240 @@ -1754,6 +1754,8 @@ static int __devinit sym2_probe(struct p
38241 int do_iounmap = 0;
38242 int do_disable_device = 1;
38243
38244 + pax_track_stack();
38245 +
38246 memset(&sym_dev, 0, sizeof(sym_dev));
38247 memset(&nvram, 0, sizeof(nvram));
38248 sym_dev.pdev = pdev;
38249 diff -urNp linux-2.6.32.46/drivers/serial/kgdboc.c linux-2.6.32.46/drivers/serial/kgdboc.c
38250 --- linux-2.6.32.46/drivers/serial/kgdboc.c 2011-03-27 14:31:47.000000000 -0400
38251 +++ linux-2.6.32.46/drivers/serial/kgdboc.c 2011-04-17 15:56:46.000000000 -0400
38252 @@ -18,7 +18,7 @@
38253
38254 #define MAX_CONFIG_LEN 40
38255
38256 -static struct kgdb_io kgdboc_io_ops;
38257 +static const struct kgdb_io kgdboc_io_ops;
38258
38259 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38260 static int configured = -1;
38261 @@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void
38262 module_put(THIS_MODULE);
38263 }
38264
38265 -static struct kgdb_io kgdboc_io_ops = {
38266 +static const struct kgdb_io kgdboc_io_ops = {
38267 .name = "kgdboc",
38268 .read_char = kgdboc_get_char,
38269 .write_char = kgdboc_put_char,
38270 diff -urNp linux-2.6.32.46/drivers/spi/spi.c linux-2.6.32.46/drivers/spi/spi.c
38271 --- linux-2.6.32.46/drivers/spi/spi.c 2011-03-27 14:31:47.000000000 -0400
38272 +++ linux-2.6.32.46/drivers/spi/spi.c 2011-05-04 17:56:28.000000000 -0400
38273 @@ -774,7 +774,7 @@ int spi_sync(struct spi_device *spi, str
38274 EXPORT_SYMBOL_GPL(spi_sync);
38275
38276 /* portable code must never pass more than 32 bytes */
38277 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
38278 +#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
38279
38280 static u8 *buf;
38281
38282 diff -urNp linux-2.6.32.46/drivers/staging/android/binder.c linux-2.6.32.46/drivers/staging/android/binder.c
38283 --- linux-2.6.32.46/drivers/staging/android/binder.c 2011-03-27 14:31:47.000000000 -0400
38284 +++ linux-2.6.32.46/drivers/staging/android/binder.c 2011-04-17 15:56:46.000000000 -0400
38285 @@ -2756,7 +2756,7 @@ static void binder_vma_close(struct vm_a
38286 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
38287 }
38288
38289 -static struct vm_operations_struct binder_vm_ops = {
38290 +static const struct vm_operations_struct binder_vm_ops = {
38291 .open = binder_vma_open,
38292 .close = binder_vma_close,
38293 };
38294 diff -urNp linux-2.6.32.46/drivers/staging/b3dfg/b3dfg.c linux-2.6.32.46/drivers/staging/b3dfg/b3dfg.c
38295 --- linux-2.6.32.46/drivers/staging/b3dfg/b3dfg.c 2011-03-27 14:31:47.000000000 -0400
38296 +++ linux-2.6.32.46/drivers/staging/b3dfg/b3dfg.c 2011-04-17 15:56:46.000000000 -0400
38297 @@ -455,7 +455,7 @@ static int b3dfg_vma_fault(struct vm_are
38298 return VM_FAULT_NOPAGE;
38299 }
38300
38301 -static struct vm_operations_struct b3dfg_vm_ops = {
38302 +static const struct vm_operations_struct b3dfg_vm_ops = {
38303 .fault = b3dfg_vma_fault,
38304 };
38305
38306 @@ -848,7 +848,7 @@ static int b3dfg_mmap(struct file *filp,
38307 return r;
38308 }
38309
38310 -static struct file_operations b3dfg_fops = {
38311 +static const struct file_operations b3dfg_fops = {
38312 .owner = THIS_MODULE,
38313 .open = b3dfg_open,
38314 .release = b3dfg_release,
38315 diff -urNp linux-2.6.32.46/drivers/staging/comedi/comedi_fops.c linux-2.6.32.46/drivers/staging/comedi/comedi_fops.c
38316 --- linux-2.6.32.46/drivers/staging/comedi/comedi_fops.c 2011-08-09 18:35:29.000000000 -0400
38317 +++ linux-2.6.32.46/drivers/staging/comedi/comedi_fops.c 2011-08-09 18:34:00.000000000 -0400
38318 @@ -1389,7 +1389,7 @@ void comedi_unmap(struct vm_area_struct
38319 mutex_unlock(&dev->mutex);
38320 }
38321
38322 -static struct vm_operations_struct comedi_vm_ops = {
38323 +static const struct vm_operations_struct comedi_vm_ops = {
38324 .close = comedi_unmap,
38325 };
38326
38327 diff -urNp linux-2.6.32.46/drivers/staging/dream/qdsp5/adsp_driver.c linux-2.6.32.46/drivers/staging/dream/qdsp5/adsp_driver.c
38328 --- linux-2.6.32.46/drivers/staging/dream/qdsp5/adsp_driver.c 2011-03-27 14:31:47.000000000 -0400
38329 +++ linux-2.6.32.46/drivers/staging/dream/qdsp5/adsp_driver.c 2011-04-17 15:56:46.000000000 -0400
38330 @@ -576,7 +576,7 @@ static struct adsp_device *inode_to_devi
38331 static dev_t adsp_devno;
38332 static struct class *adsp_class;
38333
38334 -static struct file_operations adsp_fops = {
38335 +static const struct file_operations adsp_fops = {
38336 .owner = THIS_MODULE,
38337 .open = adsp_open,
38338 .unlocked_ioctl = adsp_ioctl,
38339 diff -urNp linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_aac.c linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_aac.c
38340 --- linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_aac.c 2011-03-27 14:31:47.000000000 -0400
38341 +++ linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_aac.c 2011-04-17 15:56:46.000000000 -0400
38342 @@ -1022,7 +1022,7 @@ done:
38343 return rc;
38344 }
38345
38346 -static struct file_operations audio_aac_fops = {
38347 +static const struct file_operations audio_aac_fops = {
38348 .owner = THIS_MODULE,
38349 .open = audio_open,
38350 .release = audio_release,
38351 diff -urNp linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_amrnb.c linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_amrnb.c
38352 --- linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_amrnb.c 2011-03-27 14:31:47.000000000 -0400
38353 +++ linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_amrnb.c 2011-04-17 15:56:46.000000000 -0400
38354 @@ -833,7 +833,7 @@ done:
38355 return rc;
38356 }
38357
38358 -static struct file_operations audio_amrnb_fops = {
38359 +static const struct file_operations audio_amrnb_fops = {
38360 .owner = THIS_MODULE,
38361 .open = audamrnb_open,
38362 .release = audamrnb_release,
38363 diff -urNp linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_evrc.c linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_evrc.c
38364 --- linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_evrc.c 2011-03-27 14:31:47.000000000 -0400
38365 +++ linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_evrc.c 2011-04-17 15:56:46.000000000 -0400
38366 @@ -805,7 +805,7 @@ dma_fail:
38367 return rc;
38368 }
38369
38370 -static struct file_operations audio_evrc_fops = {
38371 +static const struct file_operations audio_evrc_fops = {
38372 .owner = THIS_MODULE,
38373 .open = audevrc_open,
38374 .release = audevrc_release,
38375 diff -urNp linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_in.c linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_in.c
38376 --- linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_in.c 2011-03-27 14:31:47.000000000 -0400
38377 +++ linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_in.c 2011-04-17 15:56:46.000000000 -0400
38378 @@ -913,7 +913,7 @@ static int audpre_open(struct inode *ino
38379 return 0;
38380 }
38381
38382 -static struct file_operations audio_fops = {
38383 +static const struct file_operations audio_fops = {
38384 .owner = THIS_MODULE,
38385 .open = audio_in_open,
38386 .release = audio_in_release,
38387 @@ -922,7 +922,7 @@ static struct file_operations audio_fops
38388 .unlocked_ioctl = audio_in_ioctl,
38389 };
38390
38391 -static struct file_operations audpre_fops = {
38392 +static const struct file_operations audpre_fops = {
38393 .owner = THIS_MODULE,
38394 .open = audpre_open,
38395 .unlocked_ioctl = audpre_ioctl,
38396 diff -urNp linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_mp3.c linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_mp3.c
38397 --- linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_mp3.c 2011-03-27 14:31:47.000000000 -0400
38398 +++ linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_mp3.c 2011-04-17 15:56:46.000000000 -0400
38399 @@ -941,7 +941,7 @@ done:
38400 return rc;
38401 }
38402
38403 -static struct file_operations audio_mp3_fops = {
38404 +static const struct file_operations audio_mp3_fops = {
38405 .owner = THIS_MODULE,
38406 .open = audio_open,
38407 .release = audio_release,
38408 diff -urNp linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_out.c linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_out.c
38409 --- linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_out.c 2011-03-27 14:31:47.000000000 -0400
38410 +++ linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_out.c 2011-04-17 15:56:46.000000000 -0400
38411 @@ -810,7 +810,7 @@ static int audpp_open(struct inode *inod
38412 return 0;
38413 }
38414
38415 -static struct file_operations audio_fops = {
38416 +static const struct file_operations audio_fops = {
38417 .owner = THIS_MODULE,
38418 .open = audio_open,
38419 .release = audio_release,
38420 @@ -819,7 +819,7 @@ static struct file_operations audio_fops
38421 .unlocked_ioctl = audio_ioctl,
38422 };
38423
38424 -static struct file_operations audpp_fops = {
38425 +static const struct file_operations audpp_fops = {
38426 .owner = THIS_MODULE,
38427 .open = audpp_open,
38428 .unlocked_ioctl = audpp_ioctl,
38429 diff -urNp linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_qcelp.c linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_qcelp.c
38430 --- linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_qcelp.c 2011-03-27 14:31:47.000000000 -0400
38431 +++ linux-2.6.32.46/drivers/staging/dream/qdsp5/audio_qcelp.c 2011-04-17 15:56:46.000000000 -0400
38432 @@ -816,7 +816,7 @@ err:
38433 return rc;
38434 }
38435
38436 -static struct file_operations audio_qcelp_fops = {
38437 +static const struct file_operations audio_qcelp_fops = {
38438 .owner = THIS_MODULE,
38439 .open = audqcelp_open,
38440 .release = audqcelp_release,
38441 diff -urNp linux-2.6.32.46/drivers/staging/dream/qdsp5/snd.c linux-2.6.32.46/drivers/staging/dream/qdsp5/snd.c
38442 --- linux-2.6.32.46/drivers/staging/dream/qdsp5/snd.c 2011-03-27 14:31:47.000000000 -0400
38443 +++ linux-2.6.32.46/drivers/staging/dream/qdsp5/snd.c 2011-04-17 15:56:46.000000000 -0400
38444 @@ -242,7 +242,7 @@ err:
38445 return rc;
38446 }
38447
38448 -static struct file_operations snd_fops = {
38449 +static const struct file_operations snd_fops = {
38450 .owner = THIS_MODULE,
38451 .open = snd_open,
38452 .release = snd_release,
38453 diff -urNp linux-2.6.32.46/drivers/staging/dream/smd/smd_qmi.c linux-2.6.32.46/drivers/staging/dream/smd/smd_qmi.c
38454 --- linux-2.6.32.46/drivers/staging/dream/smd/smd_qmi.c 2011-03-27 14:31:47.000000000 -0400
38455 +++ linux-2.6.32.46/drivers/staging/dream/smd/smd_qmi.c 2011-04-17 15:56:46.000000000 -0400
38456 @@ -793,7 +793,7 @@ static int qmi_release(struct inode *ip,
38457 return 0;
38458 }
38459
38460 -static struct file_operations qmi_fops = {
38461 +static const struct file_operations qmi_fops = {
38462 .owner = THIS_MODULE,
38463 .read = qmi_read,
38464 .write = qmi_write,
38465 diff -urNp linux-2.6.32.46/drivers/staging/dream/smd/smd_rpcrouter_device.c linux-2.6.32.46/drivers/staging/dream/smd/smd_rpcrouter_device.c
38466 --- linux-2.6.32.46/drivers/staging/dream/smd/smd_rpcrouter_device.c 2011-03-27 14:31:47.000000000 -0400
38467 +++ linux-2.6.32.46/drivers/staging/dream/smd/smd_rpcrouter_device.c 2011-04-17 15:56:46.000000000 -0400
38468 @@ -214,7 +214,7 @@ static long rpcrouter_ioctl(struct file
38469 return rc;
38470 }
38471
38472 -static struct file_operations rpcrouter_server_fops = {
38473 +static const struct file_operations rpcrouter_server_fops = {
38474 .owner = THIS_MODULE,
38475 .open = rpcrouter_open,
38476 .release = rpcrouter_release,
38477 @@ -224,7 +224,7 @@ static struct file_operations rpcrouter_
38478 .unlocked_ioctl = rpcrouter_ioctl,
38479 };
38480
38481 -static struct file_operations rpcrouter_router_fops = {
38482 +static const struct file_operations rpcrouter_router_fops = {
38483 .owner = THIS_MODULE,
38484 .open = rpcrouter_open,
38485 .release = rpcrouter_release,
38486 diff -urNp linux-2.6.32.46/drivers/staging/dst/dcore.c linux-2.6.32.46/drivers/staging/dst/dcore.c
38487 --- linux-2.6.32.46/drivers/staging/dst/dcore.c 2011-03-27 14:31:47.000000000 -0400
38488 +++ linux-2.6.32.46/drivers/staging/dst/dcore.c 2011-04-17 15:56:46.000000000 -0400
38489 @@ -149,7 +149,7 @@ static int dst_bdev_release(struct gendi
38490 return 0;
38491 }
38492
38493 -static struct block_device_operations dst_blk_ops = {
38494 +static const struct block_device_operations dst_blk_ops = {
38495 .open = dst_bdev_open,
38496 .release = dst_bdev_release,
38497 .owner = THIS_MODULE,
38498 @@ -588,7 +588,7 @@ static struct dst_node *dst_alloc_node(s
38499 n->size = ctl->size;
38500
38501 atomic_set(&n->refcnt, 1);
38502 - atomic_long_set(&n->gen, 0);
38503 + atomic_long_set_unchecked(&n->gen, 0);
38504 snprintf(n->name, sizeof(n->name), "%s", ctl->name);
38505
38506 err = dst_node_sysfs_init(n);
38507 diff -urNp linux-2.6.32.46/drivers/staging/dst/trans.c linux-2.6.32.46/drivers/staging/dst/trans.c
38508 --- linux-2.6.32.46/drivers/staging/dst/trans.c 2011-03-27 14:31:47.000000000 -0400
38509 +++ linux-2.6.32.46/drivers/staging/dst/trans.c 2011-04-17 15:56:46.000000000 -0400
38510 @@ -169,7 +169,7 @@ int dst_process_bio(struct dst_node *n,
38511 t->error = 0;
38512 t->retries = 0;
38513 atomic_set(&t->refcnt, 1);
38514 - t->gen = atomic_long_inc_return(&n->gen);
38515 + t->gen = atomic_long_inc_return_unchecked(&n->gen);
38516
38517 t->enc = bio_data_dir(bio);
38518 dst_bio_to_cmd(bio, &t->cmd, DST_IO, t->gen);
38519 diff -urNp linux-2.6.32.46/drivers/staging/et131x/et1310_tx.c linux-2.6.32.46/drivers/staging/et131x/et1310_tx.c
38520 --- linux-2.6.32.46/drivers/staging/et131x/et1310_tx.c 2011-03-27 14:31:47.000000000 -0400
38521 +++ linux-2.6.32.46/drivers/staging/et131x/et1310_tx.c 2011-05-04 17:56:28.000000000 -0400
38522 @@ -710,11 +710,11 @@ inline void et131x_free_send_packet(stru
38523 struct net_device_stats *stats = &etdev->net_stats;
38524
38525 if (pMpTcb->Flags & fMP_DEST_BROAD)
38526 - atomic_inc(&etdev->Stats.brdcstxmt);
38527 + atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
38528 else if (pMpTcb->Flags & fMP_DEST_MULTI)
38529 - atomic_inc(&etdev->Stats.multixmt);
38530 + atomic_inc_unchecked(&etdev->Stats.multixmt);
38531 else
38532 - atomic_inc(&etdev->Stats.unixmt);
38533 + atomic_inc_unchecked(&etdev->Stats.unixmt);
38534
38535 if (pMpTcb->Packet) {
38536 stats->tx_bytes += pMpTcb->Packet->len;
38537 diff -urNp linux-2.6.32.46/drivers/staging/et131x/et131x_adapter.h linux-2.6.32.46/drivers/staging/et131x/et131x_adapter.h
38538 --- linux-2.6.32.46/drivers/staging/et131x/et131x_adapter.h 2011-03-27 14:31:47.000000000 -0400
38539 +++ linux-2.6.32.46/drivers/staging/et131x/et131x_adapter.h 2011-05-04 17:56:28.000000000 -0400
38540 @@ -145,11 +145,11 @@ typedef struct _ce_stats_t {
38541 * operations
38542 */
38543 u32 unircv; /* # multicast packets received */
38544 - atomic_t unixmt; /* # multicast packets for Tx */
38545 + atomic_unchecked_t unixmt; /* # multicast packets for Tx */
38546 u32 multircv; /* # multicast packets received */
38547 - atomic_t multixmt; /* # multicast packets for Tx */
38548 + atomic_unchecked_t multixmt; /* # multicast packets for Tx */
38549 u32 brdcstrcv; /* # broadcast packets received */
38550 - atomic_t brdcstxmt; /* # broadcast packets for Tx */
38551 + atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
38552 u32 norcvbuf; /* # Rx packets discarded */
38553 u32 noxmtbuf; /* # Tx packets discarded */
38554
38555 diff -urNp linux-2.6.32.46/drivers/staging/go7007/go7007-v4l2.c linux-2.6.32.46/drivers/staging/go7007/go7007-v4l2.c
38556 --- linux-2.6.32.46/drivers/staging/go7007/go7007-v4l2.c 2011-03-27 14:31:47.000000000 -0400
38557 +++ linux-2.6.32.46/drivers/staging/go7007/go7007-v4l2.c 2011-04-17 15:56:46.000000000 -0400
38558 @@ -1700,7 +1700,7 @@ static int go7007_vm_fault(struct vm_are
38559 return 0;
38560 }
38561
38562 -static struct vm_operations_struct go7007_vm_ops = {
38563 +static const struct vm_operations_struct go7007_vm_ops = {
38564 .open = go7007_vm_open,
38565 .close = go7007_vm_close,
38566 .fault = go7007_vm_fault,
38567 diff -urNp linux-2.6.32.46/drivers/staging/hv/Channel.c linux-2.6.32.46/drivers/staging/hv/Channel.c
38568 --- linux-2.6.32.46/drivers/staging/hv/Channel.c 2011-04-17 17:00:52.000000000 -0400
38569 +++ linux-2.6.32.46/drivers/staging/hv/Channel.c 2011-05-04 17:56:28.000000000 -0400
38570 @@ -464,8 +464,8 @@ int VmbusChannelEstablishGpadl(struct vm
38571
38572 DPRINT_ENTER(VMBUS);
38573
38574 - nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
38575 - atomic_inc(&gVmbusConnection.NextGpadlHandle);
38576 + nextGpadlHandle = atomic_read_unchecked(&gVmbusConnection.NextGpadlHandle);
38577 + atomic_inc_unchecked(&gVmbusConnection.NextGpadlHandle);
38578
38579 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
38580 ASSERT(msgInfo != NULL);
38581 diff -urNp linux-2.6.32.46/drivers/staging/hv/Hv.c linux-2.6.32.46/drivers/staging/hv/Hv.c
38582 --- linux-2.6.32.46/drivers/staging/hv/Hv.c 2011-03-27 14:31:47.000000000 -0400
38583 +++ linux-2.6.32.46/drivers/staging/hv/Hv.c 2011-04-17 15:56:46.000000000 -0400
38584 @@ -161,7 +161,7 @@ static u64 HvDoHypercall(u64 Control, vo
38585 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
38586 u32 outputAddressHi = outputAddress >> 32;
38587 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
38588 - volatile void *hypercallPage = gHvContext.HypercallPage;
38589 + volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
38590
38591 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
38592 Control, Input, Output);
38593 diff -urNp linux-2.6.32.46/drivers/staging/hv/VmbusApi.h linux-2.6.32.46/drivers/staging/hv/VmbusApi.h
38594 --- linux-2.6.32.46/drivers/staging/hv/VmbusApi.h 2011-03-27 14:31:47.000000000 -0400
38595 +++ linux-2.6.32.46/drivers/staging/hv/VmbusApi.h 2011-08-29 22:32:57.000000000 -0400
38596 @@ -109,7 +109,7 @@ struct vmbus_channel_interface {
38597 u32 *GpadlHandle);
38598 int (*TeardownGpadl)(struct hv_device *device, u32 GpadlHandle);
38599 void (*GetInfo)(struct hv_device *dev, struct hv_device_info *devinfo);
38600 -};
38601 +} __no_const;
38602
38603 /* Base driver object */
38604 struct hv_driver {
38605 diff -urNp linux-2.6.32.46/drivers/staging/hv/VmbusPrivate.h linux-2.6.32.46/drivers/staging/hv/VmbusPrivate.h
38606 --- linux-2.6.32.46/drivers/staging/hv/VmbusPrivate.h 2011-04-17 17:00:52.000000000 -0400
38607 +++ linux-2.6.32.46/drivers/staging/hv/VmbusPrivate.h 2011-05-04 17:56:28.000000000 -0400
38608 @@ -59,7 +59,7 @@ enum VMBUS_CONNECT_STATE {
38609 struct VMBUS_CONNECTION {
38610 enum VMBUS_CONNECT_STATE ConnectState;
38611
38612 - atomic_t NextGpadlHandle;
38613 + atomic_unchecked_t NextGpadlHandle;
38614
38615 /*
38616 * Represents channel interrupts. Each bit position represents a
38617 diff -urNp linux-2.6.32.46/drivers/staging/hv/blkvsc_drv.c linux-2.6.32.46/drivers/staging/hv/blkvsc_drv.c
38618 --- linux-2.6.32.46/drivers/staging/hv/blkvsc_drv.c 2011-03-27 14:31:47.000000000 -0400
38619 +++ linux-2.6.32.46/drivers/staging/hv/blkvsc_drv.c 2011-04-17 15:56:46.000000000 -0400
38620 @@ -153,7 +153,7 @@ static int blkvsc_ringbuffer_size = BLKV
38621 /* The one and only one */
38622 static struct blkvsc_driver_context g_blkvsc_drv;
38623
38624 -static struct block_device_operations block_ops = {
38625 +static const struct block_device_operations block_ops = {
38626 .owner = THIS_MODULE,
38627 .open = blkvsc_open,
38628 .release = blkvsc_release,
38629 diff -urNp linux-2.6.32.46/drivers/staging/hv/vmbus_drv.c linux-2.6.32.46/drivers/staging/hv/vmbus_drv.c
38630 --- linux-2.6.32.46/drivers/staging/hv/vmbus_drv.c 2011-03-27 14:31:47.000000000 -0400
38631 +++ linux-2.6.32.46/drivers/staging/hv/vmbus_drv.c 2011-05-04 17:56:28.000000000 -0400
38632 @@ -532,7 +532,7 @@ static int vmbus_child_device_register(s
38633 to_device_context(root_device_obj);
38634 struct device_context *child_device_ctx =
38635 to_device_context(child_device_obj);
38636 - static atomic_t device_num = ATOMIC_INIT(0);
38637 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
38638
38639 DPRINT_ENTER(VMBUS_DRV);
38640
38641 @@ -541,7 +541,7 @@ static int vmbus_child_device_register(s
38642
38643 /* Set the device name. Otherwise, device_register() will fail. */
38644 dev_set_name(&child_device_ctx->device, "vmbus_0_%d",
38645 - atomic_inc_return(&device_num));
38646 + atomic_inc_return_unchecked(&device_num));
38647
38648 /* The new device belongs to this bus */
38649 child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
38650 diff -urNp linux-2.6.32.46/drivers/staging/iio/ring_generic.h linux-2.6.32.46/drivers/staging/iio/ring_generic.h
38651 --- linux-2.6.32.46/drivers/staging/iio/ring_generic.h 2011-03-27 14:31:47.000000000 -0400
38652 +++ linux-2.6.32.46/drivers/staging/iio/ring_generic.h 2011-08-23 20:24:26.000000000 -0400
38653 @@ -87,7 +87,7 @@ struct iio_ring_access_funcs {
38654
38655 int (*is_enabled)(struct iio_ring_buffer *ring);
38656 int (*enable)(struct iio_ring_buffer *ring);
38657 -};
38658 +} __no_const;
38659
38660 /**
38661 * struct iio_ring_buffer - general ring buffer structure
38662 diff -urNp linux-2.6.32.46/drivers/staging/octeon/ethernet-rx.c linux-2.6.32.46/drivers/staging/octeon/ethernet-rx.c
38663 --- linux-2.6.32.46/drivers/staging/octeon/ethernet-rx.c 2011-03-27 14:31:47.000000000 -0400
38664 +++ linux-2.6.32.46/drivers/staging/octeon/ethernet-rx.c 2011-05-04 17:56:28.000000000 -0400
38665 @@ -406,11 +406,11 @@ void cvm_oct_tasklet_rx(unsigned long un
38666 /* Increment RX stats for virtual ports */
38667 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
38668 #ifdef CONFIG_64BIT
38669 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
38670 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
38671 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
38672 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
38673 #else
38674 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
38675 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
38676 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
38677 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
38678 #endif
38679 }
38680 netif_receive_skb(skb);
38681 @@ -424,9 +424,9 @@ void cvm_oct_tasklet_rx(unsigned long un
38682 dev->name);
38683 */
38684 #ifdef CONFIG_64BIT
38685 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
38686 + atomic64_add_unchecked(1, (atomic64_t *)&priv->stats.rx_dropped);
38687 #else
38688 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
38689 + atomic_add_unchecked(1, (atomic_t *)&priv->stats.rx_dropped);
38690 #endif
38691 dev_kfree_skb_irq(skb);
38692 }
38693 diff -urNp linux-2.6.32.46/drivers/staging/octeon/ethernet.c linux-2.6.32.46/drivers/staging/octeon/ethernet.c
38694 --- linux-2.6.32.46/drivers/staging/octeon/ethernet.c 2011-03-27 14:31:47.000000000 -0400
38695 +++ linux-2.6.32.46/drivers/staging/octeon/ethernet.c 2011-05-04 17:56:28.000000000 -0400
38696 @@ -294,11 +294,11 @@ static struct net_device_stats *cvm_oct_
38697 * since the RX tasklet also increments it.
38698 */
38699 #ifdef CONFIG_64BIT
38700 - atomic64_add(rx_status.dropped_packets,
38701 - (atomic64_t *)&priv->stats.rx_dropped);
38702 + atomic64_add_unchecked(rx_status.dropped_packets,
38703 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38704 #else
38705 - atomic_add(rx_status.dropped_packets,
38706 - (atomic_t *)&priv->stats.rx_dropped);
38707 + atomic_add_unchecked(rx_status.dropped_packets,
38708 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
38709 #endif
38710 }
38711
38712 diff -urNp linux-2.6.32.46/drivers/staging/panel/panel.c linux-2.6.32.46/drivers/staging/panel/panel.c
38713 --- linux-2.6.32.46/drivers/staging/panel/panel.c 2011-03-27 14:31:47.000000000 -0400
38714 +++ linux-2.6.32.46/drivers/staging/panel/panel.c 2011-04-17 15:56:46.000000000 -0400
38715 @@ -1305,7 +1305,7 @@ static int lcd_release(struct inode *ino
38716 return 0;
38717 }
38718
38719 -static struct file_operations lcd_fops = {
38720 +static const struct file_operations lcd_fops = {
38721 .write = lcd_write,
38722 .open = lcd_open,
38723 .release = lcd_release,
38724 @@ -1565,7 +1565,7 @@ static int keypad_release(struct inode *
38725 return 0;
38726 }
38727
38728 -static struct file_operations keypad_fops = {
38729 +static const struct file_operations keypad_fops = {
38730 .read = keypad_read, /* read */
38731 .open = keypad_open, /* open */
38732 .release = keypad_release, /* close */
38733 diff -urNp linux-2.6.32.46/drivers/staging/phison/phison.c linux-2.6.32.46/drivers/staging/phison/phison.c
38734 --- linux-2.6.32.46/drivers/staging/phison/phison.c 2011-03-27 14:31:47.000000000 -0400
38735 +++ linux-2.6.32.46/drivers/staging/phison/phison.c 2011-04-17 15:56:46.000000000 -0400
38736 @@ -43,7 +43,7 @@ static struct scsi_host_template phison_
38737 ATA_BMDMA_SHT(DRV_NAME),
38738 };
38739
38740 -static struct ata_port_operations phison_ops = {
38741 +static const struct ata_port_operations phison_ops = {
38742 .inherits = &ata_bmdma_port_ops,
38743 .prereset = phison_pre_reset,
38744 };
38745 diff -urNp linux-2.6.32.46/drivers/staging/poch/poch.c linux-2.6.32.46/drivers/staging/poch/poch.c
38746 --- linux-2.6.32.46/drivers/staging/poch/poch.c 2011-03-27 14:31:47.000000000 -0400
38747 +++ linux-2.6.32.46/drivers/staging/poch/poch.c 2011-04-17 15:56:46.000000000 -0400
38748 @@ -1057,7 +1057,7 @@ static int poch_ioctl(struct inode *inod
38749 return 0;
38750 }
38751
38752 -static struct file_operations poch_fops = {
38753 +static const struct file_operations poch_fops = {
38754 .owner = THIS_MODULE,
38755 .open = poch_open,
38756 .release = poch_release,
38757 diff -urNp linux-2.6.32.46/drivers/staging/pohmelfs/inode.c linux-2.6.32.46/drivers/staging/pohmelfs/inode.c
38758 --- linux-2.6.32.46/drivers/staging/pohmelfs/inode.c 2011-03-27 14:31:47.000000000 -0400
38759 +++ linux-2.6.32.46/drivers/staging/pohmelfs/inode.c 2011-05-04 17:56:20.000000000 -0400
38760 @@ -1850,7 +1850,7 @@ static int pohmelfs_fill_super(struct su
38761 mutex_init(&psb->mcache_lock);
38762 psb->mcache_root = RB_ROOT;
38763 psb->mcache_timeout = msecs_to_jiffies(5000);
38764 - atomic_long_set(&psb->mcache_gen, 0);
38765 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
38766
38767 psb->trans_max_pages = 100;
38768
38769 @@ -1865,7 +1865,7 @@ static int pohmelfs_fill_super(struct su
38770 INIT_LIST_HEAD(&psb->crypto_ready_list);
38771 INIT_LIST_HEAD(&psb->crypto_active_list);
38772
38773 - atomic_set(&psb->trans_gen, 1);
38774 + atomic_set_unchecked(&psb->trans_gen, 1);
38775 atomic_long_set(&psb->total_inodes, 0);
38776
38777 mutex_init(&psb->state_lock);
38778 diff -urNp linux-2.6.32.46/drivers/staging/pohmelfs/mcache.c linux-2.6.32.46/drivers/staging/pohmelfs/mcache.c
38779 --- linux-2.6.32.46/drivers/staging/pohmelfs/mcache.c 2011-03-27 14:31:47.000000000 -0400
38780 +++ linux-2.6.32.46/drivers/staging/pohmelfs/mcache.c 2011-04-17 15:56:46.000000000 -0400
38781 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
38782 m->data = data;
38783 m->start = start;
38784 m->size = size;
38785 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
38786 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
38787
38788 mutex_lock(&psb->mcache_lock);
38789 err = pohmelfs_mcache_insert(psb, m);
38790 diff -urNp linux-2.6.32.46/drivers/staging/pohmelfs/netfs.h linux-2.6.32.46/drivers/staging/pohmelfs/netfs.h
38791 --- linux-2.6.32.46/drivers/staging/pohmelfs/netfs.h 2011-03-27 14:31:47.000000000 -0400
38792 +++ linux-2.6.32.46/drivers/staging/pohmelfs/netfs.h 2011-05-04 17:56:20.000000000 -0400
38793 @@ -570,14 +570,14 @@ struct pohmelfs_config;
38794 struct pohmelfs_sb {
38795 struct rb_root mcache_root;
38796 struct mutex mcache_lock;
38797 - atomic_long_t mcache_gen;
38798 + atomic_long_unchecked_t mcache_gen;
38799 unsigned long mcache_timeout;
38800
38801 unsigned int idx;
38802
38803 unsigned int trans_retries;
38804
38805 - atomic_t trans_gen;
38806 + atomic_unchecked_t trans_gen;
38807
38808 unsigned int crypto_attached_size;
38809 unsigned int crypto_align_size;
38810 diff -urNp linux-2.6.32.46/drivers/staging/pohmelfs/trans.c linux-2.6.32.46/drivers/staging/pohmelfs/trans.c
38811 --- linux-2.6.32.46/drivers/staging/pohmelfs/trans.c 2011-03-27 14:31:47.000000000 -0400
38812 +++ linux-2.6.32.46/drivers/staging/pohmelfs/trans.c 2011-05-04 17:56:28.000000000 -0400
38813 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
38814 int err;
38815 struct netfs_cmd *cmd = t->iovec.iov_base;
38816
38817 - t->gen = atomic_inc_return(&psb->trans_gen);
38818 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
38819
38820 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
38821 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
38822 diff -urNp linux-2.6.32.46/drivers/staging/sep/sep_driver.c linux-2.6.32.46/drivers/staging/sep/sep_driver.c
38823 --- linux-2.6.32.46/drivers/staging/sep/sep_driver.c 2011-03-27 14:31:47.000000000 -0400
38824 +++ linux-2.6.32.46/drivers/staging/sep/sep_driver.c 2011-04-17 15:56:46.000000000 -0400
38825 @@ -2603,7 +2603,7 @@ static struct pci_driver sep_pci_driver
38826 static dev_t sep_devno;
38827
38828 /* the files operations structure of the driver */
38829 -static struct file_operations sep_file_operations = {
38830 +static const struct file_operations sep_file_operations = {
38831 .owner = THIS_MODULE,
38832 .ioctl = sep_ioctl,
38833 .poll = sep_poll,
38834 diff -urNp linux-2.6.32.46/drivers/staging/usbip/usbip_common.h linux-2.6.32.46/drivers/staging/usbip/usbip_common.h
38835 --- linux-2.6.32.46/drivers/staging/usbip/usbip_common.h 2011-04-17 17:00:52.000000000 -0400
38836 +++ linux-2.6.32.46/drivers/staging/usbip/usbip_common.h 2011-08-23 20:24:26.000000000 -0400
38837 @@ -374,7 +374,7 @@ struct usbip_device {
38838 void (*shutdown)(struct usbip_device *);
38839 void (*reset)(struct usbip_device *);
38840 void (*unusable)(struct usbip_device *);
38841 - } eh_ops;
38842 + } __no_const eh_ops;
38843 };
38844
38845
38846 diff -urNp linux-2.6.32.46/drivers/staging/usbip/vhci.h linux-2.6.32.46/drivers/staging/usbip/vhci.h
38847 --- linux-2.6.32.46/drivers/staging/usbip/vhci.h 2011-03-27 14:31:47.000000000 -0400
38848 +++ linux-2.6.32.46/drivers/staging/usbip/vhci.h 2011-05-04 17:56:28.000000000 -0400
38849 @@ -92,7 +92,7 @@ struct vhci_hcd {
38850 unsigned resuming:1;
38851 unsigned long re_timeout;
38852
38853 - atomic_t seqnum;
38854 + atomic_unchecked_t seqnum;
38855
38856 /*
38857 * NOTE:
38858 diff -urNp linux-2.6.32.46/drivers/staging/usbip/vhci_hcd.c linux-2.6.32.46/drivers/staging/usbip/vhci_hcd.c
38859 --- linux-2.6.32.46/drivers/staging/usbip/vhci_hcd.c 2011-05-10 22:12:01.000000000 -0400
38860 +++ linux-2.6.32.46/drivers/staging/usbip/vhci_hcd.c 2011-05-10 22:12:33.000000000 -0400
38861 @@ -534,7 +534,7 @@ static void vhci_tx_urb(struct urb *urb)
38862 return;
38863 }
38864
38865 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
38866 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38867 if (priv->seqnum == 0xffff)
38868 usbip_uinfo("seqnum max\n");
38869
38870 @@ -793,7 +793,7 @@ static int vhci_urb_dequeue(struct usb_h
38871 return -ENOMEM;
38872 }
38873
38874 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
38875 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38876 if (unlink->seqnum == 0xffff)
38877 usbip_uinfo("seqnum max\n");
38878
38879 @@ -988,7 +988,7 @@ static int vhci_start(struct usb_hcd *hc
38880 vdev->rhport = rhport;
38881 }
38882
38883 - atomic_set(&vhci->seqnum, 0);
38884 + atomic_set_unchecked(&vhci->seqnum, 0);
38885 spin_lock_init(&vhci->lock);
38886
38887
38888 diff -urNp linux-2.6.32.46/drivers/staging/usbip/vhci_rx.c linux-2.6.32.46/drivers/staging/usbip/vhci_rx.c
38889 --- linux-2.6.32.46/drivers/staging/usbip/vhci_rx.c 2011-04-17 17:00:52.000000000 -0400
38890 +++ linux-2.6.32.46/drivers/staging/usbip/vhci_rx.c 2011-05-04 17:56:28.000000000 -0400
38891 @@ -78,7 +78,7 @@ static void vhci_recv_ret_submit(struct
38892 usbip_uerr("cannot find a urb of seqnum %u\n",
38893 pdu->base.seqnum);
38894 usbip_uinfo("max seqnum %d\n",
38895 - atomic_read(&the_controller->seqnum));
38896 + atomic_read_unchecked(&the_controller->seqnum));
38897 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38898 return;
38899 }
38900 diff -urNp linux-2.6.32.46/drivers/staging/vme/devices/vme_user.c linux-2.6.32.46/drivers/staging/vme/devices/vme_user.c
38901 --- linux-2.6.32.46/drivers/staging/vme/devices/vme_user.c 2011-03-27 14:31:47.000000000 -0400
38902 +++ linux-2.6.32.46/drivers/staging/vme/devices/vme_user.c 2011-04-17 15:56:46.000000000 -0400
38903 @@ -136,7 +136,7 @@ static int vme_user_ioctl(struct inode *
38904 static int __init vme_user_probe(struct device *, int, int);
38905 static int __exit vme_user_remove(struct device *, int, int);
38906
38907 -static struct file_operations vme_user_fops = {
38908 +static const struct file_operations vme_user_fops = {
38909 .open = vme_user_open,
38910 .release = vme_user_release,
38911 .read = vme_user_read,
38912 diff -urNp linux-2.6.32.46/drivers/staging/vt6655/hostap.c linux-2.6.32.46/drivers/staging/vt6655/hostap.c
38913 --- linux-2.6.32.46/drivers/staging/vt6655/hostap.c 2011-03-27 14:31:47.000000000 -0400
38914 +++ linux-2.6.32.46/drivers/staging/vt6655/hostap.c 2011-09-14 09:51:07.000000000 -0400
38915 @@ -84,7 +84,7 @@ static int hostap_enable_hostapd(PSDevic
38916 PSDevice apdev_priv;
38917 struct net_device *dev = pDevice->dev;
38918 int ret;
38919 - const struct net_device_ops apdev_netdev_ops = {
38920 + net_device_ops_no_const apdev_netdev_ops = {
38921 .ndo_start_xmit = pDevice->tx_80211,
38922 };
38923
38924 diff -urNp linux-2.6.32.46/drivers/staging/vt6656/hostap.c linux-2.6.32.46/drivers/staging/vt6656/hostap.c
38925 --- linux-2.6.32.46/drivers/staging/vt6656/hostap.c 2011-03-27 14:31:47.000000000 -0400
38926 +++ linux-2.6.32.46/drivers/staging/vt6656/hostap.c 2011-09-14 09:49:53.000000000 -0400
38927 @@ -86,7 +86,7 @@ static int hostap_enable_hostapd(PSDevic
38928 PSDevice apdev_priv;
38929 struct net_device *dev = pDevice->dev;
38930 int ret;
38931 - const struct net_device_ops apdev_netdev_ops = {
38932 + net_device_ops_no_const apdev_netdev_ops = {
38933 .ndo_start_xmit = pDevice->tx_80211,
38934 };
38935
38936 diff -urNp linux-2.6.32.46/drivers/staging/wlan-ng/hfa384x_usb.c linux-2.6.32.46/drivers/staging/wlan-ng/hfa384x_usb.c
38937 --- linux-2.6.32.46/drivers/staging/wlan-ng/hfa384x_usb.c 2011-03-27 14:31:47.000000000 -0400
38938 +++ linux-2.6.32.46/drivers/staging/wlan-ng/hfa384x_usb.c 2011-08-23 20:24:26.000000000 -0400
38939 @@ -205,7 +205,7 @@ static void unlocked_usbctlx_complete(hf
38940
38941 struct usbctlx_completor {
38942 int (*complete) (struct usbctlx_completor *);
38943 -};
38944 +} __no_const;
38945 typedef struct usbctlx_completor usbctlx_completor_t;
38946
38947 static int
38948 diff -urNp linux-2.6.32.46/drivers/telephony/ixj.c linux-2.6.32.46/drivers/telephony/ixj.c
38949 --- linux-2.6.32.46/drivers/telephony/ixj.c 2011-03-27 14:31:47.000000000 -0400
38950 +++ linux-2.6.32.46/drivers/telephony/ixj.c 2011-05-16 21:46:57.000000000 -0400
38951 @@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
38952 bool mContinue;
38953 char *pIn, *pOut;
38954
38955 + pax_track_stack();
38956 +
38957 if (!SCI_Prepare(j))
38958 return 0;
38959
38960 diff -urNp linux-2.6.32.46/drivers/uio/uio.c linux-2.6.32.46/drivers/uio/uio.c
38961 --- linux-2.6.32.46/drivers/uio/uio.c 2011-03-27 14:31:47.000000000 -0400
38962 +++ linux-2.6.32.46/drivers/uio/uio.c 2011-05-04 17:56:20.000000000 -0400
38963 @@ -23,6 +23,7 @@
38964 #include <linux/string.h>
38965 #include <linux/kobject.h>
38966 #include <linux/uio_driver.h>
38967 +#include <asm/local.h>
38968
38969 #define UIO_MAX_DEVICES 255
38970
38971 @@ -30,10 +31,10 @@ struct uio_device {
38972 struct module *owner;
38973 struct device *dev;
38974 int minor;
38975 - atomic_t event;
38976 + atomic_unchecked_t event;
38977 struct fasync_struct *async_queue;
38978 wait_queue_head_t wait;
38979 - int vma_count;
38980 + local_t vma_count;
38981 struct uio_info *info;
38982 struct kobject *map_dir;
38983 struct kobject *portio_dir;
38984 @@ -129,7 +130,7 @@ static ssize_t map_type_show(struct kobj
38985 return entry->show(mem, buf);
38986 }
38987
38988 -static struct sysfs_ops map_sysfs_ops = {
38989 +static const struct sysfs_ops map_sysfs_ops = {
38990 .show = map_type_show,
38991 };
38992
38993 @@ -217,7 +218,7 @@ static ssize_t portio_type_show(struct k
38994 return entry->show(port, buf);
38995 }
38996
38997 -static struct sysfs_ops portio_sysfs_ops = {
38998 +static const struct sysfs_ops portio_sysfs_ops = {
38999 .show = portio_type_show,
39000 };
39001
39002 @@ -255,7 +256,7 @@ static ssize_t show_event(struct device
39003 struct uio_device *idev = dev_get_drvdata(dev);
39004 if (idev)
39005 return sprintf(buf, "%u\n",
39006 - (unsigned int)atomic_read(&idev->event));
39007 + (unsigned int)atomic_read_unchecked(&idev->event));
39008 else
39009 return -ENODEV;
39010 }
39011 @@ -424,7 +425,7 @@ void uio_event_notify(struct uio_info *i
39012 {
39013 struct uio_device *idev = info->uio_dev;
39014
39015 - atomic_inc(&idev->event);
39016 + atomic_inc_unchecked(&idev->event);
39017 wake_up_interruptible(&idev->wait);
39018 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39019 }
39020 @@ -477,7 +478,7 @@ static int uio_open(struct inode *inode,
39021 }
39022
39023 listener->dev = idev;
39024 - listener->event_count = atomic_read(&idev->event);
39025 + listener->event_count = atomic_read_unchecked(&idev->event);
39026 filep->private_data = listener;
39027
39028 if (idev->info->open) {
39029 @@ -528,7 +529,7 @@ static unsigned int uio_poll(struct file
39030 return -EIO;
39031
39032 poll_wait(filep, &idev->wait, wait);
39033 - if (listener->event_count != atomic_read(&idev->event))
39034 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39035 return POLLIN | POLLRDNORM;
39036 return 0;
39037 }
39038 @@ -553,7 +554,7 @@ static ssize_t uio_read(struct file *fil
39039 do {
39040 set_current_state(TASK_INTERRUPTIBLE);
39041
39042 - event_count = atomic_read(&idev->event);
39043 + event_count = atomic_read_unchecked(&idev->event);
39044 if (event_count != listener->event_count) {
39045 if (copy_to_user(buf, &event_count, count))
39046 retval = -EFAULT;
39047 @@ -624,13 +625,13 @@ static int uio_find_mem_index(struct vm_
39048 static void uio_vma_open(struct vm_area_struct *vma)
39049 {
39050 struct uio_device *idev = vma->vm_private_data;
39051 - idev->vma_count++;
39052 + local_inc(&idev->vma_count);
39053 }
39054
39055 static void uio_vma_close(struct vm_area_struct *vma)
39056 {
39057 struct uio_device *idev = vma->vm_private_data;
39058 - idev->vma_count--;
39059 + local_dec(&idev->vma_count);
39060 }
39061
39062 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39063 @@ -840,7 +841,7 @@ int __uio_register_device(struct module
39064 idev->owner = owner;
39065 idev->info = info;
39066 init_waitqueue_head(&idev->wait);
39067 - atomic_set(&idev->event, 0);
39068 + atomic_set_unchecked(&idev->event, 0);
39069
39070 ret = uio_get_minor(idev);
39071 if (ret)
39072 diff -urNp linux-2.6.32.46/drivers/usb/atm/usbatm.c linux-2.6.32.46/drivers/usb/atm/usbatm.c
39073 --- linux-2.6.32.46/drivers/usb/atm/usbatm.c 2011-03-27 14:31:47.000000000 -0400
39074 +++ linux-2.6.32.46/drivers/usb/atm/usbatm.c 2011-04-17 15:56:46.000000000 -0400
39075 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(stru
39076 if (printk_ratelimit())
39077 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39078 __func__, vpi, vci);
39079 - atomic_inc(&vcc->stats->rx_err);
39080 + atomic_inc_unchecked(&vcc->stats->rx_err);
39081 return;
39082 }
39083
39084 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(stru
39085 if (length > ATM_MAX_AAL5_PDU) {
39086 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39087 __func__, length, vcc);
39088 - atomic_inc(&vcc->stats->rx_err);
39089 + atomic_inc_unchecked(&vcc->stats->rx_err);
39090 goto out;
39091 }
39092
39093 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(stru
39094 if (sarb->len < pdu_length) {
39095 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39096 __func__, pdu_length, sarb->len, vcc);
39097 - atomic_inc(&vcc->stats->rx_err);
39098 + atomic_inc_unchecked(&vcc->stats->rx_err);
39099 goto out;
39100 }
39101
39102 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39103 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39104 __func__, vcc);
39105 - atomic_inc(&vcc->stats->rx_err);
39106 + atomic_inc_unchecked(&vcc->stats->rx_err);
39107 goto out;
39108 }
39109
39110 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(stru
39111 if (printk_ratelimit())
39112 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39113 __func__, length);
39114 - atomic_inc(&vcc->stats->rx_drop);
39115 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39116 goto out;
39117 }
39118
39119 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(stru
39120
39121 vcc->push(vcc, skb);
39122
39123 - atomic_inc(&vcc->stats->rx);
39124 + atomic_inc_unchecked(&vcc->stats->rx);
39125 out:
39126 skb_trim(sarb, 0);
39127 }
39128 @@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned l
39129 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39130
39131 usbatm_pop(vcc, skb);
39132 - atomic_inc(&vcc->stats->tx);
39133 + atomic_inc_unchecked(&vcc->stats->tx);
39134
39135 skb = skb_dequeue(&instance->sndqueue);
39136 }
39137 @@ -775,11 +775,11 @@ static int usbatm_atm_proc_read(struct a
39138 if (!left--)
39139 return sprintf(page,
39140 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39141 - atomic_read(&atm_dev->stats.aal5.tx),
39142 - atomic_read(&atm_dev->stats.aal5.tx_err),
39143 - atomic_read(&atm_dev->stats.aal5.rx),
39144 - atomic_read(&atm_dev->stats.aal5.rx_err),
39145 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39146 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39147 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39148 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39149 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39150 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39151
39152 if (!left--) {
39153 if (instance->disconnected)
39154 diff -urNp linux-2.6.32.46/drivers/usb/class/cdc-wdm.c linux-2.6.32.46/drivers/usb/class/cdc-wdm.c
39155 --- linux-2.6.32.46/drivers/usb/class/cdc-wdm.c 2011-03-27 14:31:47.000000000 -0400
39156 +++ linux-2.6.32.46/drivers/usb/class/cdc-wdm.c 2011-04-17 15:56:46.000000000 -0400
39157 @@ -314,7 +314,7 @@ static ssize_t wdm_write
39158 if (r < 0)
39159 goto outnp;
39160
39161 - if (!file->f_flags && O_NONBLOCK)
39162 + if (!(file->f_flags & O_NONBLOCK))
39163 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
39164 &desc->flags));
39165 else
39166 diff -urNp linux-2.6.32.46/drivers/usb/core/hcd.c linux-2.6.32.46/drivers/usb/core/hcd.c
39167 --- linux-2.6.32.46/drivers/usb/core/hcd.c 2011-03-27 14:31:47.000000000 -0400
39168 +++ linux-2.6.32.46/drivers/usb/core/hcd.c 2011-04-17 15:56:46.000000000 -0400
39169 @@ -2216,7 +2216,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
39170
39171 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
39172
39173 -struct usb_mon_operations *mon_ops;
39174 +const struct usb_mon_operations *mon_ops;
39175
39176 /*
39177 * The registration is unlocked.
39178 @@ -2226,7 +2226,7 @@ struct usb_mon_operations *mon_ops;
39179 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
39180 */
39181
39182 -int usb_mon_register (struct usb_mon_operations *ops)
39183 +int usb_mon_register (const struct usb_mon_operations *ops)
39184 {
39185
39186 if (mon_ops)
39187 diff -urNp linux-2.6.32.46/drivers/usb/core/hcd.h linux-2.6.32.46/drivers/usb/core/hcd.h
39188 --- linux-2.6.32.46/drivers/usb/core/hcd.h 2011-03-27 14:31:47.000000000 -0400
39189 +++ linux-2.6.32.46/drivers/usb/core/hcd.h 2011-04-17 15:56:46.000000000 -0400
39190 @@ -486,13 +486,13 @@ static inline void usbfs_cleanup(void) {
39191 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
39192
39193 struct usb_mon_operations {
39194 - void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
39195 - void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
39196 - void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
39197 + void (* const urb_submit)(struct usb_bus *bus, struct urb *urb);
39198 + void (* const urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
39199 + void (* const urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
39200 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
39201 };
39202
39203 -extern struct usb_mon_operations *mon_ops;
39204 +extern const struct usb_mon_operations *mon_ops;
39205
39206 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
39207 {
39208 @@ -514,7 +514,7 @@ static inline void usbmon_urb_complete(s
39209 (*mon_ops->urb_complete)(bus, urb, status);
39210 }
39211
39212 -int usb_mon_register(struct usb_mon_operations *ops);
39213 +int usb_mon_register(const struct usb_mon_operations *ops);
39214 void usb_mon_deregister(void);
39215
39216 #else
39217 diff -urNp linux-2.6.32.46/drivers/usb/core/message.c linux-2.6.32.46/drivers/usb/core/message.c
39218 --- linux-2.6.32.46/drivers/usb/core/message.c 2011-03-27 14:31:47.000000000 -0400
39219 +++ linux-2.6.32.46/drivers/usb/core/message.c 2011-04-17 15:56:46.000000000 -0400
39220 @@ -914,8 +914,8 @@ char *usb_cache_string(struct usb_device
39221 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
39222 if (buf) {
39223 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
39224 - if (len > 0) {
39225 - smallbuf = kmalloc(++len, GFP_NOIO);
39226 + if (len++ > 0) {
39227 + smallbuf = kmalloc(len, GFP_NOIO);
39228 if (!smallbuf)
39229 return buf;
39230 memcpy(smallbuf, buf, len);
39231 diff -urNp linux-2.6.32.46/drivers/usb/misc/appledisplay.c linux-2.6.32.46/drivers/usb/misc/appledisplay.c
39232 --- linux-2.6.32.46/drivers/usb/misc/appledisplay.c 2011-03-27 14:31:47.000000000 -0400
39233 +++ linux-2.6.32.46/drivers/usb/misc/appledisplay.c 2011-04-17 15:56:46.000000000 -0400
39234 @@ -178,7 +178,7 @@ static int appledisplay_bl_get_brightnes
39235 return pdata->msgdata[1];
39236 }
39237
39238 -static struct backlight_ops appledisplay_bl_data = {
39239 +static const struct backlight_ops appledisplay_bl_data = {
39240 .get_brightness = appledisplay_bl_get_brightness,
39241 .update_status = appledisplay_bl_update_status,
39242 };
39243 diff -urNp linux-2.6.32.46/drivers/usb/mon/mon_main.c linux-2.6.32.46/drivers/usb/mon/mon_main.c
39244 --- linux-2.6.32.46/drivers/usb/mon/mon_main.c 2011-03-27 14:31:47.000000000 -0400
39245 +++ linux-2.6.32.46/drivers/usb/mon/mon_main.c 2011-04-17 15:56:46.000000000 -0400
39246 @@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
39247 /*
39248 * Ops
39249 */
39250 -static struct usb_mon_operations mon_ops_0 = {
39251 +static const struct usb_mon_operations mon_ops_0 = {
39252 .urb_submit = mon_submit,
39253 .urb_submit_error = mon_submit_error,
39254 .urb_complete = mon_complete,
39255 diff -urNp linux-2.6.32.46/drivers/usb/wusbcore/wa-hc.h linux-2.6.32.46/drivers/usb/wusbcore/wa-hc.h
39256 --- linux-2.6.32.46/drivers/usb/wusbcore/wa-hc.h 2011-03-27 14:31:47.000000000 -0400
39257 +++ linux-2.6.32.46/drivers/usb/wusbcore/wa-hc.h 2011-05-04 17:56:28.000000000 -0400
39258 @@ -192,7 +192,7 @@ struct wahc {
39259 struct list_head xfer_delayed_list;
39260 spinlock_t xfer_list_lock;
39261 struct work_struct xfer_work;
39262 - atomic_t xfer_id_count;
39263 + atomic_unchecked_t xfer_id_count;
39264 };
39265
39266
39267 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
39268 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39269 spin_lock_init(&wa->xfer_list_lock);
39270 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39271 - atomic_set(&wa->xfer_id_count, 1);
39272 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39273 }
39274
39275 /**
39276 diff -urNp linux-2.6.32.46/drivers/usb/wusbcore/wa-xfer.c linux-2.6.32.46/drivers/usb/wusbcore/wa-xfer.c
39277 --- linux-2.6.32.46/drivers/usb/wusbcore/wa-xfer.c 2011-03-27 14:31:47.000000000 -0400
39278 +++ linux-2.6.32.46/drivers/usb/wusbcore/wa-xfer.c 2011-05-04 17:56:28.000000000 -0400
39279 @@ -293,7 +293,7 @@ out:
39280 */
39281 static void wa_xfer_id_init(struct wa_xfer *xfer)
39282 {
39283 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39284 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39285 }
39286
39287 /*
39288 diff -urNp linux-2.6.32.46/drivers/uwb/wlp/messages.c linux-2.6.32.46/drivers/uwb/wlp/messages.c
39289 --- linux-2.6.32.46/drivers/uwb/wlp/messages.c 2011-03-27 14:31:47.000000000 -0400
39290 +++ linux-2.6.32.46/drivers/uwb/wlp/messages.c 2011-04-17 15:56:46.000000000 -0400
39291 @@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct
39292 size_t len = skb->len;
39293 size_t used;
39294 ssize_t result;
39295 - struct wlp_nonce enonce, rnonce;
39296 + struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
39297 enum wlp_assc_error assc_err;
39298 char enonce_buf[WLP_WSS_NONCE_STRSIZE];
39299 char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
39300 diff -urNp linux-2.6.32.46/drivers/uwb/wlp/sysfs.c linux-2.6.32.46/drivers/uwb/wlp/sysfs.c
39301 --- linux-2.6.32.46/drivers/uwb/wlp/sysfs.c 2011-03-27 14:31:47.000000000 -0400
39302 +++ linux-2.6.32.46/drivers/uwb/wlp/sysfs.c 2011-04-17 15:56:46.000000000 -0400
39303 @@ -615,8 +615,7 @@ ssize_t wlp_wss_attr_store(struct kobjec
39304 return ret;
39305 }
39306
39307 -static
39308 -struct sysfs_ops wss_sysfs_ops = {
39309 +static const struct sysfs_ops wss_sysfs_ops = {
39310 .show = wlp_wss_attr_show,
39311 .store = wlp_wss_attr_store,
39312 };
39313 diff -urNp linux-2.6.32.46/drivers/video/atmel_lcdfb.c linux-2.6.32.46/drivers/video/atmel_lcdfb.c
39314 --- linux-2.6.32.46/drivers/video/atmel_lcdfb.c 2011-03-27 14:31:47.000000000 -0400
39315 +++ linux-2.6.32.46/drivers/video/atmel_lcdfb.c 2011-04-17 15:56:46.000000000 -0400
39316 @@ -110,7 +110,7 @@ static int atmel_bl_get_brightness(struc
39317 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
39318 }
39319
39320 -static struct backlight_ops atmel_lcdc_bl_ops = {
39321 +static const struct backlight_ops atmel_lcdc_bl_ops = {
39322 .update_status = atmel_bl_update_status,
39323 .get_brightness = atmel_bl_get_brightness,
39324 };
39325 diff -urNp linux-2.6.32.46/drivers/video/aty/aty128fb.c linux-2.6.32.46/drivers/video/aty/aty128fb.c
39326 --- linux-2.6.32.46/drivers/video/aty/aty128fb.c 2011-03-27 14:31:47.000000000 -0400
39327 +++ linux-2.6.32.46/drivers/video/aty/aty128fb.c 2011-04-17 15:56:46.000000000 -0400
39328 @@ -1787,7 +1787,7 @@ static int aty128_bl_get_brightness(stru
39329 return bd->props.brightness;
39330 }
39331
39332 -static struct backlight_ops aty128_bl_data = {
39333 +static const struct backlight_ops aty128_bl_data = {
39334 .get_brightness = aty128_bl_get_brightness,
39335 .update_status = aty128_bl_update_status,
39336 };
39337 diff -urNp linux-2.6.32.46/drivers/video/aty/atyfb_base.c linux-2.6.32.46/drivers/video/aty/atyfb_base.c
39338 --- linux-2.6.32.46/drivers/video/aty/atyfb_base.c 2011-03-27 14:31:47.000000000 -0400
39339 +++ linux-2.6.32.46/drivers/video/aty/atyfb_base.c 2011-04-17 15:56:46.000000000 -0400
39340 @@ -2225,7 +2225,7 @@ static int aty_bl_get_brightness(struct
39341 return bd->props.brightness;
39342 }
39343
39344 -static struct backlight_ops aty_bl_data = {
39345 +static const struct backlight_ops aty_bl_data = {
39346 .get_brightness = aty_bl_get_brightness,
39347 .update_status = aty_bl_update_status,
39348 };
39349 diff -urNp linux-2.6.32.46/drivers/video/aty/radeon_backlight.c linux-2.6.32.46/drivers/video/aty/radeon_backlight.c
39350 --- linux-2.6.32.46/drivers/video/aty/radeon_backlight.c 2011-03-27 14:31:47.000000000 -0400
39351 +++ linux-2.6.32.46/drivers/video/aty/radeon_backlight.c 2011-04-17 15:56:46.000000000 -0400
39352 @@ -127,7 +127,7 @@ static int radeon_bl_get_brightness(stru
39353 return bd->props.brightness;
39354 }
39355
39356 -static struct backlight_ops radeon_bl_data = {
39357 +static const struct backlight_ops radeon_bl_data = {
39358 .get_brightness = radeon_bl_get_brightness,
39359 .update_status = radeon_bl_update_status,
39360 };
39361 diff -urNp linux-2.6.32.46/drivers/video/backlight/adp5520_bl.c linux-2.6.32.46/drivers/video/backlight/adp5520_bl.c
39362 --- linux-2.6.32.46/drivers/video/backlight/adp5520_bl.c 2011-03-27 14:31:47.000000000 -0400
39363 +++ linux-2.6.32.46/drivers/video/backlight/adp5520_bl.c 2011-04-17 15:56:46.000000000 -0400
39364 @@ -84,7 +84,7 @@ static int adp5520_bl_get_brightness(str
39365 return error ? data->current_brightness : reg_val;
39366 }
39367
39368 -static struct backlight_ops adp5520_bl_ops = {
39369 +static const struct backlight_ops adp5520_bl_ops = {
39370 .update_status = adp5520_bl_update_status,
39371 .get_brightness = adp5520_bl_get_brightness,
39372 };
39373 diff -urNp linux-2.6.32.46/drivers/video/backlight/adx_bl.c linux-2.6.32.46/drivers/video/backlight/adx_bl.c
39374 --- linux-2.6.32.46/drivers/video/backlight/adx_bl.c 2011-03-27 14:31:47.000000000 -0400
39375 +++ linux-2.6.32.46/drivers/video/backlight/adx_bl.c 2011-04-17 15:56:46.000000000 -0400
39376 @@ -61,7 +61,7 @@ static int adx_backlight_check_fb(struct
39377 return 1;
39378 }
39379
39380 -static struct backlight_ops adx_backlight_ops = {
39381 +static const struct backlight_ops adx_backlight_ops = {
39382 .options = 0,
39383 .update_status = adx_backlight_update_status,
39384 .get_brightness = adx_backlight_get_brightness,
39385 diff -urNp linux-2.6.32.46/drivers/video/backlight/atmel-pwm-bl.c linux-2.6.32.46/drivers/video/backlight/atmel-pwm-bl.c
39386 --- linux-2.6.32.46/drivers/video/backlight/atmel-pwm-bl.c 2011-03-27 14:31:47.000000000 -0400
39387 +++ linux-2.6.32.46/drivers/video/backlight/atmel-pwm-bl.c 2011-04-17 15:56:46.000000000 -0400
39388 @@ -113,7 +113,7 @@ static int atmel_pwm_bl_init_pwm(struct
39389 return pwm_channel_enable(&pwmbl->pwmc);
39390 }
39391
39392 -static struct backlight_ops atmel_pwm_bl_ops = {
39393 +static const struct backlight_ops atmel_pwm_bl_ops = {
39394 .get_brightness = atmel_pwm_bl_get_intensity,
39395 .update_status = atmel_pwm_bl_set_intensity,
39396 };
39397 diff -urNp linux-2.6.32.46/drivers/video/backlight/backlight.c linux-2.6.32.46/drivers/video/backlight/backlight.c
39398 --- linux-2.6.32.46/drivers/video/backlight/backlight.c 2011-03-27 14:31:47.000000000 -0400
39399 +++ linux-2.6.32.46/drivers/video/backlight/backlight.c 2011-04-17 15:56:46.000000000 -0400
39400 @@ -269,7 +269,7 @@ EXPORT_SYMBOL(backlight_force_update);
39401 * ERR_PTR() or a pointer to the newly allocated device.
39402 */
39403 struct backlight_device *backlight_device_register(const char *name,
39404 - struct device *parent, void *devdata, struct backlight_ops *ops)
39405 + struct device *parent, void *devdata, const struct backlight_ops *ops)
39406 {
39407 struct backlight_device *new_bd;
39408 int rc;
39409 diff -urNp linux-2.6.32.46/drivers/video/backlight/corgi_lcd.c linux-2.6.32.46/drivers/video/backlight/corgi_lcd.c
39410 --- linux-2.6.32.46/drivers/video/backlight/corgi_lcd.c 2011-03-27 14:31:47.000000000 -0400
39411 +++ linux-2.6.32.46/drivers/video/backlight/corgi_lcd.c 2011-04-17 15:56:46.000000000 -0400
39412 @@ -451,7 +451,7 @@ void corgi_lcd_limit_intensity(int limit
39413 }
39414 EXPORT_SYMBOL(corgi_lcd_limit_intensity);
39415
39416 -static struct backlight_ops corgi_bl_ops = {
39417 +static const struct backlight_ops corgi_bl_ops = {
39418 .get_brightness = corgi_bl_get_intensity,
39419 .update_status = corgi_bl_update_status,
39420 };
39421 diff -urNp linux-2.6.32.46/drivers/video/backlight/cr_bllcd.c linux-2.6.32.46/drivers/video/backlight/cr_bllcd.c
39422 --- linux-2.6.32.46/drivers/video/backlight/cr_bllcd.c 2011-03-27 14:31:47.000000000 -0400
39423 +++ linux-2.6.32.46/drivers/video/backlight/cr_bllcd.c 2011-04-17 15:56:46.000000000 -0400
39424 @@ -108,7 +108,7 @@ static int cr_backlight_get_intensity(st
39425 return intensity;
39426 }
39427
39428 -static struct backlight_ops cr_backlight_ops = {
39429 +static const struct backlight_ops cr_backlight_ops = {
39430 .get_brightness = cr_backlight_get_intensity,
39431 .update_status = cr_backlight_set_intensity,
39432 };
39433 diff -urNp linux-2.6.32.46/drivers/video/backlight/da903x_bl.c linux-2.6.32.46/drivers/video/backlight/da903x_bl.c
39434 --- linux-2.6.32.46/drivers/video/backlight/da903x_bl.c 2011-03-27 14:31:47.000000000 -0400
39435 +++ linux-2.6.32.46/drivers/video/backlight/da903x_bl.c 2011-04-17 15:56:46.000000000 -0400
39436 @@ -94,7 +94,7 @@ static int da903x_backlight_get_brightne
39437 return data->current_brightness;
39438 }
39439
39440 -static struct backlight_ops da903x_backlight_ops = {
39441 +static const struct backlight_ops da903x_backlight_ops = {
39442 .update_status = da903x_backlight_update_status,
39443 .get_brightness = da903x_backlight_get_brightness,
39444 };
39445 diff -urNp linux-2.6.32.46/drivers/video/backlight/generic_bl.c linux-2.6.32.46/drivers/video/backlight/generic_bl.c
39446 --- linux-2.6.32.46/drivers/video/backlight/generic_bl.c 2011-03-27 14:31:47.000000000 -0400
39447 +++ linux-2.6.32.46/drivers/video/backlight/generic_bl.c 2011-04-17 15:56:46.000000000 -0400
39448 @@ -70,7 +70,7 @@ void corgibl_limit_intensity(int limit)
39449 }
39450 EXPORT_SYMBOL(corgibl_limit_intensity);
39451
39452 -static struct backlight_ops genericbl_ops = {
39453 +static const struct backlight_ops genericbl_ops = {
39454 .options = BL_CORE_SUSPENDRESUME,
39455 .get_brightness = genericbl_get_intensity,
39456 .update_status = genericbl_send_intensity,
39457 diff -urNp linux-2.6.32.46/drivers/video/backlight/hp680_bl.c linux-2.6.32.46/drivers/video/backlight/hp680_bl.c
39458 --- linux-2.6.32.46/drivers/video/backlight/hp680_bl.c 2011-03-27 14:31:47.000000000 -0400
39459 +++ linux-2.6.32.46/drivers/video/backlight/hp680_bl.c 2011-04-17 15:56:46.000000000 -0400
39460 @@ -98,7 +98,7 @@ static int hp680bl_get_intensity(struct
39461 return current_intensity;
39462 }
39463
39464 -static struct backlight_ops hp680bl_ops = {
39465 +static const struct backlight_ops hp680bl_ops = {
39466 .get_brightness = hp680bl_get_intensity,
39467 .update_status = hp680bl_set_intensity,
39468 };
39469 diff -urNp linux-2.6.32.46/drivers/video/backlight/jornada720_bl.c linux-2.6.32.46/drivers/video/backlight/jornada720_bl.c
39470 --- linux-2.6.32.46/drivers/video/backlight/jornada720_bl.c 2011-03-27 14:31:47.000000000 -0400
39471 +++ linux-2.6.32.46/drivers/video/backlight/jornada720_bl.c 2011-04-17 15:56:46.000000000 -0400
39472 @@ -93,7 +93,7 @@ out:
39473 return ret;
39474 }
39475
39476 -static struct backlight_ops jornada_bl_ops = {
39477 +static const struct backlight_ops jornada_bl_ops = {
39478 .get_brightness = jornada_bl_get_brightness,
39479 .update_status = jornada_bl_update_status,
39480 .options = BL_CORE_SUSPENDRESUME,
39481 diff -urNp linux-2.6.32.46/drivers/video/backlight/kb3886_bl.c linux-2.6.32.46/drivers/video/backlight/kb3886_bl.c
39482 --- linux-2.6.32.46/drivers/video/backlight/kb3886_bl.c 2011-03-27 14:31:47.000000000 -0400
39483 +++ linux-2.6.32.46/drivers/video/backlight/kb3886_bl.c 2011-04-17 15:56:46.000000000 -0400
39484 @@ -134,7 +134,7 @@ static int kb3886bl_get_intensity(struct
39485 return kb3886bl_intensity;
39486 }
39487
39488 -static struct backlight_ops kb3886bl_ops = {
39489 +static const struct backlight_ops kb3886bl_ops = {
39490 .get_brightness = kb3886bl_get_intensity,
39491 .update_status = kb3886bl_send_intensity,
39492 };
39493 diff -urNp linux-2.6.32.46/drivers/video/backlight/locomolcd.c linux-2.6.32.46/drivers/video/backlight/locomolcd.c
39494 --- linux-2.6.32.46/drivers/video/backlight/locomolcd.c 2011-03-27 14:31:47.000000000 -0400
39495 +++ linux-2.6.32.46/drivers/video/backlight/locomolcd.c 2011-04-17 15:56:46.000000000 -0400
39496 @@ -141,7 +141,7 @@ static int locomolcd_get_intensity(struc
39497 return current_intensity;
39498 }
39499
39500 -static struct backlight_ops locomobl_data = {
39501 +static const struct backlight_ops locomobl_data = {
39502 .get_brightness = locomolcd_get_intensity,
39503 .update_status = locomolcd_set_intensity,
39504 };
39505 diff -urNp linux-2.6.32.46/drivers/video/backlight/mbp_nvidia_bl.c linux-2.6.32.46/drivers/video/backlight/mbp_nvidia_bl.c
39506 --- linux-2.6.32.46/drivers/video/backlight/mbp_nvidia_bl.c 2011-05-10 22:12:01.000000000 -0400
39507 +++ linux-2.6.32.46/drivers/video/backlight/mbp_nvidia_bl.c 2011-05-10 22:12:33.000000000 -0400
39508 @@ -33,7 +33,7 @@ struct dmi_match_data {
39509 unsigned long iostart;
39510 unsigned long iolen;
39511 /* Backlight operations structure. */
39512 - struct backlight_ops backlight_ops;
39513 + const struct backlight_ops backlight_ops;
39514 };
39515
39516 /* Module parameters. */
39517 diff -urNp linux-2.6.32.46/drivers/video/backlight/omap1_bl.c linux-2.6.32.46/drivers/video/backlight/omap1_bl.c
39518 --- linux-2.6.32.46/drivers/video/backlight/omap1_bl.c 2011-03-27 14:31:47.000000000 -0400
39519 +++ linux-2.6.32.46/drivers/video/backlight/omap1_bl.c 2011-04-17 15:56:46.000000000 -0400
39520 @@ -125,7 +125,7 @@ static int omapbl_get_intensity(struct b
39521 return bl->current_intensity;
39522 }
39523
39524 -static struct backlight_ops omapbl_ops = {
39525 +static const struct backlight_ops omapbl_ops = {
39526 .get_brightness = omapbl_get_intensity,
39527 .update_status = omapbl_update_status,
39528 };
39529 diff -urNp linux-2.6.32.46/drivers/video/backlight/progear_bl.c linux-2.6.32.46/drivers/video/backlight/progear_bl.c
39530 --- linux-2.6.32.46/drivers/video/backlight/progear_bl.c 2011-03-27 14:31:47.000000000 -0400
39531 +++ linux-2.6.32.46/drivers/video/backlight/progear_bl.c 2011-04-17 15:56:46.000000000 -0400
39532 @@ -54,7 +54,7 @@ static int progearbl_get_intensity(struc
39533 return intensity - HW_LEVEL_MIN;
39534 }
39535
39536 -static struct backlight_ops progearbl_ops = {
39537 +static const struct backlight_ops progearbl_ops = {
39538 .get_brightness = progearbl_get_intensity,
39539 .update_status = progearbl_set_intensity,
39540 };
39541 diff -urNp linux-2.6.32.46/drivers/video/backlight/pwm_bl.c linux-2.6.32.46/drivers/video/backlight/pwm_bl.c
39542 --- linux-2.6.32.46/drivers/video/backlight/pwm_bl.c 2011-03-27 14:31:47.000000000 -0400
39543 +++ linux-2.6.32.46/drivers/video/backlight/pwm_bl.c 2011-04-17 15:56:46.000000000 -0400
39544 @@ -56,7 +56,7 @@ static int pwm_backlight_get_brightness(
39545 return bl->props.brightness;
39546 }
39547
39548 -static struct backlight_ops pwm_backlight_ops = {
39549 +static const struct backlight_ops pwm_backlight_ops = {
39550 .update_status = pwm_backlight_update_status,
39551 .get_brightness = pwm_backlight_get_brightness,
39552 };
39553 diff -urNp linux-2.6.32.46/drivers/video/backlight/tosa_bl.c linux-2.6.32.46/drivers/video/backlight/tosa_bl.c
39554 --- linux-2.6.32.46/drivers/video/backlight/tosa_bl.c 2011-03-27 14:31:47.000000000 -0400
39555 +++ linux-2.6.32.46/drivers/video/backlight/tosa_bl.c 2011-04-17 15:56:46.000000000 -0400
39556 @@ -72,7 +72,7 @@ static int tosa_bl_get_brightness(struct
39557 return props->brightness;
39558 }
39559
39560 -static struct backlight_ops bl_ops = {
39561 +static const struct backlight_ops bl_ops = {
39562 .get_brightness = tosa_bl_get_brightness,
39563 .update_status = tosa_bl_update_status,
39564 };
39565 diff -urNp linux-2.6.32.46/drivers/video/backlight/wm831x_bl.c linux-2.6.32.46/drivers/video/backlight/wm831x_bl.c
39566 --- linux-2.6.32.46/drivers/video/backlight/wm831x_bl.c 2011-03-27 14:31:47.000000000 -0400
39567 +++ linux-2.6.32.46/drivers/video/backlight/wm831x_bl.c 2011-04-17 15:56:46.000000000 -0400
39568 @@ -112,7 +112,7 @@ static int wm831x_backlight_get_brightne
39569 return data->current_brightness;
39570 }
39571
39572 -static struct backlight_ops wm831x_backlight_ops = {
39573 +static const struct backlight_ops wm831x_backlight_ops = {
39574 .options = BL_CORE_SUSPENDRESUME,
39575 .update_status = wm831x_backlight_update_status,
39576 .get_brightness = wm831x_backlight_get_brightness,
39577 diff -urNp linux-2.6.32.46/drivers/video/bf54x-lq043fb.c linux-2.6.32.46/drivers/video/bf54x-lq043fb.c
39578 --- linux-2.6.32.46/drivers/video/bf54x-lq043fb.c 2011-03-27 14:31:47.000000000 -0400
39579 +++ linux-2.6.32.46/drivers/video/bf54x-lq043fb.c 2011-04-17 15:56:46.000000000 -0400
39580 @@ -463,7 +463,7 @@ static int bl_get_brightness(struct back
39581 return 0;
39582 }
39583
39584 -static struct backlight_ops bfin_lq043fb_bl_ops = {
39585 +static const struct backlight_ops bfin_lq043fb_bl_ops = {
39586 .get_brightness = bl_get_brightness,
39587 };
39588
39589 diff -urNp linux-2.6.32.46/drivers/video/bfin-t350mcqb-fb.c linux-2.6.32.46/drivers/video/bfin-t350mcqb-fb.c
39590 --- linux-2.6.32.46/drivers/video/bfin-t350mcqb-fb.c 2011-03-27 14:31:47.000000000 -0400
39591 +++ linux-2.6.32.46/drivers/video/bfin-t350mcqb-fb.c 2011-04-17 15:56:46.000000000 -0400
39592 @@ -381,7 +381,7 @@ static int bl_get_brightness(struct back
39593 return 0;
39594 }
39595
39596 -static struct backlight_ops bfin_lq043fb_bl_ops = {
39597 +static const struct backlight_ops bfin_lq043fb_bl_ops = {
39598 .get_brightness = bl_get_brightness,
39599 };
39600
39601 diff -urNp linux-2.6.32.46/drivers/video/fbcmap.c linux-2.6.32.46/drivers/video/fbcmap.c
39602 --- linux-2.6.32.46/drivers/video/fbcmap.c 2011-03-27 14:31:47.000000000 -0400
39603 +++ linux-2.6.32.46/drivers/video/fbcmap.c 2011-04-17 15:56:46.000000000 -0400
39604 @@ -266,8 +266,7 @@ int fb_set_user_cmap(struct fb_cmap_user
39605 rc = -ENODEV;
39606 goto out;
39607 }
39608 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39609 - !info->fbops->fb_setcmap)) {
39610 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39611 rc = -EINVAL;
39612 goto out1;
39613 }
39614 diff -urNp linux-2.6.32.46/drivers/video/fbmem.c linux-2.6.32.46/drivers/video/fbmem.c
39615 --- linux-2.6.32.46/drivers/video/fbmem.c 2011-03-27 14:31:47.000000000 -0400
39616 +++ linux-2.6.32.46/drivers/video/fbmem.c 2011-05-16 21:46:57.000000000 -0400
39617 @@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_in
39618 image->dx += image->width + 8;
39619 }
39620 } else if (rotate == FB_ROTATE_UD) {
39621 - for (x = 0; x < num && image->dx >= 0; x++) {
39622 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39623 info->fbops->fb_imageblit(info, image);
39624 image->dx -= image->width + 8;
39625 }
39626 @@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_in
39627 image->dy += image->height + 8;
39628 }
39629 } else if (rotate == FB_ROTATE_CCW) {
39630 - for (x = 0; x < num && image->dy >= 0; x++) {
39631 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39632 info->fbops->fb_imageblit(info, image);
39633 image->dy -= image->height + 8;
39634 }
39635 @@ -915,6 +915,8 @@ fb_set_var(struct fb_info *info, struct
39636 int flags = info->flags;
39637 int ret = 0;
39638
39639 + pax_track_stack();
39640 +
39641 if (var->activate & FB_ACTIVATE_INV_MODE) {
39642 struct fb_videomode mode1, mode2;
39643
39644 @@ -1040,6 +1042,8 @@ static long do_fb_ioctl(struct fb_info *
39645 void __user *argp = (void __user *)arg;
39646 long ret = 0;
39647
39648 + pax_track_stack();
39649 +
39650 switch (cmd) {
39651 case FBIOGET_VSCREENINFO:
39652 if (!lock_fb_info(info))
39653 @@ -1119,7 +1123,7 @@ static long do_fb_ioctl(struct fb_info *
39654 return -EFAULT;
39655 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39656 return -EINVAL;
39657 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39658 + if (con2fb.framebuffer >= FB_MAX)
39659 return -EINVAL;
39660 if (!registered_fb[con2fb.framebuffer])
39661 request_module("fb%d", con2fb.framebuffer);
39662 diff -urNp linux-2.6.32.46/drivers/video/i810/i810_accel.c linux-2.6.32.46/drivers/video/i810/i810_accel.c
39663 --- linux-2.6.32.46/drivers/video/i810/i810_accel.c 2011-03-27 14:31:47.000000000 -0400
39664 +++ linux-2.6.32.46/drivers/video/i810/i810_accel.c 2011-04-17 15:56:46.000000000 -0400
39665 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct
39666 }
39667 }
39668 printk("ringbuffer lockup!!!\n");
39669 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39670 i810_report_error(mmio);
39671 par->dev_flags |= LOCKUP;
39672 info->pixmap.scan_align = 1;
39673 diff -urNp linux-2.6.32.46/drivers/video/logo/logo_linux_clut224.ppm linux-2.6.32.46/drivers/video/logo/logo_linux_clut224.ppm
39674 --- linux-2.6.32.46/drivers/video/logo/logo_linux_clut224.ppm 2011-03-27 14:31:47.000000000 -0400
39675 +++ linux-2.6.32.46/drivers/video/logo/logo_linux_clut224.ppm 2011-08-29 23:49:24.000000000 -0400
39676 @@ -1,1604 +1,1123 @@
39677 P3
39678 -# Standard 224-color Linux logo
39679 80 80
39680 255
39681 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 6 6 6 6 6 6 10 10 10 10 10 10
39691 - 10 10 10 6 6 6 6 6 6 6 6 6
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 0 0 0 0 0 0 0 0 0 0 0 0
39695 - 0 0 0 0 0 0 0 0 0 0 0 0
39696 - 0 0 0 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 6 6 6 10 10 10 14 14 14
39710 - 22 22 22 26 26 26 30 30 30 34 34 34
39711 - 30 30 30 30 30 30 26 26 26 18 18 18
39712 - 14 14 14 10 10 10 6 6 6 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 0 0 0
39714 - 0 0 0 0 0 0 0 0 0 0 0 0
39715 - 0 0 0 0 0 0 0 0 0 0 0 0
39716 - 0 0 0 0 0 0 0 0 0 0 0 0
39717 - 0 0 0 0 0 0 0 0 0 0 0 0
39718 - 0 0 0 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 1 0 0 1 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 6 6 6 14 14 14 26 26 26 42 42 42
39730 - 54 54 54 66 66 66 78 78 78 78 78 78
39731 - 78 78 78 74 74 74 66 66 66 54 54 54
39732 - 42 42 42 26 26 26 18 18 18 10 10 10
39733 - 6 6 6 0 0 0 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 0 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 1 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 10 10 10
39749 - 22 22 22 42 42 42 66 66 66 86 86 86
39750 - 66 66 66 38 38 38 38 38 38 22 22 22
39751 - 26 26 26 34 34 34 54 54 54 66 66 66
39752 - 86 86 86 70 70 70 46 46 46 26 26 26
39753 - 14 14 14 6 6 6 0 0 0 0 0 0
39754 - 0 0 0 0 0 0 0 0 0 0 0 0
39755 - 0 0 0 0 0 0 0 0 0 0 0 0
39756 - 0 0 0 0 0 0 0 0 0 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 1 0 0 1 0 0 1 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 10 10 10 26 26 26
39769 - 50 50 50 82 82 82 58 58 58 6 6 6
39770 - 2 2 6 2 2 6 2 2 6 2 2 6
39771 - 2 2 6 2 2 6 2 2 6 2 2 6
39772 - 6 6 6 54 54 54 86 86 86 66 66 66
39773 - 38 38 38 18 18 18 6 6 6 0 0 0
39774 - 0 0 0 0 0 0 0 0 0 0 0 0
39775 - 0 0 0 0 0 0 0 0 0 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 6 6 6 22 22 22 50 50 50
39789 - 78 78 78 34 34 34 2 2 6 2 2 6
39790 - 2 2 6 2 2 6 2 2 6 2 2 6
39791 - 2 2 6 2 2 6 2 2 6 2 2 6
39792 - 2 2 6 2 2 6 6 6 6 70 70 70
39793 - 78 78 78 46 46 46 22 22 22 6 6 6
39794 - 0 0 0 0 0 0 0 0 0 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 1 0 0 1 0 0 1 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 6 6 6 18 18 18 42 42 42 82 82 82
39809 - 26 26 26 2 2 6 2 2 6 2 2 6
39810 - 2 2 6 2 2 6 2 2 6 2 2 6
39811 - 2 2 6 2 2 6 2 2 6 14 14 14
39812 - 46 46 46 34 34 34 6 6 6 2 2 6
39813 - 42 42 42 78 78 78 42 42 42 18 18 18
39814 - 6 6 6 0 0 0 0 0 0 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 1 0 0 0 0 0 1 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 0 0 0
39828 - 10 10 10 30 30 30 66 66 66 58 58 58
39829 - 2 2 6 2 2 6 2 2 6 2 2 6
39830 - 2 2 6 2 2 6 2 2 6 2 2 6
39831 - 2 2 6 2 2 6 2 2 6 26 26 26
39832 - 86 86 86 101 101 101 46 46 46 10 10 10
39833 - 2 2 6 58 58 58 70 70 70 34 34 34
39834 - 10 10 10 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 1 0 0 1 0 0 1 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 0 0 0
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 14 14 14 42 42 42 86 86 86 10 10 10
39849 - 2 2 6 2 2 6 2 2 6 2 2 6
39850 - 2 2 6 2 2 6 2 2 6 2 2 6
39851 - 2 2 6 2 2 6 2 2 6 30 30 30
39852 - 94 94 94 94 94 94 58 58 58 26 26 26
39853 - 2 2 6 6 6 6 78 78 78 54 54 54
39854 - 22 22 22 6 6 6 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 0 0 0
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 6 6 6
39868 - 22 22 22 62 62 62 62 62 62 2 2 6
39869 - 2 2 6 2 2 6 2 2 6 2 2 6
39870 - 2 2 6 2 2 6 2 2 6 2 2 6
39871 - 2 2 6 2 2 6 2 2 6 26 26 26
39872 - 54 54 54 38 38 38 18 18 18 10 10 10
39873 - 2 2 6 2 2 6 34 34 34 82 82 82
39874 - 38 38 38 14 14 14 0 0 0 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 1 0 0 1 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 6 6 6
39888 - 30 30 30 78 78 78 30 30 30 2 2 6
39889 - 2 2 6 2 2 6 2 2 6 2 2 6
39890 - 2 2 6 2 2 6 2 2 6 2 2 6
39891 - 2 2 6 2 2 6 2 2 6 10 10 10
39892 - 10 10 10 2 2 6 2 2 6 2 2 6
39893 - 2 2 6 2 2 6 2 2 6 78 78 78
39894 - 50 50 50 18 18 18 6 6 6 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 0 0 0 0 0 0 0
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 1 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 10 10 10
39908 - 38 38 38 86 86 86 14 14 14 2 2 6
39909 - 2 2 6 2 2 6 2 2 6 2 2 6
39910 - 2 2 6 2 2 6 2 2 6 2 2 6
39911 - 2 2 6 2 2 6 2 2 6 2 2 6
39912 - 2 2 6 2 2 6 2 2 6 2 2 6
39913 - 2 2 6 2 2 6 2 2 6 54 54 54
39914 - 66 66 66 26 26 26 6 6 6 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 0 0 0 0 0 0
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 1 0 0 1 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 14 14 14
39928 - 42 42 42 82 82 82 2 2 6 2 2 6
39929 - 2 2 6 6 6 6 10 10 10 2 2 6
39930 - 2 2 6 2 2 6 2 2 6 2 2 6
39931 - 2 2 6 2 2 6 2 2 6 6 6 6
39932 - 14 14 14 10 10 10 2 2 6 2 2 6
39933 - 2 2 6 2 2 6 2 2 6 18 18 18
39934 - 82 82 82 34 34 34 10 10 10 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 0 0 0 0 0 0
39940 - 0 0 0 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 1 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 14 14 14
39948 - 46 46 46 86 86 86 2 2 6 2 2 6
39949 - 6 6 6 6 6 6 22 22 22 34 34 34
39950 - 6 6 6 2 2 6 2 2 6 2 2 6
39951 - 2 2 6 2 2 6 18 18 18 34 34 34
39952 - 10 10 10 50 50 50 22 22 22 2 2 6
39953 - 2 2 6 2 2 6 2 2 6 10 10 10
39954 - 86 86 86 42 42 42 14 14 14 0 0 0
39955 - 0 0 0 0 0 0 0 0 0 0 0 0
39956 - 0 0 0 0 0 0 0 0 0 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 0 0 0 0 0 0 0 0 0 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 1 0 0 1 0 0 1 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 14 14 14
39968 - 46 46 46 86 86 86 2 2 6 2 2 6
39969 - 38 38 38 116 116 116 94 94 94 22 22 22
39970 - 22 22 22 2 2 6 2 2 6 2 2 6
39971 - 14 14 14 86 86 86 138 138 138 162 162 162
39972 -154 154 154 38 38 38 26 26 26 6 6 6
39973 - 2 2 6 2 2 6 2 2 6 2 2 6
39974 - 86 86 86 46 46 46 14 14 14 0 0 0
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 14 14 14
39988 - 46 46 46 86 86 86 2 2 6 14 14 14
39989 -134 134 134 198 198 198 195 195 195 116 116 116
39990 - 10 10 10 2 2 6 2 2 6 6 6 6
39991 -101 98 89 187 187 187 210 210 210 218 218 218
39992 -214 214 214 134 134 134 14 14 14 6 6 6
39993 - 2 2 6 2 2 6 2 2 6 2 2 6
39994 - 86 86 86 50 50 50 18 18 18 6 6 6
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 1 0 0 0
40002 - 0 0 1 0 0 1 0 0 1 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 14 14 14
40008 - 46 46 46 86 86 86 2 2 6 54 54 54
40009 -218 218 218 195 195 195 226 226 226 246 246 246
40010 - 58 58 58 2 2 6 2 2 6 30 30 30
40011 -210 210 210 253 253 253 174 174 174 123 123 123
40012 -221 221 221 234 234 234 74 74 74 2 2 6
40013 - 2 2 6 2 2 6 2 2 6 2 2 6
40014 - 70 70 70 58 58 58 22 22 22 6 6 6
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 0 0 0
40025 - 0 0 0 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 14 14 14
40028 - 46 46 46 82 82 82 2 2 6 106 106 106
40029 -170 170 170 26 26 26 86 86 86 226 226 226
40030 -123 123 123 10 10 10 14 14 14 46 46 46
40031 -231 231 231 190 190 190 6 6 6 70 70 70
40032 - 90 90 90 238 238 238 158 158 158 2 2 6
40033 - 2 2 6 2 2 6 2 2 6 2 2 6
40034 - 70 70 70 58 58 58 22 22 22 6 6 6
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 0 0 0
40038 - 0 0 0 0 0 0 0 0 0 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 1 0 0 0
40042 - 0 0 1 0 0 1 0 0 1 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 0 0 0
40045 - 0 0 0 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 14 14 14
40048 - 42 42 42 86 86 86 6 6 6 116 116 116
40049 -106 106 106 6 6 6 70 70 70 149 149 149
40050 -128 128 128 18 18 18 38 38 38 54 54 54
40051 -221 221 221 106 106 106 2 2 6 14 14 14
40052 - 46 46 46 190 190 190 198 198 198 2 2 6
40053 - 2 2 6 2 2 6 2 2 6 2 2 6
40054 - 74 74 74 62 62 62 22 22 22 6 6 6
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 1 0 0 0
40062 - 0 0 1 0 0 0 0 0 1 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 0 0 0
40065 - 0 0 0 0 0 0 0 0 0 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 14 14 14
40068 - 42 42 42 94 94 94 14 14 14 101 101 101
40069 -128 128 128 2 2 6 18 18 18 116 116 116
40070 -118 98 46 121 92 8 121 92 8 98 78 10
40071 -162 162 162 106 106 106 2 2 6 2 2 6
40072 - 2 2 6 195 195 195 195 195 195 6 6 6
40073 - 2 2 6 2 2 6 2 2 6 2 2 6
40074 - 74 74 74 62 62 62 22 22 22 6 6 6
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 1 0 0 1
40082 - 0 0 1 0 0 0 0 0 1 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 0 0 0
40085 - 0 0 0 0 0 0 0 0 0 0 0 0
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 10 10 10
40088 - 38 38 38 90 90 90 14 14 14 58 58 58
40089 -210 210 210 26 26 26 54 38 6 154 114 10
40090 -226 170 11 236 186 11 225 175 15 184 144 12
40091 -215 174 15 175 146 61 37 26 9 2 2 6
40092 - 70 70 70 246 246 246 138 138 138 2 2 6
40093 - 2 2 6 2 2 6 2 2 6 2 2 6
40094 - 70 70 70 66 66 66 26 26 26 6 6 6
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 0 0 0 0 0 0
40098 - 0 0 0 0 0 0 0 0 0 0 0 0
40099 - 0 0 0 0 0 0 0 0 0 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 0 0 0
40105 - 0 0 0 0 0 0 0 0 0 0 0 0
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 10 10 10
40108 - 38 38 38 86 86 86 14 14 14 10 10 10
40109 -195 195 195 188 164 115 192 133 9 225 175 15
40110 -239 182 13 234 190 10 232 195 16 232 200 30
40111 -245 207 45 241 208 19 232 195 16 184 144 12
40112 -218 194 134 211 206 186 42 42 42 2 2 6
40113 - 2 2 6 2 2 6 2 2 6 2 2 6
40114 - 50 50 50 74 74 74 30 30 30 6 6 6
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 0 0 0 0 0 0
40118 - 0 0 0 0 0 0 0 0 0 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 0 0 0
40125 - 0 0 0 0 0 0 0 0 0 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 10 10 10
40128 - 34 34 34 86 86 86 14 14 14 2 2 6
40129 -121 87 25 192 133 9 219 162 10 239 182 13
40130 -236 186 11 232 195 16 241 208 19 244 214 54
40131 -246 218 60 246 218 38 246 215 20 241 208 19
40132 -241 208 19 226 184 13 121 87 25 2 2 6
40133 - 2 2 6 2 2 6 2 2 6 2 2 6
40134 - 50 50 50 82 82 82 34 34 34 10 10 10
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 0 0 0
40145 - 0 0 0 0 0 0 0 0 0 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 10 10 10
40148 - 34 34 34 82 82 82 30 30 30 61 42 6
40149 -180 123 7 206 145 10 230 174 11 239 182 13
40150 -234 190 10 238 202 15 241 208 19 246 218 74
40151 -246 218 38 246 215 20 246 215 20 246 215 20
40152 -226 184 13 215 174 15 184 144 12 6 6 6
40153 - 2 2 6 2 2 6 2 2 6 2 2 6
40154 - 26 26 26 94 94 94 42 42 42 14 14 14
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 0 0 0 0 0 0 0 0 0 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 0 0 0
40164 - 0 0 0 0 0 0 0 0 0 0 0 0
40165 - 0 0 0 0 0 0 0 0 0 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 10 10 10
40168 - 30 30 30 78 78 78 50 50 50 104 69 6
40169 -192 133 9 216 158 10 236 178 12 236 186 11
40170 -232 195 16 241 208 19 244 214 54 245 215 43
40171 -246 215 20 246 215 20 241 208 19 198 155 10
40172 -200 144 11 216 158 10 156 118 10 2 2 6
40173 - 2 2 6 2 2 6 2 2 6 2 2 6
40174 - 6 6 6 90 90 90 54 54 54 18 18 18
40175 - 6 6 6 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 0 0 0
40178 - 0 0 0 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 10 10 10
40188 - 30 30 30 78 78 78 46 46 46 22 22 22
40189 -137 92 6 210 162 10 239 182 13 238 190 10
40190 -238 202 15 241 208 19 246 215 20 246 215 20
40191 -241 208 19 203 166 17 185 133 11 210 150 10
40192 -216 158 10 210 150 10 102 78 10 2 2 6
40193 - 6 6 6 54 54 54 14 14 14 2 2 6
40194 - 2 2 6 62 62 62 74 74 74 30 30 30
40195 - 10 10 10 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 0 0 0
40198 - 0 0 0 0 0 0 0 0 0 0 0 0
40199 - 0 0 0 0 0 0 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 10 10 10
40208 - 34 34 34 78 78 78 50 50 50 6 6 6
40209 - 94 70 30 139 102 15 190 146 13 226 184 13
40210 -232 200 30 232 195 16 215 174 15 190 146 13
40211 -168 122 10 192 133 9 210 150 10 213 154 11
40212 -202 150 34 182 157 106 101 98 89 2 2 6
40213 - 2 2 6 78 78 78 116 116 116 58 58 58
40214 - 2 2 6 22 22 22 90 90 90 46 46 46
40215 - 18 18 18 6 6 6 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 0 0 0 0 0 0
40218 - 0 0 0 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 0 0 0 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 10 10 10
40228 - 38 38 38 86 86 86 50 50 50 6 6 6
40229 -128 128 128 174 154 114 156 107 11 168 122 10
40230 -198 155 10 184 144 12 197 138 11 200 144 11
40231 -206 145 10 206 145 10 197 138 11 188 164 115
40232 -195 195 195 198 198 198 174 174 174 14 14 14
40233 - 2 2 6 22 22 22 116 116 116 116 116 116
40234 - 22 22 22 2 2 6 74 74 74 70 70 70
40235 - 30 30 30 10 10 10 0 0 0 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 0 0 0 0 0 0
40238 - 0 0 0 0 0 0 0 0 0 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 0 0 0
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 0 0 0 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 6 6 6 18 18 18
40248 - 50 50 50 101 101 101 26 26 26 10 10 10
40249 -138 138 138 190 190 190 174 154 114 156 107 11
40250 -197 138 11 200 144 11 197 138 11 192 133 9
40251 -180 123 7 190 142 34 190 178 144 187 187 187
40252 -202 202 202 221 221 221 214 214 214 66 66 66
40253 - 2 2 6 2 2 6 50 50 50 62 62 62
40254 - 6 6 6 2 2 6 10 10 10 90 90 90
40255 - 50 50 50 18 18 18 6 6 6 0 0 0
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 0 0 0 0 0 0 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 10 10 10 34 34 34
40268 - 74 74 74 74 74 74 2 2 6 6 6 6
40269 -144 144 144 198 198 198 190 190 190 178 166 146
40270 -154 121 60 156 107 11 156 107 11 168 124 44
40271 -174 154 114 187 187 187 190 190 190 210 210 210
40272 -246 246 246 253 253 253 253 253 253 182 182 182
40273 - 6 6 6 2 2 6 2 2 6 2 2 6
40274 - 2 2 6 2 2 6 2 2 6 62 62 62
40275 - 74 74 74 34 34 34 14 14 14 0 0 0
40276 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 0 0 0 0 0 0
40278 - 0 0 0 0 0 0 0 0 0 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 0 0 0 0 0 0 0 0 0 0 0 0
40287 - 0 0 0 10 10 10 22 22 22 54 54 54
40288 - 94 94 94 18 18 18 2 2 6 46 46 46
40289 -234 234 234 221 221 221 190 190 190 190 190 190
40290 -190 190 190 187 187 187 187 187 187 190 190 190
40291 -190 190 190 195 195 195 214 214 214 242 242 242
40292 -253 253 253 253 253 253 253 253 253 253 253 253
40293 - 82 82 82 2 2 6 2 2 6 2 2 6
40294 - 2 2 6 2 2 6 2 2 6 14 14 14
40295 - 86 86 86 54 54 54 22 22 22 6 6 6
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 0 0 0 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 0 0 0
40307 - 6 6 6 18 18 18 46 46 46 90 90 90
40308 - 46 46 46 18 18 18 6 6 6 182 182 182
40309 -253 253 253 246 246 246 206 206 206 190 190 190
40310 -190 190 190 190 190 190 190 190 190 190 190 190
40311 -206 206 206 231 231 231 250 250 250 253 253 253
40312 -253 253 253 253 253 253 253 253 253 253 253 253
40313 -202 202 202 14 14 14 2 2 6 2 2 6
40314 - 2 2 6 2 2 6 2 2 6 2 2 6
40315 - 42 42 42 86 86 86 42 42 42 18 18 18
40316 - 6 6 6 0 0 0 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 0 0 0
40318 - 0 0 0 0 0 0 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 0 0 0
40326 - 0 0 0 0 0 0 0 0 0 6 6 6
40327 - 14 14 14 38 38 38 74 74 74 66 66 66
40328 - 2 2 6 6 6 6 90 90 90 250 250 250
40329 -253 253 253 253 253 253 238 238 238 198 198 198
40330 -190 190 190 190 190 190 195 195 195 221 221 221
40331 -246 246 246 253 253 253 253 253 253 253 253 253
40332 -253 253 253 253 253 253 253 253 253 253 253 253
40333 -253 253 253 82 82 82 2 2 6 2 2 6
40334 - 2 2 6 2 2 6 2 2 6 2 2 6
40335 - 2 2 6 78 78 78 70 70 70 34 34 34
40336 - 14 14 14 6 6 6 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 0 0 0
40345 - 0 0 0 0 0 0 0 0 0 0 0 0
40346 - 0 0 0 0 0 0 0 0 0 14 14 14
40347 - 34 34 34 66 66 66 78 78 78 6 6 6
40348 - 2 2 6 18 18 18 218 218 218 253 253 253
40349 -253 253 253 253 253 253 253 253 253 246 246 246
40350 -226 226 226 231 231 231 246 246 246 253 253 253
40351 -253 253 253 253 253 253 253 253 253 253 253 253
40352 -253 253 253 253 253 253 253 253 253 253 253 253
40353 -253 253 253 178 178 178 2 2 6 2 2 6
40354 - 2 2 6 2 2 6 2 2 6 2 2 6
40355 - 2 2 6 18 18 18 90 90 90 62 62 62
40356 - 30 30 30 10 10 10 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 0 0 0
40365 - 0 0 0 0 0 0 0 0 0 0 0 0
40366 - 0 0 0 0 0 0 10 10 10 26 26 26
40367 - 58 58 58 90 90 90 18 18 18 2 2 6
40368 - 2 2 6 110 110 110 253 253 253 253 253 253
40369 -253 253 253 253 253 253 253 253 253 253 253 253
40370 -250 250 250 253 253 253 253 253 253 253 253 253
40371 -253 253 253 253 253 253 253 253 253 253 253 253
40372 -253 253 253 253 253 253 253 253 253 253 253 253
40373 -253 253 253 231 231 231 18 18 18 2 2 6
40374 - 2 2 6 2 2 6 2 2 6 2 2 6
40375 - 2 2 6 2 2 6 18 18 18 94 94 94
40376 - 54 54 54 26 26 26 10 10 10 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 0 0 0 0 0 0
40386 - 0 0 0 6 6 6 22 22 22 50 50 50
40387 - 90 90 90 26 26 26 2 2 6 2 2 6
40388 - 14 14 14 195 195 195 250 250 250 253 253 253
40389 -253 253 253 253 253 253 253 253 253 253 253 253
40390 -253 253 253 253 253 253 253 253 253 253 253 253
40391 -253 253 253 253 253 253 253 253 253 253 253 253
40392 -253 253 253 253 253 253 253 253 253 253 253 253
40393 -250 250 250 242 242 242 54 54 54 2 2 6
40394 - 2 2 6 2 2 6 2 2 6 2 2 6
40395 - 2 2 6 2 2 6 2 2 6 38 38 38
40396 - 86 86 86 50 50 50 22 22 22 6 6 6
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 0 0 0 0 0 0
40406 - 6 6 6 14 14 14 38 38 38 82 82 82
40407 - 34 34 34 2 2 6 2 2 6 2 2 6
40408 - 42 42 42 195 195 195 246 246 246 253 253 253
40409 -253 253 253 253 253 253 253 253 253 250 250 250
40410 -242 242 242 242 242 242 250 250 250 253 253 253
40411 -253 253 253 253 253 253 253 253 253 253 253 253
40412 -253 253 253 250 250 250 246 246 246 238 238 238
40413 -226 226 226 231 231 231 101 101 101 6 6 6
40414 - 2 2 6 2 2 6 2 2 6 2 2 6
40415 - 2 2 6 2 2 6 2 2 6 2 2 6
40416 - 38 38 38 82 82 82 42 42 42 14 14 14
40417 - 6 6 6 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 0 0 0
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 0 0 0 0 0 0 0 0 0 0 0 0
40424 - 0 0 0 0 0 0 0 0 0 0 0 0
40425 - 0 0 0 0 0 0 0 0 0 0 0 0
40426 - 10 10 10 26 26 26 62 62 62 66 66 66
40427 - 2 2 6 2 2 6 2 2 6 6 6 6
40428 - 70 70 70 170 170 170 206 206 206 234 234 234
40429 -246 246 246 250 250 250 250 250 250 238 238 238
40430 -226 226 226 231 231 231 238 238 238 250 250 250
40431 -250 250 250 250 250 250 246 246 246 231 231 231
40432 -214 214 214 206 206 206 202 202 202 202 202 202
40433 -198 198 198 202 202 202 182 182 182 18 18 18
40434 - 2 2 6 2 2 6 2 2 6 2 2 6
40435 - 2 2 6 2 2 6 2 2 6 2 2 6
40436 - 2 2 6 62 62 62 66 66 66 30 30 30
40437 - 10 10 10 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 0 0 0
40442 - 0 0 0 0 0 0 0 0 0 0 0 0
40443 - 0 0 0 0 0 0 0 0 0 0 0 0
40444 - 0 0 0 0 0 0 0 0 0 0 0 0
40445 - 0 0 0 0 0 0 0 0 0 0 0 0
40446 - 14 14 14 42 42 42 82 82 82 18 18 18
40447 - 2 2 6 2 2 6 2 2 6 10 10 10
40448 - 94 94 94 182 182 182 218 218 218 242 242 242
40449 -250 250 250 253 253 253 253 253 253 250 250 250
40450 -234 234 234 253 253 253 253 253 253 253 253 253
40451 -253 253 253 253 253 253 253 253 253 246 246 246
40452 -238 238 238 226 226 226 210 210 210 202 202 202
40453 -195 195 195 195 195 195 210 210 210 158 158 158
40454 - 6 6 6 14 14 14 50 50 50 14 14 14
40455 - 2 2 6 2 2 6 2 2 6 2 2 6
40456 - 2 2 6 6 6 6 86 86 86 46 46 46
40457 - 18 18 18 6 6 6 0 0 0 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 0 0 0 0 0 0 0 0 0 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 0 0 0
40462 - 0 0 0 0 0 0 0 0 0 0 0 0
40463 - 0 0 0 0 0 0 0 0 0 0 0 0
40464 - 0 0 0 0 0 0 0 0 0 0 0 0
40465 - 0 0 0 0 0 0 0 0 0 6 6 6
40466 - 22 22 22 54 54 54 70 70 70 2 2 6
40467 - 2 2 6 10 10 10 2 2 6 22 22 22
40468 -166 166 166 231 231 231 250 250 250 253 253 253
40469 -253 253 253 253 253 253 253 253 253 250 250 250
40470 -242 242 242 253 253 253 253 253 253 253 253 253
40471 -253 253 253 253 253 253 253 253 253 253 253 253
40472 -253 253 253 253 253 253 253 253 253 246 246 246
40473 -231 231 231 206 206 206 198 198 198 226 226 226
40474 - 94 94 94 2 2 6 6 6 6 38 38 38
40475 - 30 30 30 2 2 6 2 2 6 2 2 6
40476 - 2 2 6 2 2 6 62 62 62 66 66 66
40477 - 26 26 26 10 10 10 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 0 0 0
40482 - 0 0 0 0 0 0 0 0 0 0 0 0
40483 - 0 0 0 0 0 0 0 0 0 0 0 0
40484 - 0 0 0 0 0 0 0 0 0 0 0 0
40485 - 0 0 0 0 0 0 0 0 0 10 10 10
40486 - 30 30 30 74 74 74 50 50 50 2 2 6
40487 - 26 26 26 26 26 26 2 2 6 106 106 106
40488 -238 238 238 253 253 253 253 253 253 253 253 253
40489 -253 253 253 253 253 253 253 253 253 253 253 253
40490 -253 253 253 253 253 253 253 253 253 253 253 253
40491 -253 253 253 253 253 253 253 253 253 253 253 253
40492 -253 253 253 253 253 253 253 253 253 253 253 253
40493 -253 253 253 246 246 246 218 218 218 202 202 202
40494 -210 210 210 14 14 14 2 2 6 2 2 6
40495 - 30 30 30 22 22 22 2 2 6 2 2 6
40496 - 2 2 6 2 2 6 18 18 18 86 86 86
40497 - 42 42 42 14 14 14 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 0 0 0
40502 - 0 0 0 0 0 0 0 0 0 0 0 0
40503 - 0 0 0 0 0 0 0 0 0 0 0 0
40504 - 0 0 0 0 0 0 0 0 0 0 0 0
40505 - 0 0 0 0 0 0 0 0 0 14 14 14
40506 - 42 42 42 90 90 90 22 22 22 2 2 6
40507 - 42 42 42 2 2 6 18 18 18 218 218 218
40508 -253 253 253 253 253 253 253 253 253 253 253 253
40509 -253 253 253 253 253 253 253 253 253 253 253 253
40510 -253 253 253 253 253 253 253 253 253 253 253 253
40511 -253 253 253 253 253 253 253 253 253 253 253 253
40512 -253 253 253 253 253 253 253 253 253 253 253 253
40513 -253 253 253 253 253 253 250 250 250 221 221 221
40514 -218 218 218 101 101 101 2 2 6 14 14 14
40515 - 18 18 18 38 38 38 10 10 10 2 2 6
40516 - 2 2 6 2 2 6 2 2 6 78 78 78
40517 - 58 58 58 22 22 22 6 6 6 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 0 0 0 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 0 0 0
40522 - 0 0 0 0 0 0 0 0 0 0 0 0
40523 - 0 0 0 0 0 0 0 0 0 0 0 0
40524 - 0 0 0 0 0 0 0 0 0 0 0 0
40525 - 0 0 0 0 0 0 6 6 6 18 18 18
40526 - 54 54 54 82 82 82 2 2 6 26 26 26
40527 - 22 22 22 2 2 6 123 123 123 253 253 253
40528 -253 253 253 253 253 253 253 253 253 253 253 253
40529 -253 253 253 253 253 253 253 253 253 253 253 253
40530 -253 253 253 253 253 253 253 253 253 253 253 253
40531 -253 253 253 253 253 253 253 253 253 253 253 253
40532 -253 253 253 253 253 253 253 253 253 253 253 253
40533 -253 253 253 253 253 253 253 253 253 250 250 250
40534 -238 238 238 198 198 198 6 6 6 38 38 38
40535 - 58 58 58 26 26 26 38 38 38 2 2 6
40536 - 2 2 6 2 2 6 2 2 6 46 46 46
40537 - 78 78 78 30 30 30 10 10 10 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 0 0 0 0 0 0
40542 - 0 0 0 0 0 0 0 0 0 0 0 0
40543 - 0 0 0 0 0 0 0 0 0 0 0 0
40544 - 0 0 0 0 0 0 0 0 0 0 0 0
40545 - 0 0 0 0 0 0 10 10 10 30 30 30
40546 - 74 74 74 58 58 58 2 2 6 42 42 42
40547 - 2 2 6 22 22 22 231 231 231 253 253 253
40548 -253 253 253 253 253 253 253 253 253 253 253 253
40549 -253 253 253 253 253 253 253 253 253 250 250 250
40550 -253 253 253 253 253 253 253 253 253 253 253 253
40551 -253 253 253 253 253 253 253 253 253 253 253 253
40552 -253 253 253 253 253 253 253 253 253 253 253 253
40553 -253 253 253 253 253 253 253 253 253 253 253 253
40554 -253 253 253 246 246 246 46 46 46 38 38 38
40555 - 42 42 42 14 14 14 38 38 38 14 14 14
40556 - 2 2 6 2 2 6 2 2 6 6 6 6
40557 - 86 86 86 46 46 46 14 14 14 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 0 0 0 0 0 0 0 0 0
40560 - 0 0 0 0 0 0 0 0 0 0 0 0
40561 - 0 0 0 0 0 0 0 0 0 0 0 0
40562 - 0 0 0 0 0 0 0 0 0 0 0 0
40563 - 0 0 0 0 0 0 0 0 0 0 0 0
40564 - 0 0 0 0 0 0 0 0 0 0 0 0
40565 - 0 0 0 6 6 6 14 14 14 42 42 42
40566 - 90 90 90 18 18 18 18 18 18 26 26 26
40567 - 2 2 6 116 116 116 253 253 253 253 253 253
40568 -253 253 253 253 253 253 253 253 253 253 253 253
40569 -253 253 253 253 253 253 250 250 250 238 238 238
40570 -253 253 253 253 253 253 253 253 253 253 253 253
40571 -253 253 253 253 253 253 253 253 253 253 253 253
40572 -253 253 253 253 253 253 253 253 253 253 253 253
40573 -253 253 253 253 253 253 253 253 253 253 253 253
40574 -253 253 253 253 253 253 94 94 94 6 6 6
40575 - 2 2 6 2 2 6 10 10 10 34 34 34
40576 - 2 2 6 2 2 6 2 2 6 2 2 6
40577 - 74 74 74 58 58 58 22 22 22 6 6 6
40578 - 0 0 0 0 0 0 0 0 0 0 0 0
40579 - 0 0 0 0 0 0 0 0 0 0 0 0
40580 - 0 0 0 0 0 0 0 0 0 0 0 0
40581 - 0 0 0 0 0 0 0 0 0 0 0 0
40582 - 0 0 0 0 0 0 0 0 0 0 0 0
40583 - 0 0 0 0 0 0 0 0 0 0 0 0
40584 - 0 0 0 0 0 0 0 0 0 0 0 0
40585 - 0 0 0 10 10 10 26 26 26 66 66 66
40586 - 82 82 82 2 2 6 38 38 38 6 6 6
40587 - 14 14 14 210 210 210 253 253 253 253 253 253
40588 -253 253 253 253 253 253 253 253 253 253 253 253
40589 -253 253 253 253 253 253 246 246 246 242 242 242
40590 -253 253 253 253 253 253 253 253 253 253 253 253
40591 -253 253 253 253 253 253 253 253 253 253 253 253
40592 -253 253 253 253 253 253 253 253 253 253 253 253
40593 -253 253 253 253 253 253 253 253 253 253 253 253
40594 -253 253 253 253 253 253 144 144 144 2 2 6
40595 - 2 2 6 2 2 6 2 2 6 46 46 46
40596 - 2 2 6 2 2 6 2 2 6 2 2 6
40597 - 42 42 42 74 74 74 30 30 30 10 10 10
40598 - 0 0 0 0 0 0 0 0 0 0 0 0
40599 - 0 0 0 0 0 0 0 0 0 0 0 0
40600 - 0 0 0 0 0 0 0 0 0 0 0 0
40601 - 0 0 0 0 0 0 0 0 0 0 0 0
40602 - 0 0 0 0 0 0 0 0 0 0 0 0
40603 - 0 0 0 0 0 0 0 0 0 0 0 0
40604 - 0 0 0 0 0 0 0 0 0 0 0 0
40605 - 6 6 6 14 14 14 42 42 42 90 90 90
40606 - 26 26 26 6 6 6 42 42 42 2 2 6
40607 - 74 74 74 250 250 250 253 253 253 253 253 253
40608 -253 253 253 253 253 253 253 253 253 253 253 253
40609 -253 253 253 253 253 253 242 242 242 242 242 242
40610 -253 253 253 253 253 253 253 253 253 253 253 253
40611 -253 253 253 253 253 253 253 253 253 253 253 253
40612 -253 253 253 253 253 253 253 253 253 253 253 253
40613 -253 253 253 253 253 253 253 253 253 253 253 253
40614 -253 253 253 253 253 253 182 182 182 2 2 6
40615 - 2 2 6 2 2 6 2 2 6 46 46 46
40616 - 2 2 6 2 2 6 2 2 6 2 2 6
40617 - 10 10 10 86 86 86 38 38 38 10 10 10
40618 - 0 0 0 0 0 0 0 0 0 0 0 0
40619 - 0 0 0 0 0 0 0 0 0 0 0 0
40620 - 0 0 0 0 0 0 0 0 0 0 0 0
40621 - 0 0 0 0 0 0 0 0 0 0 0 0
40622 - 0 0 0 0 0 0 0 0 0 0 0 0
40623 - 0 0 0 0 0 0 0 0 0 0 0 0
40624 - 0 0 0 0 0 0 0 0 0 0 0 0
40625 - 10 10 10 26 26 26 66 66 66 82 82 82
40626 - 2 2 6 22 22 22 18 18 18 2 2 6
40627 -149 149 149 253 253 253 253 253 253 253 253 253
40628 -253 253 253 253 253 253 253 253 253 253 253 253
40629 -253 253 253 253 253 253 234 234 234 242 242 242
40630 -253 253 253 253 253 253 253 253 253 253 253 253
40631 -253 253 253 253 253 253 253 253 253 253 253 253
40632 -253 253 253 253 253 253 253 253 253 253 253 253
40633 -253 253 253 253 253 253 253 253 253 253 253 253
40634 -253 253 253 253 253 253 206 206 206 2 2 6
40635 - 2 2 6 2 2 6 2 2 6 38 38 38
40636 - 2 2 6 2 2 6 2 2 6 2 2 6
40637 - 6 6 6 86 86 86 46 46 46 14 14 14
40638 - 0 0 0 0 0 0 0 0 0 0 0 0
40639 - 0 0 0 0 0 0 0 0 0 0 0 0
40640 - 0 0 0 0 0 0 0 0 0 0 0 0
40641 - 0 0 0 0 0 0 0 0 0 0 0 0
40642 - 0 0 0 0 0 0 0 0 0 0 0 0
40643 - 0 0 0 0 0 0 0 0 0 0 0 0
40644 - 0 0 0 0 0 0 0 0 0 6 6 6
40645 - 18 18 18 46 46 46 86 86 86 18 18 18
40646 - 2 2 6 34 34 34 10 10 10 6 6 6
40647 -210 210 210 253 253 253 253 253 253 253 253 253
40648 -253 253 253 253 253 253 253 253 253 253 253 253
40649 -253 253 253 253 253 253 234 234 234 242 242 242
40650 -253 253 253 253 253 253 253 253 253 253 253 253
40651 -253 253 253 253 253 253 253 253 253 253 253 253
40652 -253 253 253 253 253 253 253 253 253 253 253 253
40653 -253 253 253 253 253 253 253 253 253 253 253 253
40654 -253 253 253 253 253 253 221 221 221 6 6 6
40655 - 2 2 6 2 2 6 6 6 6 30 30 30
40656 - 2 2 6 2 2 6 2 2 6 2 2 6
40657 - 2 2 6 82 82 82 54 54 54 18 18 18
40658 - 6 6 6 0 0 0 0 0 0 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 0 0 0
40660 - 0 0 0 0 0 0 0 0 0 0 0 0
40661 - 0 0 0 0 0 0 0 0 0 0 0 0
40662 - 0 0 0 0 0 0 0 0 0 0 0 0
40663 - 0 0 0 0 0 0 0 0 0 0 0 0
40664 - 0 0 0 0 0 0 0 0 0 10 10 10
40665 - 26 26 26 66 66 66 62 62 62 2 2 6
40666 - 2 2 6 38 38 38 10 10 10 26 26 26
40667 -238 238 238 253 253 253 253 253 253 253 253 253
40668 -253 253 253 253 253 253 253 253 253 253 253 253
40669 -253 253 253 253 253 253 231 231 231 238 238 238
40670 -253 253 253 253 253 253 253 253 253 253 253 253
40671 -253 253 253 253 253 253 253 253 253 253 253 253
40672 -253 253 253 253 253 253 253 253 253 253 253 253
40673 -253 253 253 253 253 253 253 253 253 253 253 253
40674 -253 253 253 253 253 253 231 231 231 6 6 6
40675 - 2 2 6 2 2 6 10 10 10 30 30 30
40676 - 2 2 6 2 2 6 2 2 6 2 2 6
40677 - 2 2 6 66 66 66 58 58 58 22 22 22
40678 - 6 6 6 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 0 0 0
40680 - 0 0 0 0 0 0 0 0 0 0 0 0
40681 - 0 0 0 0 0 0 0 0 0 0 0 0
40682 - 0 0 0 0 0 0 0 0 0 0 0 0
40683 - 0 0 0 0 0 0 0 0 0 0 0 0
40684 - 0 0 0 0 0 0 0 0 0 10 10 10
40685 - 38 38 38 78 78 78 6 6 6 2 2 6
40686 - 2 2 6 46 46 46 14 14 14 42 42 42
40687 -246 246 246 253 253 253 253 253 253 253 253 253
40688 -253 253 253 253 253 253 253 253 253 253 253 253
40689 -253 253 253 253 253 253 231 231 231 242 242 242
40690 -253 253 253 253 253 253 253 253 253 253 253 253
40691 -253 253 253 253 253 253 253 253 253 253 253 253
40692 -253 253 253 253 253 253 253 253 253 253 253 253
40693 -253 253 253 253 253 253 253 253 253 253 253 253
40694 -253 253 253 253 253 253 234 234 234 10 10 10
40695 - 2 2 6 2 2 6 22 22 22 14 14 14
40696 - 2 2 6 2 2 6 2 2 6 2 2 6
40697 - 2 2 6 66 66 66 62 62 62 22 22 22
40698 - 6 6 6 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 0 0 0 0 0 0 0 0 0 0 0 0
40701 - 0 0 0 0 0 0 0 0 0 0 0 0
40702 - 0 0 0 0 0 0 0 0 0 0 0 0
40703 - 0 0 0 0 0 0 0 0 0 0 0 0
40704 - 0 0 0 0 0 0 6 6 6 18 18 18
40705 - 50 50 50 74 74 74 2 2 6 2 2 6
40706 - 14 14 14 70 70 70 34 34 34 62 62 62
40707 -250 250 250 253 253 253 253 253 253 253 253 253
40708 -253 253 253 253 253 253 253 253 253 253 253 253
40709 -253 253 253 253 253 253 231 231 231 246 246 246
40710 -253 253 253 253 253 253 253 253 253 253 253 253
40711 -253 253 253 253 253 253 253 253 253 253 253 253
40712 -253 253 253 253 253 253 253 253 253 253 253 253
40713 -253 253 253 253 253 253 253 253 253 253 253 253
40714 -253 253 253 253 253 253 234 234 234 14 14 14
40715 - 2 2 6 2 2 6 30 30 30 2 2 6
40716 - 2 2 6 2 2 6 2 2 6 2 2 6
40717 - 2 2 6 66 66 66 62 62 62 22 22 22
40718 - 6 6 6 0 0 0 0 0 0 0 0 0
40719 - 0 0 0 0 0 0 0 0 0 0 0 0
40720 - 0 0 0 0 0 0 0 0 0 0 0 0
40721 - 0 0 0 0 0 0 0 0 0 0 0 0
40722 - 0 0 0 0 0 0 0 0 0 0 0 0
40723 - 0 0 0 0 0 0 0 0 0 0 0 0
40724 - 0 0 0 0 0 0 6 6 6 18 18 18
40725 - 54 54 54 62 62 62 2 2 6 2 2 6
40726 - 2 2 6 30 30 30 46 46 46 70 70 70
40727 -250 250 250 253 253 253 253 253 253 253 253 253
40728 -253 253 253 253 253 253 253 253 253 253 253 253
40729 -253 253 253 253 253 253 231 231 231 246 246 246
40730 -253 253 253 253 253 253 253 253 253 253 253 253
40731 -253 253 253 253 253 253 253 253 253 253 253 253
40732 -253 253 253 253 253 253 253 253 253 253 253 253
40733 -253 253 253 253 253 253 253 253 253 253 253 253
40734 -253 253 253 253 253 253 226 226 226 10 10 10
40735 - 2 2 6 6 6 6 30 30 30 2 2 6
40736 - 2 2 6 2 2 6 2 2 6 2 2 6
40737 - 2 2 6 66 66 66 58 58 58 22 22 22
40738 - 6 6 6 0 0 0 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 0 0 0
40740 - 0 0 0 0 0 0 0 0 0 0 0 0
40741 - 0 0 0 0 0 0 0 0 0 0 0 0
40742 - 0 0 0 0 0 0 0 0 0 0 0 0
40743 - 0 0 0 0 0 0 0 0 0 0 0 0
40744 - 0 0 0 0 0 0 6 6 6 22 22 22
40745 - 58 58 58 62 62 62 2 2 6 2 2 6
40746 - 2 2 6 2 2 6 30 30 30 78 78 78
40747 -250 250 250 253 253 253 253 253 253 253 253 253
40748 -253 253 253 253 253 253 253 253 253 253 253 253
40749 -253 253 253 253 253 253 231 231 231 246 246 246
40750 -253 253 253 253 253 253 253 253 253 253 253 253
40751 -253 253 253 253 253 253 253 253 253 253 253 253
40752 -253 253 253 253 253 253 253 253 253 253 253 253
40753 -253 253 253 253 253 253 253 253 253 253 253 253
40754 -253 253 253 253 253 253 206 206 206 2 2 6
40755 - 22 22 22 34 34 34 18 14 6 22 22 22
40756 - 26 26 26 18 18 18 6 6 6 2 2 6
40757 - 2 2 6 82 82 82 54 54 54 18 18 18
40758 - 6 6 6 0 0 0 0 0 0 0 0 0
40759 - 0 0 0 0 0 0 0 0 0 0 0 0
40760 - 0 0 0 0 0 0 0 0 0 0 0 0
40761 - 0 0 0 0 0 0 0 0 0 0 0 0
40762 - 0 0 0 0 0 0 0 0 0 0 0 0
40763 - 0 0 0 0 0 0 0 0 0 0 0 0
40764 - 0 0 0 0 0 0 6 6 6 26 26 26
40765 - 62 62 62 106 106 106 74 54 14 185 133 11
40766 -210 162 10 121 92 8 6 6 6 62 62 62
40767 -238 238 238 253 253 253 253 253 253 253 253 253
40768 -253 253 253 253 253 253 253 253 253 253 253 253
40769 -253 253 253 253 253 253 231 231 231 246 246 246
40770 -253 253 253 253 253 253 253 253 253 253 253 253
40771 -253 253 253 253 253 253 253 253 253 253 253 253
40772 -253 253 253 253 253 253 253 253 253 253 253 253
40773 -253 253 253 253 253 253 253 253 253 253 253 253
40774 -253 253 253 253 253 253 158 158 158 18 18 18
40775 - 14 14 14 2 2 6 2 2 6 2 2 6
40776 - 6 6 6 18 18 18 66 66 66 38 38 38
40777 - 6 6 6 94 94 94 50 50 50 18 18 18
40778 - 6 6 6 0 0 0 0 0 0 0 0 0
40779 - 0 0 0 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 0 0 0 0 0 0 0 0 0
40781 - 0 0 0 0 0 0 0 0 0 0 0 0
40782 - 0 0 0 0 0 0 0 0 0 0 0 0
40783 - 0 0 0 0 0 0 0 0 0 6 6 6
40784 - 10 10 10 10 10 10 18 18 18 38 38 38
40785 - 78 78 78 142 134 106 216 158 10 242 186 14
40786 -246 190 14 246 190 14 156 118 10 10 10 10
40787 - 90 90 90 238 238 238 253 253 253 253 253 253
40788 -253 253 253 253 253 253 253 253 253 253 253 253
40789 -253 253 253 253 253 253 231 231 231 250 250 250
40790 -253 253 253 253 253 253 253 253 253 253 253 253
40791 -253 253 253 253 253 253 253 253 253 253 253 253
40792 -253 253 253 253 253 253 253 253 253 253 253 253
40793 -253 253 253 253 253 253 253 253 253 246 230 190
40794 -238 204 91 238 204 91 181 142 44 37 26 9
40795 - 2 2 6 2 2 6 2 2 6 2 2 6
40796 - 2 2 6 2 2 6 38 38 38 46 46 46
40797 - 26 26 26 106 106 106 54 54 54 18 18 18
40798 - 6 6 6 0 0 0 0 0 0 0 0 0
40799 - 0 0 0 0 0 0 0 0 0 0 0 0
40800 - 0 0 0 0 0 0 0 0 0 0 0 0
40801 - 0 0 0 0 0 0 0 0 0 0 0 0
40802 - 0 0 0 0 0 0 0 0 0 0 0 0
40803 - 0 0 0 6 6 6 14 14 14 22 22 22
40804 - 30 30 30 38 38 38 50 50 50 70 70 70
40805 -106 106 106 190 142 34 226 170 11 242 186 14
40806 -246 190 14 246 190 14 246 190 14 154 114 10
40807 - 6 6 6 74 74 74 226 226 226 253 253 253
40808 -253 253 253 253 253 253 253 253 253 253 253 253
40809 -253 253 253 253 253 253 231 231 231 250 250 250
40810 -253 253 253 253 253 253 253 253 253 253 253 253
40811 -253 253 253 253 253 253 253 253 253 253 253 253
40812 -253 253 253 253 253 253 253 253 253 253 253 253
40813 -253 253 253 253 253 253 253 253 253 228 184 62
40814 -241 196 14 241 208 19 232 195 16 38 30 10
40815 - 2 2 6 2 2 6 2 2 6 2 2 6
40816 - 2 2 6 6 6 6 30 30 30 26 26 26
40817 -203 166 17 154 142 90 66 66 66 26 26 26
40818 - 6 6 6 0 0 0 0 0 0 0 0 0
40819 - 0 0 0 0 0 0 0 0 0 0 0 0
40820 - 0 0 0 0 0 0 0 0 0 0 0 0
40821 - 0 0 0 0 0 0 0 0 0 0 0 0
40822 - 0 0 0 0 0 0 0 0 0 0 0 0
40823 - 6 6 6 18 18 18 38 38 38 58 58 58
40824 - 78 78 78 86 86 86 101 101 101 123 123 123
40825 -175 146 61 210 150 10 234 174 13 246 186 14
40826 -246 190 14 246 190 14 246 190 14 238 190 10
40827 -102 78 10 2 2 6 46 46 46 198 198 198
40828 -253 253 253 253 253 253 253 253 253 253 253 253
40829 -253 253 253 253 253 253 234 234 234 242 242 242
40830 -253 253 253 253 253 253 253 253 253 253 253 253
40831 -253 253 253 253 253 253 253 253 253 253 253 253
40832 -253 253 253 253 253 253 253 253 253 253 253 253
40833 -253 253 253 253 253 253 253 253 253 224 178 62
40834 -242 186 14 241 196 14 210 166 10 22 18 6
40835 - 2 2 6 2 2 6 2 2 6 2 2 6
40836 - 2 2 6 2 2 6 6 6 6 121 92 8
40837 -238 202 15 232 195 16 82 82 82 34 34 34
40838 - 10 10 10 0 0 0 0 0 0 0 0 0
40839 - 0 0 0 0 0 0 0 0 0 0 0 0
40840 - 0 0 0 0 0 0 0 0 0 0 0 0
40841 - 0 0 0 0 0 0 0 0 0 0 0 0
40842 - 0 0 0 0 0 0 0 0 0 0 0 0
40843 - 14 14 14 38 38 38 70 70 70 154 122 46
40844 -190 142 34 200 144 11 197 138 11 197 138 11
40845 -213 154 11 226 170 11 242 186 14 246 190 14
40846 -246 190 14 246 190 14 246 190 14 246 190 14
40847 -225 175 15 46 32 6 2 2 6 22 22 22
40848 -158 158 158 250 250 250 253 253 253 253 253 253
40849 -253 253 253 253 253 253 253 253 253 253 253 253
40850 -253 253 253 253 253 253 253 253 253 253 253 253
40851 -253 253 253 253 253 253 253 253 253 253 253 253
40852 -253 253 253 253 253 253 253 253 253 253 253 253
40853 -253 253 253 250 250 250 242 242 242 224 178 62
40854 -239 182 13 236 186 11 213 154 11 46 32 6
40855 - 2 2 6 2 2 6 2 2 6 2 2 6
40856 - 2 2 6 2 2 6 61 42 6 225 175 15
40857 -238 190 10 236 186 11 112 100 78 42 42 42
40858 - 14 14 14 0 0 0 0 0 0 0 0 0
40859 - 0 0 0 0 0 0 0 0 0 0 0 0
40860 - 0 0 0 0 0 0 0 0 0 0 0 0
40861 - 0 0 0 0 0 0 0 0 0 0 0 0
40862 - 0 0 0 0 0 0 0 0 0 6 6 6
40863 - 22 22 22 54 54 54 154 122 46 213 154 11
40864 -226 170 11 230 174 11 226 170 11 226 170 11
40865 -236 178 12 242 186 14 246 190 14 246 190 14
40866 -246 190 14 246 190 14 246 190 14 246 190 14
40867 -241 196 14 184 144 12 10 10 10 2 2 6
40868 - 6 6 6 116 116 116 242 242 242 253 253 253
40869 -253 253 253 253 253 253 253 253 253 253 253 253
40870 -253 253 253 253 253 253 253 253 253 253 253 253
40871 -253 253 253 253 253 253 253 253 253 253 253 253
40872 -253 253 253 253 253 253 253 253 253 253 253 253
40873 -253 253 253 231 231 231 198 198 198 214 170 54
40874 -236 178 12 236 178 12 210 150 10 137 92 6
40875 - 18 14 6 2 2 6 2 2 6 2 2 6
40876 - 6 6 6 70 47 6 200 144 11 236 178 12
40877 -239 182 13 239 182 13 124 112 88 58 58 58
40878 - 22 22 22 6 6 6 0 0 0 0 0 0
40879 - 0 0 0 0 0 0 0 0 0 0 0 0
40880 - 0 0 0 0 0 0 0 0 0 0 0 0
40881 - 0 0 0 0 0 0 0 0 0 0 0 0
40882 - 0 0 0 0 0 0 0 0 0 10 10 10
40883 - 30 30 30 70 70 70 180 133 36 226 170 11
40884 -239 182 13 242 186 14 242 186 14 246 186 14
40885 -246 190 14 246 190 14 246 190 14 246 190 14
40886 -246 190 14 246 190 14 246 190 14 246 190 14
40887 -246 190 14 232 195 16 98 70 6 2 2 6
40888 - 2 2 6 2 2 6 66 66 66 221 221 221
40889 -253 253 253 253 253 253 253 253 253 253 253 253
40890 -253 253 253 253 253 253 253 253 253 253 253 253
40891 -253 253 253 253 253 253 253 253 253 253 253 253
40892 -253 253 253 253 253 253 253 253 253 253 253 253
40893 -253 253 253 206 206 206 198 198 198 214 166 58
40894 -230 174 11 230 174 11 216 158 10 192 133 9
40895 -163 110 8 116 81 8 102 78 10 116 81 8
40896 -167 114 7 197 138 11 226 170 11 239 182 13
40897 -242 186 14 242 186 14 162 146 94 78 78 78
40898 - 34 34 34 14 14 14 6 6 6 0 0 0
40899 - 0 0 0 0 0 0 0 0 0 0 0 0
40900 - 0 0 0 0 0 0 0 0 0 0 0 0
40901 - 0 0 0 0 0 0 0 0 0 0 0 0
40902 - 0 0 0 0 0 0 0 0 0 6 6 6
40903 - 30 30 30 78 78 78 190 142 34 226 170 11
40904 -239 182 13 246 190 14 246 190 14 246 190 14
40905 -246 190 14 246 190 14 246 190 14 246 190 14
40906 -246 190 14 246 190 14 246 190 14 246 190 14
40907 -246 190 14 241 196 14 203 166 17 22 18 6
40908 - 2 2 6 2 2 6 2 2 6 38 38 38
40909 -218 218 218 253 253 253 253 253 253 253 253 253
40910 -253 253 253 253 253 253 253 253 253 253 253 253
40911 -253 253 253 253 253 253 253 253 253 253 253 253
40912 -253 253 253 253 253 253 253 253 253 253 253 253
40913 -250 250 250 206 206 206 198 198 198 202 162 69
40914 -226 170 11 236 178 12 224 166 10 210 150 10
40915 -200 144 11 197 138 11 192 133 9 197 138 11
40916 -210 150 10 226 170 11 242 186 14 246 190 14
40917 -246 190 14 246 186 14 225 175 15 124 112 88
40918 - 62 62 62 30 30 30 14 14 14 6 6 6
40919 - 0 0 0 0 0 0 0 0 0 0 0 0
40920 - 0 0 0 0 0 0 0 0 0 0 0 0
40921 - 0 0 0 0 0 0 0 0 0 0 0 0
40922 - 0 0 0 0 0 0 0 0 0 10 10 10
40923 - 30 30 30 78 78 78 174 135 50 224 166 10
40924 -239 182 13 246 190 14 246 190 14 246 190 14
40925 -246 190 14 246 190 14 246 190 14 246 190 14
40926 -246 190 14 246 190 14 246 190 14 246 190 14
40927 -246 190 14 246 190 14 241 196 14 139 102 15
40928 - 2 2 6 2 2 6 2 2 6 2 2 6
40929 - 78 78 78 250 250 250 253 253 253 253 253 253
40930 -253 253 253 253 253 253 253 253 253 253 253 253
40931 -253 253 253 253 253 253 253 253 253 253 253 253
40932 -253 253 253 253 253 253 253 253 253 253 253 253
40933 -250 250 250 214 214 214 198 198 198 190 150 46
40934 -219 162 10 236 178 12 234 174 13 224 166 10
40935 -216 158 10 213 154 11 213 154 11 216 158 10
40936 -226 170 11 239 182 13 246 190 14 246 190 14
40937 -246 190 14 246 190 14 242 186 14 206 162 42
40938 -101 101 101 58 58 58 30 30 30 14 14 14
40939 - 6 6 6 0 0 0 0 0 0 0 0 0
40940 - 0 0 0 0 0 0 0 0 0 0 0 0
40941 - 0 0 0 0 0 0 0 0 0 0 0 0
40942 - 0 0 0 0 0 0 0 0 0 10 10 10
40943 - 30 30 30 74 74 74 174 135 50 216 158 10
40944 -236 178 12 246 190 14 246 190 14 246 190 14
40945 -246 190 14 246 190 14 246 190 14 246 190 14
40946 -246 190 14 246 190 14 246 190 14 246 190 14
40947 -246 190 14 246 190 14 241 196 14 226 184 13
40948 - 61 42 6 2 2 6 2 2 6 2 2 6
40949 - 22 22 22 238 238 238 253 253 253 253 253 253
40950 -253 253 253 253 253 253 253 253 253 253 253 253
40951 -253 253 253 253 253 253 253 253 253 253 253 253
40952 -253 253 253 253 253 253 253 253 253 253 253 253
40953 -253 253 253 226 226 226 187 187 187 180 133 36
40954 -216 158 10 236 178 12 239 182 13 236 178 12
40955 -230 174 11 226 170 11 226 170 11 230 174 11
40956 -236 178 12 242 186 14 246 190 14 246 190 14
40957 -246 190 14 246 190 14 246 186 14 239 182 13
40958 -206 162 42 106 106 106 66 66 66 34 34 34
40959 - 14 14 14 6 6 6 0 0 0 0 0 0
40960 - 0 0 0 0 0 0 0 0 0 0 0 0
40961 - 0 0 0 0 0 0 0 0 0 0 0 0
40962 - 0 0 0 0 0 0 0 0 0 6 6 6
40963 - 26 26 26 70 70 70 163 133 67 213 154 11
40964 -236 178 12 246 190 14 246 190 14 246 190 14
40965 -246 190 14 246 190 14 246 190 14 246 190 14
40966 -246 190 14 246 190 14 246 190 14 246 190 14
40967 -246 190 14 246 190 14 246 190 14 241 196 14
40968 -190 146 13 18 14 6 2 2 6 2 2 6
40969 - 46 46 46 246 246 246 253 253 253 253 253 253
40970 -253 253 253 253 253 253 253 253 253 253 253 253
40971 -253 253 253 253 253 253 253 253 253 253 253 253
40972 -253 253 253 253 253 253 253 253 253 253 253 253
40973 -253 253 253 221 221 221 86 86 86 156 107 11
40974 -216 158 10 236 178 12 242 186 14 246 186 14
40975 -242 186 14 239 182 13 239 182 13 242 186 14
40976 -242 186 14 246 186 14 246 190 14 246 190 14
40977 -246 190 14 246 190 14 246 190 14 246 190 14
40978 -242 186 14 225 175 15 142 122 72 66 66 66
40979 - 30 30 30 10 10 10 0 0 0 0 0 0
40980 - 0 0 0 0 0 0 0 0 0 0 0 0
40981 - 0 0 0 0 0 0 0 0 0 0 0 0
40982 - 0 0 0 0 0 0 0 0 0 6 6 6
40983 - 26 26 26 70 70 70 163 133 67 210 150 10
40984 -236 178 12 246 190 14 246 190 14 246 190 14
40985 -246 190 14 246 190 14 246 190 14 246 190 14
40986 -246 190 14 246 190 14 246 190 14 246 190 14
40987 -246 190 14 246 190 14 246 190 14 246 190 14
40988 -232 195 16 121 92 8 34 34 34 106 106 106
40989 -221 221 221 253 253 253 253 253 253 253 253 253
40990 -253 253 253 253 253 253 253 253 253 253 253 253
40991 -253 253 253 253 253 253 253 253 253 253 253 253
40992 -253 253 253 253 253 253 253 253 253 253 253 253
40993 -242 242 242 82 82 82 18 14 6 163 110 8
40994 -216 158 10 236 178 12 242 186 14 246 190 14
40995 -246 190 14 246 190 14 246 190 14 246 190 14
40996 -246 190 14 246 190 14 246 190 14 246 190 14
40997 -246 190 14 246 190 14 246 190 14 246 190 14
40998 -246 190 14 246 190 14 242 186 14 163 133 67
40999 - 46 46 46 18 18 18 6 6 6 0 0 0
41000 - 0 0 0 0 0 0 0 0 0 0 0 0
41001 - 0 0 0 0 0 0 0 0 0 0 0 0
41002 - 0 0 0 0 0 0 0 0 0 10 10 10
41003 - 30 30 30 78 78 78 163 133 67 210 150 10
41004 -236 178 12 246 186 14 246 190 14 246 190 14
41005 -246 190 14 246 190 14 246 190 14 246 190 14
41006 -246 190 14 246 190 14 246 190 14 246 190 14
41007 -246 190 14 246 190 14 246 190 14 246 190 14
41008 -241 196 14 215 174 15 190 178 144 253 253 253
41009 -253 253 253 253 253 253 253 253 253 253 253 253
41010 -253 253 253 253 253 253 253 253 253 253 253 253
41011 -253 253 253 253 253 253 253 253 253 253 253 253
41012 -253 253 253 253 253 253 253 253 253 218 218 218
41013 - 58 58 58 2 2 6 22 18 6 167 114 7
41014 -216 158 10 236 178 12 246 186 14 246 190 14
41015 -246 190 14 246 190 14 246 190 14 246 190 14
41016 -246 190 14 246 190 14 246 190 14 246 190 14
41017 -246 190 14 246 190 14 246 190 14 246 190 14
41018 -246 190 14 246 186 14 242 186 14 190 150 46
41019 - 54 54 54 22 22 22 6 6 6 0 0 0
41020 - 0 0 0 0 0 0 0 0 0 0 0 0
41021 - 0 0 0 0 0 0 0 0 0 0 0 0
41022 - 0 0 0 0 0 0 0 0 0 14 14 14
41023 - 38 38 38 86 86 86 180 133 36 213 154 11
41024 -236 178 12 246 186 14 246 190 14 246 190 14
41025 -246 190 14 246 190 14 246 190 14 246 190 14
41026 -246 190 14 246 190 14 246 190 14 246 190 14
41027 -246 190 14 246 190 14 246 190 14 246 190 14
41028 -246 190 14 232 195 16 190 146 13 214 214 214
41029 -253 253 253 253 253 253 253 253 253 253 253 253
41030 -253 253 253 253 253 253 253 253 253 253 253 253
41031 -253 253 253 253 253 253 253 253 253 253 253 253
41032 -253 253 253 250 250 250 170 170 170 26 26 26
41033 - 2 2 6 2 2 6 37 26 9 163 110 8
41034 -219 162 10 239 182 13 246 186 14 246 190 14
41035 -246 190 14 246 190 14 246 190 14 246 190 14
41036 -246 190 14 246 190 14 246 190 14 246 190 14
41037 -246 190 14 246 190 14 246 190 14 246 190 14
41038 -246 186 14 236 178 12 224 166 10 142 122 72
41039 - 46 46 46 18 18 18 6 6 6 0 0 0
41040 - 0 0 0 0 0 0 0 0 0 0 0 0
41041 - 0 0 0 0 0 0 0 0 0 0 0 0
41042 - 0 0 0 0 0 0 6 6 6 18 18 18
41043 - 50 50 50 109 106 95 192 133 9 224 166 10
41044 -242 186 14 246 190 14 246 190 14 246 190 14
41045 -246 190 14 246 190 14 246 190 14 246 190 14
41046 -246 190 14 246 190 14 246 190 14 246 190 14
41047 -246 190 14 246 190 14 246 190 14 246 190 14
41048 -242 186 14 226 184 13 210 162 10 142 110 46
41049 -226 226 226 253 253 253 253 253 253 253 253 253
41050 -253 253 253 253 253 253 253 253 253 253 253 253
41051 -253 253 253 253 253 253 253 253 253 253 253 253
41052 -198 198 198 66 66 66 2 2 6 2 2 6
41053 - 2 2 6 2 2 6 50 34 6 156 107 11
41054 -219 162 10 239 182 13 246 186 14 246 190 14
41055 -246 190 14 246 190 14 246 190 14 246 190 14
41056 -246 190 14 246 190 14 246 190 14 246 190 14
41057 -246 190 14 246 190 14 246 190 14 242 186 14
41058 -234 174 13 213 154 11 154 122 46 66 66 66
41059 - 30 30 30 10 10 10 0 0 0 0 0 0
41060 - 0 0 0 0 0 0 0 0 0 0 0 0
41061 - 0 0 0 0 0 0 0 0 0 0 0 0
41062 - 0 0 0 0 0 0 6 6 6 22 22 22
41063 - 58 58 58 154 121 60 206 145 10 234 174 13
41064 -242 186 14 246 186 14 246 190 14 246 190 14
41065 -246 190 14 246 190 14 246 190 14 246 190 14
41066 -246 190 14 246 190 14 246 190 14 246 190 14
41067 -246 190 14 246 190 14 246 190 14 246 190 14
41068 -246 186 14 236 178 12 210 162 10 163 110 8
41069 - 61 42 6 138 138 138 218 218 218 250 250 250
41070 -253 253 253 253 253 253 253 253 253 250 250 250
41071 -242 242 242 210 210 210 144 144 144 66 66 66
41072 - 6 6 6 2 2 6 2 2 6 2 2 6
41073 - 2 2 6 2 2 6 61 42 6 163 110 8
41074 -216 158 10 236 178 12 246 190 14 246 190 14
41075 -246 190 14 246 190 14 246 190 14 246 190 14
41076 -246 190 14 246 190 14 246 190 14 246 190 14
41077 -246 190 14 239 182 13 230 174 11 216 158 10
41078 -190 142 34 124 112 88 70 70 70 38 38 38
41079 - 18 18 18 6 6 6 0 0 0 0 0 0
41080 - 0 0 0 0 0 0 0 0 0 0 0 0
41081 - 0 0 0 0 0 0 0 0 0 0 0 0
41082 - 0 0 0 0 0 0 6 6 6 22 22 22
41083 - 62 62 62 168 124 44 206 145 10 224 166 10
41084 -236 178 12 239 182 13 242 186 14 242 186 14
41085 -246 186 14 246 190 14 246 190 14 246 190 14
41086 -246 190 14 246 190 14 246 190 14 246 190 14
41087 -246 190 14 246 190 14 246 190 14 246 190 14
41088 -246 190 14 236 178 12 216 158 10 175 118 6
41089 - 80 54 7 2 2 6 6 6 6 30 30 30
41090 - 54 54 54 62 62 62 50 50 50 38 38 38
41091 - 14 14 14 2 2 6 2 2 6 2 2 6
41092 - 2 2 6 2 2 6 2 2 6 2 2 6
41093 - 2 2 6 6 6 6 80 54 7 167 114 7
41094 -213 154 11 236 178 12 246 190 14 246 190 14
41095 -246 190 14 246 190 14 246 190 14 246 190 14
41096 -246 190 14 242 186 14 239 182 13 239 182 13
41097 -230 174 11 210 150 10 174 135 50 124 112 88
41098 - 82 82 82 54 54 54 34 34 34 18 18 18
41099 - 6 6 6 0 0 0 0 0 0 0 0 0
41100 - 0 0 0 0 0 0 0 0 0 0 0 0
41101 - 0 0 0 0 0 0 0 0 0 0 0 0
41102 - 0 0 0 0 0 0 6 6 6 18 18 18
41103 - 50 50 50 158 118 36 192 133 9 200 144 11
41104 -216 158 10 219 162 10 224 166 10 226 170 11
41105 -230 174 11 236 178 12 239 182 13 239 182 13
41106 -242 186 14 246 186 14 246 190 14 246 190 14
41107 -246 190 14 246 190 14 246 190 14 246 190 14
41108 -246 186 14 230 174 11 210 150 10 163 110 8
41109 -104 69 6 10 10 10 2 2 6 2 2 6
41110 - 2 2 6 2 2 6 2 2 6 2 2 6
41111 - 2 2 6 2 2 6 2 2 6 2 2 6
41112 - 2 2 6 2 2 6 2 2 6 2 2 6
41113 - 2 2 6 6 6 6 91 60 6 167 114 7
41114 -206 145 10 230 174 11 242 186 14 246 190 14
41115 -246 190 14 246 190 14 246 186 14 242 186 14
41116 -239 182 13 230 174 11 224 166 10 213 154 11
41117 -180 133 36 124 112 88 86 86 86 58 58 58
41118 - 38 38 38 22 22 22 10 10 10 6 6 6
41119 - 0 0 0 0 0 0 0 0 0 0 0 0
41120 - 0 0 0 0 0 0 0 0 0 0 0 0
41121 - 0 0 0 0 0 0 0 0 0 0 0 0
41122 - 0 0 0 0 0 0 0 0 0 14 14 14
41123 - 34 34 34 70 70 70 138 110 50 158 118 36
41124 -167 114 7 180 123 7 192 133 9 197 138 11
41125 -200 144 11 206 145 10 213 154 11 219 162 10
41126 -224 166 10 230 174 11 239 182 13 242 186 14
41127 -246 186 14 246 186 14 246 186 14 246 186 14
41128 -239 182 13 216 158 10 185 133 11 152 99 6
41129 -104 69 6 18 14 6 2 2 6 2 2 6
41130 - 2 2 6 2 2 6 2 2 6 2 2 6
41131 - 2 2 6 2 2 6 2 2 6 2 2 6
41132 - 2 2 6 2 2 6 2 2 6 2 2 6
41133 - 2 2 6 6 6 6 80 54 7 152 99 6
41134 -192 133 9 219 162 10 236 178 12 239 182 13
41135 -246 186 14 242 186 14 239 182 13 236 178 12
41136 -224 166 10 206 145 10 192 133 9 154 121 60
41137 - 94 94 94 62 62 62 42 42 42 22 22 22
41138 - 14 14 14 6 6 6 0 0 0 0 0 0
41139 - 0 0 0 0 0 0 0 0 0 0 0 0
41140 - 0 0 0 0 0 0 0 0 0 0 0 0
41141 - 0 0 0 0 0 0 0 0 0 0 0 0
41142 - 0 0 0 0 0 0 0 0 0 6 6 6
41143 - 18 18 18 34 34 34 58 58 58 78 78 78
41144 -101 98 89 124 112 88 142 110 46 156 107 11
41145 -163 110 8 167 114 7 175 118 6 180 123 7
41146 -185 133 11 197 138 11 210 150 10 219 162 10
41147 -226 170 11 236 178 12 236 178 12 234 174 13
41148 -219 162 10 197 138 11 163 110 8 130 83 6
41149 - 91 60 6 10 10 10 2 2 6 2 2 6
41150 - 18 18 18 38 38 38 38 38 38 38 38 38
41151 - 38 38 38 38 38 38 38 38 38 38 38 38
41152 - 38 38 38 38 38 38 26 26 26 2 2 6
41153 - 2 2 6 6 6 6 70 47 6 137 92 6
41154 -175 118 6 200 144 11 219 162 10 230 174 11
41155 -234 174 13 230 174 11 219 162 10 210 150 10
41156 -192 133 9 163 110 8 124 112 88 82 82 82
41157 - 50 50 50 30 30 30 14 14 14 6 6 6
41158 - 0 0 0 0 0 0 0 0 0 0 0 0
41159 - 0 0 0 0 0 0 0 0 0 0 0 0
41160 - 0 0 0 0 0 0 0 0 0 0 0 0
41161 - 0 0 0 0 0 0 0 0 0 0 0 0
41162 - 0 0 0 0 0 0 0 0 0 0 0 0
41163 - 6 6 6 14 14 14 22 22 22 34 34 34
41164 - 42 42 42 58 58 58 74 74 74 86 86 86
41165 -101 98 89 122 102 70 130 98 46 121 87 25
41166 -137 92 6 152 99 6 163 110 8 180 123 7
41167 -185 133 11 197 138 11 206 145 10 200 144 11
41168 -180 123 7 156 107 11 130 83 6 104 69 6
41169 - 50 34 6 54 54 54 110 110 110 101 98 89
41170 - 86 86 86 82 82 82 78 78 78 78 78 78
41171 - 78 78 78 78 78 78 78 78 78 78 78 78
41172 - 78 78 78 82 82 82 86 86 86 94 94 94
41173 -106 106 106 101 101 101 86 66 34 124 80 6
41174 -156 107 11 180 123 7 192 133 9 200 144 11
41175 -206 145 10 200 144 11 192 133 9 175 118 6
41176 -139 102 15 109 106 95 70 70 70 42 42 42
41177 - 22 22 22 10 10 10 0 0 0 0 0 0
41178 - 0 0 0 0 0 0 0 0 0 0 0 0
41179 - 0 0 0 0 0 0 0 0 0 0 0 0
41180 - 0 0 0 0 0 0 0 0 0 0 0 0
41181 - 0 0 0 0 0 0 0 0 0 0 0 0
41182 - 0 0 0 0 0 0 0 0 0 0 0 0
41183 - 0 0 0 0 0 0 6 6 6 10 10 10
41184 - 14 14 14 22 22 22 30 30 30 38 38 38
41185 - 50 50 50 62 62 62 74 74 74 90 90 90
41186 -101 98 89 112 100 78 121 87 25 124 80 6
41187 -137 92 6 152 99 6 152 99 6 152 99 6
41188 -138 86 6 124 80 6 98 70 6 86 66 30
41189 -101 98 89 82 82 82 58 58 58 46 46 46
41190 - 38 38 38 34 34 34 34 34 34 34 34 34
41191 - 34 34 34 34 34 34 34 34 34 34 34 34
41192 - 34 34 34 34 34 34 38 38 38 42 42 42
41193 - 54 54 54 82 82 82 94 86 76 91 60 6
41194 -134 86 6 156 107 11 167 114 7 175 118 6
41195 -175 118 6 167 114 7 152 99 6 121 87 25
41196 -101 98 89 62 62 62 34 34 34 18 18 18
41197 - 6 6 6 0 0 0 0 0 0 0 0 0
41198 - 0 0 0 0 0 0 0 0 0 0 0 0
41199 - 0 0 0 0 0 0 0 0 0 0 0 0
41200 - 0 0 0 0 0 0 0 0 0 0 0 0
41201 - 0 0 0 0 0 0 0 0 0 0 0 0
41202 - 0 0 0 0 0 0 0 0 0 0 0 0
41203 - 0 0 0 0 0 0 0 0 0 0 0 0
41204 - 0 0 0 6 6 6 6 6 6 10 10 10
41205 - 18 18 18 22 22 22 30 30 30 42 42 42
41206 - 50 50 50 66 66 66 86 86 86 101 98 89
41207 -106 86 58 98 70 6 104 69 6 104 69 6
41208 -104 69 6 91 60 6 82 62 34 90 90 90
41209 - 62 62 62 38 38 38 22 22 22 14 14 14
41210 - 10 10 10 10 10 10 10 10 10 10 10 10
41211 - 10 10 10 10 10 10 6 6 6 10 10 10
41212 - 10 10 10 10 10 10 10 10 10 14 14 14
41213 - 22 22 22 42 42 42 70 70 70 89 81 66
41214 - 80 54 7 104 69 6 124 80 6 137 92 6
41215 -134 86 6 116 81 8 100 82 52 86 86 86
41216 - 58 58 58 30 30 30 14 14 14 6 6 6
41217 - 0 0 0 0 0 0 0 0 0 0 0 0
41218 - 0 0 0 0 0 0 0 0 0 0 0 0
41219 - 0 0 0 0 0 0 0 0 0 0 0 0
41220 - 0 0 0 0 0 0 0 0 0 0 0 0
41221 - 0 0 0 0 0 0 0 0 0 0 0 0
41222 - 0 0 0 0 0 0 0 0 0 0 0 0
41223 - 0 0 0 0 0 0 0 0 0 0 0 0
41224 - 0 0 0 0 0 0 0 0 0 0 0 0
41225 - 0 0 0 6 6 6 10 10 10 14 14 14
41226 - 18 18 18 26 26 26 38 38 38 54 54 54
41227 - 70 70 70 86 86 86 94 86 76 89 81 66
41228 - 89 81 66 86 86 86 74 74 74 50 50 50
41229 - 30 30 30 14 14 14 6 6 6 0 0 0
41230 - 0 0 0 0 0 0 0 0 0 0 0 0
41231 - 0 0 0 0 0 0 0 0 0 0 0 0
41232 - 0 0 0 0 0 0 0 0 0 0 0 0
41233 - 6 6 6 18 18 18 34 34 34 58 58 58
41234 - 82 82 82 89 81 66 89 81 66 89 81 66
41235 - 94 86 66 94 86 76 74 74 74 50 50 50
41236 - 26 26 26 14 14 14 6 6 6 0 0 0
41237 - 0 0 0 0 0 0 0 0 0 0 0 0
41238 - 0 0 0 0 0 0 0 0 0 0 0 0
41239 - 0 0 0 0 0 0 0 0 0 0 0 0
41240 - 0 0 0 0 0 0 0 0 0 0 0 0
41241 - 0 0 0 0 0 0 0 0 0 0 0 0
41242 - 0 0 0 0 0 0 0 0 0 0 0 0
41243 - 0 0 0 0 0 0 0 0 0 0 0 0
41244 - 0 0 0 0 0 0 0 0 0 0 0 0
41245 - 0 0 0 0 0 0 0 0 0 0 0 0
41246 - 6 6 6 6 6 6 14 14 14 18 18 18
41247 - 30 30 30 38 38 38 46 46 46 54 54 54
41248 - 50 50 50 42 42 42 30 30 30 18 18 18
41249 - 10 10 10 0 0 0 0 0 0 0 0 0
41250 - 0 0 0 0 0 0 0 0 0 0 0 0
41251 - 0 0 0 0 0 0 0 0 0 0 0 0
41252 - 0 0 0 0 0 0 0 0 0 0 0 0
41253 - 0 0 0 6 6 6 14 14 14 26 26 26
41254 - 38 38 38 50 50 50 58 58 58 58 58 58
41255 - 54 54 54 42 42 42 30 30 30 18 18 18
41256 - 10 10 10 0 0 0 0 0 0 0 0 0
41257 - 0 0 0 0 0 0 0 0 0 0 0 0
41258 - 0 0 0 0 0 0 0 0 0 0 0 0
41259 - 0 0 0 0 0 0 0 0 0 0 0 0
41260 - 0 0 0 0 0 0 0 0 0 0 0 0
41261 - 0 0 0 0 0 0 0 0 0 0 0 0
41262 - 0 0 0 0 0 0 0 0 0 0 0 0
41263 - 0 0 0 0 0 0 0 0 0 0 0 0
41264 - 0 0 0 0 0 0 0 0 0 0 0 0
41265 - 0 0 0 0 0 0 0 0 0 0 0 0
41266 - 0 0 0 0 0 0 0 0 0 6 6 6
41267 - 6 6 6 10 10 10 14 14 14 18 18 18
41268 - 18 18 18 14 14 14 10 10 10 6 6 6
41269 - 0 0 0 0 0 0 0 0 0 0 0 0
41270 - 0 0 0 0 0 0 0 0 0 0 0 0
41271 - 0 0 0 0 0 0 0 0 0 0 0 0
41272 - 0 0 0 0 0 0 0 0 0 0 0 0
41273 - 0 0 0 0 0 0 0 0 0 6 6 6
41274 - 14 14 14 18 18 18 22 22 22 22 22 22
41275 - 18 18 18 14 14 14 10 10 10 6 6 6
41276 - 0 0 0 0 0 0 0 0 0 0 0 0
41277 - 0 0 0 0 0 0 0 0 0 0 0 0
41278 - 0 0 0 0 0 0 0 0 0 0 0 0
41279 - 0 0 0 0 0 0 0 0 0 0 0 0
41280 - 0 0 0 0 0 0 0 0 0 0 0 0
41281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41294 +4 4 4 4 4 4
41295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41308 +4 4 4 4 4 4
41309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41322 +4 4 4 4 4 4
41323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4
41337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364 +4 4 4 4 4 4
41365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41370 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41375 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41376 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4
41379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41383 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41384 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41385 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41389 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41390 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41391 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392 +4 4 4 4 4 4
41393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41397 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41398 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41399 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41403 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41404 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41405 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41406 +4 4 4 4 4 4
41407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41410 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41411 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41412 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41413 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41415 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41416 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41417 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41418 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41419 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41420 +4 4 4 4 4 4
41421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41424 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41425 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41426 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41427 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41428 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41429 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41430 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41431 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41432 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41433 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41434 +4 4 4 4 4 4
41435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41438 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41439 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41440 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41441 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41442 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41443 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41444 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41445 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41446 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41447 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41448 +4 4 4 4 4 4
41449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41451 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41452 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41453 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41454 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41455 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41456 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41457 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41458 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41459 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41460 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41461 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41462 +4 4 4 4 4 4
41463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41465 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41466 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41467 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41468 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41469 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41470 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41471 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41472 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41473 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41474 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41475 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41476 +4 4 4 4 4 4
41477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41479 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41480 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41481 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41482 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41483 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41484 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41485 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41486 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41487 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41488 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41489 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41490 +4 4 4 4 4 4
41491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41493 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41494 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41495 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41496 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41497 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41498 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41499 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41500 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41501 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41502 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41503 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41504 +4 4 4 4 4 4
41505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41506 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41507 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41508 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41509 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41510 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41511 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41512 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41513 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41514 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41515 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41516 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41517 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41518 +4 4 4 4 4 4
41519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41520 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41521 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41522 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41523 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41524 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41525 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41526 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41527 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41528 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41529 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41530 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41531 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41532 +0 0 0 4 4 4
41533 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41534 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41535 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41536 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41537 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41538 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41539 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41540 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41541 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41542 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41543 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41544 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41545 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41546 +2 0 0 0 0 0
41547 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41548 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41549 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41550 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41551 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41552 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41553 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41554 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41555 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41556 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41557 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41558 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41559 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41560 +37 38 37 0 0 0
41561 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41562 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41563 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41564 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41565 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41566 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41567 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41568 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41569 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41570 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41571 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41572 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41573 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41574 +85 115 134 4 0 0
41575 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41576 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41577 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41578 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41579 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41580 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41581 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41582 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41583 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41584 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41585 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41586 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41587 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41588 +60 73 81 4 0 0
41589 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41590 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41591 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41592 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41593 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41594 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41595 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41596 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41597 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41598 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41599 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41600 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41601 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41602 +16 19 21 4 0 0
41603 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41604 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41605 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41606 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41607 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41608 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41609 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41610 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41611 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41612 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41613 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41614 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41615 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41616 +4 0 0 4 3 3
41617 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41618 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41619 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41621 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41622 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41623 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41624 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41625 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41626 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41627 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41628 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41629 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41630 +3 2 2 4 4 4
41631 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41632 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41633 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41634 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41635 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41636 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41637 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41638 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41639 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41640 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41641 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41642 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41643 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41644 +4 4 4 4 4 4
41645 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41646 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41647 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41648 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41649 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41650 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41651 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41652 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41653 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41654 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41655 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41656 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41657 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41658 +4 4 4 4 4 4
41659 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41660 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41661 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41662 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41663 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41664 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41665 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41666 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41667 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41668 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41669 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41670 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41671 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41672 +5 5 5 5 5 5
41673 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41674 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41675 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41676 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41677 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41678 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41679 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41680 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41681 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41682 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41683 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41684 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41685 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41686 +5 5 5 4 4 4
41687 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41688 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41689 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41690 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41691 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41692 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41693 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41694 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41695 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41696 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41697 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41698 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41700 +4 4 4 4 4 4
41701 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41702 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41703 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41704 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41705 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41706 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41707 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41708 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41709 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41710 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41711 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41712 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41714 +4 4 4 4 4 4
41715 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41716 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41717 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41718 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41719 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41720 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41721 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41722 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41723 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41724 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41725 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41728 +4 4 4 4 4 4
41729 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41730 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41731 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41732 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41733 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41734 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41735 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41736 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41737 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41738 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41739 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41742 +4 4 4 4 4 4
41743 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41744 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41745 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41746 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41747 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41748 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41749 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41750 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41751 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41752 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41753 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41756 +4 4 4 4 4 4
41757 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41758 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41759 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41760 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41761 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41762 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41763 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41764 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41765 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41766 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41767 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41770 +4 4 4 4 4 4
41771 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41772 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41773 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41774 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41775 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41776 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41777 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41778 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41779 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41780 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41781 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41784 +4 4 4 4 4 4
41785 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41786 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41787 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41788 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41789 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41790 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41791 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41792 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41793 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41794 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41795 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41798 +4 4 4 4 4 4
41799 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41800 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41801 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41802 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41803 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41804 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41805 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41806 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41807 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41808 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41809 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41812 +4 4 4 4 4 4
41813 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41814 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41815 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41816 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41817 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41818 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41819 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41820 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41821 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41822 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41823 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41826 +4 4 4 4 4 4
41827 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41828 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41829 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41830 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41831 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41832 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41833 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41834 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41835 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41836 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41837 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41840 +4 4 4 4 4 4
41841 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41842 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41843 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41844 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41845 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41846 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41847 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41848 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41849 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41850 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41851 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41854 +4 4 4 4 4 4
41855 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41856 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41857 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41858 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41859 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41860 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41861 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41862 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41863 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41864 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41865 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41868 +4 4 4 4 4 4
41869 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41870 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41871 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41872 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41873 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41874 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41875 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41876 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41877 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41878 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41879 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41882 +4 4 4 4 4 4
41883 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41884 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41885 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41886 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41887 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41888 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41889 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41890 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41891 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41892 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41893 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41896 +4 4 4 4 4 4
41897 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41898 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41899 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41900 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41901 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41902 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41903 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41904 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41905 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41906 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41907 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41910 +4 4 4 4 4 4
41911 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41912 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41913 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41914 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41915 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41916 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41917 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41918 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41919 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41920 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41921 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41924 +4 4 4 4 4 4
41925 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41926 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41927 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41928 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41929 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41930 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41931 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41932 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41933 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41934 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41935 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41938 +4 4 4 4 4 4
41939 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41940 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41941 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41942 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41943 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41944 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41945 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41946 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41947 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41948 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41949 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41952 +4 4 4 4 4 4
41953 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41954 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41955 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41956 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41957 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41958 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41959 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41960 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41961 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41962 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41963 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41966 +4 4 4 4 4 4
41967 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41968 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41969 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41970 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41971 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41972 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41973 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41974 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41975 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41976 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41977 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41980 +4 4 4 4 4 4
41981 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41982 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41983 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41984 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41985 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41986 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41987 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41988 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41989 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41990 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41991 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41994 +4 4 4 4 4 4
41995 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41996 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41997 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41998 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41999 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42000 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42001 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42002 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42003 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42004 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42005 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42008 +4 4 4 4 4 4
42009 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42010 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42011 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42012 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42013 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42014 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42015 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42016 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42017 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42018 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42019 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42022 +4 4 4 4 4 4
42023 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42024 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42025 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42026 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42027 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42028 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42029 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42030 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42031 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42032 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42033 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42036 +4 4 4 4 4 4
42037 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42038 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42039 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42040 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42041 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42042 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42043 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42044 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42045 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42046 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42047 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42050 +4 4 4 4 4 4
42051 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42052 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42053 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42054 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42055 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42056 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42057 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42058 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42059 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42060 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42061 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42064 +4 4 4 4 4 4
42065 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42066 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42067 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42068 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42069 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42070 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42071 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42072 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42073 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42074 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42075 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42078 +4 4 4 4 4 4
42079 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42080 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42081 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42082 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42083 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42084 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42085 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42086 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42087 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42088 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42089 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42092 +4 4 4 4 4 4
42093 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42094 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42095 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42096 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42097 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42098 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42099 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42100 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42101 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42102 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42106 +4 4 4 4 4 4
42107 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42108 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42109 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42110 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42111 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42112 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42113 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42114 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42115 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42116 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42120 +4 4 4 4 4 4
42121 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42122 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42123 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42124 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42125 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42126 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42127 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42128 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42129 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42130 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42134 +4 4 4 4 4 4
42135 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42136 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42137 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42138 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42139 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42140 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42141 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42142 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42143 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42144 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42148 +4 4 4 4 4 4
42149 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42150 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42151 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42152 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42153 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42154 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42155 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42156 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42157 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42162 +4 4 4 4 4 4
42163 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42164 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42165 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42166 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42167 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42168 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42169 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42170 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42171 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42176 +4 4 4 4 4 4
42177 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42178 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42179 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42180 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42181 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42182 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42183 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42184 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42185 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42190 +4 4 4 4 4 4
42191 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42192 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42193 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42194 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42195 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42196 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42197 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42198 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42204 +4 4 4 4 4 4
42205 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42206 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42207 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42208 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42209 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42210 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42211 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42212 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42218 +4 4 4 4 4 4
42219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42220 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42221 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42222 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42223 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42224 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42225 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42226 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42232 +4 4 4 4 4 4
42233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42235 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42236 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42237 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42238 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42239 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42240 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42246 +4 4 4 4 4 4
42247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42249 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42250 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42251 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42252 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42253 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42254 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42260 +4 4 4 4 4 4
42261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42264 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42265 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42266 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42267 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42268 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42274 +4 4 4 4 4 4
42275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42278 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42279 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42280 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42281 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42288 +4 4 4 4 4 4
42289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42292 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42293 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42294 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42295 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42302 +4 4 4 4 4 4
42303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42306 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42307 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42308 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42309 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42316 +4 4 4 4 4 4
42317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42320 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42321 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42322 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42323 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42330 +4 4 4 4 4 4
42331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42335 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42336 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42337 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42344 +4 4 4 4 4 4
42345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42349 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42350 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42351 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42358 +4 4 4 4 4 4
42359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42363 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42364 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42365 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42372 +4 4 4 4 4 4
42373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42377 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42378 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42386 +4 4 4 4 4 4
42387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42391 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42392 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42400 +4 4 4 4 4 4
42401 diff -urNp linux-2.6.32.46/drivers/video/nvidia/nv_backlight.c linux-2.6.32.46/drivers/video/nvidia/nv_backlight.c
42402 --- linux-2.6.32.46/drivers/video/nvidia/nv_backlight.c 2011-03-27 14:31:47.000000000 -0400
42403 +++ linux-2.6.32.46/drivers/video/nvidia/nv_backlight.c 2011-04-17 15:56:46.000000000 -0400
42404 @@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(stru
42405 return bd->props.brightness;
42406 }
42407
42408 -static struct backlight_ops nvidia_bl_ops = {
42409 +static const struct backlight_ops nvidia_bl_ops = {
42410 .get_brightness = nvidia_bl_get_brightness,
42411 .update_status = nvidia_bl_update_status,
42412 };
42413 diff -urNp linux-2.6.32.46/drivers/video/riva/fbdev.c linux-2.6.32.46/drivers/video/riva/fbdev.c
42414 --- linux-2.6.32.46/drivers/video/riva/fbdev.c 2011-03-27 14:31:47.000000000 -0400
42415 +++ linux-2.6.32.46/drivers/video/riva/fbdev.c 2011-04-17 15:56:46.000000000 -0400
42416 @@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct
42417 return bd->props.brightness;
42418 }
42419
42420 -static struct backlight_ops riva_bl_ops = {
42421 +static const struct backlight_ops riva_bl_ops = {
42422 .get_brightness = riva_bl_get_brightness,
42423 .update_status = riva_bl_update_status,
42424 };
42425 diff -urNp linux-2.6.32.46/drivers/video/uvesafb.c linux-2.6.32.46/drivers/video/uvesafb.c
42426 --- linux-2.6.32.46/drivers/video/uvesafb.c 2011-03-27 14:31:47.000000000 -0400
42427 +++ linux-2.6.32.46/drivers/video/uvesafb.c 2011-04-17 15:56:46.000000000 -0400
42428 @@ -18,6 +18,7 @@
42429 #include <linux/fb.h>
42430 #include <linux/io.h>
42431 #include <linux/mutex.h>
42432 +#include <linux/moduleloader.h>
42433 #include <video/edid.h>
42434 #include <video/uvesafb.h>
42435 #ifdef CONFIG_X86
42436 @@ -120,7 +121,7 @@ static int uvesafb_helper_start(void)
42437 NULL,
42438 };
42439
42440 - return call_usermodehelper(v86d_path, argv, envp, 1);
42441 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
42442 }
42443
42444 /*
42445 @@ -568,10 +569,32 @@ static int __devinit uvesafb_vbe_getpmi(
42446 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42447 par->pmi_setpal = par->ypan = 0;
42448 } else {
42449 +
42450 +#ifdef CONFIG_PAX_KERNEXEC
42451 +#ifdef CONFIG_MODULES
42452 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42453 +#endif
42454 + if (!par->pmi_code) {
42455 + par->pmi_setpal = par->ypan = 0;
42456 + return 0;
42457 + }
42458 +#endif
42459 +
42460 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42461 + task->t.regs.edi);
42462 +
42463 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42464 + pax_open_kernel();
42465 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42466 + pax_close_kernel();
42467 +
42468 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42469 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42470 +#else
42471 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42472 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42473 +#endif
42474 +
42475 printk(KERN_INFO "uvesafb: protected mode interface info at "
42476 "%04x:%04x\n",
42477 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42478 @@ -1799,6 +1822,11 @@ out:
42479 if (par->vbe_modes)
42480 kfree(par->vbe_modes);
42481
42482 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42483 + if (par->pmi_code)
42484 + module_free_exec(NULL, par->pmi_code);
42485 +#endif
42486 +
42487 framebuffer_release(info);
42488 return err;
42489 }
42490 @@ -1825,6 +1853,12 @@ static int uvesafb_remove(struct platfor
42491 kfree(par->vbe_state_orig);
42492 if (par->vbe_state_saved)
42493 kfree(par->vbe_state_saved);
42494 +
42495 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42496 + if (par->pmi_code)
42497 + module_free_exec(NULL, par->pmi_code);
42498 +#endif
42499 +
42500 }
42501
42502 framebuffer_release(info);
42503 diff -urNp linux-2.6.32.46/drivers/video/vesafb.c linux-2.6.32.46/drivers/video/vesafb.c
42504 --- linux-2.6.32.46/drivers/video/vesafb.c 2011-03-27 14:31:47.000000000 -0400
42505 +++ linux-2.6.32.46/drivers/video/vesafb.c 2011-08-05 20:33:55.000000000 -0400
42506 @@ -9,6 +9,7 @@
42507 */
42508
42509 #include <linux/module.h>
42510 +#include <linux/moduleloader.h>
42511 #include <linux/kernel.h>
42512 #include <linux/errno.h>
42513 #include <linux/string.h>
42514 @@ -53,8 +54,8 @@ static int vram_remap __initdata; /*
42515 static int vram_total __initdata; /* Set total amount of memory */
42516 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42517 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42518 -static void (*pmi_start)(void) __read_mostly;
42519 -static void (*pmi_pal) (void) __read_mostly;
42520 +static void (*pmi_start)(void) __read_only;
42521 +static void (*pmi_pal) (void) __read_only;
42522 static int depth __read_mostly;
42523 static int vga_compat __read_mostly;
42524 /* --------------------------------------------------------------------- */
42525 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct pl
42526 unsigned int size_vmode;
42527 unsigned int size_remap;
42528 unsigned int size_total;
42529 + void *pmi_code = NULL;
42530
42531 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42532 return -ENODEV;
42533 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct pl
42534 size_remap = size_total;
42535 vesafb_fix.smem_len = size_remap;
42536
42537 -#ifndef __i386__
42538 - screen_info.vesapm_seg = 0;
42539 -#endif
42540 -
42541 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42542 printk(KERN_WARNING
42543 "vesafb: cannot reserve video memory at 0x%lx\n",
42544 @@ -315,9 +313,21 @@ static int __init vesafb_probe(struct pl
42545 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42546 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42547
42548 +#ifdef __i386__
42549 +
42550 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42551 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42552 + if (!pmi_code)
42553 +#elif !defined(CONFIG_PAX_KERNEXEC)
42554 + if (0)
42555 +#endif
42556 +
42557 +#endif
42558 + screen_info.vesapm_seg = 0;
42559 +
42560 if (screen_info.vesapm_seg) {
42561 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42562 - screen_info.vesapm_seg,screen_info.vesapm_off);
42563 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42564 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42565 }
42566
42567 if (screen_info.vesapm_seg < 0xc000)
42568 @@ -325,9 +335,25 @@ static int __init vesafb_probe(struct pl
42569
42570 if (ypan || pmi_setpal) {
42571 unsigned short *pmi_base;
42572 +
42573 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42574 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42575 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42576 +
42577 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42578 + pax_open_kernel();
42579 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42580 +#else
42581 + pmi_code = pmi_base;
42582 +#endif
42583 +
42584 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42585 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42586 +
42587 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42588 + pmi_start = ktva_ktla(pmi_start);
42589 + pmi_pal = ktva_ktla(pmi_pal);
42590 + pax_close_kernel();
42591 +#endif
42592 +
42593 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42594 if (pmi_base[3]) {
42595 printk(KERN_INFO "vesafb: pmi: ports = ");
42596 @@ -469,6 +495,11 @@ static int __init vesafb_probe(struct pl
42597 info->node, info->fix.id);
42598 return 0;
42599 err:
42600 +
42601 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42602 + module_free_exec(NULL, pmi_code);
42603 +#endif
42604 +
42605 if (info->screen_base)
42606 iounmap(info->screen_base);
42607 framebuffer_release(info);
42608 diff -urNp linux-2.6.32.46/drivers/xen/sys-hypervisor.c linux-2.6.32.46/drivers/xen/sys-hypervisor.c
42609 --- linux-2.6.32.46/drivers/xen/sys-hypervisor.c 2011-03-27 14:31:47.000000000 -0400
42610 +++ linux-2.6.32.46/drivers/xen/sys-hypervisor.c 2011-04-17 15:56:46.000000000 -0400
42611 @@ -425,7 +425,7 @@ static ssize_t hyp_sysfs_store(struct ko
42612 return 0;
42613 }
42614
42615 -static struct sysfs_ops hyp_sysfs_ops = {
42616 +static const struct sysfs_ops hyp_sysfs_ops = {
42617 .show = hyp_sysfs_show,
42618 .store = hyp_sysfs_store,
42619 };
42620 diff -urNp linux-2.6.32.46/fs/9p/vfs_inode.c linux-2.6.32.46/fs/9p/vfs_inode.c
42621 --- linux-2.6.32.46/fs/9p/vfs_inode.c 2011-03-27 14:31:47.000000000 -0400
42622 +++ linux-2.6.32.46/fs/9p/vfs_inode.c 2011-04-17 15:56:46.000000000 -0400
42623 @@ -1079,7 +1079,7 @@ static void *v9fs_vfs_follow_link(struct
42624 static void
42625 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42626 {
42627 - char *s = nd_get_link(nd);
42628 + const char *s = nd_get_link(nd);
42629
42630 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
42631 IS_ERR(s) ? "<error>" : s);
42632 diff -urNp linux-2.6.32.46/fs/Kconfig.binfmt linux-2.6.32.46/fs/Kconfig.binfmt
42633 --- linux-2.6.32.46/fs/Kconfig.binfmt 2011-03-27 14:31:47.000000000 -0400
42634 +++ linux-2.6.32.46/fs/Kconfig.binfmt 2011-04-17 15:56:46.000000000 -0400
42635 @@ -86,7 +86,7 @@ config HAVE_AOUT
42636
42637 config BINFMT_AOUT
42638 tristate "Kernel support for a.out and ECOFF binaries"
42639 - depends on HAVE_AOUT
42640 + depends on HAVE_AOUT && BROKEN
42641 ---help---
42642 A.out (Assembler.OUTput) is a set of formats for libraries and
42643 executables used in the earliest versions of UNIX. Linux used
42644 diff -urNp linux-2.6.32.46/fs/aio.c linux-2.6.32.46/fs/aio.c
42645 --- linux-2.6.32.46/fs/aio.c 2011-03-27 14:31:47.000000000 -0400
42646 +++ linux-2.6.32.46/fs/aio.c 2011-06-04 20:40:21.000000000 -0400
42647 @@ -115,7 +115,7 @@ static int aio_setup_ring(struct kioctx
42648 size += sizeof(struct io_event) * nr_events;
42649 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42650
42651 - if (nr_pages < 0)
42652 + if (nr_pages <= 0)
42653 return -EINVAL;
42654
42655 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42656 @@ -1089,6 +1089,8 @@ static int read_events(struct kioctx *ct
42657 struct aio_timeout to;
42658 int retry = 0;
42659
42660 + pax_track_stack();
42661 +
42662 /* needed to zero any padding within an entry (there shouldn't be
42663 * any, but C is fun!
42664 */
42665 @@ -1382,13 +1384,18 @@ static ssize_t aio_fsync(struct kiocb *i
42666 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
42667 {
42668 ssize_t ret;
42669 + struct iovec iovstack;
42670
42671 ret = rw_copy_check_uvector(type, (struct iovec __user *)kiocb->ki_buf,
42672 kiocb->ki_nbytes, 1,
42673 - &kiocb->ki_inline_vec, &kiocb->ki_iovec);
42674 + &iovstack, &kiocb->ki_iovec);
42675 if (ret < 0)
42676 goto out;
42677
42678 + if (kiocb->ki_iovec == &iovstack) {
42679 + kiocb->ki_inline_vec = iovstack;
42680 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42681 + }
42682 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42683 kiocb->ki_cur_seg = 0;
42684 /* ki_nbytes/left now reflect bytes instead of segs */
42685 diff -urNp linux-2.6.32.46/fs/attr.c linux-2.6.32.46/fs/attr.c
42686 --- linux-2.6.32.46/fs/attr.c 2011-03-27 14:31:47.000000000 -0400
42687 +++ linux-2.6.32.46/fs/attr.c 2011-04-17 15:56:46.000000000 -0400
42688 @@ -83,6 +83,7 @@ int inode_newsize_ok(const struct inode
42689 unsigned long limit;
42690
42691 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
42692 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42693 if (limit != RLIM_INFINITY && offset > limit)
42694 goto out_sig;
42695 if (offset > inode->i_sb->s_maxbytes)
42696 diff -urNp linux-2.6.32.46/fs/autofs/root.c linux-2.6.32.46/fs/autofs/root.c
42697 --- linux-2.6.32.46/fs/autofs/root.c 2011-03-27 14:31:47.000000000 -0400
42698 +++ linux-2.6.32.46/fs/autofs/root.c 2011-04-17 15:56:46.000000000 -0400
42699 @@ -299,7 +299,8 @@ static int autofs_root_symlink(struct in
42700 set_bit(n,sbi->symlink_bitmap);
42701 sl = &sbi->symlink[n];
42702 sl->len = strlen(symname);
42703 - sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
42704 + slsize = sl->len+1;
42705 + sl->data = kmalloc(slsize, GFP_KERNEL);
42706 if (!sl->data) {
42707 clear_bit(n,sbi->symlink_bitmap);
42708 unlock_kernel();
42709 diff -urNp linux-2.6.32.46/fs/autofs4/symlink.c linux-2.6.32.46/fs/autofs4/symlink.c
42710 --- linux-2.6.32.46/fs/autofs4/symlink.c 2011-03-27 14:31:47.000000000 -0400
42711 +++ linux-2.6.32.46/fs/autofs4/symlink.c 2011-04-17 15:56:46.000000000 -0400
42712 @@ -15,7 +15,7 @@
42713 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
42714 {
42715 struct autofs_info *ino = autofs4_dentry_ino(dentry);
42716 - nd_set_link(nd, (char *)ino->u.symlink);
42717 + nd_set_link(nd, ino->u.symlink);
42718 return NULL;
42719 }
42720
42721 diff -urNp linux-2.6.32.46/fs/autofs4/waitq.c linux-2.6.32.46/fs/autofs4/waitq.c
42722 --- linux-2.6.32.46/fs/autofs4/waitq.c 2011-03-27 14:31:47.000000000 -0400
42723 +++ linux-2.6.32.46/fs/autofs4/waitq.c 2011-10-06 09:37:14.000000000 -0400
42724 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *fi
42725 {
42726 unsigned long sigpipe, flags;
42727 mm_segment_t fs;
42728 - const char *data = (const char *)addr;
42729 + const char __user *data = (const char __force_user *)addr;
42730 ssize_t wr = 0;
42731
42732 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
42733 diff -urNp linux-2.6.32.46/fs/befs/linuxvfs.c linux-2.6.32.46/fs/befs/linuxvfs.c
42734 --- linux-2.6.32.46/fs/befs/linuxvfs.c 2011-08-29 22:24:44.000000000 -0400
42735 +++ linux-2.6.32.46/fs/befs/linuxvfs.c 2011-08-29 22:25:07.000000000 -0400
42736 @@ -498,7 +498,7 @@ static void befs_put_link(struct dentry
42737 {
42738 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42739 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42740 - char *link = nd_get_link(nd);
42741 + const char *link = nd_get_link(nd);
42742 if (!IS_ERR(link))
42743 kfree(link);
42744 }
42745 diff -urNp linux-2.6.32.46/fs/binfmt_aout.c linux-2.6.32.46/fs/binfmt_aout.c
42746 --- linux-2.6.32.46/fs/binfmt_aout.c 2011-03-27 14:31:47.000000000 -0400
42747 +++ linux-2.6.32.46/fs/binfmt_aout.c 2011-04-17 15:56:46.000000000 -0400
42748 @@ -16,6 +16,7 @@
42749 #include <linux/string.h>
42750 #include <linux/fs.h>
42751 #include <linux/file.h>
42752 +#include <linux/security.h>
42753 #include <linux/stat.h>
42754 #include <linux/fcntl.h>
42755 #include <linux/ptrace.h>
42756 @@ -102,6 +103,8 @@ static int aout_core_dump(long signr, st
42757 #endif
42758 # define START_STACK(u) (u.start_stack)
42759
42760 + memset(&dump, 0, sizeof(dump));
42761 +
42762 fs = get_fs();
42763 set_fs(KERNEL_DS);
42764 has_dumped = 1;
42765 @@ -113,10 +116,12 @@ static int aout_core_dump(long signr, st
42766
42767 /* If the size of the dump file exceeds the rlimit, then see what would happen
42768 if we wrote the stack, but not the data area. */
42769 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42770 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
42771 dump.u_dsize = 0;
42772
42773 /* Make sure we have enough room to write the stack and data areas. */
42774 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42775 if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
42776 dump.u_ssize = 0;
42777
42778 @@ -146,9 +151,7 @@ static int aout_core_dump(long signr, st
42779 dump_size = dump.u_ssize << PAGE_SHIFT;
42780 DUMP_WRITE(dump_start,dump_size);
42781 }
42782 -/* Finally dump the task struct. Not be used by gdb, but could be useful */
42783 - set_fs(KERNEL_DS);
42784 - DUMP_WRITE(current,sizeof(*current));
42785 +/* Finally, let's not dump the task struct. Not be used by gdb, but could be useful to an attacker */
42786 end_coredump:
42787 set_fs(fs);
42788 return has_dumped;
42789 @@ -249,6 +252,8 @@ static int load_aout_binary(struct linux
42790 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
42791 if (rlim >= RLIM_INFINITY)
42792 rlim = ~0;
42793 +
42794 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42795 if (ex.a_data + ex.a_bss > rlim)
42796 return -ENOMEM;
42797
42798 @@ -277,6 +282,27 @@ static int load_aout_binary(struct linux
42799 install_exec_creds(bprm);
42800 current->flags &= ~PF_FORKNOEXEC;
42801
42802 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42803 + current->mm->pax_flags = 0UL;
42804 +#endif
42805 +
42806 +#ifdef CONFIG_PAX_PAGEEXEC
42807 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42808 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42809 +
42810 +#ifdef CONFIG_PAX_EMUTRAMP
42811 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42812 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42813 +#endif
42814 +
42815 +#ifdef CONFIG_PAX_MPROTECT
42816 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42817 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42818 +#endif
42819 +
42820 + }
42821 +#endif
42822 +
42823 if (N_MAGIC(ex) == OMAGIC) {
42824 unsigned long text_addr, map_size;
42825 loff_t pos;
42826 @@ -349,7 +375,7 @@ static int load_aout_binary(struct linux
42827
42828 down_write(&current->mm->mmap_sem);
42829 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42830 - PROT_READ | PROT_WRITE | PROT_EXEC,
42831 + PROT_READ | PROT_WRITE,
42832 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42833 fd_offset + ex.a_text);
42834 up_write(&current->mm->mmap_sem);
42835 diff -urNp linux-2.6.32.46/fs/binfmt_elf.c linux-2.6.32.46/fs/binfmt_elf.c
42836 --- linux-2.6.32.46/fs/binfmt_elf.c 2011-03-27 14:31:47.000000000 -0400
42837 +++ linux-2.6.32.46/fs/binfmt_elf.c 2011-05-16 21:46:57.000000000 -0400
42838 @@ -50,6 +50,10 @@ static int elf_core_dump(long signr, str
42839 #define elf_core_dump NULL
42840 #endif
42841
42842 +#ifdef CONFIG_PAX_MPROTECT
42843 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42844 +#endif
42845 +
42846 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42847 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42848 #else
42849 @@ -69,6 +73,11 @@ static struct linux_binfmt elf_format =
42850 .load_binary = load_elf_binary,
42851 .load_shlib = load_elf_library,
42852 .core_dump = elf_core_dump,
42853 +
42854 +#ifdef CONFIG_PAX_MPROTECT
42855 + .handle_mprotect= elf_handle_mprotect,
42856 +#endif
42857 +
42858 .min_coredump = ELF_EXEC_PAGESIZE,
42859 .hasvdso = 1
42860 };
42861 @@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
42862
42863 static int set_brk(unsigned long start, unsigned long end)
42864 {
42865 + unsigned long e = end;
42866 +
42867 start = ELF_PAGEALIGN(start);
42868 end = ELF_PAGEALIGN(end);
42869 if (end > start) {
42870 @@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
42871 if (BAD_ADDR(addr))
42872 return addr;
42873 }
42874 - current->mm->start_brk = current->mm->brk = end;
42875 + current->mm->start_brk = current->mm->brk = e;
42876 return 0;
42877 }
42878
42879 @@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
42880 elf_addr_t __user *u_rand_bytes;
42881 const char *k_platform = ELF_PLATFORM;
42882 const char *k_base_platform = ELF_BASE_PLATFORM;
42883 - unsigned char k_rand_bytes[16];
42884 + u32 k_rand_bytes[4];
42885 int items;
42886 elf_addr_t *elf_info;
42887 int ei_index = 0;
42888 const struct cred *cred = current_cred();
42889 struct vm_area_struct *vma;
42890 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42891 +
42892 + pax_track_stack();
42893
42894 /*
42895 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42896 @@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
42897 * Generate 16 random bytes for userspace PRNG seeding.
42898 */
42899 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42900 - u_rand_bytes = (elf_addr_t __user *)
42901 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42902 + srandom32(k_rand_bytes[0] ^ random32());
42903 + srandom32(k_rand_bytes[1] ^ random32());
42904 + srandom32(k_rand_bytes[2] ^ random32());
42905 + srandom32(k_rand_bytes[3] ^ random32());
42906 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42907 + u_rand_bytes = (elf_addr_t __user *) p;
42908 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42909 return -EFAULT;
42910
42911 @@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
42912 return -EFAULT;
42913 current->mm->env_end = p;
42914
42915 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42916 +
42917 /* Put the elf_info on the stack in the right place. */
42918 sp = (elf_addr_t __user *)envp + 1;
42919 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42920 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42921 return -EFAULT;
42922 return 0;
42923 }
42924 @@ -385,10 +405,10 @@ static unsigned long load_elf_interp(str
42925 {
42926 struct elf_phdr *elf_phdata;
42927 struct elf_phdr *eppnt;
42928 - unsigned long load_addr = 0;
42929 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42930 int load_addr_set = 0;
42931 unsigned long last_bss = 0, elf_bss = 0;
42932 - unsigned long error = ~0UL;
42933 + unsigned long error = -EINVAL;
42934 unsigned long total_size;
42935 int retval, i, size;
42936
42937 @@ -434,6 +454,11 @@ static unsigned long load_elf_interp(str
42938 goto out_close;
42939 }
42940
42941 +#ifdef CONFIG_PAX_SEGMEXEC
42942 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42943 + pax_task_size = SEGMEXEC_TASK_SIZE;
42944 +#endif
42945 +
42946 eppnt = elf_phdata;
42947 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42948 if (eppnt->p_type == PT_LOAD) {
42949 @@ -477,8 +502,8 @@ static unsigned long load_elf_interp(str
42950 k = load_addr + eppnt->p_vaddr;
42951 if (BAD_ADDR(k) ||
42952 eppnt->p_filesz > eppnt->p_memsz ||
42953 - eppnt->p_memsz > TASK_SIZE ||
42954 - TASK_SIZE - eppnt->p_memsz < k) {
42955 + eppnt->p_memsz > pax_task_size ||
42956 + pax_task_size - eppnt->p_memsz < k) {
42957 error = -ENOMEM;
42958 goto out_close;
42959 }
42960 @@ -532,6 +557,194 @@ out:
42961 return error;
42962 }
42963
42964 +#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
42965 +static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
42966 +{
42967 + unsigned long pax_flags = 0UL;
42968 +
42969 +#ifdef CONFIG_PAX_PAGEEXEC
42970 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42971 + pax_flags |= MF_PAX_PAGEEXEC;
42972 +#endif
42973 +
42974 +#ifdef CONFIG_PAX_SEGMEXEC
42975 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42976 + pax_flags |= MF_PAX_SEGMEXEC;
42977 +#endif
42978 +
42979 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42980 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42981 + if (nx_enabled)
42982 + pax_flags &= ~MF_PAX_SEGMEXEC;
42983 + else
42984 + pax_flags &= ~MF_PAX_PAGEEXEC;
42985 + }
42986 +#endif
42987 +
42988 +#ifdef CONFIG_PAX_EMUTRAMP
42989 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42990 + pax_flags |= MF_PAX_EMUTRAMP;
42991 +#endif
42992 +
42993 +#ifdef CONFIG_PAX_MPROTECT
42994 + if (elf_phdata->p_flags & PF_MPROTECT)
42995 + pax_flags |= MF_PAX_MPROTECT;
42996 +#endif
42997 +
42998 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42999 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43000 + pax_flags |= MF_PAX_RANDMMAP;
43001 +#endif
43002 +
43003 + return pax_flags;
43004 +}
43005 +#endif
43006 +
43007 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43008 +static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
43009 +{
43010 + unsigned long pax_flags = 0UL;
43011 +
43012 +#ifdef CONFIG_PAX_PAGEEXEC
43013 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43014 + pax_flags |= MF_PAX_PAGEEXEC;
43015 +#endif
43016 +
43017 +#ifdef CONFIG_PAX_SEGMEXEC
43018 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43019 + pax_flags |= MF_PAX_SEGMEXEC;
43020 +#endif
43021 +
43022 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43023 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43024 + if (nx_enabled)
43025 + pax_flags &= ~MF_PAX_SEGMEXEC;
43026 + else
43027 + pax_flags &= ~MF_PAX_PAGEEXEC;
43028 + }
43029 +#endif
43030 +
43031 +#ifdef CONFIG_PAX_EMUTRAMP
43032 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43033 + pax_flags |= MF_PAX_EMUTRAMP;
43034 +#endif
43035 +
43036 +#ifdef CONFIG_PAX_MPROTECT
43037 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43038 + pax_flags |= MF_PAX_MPROTECT;
43039 +#endif
43040 +
43041 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43042 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43043 + pax_flags |= MF_PAX_RANDMMAP;
43044 +#endif
43045 +
43046 + return pax_flags;
43047 +}
43048 +#endif
43049 +
43050 +#ifdef CONFIG_PAX_EI_PAX
43051 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43052 +{
43053 + unsigned long pax_flags = 0UL;
43054 +
43055 +#ifdef CONFIG_PAX_PAGEEXEC
43056 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43057 + pax_flags |= MF_PAX_PAGEEXEC;
43058 +#endif
43059 +
43060 +#ifdef CONFIG_PAX_SEGMEXEC
43061 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43062 + pax_flags |= MF_PAX_SEGMEXEC;
43063 +#endif
43064 +
43065 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43066 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43067 + if (nx_enabled)
43068 + pax_flags &= ~MF_PAX_SEGMEXEC;
43069 + else
43070 + pax_flags &= ~MF_PAX_PAGEEXEC;
43071 + }
43072 +#endif
43073 +
43074 +#ifdef CONFIG_PAX_EMUTRAMP
43075 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43076 + pax_flags |= MF_PAX_EMUTRAMP;
43077 +#endif
43078 +
43079 +#ifdef CONFIG_PAX_MPROTECT
43080 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43081 + pax_flags |= MF_PAX_MPROTECT;
43082 +#endif
43083 +
43084 +#ifdef CONFIG_PAX_ASLR
43085 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43086 + pax_flags |= MF_PAX_RANDMMAP;
43087 +#endif
43088 +
43089 + return pax_flags;
43090 +}
43091 +#endif
43092 +
43093 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43094 +static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43095 +{
43096 + unsigned long pax_flags = 0UL;
43097 +
43098 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43099 + unsigned long i;
43100 + int found_flags = 0;
43101 +#endif
43102 +
43103 +#ifdef CONFIG_PAX_EI_PAX
43104 + pax_flags = pax_parse_ei_pax(elf_ex);
43105 +#endif
43106 +
43107 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43108 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43109 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43110 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43111 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43112 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43113 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43114 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43115 + return -EINVAL;
43116 +
43117 +#ifdef CONFIG_PAX_SOFTMODE
43118 + if (pax_softmode)
43119 + pax_flags = pax_parse_softmode(&elf_phdata[i]);
43120 + else
43121 +#endif
43122 +
43123 + pax_flags = pax_parse_hardmode(&elf_phdata[i]);
43124 + found_flags = 1;
43125 + break;
43126 + }
43127 +#endif
43128 +
43129 +#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
43130 + if (found_flags == 0) {
43131 + struct elf_phdr phdr;
43132 + memset(&phdr, 0, sizeof(phdr));
43133 + phdr.p_flags = PF_NOEMUTRAMP;
43134 +#ifdef CONFIG_PAX_SOFTMODE
43135 + if (pax_softmode)
43136 + pax_flags = pax_parse_softmode(&phdr);
43137 + else
43138 +#endif
43139 + pax_flags = pax_parse_hardmode(&phdr);
43140 + }
43141 +#endif
43142 +
43143 +
43144 + if (0 > pax_check_flags(&pax_flags))
43145 + return -EINVAL;
43146 +
43147 + current->mm->pax_flags = pax_flags;
43148 + return 0;
43149 +}
43150 +#endif
43151 +
43152 /*
43153 * These are the functions used to load ELF style executables and shared
43154 * libraries. There is no binary dependent code anywhere else.
43155 @@ -548,6 +761,11 @@ static unsigned long randomize_stack_top
43156 {
43157 unsigned int random_variable = 0;
43158
43159 +#ifdef CONFIG_PAX_RANDUSTACK
43160 + if (randomize_va_space)
43161 + return stack_top - current->mm->delta_stack;
43162 +#endif
43163 +
43164 if ((current->flags & PF_RANDOMIZE) &&
43165 !(current->personality & ADDR_NO_RANDOMIZE)) {
43166 random_variable = get_random_int() & STACK_RND_MASK;
43167 @@ -566,7 +784,7 @@ static int load_elf_binary(struct linux_
43168 unsigned long load_addr = 0, load_bias = 0;
43169 int load_addr_set = 0;
43170 char * elf_interpreter = NULL;
43171 - unsigned long error;
43172 + unsigned long error = 0;
43173 struct elf_phdr *elf_ppnt, *elf_phdata;
43174 unsigned long elf_bss, elf_brk;
43175 int retval, i;
43176 @@ -576,11 +794,11 @@ static int load_elf_binary(struct linux_
43177 unsigned long start_code, end_code, start_data, end_data;
43178 unsigned long reloc_func_desc = 0;
43179 int executable_stack = EXSTACK_DEFAULT;
43180 - unsigned long def_flags = 0;
43181 struct {
43182 struct elfhdr elf_ex;
43183 struct elfhdr interp_elf_ex;
43184 } *loc;
43185 + unsigned long pax_task_size = TASK_SIZE;
43186
43187 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43188 if (!loc) {
43189 @@ -718,11 +936,80 @@ static int load_elf_binary(struct linux_
43190
43191 /* OK, This is the point of no return */
43192 current->flags &= ~PF_FORKNOEXEC;
43193 - current->mm->def_flags = def_flags;
43194 +
43195 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43196 + current->mm->pax_flags = 0UL;
43197 +#endif
43198 +
43199 +#ifdef CONFIG_PAX_DLRESOLVE
43200 + current->mm->call_dl_resolve = 0UL;
43201 +#endif
43202 +
43203 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43204 + current->mm->call_syscall = 0UL;
43205 +#endif
43206 +
43207 +#ifdef CONFIG_PAX_ASLR
43208 + current->mm->delta_mmap = 0UL;
43209 + current->mm->delta_stack = 0UL;
43210 +#endif
43211 +
43212 + current->mm->def_flags = 0;
43213 +
43214 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43215 + if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
43216 + send_sig(SIGKILL, current, 0);
43217 + goto out_free_dentry;
43218 + }
43219 +#endif
43220 +
43221 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43222 + pax_set_initial_flags(bprm);
43223 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43224 + if (pax_set_initial_flags_func)
43225 + (pax_set_initial_flags_func)(bprm);
43226 +#endif
43227 +
43228 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43229 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
43230 + current->mm->context.user_cs_limit = PAGE_SIZE;
43231 + current->mm->def_flags |= VM_PAGEEXEC;
43232 + }
43233 +#endif
43234 +
43235 +#ifdef CONFIG_PAX_SEGMEXEC
43236 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43237 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43238 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43239 + pax_task_size = SEGMEXEC_TASK_SIZE;
43240 + }
43241 +#endif
43242 +
43243 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43244 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43245 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43246 + put_cpu();
43247 + }
43248 +#endif
43249
43250 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43251 may depend on the personality. */
43252 SET_PERSONALITY(loc->elf_ex);
43253 +
43254 +#ifdef CONFIG_PAX_ASLR
43255 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43256 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43257 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43258 + }
43259 +#endif
43260 +
43261 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43262 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43263 + executable_stack = EXSTACK_DISABLE_X;
43264 + current->personality &= ~READ_IMPLIES_EXEC;
43265 + } else
43266 +#endif
43267 +
43268 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43269 current->personality |= READ_IMPLIES_EXEC;
43270
43271 @@ -804,6 +1091,20 @@ static int load_elf_binary(struct linux_
43272 #else
43273 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43274 #endif
43275 +
43276 +#ifdef CONFIG_PAX_RANDMMAP
43277 + /* PaX: randomize base address at the default exe base if requested */
43278 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43279 +#ifdef CONFIG_SPARC64
43280 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43281 +#else
43282 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43283 +#endif
43284 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43285 + elf_flags |= MAP_FIXED;
43286 + }
43287 +#endif
43288 +
43289 }
43290
43291 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43292 @@ -836,9 +1137,9 @@ static int load_elf_binary(struct linux_
43293 * allowed task size. Note that p_filesz must always be
43294 * <= p_memsz so it is only necessary to check p_memsz.
43295 */
43296 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43297 - elf_ppnt->p_memsz > TASK_SIZE ||
43298 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43299 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43300 + elf_ppnt->p_memsz > pax_task_size ||
43301 + pax_task_size - elf_ppnt->p_memsz < k) {
43302 /* set_brk can never work. Avoid overflows. */
43303 send_sig(SIGKILL, current, 0);
43304 retval = -EINVAL;
43305 @@ -866,6 +1167,11 @@ static int load_elf_binary(struct linux_
43306 start_data += load_bias;
43307 end_data += load_bias;
43308
43309 +#ifdef CONFIG_PAX_RANDMMAP
43310 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
43311 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
43312 +#endif
43313 +
43314 /* Calling set_brk effectively mmaps the pages that we need
43315 * for the bss and break sections. We must do this before
43316 * mapping in the interpreter, to make sure it doesn't wind
43317 @@ -877,9 +1183,11 @@ static int load_elf_binary(struct linux_
43318 goto out_free_dentry;
43319 }
43320 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43321 - send_sig(SIGSEGV, current, 0);
43322 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43323 - goto out_free_dentry;
43324 + /*
43325 + * This bss-zeroing can fail if the ELF
43326 + * file specifies odd protections. So
43327 + * we don't check the return value
43328 + */
43329 }
43330
43331 if (elf_interpreter) {
43332 @@ -1112,8 +1420,10 @@ static int dump_seek(struct file *file,
43333 unsigned long n = off;
43334 if (n > PAGE_SIZE)
43335 n = PAGE_SIZE;
43336 - if (!dump_write(file, buf, n))
43337 + if (!dump_write(file, buf, n)) {
43338 + free_page((unsigned long)buf);
43339 return 0;
43340 + }
43341 off -= n;
43342 }
43343 free_page((unsigned long)buf);
43344 @@ -1125,7 +1435,7 @@ static int dump_seek(struct file *file,
43345 * Decide what to dump of a segment, part, all or none.
43346 */
43347 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43348 - unsigned long mm_flags)
43349 + unsigned long mm_flags, long signr)
43350 {
43351 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43352
43353 @@ -1159,7 +1469,7 @@ static unsigned long vma_dump_size(struc
43354 if (vma->vm_file == NULL)
43355 return 0;
43356
43357 - if (FILTER(MAPPED_PRIVATE))
43358 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43359 goto whole;
43360
43361 /*
43362 @@ -1255,8 +1565,11 @@ static int writenote(struct memelfnote *
43363 #undef DUMP_WRITE
43364
43365 #define DUMP_WRITE(addr, nr) \
43366 + do { \
43367 + gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
43368 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
43369 - goto end_coredump;
43370 + goto end_coredump; \
43371 + } while (0);
43372
43373 static void fill_elf_header(struct elfhdr *elf, int segs,
43374 u16 machine, u32 flags, u8 osabi)
43375 @@ -1385,9 +1698,9 @@ static void fill_auxv_note(struct memelf
43376 {
43377 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43378 int i = 0;
43379 - do
43380 + do {
43381 i += 2;
43382 - while (auxv[i - 2] != AT_NULL);
43383 + } while (auxv[i - 2] != AT_NULL);
43384 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43385 }
43386
43387 @@ -1973,7 +2286,7 @@ static int elf_core_dump(long signr, str
43388 phdr.p_offset = offset;
43389 phdr.p_vaddr = vma->vm_start;
43390 phdr.p_paddr = 0;
43391 - phdr.p_filesz = vma_dump_size(vma, mm_flags);
43392 + phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
43393 phdr.p_memsz = vma->vm_end - vma->vm_start;
43394 offset += phdr.p_filesz;
43395 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43396 @@ -2006,7 +2319,7 @@ static int elf_core_dump(long signr, str
43397 unsigned long addr;
43398 unsigned long end;
43399
43400 - end = vma->vm_start + vma_dump_size(vma, mm_flags);
43401 + end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
43402
43403 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43404 struct page *page;
43405 @@ -2015,6 +2328,7 @@ static int elf_core_dump(long signr, str
43406 page = get_dump_page(addr);
43407 if (page) {
43408 void *kaddr = kmap(page);
43409 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43410 stop = ((size += PAGE_SIZE) > limit) ||
43411 !dump_write(file, kaddr, PAGE_SIZE);
43412 kunmap(page);
43413 @@ -2042,6 +2356,97 @@ out:
43414
43415 #endif /* USE_ELF_CORE_DUMP */
43416
43417 +#ifdef CONFIG_PAX_MPROTECT
43418 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43419 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43420 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43421 + *
43422 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43423 + * basis because we want to allow the common case and not the special ones.
43424 + */
43425 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43426 +{
43427 + struct elfhdr elf_h;
43428 + struct elf_phdr elf_p;
43429 + unsigned long i;
43430 + unsigned long oldflags;
43431 + bool is_textrel_rw, is_textrel_rx, is_relro;
43432 +
43433 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43434 + return;
43435 +
43436 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43437 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43438 +
43439 +#ifdef CONFIG_PAX_ELFRELOCS
43440 + /* possible TEXTREL */
43441 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43442 + 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);
43443 +#else
43444 + is_textrel_rw = false;
43445 + is_textrel_rx = false;
43446 +#endif
43447 +
43448 + /* possible RELRO */
43449 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43450 +
43451 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43452 + return;
43453 +
43454 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43455 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43456 +
43457 +#ifdef CONFIG_PAX_ETEXECRELOCS
43458 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43459 +#else
43460 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43461 +#endif
43462 +
43463 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43464 + !elf_check_arch(&elf_h) ||
43465 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43466 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43467 + return;
43468 +
43469 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43470 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43471 + return;
43472 + switch (elf_p.p_type) {
43473 + case PT_DYNAMIC:
43474 + if (!is_textrel_rw && !is_textrel_rx)
43475 + continue;
43476 + i = 0UL;
43477 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43478 + elf_dyn dyn;
43479 +
43480 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43481 + return;
43482 + if (dyn.d_tag == DT_NULL)
43483 + return;
43484 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43485 + gr_log_textrel(vma);
43486 + if (is_textrel_rw)
43487 + vma->vm_flags |= VM_MAYWRITE;
43488 + else
43489 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43490 + vma->vm_flags &= ~VM_MAYWRITE;
43491 + return;
43492 + }
43493 + i++;
43494 + }
43495 + return;
43496 +
43497 + case PT_GNU_RELRO:
43498 + if (!is_relro)
43499 + continue;
43500 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43501 + vma->vm_flags &= ~VM_MAYWRITE;
43502 + return;
43503 + }
43504 + }
43505 +}
43506 +#endif
43507 +
43508 static int __init init_elf_binfmt(void)
43509 {
43510 return register_binfmt(&elf_format);
43511 diff -urNp linux-2.6.32.46/fs/binfmt_flat.c linux-2.6.32.46/fs/binfmt_flat.c
43512 --- linux-2.6.32.46/fs/binfmt_flat.c 2011-03-27 14:31:47.000000000 -0400
43513 +++ linux-2.6.32.46/fs/binfmt_flat.c 2011-04-17 15:56:46.000000000 -0400
43514 @@ -564,7 +564,9 @@ static int load_flat_file(struct linux_b
43515 realdatastart = (unsigned long) -ENOMEM;
43516 printk("Unable to allocate RAM for process data, errno %d\n",
43517 (int)-realdatastart);
43518 + down_write(&current->mm->mmap_sem);
43519 do_munmap(current->mm, textpos, text_len);
43520 + up_write(&current->mm->mmap_sem);
43521 ret = realdatastart;
43522 goto err;
43523 }
43524 @@ -588,8 +590,10 @@ static int load_flat_file(struct linux_b
43525 }
43526 if (IS_ERR_VALUE(result)) {
43527 printk("Unable to read data+bss, errno %d\n", (int)-result);
43528 + down_write(&current->mm->mmap_sem);
43529 do_munmap(current->mm, textpos, text_len);
43530 do_munmap(current->mm, realdatastart, data_len + extra);
43531 + up_write(&current->mm->mmap_sem);
43532 ret = result;
43533 goto err;
43534 }
43535 @@ -658,8 +662,10 @@ static int load_flat_file(struct linux_b
43536 }
43537 if (IS_ERR_VALUE(result)) {
43538 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43539 + down_write(&current->mm->mmap_sem);
43540 do_munmap(current->mm, textpos, text_len + data_len + extra +
43541 MAX_SHARED_LIBS * sizeof(unsigned long));
43542 + up_write(&current->mm->mmap_sem);
43543 ret = result;
43544 goto err;
43545 }
43546 diff -urNp linux-2.6.32.46/fs/bio.c linux-2.6.32.46/fs/bio.c
43547 --- linux-2.6.32.46/fs/bio.c 2011-03-27 14:31:47.000000000 -0400
43548 +++ linux-2.6.32.46/fs/bio.c 2011-10-06 09:37:14.000000000 -0400
43549 @@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_cr
43550
43551 i = 0;
43552 while (i < bio_slab_nr) {
43553 - struct bio_slab *bslab = &bio_slabs[i];
43554 + bslab = &bio_slabs[i];
43555
43556 if (!bslab->slab && entry == -1)
43557 entry = i;
43558 @@ -1236,7 +1236,7 @@ static void bio_copy_kern_endio(struct b
43559 const int read = bio_data_dir(bio) == READ;
43560 struct bio_map_data *bmd = bio->bi_private;
43561 int i;
43562 - char *p = bmd->sgvecs[0].iov_base;
43563 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43564
43565 __bio_for_each_segment(bvec, bio, i, 0) {
43566 char *addr = page_address(bvec->bv_page);
43567 diff -urNp linux-2.6.32.46/fs/block_dev.c linux-2.6.32.46/fs/block_dev.c
43568 --- linux-2.6.32.46/fs/block_dev.c 2011-08-09 18:35:29.000000000 -0400
43569 +++ linux-2.6.32.46/fs/block_dev.c 2011-08-09 18:34:00.000000000 -0400
43570 @@ -664,7 +664,7 @@ int bd_claim(struct block_device *bdev,
43571 else if (bdev->bd_contains == bdev)
43572 res = 0; /* is a whole device which isn't held */
43573
43574 - else if (bdev->bd_contains->bd_holder == bd_claim)
43575 + else if (bdev->bd_contains->bd_holder == (void *)bd_claim)
43576 res = 0; /* is a partition of a device that is being partitioned */
43577 else if (bdev->bd_contains->bd_holder != NULL)
43578 res = -EBUSY; /* is a partition of a held device */
43579 diff -urNp linux-2.6.32.46/fs/btrfs/ctree.c linux-2.6.32.46/fs/btrfs/ctree.c
43580 --- linux-2.6.32.46/fs/btrfs/ctree.c 2011-03-27 14:31:47.000000000 -0400
43581 +++ linux-2.6.32.46/fs/btrfs/ctree.c 2011-04-17 15:56:46.000000000 -0400
43582 @@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(st
43583 free_extent_buffer(buf);
43584 add_root_to_dirty_list(root);
43585 } else {
43586 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43587 - parent_start = parent->start;
43588 - else
43589 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43590 + if (parent)
43591 + parent_start = parent->start;
43592 + else
43593 + parent_start = 0;
43594 + } else
43595 parent_start = 0;
43596
43597 WARN_ON(trans->transid != btrfs_header_generation(parent));
43598 @@ -3645,7 +3648,6 @@ setup_items_for_insert(struct btrfs_tran
43599
43600 ret = 0;
43601 if (slot == 0) {
43602 - struct btrfs_disk_key disk_key;
43603 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
43604 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
43605 }
43606 diff -urNp linux-2.6.32.46/fs/btrfs/disk-io.c linux-2.6.32.46/fs/btrfs/disk-io.c
43607 --- linux-2.6.32.46/fs/btrfs/disk-io.c 2011-04-17 17:00:52.000000000 -0400
43608 +++ linux-2.6.32.46/fs/btrfs/disk-io.c 2011-04-17 17:03:11.000000000 -0400
43609 @@ -39,7 +39,7 @@
43610 #include "tree-log.h"
43611 #include "free-space-cache.h"
43612
43613 -static struct extent_io_ops btree_extent_io_ops;
43614 +static const struct extent_io_ops btree_extent_io_ops;
43615 static void end_workqueue_fn(struct btrfs_work *work);
43616 static void free_fs_root(struct btrfs_root *root);
43617
43618 @@ -2607,7 +2607,7 @@ out:
43619 return 0;
43620 }
43621
43622 -static struct extent_io_ops btree_extent_io_ops = {
43623 +static const struct extent_io_ops btree_extent_io_ops = {
43624 .write_cache_pages_lock_hook = btree_lock_page_hook,
43625 .readpage_end_io_hook = btree_readpage_end_io_hook,
43626 .submit_bio_hook = btree_submit_bio_hook,
43627 diff -urNp linux-2.6.32.46/fs/btrfs/extent-tree.c linux-2.6.32.46/fs/btrfs/extent-tree.c
43628 --- linux-2.6.32.46/fs/btrfs/extent-tree.c 2011-03-27 14:31:47.000000000 -0400
43629 +++ linux-2.6.32.46/fs/btrfs/extent-tree.c 2011-06-12 06:39:08.000000000 -0400
43630 @@ -7141,6 +7141,10 @@ static noinline int relocate_one_extent(
43631 u64 group_start = group->key.objectid;
43632 new_extents = kmalloc(sizeof(*new_extents),
43633 GFP_NOFS);
43634 + if (!new_extents) {
43635 + ret = -ENOMEM;
43636 + goto out;
43637 + }
43638 nr_extents = 1;
43639 ret = get_new_locations(reloc_inode,
43640 extent_key,
43641 diff -urNp linux-2.6.32.46/fs/btrfs/extent_io.h linux-2.6.32.46/fs/btrfs/extent_io.h
43642 --- linux-2.6.32.46/fs/btrfs/extent_io.h 2011-03-27 14:31:47.000000000 -0400
43643 +++ linux-2.6.32.46/fs/btrfs/extent_io.h 2011-04-17 15:56:46.000000000 -0400
43644 @@ -49,36 +49,36 @@ typedef int (extent_submit_bio_hook_t)(s
43645 struct bio *bio, int mirror_num,
43646 unsigned long bio_flags);
43647 struct extent_io_ops {
43648 - int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
43649 + int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
43650 u64 start, u64 end, int *page_started,
43651 unsigned long *nr_written);
43652 - int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
43653 - int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
43654 + int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
43655 + int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
43656 extent_submit_bio_hook_t *submit_bio_hook;
43657 - int (*merge_bio_hook)(struct page *page, unsigned long offset,
43658 + int (* const merge_bio_hook)(struct page *page, unsigned long offset,
43659 size_t size, struct bio *bio,
43660 unsigned long bio_flags);
43661 - int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
43662 - int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
43663 + int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
43664 + int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
43665 u64 start, u64 end,
43666 struct extent_state *state);
43667 - int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
43668 + int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
43669 u64 start, u64 end,
43670 struct extent_state *state);
43671 - int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
43672 + int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
43673 struct extent_state *state);
43674 - int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
43675 + int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
43676 struct extent_state *state, int uptodate);
43677 - int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
43678 + int (* const set_bit_hook)(struct inode *inode, u64 start, u64 end,
43679 unsigned long old, unsigned long bits);
43680 - int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
43681 + int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
43682 unsigned long bits);
43683 - int (*merge_extent_hook)(struct inode *inode,
43684 + int (* const merge_extent_hook)(struct inode *inode,
43685 struct extent_state *new,
43686 struct extent_state *other);
43687 - int (*split_extent_hook)(struct inode *inode,
43688 + int (* const split_extent_hook)(struct inode *inode,
43689 struct extent_state *orig, u64 split);
43690 - int (*write_cache_pages_lock_hook)(struct page *page);
43691 + int (* const write_cache_pages_lock_hook)(struct page *page);
43692 };
43693
43694 struct extent_io_tree {
43695 @@ -88,7 +88,7 @@ struct extent_io_tree {
43696 u64 dirty_bytes;
43697 spinlock_t lock;
43698 spinlock_t buffer_lock;
43699 - struct extent_io_ops *ops;
43700 + const struct extent_io_ops *ops;
43701 };
43702
43703 struct extent_state {
43704 diff -urNp linux-2.6.32.46/fs/btrfs/free-space-cache.c linux-2.6.32.46/fs/btrfs/free-space-cache.c
43705 --- linux-2.6.32.46/fs/btrfs/free-space-cache.c 2011-03-27 14:31:47.000000000 -0400
43706 +++ linux-2.6.32.46/fs/btrfs/free-space-cache.c 2011-04-17 15:56:46.000000000 -0400
43707 @@ -1074,8 +1074,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
43708
43709 while(1) {
43710 if (entry->bytes < bytes || entry->offset < min_start) {
43711 - struct rb_node *node;
43712 -
43713 node = rb_next(&entry->offset_index);
43714 if (!node)
43715 break;
43716 @@ -1226,7 +1224,7 @@ again:
43717 */
43718 while (entry->bitmap || found_bitmap ||
43719 (!entry->bitmap && entry->bytes < min_bytes)) {
43720 - struct rb_node *node = rb_next(&entry->offset_index);
43721 + node = rb_next(&entry->offset_index);
43722
43723 if (entry->bitmap && entry->bytes > bytes + empty_size) {
43724 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
43725 diff -urNp linux-2.6.32.46/fs/btrfs/inode.c linux-2.6.32.46/fs/btrfs/inode.c
43726 --- linux-2.6.32.46/fs/btrfs/inode.c 2011-03-27 14:31:47.000000000 -0400
43727 +++ linux-2.6.32.46/fs/btrfs/inode.c 2011-06-12 06:39:58.000000000 -0400
43728 @@ -63,7 +63,7 @@ static const struct inode_operations btr
43729 static const struct address_space_operations btrfs_aops;
43730 static const struct address_space_operations btrfs_symlink_aops;
43731 static const struct file_operations btrfs_dir_file_operations;
43732 -static struct extent_io_ops btrfs_extent_io_ops;
43733 +static const struct extent_io_ops btrfs_extent_io_ops;
43734
43735 static struct kmem_cache *btrfs_inode_cachep;
43736 struct kmem_cache *btrfs_trans_handle_cachep;
43737 @@ -925,6 +925,7 @@ static int cow_file_range_async(struct i
43738 1, 0, NULL, GFP_NOFS);
43739 while (start < end) {
43740 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
43741 + BUG_ON(!async_cow);
43742 async_cow->inode = inode;
43743 async_cow->root = root;
43744 async_cow->locked_page = locked_page;
43745 @@ -4591,6 +4592,8 @@ static noinline int uncompress_inline(st
43746 inline_size = btrfs_file_extent_inline_item_len(leaf,
43747 btrfs_item_nr(leaf, path->slots[0]));
43748 tmp = kmalloc(inline_size, GFP_NOFS);
43749 + if (!tmp)
43750 + return -ENOMEM;
43751 ptr = btrfs_file_extent_inline_start(item);
43752
43753 read_extent_buffer(leaf, tmp, ptr, inline_size);
43754 @@ -5410,7 +5413,7 @@ fail:
43755 return -ENOMEM;
43756 }
43757
43758 -static int btrfs_getattr(struct vfsmount *mnt,
43759 +int btrfs_getattr(struct vfsmount *mnt,
43760 struct dentry *dentry, struct kstat *stat)
43761 {
43762 struct inode *inode = dentry->d_inode;
43763 @@ -5422,6 +5425,14 @@ static int btrfs_getattr(struct vfsmount
43764 return 0;
43765 }
43766
43767 +EXPORT_SYMBOL(btrfs_getattr);
43768 +
43769 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43770 +{
43771 + return BTRFS_I(inode)->root->anon_super.s_dev;
43772 +}
43773 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43774 +
43775 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
43776 struct inode *new_dir, struct dentry *new_dentry)
43777 {
43778 @@ -5972,7 +5983,7 @@ static const struct file_operations btrf
43779 .fsync = btrfs_sync_file,
43780 };
43781
43782 -static struct extent_io_ops btrfs_extent_io_ops = {
43783 +static const struct extent_io_ops btrfs_extent_io_ops = {
43784 .fill_delalloc = run_delalloc_range,
43785 .submit_bio_hook = btrfs_submit_bio_hook,
43786 .merge_bio_hook = btrfs_merge_bio_hook,
43787 diff -urNp linux-2.6.32.46/fs/btrfs/relocation.c linux-2.6.32.46/fs/btrfs/relocation.c
43788 --- linux-2.6.32.46/fs/btrfs/relocation.c 2011-03-27 14:31:47.000000000 -0400
43789 +++ linux-2.6.32.46/fs/btrfs/relocation.c 2011-04-17 15:56:46.000000000 -0400
43790 @@ -884,7 +884,7 @@ static int __update_reloc_root(struct bt
43791 }
43792 spin_unlock(&rc->reloc_root_tree.lock);
43793
43794 - BUG_ON((struct btrfs_root *)node->data != root);
43795 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43796
43797 if (!del) {
43798 spin_lock(&rc->reloc_root_tree.lock);
43799 diff -urNp linux-2.6.32.46/fs/btrfs/sysfs.c linux-2.6.32.46/fs/btrfs/sysfs.c
43800 --- linux-2.6.32.46/fs/btrfs/sysfs.c 2011-03-27 14:31:47.000000000 -0400
43801 +++ linux-2.6.32.46/fs/btrfs/sysfs.c 2011-04-17 15:56:46.000000000 -0400
43802 @@ -164,12 +164,12 @@ static void btrfs_root_release(struct ko
43803 complete(&root->kobj_unregister);
43804 }
43805
43806 -static struct sysfs_ops btrfs_super_attr_ops = {
43807 +static const struct sysfs_ops btrfs_super_attr_ops = {
43808 .show = btrfs_super_attr_show,
43809 .store = btrfs_super_attr_store,
43810 };
43811
43812 -static struct sysfs_ops btrfs_root_attr_ops = {
43813 +static const struct sysfs_ops btrfs_root_attr_ops = {
43814 .show = btrfs_root_attr_show,
43815 .store = btrfs_root_attr_store,
43816 };
43817 diff -urNp linux-2.6.32.46/fs/buffer.c linux-2.6.32.46/fs/buffer.c
43818 --- linux-2.6.32.46/fs/buffer.c 2011-03-27 14:31:47.000000000 -0400
43819 +++ linux-2.6.32.46/fs/buffer.c 2011-04-17 15:56:46.000000000 -0400
43820 @@ -25,6 +25,7 @@
43821 #include <linux/percpu.h>
43822 #include <linux/slab.h>
43823 #include <linux/capability.h>
43824 +#include <linux/security.h>
43825 #include <linux/blkdev.h>
43826 #include <linux/file.h>
43827 #include <linux/quotaops.h>
43828 diff -urNp linux-2.6.32.46/fs/cachefiles/bind.c linux-2.6.32.46/fs/cachefiles/bind.c
43829 --- linux-2.6.32.46/fs/cachefiles/bind.c 2011-03-27 14:31:47.000000000 -0400
43830 +++ linux-2.6.32.46/fs/cachefiles/bind.c 2011-04-17 15:56:46.000000000 -0400
43831 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
43832 args);
43833
43834 /* start by checking things over */
43835 - ASSERT(cache->fstop_percent >= 0 &&
43836 - cache->fstop_percent < cache->fcull_percent &&
43837 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43838 cache->fcull_percent < cache->frun_percent &&
43839 cache->frun_percent < 100);
43840
43841 - ASSERT(cache->bstop_percent >= 0 &&
43842 - cache->bstop_percent < cache->bcull_percent &&
43843 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43844 cache->bcull_percent < cache->brun_percent &&
43845 cache->brun_percent < 100);
43846
43847 diff -urNp linux-2.6.32.46/fs/cachefiles/daemon.c linux-2.6.32.46/fs/cachefiles/daemon.c
43848 --- linux-2.6.32.46/fs/cachefiles/daemon.c 2011-03-27 14:31:47.000000000 -0400
43849 +++ linux-2.6.32.46/fs/cachefiles/daemon.c 2011-04-17 15:56:46.000000000 -0400
43850 @@ -220,7 +220,7 @@ static ssize_t cachefiles_daemon_write(s
43851 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43852 return -EIO;
43853
43854 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43855 + if (datalen > PAGE_SIZE - 1)
43856 return -EOPNOTSUPP;
43857
43858 /* drag the command string into the kernel so we can parse it */
43859 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struc
43860 if (args[0] != '%' || args[1] != '\0')
43861 return -EINVAL;
43862
43863 - if (fstop < 0 || fstop >= cache->fcull_percent)
43864 + if (fstop >= cache->fcull_percent)
43865 return cachefiles_daemon_range_error(cache, args);
43866
43867 cache->fstop_percent = fstop;
43868 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struc
43869 if (args[0] != '%' || args[1] != '\0')
43870 return -EINVAL;
43871
43872 - if (bstop < 0 || bstop >= cache->bcull_percent)
43873 + if (bstop >= cache->bcull_percent)
43874 return cachefiles_daemon_range_error(cache, args);
43875
43876 cache->bstop_percent = bstop;
43877 diff -urNp linux-2.6.32.46/fs/cachefiles/internal.h linux-2.6.32.46/fs/cachefiles/internal.h
43878 --- linux-2.6.32.46/fs/cachefiles/internal.h 2011-03-27 14:31:47.000000000 -0400
43879 +++ linux-2.6.32.46/fs/cachefiles/internal.h 2011-05-04 17:56:28.000000000 -0400
43880 @@ -56,7 +56,7 @@ struct cachefiles_cache {
43881 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43882 struct rb_root active_nodes; /* active nodes (can't be culled) */
43883 rwlock_t active_lock; /* lock for active_nodes */
43884 - atomic_t gravecounter; /* graveyard uniquifier */
43885 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43886 unsigned frun_percent; /* when to stop culling (% files) */
43887 unsigned fcull_percent; /* when to start culling (% files) */
43888 unsigned fstop_percent; /* when to stop allocating (% files) */
43889 @@ -168,19 +168,19 @@ extern int cachefiles_check_in_use(struc
43890 * proc.c
43891 */
43892 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43893 -extern atomic_t cachefiles_lookup_histogram[HZ];
43894 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43895 -extern atomic_t cachefiles_create_histogram[HZ];
43896 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43897 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43898 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43899
43900 extern int __init cachefiles_proc_init(void);
43901 extern void cachefiles_proc_cleanup(void);
43902 static inline
43903 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43904 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43905 {
43906 unsigned long jif = jiffies - start_jif;
43907 if (jif >= HZ)
43908 jif = HZ - 1;
43909 - atomic_inc(&histogram[jif]);
43910 + atomic_inc_unchecked(&histogram[jif]);
43911 }
43912
43913 #else
43914 diff -urNp linux-2.6.32.46/fs/cachefiles/namei.c linux-2.6.32.46/fs/cachefiles/namei.c
43915 --- linux-2.6.32.46/fs/cachefiles/namei.c 2011-03-27 14:31:47.000000000 -0400
43916 +++ linux-2.6.32.46/fs/cachefiles/namei.c 2011-05-04 17:56:28.000000000 -0400
43917 @@ -250,7 +250,7 @@ try_again:
43918 /* first step is to make up a grave dentry in the graveyard */
43919 sprintf(nbuffer, "%08x%08x",
43920 (uint32_t) get_seconds(),
43921 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43922 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43923
43924 /* do the multiway lock magic */
43925 trap = lock_rename(cache->graveyard, dir);
43926 diff -urNp linux-2.6.32.46/fs/cachefiles/proc.c linux-2.6.32.46/fs/cachefiles/proc.c
43927 --- linux-2.6.32.46/fs/cachefiles/proc.c 2011-03-27 14:31:47.000000000 -0400
43928 +++ linux-2.6.32.46/fs/cachefiles/proc.c 2011-05-04 17:56:28.000000000 -0400
43929 @@ -14,9 +14,9 @@
43930 #include <linux/seq_file.h>
43931 #include "internal.h"
43932
43933 -atomic_t cachefiles_lookup_histogram[HZ];
43934 -atomic_t cachefiles_mkdir_histogram[HZ];
43935 -atomic_t cachefiles_create_histogram[HZ];
43936 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43937 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43938 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43939
43940 /*
43941 * display the latency histogram
43942 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
43943 return 0;
43944 default:
43945 index = (unsigned long) v - 3;
43946 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43947 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43948 - z = atomic_read(&cachefiles_create_histogram[index]);
43949 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43950 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43951 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43952 if (x == 0 && y == 0 && z == 0)
43953 return 0;
43954
43955 diff -urNp linux-2.6.32.46/fs/cachefiles/rdwr.c linux-2.6.32.46/fs/cachefiles/rdwr.c
43956 --- linux-2.6.32.46/fs/cachefiles/rdwr.c 2011-03-27 14:31:47.000000000 -0400
43957 +++ linux-2.6.32.46/fs/cachefiles/rdwr.c 2011-10-06 09:37:14.000000000 -0400
43958 @@ -946,7 +946,7 @@ int cachefiles_write_page(struct fscache
43959 old_fs = get_fs();
43960 set_fs(KERNEL_DS);
43961 ret = file->f_op->write(
43962 - file, (const void __user *) data, len, &pos);
43963 + file, (const void __force_user *) data, len, &pos);
43964 set_fs(old_fs);
43965 kunmap(page);
43966 if (ret != len)
43967 diff -urNp linux-2.6.32.46/fs/cifs/cifs_debug.c linux-2.6.32.46/fs/cifs/cifs_debug.c
43968 --- linux-2.6.32.46/fs/cifs/cifs_debug.c 2011-03-27 14:31:47.000000000 -0400
43969 +++ linux-2.6.32.46/fs/cifs/cifs_debug.c 2011-05-04 17:56:28.000000000 -0400
43970 @@ -256,25 +256,25 @@ static ssize_t cifs_stats_proc_write(str
43971 tcon = list_entry(tmp3,
43972 struct cifsTconInfo,
43973 tcon_list);
43974 - atomic_set(&tcon->num_smbs_sent, 0);
43975 - atomic_set(&tcon->num_writes, 0);
43976 - atomic_set(&tcon->num_reads, 0);
43977 - atomic_set(&tcon->num_oplock_brks, 0);
43978 - atomic_set(&tcon->num_opens, 0);
43979 - atomic_set(&tcon->num_posixopens, 0);
43980 - atomic_set(&tcon->num_posixmkdirs, 0);
43981 - atomic_set(&tcon->num_closes, 0);
43982 - atomic_set(&tcon->num_deletes, 0);
43983 - atomic_set(&tcon->num_mkdirs, 0);
43984 - atomic_set(&tcon->num_rmdirs, 0);
43985 - atomic_set(&tcon->num_renames, 0);
43986 - atomic_set(&tcon->num_t2renames, 0);
43987 - atomic_set(&tcon->num_ffirst, 0);
43988 - atomic_set(&tcon->num_fnext, 0);
43989 - atomic_set(&tcon->num_fclose, 0);
43990 - atomic_set(&tcon->num_hardlinks, 0);
43991 - atomic_set(&tcon->num_symlinks, 0);
43992 - atomic_set(&tcon->num_locks, 0);
43993 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43994 + atomic_set_unchecked(&tcon->num_writes, 0);
43995 + atomic_set_unchecked(&tcon->num_reads, 0);
43996 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43997 + atomic_set_unchecked(&tcon->num_opens, 0);
43998 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43999 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
44000 + atomic_set_unchecked(&tcon->num_closes, 0);
44001 + atomic_set_unchecked(&tcon->num_deletes, 0);
44002 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
44003 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
44004 + atomic_set_unchecked(&tcon->num_renames, 0);
44005 + atomic_set_unchecked(&tcon->num_t2renames, 0);
44006 + atomic_set_unchecked(&tcon->num_ffirst, 0);
44007 + atomic_set_unchecked(&tcon->num_fnext, 0);
44008 + atomic_set_unchecked(&tcon->num_fclose, 0);
44009 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
44010 + atomic_set_unchecked(&tcon->num_symlinks, 0);
44011 + atomic_set_unchecked(&tcon->num_locks, 0);
44012 }
44013 }
44014 }
44015 @@ -334,41 +334,41 @@ static int cifs_stats_proc_show(struct s
44016 if (tcon->need_reconnect)
44017 seq_puts(m, "\tDISCONNECTED ");
44018 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
44019 - atomic_read(&tcon->num_smbs_sent),
44020 - atomic_read(&tcon->num_oplock_brks));
44021 + atomic_read_unchecked(&tcon->num_smbs_sent),
44022 + atomic_read_unchecked(&tcon->num_oplock_brks));
44023 seq_printf(m, "\nReads: %d Bytes: %lld",
44024 - atomic_read(&tcon->num_reads),
44025 + atomic_read_unchecked(&tcon->num_reads),
44026 (long long)(tcon->bytes_read));
44027 seq_printf(m, "\nWrites: %d Bytes: %lld",
44028 - atomic_read(&tcon->num_writes),
44029 + atomic_read_unchecked(&tcon->num_writes),
44030 (long long)(tcon->bytes_written));
44031 seq_printf(m, "\nFlushes: %d",
44032 - atomic_read(&tcon->num_flushes));
44033 + atomic_read_unchecked(&tcon->num_flushes));
44034 seq_printf(m, "\nLocks: %d HardLinks: %d "
44035 "Symlinks: %d",
44036 - atomic_read(&tcon->num_locks),
44037 - atomic_read(&tcon->num_hardlinks),
44038 - atomic_read(&tcon->num_symlinks));
44039 + atomic_read_unchecked(&tcon->num_locks),
44040 + atomic_read_unchecked(&tcon->num_hardlinks),
44041 + atomic_read_unchecked(&tcon->num_symlinks));
44042 seq_printf(m, "\nOpens: %d Closes: %d "
44043 "Deletes: %d",
44044 - atomic_read(&tcon->num_opens),
44045 - atomic_read(&tcon->num_closes),
44046 - atomic_read(&tcon->num_deletes));
44047 + atomic_read_unchecked(&tcon->num_opens),
44048 + atomic_read_unchecked(&tcon->num_closes),
44049 + atomic_read_unchecked(&tcon->num_deletes));
44050 seq_printf(m, "\nPosix Opens: %d "
44051 "Posix Mkdirs: %d",
44052 - atomic_read(&tcon->num_posixopens),
44053 - atomic_read(&tcon->num_posixmkdirs));
44054 + atomic_read_unchecked(&tcon->num_posixopens),
44055 + atomic_read_unchecked(&tcon->num_posixmkdirs));
44056 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44057 - atomic_read(&tcon->num_mkdirs),
44058 - atomic_read(&tcon->num_rmdirs));
44059 + atomic_read_unchecked(&tcon->num_mkdirs),
44060 + atomic_read_unchecked(&tcon->num_rmdirs));
44061 seq_printf(m, "\nRenames: %d T2 Renames %d",
44062 - atomic_read(&tcon->num_renames),
44063 - atomic_read(&tcon->num_t2renames));
44064 + atomic_read_unchecked(&tcon->num_renames),
44065 + atomic_read_unchecked(&tcon->num_t2renames));
44066 seq_printf(m, "\nFindFirst: %d FNext %d "
44067 "FClose %d",
44068 - atomic_read(&tcon->num_ffirst),
44069 - atomic_read(&tcon->num_fnext),
44070 - atomic_read(&tcon->num_fclose));
44071 + atomic_read_unchecked(&tcon->num_ffirst),
44072 + atomic_read_unchecked(&tcon->num_fnext),
44073 + atomic_read_unchecked(&tcon->num_fclose));
44074 }
44075 }
44076 }
44077 diff -urNp linux-2.6.32.46/fs/cifs/cifsfs.c linux-2.6.32.46/fs/cifs/cifsfs.c
44078 --- linux-2.6.32.46/fs/cifs/cifsfs.c 2011-03-27 14:31:47.000000000 -0400
44079 +++ linux-2.6.32.46/fs/cifs/cifsfs.c 2011-08-25 17:17:57.000000000 -0400
44080 @@ -869,7 +869,7 @@ cifs_init_request_bufs(void)
44081 cifs_req_cachep = kmem_cache_create("cifs_request",
44082 CIFSMaxBufSize +
44083 MAX_CIFS_HDR_SIZE, 0,
44084 - SLAB_HWCACHE_ALIGN, NULL);
44085 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44086 if (cifs_req_cachep == NULL)
44087 return -ENOMEM;
44088
44089 @@ -896,7 +896,7 @@ cifs_init_request_bufs(void)
44090 efficient to alloc 1 per page off the slab compared to 17K (5page)
44091 alloc of large cifs buffers even when page debugging is on */
44092 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44093 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44094 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44095 NULL);
44096 if (cifs_sm_req_cachep == NULL) {
44097 mempool_destroy(cifs_req_poolp);
44098 @@ -991,8 +991,8 @@ init_cifs(void)
44099 atomic_set(&bufAllocCount, 0);
44100 atomic_set(&smBufAllocCount, 0);
44101 #ifdef CONFIG_CIFS_STATS2
44102 - atomic_set(&totBufAllocCount, 0);
44103 - atomic_set(&totSmBufAllocCount, 0);
44104 + atomic_set_unchecked(&totBufAllocCount, 0);
44105 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44106 #endif /* CONFIG_CIFS_STATS2 */
44107
44108 atomic_set(&midCount, 0);
44109 diff -urNp linux-2.6.32.46/fs/cifs/cifsglob.h linux-2.6.32.46/fs/cifs/cifsglob.h
44110 --- linux-2.6.32.46/fs/cifs/cifsglob.h 2011-08-09 18:35:29.000000000 -0400
44111 +++ linux-2.6.32.46/fs/cifs/cifsglob.h 2011-08-25 17:17:57.000000000 -0400
44112 @@ -252,28 +252,28 @@ struct cifsTconInfo {
44113 __u16 Flags; /* optional support bits */
44114 enum statusEnum tidStatus;
44115 #ifdef CONFIG_CIFS_STATS
44116 - atomic_t num_smbs_sent;
44117 - atomic_t num_writes;
44118 - atomic_t num_reads;
44119 - atomic_t num_flushes;
44120 - atomic_t num_oplock_brks;
44121 - atomic_t num_opens;
44122 - atomic_t num_closes;
44123 - atomic_t num_deletes;
44124 - atomic_t num_mkdirs;
44125 - atomic_t num_posixopens;
44126 - atomic_t num_posixmkdirs;
44127 - atomic_t num_rmdirs;
44128 - atomic_t num_renames;
44129 - atomic_t num_t2renames;
44130 - atomic_t num_ffirst;
44131 - atomic_t num_fnext;
44132 - atomic_t num_fclose;
44133 - atomic_t num_hardlinks;
44134 - atomic_t num_symlinks;
44135 - atomic_t num_locks;
44136 - atomic_t num_acl_get;
44137 - atomic_t num_acl_set;
44138 + atomic_unchecked_t num_smbs_sent;
44139 + atomic_unchecked_t num_writes;
44140 + atomic_unchecked_t num_reads;
44141 + atomic_unchecked_t num_flushes;
44142 + atomic_unchecked_t num_oplock_brks;
44143 + atomic_unchecked_t num_opens;
44144 + atomic_unchecked_t num_closes;
44145 + atomic_unchecked_t num_deletes;
44146 + atomic_unchecked_t num_mkdirs;
44147 + atomic_unchecked_t num_posixopens;
44148 + atomic_unchecked_t num_posixmkdirs;
44149 + atomic_unchecked_t num_rmdirs;
44150 + atomic_unchecked_t num_renames;
44151 + atomic_unchecked_t num_t2renames;
44152 + atomic_unchecked_t num_ffirst;
44153 + atomic_unchecked_t num_fnext;
44154 + atomic_unchecked_t num_fclose;
44155 + atomic_unchecked_t num_hardlinks;
44156 + atomic_unchecked_t num_symlinks;
44157 + atomic_unchecked_t num_locks;
44158 + atomic_unchecked_t num_acl_get;
44159 + atomic_unchecked_t num_acl_set;
44160 #ifdef CONFIG_CIFS_STATS2
44161 unsigned long long time_writes;
44162 unsigned long long time_reads;
44163 @@ -414,7 +414,7 @@ static inline char CIFS_DIR_SEP(const st
44164 }
44165
44166 #ifdef CONFIG_CIFS_STATS
44167 -#define cifs_stats_inc atomic_inc
44168 +#define cifs_stats_inc atomic_inc_unchecked
44169
44170 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
44171 unsigned int bytes)
44172 @@ -701,8 +701,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnect
44173 /* Various Debug counters */
44174 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44175 #ifdef CONFIG_CIFS_STATS2
44176 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44177 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44178 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44179 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44180 #endif
44181 GLOBAL_EXTERN atomic_t smBufAllocCount;
44182 GLOBAL_EXTERN atomic_t midCount;
44183 diff -urNp linux-2.6.32.46/fs/cifs/cifssmb.c linux-2.6.32.46/fs/cifs/cifssmb.c
44184 --- linux-2.6.32.46/fs/cifs/cifssmb.c 2011-03-27 14:31:47.000000000 -0400
44185 +++ linux-2.6.32.46/fs/cifs/cifssmb.c 2011-10-17 02:36:33.000000000 -0400
44186 @@ -3596,7 +3596,8 @@ int CIFSFindNext(const int xid, struct c
44187 T2_FNEXT_RSP_PARMS *parms;
44188 char *response_data;
44189 int rc = 0;
44190 - int bytes_returned, name_len;
44191 + int bytes_returned;
44192 + unsigned int name_len;
44193 __u16 params, byte_count;
44194
44195 cFYI(1, ("In FindNext"));
44196 diff -urNp linux-2.6.32.46/fs/cifs/link.c linux-2.6.32.46/fs/cifs/link.c
44197 --- linux-2.6.32.46/fs/cifs/link.c 2011-03-27 14:31:47.000000000 -0400
44198 +++ linux-2.6.32.46/fs/cifs/link.c 2011-04-17 15:56:46.000000000 -0400
44199 @@ -215,7 +215,7 @@ cifs_symlink(struct inode *inode, struct
44200
44201 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44202 {
44203 - char *p = nd_get_link(nd);
44204 + const char *p = nd_get_link(nd);
44205 if (!IS_ERR(p))
44206 kfree(p);
44207 }
44208 diff -urNp linux-2.6.32.46/fs/cifs/misc.c linux-2.6.32.46/fs/cifs/misc.c
44209 --- linux-2.6.32.46/fs/cifs/misc.c 2011-03-27 14:31:47.000000000 -0400
44210 +++ linux-2.6.32.46/fs/cifs/misc.c 2011-08-25 17:17:57.000000000 -0400
44211 @@ -155,7 +155,7 @@ cifs_buf_get(void)
44212 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
44213 atomic_inc(&bufAllocCount);
44214 #ifdef CONFIG_CIFS_STATS2
44215 - atomic_inc(&totBufAllocCount);
44216 + atomic_inc_unchecked(&totBufAllocCount);
44217 #endif /* CONFIG_CIFS_STATS2 */
44218 }
44219
44220 @@ -190,7 +190,7 @@ cifs_small_buf_get(void)
44221 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44222 atomic_inc(&smBufAllocCount);
44223 #ifdef CONFIG_CIFS_STATS2
44224 - atomic_inc(&totSmBufAllocCount);
44225 + atomic_inc_unchecked(&totSmBufAllocCount);
44226 #endif /* CONFIG_CIFS_STATS2 */
44227
44228 }
44229 diff -urNp linux-2.6.32.46/fs/coda/cache.c linux-2.6.32.46/fs/coda/cache.c
44230 --- linux-2.6.32.46/fs/coda/cache.c 2011-03-27 14:31:47.000000000 -0400
44231 +++ linux-2.6.32.46/fs/coda/cache.c 2011-05-04 17:56:28.000000000 -0400
44232 @@ -24,14 +24,14 @@
44233 #include <linux/coda_fs_i.h>
44234 #include <linux/coda_cache.h>
44235
44236 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44237 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44238
44239 /* replace or extend an acl cache hit */
44240 void coda_cache_enter(struct inode *inode, int mask)
44241 {
44242 struct coda_inode_info *cii = ITOC(inode);
44243
44244 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44245 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44246 if (cii->c_uid != current_fsuid()) {
44247 cii->c_uid = current_fsuid();
44248 cii->c_cached_perm = mask;
44249 @@ -43,13 +43,13 @@ void coda_cache_enter(struct inode *inod
44250 void coda_cache_clear_inode(struct inode *inode)
44251 {
44252 struct coda_inode_info *cii = ITOC(inode);
44253 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44254 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44255 }
44256
44257 /* remove all acl caches */
44258 void coda_cache_clear_all(struct super_block *sb)
44259 {
44260 - atomic_inc(&permission_epoch);
44261 + atomic_inc_unchecked(&permission_epoch);
44262 }
44263
44264
44265 @@ -61,7 +61,7 @@ int coda_cache_check(struct inode *inode
44266
44267 hit = (mask & cii->c_cached_perm) == mask &&
44268 cii->c_uid == current_fsuid() &&
44269 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44270 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44271
44272 return hit;
44273 }
44274 diff -urNp linux-2.6.32.46/fs/compat.c linux-2.6.32.46/fs/compat.c
44275 --- linux-2.6.32.46/fs/compat.c 2011-04-17 17:00:52.000000000 -0400
44276 +++ linux-2.6.32.46/fs/compat.c 2011-10-06 09:37:14.000000000 -0400
44277 @@ -133,8 +133,8 @@ asmlinkage long compat_sys_utimes(char _
44278 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
44279 {
44280 compat_ino_t ino = stat->ino;
44281 - typeof(ubuf->st_uid) uid = 0;
44282 - typeof(ubuf->st_gid) gid = 0;
44283 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
44284 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
44285 int err;
44286
44287 SET_UID(uid, stat->uid);
44288 @@ -533,7 +533,7 @@ compat_sys_io_setup(unsigned nr_reqs, u3
44289
44290 set_fs(KERNEL_DS);
44291 /* The __user pointer cast is valid because of the set_fs() */
44292 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44293 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44294 set_fs(oldfs);
44295 /* truncating is ok because it's a user address */
44296 if (!ret)
44297 @@ -830,6 +830,7 @@ struct compat_old_linux_dirent {
44298
44299 struct compat_readdir_callback {
44300 struct compat_old_linux_dirent __user *dirent;
44301 + struct file * file;
44302 int result;
44303 };
44304
44305 @@ -847,6 +848,10 @@ static int compat_fillonedir(void *__buf
44306 buf->result = -EOVERFLOW;
44307 return -EOVERFLOW;
44308 }
44309 +
44310 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44311 + return 0;
44312 +
44313 buf->result++;
44314 dirent = buf->dirent;
44315 if (!access_ok(VERIFY_WRITE, dirent,
44316 @@ -879,6 +884,7 @@ asmlinkage long compat_sys_old_readdir(u
44317
44318 buf.result = 0;
44319 buf.dirent = dirent;
44320 + buf.file = file;
44321
44322 error = vfs_readdir(file, compat_fillonedir, &buf);
44323 if (buf.result)
44324 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44325 struct compat_getdents_callback {
44326 struct compat_linux_dirent __user *current_dir;
44327 struct compat_linux_dirent __user *previous;
44328 + struct file * file;
44329 int count;
44330 int error;
44331 };
44332 @@ -919,6 +926,10 @@ static int compat_filldir(void *__buf, c
44333 buf->error = -EOVERFLOW;
44334 return -EOVERFLOW;
44335 }
44336 +
44337 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44338 + return 0;
44339 +
44340 dirent = buf->previous;
44341 if (dirent) {
44342 if (__put_user(offset, &dirent->d_off))
44343 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsi
44344 buf.previous = NULL;
44345 buf.count = count;
44346 buf.error = 0;
44347 + buf.file = file;
44348
44349 error = vfs_readdir(file, compat_filldir, &buf);
44350 if (error >= 0)
44351 @@ -987,6 +999,7 @@ out:
44352 struct compat_getdents_callback64 {
44353 struct linux_dirent64 __user *current_dir;
44354 struct linux_dirent64 __user *previous;
44355 + struct file * file;
44356 int count;
44357 int error;
44358 };
44359 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf
44360 buf->error = -EINVAL; /* only used if we fail.. */
44361 if (reclen > buf->count)
44362 return -EINVAL;
44363 +
44364 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44365 + return 0;
44366 +
44367 dirent = buf->previous;
44368
44369 if (dirent) {
44370 @@ -1054,13 +1071,14 @@ asmlinkage long compat_sys_getdents64(un
44371 buf.previous = NULL;
44372 buf.count = count;
44373 buf.error = 0;
44374 + buf.file = file;
44375
44376 error = vfs_readdir(file, compat_filldir64, &buf);
44377 if (error >= 0)
44378 error = buf.error;
44379 lastdirent = buf.previous;
44380 if (lastdirent) {
44381 - typeof(lastdirent->d_off) d_off = file->f_pos;
44382 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44383 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44384 error = -EFAULT;
44385 else
44386 @@ -1098,7 +1116,7 @@ static ssize_t compat_do_readv_writev(in
44387 * verify all the pointers
44388 */
44389 ret = -EINVAL;
44390 - if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
44391 + if (nr_segs > UIO_MAXIOV)
44392 goto out;
44393 if (!file->f_op)
44394 goto out;
44395 @@ -1463,11 +1481,35 @@ int compat_do_execve(char * filename,
44396 compat_uptr_t __user *envp,
44397 struct pt_regs * regs)
44398 {
44399 +#ifdef CONFIG_GRKERNSEC
44400 + struct file *old_exec_file;
44401 + struct acl_subject_label *old_acl;
44402 + struct rlimit old_rlim[RLIM_NLIMITS];
44403 +#endif
44404 struct linux_binprm *bprm;
44405 struct file *file;
44406 struct files_struct *displaced;
44407 bool clear_in_exec;
44408 int retval;
44409 + const struct cred *cred = current_cred();
44410 +
44411 + /*
44412 + * We move the actual failure in case of RLIMIT_NPROC excess from
44413 + * set*uid() to execve() because too many poorly written programs
44414 + * don't check setuid() return code. Here we additionally recheck
44415 + * whether NPROC limit is still exceeded.
44416 + */
44417 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44418 +
44419 + if ((current->flags & PF_NPROC_EXCEEDED) &&
44420 + atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
44421 + retval = -EAGAIN;
44422 + goto out_ret;
44423 + }
44424 +
44425 + /* We're below the limit (still or again), so we don't want to make
44426 + * further execve() calls fail. */
44427 + current->flags &= ~PF_NPROC_EXCEEDED;
44428
44429 retval = unshare_files(&displaced);
44430 if (retval)
44431 @@ -1499,6 +1541,15 @@ int compat_do_execve(char * filename,
44432 bprm->filename = filename;
44433 bprm->interp = filename;
44434
44435 + if (gr_process_user_ban()) {
44436 + retval = -EPERM;
44437 + goto out_file;
44438 + }
44439 +
44440 + retval = -EACCES;
44441 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
44442 + goto out_file;
44443 +
44444 retval = bprm_mm_init(bprm);
44445 if (retval)
44446 goto out_file;
44447 @@ -1528,9 +1579,40 @@ int compat_do_execve(char * filename,
44448 if (retval < 0)
44449 goto out;
44450
44451 + if (!gr_tpe_allow(file)) {
44452 + retval = -EACCES;
44453 + goto out;
44454 + }
44455 +
44456 + if (gr_check_crash_exec(file)) {
44457 + retval = -EACCES;
44458 + goto out;
44459 + }
44460 +
44461 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44462 +
44463 + gr_handle_exec_args_compat(bprm, argv);
44464 +
44465 +#ifdef CONFIG_GRKERNSEC
44466 + old_acl = current->acl;
44467 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44468 + old_exec_file = current->exec_file;
44469 + get_file(file);
44470 + current->exec_file = file;
44471 +#endif
44472 +
44473 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44474 + bprm->unsafe & LSM_UNSAFE_SHARE);
44475 + if (retval < 0)
44476 + goto out_fail;
44477 +
44478 retval = search_binary_handler(bprm, regs);
44479 if (retval < 0)
44480 - goto out;
44481 + goto out_fail;
44482 +#ifdef CONFIG_GRKERNSEC
44483 + if (old_exec_file)
44484 + fput(old_exec_file);
44485 +#endif
44486
44487 /* execve succeeded */
44488 current->fs->in_exec = 0;
44489 @@ -1541,6 +1623,14 @@ int compat_do_execve(char * filename,
44490 put_files_struct(displaced);
44491 return retval;
44492
44493 +out_fail:
44494 +#ifdef CONFIG_GRKERNSEC
44495 + current->acl = old_acl;
44496 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44497 + fput(current->exec_file);
44498 + current->exec_file = old_exec_file;
44499 +#endif
44500 +
44501 out:
44502 if (bprm->mm) {
44503 acct_arg_size(bprm, 0);
44504 @@ -1711,6 +1801,8 @@ int compat_core_sys_select(int n, compat
44505 struct fdtable *fdt;
44506 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
44507
44508 + pax_track_stack();
44509 +
44510 if (n < 0)
44511 goto out_nofds;
44512
44513 @@ -2151,7 +2243,7 @@ asmlinkage long compat_sys_nfsservctl(in
44514 oldfs = get_fs();
44515 set_fs(KERNEL_DS);
44516 /* The __user pointer casts are valid because of the set_fs() */
44517 - err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres);
44518 + err = sys_nfsservctl(cmd, (void __force_user *) karg, (void __force_user *) kres);
44519 set_fs(oldfs);
44520
44521 if (err)
44522 diff -urNp linux-2.6.32.46/fs/compat_binfmt_elf.c linux-2.6.32.46/fs/compat_binfmt_elf.c
44523 --- linux-2.6.32.46/fs/compat_binfmt_elf.c 2011-03-27 14:31:47.000000000 -0400
44524 +++ linux-2.6.32.46/fs/compat_binfmt_elf.c 2011-04-17 15:56:46.000000000 -0400
44525 @@ -29,10 +29,12 @@
44526 #undef elfhdr
44527 #undef elf_phdr
44528 #undef elf_note
44529 +#undef elf_dyn
44530 #undef elf_addr_t
44531 #define elfhdr elf32_hdr
44532 #define elf_phdr elf32_phdr
44533 #define elf_note elf32_note
44534 +#define elf_dyn Elf32_Dyn
44535 #define elf_addr_t Elf32_Addr
44536
44537 /*
44538 diff -urNp linux-2.6.32.46/fs/compat_ioctl.c linux-2.6.32.46/fs/compat_ioctl.c
44539 --- linux-2.6.32.46/fs/compat_ioctl.c 2011-03-27 14:31:47.000000000 -0400
44540 +++ linux-2.6.32.46/fs/compat_ioctl.c 2011-10-06 09:37:14.000000000 -0400
44541 @@ -234,6 +234,8 @@ static int do_video_set_spu_palette(unsi
44542 up = (struct compat_video_spu_palette __user *) arg;
44543 err = get_user(palp, &up->palette);
44544 err |= get_user(length, &up->length);
44545 + if (err)
44546 + return -EFAULT;
44547
44548 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44549 err = put_user(compat_ptr(palp), &up_native->palette);
44550 @@ -1513,7 +1515,7 @@ static int serial_struct_ioctl(unsigned
44551 return -EFAULT;
44552 if (__get_user(udata, &ss32->iomem_base))
44553 return -EFAULT;
44554 - ss.iomem_base = compat_ptr(udata);
44555 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44556 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44557 __get_user(ss.port_high, &ss32->port_high))
44558 return -EFAULT;
44559 @@ -1809,7 +1811,7 @@ static int compat_ioctl_preallocate(stru
44560 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44561 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44562 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44563 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44564 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44565 return -EFAULT;
44566
44567 return ioctl_preallocate(file, p);
44568 diff -urNp linux-2.6.32.46/fs/configfs/dir.c linux-2.6.32.46/fs/configfs/dir.c
44569 --- linux-2.6.32.46/fs/configfs/dir.c 2011-03-27 14:31:47.000000000 -0400
44570 +++ linux-2.6.32.46/fs/configfs/dir.c 2011-05-11 18:25:15.000000000 -0400
44571 @@ -1572,7 +1572,8 @@ static int configfs_readdir(struct file
44572 }
44573 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44574 struct configfs_dirent *next;
44575 - const char * name;
44576 + const unsigned char * name;
44577 + char d_name[sizeof(next->s_dentry->d_iname)];
44578 int len;
44579
44580 next = list_entry(p, struct configfs_dirent,
44581 @@ -1581,7 +1582,12 @@ static int configfs_readdir(struct file
44582 continue;
44583
44584 name = configfs_get_name(next);
44585 - len = strlen(name);
44586 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44587 + len = next->s_dentry->d_name.len;
44588 + memcpy(d_name, name, len);
44589 + name = d_name;
44590 + } else
44591 + len = strlen(name);
44592 if (next->s_dentry)
44593 ino = next->s_dentry->d_inode->i_ino;
44594 else
44595 diff -urNp linux-2.6.32.46/fs/dcache.c linux-2.6.32.46/fs/dcache.c
44596 --- linux-2.6.32.46/fs/dcache.c 2011-03-27 14:31:47.000000000 -0400
44597 +++ linux-2.6.32.46/fs/dcache.c 2011-04-23 13:32:21.000000000 -0400
44598 @@ -45,8 +45,6 @@ EXPORT_SYMBOL(dcache_lock);
44599
44600 static struct kmem_cache *dentry_cache __read_mostly;
44601
44602 -#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
44603 -
44604 /*
44605 * This is the single most critical data structure when it comes
44606 * to the dcache: the hashtable for lookups. Somebody should try
44607 @@ -2319,7 +2317,7 @@ void __init vfs_caches_init(unsigned lon
44608 mempages -= reserve;
44609
44610 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44611 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44612 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44613
44614 dcache_init();
44615 inode_init();
44616 diff -urNp linux-2.6.32.46/fs/dlm/lockspace.c linux-2.6.32.46/fs/dlm/lockspace.c
44617 --- linux-2.6.32.46/fs/dlm/lockspace.c 2011-03-27 14:31:47.000000000 -0400
44618 +++ linux-2.6.32.46/fs/dlm/lockspace.c 2011-04-17 15:56:46.000000000 -0400
44619 @@ -148,7 +148,7 @@ static void lockspace_kobj_release(struc
44620 kfree(ls);
44621 }
44622
44623 -static struct sysfs_ops dlm_attr_ops = {
44624 +static const struct sysfs_ops dlm_attr_ops = {
44625 .show = dlm_attr_show,
44626 .store = dlm_attr_store,
44627 };
44628 diff -urNp linux-2.6.32.46/fs/ecryptfs/inode.c linux-2.6.32.46/fs/ecryptfs/inode.c
44629 --- linux-2.6.32.46/fs/ecryptfs/inode.c 2011-03-27 14:31:47.000000000 -0400
44630 +++ linux-2.6.32.46/fs/ecryptfs/inode.c 2011-10-06 09:37:14.000000000 -0400
44631 @@ -660,7 +660,7 @@ static int ecryptfs_readlink_lower(struc
44632 old_fs = get_fs();
44633 set_fs(get_ds());
44634 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44635 - (char __user *)lower_buf,
44636 + (char __force_user *)lower_buf,
44637 lower_bufsiz);
44638 set_fs(old_fs);
44639 if (rc < 0)
44640 @@ -706,7 +706,7 @@ static void *ecryptfs_follow_link(struct
44641 }
44642 old_fs = get_fs();
44643 set_fs(get_ds());
44644 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
44645 + rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
44646 set_fs(old_fs);
44647 if (rc < 0)
44648 goto out_free;
44649 diff -urNp linux-2.6.32.46/fs/exec.c linux-2.6.32.46/fs/exec.c
44650 --- linux-2.6.32.46/fs/exec.c 2011-06-25 12:55:34.000000000 -0400
44651 +++ linux-2.6.32.46/fs/exec.c 2011-10-06 09:37:14.000000000 -0400
44652 @@ -56,12 +56,24 @@
44653 #include <linux/fsnotify.h>
44654 #include <linux/fs_struct.h>
44655 #include <linux/pipe_fs_i.h>
44656 +#include <linux/random.h>
44657 +#include <linux/seq_file.h>
44658 +
44659 +#ifdef CONFIG_PAX_REFCOUNT
44660 +#include <linux/kallsyms.h>
44661 +#include <linux/kdebug.h>
44662 +#endif
44663
44664 #include <asm/uaccess.h>
44665 #include <asm/mmu_context.h>
44666 #include <asm/tlb.h>
44667 #include "internal.h"
44668
44669 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44670 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44671 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44672 +#endif
44673 +
44674 int core_uses_pid;
44675 char core_pattern[CORENAME_MAX_SIZE] = "core";
44676 unsigned int core_pipe_limit;
44677 @@ -115,7 +127,7 @@ SYSCALL_DEFINE1(uselib, const char __use
44678 goto out;
44679
44680 file = do_filp_open(AT_FDCWD, tmp,
44681 - O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
44682 + O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
44683 MAY_READ | MAY_EXEC | MAY_OPEN);
44684 putname(tmp);
44685 error = PTR_ERR(file);
44686 @@ -178,18 +190,10 @@ struct page *get_arg_page(struct linux_b
44687 int write)
44688 {
44689 struct page *page;
44690 - int ret;
44691
44692 -#ifdef CONFIG_STACK_GROWSUP
44693 - if (write) {
44694 - ret = expand_stack_downwards(bprm->vma, pos);
44695 - if (ret < 0)
44696 - return NULL;
44697 - }
44698 -#endif
44699 - ret = get_user_pages(current, bprm->mm, pos,
44700 - 1, write, 1, &page, NULL);
44701 - if (ret <= 0)
44702 + if (0 > expand_stack_downwards(bprm->vma, pos))
44703 + return NULL;
44704 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44705 return NULL;
44706
44707 if (write) {
44708 @@ -263,6 +267,11 @@ static int __bprm_mm_init(struct linux_b
44709 vma->vm_end = STACK_TOP_MAX;
44710 vma->vm_start = vma->vm_end - PAGE_SIZE;
44711 vma->vm_flags = VM_STACK_FLAGS;
44712 +
44713 +#ifdef CONFIG_PAX_SEGMEXEC
44714 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44715 +#endif
44716 +
44717 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44718
44719 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
44720 @@ -276,6 +285,12 @@ static int __bprm_mm_init(struct linux_b
44721 mm->stack_vm = mm->total_vm = 1;
44722 up_write(&mm->mmap_sem);
44723 bprm->p = vma->vm_end - sizeof(void *);
44724 +
44725 +#ifdef CONFIG_PAX_RANDUSTACK
44726 + if (randomize_va_space)
44727 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
44728 +#endif
44729 +
44730 return 0;
44731 err:
44732 up_write(&mm->mmap_sem);
44733 @@ -510,7 +525,7 @@ int copy_strings_kernel(int argc,char **
44734 int r;
44735 mm_segment_t oldfs = get_fs();
44736 set_fs(KERNEL_DS);
44737 - r = copy_strings(argc, (char __user * __user *)argv, bprm);
44738 + r = copy_strings(argc, (__force char __user * __user *)argv, bprm);
44739 set_fs(oldfs);
44740 return r;
44741 }
44742 @@ -540,7 +555,8 @@ static int shift_arg_pages(struct vm_are
44743 unsigned long new_end = old_end - shift;
44744 struct mmu_gather *tlb;
44745
44746 - BUG_ON(new_start > new_end);
44747 + if (new_start >= new_end || new_start < mmap_min_addr)
44748 + return -ENOMEM;
44749
44750 /*
44751 * ensure there are no vmas between where we want to go
44752 @@ -549,6 +565,10 @@ static int shift_arg_pages(struct vm_are
44753 if (vma != find_vma(mm, new_start))
44754 return -EFAULT;
44755
44756 +#ifdef CONFIG_PAX_SEGMEXEC
44757 + BUG_ON(pax_find_mirror_vma(vma));
44758 +#endif
44759 +
44760 /*
44761 * cover the whole range: [new_start, old_end)
44762 */
44763 @@ -630,10 +650,6 @@ int setup_arg_pages(struct linux_binprm
44764 stack_top = arch_align_stack(stack_top);
44765 stack_top = PAGE_ALIGN(stack_top);
44766
44767 - if (unlikely(stack_top < mmap_min_addr) ||
44768 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44769 - return -ENOMEM;
44770 -
44771 stack_shift = vma->vm_end - stack_top;
44772
44773 bprm->p -= stack_shift;
44774 @@ -645,6 +661,14 @@ int setup_arg_pages(struct linux_binprm
44775 bprm->exec -= stack_shift;
44776
44777 down_write(&mm->mmap_sem);
44778 +
44779 + /* Move stack pages down in memory. */
44780 + if (stack_shift) {
44781 + ret = shift_arg_pages(vma, stack_shift);
44782 + if (ret)
44783 + goto out_unlock;
44784 + }
44785 +
44786 vm_flags = VM_STACK_FLAGS;
44787
44788 /*
44789 @@ -658,19 +682,24 @@ int setup_arg_pages(struct linux_binprm
44790 vm_flags &= ~VM_EXEC;
44791 vm_flags |= mm->def_flags;
44792
44793 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44794 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44795 + vm_flags &= ~VM_EXEC;
44796 +
44797 +#ifdef CONFIG_PAX_MPROTECT
44798 + if (mm->pax_flags & MF_PAX_MPROTECT)
44799 + vm_flags &= ~VM_MAYEXEC;
44800 +#endif
44801 +
44802 + }
44803 +#endif
44804 +
44805 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
44806 vm_flags);
44807 if (ret)
44808 goto out_unlock;
44809 BUG_ON(prev != vma);
44810
44811 - /* Move stack pages down in memory. */
44812 - if (stack_shift) {
44813 - ret = shift_arg_pages(vma, stack_shift);
44814 - if (ret)
44815 - goto out_unlock;
44816 - }
44817 -
44818 stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
44819 stack_size = vma->vm_end - vma->vm_start;
44820 /*
44821 @@ -707,7 +736,7 @@ struct file *open_exec(const char *name)
44822 int err;
44823
44824 file = do_filp_open(AT_FDCWD, name,
44825 - O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
44826 + O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
44827 MAY_EXEC | MAY_OPEN);
44828 if (IS_ERR(file))
44829 goto out;
44830 @@ -744,7 +773,7 @@ int kernel_read(struct file *file, loff_
44831 old_fs = get_fs();
44832 set_fs(get_ds());
44833 /* The cast to a user pointer is valid due to the set_fs() */
44834 - result = vfs_read(file, (void __user *)addr, count, &pos);
44835 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44836 set_fs(old_fs);
44837 return result;
44838 }
44839 @@ -1152,7 +1181,7 @@ int check_unsafe_exec(struct linux_binpr
44840 }
44841 rcu_read_unlock();
44842
44843 - if (p->fs->users > n_fs) {
44844 + if (atomic_read(&p->fs->users) > n_fs) {
44845 bprm->unsafe |= LSM_UNSAFE_SHARE;
44846 } else {
44847 res = -EAGAIN;
44848 @@ -1347,11 +1376,35 @@ int do_execve(char * filename,
44849 char __user *__user *envp,
44850 struct pt_regs * regs)
44851 {
44852 +#ifdef CONFIG_GRKERNSEC
44853 + struct file *old_exec_file;
44854 + struct acl_subject_label *old_acl;
44855 + struct rlimit old_rlim[RLIM_NLIMITS];
44856 +#endif
44857 struct linux_binprm *bprm;
44858 struct file *file;
44859 struct files_struct *displaced;
44860 bool clear_in_exec;
44861 int retval;
44862 + const struct cred *cred = current_cred();
44863 +
44864 + /*
44865 + * We move the actual failure in case of RLIMIT_NPROC excess from
44866 + * set*uid() to execve() because too many poorly written programs
44867 + * don't check setuid() return code. Here we additionally recheck
44868 + * whether NPROC limit is still exceeded.
44869 + */
44870 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44871 +
44872 + if ((current->flags & PF_NPROC_EXCEEDED) &&
44873 + atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
44874 + retval = -EAGAIN;
44875 + goto out_ret;
44876 + }
44877 +
44878 + /* We're below the limit (still or again), so we don't want to make
44879 + * further execve() calls fail. */
44880 + current->flags &= ~PF_NPROC_EXCEEDED;
44881
44882 retval = unshare_files(&displaced);
44883 if (retval)
44884 @@ -1383,6 +1436,16 @@ int do_execve(char * filename,
44885 bprm->filename = filename;
44886 bprm->interp = filename;
44887
44888 + if (gr_process_user_ban()) {
44889 + retval = -EPERM;
44890 + goto out_file;
44891 + }
44892 +
44893 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44894 + retval = -EACCES;
44895 + goto out_file;
44896 + }
44897 +
44898 retval = bprm_mm_init(bprm);
44899 if (retval)
44900 goto out_file;
44901 @@ -1412,10 +1475,41 @@ int do_execve(char * filename,
44902 if (retval < 0)
44903 goto out;
44904
44905 + if (!gr_tpe_allow(file)) {
44906 + retval = -EACCES;
44907 + goto out;
44908 + }
44909 +
44910 + if (gr_check_crash_exec(file)) {
44911 + retval = -EACCES;
44912 + goto out;
44913 + }
44914 +
44915 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44916 +
44917 + gr_handle_exec_args(bprm, (const char __user *const __user *)argv);
44918 +
44919 +#ifdef CONFIG_GRKERNSEC
44920 + old_acl = current->acl;
44921 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44922 + old_exec_file = current->exec_file;
44923 + get_file(file);
44924 + current->exec_file = file;
44925 +#endif
44926 +
44927 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44928 + bprm->unsafe & LSM_UNSAFE_SHARE);
44929 + if (retval < 0)
44930 + goto out_fail;
44931 +
44932 current->flags &= ~PF_KTHREAD;
44933 retval = search_binary_handler(bprm,regs);
44934 if (retval < 0)
44935 - goto out;
44936 + goto out_fail;
44937 +#ifdef CONFIG_GRKERNSEC
44938 + if (old_exec_file)
44939 + fput(old_exec_file);
44940 +#endif
44941
44942 /* execve succeeded */
44943 current->fs->in_exec = 0;
44944 @@ -1426,6 +1520,14 @@ int do_execve(char * filename,
44945 put_files_struct(displaced);
44946 return retval;
44947
44948 +out_fail:
44949 +#ifdef CONFIG_GRKERNSEC
44950 + current->acl = old_acl;
44951 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44952 + fput(current->exec_file);
44953 + current->exec_file = old_exec_file;
44954 +#endif
44955 +
44956 out:
44957 if (bprm->mm) {
44958 acct_arg_size(bprm, 0);
44959 @@ -1591,6 +1693,220 @@ out:
44960 return ispipe;
44961 }
44962
44963 +int pax_check_flags(unsigned long *flags)
44964 +{
44965 + int retval = 0;
44966 +
44967 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44968 + if (*flags & MF_PAX_SEGMEXEC)
44969 + {
44970 + *flags &= ~MF_PAX_SEGMEXEC;
44971 + retval = -EINVAL;
44972 + }
44973 +#endif
44974 +
44975 + if ((*flags & MF_PAX_PAGEEXEC)
44976 +
44977 +#ifdef CONFIG_PAX_PAGEEXEC
44978 + && (*flags & MF_PAX_SEGMEXEC)
44979 +#endif
44980 +
44981 + )
44982 + {
44983 + *flags &= ~MF_PAX_PAGEEXEC;
44984 + retval = -EINVAL;
44985 + }
44986 +
44987 + if ((*flags & MF_PAX_MPROTECT)
44988 +
44989 +#ifdef CONFIG_PAX_MPROTECT
44990 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44991 +#endif
44992 +
44993 + )
44994 + {
44995 + *flags &= ~MF_PAX_MPROTECT;
44996 + retval = -EINVAL;
44997 + }
44998 +
44999 + if ((*flags & MF_PAX_EMUTRAMP)
45000 +
45001 +#ifdef CONFIG_PAX_EMUTRAMP
45002 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45003 +#endif
45004 +
45005 + )
45006 + {
45007 + *flags &= ~MF_PAX_EMUTRAMP;
45008 + retval = -EINVAL;
45009 + }
45010 +
45011 + return retval;
45012 +}
45013 +
45014 +EXPORT_SYMBOL(pax_check_flags);
45015 +
45016 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45017 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45018 +{
45019 + struct task_struct *tsk = current;
45020 + struct mm_struct *mm = current->mm;
45021 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45022 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45023 + char *path_exec = NULL;
45024 + char *path_fault = NULL;
45025 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45026 +
45027 + if (buffer_exec && buffer_fault) {
45028 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45029 +
45030 + down_read(&mm->mmap_sem);
45031 + vma = mm->mmap;
45032 + while (vma && (!vma_exec || !vma_fault)) {
45033 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45034 + vma_exec = vma;
45035 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45036 + vma_fault = vma;
45037 + vma = vma->vm_next;
45038 + }
45039 + if (vma_exec) {
45040 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45041 + if (IS_ERR(path_exec))
45042 + path_exec = "<path too long>";
45043 + else {
45044 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45045 + if (path_exec) {
45046 + *path_exec = 0;
45047 + path_exec = buffer_exec;
45048 + } else
45049 + path_exec = "<path too long>";
45050 + }
45051 + }
45052 + if (vma_fault) {
45053 + start = vma_fault->vm_start;
45054 + end = vma_fault->vm_end;
45055 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45056 + if (vma_fault->vm_file) {
45057 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45058 + if (IS_ERR(path_fault))
45059 + path_fault = "<path too long>";
45060 + else {
45061 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45062 + if (path_fault) {
45063 + *path_fault = 0;
45064 + path_fault = buffer_fault;
45065 + } else
45066 + path_fault = "<path too long>";
45067 + }
45068 + } else
45069 + path_fault = "<anonymous mapping>";
45070 + }
45071 + up_read(&mm->mmap_sem);
45072 + }
45073 + if (tsk->signal->curr_ip)
45074 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45075 + else
45076 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45077 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45078 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45079 + task_uid(tsk), task_euid(tsk), pc, sp);
45080 + free_page((unsigned long)buffer_exec);
45081 + free_page((unsigned long)buffer_fault);
45082 + pax_report_insns(pc, sp);
45083 + do_coredump(SIGKILL, SIGKILL, regs);
45084 +}
45085 +#endif
45086 +
45087 +#ifdef CONFIG_PAX_REFCOUNT
45088 +void pax_report_refcount_overflow(struct pt_regs *regs)
45089 +{
45090 + if (current->signal->curr_ip)
45091 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45092 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45093 + else
45094 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45095 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45096 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45097 + show_regs(regs);
45098 + force_sig_specific(SIGKILL, current);
45099 +}
45100 +#endif
45101 +
45102 +#ifdef CONFIG_PAX_USERCOPY
45103 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45104 +int object_is_on_stack(const void *obj, unsigned long len)
45105 +{
45106 + const void * const stack = task_stack_page(current);
45107 + const void * const stackend = stack + THREAD_SIZE;
45108 +
45109 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45110 + const void *frame = NULL;
45111 + const void *oldframe;
45112 +#endif
45113 +
45114 + if (obj + len < obj)
45115 + return -1;
45116 +
45117 + if (obj + len <= stack || stackend <= obj)
45118 + return 0;
45119 +
45120 + if (obj < stack || stackend < obj + len)
45121 + return -1;
45122 +
45123 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45124 + oldframe = __builtin_frame_address(1);
45125 + if (oldframe)
45126 + frame = __builtin_frame_address(2);
45127 + /*
45128 + low ----------------------------------------------> high
45129 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45130 + ^----------------^
45131 + allow copies only within here
45132 + */
45133 + while (stack <= frame && frame < stackend) {
45134 + /* if obj + len extends past the last frame, this
45135 + check won't pass and the next frame will be 0,
45136 + causing us to bail out and correctly report
45137 + the copy as invalid
45138 + */
45139 + if (obj + len <= frame)
45140 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45141 + oldframe = frame;
45142 + frame = *(const void * const *)frame;
45143 + }
45144 + return -1;
45145 +#else
45146 + return 1;
45147 +#endif
45148 +}
45149 +
45150 +
45151 +NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45152 +{
45153 + if (current->signal->curr_ip)
45154 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45155 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45156 + else
45157 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45158 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45159 +
45160 + dump_stack();
45161 + gr_handle_kernel_exploit();
45162 + do_group_exit(SIGKILL);
45163 +}
45164 +#endif
45165 +
45166 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45167 +void pax_track_stack(void)
45168 +{
45169 + unsigned long sp = (unsigned long)&sp;
45170 + if (sp < current_thread_info()->lowest_stack &&
45171 + sp > (unsigned long)task_stack_page(current))
45172 + current_thread_info()->lowest_stack = sp;
45173 +}
45174 +EXPORT_SYMBOL(pax_track_stack);
45175 +#endif
45176 +
45177 static int zap_process(struct task_struct *start)
45178 {
45179 struct task_struct *t;
45180 @@ -1793,17 +2109,17 @@ static void wait_for_dump_helpers(struct
45181 pipe = file->f_path.dentry->d_inode->i_pipe;
45182
45183 pipe_lock(pipe);
45184 - pipe->readers++;
45185 - pipe->writers--;
45186 + atomic_inc(&pipe->readers);
45187 + atomic_dec(&pipe->writers);
45188
45189 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45190 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45191 wake_up_interruptible_sync(&pipe->wait);
45192 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45193 pipe_wait(pipe);
45194 }
45195
45196 - pipe->readers--;
45197 - pipe->writers++;
45198 + atomic_dec(&pipe->readers);
45199 + atomic_inc(&pipe->writers);
45200 pipe_unlock(pipe);
45201
45202 }
45203 @@ -1826,10 +2142,13 @@ void do_coredump(long signr, int exit_co
45204 char **helper_argv = NULL;
45205 int helper_argc = 0;
45206 int dump_count = 0;
45207 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45208 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45209
45210 audit_core_dumps(signr);
45211
45212 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45213 + gr_handle_brute_attach(current, mm->flags);
45214 +
45215 binfmt = mm->binfmt;
45216 if (!binfmt || !binfmt->core_dump)
45217 goto fail;
45218 @@ -1874,6 +2193,8 @@ void do_coredump(long signr, int exit_co
45219 */
45220 clear_thread_flag(TIF_SIGPENDING);
45221
45222 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45223 +
45224 /*
45225 * lock_kernel() because format_corename() is controlled by sysctl, which
45226 * uses lock_kernel()
45227 @@ -1908,7 +2229,7 @@ void do_coredump(long signr, int exit_co
45228 goto fail_unlock;
45229 }
45230
45231 - dump_count = atomic_inc_return(&core_dump_count);
45232 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45233 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45234 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45235 task_tgid_vnr(current), current->comm);
45236 @@ -1972,7 +2293,7 @@ close_fail:
45237 filp_close(file, NULL);
45238 fail_dropcount:
45239 if (dump_count)
45240 - atomic_dec(&core_dump_count);
45241 + atomic_dec_unchecked(&core_dump_count);
45242 fail_unlock:
45243 if (helper_argv)
45244 argv_free(helper_argv);
45245 diff -urNp linux-2.6.32.46/fs/ext2/balloc.c linux-2.6.32.46/fs/ext2/balloc.c
45246 --- linux-2.6.32.46/fs/ext2/balloc.c 2011-03-27 14:31:47.000000000 -0400
45247 +++ linux-2.6.32.46/fs/ext2/balloc.c 2011-04-17 15:56:46.000000000 -0400
45248 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
45249
45250 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45251 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45252 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45253 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45254 sbi->s_resuid != current_fsuid() &&
45255 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45256 return 0;
45257 diff -urNp linux-2.6.32.46/fs/ext3/balloc.c linux-2.6.32.46/fs/ext3/balloc.c
45258 --- linux-2.6.32.46/fs/ext3/balloc.c 2011-03-27 14:31:47.000000000 -0400
45259 +++ linux-2.6.32.46/fs/ext3/balloc.c 2011-04-17 15:56:46.000000000 -0400
45260 @@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e
45261
45262 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45263 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45264 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45265 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45266 sbi->s_resuid != current_fsuid() &&
45267 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45268 return 0;
45269 diff -urNp linux-2.6.32.46/fs/ext4/balloc.c linux-2.6.32.46/fs/ext4/balloc.c
45270 --- linux-2.6.32.46/fs/ext4/balloc.c 2011-03-27 14:31:47.000000000 -0400
45271 +++ linux-2.6.32.46/fs/ext4/balloc.c 2011-04-17 15:56:46.000000000 -0400
45272 @@ -570,7 +570,7 @@ int ext4_has_free_blocks(struct ext4_sb_
45273 /* Hm, nope. Are (enough) root reserved blocks available? */
45274 if (sbi->s_resuid == current_fsuid() ||
45275 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
45276 - capable(CAP_SYS_RESOURCE)) {
45277 + capable_nolog(CAP_SYS_RESOURCE)) {
45278 if (free_blocks >= (nblocks + dirty_blocks))
45279 return 1;
45280 }
45281 diff -urNp linux-2.6.32.46/fs/ext4/ext4.h linux-2.6.32.46/fs/ext4/ext4.h
45282 --- linux-2.6.32.46/fs/ext4/ext4.h 2011-03-27 14:31:47.000000000 -0400
45283 +++ linux-2.6.32.46/fs/ext4/ext4.h 2011-04-17 15:56:46.000000000 -0400
45284 @@ -1078,19 +1078,19 @@ struct ext4_sb_info {
45285
45286 /* stats for buddy allocator */
45287 spinlock_t s_mb_pa_lock;
45288 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45289 - atomic_t s_bal_success; /* we found long enough chunks */
45290 - atomic_t s_bal_allocated; /* in blocks */
45291 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45292 - atomic_t s_bal_goals; /* goal hits */
45293 - atomic_t s_bal_breaks; /* too long searches */
45294 - atomic_t s_bal_2orders; /* 2^order hits */
45295 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45296 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45297 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45298 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45299 + atomic_unchecked_t s_bal_goals; /* goal hits */
45300 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45301 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45302 spinlock_t s_bal_lock;
45303 unsigned long s_mb_buddies_generated;
45304 unsigned long long s_mb_generation_time;
45305 - atomic_t s_mb_lost_chunks;
45306 - atomic_t s_mb_preallocated;
45307 - atomic_t s_mb_discarded;
45308 + atomic_unchecked_t s_mb_lost_chunks;
45309 + atomic_unchecked_t s_mb_preallocated;
45310 + atomic_unchecked_t s_mb_discarded;
45311 atomic_t s_lock_busy;
45312
45313 /* locality groups */
45314 diff -urNp linux-2.6.32.46/fs/ext4/file.c linux-2.6.32.46/fs/ext4/file.c
45315 --- linux-2.6.32.46/fs/ext4/file.c 2011-03-27 14:31:47.000000000 -0400
45316 +++ linux-2.6.32.46/fs/ext4/file.c 2011-10-17 02:30:06.000000000 -0400
45317 @@ -122,8 +122,8 @@ static int ext4_file_open(struct inode *
45318 cp = d_path(&path, buf, sizeof(buf));
45319 path_put(&path);
45320 if (!IS_ERR(cp)) {
45321 - memcpy(sbi->s_es->s_last_mounted, cp,
45322 - sizeof(sbi->s_es->s_last_mounted));
45323 + strlcpy(sbi->s_es->s_last_mounted, cp,
45324 + sizeof(sbi->s_es->s_last_mounted));
45325 sb->s_dirt = 1;
45326 }
45327 }
45328 diff -urNp linux-2.6.32.46/fs/ext4/mballoc.c linux-2.6.32.46/fs/ext4/mballoc.c
45329 --- linux-2.6.32.46/fs/ext4/mballoc.c 2011-06-25 12:55:34.000000000 -0400
45330 +++ linux-2.6.32.46/fs/ext4/mballoc.c 2011-06-25 12:56:37.000000000 -0400
45331 @@ -1755,7 +1755,7 @@ void ext4_mb_simple_scan_group(struct ex
45332 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45333
45334 if (EXT4_SB(sb)->s_mb_stats)
45335 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45336 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45337
45338 break;
45339 }
45340 @@ -2131,7 +2131,7 @@ repeat:
45341 ac->ac_status = AC_STATUS_CONTINUE;
45342 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45343 cr = 3;
45344 - atomic_inc(&sbi->s_mb_lost_chunks);
45345 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45346 goto repeat;
45347 }
45348 }
45349 @@ -2174,6 +2174,8 @@ static int ext4_mb_seq_groups_show(struc
45350 ext4_grpblk_t counters[16];
45351 } sg;
45352
45353 + pax_track_stack();
45354 +
45355 group--;
45356 if (group == 0)
45357 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
45358 @@ -2534,25 +2536,25 @@ int ext4_mb_release(struct super_block *
45359 if (sbi->s_mb_stats) {
45360 printk(KERN_INFO
45361 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
45362 - atomic_read(&sbi->s_bal_allocated),
45363 - atomic_read(&sbi->s_bal_reqs),
45364 - atomic_read(&sbi->s_bal_success));
45365 + atomic_read_unchecked(&sbi->s_bal_allocated),
45366 + atomic_read_unchecked(&sbi->s_bal_reqs),
45367 + atomic_read_unchecked(&sbi->s_bal_success));
45368 printk(KERN_INFO
45369 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
45370 "%u 2^N hits, %u breaks, %u lost\n",
45371 - atomic_read(&sbi->s_bal_ex_scanned),
45372 - atomic_read(&sbi->s_bal_goals),
45373 - atomic_read(&sbi->s_bal_2orders),
45374 - atomic_read(&sbi->s_bal_breaks),
45375 - atomic_read(&sbi->s_mb_lost_chunks));
45376 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45377 + atomic_read_unchecked(&sbi->s_bal_goals),
45378 + atomic_read_unchecked(&sbi->s_bal_2orders),
45379 + atomic_read_unchecked(&sbi->s_bal_breaks),
45380 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45381 printk(KERN_INFO
45382 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
45383 sbi->s_mb_buddies_generated++,
45384 sbi->s_mb_generation_time);
45385 printk(KERN_INFO
45386 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
45387 - atomic_read(&sbi->s_mb_preallocated),
45388 - atomic_read(&sbi->s_mb_discarded));
45389 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45390 + atomic_read_unchecked(&sbi->s_mb_discarded));
45391 }
45392
45393 free_percpu(sbi->s_locality_groups);
45394 @@ -3034,16 +3036,16 @@ static void ext4_mb_collect_stats(struct
45395 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45396
45397 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45398 - atomic_inc(&sbi->s_bal_reqs);
45399 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45400 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45401 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45402 if (ac->ac_o_ex.fe_len >= ac->ac_g_ex.fe_len)
45403 - atomic_inc(&sbi->s_bal_success);
45404 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45405 + atomic_inc_unchecked(&sbi->s_bal_success);
45406 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45407 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45408 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45409 - atomic_inc(&sbi->s_bal_goals);
45410 + atomic_inc_unchecked(&sbi->s_bal_goals);
45411 if (ac->ac_found > sbi->s_mb_max_to_scan)
45412 - atomic_inc(&sbi->s_bal_breaks);
45413 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45414 }
45415
45416 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45417 @@ -3443,7 +3445,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
45418 trace_ext4_mb_new_inode_pa(ac, pa);
45419
45420 ext4_mb_use_inode_pa(ac, pa);
45421 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45422 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45423
45424 ei = EXT4_I(ac->ac_inode);
45425 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45426 @@ -3503,7 +3505,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
45427 trace_ext4_mb_new_group_pa(ac, pa);
45428
45429 ext4_mb_use_group_pa(ac, pa);
45430 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45431 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45432
45433 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45434 lg = ac->ac_lg;
45435 @@ -3607,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
45436 * from the bitmap and continue.
45437 */
45438 }
45439 - atomic_add(free, &sbi->s_mb_discarded);
45440 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45441
45442 return err;
45443 }
45444 @@ -3626,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_bud
45445 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45446 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45447 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45448 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45449 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45450
45451 if (ac) {
45452 ac->ac_sb = sb;
45453 diff -urNp linux-2.6.32.46/fs/ext4/super.c linux-2.6.32.46/fs/ext4/super.c
45454 --- linux-2.6.32.46/fs/ext4/super.c 2011-03-27 14:31:47.000000000 -0400
45455 +++ linux-2.6.32.46/fs/ext4/super.c 2011-04-17 15:56:46.000000000 -0400
45456 @@ -2287,7 +2287,7 @@ static void ext4_sb_release(struct kobje
45457 }
45458
45459
45460 -static struct sysfs_ops ext4_attr_ops = {
45461 +static const struct sysfs_ops ext4_attr_ops = {
45462 .show = ext4_attr_show,
45463 .store = ext4_attr_store,
45464 };
45465 diff -urNp linux-2.6.32.46/fs/fcntl.c linux-2.6.32.46/fs/fcntl.c
45466 --- linux-2.6.32.46/fs/fcntl.c 2011-03-27 14:31:47.000000000 -0400
45467 +++ linux-2.6.32.46/fs/fcntl.c 2011-10-06 09:37:14.000000000 -0400
45468 @@ -223,6 +223,11 @@ int __f_setown(struct file *filp, struct
45469 if (err)
45470 return err;
45471
45472 + if (gr_handle_chroot_fowner(pid, type))
45473 + return -ENOENT;
45474 + if (gr_check_protected_task_fowner(pid, type))
45475 + return -EACCES;
45476 +
45477 f_modown(filp, pid, type, force);
45478 return 0;
45479 }
45480 @@ -265,7 +270,7 @@ pid_t f_getown(struct file *filp)
45481
45482 static int f_setown_ex(struct file *filp, unsigned long arg)
45483 {
45484 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45485 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45486 struct f_owner_ex owner;
45487 struct pid *pid;
45488 int type;
45489 @@ -305,7 +310,7 @@ static int f_setown_ex(struct file *filp
45490
45491 static int f_getown_ex(struct file *filp, unsigned long arg)
45492 {
45493 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45494 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45495 struct f_owner_ex owner;
45496 int ret = 0;
45497
45498 @@ -344,6 +349,7 @@ static long do_fcntl(int fd, unsigned in
45499 switch (cmd) {
45500 case F_DUPFD:
45501 case F_DUPFD_CLOEXEC:
45502 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45503 if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
45504 break;
45505 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45506 diff -urNp linux-2.6.32.46/fs/fifo.c linux-2.6.32.46/fs/fifo.c
45507 --- linux-2.6.32.46/fs/fifo.c 2011-03-27 14:31:47.000000000 -0400
45508 +++ linux-2.6.32.46/fs/fifo.c 2011-04-17 15:56:46.000000000 -0400
45509 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode
45510 */
45511 filp->f_op = &read_pipefifo_fops;
45512 pipe->r_counter++;
45513 - if (pipe->readers++ == 0)
45514 + if (atomic_inc_return(&pipe->readers) == 1)
45515 wake_up_partner(inode);
45516
45517 - if (!pipe->writers) {
45518 + if (!atomic_read(&pipe->writers)) {
45519 if ((filp->f_flags & O_NONBLOCK)) {
45520 /* suppress POLLHUP until we have
45521 * seen a writer */
45522 @@ -83,15 +83,15 @@ static int fifo_open(struct inode *inode
45523 * errno=ENXIO when there is no process reading the FIFO.
45524 */
45525 ret = -ENXIO;
45526 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45527 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45528 goto err;
45529
45530 filp->f_op = &write_pipefifo_fops;
45531 pipe->w_counter++;
45532 - if (!pipe->writers++)
45533 + if (atomic_inc_return(&pipe->writers) == 1)
45534 wake_up_partner(inode);
45535
45536 - if (!pipe->readers) {
45537 + if (!atomic_read(&pipe->readers)) {
45538 wait_for_partner(inode, &pipe->r_counter);
45539 if (signal_pending(current))
45540 goto err_wr;
45541 @@ -107,11 +107,11 @@ static int fifo_open(struct inode *inode
45542 */
45543 filp->f_op = &rdwr_pipefifo_fops;
45544
45545 - pipe->readers++;
45546 - pipe->writers++;
45547 + atomic_inc(&pipe->readers);
45548 + atomic_inc(&pipe->writers);
45549 pipe->r_counter++;
45550 pipe->w_counter++;
45551 - if (pipe->readers == 1 || pipe->writers == 1)
45552 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45553 wake_up_partner(inode);
45554 break;
45555
45556 @@ -125,19 +125,19 @@ static int fifo_open(struct inode *inode
45557 return 0;
45558
45559 err_rd:
45560 - if (!--pipe->readers)
45561 + if (atomic_dec_and_test(&pipe->readers))
45562 wake_up_interruptible(&pipe->wait);
45563 ret = -ERESTARTSYS;
45564 goto err;
45565
45566 err_wr:
45567 - if (!--pipe->writers)
45568 + if (atomic_dec_and_test(&pipe->writers))
45569 wake_up_interruptible(&pipe->wait);
45570 ret = -ERESTARTSYS;
45571 goto err;
45572
45573 err:
45574 - if (!pipe->readers && !pipe->writers)
45575 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45576 free_pipe_info(inode);
45577
45578 err_nocleanup:
45579 diff -urNp linux-2.6.32.46/fs/file.c linux-2.6.32.46/fs/file.c
45580 --- linux-2.6.32.46/fs/file.c 2011-03-27 14:31:47.000000000 -0400
45581 +++ linux-2.6.32.46/fs/file.c 2011-04-17 15:56:46.000000000 -0400
45582 @@ -14,6 +14,7 @@
45583 #include <linux/slab.h>
45584 #include <linux/vmalloc.h>
45585 #include <linux/file.h>
45586 +#include <linux/security.h>
45587 #include <linux/fdtable.h>
45588 #include <linux/bitops.h>
45589 #include <linux/interrupt.h>
45590 @@ -257,6 +258,8 @@ int expand_files(struct files_struct *fi
45591 * N.B. For clone tasks sharing a files structure, this test
45592 * will limit the total number of files that can be opened.
45593 */
45594 +
45595 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45596 if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
45597 return -EMFILE;
45598
45599 diff -urNp linux-2.6.32.46/fs/filesystems.c linux-2.6.32.46/fs/filesystems.c
45600 --- linux-2.6.32.46/fs/filesystems.c 2011-03-27 14:31:47.000000000 -0400
45601 +++ linux-2.6.32.46/fs/filesystems.c 2011-04-17 15:56:46.000000000 -0400
45602 @@ -272,7 +272,12 @@ struct file_system_type *get_fs_type(con
45603 int len = dot ? dot - name : strlen(name);
45604
45605 fs = __get_fs_type(name, len);
45606 +
45607 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45608 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45609 +#else
45610 if (!fs && (request_module("%.*s", len, name) == 0))
45611 +#endif
45612 fs = __get_fs_type(name, len);
45613
45614 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45615 diff -urNp linux-2.6.32.46/fs/fs_struct.c linux-2.6.32.46/fs/fs_struct.c
45616 --- linux-2.6.32.46/fs/fs_struct.c 2011-03-27 14:31:47.000000000 -0400
45617 +++ linux-2.6.32.46/fs/fs_struct.c 2011-04-17 15:56:46.000000000 -0400
45618 @@ -4,6 +4,7 @@
45619 #include <linux/path.h>
45620 #include <linux/slab.h>
45621 #include <linux/fs_struct.h>
45622 +#include <linux/grsecurity.h>
45623
45624 /*
45625 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
45626 @@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, s
45627 old_root = fs->root;
45628 fs->root = *path;
45629 path_get(path);
45630 + gr_set_chroot_entries(current, path);
45631 write_unlock(&fs->lock);
45632 if (old_root.dentry)
45633 path_put(&old_root);
45634 @@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_roo
45635 && fs->root.mnt == old_root->mnt) {
45636 path_get(new_root);
45637 fs->root = *new_root;
45638 + gr_set_chroot_entries(p, new_root);
45639 count++;
45640 }
45641 if (fs->pwd.dentry == old_root->dentry
45642 @@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
45643 task_lock(tsk);
45644 write_lock(&fs->lock);
45645 tsk->fs = NULL;
45646 - kill = !--fs->users;
45647 + gr_clear_chroot_entries(tsk);
45648 + kill = !atomic_dec_return(&fs->users);
45649 write_unlock(&fs->lock);
45650 task_unlock(tsk);
45651 if (kill)
45652 @@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct
45653 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45654 /* We don't need to lock fs - think why ;-) */
45655 if (fs) {
45656 - fs->users = 1;
45657 + atomic_set(&fs->users, 1);
45658 fs->in_exec = 0;
45659 rwlock_init(&fs->lock);
45660 fs->umask = old->umask;
45661 @@ -127,8 +131,9 @@ int unshare_fs_struct(void)
45662
45663 task_lock(current);
45664 write_lock(&fs->lock);
45665 - kill = !--fs->users;
45666 + kill = !atomic_dec_return(&fs->users);
45667 current->fs = new_fs;
45668 + gr_set_chroot_entries(current, &new_fs->root);
45669 write_unlock(&fs->lock);
45670 task_unlock(current);
45671
45672 @@ -147,7 +152,7 @@ EXPORT_SYMBOL(current_umask);
45673
45674 /* to be mentioned only in INIT_TASK */
45675 struct fs_struct init_fs = {
45676 - .users = 1,
45677 + .users = ATOMIC_INIT(1),
45678 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
45679 .umask = 0022,
45680 };
45681 @@ -162,12 +167,13 @@ void daemonize_fs_struct(void)
45682 task_lock(current);
45683
45684 write_lock(&init_fs.lock);
45685 - init_fs.users++;
45686 + atomic_inc(&init_fs.users);
45687 write_unlock(&init_fs.lock);
45688
45689 write_lock(&fs->lock);
45690 current->fs = &init_fs;
45691 - kill = !--fs->users;
45692 + gr_set_chroot_entries(current, &current->fs->root);
45693 + kill = !atomic_dec_return(&fs->users);
45694 write_unlock(&fs->lock);
45695
45696 task_unlock(current);
45697 diff -urNp linux-2.6.32.46/fs/fscache/cookie.c linux-2.6.32.46/fs/fscache/cookie.c
45698 --- linux-2.6.32.46/fs/fscache/cookie.c 2011-03-27 14:31:47.000000000 -0400
45699 +++ linux-2.6.32.46/fs/fscache/cookie.c 2011-05-04 17:56:28.000000000 -0400
45700 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
45701 parent ? (char *) parent->def->name : "<no-parent>",
45702 def->name, netfs_data);
45703
45704 - fscache_stat(&fscache_n_acquires);
45705 + fscache_stat_unchecked(&fscache_n_acquires);
45706
45707 /* if there's no parent cookie, then we don't create one here either */
45708 if (!parent) {
45709 - fscache_stat(&fscache_n_acquires_null);
45710 + fscache_stat_unchecked(&fscache_n_acquires_null);
45711 _leave(" [no parent]");
45712 return NULL;
45713 }
45714 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
45715 /* allocate and initialise a cookie */
45716 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45717 if (!cookie) {
45718 - fscache_stat(&fscache_n_acquires_oom);
45719 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45720 _leave(" [ENOMEM]");
45721 return NULL;
45722 }
45723 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
45724
45725 switch (cookie->def->type) {
45726 case FSCACHE_COOKIE_TYPE_INDEX:
45727 - fscache_stat(&fscache_n_cookie_index);
45728 + fscache_stat_unchecked(&fscache_n_cookie_index);
45729 break;
45730 case FSCACHE_COOKIE_TYPE_DATAFILE:
45731 - fscache_stat(&fscache_n_cookie_data);
45732 + fscache_stat_unchecked(&fscache_n_cookie_data);
45733 break;
45734 default:
45735 - fscache_stat(&fscache_n_cookie_special);
45736 + fscache_stat_unchecked(&fscache_n_cookie_special);
45737 break;
45738 }
45739
45740 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
45741 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45742 atomic_dec(&parent->n_children);
45743 __fscache_cookie_put(cookie);
45744 - fscache_stat(&fscache_n_acquires_nobufs);
45745 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45746 _leave(" = NULL");
45747 return NULL;
45748 }
45749 }
45750
45751 - fscache_stat(&fscache_n_acquires_ok);
45752 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45753 _leave(" = %p", cookie);
45754 return cookie;
45755 }
45756 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
45757 cache = fscache_select_cache_for_object(cookie->parent);
45758 if (!cache) {
45759 up_read(&fscache_addremove_sem);
45760 - fscache_stat(&fscache_n_acquires_no_cache);
45761 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45762 _leave(" = -ENOMEDIUM [no cache]");
45763 return -ENOMEDIUM;
45764 }
45765 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
45766 object = cache->ops->alloc_object(cache, cookie);
45767 fscache_stat_d(&fscache_n_cop_alloc_object);
45768 if (IS_ERR(object)) {
45769 - fscache_stat(&fscache_n_object_no_alloc);
45770 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45771 ret = PTR_ERR(object);
45772 goto error;
45773 }
45774
45775 - fscache_stat(&fscache_n_object_alloc);
45776 + fscache_stat_unchecked(&fscache_n_object_alloc);
45777
45778 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45779
45780 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
45781 struct fscache_object *object;
45782 struct hlist_node *_p;
45783
45784 - fscache_stat(&fscache_n_updates);
45785 + fscache_stat_unchecked(&fscache_n_updates);
45786
45787 if (!cookie) {
45788 - fscache_stat(&fscache_n_updates_null);
45789 + fscache_stat_unchecked(&fscache_n_updates_null);
45790 _leave(" [no cookie]");
45791 return;
45792 }
45793 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
45794 struct fscache_object *object;
45795 unsigned long event;
45796
45797 - fscache_stat(&fscache_n_relinquishes);
45798 + fscache_stat_unchecked(&fscache_n_relinquishes);
45799 if (retire)
45800 - fscache_stat(&fscache_n_relinquishes_retire);
45801 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45802
45803 if (!cookie) {
45804 - fscache_stat(&fscache_n_relinquishes_null);
45805 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45806 _leave(" [no cookie]");
45807 return;
45808 }
45809 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
45810
45811 /* wait for the cookie to finish being instantiated (or to fail) */
45812 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45813 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45814 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45815 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45816 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45817 }
45818 diff -urNp linux-2.6.32.46/fs/fscache/internal.h linux-2.6.32.46/fs/fscache/internal.h
45819 --- linux-2.6.32.46/fs/fscache/internal.h 2011-03-27 14:31:47.000000000 -0400
45820 +++ linux-2.6.32.46/fs/fscache/internal.h 2011-05-04 17:56:28.000000000 -0400
45821 @@ -136,94 +136,94 @@ extern void fscache_proc_cleanup(void);
45822 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45823 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45824
45825 -extern atomic_t fscache_n_op_pend;
45826 -extern atomic_t fscache_n_op_run;
45827 -extern atomic_t fscache_n_op_enqueue;
45828 -extern atomic_t fscache_n_op_deferred_release;
45829 -extern atomic_t fscache_n_op_release;
45830 -extern atomic_t fscache_n_op_gc;
45831 -extern atomic_t fscache_n_op_cancelled;
45832 -extern atomic_t fscache_n_op_rejected;
45833 -
45834 -extern atomic_t fscache_n_attr_changed;
45835 -extern atomic_t fscache_n_attr_changed_ok;
45836 -extern atomic_t fscache_n_attr_changed_nobufs;
45837 -extern atomic_t fscache_n_attr_changed_nomem;
45838 -extern atomic_t fscache_n_attr_changed_calls;
45839 -
45840 -extern atomic_t fscache_n_allocs;
45841 -extern atomic_t fscache_n_allocs_ok;
45842 -extern atomic_t fscache_n_allocs_wait;
45843 -extern atomic_t fscache_n_allocs_nobufs;
45844 -extern atomic_t fscache_n_allocs_intr;
45845 -extern atomic_t fscache_n_allocs_object_dead;
45846 -extern atomic_t fscache_n_alloc_ops;
45847 -extern atomic_t fscache_n_alloc_op_waits;
45848 -
45849 -extern atomic_t fscache_n_retrievals;
45850 -extern atomic_t fscache_n_retrievals_ok;
45851 -extern atomic_t fscache_n_retrievals_wait;
45852 -extern atomic_t fscache_n_retrievals_nodata;
45853 -extern atomic_t fscache_n_retrievals_nobufs;
45854 -extern atomic_t fscache_n_retrievals_intr;
45855 -extern atomic_t fscache_n_retrievals_nomem;
45856 -extern atomic_t fscache_n_retrievals_object_dead;
45857 -extern atomic_t fscache_n_retrieval_ops;
45858 -extern atomic_t fscache_n_retrieval_op_waits;
45859 -
45860 -extern atomic_t fscache_n_stores;
45861 -extern atomic_t fscache_n_stores_ok;
45862 -extern atomic_t fscache_n_stores_again;
45863 -extern atomic_t fscache_n_stores_nobufs;
45864 -extern atomic_t fscache_n_stores_oom;
45865 -extern atomic_t fscache_n_store_ops;
45866 -extern atomic_t fscache_n_store_calls;
45867 -extern atomic_t fscache_n_store_pages;
45868 -extern atomic_t fscache_n_store_radix_deletes;
45869 -extern atomic_t fscache_n_store_pages_over_limit;
45870 -
45871 -extern atomic_t fscache_n_store_vmscan_not_storing;
45872 -extern atomic_t fscache_n_store_vmscan_gone;
45873 -extern atomic_t fscache_n_store_vmscan_busy;
45874 -extern atomic_t fscache_n_store_vmscan_cancelled;
45875 -
45876 -extern atomic_t fscache_n_marks;
45877 -extern atomic_t fscache_n_uncaches;
45878 -
45879 -extern atomic_t fscache_n_acquires;
45880 -extern atomic_t fscache_n_acquires_null;
45881 -extern atomic_t fscache_n_acquires_no_cache;
45882 -extern atomic_t fscache_n_acquires_ok;
45883 -extern atomic_t fscache_n_acquires_nobufs;
45884 -extern atomic_t fscache_n_acquires_oom;
45885 -
45886 -extern atomic_t fscache_n_updates;
45887 -extern atomic_t fscache_n_updates_null;
45888 -extern atomic_t fscache_n_updates_run;
45889 -
45890 -extern atomic_t fscache_n_relinquishes;
45891 -extern atomic_t fscache_n_relinquishes_null;
45892 -extern atomic_t fscache_n_relinquishes_waitcrt;
45893 -extern atomic_t fscache_n_relinquishes_retire;
45894 -
45895 -extern atomic_t fscache_n_cookie_index;
45896 -extern atomic_t fscache_n_cookie_data;
45897 -extern atomic_t fscache_n_cookie_special;
45898 -
45899 -extern atomic_t fscache_n_object_alloc;
45900 -extern atomic_t fscache_n_object_no_alloc;
45901 -extern atomic_t fscache_n_object_lookups;
45902 -extern atomic_t fscache_n_object_lookups_negative;
45903 -extern atomic_t fscache_n_object_lookups_positive;
45904 -extern atomic_t fscache_n_object_lookups_timed_out;
45905 -extern atomic_t fscache_n_object_created;
45906 -extern atomic_t fscache_n_object_avail;
45907 -extern atomic_t fscache_n_object_dead;
45908 -
45909 -extern atomic_t fscache_n_checkaux_none;
45910 -extern atomic_t fscache_n_checkaux_okay;
45911 -extern atomic_t fscache_n_checkaux_update;
45912 -extern atomic_t fscache_n_checkaux_obsolete;
45913 +extern atomic_unchecked_t fscache_n_op_pend;
45914 +extern atomic_unchecked_t fscache_n_op_run;
45915 +extern atomic_unchecked_t fscache_n_op_enqueue;
45916 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45917 +extern atomic_unchecked_t fscache_n_op_release;
45918 +extern atomic_unchecked_t fscache_n_op_gc;
45919 +extern atomic_unchecked_t fscache_n_op_cancelled;
45920 +extern atomic_unchecked_t fscache_n_op_rejected;
45921 +
45922 +extern atomic_unchecked_t fscache_n_attr_changed;
45923 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45924 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45925 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45926 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45927 +
45928 +extern atomic_unchecked_t fscache_n_allocs;
45929 +extern atomic_unchecked_t fscache_n_allocs_ok;
45930 +extern atomic_unchecked_t fscache_n_allocs_wait;
45931 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45932 +extern atomic_unchecked_t fscache_n_allocs_intr;
45933 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45934 +extern atomic_unchecked_t fscache_n_alloc_ops;
45935 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45936 +
45937 +extern atomic_unchecked_t fscache_n_retrievals;
45938 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45939 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45940 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45941 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45942 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45943 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45944 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45945 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45946 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45947 +
45948 +extern atomic_unchecked_t fscache_n_stores;
45949 +extern atomic_unchecked_t fscache_n_stores_ok;
45950 +extern atomic_unchecked_t fscache_n_stores_again;
45951 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45952 +extern atomic_unchecked_t fscache_n_stores_oom;
45953 +extern atomic_unchecked_t fscache_n_store_ops;
45954 +extern atomic_unchecked_t fscache_n_store_calls;
45955 +extern atomic_unchecked_t fscache_n_store_pages;
45956 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45957 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45958 +
45959 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45960 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45961 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45962 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45963 +
45964 +extern atomic_unchecked_t fscache_n_marks;
45965 +extern atomic_unchecked_t fscache_n_uncaches;
45966 +
45967 +extern atomic_unchecked_t fscache_n_acquires;
45968 +extern atomic_unchecked_t fscache_n_acquires_null;
45969 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45970 +extern atomic_unchecked_t fscache_n_acquires_ok;
45971 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45972 +extern atomic_unchecked_t fscache_n_acquires_oom;
45973 +
45974 +extern atomic_unchecked_t fscache_n_updates;
45975 +extern atomic_unchecked_t fscache_n_updates_null;
45976 +extern atomic_unchecked_t fscache_n_updates_run;
45977 +
45978 +extern atomic_unchecked_t fscache_n_relinquishes;
45979 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45980 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45981 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45982 +
45983 +extern atomic_unchecked_t fscache_n_cookie_index;
45984 +extern atomic_unchecked_t fscache_n_cookie_data;
45985 +extern atomic_unchecked_t fscache_n_cookie_special;
45986 +
45987 +extern atomic_unchecked_t fscache_n_object_alloc;
45988 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45989 +extern atomic_unchecked_t fscache_n_object_lookups;
45990 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45991 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45992 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45993 +extern atomic_unchecked_t fscache_n_object_created;
45994 +extern atomic_unchecked_t fscache_n_object_avail;
45995 +extern atomic_unchecked_t fscache_n_object_dead;
45996 +
45997 +extern atomic_unchecked_t fscache_n_checkaux_none;
45998 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45999 +extern atomic_unchecked_t fscache_n_checkaux_update;
46000 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46001
46002 extern atomic_t fscache_n_cop_alloc_object;
46003 extern atomic_t fscache_n_cop_lookup_object;
46004 @@ -247,6 +247,11 @@ static inline void fscache_stat(atomic_t
46005 atomic_inc(stat);
46006 }
46007
46008 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46009 +{
46010 + atomic_inc_unchecked(stat);
46011 +}
46012 +
46013 static inline void fscache_stat_d(atomic_t *stat)
46014 {
46015 atomic_dec(stat);
46016 @@ -259,6 +264,7 @@ extern const struct file_operations fsca
46017
46018 #define __fscache_stat(stat) (NULL)
46019 #define fscache_stat(stat) do {} while (0)
46020 +#define fscache_stat_unchecked(stat) do {} while (0)
46021 #define fscache_stat_d(stat) do {} while (0)
46022 #endif
46023
46024 diff -urNp linux-2.6.32.46/fs/fscache/object.c linux-2.6.32.46/fs/fscache/object.c
46025 --- linux-2.6.32.46/fs/fscache/object.c 2011-03-27 14:31:47.000000000 -0400
46026 +++ linux-2.6.32.46/fs/fscache/object.c 2011-05-04 17:56:28.000000000 -0400
46027 @@ -144,7 +144,7 @@ static void fscache_object_state_machine
46028 /* update the object metadata on disk */
46029 case FSCACHE_OBJECT_UPDATING:
46030 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46031 - fscache_stat(&fscache_n_updates_run);
46032 + fscache_stat_unchecked(&fscache_n_updates_run);
46033 fscache_stat(&fscache_n_cop_update_object);
46034 object->cache->ops->update_object(object);
46035 fscache_stat_d(&fscache_n_cop_update_object);
46036 @@ -233,7 +233,7 @@ static void fscache_object_state_machine
46037 spin_lock(&object->lock);
46038 object->state = FSCACHE_OBJECT_DEAD;
46039 spin_unlock(&object->lock);
46040 - fscache_stat(&fscache_n_object_dead);
46041 + fscache_stat_unchecked(&fscache_n_object_dead);
46042 goto terminal_transit;
46043
46044 /* handle the parent cache of this object being withdrawn from
46045 @@ -248,7 +248,7 @@ static void fscache_object_state_machine
46046 spin_lock(&object->lock);
46047 object->state = FSCACHE_OBJECT_DEAD;
46048 spin_unlock(&object->lock);
46049 - fscache_stat(&fscache_n_object_dead);
46050 + fscache_stat_unchecked(&fscache_n_object_dead);
46051 goto terminal_transit;
46052
46053 /* complain about the object being woken up once it is
46054 @@ -492,7 +492,7 @@ static void fscache_lookup_object(struct
46055 parent->cookie->def->name, cookie->def->name,
46056 object->cache->tag->name);
46057
46058 - fscache_stat(&fscache_n_object_lookups);
46059 + fscache_stat_unchecked(&fscache_n_object_lookups);
46060 fscache_stat(&fscache_n_cop_lookup_object);
46061 ret = object->cache->ops->lookup_object(object);
46062 fscache_stat_d(&fscache_n_cop_lookup_object);
46063 @@ -503,7 +503,7 @@ static void fscache_lookup_object(struct
46064 if (ret == -ETIMEDOUT) {
46065 /* probably stuck behind another object, so move this one to
46066 * the back of the queue */
46067 - fscache_stat(&fscache_n_object_lookups_timed_out);
46068 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46069 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46070 }
46071
46072 @@ -526,7 +526,7 @@ void fscache_object_lookup_negative(stru
46073
46074 spin_lock(&object->lock);
46075 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46076 - fscache_stat(&fscache_n_object_lookups_negative);
46077 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46078
46079 /* transit here to allow write requests to begin stacking up
46080 * and read requests to begin returning ENODATA */
46081 @@ -572,7 +572,7 @@ void fscache_obtained_object(struct fsca
46082 * result, in which case there may be data available */
46083 spin_lock(&object->lock);
46084 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46085 - fscache_stat(&fscache_n_object_lookups_positive);
46086 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46087
46088 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46089
46090 @@ -586,7 +586,7 @@ void fscache_obtained_object(struct fsca
46091 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46092 } else {
46093 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46094 - fscache_stat(&fscache_n_object_created);
46095 + fscache_stat_unchecked(&fscache_n_object_created);
46096
46097 object->state = FSCACHE_OBJECT_AVAILABLE;
46098 spin_unlock(&object->lock);
46099 @@ -633,7 +633,7 @@ static void fscache_object_available(str
46100 fscache_enqueue_dependents(object);
46101
46102 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46103 - fscache_stat(&fscache_n_object_avail);
46104 + fscache_stat_unchecked(&fscache_n_object_avail);
46105
46106 _leave("");
46107 }
46108 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
46109 enum fscache_checkaux result;
46110
46111 if (!object->cookie->def->check_aux) {
46112 - fscache_stat(&fscache_n_checkaux_none);
46113 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46114 return FSCACHE_CHECKAUX_OKAY;
46115 }
46116
46117 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
46118 switch (result) {
46119 /* entry okay as is */
46120 case FSCACHE_CHECKAUX_OKAY:
46121 - fscache_stat(&fscache_n_checkaux_okay);
46122 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46123 break;
46124
46125 /* entry requires update */
46126 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46127 - fscache_stat(&fscache_n_checkaux_update);
46128 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46129 break;
46130
46131 /* entry requires deletion */
46132 case FSCACHE_CHECKAUX_OBSOLETE:
46133 - fscache_stat(&fscache_n_checkaux_obsolete);
46134 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46135 break;
46136
46137 default:
46138 diff -urNp linux-2.6.32.46/fs/fscache/operation.c linux-2.6.32.46/fs/fscache/operation.c
46139 --- linux-2.6.32.46/fs/fscache/operation.c 2011-03-27 14:31:47.000000000 -0400
46140 +++ linux-2.6.32.46/fs/fscache/operation.c 2011-05-04 17:56:28.000000000 -0400
46141 @@ -16,7 +16,7 @@
46142 #include <linux/seq_file.h>
46143 #include "internal.h"
46144
46145 -atomic_t fscache_op_debug_id;
46146 +atomic_unchecked_t fscache_op_debug_id;
46147 EXPORT_SYMBOL(fscache_op_debug_id);
46148
46149 /**
46150 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fs
46151 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46152 ASSERTCMP(atomic_read(&op->usage), >, 0);
46153
46154 - fscache_stat(&fscache_n_op_enqueue);
46155 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46156 switch (op->flags & FSCACHE_OP_TYPE) {
46157 case FSCACHE_OP_FAST:
46158 _debug("queue fast");
46159 @@ -76,7 +76,7 @@ static void fscache_run_op(struct fscach
46160 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46161 if (op->processor)
46162 fscache_enqueue_operation(op);
46163 - fscache_stat(&fscache_n_op_run);
46164 + fscache_stat_unchecked(&fscache_n_op_run);
46165 }
46166
46167 /*
46168 @@ -107,11 +107,11 @@ int fscache_submit_exclusive_op(struct f
46169 if (object->n_ops > 0) {
46170 atomic_inc(&op->usage);
46171 list_add_tail(&op->pend_link, &object->pending_ops);
46172 - fscache_stat(&fscache_n_op_pend);
46173 + fscache_stat_unchecked(&fscache_n_op_pend);
46174 } else if (!list_empty(&object->pending_ops)) {
46175 atomic_inc(&op->usage);
46176 list_add_tail(&op->pend_link, &object->pending_ops);
46177 - fscache_stat(&fscache_n_op_pend);
46178 + fscache_stat_unchecked(&fscache_n_op_pend);
46179 fscache_start_operations(object);
46180 } else {
46181 ASSERTCMP(object->n_in_progress, ==, 0);
46182 @@ -127,7 +127,7 @@ int fscache_submit_exclusive_op(struct f
46183 object->n_exclusive++; /* reads and writes must wait */
46184 atomic_inc(&op->usage);
46185 list_add_tail(&op->pend_link, &object->pending_ops);
46186 - fscache_stat(&fscache_n_op_pend);
46187 + fscache_stat_unchecked(&fscache_n_op_pend);
46188 ret = 0;
46189 } else {
46190 /* not allowed to submit ops in any other state */
46191 @@ -214,11 +214,11 @@ int fscache_submit_op(struct fscache_obj
46192 if (object->n_exclusive > 0) {
46193 atomic_inc(&op->usage);
46194 list_add_tail(&op->pend_link, &object->pending_ops);
46195 - fscache_stat(&fscache_n_op_pend);
46196 + fscache_stat_unchecked(&fscache_n_op_pend);
46197 } else if (!list_empty(&object->pending_ops)) {
46198 atomic_inc(&op->usage);
46199 list_add_tail(&op->pend_link, &object->pending_ops);
46200 - fscache_stat(&fscache_n_op_pend);
46201 + fscache_stat_unchecked(&fscache_n_op_pend);
46202 fscache_start_operations(object);
46203 } else {
46204 ASSERTCMP(object->n_exclusive, ==, 0);
46205 @@ -230,12 +230,12 @@ int fscache_submit_op(struct fscache_obj
46206 object->n_ops++;
46207 atomic_inc(&op->usage);
46208 list_add_tail(&op->pend_link, &object->pending_ops);
46209 - fscache_stat(&fscache_n_op_pend);
46210 + fscache_stat_unchecked(&fscache_n_op_pend);
46211 ret = 0;
46212 } else if (object->state == FSCACHE_OBJECT_DYING ||
46213 object->state == FSCACHE_OBJECT_LC_DYING ||
46214 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46215 - fscache_stat(&fscache_n_op_rejected);
46216 + fscache_stat_unchecked(&fscache_n_op_rejected);
46217 ret = -ENOBUFS;
46218 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46219 fscache_report_unexpected_submission(object, op, ostate);
46220 @@ -305,7 +305,7 @@ int fscache_cancel_op(struct fscache_ope
46221
46222 ret = -EBUSY;
46223 if (!list_empty(&op->pend_link)) {
46224 - fscache_stat(&fscache_n_op_cancelled);
46225 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46226 list_del_init(&op->pend_link);
46227 object->n_ops--;
46228 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46229 @@ -344,7 +344,7 @@ void fscache_put_operation(struct fscach
46230 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46231 BUG();
46232
46233 - fscache_stat(&fscache_n_op_release);
46234 + fscache_stat_unchecked(&fscache_n_op_release);
46235
46236 if (op->release) {
46237 op->release(op);
46238 @@ -361,7 +361,7 @@ void fscache_put_operation(struct fscach
46239 * lock, and defer it otherwise */
46240 if (!spin_trylock(&object->lock)) {
46241 _debug("defer put");
46242 - fscache_stat(&fscache_n_op_deferred_release);
46243 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46244
46245 cache = object->cache;
46246 spin_lock(&cache->op_gc_list_lock);
46247 @@ -423,7 +423,7 @@ void fscache_operation_gc(struct work_st
46248
46249 _debug("GC DEFERRED REL OBJ%x OP%x",
46250 object->debug_id, op->debug_id);
46251 - fscache_stat(&fscache_n_op_gc);
46252 + fscache_stat_unchecked(&fscache_n_op_gc);
46253
46254 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46255
46256 diff -urNp linux-2.6.32.46/fs/fscache/page.c linux-2.6.32.46/fs/fscache/page.c
46257 --- linux-2.6.32.46/fs/fscache/page.c 2011-03-27 14:31:47.000000000 -0400
46258 +++ linux-2.6.32.46/fs/fscache/page.c 2011-05-04 17:56:28.000000000 -0400
46259 @@ -59,7 +59,7 @@ bool __fscache_maybe_release_page(struct
46260 val = radix_tree_lookup(&cookie->stores, page->index);
46261 if (!val) {
46262 rcu_read_unlock();
46263 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46264 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46265 __fscache_uncache_page(cookie, page);
46266 return true;
46267 }
46268 @@ -89,11 +89,11 @@ bool __fscache_maybe_release_page(struct
46269 spin_unlock(&cookie->stores_lock);
46270
46271 if (xpage) {
46272 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46273 - fscache_stat(&fscache_n_store_radix_deletes);
46274 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46275 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46276 ASSERTCMP(xpage, ==, page);
46277 } else {
46278 - fscache_stat(&fscache_n_store_vmscan_gone);
46279 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46280 }
46281
46282 wake_up_bit(&cookie->flags, 0);
46283 @@ -106,7 +106,7 @@ page_busy:
46284 /* we might want to wait here, but that could deadlock the allocator as
46285 * the slow-work threads writing to the cache may all end up sleeping
46286 * on memory allocation */
46287 - fscache_stat(&fscache_n_store_vmscan_busy);
46288 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46289 return false;
46290 }
46291 EXPORT_SYMBOL(__fscache_maybe_release_page);
46292 @@ -130,7 +130,7 @@ static void fscache_end_page_write(struc
46293 FSCACHE_COOKIE_STORING_TAG);
46294 if (!radix_tree_tag_get(&cookie->stores, page->index,
46295 FSCACHE_COOKIE_PENDING_TAG)) {
46296 - fscache_stat(&fscache_n_store_radix_deletes);
46297 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46298 xpage = radix_tree_delete(&cookie->stores, page->index);
46299 }
46300 spin_unlock(&cookie->stores_lock);
46301 @@ -151,7 +151,7 @@ static void fscache_attr_changed_op(stru
46302
46303 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46304
46305 - fscache_stat(&fscache_n_attr_changed_calls);
46306 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46307
46308 if (fscache_object_is_active(object)) {
46309 fscache_set_op_state(op, "CallFS");
46310 @@ -178,11 +178,11 @@ int __fscache_attr_changed(struct fscach
46311
46312 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46313
46314 - fscache_stat(&fscache_n_attr_changed);
46315 + fscache_stat_unchecked(&fscache_n_attr_changed);
46316
46317 op = kzalloc(sizeof(*op), GFP_KERNEL);
46318 if (!op) {
46319 - fscache_stat(&fscache_n_attr_changed_nomem);
46320 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46321 _leave(" = -ENOMEM");
46322 return -ENOMEM;
46323 }
46324 @@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscach
46325 if (fscache_submit_exclusive_op(object, op) < 0)
46326 goto nobufs;
46327 spin_unlock(&cookie->lock);
46328 - fscache_stat(&fscache_n_attr_changed_ok);
46329 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46330 fscache_put_operation(op);
46331 _leave(" = 0");
46332 return 0;
46333 @@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscach
46334 nobufs:
46335 spin_unlock(&cookie->lock);
46336 kfree(op);
46337 - fscache_stat(&fscache_n_attr_changed_nobufs);
46338 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46339 _leave(" = %d", -ENOBUFS);
46340 return -ENOBUFS;
46341 }
46342 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache
46343 /* allocate a retrieval operation and attempt to submit it */
46344 op = kzalloc(sizeof(*op), GFP_NOIO);
46345 if (!op) {
46346 - fscache_stat(&fscache_n_retrievals_nomem);
46347 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46348 return NULL;
46349 }
46350
46351 @@ -294,13 +294,13 @@ static int fscache_wait_for_deferred_loo
46352 return 0;
46353 }
46354
46355 - fscache_stat(&fscache_n_retrievals_wait);
46356 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46357
46358 jif = jiffies;
46359 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46360 fscache_wait_bit_interruptible,
46361 TASK_INTERRUPTIBLE) != 0) {
46362 - fscache_stat(&fscache_n_retrievals_intr);
46363 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46364 _leave(" = -ERESTARTSYS");
46365 return -ERESTARTSYS;
46366 }
46367 @@ -318,8 +318,8 @@ static int fscache_wait_for_deferred_loo
46368 */
46369 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46370 struct fscache_retrieval *op,
46371 - atomic_t *stat_op_waits,
46372 - atomic_t *stat_object_dead)
46373 + atomic_unchecked_t *stat_op_waits,
46374 + atomic_unchecked_t *stat_object_dead)
46375 {
46376 int ret;
46377
46378 @@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_ac
46379 goto check_if_dead;
46380
46381 _debug(">>> WT");
46382 - fscache_stat(stat_op_waits);
46383 + fscache_stat_unchecked(stat_op_waits);
46384 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46385 fscache_wait_bit_interruptible,
46386 TASK_INTERRUPTIBLE) < 0) {
46387 @@ -344,7 +344,7 @@ static int fscache_wait_for_retrieval_ac
46388
46389 check_if_dead:
46390 if (unlikely(fscache_object_is_dead(object))) {
46391 - fscache_stat(stat_object_dead);
46392 + fscache_stat_unchecked(stat_object_dead);
46393 return -ENOBUFS;
46394 }
46395 return 0;
46396 @@ -371,7 +371,7 @@ int __fscache_read_or_alloc_page(struct
46397
46398 _enter("%p,%p,,,", cookie, page);
46399
46400 - fscache_stat(&fscache_n_retrievals);
46401 + fscache_stat_unchecked(&fscache_n_retrievals);
46402
46403 if (hlist_empty(&cookie->backing_objects))
46404 goto nobufs;
46405 @@ -405,7 +405,7 @@ int __fscache_read_or_alloc_page(struct
46406 goto nobufs_unlock;
46407 spin_unlock(&cookie->lock);
46408
46409 - fscache_stat(&fscache_n_retrieval_ops);
46410 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46411
46412 /* pin the netfs read context in case we need to do the actual netfs
46413 * read because we've encountered a cache read failure */
46414 @@ -435,15 +435,15 @@ int __fscache_read_or_alloc_page(struct
46415
46416 error:
46417 if (ret == -ENOMEM)
46418 - fscache_stat(&fscache_n_retrievals_nomem);
46419 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46420 else if (ret == -ERESTARTSYS)
46421 - fscache_stat(&fscache_n_retrievals_intr);
46422 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46423 else if (ret == -ENODATA)
46424 - fscache_stat(&fscache_n_retrievals_nodata);
46425 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46426 else if (ret < 0)
46427 - fscache_stat(&fscache_n_retrievals_nobufs);
46428 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46429 else
46430 - fscache_stat(&fscache_n_retrievals_ok);
46431 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46432
46433 fscache_put_retrieval(op);
46434 _leave(" = %d", ret);
46435 @@ -453,7 +453,7 @@ nobufs_unlock:
46436 spin_unlock(&cookie->lock);
46437 kfree(op);
46438 nobufs:
46439 - fscache_stat(&fscache_n_retrievals_nobufs);
46440 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46441 _leave(" = -ENOBUFS");
46442 return -ENOBUFS;
46443 }
46444 @@ -491,7 +491,7 @@ int __fscache_read_or_alloc_pages(struct
46445
46446 _enter("%p,,%d,,,", cookie, *nr_pages);
46447
46448 - fscache_stat(&fscache_n_retrievals);
46449 + fscache_stat_unchecked(&fscache_n_retrievals);
46450
46451 if (hlist_empty(&cookie->backing_objects))
46452 goto nobufs;
46453 @@ -522,7 +522,7 @@ int __fscache_read_or_alloc_pages(struct
46454 goto nobufs_unlock;
46455 spin_unlock(&cookie->lock);
46456
46457 - fscache_stat(&fscache_n_retrieval_ops);
46458 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46459
46460 /* pin the netfs read context in case we need to do the actual netfs
46461 * read because we've encountered a cache read failure */
46462 @@ -552,15 +552,15 @@ int __fscache_read_or_alloc_pages(struct
46463
46464 error:
46465 if (ret == -ENOMEM)
46466 - fscache_stat(&fscache_n_retrievals_nomem);
46467 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46468 else if (ret == -ERESTARTSYS)
46469 - fscache_stat(&fscache_n_retrievals_intr);
46470 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46471 else if (ret == -ENODATA)
46472 - fscache_stat(&fscache_n_retrievals_nodata);
46473 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46474 else if (ret < 0)
46475 - fscache_stat(&fscache_n_retrievals_nobufs);
46476 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46477 else
46478 - fscache_stat(&fscache_n_retrievals_ok);
46479 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46480
46481 fscache_put_retrieval(op);
46482 _leave(" = %d", ret);
46483 @@ -570,7 +570,7 @@ nobufs_unlock:
46484 spin_unlock(&cookie->lock);
46485 kfree(op);
46486 nobufs:
46487 - fscache_stat(&fscache_n_retrievals_nobufs);
46488 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46489 _leave(" = -ENOBUFS");
46490 return -ENOBUFS;
46491 }
46492 @@ -594,7 +594,7 @@ int __fscache_alloc_page(struct fscache_
46493
46494 _enter("%p,%p,,,", cookie, page);
46495
46496 - fscache_stat(&fscache_n_allocs);
46497 + fscache_stat_unchecked(&fscache_n_allocs);
46498
46499 if (hlist_empty(&cookie->backing_objects))
46500 goto nobufs;
46501 @@ -621,7 +621,7 @@ int __fscache_alloc_page(struct fscache_
46502 goto nobufs_unlock;
46503 spin_unlock(&cookie->lock);
46504
46505 - fscache_stat(&fscache_n_alloc_ops);
46506 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46507
46508 ret = fscache_wait_for_retrieval_activation(
46509 object, op,
46510 @@ -637,11 +637,11 @@ int __fscache_alloc_page(struct fscache_
46511
46512 error:
46513 if (ret == -ERESTARTSYS)
46514 - fscache_stat(&fscache_n_allocs_intr);
46515 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46516 else if (ret < 0)
46517 - fscache_stat(&fscache_n_allocs_nobufs);
46518 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46519 else
46520 - fscache_stat(&fscache_n_allocs_ok);
46521 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46522
46523 fscache_put_retrieval(op);
46524 _leave(" = %d", ret);
46525 @@ -651,7 +651,7 @@ nobufs_unlock:
46526 spin_unlock(&cookie->lock);
46527 kfree(op);
46528 nobufs:
46529 - fscache_stat(&fscache_n_allocs_nobufs);
46530 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46531 _leave(" = -ENOBUFS");
46532 return -ENOBUFS;
46533 }
46534 @@ -694,7 +694,7 @@ static void fscache_write_op(struct fsca
46535
46536 spin_lock(&cookie->stores_lock);
46537
46538 - fscache_stat(&fscache_n_store_calls);
46539 + fscache_stat_unchecked(&fscache_n_store_calls);
46540
46541 /* find a page to store */
46542 page = NULL;
46543 @@ -705,7 +705,7 @@ static void fscache_write_op(struct fsca
46544 page = results[0];
46545 _debug("gang %d [%lx]", n, page->index);
46546 if (page->index > op->store_limit) {
46547 - fscache_stat(&fscache_n_store_pages_over_limit);
46548 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46549 goto superseded;
46550 }
46551
46552 @@ -721,7 +721,7 @@ static void fscache_write_op(struct fsca
46553
46554 if (page) {
46555 fscache_set_op_state(&op->op, "Store");
46556 - fscache_stat(&fscache_n_store_pages);
46557 + fscache_stat_unchecked(&fscache_n_store_pages);
46558 fscache_stat(&fscache_n_cop_write_page);
46559 ret = object->cache->ops->write_page(op, page);
46560 fscache_stat_d(&fscache_n_cop_write_page);
46561 @@ -792,7 +792,7 @@ int __fscache_write_page(struct fscache_
46562 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46563 ASSERT(PageFsCache(page));
46564
46565 - fscache_stat(&fscache_n_stores);
46566 + fscache_stat_unchecked(&fscache_n_stores);
46567
46568 op = kzalloc(sizeof(*op), GFP_NOIO);
46569 if (!op)
46570 @@ -844,7 +844,7 @@ int __fscache_write_page(struct fscache_
46571 spin_unlock(&cookie->stores_lock);
46572 spin_unlock(&object->lock);
46573
46574 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46575 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46576 op->store_limit = object->store_limit;
46577
46578 if (fscache_submit_op(object, &op->op) < 0)
46579 @@ -852,8 +852,8 @@ int __fscache_write_page(struct fscache_
46580
46581 spin_unlock(&cookie->lock);
46582 radix_tree_preload_end();
46583 - fscache_stat(&fscache_n_store_ops);
46584 - fscache_stat(&fscache_n_stores_ok);
46585 + fscache_stat_unchecked(&fscache_n_store_ops);
46586 + fscache_stat_unchecked(&fscache_n_stores_ok);
46587
46588 /* the slow work queue now carries its own ref on the object */
46589 fscache_put_operation(&op->op);
46590 @@ -861,14 +861,14 @@ int __fscache_write_page(struct fscache_
46591 return 0;
46592
46593 already_queued:
46594 - fscache_stat(&fscache_n_stores_again);
46595 + fscache_stat_unchecked(&fscache_n_stores_again);
46596 already_pending:
46597 spin_unlock(&cookie->stores_lock);
46598 spin_unlock(&object->lock);
46599 spin_unlock(&cookie->lock);
46600 radix_tree_preload_end();
46601 kfree(op);
46602 - fscache_stat(&fscache_n_stores_ok);
46603 + fscache_stat_unchecked(&fscache_n_stores_ok);
46604 _leave(" = 0");
46605 return 0;
46606
46607 @@ -886,14 +886,14 @@ nobufs:
46608 spin_unlock(&cookie->lock);
46609 radix_tree_preload_end();
46610 kfree(op);
46611 - fscache_stat(&fscache_n_stores_nobufs);
46612 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46613 _leave(" = -ENOBUFS");
46614 return -ENOBUFS;
46615
46616 nomem_free:
46617 kfree(op);
46618 nomem:
46619 - fscache_stat(&fscache_n_stores_oom);
46620 + fscache_stat_unchecked(&fscache_n_stores_oom);
46621 _leave(" = -ENOMEM");
46622 return -ENOMEM;
46623 }
46624 @@ -911,7 +911,7 @@ void __fscache_uncache_page(struct fscac
46625 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46626 ASSERTCMP(page, !=, NULL);
46627
46628 - fscache_stat(&fscache_n_uncaches);
46629 + fscache_stat_unchecked(&fscache_n_uncaches);
46630
46631 /* cache withdrawal may beat us to it */
46632 if (!PageFsCache(page))
46633 @@ -964,7 +964,7 @@ void fscache_mark_pages_cached(struct fs
46634 unsigned long loop;
46635
46636 #ifdef CONFIG_FSCACHE_STATS
46637 - atomic_add(pagevec->nr, &fscache_n_marks);
46638 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46639 #endif
46640
46641 for (loop = 0; loop < pagevec->nr; loop++) {
46642 diff -urNp linux-2.6.32.46/fs/fscache/stats.c linux-2.6.32.46/fs/fscache/stats.c
46643 --- linux-2.6.32.46/fs/fscache/stats.c 2011-03-27 14:31:47.000000000 -0400
46644 +++ linux-2.6.32.46/fs/fscache/stats.c 2011-05-04 17:56:28.000000000 -0400
46645 @@ -18,95 +18,95 @@
46646 /*
46647 * operation counters
46648 */
46649 -atomic_t fscache_n_op_pend;
46650 -atomic_t fscache_n_op_run;
46651 -atomic_t fscache_n_op_enqueue;
46652 -atomic_t fscache_n_op_requeue;
46653 -atomic_t fscache_n_op_deferred_release;
46654 -atomic_t fscache_n_op_release;
46655 -atomic_t fscache_n_op_gc;
46656 -atomic_t fscache_n_op_cancelled;
46657 -atomic_t fscache_n_op_rejected;
46658 -
46659 -atomic_t fscache_n_attr_changed;
46660 -atomic_t fscache_n_attr_changed_ok;
46661 -atomic_t fscache_n_attr_changed_nobufs;
46662 -atomic_t fscache_n_attr_changed_nomem;
46663 -atomic_t fscache_n_attr_changed_calls;
46664 -
46665 -atomic_t fscache_n_allocs;
46666 -atomic_t fscache_n_allocs_ok;
46667 -atomic_t fscache_n_allocs_wait;
46668 -atomic_t fscache_n_allocs_nobufs;
46669 -atomic_t fscache_n_allocs_intr;
46670 -atomic_t fscache_n_allocs_object_dead;
46671 -atomic_t fscache_n_alloc_ops;
46672 -atomic_t fscache_n_alloc_op_waits;
46673 -
46674 -atomic_t fscache_n_retrievals;
46675 -atomic_t fscache_n_retrievals_ok;
46676 -atomic_t fscache_n_retrievals_wait;
46677 -atomic_t fscache_n_retrievals_nodata;
46678 -atomic_t fscache_n_retrievals_nobufs;
46679 -atomic_t fscache_n_retrievals_intr;
46680 -atomic_t fscache_n_retrievals_nomem;
46681 -atomic_t fscache_n_retrievals_object_dead;
46682 -atomic_t fscache_n_retrieval_ops;
46683 -atomic_t fscache_n_retrieval_op_waits;
46684 -
46685 -atomic_t fscache_n_stores;
46686 -atomic_t fscache_n_stores_ok;
46687 -atomic_t fscache_n_stores_again;
46688 -atomic_t fscache_n_stores_nobufs;
46689 -atomic_t fscache_n_stores_oom;
46690 -atomic_t fscache_n_store_ops;
46691 -atomic_t fscache_n_store_calls;
46692 -atomic_t fscache_n_store_pages;
46693 -atomic_t fscache_n_store_radix_deletes;
46694 -atomic_t fscache_n_store_pages_over_limit;
46695 -
46696 -atomic_t fscache_n_store_vmscan_not_storing;
46697 -atomic_t fscache_n_store_vmscan_gone;
46698 -atomic_t fscache_n_store_vmscan_busy;
46699 -atomic_t fscache_n_store_vmscan_cancelled;
46700 -
46701 -atomic_t fscache_n_marks;
46702 -atomic_t fscache_n_uncaches;
46703 -
46704 -atomic_t fscache_n_acquires;
46705 -atomic_t fscache_n_acquires_null;
46706 -atomic_t fscache_n_acquires_no_cache;
46707 -atomic_t fscache_n_acquires_ok;
46708 -atomic_t fscache_n_acquires_nobufs;
46709 -atomic_t fscache_n_acquires_oom;
46710 -
46711 -atomic_t fscache_n_updates;
46712 -atomic_t fscache_n_updates_null;
46713 -atomic_t fscache_n_updates_run;
46714 -
46715 -atomic_t fscache_n_relinquishes;
46716 -atomic_t fscache_n_relinquishes_null;
46717 -atomic_t fscache_n_relinquishes_waitcrt;
46718 -atomic_t fscache_n_relinquishes_retire;
46719 -
46720 -atomic_t fscache_n_cookie_index;
46721 -atomic_t fscache_n_cookie_data;
46722 -atomic_t fscache_n_cookie_special;
46723 -
46724 -atomic_t fscache_n_object_alloc;
46725 -atomic_t fscache_n_object_no_alloc;
46726 -atomic_t fscache_n_object_lookups;
46727 -atomic_t fscache_n_object_lookups_negative;
46728 -atomic_t fscache_n_object_lookups_positive;
46729 -atomic_t fscache_n_object_lookups_timed_out;
46730 -atomic_t fscache_n_object_created;
46731 -atomic_t fscache_n_object_avail;
46732 -atomic_t fscache_n_object_dead;
46733 -
46734 -atomic_t fscache_n_checkaux_none;
46735 -atomic_t fscache_n_checkaux_okay;
46736 -atomic_t fscache_n_checkaux_update;
46737 -atomic_t fscache_n_checkaux_obsolete;
46738 +atomic_unchecked_t fscache_n_op_pend;
46739 +atomic_unchecked_t fscache_n_op_run;
46740 +atomic_unchecked_t fscache_n_op_enqueue;
46741 +atomic_unchecked_t fscache_n_op_requeue;
46742 +atomic_unchecked_t fscache_n_op_deferred_release;
46743 +atomic_unchecked_t fscache_n_op_release;
46744 +atomic_unchecked_t fscache_n_op_gc;
46745 +atomic_unchecked_t fscache_n_op_cancelled;
46746 +atomic_unchecked_t fscache_n_op_rejected;
46747 +
46748 +atomic_unchecked_t fscache_n_attr_changed;
46749 +atomic_unchecked_t fscache_n_attr_changed_ok;
46750 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46751 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46752 +atomic_unchecked_t fscache_n_attr_changed_calls;
46753 +
46754 +atomic_unchecked_t fscache_n_allocs;
46755 +atomic_unchecked_t fscache_n_allocs_ok;
46756 +atomic_unchecked_t fscache_n_allocs_wait;
46757 +atomic_unchecked_t fscache_n_allocs_nobufs;
46758 +atomic_unchecked_t fscache_n_allocs_intr;
46759 +atomic_unchecked_t fscache_n_allocs_object_dead;
46760 +atomic_unchecked_t fscache_n_alloc_ops;
46761 +atomic_unchecked_t fscache_n_alloc_op_waits;
46762 +
46763 +atomic_unchecked_t fscache_n_retrievals;
46764 +atomic_unchecked_t fscache_n_retrievals_ok;
46765 +atomic_unchecked_t fscache_n_retrievals_wait;
46766 +atomic_unchecked_t fscache_n_retrievals_nodata;
46767 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46768 +atomic_unchecked_t fscache_n_retrievals_intr;
46769 +atomic_unchecked_t fscache_n_retrievals_nomem;
46770 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46771 +atomic_unchecked_t fscache_n_retrieval_ops;
46772 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46773 +
46774 +atomic_unchecked_t fscache_n_stores;
46775 +atomic_unchecked_t fscache_n_stores_ok;
46776 +atomic_unchecked_t fscache_n_stores_again;
46777 +atomic_unchecked_t fscache_n_stores_nobufs;
46778 +atomic_unchecked_t fscache_n_stores_oom;
46779 +atomic_unchecked_t fscache_n_store_ops;
46780 +atomic_unchecked_t fscache_n_store_calls;
46781 +atomic_unchecked_t fscache_n_store_pages;
46782 +atomic_unchecked_t fscache_n_store_radix_deletes;
46783 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46784 +
46785 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46786 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46787 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46788 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46789 +
46790 +atomic_unchecked_t fscache_n_marks;
46791 +atomic_unchecked_t fscache_n_uncaches;
46792 +
46793 +atomic_unchecked_t fscache_n_acquires;
46794 +atomic_unchecked_t fscache_n_acquires_null;
46795 +atomic_unchecked_t fscache_n_acquires_no_cache;
46796 +atomic_unchecked_t fscache_n_acquires_ok;
46797 +atomic_unchecked_t fscache_n_acquires_nobufs;
46798 +atomic_unchecked_t fscache_n_acquires_oom;
46799 +
46800 +atomic_unchecked_t fscache_n_updates;
46801 +atomic_unchecked_t fscache_n_updates_null;
46802 +atomic_unchecked_t fscache_n_updates_run;
46803 +
46804 +atomic_unchecked_t fscache_n_relinquishes;
46805 +atomic_unchecked_t fscache_n_relinquishes_null;
46806 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46807 +atomic_unchecked_t fscache_n_relinquishes_retire;
46808 +
46809 +atomic_unchecked_t fscache_n_cookie_index;
46810 +atomic_unchecked_t fscache_n_cookie_data;
46811 +atomic_unchecked_t fscache_n_cookie_special;
46812 +
46813 +atomic_unchecked_t fscache_n_object_alloc;
46814 +atomic_unchecked_t fscache_n_object_no_alloc;
46815 +atomic_unchecked_t fscache_n_object_lookups;
46816 +atomic_unchecked_t fscache_n_object_lookups_negative;
46817 +atomic_unchecked_t fscache_n_object_lookups_positive;
46818 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46819 +atomic_unchecked_t fscache_n_object_created;
46820 +atomic_unchecked_t fscache_n_object_avail;
46821 +atomic_unchecked_t fscache_n_object_dead;
46822 +
46823 +atomic_unchecked_t fscache_n_checkaux_none;
46824 +atomic_unchecked_t fscache_n_checkaux_okay;
46825 +atomic_unchecked_t fscache_n_checkaux_update;
46826 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46827
46828 atomic_t fscache_n_cop_alloc_object;
46829 atomic_t fscache_n_cop_lookup_object;
46830 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
46831 seq_puts(m, "FS-Cache statistics\n");
46832
46833 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46834 - atomic_read(&fscache_n_cookie_index),
46835 - atomic_read(&fscache_n_cookie_data),
46836 - atomic_read(&fscache_n_cookie_special));
46837 + atomic_read_unchecked(&fscache_n_cookie_index),
46838 + atomic_read_unchecked(&fscache_n_cookie_data),
46839 + atomic_read_unchecked(&fscache_n_cookie_special));
46840
46841 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46842 - atomic_read(&fscache_n_object_alloc),
46843 - atomic_read(&fscache_n_object_no_alloc),
46844 - atomic_read(&fscache_n_object_avail),
46845 - atomic_read(&fscache_n_object_dead));
46846 + atomic_read_unchecked(&fscache_n_object_alloc),
46847 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46848 + atomic_read_unchecked(&fscache_n_object_avail),
46849 + atomic_read_unchecked(&fscache_n_object_dead));
46850 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46851 - atomic_read(&fscache_n_checkaux_none),
46852 - atomic_read(&fscache_n_checkaux_okay),
46853 - atomic_read(&fscache_n_checkaux_update),
46854 - atomic_read(&fscache_n_checkaux_obsolete));
46855 + atomic_read_unchecked(&fscache_n_checkaux_none),
46856 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46857 + atomic_read_unchecked(&fscache_n_checkaux_update),
46858 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46859
46860 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46861 - atomic_read(&fscache_n_marks),
46862 - atomic_read(&fscache_n_uncaches));
46863 + atomic_read_unchecked(&fscache_n_marks),
46864 + atomic_read_unchecked(&fscache_n_uncaches));
46865
46866 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46867 " oom=%u\n",
46868 - atomic_read(&fscache_n_acquires),
46869 - atomic_read(&fscache_n_acquires_null),
46870 - atomic_read(&fscache_n_acquires_no_cache),
46871 - atomic_read(&fscache_n_acquires_ok),
46872 - atomic_read(&fscache_n_acquires_nobufs),
46873 - atomic_read(&fscache_n_acquires_oom));
46874 + atomic_read_unchecked(&fscache_n_acquires),
46875 + atomic_read_unchecked(&fscache_n_acquires_null),
46876 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46877 + atomic_read_unchecked(&fscache_n_acquires_ok),
46878 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46879 + atomic_read_unchecked(&fscache_n_acquires_oom));
46880
46881 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46882 - atomic_read(&fscache_n_object_lookups),
46883 - atomic_read(&fscache_n_object_lookups_negative),
46884 - atomic_read(&fscache_n_object_lookups_positive),
46885 - atomic_read(&fscache_n_object_lookups_timed_out),
46886 - atomic_read(&fscache_n_object_created));
46887 + atomic_read_unchecked(&fscache_n_object_lookups),
46888 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46889 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46890 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out),
46891 + atomic_read_unchecked(&fscache_n_object_created));
46892
46893 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46894 - atomic_read(&fscache_n_updates),
46895 - atomic_read(&fscache_n_updates_null),
46896 - atomic_read(&fscache_n_updates_run));
46897 + atomic_read_unchecked(&fscache_n_updates),
46898 + atomic_read_unchecked(&fscache_n_updates_null),
46899 + atomic_read_unchecked(&fscache_n_updates_run));
46900
46901 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46902 - atomic_read(&fscache_n_relinquishes),
46903 - atomic_read(&fscache_n_relinquishes_null),
46904 - atomic_read(&fscache_n_relinquishes_waitcrt),
46905 - atomic_read(&fscache_n_relinquishes_retire));
46906 + atomic_read_unchecked(&fscache_n_relinquishes),
46907 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46908 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46909 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46910
46911 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46912 - atomic_read(&fscache_n_attr_changed),
46913 - atomic_read(&fscache_n_attr_changed_ok),
46914 - atomic_read(&fscache_n_attr_changed_nobufs),
46915 - atomic_read(&fscache_n_attr_changed_nomem),
46916 - atomic_read(&fscache_n_attr_changed_calls));
46917 + atomic_read_unchecked(&fscache_n_attr_changed),
46918 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46919 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46920 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46921 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46922
46923 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46924 - atomic_read(&fscache_n_allocs),
46925 - atomic_read(&fscache_n_allocs_ok),
46926 - atomic_read(&fscache_n_allocs_wait),
46927 - atomic_read(&fscache_n_allocs_nobufs),
46928 - atomic_read(&fscache_n_allocs_intr));
46929 + atomic_read_unchecked(&fscache_n_allocs),
46930 + atomic_read_unchecked(&fscache_n_allocs_ok),
46931 + atomic_read_unchecked(&fscache_n_allocs_wait),
46932 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46933 + atomic_read_unchecked(&fscache_n_allocs_intr));
46934 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46935 - atomic_read(&fscache_n_alloc_ops),
46936 - atomic_read(&fscache_n_alloc_op_waits),
46937 - atomic_read(&fscache_n_allocs_object_dead));
46938 + atomic_read_unchecked(&fscache_n_alloc_ops),
46939 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46940 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46941
46942 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46943 " int=%u oom=%u\n",
46944 - atomic_read(&fscache_n_retrievals),
46945 - atomic_read(&fscache_n_retrievals_ok),
46946 - atomic_read(&fscache_n_retrievals_wait),
46947 - atomic_read(&fscache_n_retrievals_nodata),
46948 - atomic_read(&fscache_n_retrievals_nobufs),
46949 - atomic_read(&fscache_n_retrievals_intr),
46950 - atomic_read(&fscache_n_retrievals_nomem));
46951 + atomic_read_unchecked(&fscache_n_retrievals),
46952 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46953 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46954 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46955 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46956 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46957 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46958 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46959 - atomic_read(&fscache_n_retrieval_ops),
46960 - atomic_read(&fscache_n_retrieval_op_waits),
46961 - atomic_read(&fscache_n_retrievals_object_dead));
46962 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46963 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46964 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46965
46966 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46967 - atomic_read(&fscache_n_stores),
46968 - atomic_read(&fscache_n_stores_ok),
46969 - atomic_read(&fscache_n_stores_again),
46970 - atomic_read(&fscache_n_stores_nobufs),
46971 - atomic_read(&fscache_n_stores_oom));
46972 + atomic_read_unchecked(&fscache_n_stores),
46973 + atomic_read_unchecked(&fscache_n_stores_ok),
46974 + atomic_read_unchecked(&fscache_n_stores_again),
46975 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46976 + atomic_read_unchecked(&fscache_n_stores_oom));
46977 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46978 - atomic_read(&fscache_n_store_ops),
46979 - atomic_read(&fscache_n_store_calls),
46980 - atomic_read(&fscache_n_store_pages),
46981 - atomic_read(&fscache_n_store_radix_deletes),
46982 - atomic_read(&fscache_n_store_pages_over_limit));
46983 + atomic_read_unchecked(&fscache_n_store_ops),
46984 + atomic_read_unchecked(&fscache_n_store_calls),
46985 + atomic_read_unchecked(&fscache_n_store_pages),
46986 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46987 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46988
46989 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46990 - atomic_read(&fscache_n_store_vmscan_not_storing),
46991 - atomic_read(&fscache_n_store_vmscan_gone),
46992 - atomic_read(&fscache_n_store_vmscan_busy),
46993 - atomic_read(&fscache_n_store_vmscan_cancelled));
46994 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46995 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46996 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46997 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46998
46999 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47000 - atomic_read(&fscache_n_op_pend),
47001 - atomic_read(&fscache_n_op_run),
47002 - atomic_read(&fscache_n_op_enqueue),
47003 - atomic_read(&fscache_n_op_cancelled),
47004 - atomic_read(&fscache_n_op_rejected));
47005 + atomic_read_unchecked(&fscache_n_op_pend),
47006 + atomic_read_unchecked(&fscache_n_op_run),
47007 + atomic_read_unchecked(&fscache_n_op_enqueue),
47008 + atomic_read_unchecked(&fscache_n_op_cancelled),
47009 + atomic_read_unchecked(&fscache_n_op_rejected));
47010 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47011 - atomic_read(&fscache_n_op_deferred_release),
47012 - atomic_read(&fscache_n_op_release),
47013 - atomic_read(&fscache_n_op_gc));
47014 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47015 + atomic_read_unchecked(&fscache_n_op_release),
47016 + atomic_read_unchecked(&fscache_n_op_gc));
47017
47018 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47019 atomic_read(&fscache_n_cop_alloc_object),
47020 diff -urNp linux-2.6.32.46/fs/fuse/cuse.c linux-2.6.32.46/fs/fuse/cuse.c
47021 --- linux-2.6.32.46/fs/fuse/cuse.c 2011-03-27 14:31:47.000000000 -0400
47022 +++ linux-2.6.32.46/fs/fuse/cuse.c 2011-08-05 20:33:55.000000000 -0400
47023 @@ -576,10 +576,12 @@ static int __init cuse_init(void)
47024 INIT_LIST_HEAD(&cuse_conntbl[i]);
47025
47026 /* inherit and extend fuse_dev_operations */
47027 - cuse_channel_fops = fuse_dev_operations;
47028 - cuse_channel_fops.owner = THIS_MODULE;
47029 - cuse_channel_fops.open = cuse_channel_open;
47030 - cuse_channel_fops.release = cuse_channel_release;
47031 + pax_open_kernel();
47032 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47033 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47034 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47035 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47036 + pax_close_kernel();
47037
47038 cuse_class = class_create(THIS_MODULE, "cuse");
47039 if (IS_ERR(cuse_class))
47040 diff -urNp linux-2.6.32.46/fs/fuse/dev.c linux-2.6.32.46/fs/fuse/dev.c
47041 --- linux-2.6.32.46/fs/fuse/dev.c 2011-08-29 22:24:44.000000000 -0400
47042 +++ linux-2.6.32.46/fs/fuse/dev.c 2011-08-29 22:25:07.000000000 -0400
47043 @@ -885,7 +885,7 @@ static int fuse_notify_inval_entry(struc
47044 {
47045 struct fuse_notify_inval_entry_out outarg;
47046 int err = -EINVAL;
47047 - char buf[FUSE_NAME_MAX+1];
47048 + char *buf = NULL;
47049 struct qstr name;
47050
47051 if (size < sizeof(outarg))
47052 @@ -899,6 +899,11 @@ static int fuse_notify_inval_entry(struc
47053 if (outarg.namelen > FUSE_NAME_MAX)
47054 goto err;
47055
47056 + err = -ENOMEM;
47057 + buf = kmalloc(FUSE_NAME_MAX+1, GFP_KERNEL);
47058 + if (!buf)
47059 + goto err;
47060 +
47061 err = -EINVAL;
47062 if (size != sizeof(outarg) + outarg.namelen + 1)
47063 goto err;
47064 @@ -914,17 +919,15 @@ static int fuse_notify_inval_entry(struc
47065
47066 down_read(&fc->killsb);
47067 err = -ENOENT;
47068 - if (!fc->sb)
47069 - goto err_unlock;
47070 -
47071 - err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
47072 -
47073 -err_unlock:
47074 + if (fc->sb)
47075 + err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
47076 up_read(&fc->killsb);
47077 + kfree(buf);
47078 return err;
47079
47080 err:
47081 fuse_copy_finish(cs);
47082 + kfree(buf);
47083 return err;
47084 }
47085
47086 diff -urNp linux-2.6.32.46/fs/fuse/dir.c linux-2.6.32.46/fs/fuse/dir.c
47087 --- linux-2.6.32.46/fs/fuse/dir.c 2011-03-27 14:31:47.000000000 -0400
47088 +++ linux-2.6.32.46/fs/fuse/dir.c 2011-04-17 15:56:46.000000000 -0400
47089 @@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *de
47090 return link;
47091 }
47092
47093 -static void free_link(char *link)
47094 +static void free_link(const char *link)
47095 {
47096 if (!IS_ERR(link))
47097 free_page((unsigned long) link);
47098 diff -urNp linux-2.6.32.46/fs/gfs2/ops_inode.c linux-2.6.32.46/fs/gfs2/ops_inode.c
47099 --- linux-2.6.32.46/fs/gfs2/ops_inode.c 2011-03-27 14:31:47.000000000 -0400
47100 +++ linux-2.6.32.46/fs/gfs2/ops_inode.c 2011-05-16 21:46:57.000000000 -0400
47101 @@ -752,6 +752,8 @@ static int gfs2_rename(struct inode *odi
47102 unsigned int x;
47103 int error;
47104
47105 + pax_track_stack();
47106 +
47107 if (ndentry->d_inode) {
47108 nip = GFS2_I(ndentry->d_inode);
47109 if (ip == nip)
47110 diff -urNp linux-2.6.32.46/fs/gfs2/sys.c linux-2.6.32.46/fs/gfs2/sys.c
47111 --- linux-2.6.32.46/fs/gfs2/sys.c 2011-03-27 14:31:47.000000000 -0400
47112 +++ linux-2.6.32.46/fs/gfs2/sys.c 2011-04-17 15:56:46.000000000 -0400
47113 @@ -49,7 +49,7 @@ static ssize_t gfs2_attr_store(struct ko
47114 return a->store ? a->store(sdp, buf, len) : len;
47115 }
47116
47117 -static struct sysfs_ops gfs2_attr_ops = {
47118 +static const struct sysfs_ops gfs2_attr_ops = {
47119 .show = gfs2_attr_show,
47120 .store = gfs2_attr_store,
47121 };
47122 @@ -584,7 +584,7 @@ static int gfs2_uevent(struct kset *kset
47123 return 0;
47124 }
47125
47126 -static struct kset_uevent_ops gfs2_uevent_ops = {
47127 +static const struct kset_uevent_ops gfs2_uevent_ops = {
47128 .uevent = gfs2_uevent,
47129 };
47130
47131 diff -urNp linux-2.6.32.46/fs/hfsplus/catalog.c linux-2.6.32.46/fs/hfsplus/catalog.c
47132 --- linux-2.6.32.46/fs/hfsplus/catalog.c 2011-03-27 14:31:47.000000000 -0400
47133 +++ linux-2.6.32.46/fs/hfsplus/catalog.c 2011-05-16 21:46:57.000000000 -0400
47134 @@ -157,6 +157,8 @@ int hfsplus_find_cat(struct super_block
47135 int err;
47136 u16 type;
47137
47138 + pax_track_stack();
47139 +
47140 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
47141 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
47142 if (err)
47143 @@ -186,6 +188,8 @@ int hfsplus_create_cat(u32 cnid, struct
47144 int entry_size;
47145 int err;
47146
47147 + pax_track_stack();
47148 +
47149 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
47150 sb = dir->i_sb;
47151 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
47152 @@ -318,6 +322,8 @@ int hfsplus_rename_cat(u32 cnid,
47153 int entry_size, type;
47154 int err = 0;
47155
47156 + pax_track_stack();
47157 +
47158 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
47159 dst_dir->i_ino, dst_name->name);
47160 sb = src_dir->i_sb;
47161 diff -urNp linux-2.6.32.46/fs/hfsplus/dir.c linux-2.6.32.46/fs/hfsplus/dir.c
47162 --- linux-2.6.32.46/fs/hfsplus/dir.c 2011-03-27 14:31:47.000000000 -0400
47163 +++ linux-2.6.32.46/fs/hfsplus/dir.c 2011-05-16 21:46:57.000000000 -0400
47164 @@ -121,6 +121,8 @@ static int hfsplus_readdir(struct file *
47165 struct hfsplus_readdir_data *rd;
47166 u16 type;
47167
47168 + pax_track_stack();
47169 +
47170 if (filp->f_pos >= inode->i_size)
47171 return 0;
47172
47173 diff -urNp linux-2.6.32.46/fs/hfsplus/inode.c linux-2.6.32.46/fs/hfsplus/inode.c
47174 --- linux-2.6.32.46/fs/hfsplus/inode.c 2011-03-27 14:31:47.000000000 -0400
47175 +++ linux-2.6.32.46/fs/hfsplus/inode.c 2011-05-16 21:46:57.000000000 -0400
47176 @@ -399,6 +399,8 @@ int hfsplus_cat_read_inode(struct inode
47177 int res = 0;
47178 u16 type;
47179
47180 + pax_track_stack();
47181 +
47182 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
47183
47184 HFSPLUS_I(inode).dev = 0;
47185 @@ -461,6 +463,8 @@ int hfsplus_cat_write_inode(struct inode
47186 struct hfs_find_data fd;
47187 hfsplus_cat_entry entry;
47188
47189 + pax_track_stack();
47190 +
47191 if (HFSPLUS_IS_RSRC(inode))
47192 main_inode = HFSPLUS_I(inode).rsrc_inode;
47193
47194 diff -urNp linux-2.6.32.46/fs/hfsplus/ioctl.c linux-2.6.32.46/fs/hfsplus/ioctl.c
47195 --- linux-2.6.32.46/fs/hfsplus/ioctl.c 2011-03-27 14:31:47.000000000 -0400
47196 +++ linux-2.6.32.46/fs/hfsplus/ioctl.c 2011-05-16 21:46:57.000000000 -0400
47197 @@ -101,6 +101,8 @@ int hfsplus_setxattr(struct dentry *dent
47198 struct hfsplus_cat_file *file;
47199 int res;
47200
47201 + pax_track_stack();
47202 +
47203 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47204 return -EOPNOTSUPP;
47205
47206 @@ -143,6 +145,8 @@ ssize_t hfsplus_getxattr(struct dentry *
47207 struct hfsplus_cat_file *file;
47208 ssize_t res = 0;
47209
47210 + pax_track_stack();
47211 +
47212 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47213 return -EOPNOTSUPP;
47214
47215 diff -urNp linux-2.6.32.46/fs/hfsplus/super.c linux-2.6.32.46/fs/hfsplus/super.c
47216 --- linux-2.6.32.46/fs/hfsplus/super.c 2011-03-27 14:31:47.000000000 -0400
47217 +++ linux-2.6.32.46/fs/hfsplus/super.c 2011-05-16 21:46:57.000000000 -0400
47218 @@ -312,6 +312,8 @@ static int hfsplus_fill_super(struct sup
47219 struct nls_table *nls = NULL;
47220 int err = -EINVAL;
47221
47222 + pax_track_stack();
47223 +
47224 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
47225 if (!sbi)
47226 return -ENOMEM;
47227 diff -urNp linux-2.6.32.46/fs/hugetlbfs/inode.c linux-2.6.32.46/fs/hugetlbfs/inode.c
47228 --- linux-2.6.32.46/fs/hugetlbfs/inode.c 2011-03-27 14:31:47.000000000 -0400
47229 +++ linux-2.6.32.46/fs/hugetlbfs/inode.c 2011-04-17 15:56:46.000000000 -0400
47230 @@ -909,7 +909,7 @@ static struct file_system_type hugetlbfs
47231 .kill_sb = kill_litter_super,
47232 };
47233
47234 -static struct vfsmount *hugetlbfs_vfsmount;
47235 +struct vfsmount *hugetlbfs_vfsmount;
47236
47237 static int can_do_hugetlb_shm(void)
47238 {
47239 diff -urNp linux-2.6.32.46/fs/ioctl.c linux-2.6.32.46/fs/ioctl.c
47240 --- linux-2.6.32.46/fs/ioctl.c 2011-03-27 14:31:47.000000000 -0400
47241 +++ linux-2.6.32.46/fs/ioctl.c 2011-04-17 15:56:46.000000000 -0400
47242 @@ -97,7 +97,7 @@ int fiemap_fill_next_extent(struct fiema
47243 u64 phys, u64 len, u32 flags)
47244 {
47245 struct fiemap_extent extent;
47246 - struct fiemap_extent *dest = fieinfo->fi_extents_start;
47247 + struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
47248
47249 /* only count the extents */
47250 if (fieinfo->fi_extents_max == 0) {
47251 @@ -207,7 +207,7 @@ static int ioctl_fiemap(struct file *fil
47252
47253 fieinfo.fi_flags = fiemap.fm_flags;
47254 fieinfo.fi_extents_max = fiemap.fm_extent_count;
47255 - fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
47256 + fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
47257
47258 if (fiemap.fm_extent_count != 0 &&
47259 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
47260 @@ -220,7 +220,7 @@ static int ioctl_fiemap(struct file *fil
47261 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
47262 fiemap.fm_flags = fieinfo.fi_flags;
47263 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
47264 - if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
47265 + if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
47266 error = -EFAULT;
47267
47268 return error;
47269 diff -urNp linux-2.6.32.46/fs/jbd/checkpoint.c linux-2.6.32.46/fs/jbd/checkpoint.c
47270 --- linux-2.6.32.46/fs/jbd/checkpoint.c 2011-03-27 14:31:47.000000000 -0400
47271 +++ linux-2.6.32.46/fs/jbd/checkpoint.c 2011-05-16 21:46:57.000000000 -0400
47272 @@ -348,6 +348,8 @@ int log_do_checkpoint(journal_t *journal
47273 tid_t this_tid;
47274 int result;
47275
47276 + pax_track_stack();
47277 +
47278 jbd_debug(1, "Start checkpoint\n");
47279
47280 /*
47281 diff -urNp linux-2.6.32.46/fs/jffs2/compr_rtime.c linux-2.6.32.46/fs/jffs2/compr_rtime.c
47282 --- linux-2.6.32.46/fs/jffs2/compr_rtime.c 2011-03-27 14:31:47.000000000 -0400
47283 +++ linux-2.6.32.46/fs/jffs2/compr_rtime.c 2011-05-16 21:46:57.000000000 -0400
47284 @@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
47285 int outpos = 0;
47286 int pos=0;
47287
47288 + pax_track_stack();
47289 +
47290 memset(positions,0,sizeof(positions));
47291
47292 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
47293 @@ -79,6 +81,8 @@ static int jffs2_rtime_decompress(unsign
47294 int outpos = 0;
47295 int pos=0;
47296
47297 + pax_track_stack();
47298 +
47299 memset(positions,0,sizeof(positions));
47300
47301 while (outpos<destlen) {
47302 diff -urNp linux-2.6.32.46/fs/jffs2/compr_rubin.c linux-2.6.32.46/fs/jffs2/compr_rubin.c
47303 --- linux-2.6.32.46/fs/jffs2/compr_rubin.c 2011-03-27 14:31:47.000000000 -0400
47304 +++ linux-2.6.32.46/fs/jffs2/compr_rubin.c 2011-05-16 21:46:57.000000000 -0400
47305 @@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
47306 int ret;
47307 uint32_t mysrclen, mydstlen;
47308
47309 + pax_track_stack();
47310 +
47311 mysrclen = *sourcelen;
47312 mydstlen = *dstlen - 8;
47313
47314 diff -urNp linux-2.6.32.46/fs/jffs2/erase.c linux-2.6.32.46/fs/jffs2/erase.c
47315 --- linux-2.6.32.46/fs/jffs2/erase.c 2011-03-27 14:31:47.000000000 -0400
47316 +++ linux-2.6.32.46/fs/jffs2/erase.c 2011-04-17 15:56:46.000000000 -0400
47317 @@ -434,7 +434,8 @@ static void jffs2_mark_erased_block(stru
47318 struct jffs2_unknown_node marker = {
47319 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47320 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47321 - .totlen = cpu_to_je32(c->cleanmarker_size)
47322 + .totlen = cpu_to_je32(c->cleanmarker_size),
47323 + .hdr_crc = cpu_to_je32(0)
47324 };
47325
47326 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47327 diff -urNp linux-2.6.32.46/fs/jffs2/wbuf.c linux-2.6.32.46/fs/jffs2/wbuf.c
47328 --- linux-2.6.32.46/fs/jffs2/wbuf.c 2011-03-27 14:31:47.000000000 -0400
47329 +++ linux-2.6.32.46/fs/jffs2/wbuf.c 2011-04-17 15:56:46.000000000 -0400
47330 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
47331 {
47332 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47333 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47334 - .totlen = constant_cpu_to_je32(8)
47335 + .totlen = constant_cpu_to_je32(8),
47336 + .hdr_crc = constant_cpu_to_je32(0)
47337 };
47338
47339 /*
47340 diff -urNp linux-2.6.32.46/fs/jffs2/xattr.c linux-2.6.32.46/fs/jffs2/xattr.c
47341 --- linux-2.6.32.46/fs/jffs2/xattr.c 2011-03-27 14:31:47.000000000 -0400
47342 +++ linux-2.6.32.46/fs/jffs2/xattr.c 2011-05-16 21:46:57.000000000 -0400
47343 @@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
47344
47345 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
47346
47347 + pax_track_stack();
47348 +
47349 /* Phase.1 : Merge same xref */
47350 for (i=0; i < XREF_TMPHASH_SIZE; i++)
47351 xref_tmphash[i] = NULL;
47352 diff -urNp linux-2.6.32.46/fs/jfs/super.c linux-2.6.32.46/fs/jfs/super.c
47353 --- linux-2.6.32.46/fs/jfs/super.c 2011-03-27 14:31:47.000000000 -0400
47354 +++ linux-2.6.32.46/fs/jfs/super.c 2011-06-07 18:06:04.000000000 -0400
47355 @@ -793,7 +793,7 @@ static int __init init_jfs_fs(void)
47356
47357 jfs_inode_cachep =
47358 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47359 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47360 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47361 init_once);
47362 if (jfs_inode_cachep == NULL)
47363 return -ENOMEM;
47364 diff -urNp linux-2.6.32.46/fs/libfs.c linux-2.6.32.46/fs/libfs.c
47365 --- linux-2.6.32.46/fs/libfs.c 2011-03-27 14:31:47.000000000 -0400
47366 +++ linux-2.6.32.46/fs/libfs.c 2011-05-11 18:25:15.000000000 -0400
47367 @@ -157,12 +157,20 @@ int dcache_readdir(struct file * filp, v
47368
47369 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47370 struct dentry *next;
47371 + char d_name[sizeof(next->d_iname)];
47372 + const unsigned char *name;
47373 +
47374 next = list_entry(p, struct dentry, d_u.d_child);
47375 if (d_unhashed(next) || !next->d_inode)
47376 continue;
47377
47378 spin_unlock(&dcache_lock);
47379 - if (filldir(dirent, next->d_name.name,
47380 + name = next->d_name.name;
47381 + if (name == next->d_iname) {
47382 + memcpy(d_name, name, next->d_name.len);
47383 + name = d_name;
47384 + }
47385 + if (filldir(dirent, name,
47386 next->d_name.len, filp->f_pos,
47387 next->d_inode->i_ino,
47388 dt_type(next->d_inode)) < 0)
47389 diff -urNp linux-2.6.32.46/fs/lockd/clntproc.c linux-2.6.32.46/fs/lockd/clntproc.c
47390 --- linux-2.6.32.46/fs/lockd/clntproc.c 2011-03-27 14:31:47.000000000 -0400
47391 +++ linux-2.6.32.46/fs/lockd/clntproc.c 2011-05-16 21:46:57.000000000 -0400
47392 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
47393 /*
47394 * Cookie counter for NLM requests
47395 */
47396 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47397 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47398
47399 void nlmclnt_next_cookie(struct nlm_cookie *c)
47400 {
47401 - u32 cookie = atomic_inc_return(&nlm_cookie);
47402 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47403
47404 memcpy(c->data, &cookie, 4);
47405 c->len=4;
47406 @@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
47407 struct nlm_rqst reqst, *req;
47408 int status;
47409
47410 + pax_track_stack();
47411 +
47412 req = &reqst;
47413 memset(req, 0, sizeof(*req));
47414 locks_init_lock(&req->a_args.lock.fl);
47415 diff -urNp linux-2.6.32.46/fs/lockd/svc.c linux-2.6.32.46/fs/lockd/svc.c
47416 --- linux-2.6.32.46/fs/lockd/svc.c 2011-03-27 14:31:47.000000000 -0400
47417 +++ linux-2.6.32.46/fs/lockd/svc.c 2011-04-17 15:56:46.000000000 -0400
47418 @@ -43,7 +43,7 @@
47419
47420 static struct svc_program nlmsvc_program;
47421
47422 -struct nlmsvc_binding * nlmsvc_ops;
47423 +const struct nlmsvc_binding * nlmsvc_ops;
47424 EXPORT_SYMBOL_GPL(nlmsvc_ops);
47425
47426 static DEFINE_MUTEX(nlmsvc_mutex);
47427 diff -urNp linux-2.6.32.46/fs/locks.c linux-2.6.32.46/fs/locks.c
47428 --- linux-2.6.32.46/fs/locks.c 2011-03-27 14:31:47.000000000 -0400
47429 +++ linux-2.6.32.46/fs/locks.c 2011-07-06 19:47:11.000000000 -0400
47430 @@ -145,10 +145,28 @@ static LIST_HEAD(blocked_list);
47431
47432 static struct kmem_cache *filelock_cache __read_mostly;
47433
47434 +static void locks_init_lock_always(struct file_lock *fl)
47435 +{
47436 + fl->fl_next = NULL;
47437 + fl->fl_fasync = NULL;
47438 + fl->fl_owner = NULL;
47439 + fl->fl_pid = 0;
47440 + fl->fl_nspid = NULL;
47441 + fl->fl_file = NULL;
47442 + fl->fl_flags = 0;
47443 + fl->fl_type = 0;
47444 + fl->fl_start = fl->fl_end = 0;
47445 +}
47446 +
47447 /* Allocate an empty lock structure. */
47448 static struct file_lock *locks_alloc_lock(void)
47449 {
47450 - return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
47451 + struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
47452 +
47453 + if (fl)
47454 + locks_init_lock_always(fl);
47455 +
47456 + return fl;
47457 }
47458
47459 void locks_release_private(struct file_lock *fl)
47460 @@ -183,17 +201,9 @@ void locks_init_lock(struct file_lock *f
47461 INIT_LIST_HEAD(&fl->fl_link);
47462 INIT_LIST_HEAD(&fl->fl_block);
47463 init_waitqueue_head(&fl->fl_wait);
47464 - fl->fl_next = NULL;
47465 - fl->fl_fasync = NULL;
47466 - fl->fl_owner = NULL;
47467 - fl->fl_pid = 0;
47468 - fl->fl_nspid = NULL;
47469 - fl->fl_file = NULL;
47470 - fl->fl_flags = 0;
47471 - fl->fl_type = 0;
47472 - fl->fl_start = fl->fl_end = 0;
47473 fl->fl_ops = NULL;
47474 fl->fl_lmops = NULL;
47475 + locks_init_lock_always(fl);
47476 }
47477
47478 EXPORT_SYMBOL(locks_init_lock);
47479 @@ -2007,16 +2017,16 @@ void locks_remove_flock(struct file *fil
47480 return;
47481
47482 if (filp->f_op && filp->f_op->flock) {
47483 - struct file_lock fl = {
47484 + struct file_lock flock = {
47485 .fl_pid = current->tgid,
47486 .fl_file = filp,
47487 .fl_flags = FL_FLOCK,
47488 .fl_type = F_UNLCK,
47489 .fl_end = OFFSET_MAX,
47490 };
47491 - filp->f_op->flock(filp, F_SETLKW, &fl);
47492 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47493 - fl.fl_ops->fl_release_private(&fl);
47494 + filp->f_op->flock(filp, F_SETLKW, &flock);
47495 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47496 + flock.fl_ops->fl_release_private(&flock);
47497 }
47498
47499 lock_kernel();
47500 diff -urNp linux-2.6.32.46/fs/mbcache.c linux-2.6.32.46/fs/mbcache.c
47501 --- linux-2.6.32.46/fs/mbcache.c 2011-03-27 14:31:47.000000000 -0400
47502 +++ linux-2.6.32.46/fs/mbcache.c 2011-08-05 20:33:55.000000000 -0400
47503 @@ -266,9 +266,9 @@ mb_cache_create(const char *name, struct
47504 if (!cache)
47505 goto fail;
47506 cache->c_name = name;
47507 - cache->c_op.free = NULL;
47508 + *(void **)&cache->c_op.free = NULL;
47509 if (cache_op)
47510 - cache->c_op.free = cache_op->free;
47511 + *(void **)&cache->c_op.free = cache_op->free;
47512 atomic_set(&cache->c_entry_count, 0);
47513 cache->c_bucket_bits = bucket_bits;
47514 #ifdef MB_CACHE_INDEXES_COUNT
47515 diff -urNp linux-2.6.32.46/fs/namei.c linux-2.6.32.46/fs/namei.c
47516 --- linux-2.6.32.46/fs/namei.c 2011-03-27 14:31:47.000000000 -0400
47517 +++ linux-2.6.32.46/fs/namei.c 2011-10-19 12:12:56.000000000 -0400
47518 @@ -224,14 +224,6 @@ int generic_permission(struct inode *ino
47519 return ret;
47520
47521 /*
47522 - * Read/write DACs are always overridable.
47523 - * Executable DACs are overridable if at least one exec bit is set.
47524 - */
47525 - if (!(mask & MAY_EXEC) || execute_ok(inode))
47526 - if (capable(CAP_DAC_OVERRIDE))
47527 - return 0;
47528 -
47529 - /*
47530 * Searching includes executable on directories, else just read.
47531 */
47532 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47533 @@ -239,6 +231,14 @@ int generic_permission(struct inode *ino
47534 if (capable(CAP_DAC_READ_SEARCH))
47535 return 0;
47536
47537 + /*
47538 + * Read/write DACs are always overridable.
47539 + * Executable DACs are overridable if at least one exec bit is set.
47540 + */
47541 + if (!(mask & MAY_EXEC) || execute_ok(inode))
47542 + if (capable(CAP_DAC_OVERRIDE))
47543 + return 0;
47544 +
47545 return -EACCES;
47546 }
47547
47548 @@ -458,7 +458,8 @@ static int exec_permission_lite(struct i
47549 if (!ret)
47550 goto ok;
47551
47552 - if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
47553 + if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
47554 + capable(CAP_DAC_OVERRIDE))
47555 goto ok;
47556
47557 return ret;
47558 @@ -638,7 +639,7 @@ static __always_inline int __do_follow_l
47559 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
47560 error = PTR_ERR(cookie);
47561 if (!IS_ERR(cookie)) {
47562 - char *s = nd_get_link(nd);
47563 + const char *s = nd_get_link(nd);
47564 error = 0;
47565 if (s)
47566 error = __vfs_follow_link(nd, s);
47567 @@ -669,6 +670,13 @@ static inline int do_follow_link(struct
47568 err = security_inode_follow_link(path->dentry, nd);
47569 if (err)
47570 goto loop;
47571 +
47572 + if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
47573 + path->dentry->d_inode, path->dentry, nd->path.mnt)) {
47574 + err = -EACCES;
47575 + goto loop;
47576 + }
47577 +
47578 current->link_count++;
47579 current->total_link_count++;
47580 nd->depth++;
47581 @@ -1016,11 +1024,19 @@ return_reval:
47582 break;
47583 }
47584 return_base:
47585 + if (!(nd->flags & (LOOKUP_CONTINUE | LOOKUP_PARENT)) &&
47586 + !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47587 + path_put(&nd->path);
47588 + return -ENOENT;
47589 + }
47590 return 0;
47591 out_dput:
47592 path_put_conditional(&next, nd);
47593 break;
47594 }
47595 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
47596 + err = -ENOENT;
47597 +
47598 path_put(&nd->path);
47599 return_err:
47600 return err;
47601 @@ -1091,13 +1107,20 @@ static int do_path_lookup(int dfd, const
47602 int retval = path_init(dfd, name, flags, nd);
47603 if (!retval)
47604 retval = path_walk(name, nd);
47605 - if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
47606 - nd->path.dentry->d_inode))
47607 - audit_inode(name, nd->path.dentry);
47608 +
47609 + if (likely(!retval)) {
47610 + if (nd->path.dentry && nd->path.dentry->d_inode) {
47611 + if (*name != '/' && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47612 + retval = -ENOENT;
47613 + if (!audit_dummy_context())
47614 + audit_inode(name, nd->path.dentry);
47615 + }
47616 + }
47617 if (nd->root.mnt) {
47618 path_put(&nd->root);
47619 nd->root.mnt = NULL;
47620 }
47621 +
47622 return retval;
47623 }
47624
47625 @@ -1576,6 +1599,20 @@ int may_open(struct path *path, int acc_
47626 if (error)
47627 goto err_out;
47628
47629 +
47630 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
47631 + error = -EPERM;
47632 + goto err_out;
47633 + }
47634 + if (gr_handle_rawio(inode)) {
47635 + error = -EPERM;
47636 + goto err_out;
47637 + }
47638 + if (!gr_acl_handle_open(dentry, path->mnt, flag)) {
47639 + error = -EACCES;
47640 + goto err_out;
47641 + }
47642 +
47643 if (flag & O_TRUNC) {
47644 error = get_write_access(inode);
47645 if (error)
47646 @@ -1621,12 +1658,19 @@ static int __open_namei_create(struct na
47647 int error;
47648 struct dentry *dir = nd->path.dentry;
47649
47650 + if (!gr_acl_handle_creat(path->dentry, dir, nd->path.mnt, flag, mode)) {
47651 + error = -EACCES;
47652 + goto out_unlock;
47653 + }
47654 +
47655 if (!IS_POSIXACL(dir->d_inode))
47656 mode &= ~current_umask();
47657 error = security_path_mknod(&nd->path, path->dentry, mode, 0);
47658 if (error)
47659 goto out_unlock;
47660 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
47661 + if (!error)
47662 + gr_handle_create(path->dentry, nd->path.mnt);
47663 out_unlock:
47664 mutex_unlock(&dir->d_inode->i_mutex);
47665 dput(nd->path.dentry);
47666 @@ -1709,6 +1753,22 @@ struct file *do_filp_open(int dfd, const
47667 &nd, flag);
47668 if (error)
47669 return ERR_PTR(error);
47670 +
47671 + if (gr_handle_rofs_blockwrite(nd.path.dentry, nd.path.mnt, acc_mode)) {
47672 + error = -EPERM;
47673 + goto exit;
47674 + }
47675 +
47676 + if (gr_handle_rawio(nd.path.dentry->d_inode)) {
47677 + error = -EPERM;
47678 + goto exit;
47679 + }
47680 +
47681 + if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) {
47682 + error = -EACCES;
47683 + goto exit;
47684 + }
47685 +
47686 goto ok;
47687 }
47688
47689 @@ -1795,6 +1855,19 @@ do_last:
47690 /*
47691 * It already exists.
47692 */
47693 +
47694 + if (!gr_acl_handle_hidden_file(path.dentry, path.mnt)) {
47695 + error = -ENOENT;
47696 + goto exit_mutex_unlock;
47697 + }
47698 +
47699 + /* only check if O_CREAT is specified, all other checks need
47700 + to go into may_open */
47701 + if (gr_handle_fifo(path.dentry, path.mnt, dir, flag, acc_mode)) {
47702 + error = -EACCES;
47703 + goto exit_mutex_unlock;
47704 + }
47705 +
47706 mutex_unlock(&dir->d_inode->i_mutex);
47707 audit_inode(pathname, path.dentry);
47708
47709 @@ -1887,6 +1960,13 @@ do_link:
47710 error = security_inode_follow_link(path.dentry, &nd);
47711 if (error)
47712 goto exit_dput;
47713 +
47714 + if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
47715 + path.dentry, nd.path.mnt)) {
47716 + error = -EACCES;
47717 + goto exit_dput;
47718 + }
47719 +
47720 error = __do_follow_link(&path, &nd);
47721 if (error) {
47722 /* Does someone understand code flow here? Or it is only
47723 @@ -1984,6 +2064,10 @@ struct dentry *lookup_create(struct name
47724 }
47725 return dentry;
47726 eexist:
47727 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47728 + dput(dentry);
47729 + return ERR_PTR(-ENOENT);
47730 + }
47731 dput(dentry);
47732 dentry = ERR_PTR(-EEXIST);
47733 fail:
47734 @@ -2061,6 +2145,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
47735 error = may_mknod(mode);
47736 if (error)
47737 goto out_dput;
47738 +
47739 + if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
47740 + error = -EPERM;
47741 + goto out_dput;
47742 + }
47743 +
47744 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
47745 + error = -EACCES;
47746 + goto out_dput;
47747 + }
47748 +
47749 error = mnt_want_write(nd.path.mnt);
47750 if (error)
47751 goto out_dput;
47752 @@ -2081,6 +2176,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
47753 }
47754 out_drop_write:
47755 mnt_drop_write(nd.path.mnt);
47756 +
47757 + if (!error)
47758 + gr_handle_create(dentry, nd.path.mnt);
47759 out_dput:
47760 dput(dentry);
47761 out_unlock:
47762 @@ -2134,6 +2232,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
47763 if (IS_ERR(dentry))
47764 goto out_unlock;
47765
47766 + if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
47767 + error = -EACCES;
47768 + goto out_dput;
47769 + }
47770 +
47771 if (!IS_POSIXACL(nd.path.dentry->d_inode))
47772 mode &= ~current_umask();
47773 error = mnt_want_write(nd.path.mnt);
47774 @@ -2145,6 +2248,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
47775 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
47776 out_drop_write:
47777 mnt_drop_write(nd.path.mnt);
47778 +
47779 + if (!error)
47780 + gr_handle_create(dentry, nd.path.mnt);
47781 +
47782 out_dput:
47783 dput(dentry);
47784 out_unlock:
47785 @@ -2226,6 +2333,8 @@ static long do_rmdir(int dfd, const char
47786 char * name;
47787 struct dentry *dentry;
47788 struct nameidata nd;
47789 + ino_t saved_ino = 0;
47790 + dev_t saved_dev = 0;
47791
47792 error = user_path_parent(dfd, pathname, &nd, &name);
47793 if (error)
47794 @@ -2250,6 +2359,19 @@ static long do_rmdir(int dfd, const char
47795 error = PTR_ERR(dentry);
47796 if (IS_ERR(dentry))
47797 goto exit2;
47798 +
47799 + if (dentry->d_inode != NULL) {
47800 + if (dentry->d_inode->i_nlink <= 1) {
47801 + saved_ino = dentry->d_inode->i_ino;
47802 + saved_dev = gr_get_dev_from_dentry(dentry);
47803 + }
47804 +
47805 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47806 + error = -EACCES;
47807 + goto exit3;
47808 + }
47809 + }
47810 +
47811 error = mnt_want_write(nd.path.mnt);
47812 if (error)
47813 goto exit3;
47814 @@ -2257,6 +2379,8 @@ static long do_rmdir(int dfd, const char
47815 if (error)
47816 goto exit4;
47817 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47818 + if (!error && (saved_dev || saved_ino))
47819 + gr_handle_delete(saved_ino, saved_dev);
47820 exit4:
47821 mnt_drop_write(nd.path.mnt);
47822 exit3:
47823 @@ -2318,6 +2442,8 @@ static long do_unlinkat(int dfd, const c
47824 struct dentry *dentry;
47825 struct nameidata nd;
47826 struct inode *inode = NULL;
47827 + ino_t saved_ino = 0;
47828 + dev_t saved_dev = 0;
47829
47830 error = user_path_parent(dfd, pathname, &nd, &name);
47831 if (error)
47832 @@ -2337,8 +2463,19 @@ static long do_unlinkat(int dfd, const c
47833 if (nd.last.name[nd.last.len])
47834 goto slashes;
47835 inode = dentry->d_inode;
47836 - if (inode)
47837 + if (inode) {
47838 + if (inode->i_nlink <= 1) {
47839 + saved_ino = inode->i_ino;
47840 + saved_dev = gr_get_dev_from_dentry(dentry);
47841 + }
47842 +
47843 atomic_inc(&inode->i_count);
47844 +
47845 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47846 + error = -EACCES;
47847 + goto exit2;
47848 + }
47849 + }
47850 error = mnt_want_write(nd.path.mnt);
47851 if (error)
47852 goto exit2;
47853 @@ -2346,6 +2483,8 @@ static long do_unlinkat(int dfd, const c
47854 if (error)
47855 goto exit3;
47856 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47857 + if (!error && (saved_ino || saved_dev))
47858 + gr_handle_delete(saved_ino, saved_dev);
47859 exit3:
47860 mnt_drop_write(nd.path.mnt);
47861 exit2:
47862 @@ -2424,6 +2563,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
47863 if (IS_ERR(dentry))
47864 goto out_unlock;
47865
47866 + if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
47867 + error = -EACCES;
47868 + goto out_dput;
47869 + }
47870 +
47871 error = mnt_want_write(nd.path.mnt);
47872 if (error)
47873 goto out_dput;
47874 @@ -2431,6 +2575,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
47875 if (error)
47876 goto out_drop_write;
47877 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
47878 + if (!error)
47879 + gr_handle_create(dentry, nd.path.mnt);
47880 out_drop_write:
47881 mnt_drop_write(nd.path.mnt);
47882 out_dput:
47883 @@ -2524,6 +2670,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
47884 error = PTR_ERR(new_dentry);
47885 if (IS_ERR(new_dentry))
47886 goto out_unlock;
47887 +
47888 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47889 + old_path.dentry->d_inode,
47890 + old_path.dentry->d_inode->i_mode, to)) {
47891 + error = -EACCES;
47892 + goto out_dput;
47893 + }
47894 +
47895 + if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
47896 + old_path.dentry, old_path.mnt, to)) {
47897 + error = -EACCES;
47898 + goto out_dput;
47899 + }
47900 +
47901 error = mnt_want_write(nd.path.mnt);
47902 if (error)
47903 goto out_dput;
47904 @@ -2531,6 +2691,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
47905 if (error)
47906 goto out_drop_write;
47907 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
47908 + if (!error)
47909 + gr_handle_create(new_dentry, nd.path.mnt);
47910 out_drop_write:
47911 mnt_drop_write(nd.path.mnt);
47912 out_dput:
47913 @@ -2708,6 +2870,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
47914 char *to;
47915 int error;
47916
47917 + pax_track_stack();
47918 +
47919 error = user_path_parent(olddfd, oldname, &oldnd, &from);
47920 if (error)
47921 goto exit;
47922 @@ -2764,6 +2928,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
47923 if (new_dentry == trap)
47924 goto exit5;
47925
47926 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47927 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47928 + to);
47929 + if (error)
47930 + goto exit5;
47931 +
47932 error = mnt_want_write(oldnd.path.mnt);
47933 if (error)
47934 goto exit5;
47935 @@ -2773,6 +2943,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
47936 goto exit6;
47937 error = vfs_rename(old_dir->d_inode, old_dentry,
47938 new_dir->d_inode, new_dentry);
47939 + if (!error)
47940 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47941 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47942 exit6:
47943 mnt_drop_write(oldnd.path.mnt);
47944 exit5:
47945 @@ -2798,6 +2971,8 @@ SYSCALL_DEFINE2(rename, const char __use
47946
47947 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47948 {
47949 + char tmpbuf[64];
47950 + const char *newlink;
47951 int len;
47952
47953 len = PTR_ERR(link);
47954 @@ -2807,7 +2982,14 @@ int vfs_readlink(struct dentry *dentry,
47955 len = strlen(link);
47956 if (len > (unsigned) buflen)
47957 len = buflen;
47958 - if (copy_to_user(buffer, link, len))
47959 +
47960 + if (len < sizeof(tmpbuf)) {
47961 + memcpy(tmpbuf, link, len);
47962 + newlink = tmpbuf;
47963 + } else
47964 + newlink = link;
47965 +
47966 + if (copy_to_user(buffer, newlink, len))
47967 len = -EFAULT;
47968 out:
47969 return len;
47970 diff -urNp linux-2.6.32.46/fs/namespace.c linux-2.6.32.46/fs/namespace.c
47971 --- linux-2.6.32.46/fs/namespace.c 2011-03-27 14:31:47.000000000 -0400
47972 +++ linux-2.6.32.46/fs/namespace.c 2011-04-17 15:56:46.000000000 -0400
47973 @@ -1083,6 +1083,9 @@ static int do_umount(struct vfsmount *mn
47974 if (!(sb->s_flags & MS_RDONLY))
47975 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47976 up_write(&sb->s_umount);
47977 +
47978 + gr_log_remount(mnt->mnt_devname, retval);
47979 +
47980 return retval;
47981 }
47982
47983 @@ -1104,6 +1107,9 @@ static int do_umount(struct vfsmount *mn
47984 security_sb_umount_busy(mnt);
47985 up_write(&namespace_sem);
47986 release_mounts(&umount_list);
47987 +
47988 + gr_log_unmount(mnt->mnt_devname, retval);
47989 +
47990 return retval;
47991 }
47992
47993 @@ -1962,6 +1968,16 @@ long do_mount(char *dev_name, char *dir_
47994 if (retval)
47995 goto dput_out;
47996
47997 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47998 + retval = -EPERM;
47999 + goto dput_out;
48000 + }
48001 +
48002 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48003 + retval = -EPERM;
48004 + goto dput_out;
48005 + }
48006 +
48007 if (flags & MS_REMOUNT)
48008 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48009 data_page);
48010 @@ -1976,6 +1992,9 @@ long do_mount(char *dev_name, char *dir_
48011 dev_name, data_page);
48012 dput_out:
48013 path_put(&path);
48014 +
48015 + gr_log_mount(dev_name, dir_name, retval);
48016 +
48017 return retval;
48018 }
48019
48020 @@ -2182,6 +2201,12 @@ SYSCALL_DEFINE2(pivot_root, const char _
48021 goto out1;
48022 }
48023
48024 + if (gr_handle_chroot_pivot()) {
48025 + error = -EPERM;
48026 + path_put(&old);
48027 + goto out1;
48028 + }
48029 +
48030 read_lock(&current->fs->lock);
48031 root = current->fs->root;
48032 path_get(&current->fs->root);
48033 diff -urNp linux-2.6.32.46/fs/ncpfs/dir.c linux-2.6.32.46/fs/ncpfs/dir.c
48034 --- linux-2.6.32.46/fs/ncpfs/dir.c 2011-03-27 14:31:47.000000000 -0400
48035 +++ linux-2.6.32.46/fs/ncpfs/dir.c 2011-05-16 21:46:57.000000000 -0400
48036 @@ -275,6 +275,8 @@ __ncp_lookup_validate(struct dentry *den
48037 int res, val = 0, len;
48038 __u8 __name[NCP_MAXPATHLEN + 1];
48039
48040 + pax_track_stack();
48041 +
48042 parent = dget_parent(dentry);
48043 dir = parent->d_inode;
48044
48045 @@ -799,6 +801,8 @@ static struct dentry *ncp_lookup(struct
48046 int error, res, len;
48047 __u8 __name[NCP_MAXPATHLEN + 1];
48048
48049 + pax_track_stack();
48050 +
48051 lock_kernel();
48052 error = -EIO;
48053 if (!ncp_conn_valid(server))
48054 @@ -883,10 +887,12 @@ int ncp_create_new(struct inode *dir, st
48055 int error, result, len;
48056 int opmode;
48057 __u8 __name[NCP_MAXPATHLEN + 1];
48058 -
48059 +
48060 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
48061 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
48062
48063 + pax_track_stack();
48064 +
48065 error = -EIO;
48066 lock_kernel();
48067 if (!ncp_conn_valid(server))
48068 @@ -952,6 +958,8 @@ static int ncp_mkdir(struct inode *dir,
48069 int error, len;
48070 __u8 __name[NCP_MAXPATHLEN + 1];
48071
48072 + pax_track_stack();
48073 +
48074 DPRINTK("ncp_mkdir: making %s/%s\n",
48075 dentry->d_parent->d_name.name, dentry->d_name.name);
48076
48077 @@ -960,6 +968,8 @@ static int ncp_mkdir(struct inode *dir,
48078 if (!ncp_conn_valid(server))
48079 goto out;
48080
48081 + pax_track_stack();
48082 +
48083 ncp_age_dentry(server, dentry);
48084 len = sizeof(__name);
48085 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
48086 @@ -1114,6 +1124,8 @@ static int ncp_rename(struct inode *old_
48087 int old_len, new_len;
48088 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
48089
48090 + pax_track_stack();
48091 +
48092 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
48093 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
48094 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
48095 diff -urNp linux-2.6.32.46/fs/ncpfs/inode.c linux-2.6.32.46/fs/ncpfs/inode.c
48096 --- linux-2.6.32.46/fs/ncpfs/inode.c 2011-03-27 14:31:47.000000000 -0400
48097 +++ linux-2.6.32.46/fs/ncpfs/inode.c 2011-05-16 21:46:57.000000000 -0400
48098 @@ -445,6 +445,8 @@ static int ncp_fill_super(struct super_b
48099 #endif
48100 struct ncp_entry_info finfo;
48101
48102 + pax_track_stack();
48103 +
48104 data.wdog_pid = NULL;
48105 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
48106 if (!server)
48107 diff -urNp linux-2.6.32.46/fs/nfs/inode.c linux-2.6.32.46/fs/nfs/inode.c
48108 --- linux-2.6.32.46/fs/nfs/inode.c 2011-05-10 22:12:01.000000000 -0400
48109 +++ linux-2.6.32.46/fs/nfs/inode.c 2011-07-06 19:53:33.000000000 -0400
48110 @@ -156,7 +156,7 @@ static void nfs_zap_caches_locked(struct
48111 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
48112 nfsi->attrtimeo_timestamp = jiffies;
48113
48114 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
48115 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
48116 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
48117 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
48118 else
48119 @@ -973,16 +973,16 @@ static int nfs_size_need_update(const st
48120 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48121 }
48122
48123 -static atomic_long_t nfs_attr_generation_counter;
48124 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48125
48126 static unsigned long nfs_read_attr_generation_counter(void)
48127 {
48128 - return atomic_long_read(&nfs_attr_generation_counter);
48129 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48130 }
48131
48132 unsigned long nfs_inc_attr_generation_counter(void)
48133 {
48134 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48135 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48136 }
48137
48138 void nfs_fattr_init(struct nfs_fattr *fattr)
48139 diff -urNp linux-2.6.32.46/fs/nfsd/lockd.c linux-2.6.32.46/fs/nfsd/lockd.c
48140 --- linux-2.6.32.46/fs/nfsd/lockd.c 2011-04-17 17:00:52.000000000 -0400
48141 +++ linux-2.6.32.46/fs/nfsd/lockd.c 2011-04-17 17:03:15.000000000 -0400
48142 @@ -66,7 +66,7 @@ nlm_fclose(struct file *filp)
48143 fput(filp);
48144 }
48145
48146 -static struct nlmsvc_binding nfsd_nlm_ops = {
48147 +static const struct nlmsvc_binding nfsd_nlm_ops = {
48148 .fopen = nlm_fopen, /* open file for locking */
48149 .fclose = nlm_fclose, /* close file */
48150 };
48151 diff -urNp linux-2.6.32.46/fs/nfsd/nfs4state.c linux-2.6.32.46/fs/nfsd/nfs4state.c
48152 --- linux-2.6.32.46/fs/nfsd/nfs4state.c 2011-03-27 14:31:47.000000000 -0400
48153 +++ linux-2.6.32.46/fs/nfsd/nfs4state.c 2011-05-16 21:46:57.000000000 -0400
48154 @@ -3457,6 +3457,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
48155 unsigned int cmd;
48156 int err;
48157
48158 + pax_track_stack();
48159 +
48160 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
48161 (long long) lock->lk_offset,
48162 (long long) lock->lk_length);
48163 diff -urNp linux-2.6.32.46/fs/nfsd/nfs4xdr.c linux-2.6.32.46/fs/nfsd/nfs4xdr.c
48164 --- linux-2.6.32.46/fs/nfsd/nfs4xdr.c 2011-03-27 14:31:47.000000000 -0400
48165 +++ linux-2.6.32.46/fs/nfsd/nfs4xdr.c 2011-05-16 21:46:57.000000000 -0400
48166 @@ -1751,6 +1751,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
48167 struct nfsd4_compoundres *resp = rqstp->rq_resp;
48168 u32 minorversion = resp->cstate.minorversion;
48169
48170 + pax_track_stack();
48171 +
48172 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
48173 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
48174 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
48175 diff -urNp linux-2.6.32.46/fs/nfsd/vfs.c linux-2.6.32.46/fs/nfsd/vfs.c
48176 --- linux-2.6.32.46/fs/nfsd/vfs.c 2011-05-10 22:12:01.000000000 -0400
48177 +++ linux-2.6.32.46/fs/nfsd/vfs.c 2011-10-06 09:37:14.000000000 -0400
48178 @@ -937,7 +937,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
48179 } else {
48180 oldfs = get_fs();
48181 set_fs(KERNEL_DS);
48182 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48183 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48184 set_fs(oldfs);
48185 }
48186
48187 @@ -1060,7 +1060,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
48188
48189 /* Write the data. */
48190 oldfs = get_fs(); set_fs(KERNEL_DS);
48191 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48192 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48193 set_fs(oldfs);
48194 if (host_err < 0)
48195 goto out_nfserr;
48196 @@ -1542,7 +1542,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
48197 */
48198
48199 oldfs = get_fs(); set_fs(KERNEL_DS);
48200 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
48201 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
48202 set_fs(oldfs);
48203
48204 if (host_err < 0)
48205 diff -urNp linux-2.6.32.46/fs/nilfs2/ioctl.c linux-2.6.32.46/fs/nilfs2/ioctl.c
48206 --- linux-2.6.32.46/fs/nilfs2/ioctl.c 2011-03-27 14:31:47.000000000 -0400
48207 +++ linux-2.6.32.46/fs/nilfs2/ioctl.c 2011-05-04 17:56:28.000000000 -0400
48208 @@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(st
48209 unsigned int cmd, void __user *argp)
48210 {
48211 struct nilfs_argv argv[5];
48212 - const static size_t argsz[5] = {
48213 + static const size_t argsz[5] = {
48214 sizeof(struct nilfs_vdesc),
48215 sizeof(struct nilfs_period),
48216 sizeof(__u64),
48217 diff -urNp linux-2.6.32.46/fs/notify/dnotify/dnotify.c linux-2.6.32.46/fs/notify/dnotify/dnotify.c
48218 --- linux-2.6.32.46/fs/notify/dnotify/dnotify.c 2011-03-27 14:31:47.000000000 -0400
48219 +++ linux-2.6.32.46/fs/notify/dnotify/dnotify.c 2011-04-17 15:56:46.000000000 -0400
48220 @@ -173,7 +173,7 @@ static void dnotify_free_mark(struct fsn
48221 kmem_cache_free(dnotify_mark_entry_cache, dnentry);
48222 }
48223
48224 -static struct fsnotify_ops dnotify_fsnotify_ops = {
48225 +static const struct fsnotify_ops dnotify_fsnotify_ops = {
48226 .handle_event = dnotify_handle_event,
48227 .should_send_event = dnotify_should_send_event,
48228 .free_group_priv = NULL,
48229 diff -urNp linux-2.6.32.46/fs/notify/notification.c linux-2.6.32.46/fs/notify/notification.c
48230 --- linux-2.6.32.46/fs/notify/notification.c 2011-03-27 14:31:47.000000000 -0400
48231 +++ linux-2.6.32.46/fs/notify/notification.c 2011-05-04 17:56:28.000000000 -0400
48232 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
48233 * get set to 0 so it will never get 'freed'
48234 */
48235 static struct fsnotify_event q_overflow_event;
48236 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48237 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48238
48239 /**
48240 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48241 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
48242 */
48243 u32 fsnotify_get_cookie(void)
48244 {
48245 - return atomic_inc_return(&fsnotify_sync_cookie);
48246 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48247 }
48248 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48249
48250 diff -urNp linux-2.6.32.46/fs/ntfs/dir.c linux-2.6.32.46/fs/ntfs/dir.c
48251 --- linux-2.6.32.46/fs/ntfs/dir.c 2011-03-27 14:31:47.000000000 -0400
48252 +++ linux-2.6.32.46/fs/ntfs/dir.c 2011-04-17 15:56:46.000000000 -0400
48253 @@ -1328,7 +1328,7 @@ find_next_index_buffer:
48254 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48255 ~(s64)(ndir->itype.index.block_size - 1)));
48256 /* Bounds checks. */
48257 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48258 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48259 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48260 "inode 0x%lx or driver bug.", vdir->i_ino);
48261 goto err_out;
48262 diff -urNp linux-2.6.32.46/fs/ntfs/file.c linux-2.6.32.46/fs/ntfs/file.c
48263 --- linux-2.6.32.46/fs/ntfs/file.c 2011-03-27 14:31:47.000000000 -0400
48264 +++ linux-2.6.32.46/fs/ntfs/file.c 2011-04-17 15:56:46.000000000 -0400
48265 @@ -2243,6 +2243,6 @@ const struct inode_operations ntfs_file_
48266 #endif /* NTFS_RW */
48267 };
48268
48269 -const struct file_operations ntfs_empty_file_ops = {};
48270 +const struct file_operations ntfs_empty_file_ops __read_only;
48271
48272 -const struct inode_operations ntfs_empty_inode_ops = {};
48273 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48274 diff -urNp linux-2.6.32.46/fs/ocfs2/cluster/masklog.c linux-2.6.32.46/fs/ocfs2/cluster/masklog.c
48275 --- linux-2.6.32.46/fs/ocfs2/cluster/masklog.c 2011-03-27 14:31:47.000000000 -0400
48276 +++ linux-2.6.32.46/fs/ocfs2/cluster/masklog.c 2011-04-17 15:56:46.000000000 -0400
48277 @@ -135,7 +135,7 @@ static ssize_t mlog_store(struct kobject
48278 return mlog_mask_store(mlog_attr->mask, buf, count);
48279 }
48280
48281 -static struct sysfs_ops mlog_attr_ops = {
48282 +static const struct sysfs_ops mlog_attr_ops = {
48283 .show = mlog_show,
48284 .store = mlog_store,
48285 };
48286 diff -urNp linux-2.6.32.46/fs/ocfs2/localalloc.c linux-2.6.32.46/fs/ocfs2/localalloc.c
48287 --- linux-2.6.32.46/fs/ocfs2/localalloc.c 2011-03-27 14:31:47.000000000 -0400
48288 +++ linux-2.6.32.46/fs/ocfs2/localalloc.c 2011-04-17 15:56:46.000000000 -0400
48289 @@ -1188,7 +1188,7 @@ static int ocfs2_local_alloc_slide_windo
48290 goto bail;
48291 }
48292
48293 - atomic_inc(&osb->alloc_stats.moves);
48294 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48295
48296 status = 0;
48297 bail:
48298 diff -urNp linux-2.6.32.46/fs/ocfs2/namei.c linux-2.6.32.46/fs/ocfs2/namei.c
48299 --- linux-2.6.32.46/fs/ocfs2/namei.c 2011-03-27 14:31:47.000000000 -0400
48300 +++ linux-2.6.32.46/fs/ocfs2/namei.c 2011-05-16 21:46:57.000000000 -0400
48301 @@ -1043,6 +1043,8 @@ static int ocfs2_rename(struct inode *ol
48302 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
48303 struct ocfs2_dir_lookup_result target_insert = { NULL, };
48304
48305 + pax_track_stack();
48306 +
48307 /* At some point it might be nice to break this function up a
48308 * bit. */
48309
48310 diff -urNp linux-2.6.32.46/fs/ocfs2/ocfs2.h linux-2.6.32.46/fs/ocfs2/ocfs2.h
48311 --- linux-2.6.32.46/fs/ocfs2/ocfs2.h 2011-03-27 14:31:47.000000000 -0400
48312 +++ linux-2.6.32.46/fs/ocfs2/ocfs2.h 2011-04-17 15:56:46.000000000 -0400
48313 @@ -217,11 +217,11 @@ enum ocfs2_vol_state
48314
48315 struct ocfs2_alloc_stats
48316 {
48317 - atomic_t moves;
48318 - atomic_t local_data;
48319 - atomic_t bitmap_data;
48320 - atomic_t bg_allocs;
48321 - atomic_t bg_extends;
48322 + atomic_unchecked_t moves;
48323 + atomic_unchecked_t local_data;
48324 + atomic_unchecked_t bitmap_data;
48325 + atomic_unchecked_t bg_allocs;
48326 + atomic_unchecked_t bg_extends;
48327 };
48328
48329 enum ocfs2_local_alloc_state
48330 diff -urNp linux-2.6.32.46/fs/ocfs2/suballoc.c linux-2.6.32.46/fs/ocfs2/suballoc.c
48331 --- linux-2.6.32.46/fs/ocfs2/suballoc.c 2011-03-27 14:31:47.000000000 -0400
48332 +++ linux-2.6.32.46/fs/ocfs2/suballoc.c 2011-04-17 15:56:46.000000000 -0400
48333 @@ -623,7 +623,7 @@ static int ocfs2_reserve_suballoc_bits(s
48334 mlog_errno(status);
48335 goto bail;
48336 }
48337 - atomic_inc(&osb->alloc_stats.bg_extends);
48338 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48339
48340 /* You should never ask for this much metadata */
48341 BUG_ON(bits_wanted >
48342 @@ -1654,7 +1654,7 @@ int ocfs2_claim_metadata(struct ocfs2_su
48343 mlog_errno(status);
48344 goto bail;
48345 }
48346 - atomic_inc(&osb->alloc_stats.bg_allocs);
48347 + atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
48348
48349 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
48350 ac->ac_bits_given += (*num_bits);
48351 @@ -1728,7 +1728,7 @@ int ocfs2_claim_new_inode(struct ocfs2_s
48352 mlog_errno(status);
48353 goto bail;
48354 }
48355 - atomic_inc(&osb->alloc_stats.bg_allocs);
48356 + atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
48357
48358 BUG_ON(num_bits != 1);
48359
48360 @@ -1830,7 +1830,7 @@ int __ocfs2_claim_clusters(struct ocfs2_
48361 cluster_start,
48362 num_clusters);
48363 if (!status)
48364 - atomic_inc(&osb->alloc_stats.local_data);
48365 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48366 } else {
48367 if (min_clusters > (osb->bitmap_cpg - 1)) {
48368 /* The only paths asking for contiguousness
48369 @@ -1858,7 +1858,7 @@ int __ocfs2_claim_clusters(struct ocfs2_
48370 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48371 bg_blkno,
48372 bg_bit_off);
48373 - atomic_inc(&osb->alloc_stats.bitmap_data);
48374 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48375 }
48376 }
48377 if (status < 0) {
48378 diff -urNp linux-2.6.32.46/fs/ocfs2/super.c linux-2.6.32.46/fs/ocfs2/super.c
48379 --- linux-2.6.32.46/fs/ocfs2/super.c 2011-03-27 14:31:47.000000000 -0400
48380 +++ linux-2.6.32.46/fs/ocfs2/super.c 2011-04-17 15:56:46.000000000 -0400
48381 @@ -284,11 +284,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
48382 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48383 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48384 "Stats",
48385 - atomic_read(&osb->alloc_stats.bitmap_data),
48386 - atomic_read(&osb->alloc_stats.local_data),
48387 - atomic_read(&osb->alloc_stats.bg_allocs),
48388 - atomic_read(&osb->alloc_stats.moves),
48389 - atomic_read(&osb->alloc_stats.bg_extends));
48390 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48391 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48392 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48393 + atomic_read_unchecked(&osb->alloc_stats.moves),
48394 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48395
48396 out += snprintf(buf + out, len - out,
48397 "%10s => State: %u Descriptor: %llu Size: %u bits "
48398 @@ -2002,11 +2002,11 @@ static int ocfs2_initialize_super(struct
48399 spin_lock_init(&osb->osb_xattr_lock);
48400 ocfs2_init_inode_steal_slot(osb);
48401
48402 - atomic_set(&osb->alloc_stats.moves, 0);
48403 - atomic_set(&osb->alloc_stats.local_data, 0);
48404 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48405 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48406 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48407 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48408 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48409 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48410 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48411 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48412
48413 /* Copy the blockcheck stats from the superblock probe */
48414 osb->osb_ecc_stats = *stats;
48415 diff -urNp linux-2.6.32.46/fs/open.c linux-2.6.32.46/fs/open.c
48416 --- linux-2.6.32.46/fs/open.c 2011-03-27 14:31:47.000000000 -0400
48417 +++ linux-2.6.32.46/fs/open.c 2011-09-13 16:03:56.000000000 -0400
48418 @@ -275,6 +275,10 @@ static long do_sys_truncate(const char _
48419 error = locks_verify_truncate(inode, NULL, length);
48420 if (!error)
48421 error = security_path_truncate(&path, length, 0);
48422 +
48423 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48424 + error = -EACCES;
48425 +
48426 if (!error) {
48427 vfs_dq_init(inode);
48428 error = do_truncate(path.dentry, length, 0, NULL);
48429 @@ -511,6 +515,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
48430 if (__mnt_is_readonly(path.mnt))
48431 res = -EROFS;
48432
48433 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48434 + res = -EACCES;
48435 +
48436 out_path_release:
48437 path_put(&path);
48438 out:
48439 @@ -537,6 +544,8 @@ SYSCALL_DEFINE1(chdir, const char __user
48440 if (error)
48441 goto dput_and_out;
48442
48443 + gr_log_chdir(path.dentry, path.mnt);
48444 +
48445 set_fs_pwd(current->fs, &path);
48446
48447 dput_and_out:
48448 @@ -563,6 +572,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
48449 goto out_putf;
48450
48451 error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
48452 +
48453 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48454 + error = -EPERM;
48455 +
48456 + if (!error)
48457 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48458 +
48459 if (!error)
48460 set_fs_pwd(current->fs, &file->f_path);
48461 out_putf:
48462 @@ -588,7 +604,13 @@ SYSCALL_DEFINE1(chroot, const char __use
48463 if (!capable(CAP_SYS_CHROOT))
48464 goto dput_and_out;
48465
48466 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48467 + goto dput_and_out;
48468 +
48469 set_fs_root(current->fs, &path);
48470 +
48471 + gr_handle_chroot_chdir(&path);
48472 +
48473 error = 0;
48474 dput_and_out:
48475 path_put(&path);
48476 @@ -616,12 +638,27 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
48477 err = mnt_want_write_file(file);
48478 if (err)
48479 goto out_putf;
48480 +
48481 mutex_lock(&inode->i_mutex);
48482 +
48483 + if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
48484 + err = -EACCES;
48485 + goto out_unlock;
48486 + }
48487 +
48488 if (mode == (mode_t) -1)
48489 mode = inode->i_mode;
48490 +
48491 + if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
48492 + err = -EPERM;
48493 + goto out_unlock;
48494 + }
48495 +
48496 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
48497 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
48498 err = notify_change(dentry, &newattrs);
48499 +
48500 +out_unlock:
48501 mutex_unlock(&inode->i_mutex);
48502 mnt_drop_write(file->f_path.mnt);
48503 out_putf:
48504 @@ -645,12 +682,27 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
48505 error = mnt_want_write(path.mnt);
48506 if (error)
48507 goto dput_and_out;
48508 +
48509 mutex_lock(&inode->i_mutex);
48510 +
48511 + if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
48512 + error = -EACCES;
48513 + goto out_unlock;
48514 + }
48515 +
48516 if (mode == (mode_t) -1)
48517 mode = inode->i_mode;
48518 +
48519 + if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
48520 + error = -EACCES;
48521 + goto out_unlock;
48522 + }
48523 +
48524 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
48525 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
48526 error = notify_change(path.dentry, &newattrs);
48527 +
48528 +out_unlock:
48529 mutex_unlock(&inode->i_mutex);
48530 mnt_drop_write(path.mnt);
48531 dput_and_out:
48532 @@ -664,12 +716,15 @@ SYSCALL_DEFINE2(chmod, const char __user
48533 return sys_fchmodat(AT_FDCWD, filename, mode);
48534 }
48535
48536 -static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
48537 +static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
48538 {
48539 struct inode *inode = dentry->d_inode;
48540 int error;
48541 struct iattr newattrs;
48542
48543 + if (!gr_acl_handle_chown(dentry, mnt))
48544 + return -EACCES;
48545 +
48546 newattrs.ia_valid = ATTR_CTIME;
48547 if (user != (uid_t) -1) {
48548 newattrs.ia_valid |= ATTR_UID;
48549 @@ -700,7 +755,7 @@ SYSCALL_DEFINE3(chown, const char __user
48550 error = mnt_want_write(path.mnt);
48551 if (error)
48552 goto out_release;
48553 - error = chown_common(path.dentry, user, group);
48554 + error = chown_common(path.dentry, user, group, path.mnt);
48555 mnt_drop_write(path.mnt);
48556 out_release:
48557 path_put(&path);
48558 @@ -725,7 +780,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
48559 error = mnt_want_write(path.mnt);
48560 if (error)
48561 goto out_release;
48562 - error = chown_common(path.dentry, user, group);
48563 + error = chown_common(path.dentry, user, group, path.mnt);
48564 mnt_drop_write(path.mnt);
48565 out_release:
48566 path_put(&path);
48567 @@ -744,7 +799,7 @@ SYSCALL_DEFINE3(lchown, const char __use
48568 error = mnt_want_write(path.mnt);
48569 if (error)
48570 goto out_release;
48571 - error = chown_common(path.dentry, user, group);
48572 + error = chown_common(path.dentry, user, group, path.mnt);
48573 mnt_drop_write(path.mnt);
48574 out_release:
48575 path_put(&path);
48576 @@ -767,7 +822,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd
48577 goto out_fput;
48578 dentry = file->f_path.dentry;
48579 audit_inode(NULL, dentry);
48580 - error = chown_common(dentry, user, group);
48581 + error = chown_common(dentry, user, group, file->f_path.mnt);
48582 mnt_drop_write(file->f_path.mnt);
48583 out_fput:
48584 fput(file);
48585 @@ -1036,7 +1091,10 @@ long do_sys_open(int dfd, const char __u
48586 if (!IS_ERR(tmp)) {
48587 fd = get_unused_fd_flags(flags);
48588 if (fd >= 0) {
48589 - struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
48590 + struct file *f;
48591 + /* don't allow to be set by userland */
48592 + flags &= ~FMODE_GREXEC;
48593 + f = do_filp_open(dfd, tmp, flags, mode, 0);
48594 if (IS_ERR(f)) {
48595 put_unused_fd(fd);
48596 fd = PTR_ERR(f);
48597 diff -urNp linux-2.6.32.46/fs/partitions/ldm.c linux-2.6.32.46/fs/partitions/ldm.c
48598 --- linux-2.6.32.46/fs/partitions/ldm.c 2011-06-25 12:55:34.000000000 -0400
48599 +++ linux-2.6.32.46/fs/partitions/ldm.c 2011-06-25 12:56:37.000000000 -0400
48600 @@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
48601 ldm_error ("A VBLK claims to have %d parts.", num);
48602 return false;
48603 }
48604 +
48605 if (rec >= num) {
48606 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
48607 return false;
48608 @@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
48609 goto found;
48610 }
48611
48612 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
48613 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
48614 if (!f) {
48615 ldm_crit ("Out of memory.");
48616 return false;
48617 diff -urNp linux-2.6.32.46/fs/partitions/mac.c linux-2.6.32.46/fs/partitions/mac.c
48618 --- linux-2.6.32.46/fs/partitions/mac.c 2011-03-27 14:31:47.000000000 -0400
48619 +++ linux-2.6.32.46/fs/partitions/mac.c 2011-04-17 15:56:46.000000000 -0400
48620 @@ -59,11 +59,11 @@ int mac_partition(struct parsed_partitio
48621 return 0; /* not a MacOS disk */
48622 }
48623 blocks_in_map = be32_to_cpu(part->map_count);
48624 + printk(" [mac]");
48625 if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
48626 put_dev_sector(sect);
48627 return 0;
48628 }
48629 - printk(" [mac]");
48630 for (slot = 1; slot <= blocks_in_map; ++slot) {
48631 int pos = slot * secsize;
48632 put_dev_sector(sect);
48633 diff -urNp linux-2.6.32.46/fs/pipe.c linux-2.6.32.46/fs/pipe.c
48634 --- linux-2.6.32.46/fs/pipe.c 2011-03-27 14:31:47.000000000 -0400
48635 +++ linux-2.6.32.46/fs/pipe.c 2011-04-23 13:37:17.000000000 -0400
48636 @@ -401,9 +401,9 @@ redo:
48637 }
48638 if (bufs) /* More to do? */
48639 continue;
48640 - if (!pipe->writers)
48641 + if (!atomic_read(&pipe->writers))
48642 break;
48643 - if (!pipe->waiting_writers) {
48644 + if (!atomic_read(&pipe->waiting_writers)) {
48645 /* syscall merging: Usually we must not sleep
48646 * if O_NONBLOCK is set, or if we got some data.
48647 * But if a writer sleeps in kernel space, then
48648 @@ -462,7 +462,7 @@ pipe_write(struct kiocb *iocb, const str
48649 mutex_lock(&inode->i_mutex);
48650 pipe = inode->i_pipe;
48651
48652 - if (!pipe->readers) {
48653 + if (!atomic_read(&pipe->readers)) {
48654 send_sig(SIGPIPE, current, 0);
48655 ret = -EPIPE;
48656 goto out;
48657 @@ -511,7 +511,7 @@ redo1:
48658 for (;;) {
48659 int bufs;
48660
48661 - if (!pipe->readers) {
48662 + if (!atomic_read(&pipe->readers)) {
48663 send_sig(SIGPIPE, current, 0);
48664 if (!ret)
48665 ret = -EPIPE;
48666 @@ -597,9 +597,9 @@ redo2:
48667 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48668 do_wakeup = 0;
48669 }
48670 - pipe->waiting_writers++;
48671 + atomic_inc(&pipe->waiting_writers);
48672 pipe_wait(pipe);
48673 - pipe->waiting_writers--;
48674 + atomic_dec(&pipe->waiting_writers);
48675 }
48676 out:
48677 mutex_unlock(&inode->i_mutex);
48678 @@ -666,7 +666,7 @@ pipe_poll(struct file *filp, poll_table
48679 mask = 0;
48680 if (filp->f_mode & FMODE_READ) {
48681 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48682 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48683 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48684 mask |= POLLHUP;
48685 }
48686
48687 @@ -676,7 +676,7 @@ pipe_poll(struct file *filp, poll_table
48688 * Most Unices do not set POLLERR for FIFOs but on Linux they
48689 * behave exactly like pipes for poll().
48690 */
48691 - if (!pipe->readers)
48692 + if (!atomic_read(&pipe->readers))
48693 mask |= POLLERR;
48694 }
48695
48696 @@ -690,10 +690,10 @@ pipe_release(struct inode *inode, int de
48697
48698 mutex_lock(&inode->i_mutex);
48699 pipe = inode->i_pipe;
48700 - pipe->readers -= decr;
48701 - pipe->writers -= decw;
48702 + atomic_sub(decr, &pipe->readers);
48703 + atomic_sub(decw, &pipe->writers);
48704
48705 - if (!pipe->readers && !pipe->writers) {
48706 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48707 free_pipe_info(inode);
48708 } else {
48709 wake_up_interruptible_sync(&pipe->wait);
48710 @@ -783,7 +783,7 @@ pipe_read_open(struct inode *inode, stru
48711
48712 if (inode->i_pipe) {
48713 ret = 0;
48714 - inode->i_pipe->readers++;
48715 + atomic_inc(&inode->i_pipe->readers);
48716 }
48717
48718 mutex_unlock(&inode->i_mutex);
48719 @@ -800,7 +800,7 @@ pipe_write_open(struct inode *inode, str
48720
48721 if (inode->i_pipe) {
48722 ret = 0;
48723 - inode->i_pipe->writers++;
48724 + atomic_inc(&inode->i_pipe->writers);
48725 }
48726
48727 mutex_unlock(&inode->i_mutex);
48728 @@ -818,9 +818,9 @@ pipe_rdwr_open(struct inode *inode, stru
48729 if (inode->i_pipe) {
48730 ret = 0;
48731 if (filp->f_mode & FMODE_READ)
48732 - inode->i_pipe->readers++;
48733 + atomic_inc(&inode->i_pipe->readers);
48734 if (filp->f_mode & FMODE_WRITE)
48735 - inode->i_pipe->writers++;
48736 + atomic_inc(&inode->i_pipe->writers);
48737 }
48738
48739 mutex_unlock(&inode->i_mutex);
48740 @@ -905,7 +905,7 @@ void free_pipe_info(struct inode *inode)
48741 inode->i_pipe = NULL;
48742 }
48743
48744 -static struct vfsmount *pipe_mnt __read_mostly;
48745 +struct vfsmount *pipe_mnt __read_mostly;
48746 static int pipefs_delete_dentry(struct dentry *dentry)
48747 {
48748 /*
48749 @@ -945,7 +945,8 @@ static struct inode * get_pipe_inode(voi
48750 goto fail_iput;
48751 inode->i_pipe = pipe;
48752
48753 - pipe->readers = pipe->writers = 1;
48754 + atomic_set(&pipe->readers, 1);
48755 + atomic_set(&pipe->writers, 1);
48756 inode->i_fop = &rdwr_pipefifo_fops;
48757
48758 /*
48759 diff -urNp linux-2.6.32.46/fs/proc/Kconfig linux-2.6.32.46/fs/proc/Kconfig
48760 --- linux-2.6.32.46/fs/proc/Kconfig 2011-03-27 14:31:47.000000000 -0400
48761 +++ linux-2.6.32.46/fs/proc/Kconfig 2011-04-17 15:56:46.000000000 -0400
48762 @@ -30,12 +30,12 @@ config PROC_FS
48763
48764 config PROC_KCORE
48765 bool "/proc/kcore support" if !ARM
48766 - depends on PROC_FS && MMU
48767 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48768
48769 config PROC_VMCORE
48770 bool "/proc/vmcore support (EXPERIMENTAL)"
48771 - depends on PROC_FS && CRASH_DUMP
48772 - default y
48773 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48774 + default n
48775 help
48776 Exports the dump image of crashed kernel in ELF format.
48777
48778 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48779 limited in memory.
48780
48781 config PROC_PAGE_MONITOR
48782 - default y
48783 - depends on PROC_FS && MMU
48784 + default n
48785 + depends on PROC_FS && MMU && !GRKERNSEC
48786 bool "Enable /proc page monitoring" if EMBEDDED
48787 help
48788 Various /proc files exist to monitor process memory utilization:
48789 diff -urNp linux-2.6.32.46/fs/proc/array.c linux-2.6.32.46/fs/proc/array.c
48790 --- linux-2.6.32.46/fs/proc/array.c 2011-03-27 14:31:47.000000000 -0400
48791 +++ linux-2.6.32.46/fs/proc/array.c 2011-05-16 21:46:57.000000000 -0400
48792 @@ -60,6 +60,7 @@
48793 #include <linux/tty.h>
48794 #include <linux/string.h>
48795 #include <linux/mman.h>
48796 +#include <linux/grsecurity.h>
48797 #include <linux/proc_fs.h>
48798 #include <linux/ioport.h>
48799 #include <linux/uaccess.h>
48800 @@ -321,6 +322,21 @@ static inline void task_context_switch_c
48801 p->nivcsw);
48802 }
48803
48804 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48805 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48806 +{
48807 + if (p->mm)
48808 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48809 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48810 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48811 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48812 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48813 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48814 + else
48815 + seq_printf(m, "PaX:\t-----\n");
48816 +}
48817 +#endif
48818 +
48819 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48820 struct pid *pid, struct task_struct *task)
48821 {
48822 @@ -337,9 +353,24 @@ int proc_pid_status(struct seq_file *m,
48823 task_cap(m, task);
48824 cpuset_task_status_allowed(m, task);
48825 task_context_switch_counts(m, task);
48826 +
48827 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48828 + task_pax(m, task);
48829 +#endif
48830 +
48831 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48832 + task_grsec_rbac(m, task);
48833 +#endif
48834 +
48835 return 0;
48836 }
48837
48838 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48839 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48840 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48841 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48842 +#endif
48843 +
48844 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48845 struct pid *pid, struct task_struct *task, int whole)
48846 {
48847 @@ -358,9 +389,11 @@ static int do_task_stat(struct seq_file
48848 cputime_t cutime, cstime, utime, stime;
48849 cputime_t cgtime, gtime;
48850 unsigned long rsslim = 0;
48851 - char tcomm[sizeof(task->comm)];
48852 + char tcomm[sizeof(task->comm)] = { 0 };
48853 unsigned long flags;
48854
48855 + pax_track_stack();
48856 +
48857 state = *get_task_state(task);
48858 vsize = eip = esp = 0;
48859 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
48860 @@ -433,6 +466,19 @@ static int do_task_stat(struct seq_file
48861 gtime = task_gtime(task);
48862 }
48863
48864 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48865 + if (PAX_RAND_FLAGS(mm)) {
48866 + eip = 0;
48867 + esp = 0;
48868 + wchan = 0;
48869 + }
48870 +#endif
48871 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48872 + wchan = 0;
48873 + eip =0;
48874 + esp =0;
48875 +#endif
48876 +
48877 /* scale priority and nice values from timeslices to -20..20 */
48878 /* to make it look like a "normal" Unix priority/nice value */
48879 priority = task_prio(task);
48880 @@ -473,9 +519,15 @@ static int do_task_stat(struct seq_file
48881 vsize,
48882 mm ? get_mm_rss(mm) : 0,
48883 rsslim,
48884 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48885 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
48886 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
48887 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
48888 +#else
48889 mm ? (permitted ? mm->start_code : 1) : 0,
48890 mm ? (permitted ? mm->end_code : 1) : 0,
48891 (permitted && mm) ? mm->start_stack : 0,
48892 +#endif
48893 esp,
48894 eip,
48895 /* The signal information here is obsolete.
48896 @@ -528,3 +580,18 @@ int proc_pid_statm(struct seq_file *m, s
48897
48898 return 0;
48899 }
48900 +
48901 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48902 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48903 +{
48904 + u32 curr_ip = 0;
48905 + unsigned long flags;
48906 +
48907 + if (lock_task_sighand(task, &flags)) {
48908 + curr_ip = task->signal->curr_ip;
48909 + unlock_task_sighand(task, &flags);
48910 + }
48911 +
48912 + return sprintf(buffer, "%pI4\n", &curr_ip);
48913 +}
48914 +#endif
48915 diff -urNp linux-2.6.32.46/fs/proc/base.c linux-2.6.32.46/fs/proc/base.c
48916 --- linux-2.6.32.46/fs/proc/base.c 2011-08-09 18:35:30.000000000 -0400
48917 +++ linux-2.6.32.46/fs/proc/base.c 2011-10-19 04:05:03.000000000 -0400
48918 @@ -102,6 +102,22 @@ struct pid_entry {
48919 union proc_op op;
48920 };
48921
48922 +struct getdents_callback {
48923 + struct linux_dirent __user * current_dir;
48924 + struct linux_dirent __user * previous;
48925 + struct file * file;
48926 + int count;
48927 + int error;
48928 +};
48929 +
48930 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
48931 + loff_t offset, u64 ino, unsigned int d_type)
48932 +{
48933 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
48934 + buf->error = -EINVAL;
48935 + return 0;
48936 +}
48937 +
48938 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48939 .name = (NAME), \
48940 .len = sizeof(NAME) - 1, \
48941 @@ -213,6 +229,9 @@ static int check_mem_permission(struct t
48942 if (task == current)
48943 return 0;
48944
48945 + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
48946 + return -EPERM;
48947 +
48948 /*
48949 * If current is actively ptrace'ing, and would also be
48950 * permitted to freshly attach with ptrace now, permit it.
48951 @@ -260,6 +279,9 @@ static int proc_pid_cmdline(struct task_
48952 if (!mm->arg_end)
48953 goto out_mm; /* Shh! No looking before we're done */
48954
48955 + if (gr_acl_handle_procpidmem(task))
48956 + goto out_mm;
48957 +
48958 len = mm->arg_end - mm->arg_start;
48959
48960 if (len > PAGE_SIZE)
48961 @@ -287,12 +309,28 @@ out:
48962 return res;
48963 }
48964
48965 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48966 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48967 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48968 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48969 +#endif
48970 +
48971 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48972 {
48973 int res = 0;
48974 struct mm_struct *mm = get_task_mm(task);
48975 if (mm) {
48976 unsigned int nwords = 0;
48977 +
48978 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48979 + /* allow if we're currently ptracing this task */
48980 + if (PAX_RAND_FLAGS(mm) &&
48981 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48982 + mmput(mm);
48983 + return 0;
48984 + }
48985 +#endif
48986 +
48987 do {
48988 nwords += 2;
48989 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48990 @@ -306,7 +344,7 @@ static int proc_pid_auxv(struct task_str
48991 }
48992
48993
48994 -#ifdef CONFIG_KALLSYMS
48995 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48996 /*
48997 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48998 * Returns the resolved symbol. If that fails, simply return the address.
48999 @@ -328,7 +366,7 @@ static int proc_pid_wchan(struct task_st
49000 }
49001 #endif /* CONFIG_KALLSYMS */
49002
49003 -#ifdef CONFIG_STACKTRACE
49004 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49005
49006 #define MAX_STACK_TRACE_DEPTH 64
49007
49008 @@ -522,7 +560,7 @@ static int proc_pid_limits(struct task_s
49009 return count;
49010 }
49011
49012 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49013 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49014 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49015 {
49016 long nr;
49017 @@ -547,7 +585,7 @@ static int proc_pid_syscall(struct task_
49018 /************************************************************************/
49019
49020 /* permission checks */
49021 -static int proc_fd_access_allowed(struct inode *inode)
49022 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49023 {
49024 struct task_struct *task;
49025 int allowed = 0;
49026 @@ -557,7 +595,10 @@ static int proc_fd_access_allowed(struct
49027 */
49028 task = get_proc_task(inode);
49029 if (task) {
49030 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49031 + if (log)
49032 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
49033 + else
49034 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49035 put_task_struct(task);
49036 }
49037 return allowed;
49038 @@ -936,6 +977,9 @@ static ssize_t environ_read(struct file
49039 if (!task)
49040 goto out_no_task;
49041
49042 + if (gr_acl_handle_procpidmem(task))
49043 + goto out;
49044 +
49045 if (!ptrace_may_access(task, PTRACE_MODE_READ))
49046 goto out;
49047
49048 @@ -1350,7 +1394,7 @@ static void *proc_pid_follow_link(struct
49049 path_put(&nd->path);
49050
49051 /* Are we allowed to snoop on the tasks file descriptors? */
49052 - if (!proc_fd_access_allowed(inode))
49053 + if (!proc_fd_access_allowed(inode,0))
49054 goto out;
49055
49056 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
49057 @@ -1390,8 +1434,18 @@ static int proc_pid_readlink(struct dent
49058 struct path path;
49059
49060 /* Are we allowed to snoop on the tasks file descriptors? */
49061 - if (!proc_fd_access_allowed(inode))
49062 - goto out;
49063 + /* logging this is needed for learning on chromium to work properly,
49064 + but we don't want to flood the logs from 'ps' which does a readlink
49065 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49066 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49067 + */
49068 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49069 + if (!proc_fd_access_allowed(inode,0))
49070 + goto out;
49071 + } else {
49072 + if (!proc_fd_access_allowed(inode,1))
49073 + goto out;
49074 + }
49075
49076 error = PROC_I(inode)->op.proc_get_link(inode, &path);
49077 if (error)
49078 @@ -1456,7 +1510,11 @@ static struct inode *proc_pid_make_inode
49079 rcu_read_lock();
49080 cred = __task_cred(task);
49081 inode->i_uid = cred->euid;
49082 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49083 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49084 +#else
49085 inode->i_gid = cred->egid;
49086 +#endif
49087 rcu_read_unlock();
49088 }
49089 security_task_to_inode(task, inode);
49090 @@ -1474,6 +1532,9 @@ static int pid_getattr(struct vfsmount *
49091 struct inode *inode = dentry->d_inode;
49092 struct task_struct *task;
49093 const struct cred *cred;
49094 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49095 + const struct cred *tmpcred = current_cred();
49096 +#endif
49097
49098 generic_fillattr(inode, stat);
49099
49100 @@ -1481,13 +1542,41 @@ static int pid_getattr(struct vfsmount *
49101 stat->uid = 0;
49102 stat->gid = 0;
49103 task = pid_task(proc_pid(inode), PIDTYPE_PID);
49104 +
49105 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
49106 + rcu_read_unlock();
49107 + return -ENOENT;
49108 + }
49109 +
49110 if (task) {
49111 + cred = __task_cred(task);
49112 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49113 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49114 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49115 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49116 +#endif
49117 + ) {
49118 +#endif
49119 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49120 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49121 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49122 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49123 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49124 +#endif
49125 task_dumpable(task)) {
49126 - cred = __task_cred(task);
49127 stat->uid = cred->euid;
49128 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49129 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
49130 +#else
49131 stat->gid = cred->egid;
49132 +#endif
49133 }
49134 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49135 + } else {
49136 + rcu_read_unlock();
49137 + return -ENOENT;
49138 + }
49139 +#endif
49140 }
49141 rcu_read_unlock();
49142 return 0;
49143 @@ -1518,11 +1607,20 @@ static int pid_revalidate(struct dentry
49144
49145 if (task) {
49146 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49147 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49148 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49149 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49150 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49151 +#endif
49152 task_dumpable(task)) {
49153 rcu_read_lock();
49154 cred = __task_cred(task);
49155 inode->i_uid = cred->euid;
49156 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49157 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49158 +#else
49159 inode->i_gid = cred->egid;
49160 +#endif
49161 rcu_read_unlock();
49162 } else {
49163 inode->i_uid = 0;
49164 @@ -1643,7 +1741,8 @@ static int proc_fd_info(struct inode *in
49165 int fd = proc_fd(inode);
49166
49167 if (task) {
49168 - files = get_files_struct(task);
49169 + if (!gr_acl_handle_procpidmem(task))
49170 + files = get_files_struct(task);
49171 put_task_struct(task);
49172 }
49173 if (files) {
49174 @@ -1895,12 +1994,22 @@ static const struct file_operations proc
49175 static int proc_fd_permission(struct inode *inode, int mask)
49176 {
49177 int rv;
49178 + struct task_struct *task;
49179
49180 rv = generic_permission(inode, mask, NULL);
49181 - if (rv == 0)
49182 - return 0;
49183 +
49184 if (task_pid(current) == proc_pid(inode))
49185 rv = 0;
49186 +
49187 + task = get_proc_task(inode);
49188 + if (task == NULL)
49189 + return rv;
49190 +
49191 + if (gr_acl_handle_procpidmem(task))
49192 + rv = -EACCES;
49193 +
49194 + put_task_struct(task);
49195 +
49196 return rv;
49197 }
49198
49199 @@ -2009,6 +2118,9 @@ static struct dentry *proc_pident_lookup
49200 if (!task)
49201 goto out_no_task;
49202
49203 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49204 + goto out;
49205 +
49206 /*
49207 * Yes, it does not scale. And it should not. Don't add
49208 * new entries into /proc/<tgid>/ without very good reasons.
49209 @@ -2053,6 +2165,9 @@ static int proc_pident_readdir(struct fi
49210 if (!task)
49211 goto out_no_task;
49212
49213 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49214 + goto out;
49215 +
49216 ret = 0;
49217 i = filp->f_pos;
49218 switch (i) {
49219 @@ -2320,7 +2435,7 @@ static void *proc_self_follow_link(struc
49220 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49221 void *cookie)
49222 {
49223 - char *s = nd_get_link(nd);
49224 + const char *s = nd_get_link(nd);
49225 if (!IS_ERR(s))
49226 __putname(s);
49227 }
49228 @@ -2522,7 +2637,7 @@ static const struct pid_entry tgid_base_
49229 #ifdef CONFIG_SCHED_DEBUG
49230 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49231 #endif
49232 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49233 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49234 INF("syscall", S_IRUSR, proc_pid_syscall),
49235 #endif
49236 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49237 @@ -2547,10 +2662,10 @@ static const struct pid_entry tgid_base_
49238 #ifdef CONFIG_SECURITY
49239 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49240 #endif
49241 -#ifdef CONFIG_KALLSYMS
49242 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49243 INF("wchan", S_IRUGO, proc_pid_wchan),
49244 #endif
49245 -#ifdef CONFIG_STACKTRACE
49246 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49247 ONE("stack", S_IRUSR, proc_pid_stack),
49248 #endif
49249 #ifdef CONFIG_SCHEDSTATS
49250 @@ -2580,6 +2695,9 @@ static const struct pid_entry tgid_base_
49251 #ifdef CONFIG_TASK_IO_ACCOUNTING
49252 INF("io", S_IRUSR, proc_tgid_io_accounting),
49253 #endif
49254 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49255 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49256 +#endif
49257 };
49258
49259 static int proc_tgid_base_readdir(struct file * filp,
49260 @@ -2704,7 +2822,14 @@ static struct dentry *proc_pid_instantia
49261 if (!inode)
49262 goto out;
49263
49264 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49265 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49266 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49267 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49268 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49269 +#else
49270 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49271 +#endif
49272 inode->i_op = &proc_tgid_base_inode_operations;
49273 inode->i_fop = &proc_tgid_base_operations;
49274 inode->i_flags|=S_IMMUTABLE;
49275 @@ -2746,7 +2871,14 @@ struct dentry *proc_pid_lookup(struct in
49276 if (!task)
49277 goto out;
49278
49279 + if (!has_group_leader_pid(task))
49280 + goto out_put_task;
49281 +
49282 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49283 + goto out_put_task;
49284 +
49285 result = proc_pid_instantiate(dir, dentry, task, NULL);
49286 +out_put_task:
49287 put_task_struct(task);
49288 out:
49289 return result;
49290 @@ -2811,6 +2943,11 @@ int proc_pid_readdir(struct file * filp,
49291 {
49292 unsigned int nr;
49293 struct task_struct *reaper;
49294 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49295 + const struct cred *tmpcred = current_cred();
49296 + const struct cred *itercred;
49297 +#endif
49298 + filldir_t __filldir = filldir;
49299 struct tgid_iter iter;
49300 struct pid_namespace *ns;
49301
49302 @@ -2834,8 +2971,27 @@ int proc_pid_readdir(struct file * filp,
49303 for (iter = next_tgid(ns, iter);
49304 iter.task;
49305 iter.tgid += 1, iter = next_tgid(ns, iter)) {
49306 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49307 + rcu_read_lock();
49308 + itercred = __task_cred(iter.task);
49309 +#endif
49310 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
49311 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49312 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
49313 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49314 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49315 +#endif
49316 + )
49317 +#endif
49318 + )
49319 + __filldir = &gr_fake_filldir;
49320 + else
49321 + __filldir = filldir;
49322 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49323 + rcu_read_unlock();
49324 +#endif
49325 filp->f_pos = iter.tgid + TGID_OFFSET;
49326 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
49327 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
49328 put_task_struct(iter.task);
49329 goto out;
49330 }
49331 @@ -2861,7 +3017,7 @@ static const struct pid_entry tid_base_s
49332 #ifdef CONFIG_SCHED_DEBUG
49333 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49334 #endif
49335 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49336 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49337 INF("syscall", S_IRUSR, proc_pid_syscall),
49338 #endif
49339 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49340 @@ -2885,10 +3041,10 @@ static const struct pid_entry tid_base_s
49341 #ifdef CONFIG_SECURITY
49342 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49343 #endif
49344 -#ifdef CONFIG_KALLSYMS
49345 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49346 INF("wchan", S_IRUGO, proc_pid_wchan),
49347 #endif
49348 -#ifdef CONFIG_STACKTRACE
49349 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49350 ONE("stack", S_IRUSR, proc_pid_stack),
49351 #endif
49352 #ifdef CONFIG_SCHEDSTATS
49353 diff -urNp linux-2.6.32.46/fs/proc/cmdline.c linux-2.6.32.46/fs/proc/cmdline.c
49354 --- linux-2.6.32.46/fs/proc/cmdline.c 2011-03-27 14:31:47.000000000 -0400
49355 +++ linux-2.6.32.46/fs/proc/cmdline.c 2011-04-17 15:56:46.000000000 -0400
49356 @@ -23,7 +23,11 @@ static const struct file_operations cmdl
49357
49358 static int __init proc_cmdline_init(void)
49359 {
49360 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49361 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49362 +#else
49363 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49364 +#endif
49365 return 0;
49366 }
49367 module_init(proc_cmdline_init);
49368 diff -urNp linux-2.6.32.46/fs/proc/devices.c linux-2.6.32.46/fs/proc/devices.c
49369 --- linux-2.6.32.46/fs/proc/devices.c 2011-03-27 14:31:47.000000000 -0400
49370 +++ linux-2.6.32.46/fs/proc/devices.c 2011-04-17 15:56:46.000000000 -0400
49371 @@ -64,7 +64,11 @@ static const struct file_operations proc
49372
49373 static int __init proc_devices_init(void)
49374 {
49375 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49376 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49377 +#else
49378 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49379 +#endif
49380 return 0;
49381 }
49382 module_init(proc_devices_init);
49383 diff -urNp linux-2.6.32.46/fs/proc/inode.c linux-2.6.32.46/fs/proc/inode.c
49384 --- linux-2.6.32.46/fs/proc/inode.c 2011-03-27 14:31:47.000000000 -0400
49385 +++ linux-2.6.32.46/fs/proc/inode.c 2011-10-19 04:08:02.000000000 -0400
49386 @@ -18,12 +18,19 @@
49387 #include <linux/module.h>
49388 #include <linux/smp_lock.h>
49389 #include <linux/sysctl.h>
49390 +#include <linux/grsecurity.h>
49391
49392 #include <asm/system.h>
49393 #include <asm/uaccess.h>
49394
49395 #include "internal.h"
49396
49397 +#ifdef CONFIG_PROC_SYSCTL
49398 +extern const struct inode_operations proc_sys_inode_operations;
49399 +extern const struct inode_operations proc_sys_dir_operations;
49400 +#endif
49401 +
49402 +
49403 struct proc_dir_entry *de_get(struct proc_dir_entry *de)
49404 {
49405 atomic_inc(&de->count);
49406 @@ -62,6 +69,13 @@ static void proc_delete_inode(struct ino
49407 de_put(de);
49408 if (PROC_I(inode)->sysctl)
49409 sysctl_head_put(PROC_I(inode)->sysctl);
49410 +
49411 +#ifdef CONFIG_PROC_SYSCTL
49412 + if (inode->i_op == &proc_sys_inode_operations ||
49413 + inode->i_op == &proc_sys_dir_operations)
49414 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49415 +#endif
49416 +
49417 clear_inode(inode);
49418 }
49419
49420 @@ -457,7 +471,11 @@ struct inode *proc_get_inode(struct supe
49421 if (de->mode) {
49422 inode->i_mode = de->mode;
49423 inode->i_uid = de->uid;
49424 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49425 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49426 +#else
49427 inode->i_gid = de->gid;
49428 +#endif
49429 }
49430 if (de->size)
49431 inode->i_size = de->size;
49432 diff -urNp linux-2.6.32.46/fs/proc/internal.h linux-2.6.32.46/fs/proc/internal.h
49433 --- linux-2.6.32.46/fs/proc/internal.h 2011-03-27 14:31:47.000000000 -0400
49434 +++ linux-2.6.32.46/fs/proc/internal.h 2011-04-17 15:56:46.000000000 -0400
49435 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
49436 struct pid *pid, struct task_struct *task);
49437 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49438 struct pid *pid, struct task_struct *task);
49439 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49440 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49441 +#endif
49442 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49443
49444 extern const struct file_operations proc_maps_operations;
49445 diff -urNp linux-2.6.32.46/fs/proc/kcore.c linux-2.6.32.46/fs/proc/kcore.c
49446 --- linux-2.6.32.46/fs/proc/kcore.c 2011-03-27 14:31:47.000000000 -0400
49447 +++ linux-2.6.32.46/fs/proc/kcore.c 2011-05-16 21:46:57.000000000 -0400
49448 @@ -320,6 +320,8 @@ static void elf_kcore_store_hdr(char *bu
49449 off_t offset = 0;
49450 struct kcore_list *m;
49451
49452 + pax_track_stack();
49453 +
49454 /* setup ELF header */
49455 elf = (struct elfhdr *) bufp;
49456 bufp += sizeof(struct elfhdr);
49457 @@ -477,9 +479,10 @@ read_kcore(struct file *file, char __use
49458 * the addresses in the elf_phdr on our list.
49459 */
49460 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49461 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49462 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49463 + if (tsz > buflen)
49464 tsz = buflen;
49465 -
49466 +
49467 while (buflen) {
49468 struct kcore_list *m;
49469
49470 @@ -508,20 +511,23 @@ read_kcore(struct file *file, char __use
49471 kfree(elf_buf);
49472 } else {
49473 if (kern_addr_valid(start)) {
49474 - unsigned long n;
49475 + char *elf_buf;
49476 + mm_segment_t oldfs;
49477
49478 - n = copy_to_user(buffer, (char *)start, tsz);
49479 - /*
49480 - * We cannot distingush between fault on source
49481 - * and fault on destination. When this happens
49482 - * we clear too and hope it will trigger the
49483 - * EFAULT again.
49484 - */
49485 - if (n) {
49486 - if (clear_user(buffer + tsz - n,
49487 - n))
49488 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49489 + if (!elf_buf)
49490 + return -ENOMEM;
49491 + oldfs = get_fs();
49492 + set_fs(KERNEL_DS);
49493 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49494 + set_fs(oldfs);
49495 + if (copy_to_user(buffer, elf_buf, tsz)) {
49496 + kfree(elf_buf);
49497 return -EFAULT;
49498 + }
49499 }
49500 + set_fs(oldfs);
49501 + kfree(elf_buf);
49502 } else {
49503 if (clear_user(buffer, tsz))
49504 return -EFAULT;
49505 @@ -541,6 +547,9 @@ read_kcore(struct file *file, char __use
49506
49507 static int open_kcore(struct inode *inode, struct file *filp)
49508 {
49509 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49510 + return -EPERM;
49511 +#endif
49512 if (!capable(CAP_SYS_RAWIO))
49513 return -EPERM;
49514 if (kcore_need_update)
49515 diff -urNp linux-2.6.32.46/fs/proc/meminfo.c linux-2.6.32.46/fs/proc/meminfo.c
49516 --- linux-2.6.32.46/fs/proc/meminfo.c 2011-03-27 14:31:47.000000000 -0400
49517 +++ linux-2.6.32.46/fs/proc/meminfo.c 2011-05-16 21:46:57.000000000 -0400
49518 @@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
49519 unsigned long pages[NR_LRU_LISTS];
49520 int lru;
49521
49522 + pax_track_stack();
49523 +
49524 /*
49525 * display in kilobytes.
49526 */
49527 @@ -149,7 +151,7 @@ static int meminfo_proc_show(struct seq_
49528 vmi.used >> 10,
49529 vmi.largest_chunk >> 10
49530 #ifdef CONFIG_MEMORY_FAILURE
49531 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49532 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49533 #endif
49534 );
49535
49536 diff -urNp linux-2.6.32.46/fs/proc/nommu.c linux-2.6.32.46/fs/proc/nommu.c
49537 --- linux-2.6.32.46/fs/proc/nommu.c 2011-03-27 14:31:47.000000000 -0400
49538 +++ linux-2.6.32.46/fs/proc/nommu.c 2011-04-17 15:56:46.000000000 -0400
49539 @@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_
49540 if (len < 1)
49541 len = 1;
49542 seq_printf(m, "%*c", len, ' ');
49543 - seq_path(m, &file->f_path, "");
49544 + seq_path(m, &file->f_path, "\n\\");
49545 }
49546
49547 seq_putc(m, '\n');
49548 diff -urNp linux-2.6.32.46/fs/proc/proc_net.c linux-2.6.32.46/fs/proc/proc_net.c
49549 --- linux-2.6.32.46/fs/proc/proc_net.c 2011-03-27 14:31:47.000000000 -0400
49550 +++ linux-2.6.32.46/fs/proc/proc_net.c 2011-04-17 15:56:46.000000000 -0400
49551 @@ -104,6 +104,17 @@ static struct net *get_proc_task_net(str
49552 struct task_struct *task;
49553 struct nsproxy *ns;
49554 struct net *net = NULL;
49555 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49556 + const struct cred *cred = current_cred();
49557 +#endif
49558 +
49559 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49560 + if (cred->fsuid)
49561 + return net;
49562 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49563 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
49564 + return net;
49565 +#endif
49566
49567 rcu_read_lock();
49568 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49569 diff -urNp linux-2.6.32.46/fs/proc/proc_sysctl.c linux-2.6.32.46/fs/proc/proc_sysctl.c
49570 --- linux-2.6.32.46/fs/proc/proc_sysctl.c 2011-03-27 14:31:47.000000000 -0400
49571 +++ linux-2.6.32.46/fs/proc/proc_sysctl.c 2011-10-19 04:08:51.000000000 -0400
49572 @@ -7,11 +7,13 @@
49573 #include <linux/security.h>
49574 #include "internal.h"
49575
49576 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
49577 +
49578 static const struct dentry_operations proc_sys_dentry_operations;
49579 static const struct file_operations proc_sys_file_operations;
49580 -static const struct inode_operations proc_sys_inode_operations;
49581 +const struct inode_operations proc_sys_inode_operations;
49582 static const struct file_operations proc_sys_dir_file_operations;
49583 -static const struct inode_operations proc_sys_dir_operations;
49584 +const struct inode_operations proc_sys_dir_operations;
49585
49586 static struct inode *proc_sys_make_inode(struct super_block *sb,
49587 struct ctl_table_header *head, struct ctl_table *table)
49588 @@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(st
49589 if (!p)
49590 goto out;
49591
49592 + if (gr_handle_sysctl(p, MAY_EXEC))
49593 + goto out;
49594 +
49595 err = ERR_PTR(-ENOMEM);
49596 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
49597 if (h)
49598 @@ -119,6 +124,9 @@ static struct dentry *proc_sys_lookup(st
49599
49600 err = NULL;
49601 dentry->d_op = &proc_sys_dentry_operations;
49602 +
49603 + gr_handle_proc_create(dentry, inode);
49604 +
49605 d_add(dentry, inode);
49606
49607 out:
49608 @@ -200,6 +208,9 @@ static int proc_sys_fill_cache(struct fi
49609 return -ENOMEM;
49610 } else {
49611 child->d_op = &proc_sys_dentry_operations;
49612 +
49613 + gr_handle_proc_create(child, inode);
49614 +
49615 d_add(child, inode);
49616 }
49617 } else {
49618 @@ -228,6 +239,9 @@ static int scan(struct ctl_table_header
49619 if (*pos < file->f_pos)
49620 continue;
49621
49622 + if (gr_handle_sysctl(table, 0))
49623 + continue;
49624 +
49625 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
49626 if (res)
49627 return res;
49628 @@ -344,6 +358,9 @@ static int proc_sys_getattr(struct vfsmo
49629 if (IS_ERR(head))
49630 return PTR_ERR(head);
49631
49632 + if (table && gr_handle_sysctl(table, MAY_EXEC))
49633 + return -ENOENT;
49634 +
49635 generic_fillattr(inode, stat);
49636 if (table)
49637 stat->mode = (stat->mode & S_IFMT) | table->mode;
49638 @@ -362,13 +379,13 @@ static const struct file_operations proc
49639 .llseek = generic_file_llseek,
49640 };
49641
49642 -static const struct inode_operations proc_sys_inode_operations = {
49643 +const struct inode_operations proc_sys_inode_operations = {
49644 .permission = proc_sys_permission,
49645 .setattr = proc_sys_setattr,
49646 .getattr = proc_sys_getattr,
49647 };
49648
49649 -static const struct inode_operations proc_sys_dir_operations = {
49650 +const struct inode_operations proc_sys_dir_operations = {
49651 .lookup = proc_sys_lookup,
49652 .permission = proc_sys_permission,
49653 .setattr = proc_sys_setattr,
49654 diff -urNp linux-2.6.32.46/fs/proc/root.c linux-2.6.32.46/fs/proc/root.c
49655 --- linux-2.6.32.46/fs/proc/root.c 2011-03-27 14:31:47.000000000 -0400
49656 +++ linux-2.6.32.46/fs/proc/root.c 2011-04-17 15:56:46.000000000 -0400
49657 @@ -134,7 +134,15 @@ void __init proc_root_init(void)
49658 #ifdef CONFIG_PROC_DEVICETREE
49659 proc_device_tree_init();
49660 #endif
49661 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49662 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49663 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49664 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49665 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49666 +#endif
49667 +#else
49668 proc_mkdir("bus", NULL);
49669 +#endif
49670 proc_sys_init();
49671 }
49672
49673 diff -urNp linux-2.6.32.46/fs/proc/task_mmu.c linux-2.6.32.46/fs/proc/task_mmu.c
49674 --- linux-2.6.32.46/fs/proc/task_mmu.c 2011-03-27 14:31:47.000000000 -0400
49675 +++ linux-2.6.32.46/fs/proc/task_mmu.c 2011-04-23 13:38:09.000000000 -0400
49676 @@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct
49677 "VmStk:\t%8lu kB\n"
49678 "VmExe:\t%8lu kB\n"
49679 "VmLib:\t%8lu kB\n"
49680 - "VmPTE:\t%8lu kB\n",
49681 - hiwater_vm << (PAGE_SHIFT-10),
49682 + "VmPTE:\t%8lu kB\n"
49683 +
49684 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49685 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49686 +#endif
49687 +
49688 + ,hiwater_vm << (PAGE_SHIFT-10),
49689 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49690 mm->locked_vm << (PAGE_SHIFT-10),
49691 hiwater_rss << (PAGE_SHIFT-10),
49692 total_rss << (PAGE_SHIFT-10),
49693 data << (PAGE_SHIFT-10),
49694 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49695 - (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
49696 + (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
49697 +
49698 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49699 + , mm->context.user_cs_base, mm->context.user_cs_limit
49700 +#endif
49701 +
49702 + );
49703 }
49704
49705 unsigned long task_vsize(struct mm_struct *mm)
49706 @@ -175,7 +186,8 @@ static void m_stop(struct seq_file *m, v
49707 struct proc_maps_private *priv = m->private;
49708 struct vm_area_struct *vma = v;
49709
49710 - vma_stop(priv, vma);
49711 + if (!IS_ERR(vma))
49712 + vma_stop(priv, vma);
49713 if (priv->task)
49714 put_task_struct(priv->task);
49715 }
49716 @@ -199,6 +211,12 @@ static int do_maps_open(struct inode *in
49717 return ret;
49718 }
49719
49720 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49721 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49722 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49723 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49724 +#endif
49725 +
49726 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49727 {
49728 struct mm_struct *mm = vma->vm_mm;
49729 @@ -206,7 +224,6 @@ static void show_map_vma(struct seq_file
49730 int flags = vma->vm_flags;
49731 unsigned long ino = 0;
49732 unsigned long long pgoff = 0;
49733 - unsigned long start;
49734 dev_t dev = 0;
49735 int len;
49736
49737 @@ -217,20 +234,23 @@ static void show_map_vma(struct seq_file
49738 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49739 }
49740
49741 - /* We don't show the stack guard page in /proc/maps */
49742 - start = vma->vm_start;
49743 - if (vma->vm_flags & VM_GROWSDOWN)
49744 - if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
49745 - start += PAGE_SIZE;
49746 -
49747 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49748 - start,
49749 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49750 + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
49751 + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
49752 +#else
49753 + vma->vm_start,
49754 vma->vm_end,
49755 +#endif
49756 flags & VM_READ ? 'r' : '-',
49757 flags & VM_WRITE ? 'w' : '-',
49758 flags & VM_EXEC ? 'x' : '-',
49759 flags & VM_MAYSHARE ? 's' : 'p',
49760 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49761 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49762 +#else
49763 pgoff,
49764 +#endif
49765 MAJOR(dev), MINOR(dev), ino, &len);
49766
49767 /*
49768 @@ -239,7 +259,7 @@ static void show_map_vma(struct seq_file
49769 */
49770 if (file) {
49771 pad_len_spaces(m, len);
49772 - seq_path(m, &file->f_path, "\n");
49773 + seq_path(m, &file->f_path, "\n\\");
49774 } else {
49775 const char *name = arch_vma_name(vma);
49776 if (!name) {
49777 @@ -247,8 +267,9 @@ static void show_map_vma(struct seq_file
49778 if (vma->vm_start <= mm->brk &&
49779 vma->vm_end >= mm->start_brk) {
49780 name = "[heap]";
49781 - } else if (vma->vm_start <= mm->start_stack &&
49782 - vma->vm_end >= mm->start_stack) {
49783 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49784 + (vma->vm_start <= mm->start_stack &&
49785 + vma->vm_end >= mm->start_stack)) {
49786 name = "[stack]";
49787 }
49788 } else {
49789 @@ -391,9 +412,16 @@ static int show_smap(struct seq_file *m,
49790 };
49791
49792 memset(&mss, 0, sizeof mss);
49793 - mss.vma = vma;
49794 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49795 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49796 +
49797 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49798 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49799 +#endif
49800 + mss.vma = vma;
49801 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49802 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49803 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49804 + }
49805 +#endif
49806
49807 show_map_vma(m, vma);
49808
49809 @@ -409,7 +437,11 @@ static int show_smap(struct seq_file *m,
49810 "Swap: %8lu kB\n"
49811 "KernelPageSize: %8lu kB\n"
49812 "MMUPageSize: %8lu kB\n",
49813 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49814 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49815 +#else
49816 (vma->vm_end - vma->vm_start) >> 10,
49817 +#endif
49818 mss.resident >> 10,
49819 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49820 mss.shared_clean >> 10,
49821 diff -urNp linux-2.6.32.46/fs/proc/task_nommu.c linux-2.6.32.46/fs/proc/task_nommu.c
49822 --- linux-2.6.32.46/fs/proc/task_nommu.c 2011-03-27 14:31:47.000000000 -0400
49823 +++ linux-2.6.32.46/fs/proc/task_nommu.c 2011-04-17 15:56:46.000000000 -0400
49824 @@ -50,7 +50,7 @@ void task_mem(struct seq_file *m, struct
49825 else
49826 bytes += kobjsize(mm);
49827
49828 - if (current->fs && current->fs->users > 1)
49829 + if (current->fs && atomic_read(&current->fs->users) > 1)
49830 sbytes += kobjsize(current->fs);
49831 else
49832 bytes += kobjsize(current->fs);
49833 @@ -154,7 +154,7 @@ static int nommu_vma_show(struct seq_fil
49834 if (len < 1)
49835 len = 1;
49836 seq_printf(m, "%*c", len, ' ');
49837 - seq_path(m, &file->f_path, "");
49838 + seq_path(m, &file->f_path, "\n\\");
49839 }
49840
49841 seq_putc(m, '\n');
49842 diff -urNp linux-2.6.32.46/fs/readdir.c linux-2.6.32.46/fs/readdir.c
49843 --- linux-2.6.32.46/fs/readdir.c 2011-03-27 14:31:47.000000000 -0400
49844 +++ linux-2.6.32.46/fs/readdir.c 2011-10-06 09:37:14.000000000 -0400
49845 @@ -16,6 +16,7 @@
49846 #include <linux/security.h>
49847 #include <linux/syscalls.h>
49848 #include <linux/unistd.h>
49849 +#include <linux/namei.h>
49850
49851 #include <asm/uaccess.h>
49852
49853 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49854
49855 struct readdir_callback {
49856 struct old_linux_dirent __user * dirent;
49857 + struct file * file;
49858 int result;
49859 };
49860
49861 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
49862 buf->result = -EOVERFLOW;
49863 return -EOVERFLOW;
49864 }
49865 +
49866 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49867 + return 0;
49868 +
49869 buf->result++;
49870 dirent = buf->dirent;
49871 if (!access_ok(VERIFY_WRITE, dirent,
49872 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
49873
49874 buf.result = 0;
49875 buf.dirent = dirent;
49876 + buf.file = file;
49877
49878 error = vfs_readdir(file, fillonedir, &buf);
49879 if (buf.result)
49880 @@ -142,6 +149,7 @@ struct linux_dirent {
49881 struct getdents_callback {
49882 struct linux_dirent __user * current_dir;
49883 struct linux_dirent __user * previous;
49884 + struct file * file;
49885 int count;
49886 int error;
49887 };
49888 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const c
49889 buf->error = -EOVERFLOW;
49890 return -EOVERFLOW;
49891 }
49892 +
49893 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49894 + return 0;
49895 +
49896 dirent = buf->previous;
49897 if (dirent) {
49898 if (__put_user(offset, &dirent->d_off))
49899 @@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
49900 buf.previous = NULL;
49901 buf.count = count;
49902 buf.error = 0;
49903 + buf.file = file;
49904
49905 error = vfs_readdir(file, filldir, &buf);
49906 if (error >= 0)
49907 @@ -228,6 +241,7 @@ out:
49908 struct getdents_callback64 {
49909 struct linux_dirent64 __user * current_dir;
49910 struct linux_dirent64 __user * previous;
49911 + struct file *file;
49912 int count;
49913 int error;
49914 };
49915 @@ -242,6 +256,10 @@ static int filldir64(void * __buf, const
49916 buf->error = -EINVAL; /* only used if we fail.. */
49917 if (reclen > buf->count)
49918 return -EINVAL;
49919 +
49920 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49921 + return 0;
49922 +
49923 dirent = buf->previous;
49924 if (dirent) {
49925 if (__put_user(offset, &dirent->d_off))
49926 @@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
49927
49928 buf.current_dir = dirent;
49929 buf.previous = NULL;
49930 + buf.file = file;
49931 buf.count = count;
49932 buf.error = 0;
49933
49934 @@ -297,7 +316,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
49935 error = buf.error;
49936 lastdirent = buf.previous;
49937 if (lastdirent) {
49938 - typeof(lastdirent->d_off) d_off = file->f_pos;
49939 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49940 if (__put_user(d_off, &lastdirent->d_off))
49941 error = -EFAULT;
49942 else
49943 diff -urNp linux-2.6.32.46/fs/reiserfs/dir.c linux-2.6.32.46/fs/reiserfs/dir.c
49944 --- linux-2.6.32.46/fs/reiserfs/dir.c 2011-03-27 14:31:47.000000000 -0400
49945 +++ linux-2.6.32.46/fs/reiserfs/dir.c 2011-05-16 21:46:57.000000000 -0400
49946 @@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
49947 struct reiserfs_dir_entry de;
49948 int ret = 0;
49949
49950 + pax_track_stack();
49951 +
49952 reiserfs_write_lock(inode->i_sb);
49953
49954 reiserfs_check_lock_depth(inode->i_sb, "readdir");
49955 diff -urNp linux-2.6.32.46/fs/reiserfs/do_balan.c linux-2.6.32.46/fs/reiserfs/do_balan.c
49956 --- linux-2.6.32.46/fs/reiserfs/do_balan.c 2011-03-27 14:31:47.000000000 -0400
49957 +++ linux-2.6.32.46/fs/reiserfs/do_balan.c 2011-04-17 15:56:46.000000000 -0400
49958 @@ -2058,7 +2058,7 @@ void do_balance(struct tree_balance *tb,
49959 return;
49960 }
49961
49962 - atomic_inc(&(fs_generation(tb->tb_sb)));
49963 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49964 do_balance_starts(tb);
49965
49966 /* balance leaf returns 0 except if combining L R and S into
49967 diff -urNp linux-2.6.32.46/fs/reiserfs/item_ops.c linux-2.6.32.46/fs/reiserfs/item_ops.c
49968 --- linux-2.6.32.46/fs/reiserfs/item_ops.c 2011-03-27 14:31:47.000000000 -0400
49969 +++ linux-2.6.32.46/fs/reiserfs/item_ops.c 2011-04-17 15:56:46.000000000 -0400
49970 @@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
49971 vi->vi_index, vi->vi_type, vi->vi_ih);
49972 }
49973
49974 -static struct item_operations stat_data_ops = {
49975 +static const struct item_operations stat_data_ops = {
49976 .bytes_number = sd_bytes_number,
49977 .decrement_key = sd_decrement_key,
49978 .is_left_mergeable = sd_is_left_mergeable,
49979 @@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
49980 vi->vi_index, vi->vi_type, vi->vi_ih);
49981 }
49982
49983 -static struct item_operations direct_ops = {
49984 +static const struct item_operations direct_ops = {
49985 .bytes_number = direct_bytes_number,
49986 .decrement_key = direct_decrement_key,
49987 .is_left_mergeable = direct_is_left_mergeable,
49988 @@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
49989 vi->vi_index, vi->vi_type, vi->vi_ih);
49990 }
49991
49992 -static struct item_operations indirect_ops = {
49993 +static const struct item_operations indirect_ops = {
49994 .bytes_number = indirect_bytes_number,
49995 .decrement_key = indirect_decrement_key,
49996 .is_left_mergeable = indirect_is_left_mergeable,
49997 @@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
49998 printk("\n");
49999 }
50000
50001 -static struct item_operations direntry_ops = {
50002 +static const struct item_operations direntry_ops = {
50003 .bytes_number = direntry_bytes_number,
50004 .decrement_key = direntry_decrement_key,
50005 .is_left_mergeable = direntry_is_left_mergeable,
50006 @@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
50007 "Invalid item type observed, run fsck ASAP");
50008 }
50009
50010 -static struct item_operations errcatch_ops = {
50011 +static const struct item_operations errcatch_ops = {
50012 errcatch_bytes_number,
50013 errcatch_decrement_key,
50014 errcatch_is_left_mergeable,
50015 @@ -746,7 +746,7 @@ static struct item_operations errcatch_o
50016 #error Item types must use disk-format assigned values.
50017 #endif
50018
50019 -struct item_operations *item_ops[TYPE_ANY + 1] = {
50020 +const struct item_operations * const item_ops[TYPE_ANY + 1] = {
50021 &stat_data_ops,
50022 &indirect_ops,
50023 &direct_ops,
50024 diff -urNp linux-2.6.32.46/fs/reiserfs/journal.c linux-2.6.32.46/fs/reiserfs/journal.c
50025 --- linux-2.6.32.46/fs/reiserfs/journal.c 2011-03-27 14:31:47.000000000 -0400
50026 +++ linux-2.6.32.46/fs/reiserfs/journal.c 2011-05-16 21:46:57.000000000 -0400
50027 @@ -2329,6 +2329,8 @@ static struct buffer_head *reiserfs_brea
50028 struct buffer_head *bh;
50029 int i, j;
50030
50031 + pax_track_stack();
50032 +
50033 bh = __getblk(dev, block, bufsize);
50034 if (buffer_uptodate(bh))
50035 return (bh);
50036 diff -urNp linux-2.6.32.46/fs/reiserfs/namei.c linux-2.6.32.46/fs/reiserfs/namei.c
50037 --- linux-2.6.32.46/fs/reiserfs/namei.c 2011-03-27 14:31:47.000000000 -0400
50038 +++ linux-2.6.32.46/fs/reiserfs/namei.c 2011-05-16 21:46:57.000000000 -0400
50039 @@ -1214,6 +1214,8 @@ static int reiserfs_rename(struct inode
50040 unsigned long savelink = 1;
50041 struct timespec ctime;
50042
50043 + pax_track_stack();
50044 +
50045 /* three balancings: (1) old name removal, (2) new name insertion
50046 and (3) maybe "save" link insertion
50047 stat data updates: (1) old directory,
50048 diff -urNp linux-2.6.32.46/fs/reiserfs/procfs.c linux-2.6.32.46/fs/reiserfs/procfs.c
50049 --- linux-2.6.32.46/fs/reiserfs/procfs.c 2011-03-27 14:31:47.000000000 -0400
50050 +++ linux-2.6.32.46/fs/reiserfs/procfs.c 2011-05-16 21:46:57.000000000 -0400
50051 @@ -123,7 +123,7 @@ static int show_super(struct seq_file *m
50052 "SMALL_TAILS " : "NO_TAILS ",
50053 replay_only(sb) ? "REPLAY_ONLY " : "",
50054 convert_reiserfs(sb) ? "CONV " : "",
50055 - atomic_read(&r->s_generation_counter),
50056 + atomic_read_unchecked(&r->s_generation_counter),
50057 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50058 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50059 SF(s_good_search_by_key_reada), SF(s_bmaps),
50060 @@ -309,6 +309,8 @@ static int show_journal(struct seq_file
50061 struct journal_params *jp = &rs->s_v1.s_journal;
50062 char b[BDEVNAME_SIZE];
50063
50064 + pax_track_stack();
50065 +
50066 seq_printf(m, /* on-disk fields */
50067 "jp_journal_1st_block: \t%i\n"
50068 "jp_journal_dev: \t%s[%x]\n"
50069 diff -urNp linux-2.6.32.46/fs/reiserfs/stree.c linux-2.6.32.46/fs/reiserfs/stree.c
50070 --- linux-2.6.32.46/fs/reiserfs/stree.c 2011-03-27 14:31:47.000000000 -0400
50071 +++ linux-2.6.32.46/fs/reiserfs/stree.c 2011-05-16 21:46:57.000000000 -0400
50072 @@ -1159,6 +1159,8 @@ int reiserfs_delete_item(struct reiserfs
50073 int iter = 0;
50074 #endif
50075
50076 + pax_track_stack();
50077 +
50078 BUG_ON(!th->t_trans_id);
50079
50080 init_tb_struct(th, &s_del_balance, sb, path,
50081 @@ -1296,6 +1298,8 @@ void reiserfs_delete_solid_item(struct r
50082 int retval;
50083 int quota_cut_bytes = 0;
50084
50085 + pax_track_stack();
50086 +
50087 BUG_ON(!th->t_trans_id);
50088
50089 le_key2cpu_key(&cpu_key, key);
50090 @@ -1525,6 +1529,8 @@ int reiserfs_cut_from_item(struct reiser
50091 int quota_cut_bytes;
50092 loff_t tail_pos = 0;
50093
50094 + pax_track_stack();
50095 +
50096 BUG_ON(!th->t_trans_id);
50097
50098 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
50099 @@ -1920,6 +1926,8 @@ int reiserfs_paste_into_item(struct reis
50100 int retval;
50101 int fs_gen;
50102
50103 + pax_track_stack();
50104 +
50105 BUG_ON(!th->t_trans_id);
50106
50107 fs_gen = get_generation(inode->i_sb);
50108 @@ -2007,6 +2015,8 @@ int reiserfs_insert_item(struct reiserfs
50109 int fs_gen = 0;
50110 int quota_bytes = 0;
50111
50112 + pax_track_stack();
50113 +
50114 BUG_ON(!th->t_trans_id);
50115
50116 if (inode) { /* Do we count quotas for item? */
50117 diff -urNp linux-2.6.32.46/fs/reiserfs/super.c linux-2.6.32.46/fs/reiserfs/super.c
50118 --- linux-2.6.32.46/fs/reiserfs/super.c 2011-03-27 14:31:47.000000000 -0400
50119 +++ linux-2.6.32.46/fs/reiserfs/super.c 2011-05-16 21:46:57.000000000 -0400
50120 @@ -912,6 +912,8 @@ static int reiserfs_parse_options(struct
50121 {.option_name = NULL}
50122 };
50123
50124 + pax_track_stack();
50125 +
50126 *blocks = 0;
50127 if (!options || !*options)
50128 /* use default configuration: create tails, journaling on, no
50129 diff -urNp linux-2.6.32.46/fs/select.c linux-2.6.32.46/fs/select.c
50130 --- linux-2.6.32.46/fs/select.c 2011-03-27 14:31:47.000000000 -0400
50131 +++ linux-2.6.32.46/fs/select.c 2011-05-16 21:46:57.000000000 -0400
50132 @@ -20,6 +20,7 @@
50133 #include <linux/module.h>
50134 #include <linux/slab.h>
50135 #include <linux/poll.h>
50136 +#include <linux/security.h>
50137 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50138 #include <linux/file.h>
50139 #include <linux/fdtable.h>
50140 @@ -401,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, s
50141 int retval, i, timed_out = 0;
50142 unsigned long slack = 0;
50143
50144 + pax_track_stack();
50145 +
50146 rcu_read_lock();
50147 retval = max_select_fd(n, fds);
50148 rcu_read_unlock();
50149 @@ -529,6 +532,8 @@ int core_sys_select(int n, fd_set __user
50150 /* Allocate small arguments on the stack to save memory and be faster */
50151 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
50152
50153 + pax_track_stack();
50154 +
50155 ret = -EINVAL;
50156 if (n < 0)
50157 goto out_nofds;
50158 @@ -821,6 +826,9 @@ int do_sys_poll(struct pollfd __user *uf
50159 struct poll_list *walk = head;
50160 unsigned long todo = nfds;
50161
50162 + pax_track_stack();
50163 +
50164 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50165 if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
50166 return -EINVAL;
50167
50168 diff -urNp linux-2.6.32.46/fs/seq_file.c linux-2.6.32.46/fs/seq_file.c
50169 --- linux-2.6.32.46/fs/seq_file.c 2011-03-27 14:31:47.000000000 -0400
50170 +++ linux-2.6.32.46/fs/seq_file.c 2011-08-23 21:22:32.000000000 -0400
50171 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
50172 return 0;
50173 }
50174 if (!m->buf) {
50175 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50176 + m->size = PAGE_SIZE;
50177 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50178 if (!m->buf)
50179 return -ENOMEM;
50180 }
50181 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
50182 Eoverflow:
50183 m->op->stop(m, p);
50184 kfree(m->buf);
50185 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50186 + m->size <<= 1;
50187 + m->buf = kmalloc(m->size, GFP_KERNEL);
50188 return !m->buf ? -ENOMEM : -EAGAIN;
50189 }
50190
50191 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
50192 m->version = file->f_version;
50193 /* grab buffer if we didn't have one */
50194 if (!m->buf) {
50195 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50196 + m->size = PAGE_SIZE;
50197 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50198 if (!m->buf)
50199 goto Enomem;
50200 }
50201 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
50202 goto Fill;
50203 m->op->stop(m, p);
50204 kfree(m->buf);
50205 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50206 + m->size <<= 1;
50207 + m->buf = kmalloc(m->size, GFP_KERNEL);
50208 if (!m->buf)
50209 goto Enomem;
50210 m->count = 0;
50211 @@ -551,7 +555,7 @@ static void single_stop(struct seq_file
50212 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50213 void *data)
50214 {
50215 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50216 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50217 int res = -ENOMEM;
50218
50219 if (op) {
50220 diff -urNp linux-2.6.32.46/fs/smbfs/proc.c linux-2.6.32.46/fs/smbfs/proc.c
50221 --- linux-2.6.32.46/fs/smbfs/proc.c 2011-03-27 14:31:47.000000000 -0400
50222 +++ linux-2.6.32.46/fs/smbfs/proc.c 2011-08-05 20:33:55.000000000 -0400
50223 @@ -266,9 +266,9 @@ int smb_setcodepage(struct smb_sb_info *
50224
50225 out:
50226 if (server->local_nls != NULL && server->remote_nls != NULL)
50227 - server->ops->convert = convert_cp;
50228 + *(void **)&server->ops->convert = convert_cp;
50229 else
50230 - server->ops->convert = convert_memcpy;
50231 + *(void **)&server->ops->convert = convert_memcpy;
50232
50233 smb_unlock_server(server);
50234 return n;
50235 @@ -933,9 +933,9 @@ smb_newconn(struct smb_sb_info *server,
50236
50237 /* FIXME: the win9x code wants to modify these ... (seek/trunc bug) */
50238 if (server->mnt->flags & SMB_MOUNT_OLDATTR) {
50239 - server->ops->getattr = smb_proc_getattr_core;
50240 + *(void **)&server->ops->getattr = smb_proc_getattr_core;
50241 } else if (server->mnt->flags & SMB_MOUNT_DIRATTR) {
50242 - server->ops->getattr = smb_proc_getattr_ff;
50243 + *(void **)&server->ops->getattr = smb_proc_getattr_ff;
50244 }
50245
50246 /* Decode server capabilities */
50247 @@ -3439,7 +3439,7 @@ out:
50248 static void
50249 install_ops(struct smb_ops *dst, struct smb_ops *src)
50250 {
50251 - memcpy(dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
50252 + memcpy((void *)dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
50253 }
50254
50255 /* < LANMAN2 */
50256 diff -urNp linux-2.6.32.46/fs/smbfs/symlink.c linux-2.6.32.46/fs/smbfs/symlink.c
50257 --- linux-2.6.32.46/fs/smbfs/symlink.c 2011-03-27 14:31:47.000000000 -0400
50258 +++ linux-2.6.32.46/fs/smbfs/symlink.c 2011-04-17 15:56:46.000000000 -0400
50259 @@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent
50260
50261 static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
50262 {
50263 - char *s = nd_get_link(nd);
50264 + const char *s = nd_get_link(nd);
50265 if (!IS_ERR(s))
50266 __putname(s);
50267 }
50268 diff -urNp linux-2.6.32.46/fs/splice.c linux-2.6.32.46/fs/splice.c
50269 --- linux-2.6.32.46/fs/splice.c 2011-03-27 14:31:47.000000000 -0400
50270 +++ linux-2.6.32.46/fs/splice.c 2011-10-06 09:37:14.000000000 -0400
50271 @@ -185,7 +185,7 @@ ssize_t splice_to_pipe(struct pipe_inode
50272 pipe_lock(pipe);
50273
50274 for (;;) {
50275 - if (!pipe->readers) {
50276 + if (!atomic_read(&pipe->readers)) {
50277 send_sig(SIGPIPE, current, 0);
50278 if (!ret)
50279 ret = -EPIPE;
50280 @@ -239,9 +239,9 @@ ssize_t splice_to_pipe(struct pipe_inode
50281 do_wakeup = 0;
50282 }
50283
50284 - pipe->waiting_writers++;
50285 + atomic_inc(&pipe->waiting_writers);
50286 pipe_wait(pipe);
50287 - pipe->waiting_writers--;
50288 + atomic_dec(&pipe->waiting_writers);
50289 }
50290
50291 pipe_unlock(pipe);
50292 @@ -285,6 +285,8 @@ __generic_file_splice_read(struct file *
50293 .spd_release = spd_release_page,
50294 };
50295
50296 + pax_track_stack();
50297 +
50298 index = *ppos >> PAGE_CACHE_SHIFT;
50299 loff = *ppos & ~PAGE_CACHE_MASK;
50300 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
50301 @@ -521,7 +523,7 @@ static ssize_t kernel_readv(struct file
50302 old_fs = get_fs();
50303 set_fs(get_ds());
50304 /* The cast to a user pointer is valid due to the set_fs() */
50305 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50306 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50307 set_fs(old_fs);
50308
50309 return res;
50310 @@ -536,7 +538,7 @@ static ssize_t kernel_write(struct file
50311 old_fs = get_fs();
50312 set_fs(get_ds());
50313 /* The cast to a user pointer is valid due to the set_fs() */
50314 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50315 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50316 set_fs(old_fs);
50317
50318 return res;
50319 @@ -565,6 +567,8 @@ ssize_t default_file_splice_read(struct
50320 .spd_release = spd_release_page,
50321 };
50322
50323 + pax_track_stack();
50324 +
50325 index = *ppos >> PAGE_CACHE_SHIFT;
50326 offset = *ppos & ~PAGE_CACHE_MASK;
50327 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
50328 @@ -578,7 +582,7 @@ ssize_t default_file_splice_read(struct
50329 goto err;
50330
50331 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50332 - vec[i].iov_base = (void __user *) page_address(page);
50333 + vec[i].iov_base = (__force void __user *) page_address(page);
50334 vec[i].iov_len = this_len;
50335 pages[i] = page;
50336 spd.nr_pages++;
50337 @@ -800,10 +804,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50338 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50339 {
50340 while (!pipe->nrbufs) {
50341 - if (!pipe->writers)
50342 + if (!atomic_read(&pipe->writers))
50343 return 0;
50344
50345 - if (!pipe->waiting_writers && sd->num_spliced)
50346 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50347 return 0;
50348
50349 if (sd->flags & SPLICE_F_NONBLOCK)
50350 @@ -1140,7 +1144,7 @@ ssize_t splice_direct_to_actor(struct fi
50351 * out of the pipe right after the splice_to_pipe(). So set
50352 * PIPE_READERS appropriately.
50353 */
50354 - pipe->readers = 1;
50355 + atomic_set(&pipe->readers, 1);
50356
50357 current->splice_pipe = pipe;
50358 }
50359 @@ -1592,6 +1596,8 @@ static long vmsplice_to_pipe(struct file
50360 .spd_release = spd_release_page,
50361 };
50362
50363 + pax_track_stack();
50364 +
50365 pipe = pipe_info(file->f_path.dentry->d_inode);
50366 if (!pipe)
50367 return -EBADF;
50368 @@ -1700,9 +1706,9 @@ static int ipipe_prep(struct pipe_inode_
50369 ret = -ERESTARTSYS;
50370 break;
50371 }
50372 - if (!pipe->writers)
50373 + if (!atomic_read(&pipe->writers))
50374 break;
50375 - if (!pipe->waiting_writers) {
50376 + if (!atomic_read(&pipe->waiting_writers)) {
50377 if (flags & SPLICE_F_NONBLOCK) {
50378 ret = -EAGAIN;
50379 break;
50380 @@ -1734,7 +1740,7 @@ static int opipe_prep(struct pipe_inode_
50381 pipe_lock(pipe);
50382
50383 while (pipe->nrbufs >= PIPE_BUFFERS) {
50384 - if (!pipe->readers) {
50385 + if (!atomic_read(&pipe->readers)) {
50386 send_sig(SIGPIPE, current, 0);
50387 ret = -EPIPE;
50388 break;
50389 @@ -1747,9 +1753,9 @@ static int opipe_prep(struct pipe_inode_
50390 ret = -ERESTARTSYS;
50391 break;
50392 }
50393 - pipe->waiting_writers++;
50394 + atomic_inc(&pipe->waiting_writers);
50395 pipe_wait(pipe);
50396 - pipe->waiting_writers--;
50397 + atomic_dec(&pipe->waiting_writers);
50398 }
50399
50400 pipe_unlock(pipe);
50401 @@ -1785,14 +1791,14 @@ retry:
50402 pipe_double_lock(ipipe, opipe);
50403
50404 do {
50405 - if (!opipe->readers) {
50406 + if (!atomic_read(&opipe->readers)) {
50407 send_sig(SIGPIPE, current, 0);
50408 if (!ret)
50409 ret = -EPIPE;
50410 break;
50411 }
50412
50413 - if (!ipipe->nrbufs && !ipipe->writers)
50414 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50415 break;
50416
50417 /*
50418 @@ -1892,7 +1898,7 @@ static int link_pipe(struct pipe_inode_i
50419 pipe_double_lock(ipipe, opipe);
50420
50421 do {
50422 - if (!opipe->readers) {
50423 + if (!atomic_read(&opipe->readers)) {
50424 send_sig(SIGPIPE, current, 0);
50425 if (!ret)
50426 ret = -EPIPE;
50427 @@ -1937,7 +1943,7 @@ static int link_pipe(struct pipe_inode_i
50428 * return EAGAIN if we have the potential of some data in the
50429 * future, otherwise just return 0
50430 */
50431 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50432 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50433 ret = -EAGAIN;
50434
50435 pipe_unlock(ipipe);
50436 diff -urNp linux-2.6.32.46/fs/sysfs/file.c linux-2.6.32.46/fs/sysfs/file.c
50437 --- linux-2.6.32.46/fs/sysfs/file.c 2011-03-27 14:31:47.000000000 -0400
50438 +++ linux-2.6.32.46/fs/sysfs/file.c 2011-05-04 17:56:20.000000000 -0400
50439 @@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
50440
50441 struct sysfs_open_dirent {
50442 atomic_t refcnt;
50443 - atomic_t event;
50444 + atomic_unchecked_t event;
50445 wait_queue_head_t poll;
50446 struct list_head buffers; /* goes through sysfs_buffer.list */
50447 };
50448 @@ -53,7 +53,7 @@ struct sysfs_buffer {
50449 size_t count;
50450 loff_t pos;
50451 char * page;
50452 - struct sysfs_ops * ops;
50453 + const struct sysfs_ops * ops;
50454 struct mutex mutex;
50455 int needs_read_fill;
50456 int event;
50457 @@ -75,7 +75,7 @@ static int fill_read_buffer(struct dentr
50458 {
50459 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
50460 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
50461 - struct sysfs_ops * ops = buffer->ops;
50462 + const struct sysfs_ops * ops = buffer->ops;
50463 int ret = 0;
50464 ssize_t count;
50465
50466 @@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentr
50467 if (!sysfs_get_active_two(attr_sd))
50468 return -ENODEV;
50469
50470 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50471 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50472 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50473
50474 sysfs_put_active_two(attr_sd);
50475 @@ -199,7 +199,7 @@ flush_write_buffer(struct dentry * dentr
50476 {
50477 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
50478 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
50479 - struct sysfs_ops * ops = buffer->ops;
50480 + const struct sysfs_ops * ops = buffer->ops;
50481 int rc;
50482
50483 /* need attr_sd for attr and ops, its parent for kobj */
50484 @@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct
50485 return -ENOMEM;
50486
50487 atomic_set(&new_od->refcnt, 0);
50488 - atomic_set(&new_od->event, 1);
50489 + atomic_set_unchecked(&new_od->event, 1);
50490 init_waitqueue_head(&new_od->poll);
50491 INIT_LIST_HEAD(&new_od->buffers);
50492 goto retry;
50493 @@ -335,7 +335,7 @@ static int sysfs_open_file(struct inode
50494 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
50495 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
50496 struct sysfs_buffer *buffer;
50497 - struct sysfs_ops *ops;
50498 + const struct sysfs_ops *ops;
50499 int error = -EACCES;
50500 char *p;
50501
50502 @@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct fi
50503
50504 sysfs_put_active_two(attr_sd);
50505
50506 - if (buffer->event != atomic_read(&od->event))
50507 + if (buffer->event != atomic_read_unchecked(&od->event))
50508 goto trigger;
50509
50510 return DEFAULT_POLLMASK;
50511 @@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_di
50512
50513 od = sd->s_attr.open;
50514 if (od) {
50515 - atomic_inc(&od->event);
50516 + atomic_inc_unchecked(&od->event);
50517 wake_up_interruptible(&od->poll);
50518 }
50519
50520 diff -urNp linux-2.6.32.46/fs/sysfs/mount.c linux-2.6.32.46/fs/sysfs/mount.c
50521 --- linux-2.6.32.46/fs/sysfs/mount.c 2011-03-27 14:31:47.000000000 -0400
50522 +++ linux-2.6.32.46/fs/sysfs/mount.c 2011-04-17 15:56:46.000000000 -0400
50523 @@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
50524 .s_name = "",
50525 .s_count = ATOMIC_INIT(1),
50526 .s_flags = SYSFS_DIR,
50527 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50528 + .s_mode = S_IFDIR | S_IRWXU,
50529 +#else
50530 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50531 +#endif
50532 .s_ino = 1,
50533 };
50534
50535 diff -urNp linux-2.6.32.46/fs/sysfs/symlink.c linux-2.6.32.46/fs/sysfs/symlink.c
50536 --- linux-2.6.32.46/fs/sysfs/symlink.c 2011-03-27 14:31:47.000000000 -0400
50537 +++ linux-2.6.32.46/fs/sysfs/symlink.c 2011-04-17 15:56:46.000000000 -0400
50538 @@ -204,7 +204,7 @@ static void *sysfs_follow_link(struct de
50539
50540 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50541 {
50542 - char *page = nd_get_link(nd);
50543 + const char *page = nd_get_link(nd);
50544 if (!IS_ERR(page))
50545 free_page((unsigned long)page);
50546 }
50547 diff -urNp linux-2.6.32.46/fs/udf/balloc.c linux-2.6.32.46/fs/udf/balloc.c
50548 --- linux-2.6.32.46/fs/udf/balloc.c 2011-03-27 14:31:47.000000000 -0400
50549 +++ linux-2.6.32.46/fs/udf/balloc.c 2011-04-17 15:56:46.000000000 -0400
50550 @@ -172,9 +172,7 @@ static void udf_bitmap_free_blocks(struc
50551
50552 mutex_lock(&sbi->s_alloc_mutex);
50553 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
50554 - if (bloc->logicalBlockNum < 0 ||
50555 - (bloc->logicalBlockNum + count) >
50556 - partmap->s_partition_len) {
50557 + if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
50558 udf_debug("%d < %d || %d + %d > %d\n",
50559 bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
50560 count, partmap->s_partition_len);
50561 @@ -436,9 +434,7 @@ static void udf_table_free_blocks(struct
50562
50563 mutex_lock(&sbi->s_alloc_mutex);
50564 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
50565 - if (bloc->logicalBlockNum < 0 ||
50566 - (bloc->logicalBlockNum + count) >
50567 - partmap->s_partition_len) {
50568 + if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
50569 udf_debug("%d < %d || %d + %d > %d\n",
50570 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
50571 partmap->s_partition_len);
50572 diff -urNp linux-2.6.32.46/fs/udf/inode.c linux-2.6.32.46/fs/udf/inode.c
50573 --- linux-2.6.32.46/fs/udf/inode.c 2011-03-27 14:31:47.000000000 -0400
50574 +++ linux-2.6.32.46/fs/udf/inode.c 2011-05-16 21:46:57.000000000 -0400
50575 @@ -484,6 +484,8 @@ static struct buffer_head *inode_getblk(
50576 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
50577 int lastblock = 0;
50578
50579 + pax_track_stack();
50580 +
50581 prev_epos.offset = udf_file_entry_alloc_offset(inode);
50582 prev_epos.block = iinfo->i_location;
50583 prev_epos.bh = NULL;
50584 diff -urNp linux-2.6.32.46/fs/udf/misc.c linux-2.6.32.46/fs/udf/misc.c
50585 --- linux-2.6.32.46/fs/udf/misc.c 2011-03-27 14:31:47.000000000 -0400
50586 +++ linux-2.6.32.46/fs/udf/misc.c 2011-04-23 12:56:11.000000000 -0400
50587 @@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
50588
50589 u8 udf_tag_checksum(const struct tag *t)
50590 {
50591 - u8 *data = (u8 *)t;
50592 + const u8 *data = (const u8 *)t;
50593 u8 checksum = 0;
50594 int i;
50595 for (i = 0; i < sizeof(struct tag); ++i)
50596 diff -urNp linux-2.6.32.46/fs/utimes.c linux-2.6.32.46/fs/utimes.c
50597 --- linux-2.6.32.46/fs/utimes.c 2011-03-27 14:31:47.000000000 -0400
50598 +++ linux-2.6.32.46/fs/utimes.c 2011-04-17 15:56:46.000000000 -0400
50599 @@ -1,6 +1,7 @@
50600 #include <linux/compiler.h>
50601 #include <linux/file.h>
50602 #include <linux/fs.h>
50603 +#include <linux/security.h>
50604 #include <linux/linkage.h>
50605 #include <linux/mount.h>
50606 #include <linux/namei.h>
50607 @@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
50608 goto mnt_drop_write_and_out;
50609 }
50610 }
50611 +
50612 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50613 + error = -EACCES;
50614 + goto mnt_drop_write_and_out;
50615 + }
50616 +
50617 mutex_lock(&inode->i_mutex);
50618 error = notify_change(path->dentry, &newattrs);
50619 mutex_unlock(&inode->i_mutex);
50620 diff -urNp linux-2.6.32.46/fs/xattr.c linux-2.6.32.46/fs/xattr.c
50621 --- linux-2.6.32.46/fs/xattr.c 2011-03-27 14:31:47.000000000 -0400
50622 +++ linux-2.6.32.46/fs/xattr.c 2011-04-17 15:56:46.000000000 -0400
50623 @@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50624 * Extended attribute SET operations
50625 */
50626 static long
50627 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50628 +setxattr(struct path *path, const char __user *name, const void __user *value,
50629 size_t size, int flags)
50630 {
50631 int error;
50632 @@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
50633 return PTR_ERR(kvalue);
50634 }
50635
50636 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50637 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50638 + error = -EACCES;
50639 + goto out;
50640 + }
50641 +
50642 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50643 +out:
50644 kfree(kvalue);
50645 return error;
50646 }
50647 @@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
50648 return error;
50649 error = mnt_want_write(path.mnt);
50650 if (!error) {
50651 - error = setxattr(path.dentry, name, value, size, flags);
50652 + error = setxattr(&path, name, value, size, flags);
50653 mnt_drop_write(path.mnt);
50654 }
50655 path_put(&path);
50656 @@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
50657 return error;
50658 error = mnt_want_write(path.mnt);
50659 if (!error) {
50660 - error = setxattr(path.dentry, name, value, size, flags);
50661 + error = setxattr(&path, name, value, size, flags);
50662 mnt_drop_write(path.mnt);
50663 }
50664 path_put(&path);
50665 @@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
50666 const void __user *,value, size_t, size, int, flags)
50667 {
50668 struct file *f;
50669 - struct dentry *dentry;
50670 int error = -EBADF;
50671
50672 f = fget(fd);
50673 if (!f)
50674 return error;
50675 - dentry = f->f_path.dentry;
50676 - audit_inode(NULL, dentry);
50677 + audit_inode(NULL, f->f_path.dentry);
50678 error = mnt_want_write_file(f);
50679 if (!error) {
50680 - error = setxattr(dentry, name, value, size, flags);
50681 + error = setxattr(&f->f_path, name, value, size, flags);
50682 mnt_drop_write(f->f_path.mnt);
50683 }
50684 fput(f);
50685 diff -urNp linux-2.6.32.46/fs/xattr_acl.c linux-2.6.32.46/fs/xattr_acl.c
50686 --- linux-2.6.32.46/fs/xattr_acl.c 2011-03-27 14:31:47.000000000 -0400
50687 +++ linux-2.6.32.46/fs/xattr_acl.c 2011-04-17 15:56:46.000000000 -0400
50688 @@ -17,8 +17,8 @@
50689 struct posix_acl *
50690 posix_acl_from_xattr(const void *value, size_t size)
50691 {
50692 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50693 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50694 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50695 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50696 int count;
50697 struct posix_acl *acl;
50698 struct posix_acl_entry *acl_e;
50699 diff -urNp linux-2.6.32.46/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32.46/fs/xfs/linux-2.6/xfs_ioctl.c
50700 --- linux-2.6.32.46/fs/xfs/linux-2.6/xfs_ioctl.c 2011-04-17 17:00:52.000000000 -0400
50701 +++ linux-2.6.32.46/fs/xfs/linux-2.6/xfs_ioctl.c 2011-04-17 20:07:09.000000000 -0400
50702 @@ -134,7 +134,7 @@ xfs_find_handle(
50703 }
50704
50705 error = -EFAULT;
50706 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50707 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50708 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50709 goto out_put;
50710
50711 @@ -423,7 +423,7 @@ xfs_attrlist_by_handle(
50712 if (IS_ERR(dentry))
50713 return PTR_ERR(dentry);
50714
50715 - kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
50716 + kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
50717 if (!kbuf)
50718 goto out_dput;
50719
50720 @@ -697,7 +697,7 @@ xfs_ioc_fsgeometry_v1(
50721 xfs_mount_t *mp,
50722 void __user *arg)
50723 {
50724 - xfs_fsop_geom_t fsgeo;
50725 + xfs_fsop_geom_t fsgeo;
50726 int error;
50727
50728 error = xfs_fs_geometry(mp, &fsgeo, 3);
50729 diff -urNp linux-2.6.32.46/fs/xfs/linux-2.6/xfs_ioctl32.c linux-2.6.32.46/fs/xfs/linux-2.6/xfs_ioctl32.c
50730 --- linux-2.6.32.46/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-03-27 14:31:47.000000000 -0400
50731 +++ linux-2.6.32.46/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-04-17 15:56:46.000000000 -0400
50732 @@ -75,6 +75,7 @@ xfs_compat_ioc_fsgeometry_v1(
50733 xfs_fsop_geom_t fsgeo;
50734 int error;
50735
50736 + memset(&fsgeo, 0, sizeof(fsgeo));
50737 error = xfs_fs_geometry(mp, &fsgeo, 3);
50738 if (error)
50739 return -error;
50740 diff -urNp linux-2.6.32.46/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32.46/fs/xfs/linux-2.6/xfs_iops.c
50741 --- linux-2.6.32.46/fs/xfs/linux-2.6/xfs_iops.c 2011-03-27 14:31:47.000000000 -0400
50742 +++ linux-2.6.32.46/fs/xfs/linux-2.6/xfs_iops.c 2011-04-17 15:56:46.000000000 -0400
50743 @@ -468,7 +468,7 @@ xfs_vn_put_link(
50744 struct nameidata *nd,
50745 void *p)
50746 {
50747 - char *s = nd_get_link(nd);
50748 + const char *s = nd_get_link(nd);
50749
50750 if (!IS_ERR(s))
50751 kfree(s);
50752 diff -urNp linux-2.6.32.46/fs/xfs/xfs_bmap.c linux-2.6.32.46/fs/xfs/xfs_bmap.c
50753 --- linux-2.6.32.46/fs/xfs/xfs_bmap.c 2011-03-27 14:31:47.000000000 -0400
50754 +++ linux-2.6.32.46/fs/xfs/xfs_bmap.c 2011-04-17 15:56:46.000000000 -0400
50755 @@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
50756 int nmap,
50757 int ret_nmap);
50758 #else
50759 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50760 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50761 #endif /* DEBUG */
50762
50763 #if defined(XFS_RW_TRACE)
50764 diff -urNp linux-2.6.32.46/fs/xfs/xfs_dir2_sf.c linux-2.6.32.46/fs/xfs/xfs_dir2_sf.c
50765 --- linux-2.6.32.46/fs/xfs/xfs_dir2_sf.c 2011-03-27 14:31:47.000000000 -0400
50766 +++ linux-2.6.32.46/fs/xfs/xfs_dir2_sf.c 2011-04-18 22:07:30.000000000 -0400
50767 @@ -779,7 +779,15 @@ xfs_dir2_sf_getdents(
50768 }
50769
50770 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
50771 - if (filldir(dirent, sfep->name, sfep->namelen,
50772 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50773 + char name[sfep->namelen];
50774 + memcpy(name, sfep->name, sfep->namelen);
50775 + if (filldir(dirent, name, sfep->namelen,
50776 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50777 + *offset = off & 0x7fffffff;
50778 + return 0;
50779 + }
50780 + } else if (filldir(dirent, sfep->name, sfep->namelen,
50781 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50782 *offset = off & 0x7fffffff;
50783 return 0;
50784 diff -urNp linux-2.6.32.46/grsecurity/Kconfig linux-2.6.32.46/grsecurity/Kconfig
50785 --- linux-2.6.32.46/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
50786 +++ linux-2.6.32.46/grsecurity/Kconfig 2011-09-15 00:00:38.000000000 -0400
50787 @@ -0,0 +1,1037 @@
50788 +#
50789 +# grecurity configuration
50790 +#
50791 +
50792 +menu "Grsecurity"
50793 +
50794 +config GRKERNSEC
50795 + bool "Grsecurity"
50796 + select CRYPTO
50797 + select CRYPTO_SHA256
50798 + help
50799 + If you say Y here, you will be able to configure many features
50800 + that will enhance the security of your system. It is highly
50801 + recommended that you say Y here and read through the help
50802 + for each option so that you fully understand the features and
50803 + can evaluate their usefulness for your machine.
50804 +
50805 +choice
50806 + prompt "Security Level"
50807 + depends on GRKERNSEC
50808 + default GRKERNSEC_CUSTOM
50809 +
50810 +config GRKERNSEC_LOW
50811 + bool "Low"
50812 + select GRKERNSEC_LINK
50813 + select GRKERNSEC_FIFO
50814 + select GRKERNSEC_RANDNET
50815 + select GRKERNSEC_DMESG
50816 + select GRKERNSEC_CHROOT
50817 + select GRKERNSEC_CHROOT_CHDIR
50818 +
50819 + help
50820 + If you choose this option, several of the grsecurity options will
50821 + be enabled that will give you greater protection against a number
50822 + of attacks, while assuring that none of your software will have any
50823 + conflicts with the additional security measures. If you run a lot
50824 + of unusual software, or you are having problems with the higher
50825 + security levels, you should say Y here. With this option, the
50826 + following features are enabled:
50827 +
50828 + - Linking restrictions
50829 + - FIFO restrictions
50830 + - Restricted dmesg
50831 + - Enforced chdir("/") on chroot
50832 + - Runtime module disabling
50833 +
50834 +config GRKERNSEC_MEDIUM
50835 + bool "Medium"
50836 + select PAX
50837 + select PAX_EI_PAX
50838 + select PAX_PT_PAX_FLAGS
50839 + select PAX_HAVE_ACL_FLAGS
50840 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
50841 + select GRKERNSEC_CHROOT
50842 + select GRKERNSEC_CHROOT_SYSCTL
50843 + select GRKERNSEC_LINK
50844 + select GRKERNSEC_FIFO
50845 + select GRKERNSEC_DMESG
50846 + select GRKERNSEC_RANDNET
50847 + select GRKERNSEC_FORKFAIL
50848 + select GRKERNSEC_TIME
50849 + select GRKERNSEC_SIGNAL
50850 + select GRKERNSEC_CHROOT
50851 + select GRKERNSEC_CHROOT_UNIX
50852 + select GRKERNSEC_CHROOT_MOUNT
50853 + select GRKERNSEC_CHROOT_PIVOT
50854 + select GRKERNSEC_CHROOT_DOUBLE
50855 + select GRKERNSEC_CHROOT_CHDIR
50856 + select GRKERNSEC_CHROOT_MKNOD
50857 + select GRKERNSEC_PROC
50858 + select GRKERNSEC_PROC_USERGROUP
50859 + select PAX_RANDUSTACK
50860 + select PAX_ASLR
50861 + select PAX_RANDMMAP
50862 + select PAX_REFCOUNT if (X86 || SPARC64)
50863 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
50864 +
50865 + help
50866 + If you say Y here, several features in addition to those included
50867 + in the low additional security level will be enabled. These
50868 + features provide even more security to your system, though in rare
50869 + cases they may be incompatible with very old or poorly written
50870 + software. If you enable this option, make sure that your auth
50871 + service (identd) is running as gid 1001. With this option,
50872 + the following features (in addition to those provided in the
50873 + low additional security level) will be enabled:
50874 +
50875 + - Failed fork logging
50876 + - Time change logging
50877 + - Signal logging
50878 + - Deny mounts in chroot
50879 + - Deny double chrooting
50880 + - Deny sysctl writes in chroot
50881 + - Deny mknod in chroot
50882 + - Deny access to abstract AF_UNIX sockets out of chroot
50883 + - Deny pivot_root in chroot
50884 + - Denied writes of /dev/kmem, /dev/mem, and /dev/port
50885 + - /proc restrictions with special GID set to 10 (usually wheel)
50886 + - Address Space Layout Randomization (ASLR)
50887 + - Prevent exploitation of most refcount overflows
50888 + - Bounds checking of copying between the kernel and userland
50889 +
50890 +config GRKERNSEC_HIGH
50891 + bool "High"
50892 + select GRKERNSEC_LINK
50893 + select GRKERNSEC_FIFO
50894 + select GRKERNSEC_DMESG
50895 + select GRKERNSEC_FORKFAIL
50896 + select GRKERNSEC_TIME
50897 + select GRKERNSEC_SIGNAL
50898 + select GRKERNSEC_CHROOT
50899 + select GRKERNSEC_CHROOT_SHMAT
50900 + select GRKERNSEC_CHROOT_UNIX
50901 + select GRKERNSEC_CHROOT_MOUNT
50902 + select GRKERNSEC_CHROOT_FCHDIR
50903 + select GRKERNSEC_CHROOT_PIVOT
50904 + select GRKERNSEC_CHROOT_DOUBLE
50905 + select GRKERNSEC_CHROOT_CHDIR
50906 + select GRKERNSEC_CHROOT_MKNOD
50907 + select GRKERNSEC_CHROOT_CAPS
50908 + select GRKERNSEC_CHROOT_SYSCTL
50909 + select GRKERNSEC_CHROOT_FINDTASK
50910 + select GRKERNSEC_SYSFS_RESTRICT
50911 + select GRKERNSEC_PROC
50912 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
50913 + select GRKERNSEC_HIDESYM
50914 + select GRKERNSEC_BRUTE
50915 + select GRKERNSEC_PROC_USERGROUP
50916 + select GRKERNSEC_KMEM
50917 + select GRKERNSEC_RESLOG
50918 + select GRKERNSEC_RANDNET
50919 + select GRKERNSEC_PROC_ADD
50920 + select GRKERNSEC_CHROOT_CHMOD
50921 + select GRKERNSEC_CHROOT_NICE
50922 + select GRKERNSEC_AUDIT_MOUNT
50923 + select GRKERNSEC_MODHARDEN if (MODULES)
50924 + select GRKERNSEC_HARDEN_PTRACE
50925 + select GRKERNSEC_VM86 if (X86_32)
50926 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
50927 + select PAX
50928 + select PAX_RANDUSTACK
50929 + select PAX_ASLR
50930 + select PAX_RANDMMAP
50931 + select PAX_NOEXEC
50932 + select PAX_MPROTECT
50933 + select PAX_EI_PAX
50934 + select PAX_PT_PAX_FLAGS
50935 + select PAX_HAVE_ACL_FLAGS
50936 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
50937 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
50938 + select PAX_RANDKSTACK if (X86_TSC && X86)
50939 + select PAX_SEGMEXEC if (X86_32)
50940 + select PAX_PAGEEXEC
50941 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
50942 + select PAX_EMUTRAMP if (PARISC)
50943 + select PAX_EMUSIGRT if (PARISC)
50944 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
50945 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
50946 + select PAX_REFCOUNT if (X86 || SPARC64)
50947 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
50948 + help
50949 + If you say Y here, many of the features of grsecurity will be
50950 + enabled, which will protect you against many kinds of attacks
50951 + against your system. The heightened security comes at a cost
50952 + of an increased chance of incompatibilities with rare software
50953 + on your machine. Since this security level enables PaX, you should
50954 + view <http://pax.grsecurity.net> and read about the PaX
50955 + project. While you are there, download chpax and run it on
50956 + binaries that cause problems with PaX. Also remember that
50957 + since the /proc restrictions are enabled, you must run your
50958 + identd as gid 1001. This security level enables the following
50959 + features in addition to those listed in the low and medium
50960 + security levels:
50961 +
50962 + - Additional /proc restrictions
50963 + - Chmod restrictions in chroot
50964 + - No signals, ptrace, or viewing of processes outside of chroot
50965 + - Capability restrictions in chroot
50966 + - Deny fchdir out of chroot
50967 + - Priority restrictions in chroot
50968 + - Segmentation-based implementation of PaX
50969 + - Mprotect restrictions
50970 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
50971 + - Kernel stack randomization
50972 + - Mount/unmount/remount logging
50973 + - Kernel symbol hiding
50974 + - Prevention of memory exhaustion-based exploits
50975 + - Hardening of module auto-loading
50976 + - Ptrace restrictions
50977 + - Restricted vm86 mode
50978 + - Restricted sysfs/debugfs
50979 + - Active kernel exploit response
50980 +
50981 +config GRKERNSEC_CUSTOM
50982 + bool "Custom"
50983 + help
50984 + If you say Y here, you will be able to configure every grsecurity
50985 + option, which allows you to enable many more features that aren't
50986 + covered in the basic security levels. These additional features
50987 + include TPE, socket restrictions, and the sysctl system for
50988 + grsecurity. It is advised that you read through the help for
50989 + each option to determine its usefulness in your situation.
50990 +
50991 +endchoice
50992 +
50993 +menu "Address Space Protection"
50994 +depends on GRKERNSEC
50995 +
50996 +config GRKERNSEC_KMEM
50997 + bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
50998 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50999 + help
51000 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
51001 + be written to via mmap or otherwise to modify the running kernel.
51002 + /dev/port will also not be allowed to be opened. If you have module
51003 + support disabled, enabling this will close up four ways that are
51004 + currently used to insert malicious code into the running kernel.
51005 + Even with all these features enabled, we still highly recommend that
51006 + you use the RBAC system, as it is still possible for an attacker to
51007 + modify the running kernel through privileged I/O granted by ioperm/iopl.
51008 + If you are not using XFree86, you may be able to stop this additional
51009 + case by enabling the 'Disable privileged I/O' option. Though nothing
51010 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
51011 + but only to video memory, which is the only writing we allow in this
51012 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
51013 + not be allowed to mprotect it with PROT_WRITE later.
51014 + It is highly recommended that you say Y here if you meet all the
51015 + conditions above.
51016 +
51017 +config GRKERNSEC_VM86
51018 + bool "Restrict VM86 mode"
51019 + depends on X86_32
51020 +
51021 + help
51022 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
51023 + make use of a special execution mode on 32bit x86 processors called
51024 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
51025 + video cards and will still work with this option enabled. The purpose
51026 + of the option is to prevent exploitation of emulation errors in
51027 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
51028 + Nearly all users should be able to enable this option.
51029 +
51030 +config GRKERNSEC_IO
51031 + bool "Disable privileged I/O"
51032 + depends on X86
51033 + select RTC_CLASS
51034 + select RTC_INTF_DEV
51035 + select RTC_DRV_CMOS
51036 +
51037 + help
51038 + If you say Y here, all ioperm and iopl calls will return an error.
51039 + Ioperm and iopl can be used to modify the running kernel.
51040 + Unfortunately, some programs need this access to operate properly,
51041 + the most notable of which are XFree86 and hwclock. hwclock can be
51042 + remedied by having RTC support in the kernel, so real-time
51043 + clock support is enabled if this option is enabled, to ensure
51044 + that hwclock operates correctly. XFree86 still will not
51045 + operate correctly with this option enabled, so DO NOT CHOOSE Y
51046 + IF YOU USE XFree86. If you use XFree86 and you still want to
51047 + protect your kernel against modification, use the RBAC system.
51048 +
51049 +config GRKERNSEC_PROC_MEMMAP
51050 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
51051 + default y if (PAX_NOEXEC || PAX_ASLR)
51052 + depends on PAX_NOEXEC || PAX_ASLR
51053 + help
51054 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
51055 + give no information about the addresses of its mappings if
51056 + PaX features that rely on random addresses are enabled on the task.
51057 + If you use PaX it is greatly recommended that you say Y here as it
51058 + closes up a hole that makes the full ASLR useless for suid
51059 + binaries.
51060 +
51061 +config GRKERNSEC_BRUTE
51062 + bool "Deter exploit bruteforcing"
51063 + help
51064 + If you say Y here, attempts to bruteforce exploits against forking
51065 + daemons such as apache or sshd, as well as against suid/sgid binaries
51066 + will be deterred. When a child of a forking daemon is killed by PaX
51067 + or crashes due to an illegal instruction or other suspicious signal,
51068 + the parent process will be delayed 30 seconds upon every subsequent
51069 + fork until the administrator is able to assess the situation and
51070 + restart the daemon.
51071 + In the suid/sgid case, the attempt is logged, the user has all their
51072 + processes terminated, and they are prevented from executing any further
51073 + processes for 15 minutes.
51074 + It is recommended that you also enable signal logging in the auditing
51075 + section so that logs are generated when a process triggers a suspicious
51076 + signal.
51077 + If the sysctl option is enabled, a sysctl option with name
51078 + "deter_bruteforce" is created.
51079 +
51080 +config GRKERNSEC_MODHARDEN
51081 + bool "Harden module auto-loading"
51082 + depends on MODULES
51083 + help
51084 + If you say Y here, module auto-loading in response to use of some
51085 + feature implemented by an unloaded module will be restricted to
51086 + root users. Enabling this option helps defend against attacks
51087 + by unprivileged users who abuse the auto-loading behavior to
51088 + cause a vulnerable module to load that is then exploited.
51089 +
51090 + If this option prevents a legitimate use of auto-loading for a
51091 + non-root user, the administrator can execute modprobe manually
51092 + with the exact name of the module mentioned in the alert log.
51093 + Alternatively, the administrator can add the module to the list
51094 + of modules loaded at boot by modifying init scripts.
51095 +
51096 + Modification of init scripts will most likely be needed on
51097 + Ubuntu servers with encrypted home directory support enabled,
51098 + as the first non-root user logging in will cause the ecb(aes),
51099 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
51100 +
51101 +config GRKERNSEC_HIDESYM
51102 + bool "Hide kernel symbols"
51103 + help
51104 + If you say Y here, getting information on loaded modules, and
51105 + displaying all kernel symbols through a syscall will be restricted
51106 + to users with CAP_SYS_MODULE. For software compatibility reasons,
51107 + /proc/kallsyms will be restricted to the root user. The RBAC
51108 + system can hide that entry even from root.
51109 +
51110 + This option also prevents leaking of kernel addresses through
51111 + several /proc entries.
51112 +
51113 + Note that this option is only effective provided the following
51114 + conditions are met:
51115 + 1) The kernel using grsecurity is not precompiled by some distribution
51116 + 2) You have also enabled GRKERNSEC_DMESG
51117 + 3) You are using the RBAC system and hiding other files such as your
51118 + kernel image and System.map. Alternatively, enabling this option
51119 + causes the permissions on /boot, /lib/modules, and the kernel
51120 + source directory to change at compile time to prevent
51121 + reading by non-root users.
51122 + If the above conditions are met, this option will aid in providing a
51123 + useful protection against local kernel exploitation of overflows
51124 + and arbitrary read/write vulnerabilities.
51125 +
51126 +config GRKERNSEC_KERN_LOCKOUT
51127 + bool "Active kernel exploit response"
51128 + depends on X86 || ARM || PPC || SPARC
51129 + help
51130 + If you say Y here, when a PaX alert is triggered due to suspicious
51131 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
51132 + or an OOPs occurs due to bad memory accesses, instead of just
51133 + terminating the offending process (and potentially allowing
51134 + a subsequent exploit from the same user), we will take one of two
51135 + actions:
51136 + If the user was root, we will panic the system
51137 + If the user was non-root, we will log the attempt, terminate
51138 + all processes owned by the user, then prevent them from creating
51139 + any new processes until the system is restarted
51140 + This deters repeated kernel exploitation/bruteforcing attempts
51141 + and is useful for later forensics.
51142 +
51143 +endmenu
51144 +menu "Role Based Access Control Options"
51145 +depends on GRKERNSEC
51146 +
51147 +config GRKERNSEC_RBAC_DEBUG
51148 + bool
51149 +
51150 +config GRKERNSEC_NO_RBAC
51151 + bool "Disable RBAC system"
51152 + help
51153 + If you say Y here, the /dev/grsec device will be removed from the kernel,
51154 + preventing the RBAC system from being enabled. You should only say Y
51155 + here if you have no intention of using the RBAC system, so as to prevent
51156 + an attacker with root access from misusing the RBAC system to hide files
51157 + and processes when loadable module support and /dev/[k]mem have been
51158 + locked down.
51159 +
51160 +config GRKERNSEC_ACL_HIDEKERN
51161 + bool "Hide kernel processes"
51162 + help
51163 + If you say Y here, all kernel threads will be hidden to all
51164 + processes but those whose subject has the "view hidden processes"
51165 + flag.
51166 +
51167 +config GRKERNSEC_ACL_MAXTRIES
51168 + int "Maximum tries before password lockout"
51169 + default 3
51170 + help
51171 + This option enforces the maximum number of times a user can attempt
51172 + to authorize themselves with the grsecurity RBAC system before being
51173 + denied the ability to attempt authorization again for a specified time.
51174 + The lower the number, the harder it will be to brute-force a password.
51175 +
51176 +config GRKERNSEC_ACL_TIMEOUT
51177 + int "Time to wait after max password tries, in seconds"
51178 + default 30
51179 + help
51180 + This option specifies the time the user must wait after attempting to
51181 + authorize to the RBAC system with the maximum number of invalid
51182 + passwords. The higher the number, the harder it will be to brute-force
51183 + a password.
51184 +
51185 +endmenu
51186 +menu "Filesystem Protections"
51187 +depends on GRKERNSEC
51188 +
51189 +config GRKERNSEC_PROC
51190 + bool "Proc restrictions"
51191 + help
51192 + If you say Y here, the permissions of the /proc filesystem
51193 + will be altered to enhance system security and privacy. You MUST
51194 + choose either a user only restriction or a user and group restriction.
51195 + Depending upon the option you choose, you can either restrict users to
51196 + see only the processes they themselves run, or choose a group that can
51197 + view all processes and files normally restricted to root if you choose
51198 + the "restrict to user only" option. NOTE: If you're running identd as
51199 + a non-root user, you will have to run it as the group you specify here.
51200 +
51201 +config GRKERNSEC_PROC_USER
51202 + bool "Restrict /proc to user only"
51203 + depends on GRKERNSEC_PROC
51204 + help
51205 + If you say Y here, non-root users will only be able to view their own
51206 + processes, and restricts them from viewing network-related information,
51207 + and viewing kernel symbol and module information.
51208 +
51209 +config GRKERNSEC_PROC_USERGROUP
51210 + bool "Allow special group"
51211 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
51212 + help
51213 + If you say Y here, you will be able to select a group that will be
51214 + able to view all processes and network-related information. If you've
51215 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
51216 + remain hidden. This option is useful if you want to run identd as
51217 + a non-root user.
51218 +
51219 +config GRKERNSEC_PROC_GID
51220 + int "GID for special group"
51221 + depends on GRKERNSEC_PROC_USERGROUP
51222 + default 1001
51223 +
51224 +config GRKERNSEC_PROC_ADD
51225 + bool "Additional restrictions"
51226 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51227 + help
51228 + If you say Y here, additional restrictions will be placed on
51229 + /proc that keep normal users from viewing device information and
51230 + slabinfo information that could be useful for exploits.
51231 +
51232 +config GRKERNSEC_LINK
51233 + bool "Linking restrictions"
51234 + help
51235 + If you say Y here, /tmp race exploits will be prevented, since users
51236 + will no longer be able to follow symlinks owned by other users in
51237 + world-writable +t directories (e.g. /tmp), unless the owner of the
51238 + symlink is the owner of the directory. users will also not be
51239 + able to hardlink to files they do not own. If the sysctl option is
51240 + enabled, a sysctl option with name "linking_restrictions" is created.
51241 +
51242 +config GRKERNSEC_FIFO
51243 + bool "FIFO restrictions"
51244 + help
51245 + If you say Y here, users will not be able to write to FIFOs they don't
51246 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51247 + the FIFO is the same owner of the directory it's held in. If the sysctl
51248 + option is enabled, a sysctl option with name "fifo_restrictions" is
51249 + created.
51250 +
51251 +config GRKERNSEC_SYSFS_RESTRICT
51252 + bool "Sysfs/debugfs restriction"
51253 + depends on SYSFS
51254 + help
51255 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51256 + any filesystem normally mounted under it (e.g. debugfs) will only
51257 + be accessible by root. These filesystems generally provide access
51258 + to hardware and debug information that isn't appropriate for unprivileged
51259 + users of the system. Sysfs and debugfs have also become a large source
51260 + of new vulnerabilities, ranging from infoleaks to local compromise.
51261 + There has been very little oversight with an eye toward security involved
51262 + in adding new exporters of information to these filesystems, so their
51263 + use is discouraged.
51264 + This option is equivalent to a chmod 0700 of the mount paths.
51265 +
51266 +config GRKERNSEC_ROFS
51267 + bool "Runtime read-only mount protection"
51268 + help
51269 + If you say Y here, a sysctl option with name "romount_protect" will
51270 + be created. By setting this option to 1 at runtime, filesystems
51271 + will be protected in the following ways:
51272 + * No new writable mounts will be allowed
51273 + * Existing read-only mounts won't be able to be remounted read/write
51274 + * Write operations will be denied on all block devices
51275 + This option acts independently of grsec_lock: once it is set to 1,
51276 + it cannot be turned off. Therefore, please be mindful of the resulting
51277 + behavior if this option is enabled in an init script on a read-only
51278 + filesystem. This feature is mainly intended for secure embedded systems.
51279 +
51280 +config GRKERNSEC_CHROOT
51281 + bool "Chroot jail restrictions"
51282 + help
51283 + If you say Y here, you will be able to choose several options that will
51284 + make breaking out of a chrooted jail much more difficult. If you
51285 + encounter no software incompatibilities with the following options, it
51286 + is recommended that you enable each one.
51287 +
51288 +config GRKERNSEC_CHROOT_MOUNT
51289 + bool "Deny mounts"
51290 + depends on GRKERNSEC_CHROOT
51291 + help
51292 + If you say Y here, processes inside a chroot will not be able to
51293 + mount or remount filesystems. If the sysctl option is enabled, a
51294 + sysctl option with name "chroot_deny_mount" is created.
51295 +
51296 +config GRKERNSEC_CHROOT_DOUBLE
51297 + bool "Deny double-chroots"
51298 + depends on GRKERNSEC_CHROOT
51299 + help
51300 + If you say Y here, processes inside a chroot will not be able to chroot
51301 + again outside the chroot. This is a widely used method of breaking
51302 + out of a chroot jail and should not be allowed. If the sysctl
51303 + option is enabled, a sysctl option with name
51304 + "chroot_deny_chroot" is created.
51305 +
51306 +config GRKERNSEC_CHROOT_PIVOT
51307 + bool "Deny pivot_root in chroot"
51308 + depends on GRKERNSEC_CHROOT
51309 + help
51310 + If you say Y here, processes inside a chroot will not be able to use
51311 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51312 + works similar to chroot in that it changes the root filesystem. This
51313 + function could be misused in a chrooted process to attempt to break out
51314 + of the chroot, and therefore should not be allowed. If the sysctl
51315 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51316 + created.
51317 +
51318 +config GRKERNSEC_CHROOT_CHDIR
51319 + bool "Enforce chdir(\"/\") on all chroots"
51320 + depends on GRKERNSEC_CHROOT
51321 + help
51322 + If you say Y here, the current working directory of all newly-chrooted
51323 + applications will be set to the the root directory of the chroot.
51324 + The man page on chroot(2) states:
51325 + Note that this call does not change the current working
51326 + directory, so that `.' can be outside the tree rooted at
51327 + `/'. In particular, the super-user can escape from a
51328 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51329 +
51330 + It is recommended that you say Y here, since it's not known to break
51331 + any software. If the sysctl option is enabled, a sysctl option with
51332 + name "chroot_enforce_chdir" is created.
51333 +
51334 +config GRKERNSEC_CHROOT_CHMOD
51335 + bool "Deny (f)chmod +s"
51336 + depends on GRKERNSEC_CHROOT
51337 + help
51338 + If you say Y here, processes inside a chroot will not be able to chmod
51339 + or fchmod files to make them have suid or sgid bits. This protects
51340 + against another published method of breaking a chroot. If the sysctl
51341 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51342 + created.
51343 +
51344 +config GRKERNSEC_CHROOT_FCHDIR
51345 + bool "Deny fchdir out of chroot"
51346 + depends on GRKERNSEC_CHROOT
51347 + help
51348 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51349 + to a file descriptor of the chrooting process that points to a directory
51350 + outside the filesystem will be stopped. If the sysctl option
51351 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51352 +
51353 +config GRKERNSEC_CHROOT_MKNOD
51354 + bool "Deny mknod"
51355 + depends on GRKERNSEC_CHROOT
51356 + help
51357 + If you say Y here, processes inside a chroot will not be allowed to
51358 + mknod. The problem with using mknod inside a chroot is that it
51359 + would allow an attacker to create a device entry that is the same
51360 + as one on the physical root of your system, which could range from
51361 + anything from the console device to a device for your harddrive (which
51362 + they could then use to wipe the drive or steal data). It is recommended
51363 + that you say Y here, unless you run into software incompatibilities.
51364 + If the sysctl option is enabled, a sysctl option with name
51365 + "chroot_deny_mknod" is created.
51366 +
51367 +config GRKERNSEC_CHROOT_SHMAT
51368 + bool "Deny shmat() out of chroot"
51369 + depends on GRKERNSEC_CHROOT
51370 + help
51371 + If you say Y here, processes inside a chroot will not be able to attach
51372 + to shared memory segments that were created outside of the chroot jail.
51373 + It is recommended that you say Y here. If the sysctl option is enabled,
51374 + a sysctl option with name "chroot_deny_shmat" is created.
51375 +
51376 +config GRKERNSEC_CHROOT_UNIX
51377 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51378 + depends on GRKERNSEC_CHROOT
51379 + help
51380 + If you say Y here, processes inside a chroot will not be able to
51381 + connect to abstract (meaning not belonging to a filesystem) Unix
51382 + domain sockets that were bound outside of a chroot. It is recommended
51383 + that you say Y here. If the sysctl option is enabled, a sysctl option
51384 + with name "chroot_deny_unix" is created.
51385 +
51386 +config GRKERNSEC_CHROOT_FINDTASK
51387 + bool "Protect outside processes"
51388 + depends on GRKERNSEC_CHROOT
51389 + help
51390 + If you say Y here, processes inside a chroot will not be able to
51391 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51392 + getsid, or view any process outside of the chroot. If the sysctl
51393 + option is enabled, a sysctl option with name "chroot_findtask" is
51394 + created.
51395 +
51396 +config GRKERNSEC_CHROOT_NICE
51397 + bool "Restrict priority changes"
51398 + depends on GRKERNSEC_CHROOT
51399 + help
51400 + If you say Y here, processes inside a chroot will not be able to raise
51401 + the priority of processes in the chroot, or alter the priority of
51402 + processes outside the chroot. This provides more security than simply
51403 + removing CAP_SYS_NICE from the process' capability set. If the
51404 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51405 + is created.
51406 +
51407 +config GRKERNSEC_CHROOT_SYSCTL
51408 + bool "Deny sysctl writes"
51409 + depends on GRKERNSEC_CHROOT
51410 + help
51411 + If you say Y here, an attacker in a chroot will not be able to
51412 + write to sysctl entries, either by sysctl(2) or through a /proc
51413 + interface. It is strongly recommended that you say Y here. If the
51414 + sysctl option is enabled, a sysctl option with name
51415 + "chroot_deny_sysctl" is created.
51416 +
51417 +config GRKERNSEC_CHROOT_CAPS
51418 + bool "Capability restrictions"
51419 + depends on GRKERNSEC_CHROOT
51420 + help
51421 + If you say Y here, the capabilities on all processes within a
51422 + chroot jail will be lowered to stop module insertion, raw i/o,
51423 + system and net admin tasks, rebooting the system, modifying immutable
51424 + files, modifying IPC owned by another, and changing the system time.
51425 + This is left an option because it can break some apps. Disable this
51426 + if your chrooted apps are having problems performing those kinds of
51427 + tasks. If the sysctl option is enabled, a sysctl option with
51428 + name "chroot_caps" is created.
51429 +
51430 +endmenu
51431 +menu "Kernel Auditing"
51432 +depends on GRKERNSEC
51433 +
51434 +config GRKERNSEC_AUDIT_GROUP
51435 + bool "Single group for auditing"
51436 + help
51437 + If you say Y here, the exec, chdir, and (un)mount logging features
51438 + will only operate on a group you specify. This option is recommended
51439 + if you only want to watch certain users instead of having a large
51440 + amount of logs from the entire system. If the sysctl option is enabled,
51441 + a sysctl option with name "audit_group" is created.
51442 +
51443 +config GRKERNSEC_AUDIT_GID
51444 + int "GID for auditing"
51445 + depends on GRKERNSEC_AUDIT_GROUP
51446 + default 1007
51447 +
51448 +config GRKERNSEC_EXECLOG
51449 + bool "Exec logging"
51450 + help
51451 + If you say Y here, all execve() calls will be logged (since the
51452 + other exec*() calls are frontends to execve(), all execution
51453 + will be logged). Useful for shell-servers that like to keep track
51454 + of their users. If the sysctl option is enabled, a sysctl option with
51455 + name "exec_logging" is created.
51456 + WARNING: This option when enabled will produce a LOT of logs, especially
51457 + on an active system.
51458 +
51459 +config GRKERNSEC_RESLOG
51460 + bool "Resource logging"
51461 + help
51462 + If you say Y here, all attempts to overstep resource limits will
51463 + be logged with the resource name, the requested size, and the current
51464 + limit. It is highly recommended that you say Y here. If the sysctl
51465 + option is enabled, a sysctl option with name "resource_logging" is
51466 + created. If the RBAC system is enabled, the sysctl value is ignored.
51467 +
51468 +config GRKERNSEC_CHROOT_EXECLOG
51469 + bool "Log execs within chroot"
51470 + help
51471 + If you say Y here, all executions inside a chroot jail will be logged
51472 + to syslog. This can cause a large amount of logs if certain
51473 + applications (eg. djb's daemontools) are installed on the system, and
51474 + is therefore left as an option. If the sysctl option is enabled, a
51475 + sysctl option with name "chroot_execlog" is created.
51476 +
51477 +config GRKERNSEC_AUDIT_PTRACE
51478 + bool "Ptrace logging"
51479 + help
51480 + If you say Y here, all attempts to attach to a process via ptrace
51481 + will be logged. If the sysctl option is enabled, a sysctl option
51482 + with name "audit_ptrace" is created.
51483 +
51484 +config GRKERNSEC_AUDIT_CHDIR
51485 + bool "Chdir logging"
51486 + help
51487 + If you say Y here, all chdir() calls will be logged. If the sysctl
51488 + option is enabled, a sysctl option with name "audit_chdir" is created.
51489 +
51490 +config GRKERNSEC_AUDIT_MOUNT
51491 + bool "(Un)Mount logging"
51492 + help
51493 + If you say Y here, all mounts and unmounts will be logged. If the
51494 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51495 + created.
51496 +
51497 +config GRKERNSEC_SIGNAL
51498 + bool "Signal logging"
51499 + help
51500 + If you say Y here, certain important signals will be logged, such as
51501 + SIGSEGV, which will as a result inform you of when a error in a program
51502 + occurred, which in some cases could mean a possible exploit attempt.
51503 + If the sysctl option is enabled, a sysctl option with name
51504 + "signal_logging" is created.
51505 +
51506 +config GRKERNSEC_FORKFAIL
51507 + bool "Fork failure logging"
51508 + help
51509 + If you say Y here, all failed fork() attempts will be logged.
51510 + This could suggest a fork bomb, or someone attempting to overstep
51511 + their process limit. If the sysctl option is enabled, a sysctl option
51512 + with name "forkfail_logging" is created.
51513 +
51514 +config GRKERNSEC_TIME
51515 + bool "Time change logging"
51516 + help
51517 + If you say Y here, any changes of the system clock will be logged.
51518 + If the sysctl option is enabled, a sysctl option with name
51519 + "timechange_logging" is created.
51520 +
51521 +config GRKERNSEC_PROC_IPADDR
51522 + bool "/proc/<pid>/ipaddr support"
51523 + help
51524 + If you say Y here, a new entry will be added to each /proc/<pid>
51525 + directory that contains the IP address of the person using the task.
51526 + The IP is carried across local TCP and AF_UNIX stream sockets.
51527 + This information can be useful for IDS/IPSes to perform remote response
51528 + to a local attack. The entry is readable by only the owner of the
51529 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51530 + the RBAC system), and thus does not create privacy concerns.
51531 +
51532 +config GRKERNSEC_RWXMAP_LOG
51533 + bool 'Denied RWX mmap/mprotect logging'
51534 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51535 + help
51536 + If you say Y here, calls to mmap() and mprotect() with explicit
51537 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51538 + denied by the PAX_MPROTECT feature. If the sysctl option is
51539 + enabled, a sysctl option with name "rwxmap_logging" is created.
51540 +
51541 +config GRKERNSEC_AUDIT_TEXTREL
51542 + bool 'ELF text relocations logging (READ HELP)'
51543 + depends on PAX_MPROTECT
51544 + help
51545 + If you say Y here, text relocations will be logged with the filename
51546 + of the offending library or binary. The purpose of the feature is
51547 + to help Linux distribution developers get rid of libraries and
51548 + binaries that need text relocations which hinder the future progress
51549 + of PaX. Only Linux distribution developers should say Y here, and
51550 + never on a production machine, as this option creates an information
51551 + leak that could aid an attacker in defeating the randomization of
51552 + a single memory region. If the sysctl option is enabled, a sysctl
51553 + option with name "audit_textrel" is created.
51554 +
51555 +endmenu
51556 +
51557 +menu "Executable Protections"
51558 +depends on GRKERNSEC
51559 +
51560 +config GRKERNSEC_DMESG
51561 + bool "Dmesg(8) restriction"
51562 + help
51563 + If you say Y here, non-root users will not be able to use dmesg(8)
51564 + to view up to the last 4kb of messages in the kernel's log buffer.
51565 + The kernel's log buffer often contains kernel addresses and other
51566 + identifying information useful to an attacker in fingerprinting a
51567 + system for a targeted exploit.
51568 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51569 + created.
51570 +
51571 +config GRKERNSEC_HARDEN_PTRACE
51572 + bool "Deter ptrace-based process snooping"
51573 + help
51574 + If you say Y here, TTY sniffers and other malicious monitoring
51575 + programs implemented through ptrace will be defeated. If you
51576 + have been using the RBAC system, this option has already been
51577 + enabled for several years for all users, with the ability to make
51578 + fine-grained exceptions.
51579 +
51580 + This option only affects the ability of non-root users to ptrace
51581 + processes that are not a descendent of the ptracing process.
51582 + This means that strace ./binary and gdb ./binary will still work,
51583 + but attaching to arbitrary processes will not. If the sysctl
51584 + option is enabled, a sysctl option with name "harden_ptrace" is
51585 + created.
51586 +
51587 +config GRKERNSEC_TPE
51588 + bool "Trusted Path Execution (TPE)"
51589 + help
51590 + If you say Y here, you will be able to choose a gid to add to the
51591 + supplementary groups of users you want to mark as "untrusted."
51592 + These users will not be able to execute any files that are not in
51593 + root-owned directories writable only by root. If the sysctl option
51594 + is enabled, a sysctl option with name "tpe" is created.
51595 +
51596 +config GRKERNSEC_TPE_ALL
51597 + bool "Partially restrict all non-root users"
51598 + depends on GRKERNSEC_TPE
51599 + help
51600 + If you say Y here, all non-root users will be covered under
51601 + a weaker TPE restriction. This is separate from, and in addition to,
51602 + the main TPE options that you have selected elsewhere. Thus, if a
51603 + "trusted" GID is chosen, this restriction applies to even that GID.
51604 + Under this restriction, all non-root users will only be allowed to
51605 + execute files in directories they own that are not group or
51606 + world-writable, or in directories owned by root and writable only by
51607 + root. If the sysctl option is enabled, a sysctl option with name
51608 + "tpe_restrict_all" is created.
51609 +
51610 +config GRKERNSEC_TPE_INVERT
51611 + bool "Invert GID option"
51612 + depends on GRKERNSEC_TPE
51613 + help
51614 + If you say Y here, the group you specify in the TPE configuration will
51615 + decide what group TPE restrictions will be *disabled* for. This
51616 + option is useful if you want TPE restrictions to be applied to most
51617 + users on the system. If the sysctl option is enabled, a sysctl option
51618 + with name "tpe_invert" is created. Unlike other sysctl options, this
51619 + entry will default to on for backward-compatibility.
51620 +
51621 +config GRKERNSEC_TPE_GID
51622 + int "GID for untrusted users"
51623 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51624 + default 1005
51625 + help
51626 + Setting this GID determines what group TPE restrictions will be
51627 + *enabled* for. If the sysctl option is enabled, a sysctl option
51628 + with name "tpe_gid" is created.
51629 +
51630 +config GRKERNSEC_TPE_GID
51631 + int "GID for trusted users"
51632 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51633 + default 1005
51634 + help
51635 + Setting this GID determines what group TPE restrictions will be
51636 + *disabled* for. If the sysctl option is enabled, a sysctl option
51637 + with name "tpe_gid" is created.
51638 +
51639 +endmenu
51640 +menu "Network Protections"
51641 +depends on GRKERNSEC
51642 +
51643 +config GRKERNSEC_RANDNET
51644 + bool "Larger entropy pools"
51645 + help
51646 + If you say Y here, the entropy pools used for many features of Linux
51647 + and grsecurity will be doubled in size. Since several grsecurity
51648 + features use additional randomness, it is recommended that you say Y
51649 + here. Saying Y here has a similar effect as modifying
51650 + /proc/sys/kernel/random/poolsize.
51651 +
51652 +config GRKERNSEC_BLACKHOLE
51653 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51654 + depends on NET
51655 + help
51656 + If you say Y here, neither TCP resets nor ICMP
51657 + destination-unreachable packets will be sent in response to packets
51658 + sent to ports for which no associated listening process exists.
51659 + This feature supports both IPV4 and IPV6 and exempts the
51660 + loopback interface from blackholing. Enabling this feature
51661 + makes a host more resilient to DoS attacks and reduces network
51662 + visibility against scanners.
51663 +
51664 + The blackhole feature as-implemented is equivalent to the FreeBSD
51665 + blackhole feature, as it prevents RST responses to all packets, not
51666 + just SYNs. Under most application behavior this causes no
51667 + problems, but applications (like haproxy) may not close certain
51668 + connections in a way that cleanly terminates them on the remote
51669 + end, leaving the remote host in LAST_ACK state. Because of this
51670 + side-effect and to prevent intentional LAST_ACK DoSes, this
51671 + feature also adds automatic mitigation against such attacks.
51672 + The mitigation drastically reduces the amount of time a socket
51673 + can spend in LAST_ACK state. If you're using haproxy and not
51674 + all servers it connects to have this option enabled, consider
51675 + disabling this feature on the haproxy host.
51676 +
51677 + If the sysctl option is enabled, two sysctl options with names
51678 + "ip_blackhole" and "lastack_retries" will be created.
51679 + While "ip_blackhole" takes the standard zero/non-zero on/off
51680 + toggle, "lastack_retries" uses the same kinds of values as
51681 + "tcp_retries1" and "tcp_retries2". The default value of 4
51682 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51683 + state.
51684 +
51685 +config GRKERNSEC_SOCKET
51686 + bool "Socket restrictions"
51687 + depends on NET
51688 + help
51689 + If you say Y here, you will be able to choose from several options.
51690 + If you assign a GID on your system and add it to the supplementary
51691 + groups of users you want to restrict socket access to, this patch
51692 + will perform up to three things, based on the option(s) you choose.
51693 +
51694 +config GRKERNSEC_SOCKET_ALL
51695 + bool "Deny any sockets to group"
51696 + depends on GRKERNSEC_SOCKET
51697 + help
51698 + If you say Y here, you will be able to choose a GID of whose users will
51699 + be unable to connect to other hosts from your machine or run server
51700 + applications from your machine. If the sysctl option is enabled, a
51701 + sysctl option with name "socket_all" is created.
51702 +
51703 +config GRKERNSEC_SOCKET_ALL_GID
51704 + int "GID to deny all sockets for"
51705 + depends on GRKERNSEC_SOCKET_ALL
51706 + default 1004
51707 + help
51708 + Here you can choose the GID to disable socket access for. Remember to
51709 + add the users you want socket access disabled for to the GID
51710 + specified here. If the sysctl option is enabled, a sysctl option
51711 + with name "socket_all_gid" is created.
51712 +
51713 +config GRKERNSEC_SOCKET_CLIENT
51714 + bool "Deny client sockets to group"
51715 + depends on GRKERNSEC_SOCKET
51716 + help
51717 + If you say Y here, you will be able to choose a GID of whose users will
51718 + be unable to connect to other hosts from your machine, but will be
51719 + able to run servers. If this option is enabled, all users in the group
51720 + you specify will have to use passive mode when initiating ftp transfers
51721 + from the shell on your machine. If the sysctl option is enabled, a
51722 + sysctl option with name "socket_client" is created.
51723 +
51724 +config GRKERNSEC_SOCKET_CLIENT_GID
51725 + int "GID to deny client sockets for"
51726 + depends on GRKERNSEC_SOCKET_CLIENT
51727 + default 1003
51728 + help
51729 + Here you can choose the GID to disable client socket access for.
51730 + Remember to add the users you want client socket access disabled for to
51731 + the GID specified here. If the sysctl option is enabled, a sysctl
51732 + option with name "socket_client_gid" is created.
51733 +
51734 +config GRKERNSEC_SOCKET_SERVER
51735 + bool "Deny server sockets to group"
51736 + depends on GRKERNSEC_SOCKET
51737 + help
51738 + If you say Y here, you will be able to choose a GID of whose users will
51739 + be unable to run server applications from your machine. If the sysctl
51740 + option is enabled, a sysctl option with name "socket_server" is created.
51741 +
51742 +config GRKERNSEC_SOCKET_SERVER_GID
51743 + int "GID to deny server sockets for"
51744 + depends on GRKERNSEC_SOCKET_SERVER
51745 + default 1002
51746 + help
51747 + Here you can choose the GID to disable server socket access for.
51748 + Remember to add the users you want server socket access disabled for to
51749 + the GID specified here. If the sysctl option is enabled, a sysctl
51750 + option with name "socket_server_gid" is created.
51751 +
51752 +endmenu
51753 +menu "Sysctl support"
51754 +depends on GRKERNSEC && SYSCTL
51755 +
51756 +config GRKERNSEC_SYSCTL
51757 + bool "Sysctl support"
51758 + help
51759 + If you say Y here, you will be able to change the options that
51760 + grsecurity runs with at bootup, without having to recompile your
51761 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51762 + to enable (1) or disable (0) various features. All the sysctl entries
51763 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51764 + All features enabled in the kernel configuration are disabled at boot
51765 + if you do not say Y to the "Turn on features by default" option.
51766 + All options should be set at startup, and the grsec_lock entry should
51767 + be set to a non-zero value after all the options are set.
51768 + *THIS IS EXTREMELY IMPORTANT*
51769 +
51770 +config GRKERNSEC_SYSCTL_DISTRO
51771 + bool "Extra sysctl support for distro makers (READ HELP)"
51772 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51773 + help
51774 + If you say Y here, additional sysctl options will be created
51775 + for features that affect processes running as root. Therefore,
51776 + it is critical when using this option that the grsec_lock entry be
51777 + enabled after boot. Only distros with prebuilt kernel packages
51778 + with this option enabled that can ensure grsec_lock is enabled
51779 + after boot should use this option.
51780 + *Failure to set grsec_lock after boot makes all grsec features
51781 + this option covers useless*
51782 +
51783 + Currently this option creates the following sysctl entries:
51784 + "Disable Privileged I/O": "disable_priv_io"
51785 +
51786 +config GRKERNSEC_SYSCTL_ON
51787 + bool "Turn on features by default"
51788 + depends on GRKERNSEC_SYSCTL
51789 + help
51790 + If you say Y here, instead of having all features enabled in the
51791 + kernel configuration disabled at boot time, the features will be
51792 + enabled at boot time. It is recommended you say Y here unless
51793 + there is some reason you would want all sysctl-tunable features to
51794 + be disabled by default. As mentioned elsewhere, it is important
51795 + to enable the grsec_lock entry once you have finished modifying
51796 + the sysctl entries.
51797 +
51798 +endmenu
51799 +menu "Logging Options"
51800 +depends on GRKERNSEC
51801 +
51802 +config GRKERNSEC_FLOODTIME
51803 + int "Seconds in between log messages (minimum)"
51804 + default 10
51805 + help
51806 + This option allows you to enforce the number of seconds between
51807 + grsecurity log messages. The default should be suitable for most
51808 + people, however, if you choose to change it, choose a value small enough
51809 + to allow informative logs to be produced, but large enough to
51810 + prevent flooding.
51811 +
51812 +config GRKERNSEC_FLOODBURST
51813 + int "Number of messages in a burst (maximum)"
51814 + default 6
51815 + help
51816 + This option allows you to choose the maximum number of messages allowed
51817 + within the flood time interval you chose in a separate option. The
51818 + default should be suitable for most people, however if you find that
51819 + many of your logs are being interpreted as flooding, you may want to
51820 + raise this value.
51821 +
51822 +endmenu
51823 +
51824 +endmenu
51825 diff -urNp linux-2.6.32.46/grsecurity/Makefile linux-2.6.32.46/grsecurity/Makefile
51826 --- linux-2.6.32.46/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
51827 +++ linux-2.6.32.46/grsecurity/Makefile 2011-10-17 06:48:36.000000000 -0400
51828 @@ -0,0 +1,36 @@
51829 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51830 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51831 +# into an RBAC system
51832 +#
51833 +# All code in this directory and various hooks inserted throughout the kernel
51834 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51835 +# under the GPL v2 or higher
51836 +
51837 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51838 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51839 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51840 +
51841 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51842 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51843 + gracl_learn.o grsec_log.o
51844 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51845 +
51846 +ifdef CONFIG_NET
51847 +obj-y += grsec_sock.o
51848 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51849 +endif
51850 +
51851 +ifndef CONFIG_GRKERNSEC
51852 +obj-y += grsec_disabled.o
51853 +endif
51854 +
51855 +ifdef CONFIG_GRKERNSEC_HIDESYM
51856 +extra-y := grsec_hidesym.o
51857 +$(obj)/grsec_hidesym.o:
51858 + @-chmod -f 500 /boot
51859 + @-chmod -f 500 /lib/modules
51860 + @-chmod -f 500 /lib64/modules
51861 + @-chmod -f 500 /lib32/modules
51862 + @-chmod -f 700 .
51863 + @echo ' grsec: protected kernel image paths'
51864 +endif
51865 diff -urNp linux-2.6.32.46/grsecurity/gracl.c linux-2.6.32.46/grsecurity/gracl.c
51866 --- linux-2.6.32.46/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
51867 +++ linux-2.6.32.46/grsecurity/gracl.c 2011-10-17 07:04:31.000000000 -0400
51868 @@ -0,0 +1,4140 @@
51869 +#include <linux/kernel.h>
51870 +#include <linux/module.h>
51871 +#include <linux/sched.h>
51872 +#include <linux/mm.h>
51873 +#include <linux/file.h>
51874 +#include <linux/fs.h>
51875 +#include <linux/namei.h>
51876 +#include <linux/mount.h>
51877 +#include <linux/tty.h>
51878 +#include <linux/proc_fs.h>
51879 +#include <linux/smp_lock.h>
51880 +#include <linux/slab.h>
51881 +#include <linux/vmalloc.h>
51882 +#include <linux/types.h>
51883 +#include <linux/sysctl.h>
51884 +#include <linux/netdevice.h>
51885 +#include <linux/ptrace.h>
51886 +#include <linux/gracl.h>
51887 +#include <linux/gralloc.h>
51888 +#include <linux/grsecurity.h>
51889 +#include <linux/grinternal.h>
51890 +#include <linux/pid_namespace.h>
51891 +#include <linux/fdtable.h>
51892 +#include <linux/percpu.h>
51893 +
51894 +#include <asm/uaccess.h>
51895 +#include <asm/errno.h>
51896 +#include <asm/mman.h>
51897 +
51898 +static struct acl_role_db acl_role_set;
51899 +static struct name_db name_set;
51900 +static struct inodev_db inodev_set;
51901 +
51902 +/* for keeping track of userspace pointers used for subjects, so we
51903 + can share references in the kernel as well
51904 +*/
51905 +
51906 +static struct dentry *real_root;
51907 +static struct vfsmount *real_root_mnt;
51908 +
51909 +static struct acl_subj_map_db subj_map_set;
51910 +
51911 +static struct acl_role_label *default_role;
51912 +
51913 +static struct acl_role_label *role_list;
51914 +
51915 +static u16 acl_sp_role_value;
51916 +
51917 +extern char *gr_shared_page[4];
51918 +static DEFINE_MUTEX(gr_dev_mutex);
51919 +DEFINE_RWLOCK(gr_inode_lock);
51920 +
51921 +struct gr_arg *gr_usermode;
51922 +
51923 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51924 +
51925 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51926 +extern void gr_clear_learn_entries(void);
51927 +
51928 +#ifdef CONFIG_GRKERNSEC_RESLOG
51929 +extern void gr_log_resource(const struct task_struct *task,
51930 + const int res, const unsigned long wanted, const int gt);
51931 +#endif
51932 +
51933 +unsigned char *gr_system_salt;
51934 +unsigned char *gr_system_sum;
51935 +
51936 +static struct sprole_pw **acl_special_roles = NULL;
51937 +static __u16 num_sprole_pws = 0;
51938 +
51939 +static struct acl_role_label *kernel_role = NULL;
51940 +
51941 +static unsigned int gr_auth_attempts = 0;
51942 +static unsigned long gr_auth_expires = 0UL;
51943 +
51944 +#ifdef CONFIG_NET
51945 +extern struct vfsmount *sock_mnt;
51946 +#endif
51947 +extern struct vfsmount *pipe_mnt;
51948 +extern struct vfsmount *shm_mnt;
51949 +#ifdef CONFIG_HUGETLBFS
51950 +extern struct vfsmount *hugetlbfs_vfsmount;
51951 +#endif
51952 +
51953 +static struct acl_object_label *fakefs_obj_rw;
51954 +static struct acl_object_label *fakefs_obj_rwx;
51955 +
51956 +extern int gr_init_uidset(void);
51957 +extern void gr_free_uidset(void);
51958 +extern void gr_remove_uid(uid_t uid);
51959 +extern int gr_find_uid(uid_t uid);
51960 +
51961 +__inline__ int
51962 +gr_acl_is_enabled(void)
51963 +{
51964 + return (gr_status & GR_READY);
51965 +}
51966 +
51967 +#ifdef CONFIG_BTRFS_FS
51968 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51969 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51970 +#endif
51971 +
51972 +static inline dev_t __get_dev(const struct dentry *dentry)
51973 +{
51974 +#ifdef CONFIG_BTRFS_FS
51975 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51976 + return get_btrfs_dev_from_inode(dentry->d_inode);
51977 + else
51978 +#endif
51979 + return dentry->d_inode->i_sb->s_dev;
51980 +}
51981 +
51982 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51983 +{
51984 + return __get_dev(dentry);
51985 +}
51986 +
51987 +static char gr_task_roletype_to_char(struct task_struct *task)
51988 +{
51989 + switch (task->role->roletype &
51990 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51991 + GR_ROLE_SPECIAL)) {
51992 + case GR_ROLE_DEFAULT:
51993 + return 'D';
51994 + case GR_ROLE_USER:
51995 + return 'U';
51996 + case GR_ROLE_GROUP:
51997 + return 'G';
51998 + case GR_ROLE_SPECIAL:
51999 + return 'S';
52000 + }
52001 +
52002 + return 'X';
52003 +}
52004 +
52005 +char gr_roletype_to_char(void)
52006 +{
52007 + return gr_task_roletype_to_char(current);
52008 +}
52009 +
52010 +__inline__ int
52011 +gr_acl_tpe_check(void)
52012 +{
52013 + if (unlikely(!(gr_status & GR_READY)))
52014 + return 0;
52015 + if (current->role->roletype & GR_ROLE_TPE)
52016 + return 1;
52017 + else
52018 + return 0;
52019 +}
52020 +
52021 +int
52022 +gr_handle_rawio(const struct inode *inode)
52023 +{
52024 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52025 + if (inode && S_ISBLK(inode->i_mode) &&
52026 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
52027 + !capable(CAP_SYS_RAWIO))
52028 + return 1;
52029 +#endif
52030 + return 0;
52031 +}
52032 +
52033 +static int
52034 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
52035 +{
52036 + if (likely(lena != lenb))
52037 + return 0;
52038 +
52039 + return !memcmp(a, b, lena);
52040 +}
52041 +
52042 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
52043 +{
52044 + *buflen -= namelen;
52045 + if (*buflen < 0)
52046 + return -ENAMETOOLONG;
52047 + *buffer -= namelen;
52048 + memcpy(*buffer, str, namelen);
52049 + return 0;
52050 +}
52051 +
52052 +/* this must be called with vfsmount_lock and dcache_lock held */
52053 +
52054 +static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
52055 + struct dentry *root, struct vfsmount *rootmnt,
52056 + char *buffer, int buflen)
52057 +{
52058 + char * end = buffer+buflen;
52059 + char * retval;
52060 + int namelen;
52061 +
52062 + *--end = '\0';
52063 + buflen--;
52064 +
52065 + if (buflen < 1)
52066 + goto Elong;
52067 + /* Get '/' right */
52068 + retval = end-1;
52069 + *retval = '/';
52070 +
52071 + for (;;) {
52072 + struct dentry * parent;
52073 +
52074 + if (dentry == root && vfsmnt == rootmnt)
52075 + break;
52076 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
52077 + /* Global root? */
52078 + if (vfsmnt->mnt_parent == vfsmnt)
52079 + goto global_root;
52080 + dentry = vfsmnt->mnt_mountpoint;
52081 + vfsmnt = vfsmnt->mnt_parent;
52082 + continue;
52083 + }
52084 + parent = dentry->d_parent;
52085 + prefetch(parent);
52086 + namelen = dentry->d_name.len;
52087 + buflen -= namelen + 1;
52088 + if (buflen < 0)
52089 + goto Elong;
52090 + end -= namelen;
52091 + memcpy(end, dentry->d_name.name, namelen);
52092 + *--end = '/';
52093 + retval = end;
52094 + dentry = parent;
52095 + }
52096 +
52097 +out:
52098 + return retval;
52099 +
52100 +global_root:
52101 + namelen = dentry->d_name.len;
52102 + buflen -= namelen;
52103 + if (buflen < 0)
52104 + goto Elong;
52105 + retval -= namelen-1; /* hit the slash */
52106 + memcpy(retval, dentry->d_name.name, namelen);
52107 + goto out;
52108 +Elong:
52109 + retval = ERR_PTR(-ENAMETOOLONG);
52110 + goto out;
52111 +}
52112 +
52113 +static char *
52114 +gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
52115 + struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
52116 +{
52117 + char *retval;
52118 +
52119 + retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
52120 + if (unlikely(IS_ERR(retval)))
52121 + retval = strcpy(buf, "<path too long>");
52122 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52123 + retval[1] = '\0';
52124 +
52125 + return retval;
52126 +}
52127 +
52128 +static char *
52129 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52130 + char *buf, int buflen)
52131 +{
52132 + char *res;
52133 +
52134 + /* we can use real_root, real_root_mnt, because this is only called
52135 + by the RBAC system */
52136 + res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
52137 +
52138 + return res;
52139 +}
52140 +
52141 +static char *
52142 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52143 + char *buf, int buflen)
52144 +{
52145 + char *res;
52146 + struct dentry *root;
52147 + struct vfsmount *rootmnt;
52148 + struct task_struct *reaper = &init_task;
52149 +
52150 + /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
52151 + read_lock(&reaper->fs->lock);
52152 + root = dget(reaper->fs->root.dentry);
52153 + rootmnt = mntget(reaper->fs->root.mnt);
52154 + read_unlock(&reaper->fs->lock);
52155 +
52156 + spin_lock(&dcache_lock);
52157 + spin_lock(&vfsmount_lock);
52158 + res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
52159 + spin_unlock(&vfsmount_lock);
52160 + spin_unlock(&dcache_lock);
52161 +
52162 + dput(root);
52163 + mntput(rootmnt);
52164 + return res;
52165 +}
52166 +
52167 +static char *
52168 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52169 +{
52170 + char *ret;
52171 + spin_lock(&dcache_lock);
52172 + spin_lock(&vfsmount_lock);
52173 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52174 + PAGE_SIZE);
52175 + spin_unlock(&vfsmount_lock);
52176 + spin_unlock(&dcache_lock);
52177 + return ret;
52178 +}
52179 +
52180 +static char *
52181 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52182 +{
52183 + char *ret;
52184 + char *buf;
52185 + int buflen;
52186 +
52187 + spin_lock(&dcache_lock);
52188 + spin_lock(&vfsmount_lock);
52189 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52190 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52191 + buflen = (int)(ret - buf);
52192 + if (buflen >= 5)
52193 + prepend(&ret, &buflen, "/proc", 5);
52194 + else
52195 + ret = strcpy(buf, "<path too long>");
52196 + spin_unlock(&vfsmount_lock);
52197 + spin_unlock(&dcache_lock);
52198 + return ret;
52199 +}
52200 +
52201 +char *
52202 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52203 +{
52204 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52205 + PAGE_SIZE);
52206 +}
52207 +
52208 +char *
52209 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52210 +{
52211 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52212 + PAGE_SIZE);
52213 +}
52214 +
52215 +char *
52216 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52217 +{
52218 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52219 + PAGE_SIZE);
52220 +}
52221 +
52222 +char *
52223 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52224 +{
52225 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52226 + PAGE_SIZE);
52227 +}
52228 +
52229 +char *
52230 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52231 +{
52232 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52233 + PAGE_SIZE);
52234 +}
52235 +
52236 +__inline__ __u32
52237 +to_gr_audit(const __u32 reqmode)
52238 +{
52239 + /* masks off auditable permission flags, then shifts them to create
52240 + auditing flags, and adds the special case of append auditing if
52241 + we're requesting write */
52242 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52243 +}
52244 +
52245 +struct acl_subject_label *
52246 +lookup_subject_map(const struct acl_subject_label *userp)
52247 +{
52248 + unsigned int index = shash(userp, subj_map_set.s_size);
52249 + struct subject_map *match;
52250 +
52251 + match = subj_map_set.s_hash[index];
52252 +
52253 + while (match && match->user != userp)
52254 + match = match->next;
52255 +
52256 + if (match != NULL)
52257 + return match->kernel;
52258 + else
52259 + return NULL;
52260 +}
52261 +
52262 +static void
52263 +insert_subj_map_entry(struct subject_map *subjmap)
52264 +{
52265 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52266 + struct subject_map **curr;
52267 +
52268 + subjmap->prev = NULL;
52269 +
52270 + curr = &subj_map_set.s_hash[index];
52271 + if (*curr != NULL)
52272 + (*curr)->prev = subjmap;
52273 +
52274 + subjmap->next = *curr;
52275 + *curr = subjmap;
52276 +
52277 + return;
52278 +}
52279 +
52280 +static struct acl_role_label *
52281 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52282 + const gid_t gid)
52283 +{
52284 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52285 + struct acl_role_label *match;
52286 + struct role_allowed_ip *ipp;
52287 + unsigned int x;
52288 + u32 curr_ip = task->signal->curr_ip;
52289 +
52290 + task->signal->saved_ip = curr_ip;
52291 +
52292 + match = acl_role_set.r_hash[index];
52293 +
52294 + while (match) {
52295 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52296 + for (x = 0; x < match->domain_child_num; x++) {
52297 + if (match->domain_children[x] == uid)
52298 + goto found;
52299 + }
52300 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52301 + break;
52302 + match = match->next;
52303 + }
52304 +found:
52305 + if (match == NULL) {
52306 + try_group:
52307 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52308 + match = acl_role_set.r_hash[index];
52309 +
52310 + while (match) {
52311 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52312 + for (x = 0; x < match->domain_child_num; x++) {
52313 + if (match->domain_children[x] == gid)
52314 + goto found2;
52315 + }
52316 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52317 + break;
52318 + match = match->next;
52319 + }
52320 +found2:
52321 + if (match == NULL)
52322 + match = default_role;
52323 + if (match->allowed_ips == NULL)
52324 + return match;
52325 + else {
52326 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52327 + if (likely
52328 + ((ntohl(curr_ip) & ipp->netmask) ==
52329 + (ntohl(ipp->addr) & ipp->netmask)))
52330 + return match;
52331 + }
52332 + match = default_role;
52333 + }
52334 + } else if (match->allowed_ips == NULL) {
52335 + return match;
52336 + } else {
52337 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52338 + if (likely
52339 + ((ntohl(curr_ip) & ipp->netmask) ==
52340 + (ntohl(ipp->addr) & ipp->netmask)))
52341 + return match;
52342 + }
52343 + goto try_group;
52344 + }
52345 +
52346 + return match;
52347 +}
52348 +
52349 +struct acl_subject_label *
52350 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52351 + const struct acl_role_label *role)
52352 +{
52353 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52354 + struct acl_subject_label *match;
52355 +
52356 + match = role->subj_hash[index];
52357 +
52358 + while (match && (match->inode != ino || match->device != dev ||
52359 + (match->mode & GR_DELETED))) {
52360 + match = match->next;
52361 + }
52362 +
52363 + if (match && !(match->mode & GR_DELETED))
52364 + return match;
52365 + else
52366 + return NULL;
52367 +}
52368 +
52369 +struct acl_subject_label *
52370 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52371 + const struct acl_role_label *role)
52372 +{
52373 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52374 + struct acl_subject_label *match;
52375 +
52376 + match = role->subj_hash[index];
52377 +
52378 + while (match && (match->inode != ino || match->device != dev ||
52379 + !(match->mode & GR_DELETED))) {
52380 + match = match->next;
52381 + }
52382 +
52383 + if (match && (match->mode & GR_DELETED))
52384 + return match;
52385 + else
52386 + return NULL;
52387 +}
52388 +
52389 +static struct acl_object_label *
52390 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52391 + const struct acl_subject_label *subj)
52392 +{
52393 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52394 + struct acl_object_label *match;
52395 +
52396 + match = subj->obj_hash[index];
52397 +
52398 + while (match && (match->inode != ino || match->device != dev ||
52399 + (match->mode & GR_DELETED))) {
52400 + match = match->next;
52401 + }
52402 +
52403 + if (match && !(match->mode & GR_DELETED))
52404 + return match;
52405 + else
52406 + return NULL;
52407 +}
52408 +
52409 +static struct acl_object_label *
52410 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52411 + const struct acl_subject_label *subj)
52412 +{
52413 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52414 + struct acl_object_label *match;
52415 +
52416 + match = subj->obj_hash[index];
52417 +
52418 + while (match && (match->inode != ino || match->device != dev ||
52419 + !(match->mode & GR_DELETED))) {
52420 + match = match->next;
52421 + }
52422 +
52423 + if (match && (match->mode & GR_DELETED))
52424 + return match;
52425 +
52426 + match = subj->obj_hash[index];
52427 +
52428 + while (match && (match->inode != ino || match->device != dev ||
52429 + (match->mode & GR_DELETED))) {
52430 + match = match->next;
52431 + }
52432 +
52433 + if (match && !(match->mode & GR_DELETED))
52434 + return match;
52435 + else
52436 + return NULL;
52437 +}
52438 +
52439 +static struct name_entry *
52440 +lookup_name_entry(const char *name)
52441 +{
52442 + unsigned int len = strlen(name);
52443 + unsigned int key = full_name_hash(name, len);
52444 + unsigned int index = key % name_set.n_size;
52445 + struct name_entry *match;
52446 +
52447 + match = name_set.n_hash[index];
52448 +
52449 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52450 + match = match->next;
52451 +
52452 + return match;
52453 +}
52454 +
52455 +static struct name_entry *
52456 +lookup_name_entry_create(const char *name)
52457 +{
52458 + unsigned int len = strlen(name);
52459 + unsigned int key = full_name_hash(name, len);
52460 + unsigned int index = key % name_set.n_size;
52461 + struct name_entry *match;
52462 +
52463 + match = name_set.n_hash[index];
52464 +
52465 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52466 + !match->deleted))
52467 + match = match->next;
52468 +
52469 + if (match && match->deleted)
52470 + return match;
52471 +
52472 + match = name_set.n_hash[index];
52473 +
52474 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52475 + match->deleted))
52476 + match = match->next;
52477 +
52478 + if (match && !match->deleted)
52479 + return match;
52480 + else
52481 + return NULL;
52482 +}
52483 +
52484 +static struct inodev_entry *
52485 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52486 +{
52487 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52488 + struct inodev_entry *match;
52489 +
52490 + match = inodev_set.i_hash[index];
52491 +
52492 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52493 + match = match->next;
52494 +
52495 + return match;
52496 +}
52497 +
52498 +static void
52499 +insert_inodev_entry(struct inodev_entry *entry)
52500 +{
52501 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52502 + inodev_set.i_size);
52503 + struct inodev_entry **curr;
52504 +
52505 + entry->prev = NULL;
52506 +
52507 + curr = &inodev_set.i_hash[index];
52508 + if (*curr != NULL)
52509 + (*curr)->prev = entry;
52510 +
52511 + entry->next = *curr;
52512 + *curr = entry;
52513 +
52514 + return;
52515 +}
52516 +
52517 +static void
52518 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52519 +{
52520 + unsigned int index =
52521 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52522 + struct acl_role_label **curr;
52523 + struct acl_role_label *tmp;
52524 +
52525 + curr = &acl_role_set.r_hash[index];
52526 +
52527 + /* if role was already inserted due to domains and already has
52528 + a role in the same bucket as it attached, then we need to
52529 + combine these two buckets
52530 + */
52531 + if (role->next) {
52532 + tmp = role->next;
52533 + while (tmp->next)
52534 + tmp = tmp->next;
52535 + tmp->next = *curr;
52536 + } else
52537 + role->next = *curr;
52538 + *curr = role;
52539 +
52540 + return;
52541 +}
52542 +
52543 +static void
52544 +insert_acl_role_label(struct acl_role_label *role)
52545 +{
52546 + int i;
52547 +
52548 + if (role_list == NULL) {
52549 + role_list = role;
52550 + role->prev = NULL;
52551 + } else {
52552 + role->prev = role_list;
52553 + role_list = role;
52554 + }
52555 +
52556 + /* used for hash chains */
52557 + role->next = NULL;
52558 +
52559 + if (role->roletype & GR_ROLE_DOMAIN) {
52560 + for (i = 0; i < role->domain_child_num; i++)
52561 + __insert_acl_role_label(role, role->domain_children[i]);
52562 + } else
52563 + __insert_acl_role_label(role, role->uidgid);
52564 +}
52565 +
52566 +static int
52567 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52568 +{
52569 + struct name_entry **curr, *nentry;
52570 + struct inodev_entry *ientry;
52571 + unsigned int len = strlen(name);
52572 + unsigned int key = full_name_hash(name, len);
52573 + unsigned int index = key % name_set.n_size;
52574 +
52575 + curr = &name_set.n_hash[index];
52576 +
52577 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52578 + curr = &((*curr)->next);
52579 +
52580 + if (*curr != NULL)
52581 + return 1;
52582 +
52583 + nentry = acl_alloc(sizeof (struct name_entry));
52584 + if (nentry == NULL)
52585 + return 0;
52586 + ientry = acl_alloc(sizeof (struct inodev_entry));
52587 + if (ientry == NULL)
52588 + return 0;
52589 + ientry->nentry = nentry;
52590 +
52591 + nentry->key = key;
52592 + nentry->name = name;
52593 + nentry->inode = inode;
52594 + nentry->device = device;
52595 + nentry->len = len;
52596 + nentry->deleted = deleted;
52597 +
52598 + nentry->prev = NULL;
52599 + curr = &name_set.n_hash[index];
52600 + if (*curr != NULL)
52601 + (*curr)->prev = nentry;
52602 + nentry->next = *curr;
52603 + *curr = nentry;
52604 +
52605 + /* insert us into the table searchable by inode/dev */
52606 + insert_inodev_entry(ientry);
52607 +
52608 + return 1;
52609 +}
52610 +
52611 +static void
52612 +insert_acl_obj_label(struct acl_object_label *obj,
52613 + struct acl_subject_label *subj)
52614 +{
52615 + unsigned int index =
52616 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52617 + struct acl_object_label **curr;
52618 +
52619 +
52620 + obj->prev = NULL;
52621 +
52622 + curr = &subj->obj_hash[index];
52623 + if (*curr != NULL)
52624 + (*curr)->prev = obj;
52625 +
52626 + obj->next = *curr;
52627 + *curr = obj;
52628 +
52629 + return;
52630 +}
52631 +
52632 +static void
52633 +insert_acl_subj_label(struct acl_subject_label *obj,
52634 + struct acl_role_label *role)
52635 +{
52636 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52637 + struct acl_subject_label **curr;
52638 +
52639 + obj->prev = NULL;
52640 +
52641 + curr = &role->subj_hash[index];
52642 + if (*curr != NULL)
52643 + (*curr)->prev = obj;
52644 +
52645 + obj->next = *curr;
52646 + *curr = obj;
52647 +
52648 + return;
52649 +}
52650 +
52651 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52652 +
52653 +static void *
52654 +create_table(__u32 * len, int elementsize)
52655 +{
52656 + unsigned int table_sizes[] = {
52657 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52658 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52659 + 4194301, 8388593, 16777213, 33554393, 67108859
52660 + };
52661 + void *newtable = NULL;
52662 + unsigned int pwr = 0;
52663 +
52664 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52665 + table_sizes[pwr] <= *len)
52666 + pwr++;
52667 +
52668 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52669 + return newtable;
52670 +
52671 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52672 + newtable =
52673 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52674 + else
52675 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52676 +
52677 + *len = table_sizes[pwr];
52678 +
52679 + return newtable;
52680 +}
52681 +
52682 +static int
52683 +init_variables(const struct gr_arg *arg)
52684 +{
52685 + struct task_struct *reaper = &init_task;
52686 + unsigned int stacksize;
52687 +
52688 + subj_map_set.s_size = arg->role_db.num_subjects;
52689 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52690 + name_set.n_size = arg->role_db.num_objects;
52691 + inodev_set.i_size = arg->role_db.num_objects;
52692 +
52693 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52694 + !name_set.n_size || !inodev_set.i_size)
52695 + return 1;
52696 +
52697 + if (!gr_init_uidset())
52698 + return 1;
52699 +
52700 + /* set up the stack that holds allocation info */
52701 +
52702 + stacksize = arg->role_db.num_pointers + 5;
52703 +
52704 + if (!acl_alloc_stack_init(stacksize))
52705 + return 1;
52706 +
52707 + /* grab reference for the real root dentry and vfsmount */
52708 + read_lock(&reaper->fs->lock);
52709 + real_root = dget(reaper->fs->root.dentry);
52710 + real_root_mnt = mntget(reaper->fs->root.mnt);
52711 + read_unlock(&reaper->fs->lock);
52712 +
52713 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52714 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root), real_root->d_inode->i_ino);
52715 +#endif
52716 +
52717 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52718 + if (fakefs_obj_rw == NULL)
52719 + return 1;
52720 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52721 +
52722 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52723 + if (fakefs_obj_rwx == NULL)
52724 + return 1;
52725 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52726 +
52727 + subj_map_set.s_hash =
52728 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52729 + acl_role_set.r_hash =
52730 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52731 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52732 + inodev_set.i_hash =
52733 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52734 +
52735 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52736 + !name_set.n_hash || !inodev_set.i_hash)
52737 + return 1;
52738 +
52739 + memset(subj_map_set.s_hash, 0,
52740 + sizeof(struct subject_map *) * subj_map_set.s_size);
52741 + memset(acl_role_set.r_hash, 0,
52742 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52743 + memset(name_set.n_hash, 0,
52744 + sizeof (struct name_entry *) * name_set.n_size);
52745 + memset(inodev_set.i_hash, 0,
52746 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52747 +
52748 + return 0;
52749 +}
52750 +
52751 +/* free information not needed after startup
52752 + currently contains user->kernel pointer mappings for subjects
52753 +*/
52754 +
52755 +static void
52756 +free_init_variables(void)
52757 +{
52758 + __u32 i;
52759 +
52760 + if (subj_map_set.s_hash) {
52761 + for (i = 0; i < subj_map_set.s_size; i++) {
52762 + if (subj_map_set.s_hash[i]) {
52763 + kfree(subj_map_set.s_hash[i]);
52764 + subj_map_set.s_hash[i] = NULL;
52765 + }
52766 + }
52767 +
52768 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52769 + PAGE_SIZE)
52770 + kfree(subj_map_set.s_hash);
52771 + else
52772 + vfree(subj_map_set.s_hash);
52773 + }
52774 +
52775 + return;
52776 +}
52777 +
52778 +static void
52779 +free_variables(void)
52780 +{
52781 + struct acl_subject_label *s;
52782 + struct acl_role_label *r;
52783 + struct task_struct *task, *task2;
52784 + unsigned int x;
52785 +
52786 + gr_clear_learn_entries();
52787 +
52788 + read_lock(&tasklist_lock);
52789 + do_each_thread(task2, task) {
52790 + task->acl_sp_role = 0;
52791 + task->acl_role_id = 0;
52792 + task->acl = NULL;
52793 + task->role = NULL;
52794 + } while_each_thread(task2, task);
52795 + read_unlock(&tasklist_lock);
52796 +
52797 + /* release the reference to the real root dentry and vfsmount */
52798 + if (real_root)
52799 + dput(real_root);
52800 + real_root = NULL;
52801 + if (real_root_mnt)
52802 + mntput(real_root_mnt);
52803 + real_root_mnt = NULL;
52804 +
52805 + /* free all object hash tables */
52806 +
52807 + FOR_EACH_ROLE_START(r)
52808 + if (r->subj_hash == NULL)
52809 + goto next_role;
52810 + FOR_EACH_SUBJECT_START(r, s, x)
52811 + if (s->obj_hash == NULL)
52812 + break;
52813 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52814 + kfree(s->obj_hash);
52815 + else
52816 + vfree(s->obj_hash);
52817 + FOR_EACH_SUBJECT_END(s, x)
52818 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52819 + if (s->obj_hash == NULL)
52820 + break;
52821 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52822 + kfree(s->obj_hash);
52823 + else
52824 + vfree(s->obj_hash);
52825 + FOR_EACH_NESTED_SUBJECT_END(s)
52826 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52827 + kfree(r->subj_hash);
52828 + else
52829 + vfree(r->subj_hash);
52830 + r->subj_hash = NULL;
52831 +next_role:
52832 + FOR_EACH_ROLE_END(r)
52833 +
52834 + acl_free_all();
52835 +
52836 + if (acl_role_set.r_hash) {
52837 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52838 + PAGE_SIZE)
52839 + kfree(acl_role_set.r_hash);
52840 + else
52841 + vfree(acl_role_set.r_hash);
52842 + }
52843 + if (name_set.n_hash) {
52844 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52845 + PAGE_SIZE)
52846 + kfree(name_set.n_hash);
52847 + else
52848 + vfree(name_set.n_hash);
52849 + }
52850 +
52851 + if (inodev_set.i_hash) {
52852 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52853 + PAGE_SIZE)
52854 + kfree(inodev_set.i_hash);
52855 + else
52856 + vfree(inodev_set.i_hash);
52857 + }
52858 +
52859 + gr_free_uidset();
52860 +
52861 + memset(&name_set, 0, sizeof (struct name_db));
52862 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52863 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52864 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52865 +
52866 + default_role = NULL;
52867 + role_list = NULL;
52868 +
52869 + return;
52870 +}
52871 +
52872 +static __u32
52873 +count_user_objs(struct acl_object_label *userp)
52874 +{
52875 + struct acl_object_label o_tmp;
52876 + __u32 num = 0;
52877 +
52878 + while (userp) {
52879 + if (copy_from_user(&o_tmp, userp,
52880 + sizeof (struct acl_object_label)))
52881 + break;
52882 +
52883 + userp = o_tmp.prev;
52884 + num++;
52885 + }
52886 +
52887 + return num;
52888 +}
52889 +
52890 +static struct acl_subject_label *
52891 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52892 +
52893 +static int
52894 +copy_user_glob(struct acl_object_label *obj)
52895 +{
52896 + struct acl_object_label *g_tmp, **guser;
52897 + unsigned int len;
52898 + char *tmp;
52899 +
52900 + if (obj->globbed == NULL)
52901 + return 0;
52902 +
52903 + guser = &obj->globbed;
52904 + while (*guser) {
52905 + g_tmp = (struct acl_object_label *)
52906 + acl_alloc(sizeof (struct acl_object_label));
52907 + if (g_tmp == NULL)
52908 + return -ENOMEM;
52909 +
52910 + if (copy_from_user(g_tmp, *guser,
52911 + sizeof (struct acl_object_label)))
52912 + return -EFAULT;
52913 +
52914 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52915 +
52916 + if (!len || len >= PATH_MAX)
52917 + return -EINVAL;
52918 +
52919 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52920 + return -ENOMEM;
52921 +
52922 + if (copy_from_user(tmp, g_tmp->filename, len))
52923 + return -EFAULT;
52924 + tmp[len-1] = '\0';
52925 + g_tmp->filename = tmp;
52926 +
52927 + *guser = g_tmp;
52928 + guser = &(g_tmp->next);
52929 + }
52930 +
52931 + return 0;
52932 +}
52933 +
52934 +static int
52935 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52936 + struct acl_role_label *role)
52937 +{
52938 + struct acl_object_label *o_tmp;
52939 + unsigned int len;
52940 + int ret;
52941 + char *tmp;
52942 +
52943 + while (userp) {
52944 + if ((o_tmp = (struct acl_object_label *)
52945 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52946 + return -ENOMEM;
52947 +
52948 + if (copy_from_user(o_tmp, userp,
52949 + sizeof (struct acl_object_label)))
52950 + return -EFAULT;
52951 +
52952 + userp = o_tmp->prev;
52953 +
52954 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52955 +
52956 + if (!len || len >= PATH_MAX)
52957 + return -EINVAL;
52958 +
52959 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52960 + return -ENOMEM;
52961 +
52962 + if (copy_from_user(tmp, o_tmp->filename, len))
52963 + return -EFAULT;
52964 + tmp[len-1] = '\0';
52965 + o_tmp->filename = tmp;
52966 +
52967 + insert_acl_obj_label(o_tmp, subj);
52968 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52969 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52970 + return -ENOMEM;
52971 +
52972 + ret = copy_user_glob(o_tmp);
52973 + if (ret)
52974 + return ret;
52975 +
52976 + if (o_tmp->nested) {
52977 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52978 + if (IS_ERR(o_tmp->nested))
52979 + return PTR_ERR(o_tmp->nested);
52980 +
52981 + /* insert into nested subject list */
52982 + o_tmp->nested->next = role->hash->first;
52983 + role->hash->first = o_tmp->nested;
52984 + }
52985 + }
52986 +
52987 + return 0;
52988 +}
52989 +
52990 +static __u32
52991 +count_user_subjs(struct acl_subject_label *userp)
52992 +{
52993 + struct acl_subject_label s_tmp;
52994 + __u32 num = 0;
52995 +
52996 + while (userp) {
52997 + if (copy_from_user(&s_tmp, userp,
52998 + sizeof (struct acl_subject_label)))
52999 + break;
53000 +
53001 + userp = s_tmp.prev;
53002 + /* do not count nested subjects against this count, since
53003 + they are not included in the hash table, but are
53004 + attached to objects. We have already counted
53005 + the subjects in userspace for the allocation
53006 + stack
53007 + */
53008 + if (!(s_tmp.mode & GR_NESTED))
53009 + num++;
53010 + }
53011 +
53012 + return num;
53013 +}
53014 +
53015 +static int
53016 +copy_user_allowedips(struct acl_role_label *rolep)
53017 +{
53018 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
53019 +
53020 + ruserip = rolep->allowed_ips;
53021 +
53022 + while (ruserip) {
53023 + rlast = rtmp;
53024 +
53025 + if ((rtmp = (struct role_allowed_ip *)
53026 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
53027 + return -ENOMEM;
53028 +
53029 + if (copy_from_user(rtmp, ruserip,
53030 + sizeof (struct role_allowed_ip)))
53031 + return -EFAULT;
53032 +
53033 + ruserip = rtmp->prev;
53034 +
53035 + if (!rlast) {
53036 + rtmp->prev = NULL;
53037 + rolep->allowed_ips = rtmp;
53038 + } else {
53039 + rlast->next = rtmp;
53040 + rtmp->prev = rlast;
53041 + }
53042 +
53043 + if (!ruserip)
53044 + rtmp->next = NULL;
53045 + }
53046 +
53047 + return 0;
53048 +}
53049 +
53050 +static int
53051 +copy_user_transitions(struct acl_role_label *rolep)
53052 +{
53053 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
53054 +
53055 + unsigned int len;
53056 + char *tmp;
53057 +
53058 + rusertp = rolep->transitions;
53059 +
53060 + while (rusertp) {
53061 + rlast = rtmp;
53062 +
53063 + if ((rtmp = (struct role_transition *)
53064 + acl_alloc(sizeof (struct role_transition))) == NULL)
53065 + return -ENOMEM;
53066 +
53067 + if (copy_from_user(rtmp, rusertp,
53068 + sizeof (struct role_transition)))
53069 + return -EFAULT;
53070 +
53071 + rusertp = rtmp->prev;
53072 +
53073 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
53074 +
53075 + if (!len || len >= GR_SPROLE_LEN)
53076 + return -EINVAL;
53077 +
53078 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53079 + return -ENOMEM;
53080 +
53081 + if (copy_from_user(tmp, rtmp->rolename, len))
53082 + return -EFAULT;
53083 + tmp[len-1] = '\0';
53084 + rtmp->rolename = tmp;
53085 +
53086 + if (!rlast) {
53087 + rtmp->prev = NULL;
53088 + rolep->transitions = rtmp;
53089 + } else {
53090 + rlast->next = rtmp;
53091 + rtmp->prev = rlast;
53092 + }
53093 +
53094 + if (!rusertp)
53095 + rtmp->next = NULL;
53096 + }
53097 +
53098 + return 0;
53099 +}
53100 +
53101 +static struct acl_subject_label *
53102 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
53103 +{
53104 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53105 + unsigned int len;
53106 + char *tmp;
53107 + __u32 num_objs;
53108 + struct acl_ip_label **i_tmp, *i_utmp2;
53109 + struct gr_hash_struct ghash;
53110 + struct subject_map *subjmap;
53111 + unsigned int i_num;
53112 + int err;
53113 +
53114 + s_tmp = lookup_subject_map(userp);
53115 +
53116 + /* we've already copied this subject into the kernel, just return
53117 + the reference to it, and don't copy it over again
53118 + */
53119 + if (s_tmp)
53120 + return(s_tmp);
53121 +
53122 + if ((s_tmp = (struct acl_subject_label *)
53123 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53124 + return ERR_PTR(-ENOMEM);
53125 +
53126 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53127 + if (subjmap == NULL)
53128 + return ERR_PTR(-ENOMEM);
53129 +
53130 + subjmap->user = userp;
53131 + subjmap->kernel = s_tmp;
53132 + insert_subj_map_entry(subjmap);
53133 +
53134 + if (copy_from_user(s_tmp, userp,
53135 + sizeof (struct acl_subject_label)))
53136 + return ERR_PTR(-EFAULT);
53137 +
53138 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53139 +
53140 + if (!len || len >= PATH_MAX)
53141 + return ERR_PTR(-EINVAL);
53142 +
53143 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53144 + return ERR_PTR(-ENOMEM);
53145 +
53146 + if (copy_from_user(tmp, s_tmp->filename, len))
53147 + return ERR_PTR(-EFAULT);
53148 + tmp[len-1] = '\0';
53149 + s_tmp->filename = tmp;
53150 +
53151 + if (!strcmp(s_tmp->filename, "/"))
53152 + role->root_label = s_tmp;
53153 +
53154 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53155 + return ERR_PTR(-EFAULT);
53156 +
53157 + /* copy user and group transition tables */
53158 +
53159 + if (s_tmp->user_trans_num) {
53160 + uid_t *uidlist;
53161 +
53162 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53163 + if (uidlist == NULL)
53164 + return ERR_PTR(-ENOMEM);
53165 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53166 + return ERR_PTR(-EFAULT);
53167 +
53168 + s_tmp->user_transitions = uidlist;
53169 + }
53170 +
53171 + if (s_tmp->group_trans_num) {
53172 + gid_t *gidlist;
53173 +
53174 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53175 + if (gidlist == NULL)
53176 + return ERR_PTR(-ENOMEM);
53177 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53178 + return ERR_PTR(-EFAULT);
53179 +
53180 + s_tmp->group_transitions = gidlist;
53181 + }
53182 +
53183 + /* set up object hash table */
53184 + num_objs = count_user_objs(ghash.first);
53185 +
53186 + s_tmp->obj_hash_size = num_objs;
53187 + s_tmp->obj_hash =
53188 + (struct acl_object_label **)
53189 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53190 +
53191 + if (!s_tmp->obj_hash)
53192 + return ERR_PTR(-ENOMEM);
53193 +
53194 + memset(s_tmp->obj_hash, 0,
53195 + s_tmp->obj_hash_size *
53196 + sizeof (struct acl_object_label *));
53197 +
53198 + /* add in objects */
53199 + err = copy_user_objs(ghash.first, s_tmp, role);
53200 +
53201 + if (err)
53202 + return ERR_PTR(err);
53203 +
53204 + /* set pointer for parent subject */
53205 + if (s_tmp->parent_subject) {
53206 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
53207 +
53208 + if (IS_ERR(s_tmp2))
53209 + return s_tmp2;
53210 +
53211 + s_tmp->parent_subject = s_tmp2;
53212 + }
53213 +
53214 + /* add in ip acls */
53215 +
53216 + if (!s_tmp->ip_num) {
53217 + s_tmp->ips = NULL;
53218 + goto insert;
53219 + }
53220 +
53221 + i_tmp =
53222 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53223 + sizeof (struct acl_ip_label *));
53224 +
53225 + if (!i_tmp)
53226 + return ERR_PTR(-ENOMEM);
53227 +
53228 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53229 + *(i_tmp + i_num) =
53230 + (struct acl_ip_label *)
53231 + acl_alloc(sizeof (struct acl_ip_label));
53232 + if (!*(i_tmp + i_num))
53233 + return ERR_PTR(-ENOMEM);
53234 +
53235 + if (copy_from_user
53236 + (&i_utmp2, s_tmp->ips + i_num,
53237 + sizeof (struct acl_ip_label *)))
53238 + return ERR_PTR(-EFAULT);
53239 +
53240 + if (copy_from_user
53241 + (*(i_tmp + i_num), i_utmp2,
53242 + sizeof (struct acl_ip_label)))
53243 + return ERR_PTR(-EFAULT);
53244 +
53245 + if ((*(i_tmp + i_num))->iface == NULL)
53246 + continue;
53247 +
53248 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53249 + if (!len || len >= IFNAMSIZ)
53250 + return ERR_PTR(-EINVAL);
53251 + tmp = acl_alloc(len);
53252 + if (tmp == NULL)
53253 + return ERR_PTR(-ENOMEM);
53254 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53255 + return ERR_PTR(-EFAULT);
53256 + (*(i_tmp + i_num))->iface = tmp;
53257 + }
53258 +
53259 + s_tmp->ips = i_tmp;
53260 +
53261 +insert:
53262 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53263 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53264 + return ERR_PTR(-ENOMEM);
53265 +
53266 + return s_tmp;
53267 +}
53268 +
53269 +static int
53270 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53271 +{
53272 + struct acl_subject_label s_pre;
53273 + struct acl_subject_label * ret;
53274 + int err;
53275 +
53276 + while (userp) {
53277 + if (copy_from_user(&s_pre, userp,
53278 + sizeof (struct acl_subject_label)))
53279 + return -EFAULT;
53280 +
53281 + /* do not add nested subjects here, add
53282 + while parsing objects
53283 + */
53284 +
53285 + if (s_pre.mode & GR_NESTED) {
53286 + userp = s_pre.prev;
53287 + continue;
53288 + }
53289 +
53290 + ret = do_copy_user_subj(userp, role);
53291 +
53292 + err = PTR_ERR(ret);
53293 + if (IS_ERR(ret))
53294 + return err;
53295 +
53296 + insert_acl_subj_label(ret, role);
53297 +
53298 + userp = s_pre.prev;
53299 + }
53300 +
53301 + return 0;
53302 +}
53303 +
53304 +static int
53305 +copy_user_acl(struct gr_arg *arg)
53306 +{
53307 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53308 + struct sprole_pw *sptmp;
53309 + struct gr_hash_struct *ghash;
53310 + uid_t *domainlist;
53311 + unsigned int r_num;
53312 + unsigned int len;
53313 + char *tmp;
53314 + int err = 0;
53315 + __u16 i;
53316 + __u32 num_subjs;
53317 +
53318 + /* we need a default and kernel role */
53319 + if (arg->role_db.num_roles < 2)
53320 + return -EINVAL;
53321 +
53322 + /* copy special role authentication info from userspace */
53323 +
53324 + num_sprole_pws = arg->num_sprole_pws;
53325 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53326 +
53327 + if (!acl_special_roles) {
53328 + err = -ENOMEM;
53329 + goto cleanup;
53330 + }
53331 +
53332 + for (i = 0; i < num_sprole_pws; i++) {
53333 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53334 + if (!sptmp) {
53335 + err = -ENOMEM;
53336 + goto cleanup;
53337 + }
53338 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53339 + sizeof (struct sprole_pw))) {
53340 + err = -EFAULT;
53341 + goto cleanup;
53342 + }
53343 +
53344 + len =
53345 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53346 +
53347 + if (!len || len >= GR_SPROLE_LEN) {
53348 + err = -EINVAL;
53349 + goto cleanup;
53350 + }
53351 +
53352 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
53353 + err = -ENOMEM;
53354 + goto cleanup;
53355 + }
53356 +
53357 + if (copy_from_user(tmp, sptmp->rolename, len)) {
53358 + err = -EFAULT;
53359 + goto cleanup;
53360 + }
53361 + tmp[len-1] = '\0';
53362 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53363 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53364 +#endif
53365 + sptmp->rolename = tmp;
53366 + acl_special_roles[i] = sptmp;
53367 + }
53368 +
53369 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53370 +
53371 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53372 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53373 +
53374 + if (!r_tmp) {
53375 + err = -ENOMEM;
53376 + goto cleanup;
53377 + }
53378 +
53379 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53380 + sizeof (struct acl_role_label *))) {
53381 + err = -EFAULT;
53382 + goto cleanup;
53383 + }
53384 +
53385 + if (copy_from_user(r_tmp, r_utmp2,
53386 + sizeof (struct acl_role_label))) {
53387 + err = -EFAULT;
53388 + goto cleanup;
53389 + }
53390 +
53391 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53392 +
53393 + if (!len || len >= PATH_MAX) {
53394 + err = -EINVAL;
53395 + goto cleanup;
53396 + }
53397 +
53398 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
53399 + err = -ENOMEM;
53400 + goto cleanup;
53401 + }
53402 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
53403 + err = -EFAULT;
53404 + goto cleanup;
53405 + }
53406 + tmp[len-1] = '\0';
53407 + r_tmp->rolename = tmp;
53408 +
53409 + if (!strcmp(r_tmp->rolename, "default")
53410 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53411 + default_role = r_tmp;
53412 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53413 + kernel_role = r_tmp;
53414 + }
53415 +
53416 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
53417 + err = -ENOMEM;
53418 + goto cleanup;
53419 + }
53420 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
53421 + err = -EFAULT;
53422 + goto cleanup;
53423 + }
53424 +
53425 + r_tmp->hash = ghash;
53426 +
53427 + num_subjs = count_user_subjs(r_tmp->hash->first);
53428 +
53429 + r_tmp->subj_hash_size = num_subjs;
53430 + r_tmp->subj_hash =
53431 + (struct acl_subject_label **)
53432 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53433 +
53434 + if (!r_tmp->subj_hash) {
53435 + err = -ENOMEM;
53436 + goto cleanup;
53437 + }
53438 +
53439 + err = copy_user_allowedips(r_tmp);
53440 + if (err)
53441 + goto cleanup;
53442 +
53443 + /* copy domain info */
53444 + if (r_tmp->domain_children != NULL) {
53445 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53446 + if (domainlist == NULL) {
53447 + err = -ENOMEM;
53448 + goto cleanup;
53449 + }
53450 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
53451 + err = -EFAULT;
53452 + goto cleanup;
53453 + }
53454 + r_tmp->domain_children = domainlist;
53455 + }
53456 +
53457 + err = copy_user_transitions(r_tmp);
53458 + if (err)
53459 + goto cleanup;
53460 +
53461 + memset(r_tmp->subj_hash, 0,
53462 + r_tmp->subj_hash_size *
53463 + sizeof (struct acl_subject_label *));
53464 +
53465 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
53466 +
53467 + if (err)
53468 + goto cleanup;
53469 +
53470 + /* set nested subject list to null */
53471 + r_tmp->hash->first = NULL;
53472 +
53473 + insert_acl_role_label(r_tmp);
53474 + }
53475 +
53476 + goto return_err;
53477 + cleanup:
53478 + free_variables();
53479 + return_err:
53480 + return err;
53481 +
53482 +}
53483 +
53484 +static int
53485 +gracl_init(struct gr_arg *args)
53486 +{
53487 + int error = 0;
53488 +
53489 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53490 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53491 +
53492 + if (init_variables(args)) {
53493 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53494 + error = -ENOMEM;
53495 + free_variables();
53496 + goto out;
53497 + }
53498 +
53499 + error = copy_user_acl(args);
53500 + free_init_variables();
53501 + if (error) {
53502 + free_variables();
53503 + goto out;
53504 + }
53505 +
53506 + if ((error = gr_set_acls(0))) {
53507 + free_variables();
53508 + goto out;
53509 + }
53510 +
53511 + pax_open_kernel();
53512 + gr_status |= GR_READY;
53513 + pax_close_kernel();
53514 +
53515 + out:
53516 + return error;
53517 +}
53518 +
53519 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53520 +
53521 +static int
53522 +glob_match(const char *p, const char *n)
53523 +{
53524 + char c;
53525 +
53526 + while ((c = *p++) != '\0') {
53527 + switch (c) {
53528 + case '?':
53529 + if (*n == '\0')
53530 + return 1;
53531 + else if (*n == '/')
53532 + return 1;
53533 + break;
53534 + case '\\':
53535 + if (*n != c)
53536 + return 1;
53537 + break;
53538 + case '*':
53539 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53540 + if (*n == '/')
53541 + return 1;
53542 + else if (c == '?') {
53543 + if (*n == '\0')
53544 + return 1;
53545 + else
53546 + ++n;
53547 + }
53548 + }
53549 + if (c == '\0') {
53550 + return 0;
53551 + } else {
53552 + const char *endp;
53553 +
53554 + if ((endp = strchr(n, '/')) == NULL)
53555 + endp = n + strlen(n);
53556 +
53557 + if (c == '[') {
53558 + for (--p; n < endp; ++n)
53559 + if (!glob_match(p, n))
53560 + return 0;
53561 + } else if (c == '/') {
53562 + while (*n != '\0' && *n != '/')
53563 + ++n;
53564 + if (*n == '/' && !glob_match(p, n + 1))
53565 + return 0;
53566 + } else {
53567 + for (--p; n < endp; ++n)
53568 + if (*n == c && !glob_match(p, n))
53569 + return 0;
53570 + }
53571 +
53572 + return 1;
53573 + }
53574 + case '[':
53575 + {
53576 + int not;
53577 + char cold;
53578 +
53579 + if (*n == '\0' || *n == '/')
53580 + return 1;
53581 +
53582 + not = (*p == '!' || *p == '^');
53583 + if (not)
53584 + ++p;
53585 +
53586 + c = *p++;
53587 + for (;;) {
53588 + unsigned char fn = (unsigned char)*n;
53589 +
53590 + if (c == '\0')
53591 + return 1;
53592 + else {
53593 + if (c == fn)
53594 + goto matched;
53595 + cold = c;
53596 + c = *p++;
53597 +
53598 + if (c == '-' && *p != ']') {
53599 + unsigned char cend = *p++;
53600 +
53601 + if (cend == '\0')
53602 + return 1;
53603 +
53604 + if (cold <= fn && fn <= cend)
53605 + goto matched;
53606 +
53607 + c = *p++;
53608 + }
53609 + }
53610 +
53611 + if (c == ']')
53612 + break;
53613 + }
53614 + if (!not)
53615 + return 1;
53616 + break;
53617 + matched:
53618 + while (c != ']') {
53619 + if (c == '\0')
53620 + return 1;
53621 +
53622 + c = *p++;
53623 + }
53624 + if (not)
53625 + return 1;
53626 + }
53627 + break;
53628 + default:
53629 + if (c != *n)
53630 + return 1;
53631 + }
53632 +
53633 + ++n;
53634 + }
53635 +
53636 + if (*n == '\0')
53637 + return 0;
53638 +
53639 + if (*n == '/')
53640 + return 0;
53641 +
53642 + return 1;
53643 +}
53644 +
53645 +static struct acl_object_label *
53646 +chk_glob_label(struct acl_object_label *globbed,
53647 + struct dentry *dentry, struct vfsmount *mnt, char **path)
53648 +{
53649 + struct acl_object_label *tmp;
53650 +
53651 + if (*path == NULL)
53652 + *path = gr_to_filename_nolock(dentry, mnt);
53653 +
53654 + tmp = globbed;
53655 +
53656 + while (tmp) {
53657 + if (!glob_match(tmp->filename, *path))
53658 + return tmp;
53659 + tmp = tmp->next;
53660 + }
53661 +
53662 + return NULL;
53663 +}
53664 +
53665 +static struct acl_object_label *
53666 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53667 + const ino_t curr_ino, const dev_t curr_dev,
53668 + const struct acl_subject_label *subj, char **path, const int checkglob)
53669 +{
53670 + struct acl_subject_label *tmpsubj;
53671 + struct acl_object_label *retval;
53672 + struct acl_object_label *retval2;
53673 +
53674 + tmpsubj = (struct acl_subject_label *) subj;
53675 + read_lock(&gr_inode_lock);
53676 + do {
53677 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53678 + if (retval) {
53679 + if (checkglob && retval->globbed) {
53680 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
53681 + (struct vfsmount *)orig_mnt, path);
53682 + if (retval2)
53683 + retval = retval2;
53684 + }
53685 + break;
53686 + }
53687 + } while ((tmpsubj = tmpsubj->parent_subject));
53688 + read_unlock(&gr_inode_lock);
53689 +
53690 + return retval;
53691 +}
53692 +
53693 +static __inline__ struct acl_object_label *
53694 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53695 + const struct dentry *curr_dentry,
53696 + const struct acl_subject_label *subj, char **path, const int checkglob)
53697 +{
53698 + int newglob = checkglob;
53699 +
53700 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53701 + as we don't want a / * rule to match instead of the / object
53702 + don't do this for create lookups that call this function though, since they're looking up
53703 + on the parent and thus need globbing checks on all paths
53704 + */
53705 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53706 + newglob = GR_NO_GLOB;
53707 +
53708 + return __full_lookup(orig_dentry, orig_mnt,
53709 + curr_dentry->d_inode->i_ino,
53710 + __get_dev(curr_dentry), subj, path, newglob);
53711 +}
53712 +
53713 +static struct acl_object_label *
53714 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53715 + const struct acl_subject_label *subj, char *path, const int checkglob)
53716 +{
53717 + struct dentry *dentry = (struct dentry *) l_dentry;
53718 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53719 + struct acl_object_label *retval;
53720 +
53721 + spin_lock(&dcache_lock);
53722 + spin_lock(&vfsmount_lock);
53723 +
53724 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53725 +#ifdef CONFIG_NET
53726 + mnt == sock_mnt ||
53727 +#endif
53728 +#ifdef CONFIG_HUGETLBFS
53729 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53730 +#endif
53731 + /* ignore Eric Biederman */
53732 + IS_PRIVATE(l_dentry->d_inode))) {
53733 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53734 + goto out;
53735 + }
53736 +
53737 + for (;;) {
53738 + if (dentry == real_root && mnt == real_root_mnt)
53739 + break;
53740 +
53741 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53742 + if (mnt->mnt_parent == mnt)
53743 + break;
53744 +
53745 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53746 + if (retval != NULL)
53747 + goto out;
53748 +
53749 + dentry = mnt->mnt_mountpoint;
53750 + mnt = mnt->mnt_parent;
53751 + continue;
53752 + }
53753 +
53754 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53755 + if (retval != NULL)
53756 + goto out;
53757 +
53758 + dentry = dentry->d_parent;
53759 + }
53760 +
53761 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53762 +
53763 + if (retval == NULL)
53764 + retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob);
53765 +out:
53766 + spin_unlock(&vfsmount_lock);
53767 + spin_unlock(&dcache_lock);
53768 +
53769 + BUG_ON(retval == NULL);
53770 +
53771 + return retval;
53772 +}
53773 +
53774 +static __inline__ struct acl_object_label *
53775 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53776 + const struct acl_subject_label *subj)
53777 +{
53778 + char *path = NULL;
53779 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53780 +}
53781 +
53782 +static __inline__ struct acl_object_label *
53783 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53784 + const struct acl_subject_label *subj)
53785 +{
53786 + char *path = NULL;
53787 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53788 +}
53789 +
53790 +static __inline__ struct acl_object_label *
53791 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53792 + const struct acl_subject_label *subj, char *path)
53793 +{
53794 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53795 +}
53796 +
53797 +static struct acl_subject_label *
53798 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53799 + const struct acl_role_label *role)
53800 +{
53801 + struct dentry *dentry = (struct dentry *) l_dentry;
53802 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53803 + struct acl_subject_label *retval;
53804 +
53805 + spin_lock(&dcache_lock);
53806 + spin_lock(&vfsmount_lock);
53807 +
53808 + for (;;) {
53809 + if (dentry == real_root && mnt == real_root_mnt)
53810 + break;
53811 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53812 + if (mnt->mnt_parent == mnt)
53813 + break;
53814 +
53815 + read_lock(&gr_inode_lock);
53816 + retval =
53817 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53818 + __get_dev(dentry), role);
53819 + read_unlock(&gr_inode_lock);
53820 + if (retval != NULL)
53821 + goto out;
53822 +
53823 + dentry = mnt->mnt_mountpoint;
53824 + mnt = mnt->mnt_parent;
53825 + continue;
53826 + }
53827 +
53828 + read_lock(&gr_inode_lock);
53829 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53830 + __get_dev(dentry), role);
53831 + read_unlock(&gr_inode_lock);
53832 + if (retval != NULL)
53833 + goto out;
53834 +
53835 + dentry = dentry->d_parent;
53836 + }
53837 +
53838 + read_lock(&gr_inode_lock);
53839 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53840 + __get_dev(dentry), role);
53841 + read_unlock(&gr_inode_lock);
53842 +
53843 + if (unlikely(retval == NULL)) {
53844 + read_lock(&gr_inode_lock);
53845 + retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
53846 + __get_dev(real_root), role);
53847 + read_unlock(&gr_inode_lock);
53848 + }
53849 +out:
53850 + spin_unlock(&vfsmount_lock);
53851 + spin_unlock(&dcache_lock);
53852 +
53853 + BUG_ON(retval == NULL);
53854 +
53855 + return retval;
53856 +}
53857 +
53858 +static void
53859 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53860 +{
53861 + struct task_struct *task = current;
53862 + const struct cred *cred = current_cred();
53863 +
53864 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53865 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53866 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53867 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53868 +
53869 + return;
53870 +}
53871 +
53872 +static void
53873 +gr_log_learn_sysctl(const char *path, const __u32 mode)
53874 +{
53875 + struct task_struct *task = current;
53876 + const struct cred *cred = current_cred();
53877 +
53878 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53879 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53880 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53881 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
53882 +
53883 + return;
53884 +}
53885 +
53886 +static void
53887 +gr_log_learn_id_change(const char type, const unsigned int real,
53888 + const unsigned int effective, const unsigned int fs)
53889 +{
53890 + struct task_struct *task = current;
53891 + const struct cred *cred = current_cred();
53892 +
53893 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53894 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53895 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53896 + type, real, effective, fs, &task->signal->saved_ip);
53897 +
53898 + return;
53899 +}
53900 +
53901 +__u32
53902 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53903 + const struct vfsmount * mnt)
53904 +{
53905 + __u32 retval = mode;
53906 + struct acl_subject_label *curracl;
53907 + struct acl_object_label *currobj;
53908 +
53909 + if (unlikely(!(gr_status & GR_READY)))
53910 + return (mode & ~GR_AUDITS);
53911 +
53912 + curracl = current->acl;
53913 +
53914 + currobj = chk_obj_label(dentry, mnt, curracl);
53915 + retval = currobj->mode & mode;
53916 +
53917 + /* if we're opening a specified transfer file for writing
53918 + (e.g. /dev/initctl), then transfer our role to init
53919 + */
53920 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53921 + current->role->roletype & GR_ROLE_PERSIST)) {
53922 + struct task_struct *task = init_pid_ns.child_reaper;
53923 +
53924 + if (task->role != current->role) {
53925 + task->acl_sp_role = 0;
53926 + task->acl_role_id = current->acl_role_id;
53927 + task->role = current->role;
53928 + rcu_read_lock();
53929 + read_lock(&grsec_exec_file_lock);
53930 + gr_apply_subject_to_task(task);
53931 + read_unlock(&grsec_exec_file_lock);
53932 + rcu_read_unlock();
53933 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53934 + }
53935 + }
53936 +
53937 + if (unlikely
53938 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53939 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53940 + __u32 new_mode = mode;
53941 +
53942 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53943 +
53944 + retval = new_mode;
53945 +
53946 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53947 + new_mode |= GR_INHERIT;
53948 +
53949 + if (!(mode & GR_NOLEARN))
53950 + gr_log_learn(dentry, mnt, new_mode);
53951 + }
53952 +
53953 + return retval;
53954 +}
53955 +
53956 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53957 + const struct dentry *parent,
53958 + const struct vfsmount *mnt)
53959 +{
53960 + struct name_entry *match;
53961 + struct acl_object_label *matchpo;
53962 + struct acl_subject_label *curracl;
53963 + char *path;
53964 +
53965 + if (unlikely(!(gr_status & GR_READY)))
53966 + return NULL;
53967 +
53968 + preempt_disable();
53969 + path = gr_to_filename_rbac(new_dentry, mnt);
53970 + match = lookup_name_entry_create(path);
53971 +
53972 + curracl = current->acl;
53973 +
53974 + if (match) {
53975 + read_lock(&gr_inode_lock);
53976 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53977 + read_unlock(&gr_inode_lock);
53978 +
53979 + if (matchpo) {
53980 + preempt_enable();
53981 + return matchpo;
53982 + }
53983 + }
53984 +
53985 + // lookup parent
53986 +
53987 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53988 +
53989 + preempt_enable();
53990 + return matchpo;
53991 +}
53992 +
53993 +__u32
53994 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53995 + const struct vfsmount * mnt, const __u32 mode)
53996 +{
53997 + struct acl_object_label *matchpo;
53998 + __u32 retval;
53999 +
54000 + if (unlikely(!(gr_status & GR_READY)))
54001 + return (mode & ~GR_AUDITS);
54002 +
54003 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
54004 +
54005 + retval = matchpo->mode & mode;
54006 +
54007 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
54008 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54009 + __u32 new_mode = mode;
54010 +
54011 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54012 +
54013 + gr_log_learn(new_dentry, mnt, new_mode);
54014 + return new_mode;
54015 + }
54016 +
54017 + return retval;
54018 +}
54019 +
54020 +__u32
54021 +gr_check_link(const struct dentry * new_dentry,
54022 + const struct dentry * parent_dentry,
54023 + const struct vfsmount * parent_mnt,
54024 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
54025 +{
54026 + struct acl_object_label *obj;
54027 + __u32 oldmode, newmode;
54028 + __u32 needmode;
54029 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
54030 + GR_DELETE | GR_INHERIT;
54031 +
54032 + if (unlikely(!(gr_status & GR_READY)))
54033 + return (GR_CREATE | GR_LINK);
54034 +
54035 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
54036 + oldmode = obj->mode;
54037 +
54038 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
54039 + newmode = obj->mode;
54040 +
54041 + needmode = newmode & checkmodes;
54042 +
54043 + // old name for hardlink must have at least the permissions of the new name
54044 + if ((oldmode & needmode) != needmode)
54045 + goto bad;
54046 +
54047 + // if old name had restrictions/auditing, make sure the new name does as well
54048 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
54049 +
54050 + // don't allow hardlinking of suid/sgid files without permission
54051 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
54052 + needmode |= GR_SETID;
54053 +
54054 + if ((newmode & needmode) != needmode)
54055 + goto bad;
54056 +
54057 + // enforce minimum permissions
54058 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
54059 + return newmode;
54060 +bad:
54061 + needmode = oldmode;
54062 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
54063 + needmode |= GR_SETID;
54064 +
54065 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
54066 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
54067 + return (GR_CREATE | GR_LINK);
54068 + } else if (newmode & GR_SUPPRESS)
54069 + return GR_SUPPRESS;
54070 + else
54071 + return 0;
54072 +}
54073 +
54074 +int
54075 +gr_check_hidden_task(const struct task_struct *task)
54076 +{
54077 + if (unlikely(!(gr_status & GR_READY)))
54078 + return 0;
54079 +
54080 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
54081 + return 1;
54082 +
54083 + return 0;
54084 +}
54085 +
54086 +int
54087 +gr_check_protected_task(const struct task_struct *task)
54088 +{
54089 + if (unlikely(!(gr_status & GR_READY) || !task))
54090 + return 0;
54091 +
54092 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54093 + task->acl != current->acl)
54094 + return 1;
54095 +
54096 + return 0;
54097 +}
54098 +
54099 +int
54100 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54101 +{
54102 + struct task_struct *p;
54103 + int ret = 0;
54104 +
54105 + if (unlikely(!(gr_status & GR_READY) || !pid))
54106 + return ret;
54107 +
54108 + read_lock(&tasklist_lock);
54109 + do_each_pid_task(pid, type, p) {
54110 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54111 + p->acl != current->acl) {
54112 + ret = 1;
54113 + goto out;
54114 + }
54115 + } while_each_pid_task(pid, type, p);
54116 +out:
54117 + read_unlock(&tasklist_lock);
54118 +
54119 + return ret;
54120 +}
54121 +
54122 +void
54123 +gr_copy_label(struct task_struct *tsk)
54124 +{
54125 + tsk->signal->used_accept = 0;
54126 + tsk->acl_sp_role = 0;
54127 + tsk->acl_role_id = current->acl_role_id;
54128 + tsk->acl = current->acl;
54129 + tsk->role = current->role;
54130 + tsk->signal->curr_ip = current->signal->curr_ip;
54131 + tsk->signal->saved_ip = current->signal->saved_ip;
54132 + if (current->exec_file)
54133 + get_file(current->exec_file);
54134 + tsk->exec_file = current->exec_file;
54135 + tsk->is_writable = current->is_writable;
54136 + if (unlikely(current->signal->used_accept)) {
54137 + current->signal->curr_ip = 0;
54138 + current->signal->saved_ip = 0;
54139 + }
54140 +
54141 + return;
54142 +}
54143 +
54144 +static void
54145 +gr_set_proc_res(struct task_struct *task)
54146 +{
54147 + struct acl_subject_label *proc;
54148 + unsigned short i;
54149 +
54150 + proc = task->acl;
54151 +
54152 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54153 + return;
54154 +
54155 + for (i = 0; i < RLIM_NLIMITS; i++) {
54156 + if (!(proc->resmask & (1 << i)))
54157 + continue;
54158 +
54159 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54160 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54161 + }
54162 +
54163 + return;
54164 +}
54165 +
54166 +extern int __gr_process_user_ban(struct user_struct *user);
54167 +
54168 +int
54169 +gr_check_user_change(int real, int effective, int fs)
54170 +{
54171 + unsigned int i;
54172 + __u16 num;
54173 + uid_t *uidlist;
54174 + int curuid;
54175 + int realok = 0;
54176 + int effectiveok = 0;
54177 + int fsok = 0;
54178 +
54179 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54180 + struct user_struct *user;
54181 +
54182 + if (real == -1)
54183 + goto skipit;
54184 +
54185 + user = find_user(real);
54186 + if (user == NULL)
54187 + goto skipit;
54188 +
54189 + if (__gr_process_user_ban(user)) {
54190 + /* for find_user */
54191 + free_uid(user);
54192 + return 1;
54193 + }
54194 +
54195 + /* for find_user */
54196 + free_uid(user);
54197 +
54198 +skipit:
54199 +#endif
54200 +
54201 + if (unlikely(!(gr_status & GR_READY)))
54202 + return 0;
54203 +
54204 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54205 + gr_log_learn_id_change('u', real, effective, fs);
54206 +
54207 + num = current->acl->user_trans_num;
54208 + uidlist = current->acl->user_transitions;
54209 +
54210 + if (uidlist == NULL)
54211 + return 0;
54212 +
54213 + if (real == -1)
54214 + realok = 1;
54215 + if (effective == -1)
54216 + effectiveok = 1;
54217 + if (fs == -1)
54218 + fsok = 1;
54219 +
54220 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54221 + for (i = 0; i < num; i++) {
54222 + curuid = (int)uidlist[i];
54223 + if (real == curuid)
54224 + realok = 1;
54225 + if (effective == curuid)
54226 + effectiveok = 1;
54227 + if (fs == curuid)
54228 + fsok = 1;
54229 + }
54230 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54231 + for (i = 0; i < num; i++) {
54232 + curuid = (int)uidlist[i];
54233 + if (real == curuid)
54234 + break;
54235 + if (effective == curuid)
54236 + break;
54237 + if (fs == curuid)
54238 + break;
54239 + }
54240 + /* not in deny list */
54241 + if (i == num) {
54242 + realok = 1;
54243 + effectiveok = 1;
54244 + fsok = 1;
54245 + }
54246 + }
54247 +
54248 + if (realok && effectiveok && fsok)
54249 + return 0;
54250 + else {
54251 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54252 + return 1;
54253 + }
54254 +}
54255 +
54256 +int
54257 +gr_check_group_change(int real, int effective, int fs)
54258 +{
54259 + unsigned int i;
54260 + __u16 num;
54261 + gid_t *gidlist;
54262 + int curgid;
54263 + int realok = 0;
54264 + int effectiveok = 0;
54265 + int fsok = 0;
54266 +
54267 + if (unlikely(!(gr_status & GR_READY)))
54268 + return 0;
54269 +
54270 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54271 + gr_log_learn_id_change('g', real, effective, fs);
54272 +
54273 + num = current->acl->group_trans_num;
54274 + gidlist = current->acl->group_transitions;
54275 +
54276 + if (gidlist == NULL)
54277 + return 0;
54278 +
54279 + if (real == -1)
54280 + realok = 1;
54281 + if (effective == -1)
54282 + effectiveok = 1;
54283 + if (fs == -1)
54284 + fsok = 1;
54285 +
54286 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54287 + for (i = 0; i < num; i++) {
54288 + curgid = (int)gidlist[i];
54289 + if (real == curgid)
54290 + realok = 1;
54291 + if (effective == curgid)
54292 + effectiveok = 1;
54293 + if (fs == curgid)
54294 + fsok = 1;
54295 + }
54296 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54297 + for (i = 0; i < num; i++) {
54298 + curgid = (int)gidlist[i];
54299 + if (real == curgid)
54300 + break;
54301 + if (effective == curgid)
54302 + break;
54303 + if (fs == curgid)
54304 + break;
54305 + }
54306 + /* not in deny list */
54307 + if (i == num) {
54308 + realok = 1;
54309 + effectiveok = 1;
54310 + fsok = 1;
54311 + }
54312 + }
54313 +
54314 + if (realok && effectiveok && fsok)
54315 + return 0;
54316 + else {
54317 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54318 + return 1;
54319 + }
54320 +}
54321 +
54322 +void
54323 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54324 +{
54325 + struct acl_role_label *role = task->role;
54326 + struct acl_subject_label *subj = NULL;
54327 + struct acl_object_label *obj;
54328 + struct file *filp;
54329 +
54330 + if (unlikely(!(gr_status & GR_READY)))
54331 + return;
54332 +
54333 + filp = task->exec_file;
54334 +
54335 + /* kernel process, we'll give them the kernel role */
54336 + if (unlikely(!filp)) {
54337 + task->role = kernel_role;
54338 + task->acl = kernel_role->root_label;
54339 + return;
54340 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54341 + role = lookup_acl_role_label(task, uid, gid);
54342 +
54343 + /* perform subject lookup in possibly new role
54344 + we can use this result below in the case where role == task->role
54345 + */
54346 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54347 +
54348 + /* if we changed uid/gid, but result in the same role
54349 + and are using inheritance, don't lose the inherited subject
54350 + if current subject is other than what normal lookup
54351 + would result in, we arrived via inheritance, don't
54352 + lose subject
54353 + */
54354 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54355 + (subj == task->acl)))
54356 + task->acl = subj;
54357 +
54358 + task->role = role;
54359 +
54360 + task->is_writable = 0;
54361 +
54362 + /* ignore additional mmap checks for processes that are writable
54363 + by the default ACL */
54364 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54365 + if (unlikely(obj->mode & GR_WRITE))
54366 + task->is_writable = 1;
54367 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54368 + if (unlikely(obj->mode & GR_WRITE))
54369 + task->is_writable = 1;
54370 +
54371 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54372 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54373 +#endif
54374 +
54375 + gr_set_proc_res(task);
54376 +
54377 + return;
54378 +}
54379 +
54380 +int
54381 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54382 + const int unsafe_share)
54383 +{
54384 + struct task_struct *task = current;
54385 + struct acl_subject_label *newacl;
54386 + struct acl_object_label *obj;
54387 + __u32 retmode;
54388 +
54389 + if (unlikely(!(gr_status & GR_READY)))
54390 + return 0;
54391 +
54392 + newacl = chk_subj_label(dentry, mnt, task->role);
54393 +
54394 + task_lock(task);
54395 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
54396 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54397 + !(task->role->roletype & GR_ROLE_GOD) &&
54398 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54399 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
54400 + task_unlock(task);
54401 + if (unsafe_share)
54402 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54403 + else
54404 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54405 + return -EACCES;
54406 + }
54407 + task_unlock(task);
54408 +
54409 + obj = chk_obj_label(dentry, mnt, task->acl);
54410 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54411 +
54412 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54413 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54414 + if (obj->nested)
54415 + task->acl = obj->nested;
54416 + else
54417 + task->acl = newacl;
54418 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54419 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54420 +
54421 + task->is_writable = 0;
54422 +
54423 + /* ignore additional mmap checks for processes that are writable
54424 + by the default ACL */
54425 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54426 + if (unlikely(obj->mode & GR_WRITE))
54427 + task->is_writable = 1;
54428 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54429 + if (unlikely(obj->mode & GR_WRITE))
54430 + task->is_writable = 1;
54431 +
54432 + gr_set_proc_res(task);
54433 +
54434 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54435 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54436 +#endif
54437 + return 0;
54438 +}
54439 +
54440 +/* always called with valid inodev ptr */
54441 +static void
54442 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54443 +{
54444 + struct acl_object_label *matchpo;
54445 + struct acl_subject_label *matchps;
54446 + struct acl_subject_label *subj;
54447 + struct acl_role_label *role;
54448 + unsigned int x;
54449 +
54450 + FOR_EACH_ROLE_START(role)
54451 + FOR_EACH_SUBJECT_START(role, subj, x)
54452 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54453 + matchpo->mode |= GR_DELETED;
54454 + FOR_EACH_SUBJECT_END(subj,x)
54455 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54456 + if (subj->inode == ino && subj->device == dev)
54457 + subj->mode |= GR_DELETED;
54458 + FOR_EACH_NESTED_SUBJECT_END(subj)
54459 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54460 + matchps->mode |= GR_DELETED;
54461 + FOR_EACH_ROLE_END(role)
54462 +
54463 + inodev->nentry->deleted = 1;
54464 +
54465 + return;
54466 +}
54467 +
54468 +void
54469 +gr_handle_delete(const ino_t ino, const dev_t dev)
54470 +{
54471 + struct inodev_entry *inodev;
54472 +
54473 + if (unlikely(!(gr_status & GR_READY)))
54474 + return;
54475 +
54476 + write_lock(&gr_inode_lock);
54477 + inodev = lookup_inodev_entry(ino, dev);
54478 + if (inodev != NULL)
54479 + do_handle_delete(inodev, ino, dev);
54480 + write_unlock(&gr_inode_lock);
54481 +
54482 + return;
54483 +}
54484 +
54485 +static void
54486 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54487 + const ino_t newinode, const dev_t newdevice,
54488 + struct acl_subject_label *subj)
54489 +{
54490 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54491 + struct acl_object_label *match;
54492 +
54493 + match = subj->obj_hash[index];
54494 +
54495 + while (match && (match->inode != oldinode ||
54496 + match->device != olddevice ||
54497 + !(match->mode & GR_DELETED)))
54498 + match = match->next;
54499 +
54500 + if (match && (match->inode == oldinode)
54501 + && (match->device == olddevice)
54502 + && (match->mode & GR_DELETED)) {
54503 + if (match->prev == NULL) {
54504 + subj->obj_hash[index] = match->next;
54505 + if (match->next != NULL)
54506 + match->next->prev = NULL;
54507 + } else {
54508 + match->prev->next = match->next;
54509 + if (match->next != NULL)
54510 + match->next->prev = match->prev;
54511 + }
54512 + match->prev = NULL;
54513 + match->next = NULL;
54514 + match->inode = newinode;
54515 + match->device = newdevice;
54516 + match->mode &= ~GR_DELETED;
54517 +
54518 + insert_acl_obj_label(match, subj);
54519 + }
54520 +
54521 + return;
54522 +}
54523 +
54524 +static void
54525 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54526 + const ino_t newinode, const dev_t newdevice,
54527 + struct acl_role_label *role)
54528 +{
54529 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54530 + struct acl_subject_label *match;
54531 +
54532 + match = role->subj_hash[index];
54533 +
54534 + while (match && (match->inode != oldinode ||
54535 + match->device != olddevice ||
54536 + !(match->mode & GR_DELETED)))
54537 + match = match->next;
54538 +
54539 + if (match && (match->inode == oldinode)
54540 + && (match->device == olddevice)
54541 + && (match->mode & GR_DELETED)) {
54542 + if (match->prev == NULL) {
54543 + role->subj_hash[index] = match->next;
54544 + if (match->next != NULL)
54545 + match->next->prev = NULL;
54546 + } else {
54547 + match->prev->next = match->next;
54548 + if (match->next != NULL)
54549 + match->next->prev = match->prev;
54550 + }
54551 + match->prev = NULL;
54552 + match->next = NULL;
54553 + match->inode = newinode;
54554 + match->device = newdevice;
54555 + match->mode &= ~GR_DELETED;
54556 +
54557 + insert_acl_subj_label(match, role);
54558 + }
54559 +
54560 + return;
54561 +}
54562 +
54563 +static void
54564 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54565 + const ino_t newinode, const dev_t newdevice)
54566 +{
54567 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54568 + struct inodev_entry *match;
54569 +
54570 + match = inodev_set.i_hash[index];
54571 +
54572 + while (match && (match->nentry->inode != oldinode ||
54573 + match->nentry->device != olddevice || !match->nentry->deleted))
54574 + match = match->next;
54575 +
54576 + if (match && (match->nentry->inode == oldinode)
54577 + && (match->nentry->device == olddevice) &&
54578 + match->nentry->deleted) {
54579 + if (match->prev == NULL) {
54580 + inodev_set.i_hash[index] = match->next;
54581 + if (match->next != NULL)
54582 + match->next->prev = NULL;
54583 + } else {
54584 + match->prev->next = match->next;
54585 + if (match->next != NULL)
54586 + match->next->prev = match->prev;
54587 + }
54588 + match->prev = NULL;
54589 + match->next = NULL;
54590 + match->nentry->inode = newinode;
54591 + match->nentry->device = newdevice;
54592 + match->nentry->deleted = 0;
54593 +
54594 + insert_inodev_entry(match);
54595 + }
54596 +
54597 + return;
54598 +}
54599 +
54600 +static void
54601 +__do_handle_create(const struct name_entry *matchn, ino_t inode, dev_t dev)
54602 +{
54603 + struct acl_subject_label *subj;
54604 + struct acl_role_label *role;
54605 + unsigned int x;
54606 +
54607 + FOR_EACH_ROLE_START(role)
54608 + update_acl_subj_label(matchn->inode, matchn->device,
54609 + inode, dev, role);
54610 +
54611 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54612 + if ((subj->inode == inode) && (subj->device == dev)) {
54613 + subj->inode = inode;
54614 + subj->device = dev;
54615 + }
54616 + FOR_EACH_NESTED_SUBJECT_END(subj)
54617 + FOR_EACH_SUBJECT_START(role, subj, x)
54618 + update_acl_obj_label(matchn->inode, matchn->device,
54619 + inode, dev, subj);
54620 + FOR_EACH_SUBJECT_END(subj,x)
54621 + FOR_EACH_ROLE_END(role)
54622 +
54623 + update_inodev_entry(matchn->inode, matchn->device, inode, dev);
54624 +
54625 + return;
54626 +}
54627 +
54628 +static void
54629 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54630 + const struct vfsmount *mnt)
54631 +{
54632 + ino_t ino = dentry->d_inode->i_ino;
54633 + dev_t dev = __get_dev(dentry);
54634 +
54635 + __do_handle_create(matchn, ino, dev);
54636 +
54637 + return;
54638 +}
54639 +
54640 +void
54641 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54642 +{
54643 + struct name_entry *matchn;
54644 +
54645 + if (unlikely(!(gr_status & GR_READY)))
54646 + return;
54647 +
54648 + preempt_disable();
54649 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54650 +
54651 + if (unlikely((unsigned long)matchn)) {
54652 + write_lock(&gr_inode_lock);
54653 + do_handle_create(matchn, dentry, mnt);
54654 + write_unlock(&gr_inode_lock);
54655 + }
54656 + preempt_enable();
54657 +
54658 + return;
54659 +}
54660 +
54661 +void
54662 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54663 +{
54664 + struct name_entry *matchn;
54665 +
54666 + if (unlikely(!(gr_status & GR_READY)))
54667 + return;
54668 +
54669 + preempt_disable();
54670 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54671 +
54672 + if (unlikely((unsigned long)matchn)) {
54673 + write_lock(&gr_inode_lock);
54674 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54675 + write_unlock(&gr_inode_lock);
54676 + }
54677 + preempt_enable();
54678 +
54679 + return;
54680 +}
54681 +
54682 +void
54683 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54684 + struct dentry *old_dentry,
54685 + struct dentry *new_dentry,
54686 + struct vfsmount *mnt, const __u8 replace)
54687 +{
54688 + struct name_entry *matchn;
54689 + struct inodev_entry *inodev;
54690 + ino_t oldinode = old_dentry->d_inode->i_ino;
54691 + dev_t olddev = __get_dev(old_dentry);
54692 +
54693 + /* vfs_rename swaps the name and parent link for old_dentry and
54694 + new_dentry
54695 + at this point, old_dentry has the new name, parent link, and inode
54696 + for the renamed file
54697 + if a file is being replaced by a rename, new_dentry has the inode
54698 + and name for the replaced file
54699 + */
54700 +
54701 + if (unlikely(!(gr_status & GR_READY)))
54702 + return;
54703 +
54704 + preempt_disable();
54705 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54706 +
54707 + /* we wouldn't have to check d_inode if it weren't for
54708 + NFS silly-renaming
54709 + */
54710 +
54711 + write_lock(&gr_inode_lock);
54712 + if (unlikely(replace && new_dentry->d_inode)) {
54713 + ino_t newinode = new_dentry->d_inode->i_ino;
54714 + dev_t newdev = __get_dev(new_dentry);
54715 + inodev = lookup_inodev_entry(newinode, newdev);
54716 + if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
54717 + do_handle_delete(inodev, newinode, newdev);
54718 + }
54719 +
54720 + inodev = lookup_inodev_entry(oldinode, olddev);
54721 + if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
54722 + do_handle_delete(inodev, oldinode, olddev);
54723 +
54724 + if (unlikely((unsigned long)matchn))
54725 + do_handle_create(matchn, old_dentry, mnt);
54726 +
54727 + write_unlock(&gr_inode_lock);
54728 + preempt_enable();
54729 +
54730 + return;
54731 +}
54732 +
54733 +static int
54734 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54735 + unsigned char **sum)
54736 +{
54737 + struct acl_role_label *r;
54738 + struct role_allowed_ip *ipp;
54739 + struct role_transition *trans;
54740 + unsigned int i;
54741 + int found = 0;
54742 + u32 curr_ip = current->signal->curr_ip;
54743 +
54744 + current->signal->saved_ip = curr_ip;
54745 +
54746 + /* check transition table */
54747 +
54748 + for (trans = current->role->transitions; trans; trans = trans->next) {
54749 + if (!strcmp(rolename, trans->rolename)) {
54750 + found = 1;
54751 + break;
54752 + }
54753 + }
54754 +
54755 + if (!found)
54756 + return 0;
54757 +
54758 + /* handle special roles that do not require authentication
54759 + and check ip */
54760 +
54761 + FOR_EACH_ROLE_START(r)
54762 + if (!strcmp(rolename, r->rolename) &&
54763 + (r->roletype & GR_ROLE_SPECIAL)) {
54764 + found = 0;
54765 + if (r->allowed_ips != NULL) {
54766 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54767 + if ((ntohl(curr_ip) & ipp->netmask) ==
54768 + (ntohl(ipp->addr) & ipp->netmask))
54769 + found = 1;
54770 + }
54771 + } else
54772 + found = 2;
54773 + if (!found)
54774 + return 0;
54775 +
54776 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54777 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54778 + *salt = NULL;
54779 + *sum = NULL;
54780 + return 1;
54781 + }
54782 + }
54783 + FOR_EACH_ROLE_END(r)
54784 +
54785 + for (i = 0; i < num_sprole_pws; i++) {
54786 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54787 + *salt = acl_special_roles[i]->salt;
54788 + *sum = acl_special_roles[i]->sum;
54789 + return 1;
54790 + }
54791 + }
54792 +
54793 + return 0;
54794 +}
54795 +
54796 +static void
54797 +assign_special_role(char *rolename)
54798 +{
54799 + struct acl_object_label *obj;
54800 + struct acl_role_label *r;
54801 + struct acl_role_label *assigned = NULL;
54802 + struct task_struct *tsk;
54803 + struct file *filp;
54804 +
54805 + FOR_EACH_ROLE_START(r)
54806 + if (!strcmp(rolename, r->rolename) &&
54807 + (r->roletype & GR_ROLE_SPECIAL)) {
54808 + assigned = r;
54809 + break;
54810 + }
54811 + FOR_EACH_ROLE_END(r)
54812 +
54813 + if (!assigned)
54814 + return;
54815 +
54816 + read_lock(&tasklist_lock);
54817 + read_lock(&grsec_exec_file_lock);
54818 +
54819 + tsk = current->real_parent;
54820 + if (tsk == NULL)
54821 + goto out_unlock;
54822 +
54823 + filp = tsk->exec_file;
54824 + if (filp == NULL)
54825 + goto out_unlock;
54826 +
54827 + tsk->is_writable = 0;
54828 +
54829 + tsk->acl_sp_role = 1;
54830 + tsk->acl_role_id = ++acl_sp_role_value;
54831 + tsk->role = assigned;
54832 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54833 +
54834 + /* ignore additional mmap checks for processes that are writable
54835 + by the default ACL */
54836 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54837 + if (unlikely(obj->mode & GR_WRITE))
54838 + tsk->is_writable = 1;
54839 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54840 + if (unlikely(obj->mode & GR_WRITE))
54841 + tsk->is_writable = 1;
54842 +
54843 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54844 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54845 +#endif
54846 +
54847 +out_unlock:
54848 + read_unlock(&grsec_exec_file_lock);
54849 + read_unlock(&tasklist_lock);
54850 + return;
54851 +}
54852 +
54853 +int gr_check_secure_terminal(struct task_struct *task)
54854 +{
54855 + struct task_struct *p, *p2, *p3;
54856 + struct files_struct *files;
54857 + struct fdtable *fdt;
54858 + struct file *our_file = NULL, *file;
54859 + int i;
54860 +
54861 + if (task->signal->tty == NULL)
54862 + return 1;
54863 +
54864 + files = get_files_struct(task);
54865 + if (files != NULL) {
54866 + rcu_read_lock();
54867 + fdt = files_fdtable(files);
54868 + for (i=0; i < fdt->max_fds; i++) {
54869 + file = fcheck_files(files, i);
54870 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54871 + get_file(file);
54872 + our_file = file;
54873 + }
54874 + }
54875 + rcu_read_unlock();
54876 + put_files_struct(files);
54877 + }
54878 +
54879 + if (our_file == NULL)
54880 + return 1;
54881 +
54882 + read_lock(&tasklist_lock);
54883 + do_each_thread(p2, p) {
54884 + files = get_files_struct(p);
54885 + if (files == NULL ||
54886 + (p->signal && p->signal->tty == task->signal->tty)) {
54887 + if (files != NULL)
54888 + put_files_struct(files);
54889 + continue;
54890 + }
54891 + rcu_read_lock();
54892 + fdt = files_fdtable(files);
54893 + for (i=0; i < fdt->max_fds; i++) {
54894 + file = fcheck_files(files, i);
54895 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54896 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54897 + p3 = task;
54898 + while (p3->pid > 0) {
54899 + if (p3 == p)
54900 + break;
54901 + p3 = p3->real_parent;
54902 + }
54903 + if (p3 == p)
54904 + break;
54905 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54906 + gr_handle_alertkill(p);
54907 + rcu_read_unlock();
54908 + put_files_struct(files);
54909 + read_unlock(&tasklist_lock);
54910 + fput(our_file);
54911 + return 0;
54912 + }
54913 + }
54914 + rcu_read_unlock();
54915 + put_files_struct(files);
54916 + } while_each_thread(p2, p);
54917 + read_unlock(&tasklist_lock);
54918 +
54919 + fput(our_file);
54920 + return 1;
54921 +}
54922 +
54923 +ssize_t
54924 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54925 +{
54926 + struct gr_arg_wrapper uwrap;
54927 + unsigned char *sprole_salt = NULL;
54928 + unsigned char *sprole_sum = NULL;
54929 + int error = sizeof (struct gr_arg_wrapper);
54930 + int error2 = 0;
54931 +
54932 + mutex_lock(&gr_dev_mutex);
54933 +
54934 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54935 + error = -EPERM;
54936 + goto out;
54937 + }
54938 +
54939 + if (count != sizeof (struct gr_arg_wrapper)) {
54940 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54941 + error = -EINVAL;
54942 + goto out;
54943 + }
54944 +
54945 +
54946 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54947 + gr_auth_expires = 0;
54948 + gr_auth_attempts = 0;
54949 + }
54950 +
54951 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54952 + error = -EFAULT;
54953 + goto out;
54954 + }
54955 +
54956 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54957 + error = -EINVAL;
54958 + goto out;
54959 + }
54960 +
54961 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54962 + error = -EFAULT;
54963 + goto out;
54964 + }
54965 +
54966 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54967 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54968 + time_after(gr_auth_expires, get_seconds())) {
54969 + error = -EBUSY;
54970 + goto out;
54971 + }
54972 +
54973 + /* if non-root trying to do anything other than use a special role,
54974 + do not attempt authentication, do not count towards authentication
54975 + locking
54976 + */
54977 +
54978 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54979 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54980 + current_uid()) {
54981 + error = -EPERM;
54982 + goto out;
54983 + }
54984 +
54985 + /* ensure pw and special role name are null terminated */
54986 +
54987 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54988 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54989 +
54990 + /* Okay.
54991 + * We have our enough of the argument structure..(we have yet
54992 + * to copy_from_user the tables themselves) . Copy the tables
54993 + * only if we need them, i.e. for loading operations. */
54994 +
54995 + switch (gr_usermode->mode) {
54996 + case GR_STATUS:
54997 + if (gr_status & GR_READY) {
54998 + error = 1;
54999 + if (!gr_check_secure_terminal(current))
55000 + error = 3;
55001 + } else
55002 + error = 2;
55003 + goto out;
55004 + case GR_SHUTDOWN:
55005 + if ((gr_status & GR_READY)
55006 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55007 + pax_open_kernel();
55008 + gr_status &= ~GR_READY;
55009 + pax_close_kernel();
55010 +
55011 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
55012 + free_variables();
55013 + memset(gr_usermode, 0, sizeof (struct gr_arg));
55014 + memset(gr_system_salt, 0, GR_SALT_LEN);
55015 + memset(gr_system_sum, 0, GR_SHA_LEN);
55016 + } else if (gr_status & GR_READY) {
55017 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
55018 + error = -EPERM;
55019 + } else {
55020 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
55021 + error = -EAGAIN;
55022 + }
55023 + break;
55024 + case GR_ENABLE:
55025 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
55026 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
55027 + else {
55028 + if (gr_status & GR_READY)
55029 + error = -EAGAIN;
55030 + else
55031 + error = error2;
55032 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
55033 + }
55034 + break;
55035 + case GR_RELOAD:
55036 + if (!(gr_status & GR_READY)) {
55037 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
55038 + error = -EAGAIN;
55039 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55040 + lock_kernel();
55041 +
55042 + pax_open_kernel();
55043 + gr_status &= ~GR_READY;
55044 + pax_close_kernel();
55045 +
55046 + free_variables();
55047 + if (!(error2 = gracl_init(gr_usermode))) {
55048 + unlock_kernel();
55049 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
55050 + } else {
55051 + unlock_kernel();
55052 + error = error2;
55053 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55054 + }
55055 + } else {
55056 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55057 + error = -EPERM;
55058 + }
55059 + break;
55060 + case GR_SEGVMOD:
55061 + if (unlikely(!(gr_status & GR_READY))) {
55062 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
55063 + error = -EAGAIN;
55064 + break;
55065 + }
55066 +
55067 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55068 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
55069 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55070 + struct acl_subject_label *segvacl;
55071 + segvacl =
55072 + lookup_acl_subj_label(gr_usermode->segv_inode,
55073 + gr_usermode->segv_device,
55074 + current->role);
55075 + if (segvacl) {
55076 + segvacl->crashes = 0;
55077 + segvacl->expires = 0;
55078 + }
55079 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55080 + gr_remove_uid(gr_usermode->segv_uid);
55081 + }
55082 + } else {
55083 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55084 + error = -EPERM;
55085 + }
55086 + break;
55087 + case GR_SPROLE:
55088 + case GR_SPROLEPAM:
55089 + if (unlikely(!(gr_status & GR_READY))) {
55090 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55091 + error = -EAGAIN;
55092 + break;
55093 + }
55094 +
55095 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55096 + current->role->expires = 0;
55097 + current->role->auth_attempts = 0;
55098 + }
55099 +
55100 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55101 + time_after(current->role->expires, get_seconds())) {
55102 + error = -EBUSY;
55103 + goto out;
55104 + }
55105 +
55106 + if (lookup_special_role_auth
55107 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55108 + && ((!sprole_salt && !sprole_sum)
55109 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55110 + char *p = "";
55111 + assign_special_role(gr_usermode->sp_role);
55112 + read_lock(&tasklist_lock);
55113 + if (current->real_parent)
55114 + p = current->real_parent->role->rolename;
55115 + read_unlock(&tasklist_lock);
55116 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55117 + p, acl_sp_role_value);
55118 + } else {
55119 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55120 + error = -EPERM;
55121 + if(!(current->role->auth_attempts++))
55122 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55123 +
55124 + goto out;
55125 + }
55126 + break;
55127 + case GR_UNSPROLE:
55128 + if (unlikely(!(gr_status & GR_READY))) {
55129 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55130 + error = -EAGAIN;
55131 + break;
55132 + }
55133 +
55134 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55135 + char *p = "";
55136 + int i = 0;
55137 +
55138 + read_lock(&tasklist_lock);
55139 + if (current->real_parent) {
55140 + p = current->real_parent->role->rolename;
55141 + i = current->real_parent->acl_role_id;
55142 + }
55143 + read_unlock(&tasklist_lock);
55144 +
55145 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55146 + gr_set_acls(1);
55147 + } else {
55148 + error = -EPERM;
55149 + goto out;
55150 + }
55151 + break;
55152 + default:
55153 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55154 + error = -EINVAL;
55155 + break;
55156 + }
55157 +
55158 + if (error != -EPERM)
55159 + goto out;
55160 +
55161 + if(!(gr_auth_attempts++))
55162 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55163 +
55164 + out:
55165 + mutex_unlock(&gr_dev_mutex);
55166 + return error;
55167 +}
55168 +
55169 +/* must be called with
55170 + rcu_read_lock();
55171 + read_lock(&tasklist_lock);
55172 + read_lock(&grsec_exec_file_lock);
55173 +*/
55174 +int gr_apply_subject_to_task(struct task_struct *task)
55175 +{
55176 + struct acl_object_label *obj;
55177 + char *tmpname;
55178 + struct acl_subject_label *tmpsubj;
55179 + struct file *filp;
55180 + struct name_entry *nmatch;
55181 +
55182 + filp = task->exec_file;
55183 + if (filp == NULL)
55184 + return 0;
55185 +
55186 + /* the following is to apply the correct subject
55187 + on binaries running when the RBAC system
55188 + is enabled, when the binaries have been
55189 + replaced or deleted since their execution
55190 + -----
55191 + when the RBAC system starts, the inode/dev
55192 + from exec_file will be one the RBAC system
55193 + is unaware of. It only knows the inode/dev
55194 + of the present file on disk, or the absence
55195 + of it.
55196 + */
55197 + preempt_disable();
55198 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55199 +
55200 + nmatch = lookup_name_entry(tmpname);
55201 + preempt_enable();
55202 + tmpsubj = NULL;
55203 + if (nmatch) {
55204 + if (nmatch->deleted)
55205 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55206 + else
55207 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55208 + if (tmpsubj != NULL)
55209 + task->acl = tmpsubj;
55210 + }
55211 + if (tmpsubj == NULL)
55212 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55213 + task->role);
55214 + if (task->acl) {
55215 + task->is_writable = 0;
55216 + /* ignore additional mmap checks for processes that are writable
55217 + by the default ACL */
55218 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55219 + if (unlikely(obj->mode & GR_WRITE))
55220 + task->is_writable = 1;
55221 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55222 + if (unlikely(obj->mode & GR_WRITE))
55223 + task->is_writable = 1;
55224 +
55225 + gr_set_proc_res(task);
55226 +
55227 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55228 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55229 +#endif
55230 + } else {
55231 + return 1;
55232 + }
55233 +
55234 + return 0;
55235 +}
55236 +
55237 +int
55238 +gr_set_acls(const int type)
55239 +{
55240 + struct task_struct *task, *task2;
55241 + struct acl_role_label *role = current->role;
55242 + __u16 acl_role_id = current->acl_role_id;
55243 + const struct cred *cred;
55244 + int ret;
55245 +
55246 + rcu_read_lock();
55247 + read_lock(&tasklist_lock);
55248 + read_lock(&grsec_exec_file_lock);
55249 + do_each_thread(task2, task) {
55250 + /* check to see if we're called from the exit handler,
55251 + if so, only replace ACLs that have inherited the admin
55252 + ACL */
55253 +
55254 + if (type && (task->role != role ||
55255 + task->acl_role_id != acl_role_id))
55256 + continue;
55257 +
55258 + task->acl_role_id = 0;
55259 + task->acl_sp_role = 0;
55260 +
55261 + if (task->exec_file) {
55262 + cred = __task_cred(task);
55263 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55264 +
55265 + ret = gr_apply_subject_to_task(task);
55266 + if (ret) {
55267 + read_unlock(&grsec_exec_file_lock);
55268 + read_unlock(&tasklist_lock);
55269 + rcu_read_unlock();
55270 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55271 + return ret;
55272 + }
55273 + } else {
55274 + // it's a kernel process
55275 + task->role = kernel_role;
55276 + task->acl = kernel_role->root_label;
55277 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55278 + task->acl->mode &= ~GR_PROCFIND;
55279 +#endif
55280 + }
55281 + } while_each_thread(task2, task);
55282 + read_unlock(&grsec_exec_file_lock);
55283 + read_unlock(&tasklist_lock);
55284 + rcu_read_unlock();
55285 +
55286 + return 0;
55287 +}
55288 +
55289 +void
55290 +gr_learn_resource(const struct task_struct *task,
55291 + const int res, const unsigned long wanted, const int gt)
55292 +{
55293 + struct acl_subject_label *acl;
55294 + const struct cred *cred;
55295 +
55296 + if (unlikely((gr_status & GR_READY) &&
55297 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55298 + goto skip_reslog;
55299 +
55300 +#ifdef CONFIG_GRKERNSEC_RESLOG
55301 + gr_log_resource(task, res, wanted, gt);
55302 +#endif
55303 + skip_reslog:
55304 +
55305 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55306 + return;
55307 +
55308 + acl = task->acl;
55309 +
55310 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55311 + !(acl->resmask & (1 << (unsigned short) res))))
55312 + return;
55313 +
55314 + if (wanted >= acl->res[res].rlim_cur) {
55315 + unsigned long res_add;
55316 +
55317 + res_add = wanted;
55318 + switch (res) {
55319 + case RLIMIT_CPU:
55320 + res_add += GR_RLIM_CPU_BUMP;
55321 + break;
55322 + case RLIMIT_FSIZE:
55323 + res_add += GR_RLIM_FSIZE_BUMP;
55324 + break;
55325 + case RLIMIT_DATA:
55326 + res_add += GR_RLIM_DATA_BUMP;
55327 + break;
55328 + case RLIMIT_STACK:
55329 + res_add += GR_RLIM_STACK_BUMP;
55330 + break;
55331 + case RLIMIT_CORE:
55332 + res_add += GR_RLIM_CORE_BUMP;
55333 + break;
55334 + case RLIMIT_RSS:
55335 + res_add += GR_RLIM_RSS_BUMP;
55336 + break;
55337 + case RLIMIT_NPROC:
55338 + res_add += GR_RLIM_NPROC_BUMP;
55339 + break;
55340 + case RLIMIT_NOFILE:
55341 + res_add += GR_RLIM_NOFILE_BUMP;
55342 + break;
55343 + case RLIMIT_MEMLOCK:
55344 + res_add += GR_RLIM_MEMLOCK_BUMP;
55345 + break;
55346 + case RLIMIT_AS:
55347 + res_add += GR_RLIM_AS_BUMP;
55348 + break;
55349 + case RLIMIT_LOCKS:
55350 + res_add += GR_RLIM_LOCKS_BUMP;
55351 + break;
55352 + case RLIMIT_SIGPENDING:
55353 + res_add += GR_RLIM_SIGPENDING_BUMP;
55354 + break;
55355 + case RLIMIT_MSGQUEUE:
55356 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55357 + break;
55358 + case RLIMIT_NICE:
55359 + res_add += GR_RLIM_NICE_BUMP;
55360 + break;
55361 + case RLIMIT_RTPRIO:
55362 + res_add += GR_RLIM_RTPRIO_BUMP;
55363 + break;
55364 + case RLIMIT_RTTIME:
55365 + res_add += GR_RLIM_RTTIME_BUMP;
55366 + break;
55367 + }
55368 +
55369 + acl->res[res].rlim_cur = res_add;
55370 +
55371 + if (wanted > acl->res[res].rlim_max)
55372 + acl->res[res].rlim_max = res_add;
55373 +
55374 + /* only log the subject filename, since resource logging is supported for
55375 + single-subject learning only */
55376 + rcu_read_lock();
55377 + cred = __task_cred(task);
55378 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55379 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55380 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55381 + "", (unsigned long) res, &task->signal->saved_ip);
55382 + rcu_read_unlock();
55383 + }
55384 +
55385 + return;
55386 +}
55387 +
55388 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55389 +void
55390 +pax_set_initial_flags(struct linux_binprm *bprm)
55391 +{
55392 + struct task_struct *task = current;
55393 + struct acl_subject_label *proc;
55394 + unsigned long flags;
55395 +
55396 + if (unlikely(!(gr_status & GR_READY)))
55397 + return;
55398 +
55399 + flags = pax_get_flags(task);
55400 +
55401 + proc = task->acl;
55402 +
55403 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55404 + flags &= ~MF_PAX_PAGEEXEC;
55405 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55406 + flags &= ~MF_PAX_SEGMEXEC;
55407 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55408 + flags &= ~MF_PAX_RANDMMAP;
55409 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55410 + flags &= ~MF_PAX_EMUTRAMP;
55411 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55412 + flags &= ~MF_PAX_MPROTECT;
55413 +
55414 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55415 + flags |= MF_PAX_PAGEEXEC;
55416 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55417 + flags |= MF_PAX_SEGMEXEC;
55418 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55419 + flags |= MF_PAX_RANDMMAP;
55420 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55421 + flags |= MF_PAX_EMUTRAMP;
55422 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55423 + flags |= MF_PAX_MPROTECT;
55424 +
55425 + pax_set_flags(task, flags);
55426 +
55427 + return;
55428 +}
55429 +#endif
55430 +
55431 +#ifdef CONFIG_SYSCTL
55432 +/* Eric Biederman likes breaking userland ABI and every inode-based security
55433 + system to save 35kb of memory */
55434 +
55435 +/* we modify the passed in filename, but adjust it back before returning */
55436 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
55437 +{
55438 + struct name_entry *nmatch;
55439 + char *p, *lastp = NULL;
55440 + struct acl_object_label *obj = NULL, *tmp;
55441 + struct acl_subject_label *tmpsubj;
55442 + char c = '\0';
55443 +
55444 + read_lock(&gr_inode_lock);
55445 +
55446 + p = name + len - 1;
55447 + do {
55448 + nmatch = lookup_name_entry(name);
55449 + if (lastp != NULL)
55450 + *lastp = c;
55451 +
55452 + if (nmatch == NULL)
55453 + goto next_component;
55454 + tmpsubj = current->acl;
55455 + do {
55456 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
55457 + if (obj != NULL) {
55458 + tmp = obj->globbed;
55459 + while (tmp) {
55460 + if (!glob_match(tmp->filename, name)) {
55461 + obj = tmp;
55462 + goto found_obj;
55463 + }
55464 + tmp = tmp->next;
55465 + }
55466 + goto found_obj;
55467 + }
55468 + } while ((tmpsubj = tmpsubj->parent_subject));
55469 +next_component:
55470 + /* end case */
55471 + if (p == name)
55472 + break;
55473 +
55474 + while (*p != '/')
55475 + p--;
55476 + if (p == name)
55477 + lastp = p + 1;
55478 + else {
55479 + lastp = p;
55480 + p--;
55481 + }
55482 + c = *lastp;
55483 + *lastp = '\0';
55484 + } while (1);
55485 +found_obj:
55486 + read_unlock(&gr_inode_lock);
55487 + /* obj returned will always be non-null */
55488 + return obj;
55489 +}
55490 +
55491 +/* returns 0 when allowing, non-zero on error
55492 + op of 0 is used for readdir, so we don't log the names of hidden files
55493 +*/
55494 +__u32
55495 +gr_handle_sysctl(const struct ctl_table *table, const int op)
55496 +{
55497 + ctl_table *tmp;
55498 + const char *proc_sys = "/proc/sys";
55499 + char *path;
55500 + struct acl_object_label *obj;
55501 + unsigned short len = 0, pos = 0, depth = 0, i;
55502 + __u32 err = 0;
55503 + __u32 mode = 0;
55504 +
55505 + if (unlikely(!(gr_status & GR_READY)))
55506 + return 0;
55507 +
55508 + /* for now, ignore operations on non-sysctl entries if it's not a
55509 + readdir*/
55510 + if (table->child != NULL && op != 0)
55511 + return 0;
55512 +
55513 + mode |= GR_FIND;
55514 + /* it's only a read if it's an entry, read on dirs is for readdir */
55515 + if (op & MAY_READ)
55516 + mode |= GR_READ;
55517 + if (op & MAY_WRITE)
55518 + mode |= GR_WRITE;
55519 +
55520 + preempt_disable();
55521 +
55522 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
55523 +
55524 + /* it's only a read/write if it's an actual entry, not a dir
55525 + (which are opened for readdir)
55526 + */
55527 +
55528 + /* convert the requested sysctl entry into a pathname */
55529 +
55530 + for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
55531 + len += strlen(tmp->procname);
55532 + len++;
55533 + depth++;
55534 + }
55535 +
55536 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
55537 + /* deny */
55538 + goto out;
55539 + }
55540 +
55541 + memset(path, 0, PAGE_SIZE);
55542 +
55543 + memcpy(path, proc_sys, strlen(proc_sys));
55544 +
55545 + pos += strlen(proc_sys);
55546 +
55547 + for (; depth > 0; depth--) {
55548 + path[pos] = '/';
55549 + pos++;
55550 + for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
55551 + if (depth == i) {
55552 + memcpy(path + pos, tmp->procname,
55553 + strlen(tmp->procname));
55554 + pos += strlen(tmp->procname);
55555 + }
55556 + i++;
55557 + }
55558 + }
55559 +
55560 + obj = gr_lookup_by_name(path, pos);
55561 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
55562 +
55563 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
55564 + ((err & mode) != mode))) {
55565 + __u32 new_mode = mode;
55566 +
55567 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55568 +
55569 + err = 0;
55570 + gr_log_learn_sysctl(path, new_mode);
55571 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
55572 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
55573 + err = -ENOENT;
55574 + } else if (!(err & GR_FIND)) {
55575 + err = -ENOENT;
55576 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
55577 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
55578 + path, (mode & GR_READ) ? " reading" : "",
55579 + (mode & GR_WRITE) ? " writing" : "");
55580 + err = -EACCES;
55581 + } else if ((err & mode) != mode) {
55582 + err = -EACCES;
55583 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
55584 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
55585 + path, (mode & GR_READ) ? " reading" : "",
55586 + (mode & GR_WRITE) ? " writing" : "");
55587 + err = 0;
55588 + } else
55589 + err = 0;
55590 +
55591 + out:
55592 + preempt_enable();
55593 +
55594 + return err;
55595 +}
55596 +#endif
55597 +
55598 +int
55599 +gr_handle_proc_ptrace(struct task_struct *task)
55600 +{
55601 + struct file *filp;
55602 + struct task_struct *tmp = task;
55603 + struct task_struct *curtemp = current;
55604 + __u32 retmode;
55605 +
55606 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55607 + if (unlikely(!(gr_status & GR_READY)))
55608 + return 0;
55609 +#endif
55610 +
55611 + read_lock(&tasklist_lock);
55612 + read_lock(&grsec_exec_file_lock);
55613 + filp = task->exec_file;
55614 +
55615 + while (tmp->pid > 0) {
55616 + if (tmp == curtemp)
55617 + break;
55618 + tmp = tmp->real_parent;
55619 + }
55620 +
55621 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55622 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55623 + read_unlock(&grsec_exec_file_lock);
55624 + read_unlock(&tasklist_lock);
55625 + return 1;
55626 + }
55627 +
55628 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55629 + if (!(gr_status & GR_READY)) {
55630 + read_unlock(&grsec_exec_file_lock);
55631 + read_unlock(&tasklist_lock);
55632 + return 0;
55633 + }
55634 +#endif
55635 +
55636 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55637 + read_unlock(&grsec_exec_file_lock);
55638 + read_unlock(&tasklist_lock);
55639 +
55640 + if (retmode & GR_NOPTRACE)
55641 + return 1;
55642 +
55643 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55644 + && (current->acl != task->acl || (current->acl != current->role->root_label
55645 + && current->pid != task->pid)))
55646 + return 1;
55647 +
55648 + return 0;
55649 +}
55650 +
55651 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55652 +{
55653 + if (unlikely(!(gr_status & GR_READY)))
55654 + return;
55655 +
55656 + if (!(current->role->roletype & GR_ROLE_GOD))
55657 + return;
55658 +
55659 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55660 + p->role->rolename, gr_task_roletype_to_char(p),
55661 + p->acl->filename);
55662 +}
55663 +
55664 +int
55665 +gr_handle_ptrace(struct task_struct *task, const long request)
55666 +{
55667 + struct task_struct *tmp = task;
55668 + struct task_struct *curtemp = current;
55669 + __u32 retmode;
55670 +
55671 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55672 + if (unlikely(!(gr_status & GR_READY)))
55673 + return 0;
55674 +#endif
55675 +
55676 + read_lock(&tasklist_lock);
55677 + while (tmp->pid > 0) {
55678 + if (tmp == curtemp)
55679 + break;
55680 + tmp = tmp->real_parent;
55681 + }
55682 +
55683 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55684 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55685 + read_unlock(&tasklist_lock);
55686 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55687 + return 1;
55688 + }
55689 + read_unlock(&tasklist_lock);
55690 +
55691 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55692 + if (!(gr_status & GR_READY))
55693 + return 0;
55694 +#endif
55695 +
55696 + read_lock(&grsec_exec_file_lock);
55697 + if (unlikely(!task->exec_file)) {
55698 + read_unlock(&grsec_exec_file_lock);
55699 + return 0;
55700 + }
55701 +
55702 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55703 + read_unlock(&grsec_exec_file_lock);
55704 +
55705 + if (retmode & GR_NOPTRACE) {
55706 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55707 + return 1;
55708 + }
55709 +
55710 + if (retmode & GR_PTRACERD) {
55711 + switch (request) {
55712 + case PTRACE_POKETEXT:
55713 + case PTRACE_POKEDATA:
55714 + case PTRACE_POKEUSR:
55715 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55716 + case PTRACE_SETREGS:
55717 + case PTRACE_SETFPREGS:
55718 +#endif
55719 +#ifdef CONFIG_X86
55720 + case PTRACE_SETFPXREGS:
55721 +#endif
55722 +#ifdef CONFIG_ALTIVEC
55723 + case PTRACE_SETVRREGS:
55724 +#endif
55725 + return 1;
55726 + default:
55727 + return 0;
55728 + }
55729 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55730 + !(current->role->roletype & GR_ROLE_GOD) &&
55731 + (current->acl != task->acl)) {
55732 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55733 + return 1;
55734 + }
55735 +
55736 + return 0;
55737 +}
55738 +
55739 +static int is_writable_mmap(const struct file *filp)
55740 +{
55741 + struct task_struct *task = current;
55742 + struct acl_object_label *obj, *obj2;
55743 +
55744 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55745 + !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))) {
55746 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55747 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55748 + task->role->root_label);
55749 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55750 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55751 + return 1;
55752 + }
55753 + }
55754 + return 0;
55755 +}
55756 +
55757 +int
55758 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55759 +{
55760 + __u32 mode;
55761 +
55762 + if (unlikely(!file || !(prot & PROT_EXEC)))
55763 + return 1;
55764 +
55765 + if (is_writable_mmap(file))
55766 + return 0;
55767 +
55768 + mode =
55769 + gr_search_file(file->f_path.dentry,
55770 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55771 + file->f_path.mnt);
55772 +
55773 + if (!gr_tpe_allow(file))
55774 + return 0;
55775 +
55776 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55777 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55778 + return 0;
55779 + } else if (unlikely(!(mode & GR_EXEC))) {
55780 + return 0;
55781 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55782 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55783 + return 1;
55784 + }
55785 +
55786 + return 1;
55787 +}
55788 +
55789 +int
55790 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55791 +{
55792 + __u32 mode;
55793 +
55794 + if (unlikely(!file || !(prot & PROT_EXEC)))
55795 + return 1;
55796 +
55797 + if (is_writable_mmap(file))
55798 + return 0;
55799 +
55800 + mode =
55801 + gr_search_file(file->f_path.dentry,
55802 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55803 + file->f_path.mnt);
55804 +
55805 + if (!gr_tpe_allow(file))
55806 + return 0;
55807 +
55808 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55809 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55810 + return 0;
55811 + } else if (unlikely(!(mode & GR_EXEC))) {
55812 + return 0;
55813 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55814 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55815 + return 1;
55816 + }
55817 +
55818 + return 1;
55819 +}
55820 +
55821 +void
55822 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55823 +{
55824 + unsigned long runtime;
55825 + unsigned long cputime;
55826 + unsigned int wday, cday;
55827 + __u8 whr, chr;
55828 + __u8 wmin, cmin;
55829 + __u8 wsec, csec;
55830 + struct timespec timeval;
55831 +
55832 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55833 + !(task->acl->mode & GR_PROCACCT)))
55834 + return;
55835 +
55836 + do_posix_clock_monotonic_gettime(&timeval);
55837 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55838 + wday = runtime / (3600 * 24);
55839 + runtime -= wday * (3600 * 24);
55840 + whr = runtime / 3600;
55841 + runtime -= whr * 3600;
55842 + wmin = runtime / 60;
55843 + runtime -= wmin * 60;
55844 + wsec = runtime;
55845 +
55846 + cputime = (task->utime + task->stime) / HZ;
55847 + cday = cputime / (3600 * 24);
55848 + cputime -= cday * (3600 * 24);
55849 + chr = cputime / 3600;
55850 + cputime -= chr * 3600;
55851 + cmin = cputime / 60;
55852 + cputime -= cmin * 60;
55853 + csec = cputime;
55854 +
55855 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55856 +
55857 + return;
55858 +}
55859 +
55860 +void gr_set_kernel_label(struct task_struct *task)
55861 +{
55862 + if (gr_status & GR_READY) {
55863 + task->role = kernel_role;
55864 + task->acl = kernel_role->root_label;
55865 + }
55866 + return;
55867 +}
55868 +
55869 +#ifdef CONFIG_TASKSTATS
55870 +int gr_is_taskstats_denied(int pid)
55871 +{
55872 + struct task_struct *task;
55873 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55874 + const struct cred *cred;
55875 +#endif
55876 + int ret = 0;
55877 +
55878 + /* restrict taskstats viewing to un-chrooted root users
55879 + who have the 'view' subject flag if the RBAC system is enabled
55880 + */
55881 +
55882 + rcu_read_lock();
55883 + read_lock(&tasklist_lock);
55884 + task = find_task_by_vpid(pid);
55885 + if (task) {
55886 +#ifdef CONFIG_GRKERNSEC_CHROOT
55887 + if (proc_is_chrooted(task))
55888 + ret = -EACCES;
55889 +#endif
55890 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55891 + cred = __task_cred(task);
55892 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55893 + if (cred->uid != 0)
55894 + ret = -EACCES;
55895 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55896 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55897 + ret = -EACCES;
55898 +#endif
55899 +#endif
55900 + if (gr_status & GR_READY) {
55901 + if (!(task->acl->mode & GR_VIEW))
55902 + ret = -EACCES;
55903 + }
55904 + } else
55905 + ret = -ENOENT;
55906 +
55907 + read_unlock(&tasklist_lock);
55908 + rcu_read_unlock();
55909 +
55910 + return ret;
55911 +}
55912 +#endif
55913 +
55914 +/* AUXV entries are filled via a descendant of search_binary_handler
55915 + after we've already applied the subject for the target
55916 +*/
55917 +int gr_acl_enable_at_secure(void)
55918 +{
55919 + if (unlikely(!(gr_status & GR_READY)))
55920 + return 0;
55921 +
55922 + if (current->acl->mode & GR_ATSECURE)
55923 + return 1;
55924 +
55925 + return 0;
55926 +}
55927 +
55928 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55929 +{
55930 + struct task_struct *task = current;
55931 + struct dentry *dentry = file->f_path.dentry;
55932 + struct vfsmount *mnt = file->f_path.mnt;
55933 + struct acl_object_label *obj, *tmp;
55934 + struct acl_subject_label *subj;
55935 + unsigned int bufsize;
55936 + int is_not_root;
55937 + char *path;
55938 + dev_t dev = __get_dev(dentry);
55939 +
55940 + if (unlikely(!(gr_status & GR_READY)))
55941 + return 1;
55942 +
55943 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55944 + return 1;
55945 +
55946 + /* ignore Eric Biederman */
55947 + if (IS_PRIVATE(dentry->d_inode))
55948 + return 1;
55949 +
55950 + subj = task->acl;
55951 + do {
55952 + obj = lookup_acl_obj_label(ino, dev, subj);
55953 + if (obj != NULL)
55954 + return (obj->mode & GR_FIND) ? 1 : 0;
55955 + } while ((subj = subj->parent_subject));
55956 +
55957 + /* this is purely an optimization since we're looking for an object
55958 + for the directory we're doing a readdir on
55959 + if it's possible for any globbed object to match the entry we're
55960 + filling into the directory, then the object we find here will be
55961 + an anchor point with attached globbed objects
55962 + */
55963 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55964 + if (obj->globbed == NULL)
55965 + return (obj->mode & GR_FIND) ? 1 : 0;
55966 +
55967 + is_not_root = ((obj->filename[0] == '/') &&
55968 + (obj->filename[1] == '\0')) ? 0 : 1;
55969 + bufsize = PAGE_SIZE - namelen - is_not_root;
55970 +
55971 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55972 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55973 + return 1;
55974 +
55975 + preempt_disable();
55976 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55977 + bufsize);
55978 +
55979 + bufsize = strlen(path);
55980 +
55981 + /* if base is "/", don't append an additional slash */
55982 + if (is_not_root)
55983 + *(path + bufsize) = '/';
55984 + memcpy(path + bufsize + is_not_root, name, namelen);
55985 + *(path + bufsize + namelen + is_not_root) = '\0';
55986 +
55987 + tmp = obj->globbed;
55988 + while (tmp) {
55989 + if (!glob_match(tmp->filename, path)) {
55990 + preempt_enable();
55991 + return (tmp->mode & GR_FIND) ? 1 : 0;
55992 + }
55993 + tmp = tmp->next;
55994 + }
55995 + preempt_enable();
55996 + return (obj->mode & GR_FIND) ? 1 : 0;
55997 +}
55998 +
55999 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
56000 +EXPORT_SYMBOL(gr_acl_is_enabled);
56001 +#endif
56002 +EXPORT_SYMBOL(gr_learn_resource);
56003 +EXPORT_SYMBOL(gr_set_kernel_label);
56004 +#ifdef CONFIG_SECURITY
56005 +EXPORT_SYMBOL(gr_check_user_change);
56006 +EXPORT_SYMBOL(gr_check_group_change);
56007 +#endif
56008 +
56009 diff -urNp linux-2.6.32.46/grsecurity/gracl_alloc.c linux-2.6.32.46/grsecurity/gracl_alloc.c
56010 --- linux-2.6.32.46/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
56011 +++ linux-2.6.32.46/grsecurity/gracl_alloc.c 2011-04-17 15:56:46.000000000 -0400
56012 @@ -0,0 +1,105 @@
56013 +#include <linux/kernel.h>
56014 +#include <linux/mm.h>
56015 +#include <linux/slab.h>
56016 +#include <linux/vmalloc.h>
56017 +#include <linux/gracl.h>
56018 +#include <linux/grsecurity.h>
56019 +
56020 +static unsigned long alloc_stack_next = 1;
56021 +static unsigned long alloc_stack_size = 1;
56022 +static void **alloc_stack;
56023 +
56024 +static __inline__ int
56025 +alloc_pop(void)
56026 +{
56027 + if (alloc_stack_next == 1)
56028 + return 0;
56029 +
56030 + kfree(alloc_stack[alloc_stack_next - 2]);
56031 +
56032 + alloc_stack_next--;
56033 +
56034 + return 1;
56035 +}
56036 +
56037 +static __inline__ int
56038 +alloc_push(void *buf)
56039 +{
56040 + if (alloc_stack_next >= alloc_stack_size)
56041 + return 1;
56042 +
56043 + alloc_stack[alloc_stack_next - 1] = buf;
56044 +
56045 + alloc_stack_next++;
56046 +
56047 + return 0;
56048 +}
56049 +
56050 +void *
56051 +acl_alloc(unsigned long len)
56052 +{
56053 + void *ret = NULL;
56054 +
56055 + if (!len || len > PAGE_SIZE)
56056 + goto out;
56057 +
56058 + ret = kmalloc(len, GFP_KERNEL);
56059 +
56060 + if (ret) {
56061 + if (alloc_push(ret)) {
56062 + kfree(ret);
56063 + ret = NULL;
56064 + }
56065 + }
56066 +
56067 +out:
56068 + return ret;
56069 +}
56070 +
56071 +void *
56072 +acl_alloc_num(unsigned long num, unsigned long len)
56073 +{
56074 + if (!len || (num > (PAGE_SIZE / len)))
56075 + return NULL;
56076 +
56077 + return acl_alloc(num * len);
56078 +}
56079 +
56080 +void
56081 +acl_free_all(void)
56082 +{
56083 + if (gr_acl_is_enabled() || !alloc_stack)
56084 + return;
56085 +
56086 + while (alloc_pop()) ;
56087 +
56088 + if (alloc_stack) {
56089 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
56090 + kfree(alloc_stack);
56091 + else
56092 + vfree(alloc_stack);
56093 + }
56094 +
56095 + alloc_stack = NULL;
56096 + alloc_stack_size = 1;
56097 + alloc_stack_next = 1;
56098 +
56099 + return;
56100 +}
56101 +
56102 +int
56103 +acl_alloc_stack_init(unsigned long size)
56104 +{
56105 + if ((size * sizeof (void *)) <= PAGE_SIZE)
56106 + alloc_stack =
56107 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
56108 + else
56109 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
56110 +
56111 + alloc_stack_size = size;
56112 +
56113 + if (!alloc_stack)
56114 + return 0;
56115 + else
56116 + return 1;
56117 +}
56118 diff -urNp linux-2.6.32.46/grsecurity/gracl_cap.c linux-2.6.32.46/grsecurity/gracl_cap.c
56119 --- linux-2.6.32.46/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
56120 +++ linux-2.6.32.46/grsecurity/gracl_cap.c 2011-09-14 08:53:50.000000000 -0400
56121 @@ -0,0 +1,101 @@
56122 +#include <linux/kernel.h>
56123 +#include <linux/module.h>
56124 +#include <linux/sched.h>
56125 +#include <linux/gracl.h>
56126 +#include <linux/grsecurity.h>
56127 +#include <linux/grinternal.h>
56128 +
56129 +extern const char *captab_log[];
56130 +extern int captab_log_entries;
56131 +
56132 +int
56133 +gr_acl_is_capable(const int cap)
56134 +{
56135 + struct task_struct *task = current;
56136 + const struct cred *cred = current_cred();
56137 + struct acl_subject_label *curracl;
56138 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56139 + kernel_cap_t cap_audit = __cap_empty_set;
56140 +
56141 + if (!gr_acl_is_enabled())
56142 + return 1;
56143 +
56144 + curracl = task->acl;
56145 +
56146 + cap_drop = curracl->cap_lower;
56147 + cap_mask = curracl->cap_mask;
56148 + cap_audit = curracl->cap_invert_audit;
56149 +
56150 + while ((curracl = curracl->parent_subject)) {
56151 + /* if the cap isn't specified in the current computed mask but is specified in the
56152 + current level subject, and is lowered in the current level subject, then add
56153 + it to the set of dropped capabilities
56154 + otherwise, add the current level subject's mask to the current computed mask
56155 + */
56156 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56157 + cap_raise(cap_mask, cap);
56158 + if (cap_raised(curracl->cap_lower, cap))
56159 + cap_raise(cap_drop, cap);
56160 + if (cap_raised(curracl->cap_invert_audit, cap))
56161 + cap_raise(cap_audit, cap);
56162 + }
56163 + }
56164 +
56165 + if (!cap_raised(cap_drop, cap)) {
56166 + if (cap_raised(cap_audit, cap))
56167 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
56168 + return 1;
56169 + }
56170 +
56171 + curracl = task->acl;
56172 +
56173 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
56174 + && cap_raised(cred->cap_effective, cap)) {
56175 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56176 + task->role->roletype, cred->uid,
56177 + cred->gid, task->exec_file ?
56178 + gr_to_filename(task->exec_file->f_path.dentry,
56179 + task->exec_file->f_path.mnt) : curracl->filename,
56180 + curracl->filename, 0UL,
56181 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56182 + return 1;
56183 + }
56184 +
56185 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56186 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56187 + return 0;
56188 +}
56189 +
56190 +int
56191 +gr_acl_is_capable_nolog(const int cap)
56192 +{
56193 + struct acl_subject_label *curracl;
56194 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56195 +
56196 + if (!gr_acl_is_enabled())
56197 + return 1;
56198 +
56199 + curracl = current->acl;
56200 +
56201 + cap_drop = curracl->cap_lower;
56202 + cap_mask = curracl->cap_mask;
56203 +
56204 + while ((curracl = curracl->parent_subject)) {
56205 + /* if the cap isn't specified in the current computed mask but is specified in the
56206 + current level subject, and is lowered in the current level subject, then add
56207 + it to the set of dropped capabilities
56208 + otherwise, add the current level subject's mask to the current computed mask
56209 + */
56210 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56211 + cap_raise(cap_mask, cap);
56212 + if (cap_raised(curracl->cap_lower, cap))
56213 + cap_raise(cap_drop, cap);
56214 + }
56215 + }
56216 +
56217 + if (!cap_raised(cap_drop, cap))
56218 + return 1;
56219 +
56220 + return 0;
56221 +}
56222 +
56223 diff -urNp linux-2.6.32.46/grsecurity/gracl_fs.c linux-2.6.32.46/grsecurity/gracl_fs.c
56224 --- linux-2.6.32.46/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
56225 +++ linux-2.6.32.46/grsecurity/gracl_fs.c 2011-10-17 02:16:34.000000000 -0400
56226 @@ -0,0 +1,431 @@
56227 +#include <linux/kernel.h>
56228 +#include <linux/sched.h>
56229 +#include <linux/types.h>
56230 +#include <linux/fs.h>
56231 +#include <linux/file.h>
56232 +#include <linux/stat.h>
56233 +#include <linux/grsecurity.h>
56234 +#include <linux/grinternal.h>
56235 +#include <linux/gracl.h>
56236 +
56237 +__u32
56238 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56239 + const struct vfsmount * mnt)
56240 +{
56241 + __u32 mode;
56242 +
56243 + if (unlikely(!dentry->d_inode))
56244 + return GR_FIND;
56245 +
56246 + mode =
56247 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56248 +
56249 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56250 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56251 + return mode;
56252 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56253 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56254 + return 0;
56255 + } else if (unlikely(!(mode & GR_FIND)))
56256 + return 0;
56257 +
56258 + return GR_FIND;
56259 +}
56260 +
56261 +__u32
56262 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56263 + const int fmode)
56264 +{
56265 + __u32 reqmode = GR_FIND;
56266 + __u32 mode;
56267 +
56268 + if (unlikely(!dentry->d_inode))
56269 + return reqmode;
56270 +
56271 + if (unlikely(fmode & O_APPEND))
56272 + reqmode |= GR_APPEND;
56273 + else if (unlikely(fmode & FMODE_WRITE))
56274 + reqmode |= GR_WRITE;
56275 + if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
56276 + reqmode |= GR_READ;
56277 + if ((fmode & FMODE_GREXEC) && (fmode & FMODE_EXEC))
56278 + reqmode &= ~GR_READ;
56279 + mode =
56280 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56281 + mnt);
56282 +
56283 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56284 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56285 + reqmode & GR_READ ? " reading" : "",
56286 + reqmode & GR_WRITE ? " writing" : reqmode &
56287 + GR_APPEND ? " appending" : "");
56288 + return reqmode;
56289 + } else
56290 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56291 + {
56292 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56293 + reqmode & GR_READ ? " reading" : "",
56294 + reqmode & GR_WRITE ? " writing" : reqmode &
56295 + GR_APPEND ? " appending" : "");
56296 + return 0;
56297 + } else if (unlikely((mode & reqmode) != reqmode))
56298 + return 0;
56299 +
56300 + return reqmode;
56301 +}
56302 +
56303 +__u32
56304 +gr_acl_handle_creat(const struct dentry * dentry,
56305 + const struct dentry * p_dentry,
56306 + const struct vfsmount * p_mnt, const int fmode,
56307 + const int imode)
56308 +{
56309 + __u32 reqmode = GR_WRITE | GR_CREATE;
56310 + __u32 mode;
56311 +
56312 + if (unlikely(fmode & O_APPEND))
56313 + reqmode |= GR_APPEND;
56314 + if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
56315 + reqmode |= GR_READ;
56316 + if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
56317 + reqmode |= GR_SETID;
56318 +
56319 + mode =
56320 + gr_check_create(dentry, p_dentry, p_mnt,
56321 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56322 +
56323 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56324 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56325 + reqmode & GR_READ ? " reading" : "",
56326 + reqmode & GR_WRITE ? " writing" : reqmode &
56327 + GR_APPEND ? " appending" : "");
56328 + return reqmode;
56329 + } else
56330 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56331 + {
56332 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56333 + reqmode & GR_READ ? " reading" : "",
56334 + reqmode & GR_WRITE ? " writing" : reqmode &
56335 + GR_APPEND ? " appending" : "");
56336 + return 0;
56337 + } else if (unlikely((mode & reqmode) != reqmode))
56338 + return 0;
56339 +
56340 + return reqmode;
56341 +}
56342 +
56343 +__u32
56344 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56345 + const int fmode)
56346 +{
56347 + __u32 mode, reqmode = GR_FIND;
56348 +
56349 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56350 + reqmode |= GR_EXEC;
56351 + if (fmode & S_IWOTH)
56352 + reqmode |= GR_WRITE;
56353 + if (fmode & S_IROTH)
56354 + reqmode |= GR_READ;
56355 +
56356 + mode =
56357 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56358 + mnt);
56359 +
56360 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56361 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56362 + reqmode & GR_READ ? " reading" : "",
56363 + reqmode & GR_WRITE ? " writing" : "",
56364 + reqmode & GR_EXEC ? " executing" : "");
56365 + return reqmode;
56366 + } else
56367 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56368 + {
56369 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56370 + reqmode & GR_READ ? " reading" : "",
56371 + reqmode & GR_WRITE ? " writing" : "",
56372 + reqmode & GR_EXEC ? " executing" : "");
56373 + return 0;
56374 + } else if (unlikely((mode & reqmode) != reqmode))
56375 + return 0;
56376 +
56377 + return reqmode;
56378 +}
56379 +
56380 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56381 +{
56382 + __u32 mode;
56383 +
56384 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56385 +
56386 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56387 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56388 + return mode;
56389 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56390 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56391 + return 0;
56392 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56393 + return 0;
56394 +
56395 + return (reqmode);
56396 +}
56397 +
56398 +__u32
56399 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56400 +{
56401 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56402 +}
56403 +
56404 +__u32
56405 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56406 +{
56407 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56408 +}
56409 +
56410 +__u32
56411 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56412 +{
56413 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56414 +}
56415 +
56416 +__u32
56417 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56418 +{
56419 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56420 +}
56421 +
56422 +__u32
56423 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
56424 + mode_t mode)
56425 +{
56426 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56427 + return 1;
56428 +
56429 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
56430 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56431 + GR_FCHMOD_ACL_MSG);
56432 + } else {
56433 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
56434 + }
56435 +}
56436 +
56437 +__u32
56438 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56439 + mode_t mode)
56440 +{
56441 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
56442 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56443 + GR_CHMOD_ACL_MSG);
56444 + } else {
56445 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56446 + }
56447 +}
56448 +
56449 +__u32
56450 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56451 +{
56452 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56453 +}
56454 +
56455 +__u32
56456 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56457 +{
56458 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56459 +}
56460 +
56461 +__u32
56462 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56463 +{
56464 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56465 +}
56466 +
56467 +__u32
56468 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56469 +{
56470 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56471 + GR_UNIXCONNECT_ACL_MSG);
56472 +}
56473 +
56474 +/* hardlinks require at minimum create and link permission,
56475 + any additional privilege required is based on the
56476 + privilege of the file being linked to
56477 +*/
56478 +__u32
56479 +gr_acl_handle_link(const struct dentry * new_dentry,
56480 + const struct dentry * parent_dentry,
56481 + const struct vfsmount * parent_mnt,
56482 + const struct dentry * old_dentry,
56483 + const struct vfsmount * old_mnt, const char *to)
56484 +{
56485 + __u32 mode;
56486 + __u32 needmode = GR_CREATE | GR_LINK;
56487 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56488 +
56489 + mode =
56490 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56491 + old_mnt);
56492 +
56493 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56494 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56495 + return mode;
56496 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56497 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56498 + return 0;
56499 + } else if (unlikely((mode & needmode) != needmode))
56500 + return 0;
56501 +
56502 + return 1;
56503 +}
56504 +
56505 +__u32
56506 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56507 + const struct dentry * parent_dentry,
56508 + const struct vfsmount * parent_mnt, const char *from)
56509 +{
56510 + __u32 needmode = GR_WRITE | GR_CREATE;
56511 + __u32 mode;
56512 +
56513 + mode =
56514 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56515 + GR_CREATE | GR_AUDIT_CREATE |
56516 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56517 +
56518 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56519 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56520 + return mode;
56521 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56522 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56523 + return 0;
56524 + } else if (unlikely((mode & needmode) != needmode))
56525 + return 0;
56526 +
56527 + return (GR_WRITE | GR_CREATE);
56528 +}
56529 +
56530 +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)
56531 +{
56532 + __u32 mode;
56533 +
56534 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56535 +
56536 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56537 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56538 + return mode;
56539 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56540 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56541 + return 0;
56542 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56543 + return 0;
56544 +
56545 + return (reqmode);
56546 +}
56547 +
56548 +__u32
56549 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56550 + const struct dentry * parent_dentry,
56551 + const struct vfsmount * parent_mnt,
56552 + const int mode)
56553 +{
56554 + __u32 reqmode = GR_WRITE | GR_CREATE;
56555 + if (unlikely(mode & (S_ISUID | S_ISGID)))
56556 + reqmode |= GR_SETID;
56557 +
56558 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56559 + reqmode, GR_MKNOD_ACL_MSG);
56560 +}
56561 +
56562 +__u32
56563 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56564 + const struct dentry *parent_dentry,
56565 + const struct vfsmount *parent_mnt)
56566 +{
56567 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56568 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56569 +}
56570 +
56571 +#define RENAME_CHECK_SUCCESS(old, new) \
56572 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56573 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56574 +
56575 +int
56576 +gr_acl_handle_rename(struct dentry *new_dentry,
56577 + struct dentry *parent_dentry,
56578 + const struct vfsmount *parent_mnt,
56579 + struct dentry *old_dentry,
56580 + struct inode *old_parent_inode,
56581 + struct vfsmount *old_mnt, const char *newname)
56582 +{
56583 + __u32 comp1, comp2;
56584 + int error = 0;
56585 +
56586 + if (unlikely(!gr_acl_is_enabled()))
56587 + return 0;
56588 +
56589 + if (!new_dentry->d_inode) {
56590 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56591 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56592 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56593 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56594 + GR_DELETE | GR_AUDIT_DELETE |
56595 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56596 + GR_SUPPRESS, old_mnt);
56597 + } else {
56598 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56599 + GR_CREATE | GR_DELETE |
56600 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56601 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56602 + GR_SUPPRESS, parent_mnt);
56603 + comp2 =
56604 + gr_search_file(old_dentry,
56605 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56606 + GR_DELETE | GR_AUDIT_DELETE |
56607 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56608 + }
56609 +
56610 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56611 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56612 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56613 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56614 + && !(comp2 & GR_SUPPRESS)) {
56615 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56616 + error = -EACCES;
56617 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56618 + error = -EACCES;
56619 +
56620 + return error;
56621 +}
56622 +
56623 +void
56624 +gr_acl_handle_exit(void)
56625 +{
56626 + u16 id;
56627 + char *rolename;
56628 + struct file *exec_file;
56629 +
56630 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56631 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56632 + id = current->acl_role_id;
56633 + rolename = current->role->rolename;
56634 + gr_set_acls(1);
56635 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56636 + }
56637 +
56638 + write_lock(&grsec_exec_file_lock);
56639 + exec_file = current->exec_file;
56640 + current->exec_file = NULL;
56641 + write_unlock(&grsec_exec_file_lock);
56642 +
56643 + if (exec_file)
56644 + fput(exec_file);
56645 +}
56646 +
56647 +int
56648 +gr_acl_handle_procpidmem(const struct task_struct *task)
56649 +{
56650 + if (unlikely(!gr_acl_is_enabled()))
56651 + return 0;
56652 +
56653 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56654 + return -EACCES;
56655 +
56656 + return 0;
56657 +}
56658 diff -urNp linux-2.6.32.46/grsecurity/gracl_ip.c linux-2.6.32.46/grsecurity/gracl_ip.c
56659 --- linux-2.6.32.46/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
56660 +++ linux-2.6.32.46/grsecurity/gracl_ip.c 2011-04-17 15:56:46.000000000 -0400
56661 @@ -0,0 +1,382 @@
56662 +#include <linux/kernel.h>
56663 +#include <asm/uaccess.h>
56664 +#include <asm/errno.h>
56665 +#include <net/sock.h>
56666 +#include <linux/file.h>
56667 +#include <linux/fs.h>
56668 +#include <linux/net.h>
56669 +#include <linux/in.h>
56670 +#include <linux/skbuff.h>
56671 +#include <linux/ip.h>
56672 +#include <linux/udp.h>
56673 +#include <linux/smp_lock.h>
56674 +#include <linux/types.h>
56675 +#include <linux/sched.h>
56676 +#include <linux/netdevice.h>
56677 +#include <linux/inetdevice.h>
56678 +#include <linux/gracl.h>
56679 +#include <linux/grsecurity.h>
56680 +#include <linux/grinternal.h>
56681 +
56682 +#define GR_BIND 0x01
56683 +#define GR_CONNECT 0x02
56684 +#define GR_INVERT 0x04
56685 +#define GR_BINDOVERRIDE 0x08
56686 +#define GR_CONNECTOVERRIDE 0x10
56687 +#define GR_SOCK_FAMILY 0x20
56688 +
56689 +static const char * gr_protocols[IPPROTO_MAX] = {
56690 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56691 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56692 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56693 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56694 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56695 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56696 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56697 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56698 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56699 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56700 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56701 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56702 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56703 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56704 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56705 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56706 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56707 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56708 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56709 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56710 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56711 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56712 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56713 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56714 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56715 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56716 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56717 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56718 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56719 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56720 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56721 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56722 + };
56723 +
56724 +static const char * gr_socktypes[SOCK_MAX] = {
56725 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56726 + "unknown:7", "unknown:8", "unknown:9", "packet"
56727 + };
56728 +
56729 +static const char * gr_sockfamilies[AF_MAX+1] = {
56730 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56731 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56732 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56733 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154"
56734 + };
56735 +
56736 +const char *
56737 +gr_proto_to_name(unsigned char proto)
56738 +{
56739 + return gr_protocols[proto];
56740 +}
56741 +
56742 +const char *
56743 +gr_socktype_to_name(unsigned char type)
56744 +{
56745 + return gr_socktypes[type];
56746 +}
56747 +
56748 +const char *
56749 +gr_sockfamily_to_name(unsigned char family)
56750 +{
56751 + return gr_sockfamilies[family];
56752 +}
56753 +
56754 +int
56755 +gr_search_socket(const int domain, const int type, const int protocol)
56756 +{
56757 + struct acl_subject_label *curr;
56758 + const struct cred *cred = current_cred();
56759 +
56760 + if (unlikely(!gr_acl_is_enabled()))
56761 + goto exit;
56762 +
56763 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56764 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56765 + goto exit; // let the kernel handle it
56766 +
56767 + curr = current->acl;
56768 +
56769 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56770 + /* the family is allowed, if this is PF_INET allow it only if
56771 + the extra sock type/protocol checks pass */
56772 + if (domain == PF_INET)
56773 + goto inet_check;
56774 + goto exit;
56775 + } else {
56776 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56777 + __u32 fakeip = 0;
56778 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56779 + current->role->roletype, cred->uid,
56780 + cred->gid, current->exec_file ?
56781 + gr_to_filename(current->exec_file->f_path.dentry,
56782 + current->exec_file->f_path.mnt) :
56783 + curr->filename, curr->filename,
56784 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56785 + &current->signal->saved_ip);
56786 + goto exit;
56787 + }
56788 + goto exit_fail;
56789 + }
56790 +
56791 +inet_check:
56792 + /* the rest of this checking is for IPv4 only */
56793 + if (!curr->ips)
56794 + goto exit;
56795 +
56796 + if ((curr->ip_type & (1 << type)) &&
56797 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56798 + goto exit;
56799 +
56800 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56801 + /* we don't place acls on raw sockets , and sometimes
56802 + dgram/ip sockets are opened for ioctl and not
56803 + bind/connect, so we'll fake a bind learn log */
56804 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56805 + __u32 fakeip = 0;
56806 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56807 + current->role->roletype, cred->uid,
56808 + cred->gid, current->exec_file ?
56809 + gr_to_filename(current->exec_file->f_path.dentry,
56810 + current->exec_file->f_path.mnt) :
56811 + curr->filename, curr->filename,
56812 + &fakeip, 0, type,
56813 + protocol, GR_CONNECT, &current->signal->saved_ip);
56814 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56815 + __u32 fakeip = 0;
56816 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56817 + current->role->roletype, cred->uid,
56818 + cred->gid, current->exec_file ?
56819 + gr_to_filename(current->exec_file->f_path.dentry,
56820 + current->exec_file->f_path.mnt) :
56821 + curr->filename, curr->filename,
56822 + &fakeip, 0, type,
56823 + protocol, GR_BIND, &current->signal->saved_ip);
56824 + }
56825 + /* we'll log when they use connect or bind */
56826 + goto exit;
56827 + }
56828 +
56829 +exit_fail:
56830 + if (domain == PF_INET)
56831 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56832 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56833 + else
56834 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56835 + gr_socktype_to_name(type), protocol);
56836 +
56837 + return 0;
56838 +exit:
56839 + return 1;
56840 +}
56841 +
56842 +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)
56843 +{
56844 + if ((ip->mode & mode) &&
56845 + (ip_port >= ip->low) &&
56846 + (ip_port <= ip->high) &&
56847 + ((ntohl(ip_addr) & our_netmask) ==
56848 + (ntohl(our_addr) & our_netmask))
56849 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56850 + && (ip->type & (1 << type))) {
56851 + if (ip->mode & GR_INVERT)
56852 + return 2; // specifically denied
56853 + else
56854 + return 1; // allowed
56855 + }
56856 +
56857 + return 0; // not specifically allowed, may continue parsing
56858 +}
56859 +
56860 +static int
56861 +gr_search_connectbind(const int full_mode, struct sock *sk,
56862 + struct sockaddr_in *addr, const int type)
56863 +{
56864 + char iface[IFNAMSIZ] = {0};
56865 + struct acl_subject_label *curr;
56866 + struct acl_ip_label *ip;
56867 + struct inet_sock *isk;
56868 + struct net_device *dev;
56869 + struct in_device *idev;
56870 + unsigned long i;
56871 + int ret;
56872 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56873 + __u32 ip_addr = 0;
56874 + __u32 our_addr;
56875 + __u32 our_netmask;
56876 + char *p;
56877 + __u16 ip_port = 0;
56878 + const struct cred *cred = current_cred();
56879 +
56880 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56881 + return 0;
56882 +
56883 + curr = current->acl;
56884 + isk = inet_sk(sk);
56885 +
56886 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56887 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56888 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56889 + if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56890 + struct sockaddr_in saddr;
56891 + int err;
56892 +
56893 + saddr.sin_family = AF_INET;
56894 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56895 + saddr.sin_port = isk->sport;
56896 +
56897 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56898 + if (err)
56899 + return err;
56900 +
56901 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56902 + if (err)
56903 + return err;
56904 + }
56905 +
56906 + if (!curr->ips)
56907 + return 0;
56908 +
56909 + ip_addr = addr->sin_addr.s_addr;
56910 + ip_port = ntohs(addr->sin_port);
56911 +
56912 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56913 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56914 + current->role->roletype, cred->uid,
56915 + cred->gid, current->exec_file ?
56916 + gr_to_filename(current->exec_file->f_path.dentry,
56917 + current->exec_file->f_path.mnt) :
56918 + curr->filename, curr->filename,
56919 + &ip_addr, ip_port, type,
56920 + sk->sk_protocol, mode, &current->signal->saved_ip);
56921 + return 0;
56922 + }
56923 +
56924 + for (i = 0; i < curr->ip_num; i++) {
56925 + ip = *(curr->ips + i);
56926 + if (ip->iface != NULL) {
56927 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56928 + p = strchr(iface, ':');
56929 + if (p != NULL)
56930 + *p = '\0';
56931 + dev = dev_get_by_name(sock_net(sk), iface);
56932 + if (dev == NULL)
56933 + continue;
56934 + idev = in_dev_get(dev);
56935 + if (idev == NULL) {
56936 + dev_put(dev);
56937 + continue;
56938 + }
56939 + rcu_read_lock();
56940 + for_ifa(idev) {
56941 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56942 + our_addr = ifa->ifa_address;
56943 + our_netmask = 0xffffffff;
56944 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56945 + if (ret == 1) {
56946 + rcu_read_unlock();
56947 + in_dev_put(idev);
56948 + dev_put(dev);
56949 + return 0;
56950 + } else if (ret == 2) {
56951 + rcu_read_unlock();
56952 + in_dev_put(idev);
56953 + dev_put(dev);
56954 + goto denied;
56955 + }
56956 + }
56957 + } endfor_ifa(idev);
56958 + rcu_read_unlock();
56959 + in_dev_put(idev);
56960 + dev_put(dev);
56961 + } else {
56962 + our_addr = ip->addr;
56963 + our_netmask = ip->netmask;
56964 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56965 + if (ret == 1)
56966 + return 0;
56967 + else if (ret == 2)
56968 + goto denied;
56969 + }
56970 + }
56971 +
56972 +denied:
56973 + if (mode == GR_BIND)
56974 + 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));
56975 + else if (mode == GR_CONNECT)
56976 + 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));
56977 +
56978 + return -EACCES;
56979 +}
56980 +
56981 +int
56982 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56983 +{
56984 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56985 +}
56986 +
56987 +int
56988 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56989 +{
56990 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56991 +}
56992 +
56993 +int gr_search_listen(struct socket *sock)
56994 +{
56995 + struct sock *sk = sock->sk;
56996 + struct sockaddr_in addr;
56997 +
56998 + addr.sin_addr.s_addr = inet_sk(sk)->saddr;
56999 + addr.sin_port = inet_sk(sk)->sport;
57000 +
57001 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57002 +}
57003 +
57004 +int gr_search_accept(struct socket *sock)
57005 +{
57006 + struct sock *sk = sock->sk;
57007 + struct sockaddr_in addr;
57008 +
57009 + addr.sin_addr.s_addr = inet_sk(sk)->saddr;
57010 + addr.sin_port = inet_sk(sk)->sport;
57011 +
57012 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57013 +}
57014 +
57015 +int
57016 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
57017 +{
57018 + if (addr)
57019 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
57020 + else {
57021 + struct sockaddr_in sin;
57022 + const struct inet_sock *inet = inet_sk(sk);
57023 +
57024 + sin.sin_addr.s_addr = inet->daddr;
57025 + sin.sin_port = inet->dport;
57026 +
57027 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57028 + }
57029 +}
57030 +
57031 +int
57032 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
57033 +{
57034 + struct sockaddr_in sin;
57035 +
57036 + if (unlikely(skb->len < sizeof (struct udphdr)))
57037 + return 0; // skip this packet
57038 +
57039 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
57040 + sin.sin_port = udp_hdr(skb)->source;
57041 +
57042 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57043 +}
57044 diff -urNp linux-2.6.32.46/grsecurity/gracl_learn.c linux-2.6.32.46/grsecurity/gracl_learn.c
57045 --- linux-2.6.32.46/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
57046 +++ linux-2.6.32.46/grsecurity/gracl_learn.c 2011-07-14 21:02:03.000000000 -0400
57047 @@ -0,0 +1,208 @@
57048 +#include <linux/kernel.h>
57049 +#include <linux/mm.h>
57050 +#include <linux/sched.h>
57051 +#include <linux/poll.h>
57052 +#include <linux/smp_lock.h>
57053 +#include <linux/string.h>
57054 +#include <linux/file.h>
57055 +#include <linux/types.h>
57056 +#include <linux/vmalloc.h>
57057 +#include <linux/grinternal.h>
57058 +
57059 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
57060 + size_t count, loff_t *ppos);
57061 +extern int gr_acl_is_enabled(void);
57062 +
57063 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
57064 +static int gr_learn_attached;
57065 +
57066 +/* use a 512k buffer */
57067 +#define LEARN_BUFFER_SIZE (512 * 1024)
57068 +
57069 +static DEFINE_SPINLOCK(gr_learn_lock);
57070 +static DEFINE_MUTEX(gr_learn_user_mutex);
57071 +
57072 +/* we need to maintain two buffers, so that the kernel context of grlearn
57073 + uses a semaphore around the userspace copying, and the other kernel contexts
57074 + use a spinlock when copying into the buffer, since they cannot sleep
57075 +*/
57076 +static char *learn_buffer;
57077 +static char *learn_buffer_user;
57078 +static int learn_buffer_len;
57079 +static int learn_buffer_user_len;
57080 +
57081 +static ssize_t
57082 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
57083 +{
57084 + DECLARE_WAITQUEUE(wait, current);
57085 + ssize_t retval = 0;
57086 +
57087 + add_wait_queue(&learn_wait, &wait);
57088 + set_current_state(TASK_INTERRUPTIBLE);
57089 + do {
57090 + mutex_lock(&gr_learn_user_mutex);
57091 + spin_lock(&gr_learn_lock);
57092 + if (learn_buffer_len)
57093 + break;
57094 + spin_unlock(&gr_learn_lock);
57095 + mutex_unlock(&gr_learn_user_mutex);
57096 + if (file->f_flags & O_NONBLOCK) {
57097 + retval = -EAGAIN;
57098 + goto out;
57099 + }
57100 + if (signal_pending(current)) {
57101 + retval = -ERESTARTSYS;
57102 + goto out;
57103 + }
57104 +
57105 + schedule();
57106 + } while (1);
57107 +
57108 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
57109 + learn_buffer_user_len = learn_buffer_len;
57110 + retval = learn_buffer_len;
57111 + learn_buffer_len = 0;
57112 +
57113 + spin_unlock(&gr_learn_lock);
57114 +
57115 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
57116 + retval = -EFAULT;
57117 +
57118 + mutex_unlock(&gr_learn_user_mutex);
57119 +out:
57120 + set_current_state(TASK_RUNNING);
57121 + remove_wait_queue(&learn_wait, &wait);
57122 + return retval;
57123 +}
57124 +
57125 +static unsigned int
57126 +poll_learn(struct file * file, poll_table * wait)
57127 +{
57128 + poll_wait(file, &learn_wait, wait);
57129 +
57130 + if (learn_buffer_len)
57131 + return (POLLIN | POLLRDNORM);
57132 +
57133 + return 0;
57134 +}
57135 +
57136 +void
57137 +gr_clear_learn_entries(void)
57138 +{
57139 + char *tmp;
57140 +
57141 + mutex_lock(&gr_learn_user_mutex);
57142 + spin_lock(&gr_learn_lock);
57143 + tmp = learn_buffer;
57144 + learn_buffer = NULL;
57145 + spin_unlock(&gr_learn_lock);
57146 + if (tmp)
57147 + vfree(tmp);
57148 + if (learn_buffer_user != NULL) {
57149 + vfree(learn_buffer_user);
57150 + learn_buffer_user = NULL;
57151 + }
57152 + learn_buffer_len = 0;
57153 + mutex_unlock(&gr_learn_user_mutex);
57154 +
57155 + return;
57156 +}
57157 +
57158 +void
57159 +gr_add_learn_entry(const char *fmt, ...)
57160 +{
57161 + va_list args;
57162 + unsigned int len;
57163 +
57164 + if (!gr_learn_attached)
57165 + return;
57166 +
57167 + spin_lock(&gr_learn_lock);
57168 +
57169 + /* leave a gap at the end so we know when it's "full" but don't have to
57170 + compute the exact length of the string we're trying to append
57171 + */
57172 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57173 + spin_unlock(&gr_learn_lock);
57174 + wake_up_interruptible(&learn_wait);
57175 + return;
57176 + }
57177 + if (learn_buffer == NULL) {
57178 + spin_unlock(&gr_learn_lock);
57179 + return;
57180 + }
57181 +
57182 + va_start(args, fmt);
57183 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57184 + va_end(args);
57185 +
57186 + learn_buffer_len += len + 1;
57187 +
57188 + spin_unlock(&gr_learn_lock);
57189 + wake_up_interruptible(&learn_wait);
57190 +
57191 + return;
57192 +}
57193 +
57194 +static int
57195 +open_learn(struct inode *inode, struct file *file)
57196 +{
57197 + if (file->f_mode & FMODE_READ && gr_learn_attached)
57198 + return -EBUSY;
57199 + if (file->f_mode & FMODE_READ) {
57200 + int retval = 0;
57201 + mutex_lock(&gr_learn_user_mutex);
57202 + if (learn_buffer == NULL)
57203 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57204 + if (learn_buffer_user == NULL)
57205 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57206 + if (learn_buffer == NULL) {
57207 + retval = -ENOMEM;
57208 + goto out_error;
57209 + }
57210 + if (learn_buffer_user == NULL) {
57211 + retval = -ENOMEM;
57212 + goto out_error;
57213 + }
57214 + learn_buffer_len = 0;
57215 + learn_buffer_user_len = 0;
57216 + gr_learn_attached = 1;
57217 +out_error:
57218 + mutex_unlock(&gr_learn_user_mutex);
57219 + return retval;
57220 + }
57221 + return 0;
57222 +}
57223 +
57224 +static int
57225 +close_learn(struct inode *inode, struct file *file)
57226 +{
57227 + if (file->f_mode & FMODE_READ) {
57228 + char *tmp = NULL;
57229 + mutex_lock(&gr_learn_user_mutex);
57230 + spin_lock(&gr_learn_lock);
57231 + tmp = learn_buffer;
57232 + learn_buffer = NULL;
57233 + spin_unlock(&gr_learn_lock);
57234 + if (tmp)
57235 + vfree(tmp);
57236 + if (learn_buffer_user != NULL) {
57237 + vfree(learn_buffer_user);
57238 + learn_buffer_user = NULL;
57239 + }
57240 + learn_buffer_len = 0;
57241 + learn_buffer_user_len = 0;
57242 + gr_learn_attached = 0;
57243 + mutex_unlock(&gr_learn_user_mutex);
57244 + }
57245 +
57246 + return 0;
57247 +}
57248 +
57249 +const struct file_operations grsec_fops = {
57250 + .read = read_learn,
57251 + .write = write_grsec_handler,
57252 + .open = open_learn,
57253 + .release = close_learn,
57254 + .poll = poll_learn,
57255 +};
57256 diff -urNp linux-2.6.32.46/grsecurity/gracl_res.c linux-2.6.32.46/grsecurity/gracl_res.c
57257 --- linux-2.6.32.46/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
57258 +++ linux-2.6.32.46/grsecurity/gracl_res.c 2011-04-17 15:56:46.000000000 -0400
57259 @@ -0,0 +1,67 @@
57260 +#include <linux/kernel.h>
57261 +#include <linux/sched.h>
57262 +#include <linux/gracl.h>
57263 +#include <linux/grinternal.h>
57264 +
57265 +static const char *restab_log[] = {
57266 + [RLIMIT_CPU] = "RLIMIT_CPU",
57267 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57268 + [RLIMIT_DATA] = "RLIMIT_DATA",
57269 + [RLIMIT_STACK] = "RLIMIT_STACK",
57270 + [RLIMIT_CORE] = "RLIMIT_CORE",
57271 + [RLIMIT_RSS] = "RLIMIT_RSS",
57272 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57273 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57274 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57275 + [RLIMIT_AS] = "RLIMIT_AS",
57276 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57277 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57278 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57279 + [RLIMIT_NICE] = "RLIMIT_NICE",
57280 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57281 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57282 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57283 +};
57284 +
57285 +void
57286 +gr_log_resource(const struct task_struct *task,
57287 + const int res, const unsigned long wanted, const int gt)
57288 +{
57289 + const struct cred *cred;
57290 + unsigned long rlim;
57291 +
57292 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57293 + return;
57294 +
57295 + // not yet supported resource
57296 + if (unlikely(!restab_log[res]))
57297 + return;
57298 +
57299 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57300 + rlim = task->signal->rlim[res].rlim_max;
57301 + else
57302 + rlim = task->signal->rlim[res].rlim_cur;
57303 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57304 + return;
57305 +
57306 + rcu_read_lock();
57307 + cred = __task_cred(task);
57308 +
57309 + if (res == RLIMIT_NPROC &&
57310 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57311 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57312 + goto out_rcu_unlock;
57313 + else if (res == RLIMIT_MEMLOCK &&
57314 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57315 + goto out_rcu_unlock;
57316 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57317 + goto out_rcu_unlock;
57318 + rcu_read_unlock();
57319 +
57320 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57321 +
57322 + return;
57323 +out_rcu_unlock:
57324 + rcu_read_unlock();
57325 + return;
57326 +}
57327 diff -urNp linux-2.6.32.46/grsecurity/gracl_segv.c linux-2.6.32.46/grsecurity/gracl_segv.c
57328 --- linux-2.6.32.46/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
57329 +++ linux-2.6.32.46/grsecurity/gracl_segv.c 2011-04-17 15:56:46.000000000 -0400
57330 @@ -0,0 +1,284 @@
57331 +#include <linux/kernel.h>
57332 +#include <linux/mm.h>
57333 +#include <asm/uaccess.h>
57334 +#include <asm/errno.h>
57335 +#include <asm/mman.h>
57336 +#include <net/sock.h>
57337 +#include <linux/file.h>
57338 +#include <linux/fs.h>
57339 +#include <linux/net.h>
57340 +#include <linux/in.h>
57341 +#include <linux/smp_lock.h>
57342 +#include <linux/slab.h>
57343 +#include <linux/types.h>
57344 +#include <linux/sched.h>
57345 +#include <linux/timer.h>
57346 +#include <linux/gracl.h>
57347 +#include <linux/grsecurity.h>
57348 +#include <linux/grinternal.h>
57349 +
57350 +static struct crash_uid *uid_set;
57351 +static unsigned short uid_used;
57352 +static DEFINE_SPINLOCK(gr_uid_lock);
57353 +extern rwlock_t gr_inode_lock;
57354 +extern struct acl_subject_label *
57355 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57356 + struct acl_role_label *role);
57357 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57358 +
57359 +int
57360 +gr_init_uidset(void)
57361 +{
57362 + uid_set =
57363 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57364 + uid_used = 0;
57365 +
57366 + return uid_set ? 1 : 0;
57367 +}
57368 +
57369 +void
57370 +gr_free_uidset(void)
57371 +{
57372 + if (uid_set)
57373 + kfree(uid_set);
57374 +
57375 + return;
57376 +}
57377 +
57378 +int
57379 +gr_find_uid(const uid_t uid)
57380 +{
57381 + struct crash_uid *tmp = uid_set;
57382 + uid_t buid;
57383 + int low = 0, high = uid_used - 1, mid;
57384 +
57385 + while (high >= low) {
57386 + mid = (low + high) >> 1;
57387 + buid = tmp[mid].uid;
57388 + if (buid == uid)
57389 + return mid;
57390 + if (buid > uid)
57391 + high = mid - 1;
57392 + if (buid < uid)
57393 + low = mid + 1;
57394 + }
57395 +
57396 + return -1;
57397 +}
57398 +
57399 +static __inline__ void
57400 +gr_insertsort(void)
57401 +{
57402 + unsigned short i, j;
57403 + struct crash_uid index;
57404 +
57405 + for (i = 1; i < uid_used; i++) {
57406 + index = uid_set[i];
57407 + j = i;
57408 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57409 + uid_set[j] = uid_set[j - 1];
57410 + j--;
57411 + }
57412 + uid_set[j] = index;
57413 + }
57414 +
57415 + return;
57416 +}
57417 +
57418 +static __inline__ void
57419 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57420 +{
57421 + int loc;
57422 +
57423 + if (uid_used == GR_UIDTABLE_MAX)
57424 + return;
57425 +
57426 + loc = gr_find_uid(uid);
57427 +
57428 + if (loc >= 0) {
57429 + uid_set[loc].expires = expires;
57430 + return;
57431 + }
57432 +
57433 + uid_set[uid_used].uid = uid;
57434 + uid_set[uid_used].expires = expires;
57435 + uid_used++;
57436 +
57437 + gr_insertsort();
57438 +
57439 + return;
57440 +}
57441 +
57442 +void
57443 +gr_remove_uid(const unsigned short loc)
57444 +{
57445 + unsigned short i;
57446 +
57447 + for (i = loc + 1; i < uid_used; i++)
57448 + uid_set[i - 1] = uid_set[i];
57449 +
57450 + uid_used--;
57451 +
57452 + return;
57453 +}
57454 +
57455 +int
57456 +gr_check_crash_uid(const uid_t uid)
57457 +{
57458 + int loc;
57459 + int ret = 0;
57460 +
57461 + if (unlikely(!gr_acl_is_enabled()))
57462 + return 0;
57463 +
57464 + spin_lock(&gr_uid_lock);
57465 + loc = gr_find_uid(uid);
57466 +
57467 + if (loc < 0)
57468 + goto out_unlock;
57469 +
57470 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57471 + gr_remove_uid(loc);
57472 + else
57473 + ret = 1;
57474 +
57475 +out_unlock:
57476 + spin_unlock(&gr_uid_lock);
57477 + return ret;
57478 +}
57479 +
57480 +static __inline__ int
57481 +proc_is_setxid(const struct cred *cred)
57482 +{
57483 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
57484 + cred->uid != cred->fsuid)
57485 + return 1;
57486 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
57487 + cred->gid != cred->fsgid)
57488 + return 1;
57489 +
57490 + return 0;
57491 +}
57492 +
57493 +void
57494 +gr_handle_crash(struct task_struct *task, const int sig)
57495 +{
57496 + struct acl_subject_label *curr;
57497 + struct acl_subject_label *curr2;
57498 + struct task_struct *tsk, *tsk2;
57499 + const struct cred *cred;
57500 + const struct cred *cred2;
57501 +
57502 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57503 + return;
57504 +
57505 + if (unlikely(!gr_acl_is_enabled()))
57506 + return;
57507 +
57508 + curr = task->acl;
57509 +
57510 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57511 + return;
57512 +
57513 + if (time_before_eq(curr->expires, get_seconds())) {
57514 + curr->expires = 0;
57515 + curr->crashes = 0;
57516 + }
57517 +
57518 + curr->crashes++;
57519 +
57520 + if (!curr->expires)
57521 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57522 +
57523 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57524 + time_after(curr->expires, get_seconds())) {
57525 + rcu_read_lock();
57526 + cred = __task_cred(task);
57527 + if (cred->uid && proc_is_setxid(cred)) {
57528 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57529 + spin_lock(&gr_uid_lock);
57530 + gr_insert_uid(cred->uid, curr->expires);
57531 + spin_unlock(&gr_uid_lock);
57532 + curr->expires = 0;
57533 + curr->crashes = 0;
57534 + read_lock(&tasklist_lock);
57535 + do_each_thread(tsk2, tsk) {
57536 + cred2 = __task_cred(tsk);
57537 + if (tsk != task && cred2->uid == cred->uid)
57538 + gr_fake_force_sig(SIGKILL, tsk);
57539 + } while_each_thread(tsk2, tsk);
57540 + read_unlock(&tasklist_lock);
57541 + } else {
57542 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57543 + read_lock(&tasklist_lock);
57544 + do_each_thread(tsk2, tsk) {
57545 + if (likely(tsk != task)) {
57546 + curr2 = tsk->acl;
57547 +
57548 + if (curr2->device == curr->device &&
57549 + curr2->inode == curr->inode)
57550 + gr_fake_force_sig(SIGKILL, tsk);
57551 + }
57552 + } while_each_thread(tsk2, tsk);
57553 + read_unlock(&tasklist_lock);
57554 + }
57555 + rcu_read_unlock();
57556 + }
57557 +
57558 + return;
57559 +}
57560 +
57561 +int
57562 +gr_check_crash_exec(const struct file *filp)
57563 +{
57564 + struct acl_subject_label *curr;
57565 +
57566 + if (unlikely(!gr_acl_is_enabled()))
57567 + return 0;
57568 +
57569 + read_lock(&gr_inode_lock);
57570 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57571 + filp->f_path.dentry->d_inode->i_sb->s_dev,
57572 + current->role);
57573 + read_unlock(&gr_inode_lock);
57574 +
57575 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57576 + (!curr->crashes && !curr->expires))
57577 + return 0;
57578 +
57579 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57580 + time_after(curr->expires, get_seconds()))
57581 + return 1;
57582 + else if (time_before_eq(curr->expires, get_seconds())) {
57583 + curr->crashes = 0;
57584 + curr->expires = 0;
57585 + }
57586 +
57587 + return 0;
57588 +}
57589 +
57590 +void
57591 +gr_handle_alertkill(struct task_struct *task)
57592 +{
57593 + struct acl_subject_label *curracl;
57594 + __u32 curr_ip;
57595 + struct task_struct *p, *p2;
57596 +
57597 + if (unlikely(!gr_acl_is_enabled()))
57598 + return;
57599 +
57600 + curracl = task->acl;
57601 + curr_ip = task->signal->curr_ip;
57602 +
57603 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57604 + read_lock(&tasklist_lock);
57605 + do_each_thread(p2, p) {
57606 + if (p->signal->curr_ip == curr_ip)
57607 + gr_fake_force_sig(SIGKILL, p);
57608 + } while_each_thread(p2, p);
57609 + read_unlock(&tasklist_lock);
57610 + } else if (curracl->mode & GR_KILLPROC)
57611 + gr_fake_force_sig(SIGKILL, task);
57612 +
57613 + return;
57614 +}
57615 diff -urNp linux-2.6.32.46/grsecurity/gracl_shm.c linux-2.6.32.46/grsecurity/gracl_shm.c
57616 --- linux-2.6.32.46/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
57617 +++ linux-2.6.32.46/grsecurity/gracl_shm.c 2011-04-17 15:56:46.000000000 -0400
57618 @@ -0,0 +1,40 @@
57619 +#include <linux/kernel.h>
57620 +#include <linux/mm.h>
57621 +#include <linux/sched.h>
57622 +#include <linux/file.h>
57623 +#include <linux/ipc.h>
57624 +#include <linux/gracl.h>
57625 +#include <linux/grsecurity.h>
57626 +#include <linux/grinternal.h>
57627 +
57628 +int
57629 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57630 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57631 +{
57632 + struct task_struct *task;
57633 +
57634 + if (!gr_acl_is_enabled())
57635 + return 1;
57636 +
57637 + rcu_read_lock();
57638 + read_lock(&tasklist_lock);
57639 +
57640 + task = find_task_by_vpid(shm_cprid);
57641 +
57642 + if (unlikely(!task))
57643 + task = find_task_by_vpid(shm_lapid);
57644 +
57645 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57646 + (task->pid == shm_lapid)) &&
57647 + (task->acl->mode & GR_PROTSHM) &&
57648 + (task->acl != current->acl))) {
57649 + read_unlock(&tasklist_lock);
57650 + rcu_read_unlock();
57651 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57652 + return 0;
57653 + }
57654 + read_unlock(&tasklist_lock);
57655 + rcu_read_unlock();
57656 +
57657 + return 1;
57658 +}
57659 diff -urNp linux-2.6.32.46/grsecurity/grsec_chdir.c linux-2.6.32.46/grsecurity/grsec_chdir.c
57660 --- linux-2.6.32.46/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
57661 +++ linux-2.6.32.46/grsecurity/grsec_chdir.c 2011-04-17 15:56:46.000000000 -0400
57662 @@ -0,0 +1,19 @@
57663 +#include <linux/kernel.h>
57664 +#include <linux/sched.h>
57665 +#include <linux/fs.h>
57666 +#include <linux/file.h>
57667 +#include <linux/grsecurity.h>
57668 +#include <linux/grinternal.h>
57669 +
57670 +void
57671 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57672 +{
57673 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57674 + if ((grsec_enable_chdir && grsec_enable_group &&
57675 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57676 + !grsec_enable_group)) {
57677 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57678 + }
57679 +#endif
57680 + return;
57681 +}
57682 diff -urNp linux-2.6.32.46/grsecurity/grsec_chroot.c linux-2.6.32.46/grsecurity/grsec_chroot.c
57683 --- linux-2.6.32.46/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
57684 +++ linux-2.6.32.46/grsecurity/grsec_chroot.c 2011-09-15 06:48:16.000000000 -0400
57685 @@ -0,0 +1,386 @@
57686 +#include <linux/kernel.h>
57687 +#include <linux/module.h>
57688 +#include <linux/sched.h>
57689 +#include <linux/file.h>
57690 +#include <linux/fs.h>
57691 +#include <linux/mount.h>
57692 +#include <linux/types.h>
57693 +#include <linux/pid_namespace.h>
57694 +#include <linux/grsecurity.h>
57695 +#include <linux/grinternal.h>
57696 +
57697 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57698 +{
57699 +#ifdef CONFIG_GRKERNSEC
57700 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57701 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
57702 + task->gr_is_chrooted = 1;
57703 + else
57704 + task->gr_is_chrooted = 0;
57705 +
57706 + task->gr_chroot_dentry = path->dentry;
57707 +#endif
57708 + return;
57709 +}
57710 +
57711 +void gr_clear_chroot_entries(struct task_struct *task)
57712 +{
57713 +#ifdef CONFIG_GRKERNSEC
57714 + task->gr_is_chrooted = 0;
57715 + task->gr_chroot_dentry = NULL;
57716 +#endif
57717 + return;
57718 +}
57719 +
57720 +int
57721 +gr_handle_chroot_unix(const pid_t pid)
57722 +{
57723 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57724 + struct task_struct *p;
57725 +
57726 + if (unlikely(!grsec_enable_chroot_unix))
57727 + return 1;
57728 +
57729 + if (likely(!proc_is_chrooted(current)))
57730 + return 1;
57731 +
57732 + rcu_read_lock();
57733 + read_lock(&tasklist_lock);
57734 +
57735 + p = find_task_by_vpid_unrestricted(pid);
57736 + if (unlikely(p && !have_same_root(current, p))) {
57737 + read_unlock(&tasklist_lock);
57738 + rcu_read_unlock();
57739 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57740 + return 0;
57741 + }
57742 + read_unlock(&tasklist_lock);
57743 + rcu_read_unlock();
57744 +#endif
57745 + return 1;
57746 +}
57747 +
57748 +int
57749 +gr_handle_chroot_nice(void)
57750 +{
57751 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57752 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57753 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57754 + return -EPERM;
57755 + }
57756 +#endif
57757 + return 0;
57758 +}
57759 +
57760 +int
57761 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57762 +{
57763 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57764 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57765 + && proc_is_chrooted(current)) {
57766 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57767 + return -EACCES;
57768 + }
57769 +#endif
57770 + return 0;
57771 +}
57772 +
57773 +int
57774 +gr_handle_chroot_rawio(const struct inode *inode)
57775 +{
57776 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57777 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57778 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57779 + return 1;
57780 +#endif
57781 + return 0;
57782 +}
57783 +
57784 +int
57785 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57786 +{
57787 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57788 + struct task_struct *p;
57789 + int ret = 0;
57790 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57791 + return ret;
57792 +
57793 + read_lock(&tasklist_lock);
57794 + do_each_pid_task(pid, type, p) {
57795 + if (!have_same_root(current, p)) {
57796 + ret = 1;
57797 + goto out;
57798 + }
57799 + } while_each_pid_task(pid, type, p);
57800 +out:
57801 + read_unlock(&tasklist_lock);
57802 + return ret;
57803 +#endif
57804 + return 0;
57805 +}
57806 +
57807 +int
57808 +gr_pid_is_chrooted(struct task_struct *p)
57809 +{
57810 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57811 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57812 + return 0;
57813 +
57814 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57815 + !have_same_root(current, p)) {
57816 + return 1;
57817 + }
57818 +#endif
57819 + return 0;
57820 +}
57821 +
57822 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57823 +
57824 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57825 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57826 +{
57827 + struct dentry *dentry = (struct dentry *)u_dentry;
57828 + struct vfsmount *mnt = (struct vfsmount *)u_mnt;
57829 + struct dentry *realroot;
57830 + struct vfsmount *realrootmnt;
57831 + struct dentry *currentroot;
57832 + struct vfsmount *currentmnt;
57833 + struct task_struct *reaper = &init_task;
57834 + int ret = 1;
57835 +
57836 + read_lock(&reaper->fs->lock);
57837 + realrootmnt = mntget(reaper->fs->root.mnt);
57838 + realroot = dget(reaper->fs->root.dentry);
57839 + read_unlock(&reaper->fs->lock);
57840 +
57841 + read_lock(&current->fs->lock);
57842 + currentmnt = mntget(current->fs->root.mnt);
57843 + currentroot = dget(current->fs->root.dentry);
57844 + read_unlock(&current->fs->lock);
57845 +
57846 + spin_lock(&dcache_lock);
57847 + for (;;) {
57848 + if (unlikely((dentry == realroot && mnt == realrootmnt)
57849 + || (dentry == currentroot && mnt == currentmnt)))
57850 + break;
57851 + if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
57852 + if (mnt->mnt_parent == mnt)
57853 + break;
57854 + dentry = mnt->mnt_mountpoint;
57855 + mnt = mnt->mnt_parent;
57856 + continue;
57857 + }
57858 + dentry = dentry->d_parent;
57859 + }
57860 + spin_unlock(&dcache_lock);
57861 +
57862 + dput(currentroot);
57863 + mntput(currentmnt);
57864 +
57865 + /* access is outside of chroot */
57866 + if (dentry == realroot && mnt == realrootmnt)
57867 + ret = 0;
57868 +
57869 + dput(realroot);
57870 + mntput(realrootmnt);
57871 + return ret;
57872 +}
57873 +#endif
57874 +
57875 +int
57876 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57877 +{
57878 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57879 + if (!grsec_enable_chroot_fchdir)
57880 + return 1;
57881 +
57882 + if (!proc_is_chrooted(current))
57883 + return 1;
57884 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57885 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57886 + return 0;
57887 + }
57888 +#endif
57889 + return 1;
57890 +}
57891 +
57892 +int
57893 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57894 + const time_t shm_createtime)
57895 +{
57896 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57897 + struct task_struct *p;
57898 + time_t starttime;
57899 +
57900 + if (unlikely(!grsec_enable_chroot_shmat))
57901 + return 1;
57902 +
57903 + if (likely(!proc_is_chrooted(current)))
57904 + return 1;
57905 +
57906 + rcu_read_lock();
57907 + read_lock(&tasklist_lock);
57908 +
57909 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57910 + starttime = p->start_time.tv_sec;
57911 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57912 + if (have_same_root(current, p)) {
57913 + goto allow;
57914 + } else {
57915 + read_unlock(&tasklist_lock);
57916 + rcu_read_unlock();
57917 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57918 + return 0;
57919 + }
57920 + }
57921 + /* creator exited, pid reuse, fall through to next check */
57922 + }
57923 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57924 + if (unlikely(!have_same_root(current, p))) {
57925 + read_unlock(&tasklist_lock);
57926 + rcu_read_unlock();
57927 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57928 + return 0;
57929 + }
57930 + }
57931 +
57932 +allow:
57933 + read_unlock(&tasklist_lock);
57934 + rcu_read_unlock();
57935 +#endif
57936 + return 1;
57937 +}
57938 +
57939 +void
57940 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57941 +{
57942 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57943 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57944 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57945 +#endif
57946 + return;
57947 +}
57948 +
57949 +int
57950 +gr_handle_chroot_mknod(const struct dentry *dentry,
57951 + const struct vfsmount *mnt, const int mode)
57952 +{
57953 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57954 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57955 + proc_is_chrooted(current)) {
57956 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57957 + return -EPERM;
57958 + }
57959 +#endif
57960 + return 0;
57961 +}
57962 +
57963 +int
57964 +gr_handle_chroot_mount(const struct dentry *dentry,
57965 + const struct vfsmount *mnt, const char *dev_name)
57966 +{
57967 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57968 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57969 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none" , dentry, mnt);
57970 + return -EPERM;
57971 + }
57972 +#endif
57973 + return 0;
57974 +}
57975 +
57976 +int
57977 +gr_handle_chroot_pivot(void)
57978 +{
57979 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57980 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57981 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57982 + return -EPERM;
57983 + }
57984 +#endif
57985 + return 0;
57986 +}
57987 +
57988 +int
57989 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57990 +{
57991 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57992 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57993 + !gr_is_outside_chroot(dentry, mnt)) {
57994 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57995 + return -EPERM;
57996 + }
57997 +#endif
57998 + return 0;
57999 +}
58000 +
58001 +extern const char *captab_log[];
58002 +extern int captab_log_entries;
58003 +
58004 +int
58005 +gr_chroot_is_capable(const int cap)
58006 +{
58007 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58008 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
58009 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58010 + if (cap_raised(chroot_caps, cap)) {
58011 + const struct cred *creds = current_cred();
58012 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
58013 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
58014 + }
58015 + return 0;
58016 + }
58017 + }
58018 +#endif
58019 + return 1;
58020 +}
58021 +
58022 +int
58023 +gr_chroot_is_capable_nolog(const int cap)
58024 +{
58025 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58026 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
58027 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58028 + if (cap_raised(chroot_caps, cap)) {
58029 + return 0;
58030 + }
58031 + }
58032 +#endif
58033 + return 1;
58034 +}
58035 +
58036 +int
58037 +gr_handle_chroot_sysctl(const int op)
58038 +{
58039 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58040 + if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
58041 + && (op & MAY_WRITE))
58042 + return -EACCES;
58043 +#endif
58044 + return 0;
58045 +}
58046 +
58047 +void
58048 +gr_handle_chroot_chdir(struct path *path)
58049 +{
58050 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58051 + if (grsec_enable_chroot_chdir)
58052 + set_fs_pwd(current->fs, path);
58053 +#endif
58054 + return;
58055 +}
58056 +
58057 +int
58058 +gr_handle_chroot_chmod(const struct dentry *dentry,
58059 + const struct vfsmount *mnt, const int mode)
58060 +{
58061 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58062 + /* allow chmod +s on directories, but not on files */
58063 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
58064 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
58065 + proc_is_chrooted(current)) {
58066 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
58067 + return -EPERM;
58068 + }
58069 +#endif
58070 + return 0;
58071 +}
58072 diff -urNp linux-2.6.32.46/grsecurity/grsec_disabled.c linux-2.6.32.46/grsecurity/grsec_disabled.c
58073 --- linux-2.6.32.46/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
58074 +++ linux-2.6.32.46/grsecurity/grsec_disabled.c 2011-09-24 08:13:29.000000000 -0400
58075 @@ -0,0 +1,433 @@
58076 +#include <linux/kernel.h>
58077 +#include <linux/module.h>
58078 +#include <linux/sched.h>
58079 +#include <linux/file.h>
58080 +#include <linux/fs.h>
58081 +#include <linux/kdev_t.h>
58082 +#include <linux/net.h>
58083 +#include <linux/in.h>
58084 +#include <linux/ip.h>
58085 +#include <linux/skbuff.h>
58086 +#include <linux/sysctl.h>
58087 +
58088 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58089 +void
58090 +pax_set_initial_flags(struct linux_binprm *bprm)
58091 +{
58092 + return;
58093 +}
58094 +#endif
58095 +
58096 +#ifdef CONFIG_SYSCTL
58097 +__u32
58098 +gr_handle_sysctl(const struct ctl_table * table, const int op)
58099 +{
58100 + return 0;
58101 +}
58102 +#endif
58103 +
58104 +#ifdef CONFIG_TASKSTATS
58105 +int gr_is_taskstats_denied(int pid)
58106 +{
58107 + return 0;
58108 +}
58109 +#endif
58110 +
58111 +int
58112 +gr_acl_is_enabled(void)
58113 +{
58114 + return 0;
58115 +}
58116 +
58117 +int
58118 +gr_handle_rawio(const struct inode *inode)
58119 +{
58120 + return 0;
58121 +}
58122 +
58123 +void
58124 +gr_acl_handle_psacct(struct task_struct *task, const long code)
58125 +{
58126 + return;
58127 +}
58128 +
58129 +int
58130 +gr_handle_ptrace(struct task_struct *task, const long request)
58131 +{
58132 + return 0;
58133 +}
58134 +
58135 +int
58136 +gr_handle_proc_ptrace(struct task_struct *task)
58137 +{
58138 + return 0;
58139 +}
58140 +
58141 +void
58142 +gr_learn_resource(const struct task_struct *task,
58143 + const int res, const unsigned long wanted, const int gt)
58144 +{
58145 + return;
58146 +}
58147 +
58148 +int
58149 +gr_set_acls(const int type)
58150 +{
58151 + return 0;
58152 +}
58153 +
58154 +int
58155 +gr_check_hidden_task(const struct task_struct *tsk)
58156 +{
58157 + return 0;
58158 +}
58159 +
58160 +int
58161 +gr_check_protected_task(const struct task_struct *task)
58162 +{
58163 + return 0;
58164 +}
58165 +
58166 +int
58167 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58168 +{
58169 + return 0;
58170 +}
58171 +
58172 +void
58173 +gr_copy_label(struct task_struct *tsk)
58174 +{
58175 + return;
58176 +}
58177 +
58178 +void
58179 +gr_set_pax_flags(struct task_struct *task)
58180 +{
58181 + return;
58182 +}
58183 +
58184 +int
58185 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58186 + const int unsafe_share)
58187 +{
58188 + return 0;
58189 +}
58190 +
58191 +void
58192 +gr_handle_delete(const ino_t ino, const dev_t dev)
58193 +{
58194 + return;
58195 +}
58196 +
58197 +void
58198 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58199 +{
58200 + return;
58201 +}
58202 +
58203 +void
58204 +gr_handle_crash(struct task_struct *task, const int sig)
58205 +{
58206 + return;
58207 +}
58208 +
58209 +int
58210 +gr_check_crash_exec(const struct file *filp)
58211 +{
58212 + return 0;
58213 +}
58214 +
58215 +int
58216 +gr_check_crash_uid(const uid_t uid)
58217 +{
58218 + return 0;
58219 +}
58220 +
58221 +void
58222 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58223 + struct dentry *old_dentry,
58224 + struct dentry *new_dentry,
58225 + struct vfsmount *mnt, const __u8 replace)
58226 +{
58227 + return;
58228 +}
58229 +
58230 +int
58231 +gr_search_socket(const int family, const int type, const int protocol)
58232 +{
58233 + return 1;
58234 +}
58235 +
58236 +int
58237 +gr_search_connectbind(const int mode, const struct socket *sock,
58238 + const struct sockaddr_in *addr)
58239 +{
58240 + return 0;
58241 +}
58242 +
58243 +void
58244 +gr_handle_alertkill(struct task_struct *task)
58245 +{
58246 + return;
58247 +}
58248 +
58249 +__u32
58250 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58251 +{
58252 + return 1;
58253 +}
58254 +
58255 +__u32
58256 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58257 + const struct vfsmount * mnt)
58258 +{
58259 + return 1;
58260 +}
58261 +
58262 +__u32
58263 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58264 + const int fmode)
58265 +{
58266 + return 1;
58267 +}
58268 +
58269 +__u32
58270 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58271 +{
58272 + return 1;
58273 +}
58274 +
58275 +__u32
58276 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58277 +{
58278 + return 1;
58279 +}
58280 +
58281 +int
58282 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58283 + unsigned int *vm_flags)
58284 +{
58285 + return 1;
58286 +}
58287 +
58288 +__u32
58289 +gr_acl_handle_truncate(const struct dentry * dentry,
58290 + const struct vfsmount * mnt)
58291 +{
58292 + return 1;
58293 +}
58294 +
58295 +__u32
58296 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58297 +{
58298 + return 1;
58299 +}
58300 +
58301 +__u32
58302 +gr_acl_handle_access(const struct dentry * dentry,
58303 + const struct vfsmount * mnt, const int fmode)
58304 +{
58305 + return 1;
58306 +}
58307 +
58308 +__u32
58309 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
58310 + mode_t mode)
58311 +{
58312 + return 1;
58313 +}
58314 +
58315 +__u32
58316 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58317 + mode_t mode)
58318 +{
58319 + return 1;
58320 +}
58321 +
58322 +__u32
58323 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58324 +{
58325 + return 1;
58326 +}
58327 +
58328 +__u32
58329 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58330 +{
58331 + return 1;
58332 +}
58333 +
58334 +void
58335 +grsecurity_init(void)
58336 +{
58337 + return;
58338 +}
58339 +
58340 +__u32
58341 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58342 + const struct dentry * parent_dentry,
58343 + const struct vfsmount * parent_mnt,
58344 + const int mode)
58345 +{
58346 + return 1;
58347 +}
58348 +
58349 +__u32
58350 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58351 + const struct dentry * parent_dentry,
58352 + const struct vfsmount * parent_mnt)
58353 +{
58354 + return 1;
58355 +}
58356 +
58357 +__u32
58358 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58359 + const struct dentry * parent_dentry,
58360 + const struct vfsmount * parent_mnt, const char *from)
58361 +{
58362 + return 1;
58363 +}
58364 +
58365 +__u32
58366 +gr_acl_handle_link(const struct dentry * new_dentry,
58367 + const struct dentry * parent_dentry,
58368 + const struct vfsmount * parent_mnt,
58369 + const struct dentry * old_dentry,
58370 + const struct vfsmount * old_mnt, const char *to)
58371 +{
58372 + return 1;
58373 +}
58374 +
58375 +int
58376 +gr_acl_handle_rename(const struct dentry *new_dentry,
58377 + const struct dentry *parent_dentry,
58378 + const struct vfsmount *parent_mnt,
58379 + const struct dentry *old_dentry,
58380 + const struct inode *old_parent_inode,
58381 + const struct vfsmount *old_mnt, const char *newname)
58382 +{
58383 + return 0;
58384 +}
58385 +
58386 +int
58387 +gr_acl_handle_filldir(const struct file *file, const char *name,
58388 + const int namelen, const ino_t ino)
58389 +{
58390 + return 1;
58391 +}
58392 +
58393 +int
58394 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58395 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58396 +{
58397 + return 1;
58398 +}
58399 +
58400 +int
58401 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58402 +{
58403 + return 0;
58404 +}
58405 +
58406 +int
58407 +gr_search_accept(const struct socket *sock)
58408 +{
58409 + return 0;
58410 +}
58411 +
58412 +int
58413 +gr_search_listen(const struct socket *sock)
58414 +{
58415 + return 0;
58416 +}
58417 +
58418 +int
58419 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58420 +{
58421 + return 0;
58422 +}
58423 +
58424 +__u32
58425 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58426 +{
58427 + return 1;
58428 +}
58429 +
58430 +__u32
58431 +gr_acl_handle_creat(const struct dentry * dentry,
58432 + const struct dentry * p_dentry,
58433 + const struct vfsmount * p_mnt, const int fmode,
58434 + const int imode)
58435 +{
58436 + return 1;
58437 +}
58438 +
58439 +void
58440 +gr_acl_handle_exit(void)
58441 +{
58442 + return;
58443 +}
58444 +
58445 +int
58446 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58447 +{
58448 + return 1;
58449 +}
58450 +
58451 +void
58452 +gr_set_role_label(const uid_t uid, const gid_t gid)
58453 +{
58454 + return;
58455 +}
58456 +
58457 +int
58458 +gr_acl_handle_procpidmem(const struct task_struct *task)
58459 +{
58460 + return 0;
58461 +}
58462 +
58463 +int
58464 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58465 +{
58466 + return 0;
58467 +}
58468 +
58469 +int
58470 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58471 +{
58472 + return 0;
58473 +}
58474 +
58475 +void
58476 +gr_set_kernel_label(struct task_struct *task)
58477 +{
58478 + return;
58479 +}
58480 +
58481 +int
58482 +gr_check_user_change(int real, int effective, int fs)
58483 +{
58484 + return 0;
58485 +}
58486 +
58487 +int
58488 +gr_check_group_change(int real, int effective, int fs)
58489 +{
58490 + return 0;
58491 +}
58492 +
58493 +int gr_acl_enable_at_secure(void)
58494 +{
58495 + return 0;
58496 +}
58497 +
58498 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58499 +{
58500 + return dentry->d_inode->i_sb->s_dev;
58501 +}
58502 +
58503 +EXPORT_SYMBOL(gr_learn_resource);
58504 +EXPORT_SYMBOL(gr_set_kernel_label);
58505 +#ifdef CONFIG_SECURITY
58506 +EXPORT_SYMBOL(gr_check_user_change);
58507 +EXPORT_SYMBOL(gr_check_group_change);
58508 +#endif
58509 diff -urNp linux-2.6.32.46/grsecurity/grsec_exec.c linux-2.6.32.46/grsecurity/grsec_exec.c
58510 --- linux-2.6.32.46/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
58511 +++ linux-2.6.32.46/grsecurity/grsec_exec.c 2011-09-13 22:54:27.000000000 -0400
58512 @@ -0,0 +1,204 @@
58513 +#include <linux/kernel.h>
58514 +#include <linux/sched.h>
58515 +#include <linux/file.h>
58516 +#include <linux/binfmts.h>
58517 +#include <linux/smp_lock.h>
58518 +#include <linux/fs.h>
58519 +#include <linux/types.h>
58520 +#include <linux/grdefs.h>
58521 +#include <linux/grinternal.h>
58522 +#include <linux/capability.h>
58523 +#include <linux/compat.h>
58524 +#include <linux/module.h>
58525 +
58526 +#include <asm/uaccess.h>
58527 +
58528 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58529 +static char gr_exec_arg_buf[132];
58530 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58531 +#endif
58532 +
58533 +void
58534 +gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
58535 +{
58536 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58537 + char *grarg = gr_exec_arg_buf;
58538 + unsigned int i, x, execlen = 0;
58539 + char c;
58540 +
58541 + if (!((grsec_enable_execlog && grsec_enable_group &&
58542 + in_group_p(grsec_audit_gid))
58543 + || (grsec_enable_execlog && !grsec_enable_group)))
58544 + return;
58545 +
58546 + mutex_lock(&gr_exec_arg_mutex);
58547 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58548 +
58549 + if (unlikely(argv == NULL))
58550 + goto log;
58551 +
58552 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58553 + const char __user *p;
58554 + unsigned int len;
58555 +
58556 + if (copy_from_user(&p, argv + i, sizeof(p)))
58557 + goto log;
58558 + if (!p)
58559 + goto log;
58560 + len = strnlen_user(p, 128 - execlen);
58561 + if (len > 128 - execlen)
58562 + len = 128 - execlen;
58563 + else if (len > 0)
58564 + len--;
58565 + if (copy_from_user(grarg + execlen, p, len))
58566 + goto log;
58567 +
58568 + /* rewrite unprintable characters */
58569 + for (x = 0; x < len; x++) {
58570 + c = *(grarg + execlen + x);
58571 + if (c < 32 || c > 126)
58572 + *(grarg + execlen + x) = ' ';
58573 + }
58574 +
58575 + execlen += len;
58576 + *(grarg + execlen) = ' ';
58577 + *(grarg + execlen + 1) = '\0';
58578 + execlen++;
58579 + }
58580 +
58581 + log:
58582 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58583 + bprm->file->f_path.mnt, grarg);
58584 + mutex_unlock(&gr_exec_arg_mutex);
58585 +#endif
58586 + return;
58587 +}
58588 +
58589 +#ifdef CONFIG_COMPAT
58590 +void
58591 +gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
58592 +{
58593 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58594 + char *grarg = gr_exec_arg_buf;
58595 + unsigned int i, x, execlen = 0;
58596 + char c;
58597 +
58598 + if (!((grsec_enable_execlog && grsec_enable_group &&
58599 + in_group_p(grsec_audit_gid))
58600 + || (grsec_enable_execlog && !grsec_enable_group)))
58601 + return;
58602 +
58603 + mutex_lock(&gr_exec_arg_mutex);
58604 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58605 +
58606 + if (unlikely(argv == NULL))
58607 + goto log;
58608 +
58609 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58610 + compat_uptr_t p;
58611 + unsigned int len;
58612 +
58613 + if (get_user(p, argv + i))
58614 + goto log;
58615 + len = strnlen_user(compat_ptr(p), 128 - execlen);
58616 + if (len > 128 - execlen)
58617 + len = 128 - execlen;
58618 + else if (len > 0)
58619 + len--;
58620 + else
58621 + goto log;
58622 + if (copy_from_user(grarg + execlen, compat_ptr(p), len))
58623 + goto log;
58624 +
58625 + /* rewrite unprintable characters */
58626 + for (x = 0; x < len; x++) {
58627 + c = *(grarg + execlen + x);
58628 + if (c < 32 || c > 126)
58629 + *(grarg + execlen + x) = ' ';
58630 + }
58631 +
58632 + execlen += len;
58633 + *(grarg + execlen) = ' ';
58634 + *(grarg + execlen + 1) = '\0';
58635 + execlen++;
58636 + }
58637 +
58638 + log:
58639 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58640 + bprm->file->f_path.mnt, grarg);
58641 + mutex_unlock(&gr_exec_arg_mutex);
58642 +#endif
58643 + return;
58644 +}
58645 +#endif
58646 +
58647 +#ifdef CONFIG_GRKERNSEC
58648 +extern int gr_acl_is_capable(const int cap);
58649 +extern int gr_acl_is_capable_nolog(const int cap);
58650 +extern int gr_chroot_is_capable(const int cap);
58651 +extern int gr_chroot_is_capable_nolog(const int cap);
58652 +#endif
58653 +
58654 +const char *captab_log[] = {
58655 + "CAP_CHOWN",
58656 + "CAP_DAC_OVERRIDE",
58657 + "CAP_DAC_READ_SEARCH",
58658 + "CAP_FOWNER",
58659 + "CAP_FSETID",
58660 + "CAP_KILL",
58661 + "CAP_SETGID",
58662 + "CAP_SETUID",
58663 + "CAP_SETPCAP",
58664 + "CAP_LINUX_IMMUTABLE",
58665 + "CAP_NET_BIND_SERVICE",
58666 + "CAP_NET_BROADCAST",
58667 + "CAP_NET_ADMIN",
58668 + "CAP_NET_RAW",
58669 + "CAP_IPC_LOCK",
58670 + "CAP_IPC_OWNER",
58671 + "CAP_SYS_MODULE",
58672 + "CAP_SYS_RAWIO",
58673 + "CAP_SYS_CHROOT",
58674 + "CAP_SYS_PTRACE",
58675 + "CAP_SYS_PACCT",
58676 + "CAP_SYS_ADMIN",
58677 + "CAP_SYS_BOOT",
58678 + "CAP_SYS_NICE",
58679 + "CAP_SYS_RESOURCE",
58680 + "CAP_SYS_TIME",
58681 + "CAP_SYS_TTY_CONFIG",
58682 + "CAP_MKNOD",
58683 + "CAP_LEASE",
58684 + "CAP_AUDIT_WRITE",
58685 + "CAP_AUDIT_CONTROL",
58686 + "CAP_SETFCAP",
58687 + "CAP_MAC_OVERRIDE",
58688 + "CAP_MAC_ADMIN"
58689 +};
58690 +
58691 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58692 +
58693 +int gr_is_capable(const int cap)
58694 +{
58695 +#ifdef CONFIG_GRKERNSEC
58696 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58697 + return 1;
58698 + return 0;
58699 +#else
58700 + return 1;
58701 +#endif
58702 +}
58703 +
58704 +int gr_is_capable_nolog(const int cap)
58705 +{
58706 +#ifdef CONFIG_GRKERNSEC
58707 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58708 + return 1;
58709 + return 0;
58710 +#else
58711 + return 1;
58712 +#endif
58713 +}
58714 +
58715 +EXPORT_SYMBOL(gr_is_capable);
58716 +EXPORT_SYMBOL(gr_is_capable_nolog);
58717 diff -urNp linux-2.6.32.46/grsecurity/grsec_fifo.c linux-2.6.32.46/grsecurity/grsec_fifo.c
58718 --- linux-2.6.32.46/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
58719 +++ linux-2.6.32.46/grsecurity/grsec_fifo.c 2011-04-17 15:56:46.000000000 -0400
58720 @@ -0,0 +1,24 @@
58721 +#include <linux/kernel.h>
58722 +#include <linux/sched.h>
58723 +#include <linux/fs.h>
58724 +#include <linux/file.h>
58725 +#include <linux/grinternal.h>
58726 +
58727 +int
58728 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58729 + const struct dentry *dir, const int flag, const int acc_mode)
58730 +{
58731 +#ifdef CONFIG_GRKERNSEC_FIFO
58732 + const struct cred *cred = current_cred();
58733 +
58734 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58735 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58736 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58737 + (cred->fsuid != dentry->d_inode->i_uid)) {
58738 + if (!inode_permission(dentry->d_inode, acc_mode))
58739 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58740 + return -EACCES;
58741 + }
58742 +#endif
58743 + return 0;
58744 +}
58745 diff -urNp linux-2.6.32.46/grsecurity/grsec_fork.c linux-2.6.32.46/grsecurity/grsec_fork.c
58746 --- linux-2.6.32.46/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
58747 +++ linux-2.6.32.46/grsecurity/grsec_fork.c 2011-04-17 15:56:46.000000000 -0400
58748 @@ -0,0 +1,23 @@
58749 +#include <linux/kernel.h>
58750 +#include <linux/sched.h>
58751 +#include <linux/grsecurity.h>
58752 +#include <linux/grinternal.h>
58753 +#include <linux/errno.h>
58754 +
58755 +void
58756 +gr_log_forkfail(const int retval)
58757 +{
58758 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58759 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58760 + switch (retval) {
58761 + case -EAGAIN:
58762 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58763 + break;
58764 + case -ENOMEM:
58765 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58766 + break;
58767 + }
58768 + }
58769 +#endif
58770 + return;
58771 +}
58772 diff -urNp linux-2.6.32.46/grsecurity/grsec_init.c linux-2.6.32.46/grsecurity/grsec_init.c
58773 --- linux-2.6.32.46/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
58774 +++ linux-2.6.32.46/grsecurity/grsec_init.c 2011-08-11 19:57:42.000000000 -0400
58775 @@ -0,0 +1,270 @@
58776 +#include <linux/kernel.h>
58777 +#include <linux/sched.h>
58778 +#include <linux/mm.h>
58779 +#include <linux/smp_lock.h>
58780 +#include <linux/gracl.h>
58781 +#include <linux/slab.h>
58782 +#include <linux/vmalloc.h>
58783 +#include <linux/percpu.h>
58784 +#include <linux/module.h>
58785 +
58786 +int grsec_enable_brute;
58787 +int grsec_enable_link;
58788 +int grsec_enable_dmesg;
58789 +int grsec_enable_harden_ptrace;
58790 +int grsec_enable_fifo;
58791 +int grsec_enable_execlog;
58792 +int grsec_enable_signal;
58793 +int grsec_enable_forkfail;
58794 +int grsec_enable_audit_ptrace;
58795 +int grsec_enable_time;
58796 +int grsec_enable_audit_textrel;
58797 +int grsec_enable_group;
58798 +int grsec_audit_gid;
58799 +int grsec_enable_chdir;
58800 +int grsec_enable_mount;
58801 +int grsec_enable_rofs;
58802 +int grsec_enable_chroot_findtask;
58803 +int grsec_enable_chroot_mount;
58804 +int grsec_enable_chroot_shmat;
58805 +int grsec_enable_chroot_fchdir;
58806 +int grsec_enable_chroot_double;
58807 +int grsec_enable_chroot_pivot;
58808 +int grsec_enable_chroot_chdir;
58809 +int grsec_enable_chroot_chmod;
58810 +int grsec_enable_chroot_mknod;
58811 +int grsec_enable_chroot_nice;
58812 +int grsec_enable_chroot_execlog;
58813 +int grsec_enable_chroot_caps;
58814 +int grsec_enable_chroot_sysctl;
58815 +int grsec_enable_chroot_unix;
58816 +int grsec_enable_tpe;
58817 +int grsec_tpe_gid;
58818 +int grsec_enable_blackhole;
58819 +#ifdef CONFIG_IPV6_MODULE
58820 +EXPORT_SYMBOL(grsec_enable_blackhole);
58821 +#endif
58822 +int grsec_lastack_retries;
58823 +int grsec_enable_tpe_all;
58824 +int grsec_enable_tpe_invert;
58825 +int grsec_enable_socket_all;
58826 +int grsec_socket_all_gid;
58827 +int grsec_enable_socket_client;
58828 +int grsec_socket_client_gid;
58829 +int grsec_enable_socket_server;
58830 +int grsec_socket_server_gid;
58831 +int grsec_resource_logging;
58832 +int grsec_disable_privio;
58833 +int grsec_enable_log_rwxmaps;
58834 +int grsec_lock;
58835 +
58836 +DEFINE_SPINLOCK(grsec_alert_lock);
58837 +unsigned long grsec_alert_wtime = 0;
58838 +unsigned long grsec_alert_fyet = 0;
58839 +
58840 +DEFINE_SPINLOCK(grsec_audit_lock);
58841 +
58842 +DEFINE_RWLOCK(grsec_exec_file_lock);
58843 +
58844 +char *gr_shared_page[4];
58845 +
58846 +char *gr_alert_log_fmt;
58847 +char *gr_audit_log_fmt;
58848 +char *gr_alert_log_buf;
58849 +char *gr_audit_log_buf;
58850 +
58851 +extern struct gr_arg *gr_usermode;
58852 +extern unsigned char *gr_system_salt;
58853 +extern unsigned char *gr_system_sum;
58854 +
58855 +void __init
58856 +grsecurity_init(void)
58857 +{
58858 + int j;
58859 + /* create the per-cpu shared pages */
58860 +
58861 +#ifdef CONFIG_X86
58862 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58863 +#endif
58864 +
58865 + for (j = 0; j < 4; j++) {
58866 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58867 + if (gr_shared_page[j] == NULL) {
58868 + panic("Unable to allocate grsecurity shared page");
58869 + return;
58870 + }
58871 + }
58872 +
58873 + /* allocate log buffers */
58874 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58875 + if (!gr_alert_log_fmt) {
58876 + panic("Unable to allocate grsecurity alert log format buffer");
58877 + return;
58878 + }
58879 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58880 + if (!gr_audit_log_fmt) {
58881 + panic("Unable to allocate grsecurity audit log format buffer");
58882 + return;
58883 + }
58884 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58885 + if (!gr_alert_log_buf) {
58886 + panic("Unable to allocate grsecurity alert log buffer");
58887 + return;
58888 + }
58889 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58890 + if (!gr_audit_log_buf) {
58891 + panic("Unable to allocate grsecurity audit log buffer");
58892 + return;
58893 + }
58894 +
58895 + /* allocate memory for authentication structure */
58896 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58897 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58898 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58899 +
58900 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58901 + panic("Unable to allocate grsecurity authentication structure");
58902 + return;
58903 + }
58904 +
58905 +
58906 +#ifdef CONFIG_GRKERNSEC_IO
58907 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58908 + grsec_disable_privio = 1;
58909 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58910 + grsec_disable_privio = 1;
58911 +#else
58912 + grsec_disable_privio = 0;
58913 +#endif
58914 +#endif
58915 +
58916 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58917 + /* for backward compatibility, tpe_invert always defaults to on if
58918 + enabled in the kernel
58919 + */
58920 + grsec_enable_tpe_invert = 1;
58921 +#endif
58922 +
58923 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58924 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58925 + grsec_lock = 1;
58926 +#endif
58927 +
58928 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58929 + grsec_enable_audit_textrel = 1;
58930 +#endif
58931 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58932 + grsec_enable_log_rwxmaps = 1;
58933 +#endif
58934 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58935 + grsec_enable_group = 1;
58936 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58937 +#endif
58938 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58939 + grsec_enable_chdir = 1;
58940 +#endif
58941 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58942 + grsec_enable_harden_ptrace = 1;
58943 +#endif
58944 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58945 + grsec_enable_mount = 1;
58946 +#endif
58947 +#ifdef CONFIG_GRKERNSEC_LINK
58948 + grsec_enable_link = 1;
58949 +#endif
58950 +#ifdef CONFIG_GRKERNSEC_BRUTE
58951 + grsec_enable_brute = 1;
58952 +#endif
58953 +#ifdef CONFIG_GRKERNSEC_DMESG
58954 + grsec_enable_dmesg = 1;
58955 +#endif
58956 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58957 + grsec_enable_blackhole = 1;
58958 + grsec_lastack_retries = 4;
58959 +#endif
58960 +#ifdef CONFIG_GRKERNSEC_FIFO
58961 + grsec_enable_fifo = 1;
58962 +#endif
58963 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58964 + grsec_enable_execlog = 1;
58965 +#endif
58966 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58967 + grsec_enable_signal = 1;
58968 +#endif
58969 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58970 + grsec_enable_forkfail = 1;
58971 +#endif
58972 +#ifdef CONFIG_GRKERNSEC_TIME
58973 + grsec_enable_time = 1;
58974 +#endif
58975 +#ifdef CONFIG_GRKERNSEC_RESLOG
58976 + grsec_resource_logging = 1;
58977 +#endif
58978 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58979 + grsec_enable_chroot_findtask = 1;
58980 +#endif
58981 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58982 + grsec_enable_chroot_unix = 1;
58983 +#endif
58984 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58985 + grsec_enable_chroot_mount = 1;
58986 +#endif
58987 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58988 + grsec_enable_chroot_fchdir = 1;
58989 +#endif
58990 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58991 + grsec_enable_chroot_shmat = 1;
58992 +#endif
58993 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58994 + grsec_enable_audit_ptrace = 1;
58995 +#endif
58996 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58997 + grsec_enable_chroot_double = 1;
58998 +#endif
58999 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59000 + grsec_enable_chroot_pivot = 1;
59001 +#endif
59002 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59003 + grsec_enable_chroot_chdir = 1;
59004 +#endif
59005 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59006 + grsec_enable_chroot_chmod = 1;
59007 +#endif
59008 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59009 + grsec_enable_chroot_mknod = 1;
59010 +#endif
59011 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59012 + grsec_enable_chroot_nice = 1;
59013 +#endif
59014 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59015 + grsec_enable_chroot_execlog = 1;
59016 +#endif
59017 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59018 + grsec_enable_chroot_caps = 1;
59019 +#endif
59020 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59021 + grsec_enable_chroot_sysctl = 1;
59022 +#endif
59023 +#ifdef CONFIG_GRKERNSEC_TPE
59024 + grsec_enable_tpe = 1;
59025 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
59026 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59027 + grsec_enable_tpe_all = 1;
59028 +#endif
59029 +#endif
59030 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59031 + grsec_enable_socket_all = 1;
59032 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
59033 +#endif
59034 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59035 + grsec_enable_socket_client = 1;
59036 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
59037 +#endif
59038 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59039 + grsec_enable_socket_server = 1;
59040 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
59041 +#endif
59042 +#endif
59043 +
59044 + return;
59045 +}
59046 diff -urNp linux-2.6.32.46/grsecurity/grsec_link.c linux-2.6.32.46/grsecurity/grsec_link.c
59047 --- linux-2.6.32.46/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
59048 +++ linux-2.6.32.46/grsecurity/grsec_link.c 2011-04-17 15:56:46.000000000 -0400
59049 @@ -0,0 +1,43 @@
59050 +#include <linux/kernel.h>
59051 +#include <linux/sched.h>
59052 +#include <linux/fs.h>
59053 +#include <linux/file.h>
59054 +#include <linux/grinternal.h>
59055 +
59056 +int
59057 +gr_handle_follow_link(const struct inode *parent,
59058 + const struct inode *inode,
59059 + const struct dentry *dentry, const struct vfsmount *mnt)
59060 +{
59061 +#ifdef CONFIG_GRKERNSEC_LINK
59062 + const struct cred *cred = current_cred();
59063 +
59064 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
59065 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
59066 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
59067 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
59068 + return -EACCES;
59069 + }
59070 +#endif
59071 + return 0;
59072 +}
59073 +
59074 +int
59075 +gr_handle_hardlink(const struct dentry *dentry,
59076 + const struct vfsmount *mnt,
59077 + struct inode *inode, const int mode, const char *to)
59078 +{
59079 +#ifdef CONFIG_GRKERNSEC_LINK
59080 + const struct cred *cred = current_cred();
59081 +
59082 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
59083 + (!S_ISREG(mode) || (mode & S_ISUID) ||
59084 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
59085 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
59086 + !capable(CAP_FOWNER) && cred->uid) {
59087 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
59088 + return -EPERM;
59089 + }
59090 +#endif
59091 + return 0;
59092 +}
59093 diff -urNp linux-2.6.32.46/grsecurity/grsec_log.c linux-2.6.32.46/grsecurity/grsec_log.c
59094 --- linux-2.6.32.46/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
59095 +++ linux-2.6.32.46/grsecurity/grsec_log.c 2011-09-26 10:44:49.000000000 -0400
59096 @@ -0,0 +1,315 @@
59097 +#include <linux/kernel.h>
59098 +#include <linux/sched.h>
59099 +#include <linux/file.h>
59100 +#include <linux/tty.h>
59101 +#include <linux/fs.h>
59102 +#include <linux/grinternal.h>
59103 +
59104 +#ifdef CONFIG_TREE_PREEMPT_RCU
59105 +#define DISABLE_PREEMPT() preempt_disable()
59106 +#define ENABLE_PREEMPT() preempt_enable()
59107 +#else
59108 +#define DISABLE_PREEMPT()
59109 +#define ENABLE_PREEMPT()
59110 +#endif
59111 +
59112 +#define BEGIN_LOCKS(x) \
59113 + DISABLE_PREEMPT(); \
59114 + rcu_read_lock(); \
59115 + read_lock(&tasklist_lock); \
59116 + read_lock(&grsec_exec_file_lock); \
59117 + if (x != GR_DO_AUDIT) \
59118 + spin_lock(&grsec_alert_lock); \
59119 + else \
59120 + spin_lock(&grsec_audit_lock)
59121 +
59122 +#define END_LOCKS(x) \
59123 + if (x != GR_DO_AUDIT) \
59124 + spin_unlock(&grsec_alert_lock); \
59125 + else \
59126 + spin_unlock(&grsec_audit_lock); \
59127 + read_unlock(&grsec_exec_file_lock); \
59128 + read_unlock(&tasklist_lock); \
59129 + rcu_read_unlock(); \
59130 + ENABLE_PREEMPT(); \
59131 + if (x == GR_DONT_AUDIT) \
59132 + gr_handle_alertkill(current)
59133 +
59134 +enum {
59135 + FLOODING,
59136 + NO_FLOODING
59137 +};
59138 +
59139 +extern char *gr_alert_log_fmt;
59140 +extern char *gr_audit_log_fmt;
59141 +extern char *gr_alert_log_buf;
59142 +extern char *gr_audit_log_buf;
59143 +
59144 +static int gr_log_start(int audit)
59145 +{
59146 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
59147 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
59148 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59149 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
59150 + unsigned long curr_secs = get_seconds();
59151 +
59152 + if (audit == GR_DO_AUDIT)
59153 + goto set_fmt;
59154 +
59155 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59156 + grsec_alert_wtime = curr_secs;
59157 + grsec_alert_fyet = 0;
59158 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59159 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59160 + grsec_alert_fyet++;
59161 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59162 + grsec_alert_wtime = curr_secs;
59163 + grsec_alert_fyet++;
59164 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59165 + return FLOODING;
59166 + }
59167 + else return FLOODING;
59168 +
59169 +set_fmt:
59170 +#endif
59171 + memset(buf, 0, PAGE_SIZE);
59172 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
59173 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59174 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59175 + } else if (current->signal->curr_ip) {
59176 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59177 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59178 + } else if (gr_acl_is_enabled()) {
59179 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59180 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59181 + } else {
59182 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
59183 + strcpy(buf, fmt);
59184 + }
59185 +
59186 + return NO_FLOODING;
59187 +}
59188 +
59189 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59190 + __attribute__ ((format (printf, 2, 0)));
59191 +
59192 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59193 +{
59194 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59195 + unsigned int len = strlen(buf);
59196 +
59197 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59198 +
59199 + return;
59200 +}
59201 +
59202 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59203 + __attribute__ ((format (printf, 2, 3)));
59204 +
59205 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59206 +{
59207 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59208 + unsigned int len = strlen(buf);
59209 + va_list ap;
59210 +
59211 + va_start(ap, msg);
59212 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59213 + va_end(ap);
59214 +
59215 + return;
59216 +}
59217 +
59218 +static void gr_log_end(int audit)
59219 +{
59220 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59221 + unsigned int len = strlen(buf);
59222 +
59223 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59224 + printk("%s\n", buf);
59225 +
59226 + return;
59227 +}
59228 +
59229 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59230 +{
59231 + int logtype;
59232 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59233 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59234 + void *voidptr = NULL;
59235 + int num1 = 0, num2 = 0;
59236 + unsigned long ulong1 = 0, ulong2 = 0;
59237 + struct dentry *dentry = NULL;
59238 + struct vfsmount *mnt = NULL;
59239 + struct file *file = NULL;
59240 + struct task_struct *task = NULL;
59241 + const struct cred *cred, *pcred;
59242 + va_list ap;
59243 +
59244 + BEGIN_LOCKS(audit);
59245 + logtype = gr_log_start(audit);
59246 + if (logtype == FLOODING) {
59247 + END_LOCKS(audit);
59248 + return;
59249 + }
59250 + va_start(ap, argtypes);
59251 + switch (argtypes) {
59252 + case GR_TTYSNIFF:
59253 + task = va_arg(ap, struct task_struct *);
59254 + 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);
59255 + break;
59256 + case GR_SYSCTL_HIDDEN:
59257 + str1 = va_arg(ap, char *);
59258 + gr_log_middle_varargs(audit, msg, result, str1);
59259 + break;
59260 + case GR_RBAC:
59261 + dentry = va_arg(ap, struct dentry *);
59262 + mnt = va_arg(ap, struct vfsmount *);
59263 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59264 + break;
59265 + case GR_RBAC_STR:
59266 + dentry = va_arg(ap, struct dentry *);
59267 + mnt = va_arg(ap, struct vfsmount *);
59268 + str1 = va_arg(ap, char *);
59269 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59270 + break;
59271 + case GR_STR_RBAC:
59272 + str1 = va_arg(ap, char *);
59273 + dentry = va_arg(ap, struct dentry *);
59274 + mnt = va_arg(ap, struct vfsmount *);
59275 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59276 + break;
59277 + case GR_RBAC_MODE2:
59278 + dentry = va_arg(ap, struct dentry *);
59279 + mnt = va_arg(ap, struct vfsmount *);
59280 + str1 = va_arg(ap, char *);
59281 + str2 = va_arg(ap, char *);
59282 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59283 + break;
59284 + case GR_RBAC_MODE3:
59285 + dentry = va_arg(ap, struct dentry *);
59286 + mnt = va_arg(ap, struct vfsmount *);
59287 + str1 = va_arg(ap, char *);
59288 + str2 = va_arg(ap, char *);
59289 + str3 = va_arg(ap, char *);
59290 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59291 + break;
59292 + case GR_FILENAME:
59293 + dentry = va_arg(ap, struct dentry *);
59294 + mnt = va_arg(ap, struct vfsmount *);
59295 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59296 + break;
59297 + case GR_STR_FILENAME:
59298 + str1 = va_arg(ap, char *);
59299 + dentry = va_arg(ap, struct dentry *);
59300 + mnt = va_arg(ap, struct vfsmount *);
59301 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59302 + break;
59303 + case GR_FILENAME_STR:
59304 + dentry = va_arg(ap, struct dentry *);
59305 + mnt = va_arg(ap, struct vfsmount *);
59306 + str1 = va_arg(ap, char *);
59307 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59308 + break;
59309 + case GR_FILENAME_TWO_INT:
59310 + dentry = va_arg(ap, struct dentry *);
59311 + mnt = va_arg(ap, struct vfsmount *);
59312 + num1 = va_arg(ap, int);
59313 + num2 = va_arg(ap, int);
59314 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59315 + break;
59316 + case GR_FILENAME_TWO_INT_STR:
59317 + dentry = va_arg(ap, struct dentry *);
59318 + mnt = va_arg(ap, struct vfsmount *);
59319 + num1 = va_arg(ap, int);
59320 + num2 = va_arg(ap, int);
59321 + str1 = va_arg(ap, char *);
59322 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59323 + break;
59324 + case GR_TEXTREL:
59325 + file = va_arg(ap, struct file *);
59326 + ulong1 = va_arg(ap, unsigned long);
59327 + ulong2 = va_arg(ap, unsigned long);
59328 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59329 + break;
59330 + case GR_PTRACE:
59331 + task = va_arg(ap, struct task_struct *);
59332 + 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);
59333 + break;
59334 + case GR_RESOURCE:
59335 + task = va_arg(ap, struct task_struct *);
59336 + cred = __task_cred(task);
59337 + pcred = __task_cred(task->real_parent);
59338 + ulong1 = va_arg(ap, unsigned long);
59339 + str1 = va_arg(ap, char *);
59340 + ulong2 = va_arg(ap, unsigned long);
59341 + 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);
59342 + break;
59343 + case GR_CAP:
59344 + task = va_arg(ap, struct task_struct *);
59345 + cred = __task_cred(task);
59346 + pcred = __task_cred(task->real_parent);
59347 + str1 = va_arg(ap, char *);
59348 + 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);
59349 + break;
59350 + case GR_SIG:
59351 + str1 = va_arg(ap, char *);
59352 + voidptr = va_arg(ap, void *);
59353 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59354 + break;
59355 + case GR_SIG2:
59356 + task = va_arg(ap, struct task_struct *);
59357 + cred = __task_cred(task);
59358 + pcred = __task_cred(task->real_parent);
59359 + num1 = va_arg(ap, int);
59360 + 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);
59361 + break;
59362 + case GR_CRASH1:
59363 + task = va_arg(ap, struct task_struct *);
59364 + cred = __task_cred(task);
59365 + pcred = __task_cred(task->real_parent);
59366 + ulong1 = va_arg(ap, unsigned long);
59367 + 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);
59368 + break;
59369 + case GR_CRASH2:
59370 + task = va_arg(ap, struct task_struct *);
59371 + cred = __task_cred(task);
59372 + pcred = __task_cred(task->real_parent);
59373 + ulong1 = va_arg(ap, unsigned long);
59374 + 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);
59375 + break;
59376 + case GR_RWXMAP:
59377 + file = va_arg(ap, struct file *);
59378 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59379 + break;
59380 + case GR_PSACCT:
59381 + {
59382 + unsigned int wday, cday;
59383 + __u8 whr, chr;
59384 + __u8 wmin, cmin;
59385 + __u8 wsec, csec;
59386 + char cur_tty[64] = { 0 };
59387 + char parent_tty[64] = { 0 };
59388 +
59389 + task = va_arg(ap, struct task_struct *);
59390 + wday = va_arg(ap, unsigned int);
59391 + cday = va_arg(ap, unsigned int);
59392 + whr = va_arg(ap, int);
59393 + chr = va_arg(ap, int);
59394 + wmin = va_arg(ap, int);
59395 + cmin = va_arg(ap, int);
59396 + wsec = va_arg(ap, int);
59397 + csec = va_arg(ap, int);
59398 + ulong1 = va_arg(ap, unsigned long);
59399 + cred = __task_cred(task);
59400 + pcred = __task_cred(task->real_parent);
59401 +
59402 + 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);
59403 + }
59404 + break;
59405 + default:
59406 + gr_log_middle(audit, msg, ap);
59407 + }
59408 + va_end(ap);
59409 + gr_log_end(audit);
59410 + END_LOCKS(audit);
59411 +}
59412 diff -urNp linux-2.6.32.46/grsecurity/grsec_mem.c linux-2.6.32.46/grsecurity/grsec_mem.c
59413 --- linux-2.6.32.46/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
59414 +++ linux-2.6.32.46/grsecurity/grsec_mem.c 2011-04-17 15:56:46.000000000 -0400
59415 @@ -0,0 +1,33 @@
59416 +#include <linux/kernel.h>
59417 +#include <linux/sched.h>
59418 +#include <linux/mm.h>
59419 +#include <linux/mman.h>
59420 +#include <linux/grinternal.h>
59421 +
59422 +void
59423 +gr_handle_ioperm(void)
59424 +{
59425 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59426 + return;
59427 +}
59428 +
59429 +void
59430 +gr_handle_iopl(void)
59431 +{
59432 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59433 + return;
59434 +}
59435 +
59436 +void
59437 +gr_handle_mem_readwrite(u64 from, u64 to)
59438 +{
59439 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59440 + return;
59441 +}
59442 +
59443 +void
59444 +gr_handle_vm86(void)
59445 +{
59446 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59447 + return;
59448 +}
59449 diff -urNp linux-2.6.32.46/grsecurity/grsec_mount.c linux-2.6.32.46/grsecurity/grsec_mount.c
59450 --- linux-2.6.32.46/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
59451 +++ linux-2.6.32.46/grsecurity/grsec_mount.c 2011-06-20 19:47:03.000000000 -0400
59452 @@ -0,0 +1,62 @@
59453 +#include <linux/kernel.h>
59454 +#include <linux/sched.h>
59455 +#include <linux/mount.h>
59456 +#include <linux/grsecurity.h>
59457 +#include <linux/grinternal.h>
59458 +
59459 +void
59460 +gr_log_remount(const char *devname, const int retval)
59461 +{
59462 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59463 + if (grsec_enable_mount && (retval >= 0))
59464 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59465 +#endif
59466 + return;
59467 +}
59468 +
59469 +void
59470 +gr_log_unmount(const char *devname, const int retval)
59471 +{
59472 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59473 + if (grsec_enable_mount && (retval >= 0))
59474 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59475 +#endif
59476 + return;
59477 +}
59478 +
59479 +void
59480 +gr_log_mount(const char *from, const char *to, const int retval)
59481 +{
59482 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59483 + if (grsec_enable_mount && (retval >= 0))
59484 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59485 +#endif
59486 + return;
59487 +}
59488 +
59489 +int
59490 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59491 +{
59492 +#ifdef CONFIG_GRKERNSEC_ROFS
59493 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59494 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59495 + return -EPERM;
59496 + } else
59497 + return 0;
59498 +#endif
59499 + return 0;
59500 +}
59501 +
59502 +int
59503 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59504 +{
59505 +#ifdef CONFIG_GRKERNSEC_ROFS
59506 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59507 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59508 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59509 + return -EPERM;
59510 + } else
59511 + return 0;
59512 +#endif
59513 + return 0;
59514 +}
59515 diff -urNp linux-2.6.32.46/grsecurity/grsec_pax.c linux-2.6.32.46/grsecurity/grsec_pax.c
59516 --- linux-2.6.32.46/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
59517 +++ linux-2.6.32.46/grsecurity/grsec_pax.c 2011-04-17 15:56:46.000000000 -0400
59518 @@ -0,0 +1,36 @@
59519 +#include <linux/kernel.h>
59520 +#include <linux/sched.h>
59521 +#include <linux/mm.h>
59522 +#include <linux/file.h>
59523 +#include <linux/grinternal.h>
59524 +#include <linux/grsecurity.h>
59525 +
59526 +void
59527 +gr_log_textrel(struct vm_area_struct * vma)
59528 +{
59529 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59530 + if (grsec_enable_audit_textrel)
59531 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59532 +#endif
59533 + return;
59534 +}
59535 +
59536 +void
59537 +gr_log_rwxmmap(struct file *file)
59538 +{
59539 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59540 + if (grsec_enable_log_rwxmaps)
59541 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59542 +#endif
59543 + return;
59544 +}
59545 +
59546 +void
59547 +gr_log_rwxmprotect(struct file *file)
59548 +{
59549 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59550 + if (grsec_enable_log_rwxmaps)
59551 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59552 +#endif
59553 + return;
59554 +}
59555 diff -urNp linux-2.6.32.46/grsecurity/grsec_ptrace.c linux-2.6.32.46/grsecurity/grsec_ptrace.c
59556 --- linux-2.6.32.46/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
59557 +++ linux-2.6.32.46/grsecurity/grsec_ptrace.c 2011-04-17 15:56:46.000000000 -0400
59558 @@ -0,0 +1,14 @@
59559 +#include <linux/kernel.h>
59560 +#include <linux/sched.h>
59561 +#include <linux/grinternal.h>
59562 +#include <linux/grsecurity.h>
59563 +
59564 +void
59565 +gr_audit_ptrace(struct task_struct *task)
59566 +{
59567 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59568 + if (grsec_enable_audit_ptrace)
59569 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59570 +#endif
59571 + return;
59572 +}
59573 diff -urNp linux-2.6.32.46/grsecurity/grsec_sig.c linux-2.6.32.46/grsecurity/grsec_sig.c
59574 --- linux-2.6.32.46/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
59575 +++ linux-2.6.32.46/grsecurity/grsec_sig.c 2011-06-29 19:40:31.000000000 -0400
59576 @@ -0,0 +1,205 @@
59577 +#include <linux/kernel.h>
59578 +#include <linux/sched.h>
59579 +#include <linux/delay.h>
59580 +#include <linux/grsecurity.h>
59581 +#include <linux/grinternal.h>
59582 +#include <linux/hardirq.h>
59583 +
59584 +char *signames[] = {
59585 + [SIGSEGV] = "Segmentation fault",
59586 + [SIGILL] = "Illegal instruction",
59587 + [SIGABRT] = "Abort",
59588 + [SIGBUS] = "Invalid alignment/Bus error"
59589 +};
59590 +
59591 +void
59592 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59593 +{
59594 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59595 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59596 + (sig == SIGABRT) || (sig == SIGBUS))) {
59597 + if (t->pid == current->pid) {
59598 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59599 + } else {
59600 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59601 + }
59602 + }
59603 +#endif
59604 + return;
59605 +}
59606 +
59607 +int
59608 +gr_handle_signal(const struct task_struct *p, const int sig)
59609 +{
59610 +#ifdef CONFIG_GRKERNSEC
59611 + if (current->pid > 1 && gr_check_protected_task(p)) {
59612 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59613 + return -EPERM;
59614 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59615 + return -EPERM;
59616 + }
59617 +#endif
59618 + return 0;
59619 +}
59620 +
59621 +#ifdef CONFIG_GRKERNSEC
59622 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59623 +
59624 +int gr_fake_force_sig(int sig, struct task_struct *t)
59625 +{
59626 + unsigned long int flags;
59627 + int ret, blocked, ignored;
59628 + struct k_sigaction *action;
59629 +
59630 + spin_lock_irqsave(&t->sighand->siglock, flags);
59631 + action = &t->sighand->action[sig-1];
59632 + ignored = action->sa.sa_handler == SIG_IGN;
59633 + blocked = sigismember(&t->blocked, sig);
59634 + if (blocked || ignored) {
59635 + action->sa.sa_handler = SIG_DFL;
59636 + if (blocked) {
59637 + sigdelset(&t->blocked, sig);
59638 + recalc_sigpending_and_wake(t);
59639 + }
59640 + }
59641 + if (action->sa.sa_handler == SIG_DFL)
59642 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59643 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59644 +
59645 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59646 +
59647 + return ret;
59648 +}
59649 +#endif
59650 +
59651 +#ifdef CONFIG_GRKERNSEC_BRUTE
59652 +#define GR_USER_BAN_TIME (15 * 60)
59653 +
59654 +static int __get_dumpable(unsigned long mm_flags)
59655 +{
59656 + int ret;
59657 +
59658 + ret = mm_flags & MMF_DUMPABLE_MASK;
59659 + return (ret >= 2) ? 2 : ret;
59660 +}
59661 +#endif
59662 +
59663 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59664 +{
59665 +#ifdef CONFIG_GRKERNSEC_BRUTE
59666 + uid_t uid = 0;
59667 +
59668 + if (!grsec_enable_brute)
59669 + return;
59670 +
59671 + rcu_read_lock();
59672 + read_lock(&tasklist_lock);
59673 + read_lock(&grsec_exec_file_lock);
59674 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59675 + p->real_parent->brute = 1;
59676 + else {
59677 + const struct cred *cred = __task_cred(p), *cred2;
59678 + struct task_struct *tsk, *tsk2;
59679 +
59680 + if (!__get_dumpable(mm_flags) && cred->uid) {
59681 + struct user_struct *user;
59682 +
59683 + uid = cred->uid;
59684 +
59685 + /* this is put upon execution past expiration */
59686 + user = find_user(uid);
59687 + if (user == NULL)
59688 + goto unlock;
59689 + user->banned = 1;
59690 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59691 + if (user->ban_expires == ~0UL)
59692 + user->ban_expires--;
59693 +
59694 + do_each_thread(tsk2, tsk) {
59695 + cred2 = __task_cred(tsk);
59696 + if (tsk != p && cred2->uid == uid)
59697 + gr_fake_force_sig(SIGKILL, tsk);
59698 + } while_each_thread(tsk2, tsk);
59699 + }
59700 + }
59701 +unlock:
59702 + read_unlock(&grsec_exec_file_lock);
59703 + read_unlock(&tasklist_lock);
59704 + rcu_read_unlock();
59705 +
59706 + if (uid)
59707 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
59708 +#endif
59709 + return;
59710 +}
59711 +
59712 +void gr_handle_brute_check(void)
59713 +{
59714 +#ifdef CONFIG_GRKERNSEC_BRUTE
59715 + if (current->brute)
59716 + msleep(30 * 1000);
59717 +#endif
59718 + return;
59719 +}
59720 +
59721 +void gr_handle_kernel_exploit(void)
59722 +{
59723 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59724 + const struct cred *cred;
59725 + struct task_struct *tsk, *tsk2;
59726 + struct user_struct *user;
59727 + uid_t uid;
59728 +
59729 + if (in_irq() || in_serving_softirq() || in_nmi())
59730 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59731 +
59732 + uid = current_uid();
59733 +
59734 + if (uid == 0)
59735 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59736 + else {
59737 + /* kill all the processes of this user, hold a reference
59738 + to their creds struct, and prevent them from creating
59739 + another process until system reset
59740 + */
59741 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
59742 + /* we intentionally leak this ref */
59743 + user = get_uid(current->cred->user);
59744 + if (user) {
59745 + user->banned = 1;
59746 + user->ban_expires = ~0UL;
59747 + }
59748 +
59749 + read_lock(&tasklist_lock);
59750 + do_each_thread(tsk2, tsk) {
59751 + cred = __task_cred(tsk);
59752 + if (cred->uid == uid)
59753 + gr_fake_force_sig(SIGKILL, tsk);
59754 + } while_each_thread(tsk2, tsk);
59755 + read_unlock(&tasklist_lock);
59756 + }
59757 +#endif
59758 +}
59759 +
59760 +int __gr_process_user_ban(struct user_struct *user)
59761 +{
59762 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59763 + if (unlikely(user->banned)) {
59764 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59765 + user->banned = 0;
59766 + user->ban_expires = 0;
59767 + free_uid(user);
59768 + } else
59769 + return -EPERM;
59770 + }
59771 +#endif
59772 + return 0;
59773 +}
59774 +
59775 +int gr_process_user_ban(void)
59776 +{
59777 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59778 + return __gr_process_user_ban(current->cred->user);
59779 +#endif
59780 + return 0;
59781 +}
59782 diff -urNp linux-2.6.32.46/grsecurity/grsec_sock.c linux-2.6.32.46/grsecurity/grsec_sock.c
59783 --- linux-2.6.32.46/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
59784 +++ linux-2.6.32.46/grsecurity/grsec_sock.c 2011-04-17 15:56:46.000000000 -0400
59785 @@ -0,0 +1,275 @@
59786 +#include <linux/kernel.h>
59787 +#include <linux/module.h>
59788 +#include <linux/sched.h>
59789 +#include <linux/file.h>
59790 +#include <linux/net.h>
59791 +#include <linux/in.h>
59792 +#include <linux/ip.h>
59793 +#include <net/sock.h>
59794 +#include <net/inet_sock.h>
59795 +#include <linux/grsecurity.h>
59796 +#include <linux/grinternal.h>
59797 +#include <linux/gracl.h>
59798 +
59799 +kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
59800 +EXPORT_SYMBOL(gr_cap_rtnetlink);
59801 +
59802 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59803 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59804 +
59805 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59806 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59807 +
59808 +#ifdef CONFIG_UNIX_MODULE
59809 +EXPORT_SYMBOL(gr_acl_handle_unix);
59810 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59811 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59812 +EXPORT_SYMBOL(gr_handle_create);
59813 +#endif
59814 +
59815 +#ifdef CONFIG_GRKERNSEC
59816 +#define gr_conn_table_size 32749
59817 +struct conn_table_entry {
59818 + struct conn_table_entry *next;
59819 + struct signal_struct *sig;
59820 +};
59821 +
59822 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59823 +DEFINE_SPINLOCK(gr_conn_table_lock);
59824 +
59825 +extern const char * gr_socktype_to_name(unsigned char type);
59826 +extern const char * gr_proto_to_name(unsigned char proto);
59827 +extern const char * gr_sockfamily_to_name(unsigned char family);
59828 +
59829 +static __inline__ int
59830 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59831 +{
59832 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59833 +}
59834 +
59835 +static __inline__ int
59836 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59837 + __u16 sport, __u16 dport)
59838 +{
59839 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59840 + sig->gr_sport == sport && sig->gr_dport == dport))
59841 + return 1;
59842 + else
59843 + return 0;
59844 +}
59845 +
59846 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59847 +{
59848 + struct conn_table_entry **match;
59849 + unsigned int index;
59850 +
59851 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59852 + sig->gr_sport, sig->gr_dport,
59853 + gr_conn_table_size);
59854 +
59855 + newent->sig = sig;
59856 +
59857 + match = &gr_conn_table[index];
59858 + newent->next = *match;
59859 + *match = newent;
59860 +
59861 + return;
59862 +}
59863 +
59864 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59865 +{
59866 + struct conn_table_entry *match, *last = NULL;
59867 + unsigned int index;
59868 +
59869 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59870 + sig->gr_sport, sig->gr_dport,
59871 + gr_conn_table_size);
59872 +
59873 + match = gr_conn_table[index];
59874 + while (match && !conn_match(match->sig,
59875 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59876 + sig->gr_dport)) {
59877 + last = match;
59878 + match = match->next;
59879 + }
59880 +
59881 + if (match) {
59882 + if (last)
59883 + last->next = match->next;
59884 + else
59885 + gr_conn_table[index] = NULL;
59886 + kfree(match);
59887 + }
59888 +
59889 + return;
59890 +}
59891 +
59892 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59893 + __u16 sport, __u16 dport)
59894 +{
59895 + struct conn_table_entry *match;
59896 + unsigned int index;
59897 +
59898 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59899 +
59900 + match = gr_conn_table[index];
59901 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59902 + match = match->next;
59903 +
59904 + if (match)
59905 + return match->sig;
59906 + else
59907 + return NULL;
59908 +}
59909 +
59910 +#endif
59911 +
59912 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59913 +{
59914 +#ifdef CONFIG_GRKERNSEC
59915 + struct signal_struct *sig = task->signal;
59916 + struct conn_table_entry *newent;
59917 +
59918 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59919 + if (newent == NULL)
59920 + return;
59921 + /* no bh lock needed since we are called with bh disabled */
59922 + spin_lock(&gr_conn_table_lock);
59923 + gr_del_task_from_ip_table_nolock(sig);
59924 + sig->gr_saddr = inet->rcv_saddr;
59925 + sig->gr_daddr = inet->daddr;
59926 + sig->gr_sport = inet->sport;
59927 + sig->gr_dport = inet->dport;
59928 + gr_add_to_task_ip_table_nolock(sig, newent);
59929 + spin_unlock(&gr_conn_table_lock);
59930 +#endif
59931 + return;
59932 +}
59933 +
59934 +void gr_del_task_from_ip_table(struct task_struct *task)
59935 +{
59936 +#ifdef CONFIG_GRKERNSEC
59937 + spin_lock_bh(&gr_conn_table_lock);
59938 + gr_del_task_from_ip_table_nolock(task->signal);
59939 + spin_unlock_bh(&gr_conn_table_lock);
59940 +#endif
59941 + return;
59942 +}
59943 +
59944 +void
59945 +gr_attach_curr_ip(const struct sock *sk)
59946 +{
59947 +#ifdef CONFIG_GRKERNSEC
59948 + struct signal_struct *p, *set;
59949 + const struct inet_sock *inet = inet_sk(sk);
59950 +
59951 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59952 + return;
59953 +
59954 + set = current->signal;
59955 +
59956 + spin_lock_bh(&gr_conn_table_lock);
59957 + p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
59958 + inet->dport, inet->sport);
59959 + if (unlikely(p != NULL)) {
59960 + set->curr_ip = p->curr_ip;
59961 + set->used_accept = 1;
59962 + gr_del_task_from_ip_table_nolock(p);
59963 + spin_unlock_bh(&gr_conn_table_lock);
59964 + return;
59965 + }
59966 + spin_unlock_bh(&gr_conn_table_lock);
59967 +
59968 + set->curr_ip = inet->daddr;
59969 + set->used_accept = 1;
59970 +#endif
59971 + return;
59972 +}
59973 +
59974 +int
59975 +gr_handle_sock_all(const int family, const int type, const int protocol)
59976 +{
59977 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59978 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59979 + (family != AF_UNIX)) {
59980 + if (family == AF_INET)
59981 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59982 + else
59983 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59984 + return -EACCES;
59985 + }
59986 +#endif
59987 + return 0;
59988 +}
59989 +
59990 +int
59991 +gr_handle_sock_server(const struct sockaddr *sck)
59992 +{
59993 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59994 + if (grsec_enable_socket_server &&
59995 + in_group_p(grsec_socket_server_gid) &&
59996 + sck && (sck->sa_family != AF_UNIX) &&
59997 + (sck->sa_family != AF_LOCAL)) {
59998 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59999 + return -EACCES;
60000 + }
60001 +#endif
60002 + return 0;
60003 +}
60004 +
60005 +int
60006 +gr_handle_sock_server_other(const struct sock *sck)
60007 +{
60008 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60009 + if (grsec_enable_socket_server &&
60010 + in_group_p(grsec_socket_server_gid) &&
60011 + sck && (sck->sk_family != AF_UNIX) &&
60012 + (sck->sk_family != AF_LOCAL)) {
60013 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60014 + return -EACCES;
60015 + }
60016 +#endif
60017 + return 0;
60018 +}
60019 +
60020 +int
60021 +gr_handle_sock_client(const struct sockaddr *sck)
60022 +{
60023 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60024 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
60025 + sck && (sck->sa_family != AF_UNIX) &&
60026 + (sck->sa_family != AF_LOCAL)) {
60027 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
60028 + return -EACCES;
60029 + }
60030 +#endif
60031 + return 0;
60032 +}
60033 +
60034 +kernel_cap_t
60035 +gr_cap_rtnetlink(struct sock *sock)
60036 +{
60037 +#ifdef CONFIG_GRKERNSEC
60038 + if (!gr_acl_is_enabled())
60039 + return current_cap();
60040 + else if (sock->sk_protocol == NETLINK_ISCSI &&
60041 + cap_raised(current_cap(), CAP_SYS_ADMIN) &&
60042 + gr_is_capable(CAP_SYS_ADMIN))
60043 + return current_cap();
60044 + else if (sock->sk_protocol == NETLINK_AUDIT &&
60045 + cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
60046 + gr_is_capable(CAP_AUDIT_WRITE) &&
60047 + cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
60048 + gr_is_capable(CAP_AUDIT_CONTROL))
60049 + return current_cap();
60050 + else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
60051 + ((sock->sk_protocol == NETLINK_ROUTE) ?
60052 + gr_is_capable_nolog(CAP_NET_ADMIN) :
60053 + gr_is_capable(CAP_NET_ADMIN)))
60054 + return current_cap();
60055 + else
60056 + return __cap_empty_set;
60057 +#else
60058 + return current_cap();
60059 +#endif
60060 +}
60061 diff -urNp linux-2.6.32.46/grsecurity/grsec_sysctl.c linux-2.6.32.46/grsecurity/grsec_sysctl.c
60062 --- linux-2.6.32.46/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
60063 +++ linux-2.6.32.46/grsecurity/grsec_sysctl.c 2011-08-11 19:57:54.000000000 -0400
60064 @@ -0,0 +1,479 @@
60065 +#include <linux/kernel.h>
60066 +#include <linux/sched.h>
60067 +#include <linux/sysctl.h>
60068 +#include <linux/grsecurity.h>
60069 +#include <linux/grinternal.h>
60070 +
60071 +int
60072 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
60073 +{
60074 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60075 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
60076 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
60077 + return -EACCES;
60078 + }
60079 +#endif
60080 + return 0;
60081 +}
60082 +
60083 +#ifdef CONFIG_GRKERNSEC_ROFS
60084 +static int __maybe_unused one = 1;
60085 +#endif
60086 +
60087 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
60088 +ctl_table grsecurity_table[] = {
60089 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60090 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
60091 +#ifdef CONFIG_GRKERNSEC_IO
60092 + {
60093 + .ctl_name = CTL_UNNUMBERED,
60094 + .procname = "disable_priv_io",
60095 + .data = &grsec_disable_privio,
60096 + .maxlen = sizeof(int),
60097 + .mode = 0600,
60098 + .proc_handler = &proc_dointvec,
60099 + },
60100 +#endif
60101 +#endif
60102 +#ifdef CONFIG_GRKERNSEC_LINK
60103 + {
60104 + .ctl_name = CTL_UNNUMBERED,
60105 + .procname = "linking_restrictions",
60106 + .data = &grsec_enable_link,
60107 + .maxlen = sizeof(int),
60108 + .mode = 0600,
60109 + .proc_handler = &proc_dointvec,
60110 + },
60111 +#endif
60112 +#ifdef CONFIG_GRKERNSEC_BRUTE
60113 + {
60114 + .ctl_name = CTL_UNNUMBERED,
60115 + .procname = "deter_bruteforce",
60116 + .data = &grsec_enable_brute,
60117 + .maxlen = sizeof(int),
60118 + .mode = 0600,
60119 + .proc_handler = &proc_dointvec,
60120 + },
60121 +#endif
60122 +#ifdef CONFIG_GRKERNSEC_FIFO
60123 + {
60124 + .ctl_name = CTL_UNNUMBERED,
60125 + .procname = "fifo_restrictions",
60126 + .data = &grsec_enable_fifo,
60127 + .maxlen = sizeof(int),
60128 + .mode = 0600,
60129 + .proc_handler = &proc_dointvec,
60130 + },
60131 +#endif
60132 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60133 + {
60134 + .ctl_name = CTL_UNNUMBERED,
60135 + .procname = "ip_blackhole",
60136 + .data = &grsec_enable_blackhole,
60137 + .maxlen = sizeof(int),
60138 + .mode = 0600,
60139 + .proc_handler = &proc_dointvec,
60140 + },
60141 + {
60142 + .ctl_name = CTL_UNNUMBERED,
60143 + .procname = "lastack_retries",
60144 + .data = &grsec_lastack_retries,
60145 + .maxlen = sizeof(int),
60146 + .mode = 0600,
60147 + .proc_handler = &proc_dointvec,
60148 + },
60149 +#endif
60150 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60151 + {
60152 + .ctl_name = CTL_UNNUMBERED,
60153 + .procname = "exec_logging",
60154 + .data = &grsec_enable_execlog,
60155 + .maxlen = sizeof(int),
60156 + .mode = 0600,
60157 + .proc_handler = &proc_dointvec,
60158 + },
60159 +#endif
60160 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60161 + {
60162 + .ctl_name = CTL_UNNUMBERED,
60163 + .procname = "rwxmap_logging",
60164 + .data = &grsec_enable_log_rwxmaps,
60165 + .maxlen = sizeof(int),
60166 + .mode = 0600,
60167 + .proc_handler = &proc_dointvec,
60168 + },
60169 +#endif
60170 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60171 + {
60172 + .ctl_name = CTL_UNNUMBERED,
60173 + .procname = "signal_logging",
60174 + .data = &grsec_enable_signal,
60175 + .maxlen = sizeof(int),
60176 + .mode = 0600,
60177 + .proc_handler = &proc_dointvec,
60178 + },
60179 +#endif
60180 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60181 + {
60182 + .ctl_name = CTL_UNNUMBERED,
60183 + .procname = "forkfail_logging",
60184 + .data = &grsec_enable_forkfail,
60185 + .maxlen = sizeof(int),
60186 + .mode = 0600,
60187 + .proc_handler = &proc_dointvec,
60188 + },
60189 +#endif
60190 +#ifdef CONFIG_GRKERNSEC_TIME
60191 + {
60192 + .ctl_name = CTL_UNNUMBERED,
60193 + .procname = "timechange_logging",
60194 + .data = &grsec_enable_time,
60195 + .maxlen = sizeof(int),
60196 + .mode = 0600,
60197 + .proc_handler = &proc_dointvec,
60198 + },
60199 +#endif
60200 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60201 + {
60202 + .ctl_name = CTL_UNNUMBERED,
60203 + .procname = "chroot_deny_shmat",
60204 + .data = &grsec_enable_chroot_shmat,
60205 + .maxlen = sizeof(int),
60206 + .mode = 0600,
60207 + .proc_handler = &proc_dointvec,
60208 + },
60209 +#endif
60210 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60211 + {
60212 + .ctl_name = CTL_UNNUMBERED,
60213 + .procname = "chroot_deny_unix",
60214 + .data = &grsec_enable_chroot_unix,
60215 + .maxlen = sizeof(int),
60216 + .mode = 0600,
60217 + .proc_handler = &proc_dointvec,
60218 + },
60219 +#endif
60220 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60221 + {
60222 + .ctl_name = CTL_UNNUMBERED,
60223 + .procname = "chroot_deny_mount",
60224 + .data = &grsec_enable_chroot_mount,
60225 + .maxlen = sizeof(int),
60226 + .mode = 0600,
60227 + .proc_handler = &proc_dointvec,
60228 + },
60229 +#endif
60230 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60231 + {
60232 + .ctl_name = CTL_UNNUMBERED,
60233 + .procname = "chroot_deny_fchdir",
60234 + .data = &grsec_enable_chroot_fchdir,
60235 + .maxlen = sizeof(int),
60236 + .mode = 0600,
60237 + .proc_handler = &proc_dointvec,
60238 + },
60239 +#endif
60240 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60241 + {
60242 + .ctl_name = CTL_UNNUMBERED,
60243 + .procname = "chroot_deny_chroot",
60244 + .data = &grsec_enable_chroot_double,
60245 + .maxlen = sizeof(int),
60246 + .mode = 0600,
60247 + .proc_handler = &proc_dointvec,
60248 + },
60249 +#endif
60250 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60251 + {
60252 + .ctl_name = CTL_UNNUMBERED,
60253 + .procname = "chroot_deny_pivot",
60254 + .data = &grsec_enable_chroot_pivot,
60255 + .maxlen = sizeof(int),
60256 + .mode = 0600,
60257 + .proc_handler = &proc_dointvec,
60258 + },
60259 +#endif
60260 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60261 + {
60262 + .ctl_name = CTL_UNNUMBERED,
60263 + .procname = "chroot_enforce_chdir",
60264 + .data = &grsec_enable_chroot_chdir,
60265 + .maxlen = sizeof(int),
60266 + .mode = 0600,
60267 + .proc_handler = &proc_dointvec,
60268 + },
60269 +#endif
60270 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60271 + {
60272 + .ctl_name = CTL_UNNUMBERED,
60273 + .procname = "chroot_deny_chmod",
60274 + .data = &grsec_enable_chroot_chmod,
60275 + .maxlen = sizeof(int),
60276 + .mode = 0600,
60277 + .proc_handler = &proc_dointvec,
60278 + },
60279 +#endif
60280 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60281 + {
60282 + .ctl_name = CTL_UNNUMBERED,
60283 + .procname = "chroot_deny_mknod",
60284 + .data = &grsec_enable_chroot_mknod,
60285 + .maxlen = sizeof(int),
60286 + .mode = 0600,
60287 + .proc_handler = &proc_dointvec,
60288 + },
60289 +#endif
60290 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60291 + {
60292 + .ctl_name = CTL_UNNUMBERED,
60293 + .procname = "chroot_restrict_nice",
60294 + .data = &grsec_enable_chroot_nice,
60295 + .maxlen = sizeof(int),
60296 + .mode = 0600,
60297 + .proc_handler = &proc_dointvec,
60298 + },
60299 +#endif
60300 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60301 + {
60302 + .ctl_name = CTL_UNNUMBERED,
60303 + .procname = "chroot_execlog",
60304 + .data = &grsec_enable_chroot_execlog,
60305 + .maxlen = sizeof(int),
60306 + .mode = 0600,
60307 + .proc_handler = &proc_dointvec,
60308 + },
60309 +#endif
60310 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60311 + {
60312 + .ctl_name = CTL_UNNUMBERED,
60313 + .procname = "chroot_caps",
60314 + .data = &grsec_enable_chroot_caps,
60315 + .maxlen = sizeof(int),
60316 + .mode = 0600,
60317 + .proc_handler = &proc_dointvec,
60318 + },
60319 +#endif
60320 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60321 + {
60322 + .ctl_name = CTL_UNNUMBERED,
60323 + .procname = "chroot_deny_sysctl",
60324 + .data = &grsec_enable_chroot_sysctl,
60325 + .maxlen = sizeof(int),
60326 + .mode = 0600,
60327 + .proc_handler = &proc_dointvec,
60328 + },
60329 +#endif
60330 +#ifdef CONFIG_GRKERNSEC_TPE
60331 + {
60332 + .ctl_name = CTL_UNNUMBERED,
60333 + .procname = "tpe",
60334 + .data = &grsec_enable_tpe,
60335 + .maxlen = sizeof(int),
60336 + .mode = 0600,
60337 + .proc_handler = &proc_dointvec,
60338 + },
60339 + {
60340 + .ctl_name = CTL_UNNUMBERED,
60341 + .procname = "tpe_gid",
60342 + .data = &grsec_tpe_gid,
60343 + .maxlen = sizeof(int),
60344 + .mode = 0600,
60345 + .proc_handler = &proc_dointvec,
60346 + },
60347 +#endif
60348 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60349 + {
60350 + .ctl_name = CTL_UNNUMBERED,
60351 + .procname = "tpe_invert",
60352 + .data = &grsec_enable_tpe_invert,
60353 + .maxlen = sizeof(int),
60354 + .mode = 0600,
60355 + .proc_handler = &proc_dointvec,
60356 + },
60357 +#endif
60358 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60359 + {
60360 + .ctl_name = CTL_UNNUMBERED,
60361 + .procname = "tpe_restrict_all",
60362 + .data = &grsec_enable_tpe_all,
60363 + .maxlen = sizeof(int),
60364 + .mode = 0600,
60365 + .proc_handler = &proc_dointvec,
60366 + },
60367 +#endif
60368 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60369 + {
60370 + .ctl_name = CTL_UNNUMBERED,
60371 + .procname = "socket_all",
60372 + .data = &grsec_enable_socket_all,
60373 + .maxlen = sizeof(int),
60374 + .mode = 0600,
60375 + .proc_handler = &proc_dointvec,
60376 + },
60377 + {
60378 + .ctl_name = CTL_UNNUMBERED,
60379 + .procname = "socket_all_gid",
60380 + .data = &grsec_socket_all_gid,
60381 + .maxlen = sizeof(int),
60382 + .mode = 0600,
60383 + .proc_handler = &proc_dointvec,
60384 + },
60385 +#endif
60386 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60387 + {
60388 + .ctl_name = CTL_UNNUMBERED,
60389 + .procname = "socket_client",
60390 + .data = &grsec_enable_socket_client,
60391 + .maxlen = sizeof(int),
60392 + .mode = 0600,
60393 + .proc_handler = &proc_dointvec,
60394 + },
60395 + {
60396 + .ctl_name = CTL_UNNUMBERED,
60397 + .procname = "socket_client_gid",
60398 + .data = &grsec_socket_client_gid,
60399 + .maxlen = sizeof(int),
60400 + .mode = 0600,
60401 + .proc_handler = &proc_dointvec,
60402 + },
60403 +#endif
60404 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60405 + {
60406 + .ctl_name = CTL_UNNUMBERED,
60407 + .procname = "socket_server",
60408 + .data = &grsec_enable_socket_server,
60409 + .maxlen = sizeof(int),
60410 + .mode = 0600,
60411 + .proc_handler = &proc_dointvec,
60412 + },
60413 + {
60414 + .ctl_name = CTL_UNNUMBERED,
60415 + .procname = "socket_server_gid",
60416 + .data = &grsec_socket_server_gid,
60417 + .maxlen = sizeof(int),
60418 + .mode = 0600,
60419 + .proc_handler = &proc_dointvec,
60420 + },
60421 +#endif
60422 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60423 + {
60424 + .ctl_name = CTL_UNNUMBERED,
60425 + .procname = "audit_group",
60426 + .data = &grsec_enable_group,
60427 + .maxlen = sizeof(int),
60428 + .mode = 0600,
60429 + .proc_handler = &proc_dointvec,
60430 + },
60431 + {
60432 + .ctl_name = CTL_UNNUMBERED,
60433 + .procname = "audit_gid",
60434 + .data = &grsec_audit_gid,
60435 + .maxlen = sizeof(int),
60436 + .mode = 0600,
60437 + .proc_handler = &proc_dointvec,
60438 + },
60439 +#endif
60440 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60441 + {
60442 + .ctl_name = CTL_UNNUMBERED,
60443 + .procname = "audit_chdir",
60444 + .data = &grsec_enable_chdir,
60445 + .maxlen = sizeof(int),
60446 + .mode = 0600,
60447 + .proc_handler = &proc_dointvec,
60448 + },
60449 +#endif
60450 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60451 + {
60452 + .ctl_name = CTL_UNNUMBERED,
60453 + .procname = "audit_mount",
60454 + .data = &grsec_enable_mount,
60455 + .maxlen = sizeof(int),
60456 + .mode = 0600,
60457 + .proc_handler = &proc_dointvec,
60458 + },
60459 +#endif
60460 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60461 + {
60462 + .ctl_name = CTL_UNNUMBERED,
60463 + .procname = "audit_textrel",
60464 + .data = &grsec_enable_audit_textrel,
60465 + .maxlen = sizeof(int),
60466 + .mode = 0600,
60467 + .proc_handler = &proc_dointvec,
60468 + },
60469 +#endif
60470 +#ifdef CONFIG_GRKERNSEC_DMESG
60471 + {
60472 + .ctl_name = CTL_UNNUMBERED,
60473 + .procname = "dmesg",
60474 + .data = &grsec_enable_dmesg,
60475 + .maxlen = sizeof(int),
60476 + .mode = 0600,
60477 + .proc_handler = &proc_dointvec,
60478 + },
60479 +#endif
60480 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60481 + {
60482 + .ctl_name = CTL_UNNUMBERED,
60483 + .procname = "chroot_findtask",
60484 + .data = &grsec_enable_chroot_findtask,
60485 + .maxlen = sizeof(int),
60486 + .mode = 0600,
60487 + .proc_handler = &proc_dointvec,
60488 + },
60489 +#endif
60490 +#ifdef CONFIG_GRKERNSEC_RESLOG
60491 + {
60492 + .ctl_name = CTL_UNNUMBERED,
60493 + .procname = "resource_logging",
60494 + .data = &grsec_resource_logging,
60495 + .maxlen = sizeof(int),
60496 + .mode = 0600,
60497 + .proc_handler = &proc_dointvec,
60498 + },
60499 +#endif
60500 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60501 + {
60502 + .ctl_name = CTL_UNNUMBERED,
60503 + .procname = "audit_ptrace",
60504 + .data = &grsec_enable_audit_ptrace,
60505 + .maxlen = sizeof(int),
60506 + .mode = 0600,
60507 + .proc_handler = &proc_dointvec,
60508 + },
60509 +#endif
60510 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60511 + {
60512 + .ctl_name = CTL_UNNUMBERED,
60513 + .procname = "harden_ptrace",
60514 + .data = &grsec_enable_harden_ptrace,
60515 + .maxlen = sizeof(int),
60516 + .mode = 0600,
60517 + .proc_handler = &proc_dointvec,
60518 + },
60519 +#endif
60520 + {
60521 + .ctl_name = CTL_UNNUMBERED,
60522 + .procname = "grsec_lock",
60523 + .data = &grsec_lock,
60524 + .maxlen = sizeof(int),
60525 + .mode = 0600,
60526 + .proc_handler = &proc_dointvec,
60527 + },
60528 +#endif
60529 +#ifdef CONFIG_GRKERNSEC_ROFS
60530 + {
60531 + .ctl_name = CTL_UNNUMBERED,
60532 + .procname = "romount_protect",
60533 + .data = &grsec_enable_rofs,
60534 + .maxlen = sizeof(int),
60535 + .mode = 0600,
60536 + .proc_handler = &proc_dointvec_minmax,
60537 + .extra1 = &one,
60538 + .extra2 = &one,
60539 + },
60540 +#endif
60541 + { .ctl_name = 0 }
60542 +};
60543 +#endif
60544 diff -urNp linux-2.6.32.46/grsecurity/grsec_time.c linux-2.6.32.46/grsecurity/grsec_time.c
60545 --- linux-2.6.32.46/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
60546 +++ linux-2.6.32.46/grsecurity/grsec_time.c 2011-04-17 15:56:46.000000000 -0400
60547 @@ -0,0 +1,16 @@
60548 +#include <linux/kernel.h>
60549 +#include <linux/sched.h>
60550 +#include <linux/grinternal.h>
60551 +#include <linux/module.h>
60552 +
60553 +void
60554 +gr_log_timechange(void)
60555 +{
60556 +#ifdef CONFIG_GRKERNSEC_TIME
60557 + if (grsec_enable_time)
60558 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60559 +#endif
60560 + return;
60561 +}
60562 +
60563 +EXPORT_SYMBOL(gr_log_timechange);
60564 diff -urNp linux-2.6.32.46/grsecurity/grsec_tpe.c linux-2.6.32.46/grsecurity/grsec_tpe.c
60565 --- linux-2.6.32.46/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
60566 +++ linux-2.6.32.46/grsecurity/grsec_tpe.c 2011-04-17 15:56:46.000000000 -0400
60567 @@ -0,0 +1,39 @@
60568 +#include <linux/kernel.h>
60569 +#include <linux/sched.h>
60570 +#include <linux/file.h>
60571 +#include <linux/fs.h>
60572 +#include <linux/grinternal.h>
60573 +
60574 +extern int gr_acl_tpe_check(void);
60575 +
60576 +int
60577 +gr_tpe_allow(const struct file *file)
60578 +{
60579 +#ifdef CONFIG_GRKERNSEC
60580 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60581 + const struct cred *cred = current_cred();
60582 +
60583 + if (cred->uid && ((grsec_enable_tpe &&
60584 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60585 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
60586 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
60587 +#else
60588 + in_group_p(grsec_tpe_gid)
60589 +#endif
60590 + ) || gr_acl_tpe_check()) &&
60591 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
60592 + (inode->i_mode & S_IWOTH))))) {
60593 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
60594 + return 0;
60595 + }
60596 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60597 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
60598 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
60599 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
60600 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
60601 + return 0;
60602 + }
60603 +#endif
60604 +#endif
60605 + return 1;
60606 +}
60607 diff -urNp linux-2.6.32.46/grsecurity/grsum.c linux-2.6.32.46/grsecurity/grsum.c
60608 --- linux-2.6.32.46/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
60609 +++ linux-2.6.32.46/grsecurity/grsum.c 2011-04-17 15:56:46.000000000 -0400
60610 @@ -0,0 +1,61 @@
60611 +#include <linux/err.h>
60612 +#include <linux/kernel.h>
60613 +#include <linux/sched.h>
60614 +#include <linux/mm.h>
60615 +#include <linux/scatterlist.h>
60616 +#include <linux/crypto.h>
60617 +#include <linux/gracl.h>
60618 +
60619 +
60620 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60621 +#error "crypto and sha256 must be built into the kernel"
60622 +#endif
60623 +
60624 +int
60625 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60626 +{
60627 + char *p;
60628 + struct crypto_hash *tfm;
60629 + struct hash_desc desc;
60630 + struct scatterlist sg;
60631 + unsigned char temp_sum[GR_SHA_LEN];
60632 + volatile int retval = 0;
60633 + volatile int dummy = 0;
60634 + unsigned int i;
60635 +
60636 + sg_init_table(&sg, 1);
60637 +
60638 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60639 + if (IS_ERR(tfm)) {
60640 + /* should never happen, since sha256 should be built in */
60641 + return 1;
60642 + }
60643 +
60644 + desc.tfm = tfm;
60645 + desc.flags = 0;
60646 +
60647 + crypto_hash_init(&desc);
60648 +
60649 + p = salt;
60650 + sg_set_buf(&sg, p, GR_SALT_LEN);
60651 + crypto_hash_update(&desc, &sg, sg.length);
60652 +
60653 + p = entry->pw;
60654 + sg_set_buf(&sg, p, strlen(p));
60655 +
60656 + crypto_hash_update(&desc, &sg, sg.length);
60657 +
60658 + crypto_hash_final(&desc, temp_sum);
60659 +
60660 + memset(entry->pw, 0, GR_PW_LEN);
60661 +
60662 + for (i = 0; i < GR_SHA_LEN; i++)
60663 + if (sum[i] != temp_sum[i])
60664 + retval = 1;
60665 + else
60666 + dummy = 1; // waste a cycle
60667 +
60668 + crypto_free_hash(tfm);
60669 +
60670 + return retval;
60671 +}
60672 diff -urNp linux-2.6.32.46/include/acpi/acpi_bus.h linux-2.6.32.46/include/acpi/acpi_bus.h
60673 --- linux-2.6.32.46/include/acpi/acpi_bus.h 2011-03-27 14:31:47.000000000 -0400
60674 +++ linux-2.6.32.46/include/acpi/acpi_bus.h 2011-08-05 20:33:55.000000000 -0400
60675 @@ -107,7 +107,7 @@ struct acpi_device_ops {
60676 acpi_op_bind bind;
60677 acpi_op_unbind unbind;
60678 acpi_op_notify notify;
60679 -};
60680 +} __no_const;
60681
60682 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60683
60684 diff -urNp linux-2.6.32.46/include/acpi/acpi_drivers.h linux-2.6.32.46/include/acpi/acpi_drivers.h
60685 --- linux-2.6.32.46/include/acpi/acpi_drivers.h 2011-03-27 14:31:47.000000000 -0400
60686 +++ linux-2.6.32.46/include/acpi/acpi_drivers.h 2011-04-17 15:56:46.000000000 -0400
60687 @@ -119,8 +119,8 @@ int acpi_processor_set_thermal_limit(acp
60688 Dock Station
60689 -------------------------------------------------------------------------- */
60690 struct acpi_dock_ops {
60691 - acpi_notify_handler handler;
60692 - acpi_notify_handler uevent;
60693 + const acpi_notify_handler handler;
60694 + const acpi_notify_handler uevent;
60695 };
60696
60697 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
60698 @@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
60699 extern int register_dock_notifier(struct notifier_block *nb);
60700 extern void unregister_dock_notifier(struct notifier_block *nb);
60701 extern int register_hotplug_dock_device(acpi_handle handle,
60702 - struct acpi_dock_ops *ops,
60703 + const struct acpi_dock_ops *ops,
60704 void *context);
60705 extern void unregister_hotplug_dock_device(acpi_handle handle);
60706 #else
60707 @@ -144,7 +144,7 @@ static inline void unregister_dock_notif
60708 {
60709 }
60710 static inline int register_hotplug_dock_device(acpi_handle handle,
60711 - struct acpi_dock_ops *ops,
60712 + const struct acpi_dock_ops *ops,
60713 void *context)
60714 {
60715 return -ENODEV;
60716 diff -urNp linux-2.6.32.46/include/asm-generic/atomic-long.h linux-2.6.32.46/include/asm-generic/atomic-long.h
60717 --- linux-2.6.32.46/include/asm-generic/atomic-long.h 2011-03-27 14:31:47.000000000 -0400
60718 +++ linux-2.6.32.46/include/asm-generic/atomic-long.h 2011-07-13 22:21:25.000000000 -0400
60719 @@ -22,6 +22,12 @@
60720
60721 typedef atomic64_t atomic_long_t;
60722
60723 +#ifdef CONFIG_PAX_REFCOUNT
60724 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60725 +#else
60726 +typedef atomic64_t atomic_long_unchecked_t;
60727 +#endif
60728 +
60729 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60730
60731 static inline long atomic_long_read(atomic_long_t *l)
60732 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
60733 return (long)atomic64_read(v);
60734 }
60735
60736 +#ifdef CONFIG_PAX_REFCOUNT
60737 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60738 +{
60739 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60740 +
60741 + return (long)atomic64_read_unchecked(v);
60742 +}
60743 +#endif
60744 +
60745 static inline void atomic_long_set(atomic_long_t *l, long i)
60746 {
60747 atomic64_t *v = (atomic64_t *)l;
60748 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
60749 atomic64_set(v, i);
60750 }
60751
60752 +#ifdef CONFIG_PAX_REFCOUNT
60753 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60754 +{
60755 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60756 +
60757 + atomic64_set_unchecked(v, i);
60758 +}
60759 +#endif
60760 +
60761 static inline void atomic_long_inc(atomic_long_t *l)
60762 {
60763 atomic64_t *v = (atomic64_t *)l;
60764 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
60765 atomic64_inc(v);
60766 }
60767
60768 +#ifdef CONFIG_PAX_REFCOUNT
60769 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60770 +{
60771 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60772 +
60773 + atomic64_inc_unchecked(v);
60774 +}
60775 +#endif
60776 +
60777 static inline void atomic_long_dec(atomic_long_t *l)
60778 {
60779 atomic64_t *v = (atomic64_t *)l;
60780 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
60781 atomic64_dec(v);
60782 }
60783
60784 +#ifdef CONFIG_PAX_REFCOUNT
60785 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60786 +{
60787 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60788 +
60789 + atomic64_dec_unchecked(v);
60790 +}
60791 +#endif
60792 +
60793 static inline void atomic_long_add(long i, atomic_long_t *l)
60794 {
60795 atomic64_t *v = (atomic64_t *)l;
60796 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long
60797 atomic64_add(i, v);
60798 }
60799
60800 +#ifdef CONFIG_PAX_REFCOUNT
60801 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60802 +{
60803 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60804 +
60805 + atomic64_add_unchecked(i, v);
60806 +}
60807 +#endif
60808 +
60809 static inline void atomic_long_sub(long i, atomic_long_t *l)
60810 {
60811 atomic64_t *v = (atomic64_t *)l;
60812 @@ -115,6 +166,15 @@ static inline long atomic_long_inc_retur
60813 return (long)atomic64_inc_return(v);
60814 }
60815
60816 +#ifdef CONFIG_PAX_REFCOUNT
60817 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60818 +{
60819 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60820 +
60821 + return (long)atomic64_inc_return_unchecked(v);
60822 +}
60823 +#endif
60824 +
60825 static inline long atomic_long_dec_return(atomic_long_t *l)
60826 {
60827 atomic64_t *v = (atomic64_t *)l;
60828 @@ -140,6 +200,12 @@ static inline long atomic_long_add_unles
60829
60830 typedef atomic_t atomic_long_t;
60831
60832 +#ifdef CONFIG_PAX_REFCOUNT
60833 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60834 +#else
60835 +typedef atomic_t atomic_long_unchecked_t;
60836 +#endif
60837 +
60838 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60839 static inline long atomic_long_read(atomic_long_t *l)
60840 {
60841 @@ -148,6 +214,15 @@ static inline long atomic_long_read(atom
60842 return (long)atomic_read(v);
60843 }
60844
60845 +#ifdef CONFIG_PAX_REFCOUNT
60846 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60847 +{
60848 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60849 +
60850 + return (long)atomic_read_unchecked(v);
60851 +}
60852 +#endif
60853 +
60854 static inline void atomic_long_set(atomic_long_t *l, long i)
60855 {
60856 atomic_t *v = (atomic_t *)l;
60857 @@ -155,6 +230,15 @@ static inline void atomic_long_set(atomi
60858 atomic_set(v, i);
60859 }
60860
60861 +#ifdef CONFIG_PAX_REFCOUNT
60862 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60863 +{
60864 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60865 +
60866 + atomic_set_unchecked(v, i);
60867 +}
60868 +#endif
60869 +
60870 static inline void atomic_long_inc(atomic_long_t *l)
60871 {
60872 atomic_t *v = (atomic_t *)l;
60873 @@ -162,6 +246,15 @@ static inline void atomic_long_inc(atomi
60874 atomic_inc(v);
60875 }
60876
60877 +#ifdef CONFIG_PAX_REFCOUNT
60878 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60879 +{
60880 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60881 +
60882 + atomic_inc_unchecked(v);
60883 +}
60884 +#endif
60885 +
60886 static inline void atomic_long_dec(atomic_long_t *l)
60887 {
60888 atomic_t *v = (atomic_t *)l;
60889 @@ -169,6 +262,15 @@ static inline void atomic_long_dec(atomi
60890 atomic_dec(v);
60891 }
60892
60893 +#ifdef CONFIG_PAX_REFCOUNT
60894 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60895 +{
60896 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60897 +
60898 + atomic_dec_unchecked(v);
60899 +}
60900 +#endif
60901 +
60902 static inline void atomic_long_add(long i, atomic_long_t *l)
60903 {
60904 atomic_t *v = (atomic_t *)l;
60905 @@ -176,6 +278,15 @@ static inline void atomic_long_add(long
60906 atomic_add(i, v);
60907 }
60908
60909 +#ifdef CONFIG_PAX_REFCOUNT
60910 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60911 +{
60912 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60913 +
60914 + atomic_add_unchecked(i, v);
60915 +}
60916 +#endif
60917 +
60918 static inline void atomic_long_sub(long i, atomic_long_t *l)
60919 {
60920 atomic_t *v = (atomic_t *)l;
60921 @@ -232,6 +343,15 @@ static inline long atomic_long_inc_retur
60922 return (long)atomic_inc_return(v);
60923 }
60924
60925 +#ifdef CONFIG_PAX_REFCOUNT
60926 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60927 +{
60928 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60929 +
60930 + return (long)atomic_inc_return_unchecked(v);
60931 +}
60932 +#endif
60933 +
60934 static inline long atomic_long_dec_return(atomic_long_t *l)
60935 {
60936 atomic_t *v = (atomic_t *)l;
60937 @@ -255,4 +375,47 @@ static inline long atomic_long_add_unles
60938
60939 #endif /* BITS_PER_LONG == 64 */
60940
60941 +#ifdef CONFIG_PAX_REFCOUNT
60942 +static inline void pax_refcount_needs_these_functions(void)
60943 +{
60944 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60945 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60946 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60947 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60948 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60949 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60950 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60951 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60952 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60953 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60954 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60955 +
60956 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60957 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60958 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60959 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60960 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60961 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60962 +}
60963 +#else
60964 +#define atomic_read_unchecked(v) atomic_read(v)
60965 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60966 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60967 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60968 +#define atomic_inc_unchecked(v) atomic_inc(v)
60969 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60970 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60971 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60972 +#define atomic_dec_unchecked(v) atomic_dec(v)
60973 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60974 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60975 +
60976 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60977 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60978 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60979 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60980 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60981 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60982 +#endif
60983 +
60984 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60985 diff -urNp linux-2.6.32.46/include/asm-generic/bug.h linux-2.6.32.46/include/asm-generic/bug.h
60986 --- linux-2.6.32.46/include/asm-generic/bug.h 2011-07-13 17:23:04.000000000 -0400
60987 +++ linux-2.6.32.46/include/asm-generic/bug.h 2011-08-21 17:56:07.000000000 -0400
60988 @@ -105,11 +105,11 @@ extern void warn_slowpath_null(const cha
60989
60990 #else /* !CONFIG_BUG */
60991 #ifndef HAVE_ARCH_BUG
60992 -#define BUG() do {} while(0)
60993 +#define BUG() do { for (;;) ; } while(0)
60994 #endif
60995
60996 #ifndef HAVE_ARCH_BUG_ON
60997 -#define BUG_ON(condition) do { if (condition) ; } while(0)
60998 +#define BUG_ON(condition) do { if (condition) for (;;) ; } while(0)
60999 #endif
61000
61001 #ifndef HAVE_ARCH_WARN_ON
61002 diff -urNp linux-2.6.32.46/include/asm-generic/cache.h linux-2.6.32.46/include/asm-generic/cache.h
61003 --- linux-2.6.32.46/include/asm-generic/cache.h 2011-03-27 14:31:47.000000000 -0400
61004 +++ linux-2.6.32.46/include/asm-generic/cache.h 2011-07-06 19:53:33.000000000 -0400
61005 @@ -6,7 +6,7 @@
61006 * cache lines need to provide their own cache.h.
61007 */
61008
61009 -#define L1_CACHE_SHIFT 5
61010 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61011 +#define L1_CACHE_SHIFT 5UL
61012 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
61013
61014 #endif /* __ASM_GENERIC_CACHE_H */
61015 diff -urNp linux-2.6.32.46/include/asm-generic/dma-mapping-common.h linux-2.6.32.46/include/asm-generic/dma-mapping-common.h
61016 --- linux-2.6.32.46/include/asm-generic/dma-mapping-common.h 2011-03-27 14:31:47.000000000 -0400
61017 +++ linux-2.6.32.46/include/asm-generic/dma-mapping-common.h 2011-04-17 15:56:46.000000000 -0400
61018 @@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
61019 enum dma_data_direction dir,
61020 struct dma_attrs *attrs)
61021 {
61022 - struct dma_map_ops *ops = get_dma_ops(dev);
61023 + const struct dma_map_ops *ops = get_dma_ops(dev);
61024 dma_addr_t addr;
61025
61026 kmemcheck_mark_initialized(ptr, size);
61027 @@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
61028 enum dma_data_direction dir,
61029 struct dma_attrs *attrs)
61030 {
61031 - struct dma_map_ops *ops = get_dma_ops(dev);
61032 + const struct dma_map_ops *ops = get_dma_ops(dev);
61033
61034 BUG_ON(!valid_dma_direction(dir));
61035 if (ops->unmap_page)
61036 @@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
61037 int nents, enum dma_data_direction dir,
61038 struct dma_attrs *attrs)
61039 {
61040 - struct dma_map_ops *ops = get_dma_ops(dev);
61041 + const struct dma_map_ops *ops = get_dma_ops(dev);
61042 int i, ents;
61043 struct scatterlist *s;
61044
61045 @@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
61046 int nents, enum dma_data_direction dir,
61047 struct dma_attrs *attrs)
61048 {
61049 - struct dma_map_ops *ops = get_dma_ops(dev);
61050 + const struct dma_map_ops *ops = get_dma_ops(dev);
61051
61052 BUG_ON(!valid_dma_direction(dir));
61053 debug_dma_unmap_sg(dev, sg, nents, dir);
61054 @@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
61055 size_t offset, size_t size,
61056 enum dma_data_direction dir)
61057 {
61058 - struct dma_map_ops *ops = get_dma_ops(dev);
61059 + const struct dma_map_ops *ops = get_dma_ops(dev);
61060 dma_addr_t addr;
61061
61062 kmemcheck_mark_initialized(page_address(page) + offset, size);
61063 @@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
61064 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
61065 size_t size, enum dma_data_direction dir)
61066 {
61067 - struct dma_map_ops *ops = get_dma_ops(dev);
61068 + const struct dma_map_ops *ops = get_dma_ops(dev);
61069
61070 BUG_ON(!valid_dma_direction(dir));
61071 if (ops->unmap_page)
61072 @@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
61073 size_t size,
61074 enum dma_data_direction dir)
61075 {
61076 - struct dma_map_ops *ops = get_dma_ops(dev);
61077 + const struct dma_map_ops *ops = get_dma_ops(dev);
61078
61079 BUG_ON(!valid_dma_direction(dir));
61080 if (ops->sync_single_for_cpu)
61081 @@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
61082 dma_addr_t addr, size_t size,
61083 enum dma_data_direction dir)
61084 {
61085 - struct dma_map_ops *ops = get_dma_ops(dev);
61086 + const struct dma_map_ops *ops = get_dma_ops(dev);
61087
61088 BUG_ON(!valid_dma_direction(dir));
61089 if (ops->sync_single_for_device)
61090 @@ -123,7 +123,7 @@ static inline void dma_sync_single_range
61091 size_t size,
61092 enum dma_data_direction dir)
61093 {
61094 - struct dma_map_ops *ops = get_dma_ops(dev);
61095 + const struct dma_map_ops *ops = get_dma_ops(dev);
61096
61097 BUG_ON(!valid_dma_direction(dir));
61098 if (ops->sync_single_range_for_cpu) {
61099 @@ -140,7 +140,7 @@ static inline void dma_sync_single_range
61100 size_t size,
61101 enum dma_data_direction dir)
61102 {
61103 - struct dma_map_ops *ops = get_dma_ops(dev);
61104 + const struct dma_map_ops *ops = get_dma_ops(dev);
61105
61106 BUG_ON(!valid_dma_direction(dir));
61107 if (ops->sync_single_range_for_device) {
61108 @@ -155,7 +155,7 @@ static inline void
61109 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
61110 int nelems, enum dma_data_direction dir)
61111 {
61112 - struct dma_map_ops *ops = get_dma_ops(dev);
61113 + const struct dma_map_ops *ops = get_dma_ops(dev);
61114
61115 BUG_ON(!valid_dma_direction(dir));
61116 if (ops->sync_sg_for_cpu)
61117 @@ -167,7 +167,7 @@ static inline void
61118 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
61119 int nelems, enum dma_data_direction dir)
61120 {
61121 - struct dma_map_ops *ops = get_dma_ops(dev);
61122 + const struct dma_map_ops *ops = get_dma_ops(dev);
61123
61124 BUG_ON(!valid_dma_direction(dir));
61125 if (ops->sync_sg_for_device)
61126 diff -urNp linux-2.6.32.46/include/asm-generic/emergency-restart.h linux-2.6.32.46/include/asm-generic/emergency-restart.h
61127 --- linux-2.6.32.46/include/asm-generic/emergency-restart.h 2011-03-27 14:31:47.000000000 -0400
61128 +++ linux-2.6.32.46/include/asm-generic/emergency-restart.h 2011-08-21 19:17:17.000000000 -0400
61129 @@ -1,7 +1,7 @@
61130 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
61131 #define _ASM_GENERIC_EMERGENCY_RESTART_H
61132
61133 -static inline void machine_emergency_restart(void)
61134 +static inline __noreturn void machine_emergency_restart(void)
61135 {
61136 machine_restart(NULL);
61137 }
61138 diff -urNp linux-2.6.32.46/include/asm-generic/futex.h linux-2.6.32.46/include/asm-generic/futex.h
61139 --- linux-2.6.32.46/include/asm-generic/futex.h 2011-03-27 14:31:47.000000000 -0400
61140 +++ linux-2.6.32.46/include/asm-generic/futex.h 2011-04-17 15:56:46.000000000 -0400
61141 @@ -6,7 +6,7 @@
61142 #include <asm/errno.h>
61143
61144 static inline int
61145 -futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
61146 +futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
61147 {
61148 int op = (encoded_op >> 28) & 7;
61149 int cmp = (encoded_op >> 24) & 15;
61150 @@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
61151 }
61152
61153 static inline int
61154 -futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
61155 +futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
61156 {
61157 return -ENOSYS;
61158 }
61159 diff -urNp linux-2.6.32.46/include/asm-generic/int-l64.h linux-2.6.32.46/include/asm-generic/int-l64.h
61160 --- linux-2.6.32.46/include/asm-generic/int-l64.h 2011-03-27 14:31:47.000000000 -0400
61161 +++ linux-2.6.32.46/include/asm-generic/int-l64.h 2011-04-17 15:56:46.000000000 -0400
61162 @@ -46,6 +46,8 @@ typedef unsigned int u32;
61163 typedef signed long s64;
61164 typedef unsigned long u64;
61165
61166 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
61167 +
61168 #define S8_C(x) x
61169 #define U8_C(x) x ## U
61170 #define S16_C(x) x
61171 diff -urNp linux-2.6.32.46/include/asm-generic/int-ll64.h linux-2.6.32.46/include/asm-generic/int-ll64.h
61172 --- linux-2.6.32.46/include/asm-generic/int-ll64.h 2011-03-27 14:31:47.000000000 -0400
61173 +++ linux-2.6.32.46/include/asm-generic/int-ll64.h 2011-04-17 15:56:46.000000000 -0400
61174 @@ -51,6 +51,8 @@ typedef unsigned int u32;
61175 typedef signed long long s64;
61176 typedef unsigned long long u64;
61177
61178 +typedef unsigned long long intoverflow_t;
61179 +
61180 #define S8_C(x) x
61181 #define U8_C(x) x ## U
61182 #define S16_C(x) x
61183 diff -urNp linux-2.6.32.46/include/asm-generic/kmap_types.h linux-2.6.32.46/include/asm-generic/kmap_types.h
61184 --- linux-2.6.32.46/include/asm-generic/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
61185 +++ linux-2.6.32.46/include/asm-generic/kmap_types.h 2011-04-17 15:56:46.000000000 -0400
61186 @@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY,
61187 KMAP_D(16) KM_IRQ_PTE,
61188 KMAP_D(17) KM_NMI,
61189 KMAP_D(18) KM_NMI_PTE,
61190 -KMAP_D(19) KM_TYPE_NR
61191 +KMAP_D(19) KM_CLEARPAGE,
61192 +KMAP_D(20) KM_TYPE_NR
61193 };
61194
61195 #undef KMAP_D
61196 diff -urNp linux-2.6.32.46/include/asm-generic/pgtable-nopmd.h linux-2.6.32.46/include/asm-generic/pgtable-nopmd.h
61197 --- linux-2.6.32.46/include/asm-generic/pgtable-nopmd.h 2011-03-27 14:31:47.000000000 -0400
61198 +++ linux-2.6.32.46/include/asm-generic/pgtable-nopmd.h 2011-04-17 15:56:46.000000000 -0400
61199 @@ -1,14 +1,19 @@
61200 #ifndef _PGTABLE_NOPMD_H
61201 #define _PGTABLE_NOPMD_H
61202
61203 -#ifndef __ASSEMBLY__
61204 -
61205 #include <asm-generic/pgtable-nopud.h>
61206
61207 -struct mm_struct;
61208 -
61209 #define __PAGETABLE_PMD_FOLDED
61210
61211 +#define PMD_SHIFT PUD_SHIFT
61212 +#define PTRS_PER_PMD 1
61213 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61214 +#define PMD_MASK (~(PMD_SIZE-1))
61215 +
61216 +#ifndef __ASSEMBLY__
61217 +
61218 +struct mm_struct;
61219 +
61220 /*
61221 * Having the pmd type consist of a pud gets the size right, and allows
61222 * us to conceptually access the pud entry that this pmd is folded into
61223 @@ -16,11 +21,6 @@ struct mm_struct;
61224 */
61225 typedef struct { pud_t pud; } pmd_t;
61226
61227 -#define PMD_SHIFT PUD_SHIFT
61228 -#define PTRS_PER_PMD 1
61229 -#define PMD_SIZE (1UL << PMD_SHIFT)
61230 -#define PMD_MASK (~(PMD_SIZE-1))
61231 -
61232 /*
61233 * The "pud_xxx()" functions here are trivial for a folded two-level
61234 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61235 diff -urNp linux-2.6.32.46/include/asm-generic/pgtable-nopud.h linux-2.6.32.46/include/asm-generic/pgtable-nopud.h
61236 --- linux-2.6.32.46/include/asm-generic/pgtable-nopud.h 2011-03-27 14:31:47.000000000 -0400
61237 +++ linux-2.6.32.46/include/asm-generic/pgtable-nopud.h 2011-04-17 15:56:46.000000000 -0400
61238 @@ -1,10 +1,15 @@
61239 #ifndef _PGTABLE_NOPUD_H
61240 #define _PGTABLE_NOPUD_H
61241
61242 -#ifndef __ASSEMBLY__
61243 -
61244 #define __PAGETABLE_PUD_FOLDED
61245
61246 +#define PUD_SHIFT PGDIR_SHIFT
61247 +#define PTRS_PER_PUD 1
61248 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61249 +#define PUD_MASK (~(PUD_SIZE-1))
61250 +
61251 +#ifndef __ASSEMBLY__
61252 +
61253 /*
61254 * Having the pud type consist of a pgd gets the size right, and allows
61255 * us to conceptually access the pgd entry that this pud is folded into
61256 @@ -12,11 +17,6 @@
61257 */
61258 typedef struct { pgd_t pgd; } pud_t;
61259
61260 -#define PUD_SHIFT PGDIR_SHIFT
61261 -#define PTRS_PER_PUD 1
61262 -#define PUD_SIZE (1UL << PUD_SHIFT)
61263 -#define PUD_MASK (~(PUD_SIZE-1))
61264 -
61265 /*
61266 * The "pgd_xxx()" functions here are trivial for a folded two-level
61267 * setup: the pud is never bad, and a pud always exists (as it's folded
61268 diff -urNp linux-2.6.32.46/include/asm-generic/pgtable.h linux-2.6.32.46/include/asm-generic/pgtable.h
61269 --- linux-2.6.32.46/include/asm-generic/pgtable.h 2011-03-27 14:31:47.000000000 -0400
61270 +++ linux-2.6.32.46/include/asm-generic/pgtable.h 2011-04-17 15:56:46.000000000 -0400
61271 @@ -344,6 +344,14 @@ extern void untrack_pfn_vma(struct vm_ar
61272 unsigned long size);
61273 #endif
61274
61275 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61276 +static inline unsigned long pax_open_kernel(void) { return 0; }
61277 +#endif
61278 +
61279 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61280 +static inline unsigned long pax_close_kernel(void) { return 0; }
61281 +#endif
61282 +
61283 #endif /* !__ASSEMBLY__ */
61284
61285 #endif /* _ASM_GENERIC_PGTABLE_H */
61286 diff -urNp linux-2.6.32.46/include/asm-generic/vmlinux.lds.h linux-2.6.32.46/include/asm-generic/vmlinux.lds.h
61287 --- linux-2.6.32.46/include/asm-generic/vmlinux.lds.h 2011-03-27 14:31:47.000000000 -0400
61288 +++ linux-2.6.32.46/include/asm-generic/vmlinux.lds.h 2011-04-17 15:56:46.000000000 -0400
61289 @@ -199,6 +199,7 @@
61290 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61291 VMLINUX_SYMBOL(__start_rodata) = .; \
61292 *(.rodata) *(.rodata.*) \
61293 + *(.data.read_only) \
61294 *(__vermagic) /* Kernel version magic */ \
61295 *(__markers_strings) /* Markers: strings */ \
61296 *(__tracepoints_strings)/* Tracepoints: strings */ \
61297 @@ -656,22 +657,24 @@
61298 * section in the linker script will go there too. @phdr should have
61299 * a leading colon.
61300 *
61301 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61302 + * Note that this macros defines per_cpu_load as an absolute symbol.
61303 * If there is no need to put the percpu section at a predetermined
61304 * address, use PERCPU().
61305 */
61306 #define PERCPU_VADDR(vaddr, phdr) \
61307 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61308 - .data.percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61309 + per_cpu_load = .; \
61310 + .data.percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61311 - LOAD_OFFSET) { \
61312 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61313 VMLINUX_SYMBOL(__per_cpu_start) = .; \
61314 *(.data.percpu.first) \
61315 - *(.data.percpu.page_aligned) \
61316 *(.data.percpu) \
61317 + . = ALIGN(PAGE_SIZE); \
61318 + *(.data.percpu.page_aligned) \
61319 *(.data.percpu.shared_aligned) \
61320 VMLINUX_SYMBOL(__per_cpu_end) = .; \
61321 } phdr \
61322 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data.percpu);
61323 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data.percpu);
61324
61325 /**
61326 * PERCPU - define output section for percpu area, simple version
61327 diff -urNp linux-2.6.32.46/include/drm/drmP.h linux-2.6.32.46/include/drm/drmP.h
61328 --- linux-2.6.32.46/include/drm/drmP.h 2011-03-27 14:31:47.000000000 -0400
61329 +++ linux-2.6.32.46/include/drm/drmP.h 2011-04-17 15:56:46.000000000 -0400
61330 @@ -71,6 +71,7 @@
61331 #include <linux/workqueue.h>
61332 #include <linux/poll.h>
61333 #include <asm/pgalloc.h>
61334 +#include <asm/local.h>
61335 #include "drm.h"
61336
61337 #include <linux/idr.h>
61338 @@ -814,7 +815,7 @@ struct drm_driver {
61339 void (*vgaarb_irq)(struct drm_device *dev, bool state);
61340
61341 /* Driver private ops for this object */
61342 - struct vm_operations_struct *gem_vm_ops;
61343 + const struct vm_operations_struct *gem_vm_ops;
61344
61345 int major;
61346 int minor;
61347 @@ -917,7 +918,7 @@ struct drm_device {
61348
61349 /** \name Usage Counters */
61350 /*@{ */
61351 - int open_count; /**< Outstanding files open */
61352 + local_t open_count; /**< Outstanding files open */
61353 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61354 atomic_t vma_count; /**< Outstanding vma areas open */
61355 int buf_use; /**< Buffers in use -- cannot alloc */
61356 @@ -928,7 +929,7 @@ struct drm_device {
61357 /*@{ */
61358 unsigned long counters;
61359 enum drm_stat_type types[15];
61360 - atomic_t counts[15];
61361 + atomic_unchecked_t counts[15];
61362 /*@} */
61363
61364 struct list_head filelist;
61365 @@ -1016,7 +1017,7 @@ struct drm_device {
61366 struct pci_controller *hose;
61367 #endif
61368 struct drm_sg_mem *sg; /**< Scatter gather memory */
61369 - unsigned int num_crtcs; /**< Number of CRTCs on this device */
61370 + unsigned int num_crtcs; /**< Number of CRTCs on this device */
61371 void *dev_private; /**< device private data */
61372 void *mm_private;
61373 struct address_space *dev_mapping;
61374 @@ -1042,11 +1043,11 @@ struct drm_device {
61375 spinlock_t object_name_lock;
61376 struct idr object_name_idr;
61377 atomic_t object_count;
61378 - atomic_t object_memory;
61379 + atomic_unchecked_t object_memory;
61380 atomic_t pin_count;
61381 - atomic_t pin_memory;
61382 + atomic_unchecked_t pin_memory;
61383 atomic_t gtt_count;
61384 - atomic_t gtt_memory;
61385 + atomic_unchecked_t gtt_memory;
61386 uint32_t gtt_total;
61387 uint32_t invalidate_domains; /* domains pending invalidation */
61388 uint32_t flush_domains; /* domains pending flush */
61389 diff -urNp linux-2.6.32.46/include/drm/drm_crtc_helper.h linux-2.6.32.46/include/drm/drm_crtc_helper.h
61390 --- linux-2.6.32.46/include/drm/drm_crtc_helper.h 2011-03-27 14:31:47.000000000 -0400
61391 +++ linux-2.6.32.46/include/drm/drm_crtc_helper.h 2011-08-05 20:33:55.000000000 -0400
61392 @@ -64,7 +64,7 @@ struct drm_crtc_helper_funcs {
61393
61394 /* reload the current crtc LUT */
61395 void (*load_lut)(struct drm_crtc *crtc);
61396 -};
61397 +} __no_const;
61398
61399 struct drm_encoder_helper_funcs {
61400 void (*dpms)(struct drm_encoder *encoder, int mode);
61401 @@ -85,7 +85,7 @@ struct drm_encoder_helper_funcs {
61402 struct drm_connector *connector);
61403 /* disable encoder when not in use - more explicit than dpms off */
61404 void (*disable)(struct drm_encoder *encoder);
61405 -};
61406 +} __no_const;
61407
61408 struct drm_connector_helper_funcs {
61409 int (*get_modes)(struct drm_connector *connector);
61410 diff -urNp linux-2.6.32.46/include/drm/ttm/ttm_memory.h linux-2.6.32.46/include/drm/ttm/ttm_memory.h
61411 --- linux-2.6.32.46/include/drm/ttm/ttm_memory.h 2011-03-27 14:31:47.000000000 -0400
61412 +++ linux-2.6.32.46/include/drm/ttm/ttm_memory.h 2011-08-05 20:33:55.000000000 -0400
61413 @@ -47,7 +47,7 @@
61414
61415 struct ttm_mem_shrink {
61416 int (*do_shrink) (struct ttm_mem_shrink *);
61417 -};
61418 +} __no_const;
61419
61420 /**
61421 * struct ttm_mem_global - Global memory accounting structure.
61422 diff -urNp linux-2.6.32.46/include/linux/a.out.h linux-2.6.32.46/include/linux/a.out.h
61423 --- linux-2.6.32.46/include/linux/a.out.h 2011-03-27 14:31:47.000000000 -0400
61424 +++ linux-2.6.32.46/include/linux/a.out.h 2011-04-17 15:56:46.000000000 -0400
61425 @@ -39,6 +39,14 @@ enum machine_type {
61426 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61427 };
61428
61429 +/* Constants for the N_FLAGS field */
61430 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61431 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61432 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61433 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61434 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61435 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61436 +
61437 #if !defined (N_MAGIC)
61438 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61439 #endif
61440 diff -urNp linux-2.6.32.46/include/linux/atmdev.h linux-2.6.32.46/include/linux/atmdev.h
61441 --- linux-2.6.32.46/include/linux/atmdev.h 2011-03-27 14:31:47.000000000 -0400
61442 +++ linux-2.6.32.46/include/linux/atmdev.h 2011-04-17 15:56:46.000000000 -0400
61443 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61444 #endif
61445
61446 struct k_atm_aal_stats {
61447 -#define __HANDLE_ITEM(i) atomic_t i
61448 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61449 __AAL_STAT_ITEMS
61450 #undef __HANDLE_ITEM
61451 };
61452 diff -urNp linux-2.6.32.46/include/linux/backlight.h linux-2.6.32.46/include/linux/backlight.h
61453 --- linux-2.6.32.46/include/linux/backlight.h 2011-03-27 14:31:47.000000000 -0400
61454 +++ linux-2.6.32.46/include/linux/backlight.h 2011-04-17 15:56:46.000000000 -0400
61455 @@ -36,18 +36,18 @@ struct backlight_device;
61456 struct fb_info;
61457
61458 struct backlight_ops {
61459 - unsigned int options;
61460 + const unsigned int options;
61461
61462 #define BL_CORE_SUSPENDRESUME (1 << 0)
61463
61464 /* Notify the backlight driver some property has changed */
61465 - int (*update_status)(struct backlight_device *);
61466 + int (* const update_status)(struct backlight_device *);
61467 /* Return the current backlight brightness (accounting for power,
61468 fb_blank etc.) */
61469 - int (*get_brightness)(struct backlight_device *);
61470 + int (* const get_brightness)(struct backlight_device *);
61471 /* Check if given framebuffer device is the one bound to this backlight;
61472 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
61473 - int (*check_fb)(struct fb_info *);
61474 + int (* const check_fb)(struct fb_info *);
61475 };
61476
61477 /* This structure defines all the properties of a backlight */
61478 @@ -86,7 +86,7 @@ struct backlight_device {
61479 registered this device has been unloaded, and if class_get_devdata()
61480 points to something in the body of that driver, it is also invalid. */
61481 struct mutex ops_lock;
61482 - struct backlight_ops *ops;
61483 + const struct backlight_ops *ops;
61484
61485 /* The framebuffer notifier block */
61486 struct notifier_block fb_notif;
61487 @@ -103,7 +103,7 @@ static inline void backlight_update_stat
61488 }
61489
61490 extern struct backlight_device *backlight_device_register(const char *name,
61491 - struct device *dev, void *devdata, struct backlight_ops *ops);
61492 + struct device *dev, void *devdata, const struct backlight_ops *ops);
61493 extern void backlight_device_unregister(struct backlight_device *bd);
61494 extern void backlight_force_update(struct backlight_device *bd,
61495 enum backlight_update_reason reason);
61496 diff -urNp linux-2.6.32.46/include/linux/binfmts.h linux-2.6.32.46/include/linux/binfmts.h
61497 --- linux-2.6.32.46/include/linux/binfmts.h 2011-04-17 17:00:52.000000000 -0400
61498 +++ linux-2.6.32.46/include/linux/binfmts.h 2011-04-17 15:56:46.000000000 -0400
61499 @@ -83,6 +83,7 @@ struct linux_binfmt {
61500 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61501 int (*load_shlib)(struct file *);
61502 int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
61503 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61504 unsigned long min_coredump; /* minimal dump size */
61505 int hasvdso;
61506 };
61507 diff -urNp linux-2.6.32.46/include/linux/blkdev.h linux-2.6.32.46/include/linux/blkdev.h
61508 --- linux-2.6.32.46/include/linux/blkdev.h 2011-03-27 14:31:47.000000000 -0400
61509 +++ linux-2.6.32.46/include/linux/blkdev.h 2011-08-26 20:27:21.000000000 -0400
61510 @@ -1278,7 +1278,7 @@ struct block_device_operations {
61511 int (*revalidate_disk) (struct gendisk *);
61512 int (*getgeo)(struct block_device *, struct hd_geometry *);
61513 struct module *owner;
61514 -};
61515 +} __do_const;
61516
61517 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61518 unsigned long);
61519 diff -urNp linux-2.6.32.46/include/linux/blktrace_api.h linux-2.6.32.46/include/linux/blktrace_api.h
61520 --- linux-2.6.32.46/include/linux/blktrace_api.h 2011-03-27 14:31:47.000000000 -0400
61521 +++ linux-2.6.32.46/include/linux/blktrace_api.h 2011-05-04 17:56:28.000000000 -0400
61522 @@ -160,7 +160,7 @@ struct blk_trace {
61523 struct dentry *dir;
61524 struct dentry *dropped_file;
61525 struct dentry *msg_file;
61526 - atomic_t dropped;
61527 + atomic_unchecked_t dropped;
61528 };
61529
61530 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61531 diff -urNp linux-2.6.32.46/include/linux/byteorder/little_endian.h linux-2.6.32.46/include/linux/byteorder/little_endian.h
61532 --- linux-2.6.32.46/include/linux/byteorder/little_endian.h 2011-03-27 14:31:47.000000000 -0400
61533 +++ linux-2.6.32.46/include/linux/byteorder/little_endian.h 2011-04-17 15:56:46.000000000 -0400
61534 @@ -42,51 +42,51 @@
61535
61536 static inline __le64 __cpu_to_le64p(const __u64 *p)
61537 {
61538 - return (__force __le64)*p;
61539 + return (__force const __le64)*p;
61540 }
61541 static inline __u64 __le64_to_cpup(const __le64 *p)
61542 {
61543 - return (__force __u64)*p;
61544 + return (__force const __u64)*p;
61545 }
61546 static inline __le32 __cpu_to_le32p(const __u32 *p)
61547 {
61548 - return (__force __le32)*p;
61549 + return (__force const __le32)*p;
61550 }
61551 static inline __u32 __le32_to_cpup(const __le32 *p)
61552 {
61553 - return (__force __u32)*p;
61554 + return (__force const __u32)*p;
61555 }
61556 static inline __le16 __cpu_to_le16p(const __u16 *p)
61557 {
61558 - return (__force __le16)*p;
61559 + return (__force const __le16)*p;
61560 }
61561 static inline __u16 __le16_to_cpup(const __le16 *p)
61562 {
61563 - return (__force __u16)*p;
61564 + return (__force const __u16)*p;
61565 }
61566 static inline __be64 __cpu_to_be64p(const __u64 *p)
61567 {
61568 - return (__force __be64)__swab64p(p);
61569 + return (__force const __be64)__swab64p(p);
61570 }
61571 static inline __u64 __be64_to_cpup(const __be64 *p)
61572 {
61573 - return __swab64p((__u64 *)p);
61574 + return __swab64p((const __u64 *)p);
61575 }
61576 static inline __be32 __cpu_to_be32p(const __u32 *p)
61577 {
61578 - return (__force __be32)__swab32p(p);
61579 + return (__force const __be32)__swab32p(p);
61580 }
61581 static inline __u32 __be32_to_cpup(const __be32 *p)
61582 {
61583 - return __swab32p((__u32 *)p);
61584 + return __swab32p((const __u32 *)p);
61585 }
61586 static inline __be16 __cpu_to_be16p(const __u16 *p)
61587 {
61588 - return (__force __be16)__swab16p(p);
61589 + return (__force const __be16)__swab16p(p);
61590 }
61591 static inline __u16 __be16_to_cpup(const __be16 *p)
61592 {
61593 - return __swab16p((__u16 *)p);
61594 + return __swab16p((const __u16 *)p);
61595 }
61596 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61597 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61598 diff -urNp linux-2.6.32.46/include/linux/cache.h linux-2.6.32.46/include/linux/cache.h
61599 --- linux-2.6.32.46/include/linux/cache.h 2011-03-27 14:31:47.000000000 -0400
61600 +++ linux-2.6.32.46/include/linux/cache.h 2011-04-17 15:56:46.000000000 -0400
61601 @@ -16,6 +16,10 @@
61602 #define __read_mostly
61603 #endif
61604
61605 +#ifndef __read_only
61606 +#define __read_only __read_mostly
61607 +#endif
61608 +
61609 #ifndef ____cacheline_aligned
61610 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61611 #endif
61612 diff -urNp linux-2.6.32.46/include/linux/capability.h linux-2.6.32.46/include/linux/capability.h
61613 --- linux-2.6.32.46/include/linux/capability.h 2011-03-27 14:31:47.000000000 -0400
61614 +++ linux-2.6.32.46/include/linux/capability.h 2011-04-17 15:56:46.000000000 -0400
61615 @@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff
61616 (security_real_capable_noaudit((t), (cap)) == 0)
61617
61618 extern int capable(int cap);
61619 +int capable_nolog(int cap);
61620
61621 /* audit system wants to get cap info from files as well */
61622 struct dentry;
61623 diff -urNp linux-2.6.32.46/include/linux/compiler-gcc4.h linux-2.6.32.46/include/linux/compiler-gcc4.h
61624 --- linux-2.6.32.46/include/linux/compiler-gcc4.h 2011-03-27 14:31:47.000000000 -0400
61625 +++ linux-2.6.32.46/include/linux/compiler-gcc4.h 2011-08-26 20:19:09.000000000 -0400
61626 @@ -36,4 +36,16 @@
61627 the kernel context */
61628 #define __cold __attribute__((__cold__))
61629
61630 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61631 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61632 +#define __bos0(ptr) __bos((ptr), 0)
61633 +#define __bos1(ptr) __bos((ptr), 1)
61634 +
61635 +#if __GNUC_MINOR__ >= 5
61636 +#ifdef CONSTIFY_PLUGIN
61637 +#define __no_const __attribute__((no_const))
61638 +#define __do_const __attribute__((do_const))
61639 +#endif
61640 +#endif
61641 +
61642 #endif
61643 diff -urNp linux-2.6.32.46/include/linux/compiler.h linux-2.6.32.46/include/linux/compiler.h
61644 --- linux-2.6.32.46/include/linux/compiler.h 2011-03-27 14:31:47.000000000 -0400
61645 +++ linux-2.6.32.46/include/linux/compiler.h 2011-10-06 09:37:14.000000000 -0400
61646 @@ -5,11 +5,14 @@
61647
61648 #ifdef __CHECKER__
61649 # define __user __attribute__((noderef, address_space(1)))
61650 +# define __force_user __force __user
61651 # define __kernel /* default address space */
61652 +# define __force_kernel __force __kernel
61653 # define __safe __attribute__((safe))
61654 # define __force __attribute__((force))
61655 # define __nocast __attribute__((nocast))
61656 # define __iomem __attribute__((noderef, address_space(2)))
61657 +# define __force_iomem __force __iomem
61658 # define __acquires(x) __attribute__((context(x,0,1)))
61659 # define __releases(x) __attribute__((context(x,1,0)))
61660 # define __acquire(x) __context__(x,1)
61661 @@ -17,13 +20,34 @@
61662 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61663 extern void __chk_user_ptr(const volatile void __user *);
61664 extern void __chk_io_ptr(const volatile void __iomem *);
61665 +#elif defined(CHECKER_PLUGIN)
61666 +//# define __user
61667 +//# define __force_user
61668 +//# define __kernel
61669 +//# define __force_kernel
61670 +# define __safe
61671 +# define __force
61672 +# define __nocast
61673 +# define __iomem
61674 +# define __force_iomem
61675 +# define __chk_user_ptr(x) (void)0
61676 +# define __chk_io_ptr(x) (void)0
61677 +# define __builtin_warning(x, y...) (1)
61678 +# define __acquires(x)
61679 +# define __releases(x)
61680 +# define __acquire(x) (void)0
61681 +# define __release(x) (void)0
61682 +# define __cond_lock(x,c) (c)
61683 #else
61684 # define __user
61685 +# define __force_user
61686 # define __kernel
61687 +# define __force_kernel
61688 # define __safe
61689 # define __force
61690 # define __nocast
61691 # define __iomem
61692 +# define __force_iomem
61693 # define __chk_user_ptr(x) (void)0
61694 # define __chk_io_ptr(x) (void)0
61695 # define __builtin_warning(x, y...) (1)
61696 @@ -247,6 +271,14 @@ void ftrace_likely_update(struct ftrace_
61697 # define __attribute_const__ /* unimplemented */
61698 #endif
61699
61700 +#ifndef __no_const
61701 +# define __no_const
61702 +#endif
61703 +
61704 +#ifndef __do_const
61705 +# define __do_const
61706 +#endif
61707 +
61708 /*
61709 * Tell gcc if a function is cold. The compiler will assume any path
61710 * directly leading to the call is unlikely.
61711 @@ -256,6 +288,22 @@ void ftrace_likely_update(struct ftrace_
61712 #define __cold
61713 #endif
61714
61715 +#ifndef __alloc_size
61716 +#define __alloc_size(...)
61717 +#endif
61718 +
61719 +#ifndef __bos
61720 +#define __bos(ptr, arg)
61721 +#endif
61722 +
61723 +#ifndef __bos0
61724 +#define __bos0(ptr)
61725 +#endif
61726 +
61727 +#ifndef __bos1
61728 +#define __bos1(ptr)
61729 +#endif
61730 +
61731 /* Simple shorthand for a section definition */
61732 #ifndef __section
61733 # define __section(S) __attribute__ ((__section__(#S)))
61734 @@ -278,6 +326,7 @@ void ftrace_likely_update(struct ftrace_
61735 * use is to mediate communication between process-level code and irq/NMI
61736 * handlers, all running on the same CPU.
61737 */
61738 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61739 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61740 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61741
61742 #endif /* __LINUX_COMPILER_H */
61743 diff -urNp linux-2.6.32.46/include/linux/crypto.h linux-2.6.32.46/include/linux/crypto.h
61744 --- linux-2.6.32.46/include/linux/crypto.h 2011-03-27 14:31:47.000000000 -0400
61745 +++ linux-2.6.32.46/include/linux/crypto.h 2011-08-05 20:33:55.000000000 -0400
61746 @@ -394,7 +394,7 @@ struct cipher_tfm {
61747 const u8 *key, unsigned int keylen);
61748 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61749 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61750 -};
61751 +} __no_const;
61752
61753 struct hash_tfm {
61754 int (*init)(struct hash_desc *desc);
61755 @@ -415,13 +415,13 @@ struct compress_tfm {
61756 int (*cot_decompress)(struct crypto_tfm *tfm,
61757 const u8 *src, unsigned int slen,
61758 u8 *dst, unsigned int *dlen);
61759 -};
61760 +} __no_const;
61761
61762 struct rng_tfm {
61763 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61764 unsigned int dlen);
61765 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61766 -};
61767 +} __no_const;
61768
61769 #define crt_ablkcipher crt_u.ablkcipher
61770 #define crt_aead crt_u.aead
61771 diff -urNp linux-2.6.32.46/include/linux/dcache.h linux-2.6.32.46/include/linux/dcache.h
61772 --- linux-2.6.32.46/include/linux/dcache.h 2011-03-27 14:31:47.000000000 -0400
61773 +++ linux-2.6.32.46/include/linux/dcache.h 2011-04-23 13:34:46.000000000 -0400
61774 @@ -119,6 +119,8 @@ struct dentry {
61775 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
61776 };
61777
61778 +#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
61779 +
61780 /*
61781 * dentry->d_lock spinlock nesting subclasses:
61782 *
61783 diff -urNp linux-2.6.32.46/include/linux/decompress/mm.h linux-2.6.32.46/include/linux/decompress/mm.h
61784 --- linux-2.6.32.46/include/linux/decompress/mm.h 2011-03-27 14:31:47.000000000 -0400
61785 +++ linux-2.6.32.46/include/linux/decompress/mm.h 2011-04-17 15:56:46.000000000 -0400
61786 @@ -78,7 +78,7 @@ static void free(void *where)
61787 * warnings when not needed (indeed large_malloc / large_free are not
61788 * needed by inflate */
61789
61790 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61791 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61792 #define free(a) kfree(a)
61793
61794 #define large_malloc(a) vmalloc(a)
61795 diff -urNp linux-2.6.32.46/include/linux/dma-mapping.h linux-2.6.32.46/include/linux/dma-mapping.h
61796 --- linux-2.6.32.46/include/linux/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
61797 +++ linux-2.6.32.46/include/linux/dma-mapping.h 2011-08-26 20:19:09.000000000 -0400
61798 @@ -16,51 +16,51 @@ enum dma_data_direction {
61799 };
61800
61801 struct dma_map_ops {
61802 - void* (*alloc_coherent)(struct device *dev, size_t size,
61803 + void* (* const alloc_coherent)(struct device *dev, size_t size,
61804 dma_addr_t *dma_handle, gfp_t gfp);
61805 - void (*free_coherent)(struct device *dev, size_t size,
61806 + void (* const free_coherent)(struct device *dev, size_t size,
61807 void *vaddr, dma_addr_t dma_handle);
61808 - dma_addr_t (*map_page)(struct device *dev, struct page *page,
61809 + dma_addr_t (* const map_page)(struct device *dev, struct page *page,
61810 unsigned long offset, size_t size,
61811 enum dma_data_direction dir,
61812 struct dma_attrs *attrs);
61813 - void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
61814 + void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
61815 size_t size, enum dma_data_direction dir,
61816 struct dma_attrs *attrs);
61817 - int (*map_sg)(struct device *dev, struct scatterlist *sg,
61818 + int (* const map_sg)(struct device *dev, struct scatterlist *sg,
61819 int nents, enum dma_data_direction dir,
61820 struct dma_attrs *attrs);
61821 - void (*unmap_sg)(struct device *dev,
61822 + void (* const unmap_sg)(struct device *dev,
61823 struct scatterlist *sg, int nents,
61824 enum dma_data_direction dir,
61825 struct dma_attrs *attrs);
61826 - void (*sync_single_for_cpu)(struct device *dev,
61827 + void (* const sync_single_for_cpu)(struct device *dev,
61828 dma_addr_t dma_handle, size_t size,
61829 enum dma_data_direction dir);
61830 - void (*sync_single_for_device)(struct device *dev,
61831 + void (* const sync_single_for_device)(struct device *dev,
61832 dma_addr_t dma_handle, size_t size,
61833 enum dma_data_direction dir);
61834 - void (*sync_single_range_for_cpu)(struct device *dev,
61835 + void (* const sync_single_range_for_cpu)(struct device *dev,
61836 dma_addr_t dma_handle,
61837 unsigned long offset,
61838 size_t size,
61839 enum dma_data_direction dir);
61840 - void (*sync_single_range_for_device)(struct device *dev,
61841 + void (* const sync_single_range_for_device)(struct device *dev,
61842 dma_addr_t dma_handle,
61843 unsigned long offset,
61844 size_t size,
61845 enum dma_data_direction dir);
61846 - void (*sync_sg_for_cpu)(struct device *dev,
61847 + void (* const sync_sg_for_cpu)(struct device *dev,
61848 struct scatterlist *sg, int nents,
61849 enum dma_data_direction dir);
61850 - void (*sync_sg_for_device)(struct device *dev,
61851 + void (* const sync_sg_for_device)(struct device *dev,
61852 struct scatterlist *sg, int nents,
61853 enum dma_data_direction dir);
61854 - int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
61855 - int (*dma_supported)(struct device *dev, u64 mask);
61856 + int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
61857 + int (* const dma_supported)(struct device *dev, u64 mask);
61858 int (*set_dma_mask)(struct device *dev, u64 mask);
61859 int is_phys;
61860 -};
61861 +} __do_const;
61862
61863 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61864
61865 diff -urNp linux-2.6.32.46/include/linux/dst.h linux-2.6.32.46/include/linux/dst.h
61866 --- linux-2.6.32.46/include/linux/dst.h 2011-03-27 14:31:47.000000000 -0400
61867 +++ linux-2.6.32.46/include/linux/dst.h 2011-04-17 15:56:46.000000000 -0400
61868 @@ -380,7 +380,7 @@ struct dst_node
61869 struct thread_pool *pool;
61870
61871 /* Transaction IDs live here */
61872 - atomic_long_t gen;
61873 + atomic_long_unchecked_t gen;
61874
61875 /*
61876 * How frequently and how many times transaction
61877 diff -urNp linux-2.6.32.46/include/linux/elf.h linux-2.6.32.46/include/linux/elf.h
61878 --- linux-2.6.32.46/include/linux/elf.h 2011-03-27 14:31:47.000000000 -0400
61879 +++ linux-2.6.32.46/include/linux/elf.h 2011-04-17 15:56:46.000000000 -0400
61880 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
61881 #define PT_GNU_EH_FRAME 0x6474e550
61882
61883 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61884 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61885 +
61886 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61887 +
61888 +/* Constants for the e_flags field */
61889 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61890 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61891 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61892 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61893 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61894 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61895
61896 /* These constants define the different elf file types */
61897 #define ET_NONE 0
61898 @@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
61899 #define DT_DEBUG 21
61900 #define DT_TEXTREL 22
61901 #define DT_JMPREL 23
61902 +#define DT_FLAGS 30
61903 + #define DF_TEXTREL 0x00000004
61904 #define DT_ENCODING 32
61905 #define OLD_DT_LOOS 0x60000000
61906 #define DT_LOOS 0x6000000d
61907 @@ -230,6 +243,19 @@ typedef struct elf64_hdr {
61908 #define PF_W 0x2
61909 #define PF_X 0x1
61910
61911 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61912 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61913 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61914 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61915 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61916 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61917 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61918 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61919 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61920 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61921 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61922 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61923 +
61924 typedef struct elf32_phdr{
61925 Elf32_Word p_type;
61926 Elf32_Off p_offset;
61927 @@ -322,6 +348,8 @@ typedef struct elf64_shdr {
61928 #define EI_OSABI 7
61929 #define EI_PAD 8
61930
61931 +#define EI_PAX 14
61932 +
61933 #define ELFMAG0 0x7f /* EI_MAG */
61934 #define ELFMAG1 'E'
61935 #define ELFMAG2 'L'
61936 @@ -386,6 +414,7 @@ extern Elf32_Dyn _DYNAMIC [];
61937 #define elf_phdr elf32_phdr
61938 #define elf_note elf32_note
61939 #define elf_addr_t Elf32_Off
61940 +#define elf_dyn Elf32_Dyn
61941
61942 #else
61943
61944 @@ -394,6 +423,7 @@ extern Elf64_Dyn _DYNAMIC [];
61945 #define elf_phdr elf64_phdr
61946 #define elf_note elf64_note
61947 #define elf_addr_t Elf64_Off
61948 +#define elf_dyn Elf64_Dyn
61949
61950 #endif
61951
61952 diff -urNp linux-2.6.32.46/include/linux/fs.h linux-2.6.32.46/include/linux/fs.h
61953 --- linux-2.6.32.46/include/linux/fs.h 2011-07-13 17:23:04.000000000 -0400
61954 +++ linux-2.6.32.46/include/linux/fs.h 2011-08-26 20:19:09.000000000 -0400
61955 @@ -90,6 +90,11 @@ struct inodes_stat_t {
61956 /* Expect random access pattern */
61957 #define FMODE_RANDOM ((__force fmode_t)4096)
61958
61959 +/* Hack for grsec so as not to require read permission simply to execute
61960 + * a binary
61961 + */
61962 +#define FMODE_GREXEC ((__force fmode_t)0x2000000)
61963 +
61964 /*
61965 * The below are the various read and write types that we support. Some of
61966 * them include behavioral modifiers that send information down to the
61967 @@ -568,41 +573,41 @@ typedef int (*read_actor_t)(read_descrip
61968 unsigned long, unsigned long);
61969
61970 struct address_space_operations {
61971 - int (*writepage)(struct page *page, struct writeback_control *wbc);
61972 - int (*readpage)(struct file *, struct page *);
61973 - void (*sync_page)(struct page *);
61974 + int (* const writepage)(struct page *page, struct writeback_control *wbc);
61975 + int (* const readpage)(struct file *, struct page *);
61976 + void (* const sync_page)(struct page *);
61977
61978 /* Write back some dirty pages from this mapping. */
61979 - int (*writepages)(struct address_space *, struct writeback_control *);
61980 + int (* const writepages)(struct address_space *, struct writeback_control *);
61981
61982 /* Set a page dirty. Return true if this dirtied it */
61983 - int (*set_page_dirty)(struct page *page);
61984 + int (* const set_page_dirty)(struct page *page);
61985
61986 - int (*readpages)(struct file *filp, struct address_space *mapping,
61987 + int (* const readpages)(struct file *filp, struct address_space *mapping,
61988 struct list_head *pages, unsigned nr_pages);
61989
61990 - int (*write_begin)(struct file *, struct address_space *mapping,
61991 + int (* const write_begin)(struct file *, struct address_space *mapping,
61992 loff_t pos, unsigned len, unsigned flags,
61993 struct page **pagep, void **fsdata);
61994 - int (*write_end)(struct file *, struct address_space *mapping,
61995 + int (* const write_end)(struct file *, struct address_space *mapping,
61996 loff_t pos, unsigned len, unsigned copied,
61997 struct page *page, void *fsdata);
61998
61999 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
62000 - sector_t (*bmap)(struct address_space *, sector_t);
62001 - void (*invalidatepage) (struct page *, unsigned long);
62002 - int (*releasepage) (struct page *, gfp_t);
62003 - ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
62004 + sector_t (* const bmap)(struct address_space *, sector_t);
62005 + void (* const invalidatepage) (struct page *, unsigned long);
62006 + int (* const releasepage) (struct page *, gfp_t);
62007 + ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
62008 loff_t offset, unsigned long nr_segs);
62009 - int (*get_xip_mem)(struct address_space *, pgoff_t, int,
62010 + int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
62011 void **, unsigned long *);
62012 /* migrate the contents of a page to the specified target */
62013 - int (*migratepage) (struct address_space *,
62014 + int (* const migratepage) (struct address_space *,
62015 struct page *, struct page *);
62016 - int (*launder_page) (struct page *);
62017 - int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
62018 + int (* const launder_page) (struct page *);
62019 + int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
62020 unsigned long);
62021 - int (*error_remove_page)(struct address_space *, struct page *);
62022 + int (* const error_remove_page)(struct address_space *, struct page *);
62023 };
62024
62025 /*
62026 @@ -1031,19 +1036,19 @@ static inline int file_check_writeable(s
62027 typedef struct files_struct *fl_owner_t;
62028
62029 struct file_lock_operations {
62030 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
62031 - void (*fl_release_private)(struct file_lock *);
62032 + void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
62033 + void (* const fl_release_private)(struct file_lock *);
62034 };
62035
62036 struct lock_manager_operations {
62037 - int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
62038 - void (*fl_notify)(struct file_lock *); /* unblock callback */
62039 - int (*fl_grant)(struct file_lock *, struct file_lock *, int);
62040 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
62041 - void (*fl_release_private)(struct file_lock *);
62042 - void (*fl_break)(struct file_lock *);
62043 - int (*fl_mylease)(struct file_lock *, struct file_lock *);
62044 - int (*fl_change)(struct file_lock **, int);
62045 + int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
62046 + void (* const fl_notify)(struct file_lock *); /* unblock callback */
62047 + int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
62048 + void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
62049 + void (* const fl_release_private)(struct file_lock *);
62050 + void (* const fl_break)(struct file_lock *);
62051 + int (* const fl_mylease)(struct file_lock *, struct file_lock *);
62052 + int (* const fl_change)(struct file_lock **, int);
62053 };
62054
62055 struct lock_manager {
62056 @@ -1442,7 +1447,7 @@ struct fiemap_extent_info {
62057 unsigned int fi_flags; /* Flags as passed from user */
62058 unsigned int fi_extents_mapped; /* Number of mapped extents */
62059 unsigned int fi_extents_max; /* Size of fiemap_extent array */
62060 - struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
62061 + struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
62062 * array */
62063 };
62064 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
62065 @@ -1512,7 +1517,8 @@ struct file_operations {
62066 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
62067 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
62068 int (*setlease)(struct file *, long, struct file_lock **);
62069 -};
62070 +} __do_const;
62071 +typedef struct file_operations __no_const file_operations_no_const;
62072
62073 struct inode_operations {
62074 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
62075 @@ -1559,30 +1565,30 @@ extern ssize_t vfs_writev(struct file *,
62076 unsigned long, loff_t *);
62077
62078 struct super_operations {
62079 - struct inode *(*alloc_inode)(struct super_block *sb);
62080 - void (*destroy_inode)(struct inode *);
62081 + struct inode *(* const alloc_inode)(struct super_block *sb);
62082 + void (* const destroy_inode)(struct inode *);
62083
62084 - void (*dirty_inode) (struct inode *);
62085 - int (*write_inode) (struct inode *, int);
62086 - void (*drop_inode) (struct inode *);
62087 - void (*delete_inode) (struct inode *);
62088 - void (*put_super) (struct super_block *);
62089 - void (*write_super) (struct super_block *);
62090 - int (*sync_fs)(struct super_block *sb, int wait);
62091 - int (*freeze_fs) (struct super_block *);
62092 - int (*unfreeze_fs) (struct super_block *);
62093 - int (*statfs) (struct dentry *, struct kstatfs *);
62094 - int (*remount_fs) (struct super_block *, int *, char *);
62095 - void (*clear_inode) (struct inode *);
62096 - void (*umount_begin) (struct super_block *);
62097 + void (* const dirty_inode) (struct inode *);
62098 + int (* const write_inode) (struct inode *, int);
62099 + void (* const drop_inode) (struct inode *);
62100 + void (* const delete_inode) (struct inode *);
62101 + void (* const put_super) (struct super_block *);
62102 + void (* const write_super) (struct super_block *);
62103 + int (* const sync_fs)(struct super_block *sb, int wait);
62104 + int (* const freeze_fs) (struct super_block *);
62105 + int (* const unfreeze_fs) (struct super_block *);
62106 + int (* const statfs) (struct dentry *, struct kstatfs *);
62107 + int (* const remount_fs) (struct super_block *, int *, char *);
62108 + void (* const clear_inode) (struct inode *);
62109 + void (* const umount_begin) (struct super_block *);
62110
62111 - int (*show_options)(struct seq_file *, struct vfsmount *);
62112 - int (*show_stats)(struct seq_file *, struct vfsmount *);
62113 + int (* const show_options)(struct seq_file *, struct vfsmount *);
62114 + int (* const show_stats)(struct seq_file *, struct vfsmount *);
62115 #ifdef CONFIG_QUOTA
62116 - ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
62117 - ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62118 + ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
62119 + ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62120 #endif
62121 - int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62122 + int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62123 };
62124
62125 /*
62126 diff -urNp linux-2.6.32.46/include/linux/fs_struct.h linux-2.6.32.46/include/linux/fs_struct.h
62127 --- linux-2.6.32.46/include/linux/fs_struct.h 2011-03-27 14:31:47.000000000 -0400
62128 +++ linux-2.6.32.46/include/linux/fs_struct.h 2011-04-17 15:56:46.000000000 -0400
62129 @@ -4,7 +4,7 @@
62130 #include <linux/path.h>
62131
62132 struct fs_struct {
62133 - int users;
62134 + atomic_t users;
62135 rwlock_t lock;
62136 int umask;
62137 int in_exec;
62138 diff -urNp linux-2.6.32.46/include/linux/fscache-cache.h linux-2.6.32.46/include/linux/fscache-cache.h
62139 --- linux-2.6.32.46/include/linux/fscache-cache.h 2011-03-27 14:31:47.000000000 -0400
62140 +++ linux-2.6.32.46/include/linux/fscache-cache.h 2011-05-04 17:56:28.000000000 -0400
62141 @@ -116,7 +116,7 @@ struct fscache_operation {
62142 #endif
62143 };
62144
62145 -extern atomic_t fscache_op_debug_id;
62146 +extern atomic_unchecked_t fscache_op_debug_id;
62147 extern const struct slow_work_ops fscache_op_slow_work_ops;
62148
62149 extern void fscache_enqueue_operation(struct fscache_operation *);
62150 @@ -134,7 +134,7 @@ static inline void fscache_operation_ini
62151 fscache_operation_release_t release)
62152 {
62153 atomic_set(&op->usage, 1);
62154 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62155 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62156 op->release = release;
62157 INIT_LIST_HEAD(&op->pend_link);
62158 fscache_set_op_state(op, "Init");
62159 diff -urNp linux-2.6.32.46/include/linux/ftrace_event.h linux-2.6.32.46/include/linux/ftrace_event.h
62160 --- linux-2.6.32.46/include/linux/ftrace_event.h 2011-03-27 14:31:47.000000000 -0400
62161 +++ linux-2.6.32.46/include/linux/ftrace_event.h 2011-05-04 17:56:28.000000000 -0400
62162 @@ -163,7 +163,7 @@ extern int trace_define_field(struct ftr
62163 int filter_type);
62164 extern int trace_define_common_fields(struct ftrace_event_call *call);
62165
62166 -#define is_signed_type(type) (((type)(-1)) < 0)
62167 +#define is_signed_type(type) (((type)(-1)) < (type)1)
62168
62169 int trace_set_clr_event(const char *system, const char *event, int set);
62170
62171 diff -urNp linux-2.6.32.46/include/linux/genhd.h linux-2.6.32.46/include/linux/genhd.h
62172 --- linux-2.6.32.46/include/linux/genhd.h 2011-03-27 14:31:47.000000000 -0400
62173 +++ linux-2.6.32.46/include/linux/genhd.h 2011-04-17 15:56:46.000000000 -0400
62174 @@ -161,7 +161,7 @@ struct gendisk {
62175
62176 struct timer_rand_state *random;
62177
62178 - atomic_t sync_io; /* RAID */
62179 + atomic_unchecked_t sync_io; /* RAID */
62180 struct work_struct async_notify;
62181 #ifdef CONFIG_BLK_DEV_INTEGRITY
62182 struct blk_integrity *integrity;
62183 diff -urNp linux-2.6.32.46/include/linux/gracl.h linux-2.6.32.46/include/linux/gracl.h
62184 --- linux-2.6.32.46/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
62185 +++ linux-2.6.32.46/include/linux/gracl.h 2011-04-17 15:56:46.000000000 -0400
62186 @@ -0,0 +1,317 @@
62187 +#ifndef GR_ACL_H
62188 +#define GR_ACL_H
62189 +
62190 +#include <linux/grdefs.h>
62191 +#include <linux/resource.h>
62192 +#include <linux/capability.h>
62193 +#include <linux/dcache.h>
62194 +#include <asm/resource.h>
62195 +
62196 +/* Major status information */
62197 +
62198 +#define GR_VERSION "grsecurity 2.2.2"
62199 +#define GRSECURITY_VERSION 0x2202
62200 +
62201 +enum {
62202 + GR_SHUTDOWN = 0,
62203 + GR_ENABLE = 1,
62204 + GR_SPROLE = 2,
62205 + GR_RELOAD = 3,
62206 + GR_SEGVMOD = 4,
62207 + GR_STATUS = 5,
62208 + GR_UNSPROLE = 6,
62209 + GR_PASSSET = 7,
62210 + GR_SPROLEPAM = 8,
62211 +};
62212 +
62213 +/* Password setup definitions
62214 + * kernel/grhash.c */
62215 +enum {
62216 + GR_PW_LEN = 128,
62217 + GR_SALT_LEN = 16,
62218 + GR_SHA_LEN = 32,
62219 +};
62220 +
62221 +enum {
62222 + GR_SPROLE_LEN = 64,
62223 +};
62224 +
62225 +enum {
62226 + GR_NO_GLOB = 0,
62227 + GR_REG_GLOB,
62228 + GR_CREATE_GLOB
62229 +};
62230 +
62231 +#define GR_NLIMITS 32
62232 +
62233 +/* Begin Data Structures */
62234 +
62235 +struct sprole_pw {
62236 + unsigned char *rolename;
62237 + unsigned char salt[GR_SALT_LEN];
62238 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62239 +};
62240 +
62241 +struct name_entry {
62242 + __u32 key;
62243 + ino_t inode;
62244 + dev_t device;
62245 + char *name;
62246 + __u16 len;
62247 + __u8 deleted;
62248 + struct name_entry *prev;
62249 + struct name_entry *next;
62250 +};
62251 +
62252 +struct inodev_entry {
62253 + struct name_entry *nentry;
62254 + struct inodev_entry *prev;
62255 + struct inodev_entry *next;
62256 +};
62257 +
62258 +struct acl_role_db {
62259 + struct acl_role_label **r_hash;
62260 + __u32 r_size;
62261 +};
62262 +
62263 +struct inodev_db {
62264 + struct inodev_entry **i_hash;
62265 + __u32 i_size;
62266 +};
62267 +
62268 +struct name_db {
62269 + struct name_entry **n_hash;
62270 + __u32 n_size;
62271 +};
62272 +
62273 +struct crash_uid {
62274 + uid_t uid;
62275 + unsigned long expires;
62276 +};
62277 +
62278 +struct gr_hash_struct {
62279 + void **table;
62280 + void **nametable;
62281 + void *first;
62282 + __u32 table_size;
62283 + __u32 used_size;
62284 + int type;
62285 +};
62286 +
62287 +/* Userspace Grsecurity ACL data structures */
62288 +
62289 +struct acl_subject_label {
62290 + char *filename;
62291 + ino_t inode;
62292 + dev_t device;
62293 + __u32 mode;
62294 + kernel_cap_t cap_mask;
62295 + kernel_cap_t cap_lower;
62296 + kernel_cap_t cap_invert_audit;
62297 +
62298 + struct rlimit res[GR_NLIMITS];
62299 + __u32 resmask;
62300 +
62301 + __u8 user_trans_type;
62302 + __u8 group_trans_type;
62303 + uid_t *user_transitions;
62304 + gid_t *group_transitions;
62305 + __u16 user_trans_num;
62306 + __u16 group_trans_num;
62307 +
62308 + __u32 sock_families[2];
62309 + __u32 ip_proto[8];
62310 + __u32 ip_type;
62311 + struct acl_ip_label **ips;
62312 + __u32 ip_num;
62313 + __u32 inaddr_any_override;
62314 +
62315 + __u32 crashes;
62316 + unsigned long expires;
62317 +
62318 + struct acl_subject_label *parent_subject;
62319 + struct gr_hash_struct *hash;
62320 + struct acl_subject_label *prev;
62321 + struct acl_subject_label *next;
62322 +
62323 + struct acl_object_label **obj_hash;
62324 + __u32 obj_hash_size;
62325 + __u16 pax_flags;
62326 +};
62327 +
62328 +struct role_allowed_ip {
62329 + __u32 addr;
62330 + __u32 netmask;
62331 +
62332 + struct role_allowed_ip *prev;
62333 + struct role_allowed_ip *next;
62334 +};
62335 +
62336 +struct role_transition {
62337 + char *rolename;
62338 +
62339 + struct role_transition *prev;
62340 + struct role_transition *next;
62341 +};
62342 +
62343 +struct acl_role_label {
62344 + char *rolename;
62345 + uid_t uidgid;
62346 + __u16 roletype;
62347 +
62348 + __u16 auth_attempts;
62349 + unsigned long expires;
62350 +
62351 + struct acl_subject_label *root_label;
62352 + struct gr_hash_struct *hash;
62353 +
62354 + struct acl_role_label *prev;
62355 + struct acl_role_label *next;
62356 +
62357 + struct role_transition *transitions;
62358 + struct role_allowed_ip *allowed_ips;
62359 + uid_t *domain_children;
62360 + __u16 domain_child_num;
62361 +
62362 + struct acl_subject_label **subj_hash;
62363 + __u32 subj_hash_size;
62364 +};
62365 +
62366 +struct user_acl_role_db {
62367 + struct acl_role_label **r_table;
62368 + __u32 num_pointers; /* Number of allocations to track */
62369 + __u32 num_roles; /* Number of roles */
62370 + __u32 num_domain_children; /* Number of domain children */
62371 + __u32 num_subjects; /* Number of subjects */
62372 + __u32 num_objects; /* Number of objects */
62373 +};
62374 +
62375 +struct acl_object_label {
62376 + char *filename;
62377 + ino_t inode;
62378 + dev_t device;
62379 + __u32 mode;
62380 +
62381 + struct acl_subject_label *nested;
62382 + struct acl_object_label *globbed;
62383 +
62384 + /* next two structures not used */
62385 +
62386 + struct acl_object_label *prev;
62387 + struct acl_object_label *next;
62388 +};
62389 +
62390 +struct acl_ip_label {
62391 + char *iface;
62392 + __u32 addr;
62393 + __u32 netmask;
62394 + __u16 low, high;
62395 + __u8 mode;
62396 + __u32 type;
62397 + __u32 proto[8];
62398 +
62399 + /* next two structures not used */
62400 +
62401 + struct acl_ip_label *prev;
62402 + struct acl_ip_label *next;
62403 +};
62404 +
62405 +struct gr_arg {
62406 + struct user_acl_role_db role_db;
62407 + unsigned char pw[GR_PW_LEN];
62408 + unsigned char salt[GR_SALT_LEN];
62409 + unsigned char sum[GR_SHA_LEN];
62410 + unsigned char sp_role[GR_SPROLE_LEN];
62411 + struct sprole_pw *sprole_pws;
62412 + dev_t segv_device;
62413 + ino_t segv_inode;
62414 + uid_t segv_uid;
62415 + __u16 num_sprole_pws;
62416 + __u16 mode;
62417 +};
62418 +
62419 +struct gr_arg_wrapper {
62420 + struct gr_arg *arg;
62421 + __u32 version;
62422 + __u32 size;
62423 +};
62424 +
62425 +struct subject_map {
62426 + struct acl_subject_label *user;
62427 + struct acl_subject_label *kernel;
62428 + struct subject_map *prev;
62429 + struct subject_map *next;
62430 +};
62431 +
62432 +struct acl_subj_map_db {
62433 + struct subject_map **s_hash;
62434 + __u32 s_size;
62435 +};
62436 +
62437 +/* End Data Structures Section */
62438 +
62439 +/* Hash functions generated by empirical testing by Brad Spengler
62440 + Makes good use of the low bits of the inode. Generally 0-1 times
62441 + in loop for successful match. 0-3 for unsuccessful match.
62442 + Shift/add algorithm with modulus of table size and an XOR*/
62443 +
62444 +static __inline__ unsigned int
62445 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62446 +{
62447 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62448 +}
62449 +
62450 + static __inline__ unsigned int
62451 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62452 +{
62453 + return ((const unsigned long)userp % sz);
62454 +}
62455 +
62456 +static __inline__ unsigned int
62457 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62458 +{
62459 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62460 +}
62461 +
62462 +static __inline__ unsigned int
62463 +nhash(const char *name, const __u16 len, const unsigned int sz)
62464 +{
62465 + return full_name_hash((const unsigned char *)name, len) % sz;
62466 +}
62467 +
62468 +#define FOR_EACH_ROLE_START(role) \
62469 + role = role_list; \
62470 + while (role) {
62471 +
62472 +#define FOR_EACH_ROLE_END(role) \
62473 + role = role->prev; \
62474 + }
62475 +
62476 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62477 + subj = NULL; \
62478 + iter = 0; \
62479 + while (iter < role->subj_hash_size) { \
62480 + if (subj == NULL) \
62481 + subj = role->subj_hash[iter]; \
62482 + if (subj == NULL) { \
62483 + iter++; \
62484 + continue; \
62485 + }
62486 +
62487 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62488 + subj = subj->next; \
62489 + if (subj == NULL) \
62490 + iter++; \
62491 + }
62492 +
62493 +
62494 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62495 + subj = role->hash->first; \
62496 + while (subj != NULL) {
62497 +
62498 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62499 + subj = subj->next; \
62500 + }
62501 +
62502 +#endif
62503 +
62504 diff -urNp linux-2.6.32.46/include/linux/gralloc.h linux-2.6.32.46/include/linux/gralloc.h
62505 --- linux-2.6.32.46/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
62506 +++ linux-2.6.32.46/include/linux/gralloc.h 2011-04-17 15:56:46.000000000 -0400
62507 @@ -0,0 +1,9 @@
62508 +#ifndef __GRALLOC_H
62509 +#define __GRALLOC_H
62510 +
62511 +void acl_free_all(void);
62512 +int acl_alloc_stack_init(unsigned long size);
62513 +void *acl_alloc(unsigned long len);
62514 +void *acl_alloc_num(unsigned long num, unsigned long len);
62515 +
62516 +#endif
62517 diff -urNp linux-2.6.32.46/include/linux/grdefs.h linux-2.6.32.46/include/linux/grdefs.h
62518 --- linux-2.6.32.46/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
62519 +++ linux-2.6.32.46/include/linux/grdefs.h 2011-06-11 16:20:26.000000000 -0400
62520 @@ -0,0 +1,140 @@
62521 +#ifndef GRDEFS_H
62522 +#define GRDEFS_H
62523 +
62524 +/* Begin grsecurity status declarations */
62525 +
62526 +enum {
62527 + GR_READY = 0x01,
62528 + GR_STATUS_INIT = 0x00 // disabled state
62529 +};
62530 +
62531 +/* Begin ACL declarations */
62532 +
62533 +/* Role flags */
62534 +
62535 +enum {
62536 + GR_ROLE_USER = 0x0001,
62537 + GR_ROLE_GROUP = 0x0002,
62538 + GR_ROLE_DEFAULT = 0x0004,
62539 + GR_ROLE_SPECIAL = 0x0008,
62540 + GR_ROLE_AUTH = 0x0010,
62541 + GR_ROLE_NOPW = 0x0020,
62542 + GR_ROLE_GOD = 0x0040,
62543 + GR_ROLE_LEARN = 0x0080,
62544 + GR_ROLE_TPE = 0x0100,
62545 + GR_ROLE_DOMAIN = 0x0200,
62546 + GR_ROLE_PAM = 0x0400,
62547 + GR_ROLE_PERSIST = 0x800
62548 +};
62549 +
62550 +/* ACL Subject and Object mode flags */
62551 +enum {
62552 + GR_DELETED = 0x80000000
62553 +};
62554 +
62555 +/* ACL Object-only mode flags */
62556 +enum {
62557 + GR_READ = 0x00000001,
62558 + GR_APPEND = 0x00000002,
62559 + GR_WRITE = 0x00000004,
62560 + GR_EXEC = 0x00000008,
62561 + GR_FIND = 0x00000010,
62562 + GR_INHERIT = 0x00000020,
62563 + GR_SETID = 0x00000040,
62564 + GR_CREATE = 0x00000080,
62565 + GR_DELETE = 0x00000100,
62566 + GR_LINK = 0x00000200,
62567 + GR_AUDIT_READ = 0x00000400,
62568 + GR_AUDIT_APPEND = 0x00000800,
62569 + GR_AUDIT_WRITE = 0x00001000,
62570 + GR_AUDIT_EXEC = 0x00002000,
62571 + GR_AUDIT_FIND = 0x00004000,
62572 + GR_AUDIT_INHERIT= 0x00008000,
62573 + GR_AUDIT_SETID = 0x00010000,
62574 + GR_AUDIT_CREATE = 0x00020000,
62575 + GR_AUDIT_DELETE = 0x00040000,
62576 + GR_AUDIT_LINK = 0x00080000,
62577 + GR_PTRACERD = 0x00100000,
62578 + GR_NOPTRACE = 0x00200000,
62579 + GR_SUPPRESS = 0x00400000,
62580 + GR_NOLEARN = 0x00800000,
62581 + GR_INIT_TRANSFER= 0x01000000
62582 +};
62583 +
62584 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62585 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62586 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62587 +
62588 +/* ACL subject-only mode flags */
62589 +enum {
62590 + GR_KILL = 0x00000001,
62591 + GR_VIEW = 0x00000002,
62592 + GR_PROTECTED = 0x00000004,
62593 + GR_LEARN = 0x00000008,
62594 + GR_OVERRIDE = 0x00000010,
62595 + /* just a placeholder, this mode is only used in userspace */
62596 + GR_DUMMY = 0x00000020,
62597 + GR_PROTSHM = 0x00000040,
62598 + GR_KILLPROC = 0x00000080,
62599 + GR_KILLIPPROC = 0x00000100,
62600 + /* just a placeholder, this mode is only used in userspace */
62601 + GR_NOTROJAN = 0x00000200,
62602 + GR_PROTPROCFD = 0x00000400,
62603 + GR_PROCACCT = 0x00000800,
62604 + GR_RELAXPTRACE = 0x00001000,
62605 + GR_NESTED = 0x00002000,
62606 + GR_INHERITLEARN = 0x00004000,
62607 + GR_PROCFIND = 0x00008000,
62608 + GR_POVERRIDE = 0x00010000,
62609 + GR_KERNELAUTH = 0x00020000,
62610 + GR_ATSECURE = 0x00040000,
62611 + GR_SHMEXEC = 0x00080000
62612 +};
62613 +
62614 +enum {
62615 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62616 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62617 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62618 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62619 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62620 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62621 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62622 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62623 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62624 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62625 +};
62626 +
62627 +enum {
62628 + GR_ID_USER = 0x01,
62629 + GR_ID_GROUP = 0x02,
62630 +};
62631 +
62632 +enum {
62633 + GR_ID_ALLOW = 0x01,
62634 + GR_ID_DENY = 0x02,
62635 +};
62636 +
62637 +#define GR_CRASH_RES 31
62638 +#define GR_UIDTABLE_MAX 500
62639 +
62640 +/* begin resource learning section */
62641 +enum {
62642 + GR_RLIM_CPU_BUMP = 60,
62643 + GR_RLIM_FSIZE_BUMP = 50000,
62644 + GR_RLIM_DATA_BUMP = 10000,
62645 + GR_RLIM_STACK_BUMP = 1000,
62646 + GR_RLIM_CORE_BUMP = 10000,
62647 + GR_RLIM_RSS_BUMP = 500000,
62648 + GR_RLIM_NPROC_BUMP = 1,
62649 + GR_RLIM_NOFILE_BUMP = 5,
62650 + GR_RLIM_MEMLOCK_BUMP = 50000,
62651 + GR_RLIM_AS_BUMP = 500000,
62652 + GR_RLIM_LOCKS_BUMP = 2,
62653 + GR_RLIM_SIGPENDING_BUMP = 5,
62654 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62655 + GR_RLIM_NICE_BUMP = 1,
62656 + GR_RLIM_RTPRIO_BUMP = 1,
62657 + GR_RLIM_RTTIME_BUMP = 1000000
62658 +};
62659 +
62660 +#endif
62661 diff -urNp linux-2.6.32.46/include/linux/grinternal.h linux-2.6.32.46/include/linux/grinternal.h
62662 --- linux-2.6.32.46/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
62663 +++ linux-2.6.32.46/include/linux/grinternal.h 2011-10-20 00:48:45.000000000 -0400
62664 @@ -0,0 +1,218 @@
62665 +#ifndef __GRINTERNAL_H
62666 +#define __GRINTERNAL_H
62667 +
62668 +#ifdef CONFIG_GRKERNSEC
62669 +
62670 +#include <linux/fs.h>
62671 +#include <linux/mnt_namespace.h>
62672 +#include <linux/nsproxy.h>
62673 +#include <linux/gracl.h>
62674 +#include <linux/grdefs.h>
62675 +#include <linux/grmsg.h>
62676 +
62677 +void gr_add_learn_entry(const char *fmt, ...)
62678 + __attribute__ ((format (printf, 1, 2)));
62679 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62680 + const struct vfsmount *mnt);
62681 +__u32 gr_check_create(const struct dentry *new_dentry,
62682 + const struct dentry *parent,
62683 + const struct vfsmount *mnt, const __u32 mode);
62684 +int gr_check_protected_task(const struct task_struct *task);
62685 +__u32 to_gr_audit(const __u32 reqmode);
62686 +int gr_set_acls(const int type);
62687 +int gr_apply_subject_to_task(struct task_struct *task);
62688 +int gr_acl_is_enabled(void);
62689 +char gr_roletype_to_char(void);
62690 +
62691 +void gr_handle_alertkill(struct task_struct *task);
62692 +char *gr_to_filename(const struct dentry *dentry,
62693 + const struct vfsmount *mnt);
62694 +char *gr_to_filename1(const struct dentry *dentry,
62695 + const struct vfsmount *mnt);
62696 +char *gr_to_filename2(const struct dentry *dentry,
62697 + const struct vfsmount *mnt);
62698 +char *gr_to_filename3(const struct dentry *dentry,
62699 + const struct vfsmount *mnt);
62700 +
62701 +extern int grsec_enable_harden_ptrace;
62702 +extern int grsec_enable_link;
62703 +extern int grsec_enable_fifo;
62704 +extern int grsec_enable_shm;
62705 +extern int grsec_enable_execlog;
62706 +extern int grsec_enable_signal;
62707 +extern int grsec_enable_audit_ptrace;
62708 +extern int grsec_enable_forkfail;
62709 +extern int grsec_enable_time;
62710 +extern int grsec_enable_rofs;
62711 +extern int grsec_enable_chroot_shmat;
62712 +extern int grsec_enable_chroot_mount;
62713 +extern int grsec_enable_chroot_double;
62714 +extern int grsec_enable_chroot_pivot;
62715 +extern int grsec_enable_chroot_chdir;
62716 +extern int grsec_enable_chroot_chmod;
62717 +extern int grsec_enable_chroot_mknod;
62718 +extern int grsec_enable_chroot_fchdir;
62719 +extern int grsec_enable_chroot_nice;
62720 +extern int grsec_enable_chroot_execlog;
62721 +extern int grsec_enable_chroot_caps;
62722 +extern int grsec_enable_chroot_sysctl;
62723 +extern int grsec_enable_chroot_unix;
62724 +extern int grsec_enable_tpe;
62725 +extern int grsec_tpe_gid;
62726 +extern int grsec_enable_tpe_all;
62727 +extern int grsec_enable_tpe_invert;
62728 +extern int grsec_enable_socket_all;
62729 +extern int grsec_socket_all_gid;
62730 +extern int grsec_enable_socket_client;
62731 +extern int grsec_socket_client_gid;
62732 +extern int grsec_enable_socket_server;
62733 +extern int grsec_socket_server_gid;
62734 +extern int grsec_audit_gid;
62735 +extern int grsec_enable_group;
62736 +extern int grsec_enable_audit_textrel;
62737 +extern int grsec_enable_log_rwxmaps;
62738 +extern int grsec_enable_mount;
62739 +extern int grsec_enable_chdir;
62740 +extern int grsec_resource_logging;
62741 +extern int grsec_enable_blackhole;
62742 +extern int grsec_lastack_retries;
62743 +extern int grsec_enable_brute;
62744 +extern int grsec_lock;
62745 +
62746 +extern spinlock_t grsec_alert_lock;
62747 +extern unsigned long grsec_alert_wtime;
62748 +extern unsigned long grsec_alert_fyet;
62749 +
62750 +extern spinlock_t grsec_audit_lock;
62751 +
62752 +extern rwlock_t grsec_exec_file_lock;
62753 +
62754 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62755 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62756 + (tsk)->exec_file->f_vfsmnt) : "/")
62757 +
62758 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62759 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62760 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62761 +
62762 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62763 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62764 + (tsk)->exec_file->f_vfsmnt) : "/")
62765 +
62766 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62767 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62768 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62769 +
62770 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62771 +
62772 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62773 +
62774 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62775 + (task)->pid, (cred)->uid, \
62776 + (cred)->euid, (cred)->gid, (cred)->egid, \
62777 + gr_parent_task_fullpath(task), \
62778 + (task)->real_parent->comm, (task)->real_parent->pid, \
62779 + (pcred)->uid, (pcred)->euid, \
62780 + (pcred)->gid, (pcred)->egid
62781 +
62782 +#define GR_CHROOT_CAPS {{ \
62783 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62784 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62785 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62786 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62787 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62788 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62789 + CAP_TO_MASK(CAP_MAC_ADMIN) }}
62790 +
62791 +#define security_learn(normal_msg,args...) \
62792 +({ \
62793 + read_lock(&grsec_exec_file_lock); \
62794 + gr_add_learn_entry(normal_msg "\n", ## args); \
62795 + read_unlock(&grsec_exec_file_lock); \
62796 +})
62797 +
62798 +enum {
62799 + GR_DO_AUDIT,
62800 + GR_DONT_AUDIT,
62801 + GR_DONT_AUDIT_GOOD
62802 +};
62803 +
62804 +enum {
62805 + GR_TTYSNIFF,
62806 + GR_RBAC,
62807 + GR_RBAC_STR,
62808 + GR_STR_RBAC,
62809 + GR_RBAC_MODE2,
62810 + GR_RBAC_MODE3,
62811 + GR_FILENAME,
62812 + GR_SYSCTL_HIDDEN,
62813 + GR_NOARGS,
62814 + GR_ONE_INT,
62815 + GR_ONE_INT_TWO_STR,
62816 + GR_ONE_STR,
62817 + GR_STR_INT,
62818 + GR_TWO_STR_INT,
62819 + GR_TWO_INT,
62820 + GR_TWO_U64,
62821 + GR_THREE_INT,
62822 + GR_FIVE_INT_TWO_STR,
62823 + GR_TWO_STR,
62824 + GR_THREE_STR,
62825 + GR_FOUR_STR,
62826 + GR_STR_FILENAME,
62827 + GR_FILENAME_STR,
62828 + GR_FILENAME_TWO_INT,
62829 + GR_FILENAME_TWO_INT_STR,
62830 + GR_TEXTREL,
62831 + GR_PTRACE,
62832 + GR_RESOURCE,
62833 + GR_CAP,
62834 + GR_SIG,
62835 + GR_SIG2,
62836 + GR_CRASH1,
62837 + GR_CRASH2,
62838 + GR_PSACCT,
62839 + GR_RWXMAP
62840 +};
62841 +
62842 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62843 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62844 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62845 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62846 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62847 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62848 +#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)
62849 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62850 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62851 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62852 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62853 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62854 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62855 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62856 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62857 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62858 +#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)
62859 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62860 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62861 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62862 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62863 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62864 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62865 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62866 +#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)
62867 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62868 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62869 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62870 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62871 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62872 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62873 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62874 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62875 +#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)
62876 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62877 +
62878 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62879 +
62880 +#endif
62881 +
62882 +#endif
62883 diff -urNp linux-2.6.32.46/include/linux/grmsg.h linux-2.6.32.46/include/linux/grmsg.h
62884 --- linux-2.6.32.46/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
62885 +++ linux-2.6.32.46/include/linux/grmsg.h 2011-09-13 15:44:53.000000000 -0400
62886 @@ -0,0 +1,108 @@
62887 +#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"
62888 +#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"
62889 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62890 +#define GR_STOPMOD_MSG "denied modification of module state by "
62891 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62892 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62893 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62894 +#define GR_IOPL_MSG "denied use of iopl() by "
62895 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62896 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62897 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62898 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62899 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62900 +#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"
62901 +#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"
62902 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62903 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62904 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62905 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62906 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62907 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62908 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62909 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62910 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62911 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62912 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62913 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62914 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62915 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62916 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62917 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62918 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62919 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62920 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62921 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
62922 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62923 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62924 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62925 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62926 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62927 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62928 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62929 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62930 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
62931 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62932 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62933 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62934 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62935 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62936 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62937 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62938 +#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"
62939 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
62940 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62941 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62942 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62943 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62944 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62945 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62946 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62947 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62948 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62949 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62950 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62951 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62952 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62953 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62954 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62955 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62956 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62957 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62958 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62959 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62960 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62961 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62962 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62963 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62964 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62965 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62966 +#define GR_TIME_MSG "time set by "
62967 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62968 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62969 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62970 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62971 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62972 +#define GR_BIND_MSG "denied bind() by "
62973 +#define GR_CONNECT_MSG "denied connect() by "
62974 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62975 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62976 +#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"
62977 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62978 +#define GR_CAP_ACL_MSG "use of %s denied for "
62979 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62980 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62981 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62982 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62983 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62984 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62985 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62986 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62987 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62988 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62989 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62990 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62991 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62992 +#define GR_VM86_MSG "denied use of vm86 by "
62993 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62994 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62995 diff -urNp linux-2.6.32.46/include/linux/grsecurity.h linux-2.6.32.46/include/linux/grsecurity.h
62996 --- linux-2.6.32.46/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
62997 +++ linux-2.6.32.46/include/linux/grsecurity.h 2011-10-17 06:48:36.000000000 -0400
62998 @@ -0,0 +1,218 @@
62999 +#ifndef GR_SECURITY_H
63000 +#define GR_SECURITY_H
63001 +#include <linux/fs.h>
63002 +#include <linux/fs_struct.h>
63003 +#include <linux/binfmts.h>
63004 +#include <linux/gracl.h>
63005 +#include <linux/compat.h>
63006 +
63007 +/* notify of brain-dead configs */
63008 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63009 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
63010 +#endif
63011 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63012 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63013 +#endif
63014 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63015 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63016 +#endif
63017 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63018 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63019 +#endif
63020 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63021 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63022 +#endif
63023 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63024 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
63025 +#endif
63026 +
63027 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63028 +void gr_handle_brute_check(void);
63029 +void gr_handle_kernel_exploit(void);
63030 +int gr_process_user_ban(void);
63031 +
63032 +char gr_roletype_to_char(void);
63033 +
63034 +int gr_acl_enable_at_secure(void);
63035 +
63036 +int gr_check_user_change(int real, int effective, int fs);
63037 +int gr_check_group_change(int real, int effective, int fs);
63038 +
63039 +void gr_del_task_from_ip_table(struct task_struct *p);
63040 +
63041 +int gr_pid_is_chrooted(struct task_struct *p);
63042 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63043 +int gr_handle_chroot_nice(void);
63044 +int gr_handle_chroot_sysctl(const int op);
63045 +int gr_handle_chroot_setpriority(struct task_struct *p,
63046 + const int niceval);
63047 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63048 +int gr_handle_chroot_chroot(const struct dentry *dentry,
63049 + const struct vfsmount *mnt);
63050 +void gr_handle_chroot_chdir(struct path *path);
63051 +int gr_handle_chroot_chmod(const struct dentry *dentry,
63052 + const struct vfsmount *mnt, const int mode);
63053 +int gr_handle_chroot_mknod(const struct dentry *dentry,
63054 + const struct vfsmount *mnt, const int mode);
63055 +int gr_handle_chroot_mount(const struct dentry *dentry,
63056 + const struct vfsmount *mnt,
63057 + const char *dev_name);
63058 +int gr_handle_chroot_pivot(void);
63059 +int gr_handle_chroot_unix(const pid_t pid);
63060 +
63061 +int gr_handle_rawio(const struct inode *inode);
63062 +
63063 +void gr_handle_ioperm(void);
63064 +void gr_handle_iopl(void);
63065 +
63066 +int gr_tpe_allow(const struct file *file);
63067 +
63068 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63069 +void gr_clear_chroot_entries(struct task_struct *task);
63070 +
63071 +void gr_log_forkfail(const int retval);
63072 +void gr_log_timechange(void);
63073 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63074 +void gr_log_chdir(const struct dentry *dentry,
63075 + const struct vfsmount *mnt);
63076 +void gr_log_chroot_exec(const struct dentry *dentry,
63077 + const struct vfsmount *mnt);
63078 +void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
63079 +#ifdef CONFIG_COMPAT
63080 +void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
63081 +#endif
63082 +void gr_log_remount(const char *devname, const int retval);
63083 +void gr_log_unmount(const char *devname, const int retval);
63084 +void gr_log_mount(const char *from, const char *to, const int retval);
63085 +void gr_log_textrel(struct vm_area_struct *vma);
63086 +void gr_log_rwxmmap(struct file *file);
63087 +void gr_log_rwxmprotect(struct file *file);
63088 +
63089 +int gr_handle_follow_link(const struct inode *parent,
63090 + const struct inode *inode,
63091 + const struct dentry *dentry,
63092 + const struct vfsmount *mnt);
63093 +int gr_handle_fifo(const struct dentry *dentry,
63094 + const struct vfsmount *mnt,
63095 + const struct dentry *dir, const int flag,
63096 + const int acc_mode);
63097 +int gr_handle_hardlink(const struct dentry *dentry,
63098 + const struct vfsmount *mnt,
63099 + struct inode *inode,
63100 + const int mode, const char *to);
63101 +
63102 +int gr_is_capable(const int cap);
63103 +int gr_is_capable_nolog(const int cap);
63104 +void gr_learn_resource(const struct task_struct *task, const int limit,
63105 + const unsigned long wanted, const int gt);
63106 +void gr_copy_label(struct task_struct *tsk);
63107 +void gr_handle_crash(struct task_struct *task, const int sig);
63108 +int gr_handle_signal(const struct task_struct *p, const int sig);
63109 +int gr_check_crash_uid(const uid_t uid);
63110 +int gr_check_protected_task(const struct task_struct *task);
63111 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63112 +int gr_acl_handle_mmap(const struct file *file,
63113 + const unsigned long prot);
63114 +int gr_acl_handle_mprotect(const struct file *file,
63115 + const unsigned long prot);
63116 +int gr_check_hidden_task(const struct task_struct *tsk);
63117 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63118 + const struct vfsmount *mnt);
63119 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63120 + const struct vfsmount *mnt);
63121 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63122 + const struct vfsmount *mnt, const int fmode);
63123 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
63124 + const struct vfsmount *mnt, mode_t mode);
63125 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63126 + const struct vfsmount *mnt, mode_t mode);
63127 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63128 + const struct vfsmount *mnt);
63129 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63130 + const struct vfsmount *mnt);
63131 +int gr_handle_ptrace(struct task_struct *task, const long request);
63132 +int gr_handle_proc_ptrace(struct task_struct *task);
63133 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63134 + const struct vfsmount *mnt);
63135 +int gr_check_crash_exec(const struct file *filp);
63136 +int gr_acl_is_enabled(void);
63137 +void gr_set_kernel_label(struct task_struct *task);
63138 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63139 + const gid_t gid);
63140 +int gr_set_proc_label(const struct dentry *dentry,
63141 + const struct vfsmount *mnt,
63142 + const int unsafe_share);
63143 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63144 + const struct vfsmount *mnt);
63145 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63146 + const struct vfsmount *mnt, const int fmode);
63147 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63148 + const struct dentry *p_dentry,
63149 + const struct vfsmount *p_mnt, const int fmode,
63150 + const int imode);
63151 +void gr_handle_create(const struct dentry *dentry,
63152 + const struct vfsmount *mnt);
63153 +void gr_handle_proc_create(const struct dentry *dentry,
63154 + const struct inode *inode);
63155 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63156 + const struct dentry *parent_dentry,
63157 + const struct vfsmount *parent_mnt,
63158 + const int mode);
63159 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63160 + const struct dentry *parent_dentry,
63161 + const struct vfsmount *parent_mnt);
63162 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63163 + const struct vfsmount *mnt);
63164 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63165 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63166 + const struct vfsmount *mnt);
63167 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63168 + const struct dentry *parent_dentry,
63169 + const struct vfsmount *parent_mnt,
63170 + const char *from);
63171 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63172 + const struct dentry *parent_dentry,
63173 + const struct vfsmount *parent_mnt,
63174 + const struct dentry *old_dentry,
63175 + const struct vfsmount *old_mnt, const char *to);
63176 +int gr_acl_handle_rename(struct dentry *new_dentry,
63177 + struct dentry *parent_dentry,
63178 + const struct vfsmount *parent_mnt,
63179 + struct dentry *old_dentry,
63180 + struct inode *old_parent_inode,
63181 + struct vfsmount *old_mnt, const char *newname);
63182 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63183 + struct dentry *old_dentry,
63184 + struct dentry *new_dentry,
63185 + struct vfsmount *mnt, const __u8 replace);
63186 +__u32 gr_check_link(const struct dentry *new_dentry,
63187 + const struct dentry *parent_dentry,
63188 + const struct vfsmount *parent_mnt,
63189 + const struct dentry *old_dentry,
63190 + const struct vfsmount *old_mnt);
63191 +int gr_acl_handle_filldir(const struct file *file, const char *name,
63192 + const unsigned int namelen, const ino_t ino);
63193 +
63194 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
63195 + const struct vfsmount *mnt);
63196 +void gr_acl_handle_exit(void);
63197 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
63198 +int gr_acl_handle_procpidmem(const struct task_struct *task);
63199 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63200 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63201 +void gr_audit_ptrace(struct task_struct *task);
63202 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63203 +
63204 +#ifdef CONFIG_GRKERNSEC
63205 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63206 +void gr_handle_vm86(void);
63207 +void gr_handle_mem_readwrite(u64 from, u64 to);
63208 +
63209 +extern int grsec_enable_dmesg;
63210 +extern int grsec_disable_privio;
63211 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63212 +extern int grsec_enable_chroot_findtask;
63213 +#endif
63214 +#endif
63215 +
63216 +#endif
63217 diff -urNp linux-2.6.32.46/include/linux/hdpu_features.h linux-2.6.32.46/include/linux/hdpu_features.h
63218 --- linux-2.6.32.46/include/linux/hdpu_features.h 2011-03-27 14:31:47.000000000 -0400
63219 +++ linux-2.6.32.46/include/linux/hdpu_features.h 2011-04-17 15:56:46.000000000 -0400
63220 @@ -3,7 +3,7 @@
63221 struct cpustate_t {
63222 spinlock_t lock;
63223 int excl;
63224 - int open_count;
63225 + atomic_t open_count;
63226 unsigned char cached_val;
63227 int inited;
63228 unsigned long *set_addr;
63229 diff -urNp linux-2.6.32.46/include/linux/highmem.h linux-2.6.32.46/include/linux/highmem.h
63230 --- linux-2.6.32.46/include/linux/highmem.h 2011-03-27 14:31:47.000000000 -0400
63231 +++ linux-2.6.32.46/include/linux/highmem.h 2011-04-17 15:56:46.000000000 -0400
63232 @@ -137,6 +137,18 @@ static inline void clear_highpage(struct
63233 kunmap_atomic(kaddr, KM_USER0);
63234 }
63235
63236 +static inline void sanitize_highpage(struct page *page)
63237 +{
63238 + void *kaddr;
63239 + unsigned long flags;
63240 +
63241 + local_irq_save(flags);
63242 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
63243 + clear_page(kaddr);
63244 + kunmap_atomic(kaddr, KM_CLEARPAGE);
63245 + local_irq_restore(flags);
63246 +}
63247 +
63248 static inline void zero_user_segments(struct page *page,
63249 unsigned start1, unsigned end1,
63250 unsigned start2, unsigned end2)
63251 diff -urNp linux-2.6.32.46/include/linux/i2c.h linux-2.6.32.46/include/linux/i2c.h
63252 --- linux-2.6.32.46/include/linux/i2c.h 2011-03-27 14:31:47.000000000 -0400
63253 +++ linux-2.6.32.46/include/linux/i2c.h 2011-08-23 21:22:38.000000000 -0400
63254 @@ -325,6 +325,7 @@ struct i2c_algorithm {
63255 /* To determine what the adapter supports */
63256 u32 (*functionality) (struct i2c_adapter *);
63257 };
63258 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63259
63260 /*
63261 * i2c_adapter is the structure used to identify a physical i2c bus along
63262 diff -urNp linux-2.6.32.46/include/linux/i2o.h linux-2.6.32.46/include/linux/i2o.h
63263 --- linux-2.6.32.46/include/linux/i2o.h 2011-03-27 14:31:47.000000000 -0400
63264 +++ linux-2.6.32.46/include/linux/i2o.h 2011-05-04 17:56:28.000000000 -0400
63265 @@ -564,7 +564,7 @@ struct i2o_controller {
63266 struct i2o_device *exec; /* Executive */
63267 #if BITS_PER_LONG == 64
63268 spinlock_t context_list_lock; /* lock for context_list */
63269 - atomic_t context_list_counter; /* needed for unique contexts */
63270 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63271 struct list_head context_list; /* list of context id's
63272 and pointers */
63273 #endif
63274 diff -urNp linux-2.6.32.46/include/linux/init_task.h linux-2.6.32.46/include/linux/init_task.h
63275 --- linux-2.6.32.46/include/linux/init_task.h 2011-03-27 14:31:47.000000000 -0400
63276 +++ linux-2.6.32.46/include/linux/init_task.h 2011-05-18 20:44:59.000000000 -0400
63277 @@ -83,6 +83,12 @@ extern struct group_info init_groups;
63278 #define INIT_IDS
63279 #endif
63280
63281 +#ifdef CONFIG_X86
63282 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63283 +#else
63284 +#define INIT_TASK_THREAD_INFO
63285 +#endif
63286 +
63287 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
63288 /*
63289 * Because of the reduced scope of CAP_SETPCAP when filesystem
63290 @@ -156,6 +162,7 @@ extern struct cred init_cred;
63291 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
63292 .comm = "swapper", \
63293 .thread = INIT_THREAD, \
63294 + INIT_TASK_THREAD_INFO \
63295 .fs = &init_fs, \
63296 .files = &init_files, \
63297 .signal = &init_signals, \
63298 diff -urNp linux-2.6.32.46/include/linux/intel-iommu.h linux-2.6.32.46/include/linux/intel-iommu.h
63299 --- linux-2.6.32.46/include/linux/intel-iommu.h 2011-03-27 14:31:47.000000000 -0400
63300 +++ linux-2.6.32.46/include/linux/intel-iommu.h 2011-08-05 20:33:55.000000000 -0400
63301 @@ -296,7 +296,7 @@ struct iommu_flush {
63302 u8 fm, u64 type);
63303 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63304 unsigned int size_order, u64 type);
63305 -};
63306 +} __no_const;
63307
63308 enum {
63309 SR_DMAR_FECTL_REG,
63310 diff -urNp linux-2.6.32.46/include/linux/interrupt.h linux-2.6.32.46/include/linux/interrupt.h
63311 --- linux-2.6.32.46/include/linux/interrupt.h 2011-06-25 12:55:35.000000000 -0400
63312 +++ linux-2.6.32.46/include/linux/interrupt.h 2011-06-25 12:56:37.000000000 -0400
63313 @@ -363,7 +363,7 @@ enum
63314 /* map softirq index to softirq name. update 'softirq_to_name' in
63315 * kernel/softirq.c when adding a new softirq.
63316 */
63317 -extern char *softirq_to_name[NR_SOFTIRQS];
63318 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63319
63320 /* softirq mask and active fields moved to irq_cpustat_t in
63321 * asm/hardirq.h to get better cache usage. KAO
63322 @@ -371,12 +371,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
63323
63324 struct softirq_action
63325 {
63326 - void (*action)(struct softirq_action *);
63327 + void (*action)(void);
63328 };
63329
63330 asmlinkage void do_softirq(void);
63331 asmlinkage void __do_softirq(void);
63332 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63333 +extern void open_softirq(int nr, void (*action)(void));
63334 extern void softirq_init(void);
63335 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
63336 extern void raise_softirq_irqoff(unsigned int nr);
63337 diff -urNp linux-2.6.32.46/include/linux/irq.h linux-2.6.32.46/include/linux/irq.h
63338 --- linux-2.6.32.46/include/linux/irq.h 2011-03-27 14:31:47.000000000 -0400
63339 +++ linux-2.6.32.46/include/linux/irq.h 2011-04-17 15:56:46.000000000 -0400
63340 @@ -438,12 +438,12 @@ extern int set_irq_msi(unsigned int irq,
63341 static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
63342 bool boot)
63343 {
63344 +#ifdef CONFIG_CPUMASK_OFFSTACK
63345 gfp_t gfp = GFP_ATOMIC;
63346
63347 if (boot)
63348 gfp = GFP_NOWAIT;
63349
63350 -#ifdef CONFIG_CPUMASK_OFFSTACK
63351 if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
63352 return false;
63353
63354 diff -urNp linux-2.6.32.46/include/linux/kallsyms.h linux-2.6.32.46/include/linux/kallsyms.h
63355 --- linux-2.6.32.46/include/linux/kallsyms.h 2011-03-27 14:31:47.000000000 -0400
63356 +++ linux-2.6.32.46/include/linux/kallsyms.h 2011-04-17 15:56:46.000000000 -0400
63357 @@ -15,7 +15,8 @@
63358
63359 struct module;
63360
63361 -#ifdef CONFIG_KALLSYMS
63362 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63363 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63364 /* Lookup the address for a symbol. Returns 0 if not found. */
63365 unsigned long kallsyms_lookup_name(const char *name);
63366
63367 @@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(un
63368 /* Stupid that this does nothing, but I didn't create this mess. */
63369 #define __print_symbol(fmt, addr)
63370 #endif /*CONFIG_KALLSYMS*/
63371 +#else /* when included by kallsyms.c, vsnprintf.c, or
63372 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63373 +extern void __print_symbol(const char *fmt, unsigned long address);
63374 +extern int sprint_symbol(char *buffer, unsigned long address);
63375 +const char *kallsyms_lookup(unsigned long addr,
63376 + unsigned long *symbolsize,
63377 + unsigned long *offset,
63378 + char **modname, char *namebuf);
63379 +#endif
63380
63381 /* This macro allows us to keep printk typechecking */
63382 static void __check_printsym_format(const char *fmt, ...)
63383 diff -urNp linux-2.6.32.46/include/linux/kgdb.h linux-2.6.32.46/include/linux/kgdb.h
63384 --- linux-2.6.32.46/include/linux/kgdb.h 2011-03-27 14:31:47.000000000 -0400
63385 +++ linux-2.6.32.46/include/linux/kgdb.h 2011-08-26 20:25:20.000000000 -0400
63386 @@ -74,8 +74,8 @@ void kgdb_breakpoint(void);
63387
63388 extern int kgdb_connected;
63389
63390 -extern atomic_t kgdb_setting_breakpoint;
63391 -extern atomic_t kgdb_cpu_doing_single_step;
63392 +extern atomic_unchecked_t kgdb_setting_breakpoint;
63393 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63394
63395 extern struct task_struct *kgdb_usethread;
63396 extern struct task_struct *kgdb_contthread;
63397 @@ -235,7 +235,7 @@ struct kgdb_arch {
63398 int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
63399 void (*remove_all_hw_break)(void);
63400 void (*correct_hw_break)(void);
63401 -};
63402 +} __do_const;
63403
63404 /**
63405 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63406 @@ -257,14 +257,14 @@ struct kgdb_io {
63407 int (*init) (void);
63408 void (*pre_exception) (void);
63409 void (*post_exception) (void);
63410 -};
63411 +} __do_const;
63412
63413 -extern struct kgdb_arch arch_kgdb_ops;
63414 +extern const struct kgdb_arch arch_kgdb_ops;
63415
63416 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
63417
63418 -extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
63419 -extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
63420 +extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
63421 +extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
63422
63423 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
63424 extern int kgdb_mem2hex(char *mem, char *buf, int count);
63425 diff -urNp linux-2.6.32.46/include/linux/kmod.h linux-2.6.32.46/include/linux/kmod.h
63426 --- linux-2.6.32.46/include/linux/kmod.h 2011-03-27 14:31:47.000000000 -0400
63427 +++ linux-2.6.32.46/include/linux/kmod.h 2011-04-17 15:56:46.000000000 -0400
63428 @@ -31,6 +31,8 @@
63429 * usually useless though. */
63430 extern int __request_module(bool wait, const char *name, ...) \
63431 __attribute__((format(printf, 2, 3)));
63432 +extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
63433 + __attribute__((format(printf, 3, 4)));
63434 #define request_module(mod...) __request_module(true, mod)
63435 #define request_module_nowait(mod...) __request_module(false, mod)
63436 #define try_then_request_module(x, mod...) \
63437 diff -urNp linux-2.6.32.46/include/linux/kobject.h linux-2.6.32.46/include/linux/kobject.h
63438 --- linux-2.6.32.46/include/linux/kobject.h 2011-03-27 14:31:47.000000000 -0400
63439 +++ linux-2.6.32.46/include/linux/kobject.h 2011-04-17 15:56:46.000000000 -0400
63440 @@ -106,7 +106,7 @@ extern char *kobject_get_path(struct kob
63441
63442 struct kobj_type {
63443 void (*release)(struct kobject *kobj);
63444 - struct sysfs_ops *sysfs_ops;
63445 + const struct sysfs_ops *sysfs_ops;
63446 struct attribute **default_attrs;
63447 };
63448
63449 @@ -118,9 +118,9 @@ struct kobj_uevent_env {
63450 };
63451
63452 struct kset_uevent_ops {
63453 - int (*filter)(struct kset *kset, struct kobject *kobj);
63454 - const char *(*name)(struct kset *kset, struct kobject *kobj);
63455 - int (*uevent)(struct kset *kset, struct kobject *kobj,
63456 + int (* const filter)(struct kset *kset, struct kobject *kobj);
63457 + const char *(* const name)(struct kset *kset, struct kobject *kobj);
63458 + int (* const uevent)(struct kset *kset, struct kobject *kobj,
63459 struct kobj_uevent_env *env);
63460 };
63461
63462 @@ -132,7 +132,7 @@ struct kobj_attribute {
63463 const char *buf, size_t count);
63464 };
63465
63466 -extern struct sysfs_ops kobj_sysfs_ops;
63467 +extern const struct sysfs_ops kobj_sysfs_ops;
63468
63469 /**
63470 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
63471 @@ -155,14 +155,14 @@ struct kset {
63472 struct list_head list;
63473 spinlock_t list_lock;
63474 struct kobject kobj;
63475 - struct kset_uevent_ops *uevent_ops;
63476 + const struct kset_uevent_ops *uevent_ops;
63477 };
63478
63479 extern void kset_init(struct kset *kset);
63480 extern int __must_check kset_register(struct kset *kset);
63481 extern void kset_unregister(struct kset *kset);
63482 extern struct kset * __must_check kset_create_and_add(const char *name,
63483 - struct kset_uevent_ops *u,
63484 + const struct kset_uevent_ops *u,
63485 struct kobject *parent_kobj);
63486
63487 static inline struct kset *to_kset(struct kobject *kobj)
63488 diff -urNp linux-2.6.32.46/include/linux/kvm_host.h linux-2.6.32.46/include/linux/kvm_host.h
63489 --- linux-2.6.32.46/include/linux/kvm_host.h 2011-03-27 14:31:47.000000000 -0400
63490 +++ linux-2.6.32.46/include/linux/kvm_host.h 2011-04-17 15:56:46.000000000 -0400
63491 @@ -210,7 +210,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
63492 void vcpu_load(struct kvm_vcpu *vcpu);
63493 void vcpu_put(struct kvm_vcpu *vcpu);
63494
63495 -int kvm_init(void *opaque, unsigned int vcpu_size,
63496 +int kvm_init(const void *opaque, unsigned int vcpu_size,
63497 struct module *module);
63498 void kvm_exit(void);
63499
63500 @@ -316,7 +316,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
63501 struct kvm_guest_debug *dbg);
63502 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63503
63504 -int kvm_arch_init(void *opaque);
63505 +int kvm_arch_init(const void *opaque);
63506 void kvm_arch_exit(void);
63507
63508 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63509 diff -urNp linux-2.6.32.46/include/linux/libata.h linux-2.6.32.46/include/linux/libata.h
63510 --- linux-2.6.32.46/include/linux/libata.h 2011-03-27 14:31:47.000000000 -0400
63511 +++ linux-2.6.32.46/include/linux/libata.h 2011-08-26 20:19:09.000000000 -0400
63512 @@ -525,11 +525,11 @@ struct ata_ioports {
63513
63514 struct ata_host {
63515 spinlock_t lock;
63516 - struct device *dev;
63517 + struct device *dev;
63518 void __iomem * const *iomap;
63519 unsigned int n_ports;
63520 void *private_data;
63521 - struct ata_port_operations *ops;
63522 + const struct ata_port_operations *ops;
63523 unsigned long flags;
63524 #ifdef CONFIG_ATA_ACPI
63525 acpi_handle acpi_handle;
63526 @@ -710,7 +710,7 @@ struct ata_link {
63527
63528 struct ata_port {
63529 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
63530 - struct ata_port_operations *ops;
63531 + const struct ata_port_operations *ops;
63532 spinlock_t *lock;
63533 /* Flags owned by the EH context. Only EH should touch these once the
63534 port is active */
63535 @@ -884,7 +884,7 @@ struct ata_port_operations {
63536 * fields must be pointers.
63537 */
63538 const struct ata_port_operations *inherits;
63539 -};
63540 +} __do_const;
63541
63542 struct ata_port_info {
63543 unsigned long flags;
63544 @@ -892,7 +892,7 @@ struct ata_port_info {
63545 unsigned long pio_mask;
63546 unsigned long mwdma_mask;
63547 unsigned long udma_mask;
63548 - struct ata_port_operations *port_ops;
63549 + const struct ata_port_operations *port_ops;
63550 void *private_data;
63551 };
63552
63553 @@ -916,7 +916,7 @@ extern const unsigned long sata_deb_timi
63554 extern const unsigned long sata_deb_timing_hotplug[];
63555 extern const unsigned long sata_deb_timing_long[];
63556
63557 -extern struct ata_port_operations ata_dummy_port_ops;
63558 +extern const struct ata_port_operations ata_dummy_port_ops;
63559 extern const struct ata_port_info ata_dummy_port_info;
63560
63561 static inline const unsigned long *
63562 @@ -962,7 +962,7 @@ extern int ata_host_activate(struct ata_
63563 struct scsi_host_template *sht);
63564 extern void ata_host_detach(struct ata_host *host);
63565 extern void ata_host_init(struct ata_host *, struct device *,
63566 - unsigned long, struct ata_port_operations *);
63567 + unsigned long, const struct ata_port_operations *);
63568 extern int ata_scsi_detect(struct scsi_host_template *sht);
63569 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
63570 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
63571 diff -urNp linux-2.6.32.46/include/linux/lockd/bind.h linux-2.6.32.46/include/linux/lockd/bind.h
63572 --- linux-2.6.32.46/include/linux/lockd/bind.h 2011-03-27 14:31:47.000000000 -0400
63573 +++ linux-2.6.32.46/include/linux/lockd/bind.h 2011-04-17 15:56:46.000000000 -0400
63574 @@ -23,13 +23,13 @@ struct svc_rqst;
63575 * This is the set of functions for lockd->nfsd communication
63576 */
63577 struct nlmsvc_binding {
63578 - __be32 (*fopen)(struct svc_rqst *,
63579 + __be32 (* const fopen)(struct svc_rqst *,
63580 struct nfs_fh *,
63581 struct file **);
63582 - void (*fclose)(struct file *);
63583 + void (* const fclose)(struct file *);
63584 };
63585
63586 -extern struct nlmsvc_binding * nlmsvc_ops;
63587 +extern const struct nlmsvc_binding * nlmsvc_ops;
63588
63589 /*
63590 * Similar to nfs_client_initdata, but without the NFS-specific
63591 diff -urNp linux-2.6.32.46/include/linux/mca.h linux-2.6.32.46/include/linux/mca.h
63592 --- linux-2.6.32.46/include/linux/mca.h 2011-03-27 14:31:47.000000000 -0400
63593 +++ linux-2.6.32.46/include/linux/mca.h 2011-08-05 20:33:55.000000000 -0400
63594 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
63595 int region);
63596 void * (*mca_transform_memory)(struct mca_device *,
63597 void *memory);
63598 -};
63599 +} __no_const;
63600
63601 struct mca_bus {
63602 u64 default_dma_mask;
63603 diff -urNp linux-2.6.32.46/include/linux/memory.h linux-2.6.32.46/include/linux/memory.h
63604 --- linux-2.6.32.46/include/linux/memory.h 2011-03-27 14:31:47.000000000 -0400
63605 +++ linux-2.6.32.46/include/linux/memory.h 2011-08-05 20:33:55.000000000 -0400
63606 @@ -108,7 +108,7 @@ struct memory_accessor {
63607 size_t count);
63608 ssize_t (*write)(struct memory_accessor *, const char *buf,
63609 off_t offset, size_t count);
63610 -};
63611 +} __no_const;
63612
63613 /*
63614 * Kernel text modification mutex, used for code patching. Users of this lock
63615 diff -urNp linux-2.6.32.46/include/linux/mm.h linux-2.6.32.46/include/linux/mm.h
63616 --- linux-2.6.32.46/include/linux/mm.h 2011-03-27 14:31:47.000000000 -0400
63617 +++ linux-2.6.32.46/include/linux/mm.h 2011-04-17 15:56:46.000000000 -0400
63618 @@ -106,7 +106,14 @@ extern unsigned int kobjsize(const void
63619
63620 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63621 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63622 +
63623 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63624 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63625 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63626 +#else
63627 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63628 +#endif
63629 +
63630 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63631 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63632
63633 @@ -841,12 +848,6 @@ int set_page_dirty(struct page *page);
63634 int set_page_dirty_lock(struct page *page);
63635 int clear_page_dirty_for_io(struct page *page);
63636
63637 -/* Is the vma a continuation of the stack vma above it? */
63638 -static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
63639 -{
63640 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63641 -}
63642 -
63643 extern unsigned long move_page_tables(struct vm_area_struct *vma,
63644 unsigned long old_addr, struct vm_area_struct *new_vma,
63645 unsigned long new_addr, unsigned long len);
63646 @@ -890,6 +891,8 @@ struct shrinker {
63647 extern void register_shrinker(struct shrinker *);
63648 extern void unregister_shrinker(struct shrinker *);
63649
63650 +pgprot_t vm_get_page_prot(unsigned long vm_flags);
63651 +
63652 int vma_wants_writenotify(struct vm_area_struct *vma);
63653
63654 extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
63655 @@ -1162,6 +1165,7 @@ out:
63656 }
63657
63658 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63659 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63660
63661 extern unsigned long do_brk(unsigned long, unsigned long);
63662
63663 @@ -1218,6 +1222,10 @@ extern struct vm_area_struct * find_vma(
63664 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63665 struct vm_area_struct **pprev);
63666
63667 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63668 +extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63669 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63670 +
63671 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63672 NULL if none. Assume start_addr < end_addr. */
63673 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63674 @@ -1234,7 +1242,6 @@ static inline unsigned long vma_pages(st
63675 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
63676 }
63677
63678 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63679 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63680 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63681 unsigned long pfn, unsigned long size, pgprot_t);
63682 @@ -1332,7 +1339,13 @@ extern void memory_failure(unsigned long
63683 extern int __memory_failure(unsigned long pfn, int trapno, int ref);
63684 extern int sysctl_memory_failure_early_kill;
63685 extern int sysctl_memory_failure_recovery;
63686 -extern atomic_long_t mce_bad_pages;
63687 +extern atomic_long_unchecked_t mce_bad_pages;
63688 +
63689 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63690 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63691 +#else
63692 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63693 +#endif
63694
63695 #endif /* __KERNEL__ */
63696 #endif /* _LINUX_MM_H */
63697 diff -urNp linux-2.6.32.46/include/linux/mm_types.h linux-2.6.32.46/include/linux/mm_types.h
63698 --- linux-2.6.32.46/include/linux/mm_types.h 2011-03-27 14:31:47.000000000 -0400
63699 +++ linux-2.6.32.46/include/linux/mm_types.h 2011-04-17 15:56:46.000000000 -0400
63700 @@ -186,6 +186,8 @@ struct vm_area_struct {
63701 #ifdef CONFIG_NUMA
63702 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63703 #endif
63704 +
63705 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63706 };
63707
63708 struct core_thread {
63709 @@ -287,6 +289,24 @@ struct mm_struct {
63710 #ifdef CONFIG_MMU_NOTIFIER
63711 struct mmu_notifier_mm *mmu_notifier_mm;
63712 #endif
63713 +
63714 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63715 + unsigned long pax_flags;
63716 +#endif
63717 +
63718 +#ifdef CONFIG_PAX_DLRESOLVE
63719 + unsigned long call_dl_resolve;
63720 +#endif
63721 +
63722 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63723 + unsigned long call_syscall;
63724 +#endif
63725 +
63726 +#ifdef CONFIG_PAX_ASLR
63727 + unsigned long delta_mmap; /* randomized offset */
63728 + unsigned long delta_stack; /* randomized offset */
63729 +#endif
63730 +
63731 };
63732
63733 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
63734 diff -urNp linux-2.6.32.46/include/linux/mmu_notifier.h linux-2.6.32.46/include/linux/mmu_notifier.h
63735 --- linux-2.6.32.46/include/linux/mmu_notifier.h 2011-03-27 14:31:47.000000000 -0400
63736 +++ linux-2.6.32.46/include/linux/mmu_notifier.h 2011-04-17 15:56:46.000000000 -0400
63737 @@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destr
63738 */
63739 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63740 ({ \
63741 - pte_t __pte; \
63742 + pte_t ___pte; \
63743 struct vm_area_struct *___vma = __vma; \
63744 unsigned long ___address = __address; \
63745 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63746 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63747 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63748 - __pte; \
63749 + ___pte; \
63750 })
63751
63752 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
63753 diff -urNp linux-2.6.32.46/include/linux/mmzone.h linux-2.6.32.46/include/linux/mmzone.h
63754 --- linux-2.6.32.46/include/linux/mmzone.h 2011-03-27 14:31:47.000000000 -0400
63755 +++ linux-2.6.32.46/include/linux/mmzone.h 2011-04-17 15:56:46.000000000 -0400
63756 @@ -350,7 +350,7 @@ struct zone {
63757 unsigned long flags; /* zone flags, see below */
63758
63759 /* Zone statistics */
63760 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63761 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63762
63763 /*
63764 * prev_priority holds the scanning priority for this zone. It is
63765 diff -urNp linux-2.6.32.46/include/linux/mod_devicetable.h linux-2.6.32.46/include/linux/mod_devicetable.h
63766 --- linux-2.6.32.46/include/linux/mod_devicetable.h 2011-03-27 14:31:47.000000000 -0400
63767 +++ linux-2.6.32.46/include/linux/mod_devicetable.h 2011-04-17 15:56:46.000000000 -0400
63768 @@ -12,7 +12,7 @@
63769 typedef unsigned long kernel_ulong_t;
63770 #endif
63771
63772 -#define PCI_ANY_ID (~0)
63773 +#define PCI_ANY_ID ((__u16)~0)
63774
63775 struct pci_device_id {
63776 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63777 @@ -131,7 +131,7 @@ struct usb_device_id {
63778 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63779 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63780
63781 -#define HID_ANY_ID (~0)
63782 +#define HID_ANY_ID (~0U)
63783
63784 struct hid_device_id {
63785 __u16 bus;
63786 diff -urNp linux-2.6.32.46/include/linux/module.h linux-2.6.32.46/include/linux/module.h
63787 --- linux-2.6.32.46/include/linux/module.h 2011-03-27 14:31:47.000000000 -0400
63788 +++ linux-2.6.32.46/include/linux/module.h 2011-08-05 20:33:55.000000000 -0400
63789 @@ -16,6 +16,7 @@
63790 #include <linux/kobject.h>
63791 #include <linux/moduleparam.h>
63792 #include <linux/tracepoint.h>
63793 +#include <linux/fs.h>
63794
63795 #include <asm/local.h>
63796 #include <asm/module.h>
63797 @@ -287,16 +288,16 @@ struct module
63798 int (*init)(void);
63799
63800 /* If this is non-NULL, vfree after init() returns */
63801 - void *module_init;
63802 + void *module_init_rx, *module_init_rw;
63803
63804 /* Here is the actual code + data, vfree'd on unload. */
63805 - void *module_core;
63806 + void *module_core_rx, *module_core_rw;
63807
63808 /* Here are the sizes of the init and core sections */
63809 - unsigned int init_size, core_size;
63810 + unsigned int init_size_rw, core_size_rw;
63811
63812 /* The size of the executable code in each section. */
63813 - unsigned int init_text_size, core_text_size;
63814 + unsigned int init_size_rx, core_size_rx;
63815
63816 /* Arch-specific module values */
63817 struct mod_arch_specific arch;
63818 @@ -345,6 +346,10 @@ struct module
63819 #ifdef CONFIG_EVENT_TRACING
63820 struct ftrace_event_call *trace_events;
63821 unsigned int num_trace_events;
63822 + struct file_operations trace_id;
63823 + struct file_operations trace_enable;
63824 + struct file_operations trace_format;
63825 + struct file_operations trace_filter;
63826 #endif
63827 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63828 unsigned long *ftrace_callsites;
63829 @@ -393,16 +398,46 @@ struct module *__module_address(unsigned
63830 bool is_module_address(unsigned long addr);
63831 bool is_module_text_address(unsigned long addr);
63832
63833 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63834 +{
63835 +
63836 +#ifdef CONFIG_PAX_KERNEXEC
63837 + if (ktla_ktva(addr) >= (unsigned long)start &&
63838 + ktla_ktva(addr) < (unsigned long)start + size)
63839 + return 1;
63840 +#endif
63841 +
63842 + return ((void *)addr >= start && (void *)addr < start + size);
63843 +}
63844 +
63845 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63846 +{
63847 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63848 +}
63849 +
63850 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63851 +{
63852 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63853 +}
63854 +
63855 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63856 +{
63857 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63858 +}
63859 +
63860 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63861 +{
63862 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63863 +}
63864 +
63865 static inline int within_module_core(unsigned long addr, struct module *mod)
63866 {
63867 - return (unsigned long)mod->module_core <= addr &&
63868 - addr < (unsigned long)mod->module_core + mod->core_size;
63869 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63870 }
63871
63872 static inline int within_module_init(unsigned long addr, struct module *mod)
63873 {
63874 - return (unsigned long)mod->module_init <= addr &&
63875 - addr < (unsigned long)mod->module_init + mod->init_size;
63876 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63877 }
63878
63879 /* Search for module by name: must hold module_mutex. */
63880 diff -urNp linux-2.6.32.46/include/linux/moduleloader.h linux-2.6.32.46/include/linux/moduleloader.h
63881 --- linux-2.6.32.46/include/linux/moduleloader.h 2011-03-27 14:31:47.000000000 -0400
63882 +++ linux-2.6.32.46/include/linux/moduleloader.h 2011-04-17 15:56:46.000000000 -0400
63883 @@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
63884 sections. Returns NULL on failure. */
63885 void *module_alloc(unsigned long size);
63886
63887 +#ifdef CONFIG_PAX_KERNEXEC
63888 +void *module_alloc_exec(unsigned long size);
63889 +#else
63890 +#define module_alloc_exec(x) module_alloc(x)
63891 +#endif
63892 +
63893 /* Free memory returned from module_alloc. */
63894 void module_free(struct module *mod, void *module_region);
63895
63896 +#ifdef CONFIG_PAX_KERNEXEC
63897 +void module_free_exec(struct module *mod, void *module_region);
63898 +#else
63899 +#define module_free_exec(x, y) module_free((x), (y))
63900 +#endif
63901 +
63902 /* Apply the given relocation to the (simplified) ELF. Return -error
63903 or 0. */
63904 int apply_relocate(Elf_Shdr *sechdrs,
63905 diff -urNp linux-2.6.32.46/include/linux/moduleparam.h linux-2.6.32.46/include/linux/moduleparam.h
63906 --- linux-2.6.32.46/include/linux/moduleparam.h 2011-03-27 14:31:47.000000000 -0400
63907 +++ linux-2.6.32.46/include/linux/moduleparam.h 2011-04-17 15:56:46.000000000 -0400
63908 @@ -132,7 +132,7 @@ struct kparam_array
63909
63910 /* Actually copy string: maxlen param is usually sizeof(string). */
63911 #define module_param_string(name, string, len, perm) \
63912 - static const struct kparam_string __param_string_##name \
63913 + static const struct kparam_string __param_string_##name __used \
63914 = { len, string }; \
63915 __module_param_call(MODULE_PARAM_PREFIX, name, \
63916 param_set_copystring, param_get_string, \
63917 @@ -211,7 +211,7 @@ extern int param_get_invbool(char *buffe
63918
63919 /* Comma-separated array: *nump is set to number they actually specified. */
63920 #define module_param_array_named(name, array, type, nump, perm) \
63921 - static const struct kparam_array __param_arr_##name \
63922 + static const struct kparam_array __param_arr_##name __used \
63923 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
63924 sizeof(array[0]), array }; \
63925 __module_param_call(MODULE_PARAM_PREFIX, name, \
63926 diff -urNp linux-2.6.32.46/include/linux/mutex.h linux-2.6.32.46/include/linux/mutex.h
63927 --- linux-2.6.32.46/include/linux/mutex.h 2011-03-27 14:31:47.000000000 -0400
63928 +++ linux-2.6.32.46/include/linux/mutex.h 2011-04-17 15:56:46.000000000 -0400
63929 @@ -51,7 +51,7 @@ struct mutex {
63930 spinlock_t wait_lock;
63931 struct list_head wait_list;
63932 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
63933 - struct thread_info *owner;
63934 + struct task_struct *owner;
63935 #endif
63936 #ifdef CONFIG_DEBUG_MUTEXES
63937 const char *name;
63938 diff -urNp linux-2.6.32.46/include/linux/namei.h linux-2.6.32.46/include/linux/namei.h
63939 --- linux-2.6.32.46/include/linux/namei.h 2011-03-27 14:31:47.000000000 -0400
63940 +++ linux-2.6.32.46/include/linux/namei.h 2011-04-17 15:56:46.000000000 -0400
63941 @@ -22,7 +22,7 @@ struct nameidata {
63942 unsigned int flags;
63943 int last_type;
63944 unsigned depth;
63945 - char *saved_names[MAX_NESTED_LINKS + 1];
63946 + const char *saved_names[MAX_NESTED_LINKS + 1];
63947
63948 /* Intent data */
63949 union {
63950 @@ -84,12 +84,12 @@ extern int follow_up(struct path *);
63951 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63952 extern void unlock_rename(struct dentry *, struct dentry *);
63953
63954 -static inline void nd_set_link(struct nameidata *nd, char *path)
63955 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63956 {
63957 nd->saved_names[nd->depth] = path;
63958 }
63959
63960 -static inline char *nd_get_link(struct nameidata *nd)
63961 +static inline const char *nd_get_link(const struct nameidata *nd)
63962 {
63963 return nd->saved_names[nd->depth];
63964 }
63965 diff -urNp linux-2.6.32.46/include/linux/netdevice.h linux-2.6.32.46/include/linux/netdevice.h
63966 --- linux-2.6.32.46/include/linux/netdevice.h 2011-08-09 18:35:30.000000000 -0400
63967 +++ linux-2.6.32.46/include/linux/netdevice.h 2011-08-23 21:22:38.000000000 -0400
63968 @@ -637,6 +637,7 @@ struct net_device_ops {
63969 u16 xid);
63970 #endif
63971 };
63972 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63973
63974 /*
63975 * The DEVICE structure.
63976 diff -urNp linux-2.6.32.46/include/linux/netfilter/xt_gradm.h linux-2.6.32.46/include/linux/netfilter/xt_gradm.h
63977 --- linux-2.6.32.46/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
63978 +++ linux-2.6.32.46/include/linux/netfilter/xt_gradm.h 2011-04-17 15:56:46.000000000 -0400
63979 @@ -0,0 +1,9 @@
63980 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63981 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63982 +
63983 +struct xt_gradm_mtinfo {
63984 + __u16 flags;
63985 + __u16 invflags;
63986 +};
63987 +
63988 +#endif
63989 diff -urNp linux-2.6.32.46/include/linux/nodemask.h linux-2.6.32.46/include/linux/nodemask.h
63990 --- linux-2.6.32.46/include/linux/nodemask.h 2011-03-27 14:31:47.000000000 -0400
63991 +++ linux-2.6.32.46/include/linux/nodemask.h 2011-04-17 15:56:46.000000000 -0400
63992 @@ -464,11 +464,11 @@ static inline int num_node_state(enum no
63993
63994 #define any_online_node(mask) \
63995 ({ \
63996 - int node; \
63997 - for_each_node_mask(node, (mask)) \
63998 - if (node_online(node)) \
63999 + int __node; \
64000 + for_each_node_mask(__node, (mask)) \
64001 + if (node_online(__node)) \
64002 break; \
64003 - node; \
64004 + __node; \
64005 })
64006
64007 #define num_online_nodes() num_node_state(N_ONLINE)
64008 diff -urNp linux-2.6.32.46/include/linux/oprofile.h linux-2.6.32.46/include/linux/oprofile.h
64009 --- linux-2.6.32.46/include/linux/oprofile.h 2011-03-27 14:31:47.000000000 -0400
64010 +++ linux-2.6.32.46/include/linux/oprofile.h 2011-04-17 15:56:46.000000000 -0400
64011 @@ -129,9 +129,9 @@ int oprofilefs_create_ulong(struct super
64012 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64013 char const * name, ulong * val);
64014
64015 -/** Create a file for read-only access to an atomic_t. */
64016 +/** Create a file for read-only access to an atomic_unchecked_t. */
64017 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64018 - char const * name, atomic_t * val);
64019 + char const * name, atomic_unchecked_t * val);
64020
64021 /** create a directory */
64022 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64023 diff -urNp linux-2.6.32.46/include/linux/pagemap.h linux-2.6.32.46/include/linux/pagemap.h
64024 --- linux-2.6.32.46/include/linux/pagemap.h 2011-03-27 14:31:47.000000000 -0400
64025 +++ linux-2.6.32.46/include/linux/pagemap.h 2011-08-17 19:36:28.000000000 -0400
64026 @@ -425,6 +425,7 @@ static inline int fault_in_pages_readabl
64027 if (((unsigned long)uaddr & PAGE_MASK) !=
64028 ((unsigned long)end & PAGE_MASK))
64029 ret = __get_user(c, end);
64030 + (void)c;
64031 }
64032 return ret;
64033 }
64034 diff -urNp linux-2.6.32.46/include/linux/perf_event.h linux-2.6.32.46/include/linux/perf_event.h
64035 --- linux-2.6.32.46/include/linux/perf_event.h 2011-03-27 14:31:47.000000000 -0400
64036 +++ linux-2.6.32.46/include/linux/perf_event.h 2011-05-04 17:56:28.000000000 -0400
64037 @@ -476,7 +476,7 @@ struct hw_perf_event {
64038 struct hrtimer hrtimer;
64039 };
64040 };
64041 - atomic64_t prev_count;
64042 + atomic64_unchecked_t prev_count;
64043 u64 sample_period;
64044 u64 last_period;
64045 atomic64_t period_left;
64046 @@ -557,7 +557,7 @@ struct perf_event {
64047 const struct pmu *pmu;
64048
64049 enum perf_event_active_state state;
64050 - atomic64_t count;
64051 + atomic64_unchecked_t count;
64052
64053 /*
64054 * These are the total time in nanoseconds that the event
64055 @@ -595,8 +595,8 @@ struct perf_event {
64056 * These accumulate total time (in nanoseconds) that children
64057 * events have been enabled and running, respectively.
64058 */
64059 - atomic64_t child_total_time_enabled;
64060 - atomic64_t child_total_time_running;
64061 + atomic64_unchecked_t child_total_time_enabled;
64062 + atomic64_unchecked_t child_total_time_running;
64063
64064 /*
64065 * Protect attach/detach and child_list:
64066 diff -urNp linux-2.6.32.46/include/linux/pipe_fs_i.h linux-2.6.32.46/include/linux/pipe_fs_i.h
64067 --- linux-2.6.32.46/include/linux/pipe_fs_i.h 2011-03-27 14:31:47.000000000 -0400
64068 +++ linux-2.6.32.46/include/linux/pipe_fs_i.h 2011-04-17 15:56:46.000000000 -0400
64069 @@ -46,9 +46,9 @@ struct pipe_inode_info {
64070 wait_queue_head_t wait;
64071 unsigned int nrbufs, curbuf;
64072 struct page *tmp_page;
64073 - unsigned int readers;
64074 - unsigned int writers;
64075 - unsigned int waiting_writers;
64076 + atomic_t readers;
64077 + atomic_t writers;
64078 + atomic_t waiting_writers;
64079 unsigned int r_counter;
64080 unsigned int w_counter;
64081 struct fasync_struct *fasync_readers;
64082 diff -urNp linux-2.6.32.46/include/linux/poison.h linux-2.6.32.46/include/linux/poison.h
64083 --- linux-2.6.32.46/include/linux/poison.h 2011-03-27 14:31:47.000000000 -0400
64084 +++ linux-2.6.32.46/include/linux/poison.h 2011-04-17 15:56:46.000000000 -0400
64085 @@ -19,8 +19,8 @@
64086 * under normal circumstances, used to verify that nobody uses
64087 * non-initialized list entries.
64088 */
64089 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64090 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64091 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64092 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64093
64094 /********** include/linux/timer.h **********/
64095 /*
64096 diff -urNp linux-2.6.32.46/include/linux/posix-timers.h linux-2.6.32.46/include/linux/posix-timers.h
64097 --- linux-2.6.32.46/include/linux/posix-timers.h 2011-03-27 14:31:47.000000000 -0400
64098 +++ linux-2.6.32.46/include/linux/posix-timers.h 2011-08-05 20:33:55.000000000 -0400
64099 @@ -67,7 +67,7 @@ struct k_itimer {
64100 };
64101
64102 struct k_clock {
64103 - int res; /* in nanoseconds */
64104 + const int res; /* in nanoseconds */
64105 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
64106 int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
64107 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
64108 diff -urNp linux-2.6.32.46/include/linux/preempt.h linux-2.6.32.46/include/linux/preempt.h
64109 --- linux-2.6.32.46/include/linux/preempt.h 2011-03-27 14:31:47.000000000 -0400
64110 +++ linux-2.6.32.46/include/linux/preempt.h 2011-08-05 20:33:55.000000000 -0400
64111 @@ -110,7 +110,7 @@ struct preempt_ops {
64112 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64113 void (*sched_out)(struct preempt_notifier *notifier,
64114 struct task_struct *next);
64115 -};
64116 +} __no_const;
64117
64118 /**
64119 * preempt_notifier - key for installing preemption notifiers
64120 diff -urNp linux-2.6.32.46/include/linux/proc_fs.h linux-2.6.32.46/include/linux/proc_fs.h
64121 --- linux-2.6.32.46/include/linux/proc_fs.h 2011-03-27 14:31:47.000000000 -0400
64122 +++ linux-2.6.32.46/include/linux/proc_fs.h 2011-08-05 20:33:55.000000000 -0400
64123 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
64124 return proc_create_data(name, mode, parent, proc_fops, NULL);
64125 }
64126
64127 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
64128 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64129 +{
64130 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64131 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64132 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64133 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64134 +#else
64135 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64136 +#endif
64137 +}
64138 +
64139 +
64140 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64141 mode_t mode, struct proc_dir_entry *base,
64142 read_proc_t *read_proc, void * data)
64143 @@ -256,7 +269,7 @@ union proc_op {
64144 int (*proc_show)(struct seq_file *m,
64145 struct pid_namespace *ns, struct pid *pid,
64146 struct task_struct *task);
64147 -};
64148 +} __no_const;
64149
64150 struct ctl_table_header;
64151 struct ctl_table;
64152 diff -urNp linux-2.6.32.46/include/linux/ptrace.h linux-2.6.32.46/include/linux/ptrace.h
64153 --- linux-2.6.32.46/include/linux/ptrace.h 2011-03-27 14:31:47.000000000 -0400
64154 +++ linux-2.6.32.46/include/linux/ptrace.h 2011-04-17 15:56:46.000000000 -0400
64155 @@ -96,10 +96,10 @@ extern void __ptrace_unlink(struct task_
64156 extern void exit_ptrace(struct task_struct *tracer);
64157 #define PTRACE_MODE_READ 1
64158 #define PTRACE_MODE_ATTACH 2
64159 -/* Returns 0 on success, -errno on denial. */
64160 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
64161 /* Returns true on success, false on denial. */
64162 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
64163 +/* Returns true on success, false on denial. */
64164 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
64165
64166 static inline int ptrace_reparented(struct task_struct *child)
64167 {
64168 diff -urNp linux-2.6.32.46/include/linux/random.h linux-2.6.32.46/include/linux/random.h
64169 --- linux-2.6.32.46/include/linux/random.h 2011-08-16 20:37:25.000000000 -0400
64170 +++ linux-2.6.32.46/include/linux/random.h 2011-08-07 19:48:09.000000000 -0400
64171 @@ -63,6 +63,11 @@ unsigned long randomize_range(unsigned l
64172 u32 random32(void);
64173 void srandom32(u32 seed);
64174
64175 +static inline unsigned long pax_get_random_long(void)
64176 +{
64177 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64178 +}
64179 +
64180 #endif /* __KERNEL___ */
64181
64182 #endif /* _LINUX_RANDOM_H */
64183 diff -urNp linux-2.6.32.46/include/linux/reboot.h linux-2.6.32.46/include/linux/reboot.h
64184 --- linux-2.6.32.46/include/linux/reboot.h 2011-03-27 14:31:47.000000000 -0400
64185 +++ linux-2.6.32.46/include/linux/reboot.h 2011-05-22 23:02:06.000000000 -0400
64186 @@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
64187 * Architecture-specific implementations of sys_reboot commands.
64188 */
64189
64190 -extern void machine_restart(char *cmd);
64191 -extern void machine_halt(void);
64192 -extern void machine_power_off(void);
64193 +extern void machine_restart(char *cmd) __noreturn;
64194 +extern void machine_halt(void) __noreturn;
64195 +extern void machine_power_off(void) __noreturn;
64196
64197 extern void machine_shutdown(void);
64198 struct pt_regs;
64199 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
64200 */
64201
64202 extern void kernel_restart_prepare(char *cmd);
64203 -extern void kernel_restart(char *cmd);
64204 -extern void kernel_halt(void);
64205 -extern void kernel_power_off(void);
64206 +extern void kernel_restart(char *cmd) __noreturn;
64207 +extern void kernel_halt(void) __noreturn;
64208 +extern void kernel_power_off(void) __noreturn;
64209
64210 void ctrl_alt_del(void);
64211
64212 @@ -75,7 +75,7 @@ extern int orderly_poweroff(bool force);
64213 * Emergency restart, callable from an interrupt handler.
64214 */
64215
64216 -extern void emergency_restart(void);
64217 +extern void emergency_restart(void) __noreturn;
64218 #include <asm/emergency-restart.h>
64219
64220 #endif
64221 diff -urNp linux-2.6.32.46/include/linux/reiserfs_fs.h linux-2.6.32.46/include/linux/reiserfs_fs.h
64222 --- linux-2.6.32.46/include/linux/reiserfs_fs.h 2011-03-27 14:31:47.000000000 -0400
64223 +++ linux-2.6.32.46/include/linux/reiserfs_fs.h 2011-04-17 15:56:46.000000000 -0400
64224 @@ -1326,7 +1326,7 @@ static inline loff_t max_reiserfs_offset
64225 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64226
64227 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64228 -#define get_generation(s) atomic_read (&fs_generation(s))
64229 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64230 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64231 #define __fs_changed(gen,s) (gen != get_generation (s))
64232 #define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
64233 @@ -1534,24 +1534,24 @@ static inline struct super_block *sb_fro
64234 */
64235
64236 struct item_operations {
64237 - int (*bytes_number) (struct item_head * ih, int block_size);
64238 - void (*decrement_key) (struct cpu_key *);
64239 - int (*is_left_mergeable) (struct reiserfs_key * ih,
64240 + int (* const bytes_number) (struct item_head * ih, int block_size);
64241 + void (* const decrement_key) (struct cpu_key *);
64242 + int (* const is_left_mergeable) (struct reiserfs_key * ih,
64243 unsigned long bsize);
64244 - void (*print_item) (struct item_head *, char *item);
64245 - void (*check_item) (struct item_head *, char *item);
64246 + void (* const print_item) (struct item_head *, char *item);
64247 + void (* const check_item) (struct item_head *, char *item);
64248
64249 - int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64250 + int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64251 int is_affected, int insert_size);
64252 - int (*check_left) (struct virtual_item * vi, int free,
64253 + int (* const check_left) (struct virtual_item * vi, int free,
64254 int start_skip, int end_skip);
64255 - int (*check_right) (struct virtual_item * vi, int free);
64256 - int (*part_size) (struct virtual_item * vi, int from, int to);
64257 - int (*unit_num) (struct virtual_item * vi);
64258 - void (*print_vi) (struct virtual_item * vi);
64259 + int (* const check_right) (struct virtual_item * vi, int free);
64260 + int (* const part_size) (struct virtual_item * vi, int from, int to);
64261 + int (* const unit_num) (struct virtual_item * vi);
64262 + void (* const print_vi) (struct virtual_item * vi);
64263 };
64264
64265 -extern struct item_operations *item_ops[TYPE_ANY + 1];
64266 +extern const struct item_operations * const item_ops[TYPE_ANY + 1];
64267
64268 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
64269 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
64270 diff -urNp linux-2.6.32.46/include/linux/reiserfs_fs_sb.h linux-2.6.32.46/include/linux/reiserfs_fs_sb.h
64271 --- linux-2.6.32.46/include/linux/reiserfs_fs_sb.h 2011-03-27 14:31:47.000000000 -0400
64272 +++ linux-2.6.32.46/include/linux/reiserfs_fs_sb.h 2011-04-17 15:56:46.000000000 -0400
64273 @@ -377,7 +377,7 @@ struct reiserfs_sb_info {
64274 /* Comment? -Hans */
64275 wait_queue_head_t s_wait;
64276 /* To be obsoleted soon by per buffer seals.. -Hans */
64277 - atomic_t s_generation_counter; // increased by one every time the
64278 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64279 // tree gets re-balanced
64280 unsigned long s_properties; /* File system properties. Currently holds
64281 on-disk FS format */
64282 diff -urNp linux-2.6.32.46/include/linux/relay.h linux-2.6.32.46/include/linux/relay.h
64283 --- linux-2.6.32.46/include/linux/relay.h 2011-03-27 14:31:47.000000000 -0400
64284 +++ linux-2.6.32.46/include/linux/relay.h 2011-08-05 20:33:55.000000000 -0400
64285 @@ -159,7 +159,7 @@ struct rchan_callbacks
64286 * The callback should return 0 if successful, negative if not.
64287 */
64288 int (*remove_buf_file)(struct dentry *dentry);
64289 -};
64290 +} __no_const;
64291
64292 /*
64293 * CONFIG_RELAY kernel API, kernel/relay.c
64294 diff -urNp linux-2.6.32.46/include/linux/rfkill.h linux-2.6.32.46/include/linux/rfkill.h
64295 --- linux-2.6.32.46/include/linux/rfkill.h 2011-03-27 14:31:47.000000000 -0400
64296 +++ linux-2.6.32.46/include/linux/rfkill.h 2011-08-23 21:22:38.000000000 -0400
64297 @@ -144,6 +144,7 @@ struct rfkill_ops {
64298 void (*query)(struct rfkill *rfkill, void *data);
64299 int (*set_block)(void *data, bool blocked);
64300 };
64301 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64302
64303 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64304 /**
64305 diff -urNp linux-2.6.32.46/include/linux/sched.h linux-2.6.32.46/include/linux/sched.h
64306 --- linux-2.6.32.46/include/linux/sched.h 2011-03-27 14:31:47.000000000 -0400
64307 +++ linux-2.6.32.46/include/linux/sched.h 2011-08-11 19:48:55.000000000 -0400
64308 @@ -101,6 +101,7 @@ struct bio;
64309 struct fs_struct;
64310 struct bts_context;
64311 struct perf_event_context;
64312 +struct linux_binprm;
64313
64314 /*
64315 * List of flags we want to share for kernel threads,
64316 @@ -350,7 +351,7 @@ extern signed long schedule_timeout_kill
64317 extern signed long schedule_timeout_uninterruptible(signed long timeout);
64318 asmlinkage void __schedule(void);
64319 asmlinkage void schedule(void);
64320 -extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
64321 +extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
64322
64323 struct nsproxy;
64324 struct user_namespace;
64325 @@ -371,9 +372,12 @@ struct user_namespace;
64326 #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64327
64328 extern int sysctl_max_map_count;
64329 +extern unsigned long sysctl_heap_stack_gap;
64330
64331 #include <linux/aio.h>
64332
64333 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64334 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64335 extern unsigned long
64336 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64337 unsigned long, unsigned long);
64338 @@ -666,6 +670,16 @@ struct signal_struct {
64339 struct tty_audit_buf *tty_audit_buf;
64340 #endif
64341
64342 +#ifdef CONFIG_GRKERNSEC
64343 + u32 curr_ip;
64344 + u32 saved_ip;
64345 + u32 gr_saddr;
64346 + u32 gr_daddr;
64347 + u16 gr_sport;
64348 + u16 gr_dport;
64349 + u8 used_accept:1;
64350 +#endif
64351 +
64352 int oom_adj; /* OOM kill score adjustment (bit shift) */
64353 };
64354
64355 @@ -723,6 +737,11 @@ struct user_struct {
64356 struct key *session_keyring; /* UID's default session keyring */
64357 #endif
64358
64359 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64360 + unsigned int banned;
64361 + unsigned long ban_expires;
64362 +#endif
64363 +
64364 /* Hash table maintenance information */
64365 struct hlist_node uidhash_node;
64366 uid_t uid;
64367 @@ -1328,8 +1347,8 @@ struct task_struct {
64368 struct list_head thread_group;
64369
64370 struct completion *vfork_done; /* for vfork() */
64371 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64372 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64373 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64374 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64375
64376 cputime_t utime, stime, utimescaled, stimescaled;
64377 cputime_t gtime;
64378 @@ -1343,16 +1362,6 @@ struct task_struct {
64379 struct task_cputime cputime_expires;
64380 struct list_head cpu_timers[3];
64381
64382 -/* process credentials */
64383 - const struct cred *real_cred; /* objective and real subjective task
64384 - * credentials (COW) */
64385 - const struct cred *cred; /* effective (overridable) subjective task
64386 - * credentials (COW) */
64387 - struct mutex cred_guard_mutex; /* guard against foreign influences on
64388 - * credential calculations
64389 - * (notably. ptrace) */
64390 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64391 -
64392 char comm[TASK_COMM_LEN]; /* executable name excluding path
64393 - access with [gs]et_task_comm (which lock
64394 it with task_lock())
64395 @@ -1369,6 +1378,10 @@ struct task_struct {
64396 #endif
64397 /* CPU-specific state of this task */
64398 struct thread_struct thread;
64399 +/* thread_info moved to task_struct */
64400 +#ifdef CONFIG_X86
64401 + struct thread_info tinfo;
64402 +#endif
64403 /* filesystem information */
64404 struct fs_struct *fs;
64405 /* open file information */
64406 @@ -1436,6 +1449,15 @@ struct task_struct {
64407 int hardirq_context;
64408 int softirq_context;
64409 #endif
64410 +
64411 +/* process credentials */
64412 + const struct cred *real_cred; /* objective and real subjective task
64413 + * credentials (COW) */
64414 + struct mutex cred_guard_mutex; /* guard against foreign influences on
64415 + * credential calculations
64416 + * (notably. ptrace) */
64417 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64418 +
64419 #ifdef CONFIG_LOCKDEP
64420 # define MAX_LOCK_DEPTH 48UL
64421 u64 curr_chain_key;
64422 @@ -1456,6 +1478,9 @@ struct task_struct {
64423
64424 struct backing_dev_info *backing_dev_info;
64425
64426 + const struct cred *cred; /* effective (overridable) subjective task
64427 + * credentials (COW) */
64428 +
64429 struct io_context *io_context;
64430
64431 unsigned long ptrace_message;
64432 @@ -1519,6 +1544,21 @@ struct task_struct {
64433 unsigned long default_timer_slack_ns;
64434
64435 struct list_head *scm_work_list;
64436 +
64437 +#ifdef CONFIG_GRKERNSEC
64438 + /* grsecurity */
64439 + struct dentry *gr_chroot_dentry;
64440 + struct acl_subject_label *acl;
64441 + struct acl_role_label *role;
64442 + struct file *exec_file;
64443 + u16 acl_role_id;
64444 + /* is this the task that authenticated to the special role */
64445 + u8 acl_sp_role;
64446 + u8 is_writable;
64447 + u8 brute;
64448 + u8 gr_is_chrooted;
64449 +#endif
64450 +
64451 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64452 /* Index of current stored adress in ret_stack */
64453 int curr_ret_stack;
64454 @@ -1542,6 +1582,57 @@ struct task_struct {
64455 #endif /* CONFIG_TRACING */
64456 };
64457
64458 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64459 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64460 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64461 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64462 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64463 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64464 +
64465 +#ifdef CONFIG_PAX_SOFTMODE
64466 +extern int pax_softmode;
64467 +#endif
64468 +
64469 +extern int pax_check_flags(unsigned long *);
64470 +
64471 +/* if tsk != current then task_lock must be held on it */
64472 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64473 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64474 +{
64475 + if (likely(tsk->mm))
64476 + return tsk->mm->pax_flags;
64477 + else
64478 + return 0UL;
64479 +}
64480 +
64481 +/* if tsk != current then task_lock must be held on it */
64482 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64483 +{
64484 + if (likely(tsk->mm)) {
64485 + tsk->mm->pax_flags = flags;
64486 + return 0;
64487 + }
64488 + return -EINVAL;
64489 +}
64490 +#endif
64491 +
64492 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64493 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64494 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64495 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64496 +#endif
64497 +
64498 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64499 +extern void pax_report_insns(void *pc, void *sp);
64500 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64501 +extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
64502 +
64503 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
64504 +extern void pax_track_stack(void);
64505 +#else
64506 +static inline void pax_track_stack(void) {}
64507 +#endif
64508 +
64509 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64510 #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
64511
64512 @@ -1740,7 +1831,7 @@ extern void thread_group_times(struct ta
64513 #define PF_DUMPCORE 0x00000200 /* dumped core */
64514 #define PF_SIGNALED 0x00000400 /* killed by a signal */
64515 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
64516 -#define PF_FLUSHER 0x00001000 /* responsible for disk writeback */
64517 +#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
64518 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
64519 #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */
64520 #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
64521 @@ -1978,7 +2069,9 @@ void yield(void);
64522 extern struct exec_domain default_exec_domain;
64523
64524 union thread_union {
64525 +#ifndef CONFIG_X86
64526 struct thread_info thread_info;
64527 +#endif
64528 unsigned long stack[THREAD_SIZE/sizeof(long)];
64529 };
64530
64531 @@ -2011,6 +2104,7 @@ extern struct pid_namespace init_pid_ns;
64532 */
64533
64534 extern struct task_struct *find_task_by_vpid(pid_t nr);
64535 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64536 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64537 struct pid_namespace *ns);
64538
64539 @@ -2155,7 +2249,7 @@ extern void __cleanup_sighand(struct sig
64540 extern void exit_itimers(struct signal_struct *);
64541 extern void flush_itimer_signals(void);
64542
64543 -extern NORET_TYPE void do_group_exit(int);
64544 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
64545
64546 extern void daemonize(const char *, ...);
64547 extern int allow_signal(int);
64548 @@ -2284,13 +2378,17 @@ static inline unsigned long *end_of_stac
64549
64550 #endif
64551
64552 -static inline int object_is_on_stack(void *obj)
64553 +static inline int object_starts_on_stack(void *obj)
64554 {
64555 - void *stack = task_stack_page(current);
64556 + const void *stack = task_stack_page(current);
64557
64558 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64559 }
64560
64561 +#ifdef CONFIG_PAX_USERCOPY
64562 +extern int object_is_on_stack(const void *obj, unsigned long len);
64563 +#endif
64564 +
64565 extern void thread_info_cache_init(void);
64566
64567 #ifdef CONFIG_DEBUG_STACK_USAGE
64568 diff -urNp linux-2.6.32.46/include/linux/screen_info.h linux-2.6.32.46/include/linux/screen_info.h
64569 --- linux-2.6.32.46/include/linux/screen_info.h 2011-03-27 14:31:47.000000000 -0400
64570 +++ linux-2.6.32.46/include/linux/screen_info.h 2011-04-17 15:56:46.000000000 -0400
64571 @@ -42,7 +42,8 @@ struct screen_info {
64572 __u16 pages; /* 0x32 */
64573 __u16 vesa_attributes; /* 0x34 */
64574 __u32 capabilities; /* 0x36 */
64575 - __u8 _reserved[6]; /* 0x3a */
64576 + __u16 vesapm_size; /* 0x3a */
64577 + __u8 _reserved[4]; /* 0x3c */
64578 } __attribute__((packed));
64579
64580 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64581 diff -urNp linux-2.6.32.46/include/linux/security.h linux-2.6.32.46/include/linux/security.h
64582 --- linux-2.6.32.46/include/linux/security.h 2011-03-27 14:31:47.000000000 -0400
64583 +++ linux-2.6.32.46/include/linux/security.h 2011-04-17 15:56:46.000000000 -0400
64584 @@ -34,6 +34,7 @@
64585 #include <linux/key.h>
64586 #include <linux/xfrm.h>
64587 #include <linux/gfp.h>
64588 +#include <linux/grsecurity.h>
64589 #include <net/flow.h>
64590
64591 /* Maximum number of letters for an LSM name string */
64592 diff -urNp linux-2.6.32.46/include/linux/seq_file.h linux-2.6.32.46/include/linux/seq_file.h
64593 --- linux-2.6.32.46/include/linux/seq_file.h 2011-03-27 14:31:47.000000000 -0400
64594 +++ linux-2.6.32.46/include/linux/seq_file.h 2011-08-23 21:22:38.000000000 -0400
64595 @@ -32,6 +32,7 @@ struct seq_operations {
64596 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64597 int (*show) (struct seq_file *m, void *v);
64598 };
64599 +typedef struct seq_operations __no_const seq_operations_no_const;
64600
64601 #define SEQ_SKIP 1
64602
64603 diff -urNp linux-2.6.32.46/include/linux/shm.h linux-2.6.32.46/include/linux/shm.h
64604 --- linux-2.6.32.46/include/linux/shm.h 2011-03-27 14:31:47.000000000 -0400
64605 +++ linux-2.6.32.46/include/linux/shm.h 2011-04-17 15:56:46.000000000 -0400
64606 @@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
64607 pid_t shm_cprid;
64608 pid_t shm_lprid;
64609 struct user_struct *mlock_user;
64610 +#ifdef CONFIG_GRKERNSEC
64611 + time_t shm_createtime;
64612 + pid_t shm_lapid;
64613 +#endif
64614 };
64615
64616 /* shm_mode upper byte flags */
64617 diff -urNp linux-2.6.32.46/include/linux/skbuff.h linux-2.6.32.46/include/linux/skbuff.h
64618 --- linux-2.6.32.46/include/linux/skbuff.h 2011-03-27 14:31:47.000000000 -0400
64619 +++ linux-2.6.32.46/include/linux/skbuff.h 2011-08-21 15:27:56.000000000 -0400
64620 @@ -14,6 +14,7 @@
64621 #ifndef _LINUX_SKBUFF_H
64622 #define _LINUX_SKBUFF_H
64623
64624 +#include <linux/const.h>
64625 #include <linux/kernel.h>
64626 #include <linux/kmemcheck.h>
64627 #include <linux/compiler.h>
64628 @@ -544,7 +545,7 @@ static inline union skb_shared_tx *skb_t
64629 */
64630 static inline int skb_queue_empty(const struct sk_buff_head *list)
64631 {
64632 - return list->next == (struct sk_buff *)list;
64633 + return list->next == (const struct sk_buff *)list;
64634 }
64635
64636 /**
64637 @@ -557,7 +558,7 @@ static inline int skb_queue_empty(const
64638 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64639 const struct sk_buff *skb)
64640 {
64641 - return (skb->next == (struct sk_buff *) list);
64642 + return (skb->next == (const struct sk_buff *) list);
64643 }
64644
64645 /**
64646 @@ -570,7 +571,7 @@ static inline bool skb_queue_is_last(con
64647 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64648 const struct sk_buff *skb)
64649 {
64650 - return (skb->prev == (struct sk_buff *) list);
64651 + return (skb->prev == (const struct sk_buff *) list);
64652 }
64653
64654 /**
64655 @@ -1367,7 +1368,7 @@ static inline int skb_network_offset(con
64656 * headroom, you should not reduce this.
64657 */
64658 #ifndef NET_SKB_PAD
64659 -#define NET_SKB_PAD 32
64660 +#define NET_SKB_PAD (_AC(32,UL))
64661 #endif
64662
64663 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64664 diff -urNp linux-2.6.32.46/include/linux/slab.h linux-2.6.32.46/include/linux/slab.h
64665 --- linux-2.6.32.46/include/linux/slab.h 2011-03-27 14:31:47.000000000 -0400
64666 +++ linux-2.6.32.46/include/linux/slab.h 2011-04-17 15:56:46.000000000 -0400
64667 @@ -11,12 +11,20 @@
64668
64669 #include <linux/gfp.h>
64670 #include <linux/types.h>
64671 +#include <linux/err.h>
64672
64673 /*
64674 * Flags to pass to kmem_cache_create().
64675 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64676 */
64677 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64678 +
64679 +#ifdef CONFIG_PAX_USERCOPY
64680 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64681 +#else
64682 +#define SLAB_USERCOPY 0x00000000UL
64683 +#endif
64684 +
64685 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64686 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64687 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64688 @@ -82,10 +90,13 @@
64689 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64690 * Both make kfree a no-op.
64691 */
64692 -#define ZERO_SIZE_PTR ((void *)16)
64693 +#define ZERO_SIZE_PTR \
64694 +({ \
64695 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64696 + (void *)(-MAX_ERRNO-1L); \
64697 +})
64698
64699 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64700 - (unsigned long)ZERO_SIZE_PTR)
64701 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64702
64703 /*
64704 * struct kmem_cache related prototypes
64705 @@ -138,6 +149,7 @@ void * __must_check krealloc(const void
64706 void kfree(const void *);
64707 void kzfree(const void *);
64708 size_t ksize(const void *);
64709 +void check_object_size(const void *ptr, unsigned long n, bool to);
64710
64711 /*
64712 * Allocator specific definitions. These are mainly used to establish optimized
64713 @@ -328,4 +340,37 @@ static inline void *kzalloc_node(size_t
64714
64715 void __init kmem_cache_init_late(void);
64716
64717 +#define kmalloc(x, y) \
64718 +({ \
64719 + void *___retval; \
64720 + intoverflow_t ___x = (intoverflow_t)x; \
64721 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
64722 + ___retval = NULL; \
64723 + else \
64724 + ___retval = kmalloc((size_t)___x, (y)); \
64725 + ___retval; \
64726 +})
64727 +
64728 +#define kmalloc_node(x, y, z) \
64729 +({ \
64730 + void *___retval; \
64731 + intoverflow_t ___x = (intoverflow_t)x; \
64732 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
64733 + ___retval = NULL; \
64734 + else \
64735 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
64736 + ___retval; \
64737 +})
64738 +
64739 +#define kzalloc(x, y) \
64740 +({ \
64741 + void *___retval; \
64742 + intoverflow_t ___x = (intoverflow_t)x; \
64743 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
64744 + ___retval = NULL; \
64745 + else \
64746 + ___retval = kzalloc((size_t)___x, (y)); \
64747 + ___retval; \
64748 +})
64749 +
64750 #endif /* _LINUX_SLAB_H */
64751 diff -urNp linux-2.6.32.46/include/linux/slab_def.h linux-2.6.32.46/include/linux/slab_def.h
64752 --- linux-2.6.32.46/include/linux/slab_def.h 2011-03-27 14:31:47.000000000 -0400
64753 +++ linux-2.6.32.46/include/linux/slab_def.h 2011-05-04 17:56:28.000000000 -0400
64754 @@ -69,10 +69,10 @@ struct kmem_cache {
64755 unsigned long node_allocs;
64756 unsigned long node_frees;
64757 unsigned long node_overflow;
64758 - atomic_t allochit;
64759 - atomic_t allocmiss;
64760 - atomic_t freehit;
64761 - atomic_t freemiss;
64762 + atomic_unchecked_t allochit;
64763 + atomic_unchecked_t allocmiss;
64764 + atomic_unchecked_t freehit;
64765 + atomic_unchecked_t freemiss;
64766
64767 /*
64768 * If debugging is enabled, then the allocator can add additional
64769 diff -urNp linux-2.6.32.46/include/linux/slub_def.h linux-2.6.32.46/include/linux/slub_def.h
64770 --- linux-2.6.32.46/include/linux/slub_def.h 2011-03-27 14:31:47.000000000 -0400
64771 +++ linux-2.6.32.46/include/linux/slub_def.h 2011-08-05 20:33:55.000000000 -0400
64772 @@ -86,7 +86,7 @@ struct kmem_cache {
64773 struct kmem_cache_order_objects max;
64774 struct kmem_cache_order_objects min;
64775 gfp_t allocflags; /* gfp flags to use on each alloc */
64776 - int refcount; /* Refcount for slab cache destroy */
64777 + atomic_t refcount; /* Refcount for slab cache destroy */
64778 void (*ctor)(void *);
64779 int inuse; /* Offset to metadata */
64780 int align; /* Alignment */
64781 @@ -215,7 +215,7 @@ static __always_inline struct kmem_cache
64782 #endif
64783
64784 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64785 -void *__kmalloc(size_t size, gfp_t flags);
64786 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
64787
64788 #ifdef CONFIG_KMEMTRACE
64789 extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags);
64790 diff -urNp linux-2.6.32.46/include/linux/sonet.h linux-2.6.32.46/include/linux/sonet.h
64791 --- linux-2.6.32.46/include/linux/sonet.h 2011-03-27 14:31:47.000000000 -0400
64792 +++ linux-2.6.32.46/include/linux/sonet.h 2011-04-17 15:56:46.000000000 -0400
64793 @@ -61,7 +61,7 @@ struct sonet_stats {
64794 #include <asm/atomic.h>
64795
64796 struct k_sonet_stats {
64797 -#define __HANDLE_ITEM(i) atomic_t i
64798 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64799 __SONET_ITEMS
64800 #undef __HANDLE_ITEM
64801 };
64802 diff -urNp linux-2.6.32.46/include/linux/sunrpc/cache.h linux-2.6.32.46/include/linux/sunrpc/cache.h
64803 --- linux-2.6.32.46/include/linux/sunrpc/cache.h 2011-03-27 14:31:47.000000000 -0400
64804 +++ linux-2.6.32.46/include/linux/sunrpc/cache.h 2011-08-05 20:33:55.000000000 -0400
64805 @@ -125,7 +125,7 @@ struct cache_detail {
64806 */
64807 struct cache_req {
64808 struct cache_deferred_req *(*defer)(struct cache_req *req);
64809 -};
64810 +} __no_const;
64811 /* this must be embedded in a deferred_request that is being
64812 * delayed awaiting cache-fill
64813 */
64814 diff -urNp linux-2.6.32.46/include/linux/sunrpc/clnt.h linux-2.6.32.46/include/linux/sunrpc/clnt.h
64815 --- linux-2.6.32.46/include/linux/sunrpc/clnt.h 2011-03-27 14:31:47.000000000 -0400
64816 +++ linux-2.6.32.46/include/linux/sunrpc/clnt.h 2011-04-17 15:56:46.000000000 -0400
64817 @@ -167,9 +167,9 @@ static inline unsigned short rpc_get_por
64818 {
64819 switch (sap->sa_family) {
64820 case AF_INET:
64821 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64822 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64823 case AF_INET6:
64824 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64825 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64826 }
64827 return 0;
64828 }
64829 @@ -202,7 +202,7 @@ static inline bool __rpc_cmp_addr4(const
64830 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64831 const struct sockaddr *src)
64832 {
64833 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64834 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64835 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64836
64837 dsin->sin_family = ssin->sin_family;
64838 @@ -299,7 +299,7 @@ static inline u32 rpc_get_scope_id(const
64839 if (sa->sa_family != AF_INET6)
64840 return 0;
64841
64842 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64843 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64844 }
64845
64846 #endif /* __KERNEL__ */
64847 diff -urNp linux-2.6.32.46/include/linux/sunrpc/svc_rdma.h linux-2.6.32.46/include/linux/sunrpc/svc_rdma.h
64848 --- linux-2.6.32.46/include/linux/sunrpc/svc_rdma.h 2011-03-27 14:31:47.000000000 -0400
64849 +++ linux-2.6.32.46/include/linux/sunrpc/svc_rdma.h 2011-05-04 17:56:28.000000000 -0400
64850 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64851 extern unsigned int svcrdma_max_requests;
64852 extern unsigned int svcrdma_max_req_size;
64853
64854 -extern atomic_t rdma_stat_recv;
64855 -extern atomic_t rdma_stat_read;
64856 -extern atomic_t rdma_stat_write;
64857 -extern atomic_t rdma_stat_sq_starve;
64858 -extern atomic_t rdma_stat_rq_starve;
64859 -extern atomic_t rdma_stat_rq_poll;
64860 -extern atomic_t rdma_stat_rq_prod;
64861 -extern atomic_t rdma_stat_sq_poll;
64862 -extern atomic_t rdma_stat_sq_prod;
64863 +extern atomic_unchecked_t rdma_stat_recv;
64864 +extern atomic_unchecked_t rdma_stat_read;
64865 +extern atomic_unchecked_t rdma_stat_write;
64866 +extern atomic_unchecked_t rdma_stat_sq_starve;
64867 +extern atomic_unchecked_t rdma_stat_rq_starve;
64868 +extern atomic_unchecked_t rdma_stat_rq_poll;
64869 +extern atomic_unchecked_t rdma_stat_rq_prod;
64870 +extern atomic_unchecked_t rdma_stat_sq_poll;
64871 +extern atomic_unchecked_t rdma_stat_sq_prod;
64872
64873 #define RPCRDMA_VERSION 1
64874
64875 diff -urNp linux-2.6.32.46/include/linux/suspend.h linux-2.6.32.46/include/linux/suspend.h
64876 --- linux-2.6.32.46/include/linux/suspend.h 2011-03-27 14:31:47.000000000 -0400
64877 +++ linux-2.6.32.46/include/linux/suspend.h 2011-04-17 15:56:46.000000000 -0400
64878 @@ -104,15 +104,15 @@ typedef int __bitwise suspend_state_t;
64879 * which require special recovery actions in that situation.
64880 */
64881 struct platform_suspend_ops {
64882 - int (*valid)(suspend_state_t state);
64883 - int (*begin)(suspend_state_t state);
64884 - int (*prepare)(void);
64885 - int (*prepare_late)(void);
64886 - int (*enter)(suspend_state_t state);
64887 - void (*wake)(void);
64888 - void (*finish)(void);
64889 - void (*end)(void);
64890 - void (*recover)(void);
64891 + int (* const valid)(suspend_state_t state);
64892 + int (* const begin)(suspend_state_t state);
64893 + int (* const prepare)(void);
64894 + int (* const prepare_late)(void);
64895 + int (* const enter)(suspend_state_t state);
64896 + void (* const wake)(void);
64897 + void (* const finish)(void);
64898 + void (* const end)(void);
64899 + void (* const recover)(void);
64900 };
64901
64902 #ifdef CONFIG_SUSPEND
64903 @@ -120,7 +120,7 @@ struct platform_suspend_ops {
64904 * suspend_set_ops - set platform dependent suspend operations
64905 * @ops: The new suspend operations to set.
64906 */
64907 -extern void suspend_set_ops(struct platform_suspend_ops *ops);
64908 +extern void suspend_set_ops(const struct platform_suspend_ops *ops);
64909 extern int suspend_valid_only_mem(suspend_state_t state);
64910
64911 /**
64912 @@ -145,7 +145,7 @@ extern int pm_suspend(suspend_state_t st
64913 #else /* !CONFIG_SUSPEND */
64914 #define suspend_valid_only_mem NULL
64915
64916 -static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
64917 +static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
64918 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
64919 #endif /* !CONFIG_SUSPEND */
64920
64921 @@ -215,16 +215,16 @@ extern void mark_free_pages(struct zone
64922 * platforms which require special recovery actions in that situation.
64923 */
64924 struct platform_hibernation_ops {
64925 - int (*begin)(void);
64926 - void (*end)(void);
64927 - int (*pre_snapshot)(void);
64928 - void (*finish)(void);
64929 - int (*prepare)(void);
64930 - int (*enter)(void);
64931 - void (*leave)(void);
64932 - int (*pre_restore)(void);
64933 - void (*restore_cleanup)(void);
64934 - void (*recover)(void);
64935 + int (* const begin)(void);
64936 + void (* const end)(void);
64937 + int (* const pre_snapshot)(void);
64938 + void (* const finish)(void);
64939 + int (* const prepare)(void);
64940 + int (* const enter)(void);
64941 + void (* const leave)(void);
64942 + int (* const pre_restore)(void);
64943 + void (* const restore_cleanup)(void);
64944 + void (* const recover)(void);
64945 };
64946
64947 #ifdef CONFIG_HIBERNATION
64948 @@ -243,7 +243,7 @@ extern void swsusp_set_page_free(struct
64949 extern void swsusp_unset_page_free(struct page *);
64950 extern unsigned long get_safe_page(gfp_t gfp_mask);
64951
64952 -extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
64953 +extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
64954 extern int hibernate(void);
64955 extern bool system_entering_hibernation(void);
64956 #else /* CONFIG_HIBERNATION */
64957 @@ -251,7 +251,7 @@ static inline int swsusp_page_is_forbidd
64958 static inline void swsusp_set_page_free(struct page *p) {}
64959 static inline void swsusp_unset_page_free(struct page *p) {}
64960
64961 -static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
64962 +static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
64963 static inline int hibernate(void) { return -ENOSYS; }
64964 static inline bool system_entering_hibernation(void) { return false; }
64965 #endif /* CONFIG_HIBERNATION */
64966 diff -urNp linux-2.6.32.46/include/linux/sysctl.h linux-2.6.32.46/include/linux/sysctl.h
64967 --- linux-2.6.32.46/include/linux/sysctl.h 2011-03-27 14:31:47.000000000 -0400
64968 +++ linux-2.6.32.46/include/linux/sysctl.h 2011-04-17 15:56:46.000000000 -0400
64969 @@ -164,7 +164,11 @@ enum
64970 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64971 };
64972
64973 -
64974 +#ifdef CONFIG_PAX_SOFTMODE
64975 +enum {
64976 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64977 +};
64978 +#endif
64979
64980 /* CTL_VM names: */
64981 enum
64982 @@ -982,6 +986,8 @@ typedef int proc_handler (struct ctl_tab
64983
64984 extern int proc_dostring(struct ctl_table *, int,
64985 void __user *, size_t *, loff_t *);
64986 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64987 + void __user *, size_t *, loff_t *);
64988 extern int proc_dointvec(struct ctl_table *, int,
64989 void __user *, size_t *, loff_t *);
64990 extern int proc_dointvec_minmax(struct ctl_table *, int,
64991 @@ -1003,6 +1009,7 @@ extern int do_sysctl (int __user *name,
64992
64993 extern ctl_handler sysctl_data;
64994 extern ctl_handler sysctl_string;
64995 +extern ctl_handler sysctl_string_modpriv;
64996 extern ctl_handler sysctl_intvec;
64997 extern ctl_handler sysctl_jiffies;
64998 extern ctl_handler sysctl_ms_jiffies;
64999 diff -urNp linux-2.6.32.46/include/linux/sysfs.h linux-2.6.32.46/include/linux/sysfs.h
65000 --- linux-2.6.32.46/include/linux/sysfs.h 2011-03-27 14:31:47.000000000 -0400
65001 +++ linux-2.6.32.46/include/linux/sysfs.h 2011-04-17 15:56:46.000000000 -0400
65002 @@ -75,8 +75,8 @@ struct bin_attribute {
65003 };
65004
65005 struct sysfs_ops {
65006 - ssize_t (*show)(struct kobject *, struct attribute *,char *);
65007 - ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
65008 + ssize_t (* const show)(struct kobject *, struct attribute *,char *);
65009 + ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
65010 };
65011
65012 struct sysfs_dirent;
65013 diff -urNp linux-2.6.32.46/include/linux/thread_info.h linux-2.6.32.46/include/linux/thread_info.h
65014 --- linux-2.6.32.46/include/linux/thread_info.h 2011-03-27 14:31:47.000000000 -0400
65015 +++ linux-2.6.32.46/include/linux/thread_info.h 2011-04-17 15:56:46.000000000 -0400
65016 @@ -23,7 +23,7 @@ struct restart_block {
65017 };
65018 /* For futex_wait and futex_wait_requeue_pi */
65019 struct {
65020 - u32 *uaddr;
65021 + u32 __user *uaddr;
65022 u32 val;
65023 u32 flags;
65024 u32 bitset;
65025 diff -urNp linux-2.6.32.46/include/linux/tty.h linux-2.6.32.46/include/linux/tty.h
65026 --- linux-2.6.32.46/include/linux/tty.h 2011-03-27 14:31:47.000000000 -0400
65027 +++ linux-2.6.32.46/include/linux/tty.h 2011-08-05 20:33:55.000000000 -0400
65028 @@ -493,7 +493,6 @@ extern void tty_ldisc_begin(void);
65029 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
65030 extern void tty_ldisc_enable(struct tty_struct *tty);
65031
65032 -
65033 /* n_tty.c */
65034 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
65035
65036 diff -urNp linux-2.6.32.46/include/linux/tty_ldisc.h linux-2.6.32.46/include/linux/tty_ldisc.h
65037 --- linux-2.6.32.46/include/linux/tty_ldisc.h 2011-03-27 14:31:47.000000000 -0400
65038 +++ linux-2.6.32.46/include/linux/tty_ldisc.h 2011-04-17 15:56:46.000000000 -0400
65039 @@ -139,7 +139,7 @@ struct tty_ldisc_ops {
65040
65041 struct module *owner;
65042
65043 - int refcount;
65044 + atomic_t refcount;
65045 };
65046
65047 struct tty_ldisc {
65048 diff -urNp linux-2.6.32.46/include/linux/types.h linux-2.6.32.46/include/linux/types.h
65049 --- linux-2.6.32.46/include/linux/types.h 2011-03-27 14:31:47.000000000 -0400
65050 +++ linux-2.6.32.46/include/linux/types.h 2011-04-17 15:56:46.000000000 -0400
65051 @@ -191,10 +191,26 @@ typedef struct {
65052 volatile int counter;
65053 } atomic_t;
65054
65055 +#ifdef CONFIG_PAX_REFCOUNT
65056 +typedef struct {
65057 + volatile int counter;
65058 +} atomic_unchecked_t;
65059 +#else
65060 +typedef atomic_t atomic_unchecked_t;
65061 +#endif
65062 +
65063 #ifdef CONFIG_64BIT
65064 typedef struct {
65065 volatile long counter;
65066 } atomic64_t;
65067 +
65068 +#ifdef CONFIG_PAX_REFCOUNT
65069 +typedef struct {
65070 + volatile long counter;
65071 +} atomic64_unchecked_t;
65072 +#else
65073 +typedef atomic64_t atomic64_unchecked_t;
65074 +#endif
65075 #endif
65076
65077 struct ustat {
65078 diff -urNp linux-2.6.32.46/include/linux/uaccess.h linux-2.6.32.46/include/linux/uaccess.h
65079 --- linux-2.6.32.46/include/linux/uaccess.h 2011-03-27 14:31:47.000000000 -0400
65080 +++ linux-2.6.32.46/include/linux/uaccess.h 2011-10-06 09:37:14.000000000 -0400
65081 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
65082 long ret; \
65083 mm_segment_t old_fs = get_fs(); \
65084 \
65085 - set_fs(KERNEL_DS); \
65086 pagefault_disable(); \
65087 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65088 - pagefault_enable(); \
65089 + set_fs(KERNEL_DS); \
65090 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
65091 set_fs(old_fs); \
65092 + pagefault_enable(); \
65093 ret; \
65094 })
65095
65096 @@ -93,7 +93,7 @@ static inline unsigned long __copy_from_
65097 * Safely read from address @src to the buffer at @dst. If a kernel fault
65098 * happens, handle that and return -EFAULT.
65099 */
65100 -extern long probe_kernel_read(void *dst, void *src, size_t size);
65101 +extern long probe_kernel_read(void *dst, const void *src, size_t size);
65102
65103 /*
65104 * probe_kernel_write(): safely attempt to write to a location
65105 @@ -104,6 +104,6 @@ extern long probe_kernel_read(void *dst,
65106 * Safely write to address @dst from the buffer at @src. If a kernel fault
65107 * happens, handle that and return -EFAULT.
65108 */
65109 -extern long probe_kernel_write(void *dst, void *src, size_t size);
65110 +extern long probe_kernel_write(void *dst, const void *src, size_t size);
65111
65112 #endif /* __LINUX_UACCESS_H__ */
65113 diff -urNp linux-2.6.32.46/include/linux/unaligned/access_ok.h linux-2.6.32.46/include/linux/unaligned/access_ok.h
65114 --- linux-2.6.32.46/include/linux/unaligned/access_ok.h 2011-03-27 14:31:47.000000000 -0400
65115 +++ linux-2.6.32.46/include/linux/unaligned/access_ok.h 2011-04-17 15:56:46.000000000 -0400
65116 @@ -6,32 +6,32 @@
65117
65118 static inline u16 get_unaligned_le16(const void *p)
65119 {
65120 - return le16_to_cpup((__le16 *)p);
65121 + return le16_to_cpup((const __le16 *)p);
65122 }
65123
65124 static inline u32 get_unaligned_le32(const void *p)
65125 {
65126 - return le32_to_cpup((__le32 *)p);
65127 + return le32_to_cpup((const __le32 *)p);
65128 }
65129
65130 static inline u64 get_unaligned_le64(const void *p)
65131 {
65132 - return le64_to_cpup((__le64 *)p);
65133 + return le64_to_cpup((const __le64 *)p);
65134 }
65135
65136 static inline u16 get_unaligned_be16(const void *p)
65137 {
65138 - return be16_to_cpup((__be16 *)p);
65139 + return be16_to_cpup((const __be16 *)p);
65140 }
65141
65142 static inline u32 get_unaligned_be32(const void *p)
65143 {
65144 - return be32_to_cpup((__be32 *)p);
65145 + return be32_to_cpup((const __be32 *)p);
65146 }
65147
65148 static inline u64 get_unaligned_be64(const void *p)
65149 {
65150 - return be64_to_cpup((__be64 *)p);
65151 + return be64_to_cpup((const __be64 *)p);
65152 }
65153
65154 static inline void put_unaligned_le16(u16 val, void *p)
65155 diff -urNp linux-2.6.32.46/include/linux/vermagic.h linux-2.6.32.46/include/linux/vermagic.h
65156 --- linux-2.6.32.46/include/linux/vermagic.h 2011-03-27 14:31:47.000000000 -0400
65157 +++ linux-2.6.32.46/include/linux/vermagic.h 2011-10-08 08:17:48.000000000 -0400
65158 @@ -26,9 +26,28 @@
65159 #define MODULE_ARCH_VERMAGIC ""
65160 #endif
65161
65162 +#ifdef CONFIG_PAX_REFCOUNT
65163 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65164 +#else
65165 +#define MODULE_PAX_REFCOUNT ""
65166 +#endif
65167 +
65168 +#ifdef CONSTIFY_PLUGIN
65169 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65170 +#else
65171 +#define MODULE_CONSTIFY_PLUGIN ""
65172 +#endif
65173 +
65174 +#ifdef CONFIG_GRKERNSEC
65175 +#define MODULE_GRSEC "GRSEC "
65176 +#else
65177 +#define MODULE_GRSEC ""
65178 +#endif
65179 +
65180 #define VERMAGIC_STRING \
65181 UTS_RELEASE " " \
65182 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65183 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65184 - MODULE_ARCH_VERMAGIC
65185 + MODULE_ARCH_VERMAGIC \
65186 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_GRSEC
65187
65188 diff -urNp linux-2.6.32.46/include/linux/vmalloc.h linux-2.6.32.46/include/linux/vmalloc.h
65189 --- linux-2.6.32.46/include/linux/vmalloc.h 2011-03-27 14:31:47.000000000 -0400
65190 +++ linux-2.6.32.46/include/linux/vmalloc.h 2011-04-17 15:56:46.000000000 -0400
65191 @@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
65192 #define VM_MAP 0x00000004 /* vmap()ed pages */
65193 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65194 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65195 +
65196 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65197 +#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
65198 +#endif
65199 +
65200 /* bits [20..32] reserved for arch specific ioremap internals */
65201
65202 /*
65203 @@ -123,4 +128,81 @@ struct vm_struct **pcpu_get_vm_areas(con
65204
65205 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
65206
65207 +#define vmalloc(x) \
65208 +({ \
65209 + void *___retval; \
65210 + intoverflow_t ___x = (intoverflow_t)x; \
65211 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
65212 + ___retval = NULL; \
65213 + else \
65214 + ___retval = vmalloc((unsigned long)___x); \
65215 + ___retval; \
65216 +})
65217 +
65218 +#define __vmalloc(x, y, z) \
65219 +({ \
65220 + void *___retval; \
65221 + intoverflow_t ___x = (intoverflow_t)x; \
65222 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
65223 + ___retval = NULL; \
65224 + else \
65225 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
65226 + ___retval; \
65227 +})
65228 +
65229 +#define vmalloc_user(x) \
65230 +({ \
65231 + void *___retval; \
65232 + intoverflow_t ___x = (intoverflow_t)x; \
65233 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
65234 + ___retval = NULL; \
65235 + else \
65236 + ___retval = vmalloc_user((unsigned long)___x); \
65237 + ___retval; \
65238 +})
65239 +
65240 +#define vmalloc_exec(x) \
65241 +({ \
65242 + void *___retval; \
65243 + intoverflow_t ___x = (intoverflow_t)x; \
65244 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
65245 + ___retval = NULL; \
65246 + else \
65247 + ___retval = vmalloc_exec((unsigned long)___x); \
65248 + ___retval; \
65249 +})
65250 +
65251 +#define vmalloc_node(x, y) \
65252 +({ \
65253 + void *___retval; \
65254 + intoverflow_t ___x = (intoverflow_t)x; \
65255 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
65256 + ___retval = NULL; \
65257 + else \
65258 + ___retval = vmalloc_node((unsigned long)___x, (y));\
65259 + ___retval; \
65260 +})
65261 +
65262 +#define vmalloc_32(x) \
65263 +({ \
65264 + void *___retval; \
65265 + intoverflow_t ___x = (intoverflow_t)x; \
65266 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
65267 + ___retval = NULL; \
65268 + else \
65269 + ___retval = vmalloc_32((unsigned long)___x); \
65270 + ___retval; \
65271 +})
65272 +
65273 +#define vmalloc_32_user(x) \
65274 +({ \
65275 + void *___retval; \
65276 + intoverflow_t ___x = (intoverflow_t)x; \
65277 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
65278 + ___retval = NULL; \
65279 + else \
65280 + ___retval = vmalloc_32_user((unsigned long)___x);\
65281 + ___retval; \
65282 +})
65283 +
65284 #endif /* _LINUX_VMALLOC_H */
65285 diff -urNp linux-2.6.32.46/include/linux/vmstat.h linux-2.6.32.46/include/linux/vmstat.h
65286 --- linux-2.6.32.46/include/linux/vmstat.h 2011-03-27 14:31:47.000000000 -0400
65287 +++ linux-2.6.32.46/include/linux/vmstat.h 2011-04-17 15:56:46.000000000 -0400
65288 @@ -136,18 +136,18 @@ static inline void vm_events_fold_cpu(in
65289 /*
65290 * Zone based page accounting with per cpu differentials.
65291 */
65292 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65293 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65294
65295 static inline void zone_page_state_add(long x, struct zone *zone,
65296 enum zone_stat_item item)
65297 {
65298 - atomic_long_add(x, &zone->vm_stat[item]);
65299 - atomic_long_add(x, &vm_stat[item]);
65300 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65301 + atomic_long_add_unchecked(x, &vm_stat[item]);
65302 }
65303
65304 static inline unsigned long global_page_state(enum zone_stat_item item)
65305 {
65306 - long x = atomic_long_read(&vm_stat[item]);
65307 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65308 #ifdef CONFIG_SMP
65309 if (x < 0)
65310 x = 0;
65311 @@ -158,7 +158,7 @@ static inline unsigned long global_page_
65312 static inline unsigned long zone_page_state(struct zone *zone,
65313 enum zone_stat_item item)
65314 {
65315 - long x = atomic_long_read(&zone->vm_stat[item]);
65316 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65317 #ifdef CONFIG_SMP
65318 if (x < 0)
65319 x = 0;
65320 @@ -175,7 +175,7 @@ static inline unsigned long zone_page_st
65321 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65322 enum zone_stat_item item)
65323 {
65324 - long x = atomic_long_read(&zone->vm_stat[item]);
65325 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65326
65327 #ifdef CONFIG_SMP
65328 int cpu;
65329 @@ -264,8 +264,8 @@ static inline void __mod_zone_page_state
65330
65331 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65332 {
65333 - atomic_long_inc(&zone->vm_stat[item]);
65334 - atomic_long_inc(&vm_stat[item]);
65335 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65336 + atomic_long_inc_unchecked(&vm_stat[item]);
65337 }
65338
65339 static inline void __inc_zone_page_state(struct page *page,
65340 @@ -276,8 +276,8 @@ static inline void __inc_zone_page_state
65341
65342 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65343 {
65344 - atomic_long_dec(&zone->vm_stat[item]);
65345 - atomic_long_dec(&vm_stat[item]);
65346 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65347 + atomic_long_dec_unchecked(&vm_stat[item]);
65348 }
65349
65350 static inline void __dec_zone_page_state(struct page *page,
65351 diff -urNp linux-2.6.32.46/include/media/saa7146_vv.h linux-2.6.32.46/include/media/saa7146_vv.h
65352 --- linux-2.6.32.46/include/media/saa7146_vv.h 2011-03-27 14:31:47.000000000 -0400
65353 +++ linux-2.6.32.46/include/media/saa7146_vv.h 2011-08-23 21:22:38.000000000 -0400
65354 @@ -167,7 +167,7 @@ struct saa7146_ext_vv
65355 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65356
65357 /* the extension can override this */
65358 - struct v4l2_ioctl_ops ops;
65359 + v4l2_ioctl_ops_no_const ops;
65360 /* pointer to the saa7146 core ops */
65361 const struct v4l2_ioctl_ops *core_ops;
65362
65363 diff -urNp linux-2.6.32.46/include/media/v4l2-dev.h linux-2.6.32.46/include/media/v4l2-dev.h
65364 --- linux-2.6.32.46/include/media/v4l2-dev.h 2011-03-27 14:31:47.000000000 -0400
65365 +++ linux-2.6.32.46/include/media/v4l2-dev.h 2011-10-08 08:14:40.000000000 -0400
65366 @@ -34,7 +34,7 @@ struct v4l2_device;
65367 #define V4L2_FL_UNREGISTERED (0)
65368
65369 struct v4l2_file_operations {
65370 - struct module *owner;
65371 + struct module * const owner;
65372 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
65373 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
65374 unsigned int (*poll) (struct file *, struct poll_table_struct *);
65375 @@ -46,6 +46,7 @@ struct v4l2_file_operations {
65376 int (*open) (struct file *);
65377 int (*release) (struct file *);
65378 };
65379 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65380
65381 /*
65382 * Newer version of video_device, handled by videodev2.c
65383 diff -urNp linux-2.6.32.46/include/media/v4l2-device.h linux-2.6.32.46/include/media/v4l2-device.h
65384 --- linux-2.6.32.46/include/media/v4l2-device.h 2011-03-27 14:31:47.000000000 -0400
65385 +++ linux-2.6.32.46/include/media/v4l2-device.h 2011-05-04 17:56:28.000000000 -0400
65386 @@ -71,7 +71,7 @@ int __must_check v4l2_device_register(st
65387 this function returns 0. If the name ends with a digit (e.g. cx18),
65388 then the name will be set to cx18-0 since cx180 looks really odd. */
65389 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
65390 - atomic_t *instance);
65391 + atomic_unchecked_t *instance);
65392
65393 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
65394 Since the parent disappears this ensures that v4l2_dev doesn't have an
65395 diff -urNp linux-2.6.32.46/include/media/v4l2-ioctl.h linux-2.6.32.46/include/media/v4l2-ioctl.h
65396 --- linux-2.6.32.46/include/media/v4l2-ioctl.h 2011-03-27 14:31:47.000000000 -0400
65397 +++ linux-2.6.32.46/include/media/v4l2-ioctl.h 2011-08-23 21:22:38.000000000 -0400
65398 @@ -243,6 +243,7 @@ struct v4l2_ioctl_ops {
65399 long (*vidioc_default) (struct file *file, void *fh,
65400 int cmd, void *arg);
65401 };
65402 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65403
65404
65405 /* v4l debugging and diagnostics */
65406 diff -urNp linux-2.6.32.46/include/net/flow.h linux-2.6.32.46/include/net/flow.h
65407 --- linux-2.6.32.46/include/net/flow.h 2011-03-27 14:31:47.000000000 -0400
65408 +++ linux-2.6.32.46/include/net/flow.h 2011-05-04 17:56:28.000000000 -0400
65409 @@ -92,7 +92,7 @@ typedef int (*flow_resolve_t)(struct net
65410 extern void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family,
65411 u8 dir, flow_resolve_t resolver);
65412 extern void flow_cache_flush(void);
65413 -extern atomic_t flow_cache_genid;
65414 +extern atomic_unchecked_t flow_cache_genid;
65415
65416 static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2)
65417 {
65418 diff -urNp linux-2.6.32.46/include/net/inetpeer.h linux-2.6.32.46/include/net/inetpeer.h
65419 --- linux-2.6.32.46/include/net/inetpeer.h 2011-03-27 14:31:47.000000000 -0400
65420 +++ linux-2.6.32.46/include/net/inetpeer.h 2011-04-17 15:56:46.000000000 -0400
65421 @@ -24,7 +24,7 @@ struct inet_peer
65422 __u32 dtime; /* the time of last use of not
65423 * referenced entries */
65424 atomic_t refcnt;
65425 - atomic_t rid; /* Frag reception counter */
65426 + atomic_unchecked_t rid; /* Frag reception counter */
65427 __u32 tcp_ts;
65428 unsigned long tcp_ts_stamp;
65429 };
65430 diff -urNp linux-2.6.32.46/include/net/ip_vs.h linux-2.6.32.46/include/net/ip_vs.h
65431 --- linux-2.6.32.46/include/net/ip_vs.h 2011-03-27 14:31:47.000000000 -0400
65432 +++ linux-2.6.32.46/include/net/ip_vs.h 2011-05-04 17:56:28.000000000 -0400
65433 @@ -365,7 +365,7 @@ struct ip_vs_conn {
65434 struct ip_vs_conn *control; /* Master control connection */
65435 atomic_t n_control; /* Number of controlled ones */
65436 struct ip_vs_dest *dest; /* real server */
65437 - atomic_t in_pkts; /* incoming packet counter */
65438 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65439
65440 /* packet transmitter for different forwarding methods. If it
65441 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65442 @@ -466,7 +466,7 @@ struct ip_vs_dest {
65443 union nf_inet_addr addr; /* IP address of the server */
65444 __be16 port; /* port number of the server */
65445 volatile unsigned flags; /* dest status flags */
65446 - atomic_t conn_flags; /* flags to copy to conn */
65447 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65448 atomic_t weight; /* server weight */
65449
65450 atomic_t refcnt; /* reference counter */
65451 diff -urNp linux-2.6.32.46/include/net/irda/ircomm_core.h linux-2.6.32.46/include/net/irda/ircomm_core.h
65452 --- linux-2.6.32.46/include/net/irda/ircomm_core.h 2011-03-27 14:31:47.000000000 -0400
65453 +++ linux-2.6.32.46/include/net/irda/ircomm_core.h 2011-08-05 20:33:55.000000000 -0400
65454 @@ -51,7 +51,7 @@ typedef struct {
65455 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65456 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65457 struct ircomm_info *);
65458 -} call_t;
65459 +} __no_const call_t;
65460
65461 struct ircomm_cb {
65462 irda_queue_t queue;
65463 diff -urNp linux-2.6.32.46/include/net/irda/ircomm_tty.h linux-2.6.32.46/include/net/irda/ircomm_tty.h
65464 --- linux-2.6.32.46/include/net/irda/ircomm_tty.h 2011-03-27 14:31:47.000000000 -0400
65465 +++ linux-2.6.32.46/include/net/irda/ircomm_tty.h 2011-04-17 15:56:46.000000000 -0400
65466 @@ -35,6 +35,7 @@
65467 #include <linux/termios.h>
65468 #include <linux/timer.h>
65469 #include <linux/tty.h> /* struct tty_struct */
65470 +#include <asm/local.h>
65471
65472 #include <net/irda/irias_object.h>
65473 #include <net/irda/ircomm_core.h>
65474 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65475 unsigned short close_delay;
65476 unsigned short closing_wait; /* time to wait before closing */
65477
65478 - int open_count;
65479 - int blocked_open; /* # of blocked opens */
65480 + local_t open_count;
65481 + local_t blocked_open; /* # of blocked opens */
65482
65483 /* Protect concurent access to :
65484 * o self->open_count
65485 diff -urNp linux-2.6.32.46/include/net/iucv/af_iucv.h linux-2.6.32.46/include/net/iucv/af_iucv.h
65486 --- linux-2.6.32.46/include/net/iucv/af_iucv.h 2011-03-27 14:31:47.000000000 -0400
65487 +++ linux-2.6.32.46/include/net/iucv/af_iucv.h 2011-05-04 17:56:28.000000000 -0400
65488 @@ -87,7 +87,7 @@ struct iucv_sock {
65489 struct iucv_sock_list {
65490 struct hlist_head head;
65491 rwlock_t lock;
65492 - atomic_t autobind_name;
65493 + atomic_unchecked_t autobind_name;
65494 };
65495
65496 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65497 diff -urNp linux-2.6.32.46/include/net/lapb.h linux-2.6.32.46/include/net/lapb.h
65498 --- linux-2.6.32.46/include/net/lapb.h 2011-03-27 14:31:47.000000000 -0400
65499 +++ linux-2.6.32.46/include/net/lapb.h 2011-08-05 20:33:55.000000000 -0400
65500 @@ -95,7 +95,7 @@ struct lapb_cb {
65501 struct sk_buff_head write_queue;
65502 struct sk_buff_head ack_queue;
65503 unsigned char window;
65504 - struct lapb_register_struct callbacks;
65505 + struct lapb_register_struct *callbacks;
65506
65507 /* FRMR control information */
65508 struct lapb_frame frmr_data;
65509 diff -urNp linux-2.6.32.46/include/net/neighbour.h linux-2.6.32.46/include/net/neighbour.h
65510 --- linux-2.6.32.46/include/net/neighbour.h 2011-03-27 14:31:47.000000000 -0400
65511 +++ linux-2.6.32.46/include/net/neighbour.h 2011-08-26 20:29:08.000000000 -0400
65512 @@ -131,7 +131,7 @@ struct neigh_ops
65513 int (*connected_output)(struct sk_buff*);
65514 int (*hh_output)(struct sk_buff*);
65515 int (*queue_xmit)(struct sk_buff*);
65516 -};
65517 +} __do_const;
65518
65519 struct pneigh_entry
65520 {
65521 diff -urNp linux-2.6.32.46/include/net/netlink.h linux-2.6.32.46/include/net/netlink.h
65522 --- linux-2.6.32.46/include/net/netlink.h 2011-07-13 17:23:04.000000000 -0400
65523 +++ linux-2.6.32.46/include/net/netlink.h 2011-08-21 18:08:11.000000000 -0400
65524 @@ -335,7 +335,7 @@ static inline int nlmsg_ok(const struct
65525 {
65526 return (remaining >= (int) sizeof(struct nlmsghdr) &&
65527 nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
65528 - nlh->nlmsg_len <= remaining);
65529 + nlh->nlmsg_len <= (unsigned int)remaining);
65530 }
65531
65532 /**
65533 @@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct
65534 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65535 {
65536 if (mark)
65537 - skb_trim(skb, (unsigned char *) mark - skb->data);
65538 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65539 }
65540
65541 /**
65542 diff -urNp linux-2.6.32.46/include/net/netns/ipv4.h linux-2.6.32.46/include/net/netns/ipv4.h
65543 --- linux-2.6.32.46/include/net/netns/ipv4.h 2011-03-27 14:31:47.000000000 -0400
65544 +++ linux-2.6.32.46/include/net/netns/ipv4.h 2011-05-04 17:56:28.000000000 -0400
65545 @@ -54,7 +54,7 @@ struct netns_ipv4 {
65546 int current_rt_cache_rebuild_count;
65547
65548 struct timer_list rt_secret_timer;
65549 - atomic_t rt_genid;
65550 + atomic_unchecked_t rt_genid;
65551
65552 #ifdef CONFIG_IP_MROUTE
65553 struct sock *mroute_sk;
65554 diff -urNp linux-2.6.32.46/include/net/sctp/sctp.h linux-2.6.32.46/include/net/sctp/sctp.h
65555 --- linux-2.6.32.46/include/net/sctp/sctp.h 2011-03-27 14:31:47.000000000 -0400
65556 +++ linux-2.6.32.46/include/net/sctp/sctp.h 2011-04-17 15:56:46.000000000 -0400
65557 @@ -305,8 +305,8 @@ extern int sctp_debug_flag;
65558
65559 #else /* SCTP_DEBUG */
65560
65561 -#define SCTP_DEBUG_PRINTK(whatever...)
65562 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65563 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65564 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65565 #define SCTP_ENABLE_DEBUG
65566 #define SCTP_DISABLE_DEBUG
65567 #define SCTP_ASSERT(expr, str, func)
65568 diff -urNp linux-2.6.32.46/include/net/secure_seq.h linux-2.6.32.46/include/net/secure_seq.h
65569 --- linux-2.6.32.46/include/net/secure_seq.h 2011-08-16 20:37:25.000000000 -0400
65570 +++ linux-2.6.32.46/include/net/secure_seq.h 2011-08-07 19:48:09.000000000 -0400
65571 @@ -7,14 +7,14 @@ extern __u32 secure_ip_id(__be32 daddr);
65572 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
65573 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
65574 extern u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
65575 - __be16 dport);
65576 + __be16 dport);
65577 extern __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
65578 __be16 sport, __be16 dport);
65579 extern __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
65580 - __be16 sport, __be16 dport);
65581 + __be16 sport, __be16 dport);
65582 extern u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
65583 - __be16 sport, __be16 dport);
65584 + __be16 sport, __be16 dport);
65585 extern u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
65586 - __be16 sport, __be16 dport);
65587 + __be16 sport, __be16 dport);
65588
65589 #endif /* _NET_SECURE_SEQ */
65590 diff -urNp linux-2.6.32.46/include/net/sock.h linux-2.6.32.46/include/net/sock.h
65591 --- linux-2.6.32.46/include/net/sock.h 2011-03-27 14:31:47.000000000 -0400
65592 +++ linux-2.6.32.46/include/net/sock.h 2011-08-21 17:24:37.000000000 -0400
65593 @@ -272,7 +272,7 @@ struct sock {
65594 rwlock_t sk_callback_lock;
65595 int sk_err,
65596 sk_err_soft;
65597 - atomic_t sk_drops;
65598 + atomic_unchecked_t sk_drops;
65599 unsigned short sk_ack_backlog;
65600 unsigned short sk_max_ack_backlog;
65601 __u32 sk_priority;
65602 @@ -737,7 +737,7 @@ static inline void sk_refcnt_debug_relea
65603 extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
65604 extern int sock_prot_inuse_get(struct net *net, struct proto *proto);
65605 #else
65606 -static void inline sock_prot_inuse_add(struct net *net, struct proto *prot,
65607 +static inline void sock_prot_inuse_add(struct net *net, struct proto *prot,
65608 int inc)
65609 {
65610 }
65611 diff -urNp linux-2.6.32.46/include/net/tcp.h linux-2.6.32.46/include/net/tcp.h
65612 --- linux-2.6.32.46/include/net/tcp.h 2011-03-27 14:31:47.000000000 -0400
65613 +++ linux-2.6.32.46/include/net/tcp.h 2011-08-23 21:29:10.000000000 -0400
65614 @@ -1444,8 +1444,8 @@ enum tcp_seq_states {
65615 struct tcp_seq_afinfo {
65616 char *name;
65617 sa_family_t family;
65618 - struct file_operations seq_fops;
65619 - struct seq_operations seq_ops;
65620 + file_operations_no_const seq_fops;
65621 + seq_operations_no_const seq_ops;
65622 };
65623
65624 struct tcp_iter_state {
65625 diff -urNp linux-2.6.32.46/include/net/udp.h linux-2.6.32.46/include/net/udp.h
65626 --- linux-2.6.32.46/include/net/udp.h 2011-03-27 14:31:47.000000000 -0400
65627 +++ linux-2.6.32.46/include/net/udp.h 2011-08-23 21:29:34.000000000 -0400
65628 @@ -187,8 +187,8 @@ struct udp_seq_afinfo {
65629 char *name;
65630 sa_family_t family;
65631 struct udp_table *udp_table;
65632 - struct file_operations seq_fops;
65633 - struct seq_operations seq_ops;
65634 + file_operations_no_const seq_fops;
65635 + seq_operations_no_const seq_ops;
65636 };
65637
65638 struct udp_iter_state {
65639 diff -urNp linux-2.6.32.46/include/rdma/iw_cm.h linux-2.6.32.46/include/rdma/iw_cm.h
65640 --- linux-2.6.32.46/include/rdma/iw_cm.h 2011-03-27 14:31:47.000000000 -0400
65641 +++ linux-2.6.32.46/include/rdma/iw_cm.h 2011-08-05 20:33:55.000000000 -0400
65642 @@ -129,7 +129,7 @@ struct iw_cm_verbs {
65643 int backlog);
65644
65645 int (*destroy_listen)(struct iw_cm_id *cm_id);
65646 -};
65647 +} __no_const;
65648
65649 /**
65650 * iw_create_cm_id - Create an IW CM identifier.
65651 diff -urNp linux-2.6.32.46/include/scsi/libfc.h linux-2.6.32.46/include/scsi/libfc.h
65652 --- linux-2.6.32.46/include/scsi/libfc.h 2011-03-27 14:31:47.000000000 -0400
65653 +++ linux-2.6.32.46/include/scsi/libfc.h 2011-08-23 21:22:38.000000000 -0400
65654 @@ -675,6 +675,7 @@ struct libfc_function_template {
65655 */
65656 void (*disc_stop_final) (struct fc_lport *);
65657 };
65658 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65659
65660 /* information used by the discovery layer */
65661 struct fc_disc {
65662 @@ -707,7 +708,7 @@ struct fc_lport {
65663 struct fc_disc disc;
65664
65665 /* Operational Information */
65666 - struct libfc_function_template tt;
65667 + libfc_function_template_no_const tt;
65668 u8 link_up;
65669 u8 qfull;
65670 enum fc_lport_state state;
65671 diff -urNp linux-2.6.32.46/include/scsi/scsi_device.h linux-2.6.32.46/include/scsi/scsi_device.h
65672 --- linux-2.6.32.46/include/scsi/scsi_device.h 2011-04-17 17:00:52.000000000 -0400
65673 +++ linux-2.6.32.46/include/scsi/scsi_device.h 2011-05-04 17:56:28.000000000 -0400
65674 @@ -156,9 +156,9 @@ struct scsi_device {
65675 unsigned int max_device_blocked; /* what device_blocked counts down from */
65676 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65677
65678 - atomic_t iorequest_cnt;
65679 - atomic_t iodone_cnt;
65680 - atomic_t ioerr_cnt;
65681 + atomic_unchecked_t iorequest_cnt;
65682 + atomic_unchecked_t iodone_cnt;
65683 + atomic_unchecked_t ioerr_cnt;
65684
65685 struct device sdev_gendev,
65686 sdev_dev;
65687 diff -urNp linux-2.6.32.46/include/scsi/scsi_transport_fc.h linux-2.6.32.46/include/scsi/scsi_transport_fc.h
65688 --- linux-2.6.32.46/include/scsi/scsi_transport_fc.h 2011-03-27 14:31:47.000000000 -0400
65689 +++ linux-2.6.32.46/include/scsi/scsi_transport_fc.h 2011-08-26 20:19:09.000000000 -0400
65690 @@ -708,7 +708,7 @@ struct fc_function_template {
65691 unsigned long show_host_system_hostname:1;
65692
65693 unsigned long disable_target_scan:1;
65694 -};
65695 +} __do_const;
65696
65697
65698 /**
65699 diff -urNp linux-2.6.32.46/include/sound/ac97_codec.h linux-2.6.32.46/include/sound/ac97_codec.h
65700 --- linux-2.6.32.46/include/sound/ac97_codec.h 2011-03-27 14:31:47.000000000 -0400
65701 +++ linux-2.6.32.46/include/sound/ac97_codec.h 2011-04-17 15:56:46.000000000 -0400
65702 @@ -419,15 +419,15 @@
65703 struct snd_ac97;
65704
65705 struct snd_ac97_build_ops {
65706 - int (*build_3d) (struct snd_ac97 *ac97);
65707 - int (*build_specific) (struct snd_ac97 *ac97);
65708 - int (*build_spdif) (struct snd_ac97 *ac97);
65709 - int (*build_post_spdif) (struct snd_ac97 *ac97);
65710 + int (* const build_3d) (struct snd_ac97 *ac97);
65711 + int (* const build_specific) (struct snd_ac97 *ac97);
65712 + int (* const build_spdif) (struct snd_ac97 *ac97);
65713 + int (* const build_post_spdif) (struct snd_ac97 *ac97);
65714 #ifdef CONFIG_PM
65715 - void (*suspend) (struct snd_ac97 *ac97);
65716 - void (*resume) (struct snd_ac97 *ac97);
65717 + void (* const suspend) (struct snd_ac97 *ac97);
65718 + void (* const resume) (struct snd_ac97 *ac97);
65719 #endif
65720 - void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
65721 + void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
65722 };
65723
65724 struct snd_ac97_bus_ops {
65725 @@ -477,7 +477,7 @@ struct snd_ac97_template {
65726
65727 struct snd_ac97 {
65728 /* -- lowlevel (hardware) driver specific -- */
65729 - struct snd_ac97_build_ops * build_ops;
65730 + const struct snd_ac97_build_ops * build_ops;
65731 void *private_data;
65732 void (*private_free) (struct snd_ac97 *ac97);
65733 /* --- */
65734 diff -urNp linux-2.6.32.46/include/sound/ak4xxx-adda.h linux-2.6.32.46/include/sound/ak4xxx-adda.h
65735 --- linux-2.6.32.46/include/sound/ak4xxx-adda.h 2011-03-27 14:31:47.000000000 -0400
65736 +++ linux-2.6.32.46/include/sound/ak4xxx-adda.h 2011-08-05 20:33:55.000000000 -0400
65737 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65738 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65739 unsigned char val);
65740 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65741 -};
65742 +} __no_const;
65743
65744 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65745
65746 diff -urNp linux-2.6.32.46/include/sound/hwdep.h linux-2.6.32.46/include/sound/hwdep.h
65747 --- linux-2.6.32.46/include/sound/hwdep.h 2011-03-27 14:31:47.000000000 -0400
65748 +++ linux-2.6.32.46/include/sound/hwdep.h 2011-08-05 20:33:55.000000000 -0400
65749 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65750 struct snd_hwdep_dsp_status *status);
65751 int (*dsp_load)(struct snd_hwdep *hw,
65752 struct snd_hwdep_dsp_image *image);
65753 -};
65754 +} __no_const;
65755
65756 struct snd_hwdep {
65757 struct snd_card *card;
65758 diff -urNp linux-2.6.32.46/include/sound/info.h linux-2.6.32.46/include/sound/info.h
65759 --- linux-2.6.32.46/include/sound/info.h 2011-03-27 14:31:47.000000000 -0400
65760 +++ linux-2.6.32.46/include/sound/info.h 2011-08-05 20:33:55.000000000 -0400
65761 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65762 struct snd_info_buffer *buffer);
65763 void (*write)(struct snd_info_entry *entry,
65764 struct snd_info_buffer *buffer);
65765 -};
65766 +} __no_const;
65767
65768 struct snd_info_entry_ops {
65769 int (*open)(struct snd_info_entry *entry,
65770 diff -urNp linux-2.6.32.46/include/sound/pcm.h linux-2.6.32.46/include/sound/pcm.h
65771 --- linux-2.6.32.46/include/sound/pcm.h 2011-03-27 14:31:47.000000000 -0400
65772 +++ linux-2.6.32.46/include/sound/pcm.h 2011-08-23 21:22:38.000000000 -0400
65773 @@ -80,6 +80,7 @@ struct snd_pcm_ops {
65774 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65775 int (*ack)(struct snd_pcm_substream *substream);
65776 };
65777 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65778
65779 /*
65780 *
65781 diff -urNp linux-2.6.32.46/include/sound/sb16_csp.h linux-2.6.32.46/include/sound/sb16_csp.h
65782 --- linux-2.6.32.46/include/sound/sb16_csp.h 2011-03-27 14:31:47.000000000 -0400
65783 +++ linux-2.6.32.46/include/sound/sb16_csp.h 2011-08-05 20:33:55.000000000 -0400
65784 @@ -139,7 +139,7 @@ struct snd_sb_csp_ops {
65785 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65786 int (*csp_stop) (struct snd_sb_csp * p);
65787 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65788 -};
65789 +} __no_const;
65790
65791 /*
65792 * CSP private data
65793 diff -urNp linux-2.6.32.46/include/sound/ymfpci.h linux-2.6.32.46/include/sound/ymfpci.h
65794 --- linux-2.6.32.46/include/sound/ymfpci.h 2011-03-27 14:31:47.000000000 -0400
65795 +++ linux-2.6.32.46/include/sound/ymfpci.h 2011-05-04 17:56:28.000000000 -0400
65796 @@ -358,7 +358,7 @@ struct snd_ymfpci {
65797 spinlock_t reg_lock;
65798 spinlock_t voice_lock;
65799 wait_queue_head_t interrupt_sleep;
65800 - atomic_t interrupt_sleep_count;
65801 + atomic_unchecked_t interrupt_sleep_count;
65802 struct snd_info_entry *proc_entry;
65803 const struct firmware *dsp_microcode;
65804 const struct firmware *controller_microcode;
65805 diff -urNp linux-2.6.32.46/include/trace/events/irq.h linux-2.6.32.46/include/trace/events/irq.h
65806 --- linux-2.6.32.46/include/trace/events/irq.h 2011-03-27 14:31:47.000000000 -0400
65807 +++ linux-2.6.32.46/include/trace/events/irq.h 2011-04-17 15:56:46.000000000 -0400
65808 @@ -34,7 +34,7 @@
65809 */
65810 TRACE_EVENT(irq_handler_entry,
65811
65812 - TP_PROTO(int irq, struct irqaction *action),
65813 + TP_PROTO(int irq, const struct irqaction *action),
65814
65815 TP_ARGS(irq, action),
65816
65817 @@ -64,7 +64,7 @@ TRACE_EVENT(irq_handler_entry,
65818 */
65819 TRACE_EVENT(irq_handler_exit,
65820
65821 - TP_PROTO(int irq, struct irqaction *action, int ret),
65822 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65823
65824 TP_ARGS(irq, action, ret),
65825
65826 @@ -95,7 +95,7 @@ TRACE_EVENT(irq_handler_exit,
65827 */
65828 TRACE_EVENT(softirq_entry,
65829
65830 - TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
65831 + TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
65832
65833 TP_ARGS(h, vec),
65834
65835 @@ -124,7 +124,7 @@ TRACE_EVENT(softirq_entry,
65836 */
65837 TRACE_EVENT(softirq_exit,
65838
65839 - TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
65840 + TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
65841
65842 TP_ARGS(h, vec),
65843
65844 diff -urNp linux-2.6.32.46/include/video/uvesafb.h linux-2.6.32.46/include/video/uvesafb.h
65845 --- linux-2.6.32.46/include/video/uvesafb.h 2011-03-27 14:31:47.000000000 -0400
65846 +++ linux-2.6.32.46/include/video/uvesafb.h 2011-04-17 15:56:46.000000000 -0400
65847 @@ -177,6 +177,7 @@ struct uvesafb_par {
65848 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65849 u8 pmi_setpal; /* PMI for palette changes */
65850 u16 *pmi_base; /* protected mode interface location */
65851 + u8 *pmi_code; /* protected mode code location */
65852 void *pmi_start;
65853 void *pmi_pal;
65854 u8 *vbe_state_orig; /*
65855 diff -urNp linux-2.6.32.46/init/Kconfig linux-2.6.32.46/init/Kconfig
65856 --- linux-2.6.32.46/init/Kconfig 2011-05-10 22:12:01.000000000 -0400
65857 +++ linux-2.6.32.46/init/Kconfig 2011-05-10 22:12:34.000000000 -0400
65858 @@ -1004,7 +1004,7 @@ config SLUB_DEBUG
65859
65860 config COMPAT_BRK
65861 bool "Disable heap randomization"
65862 - default y
65863 + default n
65864 help
65865 Randomizing heap placement makes heap exploits harder, but it
65866 also breaks ancient binaries (including anything libc5 based).
65867 diff -urNp linux-2.6.32.46/init/do_mounts.c linux-2.6.32.46/init/do_mounts.c
65868 --- linux-2.6.32.46/init/do_mounts.c 2011-03-27 14:31:47.000000000 -0400
65869 +++ linux-2.6.32.46/init/do_mounts.c 2011-04-17 15:56:46.000000000 -0400
65870 @@ -216,11 +216,11 @@ static void __init get_fs_names(char *pa
65871
65872 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65873 {
65874 - int err = sys_mount(name, "/root", fs, flags, data);
65875 + int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
65876 if (err)
65877 return err;
65878
65879 - sys_chdir("/root");
65880 + sys_chdir((__force const char __user *)"/root");
65881 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
65882 printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
65883 current->fs->pwd.mnt->mnt_sb->s_type->name,
65884 @@ -311,18 +311,18 @@ void __init change_floppy(char *fmt, ...
65885 va_start(args, fmt);
65886 vsprintf(buf, fmt, args);
65887 va_end(args);
65888 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65889 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65890 if (fd >= 0) {
65891 sys_ioctl(fd, FDEJECT, 0);
65892 sys_close(fd);
65893 }
65894 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65895 - fd = sys_open("/dev/console", O_RDWR, 0);
65896 + fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
65897 if (fd >= 0) {
65898 sys_ioctl(fd, TCGETS, (long)&termios);
65899 termios.c_lflag &= ~ICANON;
65900 sys_ioctl(fd, TCSETSF, (long)&termios);
65901 - sys_read(fd, &c, 1);
65902 + sys_read(fd, (char __user *)&c, 1);
65903 termios.c_lflag |= ICANON;
65904 sys_ioctl(fd, TCSETSF, (long)&termios);
65905 sys_close(fd);
65906 @@ -416,6 +416,6 @@ void __init prepare_namespace(void)
65907 mount_root();
65908 out:
65909 devtmpfs_mount("dev");
65910 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65911 - sys_chroot(".");
65912 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
65913 + sys_chroot((__force char __user *)".");
65914 }
65915 diff -urNp linux-2.6.32.46/init/do_mounts.h linux-2.6.32.46/init/do_mounts.h
65916 --- linux-2.6.32.46/init/do_mounts.h 2011-03-27 14:31:47.000000000 -0400
65917 +++ linux-2.6.32.46/init/do_mounts.h 2011-10-06 09:37:14.000000000 -0400
65918 @@ -15,15 +15,15 @@ extern int root_mountflags;
65919
65920 static inline int create_dev(char *name, dev_t dev)
65921 {
65922 - sys_unlink(name);
65923 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65924 + sys_unlink((char __force_user *)name);
65925 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65926 }
65927
65928 #if BITS_PER_LONG == 32
65929 static inline u32 bstat(char *name)
65930 {
65931 struct stat64 stat;
65932 - if (sys_stat64(name, &stat) != 0)
65933 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65934 return 0;
65935 if (!S_ISBLK(stat.st_mode))
65936 return 0;
65937 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65938 static inline u32 bstat(char *name)
65939 {
65940 struct stat stat;
65941 - if (sys_newstat(name, &stat) != 0)
65942 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65943 return 0;
65944 if (!S_ISBLK(stat.st_mode))
65945 return 0;
65946 diff -urNp linux-2.6.32.46/init/do_mounts_initrd.c linux-2.6.32.46/init/do_mounts_initrd.c
65947 --- linux-2.6.32.46/init/do_mounts_initrd.c 2011-03-27 14:31:47.000000000 -0400
65948 +++ linux-2.6.32.46/init/do_mounts_initrd.c 2011-10-06 09:37:14.000000000 -0400
65949 @@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel
65950 sys_close(old_fd);sys_close(root_fd);
65951 sys_close(0);sys_close(1);sys_close(2);
65952 sys_setsid();
65953 - (void) sys_open("/dev/console",O_RDWR,0);
65954 + (void) sys_open((__force const char __user *)"/dev/console",O_RDWR,0);
65955 (void) sys_dup(0);
65956 (void) sys_dup(0);
65957 return kernel_execve(shell, argv, envp_init);
65958 @@ -47,13 +47,13 @@ static void __init handle_initrd(void)
65959 create_dev("/dev/root.old", Root_RAM0);
65960 /* mount initrd on rootfs' /root */
65961 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65962 - sys_mkdir("/old", 0700);
65963 - root_fd = sys_open("/", 0, 0);
65964 - old_fd = sys_open("/old", 0, 0);
65965 + sys_mkdir((const char __force_user *)"/old", 0700);
65966 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65967 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65968 /* move initrd over / and chdir/chroot in initrd root */
65969 - sys_chdir("/root");
65970 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65971 - sys_chroot(".");
65972 + sys_chdir((const char __force_user *)"/root");
65973 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65974 + sys_chroot((const char __force_user *)".");
65975
65976 /*
65977 * In case that a resume from disk is carried out by linuxrc or one of
65978 @@ -70,15 +70,15 @@ static void __init handle_initrd(void)
65979
65980 /* move initrd to rootfs' /old */
65981 sys_fchdir(old_fd);
65982 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65983 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65984 /* switch root and cwd back to / of rootfs */
65985 sys_fchdir(root_fd);
65986 - sys_chroot(".");
65987 + sys_chroot((const char __force_user *)".");
65988 sys_close(old_fd);
65989 sys_close(root_fd);
65990
65991 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65992 - sys_chdir("/old");
65993 + sys_chdir((const char __force_user *)"/old");
65994 return;
65995 }
65996
65997 @@ -86,17 +86,17 @@ static void __init handle_initrd(void)
65998 mount_root();
65999
66000 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66001 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66002 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66003 if (!error)
66004 printk("okay\n");
66005 else {
66006 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66007 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66008 if (error == -ENOENT)
66009 printk("/initrd does not exist. Ignored.\n");
66010 else
66011 printk("failed\n");
66012 printk(KERN_NOTICE "Unmounting old root\n");
66013 - sys_umount("/old", MNT_DETACH);
66014 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66015 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66016 if (fd < 0) {
66017 error = fd;
66018 @@ -119,11 +119,11 @@ int __init initrd_load(void)
66019 * mounted in the normal path.
66020 */
66021 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66022 - sys_unlink("/initrd.image");
66023 + sys_unlink((const char __force_user *)"/initrd.image");
66024 handle_initrd();
66025 return 1;
66026 }
66027 }
66028 - sys_unlink("/initrd.image");
66029 + sys_unlink((const char __force_user *)"/initrd.image");
66030 return 0;
66031 }
66032 diff -urNp linux-2.6.32.46/init/do_mounts_md.c linux-2.6.32.46/init/do_mounts_md.c
66033 --- linux-2.6.32.46/init/do_mounts_md.c 2011-03-27 14:31:47.000000000 -0400
66034 +++ linux-2.6.32.46/init/do_mounts_md.c 2011-10-06 09:37:14.000000000 -0400
66035 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
66036 partitioned ? "_d" : "", minor,
66037 md_setup_args[ent].device_names);
66038
66039 - fd = sys_open(name, 0, 0);
66040 + fd = sys_open((char __force_user *)name, 0, 0);
66041 if (fd < 0) {
66042 printk(KERN_ERR "md: open failed - cannot start "
66043 "array %s\n", name);
66044 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
66045 * array without it
66046 */
66047 sys_close(fd);
66048 - fd = sys_open(name, 0, 0);
66049 + fd = sys_open((char __force_user *)name, 0, 0);
66050 sys_ioctl(fd, BLKRRPART, 0);
66051 }
66052 sys_close(fd);
66053 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
66054
66055 wait_for_device_probe();
66056
66057 - fd = sys_open("/dev/md0", 0, 0);
66058 + fd = sys_open((__force char __user *)"/dev/md0", 0, 0);
66059 if (fd >= 0) {
66060 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66061 sys_close(fd);
66062 diff -urNp linux-2.6.32.46/init/initramfs.c linux-2.6.32.46/init/initramfs.c
66063 --- linux-2.6.32.46/init/initramfs.c 2011-03-27 14:31:47.000000000 -0400
66064 +++ linux-2.6.32.46/init/initramfs.c 2011-10-06 09:37:14.000000000 -0400
66065 @@ -74,7 +74,7 @@ static void __init free_hash(void)
66066 }
66067 }
66068
66069 -static long __init do_utime(char __user *filename, time_t mtime)
66070 +static long __init do_utime(__force char __user *filename, time_t mtime)
66071 {
66072 struct timespec t[2];
66073
66074 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
66075 struct dir_entry *de, *tmp;
66076 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66077 list_del(&de->list);
66078 - do_utime(de->name, de->mtime);
66079 + do_utime((char __force_user *)de->name, de->mtime);
66080 kfree(de->name);
66081 kfree(de);
66082 }
66083 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
66084 if (nlink >= 2) {
66085 char *old = find_link(major, minor, ino, mode, collected);
66086 if (old)
66087 - return (sys_link(old, collected) < 0) ? -1 : 1;
66088 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66089 }
66090 return 0;
66091 }
66092 @@ -280,11 +280,11 @@ static void __init clean_path(char *path
66093 {
66094 struct stat st;
66095
66096 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66097 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66098 if (S_ISDIR(st.st_mode))
66099 - sys_rmdir(path);
66100 + sys_rmdir((char __force_user *)path);
66101 else
66102 - sys_unlink(path);
66103 + sys_unlink((char __force_user *)path);
66104 }
66105 }
66106
66107 @@ -305,7 +305,7 @@ static int __init do_name(void)
66108 int openflags = O_WRONLY|O_CREAT;
66109 if (ml != 1)
66110 openflags |= O_TRUNC;
66111 - wfd = sys_open(collected, openflags, mode);
66112 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66113
66114 if (wfd >= 0) {
66115 sys_fchown(wfd, uid, gid);
66116 @@ -317,17 +317,17 @@ static int __init do_name(void)
66117 }
66118 }
66119 } else if (S_ISDIR(mode)) {
66120 - sys_mkdir(collected, mode);
66121 - sys_chown(collected, uid, gid);
66122 - sys_chmod(collected, mode);
66123 + sys_mkdir((char __force_user *)collected, mode);
66124 + sys_chown((char __force_user *)collected, uid, gid);
66125 + sys_chmod((char __force_user *)collected, mode);
66126 dir_add(collected, mtime);
66127 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66128 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66129 if (maybe_link() == 0) {
66130 - sys_mknod(collected, mode, rdev);
66131 - sys_chown(collected, uid, gid);
66132 - sys_chmod(collected, mode);
66133 - do_utime(collected, mtime);
66134 + sys_mknod((char __force_user *)collected, mode, rdev);
66135 + sys_chown((char __force_user *)collected, uid, gid);
66136 + sys_chmod((char __force_user *)collected, mode);
66137 + do_utime((char __force_user *)collected, mtime);
66138 }
66139 }
66140 return 0;
66141 @@ -336,15 +336,15 @@ static int __init do_name(void)
66142 static int __init do_copy(void)
66143 {
66144 if (count >= body_len) {
66145 - sys_write(wfd, victim, body_len);
66146 + sys_write(wfd, (char __force_user *)victim, body_len);
66147 sys_close(wfd);
66148 - do_utime(vcollected, mtime);
66149 + do_utime((char __force_user *)vcollected, mtime);
66150 kfree(vcollected);
66151 eat(body_len);
66152 state = SkipIt;
66153 return 0;
66154 } else {
66155 - sys_write(wfd, victim, count);
66156 + sys_write(wfd, (char __force_user *)victim, count);
66157 body_len -= count;
66158 eat(count);
66159 return 1;
66160 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
66161 {
66162 collected[N_ALIGN(name_len) + body_len] = '\0';
66163 clean_path(collected, 0);
66164 - sys_symlink(collected + N_ALIGN(name_len), collected);
66165 - sys_lchown(collected, uid, gid);
66166 - do_utime(collected, mtime);
66167 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66168 + sys_lchown((char __force_user *)collected, uid, gid);
66169 + do_utime((char __force_user *)collected, mtime);
66170 state = SkipIt;
66171 next_state = Reset;
66172 return 0;
66173 diff -urNp linux-2.6.32.46/init/main.c linux-2.6.32.46/init/main.c
66174 --- linux-2.6.32.46/init/main.c 2011-05-10 22:12:01.000000000 -0400
66175 +++ linux-2.6.32.46/init/main.c 2011-10-06 09:37:14.000000000 -0400
66176 @@ -97,6 +97,7 @@ static inline void mark_rodata_ro(void)
66177 #ifdef CONFIG_TC
66178 extern void tc_init(void);
66179 #endif
66180 +extern void grsecurity_init(void);
66181
66182 enum system_states system_state __read_mostly;
66183 EXPORT_SYMBOL(system_state);
66184 @@ -183,6 +184,49 @@ static int __init set_reset_devices(char
66185
66186 __setup("reset_devices", set_reset_devices);
66187
66188 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66189 +extern char pax_enter_kernel_user[];
66190 +extern char pax_exit_kernel_user[];
66191 +extern pgdval_t clone_pgd_mask;
66192 +#endif
66193 +
66194 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66195 +static int __init setup_pax_nouderef(char *str)
66196 +{
66197 +#ifdef CONFIG_X86_32
66198 + unsigned int cpu;
66199 + struct desc_struct *gdt;
66200 +
66201 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
66202 + gdt = get_cpu_gdt_table(cpu);
66203 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66204 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66205 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66206 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66207 + }
66208 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
66209 +#else
66210 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66211 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66212 + clone_pgd_mask = ~(pgdval_t)0UL;
66213 +#endif
66214 +
66215 + return 0;
66216 +}
66217 +early_param("pax_nouderef", setup_pax_nouderef);
66218 +#endif
66219 +
66220 +#ifdef CONFIG_PAX_SOFTMODE
66221 +int pax_softmode;
66222 +
66223 +static int __init setup_pax_softmode(char *str)
66224 +{
66225 + get_option(&str, &pax_softmode);
66226 + return 1;
66227 +}
66228 +__setup("pax_softmode=", setup_pax_softmode);
66229 +#endif
66230 +
66231 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66232 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66233 static const char *panic_later, *panic_param;
66234 @@ -705,52 +749,53 @@ int initcall_debug;
66235 core_param(initcall_debug, initcall_debug, bool, 0644);
66236
66237 static char msgbuf[64];
66238 -static struct boot_trace_call call;
66239 -static struct boot_trace_ret ret;
66240 +static struct boot_trace_call trace_call;
66241 +static struct boot_trace_ret trace_ret;
66242
66243 int do_one_initcall(initcall_t fn)
66244 {
66245 int count = preempt_count();
66246 ktime_t calltime, delta, rettime;
66247 + const char *msg1 = "", *msg2 = "";
66248
66249 if (initcall_debug) {
66250 - call.caller = task_pid_nr(current);
66251 - printk("calling %pF @ %i\n", fn, call.caller);
66252 + trace_call.caller = task_pid_nr(current);
66253 + printk("calling %pF @ %i\n", fn, trace_call.caller);
66254 calltime = ktime_get();
66255 - trace_boot_call(&call, fn);
66256 + trace_boot_call(&trace_call, fn);
66257 enable_boot_trace();
66258 }
66259
66260 - ret.result = fn();
66261 + trace_ret.result = fn();
66262
66263 if (initcall_debug) {
66264 disable_boot_trace();
66265 rettime = ktime_get();
66266 delta = ktime_sub(rettime, calltime);
66267 - ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
66268 - trace_boot_ret(&ret, fn);
66269 + trace_ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
66270 + trace_boot_ret(&trace_ret, fn);
66271 printk("initcall %pF returned %d after %Ld usecs\n", fn,
66272 - ret.result, ret.duration);
66273 + trace_ret.result, trace_ret.duration);
66274 }
66275
66276 msgbuf[0] = 0;
66277
66278 - if (ret.result && ret.result != -ENODEV && initcall_debug)
66279 - sprintf(msgbuf, "error code %d ", ret.result);
66280 + if (trace_ret.result && trace_ret.result != -ENODEV && initcall_debug)
66281 + sprintf(msgbuf, "error code %d ", trace_ret.result);
66282
66283 if (preempt_count() != count) {
66284 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66285 + msg1 = " preemption imbalance";
66286 preempt_count() = count;
66287 }
66288 if (irqs_disabled()) {
66289 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66290 + msg2 = " disabled interrupts";
66291 local_irq_enable();
66292 }
66293 - if (msgbuf[0]) {
66294 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66295 + if (msgbuf[0] || *msg1 || *msg2) {
66296 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66297 }
66298
66299 - return ret.result;
66300 + return trace_ret.result;
66301 }
66302
66303
66304 @@ -893,11 +938,13 @@ static int __init kernel_init(void * unu
66305 if (!ramdisk_execute_command)
66306 ramdisk_execute_command = "/init";
66307
66308 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66309 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66310 ramdisk_execute_command = NULL;
66311 prepare_namespace();
66312 }
66313
66314 + grsecurity_init();
66315 +
66316 /*
66317 * Ok, we have completed the initial bootup, and
66318 * we're essentially up and running. Get rid of the
66319 diff -urNp linux-2.6.32.46/init/noinitramfs.c linux-2.6.32.46/init/noinitramfs.c
66320 --- linux-2.6.32.46/init/noinitramfs.c 2011-03-27 14:31:47.000000000 -0400
66321 +++ linux-2.6.32.46/init/noinitramfs.c 2011-04-17 15:56:46.000000000 -0400
66322 @@ -29,7 +29,7 @@ static int __init default_rootfs(void)
66323 {
66324 int err;
66325
66326 - err = sys_mkdir("/dev", 0755);
66327 + err = sys_mkdir((const char __user *)"/dev", 0755);
66328 if (err < 0)
66329 goto out;
66330
66331 @@ -39,7 +39,7 @@ static int __init default_rootfs(void)
66332 if (err < 0)
66333 goto out;
66334
66335 - err = sys_mkdir("/root", 0700);
66336 + err = sys_mkdir((const char __user *)"/root", 0700);
66337 if (err < 0)
66338 goto out;
66339
66340 diff -urNp linux-2.6.32.46/ipc/mqueue.c linux-2.6.32.46/ipc/mqueue.c
66341 --- linux-2.6.32.46/ipc/mqueue.c 2011-03-27 14:31:47.000000000 -0400
66342 +++ linux-2.6.32.46/ipc/mqueue.c 2011-04-17 15:56:46.000000000 -0400
66343 @@ -150,6 +150,7 @@ static struct inode *mqueue_get_inode(st
66344 mq_bytes = (mq_msg_tblsz +
66345 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
66346
66347 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66348 spin_lock(&mq_lock);
66349 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66350 u->mq_bytes + mq_bytes >
66351 diff -urNp linux-2.6.32.46/ipc/msg.c linux-2.6.32.46/ipc/msg.c
66352 --- linux-2.6.32.46/ipc/msg.c 2011-03-27 14:31:47.000000000 -0400
66353 +++ linux-2.6.32.46/ipc/msg.c 2011-08-05 20:33:55.000000000 -0400
66354 @@ -310,18 +310,19 @@ static inline int msg_security(struct ke
66355 return security_msg_queue_associate(msq, msgflg);
66356 }
66357
66358 +static struct ipc_ops msg_ops = {
66359 + .getnew = newque,
66360 + .associate = msg_security,
66361 + .more_checks = NULL
66362 +};
66363 +
66364 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66365 {
66366 struct ipc_namespace *ns;
66367 - struct ipc_ops msg_ops;
66368 struct ipc_params msg_params;
66369
66370 ns = current->nsproxy->ipc_ns;
66371
66372 - msg_ops.getnew = newque;
66373 - msg_ops.associate = msg_security;
66374 - msg_ops.more_checks = NULL;
66375 -
66376 msg_params.key = key;
66377 msg_params.flg = msgflg;
66378
66379 diff -urNp linux-2.6.32.46/ipc/sem.c linux-2.6.32.46/ipc/sem.c
66380 --- linux-2.6.32.46/ipc/sem.c 2011-03-27 14:31:47.000000000 -0400
66381 +++ linux-2.6.32.46/ipc/sem.c 2011-08-05 20:33:55.000000000 -0400
66382 @@ -309,10 +309,15 @@ static inline int sem_more_checks(struct
66383 return 0;
66384 }
66385
66386 +static struct ipc_ops sem_ops = {
66387 + .getnew = newary,
66388 + .associate = sem_security,
66389 + .more_checks = sem_more_checks
66390 +};
66391 +
66392 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66393 {
66394 struct ipc_namespace *ns;
66395 - struct ipc_ops sem_ops;
66396 struct ipc_params sem_params;
66397
66398 ns = current->nsproxy->ipc_ns;
66399 @@ -320,10 +325,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int,
66400 if (nsems < 0 || nsems > ns->sc_semmsl)
66401 return -EINVAL;
66402
66403 - sem_ops.getnew = newary;
66404 - sem_ops.associate = sem_security;
66405 - sem_ops.more_checks = sem_more_checks;
66406 -
66407 sem_params.key = key;
66408 sem_params.flg = semflg;
66409 sem_params.u.nsems = nsems;
66410 @@ -671,6 +672,8 @@ static int semctl_main(struct ipc_namesp
66411 ushort* sem_io = fast_sem_io;
66412 int nsems;
66413
66414 + pax_track_stack();
66415 +
66416 sma = sem_lock_check(ns, semid);
66417 if (IS_ERR(sma))
66418 return PTR_ERR(sma);
66419 @@ -1071,6 +1074,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
66420 unsigned long jiffies_left = 0;
66421 struct ipc_namespace *ns;
66422
66423 + pax_track_stack();
66424 +
66425 ns = current->nsproxy->ipc_ns;
66426
66427 if (nsops < 1 || semid < 0)
66428 diff -urNp linux-2.6.32.46/ipc/shm.c linux-2.6.32.46/ipc/shm.c
66429 --- linux-2.6.32.46/ipc/shm.c 2011-03-27 14:31:47.000000000 -0400
66430 +++ linux-2.6.32.46/ipc/shm.c 2011-08-05 20:33:55.000000000 -0400
66431 @@ -70,6 +70,14 @@ static void shm_destroy (struct ipc_name
66432 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66433 #endif
66434
66435 +#ifdef CONFIG_GRKERNSEC
66436 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66437 + const time_t shm_createtime, const uid_t cuid,
66438 + const int shmid);
66439 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66440 + const time_t shm_createtime);
66441 +#endif
66442 +
66443 void shm_init_ns(struct ipc_namespace *ns)
66444 {
66445 ns->shm_ctlmax = SHMMAX;
66446 @@ -396,6 +404,14 @@ static int newseg(struct ipc_namespace *
66447 shp->shm_lprid = 0;
66448 shp->shm_atim = shp->shm_dtim = 0;
66449 shp->shm_ctim = get_seconds();
66450 +#ifdef CONFIG_GRKERNSEC
66451 + {
66452 + struct timespec timeval;
66453 + do_posix_clock_monotonic_gettime(&timeval);
66454 +
66455 + shp->shm_createtime = timeval.tv_sec;
66456 + }
66457 +#endif
66458 shp->shm_segsz = size;
66459 shp->shm_nattch = 0;
66460 shp->shm_file = file;
66461 @@ -446,18 +462,19 @@ static inline int shm_more_checks(struct
66462 return 0;
66463 }
66464
66465 +static struct ipc_ops shm_ops = {
66466 + .getnew = newseg,
66467 + .associate = shm_security,
66468 + .more_checks = shm_more_checks
66469 +};
66470 +
66471 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66472 {
66473 struct ipc_namespace *ns;
66474 - struct ipc_ops shm_ops;
66475 struct ipc_params shm_params;
66476
66477 ns = current->nsproxy->ipc_ns;
66478
66479 - shm_ops.getnew = newseg;
66480 - shm_ops.associate = shm_security;
66481 - shm_ops.more_checks = shm_more_checks;
66482 -
66483 shm_params.key = key;
66484 shm_params.flg = shmflg;
66485 shm_params.u.size = size;
66486 @@ -880,9 +897,21 @@ long do_shmat(int shmid, char __user *sh
66487 if (err)
66488 goto out_unlock;
66489
66490 +#ifdef CONFIG_GRKERNSEC
66491 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66492 + shp->shm_perm.cuid, shmid) ||
66493 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66494 + err = -EACCES;
66495 + goto out_unlock;
66496 + }
66497 +#endif
66498 +
66499 path.dentry = dget(shp->shm_file->f_path.dentry);
66500 path.mnt = shp->shm_file->f_path.mnt;
66501 shp->shm_nattch++;
66502 +#ifdef CONFIG_GRKERNSEC
66503 + shp->shm_lapid = current->pid;
66504 +#endif
66505 size = i_size_read(path.dentry->d_inode);
66506 shm_unlock(shp);
66507
66508 diff -urNp linux-2.6.32.46/kernel/acct.c linux-2.6.32.46/kernel/acct.c
66509 --- linux-2.6.32.46/kernel/acct.c 2011-03-27 14:31:47.000000000 -0400
66510 +++ linux-2.6.32.46/kernel/acct.c 2011-10-06 09:37:14.000000000 -0400
66511 @@ -579,7 +579,7 @@ static void do_acct_process(struct bsd_a
66512 */
66513 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66514 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66515 - file->f_op->write(file, (char *)&ac,
66516 + file->f_op->write(file, (char __force_user *)&ac,
66517 sizeof(acct_t), &file->f_pos);
66518 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66519 set_fs(fs);
66520 diff -urNp linux-2.6.32.46/kernel/audit.c linux-2.6.32.46/kernel/audit.c
66521 --- linux-2.6.32.46/kernel/audit.c 2011-03-27 14:31:47.000000000 -0400
66522 +++ linux-2.6.32.46/kernel/audit.c 2011-05-04 17:56:28.000000000 -0400
66523 @@ -110,7 +110,7 @@ u32 audit_sig_sid = 0;
66524 3) suppressed due to audit_rate_limit
66525 4) suppressed due to audit_backlog_limit
66526 */
66527 -static atomic_t audit_lost = ATOMIC_INIT(0);
66528 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66529
66530 /* The netlink socket. */
66531 static struct sock *audit_sock;
66532 @@ -232,7 +232,7 @@ void audit_log_lost(const char *message)
66533 unsigned long now;
66534 int print;
66535
66536 - atomic_inc(&audit_lost);
66537 + atomic_inc_unchecked(&audit_lost);
66538
66539 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66540
66541 @@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
66542 printk(KERN_WARNING
66543 "audit: audit_lost=%d audit_rate_limit=%d "
66544 "audit_backlog_limit=%d\n",
66545 - atomic_read(&audit_lost),
66546 + atomic_read_unchecked(&audit_lost),
66547 audit_rate_limit,
66548 audit_backlog_limit);
66549 audit_panic(message);
66550 @@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_b
66551 status_set.pid = audit_pid;
66552 status_set.rate_limit = audit_rate_limit;
66553 status_set.backlog_limit = audit_backlog_limit;
66554 - status_set.lost = atomic_read(&audit_lost);
66555 + status_set.lost = atomic_read_unchecked(&audit_lost);
66556 status_set.backlog = skb_queue_len(&audit_skb_queue);
66557 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66558 &status_set, sizeof(status_set));
66559 @@ -891,8 +891,10 @@ static int audit_receive_msg(struct sk_b
66560 spin_unlock_irq(&tsk->sighand->siglock);
66561 }
66562 read_unlock(&tasklist_lock);
66563 - audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_TTY_GET, 0, 0,
66564 - &s, sizeof(s));
66565 +
66566 + if (!err)
66567 + audit_send_reply(NETLINK_CB(skb).pid, seq,
66568 + AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
66569 break;
66570 }
66571 case AUDIT_TTY_SET: {
66572 diff -urNp linux-2.6.32.46/kernel/auditsc.c linux-2.6.32.46/kernel/auditsc.c
66573 --- linux-2.6.32.46/kernel/auditsc.c 2011-03-27 14:31:47.000000000 -0400
66574 +++ linux-2.6.32.46/kernel/auditsc.c 2011-05-04 17:56:28.000000000 -0400
66575 @@ -2113,7 +2113,7 @@ int auditsc_get_stamp(struct audit_conte
66576 }
66577
66578 /* global counter which is incremented every time something logs in */
66579 -static atomic_t session_id = ATOMIC_INIT(0);
66580 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66581
66582 /**
66583 * audit_set_loginuid - set a task's audit_context loginuid
66584 @@ -2126,7 +2126,7 @@ static atomic_t session_id = ATOMIC_INIT
66585 */
66586 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
66587 {
66588 - unsigned int sessionid = atomic_inc_return(&session_id);
66589 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
66590 struct audit_context *context = task->audit_context;
66591
66592 if (context && context->in_syscall) {
66593 diff -urNp linux-2.6.32.46/kernel/capability.c linux-2.6.32.46/kernel/capability.c
66594 --- linux-2.6.32.46/kernel/capability.c 2011-03-27 14:31:47.000000000 -0400
66595 +++ linux-2.6.32.46/kernel/capability.c 2011-04-17 15:56:46.000000000 -0400
66596 @@ -305,10 +305,26 @@ int capable(int cap)
66597 BUG();
66598 }
66599
66600 - if (security_capable(cap) == 0) {
66601 + if (security_capable(cap) == 0 && gr_is_capable(cap)) {
66602 current->flags |= PF_SUPERPRIV;
66603 return 1;
66604 }
66605 return 0;
66606 }
66607 +
66608 +int capable_nolog(int cap)
66609 +{
66610 + if (unlikely(!cap_valid(cap))) {
66611 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66612 + BUG();
66613 + }
66614 +
66615 + if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
66616 + current->flags |= PF_SUPERPRIV;
66617 + return 1;
66618 + }
66619 + return 0;
66620 +}
66621 +
66622 EXPORT_SYMBOL(capable);
66623 +EXPORT_SYMBOL(capable_nolog);
66624 diff -urNp linux-2.6.32.46/kernel/cgroup.c linux-2.6.32.46/kernel/cgroup.c
66625 --- linux-2.6.32.46/kernel/cgroup.c 2011-03-27 14:31:47.000000000 -0400
66626 +++ linux-2.6.32.46/kernel/cgroup.c 2011-05-16 21:46:57.000000000 -0400
66627 @@ -536,6 +536,8 @@ static struct css_set *find_css_set(
66628 struct hlist_head *hhead;
66629 struct cg_cgroup_link *link;
66630
66631 + pax_track_stack();
66632 +
66633 /* First see if we already have a cgroup group that matches
66634 * the desired set */
66635 read_lock(&css_set_lock);
66636 diff -urNp linux-2.6.32.46/kernel/compat.c linux-2.6.32.46/kernel/compat.c
66637 --- linux-2.6.32.46/kernel/compat.c 2011-03-27 14:31:47.000000000 -0400
66638 +++ linux-2.6.32.46/kernel/compat.c 2011-10-06 09:37:14.000000000 -0400
66639 @@ -108,7 +108,7 @@ static long compat_nanosleep_restart(str
66640 mm_segment_t oldfs;
66641 long ret;
66642
66643 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66644 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66645 oldfs = get_fs();
66646 set_fs(KERNEL_DS);
66647 ret = hrtimer_nanosleep_restart(restart);
66648 @@ -140,7 +140,7 @@ asmlinkage long compat_sys_nanosleep(str
66649 oldfs = get_fs();
66650 set_fs(KERNEL_DS);
66651 ret = hrtimer_nanosleep(&tu,
66652 - rmtp ? (struct timespec __user *)&rmt : NULL,
66653 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66654 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66655 set_fs(oldfs);
66656
66657 @@ -247,7 +247,7 @@ asmlinkage long compat_sys_sigpending(co
66658 mm_segment_t old_fs = get_fs();
66659
66660 set_fs(KERNEL_DS);
66661 - ret = sys_sigpending((old_sigset_t __user *) &s);
66662 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66663 set_fs(old_fs);
66664 if (ret == 0)
66665 ret = put_user(s, set);
66666 @@ -266,8 +266,8 @@ asmlinkage long compat_sys_sigprocmask(i
66667 old_fs = get_fs();
66668 set_fs(KERNEL_DS);
66669 ret = sys_sigprocmask(how,
66670 - set ? (old_sigset_t __user *) &s : NULL,
66671 - oset ? (old_sigset_t __user *) &s : NULL);
66672 + set ? (old_sigset_t __force_user *) &s : NULL,
66673 + oset ? (old_sigset_t __force_user *) &s : NULL);
66674 set_fs(old_fs);
66675 if (ret == 0)
66676 if (oset)
66677 @@ -310,7 +310,7 @@ asmlinkage long compat_sys_old_getrlimit
66678 mm_segment_t old_fs = get_fs();
66679
66680 set_fs(KERNEL_DS);
66681 - ret = sys_old_getrlimit(resource, &r);
66682 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66683 set_fs(old_fs);
66684
66685 if (!ret) {
66686 @@ -385,7 +385,7 @@ asmlinkage long compat_sys_getrusage(int
66687 mm_segment_t old_fs = get_fs();
66688
66689 set_fs(KERNEL_DS);
66690 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66691 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66692 set_fs(old_fs);
66693
66694 if (ret)
66695 @@ -412,8 +412,8 @@ compat_sys_wait4(compat_pid_t pid, compa
66696 set_fs (KERNEL_DS);
66697 ret = sys_wait4(pid,
66698 (stat_addr ?
66699 - (unsigned int __user *) &status : NULL),
66700 - options, (struct rusage __user *) &r);
66701 + (unsigned int __force_user *) &status : NULL),
66702 + options, (struct rusage __force_user *) &r);
66703 set_fs (old_fs);
66704
66705 if (ret > 0) {
66706 @@ -438,8 +438,8 @@ asmlinkage long compat_sys_waitid(int wh
66707 memset(&info, 0, sizeof(info));
66708
66709 set_fs(KERNEL_DS);
66710 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66711 - uru ? (struct rusage __user *)&ru : NULL);
66712 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66713 + uru ? (struct rusage __force_user *)&ru : NULL);
66714 set_fs(old_fs);
66715
66716 if ((ret < 0) || (info.si_signo == 0))
66717 @@ -569,8 +569,8 @@ long compat_sys_timer_settime(timer_t ti
66718 oldfs = get_fs();
66719 set_fs(KERNEL_DS);
66720 err = sys_timer_settime(timer_id, flags,
66721 - (struct itimerspec __user *) &newts,
66722 - (struct itimerspec __user *) &oldts);
66723 + (struct itimerspec __force_user *) &newts,
66724 + (struct itimerspec __force_user *) &oldts);
66725 set_fs(oldfs);
66726 if (!err && old && put_compat_itimerspec(old, &oldts))
66727 return -EFAULT;
66728 @@ -587,7 +587,7 @@ long compat_sys_timer_gettime(timer_t ti
66729 oldfs = get_fs();
66730 set_fs(KERNEL_DS);
66731 err = sys_timer_gettime(timer_id,
66732 - (struct itimerspec __user *) &ts);
66733 + (struct itimerspec __force_user *) &ts);
66734 set_fs(oldfs);
66735 if (!err && put_compat_itimerspec(setting, &ts))
66736 return -EFAULT;
66737 @@ -606,7 +606,7 @@ long compat_sys_clock_settime(clockid_t
66738 oldfs = get_fs();
66739 set_fs(KERNEL_DS);
66740 err = sys_clock_settime(which_clock,
66741 - (struct timespec __user *) &ts);
66742 + (struct timespec __force_user *) &ts);
66743 set_fs(oldfs);
66744 return err;
66745 }
66746 @@ -621,7 +621,7 @@ long compat_sys_clock_gettime(clockid_t
66747 oldfs = get_fs();
66748 set_fs(KERNEL_DS);
66749 err = sys_clock_gettime(which_clock,
66750 - (struct timespec __user *) &ts);
66751 + (struct timespec __force_user *) &ts);
66752 set_fs(oldfs);
66753 if (!err && put_compat_timespec(&ts, tp))
66754 return -EFAULT;
66755 @@ -638,7 +638,7 @@ long compat_sys_clock_getres(clockid_t w
66756 oldfs = get_fs();
66757 set_fs(KERNEL_DS);
66758 err = sys_clock_getres(which_clock,
66759 - (struct timespec __user *) &ts);
66760 + (struct timespec __force_user *) &ts);
66761 set_fs(oldfs);
66762 if (!err && tp && put_compat_timespec(&ts, tp))
66763 return -EFAULT;
66764 @@ -650,9 +650,9 @@ static long compat_clock_nanosleep_resta
66765 long err;
66766 mm_segment_t oldfs;
66767 struct timespec tu;
66768 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66769 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66770
66771 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66772 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66773 oldfs = get_fs();
66774 set_fs(KERNEL_DS);
66775 err = clock_nanosleep_restart(restart);
66776 @@ -684,8 +684,8 @@ long compat_sys_clock_nanosleep(clockid_
66777 oldfs = get_fs();
66778 set_fs(KERNEL_DS);
66779 err = sys_clock_nanosleep(which_clock, flags,
66780 - (struct timespec __user *) &in,
66781 - (struct timespec __user *) &out);
66782 + (struct timespec __force_user *) &in,
66783 + (struct timespec __force_user *) &out);
66784 set_fs(oldfs);
66785
66786 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66787 diff -urNp linux-2.6.32.46/kernel/configs.c linux-2.6.32.46/kernel/configs.c
66788 --- linux-2.6.32.46/kernel/configs.c 2011-03-27 14:31:47.000000000 -0400
66789 +++ linux-2.6.32.46/kernel/configs.c 2011-04-17 15:56:46.000000000 -0400
66790 @@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
66791 struct proc_dir_entry *entry;
66792
66793 /* create the current config file */
66794 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66795 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66796 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66797 + &ikconfig_file_ops);
66798 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66799 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66800 + &ikconfig_file_ops);
66801 +#endif
66802 +#else
66803 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66804 &ikconfig_file_ops);
66805 +#endif
66806 +
66807 if (!entry)
66808 return -ENOMEM;
66809
66810 diff -urNp linux-2.6.32.46/kernel/cpu.c linux-2.6.32.46/kernel/cpu.c
66811 --- linux-2.6.32.46/kernel/cpu.c 2011-03-27 14:31:47.000000000 -0400
66812 +++ linux-2.6.32.46/kernel/cpu.c 2011-04-17 15:56:46.000000000 -0400
66813 @@ -19,7 +19,7 @@
66814 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
66815 static DEFINE_MUTEX(cpu_add_remove_lock);
66816
66817 -static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
66818 +static RAW_NOTIFIER_HEAD(cpu_chain);
66819
66820 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
66821 * Should always be manipulated under cpu_add_remove_lock
66822 diff -urNp linux-2.6.32.46/kernel/cred.c linux-2.6.32.46/kernel/cred.c
66823 --- linux-2.6.32.46/kernel/cred.c 2011-03-27 14:31:47.000000000 -0400
66824 +++ linux-2.6.32.46/kernel/cred.c 2011-08-11 19:49:38.000000000 -0400
66825 @@ -160,6 +160,8 @@ static void put_cred_rcu(struct rcu_head
66826 */
66827 void __put_cred(struct cred *cred)
66828 {
66829 + pax_track_stack();
66830 +
66831 kdebug("__put_cred(%p{%d,%d})", cred,
66832 atomic_read(&cred->usage),
66833 read_cred_subscribers(cred));
66834 @@ -184,6 +186,8 @@ void exit_creds(struct task_struct *tsk)
66835 {
66836 struct cred *cred;
66837
66838 + pax_track_stack();
66839 +
66840 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
66841 atomic_read(&tsk->cred->usage),
66842 read_cred_subscribers(tsk->cred));
66843 @@ -222,6 +226,8 @@ const struct cred *get_task_cred(struct
66844 {
66845 const struct cred *cred;
66846
66847 + pax_track_stack();
66848 +
66849 rcu_read_lock();
66850
66851 do {
66852 @@ -241,6 +247,8 @@ struct cred *cred_alloc_blank(void)
66853 {
66854 struct cred *new;
66855
66856 + pax_track_stack();
66857 +
66858 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
66859 if (!new)
66860 return NULL;
66861 @@ -289,6 +297,8 @@ struct cred *prepare_creds(void)
66862 const struct cred *old;
66863 struct cred *new;
66864
66865 + pax_track_stack();
66866 +
66867 validate_process_creds();
66868
66869 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66870 @@ -335,6 +345,8 @@ struct cred *prepare_exec_creds(void)
66871 struct thread_group_cred *tgcred = NULL;
66872 struct cred *new;
66873
66874 + pax_track_stack();
66875 +
66876 #ifdef CONFIG_KEYS
66877 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
66878 if (!tgcred)
66879 @@ -441,6 +453,8 @@ int copy_creds(struct task_struct *p, un
66880 struct cred *new;
66881 int ret;
66882
66883 + pax_track_stack();
66884 +
66885 mutex_init(&p->cred_guard_mutex);
66886
66887 if (
66888 @@ -528,6 +542,8 @@ int commit_creds(struct cred *new)
66889 struct task_struct *task = current;
66890 const struct cred *old = task->real_cred;
66891
66892 + pax_track_stack();
66893 +
66894 kdebug("commit_creds(%p{%d,%d})", new,
66895 atomic_read(&new->usage),
66896 read_cred_subscribers(new));
66897 @@ -544,6 +560,8 @@ int commit_creds(struct cred *new)
66898
66899 get_cred(new); /* we will require a ref for the subj creds too */
66900
66901 + gr_set_role_label(task, new->uid, new->gid);
66902 +
66903 /* dumpability changes */
66904 if (old->euid != new->euid ||
66905 old->egid != new->egid ||
66906 @@ -563,10 +581,8 @@ int commit_creds(struct cred *new)
66907 key_fsgid_changed(task);
66908
66909 /* do it
66910 - * - What if a process setreuid()'s and this brings the
66911 - * new uid over his NPROC rlimit? We can check this now
66912 - * cheaply with the new uid cache, so if it matters
66913 - * we should be checking for it. -DaveM
66914 + * RLIMIT_NPROC limits on user->processes have already been checked
66915 + * in set_user().
66916 */
66917 alter_cred_subscribers(new, 2);
66918 if (new->user != old->user)
66919 @@ -606,6 +622,8 @@ EXPORT_SYMBOL(commit_creds);
66920 */
66921 void abort_creds(struct cred *new)
66922 {
66923 + pax_track_stack();
66924 +
66925 kdebug("abort_creds(%p{%d,%d})", new,
66926 atomic_read(&new->usage),
66927 read_cred_subscribers(new));
66928 @@ -629,6 +647,8 @@ const struct cred *override_creds(const
66929 {
66930 const struct cred *old = current->cred;
66931
66932 + pax_track_stack();
66933 +
66934 kdebug("override_creds(%p{%d,%d})", new,
66935 atomic_read(&new->usage),
66936 read_cred_subscribers(new));
66937 @@ -658,6 +678,8 @@ void revert_creds(const struct cred *old
66938 {
66939 const struct cred *override = current->cred;
66940
66941 + pax_track_stack();
66942 +
66943 kdebug("revert_creds(%p{%d,%d})", old,
66944 atomic_read(&old->usage),
66945 read_cred_subscribers(old));
66946 @@ -704,6 +726,8 @@ struct cred *prepare_kernel_cred(struct
66947 const struct cred *old;
66948 struct cred *new;
66949
66950 + pax_track_stack();
66951 +
66952 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66953 if (!new)
66954 return NULL;
66955 @@ -758,6 +782,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
66956 */
66957 int set_security_override(struct cred *new, u32 secid)
66958 {
66959 + pax_track_stack();
66960 +
66961 return security_kernel_act_as(new, secid);
66962 }
66963 EXPORT_SYMBOL(set_security_override);
66964 @@ -777,6 +803,8 @@ int set_security_override_from_ctx(struc
66965 u32 secid;
66966 int ret;
66967
66968 + pax_track_stack();
66969 +
66970 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
66971 if (ret < 0)
66972 return ret;
66973 diff -urNp linux-2.6.32.46/kernel/exit.c linux-2.6.32.46/kernel/exit.c
66974 --- linux-2.6.32.46/kernel/exit.c 2011-03-27 14:31:47.000000000 -0400
66975 +++ linux-2.6.32.46/kernel/exit.c 2011-08-17 19:19:50.000000000 -0400
66976 @@ -55,6 +55,10 @@
66977 #include <asm/pgtable.h>
66978 #include <asm/mmu_context.h>
66979
66980 +#ifdef CONFIG_GRKERNSEC
66981 +extern rwlock_t grsec_exec_file_lock;
66982 +#endif
66983 +
66984 static void exit_mm(struct task_struct * tsk);
66985
66986 static void __unhash_process(struct task_struct *p)
66987 @@ -174,6 +178,10 @@ void release_task(struct task_struct * p
66988 struct task_struct *leader;
66989 int zap_leader;
66990 repeat:
66991 +#ifdef CONFIG_NET
66992 + gr_del_task_from_ip_table(p);
66993 +#endif
66994 +
66995 tracehook_prepare_release_task(p);
66996 /* don't need to get the RCU readlock here - the process is dead and
66997 * can't be modifying its own credentials */
66998 @@ -341,11 +349,22 @@ static void reparent_to_kthreadd(void)
66999 {
67000 write_lock_irq(&tasklist_lock);
67001
67002 +#ifdef CONFIG_GRKERNSEC
67003 + write_lock(&grsec_exec_file_lock);
67004 + if (current->exec_file) {
67005 + fput(current->exec_file);
67006 + current->exec_file = NULL;
67007 + }
67008 + write_unlock(&grsec_exec_file_lock);
67009 +#endif
67010 +
67011 ptrace_unlink(current);
67012 /* Reparent to init */
67013 current->real_parent = current->parent = kthreadd_task;
67014 list_move_tail(&current->sibling, &current->real_parent->children);
67015
67016 + gr_set_kernel_label(current);
67017 +
67018 /* Set the exit signal to SIGCHLD so we signal init on exit */
67019 current->exit_signal = SIGCHLD;
67020
67021 @@ -397,7 +416,7 @@ int allow_signal(int sig)
67022 * know it'll be handled, so that they don't get converted to
67023 * SIGKILL or just silently dropped.
67024 */
67025 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67026 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67027 recalc_sigpending();
67028 spin_unlock_irq(&current->sighand->siglock);
67029 return 0;
67030 @@ -433,6 +452,17 @@ void daemonize(const char *name, ...)
67031 vsnprintf(current->comm, sizeof(current->comm), name, args);
67032 va_end(args);
67033
67034 +#ifdef CONFIG_GRKERNSEC
67035 + write_lock(&grsec_exec_file_lock);
67036 + if (current->exec_file) {
67037 + fput(current->exec_file);
67038 + current->exec_file = NULL;
67039 + }
67040 + write_unlock(&grsec_exec_file_lock);
67041 +#endif
67042 +
67043 + gr_set_kernel_label(current);
67044 +
67045 /*
67046 * If we were started as result of loading a module, close all of the
67047 * user space pages. We don't need them, and if we didn't close them
67048 @@ -897,17 +927,17 @@ NORET_TYPE void do_exit(long code)
67049 struct task_struct *tsk = current;
67050 int group_dead;
67051
67052 - profile_task_exit(tsk);
67053 -
67054 - WARN_ON(atomic_read(&tsk->fs_excl));
67055 -
67056 + /*
67057 + * Check this first since set_fs() below depends on
67058 + * current_thread_info(), which we better not access when we're in
67059 + * interrupt context. Other than that, we want to do the set_fs()
67060 + * as early as possible.
67061 + */
67062 if (unlikely(in_interrupt()))
67063 panic("Aiee, killing interrupt handler!");
67064 - if (unlikely(!tsk->pid))
67065 - panic("Attempted to kill the idle task!");
67066
67067 /*
67068 - * If do_exit is called because this processes oopsed, it's possible
67069 + * If do_exit is called because this processes Oops'ed, it's possible
67070 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
67071 * continuing. Amongst other possible reasons, this is to prevent
67072 * mm_release()->clear_child_tid() from writing to a user-controlled
67073 @@ -915,6 +945,13 @@ NORET_TYPE void do_exit(long code)
67074 */
67075 set_fs(USER_DS);
67076
67077 + profile_task_exit(tsk);
67078 +
67079 + WARN_ON(atomic_read(&tsk->fs_excl));
67080 +
67081 + if (unlikely(!tsk->pid))
67082 + panic("Attempted to kill the idle task!");
67083 +
67084 tracehook_report_exit(&code);
67085
67086 validate_creds_for_do_exit(tsk);
67087 @@ -973,6 +1010,9 @@ NORET_TYPE void do_exit(long code)
67088 tsk->exit_code = code;
67089 taskstats_exit(tsk, group_dead);
67090
67091 + gr_acl_handle_psacct(tsk, code);
67092 + gr_acl_handle_exit();
67093 +
67094 exit_mm(tsk);
67095
67096 if (group_dead)
67097 @@ -1188,7 +1228,7 @@ static int wait_task_zombie(struct wait_
67098
67099 if (unlikely(wo->wo_flags & WNOWAIT)) {
67100 int exit_code = p->exit_code;
67101 - int why, status;
67102 + int why;
67103
67104 get_task_struct(p);
67105 read_unlock(&tasklist_lock);
67106 diff -urNp linux-2.6.32.46/kernel/fork.c linux-2.6.32.46/kernel/fork.c
67107 --- linux-2.6.32.46/kernel/fork.c 2011-03-27 14:31:47.000000000 -0400
67108 +++ linux-2.6.32.46/kernel/fork.c 2011-08-11 19:50:07.000000000 -0400
67109 @@ -253,7 +253,7 @@ static struct task_struct *dup_task_stru
67110 *stackend = STACK_END_MAGIC; /* for overflow detection */
67111
67112 #ifdef CONFIG_CC_STACKPROTECTOR
67113 - tsk->stack_canary = get_random_int();
67114 + tsk->stack_canary = pax_get_random_long();
67115 #endif
67116
67117 /* One for us, one for whoever does the "release_task()" (usually parent) */
67118 @@ -293,8 +293,8 @@ static int dup_mmap(struct mm_struct *mm
67119 mm->locked_vm = 0;
67120 mm->mmap = NULL;
67121 mm->mmap_cache = NULL;
67122 - mm->free_area_cache = oldmm->mmap_base;
67123 - mm->cached_hole_size = ~0UL;
67124 + mm->free_area_cache = oldmm->free_area_cache;
67125 + mm->cached_hole_size = oldmm->cached_hole_size;
67126 mm->map_count = 0;
67127 cpumask_clear(mm_cpumask(mm));
67128 mm->mm_rb = RB_ROOT;
67129 @@ -335,6 +335,7 @@ static int dup_mmap(struct mm_struct *mm
67130 tmp->vm_flags &= ~VM_LOCKED;
67131 tmp->vm_mm = mm;
67132 tmp->vm_next = tmp->vm_prev = NULL;
67133 + tmp->vm_mirror = NULL;
67134 anon_vma_link(tmp);
67135 file = tmp->vm_file;
67136 if (file) {
67137 @@ -384,6 +385,31 @@ static int dup_mmap(struct mm_struct *mm
67138 if (retval)
67139 goto out;
67140 }
67141 +
67142 +#ifdef CONFIG_PAX_SEGMEXEC
67143 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67144 + struct vm_area_struct *mpnt_m;
67145 +
67146 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67147 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67148 +
67149 + if (!mpnt->vm_mirror)
67150 + continue;
67151 +
67152 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67153 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67154 + mpnt->vm_mirror = mpnt_m;
67155 + } else {
67156 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67157 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67158 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67159 + mpnt->vm_mirror->vm_mirror = mpnt;
67160 + }
67161 + }
67162 + BUG_ON(mpnt_m);
67163 + }
67164 +#endif
67165 +
67166 /* a new mm has just been created */
67167 arch_dup_mmap(oldmm, mm);
67168 retval = 0;
67169 @@ -734,13 +760,14 @@ static int copy_fs(unsigned long clone_f
67170 write_unlock(&fs->lock);
67171 return -EAGAIN;
67172 }
67173 - fs->users++;
67174 + atomic_inc(&fs->users);
67175 write_unlock(&fs->lock);
67176 return 0;
67177 }
67178 tsk->fs = copy_fs_struct(fs);
67179 if (!tsk->fs)
67180 return -ENOMEM;
67181 + gr_set_chroot_entries(tsk, &tsk->fs->root);
67182 return 0;
67183 }
67184
67185 @@ -1033,12 +1060,16 @@ static struct task_struct *copy_process(
67186 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67187 #endif
67188 retval = -EAGAIN;
67189 +
67190 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67191 +
67192 if (atomic_read(&p->real_cred->user->processes) >=
67193 p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
67194 - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67195 - p->real_cred->user != INIT_USER)
67196 + if (p->real_cred->user != INIT_USER &&
67197 + !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
67198 goto bad_fork_free;
67199 }
67200 + current->flags &= ~PF_NPROC_EXCEEDED;
67201
67202 retval = copy_creds(p, clone_flags);
67203 if (retval < 0)
67204 @@ -1183,6 +1214,8 @@ static struct task_struct *copy_process(
67205 goto bad_fork_free_pid;
67206 }
67207
67208 + gr_copy_label(p);
67209 +
67210 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
67211 /*
67212 * Clear TID on mm_release()?
67213 @@ -1333,6 +1366,8 @@ bad_fork_cleanup_count:
67214 bad_fork_free:
67215 free_task(p);
67216 fork_out:
67217 + gr_log_forkfail(retval);
67218 +
67219 return ERR_PTR(retval);
67220 }
67221
67222 @@ -1426,6 +1461,8 @@ long do_fork(unsigned long clone_flags,
67223 if (clone_flags & CLONE_PARENT_SETTID)
67224 put_user(nr, parent_tidptr);
67225
67226 + gr_handle_brute_check();
67227 +
67228 if (clone_flags & CLONE_VFORK) {
67229 p->vfork_done = &vfork;
67230 init_completion(&vfork);
67231 @@ -1558,7 +1595,7 @@ static int unshare_fs(unsigned long unsh
67232 return 0;
67233
67234 /* don't need lock here; in the worst case we'll do useless copy */
67235 - if (fs->users == 1)
67236 + if (atomic_read(&fs->users) == 1)
67237 return 0;
67238
67239 *new_fsp = copy_fs_struct(fs);
67240 @@ -1681,7 +1718,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
67241 fs = current->fs;
67242 write_lock(&fs->lock);
67243 current->fs = new_fs;
67244 - if (--fs->users)
67245 + gr_set_chroot_entries(current, &current->fs->root);
67246 + if (atomic_dec_return(&fs->users))
67247 new_fs = NULL;
67248 else
67249 new_fs = fs;
67250 diff -urNp linux-2.6.32.46/kernel/futex.c linux-2.6.32.46/kernel/futex.c
67251 --- linux-2.6.32.46/kernel/futex.c 2011-08-29 22:24:44.000000000 -0400
67252 +++ linux-2.6.32.46/kernel/futex.c 2011-08-29 22:25:07.000000000 -0400
67253 @@ -54,6 +54,7 @@
67254 #include <linux/mount.h>
67255 #include <linux/pagemap.h>
67256 #include <linux/syscalls.h>
67257 +#include <linux/ptrace.h>
67258 #include <linux/signal.h>
67259 #include <linux/module.h>
67260 #include <linux/magic.h>
67261 @@ -223,6 +224,11 @@ get_futex_key(u32 __user *uaddr, int fsh
67262 struct page *page;
67263 int err, ro = 0;
67264
67265 +#ifdef CONFIG_PAX_SEGMEXEC
67266 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67267 + return -EFAULT;
67268 +#endif
67269 +
67270 /*
67271 * The futex address must be "naturally" aligned.
67272 */
67273 @@ -1819,6 +1825,8 @@ static int futex_wait(u32 __user *uaddr,
67274 struct futex_q q;
67275 int ret;
67276
67277 + pax_track_stack();
67278 +
67279 if (!bitset)
67280 return -EINVAL;
67281
67282 @@ -1871,7 +1879,7 @@ retry:
67283
67284 restart = &current_thread_info()->restart_block;
67285 restart->fn = futex_wait_restart;
67286 - restart->futex.uaddr = (u32 *)uaddr;
67287 + restart->futex.uaddr = uaddr;
67288 restart->futex.val = val;
67289 restart->futex.time = abs_time->tv64;
67290 restart->futex.bitset = bitset;
67291 @@ -2233,6 +2241,8 @@ static int futex_wait_requeue_pi(u32 __u
67292 struct futex_q q;
67293 int res, ret;
67294
67295 + pax_track_stack();
67296 +
67297 if (!bitset)
67298 return -EINVAL;
67299
67300 @@ -2407,7 +2417,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67301 {
67302 struct robust_list_head __user *head;
67303 unsigned long ret;
67304 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67305 const struct cred *cred = current_cred(), *pcred;
67306 +#endif
67307
67308 if (!futex_cmpxchg_enabled)
67309 return -ENOSYS;
67310 @@ -2423,11 +2435,16 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67311 if (!p)
67312 goto err_unlock;
67313 ret = -EPERM;
67314 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67315 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
67316 + goto err_unlock;
67317 +#else
67318 pcred = __task_cred(p);
67319 if (cred->euid != pcred->euid &&
67320 cred->euid != pcred->uid &&
67321 !capable(CAP_SYS_PTRACE))
67322 goto err_unlock;
67323 +#endif
67324 head = p->robust_list;
67325 rcu_read_unlock();
67326 }
67327 @@ -2489,7 +2506,7 @@ retry:
67328 */
67329 static inline int fetch_robust_entry(struct robust_list __user **entry,
67330 struct robust_list __user * __user *head,
67331 - int *pi)
67332 + unsigned int *pi)
67333 {
67334 unsigned long uentry;
67335
67336 @@ -2670,6 +2687,7 @@ static int __init futex_init(void)
67337 {
67338 u32 curval;
67339 int i;
67340 + mm_segment_t oldfs;
67341
67342 /*
67343 * This will fail and we want it. Some arch implementations do
67344 @@ -2681,7 +2699,10 @@ static int __init futex_init(void)
67345 * implementation, the non functional ones will return
67346 * -ENOSYS.
67347 */
67348 + oldfs = get_fs();
67349 + set_fs(USER_DS);
67350 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
67351 + set_fs(oldfs);
67352 if (curval == -EFAULT)
67353 futex_cmpxchg_enabled = 1;
67354
67355 diff -urNp linux-2.6.32.46/kernel/futex_compat.c linux-2.6.32.46/kernel/futex_compat.c
67356 --- linux-2.6.32.46/kernel/futex_compat.c 2011-03-27 14:31:47.000000000 -0400
67357 +++ linux-2.6.32.46/kernel/futex_compat.c 2011-04-17 15:56:46.000000000 -0400
67358 @@ -10,6 +10,7 @@
67359 #include <linux/compat.h>
67360 #include <linux/nsproxy.h>
67361 #include <linux/futex.h>
67362 +#include <linux/ptrace.h>
67363
67364 #include <asm/uaccess.h>
67365
67366 @@ -135,7 +136,10 @@ compat_sys_get_robust_list(int pid, comp
67367 {
67368 struct compat_robust_list_head __user *head;
67369 unsigned long ret;
67370 - const struct cred *cred = current_cred(), *pcred;
67371 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67372 + const struct cred *cred = current_cred();
67373 + const struct cred *pcred;
67374 +#endif
67375
67376 if (!futex_cmpxchg_enabled)
67377 return -ENOSYS;
67378 @@ -151,11 +155,16 @@ compat_sys_get_robust_list(int pid, comp
67379 if (!p)
67380 goto err_unlock;
67381 ret = -EPERM;
67382 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67383 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
67384 + goto err_unlock;
67385 +#else
67386 pcred = __task_cred(p);
67387 if (cred->euid != pcred->euid &&
67388 cred->euid != pcred->uid &&
67389 !capable(CAP_SYS_PTRACE))
67390 goto err_unlock;
67391 +#endif
67392 head = p->compat_robust_list;
67393 read_unlock(&tasklist_lock);
67394 }
67395 diff -urNp linux-2.6.32.46/kernel/gcov/base.c linux-2.6.32.46/kernel/gcov/base.c
67396 --- linux-2.6.32.46/kernel/gcov/base.c 2011-03-27 14:31:47.000000000 -0400
67397 +++ linux-2.6.32.46/kernel/gcov/base.c 2011-04-17 15:56:46.000000000 -0400
67398 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67399 }
67400
67401 #ifdef CONFIG_MODULES
67402 -static inline int within(void *addr, void *start, unsigned long size)
67403 -{
67404 - return ((addr >= start) && (addr < start + size));
67405 -}
67406 -
67407 /* Update list and generate events when modules are unloaded. */
67408 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67409 void *data)
67410 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
67411 prev = NULL;
67412 /* Remove entries located in module from linked list. */
67413 for (info = gcov_info_head; info; info = info->next) {
67414 - if (within(info, mod->module_core, mod->core_size)) {
67415 + if (within_module_core_rw((unsigned long)info, mod)) {
67416 if (prev)
67417 prev->next = info->next;
67418 else
67419 diff -urNp linux-2.6.32.46/kernel/hrtimer.c linux-2.6.32.46/kernel/hrtimer.c
67420 --- linux-2.6.32.46/kernel/hrtimer.c 2011-03-27 14:31:47.000000000 -0400
67421 +++ linux-2.6.32.46/kernel/hrtimer.c 2011-04-17 15:56:46.000000000 -0400
67422 @@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
67423 local_irq_restore(flags);
67424 }
67425
67426 -static void run_hrtimer_softirq(struct softirq_action *h)
67427 +static void run_hrtimer_softirq(void)
67428 {
67429 hrtimer_peek_ahead_timers();
67430 }
67431 diff -urNp linux-2.6.32.46/kernel/kallsyms.c linux-2.6.32.46/kernel/kallsyms.c
67432 --- linux-2.6.32.46/kernel/kallsyms.c 2011-03-27 14:31:47.000000000 -0400
67433 +++ linux-2.6.32.46/kernel/kallsyms.c 2011-04-17 15:56:46.000000000 -0400
67434 @@ -11,6 +11,9 @@
67435 * Changed the compression method from stem compression to "table lookup"
67436 * compression (see scripts/kallsyms.c for a more complete description)
67437 */
67438 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67439 +#define __INCLUDED_BY_HIDESYM 1
67440 +#endif
67441 #include <linux/kallsyms.h>
67442 #include <linux/module.h>
67443 #include <linux/init.h>
67444 @@ -51,12 +54,33 @@ extern const unsigned long kallsyms_mark
67445
67446 static inline int is_kernel_inittext(unsigned long addr)
67447 {
67448 + if (system_state != SYSTEM_BOOTING)
67449 + return 0;
67450 +
67451 if (addr >= (unsigned long)_sinittext
67452 && addr <= (unsigned long)_einittext)
67453 return 1;
67454 return 0;
67455 }
67456
67457 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67458 +#ifdef CONFIG_MODULES
67459 +static inline int is_module_text(unsigned long addr)
67460 +{
67461 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67462 + return 1;
67463 +
67464 + addr = ktla_ktva(addr);
67465 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67466 +}
67467 +#else
67468 +static inline int is_module_text(unsigned long addr)
67469 +{
67470 + return 0;
67471 +}
67472 +#endif
67473 +#endif
67474 +
67475 static inline int is_kernel_text(unsigned long addr)
67476 {
67477 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67478 @@ -67,13 +91,28 @@ static inline int is_kernel_text(unsigne
67479
67480 static inline int is_kernel(unsigned long addr)
67481 {
67482 +
67483 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67484 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67485 + return 1;
67486 +
67487 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67488 +#else
67489 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67490 +#endif
67491 +
67492 return 1;
67493 return in_gate_area_no_task(addr);
67494 }
67495
67496 static int is_ksym_addr(unsigned long addr)
67497 {
67498 +
67499 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67500 + if (is_module_text(addr))
67501 + return 0;
67502 +#endif
67503 +
67504 if (all_var)
67505 return is_kernel(addr);
67506
67507 @@ -413,7 +452,6 @@ static unsigned long get_ksymbol_core(st
67508
67509 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67510 {
67511 - iter->name[0] = '\0';
67512 iter->nameoff = get_symbol_offset(new_pos);
67513 iter->pos = new_pos;
67514 }
67515 @@ -461,6 +499,11 @@ static int s_show(struct seq_file *m, vo
67516 {
67517 struct kallsym_iter *iter = m->private;
67518
67519 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67520 + if (current_uid())
67521 + return 0;
67522 +#endif
67523 +
67524 /* Some debugging symbols have no name. Ignore them. */
67525 if (!iter->name[0])
67526 return 0;
67527 @@ -501,7 +544,7 @@ static int kallsyms_open(struct inode *i
67528 struct kallsym_iter *iter;
67529 int ret;
67530
67531 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67532 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67533 if (!iter)
67534 return -ENOMEM;
67535 reset_iter(iter, 0);
67536 diff -urNp linux-2.6.32.46/kernel/kexec.c linux-2.6.32.46/kernel/kexec.c
67537 --- linux-2.6.32.46/kernel/kexec.c 2011-03-27 14:31:47.000000000 -0400
67538 +++ linux-2.6.32.46/kernel/kexec.c 2011-10-06 09:37:14.000000000 -0400
67539 @@ -1028,7 +1028,8 @@ asmlinkage long compat_sys_kexec_load(un
67540 unsigned long flags)
67541 {
67542 struct compat_kexec_segment in;
67543 - struct kexec_segment out, __user *ksegments;
67544 + struct kexec_segment out;
67545 + struct kexec_segment __user *ksegments;
67546 unsigned long i, result;
67547
67548 /* Don't allow clients that don't understand the native
67549 diff -urNp linux-2.6.32.46/kernel/kgdb.c linux-2.6.32.46/kernel/kgdb.c
67550 --- linux-2.6.32.46/kernel/kgdb.c 2011-04-17 17:00:52.000000000 -0400
67551 +++ linux-2.6.32.46/kernel/kgdb.c 2011-05-04 17:56:20.000000000 -0400
67552 @@ -86,7 +86,7 @@ static int kgdb_io_module_registered;
67553 /* Guard for recursive entry */
67554 static int exception_level;
67555
67556 -static struct kgdb_io *kgdb_io_ops;
67557 +static const struct kgdb_io *kgdb_io_ops;
67558 static DEFINE_SPINLOCK(kgdb_registration_lock);
67559
67560 /* kgdb console driver is loaded */
67561 @@ -123,7 +123,7 @@ atomic_t kgdb_active = ATOMIC_INIT(-1)
67562 */
67563 static atomic_t passive_cpu_wait[NR_CPUS];
67564 static atomic_t cpu_in_kgdb[NR_CPUS];
67565 -atomic_t kgdb_setting_breakpoint;
67566 +atomic_unchecked_t kgdb_setting_breakpoint;
67567
67568 struct task_struct *kgdb_usethread;
67569 struct task_struct *kgdb_contthread;
67570 @@ -140,7 +140,7 @@ static unsigned long gdb_regs[(NUMREGBY
67571 sizeof(unsigned long)];
67572
67573 /* to keep track of the CPU which is doing the single stepping*/
67574 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67575 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67576
67577 /*
67578 * If you are debugging a problem where roundup (the collection of
67579 @@ -815,7 +815,7 @@ static int kgdb_io_ready(int print_wait)
67580 return 0;
67581 if (kgdb_connected)
67582 return 1;
67583 - if (atomic_read(&kgdb_setting_breakpoint))
67584 + if (atomic_read_unchecked(&kgdb_setting_breakpoint))
67585 return 1;
67586 if (print_wait)
67587 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
67588 @@ -1426,8 +1426,8 @@ acquirelock:
67589 * instance of the exception handler wanted to come into the
67590 * debugger on a different CPU via a single step
67591 */
67592 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67593 - atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
67594 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67595 + atomic_read_unchecked(&kgdb_cpu_doing_single_step) != cpu) {
67596
67597 atomic_set(&kgdb_active, -1);
67598 touch_softlockup_watchdog();
67599 @@ -1634,7 +1634,7 @@ static void kgdb_initial_breakpoint(void
67600 *
67601 * Register it with the KGDB core.
67602 */
67603 -int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
67604 +int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
67605 {
67606 int err;
67607
67608 @@ -1679,7 +1679,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
67609 *
67610 * Unregister it with the KGDB core.
67611 */
67612 -void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
67613 +void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
67614 {
67615 BUG_ON(kgdb_connected);
67616
67617 @@ -1712,11 +1712,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod
67618 */
67619 void kgdb_breakpoint(void)
67620 {
67621 - atomic_set(&kgdb_setting_breakpoint, 1);
67622 + atomic_set_unchecked(&kgdb_setting_breakpoint, 1);
67623 wmb(); /* Sync point before breakpoint */
67624 arch_kgdb_breakpoint();
67625 wmb(); /* Sync point after breakpoint */
67626 - atomic_set(&kgdb_setting_breakpoint, 0);
67627 + atomic_set_unchecked(&kgdb_setting_breakpoint, 0);
67628 }
67629 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
67630
67631 diff -urNp linux-2.6.32.46/kernel/kmod.c linux-2.6.32.46/kernel/kmod.c
67632 --- linux-2.6.32.46/kernel/kmod.c 2011-03-27 14:31:47.000000000 -0400
67633 +++ linux-2.6.32.46/kernel/kmod.c 2011-10-06 09:37:14.000000000 -0400
67634 @@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
67635 * If module auto-loading support is disabled then this function
67636 * becomes a no-operation.
67637 */
67638 -int __request_module(bool wait, const char *fmt, ...)
67639 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67640 {
67641 - va_list args;
67642 char module_name[MODULE_NAME_LEN];
67643 unsigned int max_modprobes;
67644 int ret;
67645 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
67646 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
67647 static char *envp[] = { "HOME=/",
67648 "TERM=linux",
67649 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
67650 @@ -84,12 +83,24 @@ int __request_module(bool wait, const ch
67651 if (ret)
67652 return ret;
67653
67654 - va_start(args, fmt);
67655 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67656 - va_end(args);
67657 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67658 if (ret >= MODULE_NAME_LEN)
67659 return -ENAMETOOLONG;
67660
67661 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67662 + if (!current_uid()) {
67663 + /* hack to workaround consolekit/udisks stupidity */
67664 + read_lock(&tasklist_lock);
67665 + if (!strcmp(current->comm, "mount") &&
67666 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67667 + read_unlock(&tasklist_lock);
67668 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67669 + return -EPERM;
67670 + }
67671 + read_unlock(&tasklist_lock);
67672 + }
67673 +#endif
67674 +
67675 /* If modprobe needs a service that is in a module, we get a recursive
67676 * loop. Limit the number of running kmod threads to max_threads/2 or
67677 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67678 @@ -121,6 +132,48 @@ int __request_module(bool wait, const ch
67679 atomic_dec(&kmod_concurrent);
67680 return ret;
67681 }
67682 +
67683 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67684 +{
67685 + va_list args;
67686 + int ret;
67687 +
67688 + va_start(args, fmt);
67689 + ret = ____request_module(wait, module_param, fmt, args);
67690 + va_end(args);
67691 +
67692 + return ret;
67693 +}
67694 +
67695 +int __request_module(bool wait, const char *fmt, ...)
67696 +{
67697 + va_list args;
67698 + int ret;
67699 +
67700 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67701 + if (current_uid()) {
67702 + char module_param[MODULE_NAME_LEN];
67703 +
67704 + memset(module_param, 0, sizeof(module_param));
67705 +
67706 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67707 +
67708 + va_start(args, fmt);
67709 + ret = ____request_module(wait, module_param, fmt, args);
67710 + va_end(args);
67711 +
67712 + return ret;
67713 + }
67714 +#endif
67715 +
67716 + va_start(args, fmt);
67717 + ret = ____request_module(wait, NULL, fmt, args);
67718 + va_end(args);
67719 +
67720 + return ret;
67721 +}
67722 +
67723 +
67724 EXPORT_SYMBOL(__request_module);
67725 #endif /* CONFIG_MODULES */
67726
67727 @@ -226,7 +279,7 @@ static int wait_for_helper(void *data)
67728 *
67729 * Thus the __user pointer cast is valid here.
67730 */
67731 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67732 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67733
67734 /*
67735 * If ret is 0, either ____call_usermodehelper failed and the
67736 diff -urNp linux-2.6.32.46/kernel/kprobes.c linux-2.6.32.46/kernel/kprobes.c
67737 --- linux-2.6.32.46/kernel/kprobes.c 2011-03-27 14:31:47.000000000 -0400
67738 +++ linux-2.6.32.46/kernel/kprobes.c 2011-04-17 15:56:46.000000000 -0400
67739 @@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_
67740 * kernel image and loaded module images reside. This is required
67741 * so x86_64 can correctly handle the %rip-relative fixups.
67742 */
67743 - kip->insns = module_alloc(PAGE_SIZE);
67744 + kip->insns = module_alloc_exec(PAGE_SIZE);
67745 if (!kip->insns) {
67746 kfree(kip);
67747 return NULL;
67748 @@ -220,7 +220,7 @@ static int __kprobes collect_one_slot(st
67749 */
67750 if (!list_is_singular(&kprobe_insn_pages)) {
67751 list_del(&kip->list);
67752 - module_free(NULL, kip->insns);
67753 + module_free_exec(NULL, kip->insns);
67754 kfree(kip);
67755 }
67756 return 1;
67757 @@ -1189,7 +1189,7 @@ static int __init init_kprobes(void)
67758 {
67759 int i, err = 0;
67760 unsigned long offset = 0, size = 0;
67761 - char *modname, namebuf[128];
67762 + char *modname, namebuf[KSYM_NAME_LEN];
67763 const char *symbol_name;
67764 void *addr;
67765 struct kprobe_blackpoint *kb;
67766 @@ -1304,7 +1304,7 @@ static int __kprobes show_kprobe_addr(st
67767 const char *sym = NULL;
67768 unsigned int i = *(loff_t *) v;
67769 unsigned long offset = 0;
67770 - char *modname, namebuf[128];
67771 + char *modname, namebuf[KSYM_NAME_LEN];
67772
67773 head = &kprobe_table[i];
67774 preempt_disable();
67775 diff -urNp linux-2.6.32.46/kernel/lockdep.c linux-2.6.32.46/kernel/lockdep.c
67776 --- linux-2.6.32.46/kernel/lockdep.c 2011-06-25 12:55:35.000000000 -0400
67777 +++ linux-2.6.32.46/kernel/lockdep.c 2011-06-25 12:56:37.000000000 -0400
67778 @@ -421,20 +421,20 @@ static struct stack_trace lockdep_init_t
67779 /*
67780 * Various lockdep statistics:
67781 */
67782 -atomic_t chain_lookup_hits;
67783 -atomic_t chain_lookup_misses;
67784 -atomic_t hardirqs_on_events;
67785 -atomic_t hardirqs_off_events;
67786 -atomic_t redundant_hardirqs_on;
67787 -atomic_t redundant_hardirqs_off;
67788 -atomic_t softirqs_on_events;
67789 -atomic_t softirqs_off_events;
67790 -atomic_t redundant_softirqs_on;
67791 -atomic_t redundant_softirqs_off;
67792 -atomic_t nr_unused_locks;
67793 -atomic_t nr_cyclic_checks;
67794 -atomic_t nr_find_usage_forwards_checks;
67795 -atomic_t nr_find_usage_backwards_checks;
67796 +atomic_unchecked_t chain_lookup_hits;
67797 +atomic_unchecked_t chain_lookup_misses;
67798 +atomic_unchecked_t hardirqs_on_events;
67799 +atomic_unchecked_t hardirqs_off_events;
67800 +atomic_unchecked_t redundant_hardirqs_on;
67801 +atomic_unchecked_t redundant_hardirqs_off;
67802 +atomic_unchecked_t softirqs_on_events;
67803 +atomic_unchecked_t softirqs_off_events;
67804 +atomic_unchecked_t redundant_softirqs_on;
67805 +atomic_unchecked_t redundant_softirqs_off;
67806 +atomic_unchecked_t nr_unused_locks;
67807 +atomic_unchecked_t nr_cyclic_checks;
67808 +atomic_unchecked_t nr_find_usage_forwards_checks;
67809 +atomic_unchecked_t nr_find_usage_backwards_checks;
67810 #endif
67811
67812 /*
67813 @@ -577,6 +577,10 @@ static int static_obj(void *obj)
67814 int i;
67815 #endif
67816
67817 +#ifdef CONFIG_PAX_KERNEXEC
67818 + start = ktla_ktva(start);
67819 +#endif
67820 +
67821 /*
67822 * static variable?
67823 */
67824 @@ -592,8 +596,7 @@ static int static_obj(void *obj)
67825 */
67826 for_each_possible_cpu(i) {
67827 start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
67828 - end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
67829 - + per_cpu_offset(i);
67830 + end = start + PERCPU_ENOUGH_ROOM;
67831
67832 if ((addr >= start) && (addr < end))
67833 return 1;
67834 @@ -710,6 +713,7 @@ register_lock_class(struct lockdep_map *
67835 if (!static_obj(lock->key)) {
67836 debug_locks_off();
67837 printk("INFO: trying to register non-static key.\n");
67838 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67839 printk("the code is fine but needs lockdep annotation.\n");
67840 printk("turning off the locking correctness validator.\n");
67841 dump_stack();
67842 @@ -2751,7 +2755,7 @@ static int __lock_acquire(struct lockdep
67843 if (!class)
67844 return 0;
67845 }
67846 - debug_atomic_inc((atomic_t *)&class->ops);
67847 + debug_atomic_inc((atomic_unchecked_t *)&class->ops);
67848 if (very_verbose(class)) {
67849 printk("\nacquire class [%p] %s", class->key, class->name);
67850 if (class->name_version > 1)
67851 diff -urNp linux-2.6.32.46/kernel/lockdep_internals.h linux-2.6.32.46/kernel/lockdep_internals.h
67852 --- linux-2.6.32.46/kernel/lockdep_internals.h 2011-03-27 14:31:47.000000000 -0400
67853 +++ linux-2.6.32.46/kernel/lockdep_internals.h 2011-04-17 15:56:46.000000000 -0400
67854 @@ -113,26 +113,26 @@ lockdep_count_backward_deps(struct lock_
67855 /*
67856 * Various lockdep statistics:
67857 */
67858 -extern atomic_t chain_lookup_hits;
67859 -extern atomic_t chain_lookup_misses;
67860 -extern atomic_t hardirqs_on_events;
67861 -extern atomic_t hardirqs_off_events;
67862 -extern atomic_t redundant_hardirqs_on;
67863 -extern atomic_t redundant_hardirqs_off;
67864 -extern atomic_t softirqs_on_events;
67865 -extern atomic_t softirqs_off_events;
67866 -extern atomic_t redundant_softirqs_on;
67867 -extern atomic_t redundant_softirqs_off;
67868 -extern atomic_t nr_unused_locks;
67869 -extern atomic_t nr_cyclic_checks;
67870 -extern atomic_t nr_cyclic_check_recursions;
67871 -extern atomic_t nr_find_usage_forwards_checks;
67872 -extern atomic_t nr_find_usage_forwards_recursions;
67873 -extern atomic_t nr_find_usage_backwards_checks;
67874 -extern atomic_t nr_find_usage_backwards_recursions;
67875 -# define debug_atomic_inc(ptr) atomic_inc(ptr)
67876 -# define debug_atomic_dec(ptr) atomic_dec(ptr)
67877 -# define debug_atomic_read(ptr) atomic_read(ptr)
67878 +extern atomic_unchecked_t chain_lookup_hits;
67879 +extern atomic_unchecked_t chain_lookup_misses;
67880 +extern atomic_unchecked_t hardirqs_on_events;
67881 +extern atomic_unchecked_t hardirqs_off_events;
67882 +extern atomic_unchecked_t redundant_hardirqs_on;
67883 +extern atomic_unchecked_t redundant_hardirqs_off;
67884 +extern atomic_unchecked_t softirqs_on_events;
67885 +extern atomic_unchecked_t softirqs_off_events;
67886 +extern atomic_unchecked_t redundant_softirqs_on;
67887 +extern atomic_unchecked_t redundant_softirqs_off;
67888 +extern atomic_unchecked_t nr_unused_locks;
67889 +extern atomic_unchecked_t nr_cyclic_checks;
67890 +extern atomic_unchecked_t nr_cyclic_check_recursions;
67891 +extern atomic_unchecked_t nr_find_usage_forwards_checks;
67892 +extern atomic_unchecked_t nr_find_usage_forwards_recursions;
67893 +extern atomic_unchecked_t nr_find_usage_backwards_checks;
67894 +extern atomic_unchecked_t nr_find_usage_backwards_recursions;
67895 +# define debug_atomic_inc(ptr) atomic_inc_unchecked(ptr)
67896 +# define debug_atomic_dec(ptr) atomic_dec_unchecked(ptr)
67897 +# define debug_atomic_read(ptr) atomic_read_unchecked(ptr)
67898 #else
67899 # define debug_atomic_inc(ptr) do { } while (0)
67900 # define debug_atomic_dec(ptr) do { } while (0)
67901 diff -urNp linux-2.6.32.46/kernel/lockdep_proc.c linux-2.6.32.46/kernel/lockdep_proc.c
67902 --- linux-2.6.32.46/kernel/lockdep_proc.c 2011-03-27 14:31:47.000000000 -0400
67903 +++ linux-2.6.32.46/kernel/lockdep_proc.c 2011-04-17 15:56:46.000000000 -0400
67904 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
67905
67906 static void print_name(struct seq_file *m, struct lock_class *class)
67907 {
67908 - char str[128];
67909 + char str[KSYM_NAME_LEN];
67910 const char *name = class->name;
67911
67912 if (!name) {
67913 diff -urNp linux-2.6.32.46/kernel/module.c linux-2.6.32.46/kernel/module.c
67914 --- linux-2.6.32.46/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
67915 +++ linux-2.6.32.46/kernel/module.c 2011-04-29 18:52:40.000000000 -0400
67916 @@ -55,6 +55,7 @@
67917 #include <linux/async.h>
67918 #include <linux/percpu.h>
67919 #include <linux/kmemleak.h>
67920 +#include <linux/grsecurity.h>
67921
67922 #define CREATE_TRACE_POINTS
67923 #include <trace/events/module.h>
67924 @@ -89,7 +90,8 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq
67925 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67926
67927 /* Bounds of module allocation, for speeding __module_address */
67928 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67929 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67930 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67931
67932 int register_module_notifier(struct notifier_block * nb)
67933 {
67934 @@ -245,7 +247,7 @@ bool each_symbol(bool (*fn)(const struct
67935 return true;
67936
67937 list_for_each_entry_rcu(mod, &modules, list) {
67938 - struct symsearch arr[] = {
67939 + struct symsearch modarr[] = {
67940 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67941 NOT_GPL_ONLY, false },
67942 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67943 @@ -267,7 +269,7 @@ bool each_symbol(bool (*fn)(const struct
67944 #endif
67945 };
67946
67947 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67948 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67949 return true;
67950 }
67951 return false;
67952 @@ -442,7 +444,7 @@ static void *percpu_modalloc(unsigned lo
67953 void *ptr;
67954 int cpu;
67955
67956 - if (align > PAGE_SIZE) {
67957 + if (align-1 >= PAGE_SIZE) {
67958 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67959 name, align, PAGE_SIZE);
67960 align = PAGE_SIZE;
67961 @@ -1158,7 +1160,7 @@ static const struct kernel_symbol *resol
67962 * /sys/module/foo/sections stuff
67963 * J. Corbet <corbet@lwn.net>
67964 */
67965 -#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
67966 +#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67967
67968 static inline bool sect_empty(const Elf_Shdr *sect)
67969 {
67970 @@ -1545,7 +1547,8 @@ static void free_module(struct module *m
67971 destroy_params(mod->kp, mod->num_kp);
67972
67973 /* This may be NULL, but that's OK */
67974 - module_free(mod, mod->module_init);
67975 + module_free(mod, mod->module_init_rw);
67976 + module_free_exec(mod, mod->module_init_rx);
67977 kfree(mod->args);
67978 if (mod->percpu)
67979 percpu_modfree(mod->percpu);
67980 @@ -1554,10 +1557,12 @@ static void free_module(struct module *m
67981 percpu_modfree(mod->refptr);
67982 #endif
67983 /* Free lock-classes: */
67984 - lockdep_free_key_range(mod->module_core, mod->core_size);
67985 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67986 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67987
67988 /* Finally, free the core (containing the module structure) */
67989 - module_free(mod, mod->module_core);
67990 + module_free_exec(mod, mod->module_core_rx);
67991 + module_free(mod, mod->module_core_rw);
67992
67993 #ifdef CONFIG_MPU
67994 update_protections(current->mm);
67995 @@ -1628,8 +1633,32 @@ static int simplify_symbols(Elf_Shdr *se
67996 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
67997 int ret = 0;
67998 const struct kernel_symbol *ksym;
67999 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68000 + int is_fs_load = 0;
68001 + int register_filesystem_found = 0;
68002 + char *p;
68003 +
68004 + p = strstr(mod->args, "grsec_modharden_fs");
68005 +
68006 + if (p) {
68007 + char *endptr = p + strlen("grsec_modharden_fs");
68008 + /* copy \0 as well */
68009 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68010 + is_fs_load = 1;
68011 + }
68012 +#endif
68013 +
68014
68015 for (i = 1; i < n; i++) {
68016 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68017 + const char *name = strtab + sym[i].st_name;
68018 +
68019 + /* it's a real shame this will never get ripped and copied
68020 + upstream! ;(
68021 + */
68022 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68023 + register_filesystem_found = 1;
68024 +#endif
68025 switch (sym[i].st_shndx) {
68026 case SHN_COMMON:
68027 /* We compiled with -fno-common. These are not
68028 @@ -1651,7 +1680,9 @@ static int simplify_symbols(Elf_Shdr *se
68029 strtab + sym[i].st_name, mod);
68030 /* Ok if resolved. */
68031 if (ksym) {
68032 + pax_open_kernel();
68033 sym[i].st_value = ksym->value;
68034 + pax_close_kernel();
68035 break;
68036 }
68037
68038 @@ -1670,11 +1701,20 @@ static int simplify_symbols(Elf_Shdr *se
68039 secbase = (unsigned long)mod->percpu;
68040 else
68041 secbase = sechdrs[sym[i].st_shndx].sh_addr;
68042 + pax_open_kernel();
68043 sym[i].st_value += secbase;
68044 + pax_close_kernel();
68045 break;
68046 }
68047 }
68048
68049 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68050 + if (is_fs_load && !register_filesystem_found) {
68051 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68052 + ret = -EPERM;
68053 + }
68054 +#endif
68055 +
68056 return ret;
68057 }
68058
68059 @@ -1731,11 +1771,12 @@ static void layout_sections(struct modul
68060 || s->sh_entsize != ~0UL
68061 || strstarts(secstrings + s->sh_name, ".init"))
68062 continue;
68063 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68064 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68065 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68066 + else
68067 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68068 DEBUGP("\t%s\n", secstrings + s->sh_name);
68069 }
68070 - if (m == 0)
68071 - mod->core_text_size = mod->core_size;
68072 }
68073
68074 DEBUGP("Init section allocation order:\n");
68075 @@ -1748,12 +1789,13 @@ static void layout_sections(struct modul
68076 || s->sh_entsize != ~0UL
68077 || !strstarts(secstrings + s->sh_name, ".init"))
68078 continue;
68079 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68080 - | INIT_OFFSET_MASK);
68081 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68082 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68083 + else
68084 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68085 + s->sh_entsize |= INIT_OFFSET_MASK;
68086 DEBUGP("\t%s\n", secstrings + s->sh_name);
68087 }
68088 - if (m == 0)
68089 - mod->init_text_size = mod->init_size;
68090 }
68091 }
68092
68093 @@ -1857,9 +1899,8 @@ static int is_exported(const char *name,
68094
68095 /* As per nm */
68096 static char elf_type(const Elf_Sym *sym,
68097 - Elf_Shdr *sechdrs,
68098 - const char *secstrings,
68099 - struct module *mod)
68100 + const Elf_Shdr *sechdrs,
68101 + const char *secstrings)
68102 {
68103 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
68104 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
68105 @@ -1934,7 +1975,7 @@ static unsigned long layout_symtab(struc
68106
68107 /* Put symbol section at end of init part of module. */
68108 symsect->sh_flags |= SHF_ALLOC;
68109 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68110 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68111 symindex) | INIT_OFFSET_MASK;
68112 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
68113
68114 @@ -1951,19 +1992,19 @@ static unsigned long layout_symtab(struc
68115 }
68116
68117 /* Append room for core symbols at end of core part. */
68118 - symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68119 - mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
68120 + symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68121 + mod->core_size_rx = symoffs + ndst * sizeof(Elf_Sym);
68122
68123 /* Put string table section at end of init part of module. */
68124 strsect->sh_flags |= SHF_ALLOC;
68125 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68126 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68127 strindex) | INIT_OFFSET_MASK;
68128 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
68129
68130 /* Append room for core symbols' strings at end of core part. */
68131 - *pstroffs = mod->core_size;
68132 + *pstroffs = mod->core_size_rx;
68133 __set_bit(0, strmap);
68134 - mod->core_size += bitmap_weight(strmap, strsect->sh_size);
68135 + mod->core_size_rx += bitmap_weight(strmap, strsect->sh_size);
68136
68137 return symoffs;
68138 }
68139 @@ -1987,12 +2028,14 @@ static void add_kallsyms(struct module *
68140 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
68141 mod->strtab = (void *)sechdrs[strindex].sh_addr;
68142
68143 + pax_open_kernel();
68144 +
68145 /* Set types up while we still have access to sections. */
68146 for (i = 0; i < mod->num_symtab; i++)
68147 mod->symtab[i].st_info
68148 - = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
68149 + = elf_type(&mod->symtab[i], sechdrs, secstrings);
68150
68151 - mod->core_symtab = dst = mod->module_core + symoffs;
68152 + mod->core_symtab = dst = mod->module_core_rx + symoffs;
68153 src = mod->symtab;
68154 *dst = *src;
68155 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68156 @@ -2004,10 +2047,12 @@ static void add_kallsyms(struct module *
68157 }
68158 mod->core_num_syms = ndst;
68159
68160 - mod->core_strtab = s = mod->module_core + stroffs;
68161 + mod->core_strtab = s = mod->module_core_rx + stroffs;
68162 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
68163 if (test_bit(i, strmap))
68164 *++s = mod->strtab[i];
68165 +
68166 + pax_close_kernel();
68167 }
68168 #else
68169 static inline unsigned long layout_symtab(struct module *mod,
68170 @@ -2044,16 +2089,30 @@ static void dynamic_debug_setup(struct _
68171 #endif
68172 }
68173
68174 -static void *module_alloc_update_bounds(unsigned long size)
68175 +static void *module_alloc_update_bounds_rw(unsigned long size)
68176 {
68177 void *ret = module_alloc(size);
68178
68179 if (ret) {
68180 /* Update module bounds. */
68181 - if ((unsigned long)ret < module_addr_min)
68182 - module_addr_min = (unsigned long)ret;
68183 - if ((unsigned long)ret + size > module_addr_max)
68184 - module_addr_max = (unsigned long)ret + size;
68185 + if ((unsigned long)ret < module_addr_min_rw)
68186 + module_addr_min_rw = (unsigned long)ret;
68187 + if ((unsigned long)ret + size > module_addr_max_rw)
68188 + module_addr_max_rw = (unsigned long)ret + size;
68189 + }
68190 + return ret;
68191 +}
68192 +
68193 +static void *module_alloc_update_bounds_rx(unsigned long size)
68194 +{
68195 + void *ret = module_alloc_exec(size);
68196 +
68197 + if (ret) {
68198 + /* Update module bounds. */
68199 + if ((unsigned long)ret < module_addr_min_rx)
68200 + module_addr_min_rx = (unsigned long)ret;
68201 + if ((unsigned long)ret + size > module_addr_max_rx)
68202 + module_addr_max_rx = (unsigned long)ret + size;
68203 }
68204 return ret;
68205 }
68206 @@ -2065,8 +2124,8 @@ static void kmemleak_load_module(struct
68207 unsigned int i;
68208
68209 /* only scan the sections containing data */
68210 - kmemleak_scan_area(mod->module_core, (unsigned long)mod -
68211 - (unsigned long)mod->module_core,
68212 + kmemleak_scan_area(mod->module_core_rw, (unsigned long)mod -
68213 + (unsigned long)mod->module_core_rw,
68214 sizeof(struct module), GFP_KERNEL);
68215
68216 for (i = 1; i < hdr->e_shnum; i++) {
68217 @@ -2076,8 +2135,8 @@ static void kmemleak_load_module(struct
68218 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
68219 continue;
68220
68221 - kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
68222 - (unsigned long)mod->module_core,
68223 + kmemleak_scan_area(mod->module_core_rw, sechdrs[i].sh_addr -
68224 + (unsigned long)mod->module_core_rw,
68225 sechdrs[i].sh_size, GFP_KERNEL);
68226 }
68227 }
68228 @@ -2263,7 +2322,7 @@ static noinline struct module *load_modu
68229 secstrings, &stroffs, strmap);
68230
68231 /* Do the allocs. */
68232 - ptr = module_alloc_update_bounds(mod->core_size);
68233 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68234 /*
68235 * The pointer to this block is stored in the module structure
68236 * which is inside the block. Just mark it as not being a
68237 @@ -2274,23 +2333,47 @@ static noinline struct module *load_modu
68238 err = -ENOMEM;
68239 goto free_percpu;
68240 }
68241 - memset(ptr, 0, mod->core_size);
68242 - mod->module_core = ptr;
68243 + memset(ptr, 0, mod->core_size_rw);
68244 + mod->module_core_rw = ptr;
68245
68246 - ptr = module_alloc_update_bounds(mod->init_size);
68247 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68248 /*
68249 * The pointer to this block is stored in the module structure
68250 * which is inside the block. This block doesn't need to be
68251 * scanned as it contains data and code that will be freed
68252 * after the module is initialized.
68253 */
68254 - kmemleak_ignore(ptr);
68255 - if (!ptr && mod->init_size) {
68256 + kmemleak_not_leak(ptr);
68257 + if (!ptr && mod->init_size_rw) {
68258 + err = -ENOMEM;
68259 + goto free_core_rw;
68260 + }
68261 + memset(ptr, 0, mod->init_size_rw);
68262 + mod->module_init_rw = ptr;
68263 +
68264 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68265 + kmemleak_not_leak(ptr);
68266 + if (!ptr) {
68267 err = -ENOMEM;
68268 - goto free_core;
68269 + goto free_init_rw;
68270 }
68271 - memset(ptr, 0, mod->init_size);
68272 - mod->module_init = ptr;
68273 +
68274 + pax_open_kernel();
68275 + memset(ptr, 0, mod->core_size_rx);
68276 + pax_close_kernel();
68277 + mod->module_core_rx = ptr;
68278 +
68279 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68280 + kmemleak_not_leak(ptr);
68281 + if (!ptr && mod->init_size_rx) {
68282 + err = -ENOMEM;
68283 + goto free_core_rx;
68284 + }
68285 +
68286 + pax_open_kernel();
68287 + memset(ptr, 0, mod->init_size_rx);
68288 + pax_close_kernel();
68289 + mod->module_init_rx = ptr;
68290
68291 /* Transfer each section which specifies SHF_ALLOC */
68292 DEBUGP("final section addresses:\n");
68293 @@ -2300,17 +2383,45 @@ static noinline struct module *load_modu
68294 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
68295 continue;
68296
68297 - if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
68298 - dest = mod->module_init
68299 - + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
68300 - else
68301 - dest = mod->module_core + sechdrs[i].sh_entsize;
68302 + if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
68303 + if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
68304 + dest = mod->module_init_rw
68305 + + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
68306 + else
68307 + dest = mod->module_init_rx
68308 + + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
68309 + } else {
68310 + if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
68311 + dest = mod->module_core_rw + sechdrs[i].sh_entsize;
68312 + else
68313 + dest = mod->module_core_rx + sechdrs[i].sh_entsize;
68314 + }
68315 +
68316 + if (sechdrs[i].sh_type != SHT_NOBITS) {
68317
68318 - if (sechdrs[i].sh_type != SHT_NOBITS)
68319 - memcpy(dest, (void *)sechdrs[i].sh_addr,
68320 - sechdrs[i].sh_size);
68321 +#ifdef CONFIG_PAX_KERNEXEC
68322 +#ifdef CONFIG_X86_64
68323 + if ((sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_EXECINSTR))
68324 + set_memory_x((unsigned long)dest, (sechdrs[i].sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68325 +#endif
68326 + if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
68327 + pax_open_kernel();
68328 + memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
68329 + pax_close_kernel();
68330 + } else
68331 +#endif
68332 +
68333 + memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
68334 + }
68335 /* Update sh_addr to point to copy in image. */
68336 - sechdrs[i].sh_addr = (unsigned long)dest;
68337 +
68338 +#ifdef CONFIG_PAX_KERNEXEC
68339 + if (sechdrs[i].sh_flags & SHF_EXECINSTR)
68340 + sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
68341 + else
68342 +#endif
68343 +
68344 + sechdrs[i].sh_addr = (unsigned long)dest;
68345 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
68346 }
68347 /* Module has been moved. */
68348 @@ -2322,7 +2433,7 @@ static noinline struct module *load_modu
68349 mod->name);
68350 if (!mod->refptr) {
68351 err = -ENOMEM;
68352 - goto free_init;
68353 + goto free_init_rx;
68354 }
68355 #endif
68356 /* Now we've moved module, initialize linked lists, etc. */
68357 @@ -2351,6 +2462,31 @@ static noinline struct module *load_modu
68358 /* Set up MODINFO_ATTR fields */
68359 setup_modinfo(mod, sechdrs, infoindex);
68360
68361 + mod->args = args;
68362 +
68363 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68364 + {
68365 + char *p, *p2;
68366 +
68367 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68368 + 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);
68369 + err = -EPERM;
68370 + goto cleanup;
68371 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68372 + p += strlen("grsec_modharden_normal");
68373 + p2 = strstr(p, "_");
68374 + if (p2) {
68375 + *p2 = '\0';
68376 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68377 + *p2 = '_';
68378 + }
68379 + err = -EPERM;
68380 + goto cleanup;
68381 + }
68382 + }
68383 +#endif
68384 +
68385 +
68386 /* Fix up syms, so that st_value is a pointer to location. */
68387 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
68388 mod);
68389 @@ -2431,8 +2567,8 @@ static noinline struct module *load_modu
68390
68391 /* Now do relocations. */
68392 for (i = 1; i < hdr->e_shnum; i++) {
68393 - const char *strtab = (char *)sechdrs[strindex].sh_addr;
68394 unsigned int info = sechdrs[i].sh_info;
68395 + strtab = (char *)sechdrs[strindex].sh_addr;
68396
68397 /* Not a valid relocation section? */
68398 if (info >= hdr->e_shnum)
68399 @@ -2493,16 +2629,15 @@ static noinline struct module *load_modu
68400 * Do it before processing of module parameters, so the module
68401 * can provide parameter accessor functions of its own.
68402 */
68403 - if (mod->module_init)
68404 - flush_icache_range((unsigned long)mod->module_init,
68405 - (unsigned long)mod->module_init
68406 - + mod->init_size);
68407 - flush_icache_range((unsigned long)mod->module_core,
68408 - (unsigned long)mod->module_core + mod->core_size);
68409 + if (mod->module_init_rx)
68410 + flush_icache_range((unsigned long)mod->module_init_rx,
68411 + (unsigned long)mod->module_init_rx
68412 + + mod->init_size_rx);
68413 + flush_icache_range((unsigned long)mod->module_core_rx,
68414 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68415
68416 set_fs(old_fs);
68417
68418 - mod->args = args;
68419 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
68420 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
68421 mod->name);
68422 @@ -2546,12 +2681,16 @@ static noinline struct module *load_modu
68423 free_unload:
68424 module_unload_free(mod);
68425 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
68426 + free_init_rx:
68427 percpu_modfree(mod->refptr);
68428 - free_init:
68429 #endif
68430 - module_free(mod, mod->module_init);
68431 - free_core:
68432 - module_free(mod, mod->module_core);
68433 + module_free_exec(mod, mod->module_init_rx);
68434 + free_core_rx:
68435 + module_free_exec(mod, mod->module_core_rx);
68436 + free_init_rw:
68437 + module_free(mod, mod->module_init_rw);
68438 + free_core_rw:
68439 + module_free(mod, mod->module_core_rw);
68440 /* mod will be freed with core. Don't access it beyond this line! */
68441 free_percpu:
68442 if (percpu)
68443 @@ -2653,10 +2792,12 @@ SYSCALL_DEFINE3(init_module, void __user
68444 mod->symtab = mod->core_symtab;
68445 mod->strtab = mod->core_strtab;
68446 #endif
68447 - module_free(mod, mod->module_init);
68448 - mod->module_init = NULL;
68449 - mod->init_size = 0;
68450 - mod->init_text_size = 0;
68451 + module_free(mod, mod->module_init_rw);
68452 + module_free_exec(mod, mod->module_init_rx);
68453 + mod->module_init_rw = NULL;
68454 + mod->module_init_rx = NULL;
68455 + mod->init_size_rw = 0;
68456 + mod->init_size_rx = 0;
68457 mutex_unlock(&module_mutex);
68458
68459 return 0;
68460 @@ -2687,10 +2828,16 @@ static const char *get_ksymbol(struct mo
68461 unsigned long nextval;
68462
68463 /* At worse, next value is at end of module */
68464 - if (within_module_init(addr, mod))
68465 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68466 + if (within_module_init_rx(addr, mod))
68467 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68468 + else if (within_module_init_rw(addr, mod))
68469 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68470 + else if (within_module_core_rx(addr, mod))
68471 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68472 + else if (within_module_core_rw(addr, mod))
68473 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68474 else
68475 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68476 + return NULL;
68477
68478 /* Scan for closest preceeding symbol, and next symbol. (ELF
68479 starts real symbols at 1). */
68480 @@ -2936,7 +3083,7 @@ static int m_show(struct seq_file *m, vo
68481 char buf[8];
68482
68483 seq_printf(m, "%s %u",
68484 - mod->name, mod->init_size + mod->core_size);
68485 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68486 print_unload_info(m, mod);
68487
68488 /* Informative for users. */
68489 @@ -2945,7 +3092,7 @@ static int m_show(struct seq_file *m, vo
68490 mod->state == MODULE_STATE_COMING ? "Loading":
68491 "Live");
68492 /* Used by oprofile and other similar tools. */
68493 - seq_printf(m, " 0x%p", mod->module_core);
68494 + seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
68495
68496 /* Taints info */
68497 if (mod->taints)
68498 @@ -2981,7 +3128,17 @@ static const struct file_operations proc
68499
68500 static int __init proc_modules_init(void)
68501 {
68502 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68503 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68504 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68505 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68506 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68507 +#else
68508 proc_create("modules", 0, NULL, &proc_modules_operations);
68509 +#endif
68510 +#else
68511 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68512 +#endif
68513 return 0;
68514 }
68515 module_init(proc_modules_init);
68516 @@ -3040,12 +3197,12 @@ struct module *__module_address(unsigned
68517 {
68518 struct module *mod;
68519
68520 - if (addr < module_addr_min || addr > module_addr_max)
68521 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68522 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68523 return NULL;
68524
68525 list_for_each_entry_rcu(mod, &modules, list)
68526 - if (within_module_core(addr, mod)
68527 - || within_module_init(addr, mod))
68528 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68529 return mod;
68530 return NULL;
68531 }
68532 @@ -3079,11 +3236,20 @@ bool is_module_text_address(unsigned lon
68533 */
68534 struct module *__module_text_address(unsigned long addr)
68535 {
68536 - struct module *mod = __module_address(addr);
68537 + struct module *mod;
68538 +
68539 +#ifdef CONFIG_X86_32
68540 + addr = ktla_ktva(addr);
68541 +#endif
68542 +
68543 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68544 + return NULL;
68545 +
68546 + mod = __module_address(addr);
68547 +
68548 if (mod) {
68549 /* Make sure it's within the text section. */
68550 - if (!within(addr, mod->module_init, mod->init_text_size)
68551 - && !within(addr, mod->module_core, mod->core_text_size))
68552 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68553 mod = NULL;
68554 }
68555 return mod;
68556 diff -urNp linux-2.6.32.46/kernel/mutex-debug.c linux-2.6.32.46/kernel/mutex-debug.c
68557 --- linux-2.6.32.46/kernel/mutex-debug.c 2011-03-27 14:31:47.000000000 -0400
68558 +++ linux-2.6.32.46/kernel/mutex-debug.c 2011-04-17 15:56:46.000000000 -0400
68559 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
68560 }
68561
68562 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68563 - struct thread_info *ti)
68564 + struct task_struct *task)
68565 {
68566 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68567
68568 /* Mark the current thread as blocked on the lock: */
68569 - ti->task->blocked_on = waiter;
68570 + task->blocked_on = waiter;
68571 }
68572
68573 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68574 - struct thread_info *ti)
68575 + struct task_struct *task)
68576 {
68577 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68578 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68579 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68580 - ti->task->blocked_on = NULL;
68581 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68582 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68583 + task->blocked_on = NULL;
68584
68585 list_del_init(&waiter->list);
68586 waiter->task = NULL;
68587 @@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lo
68588 return;
68589
68590 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
68591 - DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
68592 + DEBUG_LOCKS_WARN_ON(lock->owner != current);
68593 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
68594 mutex_clear_owner(lock);
68595 }
68596 diff -urNp linux-2.6.32.46/kernel/mutex-debug.h linux-2.6.32.46/kernel/mutex-debug.h
68597 --- linux-2.6.32.46/kernel/mutex-debug.h 2011-03-27 14:31:47.000000000 -0400
68598 +++ linux-2.6.32.46/kernel/mutex-debug.h 2011-04-17 15:56:46.000000000 -0400
68599 @@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(stru
68600 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68601 extern void debug_mutex_add_waiter(struct mutex *lock,
68602 struct mutex_waiter *waiter,
68603 - struct thread_info *ti);
68604 + struct task_struct *task);
68605 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68606 - struct thread_info *ti);
68607 + struct task_struct *task);
68608 extern void debug_mutex_unlock(struct mutex *lock);
68609 extern void debug_mutex_init(struct mutex *lock, const char *name,
68610 struct lock_class_key *key);
68611
68612 static inline void mutex_set_owner(struct mutex *lock)
68613 {
68614 - lock->owner = current_thread_info();
68615 + lock->owner = current;
68616 }
68617
68618 static inline void mutex_clear_owner(struct mutex *lock)
68619 diff -urNp linux-2.6.32.46/kernel/mutex.c linux-2.6.32.46/kernel/mutex.c
68620 --- linux-2.6.32.46/kernel/mutex.c 2011-03-27 14:31:47.000000000 -0400
68621 +++ linux-2.6.32.46/kernel/mutex.c 2011-04-17 15:56:46.000000000 -0400
68622 @@ -169,7 +169,7 @@ __mutex_lock_common(struct mutex *lock,
68623 */
68624
68625 for (;;) {
68626 - struct thread_info *owner;
68627 + struct task_struct *owner;
68628
68629 /*
68630 * If we own the BKL, then don't spin. The owner of
68631 @@ -214,7 +214,7 @@ __mutex_lock_common(struct mutex *lock,
68632 spin_lock_mutex(&lock->wait_lock, flags);
68633
68634 debug_mutex_lock_common(lock, &waiter);
68635 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68636 + debug_mutex_add_waiter(lock, &waiter, task);
68637
68638 /* add waiting tasks to the end of the waitqueue (FIFO): */
68639 list_add_tail(&waiter.list, &lock->wait_list);
68640 @@ -243,8 +243,7 @@ __mutex_lock_common(struct mutex *lock,
68641 * TASK_UNINTERRUPTIBLE case.)
68642 */
68643 if (unlikely(signal_pending_state(state, task))) {
68644 - mutex_remove_waiter(lock, &waiter,
68645 - task_thread_info(task));
68646 + mutex_remove_waiter(lock, &waiter, task);
68647 mutex_release(&lock->dep_map, 1, ip);
68648 spin_unlock_mutex(&lock->wait_lock, flags);
68649
68650 @@ -265,7 +264,7 @@ __mutex_lock_common(struct mutex *lock,
68651 done:
68652 lock_acquired(&lock->dep_map, ip);
68653 /* got the lock - rejoice! */
68654 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68655 + mutex_remove_waiter(lock, &waiter, task);
68656 mutex_set_owner(lock);
68657
68658 /* set it to 0 if there are no waiters left: */
68659 diff -urNp linux-2.6.32.46/kernel/mutex.h linux-2.6.32.46/kernel/mutex.h
68660 --- linux-2.6.32.46/kernel/mutex.h 2011-03-27 14:31:47.000000000 -0400
68661 +++ linux-2.6.32.46/kernel/mutex.h 2011-04-17 15:56:46.000000000 -0400
68662 @@ -19,7 +19,7 @@
68663 #ifdef CONFIG_SMP
68664 static inline void mutex_set_owner(struct mutex *lock)
68665 {
68666 - lock->owner = current_thread_info();
68667 + lock->owner = current;
68668 }
68669
68670 static inline void mutex_clear_owner(struct mutex *lock)
68671 diff -urNp linux-2.6.32.46/kernel/panic.c linux-2.6.32.46/kernel/panic.c
68672 --- linux-2.6.32.46/kernel/panic.c 2011-03-27 14:31:47.000000000 -0400
68673 +++ linux-2.6.32.46/kernel/panic.c 2011-04-17 15:56:46.000000000 -0400
68674 @@ -352,7 +352,7 @@ static void warn_slowpath_common(const c
68675 const char *board;
68676
68677 printk(KERN_WARNING "------------[ cut here ]------------\n");
68678 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68679 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68680 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68681 if (board)
68682 printk(KERN_WARNING "Hardware name: %s\n", board);
68683 @@ -392,7 +392,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68684 */
68685 void __stack_chk_fail(void)
68686 {
68687 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68688 + dump_stack();
68689 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68690 __builtin_return_address(0));
68691 }
68692 EXPORT_SYMBOL(__stack_chk_fail);
68693 diff -urNp linux-2.6.32.46/kernel/params.c linux-2.6.32.46/kernel/params.c
68694 --- linux-2.6.32.46/kernel/params.c 2011-03-27 14:31:47.000000000 -0400
68695 +++ linux-2.6.32.46/kernel/params.c 2011-04-17 15:56:46.000000000 -0400
68696 @@ -725,7 +725,7 @@ static ssize_t module_attr_store(struct
68697 return ret;
68698 }
68699
68700 -static struct sysfs_ops module_sysfs_ops = {
68701 +static const struct sysfs_ops module_sysfs_ops = {
68702 .show = module_attr_show,
68703 .store = module_attr_store,
68704 };
68705 @@ -739,7 +739,7 @@ static int uevent_filter(struct kset *ks
68706 return 0;
68707 }
68708
68709 -static struct kset_uevent_ops module_uevent_ops = {
68710 +static const struct kset_uevent_ops module_uevent_ops = {
68711 .filter = uevent_filter,
68712 };
68713
68714 diff -urNp linux-2.6.32.46/kernel/perf_event.c linux-2.6.32.46/kernel/perf_event.c
68715 --- linux-2.6.32.46/kernel/perf_event.c 2011-08-09 18:35:30.000000000 -0400
68716 +++ linux-2.6.32.46/kernel/perf_event.c 2011-10-06 09:37:14.000000000 -0400
68717 @@ -77,7 +77,7 @@ int sysctl_perf_event_mlock __read_mostl
68718 */
68719 int sysctl_perf_event_sample_rate __read_mostly = 100000;
68720
68721 -static atomic64_t perf_event_id;
68722 +static atomic64_unchecked_t perf_event_id;
68723
68724 /*
68725 * Lock for (sysadmin-configurable) event reservations:
68726 @@ -1094,9 +1094,9 @@ static void __perf_event_sync_stat(struc
68727 * In order to keep per-task stats reliable we need to flip the event
68728 * values when we flip the contexts.
68729 */
68730 - value = atomic64_read(&next_event->count);
68731 - value = atomic64_xchg(&event->count, value);
68732 - atomic64_set(&next_event->count, value);
68733 + value = atomic64_read_unchecked(&next_event->count);
68734 + value = atomic64_xchg_unchecked(&event->count, value);
68735 + atomic64_set_unchecked(&next_event->count, value);
68736
68737 swap(event->total_time_enabled, next_event->total_time_enabled);
68738 swap(event->total_time_running, next_event->total_time_running);
68739 @@ -1552,7 +1552,7 @@ static u64 perf_event_read(struct perf_e
68740 update_event_times(event);
68741 }
68742
68743 - return atomic64_read(&event->count);
68744 + return atomic64_read_unchecked(&event->count);
68745 }
68746
68747 /*
68748 @@ -1790,11 +1790,11 @@ static int perf_event_read_group(struct
68749 values[n++] = 1 + leader->nr_siblings;
68750 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
68751 values[n++] = leader->total_time_enabled +
68752 - atomic64_read(&leader->child_total_time_enabled);
68753 + atomic64_read_unchecked(&leader->child_total_time_enabled);
68754 }
68755 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
68756 values[n++] = leader->total_time_running +
68757 - atomic64_read(&leader->child_total_time_running);
68758 + atomic64_read_unchecked(&leader->child_total_time_running);
68759 }
68760
68761 size = n * sizeof(u64);
68762 @@ -1829,11 +1829,11 @@ static int perf_event_read_one(struct pe
68763 values[n++] = perf_event_read_value(event);
68764 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
68765 values[n++] = event->total_time_enabled +
68766 - atomic64_read(&event->child_total_time_enabled);
68767 + atomic64_read_unchecked(&event->child_total_time_enabled);
68768 }
68769 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
68770 values[n++] = event->total_time_running +
68771 - atomic64_read(&event->child_total_time_running);
68772 + atomic64_read_unchecked(&event->child_total_time_running);
68773 }
68774 if (read_format & PERF_FORMAT_ID)
68775 values[n++] = primary_event_id(event);
68776 @@ -1903,7 +1903,7 @@ static unsigned int perf_poll(struct fil
68777 static void perf_event_reset(struct perf_event *event)
68778 {
68779 (void)perf_event_read(event);
68780 - atomic64_set(&event->count, 0);
68781 + atomic64_set_unchecked(&event->count, 0);
68782 perf_event_update_userpage(event);
68783 }
68784
68785 @@ -2079,15 +2079,15 @@ void perf_event_update_userpage(struct p
68786 ++userpg->lock;
68787 barrier();
68788 userpg->index = perf_event_index(event);
68789 - userpg->offset = atomic64_read(&event->count);
68790 + userpg->offset = atomic64_read_unchecked(&event->count);
68791 if (event->state == PERF_EVENT_STATE_ACTIVE)
68792 - userpg->offset -= atomic64_read(&event->hw.prev_count);
68793 + userpg->offset -= atomic64_read_unchecked(&event->hw.prev_count);
68794
68795 userpg->time_enabled = event->total_time_enabled +
68796 - atomic64_read(&event->child_total_time_enabled);
68797 + atomic64_read_unchecked(&event->child_total_time_enabled);
68798
68799 userpg->time_running = event->total_time_running +
68800 - atomic64_read(&event->child_total_time_running);
68801 + atomic64_read_unchecked(&event->child_total_time_running);
68802
68803 barrier();
68804 ++userpg->lock;
68805 @@ -2903,14 +2903,14 @@ static void perf_output_read_one(struct
68806 u64 values[4];
68807 int n = 0;
68808
68809 - values[n++] = atomic64_read(&event->count);
68810 + values[n++] = atomic64_read_unchecked(&event->count);
68811 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
68812 values[n++] = event->total_time_enabled +
68813 - atomic64_read(&event->child_total_time_enabled);
68814 + atomic64_read_unchecked(&event->child_total_time_enabled);
68815 }
68816 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
68817 values[n++] = event->total_time_running +
68818 - atomic64_read(&event->child_total_time_running);
68819 + atomic64_read_unchecked(&event->child_total_time_running);
68820 }
68821 if (read_format & PERF_FORMAT_ID)
68822 values[n++] = primary_event_id(event);
68823 @@ -2940,7 +2940,7 @@ static void perf_output_read_group(struc
68824 if (leader != event)
68825 leader->pmu->read(leader);
68826
68827 - values[n++] = atomic64_read(&leader->count);
68828 + values[n++] = atomic64_read_unchecked(&leader->count);
68829 if (read_format & PERF_FORMAT_ID)
68830 values[n++] = primary_event_id(leader);
68831
68832 @@ -2952,7 +2952,7 @@ static void perf_output_read_group(struc
68833 if (sub != event)
68834 sub->pmu->read(sub);
68835
68836 - values[n++] = atomic64_read(&sub->count);
68837 + values[n++] = atomic64_read_unchecked(&sub->count);
68838 if (read_format & PERF_FORMAT_ID)
68839 values[n++] = primary_event_id(sub);
68840
68841 @@ -3525,12 +3525,12 @@ static void perf_event_mmap_event(struct
68842 * need to add enough zero bytes after the string to handle
68843 * the 64bit alignment we do later.
68844 */
68845 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
68846 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
68847 if (!buf) {
68848 name = strncpy(tmp, "//enomem", sizeof(tmp));
68849 goto got_name;
68850 }
68851 - name = d_path(&file->f_path, buf, PATH_MAX);
68852 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
68853 if (IS_ERR(name)) {
68854 name = strncpy(tmp, "//toolong", sizeof(tmp));
68855 goto got_name;
68856 @@ -3783,7 +3783,7 @@ static void perf_swevent_add(struct perf
68857 {
68858 struct hw_perf_event *hwc = &event->hw;
68859
68860 - atomic64_add(nr, &event->count);
68861 + atomic64_add_unchecked(nr, &event->count);
68862
68863 if (!hwc->sample_period)
68864 return;
68865 @@ -4040,9 +4040,9 @@ static void cpu_clock_perf_event_update(
68866 u64 now;
68867
68868 now = cpu_clock(cpu);
68869 - prev = atomic64_read(&event->hw.prev_count);
68870 - atomic64_set(&event->hw.prev_count, now);
68871 - atomic64_add(now - prev, &event->count);
68872 + prev = atomic64_read_unchecked(&event->hw.prev_count);
68873 + atomic64_set_unchecked(&event->hw.prev_count, now);
68874 + atomic64_add_unchecked(now - prev, &event->count);
68875 }
68876
68877 static int cpu_clock_perf_event_enable(struct perf_event *event)
68878 @@ -4050,7 +4050,7 @@ static int cpu_clock_perf_event_enable(s
68879 struct hw_perf_event *hwc = &event->hw;
68880 int cpu = raw_smp_processor_id();
68881
68882 - atomic64_set(&hwc->prev_count, cpu_clock(cpu));
68883 + atomic64_set_unchecked(&hwc->prev_count, cpu_clock(cpu));
68884 perf_swevent_start_hrtimer(event);
68885
68886 return 0;
68887 @@ -4082,9 +4082,9 @@ static void task_clock_perf_event_update
68888 u64 prev;
68889 s64 delta;
68890
68891 - prev = atomic64_xchg(&event->hw.prev_count, now);
68892 + prev = atomic64_xchg_unchecked(&event->hw.prev_count, now);
68893 delta = now - prev;
68894 - atomic64_add(delta, &event->count);
68895 + atomic64_add_unchecked(delta, &event->count);
68896 }
68897
68898 static int task_clock_perf_event_enable(struct perf_event *event)
68899 @@ -4094,7 +4094,7 @@ static int task_clock_perf_event_enable(
68900
68901 now = event->ctx->time;
68902
68903 - atomic64_set(&hwc->prev_count, now);
68904 + atomic64_set_unchecked(&hwc->prev_count, now);
68905
68906 perf_swevent_start_hrtimer(event);
68907
68908 @@ -4289,7 +4289,7 @@ perf_event_alloc(struct perf_event_attr
68909 event->parent = parent_event;
68910
68911 event->ns = get_pid_ns(current->nsproxy->pid_ns);
68912 - event->id = atomic64_inc_return(&perf_event_id);
68913 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
68914
68915 event->state = PERF_EVENT_STATE_INACTIVE;
68916
68917 @@ -4720,15 +4720,15 @@ static void sync_child_event(struct perf
68918 if (child_event->attr.inherit_stat)
68919 perf_event_read_event(child_event, child);
68920
68921 - child_val = atomic64_read(&child_event->count);
68922 + child_val = atomic64_read_unchecked(&child_event->count);
68923
68924 /*
68925 * Add back the child's count to the parent's count:
68926 */
68927 - atomic64_add(child_val, &parent_event->count);
68928 - atomic64_add(child_event->total_time_enabled,
68929 + atomic64_add_unchecked(child_val, &parent_event->count);
68930 + atomic64_add_unchecked(child_event->total_time_enabled,
68931 &parent_event->child_total_time_enabled);
68932 - atomic64_add(child_event->total_time_running,
68933 + atomic64_add_unchecked(child_event->total_time_running,
68934 &parent_event->child_total_time_running);
68935
68936 /*
68937 diff -urNp linux-2.6.32.46/kernel/pid.c linux-2.6.32.46/kernel/pid.c
68938 --- linux-2.6.32.46/kernel/pid.c 2011-04-22 19:16:29.000000000 -0400
68939 +++ linux-2.6.32.46/kernel/pid.c 2011-08-21 19:11:29.000000000 -0400
68940 @@ -33,6 +33,7 @@
68941 #include <linux/rculist.h>
68942 #include <linux/bootmem.h>
68943 #include <linux/hash.h>
68944 +#include <linux/security.h>
68945 #include <linux/pid_namespace.h>
68946 #include <linux/init_task.h>
68947 #include <linux/syscalls.h>
68948 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
68949
68950 int pid_max = PID_MAX_DEFAULT;
68951
68952 -#define RESERVED_PIDS 300
68953 +#define RESERVED_PIDS 500
68954
68955 int pid_max_min = RESERVED_PIDS + 1;
68956 int pid_max_max = PID_MAX_LIMIT;
68957 @@ -383,7 +384,14 @@ EXPORT_SYMBOL(pid_task);
68958 */
68959 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68960 {
68961 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68962 + struct task_struct *task;
68963 +
68964 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68965 +
68966 + if (gr_pid_is_chrooted(task))
68967 + return NULL;
68968 +
68969 + return task;
68970 }
68971
68972 struct task_struct *find_task_by_vpid(pid_t vnr)
68973 @@ -391,6 +399,11 @@ struct task_struct *find_task_by_vpid(pi
68974 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68975 }
68976
68977 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68978 +{
68979 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68980 +}
68981 +
68982 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68983 {
68984 struct pid *pid;
68985 diff -urNp linux-2.6.32.46/kernel/posix-cpu-timers.c linux-2.6.32.46/kernel/posix-cpu-timers.c
68986 --- linux-2.6.32.46/kernel/posix-cpu-timers.c 2011-03-27 14:31:47.000000000 -0400
68987 +++ linux-2.6.32.46/kernel/posix-cpu-timers.c 2011-08-06 09:33:44.000000000 -0400
68988 @@ -6,6 +6,7 @@
68989 #include <linux/posix-timers.h>
68990 #include <linux/errno.h>
68991 #include <linux/math64.h>
68992 +#include <linux/security.h>
68993 #include <asm/uaccess.h>
68994 #include <linux/kernel_stat.h>
68995 #include <trace/events/timer.h>
68996 @@ -1697,7 +1698,7 @@ static long thread_cpu_nsleep_restart(st
68997
68998 static __init int init_posix_cpu_timers(void)
68999 {
69000 - struct k_clock process = {
69001 + static struct k_clock process = {
69002 .clock_getres = process_cpu_clock_getres,
69003 .clock_get = process_cpu_clock_get,
69004 .clock_set = do_posix_clock_nosettime,
69005 @@ -1705,7 +1706,7 @@ static __init int init_posix_cpu_timers(
69006 .nsleep = process_cpu_nsleep,
69007 .nsleep_restart = process_cpu_nsleep_restart,
69008 };
69009 - struct k_clock thread = {
69010 + static struct k_clock thread = {
69011 .clock_getres = thread_cpu_clock_getres,
69012 .clock_get = thread_cpu_clock_get,
69013 .clock_set = do_posix_clock_nosettime,
69014 diff -urNp linux-2.6.32.46/kernel/posix-timers.c linux-2.6.32.46/kernel/posix-timers.c
69015 --- linux-2.6.32.46/kernel/posix-timers.c 2011-03-27 14:31:47.000000000 -0400
69016 +++ linux-2.6.32.46/kernel/posix-timers.c 2011-08-23 20:22:38.000000000 -0400
69017 @@ -42,6 +42,7 @@
69018 #include <linux/compiler.h>
69019 #include <linux/idr.h>
69020 #include <linux/posix-timers.h>
69021 +#include <linux/grsecurity.h>
69022 #include <linux/syscalls.h>
69023 #include <linux/wait.h>
69024 #include <linux/workqueue.h>
69025 @@ -131,7 +132,7 @@ static DEFINE_SPINLOCK(idr_lock);
69026 * which we beg off on and pass to do_sys_settimeofday().
69027 */
69028
69029 -static struct k_clock posix_clocks[MAX_CLOCKS];
69030 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69031
69032 /*
69033 * These ones are defined below.
69034 @@ -157,8 +158,8 @@ static inline void unlock_timer(struct k
69035 */
69036 #define CLOCK_DISPATCH(clock, call, arglist) \
69037 ((clock) < 0 ? posix_cpu_##call arglist : \
69038 - (posix_clocks[clock].call != NULL \
69039 - ? (*posix_clocks[clock].call) arglist : common_##call arglist))
69040 + (posix_clocks[clock]->call != NULL \
69041 + ? (*posix_clocks[clock]->call) arglist : common_##call arglist))
69042
69043 /*
69044 * Default clock hook functions when the struct k_clock passed
69045 @@ -172,7 +173,7 @@ static inline int common_clock_getres(co
69046 struct timespec *tp)
69047 {
69048 tp->tv_sec = 0;
69049 - tp->tv_nsec = posix_clocks[which_clock].res;
69050 + tp->tv_nsec = posix_clocks[which_clock]->res;
69051 return 0;
69052 }
69053
69054 @@ -217,9 +218,11 @@ static inline int invalid_clockid(const
69055 return 0;
69056 if ((unsigned) which_clock >= MAX_CLOCKS)
69057 return 1;
69058 - if (posix_clocks[which_clock].clock_getres != NULL)
69059 + if (posix_clocks[which_clock] == NULL)
69060 return 0;
69061 - if (posix_clocks[which_clock].res != 0)
69062 + if (posix_clocks[which_clock]->clock_getres != NULL)
69063 + return 0;
69064 + if (posix_clocks[which_clock]->res != 0)
69065 return 0;
69066 return 1;
69067 }
69068 @@ -266,29 +269,29 @@ int posix_get_coarse_res(const clockid_t
69069 */
69070 static __init int init_posix_timers(void)
69071 {
69072 - struct k_clock clock_realtime = {
69073 + static struct k_clock clock_realtime = {
69074 .clock_getres = hrtimer_get_res,
69075 };
69076 - struct k_clock clock_monotonic = {
69077 + static struct k_clock clock_monotonic = {
69078 .clock_getres = hrtimer_get_res,
69079 .clock_get = posix_ktime_get_ts,
69080 .clock_set = do_posix_clock_nosettime,
69081 };
69082 - struct k_clock clock_monotonic_raw = {
69083 + static struct k_clock clock_monotonic_raw = {
69084 .clock_getres = hrtimer_get_res,
69085 .clock_get = posix_get_monotonic_raw,
69086 .clock_set = do_posix_clock_nosettime,
69087 .timer_create = no_timer_create,
69088 .nsleep = no_nsleep,
69089 };
69090 - struct k_clock clock_realtime_coarse = {
69091 + static struct k_clock clock_realtime_coarse = {
69092 .clock_getres = posix_get_coarse_res,
69093 .clock_get = posix_get_realtime_coarse,
69094 .clock_set = do_posix_clock_nosettime,
69095 .timer_create = no_timer_create,
69096 .nsleep = no_nsleep,
69097 };
69098 - struct k_clock clock_monotonic_coarse = {
69099 + static struct k_clock clock_monotonic_coarse = {
69100 .clock_getres = posix_get_coarse_res,
69101 .clock_get = posix_get_monotonic_coarse,
69102 .clock_set = do_posix_clock_nosettime,
69103 @@ -296,6 +299,8 @@ static __init int init_posix_timers(void
69104 .nsleep = no_nsleep,
69105 };
69106
69107 + pax_track_stack();
69108 +
69109 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
69110 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
69111 register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
69112 @@ -484,7 +489,7 @@ void register_posix_clock(const clockid_
69113 return;
69114 }
69115
69116 - posix_clocks[clock_id] = *new_clock;
69117 + posix_clocks[clock_id] = new_clock;
69118 }
69119 EXPORT_SYMBOL_GPL(register_posix_clock);
69120
69121 @@ -948,6 +953,13 @@ SYSCALL_DEFINE2(clock_settime, const clo
69122 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69123 return -EFAULT;
69124
69125 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69126 + have their clock_set fptr set to a nosettime dummy function
69127 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69128 + call common_clock_set, which calls do_sys_settimeofday, which
69129 + we hook
69130 + */
69131 +
69132 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
69133 }
69134
69135 diff -urNp linux-2.6.32.46/kernel/power/hibernate.c linux-2.6.32.46/kernel/power/hibernate.c
69136 --- linux-2.6.32.46/kernel/power/hibernate.c 2011-03-27 14:31:47.000000000 -0400
69137 +++ linux-2.6.32.46/kernel/power/hibernate.c 2011-04-17 15:56:46.000000000 -0400
69138 @@ -48,14 +48,14 @@ enum {
69139
69140 static int hibernation_mode = HIBERNATION_SHUTDOWN;
69141
69142 -static struct platform_hibernation_ops *hibernation_ops;
69143 +static const struct platform_hibernation_ops *hibernation_ops;
69144
69145 /**
69146 * hibernation_set_ops - set the global hibernate operations
69147 * @ops: the hibernation operations to use in subsequent hibernation transitions
69148 */
69149
69150 -void hibernation_set_ops(struct platform_hibernation_ops *ops)
69151 +void hibernation_set_ops(const struct platform_hibernation_ops *ops)
69152 {
69153 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
69154 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
69155 diff -urNp linux-2.6.32.46/kernel/power/poweroff.c linux-2.6.32.46/kernel/power/poweroff.c
69156 --- linux-2.6.32.46/kernel/power/poweroff.c 2011-03-27 14:31:47.000000000 -0400
69157 +++ linux-2.6.32.46/kernel/power/poweroff.c 2011-04-17 15:56:46.000000000 -0400
69158 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
69159 .enable_mask = SYSRQ_ENABLE_BOOT,
69160 };
69161
69162 -static int pm_sysrq_init(void)
69163 +static int __init pm_sysrq_init(void)
69164 {
69165 register_sysrq_key('o', &sysrq_poweroff_op);
69166 return 0;
69167 diff -urNp linux-2.6.32.46/kernel/power/process.c linux-2.6.32.46/kernel/power/process.c
69168 --- linux-2.6.32.46/kernel/power/process.c 2011-03-27 14:31:47.000000000 -0400
69169 +++ linux-2.6.32.46/kernel/power/process.c 2011-04-17 15:56:46.000000000 -0400
69170 @@ -37,12 +37,15 @@ static int try_to_freeze_tasks(bool sig_
69171 struct timeval start, end;
69172 u64 elapsed_csecs64;
69173 unsigned int elapsed_csecs;
69174 + bool timedout = false;
69175
69176 do_gettimeofday(&start);
69177
69178 end_time = jiffies + TIMEOUT;
69179 do {
69180 todo = 0;
69181 + if (time_after(jiffies, end_time))
69182 + timedout = true;
69183 read_lock(&tasklist_lock);
69184 do_each_thread(g, p) {
69185 if (frozen(p) || !freezeable(p))
69186 @@ -57,15 +60,17 @@ static int try_to_freeze_tasks(bool sig_
69187 * It is "frozen enough". If the task does wake
69188 * up, it will immediately call try_to_freeze.
69189 */
69190 - if (!task_is_stopped_or_traced(p) &&
69191 - !freezer_should_skip(p))
69192 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69193 todo++;
69194 + if (timedout) {
69195 + printk(KERN_ERR "Task refusing to freeze:\n");
69196 + sched_show_task(p);
69197 + }
69198 + }
69199 } while_each_thread(g, p);
69200 read_unlock(&tasklist_lock);
69201 yield(); /* Yield is okay here */
69202 - if (time_after(jiffies, end_time))
69203 - break;
69204 - } while (todo);
69205 + } while (todo && !timedout);
69206
69207 do_gettimeofday(&end);
69208 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
69209 diff -urNp linux-2.6.32.46/kernel/power/suspend.c linux-2.6.32.46/kernel/power/suspend.c
69210 --- linux-2.6.32.46/kernel/power/suspend.c 2011-03-27 14:31:47.000000000 -0400
69211 +++ linux-2.6.32.46/kernel/power/suspend.c 2011-04-17 15:56:46.000000000 -0400
69212 @@ -23,13 +23,13 @@ const char *const pm_states[PM_SUSPEND_M
69213 [PM_SUSPEND_MEM] = "mem",
69214 };
69215
69216 -static struct platform_suspend_ops *suspend_ops;
69217 +static const struct platform_suspend_ops *suspend_ops;
69218
69219 /**
69220 * suspend_set_ops - Set the global suspend method table.
69221 * @ops: Pointer to ops structure.
69222 */
69223 -void suspend_set_ops(struct platform_suspend_ops *ops)
69224 +void suspend_set_ops(const struct platform_suspend_ops *ops)
69225 {
69226 mutex_lock(&pm_mutex);
69227 suspend_ops = ops;
69228 diff -urNp linux-2.6.32.46/kernel/printk.c linux-2.6.32.46/kernel/printk.c
69229 --- linux-2.6.32.46/kernel/printk.c 2011-03-27 14:31:47.000000000 -0400
69230 +++ linux-2.6.32.46/kernel/printk.c 2011-04-17 15:56:46.000000000 -0400
69231 @@ -278,6 +278,11 @@ int do_syslog(int type, char __user *buf
69232 char c;
69233 int error = 0;
69234
69235 +#ifdef CONFIG_GRKERNSEC_DMESG
69236 + if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
69237 + return -EPERM;
69238 +#endif
69239 +
69240 error = security_syslog(type);
69241 if (error)
69242 return error;
69243 diff -urNp linux-2.6.32.46/kernel/profile.c linux-2.6.32.46/kernel/profile.c
69244 --- linux-2.6.32.46/kernel/profile.c 2011-03-27 14:31:47.000000000 -0400
69245 +++ linux-2.6.32.46/kernel/profile.c 2011-05-04 17:56:28.000000000 -0400
69246 @@ -39,7 +39,7 @@ struct profile_hit {
69247 /* Oprofile timer tick hook */
69248 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69249
69250 -static atomic_t *prof_buffer;
69251 +static atomic_unchecked_t *prof_buffer;
69252 static unsigned long prof_len, prof_shift;
69253
69254 int prof_on __read_mostly;
69255 @@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
69256 hits[i].pc = 0;
69257 continue;
69258 }
69259 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69260 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69261 hits[i].hits = hits[i].pc = 0;
69262 }
69263 }
69264 @@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc,
69265 * Add the current hit(s) and flush the write-queue out
69266 * to the global buffer:
69267 */
69268 - atomic_add(nr_hits, &prof_buffer[pc]);
69269 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69270 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69271 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69272 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69273 hits[i].pc = hits[i].hits = 0;
69274 }
69275 out:
69276 @@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc,
69277 if (prof_on != type || !prof_buffer)
69278 return;
69279 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69280 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69281 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69282 }
69283 #endif /* !CONFIG_SMP */
69284 EXPORT_SYMBOL_GPL(profile_hits);
69285 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
69286 return -EFAULT;
69287 buf++; p++; count--; read++;
69288 }
69289 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69290 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69291 if (copy_to_user(buf, (void *)pnt, count))
69292 return -EFAULT;
69293 read += count;
69294 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
69295 }
69296 #endif
69297 profile_discard_flip_buffers();
69298 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69299 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69300 return count;
69301 }
69302
69303 diff -urNp linux-2.6.32.46/kernel/ptrace.c linux-2.6.32.46/kernel/ptrace.c
69304 --- linux-2.6.32.46/kernel/ptrace.c 2011-03-27 14:31:47.000000000 -0400
69305 +++ linux-2.6.32.46/kernel/ptrace.c 2011-05-22 23:02:06.000000000 -0400
69306 @@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_stru
69307 return ret;
69308 }
69309
69310 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
69311 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
69312 + unsigned int log)
69313 {
69314 const struct cred *cred = current_cred(), *tcred;
69315
69316 @@ -141,7 +142,9 @@ int __ptrace_may_access(struct task_stru
69317 cred->gid != tcred->egid ||
69318 cred->gid != tcred->sgid ||
69319 cred->gid != tcred->gid) &&
69320 - !capable(CAP_SYS_PTRACE)) {
69321 + ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
69322 + (log && !capable(CAP_SYS_PTRACE)))
69323 + ) {
69324 rcu_read_unlock();
69325 return -EPERM;
69326 }
69327 @@ -149,7 +152,9 @@ int __ptrace_may_access(struct task_stru
69328 smp_rmb();
69329 if (task->mm)
69330 dumpable = get_dumpable(task->mm);
69331 - if (!dumpable && !capable(CAP_SYS_PTRACE))
69332 + if (!dumpable &&
69333 + ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
69334 + (log && !capable(CAP_SYS_PTRACE))))
69335 return -EPERM;
69336
69337 return security_ptrace_access_check(task, mode);
69338 @@ -159,7 +164,16 @@ bool ptrace_may_access(struct task_struc
69339 {
69340 int err;
69341 task_lock(task);
69342 - err = __ptrace_may_access(task, mode);
69343 + err = __ptrace_may_access(task, mode, 0);
69344 + task_unlock(task);
69345 + return !err;
69346 +}
69347 +
69348 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
69349 +{
69350 + int err;
69351 + task_lock(task);
69352 + err = __ptrace_may_access(task, mode, 1);
69353 task_unlock(task);
69354 return !err;
69355 }
69356 @@ -186,7 +200,7 @@ int ptrace_attach(struct task_struct *ta
69357 goto out;
69358
69359 task_lock(task);
69360 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
69361 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
69362 task_unlock(task);
69363 if (retval)
69364 goto unlock_creds;
69365 @@ -199,7 +213,7 @@ int ptrace_attach(struct task_struct *ta
69366 goto unlock_tasklist;
69367
69368 task->ptrace = PT_PTRACED;
69369 - if (capable(CAP_SYS_PTRACE))
69370 + if (capable_nolog(CAP_SYS_PTRACE))
69371 task->ptrace |= PT_PTRACE_CAP;
69372
69373 __ptrace_link(task, current);
69374 @@ -351,6 +365,8 @@ int ptrace_readdata(struct task_struct *
69375 {
69376 int copied = 0;
69377
69378 + pax_track_stack();
69379 +
69380 while (len > 0) {
69381 char buf[128];
69382 int this_len, retval;
69383 @@ -376,6 +392,8 @@ int ptrace_writedata(struct task_struct
69384 {
69385 int copied = 0;
69386
69387 + pax_track_stack();
69388 +
69389 while (len > 0) {
69390 char buf[128];
69391 int this_len, retval;
69392 @@ -517,6 +535,8 @@ int ptrace_request(struct task_struct *c
69393 int ret = -EIO;
69394 siginfo_t siginfo;
69395
69396 + pax_track_stack();
69397 +
69398 switch (request) {
69399 case PTRACE_PEEKTEXT:
69400 case PTRACE_PEEKDATA:
69401 @@ -532,18 +552,18 @@ int ptrace_request(struct task_struct *c
69402 ret = ptrace_setoptions(child, data);
69403 break;
69404 case PTRACE_GETEVENTMSG:
69405 - ret = put_user(child->ptrace_message, (unsigned long __user *) data);
69406 + ret = put_user(child->ptrace_message, (__force unsigned long __user *) data);
69407 break;
69408
69409 case PTRACE_GETSIGINFO:
69410 ret = ptrace_getsiginfo(child, &siginfo);
69411 if (!ret)
69412 - ret = copy_siginfo_to_user((siginfo_t __user *) data,
69413 + ret = copy_siginfo_to_user((__force siginfo_t __user *) data,
69414 &siginfo);
69415 break;
69416
69417 case PTRACE_SETSIGINFO:
69418 - if (copy_from_user(&siginfo, (siginfo_t __user *) data,
69419 + if (copy_from_user(&siginfo, (__force siginfo_t __user *) data,
69420 sizeof siginfo))
69421 ret = -EFAULT;
69422 else
69423 @@ -621,14 +641,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
69424 goto out;
69425 }
69426
69427 + if (gr_handle_ptrace(child, request)) {
69428 + ret = -EPERM;
69429 + goto out_put_task_struct;
69430 + }
69431 +
69432 if (request == PTRACE_ATTACH) {
69433 ret = ptrace_attach(child);
69434 /*
69435 * Some architectures need to do book-keeping after
69436 * a ptrace attach.
69437 */
69438 - if (!ret)
69439 + if (!ret) {
69440 arch_ptrace_attach(child);
69441 + gr_audit_ptrace(child);
69442 + }
69443 goto out_put_task_struct;
69444 }
69445
69446 @@ -653,7 +680,7 @@ int generic_ptrace_peekdata(struct task_
69447 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69448 if (copied != sizeof(tmp))
69449 return -EIO;
69450 - return put_user(tmp, (unsigned long __user *)data);
69451 + return put_user(tmp, (__force unsigned long __user *)data);
69452 }
69453
69454 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
69455 @@ -675,6 +702,8 @@ int compat_ptrace_request(struct task_st
69456 siginfo_t siginfo;
69457 int ret;
69458
69459 + pax_track_stack();
69460 +
69461 switch (request) {
69462 case PTRACE_PEEKTEXT:
69463 case PTRACE_PEEKDATA:
69464 @@ -740,14 +769,21 @@ asmlinkage long compat_sys_ptrace(compat
69465 goto out;
69466 }
69467
69468 + if (gr_handle_ptrace(child, request)) {
69469 + ret = -EPERM;
69470 + goto out_put_task_struct;
69471 + }
69472 +
69473 if (request == PTRACE_ATTACH) {
69474 ret = ptrace_attach(child);
69475 /*
69476 * Some architectures need to do book-keeping after
69477 * a ptrace attach.
69478 */
69479 - if (!ret)
69480 + if (!ret) {
69481 arch_ptrace_attach(child);
69482 + gr_audit_ptrace(child);
69483 + }
69484 goto out_put_task_struct;
69485 }
69486
69487 diff -urNp linux-2.6.32.46/kernel/rcutorture.c linux-2.6.32.46/kernel/rcutorture.c
69488 --- linux-2.6.32.46/kernel/rcutorture.c 2011-03-27 14:31:47.000000000 -0400
69489 +++ linux-2.6.32.46/kernel/rcutorture.c 2011-05-04 17:56:28.000000000 -0400
69490 @@ -118,12 +118,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
69491 { 0 };
69492 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69493 { 0 };
69494 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69495 -static atomic_t n_rcu_torture_alloc;
69496 -static atomic_t n_rcu_torture_alloc_fail;
69497 -static atomic_t n_rcu_torture_free;
69498 -static atomic_t n_rcu_torture_mberror;
69499 -static atomic_t n_rcu_torture_error;
69500 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69501 +static atomic_unchecked_t n_rcu_torture_alloc;
69502 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69503 +static atomic_unchecked_t n_rcu_torture_free;
69504 +static atomic_unchecked_t n_rcu_torture_mberror;
69505 +static atomic_unchecked_t n_rcu_torture_error;
69506 static long n_rcu_torture_timers;
69507 static struct list_head rcu_torture_removed;
69508 static cpumask_var_t shuffle_tmp_mask;
69509 @@ -187,11 +187,11 @@ rcu_torture_alloc(void)
69510
69511 spin_lock_bh(&rcu_torture_lock);
69512 if (list_empty(&rcu_torture_freelist)) {
69513 - atomic_inc(&n_rcu_torture_alloc_fail);
69514 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69515 spin_unlock_bh(&rcu_torture_lock);
69516 return NULL;
69517 }
69518 - atomic_inc(&n_rcu_torture_alloc);
69519 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69520 p = rcu_torture_freelist.next;
69521 list_del_init(p);
69522 spin_unlock_bh(&rcu_torture_lock);
69523 @@ -204,7 +204,7 @@ rcu_torture_alloc(void)
69524 static void
69525 rcu_torture_free(struct rcu_torture *p)
69526 {
69527 - atomic_inc(&n_rcu_torture_free);
69528 + atomic_inc_unchecked(&n_rcu_torture_free);
69529 spin_lock_bh(&rcu_torture_lock);
69530 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69531 spin_unlock_bh(&rcu_torture_lock);
69532 @@ -319,7 +319,7 @@ rcu_torture_cb(struct rcu_head *p)
69533 i = rp->rtort_pipe_count;
69534 if (i > RCU_TORTURE_PIPE_LEN)
69535 i = RCU_TORTURE_PIPE_LEN;
69536 - atomic_inc(&rcu_torture_wcount[i]);
69537 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69538 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69539 rp->rtort_mbtest = 0;
69540 rcu_torture_free(rp);
69541 @@ -359,7 +359,7 @@ static void rcu_sync_torture_deferred_fr
69542 i = rp->rtort_pipe_count;
69543 if (i > RCU_TORTURE_PIPE_LEN)
69544 i = RCU_TORTURE_PIPE_LEN;
69545 - atomic_inc(&rcu_torture_wcount[i]);
69546 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69547 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69548 rp->rtort_mbtest = 0;
69549 list_del(&rp->rtort_free);
69550 @@ -653,7 +653,7 @@ rcu_torture_writer(void *arg)
69551 i = old_rp->rtort_pipe_count;
69552 if (i > RCU_TORTURE_PIPE_LEN)
69553 i = RCU_TORTURE_PIPE_LEN;
69554 - atomic_inc(&rcu_torture_wcount[i]);
69555 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69556 old_rp->rtort_pipe_count++;
69557 cur_ops->deferred_free(old_rp);
69558 }
69559 @@ -718,7 +718,7 @@ static void rcu_torture_timer(unsigned l
69560 return;
69561 }
69562 if (p->rtort_mbtest == 0)
69563 - atomic_inc(&n_rcu_torture_mberror);
69564 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69565 spin_lock(&rand_lock);
69566 cur_ops->read_delay(&rand);
69567 n_rcu_torture_timers++;
69568 @@ -776,7 +776,7 @@ rcu_torture_reader(void *arg)
69569 continue;
69570 }
69571 if (p->rtort_mbtest == 0)
69572 - atomic_inc(&n_rcu_torture_mberror);
69573 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69574 cur_ops->read_delay(&rand);
69575 preempt_disable();
69576 pipe_count = p->rtort_pipe_count;
69577 @@ -834,17 +834,17 @@ rcu_torture_printk(char *page)
69578 rcu_torture_current,
69579 rcu_torture_current_version,
69580 list_empty(&rcu_torture_freelist),
69581 - atomic_read(&n_rcu_torture_alloc),
69582 - atomic_read(&n_rcu_torture_alloc_fail),
69583 - atomic_read(&n_rcu_torture_free),
69584 - atomic_read(&n_rcu_torture_mberror),
69585 + atomic_read_unchecked(&n_rcu_torture_alloc),
69586 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69587 + atomic_read_unchecked(&n_rcu_torture_free),
69588 + atomic_read_unchecked(&n_rcu_torture_mberror),
69589 n_rcu_torture_timers);
69590 - if (atomic_read(&n_rcu_torture_mberror) != 0)
69591 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0)
69592 cnt += sprintf(&page[cnt], " !!!");
69593 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69594 if (i > 1) {
69595 cnt += sprintf(&page[cnt], "!!! ");
69596 - atomic_inc(&n_rcu_torture_error);
69597 + atomic_inc_unchecked(&n_rcu_torture_error);
69598 WARN_ON_ONCE(1);
69599 }
69600 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69601 @@ -858,7 +858,7 @@ rcu_torture_printk(char *page)
69602 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69603 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69604 cnt += sprintf(&page[cnt], " %d",
69605 - atomic_read(&rcu_torture_wcount[i]));
69606 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69607 }
69608 cnt += sprintf(&page[cnt], "\n");
69609 if (cur_ops->stats)
69610 @@ -1084,7 +1084,7 @@ rcu_torture_cleanup(void)
69611
69612 if (cur_ops->cleanup)
69613 cur_ops->cleanup();
69614 - if (atomic_read(&n_rcu_torture_error))
69615 + if (atomic_read_unchecked(&n_rcu_torture_error))
69616 rcu_torture_print_module_parms("End of test: FAILURE");
69617 else
69618 rcu_torture_print_module_parms("End of test: SUCCESS");
69619 @@ -1138,13 +1138,13 @@ rcu_torture_init(void)
69620
69621 rcu_torture_current = NULL;
69622 rcu_torture_current_version = 0;
69623 - atomic_set(&n_rcu_torture_alloc, 0);
69624 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69625 - atomic_set(&n_rcu_torture_free, 0);
69626 - atomic_set(&n_rcu_torture_mberror, 0);
69627 - atomic_set(&n_rcu_torture_error, 0);
69628 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69629 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69630 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69631 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69632 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69633 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69634 - atomic_set(&rcu_torture_wcount[i], 0);
69635 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69636 for_each_possible_cpu(cpu) {
69637 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69638 per_cpu(rcu_torture_count, cpu)[i] = 0;
69639 diff -urNp linux-2.6.32.46/kernel/rcutree.c linux-2.6.32.46/kernel/rcutree.c
69640 --- linux-2.6.32.46/kernel/rcutree.c 2011-03-27 14:31:47.000000000 -0400
69641 +++ linux-2.6.32.46/kernel/rcutree.c 2011-04-17 15:56:46.000000000 -0400
69642 @@ -1303,7 +1303,7 @@ __rcu_process_callbacks(struct rcu_state
69643 /*
69644 * Do softirq processing for the current CPU.
69645 */
69646 -static void rcu_process_callbacks(struct softirq_action *unused)
69647 +static void rcu_process_callbacks(void)
69648 {
69649 /*
69650 * Memory references from any prior RCU read-side critical sections
69651 diff -urNp linux-2.6.32.46/kernel/rcutree_plugin.h linux-2.6.32.46/kernel/rcutree_plugin.h
69652 --- linux-2.6.32.46/kernel/rcutree_plugin.h 2011-03-27 14:31:47.000000000 -0400
69653 +++ linux-2.6.32.46/kernel/rcutree_plugin.h 2011-04-17 15:56:46.000000000 -0400
69654 @@ -145,7 +145,7 @@ static void rcu_preempt_note_context_swi
69655 */
69656 void __rcu_read_lock(void)
69657 {
69658 - ACCESS_ONCE(current->rcu_read_lock_nesting)++;
69659 + ACCESS_ONCE_RW(current->rcu_read_lock_nesting)++;
69660 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
69661 }
69662 EXPORT_SYMBOL_GPL(__rcu_read_lock);
69663 @@ -251,7 +251,7 @@ void __rcu_read_unlock(void)
69664 struct task_struct *t = current;
69665
69666 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
69667 - if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
69668 + if (--ACCESS_ONCE_RW(t->rcu_read_lock_nesting) == 0 &&
69669 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
69670 rcu_read_unlock_special(t);
69671 }
69672 diff -urNp linux-2.6.32.46/kernel/relay.c linux-2.6.32.46/kernel/relay.c
69673 --- linux-2.6.32.46/kernel/relay.c 2011-03-27 14:31:47.000000000 -0400
69674 +++ linux-2.6.32.46/kernel/relay.c 2011-05-16 21:46:57.000000000 -0400
69675 @@ -1222,7 +1222,7 @@ static int subbuf_splice_actor(struct fi
69676 unsigned int flags,
69677 int *nonpad_ret)
69678 {
69679 - unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
69680 + unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
69681 struct rchan_buf *rbuf = in->private_data;
69682 unsigned int subbuf_size = rbuf->chan->subbuf_size;
69683 uint64_t pos = (uint64_t) *ppos;
69684 @@ -1241,6 +1241,9 @@ static int subbuf_splice_actor(struct fi
69685 .ops = &relay_pipe_buf_ops,
69686 .spd_release = relay_page_release,
69687 };
69688 + ssize_t ret;
69689 +
69690 + pax_track_stack();
69691
69692 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
69693 return 0;
69694 diff -urNp linux-2.6.32.46/kernel/resource.c linux-2.6.32.46/kernel/resource.c
69695 --- linux-2.6.32.46/kernel/resource.c 2011-03-27 14:31:47.000000000 -0400
69696 +++ linux-2.6.32.46/kernel/resource.c 2011-04-17 15:56:46.000000000 -0400
69697 @@ -132,8 +132,18 @@ static const struct file_operations proc
69698
69699 static int __init ioresources_init(void)
69700 {
69701 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69702 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69703 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69704 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69705 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69706 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69707 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69708 +#endif
69709 +#else
69710 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69711 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69712 +#endif
69713 return 0;
69714 }
69715 __initcall(ioresources_init);
69716 diff -urNp linux-2.6.32.46/kernel/rtmutex-tester.c linux-2.6.32.46/kernel/rtmutex-tester.c
69717 --- linux-2.6.32.46/kernel/rtmutex-tester.c 2011-03-27 14:31:47.000000000 -0400
69718 +++ linux-2.6.32.46/kernel/rtmutex-tester.c 2011-05-04 17:56:28.000000000 -0400
69719 @@ -21,7 +21,7 @@
69720 #define MAX_RT_TEST_MUTEXES 8
69721
69722 static spinlock_t rttest_lock;
69723 -static atomic_t rttest_event;
69724 +static atomic_unchecked_t rttest_event;
69725
69726 struct test_thread_data {
69727 int opcode;
69728 @@ -64,7 +64,7 @@ static int handle_op(struct test_thread_
69729
69730 case RTTEST_LOCKCONT:
69731 td->mutexes[td->opdata] = 1;
69732 - td->event = atomic_add_return(1, &rttest_event);
69733 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69734 return 0;
69735
69736 case RTTEST_RESET:
69737 @@ -82,7 +82,7 @@ static int handle_op(struct test_thread_
69738 return 0;
69739
69740 case RTTEST_RESETEVENT:
69741 - atomic_set(&rttest_event, 0);
69742 + atomic_set_unchecked(&rttest_event, 0);
69743 return 0;
69744
69745 default:
69746 @@ -99,9 +99,9 @@ static int handle_op(struct test_thread_
69747 return ret;
69748
69749 td->mutexes[id] = 1;
69750 - td->event = atomic_add_return(1, &rttest_event);
69751 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69752 rt_mutex_lock(&mutexes[id]);
69753 - td->event = atomic_add_return(1, &rttest_event);
69754 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69755 td->mutexes[id] = 4;
69756 return 0;
69757
69758 @@ -112,9 +112,9 @@ static int handle_op(struct test_thread_
69759 return ret;
69760
69761 td->mutexes[id] = 1;
69762 - td->event = atomic_add_return(1, &rttest_event);
69763 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69764 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69765 - td->event = atomic_add_return(1, &rttest_event);
69766 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69767 td->mutexes[id] = ret ? 0 : 4;
69768 return ret ? -EINTR : 0;
69769
69770 @@ -123,9 +123,9 @@ static int handle_op(struct test_thread_
69771 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69772 return ret;
69773
69774 - td->event = atomic_add_return(1, &rttest_event);
69775 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69776 rt_mutex_unlock(&mutexes[id]);
69777 - td->event = atomic_add_return(1, &rttest_event);
69778 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69779 td->mutexes[id] = 0;
69780 return 0;
69781
69782 @@ -187,7 +187,7 @@ void schedule_rt_mutex_test(struct rt_mu
69783 break;
69784
69785 td->mutexes[dat] = 2;
69786 - td->event = atomic_add_return(1, &rttest_event);
69787 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69788 break;
69789
69790 case RTTEST_LOCKBKL:
69791 @@ -208,7 +208,7 @@ void schedule_rt_mutex_test(struct rt_mu
69792 return;
69793
69794 td->mutexes[dat] = 3;
69795 - td->event = atomic_add_return(1, &rttest_event);
69796 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69797 break;
69798
69799 case RTTEST_LOCKNOWAIT:
69800 @@ -220,7 +220,7 @@ void schedule_rt_mutex_test(struct rt_mu
69801 return;
69802
69803 td->mutexes[dat] = 1;
69804 - td->event = atomic_add_return(1, &rttest_event);
69805 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69806 return;
69807
69808 case RTTEST_LOCKBKL:
69809 diff -urNp linux-2.6.32.46/kernel/rtmutex.c linux-2.6.32.46/kernel/rtmutex.c
69810 --- linux-2.6.32.46/kernel/rtmutex.c 2011-03-27 14:31:47.000000000 -0400
69811 +++ linux-2.6.32.46/kernel/rtmutex.c 2011-04-17 15:56:46.000000000 -0400
69812 @@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt
69813 */
69814 spin_lock_irqsave(&pendowner->pi_lock, flags);
69815
69816 - WARN_ON(!pendowner->pi_blocked_on);
69817 + BUG_ON(!pendowner->pi_blocked_on);
69818 WARN_ON(pendowner->pi_blocked_on != waiter);
69819 WARN_ON(pendowner->pi_blocked_on->lock != lock);
69820
69821 diff -urNp linux-2.6.32.46/kernel/sched.c linux-2.6.32.46/kernel/sched.c
69822 --- linux-2.6.32.46/kernel/sched.c 2011-03-27 14:31:47.000000000 -0400
69823 +++ linux-2.6.32.46/kernel/sched.c 2011-08-21 19:29:25.000000000 -0400
69824 @@ -2764,9 +2764,10 @@ void wake_up_new_task(struct task_struct
69825 {
69826 unsigned long flags;
69827 struct rq *rq;
69828 - int cpu = get_cpu();
69829
69830 #ifdef CONFIG_SMP
69831 + int cpu = get_cpu();
69832 +
69833 rq = task_rq_lock(p, &flags);
69834 p->state = TASK_WAKING;
69835
69836 @@ -5043,7 +5044,7 @@ out:
69837 * In CONFIG_NO_HZ case, the idle load balance owner will do the
69838 * rebalancing for all the cpus for whom scheduler ticks are stopped.
69839 */
69840 -static void run_rebalance_domains(struct softirq_action *h)
69841 +static void run_rebalance_domains(void)
69842 {
69843 int this_cpu = smp_processor_id();
69844 struct rq *this_rq = cpu_rq(this_cpu);
69845 @@ -5700,6 +5701,8 @@ asmlinkage void __sched schedule(void)
69846 struct rq *rq;
69847 int cpu;
69848
69849 + pax_track_stack();
69850 +
69851 need_resched:
69852 preempt_disable();
69853 cpu = smp_processor_id();
69854 @@ -5770,7 +5773,7 @@ EXPORT_SYMBOL(schedule);
69855 * Look out! "owner" is an entirely speculative pointer
69856 * access and not reliable.
69857 */
69858 -int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
69859 +int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
69860 {
69861 unsigned int cpu;
69862 struct rq *rq;
69863 @@ -5784,10 +5787,10 @@ int mutex_spin_on_owner(struct mutex *lo
69864 * DEBUG_PAGEALLOC could have unmapped it if
69865 * the mutex owner just released it and exited.
69866 */
69867 - if (probe_kernel_address(&owner->cpu, cpu))
69868 + if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
69869 return 0;
69870 #else
69871 - cpu = owner->cpu;
69872 + cpu = task_thread_info(owner)->cpu;
69873 #endif
69874
69875 /*
69876 @@ -5816,7 +5819,7 @@ int mutex_spin_on_owner(struct mutex *lo
69877 /*
69878 * Is that owner really running on that cpu?
69879 */
69880 - if (task_thread_info(rq->curr) != owner || need_resched())
69881 + if (rq->curr != owner || need_resched())
69882 return 0;
69883
69884 cpu_relax();
69885 @@ -6359,6 +6362,8 @@ int can_nice(const struct task_struct *p
69886 /* convert nice value [19,-20] to rlimit style value [1,40] */
69887 int nice_rlim = 20 - nice;
69888
69889 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69890 +
69891 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur ||
69892 capable(CAP_SYS_NICE));
69893 }
69894 @@ -6392,7 +6397,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69895 if (nice > 19)
69896 nice = 19;
69897
69898 - if (increment < 0 && !can_nice(current, nice))
69899 + if (increment < 0 && (!can_nice(current, nice) ||
69900 + gr_handle_chroot_nice()))
69901 return -EPERM;
69902
69903 retval = security_task_setnice(current, nice);
69904 @@ -8774,7 +8780,7 @@ static void init_sched_groups_power(int
69905 long power;
69906 int weight;
69907
69908 - WARN_ON(!sd || !sd->groups);
69909 + BUG_ON(!sd || !sd->groups);
69910
69911 if (cpu != group_first_cpu(sd->groups))
69912 return;
69913 diff -urNp linux-2.6.32.46/kernel/signal.c linux-2.6.32.46/kernel/signal.c
69914 --- linux-2.6.32.46/kernel/signal.c 2011-04-17 17:00:52.000000000 -0400
69915 +++ linux-2.6.32.46/kernel/signal.c 2011-08-16 21:15:58.000000000 -0400
69916 @@ -41,12 +41,12 @@
69917
69918 static struct kmem_cache *sigqueue_cachep;
69919
69920 -static void __user *sig_handler(struct task_struct *t, int sig)
69921 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69922 {
69923 return t->sighand->action[sig - 1].sa.sa_handler;
69924 }
69925
69926 -static int sig_handler_ignored(void __user *handler, int sig)
69927 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69928 {
69929 /* Is it explicitly or implicitly ignored? */
69930 return handler == SIG_IGN ||
69931 @@ -56,7 +56,7 @@ static int sig_handler_ignored(void __us
69932 static int sig_task_ignored(struct task_struct *t, int sig,
69933 int from_ancestor_ns)
69934 {
69935 - void __user *handler;
69936 + __sighandler_t handler;
69937
69938 handler = sig_handler(t, sig);
69939
69940 @@ -207,6 +207,9 @@ static struct sigqueue *__sigqueue_alloc
69941 */
69942 user = get_uid(__task_cred(t)->user);
69943 atomic_inc(&user->sigpending);
69944 +
69945 + if (!override_rlimit)
69946 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69947 if (override_rlimit ||
69948 atomic_read(&user->sigpending) <=
69949 t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
69950 @@ -327,7 +330,7 @@ flush_signal_handlers(struct task_struct
69951
69952 int unhandled_signal(struct task_struct *tsk, int sig)
69953 {
69954 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69955 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69956 if (is_global_init(tsk))
69957 return 1;
69958 if (handler != SIG_IGN && handler != SIG_DFL)
69959 @@ -627,6 +630,13 @@ static int check_kill_permission(int sig
69960 }
69961 }
69962
69963 + /* allow glibc communication via tgkill to other threads in our
69964 + thread group */
69965 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69966 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69967 + && gr_handle_signal(t, sig))
69968 + return -EPERM;
69969 +
69970 return security_task_kill(t, info, sig, 0);
69971 }
69972
69973 @@ -968,7 +978,7 @@ __group_send_sig_info(int sig, struct si
69974 return send_signal(sig, info, p, 1);
69975 }
69976
69977 -static int
69978 +int
69979 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69980 {
69981 return send_signal(sig, info, t, 0);
69982 @@ -1005,6 +1015,7 @@ force_sig_info(int sig, struct siginfo *
69983 unsigned long int flags;
69984 int ret, blocked, ignored;
69985 struct k_sigaction *action;
69986 + int is_unhandled = 0;
69987
69988 spin_lock_irqsave(&t->sighand->siglock, flags);
69989 action = &t->sighand->action[sig-1];
69990 @@ -1019,9 +1030,18 @@ force_sig_info(int sig, struct siginfo *
69991 }
69992 if (action->sa.sa_handler == SIG_DFL)
69993 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69994 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69995 + is_unhandled = 1;
69996 ret = specific_send_sig_info(sig, info, t);
69997 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69998
69999 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70000 + normal operation */
70001 + if (is_unhandled) {
70002 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70003 + gr_handle_crash(t, sig);
70004 + }
70005 +
70006 return ret;
70007 }
70008
70009 @@ -1081,8 +1101,11 @@ int group_send_sig_info(int sig, struct
70010 {
70011 int ret = check_kill_permission(sig, info, p);
70012
70013 - if (!ret && sig)
70014 + if (!ret && sig) {
70015 ret = do_send_sig_info(sig, info, p, true);
70016 + if (!ret)
70017 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70018 + }
70019
70020 return ret;
70021 }
70022 @@ -1644,6 +1667,8 @@ void ptrace_notify(int exit_code)
70023 {
70024 siginfo_t info;
70025
70026 + pax_track_stack();
70027 +
70028 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
70029
70030 memset(&info, 0, sizeof info);
70031 @@ -2275,7 +2300,15 @@ do_send_specific(pid_t tgid, pid_t pid,
70032 int error = -ESRCH;
70033
70034 rcu_read_lock();
70035 - p = find_task_by_vpid(pid);
70036 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70037 + /* allow glibc communication via tgkill to other threads in our
70038 + thread group */
70039 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70040 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70041 + p = find_task_by_vpid_unrestricted(pid);
70042 + else
70043 +#endif
70044 + p = find_task_by_vpid(pid);
70045 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70046 error = check_kill_permission(sig, info, p);
70047 /*
70048 diff -urNp linux-2.6.32.46/kernel/smp.c linux-2.6.32.46/kernel/smp.c
70049 --- linux-2.6.32.46/kernel/smp.c 2011-03-27 14:31:47.000000000 -0400
70050 +++ linux-2.6.32.46/kernel/smp.c 2011-04-17 15:56:46.000000000 -0400
70051 @@ -522,22 +522,22 @@ int smp_call_function(void (*func)(void
70052 }
70053 EXPORT_SYMBOL(smp_call_function);
70054
70055 -void ipi_call_lock(void)
70056 +void ipi_call_lock(void) __acquires(call_function.lock)
70057 {
70058 spin_lock(&call_function.lock);
70059 }
70060
70061 -void ipi_call_unlock(void)
70062 +void ipi_call_unlock(void) __releases(call_function.lock)
70063 {
70064 spin_unlock(&call_function.lock);
70065 }
70066
70067 -void ipi_call_lock_irq(void)
70068 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
70069 {
70070 spin_lock_irq(&call_function.lock);
70071 }
70072
70073 -void ipi_call_unlock_irq(void)
70074 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
70075 {
70076 spin_unlock_irq(&call_function.lock);
70077 }
70078 diff -urNp linux-2.6.32.46/kernel/softirq.c linux-2.6.32.46/kernel/softirq.c
70079 --- linux-2.6.32.46/kernel/softirq.c 2011-03-27 14:31:47.000000000 -0400
70080 +++ linux-2.6.32.46/kernel/softirq.c 2011-08-05 20:33:55.000000000 -0400
70081 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
70082
70083 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70084
70085 -char *softirq_to_name[NR_SOFTIRQS] = {
70086 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70087 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70088 "TASKLET", "SCHED", "HRTIMER", "RCU"
70089 };
70090 @@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
70091
70092 asmlinkage void __do_softirq(void)
70093 {
70094 - struct softirq_action *h;
70095 + const struct softirq_action *h;
70096 __u32 pending;
70097 int max_restart = MAX_SOFTIRQ_RESTART;
70098 int cpu;
70099 @@ -233,7 +233,7 @@ restart:
70100 kstat_incr_softirqs_this_cpu(h - softirq_vec);
70101
70102 trace_softirq_entry(h, softirq_vec);
70103 - h->action(h);
70104 + h->action();
70105 trace_softirq_exit(h, softirq_vec);
70106 if (unlikely(prev_count != preempt_count())) {
70107 printk(KERN_ERR "huh, entered softirq %td %s %p"
70108 @@ -363,9 +363,11 @@ void raise_softirq(unsigned int nr)
70109 local_irq_restore(flags);
70110 }
70111
70112 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70113 +void open_softirq(int nr, void (*action)(void))
70114 {
70115 - softirq_vec[nr].action = action;
70116 + pax_open_kernel();
70117 + *(void **)&softirq_vec[nr].action = action;
70118 + pax_close_kernel();
70119 }
70120
70121 /*
70122 @@ -419,7 +421,7 @@ void __tasklet_hi_schedule_first(struct
70123
70124 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70125
70126 -static void tasklet_action(struct softirq_action *a)
70127 +static void tasklet_action(void)
70128 {
70129 struct tasklet_struct *list;
70130
70131 @@ -454,7 +456,7 @@ static void tasklet_action(struct softir
70132 }
70133 }
70134
70135 -static void tasklet_hi_action(struct softirq_action *a)
70136 +static void tasklet_hi_action(void)
70137 {
70138 struct tasklet_struct *list;
70139
70140 diff -urNp linux-2.6.32.46/kernel/sys.c linux-2.6.32.46/kernel/sys.c
70141 --- linux-2.6.32.46/kernel/sys.c 2011-03-27 14:31:47.000000000 -0400
70142 +++ linux-2.6.32.46/kernel/sys.c 2011-08-11 19:51:54.000000000 -0400
70143 @@ -133,6 +133,12 @@ static int set_one_prio(struct task_stru
70144 error = -EACCES;
70145 goto out;
70146 }
70147 +
70148 + if (gr_handle_chroot_setpriority(p, niceval)) {
70149 + error = -EACCES;
70150 + goto out;
70151 + }
70152 +
70153 no_nice = security_task_setnice(p, niceval);
70154 if (no_nice) {
70155 error = no_nice;
70156 @@ -190,10 +196,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
70157 !(user = find_user(who)))
70158 goto out_unlock; /* No processes for this user */
70159
70160 - do_each_thread(g, p)
70161 + do_each_thread(g, p) {
70162 if (__task_cred(p)->uid == who)
70163 error = set_one_prio(p, niceval, error);
70164 - while_each_thread(g, p);
70165 + } while_each_thread(g, p);
70166 if (who != cred->uid)
70167 free_uid(user); /* For find_user() */
70168 break;
70169 @@ -253,13 +259,13 @@ SYSCALL_DEFINE2(getpriority, int, which,
70170 !(user = find_user(who)))
70171 goto out_unlock; /* No processes for this user */
70172
70173 - do_each_thread(g, p)
70174 + do_each_thread(g, p) {
70175 if (__task_cred(p)->uid == who) {
70176 niceval = 20 - task_nice(p);
70177 if (niceval > retval)
70178 retval = niceval;
70179 }
70180 - while_each_thread(g, p);
70181 + } while_each_thread(g, p);
70182 if (who != cred->uid)
70183 free_uid(user); /* for find_user() */
70184 break;
70185 @@ -509,6 +515,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
70186 goto error;
70187 }
70188
70189 + if (gr_check_group_change(new->gid, new->egid, -1))
70190 + goto error;
70191 +
70192 if (rgid != (gid_t) -1 ||
70193 (egid != (gid_t) -1 && egid != old->gid))
70194 new->sgid = new->egid;
70195 @@ -542,6 +551,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70196 goto error;
70197
70198 retval = -EPERM;
70199 +
70200 + if (gr_check_group_change(gid, gid, gid))
70201 + goto error;
70202 +
70203 if (capable(CAP_SETGID))
70204 new->gid = new->egid = new->sgid = new->fsgid = gid;
70205 else if (gid == old->gid || gid == old->sgid)
70206 @@ -567,12 +580,19 @@ static int set_user(struct cred *new)
70207 if (!new_user)
70208 return -EAGAIN;
70209
70210 + /*
70211 + * We don't fail in case of NPROC limit excess here because too many
70212 + * poorly written programs don't check set*uid() return code, assuming
70213 + * it never fails if called by root. We may still enforce NPROC limit
70214 + * for programs doing set*uid()+execve() by harmlessly deferring the
70215 + * failure to the execve() stage.
70216 + */
70217 if (atomic_read(&new_user->processes) >=
70218 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
70219 - new_user != INIT_USER) {
70220 - free_uid(new_user);
70221 - return -EAGAIN;
70222 - }
70223 + new_user != INIT_USER)
70224 + current->flags |= PF_NPROC_EXCEEDED;
70225 + else
70226 + current->flags &= ~PF_NPROC_EXCEEDED;
70227
70228 free_uid(new->user);
70229 new->user = new_user;
70230 @@ -627,6 +647,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
70231 goto error;
70232 }
70233
70234 + if (gr_check_user_change(new->uid, new->euid, -1))
70235 + goto error;
70236 +
70237 if (new->uid != old->uid) {
70238 retval = set_user(new);
70239 if (retval < 0)
70240 @@ -675,6 +698,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70241 goto error;
70242
70243 retval = -EPERM;
70244 +
70245 + if (gr_check_crash_uid(uid))
70246 + goto error;
70247 + if (gr_check_user_change(uid, uid, uid))
70248 + goto error;
70249 +
70250 if (capable(CAP_SETUID)) {
70251 new->suid = new->uid = uid;
70252 if (uid != old->uid) {
70253 @@ -732,6 +761,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
70254 goto error;
70255 }
70256
70257 + if (gr_check_user_change(ruid, euid, -1))
70258 + goto error;
70259 +
70260 if (ruid != (uid_t) -1) {
70261 new->uid = ruid;
70262 if (ruid != old->uid) {
70263 @@ -800,6 +832,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
70264 goto error;
70265 }
70266
70267 + if (gr_check_group_change(rgid, egid, -1))
70268 + goto error;
70269 +
70270 if (rgid != (gid_t) -1)
70271 new->gid = rgid;
70272 if (egid != (gid_t) -1)
70273 @@ -849,6 +884,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70274 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
70275 goto error;
70276
70277 + if (gr_check_user_change(-1, -1, uid))
70278 + goto error;
70279 +
70280 if (uid == old->uid || uid == old->euid ||
70281 uid == old->suid || uid == old->fsuid ||
70282 capable(CAP_SETUID)) {
70283 @@ -889,6 +927,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70284 if (gid == old->gid || gid == old->egid ||
70285 gid == old->sgid || gid == old->fsgid ||
70286 capable(CAP_SETGID)) {
70287 + if (gr_check_group_change(-1, -1, gid))
70288 + goto error;
70289 +
70290 if (gid != old_fsgid) {
70291 new->fsgid = gid;
70292 goto change_okay;
70293 @@ -1454,7 +1495,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
70294 error = get_dumpable(me->mm);
70295 break;
70296 case PR_SET_DUMPABLE:
70297 - if (arg2 < 0 || arg2 > 1) {
70298 + if (arg2 > 1) {
70299 error = -EINVAL;
70300 break;
70301 }
70302 diff -urNp linux-2.6.32.46/kernel/sysctl.c linux-2.6.32.46/kernel/sysctl.c
70303 --- linux-2.6.32.46/kernel/sysctl.c 2011-03-27 14:31:47.000000000 -0400
70304 +++ linux-2.6.32.46/kernel/sysctl.c 2011-04-17 15:56:46.000000000 -0400
70305 @@ -63,6 +63,13 @@
70306 static int deprecated_sysctl_warning(struct __sysctl_args *args);
70307
70308 #if defined(CONFIG_SYSCTL)
70309 +#include <linux/grsecurity.h>
70310 +#include <linux/grinternal.h>
70311 +
70312 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
70313 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
70314 + const int op);
70315 +extern int gr_handle_chroot_sysctl(const int op);
70316
70317 /* External variables not in a header file. */
70318 extern int C_A_D;
70319 @@ -168,6 +175,7 @@ static int proc_do_cad_pid(struct ctl_ta
70320 static int proc_taint(struct ctl_table *table, int write,
70321 void __user *buffer, size_t *lenp, loff_t *ppos);
70322 #endif
70323 +extern ctl_table grsecurity_table[];
70324
70325 static struct ctl_table root_table[];
70326 static struct ctl_table_root sysctl_table_root;
70327 @@ -200,6 +208,21 @@ extern struct ctl_table epoll_table[];
70328 int sysctl_legacy_va_layout;
70329 #endif
70330
70331 +#ifdef CONFIG_PAX_SOFTMODE
70332 +static ctl_table pax_table[] = {
70333 + {
70334 + .ctl_name = CTL_UNNUMBERED,
70335 + .procname = "softmode",
70336 + .data = &pax_softmode,
70337 + .maxlen = sizeof(unsigned int),
70338 + .mode = 0600,
70339 + .proc_handler = &proc_dointvec,
70340 + },
70341 +
70342 + { .ctl_name = 0 }
70343 +};
70344 +#endif
70345 +
70346 extern int prove_locking;
70347 extern int lock_stat;
70348
70349 @@ -251,6 +274,24 @@ static int max_wakeup_granularity_ns = N
70350 #endif
70351
70352 static struct ctl_table kern_table[] = {
70353 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70354 + {
70355 + .ctl_name = CTL_UNNUMBERED,
70356 + .procname = "grsecurity",
70357 + .mode = 0500,
70358 + .child = grsecurity_table,
70359 + },
70360 +#endif
70361 +
70362 +#ifdef CONFIG_PAX_SOFTMODE
70363 + {
70364 + .ctl_name = CTL_UNNUMBERED,
70365 + .procname = "pax",
70366 + .mode = 0500,
70367 + .child = pax_table,
70368 + },
70369 +#endif
70370 +
70371 {
70372 .ctl_name = CTL_UNNUMBERED,
70373 .procname = "sched_child_runs_first",
70374 @@ -567,8 +608,8 @@ static struct ctl_table kern_table[] = {
70375 .data = &modprobe_path,
70376 .maxlen = KMOD_PATH_LEN,
70377 .mode = 0644,
70378 - .proc_handler = &proc_dostring,
70379 - .strategy = &sysctl_string,
70380 + .proc_handler = &proc_dostring_modpriv,
70381 + .strategy = &sysctl_string_modpriv,
70382 },
70383 {
70384 .ctl_name = CTL_UNNUMBERED,
70385 @@ -1247,6 +1288,13 @@ static struct ctl_table vm_table[] = {
70386 .mode = 0644,
70387 .proc_handler = &proc_dointvec
70388 },
70389 + {
70390 + .procname = "heap_stack_gap",
70391 + .data = &sysctl_heap_stack_gap,
70392 + .maxlen = sizeof(sysctl_heap_stack_gap),
70393 + .mode = 0644,
70394 + .proc_handler = proc_doulongvec_minmax,
70395 + },
70396 #else
70397 {
70398 .ctl_name = CTL_UNNUMBERED,
70399 @@ -1803,6 +1851,8 @@ static int do_sysctl_strategy(struct ctl
70400 return 0;
70401 }
70402
70403 +static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
70404 +
70405 static int parse_table(int __user *name, int nlen,
70406 void __user *oldval, size_t __user *oldlenp,
70407 void __user *newval, size_t newlen,
70408 @@ -1821,7 +1871,7 @@ repeat:
70409 if (n == table->ctl_name) {
70410 int error;
70411 if (table->child) {
70412 - if (sysctl_perm(root, table, MAY_EXEC))
70413 + if (sysctl_perm_nochk(root, table, MAY_EXEC))
70414 return -EPERM;
70415 name++;
70416 nlen--;
70417 @@ -1906,6 +1956,33 @@ int sysctl_perm(struct ctl_table_root *r
70418 int error;
70419 int mode;
70420
70421 + if (table->parent != NULL && table->parent->procname != NULL &&
70422 + table->procname != NULL &&
70423 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
70424 + return -EACCES;
70425 + if (gr_handle_chroot_sysctl(op))
70426 + return -EACCES;
70427 + error = gr_handle_sysctl(table, op);
70428 + if (error)
70429 + return error;
70430 +
70431 + error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
70432 + if (error)
70433 + return error;
70434 +
70435 + if (root->permissions)
70436 + mode = root->permissions(root, current->nsproxy, table);
70437 + else
70438 + mode = table->mode;
70439 +
70440 + return test_perm(mode, op);
70441 +}
70442 +
70443 +int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
70444 +{
70445 + int error;
70446 + int mode;
70447 +
70448 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
70449 if (error)
70450 return error;
70451 @@ -2335,6 +2412,16 @@ int proc_dostring(struct ctl_table *tabl
70452 buffer, lenp, ppos);
70453 }
70454
70455 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70456 + void __user *buffer, size_t *lenp, loff_t *ppos)
70457 +{
70458 + if (write && !capable(CAP_SYS_MODULE))
70459 + return -EPERM;
70460 +
70461 + return _proc_do_string(table->data, table->maxlen, write,
70462 + buffer, lenp, ppos);
70463 +}
70464 +
70465
70466 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
70467 int *valp,
70468 @@ -2609,7 +2696,7 @@ static int __do_proc_doulongvec_minmax(v
70469 vleft = table->maxlen / sizeof(unsigned long);
70470 left = *lenp;
70471
70472 - for (; left && vleft--; i++, min++, max++, first=0) {
70473 + for (; left && vleft--; i++, first=0) {
70474 if (write) {
70475 while (left) {
70476 char c;
70477 @@ -2910,6 +2997,12 @@ int proc_dostring(struct ctl_table *tabl
70478 return -ENOSYS;
70479 }
70480
70481 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70482 + void __user *buffer, size_t *lenp, loff_t *ppos)
70483 +{
70484 + return -ENOSYS;
70485 +}
70486 +
70487 int proc_dointvec(struct ctl_table *table, int write,
70488 void __user *buffer, size_t *lenp, loff_t *ppos)
70489 {
70490 @@ -3038,6 +3131,16 @@ int sysctl_string(struct ctl_table *tabl
70491 return 1;
70492 }
70493
70494 +int sysctl_string_modpriv(struct ctl_table *table,
70495 + void __user *oldval, size_t __user *oldlenp,
70496 + void __user *newval, size_t newlen)
70497 +{
70498 + if (newval && newlen && !capable(CAP_SYS_MODULE))
70499 + return -EPERM;
70500 +
70501 + return sysctl_string(table, oldval, oldlenp, newval, newlen);
70502 +}
70503 +
70504 /*
70505 * This function makes sure that all of the integers in the vector
70506 * are between the minimum and maximum values given in the arrays
70507 @@ -3182,6 +3285,13 @@ int sysctl_string(struct ctl_table *tabl
70508 return -ENOSYS;
70509 }
70510
70511 +int sysctl_string_modpriv(struct ctl_table *table,
70512 + void __user *oldval, size_t __user *oldlenp,
70513 + void __user *newval, size_t newlen)
70514 +{
70515 + return -ENOSYS;
70516 +}
70517 +
70518 int sysctl_intvec(struct ctl_table *table,
70519 void __user *oldval, size_t __user *oldlenp,
70520 void __user *newval, size_t newlen)
70521 @@ -3246,6 +3356,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70522 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70523 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70524 EXPORT_SYMBOL(proc_dostring);
70525 +EXPORT_SYMBOL(proc_dostring_modpriv);
70526 EXPORT_SYMBOL(proc_doulongvec_minmax);
70527 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70528 EXPORT_SYMBOL(register_sysctl_table);
70529 @@ -3254,5 +3365,6 @@ EXPORT_SYMBOL(sysctl_intvec);
70530 EXPORT_SYMBOL(sysctl_jiffies);
70531 EXPORT_SYMBOL(sysctl_ms_jiffies);
70532 EXPORT_SYMBOL(sysctl_string);
70533 +EXPORT_SYMBOL(sysctl_string_modpriv);
70534 EXPORT_SYMBOL(sysctl_data);
70535 EXPORT_SYMBOL(unregister_sysctl_table);
70536 diff -urNp linux-2.6.32.46/kernel/sysctl_check.c linux-2.6.32.46/kernel/sysctl_check.c
70537 --- linux-2.6.32.46/kernel/sysctl_check.c 2011-03-27 14:31:47.000000000 -0400
70538 +++ linux-2.6.32.46/kernel/sysctl_check.c 2011-04-17 15:56:46.000000000 -0400
70539 @@ -1489,10 +1489,12 @@ int sysctl_check_table(struct nsproxy *n
70540 } else {
70541 if ((table->strategy == sysctl_data) ||
70542 (table->strategy == sysctl_string) ||
70543 + (table->strategy == sysctl_string_modpriv) ||
70544 (table->strategy == sysctl_intvec) ||
70545 (table->strategy == sysctl_jiffies) ||
70546 (table->strategy == sysctl_ms_jiffies) ||
70547 (table->proc_handler == proc_dostring) ||
70548 + (table->proc_handler == proc_dostring_modpriv) ||
70549 (table->proc_handler == proc_dointvec) ||
70550 (table->proc_handler == proc_dointvec_minmax) ||
70551 (table->proc_handler == proc_dointvec_jiffies) ||
70552 diff -urNp linux-2.6.32.46/kernel/taskstats.c linux-2.6.32.46/kernel/taskstats.c
70553 --- linux-2.6.32.46/kernel/taskstats.c 2011-07-13 17:23:04.000000000 -0400
70554 +++ linux-2.6.32.46/kernel/taskstats.c 2011-07-13 17:23:19.000000000 -0400
70555 @@ -26,9 +26,12 @@
70556 #include <linux/cgroup.h>
70557 #include <linux/fs.h>
70558 #include <linux/file.h>
70559 +#include <linux/grsecurity.h>
70560 #include <net/genetlink.h>
70561 #include <asm/atomic.h>
70562
70563 +extern int gr_is_taskstats_denied(int pid);
70564 +
70565 /*
70566 * Maximum length of a cpumask that can be specified in
70567 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70568 @@ -442,6 +445,9 @@ static int taskstats_user_cmd(struct sk_
70569 size_t size;
70570 cpumask_var_t mask;
70571
70572 + if (gr_is_taskstats_denied(current->pid))
70573 + return -EACCES;
70574 +
70575 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
70576 return -ENOMEM;
70577
70578 diff -urNp linux-2.6.32.46/kernel/time/tick-broadcast.c linux-2.6.32.46/kernel/time/tick-broadcast.c
70579 --- linux-2.6.32.46/kernel/time/tick-broadcast.c 2011-05-23 16:56:59.000000000 -0400
70580 +++ linux-2.6.32.46/kernel/time/tick-broadcast.c 2011-05-23 16:57:13.000000000 -0400
70581 @@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct cl
70582 * then clear the broadcast bit.
70583 */
70584 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70585 - int cpu = smp_processor_id();
70586 + cpu = smp_processor_id();
70587
70588 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70589 tick_broadcast_clear_oneshot(cpu);
70590 diff -urNp linux-2.6.32.46/kernel/time/timekeeping.c linux-2.6.32.46/kernel/time/timekeeping.c
70591 --- linux-2.6.32.46/kernel/time/timekeeping.c 2011-06-25 12:55:35.000000000 -0400
70592 +++ linux-2.6.32.46/kernel/time/timekeeping.c 2011-06-25 12:56:37.000000000 -0400
70593 @@ -14,6 +14,7 @@
70594 #include <linux/init.h>
70595 #include <linux/mm.h>
70596 #include <linux/sched.h>
70597 +#include <linux/grsecurity.h>
70598 #include <linux/sysdev.h>
70599 #include <linux/clocksource.h>
70600 #include <linux/jiffies.h>
70601 @@ -180,7 +181,7 @@ void update_xtime_cache(u64 nsec)
70602 */
70603 struct timespec ts = xtime;
70604 timespec_add_ns(&ts, nsec);
70605 - ACCESS_ONCE(xtime_cache) = ts;
70606 + ACCESS_ONCE_RW(xtime_cache) = ts;
70607 }
70608
70609 /* must hold xtime_lock */
70610 @@ -333,6 +334,8 @@ int do_settimeofday(struct timespec *tv)
70611 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70612 return -EINVAL;
70613
70614 + gr_log_timechange();
70615 +
70616 write_seqlock_irqsave(&xtime_lock, flags);
70617
70618 timekeeping_forward_now();
70619 diff -urNp linux-2.6.32.46/kernel/time/timer_list.c linux-2.6.32.46/kernel/time/timer_list.c
70620 --- linux-2.6.32.46/kernel/time/timer_list.c 2011-03-27 14:31:47.000000000 -0400
70621 +++ linux-2.6.32.46/kernel/time/timer_list.c 2011-04-17 15:56:46.000000000 -0400
70622 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
70623
70624 static void print_name_offset(struct seq_file *m, void *sym)
70625 {
70626 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70627 + SEQ_printf(m, "<%p>", NULL);
70628 +#else
70629 char symname[KSYM_NAME_LEN];
70630
70631 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70632 SEQ_printf(m, "<%p>", sym);
70633 else
70634 SEQ_printf(m, "%s", symname);
70635 +#endif
70636 }
70637
70638 static void
70639 @@ -112,7 +116,11 @@ next_one:
70640 static void
70641 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70642 {
70643 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70644 + SEQ_printf(m, " .base: %p\n", NULL);
70645 +#else
70646 SEQ_printf(m, " .base: %p\n", base);
70647 +#endif
70648 SEQ_printf(m, " .index: %d\n",
70649 base->index);
70650 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70651 @@ -289,7 +297,11 @@ static int __init init_timer_list_procfs
70652 {
70653 struct proc_dir_entry *pe;
70654
70655 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70656 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70657 +#else
70658 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70659 +#endif
70660 if (!pe)
70661 return -ENOMEM;
70662 return 0;
70663 diff -urNp linux-2.6.32.46/kernel/time/timer_stats.c linux-2.6.32.46/kernel/time/timer_stats.c
70664 --- linux-2.6.32.46/kernel/time/timer_stats.c 2011-03-27 14:31:47.000000000 -0400
70665 +++ linux-2.6.32.46/kernel/time/timer_stats.c 2011-05-04 17:56:28.000000000 -0400
70666 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70667 static unsigned long nr_entries;
70668 static struct entry entries[MAX_ENTRIES];
70669
70670 -static atomic_t overflow_count;
70671 +static atomic_unchecked_t overflow_count;
70672
70673 /*
70674 * The entries are in a hash-table, for fast lookup:
70675 @@ -140,7 +140,7 @@ static void reset_entries(void)
70676 nr_entries = 0;
70677 memset(entries, 0, sizeof(entries));
70678 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70679 - atomic_set(&overflow_count, 0);
70680 + atomic_set_unchecked(&overflow_count, 0);
70681 }
70682
70683 static struct entry *alloc_entry(void)
70684 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
70685 if (likely(entry))
70686 entry->count++;
70687 else
70688 - atomic_inc(&overflow_count);
70689 + atomic_inc_unchecked(&overflow_count);
70690
70691 out_unlock:
70692 spin_unlock_irqrestore(lock, flags);
70693 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
70694
70695 static void print_name_offset(struct seq_file *m, unsigned long addr)
70696 {
70697 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70698 + seq_printf(m, "<%p>", NULL);
70699 +#else
70700 char symname[KSYM_NAME_LEN];
70701
70702 if (lookup_symbol_name(addr, symname) < 0)
70703 seq_printf(m, "<%p>", (void *)addr);
70704 else
70705 seq_printf(m, "%s", symname);
70706 +#endif
70707 }
70708
70709 static int tstats_show(struct seq_file *m, void *v)
70710 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
70711
70712 seq_puts(m, "Timer Stats Version: v0.2\n");
70713 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70714 - if (atomic_read(&overflow_count))
70715 + if (atomic_read_unchecked(&overflow_count))
70716 seq_printf(m, "Overflow: %d entries\n",
70717 - atomic_read(&overflow_count));
70718 + atomic_read_unchecked(&overflow_count));
70719
70720 for (i = 0; i < nr_entries; i++) {
70721 entry = entries + i;
70722 @@ -415,7 +419,11 @@ static int __init init_tstats_procfs(voi
70723 {
70724 struct proc_dir_entry *pe;
70725
70726 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70727 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70728 +#else
70729 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70730 +#endif
70731 if (!pe)
70732 return -ENOMEM;
70733 return 0;
70734 diff -urNp linux-2.6.32.46/kernel/time.c linux-2.6.32.46/kernel/time.c
70735 --- linux-2.6.32.46/kernel/time.c 2011-03-27 14:31:47.000000000 -0400
70736 +++ linux-2.6.32.46/kernel/time.c 2011-04-17 15:56:46.000000000 -0400
70737 @@ -165,6 +165,11 @@ int do_sys_settimeofday(struct timespec
70738 return error;
70739
70740 if (tz) {
70741 + /* we log in do_settimeofday called below, so don't log twice
70742 + */
70743 + if (!tv)
70744 + gr_log_timechange();
70745 +
70746 /* SMP safe, global irq locking makes it work. */
70747 sys_tz = *tz;
70748 update_vsyscall_tz();
70749 @@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time);
70750 * Avoid unnecessary multiplications/divisions in the
70751 * two most common HZ cases:
70752 */
70753 -unsigned int inline jiffies_to_msecs(const unsigned long j)
70754 +inline unsigned int jiffies_to_msecs(const unsigned long j)
70755 {
70756 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
70757 return (MSEC_PER_SEC / HZ) * j;
70758 @@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(con
70759 }
70760 EXPORT_SYMBOL(jiffies_to_msecs);
70761
70762 -unsigned int inline jiffies_to_usecs(const unsigned long j)
70763 +inline unsigned int jiffies_to_usecs(const unsigned long j)
70764 {
70765 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
70766 return (USEC_PER_SEC / HZ) * j;
70767 diff -urNp linux-2.6.32.46/kernel/timer.c linux-2.6.32.46/kernel/timer.c
70768 --- linux-2.6.32.46/kernel/timer.c 2011-03-27 14:31:47.000000000 -0400
70769 +++ linux-2.6.32.46/kernel/timer.c 2011-04-17 15:56:46.000000000 -0400
70770 @@ -1213,7 +1213,7 @@ void update_process_times(int user_tick)
70771 /*
70772 * This function runs timers and the timer-tq in bottom half context.
70773 */
70774 -static void run_timer_softirq(struct softirq_action *h)
70775 +static void run_timer_softirq(void)
70776 {
70777 struct tvec_base *base = __get_cpu_var(tvec_bases);
70778
70779 diff -urNp linux-2.6.32.46/kernel/trace/blktrace.c linux-2.6.32.46/kernel/trace/blktrace.c
70780 --- linux-2.6.32.46/kernel/trace/blktrace.c 2011-03-27 14:31:47.000000000 -0400
70781 +++ linux-2.6.32.46/kernel/trace/blktrace.c 2011-05-04 17:56:28.000000000 -0400
70782 @@ -313,7 +313,7 @@ static ssize_t blk_dropped_read(struct f
70783 struct blk_trace *bt = filp->private_data;
70784 char buf[16];
70785
70786 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70787 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70788
70789 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70790 }
70791 @@ -376,7 +376,7 @@ static int blk_subbuf_start_callback(str
70792 return 1;
70793
70794 bt = buf->chan->private_data;
70795 - atomic_inc(&bt->dropped);
70796 + atomic_inc_unchecked(&bt->dropped);
70797 return 0;
70798 }
70799
70800 @@ -477,7 +477,7 @@ int do_blk_trace_setup(struct request_qu
70801
70802 bt->dir = dir;
70803 bt->dev = dev;
70804 - atomic_set(&bt->dropped, 0);
70805 + atomic_set_unchecked(&bt->dropped, 0);
70806
70807 ret = -EIO;
70808 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70809 diff -urNp linux-2.6.32.46/kernel/trace/ftrace.c linux-2.6.32.46/kernel/trace/ftrace.c
70810 --- linux-2.6.32.46/kernel/trace/ftrace.c 2011-06-25 12:55:35.000000000 -0400
70811 +++ linux-2.6.32.46/kernel/trace/ftrace.c 2011-06-25 12:56:37.000000000 -0400
70812 @@ -1100,13 +1100,18 @@ ftrace_code_disable(struct module *mod,
70813
70814 ip = rec->ip;
70815
70816 + ret = ftrace_arch_code_modify_prepare();
70817 + FTRACE_WARN_ON(ret);
70818 + if (ret)
70819 + return 0;
70820 +
70821 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70822 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70823 if (ret) {
70824 ftrace_bug(ret, ip);
70825 rec->flags |= FTRACE_FL_FAILED;
70826 - return 0;
70827 }
70828 - return 1;
70829 + return ret ? 0 : 1;
70830 }
70831
70832 /*
70833 diff -urNp linux-2.6.32.46/kernel/trace/ring_buffer.c linux-2.6.32.46/kernel/trace/ring_buffer.c
70834 --- linux-2.6.32.46/kernel/trace/ring_buffer.c 2011-03-27 14:31:47.000000000 -0400
70835 +++ linux-2.6.32.46/kernel/trace/ring_buffer.c 2011-04-17 15:56:46.000000000 -0400
70836 @@ -606,7 +606,7 @@ static struct list_head *rb_list_head(st
70837 * the reader page). But if the next page is a header page,
70838 * its flags will be non zero.
70839 */
70840 -static int inline
70841 +static inline int
70842 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
70843 struct buffer_page *page, struct list_head *list)
70844 {
70845 diff -urNp linux-2.6.32.46/kernel/trace/trace.c linux-2.6.32.46/kernel/trace/trace.c
70846 --- linux-2.6.32.46/kernel/trace/trace.c 2011-03-27 14:31:47.000000000 -0400
70847 +++ linux-2.6.32.46/kernel/trace/trace.c 2011-05-16 21:46:57.000000000 -0400
70848 @@ -3193,6 +3193,8 @@ static ssize_t tracing_splice_read_pipe(
70849 size_t rem;
70850 unsigned int i;
70851
70852 + pax_track_stack();
70853 +
70854 /* copy the tracer to avoid using a global lock all around */
70855 mutex_lock(&trace_types_lock);
70856 if (unlikely(old_tracer != current_trace && current_trace)) {
70857 @@ -3659,6 +3661,8 @@ tracing_buffers_splice_read(struct file
70858 int entries, size, i;
70859 size_t ret;
70860
70861 + pax_track_stack();
70862 +
70863 if (*ppos & (PAGE_SIZE - 1)) {
70864 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
70865 return -EINVAL;
70866 @@ -3816,10 +3820,9 @@ static const struct file_operations trac
70867 };
70868 #endif
70869
70870 -static struct dentry *d_tracer;
70871 -
70872 struct dentry *tracing_init_dentry(void)
70873 {
70874 + static struct dentry *d_tracer;
70875 static int once;
70876
70877 if (d_tracer)
70878 @@ -3839,10 +3842,9 @@ struct dentry *tracing_init_dentry(void)
70879 return d_tracer;
70880 }
70881
70882 -static struct dentry *d_percpu;
70883 -
70884 struct dentry *tracing_dentry_percpu(void)
70885 {
70886 + static struct dentry *d_percpu;
70887 static int once;
70888 struct dentry *d_tracer;
70889
70890 diff -urNp linux-2.6.32.46/kernel/trace/trace_events.c linux-2.6.32.46/kernel/trace/trace_events.c
70891 --- linux-2.6.32.46/kernel/trace/trace_events.c 2011-03-27 14:31:47.000000000 -0400
70892 +++ linux-2.6.32.46/kernel/trace/trace_events.c 2011-08-05 20:33:55.000000000 -0400
70893 @@ -951,13 +951,10 @@ static LIST_HEAD(ftrace_module_file_list
70894 * Modules must own their file_operations to keep up with
70895 * reference counting.
70896 */
70897 +
70898 struct ftrace_module_file_ops {
70899 struct list_head list;
70900 struct module *mod;
70901 - struct file_operations id;
70902 - struct file_operations enable;
70903 - struct file_operations format;
70904 - struct file_operations filter;
70905 };
70906
70907 static void remove_subsystem_dir(const char *name)
70908 @@ -1004,17 +1001,12 @@ trace_create_file_ops(struct module *mod
70909
70910 file_ops->mod = mod;
70911
70912 - file_ops->id = ftrace_event_id_fops;
70913 - file_ops->id.owner = mod;
70914 -
70915 - file_ops->enable = ftrace_enable_fops;
70916 - file_ops->enable.owner = mod;
70917 -
70918 - file_ops->filter = ftrace_event_filter_fops;
70919 - file_ops->filter.owner = mod;
70920 -
70921 - file_ops->format = ftrace_event_format_fops;
70922 - file_ops->format.owner = mod;
70923 + pax_open_kernel();
70924 + *(void **)&mod->trace_id.owner = mod;
70925 + *(void **)&mod->trace_enable.owner = mod;
70926 + *(void **)&mod->trace_filter.owner = mod;
70927 + *(void **)&mod->trace_format.owner = mod;
70928 + pax_close_kernel();
70929
70930 list_add(&file_ops->list, &ftrace_module_file_list);
70931
70932 @@ -1063,8 +1055,8 @@ static void trace_module_add_events(stru
70933 call->mod = mod;
70934 list_add(&call->list, &ftrace_events);
70935 event_create_dir(call, d_events,
70936 - &file_ops->id, &file_ops->enable,
70937 - &file_ops->filter, &file_ops->format);
70938 + &mod->trace_id, &mod->trace_enable,
70939 + &mod->trace_filter, &mod->trace_format);
70940 }
70941 }
70942
70943 diff -urNp linux-2.6.32.46/kernel/trace/trace_mmiotrace.c linux-2.6.32.46/kernel/trace/trace_mmiotrace.c
70944 --- linux-2.6.32.46/kernel/trace/trace_mmiotrace.c 2011-03-27 14:31:47.000000000 -0400
70945 +++ linux-2.6.32.46/kernel/trace/trace_mmiotrace.c 2011-05-04 17:56:28.000000000 -0400
70946 @@ -23,7 +23,7 @@ struct header_iter {
70947 static struct trace_array *mmio_trace_array;
70948 static bool overrun_detected;
70949 static unsigned long prev_overruns;
70950 -static atomic_t dropped_count;
70951 +static atomic_unchecked_t dropped_count;
70952
70953 static void mmio_reset_data(struct trace_array *tr)
70954 {
70955 @@ -126,7 +126,7 @@ static void mmio_close(struct trace_iter
70956
70957 static unsigned long count_overruns(struct trace_iterator *iter)
70958 {
70959 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70960 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70961 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70962
70963 if (over > prev_overruns)
70964 @@ -316,7 +316,7 @@ static void __trace_mmiotrace_rw(struct
70965 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70966 sizeof(*entry), 0, pc);
70967 if (!event) {
70968 - atomic_inc(&dropped_count);
70969 + atomic_inc_unchecked(&dropped_count);
70970 return;
70971 }
70972 entry = ring_buffer_event_data(event);
70973 @@ -346,7 +346,7 @@ static void __trace_mmiotrace_map(struct
70974 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70975 sizeof(*entry), 0, pc);
70976 if (!event) {
70977 - atomic_inc(&dropped_count);
70978 + atomic_inc_unchecked(&dropped_count);
70979 return;
70980 }
70981 entry = ring_buffer_event_data(event);
70982 diff -urNp linux-2.6.32.46/kernel/trace/trace_output.c linux-2.6.32.46/kernel/trace/trace_output.c
70983 --- linux-2.6.32.46/kernel/trace/trace_output.c 2011-03-27 14:31:47.000000000 -0400
70984 +++ linux-2.6.32.46/kernel/trace/trace_output.c 2011-04-17 15:56:46.000000000 -0400
70985 @@ -237,7 +237,7 @@ int trace_seq_path(struct trace_seq *s,
70986 return 0;
70987 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70988 if (!IS_ERR(p)) {
70989 - p = mangle_path(s->buffer + s->len, p, "\n");
70990 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70991 if (p) {
70992 s->len = p - s->buffer;
70993 return 1;
70994 diff -urNp linux-2.6.32.46/kernel/trace/trace_stack.c linux-2.6.32.46/kernel/trace/trace_stack.c
70995 --- linux-2.6.32.46/kernel/trace/trace_stack.c 2011-03-27 14:31:47.000000000 -0400
70996 +++ linux-2.6.32.46/kernel/trace/trace_stack.c 2011-04-17 15:56:46.000000000 -0400
70997 @@ -50,7 +50,7 @@ static inline void check_stack(void)
70998 return;
70999
71000 /* we do not handle interrupt stacks yet */
71001 - if (!object_is_on_stack(&this_size))
71002 + if (!object_starts_on_stack(&this_size))
71003 return;
71004
71005 local_irq_save(flags);
71006 diff -urNp linux-2.6.32.46/kernel/trace/trace_workqueue.c linux-2.6.32.46/kernel/trace/trace_workqueue.c
71007 --- linux-2.6.32.46/kernel/trace/trace_workqueue.c 2011-03-27 14:31:47.000000000 -0400
71008 +++ linux-2.6.32.46/kernel/trace/trace_workqueue.c 2011-04-17 15:56:46.000000000 -0400
71009 @@ -21,7 +21,7 @@ struct cpu_workqueue_stats {
71010 int cpu;
71011 pid_t pid;
71012 /* Can be inserted from interrupt or user context, need to be atomic */
71013 - atomic_t inserted;
71014 + atomic_unchecked_t inserted;
71015 /*
71016 * Don't need to be atomic, works are serialized in a single workqueue thread
71017 * on a single CPU.
71018 @@ -58,7 +58,7 @@ probe_workqueue_insertion(struct task_st
71019 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
71020 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
71021 if (node->pid == wq_thread->pid) {
71022 - atomic_inc(&node->inserted);
71023 + atomic_inc_unchecked(&node->inserted);
71024 goto found;
71025 }
71026 }
71027 @@ -205,7 +205,7 @@ static int workqueue_stat_show(struct se
71028 tsk = get_pid_task(pid, PIDTYPE_PID);
71029 if (tsk) {
71030 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
71031 - atomic_read(&cws->inserted), cws->executed,
71032 + atomic_read_unchecked(&cws->inserted), cws->executed,
71033 tsk->comm);
71034 put_task_struct(tsk);
71035 }
71036 diff -urNp linux-2.6.32.46/kernel/user.c linux-2.6.32.46/kernel/user.c
71037 --- linux-2.6.32.46/kernel/user.c 2011-03-27 14:31:47.000000000 -0400
71038 +++ linux-2.6.32.46/kernel/user.c 2011-04-17 15:56:46.000000000 -0400
71039 @@ -159,6 +159,7 @@ struct user_struct *alloc_uid(struct use
71040 spin_lock_irq(&uidhash_lock);
71041 up = uid_hash_find(uid, hashent);
71042 if (up) {
71043 + put_user_ns(ns);
71044 key_put(new->uid_keyring);
71045 key_put(new->session_keyring);
71046 kmem_cache_free(uid_cachep, new);
71047 diff -urNp linux-2.6.32.46/lib/Kconfig.debug linux-2.6.32.46/lib/Kconfig.debug
71048 --- linux-2.6.32.46/lib/Kconfig.debug 2011-03-27 14:31:47.000000000 -0400
71049 +++ linux-2.6.32.46/lib/Kconfig.debug 2011-04-17 15:56:46.000000000 -0400
71050 @@ -905,7 +905,7 @@ config LATENCYTOP
71051 select STACKTRACE
71052 select SCHEDSTATS
71053 select SCHED_DEBUG
71054 - depends on HAVE_LATENCYTOP_SUPPORT
71055 + depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM
71056 help
71057 Enable this option if you want to use the LatencyTOP tool
71058 to find out which userspace is blocking on what kernel operations.
71059 diff -urNp linux-2.6.32.46/lib/bitmap.c linux-2.6.32.46/lib/bitmap.c
71060 --- linux-2.6.32.46/lib/bitmap.c 2011-03-27 14:31:47.000000000 -0400
71061 +++ linux-2.6.32.46/lib/bitmap.c 2011-10-06 09:37:14.000000000 -0400
71062 @@ -341,7 +341,7 @@ int __bitmap_parse(const char *buf, unsi
71063 {
71064 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71065 u32 chunk;
71066 - const char __user *ubuf = buf;
71067 + const char __user *ubuf = (const char __force_user *)buf;
71068
71069 bitmap_zero(maskp, nmaskbits);
71070
71071 @@ -426,7 +426,7 @@ int bitmap_parse_user(const char __user
71072 {
71073 if (!access_ok(VERIFY_READ, ubuf, ulen))
71074 return -EFAULT;
71075 - return __bitmap_parse((const char *)ubuf, ulen, 1, maskp, nmaskbits);
71076 + return __bitmap_parse((const char __force_kernel *)ubuf, ulen, 1, maskp, nmaskbits);
71077 }
71078 EXPORT_SYMBOL(bitmap_parse_user);
71079
71080 diff -urNp linux-2.6.32.46/lib/bug.c linux-2.6.32.46/lib/bug.c
71081 --- linux-2.6.32.46/lib/bug.c 2011-03-27 14:31:47.000000000 -0400
71082 +++ linux-2.6.32.46/lib/bug.c 2011-04-17 15:56:46.000000000 -0400
71083 @@ -135,6 +135,8 @@ enum bug_trap_type report_bug(unsigned l
71084 return BUG_TRAP_TYPE_NONE;
71085
71086 bug = find_bug(bugaddr);
71087 + if (!bug)
71088 + return BUG_TRAP_TYPE_NONE;
71089
71090 printk(KERN_EMERG "------------[ cut here ]------------\n");
71091
71092 diff -urNp linux-2.6.32.46/lib/debugobjects.c linux-2.6.32.46/lib/debugobjects.c
71093 --- linux-2.6.32.46/lib/debugobjects.c 2011-07-13 17:23:04.000000000 -0400
71094 +++ linux-2.6.32.46/lib/debugobjects.c 2011-07-13 17:23:19.000000000 -0400
71095 @@ -277,7 +277,7 @@ static void debug_object_is_on_stack(voi
71096 if (limit > 4)
71097 return;
71098
71099 - is_on_stack = object_is_on_stack(addr);
71100 + is_on_stack = object_starts_on_stack(addr);
71101 if (is_on_stack == onstack)
71102 return;
71103
71104 diff -urNp linux-2.6.32.46/lib/devres.c linux-2.6.32.46/lib/devres.c
71105 --- linux-2.6.32.46/lib/devres.c 2011-03-27 14:31:47.000000000 -0400
71106 +++ linux-2.6.32.46/lib/devres.c 2011-10-06 09:37:14.000000000 -0400
71107 @@ -80,7 +80,7 @@ void devm_iounmap(struct device *dev, vo
71108 {
71109 iounmap(addr);
71110 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71111 - (void *)addr));
71112 + (void __force *)addr));
71113 }
71114 EXPORT_SYMBOL(devm_iounmap);
71115
71116 @@ -140,7 +140,7 @@ void devm_ioport_unmap(struct device *de
71117 {
71118 ioport_unmap(addr);
71119 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71120 - devm_ioport_map_match, (void *)addr));
71121 + devm_ioport_map_match, (void __force *)addr));
71122 }
71123 EXPORT_SYMBOL(devm_ioport_unmap);
71124
71125 diff -urNp linux-2.6.32.46/lib/dma-debug.c linux-2.6.32.46/lib/dma-debug.c
71126 --- linux-2.6.32.46/lib/dma-debug.c 2011-03-27 14:31:47.000000000 -0400
71127 +++ linux-2.6.32.46/lib/dma-debug.c 2011-04-17 15:56:46.000000000 -0400
71128 @@ -861,7 +861,7 @@ out:
71129
71130 static void check_for_stack(struct device *dev, void *addr)
71131 {
71132 - if (object_is_on_stack(addr))
71133 + if (object_starts_on_stack(addr))
71134 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71135 "stack [addr=%p]\n", addr);
71136 }
71137 diff -urNp linux-2.6.32.46/lib/idr.c linux-2.6.32.46/lib/idr.c
71138 --- linux-2.6.32.46/lib/idr.c 2011-03-27 14:31:47.000000000 -0400
71139 +++ linux-2.6.32.46/lib/idr.c 2011-04-17 15:56:46.000000000 -0400
71140 @@ -156,7 +156,7 @@ static int sub_alloc(struct idr *idp, in
71141 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
71142
71143 /* if already at the top layer, we need to grow */
71144 - if (id >= 1 << (idp->layers * IDR_BITS)) {
71145 + if (id >= (1 << (idp->layers * IDR_BITS))) {
71146 *starting_id = id;
71147 return IDR_NEED_TO_GROW;
71148 }
71149 diff -urNp linux-2.6.32.46/lib/inflate.c linux-2.6.32.46/lib/inflate.c
71150 --- linux-2.6.32.46/lib/inflate.c 2011-03-27 14:31:47.000000000 -0400
71151 +++ linux-2.6.32.46/lib/inflate.c 2011-04-17 15:56:46.000000000 -0400
71152 @@ -266,7 +266,7 @@ static void free(void *where)
71153 malloc_ptr = free_mem_ptr;
71154 }
71155 #else
71156 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71157 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71158 #define free(a) kfree(a)
71159 #endif
71160
71161 diff -urNp linux-2.6.32.46/lib/kobject.c linux-2.6.32.46/lib/kobject.c
71162 --- linux-2.6.32.46/lib/kobject.c 2011-03-27 14:31:47.000000000 -0400
71163 +++ linux-2.6.32.46/lib/kobject.c 2011-04-17 15:56:46.000000000 -0400
71164 @@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct ko
71165 return ret;
71166 }
71167
71168 -struct sysfs_ops kobj_sysfs_ops = {
71169 +const struct sysfs_ops kobj_sysfs_ops = {
71170 .show = kobj_attr_show,
71171 .store = kobj_attr_store,
71172 };
71173 @@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
71174 * If the kset was not able to be created, NULL will be returned.
71175 */
71176 static struct kset *kset_create(const char *name,
71177 - struct kset_uevent_ops *uevent_ops,
71178 + const struct kset_uevent_ops *uevent_ops,
71179 struct kobject *parent_kobj)
71180 {
71181 struct kset *kset;
71182 @@ -832,7 +832,7 @@ static struct kset *kset_create(const ch
71183 * If the kset was not able to be created, NULL will be returned.
71184 */
71185 struct kset *kset_create_and_add(const char *name,
71186 - struct kset_uevent_ops *uevent_ops,
71187 + const struct kset_uevent_ops *uevent_ops,
71188 struct kobject *parent_kobj)
71189 {
71190 struct kset *kset;
71191 diff -urNp linux-2.6.32.46/lib/kobject_uevent.c linux-2.6.32.46/lib/kobject_uevent.c
71192 --- linux-2.6.32.46/lib/kobject_uevent.c 2011-03-27 14:31:47.000000000 -0400
71193 +++ linux-2.6.32.46/lib/kobject_uevent.c 2011-04-17 15:56:46.000000000 -0400
71194 @@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *k
71195 const char *subsystem;
71196 struct kobject *top_kobj;
71197 struct kset *kset;
71198 - struct kset_uevent_ops *uevent_ops;
71199 + const struct kset_uevent_ops *uevent_ops;
71200 u64 seq;
71201 int i = 0;
71202 int retval = 0;
71203 diff -urNp linux-2.6.32.46/lib/kref.c linux-2.6.32.46/lib/kref.c
71204 --- linux-2.6.32.46/lib/kref.c 2011-03-27 14:31:47.000000000 -0400
71205 +++ linux-2.6.32.46/lib/kref.c 2011-04-17 15:56:46.000000000 -0400
71206 @@ -61,7 +61,7 @@ void kref_get(struct kref *kref)
71207 */
71208 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
71209 {
71210 - WARN_ON(release == NULL);
71211 + BUG_ON(release == NULL);
71212 WARN_ON(release == (void (*)(struct kref *))kfree);
71213
71214 if (atomic_dec_and_test(&kref->refcount)) {
71215 diff -urNp linux-2.6.32.46/lib/parser.c linux-2.6.32.46/lib/parser.c
71216 --- linux-2.6.32.46/lib/parser.c 2011-03-27 14:31:47.000000000 -0400
71217 +++ linux-2.6.32.46/lib/parser.c 2011-04-17 15:56:46.000000000 -0400
71218 @@ -126,7 +126,7 @@ static int match_number(substring_t *s,
71219 char *buf;
71220 int ret;
71221
71222 - buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
71223 + buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL);
71224 if (!buf)
71225 return -ENOMEM;
71226 memcpy(buf, s->from, s->to - s->from);
71227 diff -urNp linux-2.6.32.46/lib/radix-tree.c linux-2.6.32.46/lib/radix-tree.c
71228 --- linux-2.6.32.46/lib/radix-tree.c 2011-03-27 14:31:47.000000000 -0400
71229 +++ linux-2.6.32.46/lib/radix-tree.c 2011-04-17 15:56:46.000000000 -0400
71230 @@ -81,7 +81,7 @@ struct radix_tree_preload {
71231 int nr;
71232 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
71233 };
71234 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71235 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71236
71237 static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
71238 {
71239 diff -urNp linux-2.6.32.46/lib/random32.c linux-2.6.32.46/lib/random32.c
71240 --- linux-2.6.32.46/lib/random32.c 2011-03-27 14:31:47.000000000 -0400
71241 +++ linux-2.6.32.46/lib/random32.c 2011-04-17 15:56:46.000000000 -0400
71242 @@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state *
71243 */
71244 static inline u32 __seed(u32 x, u32 m)
71245 {
71246 - return (x < m) ? x + m : x;
71247 + return (x <= m) ? x + m + 1 : x;
71248 }
71249
71250 /**
71251 diff -urNp linux-2.6.32.46/lib/vsprintf.c linux-2.6.32.46/lib/vsprintf.c
71252 --- linux-2.6.32.46/lib/vsprintf.c 2011-03-27 14:31:47.000000000 -0400
71253 +++ linux-2.6.32.46/lib/vsprintf.c 2011-04-17 15:56:46.000000000 -0400
71254 @@ -16,6 +16,9 @@
71255 * - scnprintf and vscnprintf
71256 */
71257
71258 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71259 +#define __INCLUDED_BY_HIDESYM 1
71260 +#endif
71261 #include <stdarg.h>
71262 #include <linux/module.h>
71263 #include <linux/types.h>
71264 @@ -546,12 +549,12 @@ static char *number(char *buf, char *end
71265 return buf;
71266 }
71267
71268 -static char *string(char *buf, char *end, char *s, struct printf_spec spec)
71269 +static char *string(char *buf, char *end, const char *s, struct printf_spec spec)
71270 {
71271 int len, i;
71272
71273 if ((unsigned long)s < PAGE_SIZE)
71274 - s = "<NULL>";
71275 + s = "(null)";
71276
71277 len = strnlen(s, spec.precision);
71278
71279 @@ -581,7 +584,7 @@ static char *symbol_string(char *buf, ch
71280 unsigned long value = (unsigned long) ptr;
71281 #ifdef CONFIG_KALLSYMS
71282 char sym[KSYM_SYMBOL_LEN];
71283 - if (ext != 'f' && ext != 's')
71284 + if (ext != 'f' && ext != 's' && ext != 'a')
71285 sprint_symbol(sym, value);
71286 else
71287 kallsyms_lookup(value, NULL, NULL, NULL, sym);
71288 @@ -801,6 +804,8 @@ static char *ip4_addr_string(char *buf,
71289 * - 'f' For simple symbolic function names without offset
71290 * - 'S' For symbolic direct pointers with offset
71291 * - 's' For symbolic direct pointers without offset
71292 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71293 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71294 * - 'R' For a struct resource pointer, it prints the range of
71295 * addresses (not the name nor the flags)
71296 * - 'M' For a 6-byte MAC address, it prints the address in the
71297 @@ -822,7 +827,7 @@ static char *pointer(const char *fmt, ch
71298 struct printf_spec spec)
71299 {
71300 if (!ptr)
71301 - return string(buf, end, "(null)", spec);
71302 + return string(buf, end, "(nil)", spec);
71303
71304 switch (*fmt) {
71305 case 'F':
71306 @@ -831,6 +836,14 @@ static char *pointer(const char *fmt, ch
71307 case 's':
71308 /* Fallthrough */
71309 case 'S':
71310 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71311 + break;
71312 +#else
71313 + return symbol_string(buf, end, ptr, spec, *fmt);
71314 +#endif
71315 + case 'a':
71316 + /* Fallthrough */
71317 + case 'A':
71318 return symbol_string(buf, end, ptr, spec, *fmt);
71319 case 'R':
71320 return resource_string(buf, end, ptr, spec);
71321 @@ -1445,7 +1458,7 @@ do { \
71322 size_t len;
71323 if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
71324 || (unsigned long)save_str < PAGE_SIZE)
71325 - save_str = "<NULL>";
71326 + save_str = "(null)";
71327 len = strlen(save_str);
71328 if (str + len + 1 < end)
71329 memcpy(str, save_str, len + 1);
71330 @@ -1555,11 +1568,11 @@ int bstr_printf(char *buf, size_t size,
71331 typeof(type) value; \
71332 if (sizeof(type) == 8) { \
71333 args = PTR_ALIGN(args, sizeof(u32)); \
71334 - *(u32 *)&value = *(u32 *)args; \
71335 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71336 + *(u32 *)&value = *(const u32 *)args; \
71337 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71338 } else { \
71339 args = PTR_ALIGN(args, sizeof(type)); \
71340 - value = *(typeof(type) *)args; \
71341 + value = *(const typeof(type) *)args; \
71342 } \
71343 args += sizeof(type); \
71344 value; \
71345 @@ -1622,7 +1635,7 @@ int bstr_printf(char *buf, size_t size,
71346 const char *str_arg = args;
71347 size_t len = strlen(str_arg);
71348 args += len + 1;
71349 - str = string(str, end, (char *)str_arg, spec);
71350 + str = string(str, end, str_arg, spec);
71351 break;
71352 }
71353
71354 diff -urNp linux-2.6.32.46/localversion-grsec linux-2.6.32.46/localversion-grsec
71355 --- linux-2.6.32.46/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
71356 +++ linux-2.6.32.46/localversion-grsec 2011-04-17 15:56:46.000000000 -0400
71357 @@ -0,0 +1 @@
71358 +-grsec
71359 diff -urNp linux-2.6.32.46/mm/Kconfig linux-2.6.32.46/mm/Kconfig
71360 --- linux-2.6.32.46/mm/Kconfig 2011-03-27 14:31:47.000000000 -0400
71361 +++ linux-2.6.32.46/mm/Kconfig 2011-04-17 15:56:46.000000000 -0400
71362 @@ -228,7 +228,7 @@ config KSM
71363 config DEFAULT_MMAP_MIN_ADDR
71364 int "Low address space to protect from user allocation"
71365 depends on MMU
71366 - default 4096
71367 + default 65536
71368 help
71369 This is the portion of low virtual memory which should be protected
71370 from userspace allocation. Keeping a user from writing to low pages
71371 diff -urNp linux-2.6.32.46/mm/backing-dev.c linux-2.6.32.46/mm/backing-dev.c
71372 --- linux-2.6.32.46/mm/backing-dev.c 2011-03-27 14:31:47.000000000 -0400
71373 +++ linux-2.6.32.46/mm/backing-dev.c 2011-08-11 19:48:17.000000000 -0400
71374 @@ -272,7 +272,7 @@ static void bdi_task_init(struct backing
71375 list_add_tail_rcu(&wb->list, &bdi->wb_list);
71376 spin_unlock(&bdi->wb_lock);
71377
71378 - tsk->flags |= PF_FLUSHER | PF_SWAPWRITE;
71379 + tsk->flags |= PF_SWAPWRITE;
71380 set_freezable();
71381
71382 /*
71383 @@ -484,7 +484,7 @@ static void bdi_add_to_pending(struct rc
71384 * Add the default flusher task that gets created for any bdi
71385 * that has dirty data pending writeout
71386 */
71387 -void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
71388 +static void bdi_add_default_flusher_task(struct backing_dev_info *bdi)
71389 {
71390 if (!bdi_cap_writeback_dirty(bdi))
71391 return;
71392 diff -urNp linux-2.6.32.46/mm/filemap.c linux-2.6.32.46/mm/filemap.c
71393 --- linux-2.6.32.46/mm/filemap.c 2011-03-27 14:31:47.000000000 -0400
71394 +++ linux-2.6.32.46/mm/filemap.c 2011-04-17 15:56:46.000000000 -0400
71395 @@ -1631,7 +1631,7 @@ int generic_file_mmap(struct file * file
71396 struct address_space *mapping = file->f_mapping;
71397
71398 if (!mapping->a_ops->readpage)
71399 - return -ENOEXEC;
71400 + return -ENODEV;
71401 file_accessed(file);
71402 vma->vm_ops = &generic_file_vm_ops;
71403 vma->vm_flags |= VM_CAN_NONLINEAR;
71404 @@ -2027,6 +2027,7 @@ inline int generic_write_checks(struct f
71405 *pos = i_size_read(inode);
71406
71407 if (limit != RLIM_INFINITY) {
71408 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71409 if (*pos >= limit) {
71410 send_sig(SIGXFSZ, current, 0);
71411 return -EFBIG;
71412 diff -urNp linux-2.6.32.46/mm/fremap.c linux-2.6.32.46/mm/fremap.c
71413 --- linux-2.6.32.46/mm/fremap.c 2011-03-27 14:31:47.000000000 -0400
71414 +++ linux-2.6.32.46/mm/fremap.c 2011-04-17 15:56:46.000000000 -0400
71415 @@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71416 retry:
71417 vma = find_vma(mm, start);
71418
71419 +#ifdef CONFIG_PAX_SEGMEXEC
71420 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71421 + goto out;
71422 +#endif
71423 +
71424 /*
71425 * Make sure the vma is shared, that it supports prefaulting,
71426 * and that the remapped range is valid and fully within
71427 @@ -221,7 +226,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71428 /*
71429 * drop PG_Mlocked flag for over-mapped range
71430 */
71431 - unsigned int saved_flags = vma->vm_flags;
71432 + unsigned long saved_flags = vma->vm_flags;
71433 munlock_vma_pages_range(vma, start, start + size);
71434 vma->vm_flags = saved_flags;
71435 }
71436 diff -urNp linux-2.6.32.46/mm/highmem.c linux-2.6.32.46/mm/highmem.c
71437 --- linux-2.6.32.46/mm/highmem.c 2011-03-27 14:31:47.000000000 -0400
71438 +++ linux-2.6.32.46/mm/highmem.c 2011-04-17 15:56:46.000000000 -0400
71439 @@ -116,9 +116,10 @@ static void flush_all_zero_pkmaps(void)
71440 * So no dangers, even with speculative execution.
71441 */
71442 page = pte_page(pkmap_page_table[i]);
71443 + pax_open_kernel();
71444 pte_clear(&init_mm, (unsigned long)page_address(page),
71445 &pkmap_page_table[i]);
71446 -
71447 + pax_close_kernel();
71448 set_page_address(page, NULL);
71449 need_flush = 1;
71450 }
71451 @@ -177,9 +178,11 @@ start:
71452 }
71453 }
71454 vaddr = PKMAP_ADDR(last_pkmap_nr);
71455 +
71456 + pax_open_kernel();
71457 set_pte_at(&init_mm, vaddr,
71458 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71459 -
71460 + pax_close_kernel();
71461 pkmap_count[last_pkmap_nr] = 1;
71462 set_page_address(page, (void *)vaddr);
71463
71464 diff -urNp linux-2.6.32.46/mm/hugetlb.c linux-2.6.32.46/mm/hugetlb.c
71465 --- linux-2.6.32.46/mm/hugetlb.c 2011-07-13 17:23:04.000000000 -0400
71466 +++ linux-2.6.32.46/mm/hugetlb.c 2011-07-13 17:23:19.000000000 -0400
71467 @@ -1933,6 +1933,26 @@ static int unmap_ref_private(struct mm_s
71468 return 1;
71469 }
71470
71471 +#ifdef CONFIG_PAX_SEGMEXEC
71472 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71473 +{
71474 + struct mm_struct *mm = vma->vm_mm;
71475 + struct vm_area_struct *vma_m;
71476 + unsigned long address_m;
71477 + pte_t *ptep_m;
71478 +
71479 + vma_m = pax_find_mirror_vma(vma);
71480 + if (!vma_m)
71481 + return;
71482 +
71483 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71484 + address_m = address + SEGMEXEC_TASK_SIZE;
71485 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71486 + get_page(page_m);
71487 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71488 +}
71489 +#endif
71490 +
71491 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
71492 unsigned long address, pte_t *ptep, pte_t pte,
71493 struct page *pagecache_page)
71494 @@ -2004,6 +2024,11 @@ retry_avoidcopy:
71495 huge_ptep_clear_flush(vma, address, ptep);
71496 set_huge_pte_at(mm, address, ptep,
71497 make_huge_pte(vma, new_page, 1));
71498 +
71499 +#ifdef CONFIG_PAX_SEGMEXEC
71500 + pax_mirror_huge_pte(vma, address, new_page);
71501 +#endif
71502 +
71503 /* Make the old page be freed below */
71504 new_page = old_page;
71505 }
71506 @@ -2135,6 +2160,10 @@ retry:
71507 && (vma->vm_flags & VM_SHARED)));
71508 set_huge_pte_at(mm, address, ptep, new_pte);
71509
71510 +#ifdef CONFIG_PAX_SEGMEXEC
71511 + pax_mirror_huge_pte(vma, address, page);
71512 +#endif
71513 +
71514 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71515 /* Optimization, do the COW without a second fault */
71516 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71517 @@ -2163,6 +2192,28 @@ int hugetlb_fault(struct mm_struct *mm,
71518 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71519 struct hstate *h = hstate_vma(vma);
71520
71521 +#ifdef CONFIG_PAX_SEGMEXEC
71522 + struct vm_area_struct *vma_m;
71523 +
71524 + vma_m = pax_find_mirror_vma(vma);
71525 + if (vma_m) {
71526 + unsigned long address_m;
71527 +
71528 + if (vma->vm_start > vma_m->vm_start) {
71529 + address_m = address;
71530 + address -= SEGMEXEC_TASK_SIZE;
71531 + vma = vma_m;
71532 + h = hstate_vma(vma);
71533 + } else
71534 + address_m = address + SEGMEXEC_TASK_SIZE;
71535 +
71536 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71537 + return VM_FAULT_OOM;
71538 + address_m &= HPAGE_MASK;
71539 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71540 + }
71541 +#endif
71542 +
71543 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71544 if (!ptep)
71545 return VM_FAULT_OOM;
71546 diff -urNp linux-2.6.32.46/mm/internal.h linux-2.6.32.46/mm/internal.h
71547 --- linux-2.6.32.46/mm/internal.h 2011-03-27 14:31:47.000000000 -0400
71548 +++ linux-2.6.32.46/mm/internal.h 2011-07-09 09:13:08.000000000 -0400
71549 @@ -49,6 +49,7 @@ extern void putback_lru_page(struct page
71550 * in mm/page_alloc.c
71551 */
71552 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71553 +extern void free_compound_page(struct page *page);
71554 extern void prep_compound_page(struct page *page, unsigned long order);
71555
71556
71557 diff -urNp linux-2.6.32.46/mm/kmemleak.c linux-2.6.32.46/mm/kmemleak.c
71558 --- linux-2.6.32.46/mm/kmemleak.c 2011-06-25 12:55:35.000000000 -0400
71559 +++ linux-2.6.32.46/mm/kmemleak.c 2011-06-25 12:56:37.000000000 -0400
71560 @@ -358,7 +358,7 @@ static void print_unreferenced(struct se
71561
71562 for (i = 0; i < object->trace_len; i++) {
71563 void *ptr = (void *)object->trace[i];
71564 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71565 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71566 }
71567 }
71568
71569 diff -urNp linux-2.6.32.46/mm/maccess.c linux-2.6.32.46/mm/maccess.c
71570 --- linux-2.6.32.46/mm/maccess.c 2011-03-27 14:31:47.000000000 -0400
71571 +++ linux-2.6.32.46/mm/maccess.c 2011-10-06 09:37:14.000000000 -0400
71572 @@ -14,7 +14,7 @@
71573 * Safely read from address @src to the buffer at @dst. If a kernel fault
71574 * happens, handle that and return -EFAULT.
71575 */
71576 -long probe_kernel_read(void *dst, void *src, size_t size)
71577 +long probe_kernel_read(void *dst, const void *src, size_t size)
71578 {
71579 long ret;
71580 mm_segment_t old_fs = get_fs();
71581 @@ -22,7 +22,7 @@ long probe_kernel_read(void *dst, void *
71582 set_fs(KERNEL_DS);
71583 pagefault_disable();
71584 ret = __copy_from_user_inatomic(dst,
71585 - (__force const void __user *)src, size);
71586 + (const void __force_user *)src, size);
71587 pagefault_enable();
71588 set_fs(old_fs);
71589
71590 @@ -39,14 +39,14 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
71591 * Safely write to address @dst from the buffer at @src. If a kernel fault
71592 * happens, handle that and return -EFAULT.
71593 */
71594 -long notrace __weak probe_kernel_write(void *dst, void *src, size_t size)
71595 +long notrace __weak probe_kernel_write(void *dst, const void *src, size_t size)
71596 {
71597 long ret;
71598 mm_segment_t old_fs = get_fs();
71599
71600 set_fs(KERNEL_DS);
71601 pagefault_disable();
71602 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71603 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71604 pagefault_enable();
71605 set_fs(old_fs);
71606
71607 diff -urNp linux-2.6.32.46/mm/madvise.c linux-2.6.32.46/mm/madvise.c
71608 --- linux-2.6.32.46/mm/madvise.c 2011-03-27 14:31:47.000000000 -0400
71609 +++ linux-2.6.32.46/mm/madvise.c 2011-04-17 15:56:46.000000000 -0400
71610 @@ -44,6 +44,10 @@ static long madvise_behavior(struct vm_a
71611 pgoff_t pgoff;
71612 unsigned long new_flags = vma->vm_flags;
71613
71614 +#ifdef CONFIG_PAX_SEGMEXEC
71615 + struct vm_area_struct *vma_m;
71616 +#endif
71617 +
71618 switch (behavior) {
71619 case MADV_NORMAL:
71620 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71621 @@ -103,6 +107,13 @@ success:
71622 /*
71623 * vm_flags is protected by the mmap_sem held in write mode.
71624 */
71625 +
71626 +#ifdef CONFIG_PAX_SEGMEXEC
71627 + vma_m = pax_find_mirror_vma(vma);
71628 + if (vma_m)
71629 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71630 +#endif
71631 +
71632 vma->vm_flags = new_flags;
71633
71634 out:
71635 @@ -161,6 +172,11 @@ static long madvise_dontneed(struct vm_a
71636 struct vm_area_struct ** prev,
71637 unsigned long start, unsigned long end)
71638 {
71639 +
71640 +#ifdef CONFIG_PAX_SEGMEXEC
71641 + struct vm_area_struct *vma_m;
71642 +#endif
71643 +
71644 *prev = vma;
71645 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71646 return -EINVAL;
71647 @@ -173,6 +189,21 @@ static long madvise_dontneed(struct vm_a
71648 zap_page_range(vma, start, end - start, &details);
71649 } else
71650 zap_page_range(vma, start, end - start, NULL);
71651 +
71652 +#ifdef CONFIG_PAX_SEGMEXEC
71653 + vma_m = pax_find_mirror_vma(vma);
71654 + if (vma_m) {
71655 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71656 + struct zap_details details = {
71657 + .nonlinear_vma = vma_m,
71658 + .last_index = ULONG_MAX,
71659 + };
71660 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71661 + } else
71662 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71663 + }
71664 +#endif
71665 +
71666 return 0;
71667 }
71668
71669 @@ -359,6 +390,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
71670 if (end < start)
71671 goto out;
71672
71673 +#ifdef CONFIG_PAX_SEGMEXEC
71674 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71675 + if (end > SEGMEXEC_TASK_SIZE)
71676 + goto out;
71677 + } else
71678 +#endif
71679 +
71680 + if (end > TASK_SIZE)
71681 + goto out;
71682 +
71683 error = 0;
71684 if (end == start)
71685 goto out;
71686 diff -urNp linux-2.6.32.46/mm/memory-failure.c linux-2.6.32.46/mm/memory-failure.c
71687 --- linux-2.6.32.46/mm/memory-failure.c 2011-03-27 14:31:47.000000000 -0400
71688 +++ linux-2.6.32.46/mm/memory-failure.c 2011-10-06 09:37:14.000000000 -0400
71689 @@ -46,7 +46,7 @@ int sysctl_memory_failure_early_kill __r
71690
71691 int sysctl_memory_failure_recovery __read_mostly = 1;
71692
71693 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71694 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71695
71696 /*
71697 * Send all the processes who have the page mapped an ``action optional''
71698 @@ -64,7 +64,7 @@ static int kill_proc_ao(struct task_stru
71699 si.si_signo = SIGBUS;
71700 si.si_errno = 0;
71701 si.si_code = BUS_MCEERR_AO;
71702 - si.si_addr = (void *)addr;
71703 + si.si_addr = (void __user *)addr;
71704 #ifdef __ARCH_SI_TRAPNO
71705 si.si_trapno = trapno;
71706 #endif
71707 @@ -745,7 +745,7 @@ int __memory_failure(unsigned long pfn,
71708 return 0;
71709 }
71710
71711 - atomic_long_add(1, &mce_bad_pages);
71712 + atomic_long_add_unchecked(1, &mce_bad_pages);
71713
71714 /*
71715 * We need/can do nothing about count=0 pages.
71716 diff -urNp linux-2.6.32.46/mm/memory.c linux-2.6.32.46/mm/memory.c
71717 --- linux-2.6.32.46/mm/memory.c 2011-07-13 17:23:04.000000000 -0400
71718 +++ linux-2.6.32.46/mm/memory.c 2011-07-13 17:23:23.000000000 -0400
71719 @@ -187,8 +187,12 @@ static inline void free_pmd_range(struct
71720 return;
71721
71722 pmd = pmd_offset(pud, start);
71723 +
71724 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71725 pud_clear(pud);
71726 pmd_free_tlb(tlb, pmd, start);
71727 +#endif
71728 +
71729 }
71730
71731 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71732 @@ -219,9 +223,12 @@ static inline void free_pud_range(struct
71733 if (end - 1 > ceiling - 1)
71734 return;
71735
71736 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71737 pud = pud_offset(pgd, start);
71738 pgd_clear(pgd);
71739 pud_free_tlb(tlb, pud, start);
71740 +#endif
71741 +
71742 }
71743
71744 /*
71745 @@ -1251,10 +1258,10 @@ int __get_user_pages(struct task_struct
71746 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71747 i = 0;
71748
71749 - do {
71750 + while (nr_pages) {
71751 struct vm_area_struct *vma;
71752
71753 - vma = find_extend_vma(mm, start);
71754 + vma = find_vma(mm, start);
71755 if (!vma && in_gate_area(tsk, start)) {
71756 unsigned long pg = start & PAGE_MASK;
71757 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
71758 @@ -1306,7 +1313,7 @@ int __get_user_pages(struct task_struct
71759 continue;
71760 }
71761
71762 - if (!vma ||
71763 + if (!vma || start < vma->vm_start ||
71764 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71765 !(vm_flags & vma->vm_flags))
71766 return i ? : -EFAULT;
71767 @@ -1381,7 +1388,7 @@ int __get_user_pages(struct task_struct
71768 start += PAGE_SIZE;
71769 nr_pages--;
71770 } while (nr_pages && start < vma->vm_end);
71771 - } while (nr_pages);
71772 + }
71773 return i;
71774 }
71775
71776 @@ -1526,6 +1533,10 @@ static int insert_page(struct vm_area_st
71777 page_add_file_rmap(page);
71778 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71779
71780 +#ifdef CONFIG_PAX_SEGMEXEC
71781 + pax_mirror_file_pte(vma, addr, page, ptl);
71782 +#endif
71783 +
71784 retval = 0;
71785 pte_unmap_unlock(pte, ptl);
71786 return retval;
71787 @@ -1560,10 +1571,22 @@ out:
71788 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71789 struct page *page)
71790 {
71791 +
71792 +#ifdef CONFIG_PAX_SEGMEXEC
71793 + struct vm_area_struct *vma_m;
71794 +#endif
71795 +
71796 if (addr < vma->vm_start || addr >= vma->vm_end)
71797 return -EFAULT;
71798 if (!page_count(page))
71799 return -EINVAL;
71800 +
71801 +#ifdef CONFIG_PAX_SEGMEXEC
71802 + vma_m = pax_find_mirror_vma(vma);
71803 + if (vma_m)
71804 + vma_m->vm_flags |= VM_INSERTPAGE;
71805 +#endif
71806 +
71807 vma->vm_flags |= VM_INSERTPAGE;
71808 return insert_page(vma, addr, page, vma->vm_page_prot);
71809 }
71810 @@ -1649,6 +1672,7 @@ int vm_insert_mixed(struct vm_area_struc
71811 unsigned long pfn)
71812 {
71813 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71814 + BUG_ON(vma->vm_mirror);
71815
71816 if (addr < vma->vm_start || addr >= vma->vm_end)
71817 return -EFAULT;
71818 @@ -1977,6 +2001,186 @@ static inline void cow_user_page(struct
71819 copy_user_highpage(dst, src, va, vma);
71820 }
71821
71822 +#ifdef CONFIG_PAX_SEGMEXEC
71823 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71824 +{
71825 + struct mm_struct *mm = vma->vm_mm;
71826 + spinlock_t *ptl;
71827 + pte_t *pte, entry;
71828 +
71829 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71830 + entry = *pte;
71831 + if (!pte_present(entry)) {
71832 + if (!pte_none(entry)) {
71833 + BUG_ON(pte_file(entry));
71834 + free_swap_and_cache(pte_to_swp_entry(entry));
71835 + pte_clear_not_present_full(mm, address, pte, 0);
71836 + }
71837 + } else {
71838 + struct page *page;
71839 +
71840 + flush_cache_page(vma, address, pte_pfn(entry));
71841 + entry = ptep_clear_flush(vma, address, pte);
71842 + BUG_ON(pte_dirty(entry));
71843 + page = vm_normal_page(vma, address, entry);
71844 + if (page) {
71845 + update_hiwater_rss(mm);
71846 + if (PageAnon(page))
71847 + dec_mm_counter(mm, anon_rss);
71848 + else
71849 + dec_mm_counter(mm, file_rss);
71850 + page_remove_rmap(page);
71851 + page_cache_release(page);
71852 + }
71853 + }
71854 + pte_unmap_unlock(pte, ptl);
71855 +}
71856 +
71857 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71858 + *
71859 + * the ptl of the lower mapped page is held on entry and is not released on exit
71860 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71861 + */
71862 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71863 +{
71864 + struct mm_struct *mm = vma->vm_mm;
71865 + unsigned long address_m;
71866 + spinlock_t *ptl_m;
71867 + struct vm_area_struct *vma_m;
71868 + pmd_t *pmd_m;
71869 + pte_t *pte_m, entry_m;
71870 +
71871 + BUG_ON(!page_m || !PageAnon(page_m));
71872 +
71873 + vma_m = pax_find_mirror_vma(vma);
71874 + if (!vma_m)
71875 + return;
71876 +
71877 + BUG_ON(!PageLocked(page_m));
71878 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71879 + address_m = address + SEGMEXEC_TASK_SIZE;
71880 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71881 + pte_m = pte_offset_map_nested(pmd_m, address_m);
71882 + ptl_m = pte_lockptr(mm, pmd_m);
71883 + if (ptl != ptl_m) {
71884 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71885 + if (!pte_none(*pte_m))
71886 + goto out;
71887 + }
71888 +
71889 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71890 + page_cache_get(page_m);
71891 + page_add_anon_rmap(page_m, vma_m, address_m);
71892 + inc_mm_counter(mm, anon_rss);
71893 + set_pte_at(mm, address_m, pte_m, entry_m);
71894 + update_mmu_cache(vma_m, address_m, entry_m);
71895 +out:
71896 + if (ptl != ptl_m)
71897 + spin_unlock(ptl_m);
71898 + pte_unmap_nested(pte_m);
71899 + unlock_page(page_m);
71900 +}
71901 +
71902 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71903 +{
71904 + struct mm_struct *mm = vma->vm_mm;
71905 + unsigned long address_m;
71906 + spinlock_t *ptl_m;
71907 + struct vm_area_struct *vma_m;
71908 + pmd_t *pmd_m;
71909 + pte_t *pte_m, entry_m;
71910 +
71911 + BUG_ON(!page_m || PageAnon(page_m));
71912 +
71913 + vma_m = pax_find_mirror_vma(vma);
71914 + if (!vma_m)
71915 + return;
71916 +
71917 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71918 + address_m = address + SEGMEXEC_TASK_SIZE;
71919 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71920 + pte_m = pte_offset_map_nested(pmd_m, address_m);
71921 + ptl_m = pte_lockptr(mm, pmd_m);
71922 + if (ptl != ptl_m) {
71923 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71924 + if (!pte_none(*pte_m))
71925 + goto out;
71926 + }
71927 +
71928 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71929 + page_cache_get(page_m);
71930 + page_add_file_rmap(page_m);
71931 + inc_mm_counter(mm, file_rss);
71932 + set_pte_at(mm, address_m, pte_m, entry_m);
71933 + update_mmu_cache(vma_m, address_m, entry_m);
71934 +out:
71935 + if (ptl != ptl_m)
71936 + spin_unlock(ptl_m);
71937 + pte_unmap_nested(pte_m);
71938 +}
71939 +
71940 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71941 +{
71942 + struct mm_struct *mm = vma->vm_mm;
71943 + unsigned long address_m;
71944 + spinlock_t *ptl_m;
71945 + struct vm_area_struct *vma_m;
71946 + pmd_t *pmd_m;
71947 + pte_t *pte_m, entry_m;
71948 +
71949 + vma_m = pax_find_mirror_vma(vma);
71950 + if (!vma_m)
71951 + return;
71952 +
71953 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71954 + address_m = address + SEGMEXEC_TASK_SIZE;
71955 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71956 + pte_m = pte_offset_map_nested(pmd_m, address_m);
71957 + ptl_m = pte_lockptr(mm, pmd_m);
71958 + if (ptl != ptl_m) {
71959 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71960 + if (!pte_none(*pte_m))
71961 + goto out;
71962 + }
71963 +
71964 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71965 + set_pte_at(mm, address_m, pte_m, entry_m);
71966 +out:
71967 + if (ptl != ptl_m)
71968 + spin_unlock(ptl_m);
71969 + pte_unmap_nested(pte_m);
71970 +}
71971 +
71972 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71973 +{
71974 + struct page *page_m;
71975 + pte_t entry;
71976 +
71977 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71978 + goto out;
71979 +
71980 + entry = *pte;
71981 + page_m = vm_normal_page(vma, address, entry);
71982 + if (!page_m)
71983 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71984 + else if (PageAnon(page_m)) {
71985 + if (pax_find_mirror_vma(vma)) {
71986 + pte_unmap_unlock(pte, ptl);
71987 + lock_page(page_m);
71988 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71989 + if (pte_same(entry, *pte))
71990 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71991 + else
71992 + unlock_page(page_m);
71993 + }
71994 + } else
71995 + pax_mirror_file_pte(vma, address, page_m, ptl);
71996 +
71997 +out:
71998 + pte_unmap_unlock(pte, ptl);
71999 +}
72000 +#endif
72001 +
72002 /*
72003 * This routine handles present pages, when users try to write
72004 * to a shared page. It is done by copying the page to a new address
72005 @@ -2156,6 +2360,12 @@ gotten:
72006 */
72007 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72008 if (likely(pte_same(*page_table, orig_pte))) {
72009 +
72010 +#ifdef CONFIG_PAX_SEGMEXEC
72011 + if (pax_find_mirror_vma(vma))
72012 + BUG_ON(!trylock_page(new_page));
72013 +#endif
72014 +
72015 if (old_page) {
72016 if (!PageAnon(old_page)) {
72017 dec_mm_counter(mm, file_rss);
72018 @@ -2207,6 +2417,10 @@ gotten:
72019 page_remove_rmap(old_page);
72020 }
72021
72022 +#ifdef CONFIG_PAX_SEGMEXEC
72023 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72024 +#endif
72025 +
72026 /* Free the old page.. */
72027 new_page = old_page;
72028 ret |= VM_FAULT_WRITE;
72029 @@ -2606,6 +2820,11 @@ static int do_swap_page(struct mm_struct
72030 swap_free(entry);
72031 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72032 try_to_free_swap(page);
72033 +
72034 +#ifdef CONFIG_PAX_SEGMEXEC
72035 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72036 +#endif
72037 +
72038 unlock_page(page);
72039
72040 if (flags & FAULT_FLAG_WRITE) {
72041 @@ -2617,6 +2836,11 @@ static int do_swap_page(struct mm_struct
72042
72043 /* No need to invalidate - it was non-present before */
72044 update_mmu_cache(vma, address, pte);
72045 +
72046 +#ifdef CONFIG_PAX_SEGMEXEC
72047 + pax_mirror_anon_pte(vma, address, page, ptl);
72048 +#endif
72049 +
72050 unlock:
72051 pte_unmap_unlock(page_table, ptl);
72052 out:
72053 @@ -2632,40 +2856,6 @@ out_release:
72054 }
72055
72056 /*
72057 - * This is like a special single-page "expand_{down|up}wards()",
72058 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72059 - * doesn't hit another vma.
72060 - */
72061 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72062 -{
72063 - address &= PAGE_MASK;
72064 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72065 - struct vm_area_struct *prev = vma->vm_prev;
72066 -
72067 - /*
72068 - * Is there a mapping abutting this one below?
72069 - *
72070 - * That's only ok if it's the same stack mapping
72071 - * that has gotten split..
72072 - */
72073 - if (prev && prev->vm_end == address)
72074 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72075 -
72076 - expand_stack(vma, address - PAGE_SIZE);
72077 - }
72078 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72079 - struct vm_area_struct *next = vma->vm_next;
72080 -
72081 - /* As VM_GROWSDOWN but s/below/above/ */
72082 - if (next && next->vm_start == address + PAGE_SIZE)
72083 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72084 -
72085 - expand_upwards(vma, address + PAGE_SIZE);
72086 - }
72087 - return 0;
72088 -}
72089 -
72090 -/*
72091 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72092 * but allow concurrent faults), and pte mapped but not yet locked.
72093 * We return with mmap_sem still held, but pte unmapped and unlocked.
72094 @@ -2674,27 +2864,23 @@ static int do_anonymous_page(struct mm_s
72095 unsigned long address, pte_t *page_table, pmd_t *pmd,
72096 unsigned int flags)
72097 {
72098 - struct page *page;
72099 + struct page *page = NULL;
72100 spinlock_t *ptl;
72101 pte_t entry;
72102
72103 - pte_unmap(page_table);
72104 -
72105 - /* Check if we need to add a guard page to the stack */
72106 - if (check_stack_guard_page(vma, address) < 0)
72107 - return VM_FAULT_SIGBUS;
72108 -
72109 - /* Use the zero-page for reads */
72110 if (!(flags & FAULT_FLAG_WRITE)) {
72111 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72112 vma->vm_page_prot));
72113 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72114 + ptl = pte_lockptr(mm, pmd);
72115 + spin_lock(ptl);
72116 if (!pte_none(*page_table))
72117 goto unlock;
72118 goto setpte;
72119 }
72120
72121 /* Allocate our own private page. */
72122 + pte_unmap(page_table);
72123 +
72124 if (unlikely(anon_vma_prepare(vma)))
72125 goto oom;
72126 page = alloc_zeroed_user_highpage_movable(vma, address);
72127 @@ -2713,6 +2899,11 @@ static int do_anonymous_page(struct mm_s
72128 if (!pte_none(*page_table))
72129 goto release;
72130
72131 +#ifdef CONFIG_PAX_SEGMEXEC
72132 + if (pax_find_mirror_vma(vma))
72133 + BUG_ON(!trylock_page(page));
72134 +#endif
72135 +
72136 inc_mm_counter(mm, anon_rss);
72137 page_add_new_anon_rmap(page, vma, address);
72138 setpte:
72139 @@ -2720,6 +2911,12 @@ setpte:
72140
72141 /* No need to invalidate - it was non-present before */
72142 update_mmu_cache(vma, address, entry);
72143 +
72144 +#ifdef CONFIG_PAX_SEGMEXEC
72145 + if (page)
72146 + pax_mirror_anon_pte(vma, address, page, ptl);
72147 +#endif
72148 +
72149 unlock:
72150 pte_unmap_unlock(page_table, ptl);
72151 return 0;
72152 @@ -2862,6 +3059,12 @@ static int __do_fault(struct mm_struct *
72153 */
72154 /* Only go through if we didn't race with anybody else... */
72155 if (likely(pte_same(*page_table, orig_pte))) {
72156 +
72157 +#ifdef CONFIG_PAX_SEGMEXEC
72158 + if (anon && pax_find_mirror_vma(vma))
72159 + BUG_ON(!trylock_page(page));
72160 +#endif
72161 +
72162 flush_icache_page(vma, page);
72163 entry = mk_pte(page, vma->vm_page_prot);
72164 if (flags & FAULT_FLAG_WRITE)
72165 @@ -2881,6 +3084,14 @@ static int __do_fault(struct mm_struct *
72166
72167 /* no need to invalidate: a not-present page won't be cached */
72168 update_mmu_cache(vma, address, entry);
72169 +
72170 +#ifdef CONFIG_PAX_SEGMEXEC
72171 + if (anon)
72172 + pax_mirror_anon_pte(vma, address, page, ptl);
72173 + else
72174 + pax_mirror_file_pte(vma, address, page, ptl);
72175 +#endif
72176 +
72177 } else {
72178 if (charged)
72179 mem_cgroup_uncharge_page(page);
72180 @@ -3028,6 +3239,12 @@ static inline int handle_pte_fault(struc
72181 if (flags & FAULT_FLAG_WRITE)
72182 flush_tlb_page(vma, address);
72183 }
72184 +
72185 +#ifdef CONFIG_PAX_SEGMEXEC
72186 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72187 + return 0;
72188 +#endif
72189 +
72190 unlock:
72191 pte_unmap_unlock(pte, ptl);
72192 return 0;
72193 @@ -3044,6 +3261,10 @@ int handle_mm_fault(struct mm_struct *mm
72194 pmd_t *pmd;
72195 pte_t *pte;
72196
72197 +#ifdef CONFIG_PAX_SEGMEXEC
72198 + struct vm_area_struct *vma_m;
72199 +#endif
72200 +
72201 __set_current_state(TASK_RUNNING);
72202
72203 count_vm_event(PGFAULT);
72204 @@ -3051,6 +3272,34 @@ int handle_mm_fault(struct mm_struct *mm
72205 if (unlikely(is_vm_hugetlb_page(vma)))
72206 return hugetlb_fault(mm, vma, address, flags);
72207
72208 +#ifdef CONFIG_PAX_SEGMEXEC
72209 + vma_m = pax_find_mirror_vma(vma);
72210 + if (vma_m) {
72211 + unsigned long address_m;
72212 + pgd_t *pgd_m;
72213 + pud_t *pud_m;
72214 + pmd_t *pmd_m;
72215 +
72216 + if (vma->vm_start > vma_m->vm_start) {
72217 + address_m = address;
72218 + address -= SEGMEXEC_TASK_SIZE;
72219 + vma = vma_m;
72220 + } else
72221 + address_m = address + SEGMEXEC_TASK_SIZE;
72222 +
72223 + pgd_m = pgd_offset(mm, address_m);
72224 + pud_m = pud_alloc(mm, pgd_m, address_m);
72225 + if (!pud_m)
72226 + return VM_FAULT_OOM;
72227 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72228 + if (!pmd_m)
72229 + return VM_FAULT_OOM;
72230 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
72231 + return VM_FAULT_OOM;
72232 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72233 + }
72234 +#endif
72235 +
72236 pgd = pgd_offset(mm, address);
72237 pud = pud_alloc(mm, pgd, address);
72238 if (!pud)
72239 @@ -3148,7 +3397,7 @@ static int __init gate_vma_init(void)
72240 gate_vma.vm_start = FIXADDR_USER_START;
72241 gate_vma.vm_end = FIXADDR_USER_END;
72242 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72243 - gate_vma.vm_page_prot = __P101;
72244 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72245 /*
72246 * Make sure the vDSO gets into every core dump.
72247 * Dumping its contents makes post-mortem fully interpretable later
72248 diff -urNp linux-2.6.32.46/mm/mempolicy.c linux-2.6.32.46/mm/mempolicy.c
72249 --- linux-2.6.32.46/mm/mempolicy.c 2011-03-27 14:31:47.000000000 -0400
72250 +++ linux-2.6.32.46/mm/mempolicy.c 2011-04-17 15:56:46.000000000 -0400
72251 @@ -573,6 +573,10 @@ static int mbind_range(struct vm_area_st
72252 struct vm_area_struct *next;
72253 int err;
72254
72255 +#ifdef CONFIG_PAX_SEGMEXEC
72256 + struct vm_area_struct *vma_m;
72257 +#endif
72258 +
72259 err = 0;
72260 for (; vma && vma->vm_start < end; vma = next) {
72261 next = vma->vm_next;
72262 @@ -584,6 +588,16 @@ static int mbind_range(struct vm_area_st
72263 err = policy_vma(vma, new);
72264 if (err)
72265 break;
72266 +
72267 +#ifdef CONFIG_PAX_SEGMEXEC
72268 + vma_m = pax_find_mirror_vma(vma);
72269 + if (vma_m) {
72270 + err = policy_vma(vma_m, new);
72271 + if (err)
72272 + break;
72273 + }
72274 +#endif
72275 +
72276 }
72277 return err;
72278 }
72279 @@ -1002,6 +1016,17 @@ static long do_mbind(unsigned long start
72280
72281 if (end < start)
72282 return -EINVAL;
72283 +
72284 +#ifdef CONFIG_PAX_SEGMEXEC
72285 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72286 + if (end > SEGMEXEC_TASK_SIZE)
72287 + return -EINVAL;
72288 + } else
72289 +#endif
72290 +
72291 + if (end > TASK_SIZE)
72292 + return -EINVAL;
72293 +
72294 if (end == start)
72295 return 0;
72296
72297 @@ -1207,6 +1232,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72298 if (!mm)
72299 return -EINVAL;
72300
72301 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72302 + if (mm != current->mm &&
72303 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72304 + err = -EPERM;
72305 + goto out;
72306 + }
72307 +#endif
72308 +
72309 /*
72310 * Check if this process has the right to modify the specified
72311 * process. The right exists if the process has administrative
72312 @@ -1216,8 +1249,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72313 rcu_read_lock();
72314 tcred = __task_cred(task);
72315 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72316 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72317 - !capable(CAP_SYS_NICE)) {
72318 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72319 rcu_read_unlock();
72320 err = -EPERM;
72321 goto out;
72322 @@ -2396,7 +2428,7 @@ int show_numa_map(struct seq_file *m, vo
72323
72324 if (file) {
72325 seq_printf(m, " file=");
72326 - seq_path(m, &file->f_path, "\n\t= ");
72327 + seq_path(m, &file->f_path, "\n\t\\= ");
72328 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
72329 seq_printf(m, " heap");
72330 } else if (vma->vm_start <= mm->start_stack &&
72331 diff -urNp linux-2.6.32.46/mm/migrate.c linux-2.6.32.46/mm/migrate.c
72332 --- linux-2.6.32.46/mm/migrate.c 2011-07-13 17:23:04.000000000 -0400
72333 +++ linux-2.6.32.46/mm/migrate.c 2011-07-13 17:23:23.000000000 -0400
72334 @@ -916,6 +916,8 @@ static int do_pages_move(struct mm_struc
72335 unsigned long chunk_start;
72336 int err;
72337
72338 + pax_track_stack();
72339 +
72340 task_nodes = cpuset_mems_allowed(task);
72341
72342 err = -ENOMEM;
72343 @@ -1106,6 +1108,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72344 if (!mm)
72345 return -EINVAL;
72346
72347 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72348 + if (mm != current->mm &&
72349 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72350 + err = -EPERM;
72351 + goto out;
72352 + }
72353 +#endif
72354 +
72355 /*
72356 * Check if this process has the right to modify the specified
72357 * process. The right exists if the process has administrative
72358 @@ -1115,8 +1125,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72359 rcu_read_lock();
72360 tcred = __task_cred(task);
72361 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72362 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72363 - !capable(CAP_SYS_NICE)) {
72364 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72365 rcu_read_unlock();
72366 err = -EPERM;
72367 goto out;
72368 diff -urNp linux-2.6.32.46/mm/mlock.c linux-2.6.32.46/mm/mlock.c
72369 --- linux-2.6.32.46/mm/mlock.c 2011-03-27 14:31:47.000000000 -0400
72370 +++ linux-2.6.32.46/mm/mlock.c 2011-04-17 15:56:46.000000000 -0400
72371 @@ -13,6 +13,7 @@
72372 #include <linux/pagemap.h>
72373 #include <linux/mempolicy.h>
72374 #include <linux/syscalls.h>
72375 +#include <linux/security.h>
72376 #include <linux/sched.h>
72377 #include <linux/module.h>
72378 #include <linux/rmap.h>
72379 @@ -138,13 +139,6 @@ void munlock_vma_page(struct page *page)
72380 }
72381 }
72382
72383 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72384 -{
72385 - return (vma->vm_flags & VM_GROWSDOWN) &&
72386 - (vma->vm_start == addr) &&
72387 - !vma_stack_continue(vma->vm_prev, addr);
72388 -}
72389 -
72390 /**
72391 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
72392 * @vma: target vma
72393 @@ -177,12 +171,6 @@ static long __mlock_vma_pages_range(stru
72394 if (vma->vm_flags & VM_WRITE)
72395 gup_flags |= FOLL_WRITE;
72396
72397 - /* We don't try to access the guard page of a stack vma */
72398 - if (stack_guard_page(vma, start)) {
72399 - addr += PAGE_SIZE;
72400 - nr_pages--;
72401 - }
72402 -
72403 while (nr_pages > 0) {
72404 int i;
72405
72406 @@ -440,7 +428,7 @@ static int do_mlock(unsigned long start,
72407 {
72408 unsigned long nstart, end, tmp;
72409 struct vm_area_struct * vma, * prev;
72410 - int error;
72411 + int error = -EINVAL;
72412
72413 len = PAGE_ALIGN(len);
72414 end = start + len;
72415 @@ -448,6 +436,9 @@ static int do_mlock(unsigned long start,
72416 return -EINVAL;
72417 if (end == start)
72418 return 0;
72419 + if (end > TASK_SIZE)
72420 + return -EINVAL;
72421 +
72422 vma = find_vma_prev(current->mm, start, &prev);
72423 if (!vma || vma->vm_start > start)
72424 return -ENOMEM;
72425 @@ -458,6 +449,11 @@ static int do_mlock(unsigned long start,
72426 for (nstart = start ; ; ) {
72427 unsigned int newflags;
72428
72429 +#ifdef CONFIG_PAX_SEGMEXEC
72430 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72431 + break;
72432 +#endif
72433 +
72434 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72435
72436 newflags = vma->vm_flags | VM_LOCKED;
72437 @@ -507,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
72438 lock_limit >>= PAGE_SHIFT;
72439
72440 /* check against resource limits */
72441 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72442 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72443 error = do_mlock(start, len, 1);
72444 up_write(&current->mm->mmap_sem);
72445 @@ -528,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
72446 static int do_mlockall(int flags)
72447 {
72448 struct vm_area_struct * vma, * prev = NULL;
72449 - unsigned int def_flags = 0;
72450
72451 if (flags & MCL_FUTURE)
72452 - def_flags = VM_LOCKED;
72453 - current->mm->def_flags = def_flags;
72454 + current->mm->def_flags |= VM_LOCKED;
72455 + else
72456 + current->mm->def_flags &= ~VM_LOCKED;
72457 if (flags == MCL_FUTURE)
72458 goto out;
72459
72460 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72461 - unsigned int newflags;
72462 + unsigned long newflags;
72463 +
72464 +#ifdef CONFIG_PAX_SEGMEXEC
72465 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72466 + break;
72467 +#endif
72468
72469 + BUG_ON(vma->vm_end > TASK_SIZE);
72470 newflags = vma->vm_flags | VM_LOCKED;
72471 if (!(flags & MCL_CURRENT))
72472 newflags &= ~VM_LOCKED;
72473 @@ -570,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72474 lock_limit >>= PAGE_SHIFT;
72475
72476 ret = -ENOMEM;
72477 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72478 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72479 capable(CAP_IPC_LOCK))
72480 ret = do_mlockall(flags);
72481 diff -urNp linux-2.6.32.46/mm/mmap.c linux-2.6.32.46/mm/mmap.c
72482 --- linux-2.6.32.46/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
72483 +++ linux-2.6.32.46/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
72484 @@ -45,6 +45,16 @@
72485 #define arch_rebalance_pgtables(addr, len) (addr)
72486 #endif
72487
72488 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72489 +{
72490 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72491 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72492 + up_read(&mm->mmap_sem);
72493 + BUG();
72494 + }
72495 +#endif
72496 +}
72497 +
72498 static void unmap_region(struct mm_struct *mm,
72499 struct vm_area_struct *vma, struct vm_area_struct *prev,
72500 unsigned long start, unsigned long end);
72501 @@ -70,22 +80,32 @@ static void unmap_region(struct mm_struc
72502 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72503 *
72504 */
72505 -pgprot_t protection_map[16] = {
72506 +pgprot_t protection_map[16] __read_only = {
72507 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72508 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72509 };
72510
72511 pgprot_t vm_get_page_prot(unsigned long vm_flags)
72512 {
72513 - return __pgprot(pgprot_val(protection_map[vm_flags &
72514 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72515 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72516 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72517 +
72518 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72519 + if (!nx_enabled &&
72520 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72521 + (vm_flags & (VM_READ | VM_WRITE)))
72522 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72523 +#endif
72524 +
72525 + return prot;
72526 }
72527 EXPORT_SYMBOL(vm_get_page_prot);
72528
72529 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72530 int sysctl_overcommit_ratio = 50; /* default is 50% */
72531 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72532 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72533 struct percpu_counter vm_committed_as;
72534
72535 /*
72536 @@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma
72537 struct vm_area_struct *next = vma->vm_next;
72538
72539 might_sleep();
72540 + BUG_ON(vma->vm_mirror);
72541 if (vma->vm_ops && vma->vm_ops->close)
72542 vma->vm_ops->close(vma);
72543 if (vma->vm_file) {
72544 @@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72545 * not page aligned -Ram Gupta
72546 */
72547 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
72548 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72549 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72550 (mm->end_data - mm->start_data) > rlim)
72551 goto out;
72552 @@ -704,6 +726,12 @@ static int
72553 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72554 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72555 {
72556 +
72557 +#ifdef CONFIG_PAX_SEGMEXEC
72558 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72559 + return 0;
72560 +#endif
72561 +
72562 if (is_mergeable_vma(vma, file, vm_flags) &&
72563 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72564 if (vma->vm_pgoff == vm_pgoff)
72565 @@ -723,6 +751,12 @@ static int
72566 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72567 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72568 {
72569 +
72570 +#ifdef CONFIG_PAX_SEGMEXEC
72571 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72572 + return 0;
72573 +#endif
72574 +
72575 if (is_mergeable_vma(vma, file, vm_flags) &&
72576 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72577 pgoff_t vm_pglen;
72578 @@ -765,12 +799,19 @@ can_vma_merge_after(struct vm_area_struc
72579 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72580 struct vm_area_struct *prev, unsigned long addr,
72581 unsigned long end, unsigned long vm_flags,
72582 - struct anon_vma *anon_vma, struct file *file,
72583 + struct anon_vma *anon_vma, struct file *file,
72584 pgoff_t pgoff, struct mempolicy *policy)
72585 {
72586 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72587 struct vm_area_struct *area, *next;
72588
72589 +#ifdef CONFIG_PAX_SEGMEXEC
72590 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72591 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72592 +
72593 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72594 +#endif
72595 +
72596 /*
72597 * We later require that vma->vm_flags == vm_flags,
72598 * so this tests vma->vm_flags & VM_SPECIAL, too.
72599 @@ -786,6 +827,15 @@ struct vm_area_struct *vma_merge(struct
72600 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72601 next = next->vm_next;
72602
72603 +#ifdef CONFIG_PAX_SEGMEXEC
72604 + if (prev)
72605 + prev_m = pax_find_mirror_vma(prev);
72606 + if (area)
72607 + area_m = pax_find_mirror_vma(area);
72608 + if (next)
72609 + next_m = pax_find_mirror_vma(next);
72610 +#endif
72611 +
72612 /*
72613 * Can it merge with the predecessor?
72614 */
72615 @@ -805,9 +855,24 @@ struct vm_area_struct *vma_merge(struct
72616 /* cases 1, 6 */
72617 vma_adjust(prev, prev->vm_start,
72618 next->vm_end, prev->vm_pgoff, NULL);
72619 - } else /* cases 2, 5, 7 */
72620 +
72621 +#ifdef CONFIG_PAX_SEGMEXEC
72622 + if (prev_m)
72623 + vma_adjust(prev_m, prev_m->vm_start,
72624 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72625 +#endif
72626 +
72627 + } else { /* cases 2, 5, 7 */
72628 vma_adjust(prev, prev->vm_start,
72629 end, prev->vm_pgoff, NULL);
72630 +
72631 +#ifdef CONFIG_PAX_SEGMEXEC
72632 + if (prev_m)
72633 + vma_adjust(prev_m, prev_m->vm_start,
72634 + end_m, prev_m->vm_pgoff, NULL);
72635 +#endif
72636 +
72637 + }
72638 return prev;
72639 }
72640
72641 @@ -818,12 +883,27 @@ struct vm_area_struct *vma_merge(struct
72642 mpol_equal(policy, vma_policy(next)) &&
72643 can_vma_merge_before(next, vm_flags,
72644 anon_vma, file, pgoff+pglen)) {
72645 - if (prev && addr < prev->vm_end) /* case 4 */
72646 + if (prev && addr < prev->vm_end) { /* case 4 */
72647 vma_adjust(prev, prev->vm_start,
72648 addr, prev->vm_pgoff, NULL);
72649 - else /* cases 3, 8 */
72650 +
72651 +#ifdef CONFIG_PAX_SEGMEXEC
72652 + if (prev_m)
72653 + vma_adjust(prev_m, prev_m->vm_start,
72654 + addr_m, prev_m->vm_pgoff, NULL);
72655 +#endif
72656 +
72657 + } else { /* cases 3, 8 */
72658 vma_adjust(area, addr, next->vm_end,
72659 next->vm_pgoff - pglen, NULL);
72660 +
72661 +#ifdef CONFIG_PAX_SEGMEXEC
72662 + if (area_m)
72663 + vma_adjust(area_m, addr_m, next_m->vm_end,
72664 + next_m->vm_pgoff - pglen, NULL);
72665 +#endif
72666 +
72667 + }
72668 return area;
72669 }
72670
72671 @@ -898,14 +978,11 @@ none:
72672 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72673 struct file *file, long pages)
72674 {
72675 - const unsigned long stack_flags
72676 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72677 -
72678 if (file) {
72679 mm->shared_vm += pages;
72680 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72681 mm->exec_vm += pages;
72682 - } else if (flags & stack_flags)
72683 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72684 mm->stack_vm += pages;
72685 if (flags & (VM_RESERVED|VM_IO))
72686 mm->reserved_vm += pages;
72687 @@ -932,7 +1009,7 @@ unsigned long do_mmap_pgoff(struct file
72688 * (the exception is when the underlying filesystem is noexec
72689 * mounted, in which case we dont add PROT_EXEC.)
72690 */
72691 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72692 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72693 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72694 prot |= PROT_EXEC;
72695
72696 @@ -958,7 +1035,7 @@ unsigned long do_mmap_pgoff(struct file
72697 /* Obtain the address to map to. we verify (or select) it and ensure
72698 * that it represents a valid section of the address space.
72699 */
72700 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72701 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72702 if (addr & ~PAGE_MASK)
72703 return addr;
72704
72705 @@ -969,6 +1046,36 @@ unsigned long do_mmap_pgoff(struct file
72706 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72707 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72708
72709 +#ifdef CONFIG_PAX_MPROTECT
72710 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72711 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72712 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72713 + gr_log_rwxmmap(file);
72714 +
72715 +#ifdef CONFIG_PAX_EMUPLT
72716 + vm_flags &= ~VM_EXEC;
72717 +#else
72718 + return -EPERM;
72719 +#endif
72720 +
72721 + }
72722 +
72723 + if (!(vm_flags & VM_EXEC))
72724 + vm_flags &= ~VM_MAYEXEC;
72725 +#else
72726 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72727 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72728 +#endif
72729 + else
72730 + vm_flags &= ~VM_MAYWRITE;
72731 + }
72732 +#endif
72733 +
72734 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72735 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72736 + vm_flags &= ~VM_PAGEEXEC;
72737 +#endif
72738 +
72739 if (flags & MAP_LOCKED)
72740 if (!can_do_mlock())
72741 return -EPERM;
72742 @@ -980,6 +1087,7 @@ unsigned long do_mmap_pgoff(struct file
72743 locked += mm->locked_vm;
72744 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
72745 lock_limit >>= PAGE_SHIFT;
72746 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72747 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72748 return -EAGAIN;
72749 }
72750 @@ -1053,6 +1161,9 @@ unsigned long do_mmap_pgoff(struct file
72751 if (error)
72752 return error;
72753
72754 + if (!gr_acl_handle_mmap(file, prot))
72755 + return -EACCES;
72756 +
72757 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72758 }
72759 EXPORT_SYMBOL(do_mmap_pgoff);
72760 @@ -1065,10 +1176,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
72761 */
72762 int vma_wants_writenotify(struct vm_area_struct *vma)
72763 {
72764 - unsigned int vm_flags = vma->vm_flags;
72765 + unsigned long vm_flags = vma->vm_flags;
72766
72767 /* If it was private or non-writable, the write bit is already clear */
72768 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72769 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72770 return 0;
72771
72772 /* The backer wishes to know when pages are first written to? */
72773 @@ -1117,14 +1228,24 @@ unsigned long mmap_region(struct file *f
72774 unsigned long charged = 0;
72775 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72776
72777 +#ifdef CONFIG_PAX_SEGMEXEC
72778 + struct vm_area_struct *vma_m = NULL;
72779 +#endif
72780 +
72781 + /*
72782 + * mm->mmap_sem is required to protect against another thread
72783 + * changing the mappings in case we sleep.
72784 + */
72785 + verify_mm_writelocked(mm);
72786 +
72787 /* Clear old maps */
72788 error = -ENOMEM;
72789 -munmap_back:
72790 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72791 if (vma && vma->vm_start < addr + len) {
72792 if (do_munmap(mm, addr, len))
72793 return -ENOMEM;
72794 - goto munmap_back;
72795 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72796 + BUG_ON(vma && vma->vm_start < addr + len);
72797 }
72798
72799 /* Check against address space limit. */
72800 @@ -1173,6 +1294,16 @@ munmap_back:
72801 goto unacct_error;
72802 }
72803
72804 +#ifdef CONFIG_PAX_SEGMEXEC
72805 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72806 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72807 + if (!vma_m) {
72808 + error = -ENOMEM;
72809 + goto free_vma;
72810 + }
72811 + }
72812 +#endif
72813 +
72814 vma->vm_mm = mm;
72815 vma->vm_start = addr;
72816 vma->vm_end = addr + len;
72817 @@ -1195,6 +1326,19 @@ munmap_back:
72818 error = file->f_op->mmap(file, vma);
72819 if (error)
72820 goto unmap_and_free_vma;
72821 +
72822 +#ifdef CONFIG_PAX_SEGMEXEC
72823 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72824 + added_exe_file_vma(mm);
72825 +#endif
72826 +
72827 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72828 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72829 + vma->vm_flags |= VM_PAGEEXEC;
72830 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72831 + }
72832 +#endif
72833 +
72834 if (vm_flags & VM_EXECUTABLE)
72835 added_exe_file_vma(mm);
72836
72837 @@ -1218,6 +1362,11 @@ munmap_back:
72838 vma_link(mm, vma, prev, rb_link, rb_parent);
72839 file = vma->vm_file;
72840
72841 +#ifdef CONFIG_PAX_SEGMEXEC
72842 + if (vma_m)
72843 + pax_mirror_vma(vma_m, vma);
72844 +#endif
72845 +
72846 /* Once vma denies write, undo our temporary denial count */
72847 if (correct_wcount)
72848 atomic_inc(&inode->i_writecount);
72849 @@ -1226,6 +1375,7 @@ out:
72850
72851 mm->total_vm += len >> PAGE_SHIFT;
72852 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72853 + track_exec_limit(mm, addr, addr + len, vm_flags);
72854 if (vm_flags & VM_LOCKED) {
72855 /*
72856 * makes pages present; downgrades, drops, reacquires mmap_sem
72857 @@ -1248,6 +1398,12 @@ unmap_and_free_vma:
72858 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72859 charged = 0;
72860 free_vma:
72861 +
72862 +#ifdef CONFIG_PAX_SEGMEXEC
72863 + if (vma_m)
72864 + kmem_cache_free(vm_area_cachep, vma_m);
72865 +#endif
72866 +
72867 kmem_cache_free(vm_area_cachep, vma);
72868 unacct_error:
72869 if (charged)
72870 @@ -1255,6 +1411,44 @@ unacct_error:
72871 return error;
72872 }
72873
72874 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72875 +{
72876 + if (!vma) {
72877 +#ifdef CONFIG_STACK_GROWSUP
72878 + if (addr > sysctl_heap_stack_gap)
72879 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72880 + else
72881 + vma = find_vma(current->mm, 0);
72882 + if (vma && (vma->vm_flags & VM_GROWSUP))
72883 + return false;
72884 +#endif
72885 + return true;
72886 + }
72887 +
72888 + if (addr + len > vma->vm_start)
72889 + return false;
72890 +
72891 + if (vma->vm_flags & VM_GROWSDOWN)
72892 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72893 +#ifdef CONFIG_STACK_GROWSUP
72894 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72895 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72896 +#endif
72897 +
72898 + return true;
72899 +}
72900 +
72901 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72902 +{
72903 + if (vma->vm_start < len)
72904 + return -ENOMEM;
72905 + if (!(vma->vm_flags & VM_GROWSDOWN))
72906 + return vma->vm_start - len;
72907 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72908 + return vma->vm_start - len - sysctl_heap_stack_gap;
72909 + return -ENOMEM;
72910 +}
72911 +
72912 /* Get an address range which is currently unmapped.
72913 * For shmat() with addr=0.
72914 *
72915 @@ -1281,18 +1475,23 @@ arch_get_unmapped_area(struct file *filp
72916 if (flags & MAP_FIXED)
72917 return addr;
72918
72919 +#ifdef CONFIG_PAX_RANDMMAP
72920 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72921 +#endif
72922 +
72923 if (addr) {
72924 addr = PAGE_ALIGN(addr);
72925 - vma = find_vma(mm, addr);
72926 - if (TASK_SIZE - len >= addr &&
72927 - (!vma || addr + len <= vma->vm_start))
72928 - return addr;
72929 + if (TASK_SIZE - len >= addr) {
72930 + vma = find_vma(mm, addr);
72931 + if (check_heap_stack_gap(vma, addr, len))
72932 + return addr;
72933 + }
72934 }
72935 if (len > mm->cached_hole_size) {
72936 - start_addr = addr = mm->free_area_cache;
72937 + start_addr = addr = mm->free_area_cache;
72938 } else {
72939 - start_addr = addr = TASK_UNMAPPED_BASE;
72940 - mm->cached_hole_size = 0;
72941 + start_addr = addr = mm->mmap_base;
72942 + mm->cached_hole_size = 0;
72943 }
72944
72945 full_search:
72946 @@ -1303,34 +1502,40 @@ full_search:
72947 * Start a new search - just in case we missed
72948 * some holes.
72949 */
72950 - if (start_addr != TASK_UNMAPPED_BASE) {
72951 - addr = TASK_UNMAPPED_BASE;
72952 - start_addr = addr;
72953 + if (start_addr != mm->mmap_base) {
72954 + start_addr = addr = mm->mmap_base;
72955 mm->cached_hole_size = 0;
72956 goto full_search;
72957 }
72958 return -ENOMEM;
72959 }
72960 - if (!vma || addr + len <= vma->vm_start) {
72961 - /*
72962 - * Remember the place where we stopped the search:
72963 - */
72964 - mm->free_area_cache = addr + len;
72965 - return addr;
72966 - }
72967 + if (check_heap_stack_gap(vma, addr, len))
72968 + break;
72969 if (addr + mm->cached_hole_size < vma->vm_start)
72970 mm->cached_hole_size = vma->vm_start - addr;
72971 addr = vma->vm_end;
72972 }
72973 +
72974 + /*
72975 + * Remember the place where we stopped the search:
72976 + */
72977 + mm->free_area_cache = addr + len;
72978 + return addr;
72979 }
72980 #endif
72981
72982 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72983 {
72984 +
72985 +#ifdef CONFIG_PAX_SEGMEXEC
72986 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72987 + return;
72988 +#endif
72989 +
72990 /*
72991 * Is this a new hole at the lowest possible address?
72992 */
72993 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
72994 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
72995 mm->free_area_cache = addr;
72996 mm->cached_hole_size = ~0UL;
72997 }
72998 @@ -1348,7 +1553,7 @@ arch_get_unmapped_area_topdown(struct fi
72999 {
73000 struct vm_area_struct *vma;
73001 struct mm_struct *mm = current->mm;
73002 - unsigned long addr = addr0;
73003 + unsigned long base = mm->mmap_base, addr = addr0;
73004
73005 /* requested length too big for entire address space */
73006 if (len > TASK_SIZE)
73007 @@ -1357,13 +1562,18 @@ arch_get_unmapped_area_topdown(struct fi
73008 if (flags & MAP_FIXED)
73009 return addr;
73010
73011 +#ifdef CONFIG_PAX_RANDMMAP
73012 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73013 +#endif
73014 +
73015 /* requesting a specific address */
73016 if (addr) {
73017 addr = PAGE_ALIGN(addr);
73018 - vma = find_vma(mm, addr);
73019 - if (TASK_SIZE - len >= addr &&
73020 - (!vma || addr + len <= vma->vm_start))
73021 - return addr;
73022 + if (TASK_SIZE - len >= addr) {
73023 + vma = find_vma(mm, addr);
73024 + if (check_heap_stack_gap(vma, addr, len))
73025 + return addr;
73026 + }
73027 }
73028
73029 /* check if free_area_cache is useful for us */
73030 @@ -1378,7 +1588,7 @@ arch_get_unmapped_area_topdown(struct fi
73031 /* make sure it can fit in the remaining address space */
73032 if (addr > len) {
73033 vma = find_vma(mm, addr-len);
73034 - if (!vma || addr <= vma->vm_start)
73035 + if (check_heap_stack_gap(vma, addr - len, len))
73036 /* remember the address as a hint for next time */
73037 return (mm->free_area_cache = addr-len);
73038 }
73039 @@ -1395,7 +1605,7 @@ arch_get_unmapped_area_topdown(struct fi
73040 * return with success:
73041 */
73042 vma = find_vma(mm, addr);
73043 - if (!vma || addr+len <= vma->vm_start)
73044 + if (check_heap_stack_gap(vma, addr, len))
73045 /* remember the address as a hint for next time */
73046 return (mm->free_area_cache = addr);
73047
73048 @@ -1404,8 +1614,8 @@ arch_get_unmapped_area_topdown(struct fi
73049 mm->cached_hole_size = vma->vm_start - addr;
73050
73051 /* try just below the current vma->vm_start */
73052 - addr = vma->vm_start-len;
73053 - } while (len < vma->vm_start);
73054 + addr = skip_heap_stack_gap(vma, len);
73055 + } while (!IS_ERR_VALUE(addr));
73056
73057 bottomup:
73058 /*
73059 @@ -1414,13 +1624,21 @@ bottomup:
73060 * can happen with large stack limits and large mmap()
73061 * allocations.
73062 */
73063 + mm->mmap_base = TASK_UNMAPPED_BASE;
73064 +
73065 +#ifdef CONFIG_PAX_RANDMMAP
73066 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73067 + mm->mmap_base += mm->delta_mmap;
73068 +#endif
73069 +
73070 + mm->free_area_cache = mm->mmap_base;
73071 mm->cached_hole_size = ~0UL;
73072 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73073 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73074 /*
73075 * Restore the topdown base:
73076 */
73077 - mm->free_area_cache = mm->mmap_base;
73078 + mm->mmap_base = base;
73079 + mm->free_area_cache = base;
73080 mm->cached_hole_size = ~0UL;
73081
73082 return addr;
73083 @@ -1429,6 +1647,12 @@ bottomup:
73084
73085 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73086 {
73087 +
73088 +#ifdef CONFIG_PAX_SEGMEXEC
73089 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73090 + return;
73091 +#endif
73092 +
73093 /*
73094 * Is this a new hole at the highest possible address?
73095 */
73096 @@ -1436,8 +1660,10 @@ void arch_unmap_area_topdown(struct mm_s
73097 mm->free_area_cache = addr;
73098
73099 /* dont allow allocations above current base */
73100 - if (mm->free_area_cache > mm->mmap_base)
73101 + if (mm->free_area_cache > mm->mmap_base) {
73102 mm->free_area_cache = mm->mmap_base;
73103 + mm->cached_hole_size = ~0UL;
73104 + }
73105 }
73106
73107 unsigned long
73108 @@ -1545,6 +1771,27 @@ out:
73109 return prev ? prev->vm_next : vma;
73110 }
73111
73112 +#ifdef CONFIG_PAX_SEGMEXEC
73113 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73114 +{
73115 + struct vm_area_struct *vma_m;
73116 +
73117 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73118 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73119 + BUG_ON(vma->vm_mirror);
73120 + return NULL;
73121 + }
73122 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73123 + vma_m = vma->vm_mirror;
73124 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73125 + BUG_ON(vma->vm_file != vma_m->vm_file);
73126 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73127 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
73128 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73129 + return vma_m;
73130 +}
73131 +#endif
73132 +
73133 /*
73134 * Verify that the stack growth is acceptable and
73135 * update accounting. This is shared with both the
73136 @@ -1561,6 +1808,7 @@ static int acct_stack_growth(struct vm_a
73137 return -ENOMEM;
73138
73139 /* Stack limit test */
73140 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73141 if (size > rlim[RLIMIT_STACK].rlim_cur)
73142 return -ENOMEM;
73143
73144 @@ -1570,6 +1818,7 @@ static int acct_stack_growth(struct vm_a
73145 unsigned long limit;
73146 locked = mm->locked_vm + grow;
73147 limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
73148 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73149 if (locked > limit && !capable(CAP_IPC_LOCK))
73150 return -ENOMEM;
73151 }
73152 @@ -1600,37 +1849,48 @@ static int acct_stack_growth(struct vm_a
73153 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73154 * vma is the last one with address > vma->vm_end. Have to extend vma.
73155 */
73156 +#ifndef CONFIG_IA64
73157 +static
73158 +#endif
73159 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73160 {
73161 int error;
73162 + bool locknext;
73163
73164 if (!(vma->vm_flags & VM_GROWSUP))
73165 return -EFAULT;
73166
73167 + /* Also guard against wrapping around to address 0. */
73168 + if (address < PAGE_ALIGN(address+1))
73169 + address = PAGE_ALIGN(address+1);
73170 + else
73171 + return -ENOMEM;
73172 +
73173 /*
73174 * We must make sure the anon_vma is allocated
73175 * so that the anon_vma locking is not a noop.
73176 */
73177 if (unlikely(anon_vma_prepare(vma)))
73178 return -ENOMEM;
73179 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73180 + if (locknext && anon_vma_prepare(vma->vm_next))
73181 + return -ENOMEM;
73182 anon_vma_lock(vma);
73183 + if (locknext)
73184 + anon_vma_lock(vma->vm_next);
73185
73186 /*
73187 * vma->vm_start/vm_end cannot change under us because the caller
73188 * is required to hold the mmap_sem in read mode. We need the
73189 - * anon_vma lock to serialize against concurrent expand_stacks.
73190 - * Also guard against wrapping around to address 0.
73191 + * anon_vma locks to serialize against concurrent expand_stacks
73192 + * and expand_upwards.
73193 */
73194 - if (address < PAGE_ALIGN(address+4))
73195 - address = PAGE_ALIGN(address+4);
73196 - else {
73197 - anon_vma_unlock(vma);
73198 - return -ENOMEM;
73199 - }
73200 error = 0;
73201
73202 /* Somebody else might have raced and expanded it already */
73203 - if (address > vma->vm_end) {
73204 + 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)
73205 + error = -ENOMEM;
73206 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73207 unsigned long size, grow;
73208
73209 size = address - vma->vm_start;
73210 @@ -1640,6 +1900,8 @@ int expand_upwards(struct vm_area_struct
73211 if (!error)
73212 vma->vm_end = address;
73213 }
73214 + if (locknext)
73215 + anon_vma_unlock(vma->vm_next);
73216 anon_vma_unlock(vma);
73217 return error;
73218 }
73219 @@ -1652,6 +1914,8 @@ static int expand_downwards(struct vm_ar
73220 unsigned long address)
73221 {
73222 int error;
73223 + bool lockprev = false;
73224 + struct vm_area_struct *prev;
73225
73226 /*
73227 * We must make sure the anon_vma is allocated
73228 @@ -1665,6 +1929,15 @@ static int expand_downwards(struct vm_ar
73229 if (error)
73230 return error;
73231
73232 + prev = vma->vm_prev;
73233 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73234 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73235 +#endif
73236 + if (lockprev && anon_vma_prepare(prev))
73237 + return -ENOMEM;
73238 + if (lockprev)
73239 + anon_vma_lock(prev);
73240 +
73241 anon_vma_lock(vma);
73242
73243 /*
73244 @@ -1674,9 +1947,17 @@ static int expand_downwards(struct vm_ar
73245 */
73246
73247 /* Somebody else might have raced and expanded it already */
73248 - if (address < vma->vm_start) {
73249 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73250 + error = -ENOMEM;
73251 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73252 unsigned long size, grow;
73253
73254 +#ifdef CONFIG_PAX_SEGMEXEC
73255 + struct vm_area_struct *vma_m;
73256 +
73257 + vma_m = pax_find_mirror_vma(vma);
73258 +#endif
73259 +
73260 size = vma->vm_end - address;
73261 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73262
73263 @@ -1684,9 +1965,20 @@ static int expand_downwards(struct vm_ar
73264 if (!error) {
73265 vma->vm_start = address;
73266 vma->vm_pgoff -= grow;
73267 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73268 +
73269 +#ifdef CONFIG_PAX_SEGMEXEC
73270 + if (vma_m) {
73271 + vma_m->vm_start -= grow << PAGE_SHIFT;
73272 + vma_m->vm_pgoff -= grow;
73273 + }
73274 +#endif
73275 +
73276 }
73277 }
73278 anon_vma_unlock(vma);
73279 + if (lockprev)
73280 + anon_vma_unlock(prev);
73281 return error;
73282 }
73283
73284 @@ -1762,6 +2054,13 @@ static void remove_vma_list(struct mm_st
73285 do {
73286 long nrpages = vma_pages(vma);
73287
73288 +#ifdef CONFIG_PAX_SEGMEXEC
73289 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73290 + vma = remove_vma(vma);
73291 + continue;
73292 + }
73293 +#endif
73294 +
73295 mm->total_vm -= nrpages;
73296 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73297 vma = remove_vma(vma);
73298 @@ -1807,6 +2106,16 @@ detach_vmas_to_be_unmapped(struct mm_str
73299 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73300 vma->vm_prev = NULL;
73301 do {
73302 +
73303 +#ifdef CONFIG_PAX_SEGMEXEC
73304 + if (vma->vm_mirror) {
73305 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73306 + vma->vm_mirror->vm_mirror = NULL;
73307 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73308 + vma->vm_mirror = NULL;
73309 + }
73310 +#endif
73311 +
73312 rb_erase(&vma->vm_rb, &mm->mm_rb);
73313 mm->map_count--;
73314 tail_vma = vma;
73315 @@ -1834,10 +2143,25 @@ int split_vma(struct mm_struct * mm, str
73316 struct mempolicy *pol;
73317 struct vm_area_struct *new;
73318
73319 +#ifdef CONFIG_PAX_SEGMEXEC
73320 + struct vm_area_struct *vma_m, *new_m = NULL;
73321 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73322 +#endif
73323 +
73324 if (is_vm_hugetlb_page(vma) && (addr &
73325 ~(huge_page_mask(hstate_vma(vma)))))
73326 return -EINVAL;
73327
73328 +#ifdef CONFIG_PAX_SEGMEXEC
73329 + vma_m = pax_find_mirror_vma(vma);
73330 +
73331 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73332 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73333 + if (mm->map_count >= sysctl_max_map_count-1)
73334 + return -ENOMEM;
73335 + } else
73336 +#endif
73337 +
73338 if (mm->map_count >= sysctl_max_map_count)
73339 return -ENOMEM;
73340
73341 @@ -1845,6 +2169,16 @@ int split_vma(struct mm_struct * mm, str
73342 if (!new)
73343 return -ENOMEM;
73344
73345 +#ifdef CONFIG_PAX_SEGMEXEC
73346 + if (vma_m) {
73347 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73348 + if (!new_m) {
73349 + kmem_cache_free(vm_area_cachep, new);
73350 + return -ENOMEM;
73351 + }
73352 + }
73353 +#endif
73354 +
73355 /* most fields are the same, copy all, and then fixup */
73356 *new = *vma;
73357
73358 @@ -1855,8 +2189,29 @@ int split_vma(struct mm_struct * mm, str
73359 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73360 }
73361
73362 +#ifdef CONFIG_PAX_SEGMEXEC
73363 + if (vma_m) {
73364 + *new_m = *vma_m;
73365 + new_m->vm_mirror = new;
73366 + new->vm_mirror = new_m;
73367 +
73368 + if (new_below)
73369 + new_m->vm_end = addr_m;
73370 + else {
73371 + new_m->vm_start = addr_m;
73372 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73373 + }
73374 + }
73375 +#endif
73376 +
73377 pol = mpol_dup(vma_policy(vma));
73378 if (IS_ERR(pol)) {
73379 +
73380 +#ifdef CONFIG_PAX_SEGMEXEC
73381 + if (new_m)
73382 + kmem_cache_free(vm_area_cachep, new_m);
73383 +#endif
73384 +
73385 kmem_cache_free(vm_area_cachep, new);
73386 return PTR_ERR(pol);
73387 }
73388 @@ -1877,6 +2232,28 @@ int split_vma(struct mm_struct * mm, str
73389 else
73390 vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73391
73392 +#ifdef CONFIG_PAX_SEGMEXEC
73393 + if (vma_m) {
73394 + mpol_get(pol);
73395 + vma_set_policy(new_m, pol);
73396 +
73397 + if (new_m->vm_file) {
73398 + get_file(new_m->vm_file);
73399 + if (vma_m->vm_flags & VM_EXECUTABLE)
73400 + added_exe_file_vma(mm);
73401 + }
73402 +
73403 + if (new_m->vm_ops && new_m->vm_ops->open)
73404 + new_m->vm_ops->open(new_m);
73405 +
73406 + if (new_below)
73407 + vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73408 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73409 + else
73410 + vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73411 + }
73412 +#endif
73413 +
73414 return 0;
73415 }
73416
73417 @@ -1885,11 +2262,30 @@ int split_vma(struct mm_struct * mm, str
73418 * work. This now handles partial unmappings.
73419 * Jeremy Fitzhardinge <jeremy@goop.org>
73420 */
73421 +#ifdef CONFIG_PAX_SEGMEXEC
73422 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73423 +{
73424 + int ret = __do_munmap(mm, start, len);
73425 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73426 + return ret;
73427 +
73428 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73429 +}
73430 +
73431 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73432 +#else
73433 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73434 +#endif
73435 {
73436 unsigned long end;
73437 struct vm_area_struct *vma, *prev, *last;
73438
73439 + /*
73440 + * mm->mmap_sem is required to protect against another thread
73441 + * changing the mappings in case we sleep.
73442 + */
73443 + verify_mm_writelocked(mm);
73444 +
73445 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73446 return -EINVAL;
73447
73448 @@ -1953,6 +2349,8 @@ int do_munmap(struct mm_struct *mm, unsi
73449 /* Fix up all other VM information */
73450 remove_vma_list(mm, vma);
73451
73452 + track_exec_limit(mm, start, end, 0UL);
73453 +
73454 return 0;
73455 }
73456
73457 @@ -1965,22 +2363,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
73458
73459 profile_munmap(addr);
73460
73461 +#ifdef CONFIG_PAX_SEGMEXEC
73462 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73463 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
73464 + return -EINVAL;
73465 +#endif
73466 +
73467 down_write(&mm->mmap_sem);
73468 ret = do_munmap(mm, addr, len);
73469 up_write(&mm->mmap_sem);
73470 return ret;
73471 }
73472
73473 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73474 -{
73475 -#ifdef CONFIG_DEBUG_VM
73476 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73477 - WARN_ON(1);
73478 - up_read(&mm->mmap_sem);
73479 - }
73480 -#endif
73481 -}
73482 -
73483 /*
73484 * this is really a simplified "do_mmap". it only handles
73485 * anonymous maps. eventually we may be able to do some
73486 @@ -1994,6 +2388,7 @@ unsigned long do_brk(unsigned long addr,
73487 struct rb_node ** rb_link, * rb_parent;
73488 pgoff_t pgoff = addr >> PAGE_SHIFT;
73489 int error;
73490 + unsigned long charged;
73491
73492 len = PAGE_ALIGN(len);
73493 if (!len)
73494 @@ -2005,16 +2400,30 @@ unsigned long do_brk(unsigned long addr,
73495
73496 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73497
73498 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73499 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73500 + flags &= ~VM_EXEC;
73501 +
73502 +#ifdef CONFIG_PAX_MPROTECT
73503 + if (mm->pax_flags & MF_PAX_MPROTECT)
73504 + flags &= ~VM_MAYEXEC;
73505 +#endif
73506 +
73507 + }
73508 +#endif
73509 +
73510 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73511 if (error & ~PAGE_MASK)
73512 return error;
73513
73514 + charged = len >> PAGE_SHIFT;
73515 +
73516 /*
73517 * mlock MCL_FUTURE?
73518 */
73519 if (mm->def_flags & VM_LOCKED) {
73520 unsigned long locked, lock_limit;
73521 - locked = len >> PAGE_SHIFT;
73522 + locked = charged;
73523 locked += mm->locked_vm;
73524 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
73525 lock_limit >>= PAGE_SHIFT;
73526 @@ -2031,22 +2440,22 @@ unsigned long do_brk(unsigned long addr,
73527 /*
73528 * Clear old maps. this also does some error checking for us
73529 */
73530 - munmap_back:
73531 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73532 if (vma && vma->vm_start < addr + len) {
73533 if (do_munmap(mm, addr, len))
73534 return -ENOMEM;
73535 - goto munmap_back;
73536 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73537 + BUG_ON(vma && vma->vm_start < addr + len);
73538 }
73539
73540 /* Check against address space limits *after* clearing old maps... */
73541 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73542 + if (!may_expand_vm(mm, charged))
73543 return -ENOMEM;
73544
73545 if (mm->map_count > sysctl_max_map_count)
73546 return -ENOMEM;
73547
73548 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
73549 + if (security_vm_enough_memory(charged))
73550 return -ENOMEM;
73551
73552 /* Can we just expand an old private anonymous mapping? */
73553 @@ -2060,7 +2469,7 @@ unsigned long do_brk(unsigned long addr,
73554 */
73555 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73556 if (!vma) {
73557 - vm_unacct_memory(len >> PAGE_SHIFT);
73558 + vm_unacct_memory(charged);
73559 return -ENOMEM;
73560 }
73561
73562 @@ -2072,11 +2481,12 @@ unsigned long do_brk(unsigned long addr,
73563 vma->vm_page_prot = vm_get_page_prot(flags);
73564 vma_link(mm, vma, prev, rb_link, rb_parent);
73565 out:
73566 - mm->total_vm += len >> PAGE_SHIFT;
73567 + mm->total_vm += charged;
73568 if (flags & VM_LOCKED) {
73569 if (!mlock_vma_pages_range(vma, addr, addr + len))
73570 - mm->locked_vm += (len >> PAGE_SHIFT);
73571 + mm->locked_vm += charged;
73572 }
73573 + track_exec_limit(mm, addr, addr + len, flags);
73574 return addr;
73575 }
73576
73577 @@ -2123,8 +2533,10 @@ void exit_mmap(struct mm_struct *mm)
73578 * Walk the list again, actually closing and freeing it,
73579 * with preemption enabled, without holding any MM locks.
73580 */
73581 - while (vma)
73582 + while (vma) {
73583 + vma->vm_mirror = NULL;
73584 vma = remove_vma(vma);
73585 + }
73586
73587 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
73588 }
73589 @@ -2138,6 +2550,10 @@ int insert_vm_struct(struct mm_struct *
73590 struct vm_area_struct * __vma, * prev;
73591 struct rb_node ** rb_link, * rb_parent;
73592
73593 +#ifdef CONFIG_PAX_SEGMEXEC
73594 + struct vm_area_struct *vma_m = NULL;
73595 +#endif
73596 +
73597 /*
73598 * The vm_pgoff of a purely anonymous vma should be irrelevant
73599 * until its first write fault, when page's anon_vma and index
73600 @@ -2160,7 +2576,22 @@ int insert_vm_struct(struct mm_struct *
73601 if ((vma->vm_flags & VM_ACCOUNT) &&
73602 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73603 return -ENOMEM;
73604 +
73605 +#ifdef CONFIG_PAX_SEGMEXEC
73606 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73607 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73608 + if (!vma_m)
73609 + return -ENOMEM;
73610 + }
73611 +#endif
73612 +
73613 vma_link(mm, vma, prev, rb_link, rb_parent);
73614 +
73615 +#ifdef CONFIG_PAX_SEGMEXEC
73616 + if (vma_m)
73617 + pax_mirror_vma(vma_m, vma);
73618 +#endif
73619 +
73620 return 0;
73621 }
73622
73623 @@ -2178,6 +2609,8 @@ struct vm_area_struct *copy_vma(struct v
73624 struct rb_node **rb_link, *rb_parent;
73625 struct mempolicy *pol;
73626
73627 + BUG_ON(vma->vm_mirror);
73628 +
73629 /*
73630 * If anonymous vma has not yet been faulted, update new pgoff
73631 * to match new location, to increase its chance of merging.
73632 @@ -2221,6 +2654,35 @@ struct vm_area_struct *copy_vma(struct v
73633 return new_vma;
73634 }
73635
73636 +#ifdef CONFIG_PAX_SEGMEXEC
73637 +void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73638 +{
73639 + struct vm_area_struct *prev_m;
73640 + struct rb_node **rb_link_m, *rb_parent_m;
73641 + struct mempolicy *pol_m;
73642 +
73643 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73644 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73645 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73646 + *vma_m = *vma;
73647 + pol_m = vma_policy(vma_m);
73648 + mpol_get(pol_m);
73649 + vma_set_policy(vma_m, pol_m);
73650 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73651 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73652 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73653 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73654 + if (vma_m->vm_file)
73655 + get_file(vma_m->vm_file);
73656 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73657 + vma_m->vm_ops->open(vma_m);
73658 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73659 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73660 + vma_m->vm_mirror = vma;
73661 + vma->vm_mirror = vma_m;
73662 +}
73663 +#endif
73664 +
73665 /*
73666 * Return true if the calling process may expand its vm space by the passed
73667 * number of pages
73668 @@ -2231,7 +2693,7 @@ int may_expand_vm(struct mm_struct *mm,
73669 unsigned long lim;
73670
73671 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
73672 -
73673 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73674 if (cur + npages > lim)
73675 return 0;
73676 return 1;
73677 @@ -2301,6 +2763,22 @@ int install_special_mapping(struct mm_st
73678 vma->vm_start = addr;
73679 vma->vm_end = addr + len;
73680
73681 +#ifdef CONFIG_PAX_MPROTECT
73682 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73683 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73684 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73685 + return -EPERM;
73686 + if (!(vm_flags & VM_EXEC))
73687 + vm_flags &= ~VM_MAYEXEC;
73688 +#else
73689 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73690 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73691 +#endif
73692 + else
73693 + vm_flags &= ~VM_MAYWRITE;
73694 + }
73695 +#endif
73696 +
73697 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73698 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73699
73700 diff -urNp linux-2.6.32.46/mm/mprotect.c linux-2.6.32.46/mm/mprotect.c
73701 --- linux-2.6.32.46/mm/mprotect.c 2011-03-27 14:31:47.000000000 -0400
73702 +++ linux-2.6.32.46/mm/mprotect.c 2011-04-17 15:56:46.000000000 -0400
73703 @@ -24,10 +24,16 @@
73704 #include <linux/mmu_notifier.h>
73705 #include <linux/migrate.h>
73706 #include <linux/perf_event.h>
73707 +
73708 +#ifdef CONFIG_PAX_MPROTECT
73709 +#include <linux/elf.h>
73710 +#endif
73711 +
73712 #include <asm/uaccess.h>
73713 #include <asm/pgtable.h>
73714 #include <asm/cacheflush.h>
73715 #include <asm/tlbflush.h>
73716 +#include <asm/mmu_context.h>
73717
73718 #ifndef pgprot_modify
73719 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73720 @@ -132,6 +138,48 @@ static void change_protection(struct vm_
73721 flush_tlb_range(vma, start, end);
73722 }
73723
73724 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73725 +/* called while holding the mmap semaphor for writing except stack expansion */
73726 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73727 +{
73728 + unsigned long oldlimit, newlimit = 0UL;
73729 +
73730 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
73731 + return;
73732 +
73733 + spin_lock(&mm->page_table_lock);
73734 + oldlimit = mm->context.user_cs_limit;
73735 + if ((prot & VM_EXEC) && oldlimit < end)
73736 + /* USER_CS limit moved up */
73737 + newlimit = end;
73738 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73739 + /* USER_CS limit moved down */
73740 + newlimit = start;
73741 +
73742 + if (newlimit) {
73743 + mm->context.user_cs_limit = newlimit;
73744 +
73745 +#ifdef CONFIG_SMP
73746 + wmb();
73747 + cpus_clear(mm->context.cpu_user_cs_mask);
73748 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73749 +#endif
73750 +
73751 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73752 + }
73753 + spin_unlock(&mm->page_table_lock);
73754 + if (newlimit == end) {
73755 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73756 +
73757 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73758 + if (is_vm_hugetlb_page(vma))
73759 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73760 + else
73761 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73762 + }
73763 +}
73764 +#endif
73765 +
73766 int
73767 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73768 unsigned long start, unsigned long end, unsigned long newflags)
73769 @@ -144,11 +192,29 @@ mprotect_fixup(struct vm_area_struct *vm
73770 int error;
73771 int dirty_accountable = 0;
73772
73773 +#ifdef CONFIG_PAX_SEGMEXEC
73774 + struct vm_area_struct *vma_m = NULL;
73775 + unsigned long start_m, end_m;
73776 +
73777 + start_m = start + SEGMEXEC_TASK_SIZE;
73778 + end_m = end + SEGMEXEC_TASK_SIZE;
73779 +#endif
73780 +
73781 if (newflags == oldflags) {
73782 *pprev = vma;
73783 return 0;
73784 }
73785
73786 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73787 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73788 +
73789 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73790 + return -ENOMEM;
73791 +
73792 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73793 + return -ENOMEM;
73794 + }
73795 +
73796 /*
73797 * If we make a private mapping writable we increase our commit;
73798 * but (without finer accounting) cannot reduce our commit if we
73799 @@ -165,6 +231,38 @@ mprotect_fixup(struct vm_area_struct *vm
73800 }
73801 }
73802
73803 +#ifdef CONFIG_PAX_SEGMEXEC
73804 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73805 + if (start != vma->vm_start) {
73806 + error = split_vma(mm, vma, start, 1);
73807 + if (error)
73808 + goto fail;
73809 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73810 + *pprev = (*pprev)->vm_next;
73811 + }
73812 +
73813 + if (end != vma->vm_end) {
73814 + error = split_vma(mm, vma, end, 0);
73815 + if (error)
73816 + goto fail;
73817 + }
73818 +
73819 + if (pax_find_mirror_vma(vma)) {
73820 + error = __do_munmap(mm, start_m, end_m - start_m);
73821 + if (error)
73822 + goto fail;
73823 + } else {
73824 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73825 + if (!vma_m) {
73826 + error = -ENOMEM;
73827 + goto fail;
73828 + }
73829 + vma->vm_flags = newflags;
73830 + pax_mirror_vma(vma_m, vma);
73831 + }
73832 + }
73833 +#endif
73834 +
73835 /*
73836 * First try to merge with previous and/or next vma.
73837 */
73838 @@ -195,9 +293,21 @@ success:
73839 * vm_flags and vm_page_prot are protected by the mmap_sem
73840 * held in write mode.
73841 */
73842 +
73843 +#ifdef CONFIG_PAX_SEGMEXEC
73844 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73845 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73846 +#endif
73847 +
73848 vma->vm_flags = newflags;
73849 +
73850 +#ifdef CONFIG_PAX_MPROTECT
73851 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73852 + mm->binfmt->handle_mprotect(vma, newflags);
73853 +#endif
73854 +
73855 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73856 - vm_get_page_prot(newflags));
73857 + vm_get_page_prot(vma->vm_flags));
73858
73859 if (vma_wants_writenotify(vma)) {
73860 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73861 @@ -239,6 +349,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73862 end = start + len;
73863 if (end <= start)
73864 return -ENOMEM;
73865 +
73866 +#ifdef CONFIG_PAX_SEGMEXEC
73867 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73868 + if (end > SEGMEXEC_TASK_SIZE)
73869 + return -EINVAL;
73870 + } else
73871 +#endif
73872 +
73873 + if (end > TASK_SIZE)
73874 + return -EINVAL;
73875 +
73876 if (!arch_validate_prot(prot))
73877 return -EINVAL;
73878
73879 @@ -246,7 +367,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73880 /*
73881 * Does the application expect PROT_READ to imply PROT_EXEC:
73882 */
73883 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73884 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73885 prot |= PROT_EXEC;
73886
73887 vm_flags = calc_vm_prot_bits(prot);
73888 @@ -278,6 +399,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73889 if (start > vma->vm_start)
73890 prev = vma;
73891
73892 +#ifdef CONFIG_PAX_MPROTECT
73893 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73894 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73895 +#endif
73896 +
73897 for (nstart = start ; ; ) {
73898 unsigned long newflags;
73899
73900 @@ -287,6 +413,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73901
73902 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73903 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73904 + if (prot & (PROT_WRITE | PROT_EXEC))
73905 + gr_log_rwxmprotect(vma->vm_file);
73906 +
73907 + error = -EACCES;
73908 + goto out;
73909 + }
73910 +
73911 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73912 error = -EACCES;
73913 goto out;
73914 }
73915 @@ -301,6 +435,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73916 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73917 if (error)
73918 goto out;
73919 +
73920 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73921 +
73922 nstart = tmp;
73923
73924 if (nstart < prev->vm_end)
73925 diff -urNp linux-2.6.32.46/mm/mremap.c linux-2.6.32.46/mm/mremap.c
73926 --- linux-2.6.32.46/mm/mremap.c 2011-04-17 17:00:52.000000000 -0400
73927 +++ linux-2.6.32.46/mm/mremap.c 2011-04-17 17:03:58.000000000 -0400
73928 @@ -112,6 +112,12 @@ static void move_ptes(struct vm_area_str
73929 continue;
73930 pte = ptep_clear_flush(vma, old_addr, old_pte);
73931 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73932 +
73933 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73934 + if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73935 + pte = pte_exprotect(pte);
73936 +#endif
73937 +
73938 set_pte_at(mm, new_addr, new_pte, pte);
73939 }
73940
73941 @@ -271,6 +277,11 @@ static struct vm_area_struct *vma_to_res
73942 if (is_vm_hugetlb_page(vma))
73943 goto Einval;
73944
73945 +#ifdef CONFIG_PAX_SEGMEXEC
73946 + if (pax_find_mirror_vma(vma))
73947 + goto Einval;
73948 +#endif
73949 +
73950 /* We can't remap across vm area boundaries */
73951 if (old_len > vma->vm_end - addr)
73952 goto Efault;
73953 @@ -327,20 +338,25 @@ static unsigned long mremap_to(unsigned
73954 unsigned long ret = -EINVAL;
73955 unsigned long charged = 0;
73956 unsigned long map_flags;
73957 + unsigned long pax_task_size = TASK_SIZE;
73958
73959 if (new_addr & ~PAGE_MASK)
73960 goto out;
73961
73962 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73963 +#ifdef CONFIG_PAX_SEGMEXEC
73964 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73965 + pax_task_size = SEGMEXEC_TASK_SIZE;
73966 +#endif
73967 +
73968 + pax_task_size -= PAGE_SIZE;
73969 +
73970 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73971 goto out;
73972
73973 /* Check if the location we're moving into overlaps the
73974 * old location at all, and fail if it does.
73975 */
73976 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73977 - goto out;
73978 -
73979 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73980 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73981 goto out;
73982
73983 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73984 @@ -412,6 +428,7 @@ unsigned long do_mremap(unsigned long ad
73985 struct vm_area_struct *vma;
73986 unsigned long ret = -EINVAL;
73987 unsigned long charged = 0;
73988 + unsigned long pax_task_size = TASK_SIZE;
73989
73990 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
73991 goto out;
73992 @@ -430,6 +447,17 @@ unsigned long do_mremap(unsigned long ad
73993 if (!new_len)
73994 goto out;
73995
73996 +#ifdef CONFIG_PAX_SEGMEXEC
73997 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73998 + pax_task_size = SEGMEXEC_TASK_SIZE;
73999 +#endif
74000 +
74001 + pax_task_size -= PAGE_SIZE;
74002 +
74003 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74004 + old_len > pax_task_size || addr > pax_task_size-old_len)
74005 + goto out;
74006 +
74007 if (flags & MREMAP_FIXED) {
74008 if (flags & MREMAP_MAYMOVE)
74009 ret = mremap_to(addr, old_len, new_addr, new_len);
74010 @@ -476,6 +504,7 @@ unsigned long do_mremap(unsigned long ad
74011 addr + new_len);
74012 }
74013 ret = addr;
74014 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74015 goto out;
74016 }
74017 }
74018 @@ -502,7 +531,13 @@ unsigned long do_mremap(unsigned long ad
74019 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74020 if (ret)
74021 goto out;
74022 +
74023 + map_flags = vma->vm_flags;
74024 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74025 + if (!(ret & ~PAGE_MASK)) {
74026 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74027 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74028 + }
74029 }
74030 out:
74031 if (ret & ~PAGE_MASK)
74032 diff -urNp linux-2.6.32.46/mm/nommu.c linux-2.6.32.46/mm/nommu.c
74033 --- linux-2.6.32.46/mm/nommu.c 2011-03-27 14:31:47.000000000 -0400
74034 +++ linux-2.6.32.46/mm/nommu.c 2011-04-17 15:56:46.000000000 -0400
74035 @@ -67,7 +67,6 @@ int sysctl_overcommit_memory = OVERCOMMI
74036 int sysctl_overcommit_ratio = 50; /* default is 50% */
74037 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74038 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74039 -int heap_stack_gap = 0;
74040
74041 atomic_long_t mmap_pages_allocated;
74042
74043 @@ -761,15 +760,6 @@ struct vm_area_struct *find_vma(struct m
74044 EXPORT_SYMBOL(find_vma);
74045
74046 /*
74047 - * find a VMA
74048 - * - we don't extend stack VMAs under NOMMU conditions
74049 - */
74050 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74051 -{
74052 - return find_vma(mm, addr);
74053 -}
74054 -
74055 -/*
74056 * expand a stack to a given address
74057 * - not supported under NOMMU conditions
74058 */
74059 diff -urNp linux-2.6.32.46/mm/page_alloc.c linux-2.6.32.46/mm/page_alloc.c
74060 --- linux-2.6.32.46/mm/page_alloc.c 2011-06-25 12:55:35.000000000 -0400
74061 +++ linux-2.6.32.46/mm/page_alloc.c 2011-07-09 09:13:08.000000000 -0400
74062 @@ -289,7 +289,7 @@ out:
74063 * This usage means that zero-order pages may not be compound.
74064 */
74065
74066 -static void free_compound_page(struct page *page)
74067 +void free_compound_page(struct page *page)
74068 {
74069 __free_pages_ok(page, compound_order(page));
74070 }
74071 @@ -587,6 +587,10 @@ static void __free_pages_ok(struct page
74072 int bad = 0;
74073 int wasMlocked = __TestClearPageMlocked(page);
74074
74075 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74076 + unsigned long index = 1UL << order;
74077 +#endif
74078 +
74079 kmemcheck_free_shadow(page, order);
74080
74081 for (i = 0 ; i < (1 << order) ; ++i)
74082 @@ -599,6 +603,12 @@ static void __free_pages_ok(struct page
74083 debug_check_no_obj_freed(page_address(page),
74084 PAGE_SIZE << order);
74085 }
74086 +
74087 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74088 + for (; index; --index)
74089 + sanitize_highpage(page + index - 1);
74090 +#endif
74091 +
74092 arch_free_page(page, order);
74093 kernel_map_pages(page, 1 << order, 0);
74094
74095 @@ -702,8 +712,10 @@ static int prep_new_page(struct page *pa
74096 arch_alloc_page(page, order);
74097 kernel_map_pages(page, 1 << order, 1);
74098
74099 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74100 if (gfp_flags & __GFP_ZERO)
74101 prep_zero_page(page, order, gfp_flags);
74102 +#endif
74103
74104 if (order && (gfp_flags & __GFP_COMP))
74105 prep_compound_page(page, order);
74106 @@ -1097,6 +1109,11 @@ static void free_hot_cold_page(struct pa
74107 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
74108 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
74109 }
74110 +
74111 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74112 + sanitize_highpage(page);
74113 +#endif
74114 +
74115 arch_free_page(page, 0);
74116 kernel_map_pages(page, 1, 0);
74117
74118 @@ -2179,6 +2196,8 @@ void show_free_areas(void)
74119 int cpu;
74120 struct zone *zone;
74121
74122 + pax_track_stack();
74123 +
74124 for_each_populated_zone(zone) {
74125 show_node(zone);
74126 printk("%s per-cpu:\n", zone->name);
74127 @@ -3736,7 +3755,7 @@ static void __init setup_usemap(struct p
74128 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
74129 }
74130 #else
74131 -static void inline setup_usemap(struct pglist_data *pgdat,
74132 +static inline void setup_usemap(struct pglist_data *pgdat,
74133 struct zone *zone, unsigned long zonesize) {}
74134 #endif /* CONFIG_SPARSEMEM */
74135
74136 diff -urNp linux-2.6.32.46/mm/percpu.c linux-2.6.32.46/mm/percpu.c
74137 --- linux-2.6.32.46/mm/percpu.c 2011-03-27 14:31:47.000000000 -0400
74138 +++ linux-2.6.32.46/mm/percpu.c 2011-04-17 15:56:46.000000000 -0400
74139 @@ -115,7 +115,7 @@ static unsigned int pcpu_first_unit_cpu
74140 static unsigned int pcpu_last_unit_cpu __read_mostly;
74141
74142 /* the address of the first chunk which starts with the kernel static area */
74143 -void *pcpu_base_addr __read_mostly;
74144 +void *pcpu_base_addr __read_only;
74145 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74146
74147 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74148 diff -urNp linux-2.6.32.46/mm/rmap.c linux-2.6.32.46/mm/rmap.c
74149 --- linux-2.6.32.46/mm/rmap.c 2011-03-27 14:31:47.000000000 -0400
74150 +++ linux-2.6.32.46/mm/rmap.c 2011-04-17 15:56:46.000000000 -0400
74151 @@ -121,6 +121,17 @@ int anon_vma_prepare(struct vm_area_stru
74152 /* page_table_lock to protect against threads */
74153 spin_lock(&mm->page_table_lock);
74154 if (likely(!vma->anon_vma)) {
74155 +
74156 +#ifdef CONFIG_PAX_SEGMEXEC
74157 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74158 +
74159 + if (vma_m) {
74160 + BUG_ON(vma_m->anon_vma);
74161 + vma_m->anon_vma = anon_vma;
74162 + list_add_tail(&vma_m->anon_vma_node, &anon_vma->head);
74163 + }
74164 +#endif
74165 +
74166 vma->anon_vma = anon_vma;
74167 list_add_tail(&vma->anon_vma_node, &anon_vma->head);
74168 allocated = NULL;
74169 diff -urNp linux-2.6.32.46/mm/shmem.c linux-2.6.32.46/mm/shmem.c
74170 --- linux-2.6.32.46/mm/shmem.c 2011-03-27 14:31:47.000000000 -0400
74171 +++ linux-2.6.32.46/mm/shmem.c 2011-05-18 20:09:37.000000000 -0400
74172 @@ -31,7 +31,7 @@
74173 #include <linux/swap.h>
74174 #include <linux/ima.h>
74175
74176 -static struct vfsmount *shm_mnt;
74177 +struct vfsmount *shm_mnt;
74178
74179 #ifdef CONFIG_SHMEM
74180 /*
74181 @@ -1061,6 +1061,8 @@ static int shmem_writepage(struct page *
74182 goto unlock;
74183 }
74184 entry = shmem_swp_entry(info, index, NULL);
74185 + if (!entry)
74186 + goto unlock;
74187 if (entry->val) {
74188 /*
74189 * The more uptodate page coming down from a stacked
74190 @@ -1144,6 +1146,8 @@ static struct page *shmem_swapin(swp_ent
74191 struct vm_area_struct pvma;
74192 struct page *page;
74193
74194 + pax_track_stack();
74195 +
74196 spol = mpol_cond_copy(&mpol,
74197 mpol_shared_policy_lookup(&info->policy, idx));
74198
74199 @@ -1962,7 +1966,7 @@ static int shmem_symlink(struct inode *d
74200
74201 info = SHMEM_I(inode);
74202 inode->i_size = len-1;
74203 - if (len <= (char *)inode - (char *)info) {
74204 + if (len <= (char *)inode - (char *)info && len <= 64) {
74205 /* do it inline */
74206 memcpy(info, symname, len);
74207 inode->i_op = &shmem_symlink_inline_operations;
74208 @@ -2310,8 +2314,7 @@ int shmem_fill_super(struct super_block
74209 int err = -ENOMEM;
74210
74211 /* Round up to L1_CACHE_BYTES to resist false sharing */
74212 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74213 - L1_CACHE_BYTES), GFP_KERNEL);
74214 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74215 if (!sbinfo)
74216 return -ENOMEM;
74217
74218 diff -urNp linux-2.6.32.46/mm/slab.c linux-2.6.32.46/mm/slab.c
74219 --- linux-2.6.32.46/mm/slab.c 2011-03-27 14:31:47.000000000 -0400
74220 +++ linux-2.6.32.46/mm/slab.c 2011-05-04 17:56:20.000000000 -0400
74221 @@ -174,7 +174,7 @@
74222
74223 /* Legal flag mask for kmem_cache_create(). */
74224 #if DEBUG
74225 -# define CREATE_MASK (SLAB_RED_ZONE | \
74226 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74227 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74228 SLAB_CACHE_DMA | \
74229 SLAB_STORE_USER | \
74230 @@ -182,7 +182,7 @@
74231 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74232 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74233 #else
74234 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74235 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74236 SLAB_CACHE_DMA | \
74237 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74238 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74239 @@ -308,7 +308,7 @@ struct kmem_list3 {
74240 * Need this for bootstrapping a per node allocator.
74241 */
74242 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74243 -struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74244 +struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74245 #define CACHE_CACHE 0
74246 #define SIZE_AC MAX_NUMNODES
74247 #define SIZE_L3 (2 * MAX_NUMNODES)
74248 @@ -409,10 +409,10 @@ static void kmem_list3_init(struct kmem_
74249 if ((x)->max_freeable < i) \
74250 (x)->max_freeable = i; \
74251 } while (0)
74252 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74253 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74254 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74255 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74256 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74257 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74258 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74259 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74260 #else
74261 #define STATS_INC_ACTIVE(x) do { } while (0)
74262 #define STATS_DEC_ACTIVE(x) do { } while (0)
74263 @@ -558,7 +558,7 @@ static inline void *index_to_obj(struct
74264 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74265 */
74266 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74267 - const struct slab *slab, void *obj)
74268 + const struct slab *slab, const void *obj)
74269 {
74270 u32 offset = (obj - slab->s_mem);
74271 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74272 @@ -1453,7 +1453,7 @@ void __init kmem_cache_init(void)
74273 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74274 sizes[INDEX_AC].cs_size,
74275 ARCH_KMALLOC_MINALIGN,
74276 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74277 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74278 NULL);
74279
74280 if (INDEX_AC != INDEX_L3) {
74281 @@ -1461,7 +1461,7 @@ void __init kmem_cache_init(void)
74282 kmem_cache_create(names[INDEX_L3].name,
74283 sizes[INDEX_L3].cs_size,
74284 ARCH_KMALLOC_MINALIGN,
74285 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74286 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74287 NULL);
74288 }
74289
74290 @@ -1479,7 +1479,7 @@ void __init kmem_cache_init(void)
74291 sizes->cs_cachep = kmem_cache_create(names->name,
74292 sizes->cs_size,
74293 ARCH_KMALLOC_MINALIGN,
74294 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74295 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74296 NULL);
74297 }
74298 #ifdef CONFIG_ZONE_DMA
74299 @@ -4211,10 +4211,10 @@ static int s_show(struct seq_file *m, vo
74300 }
74301 /* cpu stats */
74302 {
74303 - unsigned long allochit = atomic_read(&cachep->allochit);
74304 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74305 - unsigned long freehit = atomic_read(&cachep->freehit);
74306 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74307 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74308 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74309 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74310 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74311
74312 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74313 allochit, allocmiss, freehit, freemiss);
74314 @@ -4471,15 +4471,66 @@ static const struct file_operations proc
74315
74316 static int __init slab_proc_init(void)
74317 {
74318 - proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
74319 + mode_t gr_mode = S_IRUGO;
74320 +
74321 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74322 + gr_mode = S_IRUSR;
74323 +#endif
74324 +
74325 + proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
74326 #ifdef CONFIG_DEBUG_SLAB_LEAK
74327 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74328 + proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
74329 #endif
74330 return 0;
74331 }
74332 module_init(slab_proc_init);
74333 #endif
74334
74335 +void check_object_size(const void *ptr, unsigned long n, bool to)
74336 +{
74337 +
74338 +#ifdef CONFIG_PAX_USERCOPY
74339 + struct page *page;
74340 + struct kmem_cache *cachep = NULL;
74341 + struct slab *slabp;
74342 + unsigned int objnr;
74343 + unsigned long offset;
74344 +
74345 + if (!n)
74346 + return;
74347 +
74348 + if (ZERO_OR_NULL_PTR(ptr))
74349 + goto report;
74350 +
74351 + if (!virt_addr_valid(ptr))
74352 + return;
74353 +
74354 + page = virt_to_head_page(ptr);
74355 +
74356 + if (!PageSlab(page)) {
74357 + if (object_is_on_stack(ptr, n) == -1)
74358 + goto report;
74359 + return;
74360 + }
74361 +
74362 + cachep = page_get_cache(page);
74363 + if (!(cachep->flags & SLAB_USERCOPY))
74364 + goto report;
74365 +
74366 + slabp = page_get_slab(page);
74367 + objnr = obj_to_index(cachep, slabp, ptr);
74368 + BUG_ON(objnr >= cachep->num);
74369 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74370 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74371 + return;
74372 +
74373 +report:
74374 + pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
74375 +#endif
74376 +
74377 +}
74378 +EXPORT_SYMBOL(check_object_size);
74379 +
74380 /**
74381 * ksize - get the actual amount of memory allocated for a given object
74382 * @objp: Pointer to the object
74383 diff -urNp linux-2.6.32.46/mm/slob.c linux-2.6.32.46/mm/slob.c
74384 --- linux-2.6.32.46/mm/slob.c 2011-03-27 14:31:47.000000000 -0400
74385 +++ linux-2.6.32.46/mm/slob.c 2011-07-06 19:53:33.000000000 -0400
74386 @@ -29,7 +29,7 @@
74387 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74388 * alloc_pages() directly, allocating compound pages so the page order
74389 * does not have to be separately tracked, and also stores the exact
74390 - * allocation size in page->private so that it can be used to accurately
74391 + * allocation size in slob_page->size so that it can be used to accurately
74392 * provide ksize(). These objects are detected in kfree() because slob_page()
74393 * is false for them.
74394 *
74395 @@ -58,6 +58,7 @@
74396 */
74397
74398 #include <linux/kernel.h>
74399 +#include <linux/sched.h>
74400 #include <linux/slab.h>
74401 #include <linux/mm.h>
74402 #include <linux/swap.h> /* struct reclaim_state */
74403 @@ -100,7 +101,8 @@ struct slob_page {
74404 unsigned long flags; /* mandatory */
74405 atomic_t _count; /* mandatory */
74406 slobidx_t units; /* free units left in page */
74407 - unsigned long pad[2];
74408 + unsigned long pad[1];
74409 + unsigned long size; /* size when >=PAGE_SIZE */
74410 slob_t *free; /* first free slob_t in page */
74411 struct list_head list; /* linked list of free pages */
74412 };
74413 @@ -133,7 +135,7 @@ static LIST_HEAD(free_slob_large);
74414 */
74415 static inline int is_slob_page(struct slob_page *sp)
74416 {
74417 - return PageSlab((struct page *)sp);
74418 + return PageSlab((struct page *)sp) && !sp->size;
74419 }
74420
74421 static inline void set_slob_page(struct slob_page *sp)
74422 @@ -148,7 +150,7 @@ static inline void clear_slob_page(struc
74423
74424 static inline struct slob_page *slob_page(const void *addr)
74425 {
74426 - return (struct slob_page *)virt_to_page(addr);
74427 + return (struct slob_page *)virt_to_head_page(addr);
74428 }
74429
74430 /*
74431 @@ -208,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_
74432 /*
74433 * Return the size of a slob block.
74434 */
74435 -static slobidx_t slob_units(slob_t *s)
74436 +static slobidx_t slob_units(const slob_t *s)
74437 {
74438 if (s->units > 0)
74439 return s->units;
74440 @@ -218,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
74441 /*
74442 * Return the next free slob block pointer after this one.
74443 */
74444 -static slob_t *slob_next(slob_t *s)
74445 +static slob_t *slob_next(const slob_t *s)
74446 {
74447 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74448 slobidx_t next;
74449 @@ -233,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
74450 /*
74451 * Returns true if s is the last free block in its page.
74452 */
74453 -static int slob_last(slob_t *s)
74454 +static int slob_last(const slob_t *s)
74455 {
74456 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74457 }
74458 @@ -252,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, i
74459 if (!page)
74460 return NULL;
74461
74462 + set_slob_page(page);
74463 return page_address(page);
74464 }
74465
74466 @@ -368,11 +371,11 @@ static void *slob_alloc(size_t size, gfp
74467 if (!b)
74468 return NULL;
74469 sp = slob_page(b);
74470 - set_slob_page(sp);
74471
74472 spin_lock_irqsave(&slob_lock, flags);
74473 sp->units = SLOB_UNITS(PAGE_SIZE);
74474 sp->free = b;
74475 + sp->size = 0;
74476 INIT_LIST_HEAD(&sp->list);
74477 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74478 set_slob_page_free(sp, slob_list);
74479 @@ -475,10 +478,9 @@ out:
74480 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long)
74481 #endif
74482
74483 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74484 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74485 {
74486 - unsigned int *m;
74487 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74488 + slob_t *m;
74489 void *ret;
74490
74491 lockdep_trace_alloc(gfp);
74492 @@ -491,7 +493,10 @@ void *__kmalloc_node(size_t size, gfp_t
74493
74494 if (!m)
74495 return NULL;
74496 - *m = size;
74497 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74498 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74499 + m[0].units = size;
74500 + m[1].units = align;
74501 ret = (void *)m + align;
74502
74503 trace_kmalloc_node(_RET_IP_, ret,
74504 @@ -501,16 +506,25 @@ void *__kmalloc_node(size_t size, gfp_t
74505
74506 ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
74507 if (ret) {
74508 - struct page *page;
74509 - page = virt_to_page(ret);
74510 - page->private = size;
74511 + struct slob_page *sp;
74512 + sp = slob_page(ret);
74513 + sp->size = size;
74514 }
74515
74516 trace_kmalloc_node(_RET_IP_, ret,
74517 size, PAGE_SIZE << order, gfp, node);
74518 }
74519
74520 - kmemleak_alloc(ret, size, 1, gfp);
74521 + return ret;
74522 +}
74523 +
74524 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74525 +{
74526 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74527 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74528 +
74529 + if (!ZERO_OR_NULL_PTR(ret))
74530 + kmemleak_alloc(ret, size, 1, gfp);
74531 return ret;
74532 }
74533 EXPORT_SYMBOL(__kmalloc_node);
74534 @@ -528,13 +542,88 @@ void kfree(const void *block)
74535 sp = slob_page(block);
74536 if (is_slob_page(sp)) {
74537 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74538 - unsigned int *m = (unsigned int *)(block - align);
74539 - slob_free(m, *m + align);
74540 - } else
74541 + slob_t *m = (slob_t *)(block - align);
74542 + slob_free(m, m[0].units + align);
74543 + } else {
74544 + clear_slob_page(sp);
74545 + free_slob_page(sp);
74546 + sp->size = 0;
74547 put_page(&sp->page);
74548 + }
74549 }
74550 EXPORT_SYMBOL(kfree);
74551
74552 +void check_object_size(const void *ptr, unsigned long n, bool to)
74553 +{
74554 +
74555 +#ifdef CONFIG_PAX_USERCOPY
74556 + struct slob_page *sp;
74557 + const slob_t *free;
74558 + const void *base;
74559 + unsigned long flags;
74560 +
74561 + if (!n)
74562 + return;
74563 +
74564 + if (ZERO_OR_NULL_PTR(ptr))
74565 + goto report;
74566 +
74567 + if (!virt_addr_valid(ptr))
74568 + return;
74569 +
74570 + sp = slob_page(ptr);
74571 + if (!PageSlab((struct page*)sp)) {
74572 + if (object_is_on_stack(ptr, n) == -1)
74573 + goto report;
74574 + return;
74575 + }
74576 +
74577 + if (sp->size) {
74578 + base = page_address(&sp->page);
74579 + if (base <= ptr && n <= sp->size - (ptr - base))
74580 + return;
74581 + goto report;
74582 + }
74583 +
74584 + /* some tricky double walking to find the chunk */
74585 + spin_lock_irqsave(&slob_lock, flags);
74586 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74587 + free = sp->free;
74588 +
74589 + while (!slob_last(free) && (void *)free <= ptr) {
74590 + base = free + slob_units(free);
74591 + free = slob_next(free);
74592 + }
74593 +
74594 + while (base < (void *)free) {
74595 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74596 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74597 + int offset;
74598 +
74599 + if (ptr < base + align)
74600 + break;
74601 +
74602 + offset = ptr - base - align;
74603 + if (offset >= m) {
74604 + base += size;
74605 + continue;
74606 + }
74607 +
74608 + if (n > m - offset)
74609 + break;
74610 +
74611 + spin_unlock_irqrestore(&slob_lock, flags);
74612 + return;
74613 + }
74614 +
74615 + spin_unlock_irqrestore(&slob_lock, flags);
74616 +report:
74617 + pax_report_usercopy(ptr, n, to, NULL);
74618 +#endif
74619 +
74620 +}
74621 +EXPORT_SYMBOL(check_object_size);
74622 +
74623 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74624 size_t ksize(const void *block)
74625 {
74626 @@ -547,10 +636,10 @@ size_t ksize(const void *block)
74627 sp = slob_page(block);
74628 if (is_slob_page(sp)) {
74629 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74630 - unsigned int *m = (unsigned int *)(block - align);
74631 - return SLOB_UNITS(*m) * SLOB_UNIT;
74632 + slob_t *m = (slob_t *)(block - align);
74633 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74634 } else
74635 - return sp->page.private;
74636 + return sp->size;
74637 }
74638 EXPORT_SYMBOL(ksize);
74639
74640 @@ -566,8 +655,13 @@ struct kmem_cache *kmem_cache_create(con
74641 {
74642 struct kmem_cache *c;
74643
74644 +#ifdef CONFIG_PAX_USERCOPY
74645 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74646 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74647 +#else
74648 c = slob_alloc(sizeof(struct kmem_cache),
74649 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74650 +#endif
74651
74652 if (c) {
74653 c->name = name;
74654 @@ -605,17 +699,25 @@ void *kmem_cache_alloc_node(struct kmem_
74655 {
74656 void *b;
74657
74658 +#ifdef CONFIG_PAX_USERCOPY
74659 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74660 +#else
74661 if (c->size < PAGE_SIZE) {
74662 b = slob_alloc(c->size, flags, c->align, node);
74663 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74664 SLOB_UNITS(c->size) * SLOB_UNIT,
74665 flags, node);
74666 } else {
74667 + struct slob_page *sp;
74668 +
74669 b = slob_new_pages(flags, get_order(c->size), node);
74670 + sp = slob_page(b);
74671 + sp->size = c->size;
74672 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74673 PAGE_SIZE << get_order(c->size),
74674 flags, node);
74675 }
74676 +#endif
74677
74678 if (c->ctor)
74679 c->ctor(b);
74680 @@ -627,10 +729,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74681
74682 static void __kmem_cache_free(void *b, int size)
74683 {
74684 - if (size < PAGE_SIZE)
74685 + struct slob_page *sp = slob_page(b);
74686 +
74687 + if (is_slob_page(sp))
74688 slob_free(b, size);
74689 - else
74690 + else {
74691 + clear_slob_page(sp);
74692 + free_slob_page(sp);
74693 + sp->size = 0;
74694 slob_free_pages(b, get_order(size));
74695 + }
74696 }
74697
74698 static void kmem_rcu_free(struct rcu_head *head)
74699 @@ -643,18 +751,32 @@ static void kmem_rcu_free(struct rcu_hea
74700
74701 void kmem_cache_free(struct kmem_cache *c, void *b)
74702 {
74703 + int size = c->size;
74704 +
74705 +#ifdef CONFIG_PAX_USERCOPY
74706 + if (size + c->align < PAGE_SIZE) {
74707 + size += c->align;
74708 + b -= c->align;
74709 + }
74710 +#endif
74711 +
74712 kmemleak_free_recursive(b, c->flags);
74713 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74714 struct slob_rcu *slob_rcu;
74715 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74716 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74717 INIT_RCU_HEAD(&slob_rcu->head);
74718 - slob_rcu->size = c->size;
74719 + slob_rcu->size = size;
74720 call_rcu(&slob_rcu->head, kmem_rcu_free);
74721 } else {
74722 - __kmem_cache_free(b, c->size);
74723 + __kmem_cache_free(b, size);
74724 }
74725
74726 +#ifdef CONFIG_PAX_USERCOPY
74727 + trace_kfree(_RET_IP_, b);
74728 +#else
74729 trace_kmem_cache_free(_RET_IP_, b);
74730 +#endif
74731 +
74732 }
74733 EXPORT_SYMBOL(kmem_cache_free);
74734
74735 diff -urNp linux-2.6.32.46/mm/slub.c linux-2.6.32.46/mm/slub.c
74736 --- linux-2.6.32.46/mm/slub.c 2011-03-27 14:31:47.000000000 -0400
74737 +++ linux-2.6.32.46/mm/slub.c 2011-09-25 22:23:01.000000000 -0400
74738 @@ -201,7 +201,7 @@ struct track {
74739
74740 enum track_item { TRACK_ALLOC, TRACK_FREE };
74741
74742 -#ifdef CONFIG_SLUB_DEBUG
74743 +#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74744 static int sysfs_slab_add(struct kmem_cache *);
74745 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74746 static void sysfs_slab_remove(struct kmem_cache *);
74747 @@ -410,7 +410,7 @@ static void print_track(const char *s, s
74748 if (!t->addr)
74749 return;
74750
74751 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74752 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74753 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74754 }
74755
74756 @@ -1893,6 +1893,8 @@ void kmem_cache_free(struct kmem_cache *
74757
74758 page = virt_to_head_page(x);
74759
74760 + BUG_ON(!PageSlab(page));
74761 +
74762 slab_free(s, page, x, _RET_IP_);
74763
74764 trace_kmem_cache_free(_RET_IP_, x);
74765 @@ -1937,7 +1939,7 @@ static int slub_min_objects;
74766 * Merge control. If this is set then no merging of slab caches will occur.
74767 * (Could be removed. This was introduced to pacify the merge skeptics.)
74768 */
74769 -static int slub_nomerge;
74770 +static int slub_nomerge = 1;
74771
74772 /*
74773 * Calculate the order of allocation given an slab object size.
74774 @@ -2493,7 +2495,7 @@ static int kmem_cache_open(struct kmem_c
74775 * list to avoid pounding the page allocator excessively.
74776 */
74777 set_min_partial(s, ilog2(s->size));
74778 - s->refcount = 1;
74779 + atomic_set(&s->refcount, 1);
74780 #ifdef CONFIG_NUMA
74781 s->remote_node_defrag_ratio = 1000;
74782 #endif
74783 @@ -2630,8 +2632,7 @@ static inline int kmem_cache_close(struc
74784 void kmem_cache_destroy(struct kmem_cache *s)
74785 {
74786 down_write(&slub_lock);
74787 - s->refcount--;
74788 - if (!s->refcount) {
74789 + if (atomic_dec_and_test(&s->refcount)) {
74790 list_del(&s->list);
74791 up_write(&slub_lock);
74792 if (kmem_cache_close(s)) {
74793 @@ -2691,12 +2692,10 @@ static int __init setup_slub_nomerge(cha
74794 __setup("slub_nomerge", setup_slub_nomerge);
74795
74796 static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
74797 - const char *name, int size, gfp_t gfp_flags)
74798 + const char *name, int size, gfp_t gfp_flags, unsigned int flags)
74799 {
74800 - unsigned int flags = 0;
74801 -
74802 if (gfp_flags & SLUB_DMA)
74803 - flags = SLAB_CACHE_DMA;
74804 + flags |= SLAB_CACHE_DMA;
74805
74806 /*
74807 * This function is called with IRQs disabled during early-boot on
74808 @@ -2915,6 +2914,46 @@ void *__kmalloc_node(size_t size, gfp_t
74809 EXPORT_SYMBOL(__kmalloc_node);
74810 #endif
74811
74812 +void check_object_size(const void *ptr, unsigned long n, bool to)
74813 +{
74814 +
74815 +#ifdef CONFIG_PAX_USERCOPY
74816 + struct page *page;
74817 + struct kmem_cache *s = NULL;
74818 + unsigned long offset;
74819 +
74820 + if (!n)
74821 + return;
74822 +
74823 + if (ZERO_OR_NULL_PTR(ptr))
74824 + goto report;
74825 +
74826 + if (!virt_addr_valid(ptr))
74827 + return;
74828 +
74829 + page = get_object_page(ptr);
74830 +
74831 + if (!page) {
74832 + if (object_is_on_stack(ptr, n) == -1)
74833 + goto report;
74834 + return;
74835 + }
74836 +
74837 + s = page->slab;
74838 + if (!(s->flags & SLAB_USERCOPY))
74839 + goto report;
74840 +
74841 + offset = (ptr - page_address(page)) % s->size;
74842 + if (offset <= s->objsize && n <= s->objsize - offset)
74843 + return;
74844 +
74845 +report:
74846 + pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
74847 +#endif
74848 +
74849 +}
74850 +EXPORT_SYMBOL(check_object_size);
74851 +
74852 size_t ksize(const void *object)
74853 {
74854 struct page *page;
74855 @@ -3185,8 +3224,8 @@ void __init kmem_cache_init(void)
74856 * kmem_cache_open for slab_state == DOWN.
74857 */
74858 create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
74859 - sizeof(struct kmem_cache_node), GFP_NOWAIT);
74860 - kmalloc_caches[0].refcount = -1;
74861 + sizeof(struct kmem_cache_node), GFP_NOWAIT, 0);
74862 + atomic_set(&kmalloc_caches[0].refcount, -1);
74863 caches++;
74864
74865 hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
74866 @@ -3198,18 +3237,18 @@ void __init kmem_cache_init(void)
74867 /* Caches that are not of the two-to-the-power-of size */
74868 if (KMALLOC_MIN_SIZE <= 32) {
74869 create_kmalloc_cache(&kmalloc_caches[1],
74870 - "kmalloc-96", 96, GFP_NOWAIT);
74871 + "kmalloc-96", 96, GFP_NOWAIT, SLAB_USERCOPY);
74872 caches++;
74873 }
74874 if (KMALLOC_MIN_SIZE <= 64) {
74875 create_kmalloc_cache(&kmalloc_caches[2],
74876 - "kmalloc-192", 192, GFP_NOWAIT);
74877 + "kmalloc-192", 192, GFP_NOWAIT, SLAB_USERCOPY);
74878 caches++;
74879 }
74880
74881 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74882 create_kmalloc_cache(&kmalloc_caches[i],
74883 - "kmalloc", 1 << i, GFP_NOWAIT);
74884 + "kmalloc", 1 << i, GFP_NOWAIT, SLAB_USERCOPY);
74885 caches++;
74886 }
74887
74888 @@ -3293,7 +3332,7 @@ static int slab_unmergeable(struct kmem_
74889 /*
74890 * We may have set a slab to be unmergeable during bootstrap.
74891 */
74892 - if (s->refcount < 0)
74893 + if (atomic_read(&s->refcount) < 0)
74894 return 1;
74895
74896 return 0;
74897 @@ -3353,7 +3392,7 @@ struct kmem_cache *kmem_cache_create(con
74898 if (s) {
74899 int cpu;
74900
74901 - s->refcount++;
74902 + atomic_inc(&s->refcount);
74903 /*
74904 * Adjust the object sizes so that we clear
74905 * the complete object on kzalloc.
74906 @@ -3372,7 +3411,7 @@ struct kmem_cache *kmem_cache_create(con
74907
74908 if (sysfs_slab_alias(s, name)) {
74909 down_write(&slub_lock);
74910 - s->refcount--;
74911 + atomic_dec(&s->refcount);
74912 up_write(&slub_lock);
74913 goto err;
74914 }
74915 @@ -4101,7 +4140,7 @@ SLAB_ATTR_RO(ctor);
74916
74917 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74918 {
74919 - return sprintf(buf, "%d\n", s->refcount - 1);
74920 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74921 }
74922 SLAB_ATTR_RO(aliases);
74923
74924 @@ -4503,7 +4542,7 @@ static void kmem_cache_release(struct ko
74925 kfree(s);
74926 }
74927
74928 -static struct sysfs_ops slab_sysfs_ops = {
74929 +static const struct sysfs_ops slab_sysfs_ops = {
74930 .show = slab_attr_show,
74931 .store = slab_attr_store,
74932 };
74933 @@ -4522,7 +4561,7 @@ static int uevent_filter(struct kset *ks
74934 return 0;
74935 }
74936
74937 -static struct kset_uevent_ops slab_uevent_ops = {
74938 +static const struct kset_uevent_ops slab_uevent_ops = {
74939 .filter = uevent_filter,
74940 };
74941
74942 @@ -4564,6 +4603,7 @@ static char *create_unique_id(struct kme
74943 return name;
74944 }
74945
74946 +#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74947 static int sysfs_slab_add(struct kmem_cache *s)
74948 {
74949 int err;
74950 @@ -4619,6 +4659,7 @@ static void sysfs_slab_remove(struct kme
74951 kobject_del(&s->kobj);
74952 kobject_put(&s->kobj);
74953 }
74954 +#endif
74955
74956 /*
74957 * Need to buffer aliases during bootup until sysfs becomes
74958 @@ -4632,6 +4673,7 @@ struct saved_alias {
74959
74960 static struct saved_alias *alias_list;
74961
74962 +#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74963 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74964 {
74965 struct saved_alias *al;
74966 @@ -4654,6 +4696,7 @@ static int sysfs_slab_alias(struct kmem_
74967 alias_list = al;
74968 return 0;
74969 }
74970 +#endif
74971
74972 static int __init slab_sysfs_init(void)
74973 {
74974 @@ -4785,7 +4828,13 @@ static const struct file_operations proc
74975
74976 static int __init slab_proc_init(void)
74977 {
74978 - proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
74979 + mode_t gr_mode = S_IRUGO;
74980 +
74981 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74982 + gr_mode = S_IRUSR;
74983 +#endif
74984 +
74985 + proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
74986 return 0;
74987 }
74988 module_init(slab_proc_init);
74989 diff -urNp linux-2.6.32.46/mm/swap.c linux-2.6.32.46/mm/swap.c
74990 --- linux-2.6.32.46/mm/swap.c 2011-03-27 14:31:47.000000000 -0400
74991 +++ linux-2.6.32.46/mm/swap.c 2011-07-09 09:15:19.000000000 -0400
74992 @@ -30,6 +30,7 @@
74993 #include <linux/notifier.h>
74994 #include <linux/backing-dev.h>
74995 #include <linux/memcontrol.h>
74996 +#include <linux/hugetlb.h>
74997
74998 #include "internal.h"
74999
75000 @@ -65,6 +66,8 @@ static void put_compound_page(struct pag
75001 compound_page_dtor *dtor;
75002
75003 dtor = get_compound_page_dtor(page);
75004 + if (!PageHuge(page))
75005 + BUG_ON(dtor != free_compound_page);
75006 (*dtor)(page);
75007 }
75008 }
75009 diff -urNp linux-2.6.32.46/mm/util.c linux-2.6.32.46/mm/util.c
75010 --- linux-2.6.32.46/mm/util.c 2011-03-27 14:31:47.000000000 -0400
75011 +++ linux-2.6.32.46/mm/util.c 2011-04-17 15:56:46.000000000 -0400
75012 @@ -228,6 +228,12 @@ EXPORT_SYMBOL(strndup_user);
75013 void arch_pick_mmap_layout(struct mm_struct *mm)
75014 {
75015 mm->mmap_base = TASK_UNMAPPED_BASE;
75016 +
75017 +#ifdef CONFIG_PAX_RANDMMAP
75018 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75019 + mm->mmap_base += mm->delta_mmap;
75020 +#endif
75021 +
75022 mm->get_unmapped_area = arch_get_unmapped_area;
75023 mm->unmap_area = arch_unmap_area;
75024 }
75025 diff -urNp linux-2.6.32.46/mm/vmalloc.c linux-2.6.32.46/mm/vmalloc.c
75026 --- linux-2.6.32.46/mm/vmalloc.c 2011-08-29 22:24:44.000000000 -0400
75027 +++ linux-2.6.32.46/mm/vmalloc.c 2011-08-29 22:25:07.000000000 -0400
75028 @@ -40,8 +40,19 @@ static void vunmap_pte_range(pmd_t *pmd,
75029
75030 pte = pte_offset_kernel(pmd, addr);
75031 do {
75032 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75033 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75034 +
75035 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75036 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75037 + BUG_ON(!pte_exec(*pte));
75038 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75039 + continue;
75040 + }
75041 +#endif
75042 +
75043 + {
75044 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75045 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75046 + }
75047 } while (pte++, addr += PAGE_SIZE, addr != end);
75048 }
75049
75050 @@ -92,6 +103,7 @@ static int vmap_pte_range(pmd_t *pmd, un
75051 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75052 {
75053 pte_t *pte;
75054 + int ret = -ENOMEM;
75055
75056 /*
75057 * nr is a running index into the array which helps higher level
75058 @@ -101,17 +113,32 @@ static int vmap_pte_range(pmd_t *pmd, un
75059 pte = pte_alloc_kernel(pmd, addr);
75060 if (!pte)
75061 return -ENOMEM;
75062 +
75063 + pax_open_kernel();
75064 do {
75065 struct page *page = pages[*nr];
75066
75067 - if (WARN_ON(!pte_none(*pte)))
75068 - return -EBUSY;
75069 - if (WARN_ON(!page))
75070 - return -ENOMEM;
75071 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75072 + if (!(pgprot_val(prot) & _PAGE_NX))
75073 + BUG_ON(!pte_exec(*pte) || pte_pfn(*pte) != __pa(addr) >> PAGE_SHIFT);
75074 + else
75075 +#endif
75076 +
75077 + if (WARN_ON(!pte_none(*pte))) {
75078 + ret = -EBUSY;
75079 + goto out;
75080 + }
75081 + if (WARN_ON(!page)) {
75082 + ret = -ENOMEM;
75083 + goto out;
75084 + }
75085 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75086 (*nr)++;
75087 } while (pte++, addr += PAGE_SIZE, addr != end);
75088 - return 0;
75089 + ret = 0;
75090 +out:
75091 + pax_close_kernel();
75092 + return ret;
75093 }
75094
75095 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75096 @@ -192,11 +219,20 @@ int is_vmalloc_or_module_addr(const void
75097 * and fall back on vmalloc() if that fails. Others
75098 * just put it in the vmalloc space.
75099 */
75100 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75101 +#ifdef CONFIG_MODULES
75102 +#ifdef MODULES_VADDR
75103 unsigned long addr = (unsigned long)x;
75104 if (addr >= MODULES_VADDR && addr < MODULES_END)
75105 return 1;
75106 #endif
75107 +
75108 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75109 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75110 + return 1;
75111 +#endif
75112 +
75113 +#endif
75114 +
75115 return is_vmalloc_addr(x);
75116 }
75117
75118 @@ -217,8 +253,14 @@ struct page *vmalloc_to_page(const void
75119
75120 if (!pgd_none(*pgd)) {
75121 pud_t *pud = pud_offset(pgd, addr);
75122 +#ifdef CONFIG_X86
75123 + if (!pud_large(*pud))
75124 +#endif
75125 if (!pud_none(*pud)) {
75126 pmd_t *pmd = pmd_offset(pud, addr);
75127 +#ifdef CONFIG_X86
75128 + if (!pmd_large(*pmd))
75129 +#endif
75130 if (!pmd_none(*pmd)) {
75131 pte_t *ptep, pte;
75132
75133 @@ -292,13 +334,13 @@ static void __insert_vmap_area(struct vm
75134 struct rb_node *tmp;
75135
75136 while (*p) {
75137 - struct vmap_area *tmp;
75138 + struct vmap_area *varea;
75139
75140 parent = *p;
75141 - tmp = rb_entry(parent, struct vmap_area, rb_node);
75142 - if (va->va_start < tmp->va_end)
75143 + varea = rb_entry(parent, struct vmap_area, rb_node);
75144 + if (va->va_start < varea->va_end)
75145 p = &(*p)->rb_left;
75146 - else if (va->va_end > tmp->va_start)
75147 + else if (va->va_end > varea->va_start)
75148 p = &(*p)->rb_right;
75149 else
75150 BUG();
75151 @@ -1233,6 +1275,16 @@ static struct vm_struct *__get_vm_area_n
75152 struct vm_struct *area;
75153
75154 BUG_ON(in_interrupt());
75155 +
75156 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75157 + if (flags & VM_KERNEXEC) {
75158 + if (start != VMALLOC_START || end != VMALLOC_END)
75159 + return NULL;
75160 + start = (unsigned long)MODULES_EXEC_VADDR;
75161 + end = (unsigned long)MODULES_EXEC_END;
75162 + }
75163 +#endif
75164 +
75165 if (flags & VM_IOREMAP) {
75166 int bit = fls(size);
75167
75168 @@ -1458,6 +1510,11 @@ void *vmap(struct page **pages, unsigned
75169 if (count > totalram_pages)
75170 return NULL;
75171
75172 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75173 + if (!(pgprot_val(prot) & _PAGE_NX))
75174 + flags |= VM_KERNEXEC;
75175 +#endif
75176 +
75177 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75178 __builtin_return_address(0));
75179 if (!area)
75180 @@ -1568,6 +1625,13 @@ static void *__vmalloc_node(unsigned lon
75181 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75182 return NULL;
75183
75184 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75185 + if (!(pgprot_val(prot) & _PAGE_NX))
75186 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
75187 + node, gfp_mask, caller);
75188 + else
75189 +#endif
75190 +
75191 area = __get_vm_area_node(size, align, VM_ALLOC, VMALLOC_START,
75192 VMALLOC_END, node, gfp_mask, caller);
75193
75194 @@ -1586,6 +1650,7 @@ static void *__vmalloc_node(unsigned lon
75195 return addr;
75196 }
75197
75198 +#undef __vmalloc
75199 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
75200 {
75201 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
75202 @@ -1602,6 +1667,7 @@ EXPORT_SYMBOL(__vmalloc);
75203 * For tight control over page level allocator and protection flags
75204 * use __vmalloc() instead.
75205 */
75206 +#undef vmalloc
75207 void *vmalloc(unsigned long size)
75208 {
75209 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
75210 @@ -1616,6 +1682,7 @@ EXPORT_SYMBOL(vmalloc);
75211 * The resulting memory area is zeroed so it can be mapped to userspace
75212 * without leaking data.
75213 */
75214 +#undef vmalloc_user
75215 void *vmalloc_user(unsigned long size)
75216 {
75217 struct vm_struct *area;
75218 @@ -1643,6 +1710,7 @@ EXPORT_SYMBOL(vmalloc_user);
75219 * For tight control over page level allocator and protection flags
75220 * use __vmalloc() instead.
75221 */
75222 +#undef vmalloc_node
75223 void *vmalloc_node(unsigned long size, int node)
75224 {
75225 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
75226 @@ -1665,10 +1733,10 @@ EXPORT_SYMBOL(vmalloc_node);
75227 * For tight control over page level allocator and protection flags
75228 * use __vmalloc() instead.
75229 */
75230 -
75231 +#undef vmalloc_exec
75232 void *vmalloc_exec(unsigned long size)
75233 {
75234 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75235 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75236 -1, __builtin_return_address(0));
75237 }
75238
75239 @@ -1687,6 +1755,7 @@ void *vmalloc_exec(unsigned long size)
75240 * Allocate enough 32bit PA addressable pages to cover @size from the
75241 * page level allocator and map them into contiguous kernel virtual space.
75242 */
75243 +#undef vmalloc_32
75244 void *vmalloc_32(unsigned long size)
75245 {
75246 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
75247 @@ -1701,6 +1770,7 @@ EXPORT_SYMBOL(vmalloc_32);
75248 * The resulting memory area is 32bit addressable and zeroed so it can be
75249 * mapped to userspace without leaking data.
75250 */
75251 +#undef vmalloc_32_user
75252 void *vmalloc_32_user(unsigned long size)
75253 {
75254 struct vm_struct *area;
75255 @@ -1965,6 +2035,8 @@ int remap_vmalloc_range(struct vm_area_s
75256 unsigned long uaddr = vma->vm_start;
75257 unsigned long usize = vma->vm_end - vma->vm_start;
75258
75259 + BUG_ON(vma->vm_mirror);
75260 +
75261 if ((PAGE_SIZE-1) & (unsigned long)addr)
75262 return -EINVAL;
75263
75264 diff -urNp linux-2.6.32.46/mm/vmstat.c linux-2.6.32.46/mm/vmstat.c
75265 --- linux-2.6.32.46/mm/vmstat.c 2011-03-27 14:31:47.000000000 -0400
75266 +++ linux-2.6.32.46/mm/vmstat.c 2011-04-17 15:56:46.000000000 -0400
75267 @@ -74,7 +74,7 @@ void vm_events_fold_cpu(int cpu)
75268 *
75269 * vm_stat contains the global counters
75270 */
75271 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75272 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75273 EXPORT_SYMBOL(vm_stat);
75274
75275 #ifdef CONFIG_SMP
75276 @@ -324,7 +324,7 @@ void refresh_cpu_vm_stats(int cpu)
75277 v = p->vm_stat_diff[i];
75278 p->vm_stat_diff[i] = 0;
75279 local_irq_restore(flags);
75280 - atomic_long_add(v, &zone->vm_stat[i]);
75281 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75282 global_diff[i] += v;
75283 #ifdef CONFIG_NUMA
75284 /* 3 seconds idle till flush */
75285 @@ -362,7 +362,7 @@ void refresh_cpu_vm_stats(int cpu)
75286
75287 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75288 if (global_diff[i])
75289 - atomic_long_add(global_diff[i], &vm_stat[i]);
75290 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75291 }
75292
75293 #endif
75294 @@ -953,10 +953,20 @@ static int __init setup_vmstat(void)
75295 start_cpu_timer(cpu);
75296 #endif
75297 #ifdef CONFIG_PROC_FS
75298 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75299 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75300 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75301 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75302 + {
75303 + mode_t gr_mode = S_IRUGO;
75304 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75305 + gr_mode = S_IRUSR;
75306 +#endif
75307 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75308 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75309 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75310 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75311 +#else
75312 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75313 +#endif
75314 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75315 + }
75316 #endif
75317 return 0;
75318 }
75319 diff -urNp linux-2.6.32.46/net/8021q/vlan.c linux-2.6.32.46/net/8021q/vlan.c
75320 --- linux-2.6.32.46/net/8021q/vlan.c 2011-03-27 14:31:47.000000000 -0400
75321 +++ linux-2.6.32.46/net/8021q/vlan.c 2011-04-17 15:56:46.000000000 -0400
75322 @@ -622,8 +622,7 @@ static int vlan_ioctl_handler(struct net
75323 err = -EPERM;
75324 if (!capable(CAP_NET_ADMIN))
75325 break;
75326 - if ((args.u.name_type >= 0) &&
75327 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75328 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75329 struct vlan_net *vn;
75330
75331 vn = net_generic(net, vlan_net_id);
75332 diff -urNp linux-2.6.32.46/net/9p/trans_fd.c linux-2.6.32.46/net/9p/trans_fd.c
75333 --- linux-2.6.32.46/net/9p/trans_fd.c 2011-03-27 14:31:47.000000000 -0400
75334 +++ linux-2.6.32.46/net/9p/trans_fd.c 2011-10-06 09:37:14.000000000 -0400
75335 @@ -419,7 +419,7 @@ static int p9_fd_write(struct p9_client
75336 oldfs = get_fs();
75337 set_fs(get_ds());
75338 /* The cast to a user pointer is valid due to the set_fs() */
75339 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75340 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75341 set_fs(oldfs);
75342
75343 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75344 diff -urNp linux-2.6.32.46/net/atm/atm_misc.c linux-2.6.32.46/net/atm/atm_misc.c
75345 --- linux-2.6.32.46/net/atm/atm_misc.c 2011-03-27 14:31:47.000000000 -0400
75346 +++ linux-2.6.32.46/net/atm/atm_misc.c 2011-04-17 15:56:46.000000000 -0400
75347 @@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int t
75348 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75349 return 1;
75350 atm_return(vcc,truesize);
75351 - atomic_inc(&vcc->stats->rx_drop);
75352 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75353 return 0;
75354 }
75355
75356 @@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct
75357 }
75358 }
75359 atm_return(vcc,guess);
75360 - atomic_inc(&vcc->stats->rx_drop);
75361 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75362 return NULL;
75363 }
75364
75365 @@ -88,7 +88,7 @@ int atm_pcr_goal(const struct atm_trafpr
75366
75367 void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
75368 {
75369 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75370 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75371 __SONET_ITEMS
75372 #undef __HANDLE_ITEM
75373 }
75374 @@ -96,7 +96,7 @@ void sonet_copy_stats(struct k_sonet_sta
75375
75376 void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
75377 {
75378 -#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
75379 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75380 __SONET_ITEMS
75381 #undef __HANDLE_ITEM
75382 }
75383 diff -urNp linux-2.6.32.46/net/atm/lec.h linux-2.6.32.46/net/atm/lec.h
75384 --- linux-2.6.32.46/net/atm/lec.h 2011-03-27 14:31:47.000000000 -0400
75385 +++ linux-2.6.32.46/net/atm/lec.h 2011-08-05 20:33:55.000000000 -0400
75386 @@ -48,7 +48,7 @@ struct lane2_ops {
75387 const u8 *tlvs, u32 sizeoftlvs);
75388 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75389 const u8 *tlvs, u32 sizeoftlvs);
75390 -};
75391 +} __no_const;
75392
75393 /*
75394 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75395 diff -urNp linux-2.6.32.46/net/atm/mpc.h linux-2.6.32.46/net/atm/mpc.h
75396 --- linux-2.6.32.46/net/atm/mpc.h 2011-03-27 14:31:47.000000000 -0400
75397 +++ linux-2.6.32.46/net/atm/mpc.h 2011-08-23 21:22:38.000000000 -0400
75398 @@ -33,7 +33,7 @@ struct mpoa_client {
75399 struct mpc_parameters parameters; /* parameters for this client */
75400
75401 const struct net_device_ops *old_ops;
75402 - struct net_device_ops new_ops;
75403 + net_device_ops_no_const new_ops;
75404 };
75405
75406
75407 diff -urNp linux-2.6.32.46/net/atm/mpoa_caches.c linux-2.6.32.46/net/atm/mpoa_caches.c
75408 --- linux-2.6.32.46/net/atm/mpoa_caches.c 2011-03-27 14:31:47.000000000 -0400
75409 +++ linux-2.6.32.46/net/atm/mpoa_caches.c 2011-05-16 21:46:57.000000000 -0400
75410 @@ -498,6 +498,8 @@ static void clear_expired(struct mpoa_cl
75411 struct timeval now;
75412 struct k_message msg;
75413
75414 + pax_track_stack();
75415 +
75416 do_gettimeofday(&now);
75417
75418 write_lock_irq(&client->egress_lock);
75419 diff -urNp linux-2.6.32.46/net/atm/proc.c linux-2.6.32.46/net/atm/proc.c
75420 --- linux-2.6.32.46/net/atm/proc.c 2011-03-27 14:31:47.000000000 -0400
75421 +++ linux-2.6.32.46/net/atm/proc.c 2011-04-17 15:56:46.000000000 -0400
75422 @@ -43,9 +43,9 @@ static void add_stats(struct seq_file *s
75423 const struct k_atm_aal_stats *stats)
75424 {
75425 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75426 - atomic_read(&stats->tx),atomic_read(&stats->tx_err),
75427 - atomic_read(&stats->rx),atomic_read(&stats->rx_err),
75428 - atomic_read(&stats->rx_drop));
75429 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75430 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75431 + atomic_read_unchecked(&stats->rx_drop));
75432 }
75433
75434 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75435 @@ -188,7 +188,12 @@ static void vcc_info(struct seq_file *se
75436 {
75437 struct sock *sk = sk_atm(vcc);
75438
75439 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75440 + seq_printf(seq, "%p ", NULL);
75441 +#else
75442 seq_printf(seq, "%p ", vcc);
75443 +#endif
75444 +
75445 if (!vcc->dev)
75446 seq_printf(seq, "Unassigned ");
75447 else
75448 @@ -214,7 +219,11 @@ static void svc_info(struct seq_file *se
75449 {
75450 if (!vcc->dev)
75451 seq_printf(seq, sizeof(void *) == 4 ?
75452 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75453 + "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
75454 +#else
75455 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
75456 +#endif
75457 else
75458 seq_printf(seq, "%3d %3d %5d ",
75459 vcc->dev->number, vcc->vpi, vcc->vci);
75460 diff -urNp linux-2.6.32.46/net/atm/resources.c linux-2.6.32.46/net/atm/resources.c
75461 --- linux-2.6.32.46/net/atm/resources.c 2011-03-27 14:31:47.000000000 -0400
75462 +++ linux-2.6.32.46/net/atm/resources.c 2011-04-17 15:56:46.000000000 -0400
75463 @@ -161,7 +161,7 @@ void atm_dev_deregister(struct atm_dev *
75464 static void copy_aal_stats(struct k_atm_aal_stats *from,
75465 struct atm_aal_stats *to)
75466 {
75467 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75468 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75469 __AAL_STAT_ITEMS
75470 #undef __HANDLE_ITEM
75471 }
75472 @@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_
75473 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75474 struct atm_aal_stats *to)
75475 {
75476 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75477 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75478 __AAL_STAT_ITEMS
75479 #undef __HANDLE_ITEM
75480 }
75481 diff -urNp linux-2.6.32.46/net/bluetooth/l2cap.c linux-2.6.32.46/net/bluetooth/l2cap.c
75482 --- linux-2.6.32.46/net/bluetooth/l2cap.c 2011-03-27 14:31:47.000000000 -0400
75483 +++ linux-2.6.32.46/net/bluetooth/l2cap.c 2011-06-25 14:36:21.000000000 -0400
75484 @@ -1885,7 +1885,7 @@ static int l2cap_sock_getsockopt_old(str
75485 err = -ENOTCONN;
75486 break;
75487 }
75488 -
75489 + memset(&cinfo, 0, sizeof(cinfo));
75490 cinfo.hci_handle = l2cap_pi(sk)->conn->hcon->handle;
75491 memcpy(cinfo.dev_class, l2cap_pi(sk)->conn->hcon->dev_class, 3);
75492
75493 @@ -2719,7 +2719,7 @@ static inline int l2cap_config_req(struc
75494
75495 /* Reject if config buffer is too small. */
75496 len = cmd_len - sizeof(*req);
75497 - if (l2cap_pi(sk)->conf_len + len > sizeof(l2cap_pi(sk)->conf_req)) {
75498 + if (len < 0 || l2cap_pi(sk)->conf_len + len > sizeof(l2cap_pi(sk)->conf_req)) {
75499 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
75500 l2cap_build_conf_rsp(sk, rsp,
75501 L2CAP_CONF_REJECT, flags), rsp);
75502 diff -urNp linux-2.6.32.46/net/bluetooth/rfcomm/sock.c linux-2.6.32.46/net/bluetooth/rfcomm/sock.c
75503 --- linux-2.6.32.46/net/bluetooth/rfcomm/sock.c 2011-03-27 14:31:47.000000000 -0400
75504 +++ linux-2.6.32.46/net/bluetooth/rfcomm/sock.c 2011-06-12 06:35:00.000000000 -0400
75505 @@ -878,6 +878,7 @@ static int rfcomm_sock_getsockopt_old(st
75506
75507 l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;
75508
75509 + memset(&cinfo, 0, sizeof(cinfo));
75510 cinfo.hci_handle = l2cap_pi(l2cap_sk)->conn->hcon->handle;
75511 memcpy(cinfo.dev_class, l2cap_pi(l2cap_sk)->conn->hcon->dev_class, 3);
75512
75513 diff -urNp linux-2.6.32.46/net/bridge/br_private.h linux-2.6.32.46/net/bridge/br_private.h
75514 --- linux-2.6.32.46/net/bridge/br_private.h 2011-08-09 18:35:30.000000000 -0400
75515 +++ linux-2.6.32.46/net/bridge/br_private.h 2011-08-09 18:34:01.000000000 -0400
75516 @@ -255,7 +255,7 @@ extern void br_ifinfo_notify(int event,
75517
75518 #ifdef CONFIG_SYSFS
75519 /* br_sysfs_if.c */
75520 -extern struct sysfs_ops brport_sysfs_ops;
75521 +extern const struct sysfs_ops brport_sysfs_ops;
75522 extern int br_sysfs_addif(struct net_bridge_port *p);
75523
75524 /* br_sysfs_br.c */
75525 diff -urNp linux-2.6.32.46/net/bridge/br_stp_if.c linux-2.6.32.46/net/bridge/br_stp_if.c
75526 --- linux-2.6.32.46/net/bridge/br_stp_if.c 2011-03-27 14:31:47.000000000 -0400
75527 +++ linux-2.6.32.46/net/bridge/br_stp_if.c 2011-04-17 15:56:46.000000000 -0400
75528 @@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg
75529 char *envp[] = { NULL };
75530
75531 if (br->stp_enabled == BR_USER_STP) {
75532 - r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
75533 + r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
75534 printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
75535 br->dev->name, r);
75536
75537 diff -urNp linux-2.6.32.46/net/bridge/br_sysfs_if.c linux-2.6.32.46/net/bridge/br_sysfs_if.c
75538 --- linux-2.6.32.46/net/bridge/br_sysfs_if.c 2011-03-27 14:31:47.000000000 -0400
75539 +++ linux-2.6.32.46/net/bridge/br_sysfs_if.c 2011-04-17 15:56:46.000000000 -0400
75540 @@ -220,7 +220,7 @@ static ssize_t brport_store(struct kobje
75541 return ret;
75542 }
75543
75544 -struct sysfs_ops brport_sysfs_ops = {
75545 +const struct sysfs_ops brport_sysfs_ops = {
75546 .show = brport_show,
75547 .store = brport_store,
75548 };
75549 diff -urNp linux-2.6.32.46/net/bridge/netfilter/ebtables.c linux-2.6.32.46/net/bridge/netfilter/ebtables.c
75550 --- linux-2.6.32.46/net/bridge/netfilter/ebtables.c 2011-04-17 17:00:52.000000000 -0400
75551 +++ linux-2.6.32.46/net/bridge/netfilter/ebtables.c 2011-05-16 21:46:57.000000000 -0400
75552 @@ -1337,6 +1337,8 @@ static int copy_everything_to_user(struc
75553 unsigned int entries_size, nentries;
75554 char *entries;
75555
75556 + pax_track_stack();
75557 +
75558 if (cmd == EBT_SO_GET_ENTRIES) {
75559 entries_size = t->private->entries_size;
75560 nentries = t->private->nentries;
75561 diff -urNp linux-2.6.32.46/net/can/bcm.c linux-2.6.32.46/net/can/bcm.c
75562 --- linux-2.6.32.46/net/can/bcm.c 2011-05-10 22:12:01.000000000 -0400
75563 +++ linux-2.6.32.46/net/can/bcm.c 2011-05-10 22:12:34.000000000 -0400
75564 @@ -164,9 +164,15 @@ static int bcm_proc_show(struct seq_file
75565 struct bcm_sock *bo = bcm_sk(sk);
75566 struct bcm_op *op;
75567
75568 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75569 + seq_printf(m, ">>> socket %p", NULL);
75570 + seq_printf(m, " / sk %p", NULL);
75571 + seq_printf(m, " / bo %p", NULL);
75572 +#else
75573 seq_printf(m, ">>> socket %p", sk->sk_socket);
75574 seq_printf(m, " / sk %p", sk);
75575 seq_printf(m, " / bo %p", bo);
75576 +#endif
75577 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
75578 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
75579 seq_printf(m, " <<<\n");
75580 diff -urNp linux-2.6.32.46/net/compat.c linux-2.6.32.46/net/compat.c
75581 --- linux-2.6.32.46/net/compat.c 2011-03-27 14:31:47.000000000 -0400
75582 +++ linux-2.6.32.46/net/compat.c 2011-10-06 09:37:14.000000000 -0400
75583 @@ -69,9 +69,9 @@ int get_compat_msghdr(struct msghdr *kms
75584 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75585 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75586 return -EFAULT;
75587 - kmsg->msg_name = compat_ptr(tmp1);
75588 - kmsg->msg_iov = compat_ptr(tmp2);
75589 - kmsg->msg_control = compat_ptr(tmp3);
75590 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75591 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75592 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75593 return 0;
75594 }
75595
75596 @@ -94,7 +94,7 @@ int verify_compat_iovec(struct msghdr *k
75597 kern_msg->msg_name = NULL;
75598
75599 tot_len = iov_from_user_compat_to_kern(kern_iov,
75600 - (struct compat_iovec __user *)kern_msg->msg_iov,
75601 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75602 kern_msg->msg_iovlen);
75603 if (tot_len >= 0)
75604 kern_msg->msg_iov = kern_iov;
75605 @@ -114,20 +114,20 @@ int verify_compat_iovec(struct msghdr *k
75606
75607 #define CMSG_COMPAT_FIRSTHDR(msg) \
75608 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75609 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75610 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75611 (struct compat_cmsghdr __user *)NULL)
75612
75613 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75614 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75615 (ucmlen) <= (unsigned long) \
75616 ((mhdr)->msg_controllen - \
75617 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75618 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75619
75620 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75621 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75622 {
75623 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75624 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75625 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75626 msg->msg_controllen)
75627 return NULL;
75628 return (struct compat_cmsghdr __user *)ptr;
75629 @@ -219,7 +219,7 @@ int put_cmsg_compat(struct msghdr *kmsg,
75630 {
75631 struct compat_timeval ctv;
75632 struct compat_timespec cts[3];
75633 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75634 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75635 struct compat_cmsghdr cmhdr;
75636 int cmlen;
75637
75638 @@ -271,7 +271,7 @@ int put_cmsg_compat(struct msghdr *kmsg,
75639
75640 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75641 {
75642 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75643 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75644 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75645 int fdnum = scm->fp->count;
75646 struct file **fp = scm->fp->fp;
75647 @@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct so
75648 len = sizeof(ktime);
75649 old_fs = get_fs();
75650 set_fs(KERNEL_DS);
75651 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75652 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75653 set_fs(old_fs);
75654
75655 if (!err) {
75656 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *so
75657 case MCAST_JOIN_GROUP:
75658 case MCAST_LEAVE_GROUP:
75659 {
75660 - struct compat_group_req __user *gr32 = (void *)optval;
75661 + struct compat_group_req __user *gr32 = (void __user *)optval;
75662 struct group_req __user *kgr =
75663 compat_alloc_user_space(sizeof(struct group_req));
75664 u32 interface;
75665 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *so
75666 case MCAST_BLOCK_SOURCE:
75667 case MCAST_UNBLOCK_SOURCE:
75668 {
75669 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75670 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75671 struct group_source_req __user *kgsr = compat_alloc_user_space(
75672 sizeof(struct group_source_req));
75673 u32 interface;
75674 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *so
75675 }
75676 case MCAST_MSFILTER:
75677 {
75678 - struct compat_group_filter __user *gf32 = (void *)optval;
75679 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75680 struct group_filter __user *kgf;
75681 u32 interface, fmode, numsrc;
75682
75683 diff -urNp linux-2.6.32.46/net/core/dev.c linux-2.6.32.46/net/core/dev.c
75684 --- linux-2.6.32.46/net/core/dev.c 2011-04-17 17:00:52.000000000 -0400
75685 +++ linux-2.6.32.46/net/core/dev.c 2011-08-05 20:33:55.000000000 -0400
75686 @@ -1047,10 +1047,14 @@ void dev_load(struct net *net, const cha
75687 if (no_module && capable(CAP_NET_ADMIN))
75688 no_module = request_module("netdev-%s", name);
75689 if (no_module && capable(CAP_SYS_MODULE)) {
75690 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75691 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75692 +#else
75693 if (!request_module("%s", name))
75694 pr_err("Loading kernel module for a network device "
75695 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75696 "instead\n", name);
75697 +#endif
75698 }
75699 }
75700 EXPORT_SYMBOL(dev_load);
75701 @@ -1654,7 +1658,7 @@ static inline int illegal_highdma(struct
75702
75703 struct dev_gso_cb {
75704 void (*destructor)(struct sk_buff *skb);
75705 -};
75706 +} __no_const;
75707
75708 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75709
75710 @@ -2063,7 +2067,7 @@ int netif_rx_ni(struct sk_buff *skb)
75711 }
75712 EXPORT_SYMBOL(netif_rx_ni);
75713
75714 -static void net_tx_action(struct softirq_action *h)
75715 +static void net_tx_action(void)
75716 {
75717 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75718
75719 @@ -2826,7 +2830,7 @@ void netif_napi_del(struct napi_struct *
75720 EXPORT_SYMBOL(netif_napi_del);
75721
75722
75723 -static void net_rx_action(struct softirq_action *h)
75724 +static void net_rx_action(void)
75725 {
75726 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
75727 unsigned long time_limit = jiffies + 2;
75728 diff -urNp linux-2.6.32.46/net/core/flow.c linux-2.6.32.46/net/core/flow.c
75729 --- linux-2.6.32.46/net/core/flow.c 2011-03-27 14:31:47.000000000 -0400
75730 +++ linux-2.6.32.46/net/core/flow.c 2011-05-04 17:56:20.000000000 -0400
75731 @@ -35,11 +35,11 @@ struct flow_cache_entry {
75732 atomic_t *object_ref;
75733 };
75734
75735 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75736 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75737
75738 static u32 flow_hash_shift;
75739 #define flow_hash_size (1 << flow_hash_shift)
75740 -static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
75741 +static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
75742
75743 #define flow_table(cpu) (per_cpu(flow_tables, cpu))
75744
75745 @@ -52,7 +52,7 @@ struct flow_percpu_info {
75746 u32 hash_rnd;
75747 int count;
75748 };
75749 -static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
75750 +static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
75751
75752 #define flow_hash_rnd_recalc(cpu) \
75753 (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
75754 @@ -69,7 +69,7 @@ struct flow_flush_info {
75755 atomic_t cpuleft;
75756 struct completion completion;
75757 };
75758 -static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
75759 +static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
75760
75761 #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
75762
75763 @@ -190,7 +190,7 @@ void *flow_cache_lookup(struct net *net,
75764 if (fle->family == family &&
75765 fle->dir == dir &&
75766 flow_key_compare(key, &fle->key) == 0) {
75767 - if (fle->genid == atomic_read(&flow_cache_genid)) {
75768 + if (fle->genid == atomic_read_unchecked(&flow_cache_genid)) {
75769 void *ret = fle->object;
75770
75771 if (ret)
75772 @@ -228,7 +228,7 @@ nocache:
75773 err = resolver(net, key, family, dir, &obj, &obj_ref);
75774
75775 if (fle && !err) {
75776 - fle->genid = atomic_read(&flow_cache_genid);
75777 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75778
75779 if (fle->object)
75780 atomic_dec(fle->object_ref);
75781 @@ -258,7 +258,7 @@ static void flow_cache_flush_tasklet(uns
75782
75783 fle = flow_table(cpu)[i];
75784 for (; fle; fle = fle->next) {
75785 - unsigned genid = atomic_read(&flow_cache_genid);
75786 + unsigned genid = atomic_read_unchecked(&flow_cache_genid);
75787
75788 if (!fle->object || fle->genid == genid)
75789 continue;
75790 diff -urNp linux-2.6.32.46/net/core/rtnetlink.c linux-2.6.32.46/net/core/rtnetlink.c
75791 --- linux-2.6.32.46/net/core/rtnetlink.c 2011-03-27 14:31:47.000000000 -0400
75792 +++ linux-2.6.32.46/net/core/rtnetlink.c 2011-08-05 20:33:55.000000000 -0400
75793 @@ -57,7 +57,7 @@ struct rtnl_link
75794 {
75795 rtnl_doit_func doit;
75796 rtnl_dumpit_func dumpit;
75797 -};
75798 +} __no_const;
75799
75800 static DEFINE_MUTEX(rtnl_mutex);
75801
75802 diff -urNp linux-2.6.32.46/net/core/scm.c linux-2.6.32.46/net/core/scm.c
75803 --- linux-2.6.32.46/net/core/scm.c 2011-03-27 14:31:47.000000000 -0400
75804 +++ linux-2.6.32.46/net/core/scm.c 2011-10-06 09:37:14.000000000 -0400
75805 @@ -190,7 +190,7 @@ error:
75806 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75807 {
75808 struct cmsghdr __user *cm
75809 - = (__force struct cmsghdr __user *)msg->msg_control;
75810 + = (struct cmsghdr __force_user *)msg->msg_control;
75811 struct cmsghdr cmhdr;
75812 int cmlen = CMSG_LEN(len);
75813 int err;
75814 @@ -213,7 +213,7 @@ int put_cmsg(struct msghdr * msg, int le
75815 err = -EFAULT;
75816 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75817 goto out;
75818 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75819 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75820 goto out;
75821 cmlen = CMSG_SPACE(len);
75822 if (msg->msg_controllen < cmlen)
75823 @@ -228,7 +228,7 @@ out:
75824 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75825 {
75826 struct cmsghdr __user *cm
75827 - = (__force struct cmsghdr __user*)msg->msg_control;
75828 + = (struct cmsghdr __force_user *)msg->msg_control;
75829
75830 int fdmax = 0;
75831 int fdnum = scm->fp->count;
75832 @@ -248,7 +248,7 @@ void scm_detach_fds(struct msghdr *msg,
75833 if (fdnum < fdmax)
75834 fdmax = fdnum;
75835
75836 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75837 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75838 i++, cmfptr++)
75839 {
75840 int new_fd;
75841 diff -urNp linux-2.6.32.46/net/core/secure_seq.c linux-2.6.32.46/net/core/secure_seq.c
75842 --- linux-2.6.32.46/net/core/secure_seq.c 2011-08-16 20:37:25.000000000 -0400
75843 +++ linux-2.6.32.46/net/core/secure_seq.c 2011-08-07 19:48:09.000000000 -0400
75844 @@ -57,7 +57,7 @@ __u32 secure_tcpv6_sequence_number(__be3
75845 EXPORT_SYMBOL(secure_tcpv6_sequence_number);
75846
75847 u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
75848 - __be16 dport)
75849 + __be16 dport)
75850 {
75851 u32 secret[MD5_MESSAGE_BYTES / 4];
75852 u32 hash[MD5_DIGEST_WORDS];
75853 @@ -71,7 +71,6 @@ u32 secure_ipv6_port_ephemeral(const __b
75854 secret[i] = net_secret[i];
75855
75856 md5_transform(hash, secret);
75857 -
75858 return hash[0];
75859 }
75860 #endif
75861 diff -urNp linux-2.6.32.46/net/core/skbuff.c linux-2.6.32.46/net/core/skbuff.c
75862 --- linux-2.6.32.46/net/core/skbuff.c 2011-03-27 14:31:47.000000000 -0400
75863 +++ linux-2.6.32.46/net/core/skbuff.c 2011-05-16 21:46:57.000000000 -0400
75864 @@ -1544,6 +1544,8 @@ int skb_splice_bits(struct sk_buff *skb,
75865 struct sk_buff *frag_iter;
75866 struct sock *sk = skb->sk;
75867
75868 + pax_track_stack();
75869 +
75870 /*
75871 * __skb_splice_bits() only fails if the output has no room left,
75872 * so no point in going over the frag_list for the error case.
75873 diff -urNp linux-2.6.32.46/net/core/sock.c linux-2.6.32.46/net/core/sock.c
75874 --- linux-2.6.32.46/net/core/sock.c 2011-03-27 14:31:47.000000000 -0400
75875 +++ linux-2.6.32.46/net/core/sock.c 2011-05-04 17:56:20.000000000 -0400
75876 @@ -864,11 +864,15 @@ int sock_getsockopt(struct socket *sock,
75877 break;
75878
75879 case SO_PEERCRED:
75880 + {
75881 + struct ucred peercred;
75882 if (len > sizeof(sk->sk_peercred))
75883 len = sizeof(sk->sk_peercred);
75884 - if (copy_to_user(optval, &sk->sk_peercred, len))
75885 + peercred = sk->sk_peercred;
75886 + if (copy_to_user(optval, &peercred, len))
75887 return -EFAULT;
75888 goto lenout;
75889 + }
75890
75891 case SO_PEERNAME:
75892 {
75893 @@ -1892,7 +1896,7 @@ void sock_init_data(struct socket *sock,
75894 */
75895 smp_wmb();
75896 atomic_set(&sk->sk_refcnt, 1);
75897 - atomic_set(&sk->sk_drops, 0);
75898 + atomic_set_unchecked(&sk->sk_drops, 0);
75899 }
75900 EXPORT_SYMBOL(sock_init_data);
75901
75902 diff -urNp linux-2.6.32.46/net/decnet/sysctl_net_decnet.c linux-2.6.32.46/net/decnet/sysctl_net_decnet.c
75903 --- linux-2.6.32.46/net/decnet/sysctl_net_decnet.c 2011-03-27 14:31:47.000000000 -0400
75904 +++ linux-2.6.32.46/net/decnet/sysctl_net_decnet.c 2011-04-17 15:56:46.000000000 -0400
75905 @@ -206,7 +206,7 @@ static int dn_node_address_handler(ctl_t
75906
75907 if (len > *lenp) len = *lenp;
75908
75909 - if (copy_to_user(buffer, addr, len))
75910 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75911 return -EFAULT;
75912
75913 *lenp = len;
75914 @@ -327,7 +327,7 @@ static int dn_def_dev_handler(ctl_table
75915
75916 if (len > *lenp) len = *lenp;
75917
75918 - if (copy_to_user(buffer, devname, len))
75919 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75920 return -EFAULT;
75921
75922 *lenp = len;
75923 diff -urNp linux-2.6.32.46/net/econet/Kconfig linux-2.6.32.46/net/econet/Kconfig
75924 --- linux-2.6.32.46/net/econet/Kconfig 2011-03-27 14:31:47.000000000 -0400
75925 +++ linux-2.6.32.46/net/econet/Kconfig 2011-04-17 15:56:46.000000000 -0400
75926 @@ -4,7 +4,7 @@
75927
75928 config ECONET
75929 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75930 - depends on EXPERIMENTAL && INET
75931 + depends on EXPERIMENTAL && INET && BROKEN
75932 ---help---
75933 Econet is a fairly old and slow networking protocol mainly used by
75934 Acorn computers to access file and print servers. It uses native
75935 diff -urNp linux-2.6.32.46/net/ieee802154/dgram.c linux-2.6.32.46/net/ieee802154/dgram.c
75936 --- linux-2.6.32.46/net/ieee802154/dgram.c 2011-03-27 14:31:47.000000000 -0400
75937 +++ linux-2.6.32.46/net/ieee802154/dgram.c 2011-05-04 17:56:28.000000000 -0400
75938 @@ -318,7 +318,7 @@ out:
75939 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
75940 {
75941 if (sock_queue_rcv_skb(sk, skb) < 0) {
75942 - atomic_inc(&sk->sk_drops);
75943 + atomic_inc_unchecked(&sk->sk_drops);
75944 kfree_skb(skb);
75945 return NET_RX_DROP;
75946 }
75947 diff -urNp linux-2.6.32.46/net/ieee802154/raw.c linux-2.6.32.46/net/ieee802154/raw.c
75948 --- linux-2.6.32.46/net/ieee802154/raw.c 2011-03-27 14:31:47.000000000 -0400
75949 +++ linux-2.6.32.46/net/ieee802154/raw.c 2011-05-04 17:56:28.000000000 -0400
75950 @@ -206,7 +206,7 @@ out:
75951 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
75952 {
75953 if (sock_queue_rcv_skb(sk, skb) < 0) {
75954 - atomic_inc(&sk->sk_drops);
75955 + atomic_inc_unchecked(&sk->sk_drops);
75956 kfree_skb(skb);
75957 return NET_RX_DROP;
75958 }
75959 diff -urNp linux-2.6.32.46/net/ipv4/inet_diag.c linux-2.6.32.46/net/ipv4/inet_diag.c
75960 --- linux-2.6.32.46/net/ipv4/inet_diag.c 2011-07-13 17:23:04.000000000 -0400
75961 +++ linux-2.6.32.46/net/ipv4/inet_diag.c 2011-06-20 19:31:13.000000000 -0400
75962 @@ -113,8 +113,13 @@ static int inet_csk_diag_fill(struct soc
75963 r->idiag_retrans = 0;
75964
75965 r->id.idiag_if = sk->sk_bound_dev_if;
75966 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75967 + r->id.idiag_cookie[0] = 0;
75968 + r->id.idiag_cookie[1] = 0;
75969 +#else
75970 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
75971 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75972 +#endif
75973
75974 r->id.idiag_sport = inet->sport;
75975 r->id.idiag_dport = inet->dport;
75976 @@ -200,8 +205,15 @@ static int inet_twsk_diag_fill(struct in
75977 r->idiag_family = tw->tw_family;
75978 r->idiag_retrans = 0;
75979 r->id.idiag_if = tw->tw_bound_dev_if;
75980 +
75981 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75982 + r->id.idiag_cookie[0] = 0;
75983 + r->id.idiag_cookie[1] = 0;
75984 +#else
75985 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
75986 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
75987 +#endif
75988 +
75989 r->id.idiag_sport = tw->tw_sport;
75990 r->id.idiag_dport = tw->tw_dport;
75991 r->id.idiag_src[0] = tw->tw_rcv_saddr;
75992 @@ -284,12 +296,14 @@ static int inet_diag_get_exact(struct sk
75993 if (sk == NULL)
75994 goto unlock;
75995
75996 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75997 err = -ESTALE;
75998 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
75999 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
76000 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
76001 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
76002 goto out;
76003 +#endif
76004
76005 err = -ENOMEM;
76006 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
76007 @@ -579,8 +593,14 @@ static int inet_diag_fill_req(struct sk_
76008 r->idiag_retrans = req->retrans;
76009
76010 r->id.idiag_if = sk->sk_bound_dev_if;
76011 +
76012 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76013 + r->id.idiag_cookie[0] = 0;
76014 + r->id.idiag_cookie[1] = 0;
76015 +#else
76016 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
76017 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
76018 +#endif
76019
76020 tmo = req->expires - jiffies;
76021 if (tmo < 0)
76022 diff -urNp linux-2.6.32.46/net/ipv4/inet_hashtables.c linux-2.6.32.46/net/ipv4/inet_hashtables.c
76023 --- linux-2.6.32.46/net/ipv4/inet_hashtables.c 2011-08-16 20:37:25.000000000 -0400
76024 +++ linux-2.6.32.46/net/ipv4/inet_hashtables.c 2011-08-16 20:42:30.000000000 -0400
76025 @@ -18,12 +18,15 @@
76026 #include <linux/sched.h>
76027 #include <linux/slab.h>
76028 #include <linux/wait.h>
76029 +#include <linux/security.h>
76030
76031 #include <net/inet_connection_sock.h>
76032 #include <net/inet_hashtables.h>
76033 #include <net/secure_seq.h>
76034 #include <net/ip.h>
76035
76036 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76037 +
76038 /*
76039 * Allocate and initialize a new local port bind bucket.
76040 * The bindhash mutex for snum's hash chain must be held here.
76041 @@ -491,6 +494,8 @@ ok:
76042 }
76043 spin_unlock(&head->lock);
76044
76045 + gr_update_task_in_ip_table(current, inet_sk(sk));
76046 +
76047 if (tw) {
76048 inet_twsk_deschedule(tw, death_row);
76049 inet_twsk_put(tw);
76050 diff -urNp linux-2.6.32.46/net/ipv4/inetpeer.c linux-2.6.32.46/net/ipv4/inetpeer.c
76051 --- linux-2.6.32.46/net/ipv4/inetpeer.c 2011-08-16 20:37:25.000000000 -0400
76052 +++ linux-2.6.32.46/net/ipv4/inetpeer.c 2011-08-07 19:48:09.000000000 -0400
76053 @@ -367,6 +367,8 @@ struct inet_peer *inet_getpeer(__be32 da
76054 struct inet_peer *p, *n;
76055 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr;
76056
76057 + pax_track_stack();
76058 +
76059 /* Look up for the address quickly. */
76060 read_lock_bh(&peer_pool_lock);
76061 p = lookup(daddr, NULL);
76062 @@ -390,7 +392,7 @@ struct inet_peer *inet_getpeer(__be32 da
76063 return NULL;
76064 n->v4daddr = daddr;
76065 atomic_set(&n->refcnt, 1);
76066 - atomic_set(&n->rid, 0);
76067 + atomic_set_unchecked(&n->rid, 0);
76068 n->ip_id_count = secure_ip_id(daddr);
76069 n->tcp_ts_stamp = 0;
76070
76071 diff -urNp linux-2.6.32.46/net/ipv4/ip_fragment.c linux-2.6.32.46/net/ipv4/ip_fragment.c
76072 --- linux-2.6.32.46/net/ipv4/ip_fragment.c 2011-03-27 14:31:47.000000000 -0400
76073 +++ linux-2.6.32.46/net/ipv4/ip_fragment.c 2011-04-17 15:56:46.000000000 -0400
76074 @@ -255,7 +255,7 @@ static inline int ip_frag_too_far(struct
76075 return 0;
76076
76077 start = qp->rid;
76078 - end = atomic_inc_return(&peer->rid);
76079 + end = atomic_inc_return_unchecked(&peer->rid);
76080 qp->rid = end;
76081
76082 rc = qp->q.fragments && (end - start) > max;
76083 diff -urNp linux-2.6.32.46/net/ipv4/ip_sockglue.c linux-2.6.32.46/net/ipv4/ip_sockglue.c
76084 --- linux-2.6.32.46/net/ipv4/ip_sockglue.c 2011-03-27 14:31:47.000000000 -0400
76085 +++ linux-2.6.32.46/net/ipv4/ip_sockglue.c 2011-10-06 09:37:14.000000000 -0400
76086 @@ -1015,6 +1015,8 @@ static int do_ip_getsockopt(struct sock
76087 int val;
76088 int len;
76089
76090 + pax_track_stack();
76091 +
76092 if (level != SOL_IP)
76093 return -EOPNOTSUPP;
76094
76095 @@ -1173,7 +1175,7 @@ static int do_ip_getsockopt(struct sock
76096 if (sk->sk_type != SOCK_STREAM)
76097 return -ENOPROTOOPT;
76098
76099 - msg.msg_control = optval;
76100 + msg.msg_control = (void __force_kernel *)optval;
76101 msg.msg_controllen = len;
76102 msg.msg_flags = 0;
76103
76104 diff -urNp linux-2.6.32.46/net/ipv4/ipconfig.c linux-2.6.32.46/net/ipv4/ipconfig.c
76105 --- linux-2.6.32.46/net/ipv4/ipconfig.c 2011-03-27 14:31:47.000000000 -0400
76106 +++ linux-2.6.32.46/net/ipv4/ipconfig.c 2011-10-06 09:37:14.000000000 -0400
76107 @@ -295,7 +295,7 @@ static int __init ic_devinet_ioctl(unsig
76108
76109 mm_segment_t oldfs = get_fs();
76110 set_fs(get_ds());
76111 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76112 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76113 set_fs(oldfs);
76114 return res;
76115 }
76116 @@ -306,7 +306,7 @@ static int __init ic_dev_ioctl(unsigned
76117
76118 mm_segment_t oldfs = get_fs();
76119 set_fs(get_ds());
76120 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76121 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76122 set_fs(oldfs);
76123 return res;
76124 }
76125 @@ -317,7 +317,7 @@ static int __init ic_route_ioctl(unsigne
76126
76127 mm_segment_t oldfs = get_fs();
76128 set_fs(get_ds());
76129 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76130 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76131 set_fs(oldfs);
76132 return res;
76133 }
76134 diff -urNp linux-2.6.32.46/net/ipv4/netfilter/arp_tables.c linux-2.6.32.46/net/ipv4/netfilter/arp_tables.c
76135 --- linux-2.6.32.46/net/ipv4/netfilter/arp_tables.c 2011-04-17 17:00:52.000000000 -0400
76136 +++ linux-2.6.32.46/net/ipv4/netfilter/arp_tables.c 2011-04-17 17:04:18.000000000 -0400
76137 @@ -934,6 +934,7 @@ static int get_info(struct net *net, voi
76138 private = &tmp;
76139 }
76140 #endif
76141 + memset(&info, 0, sizeof(info));
76142 info.valid_hooks = t->valid_hooks;
76143 memcpy(info.hook_entry, private->hook_entry,
76144 sizeof(info.hook_entry));
76145 diff -urNp linux-2.6.32.46/net/ipv4/netfilter/ip_queue.c linux-2.6.32.46/net/ipv4/netfilter/ip_queue.c
76146 --- linux-2.6.32.46/net/ipv4/netfilter/ip_queue.c 2011-03-27 14:31:47.000000000 -0400
76147 +++ linux-2.6.32.46/net/ipv4/netfilter/ip_queue.c 2011-08-21 18:42:53.000000000 -0400
76148 @@ -286,6 +286,9 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, st
76149
76150 if (v->data_len < sizeof(*user_iph))
76151 return 0;
76152 + if (v->data_len > 65535)
76153 + return -EMSGSIZE;
76154 +
76155 diff = v->data_len - e->skb->len;
76156 if (diff < 0) {
76157 if (pskb_trim(e->skb, v->data_len))
76158 @@ -409,7 +412,8 @@ ipq_dev_drop(int ifindex)
76159 static inline void
76160 __ipq_rcv_skb(struct sk_buff *skb)
76161 {
76162 - int status, type, pid, flags, nlmsglen, skblen;
76163 + int status, type, pid, flags;
76164 + unsigned int nlmsglen, skblen;
76165 struct nlmsghdr *nlh;
76166
76167 skblen = skb->len;
76168 diff -urNp linux-2.6.32.46/net/ipv4/netfilter/ip_tables.c linux-2.6.32.46/net/ipv4/netfilter/ip_tables.c
76169 --- linux-2.6.32.46/net/ipv4/netfilter/ip_tables.c 2011-04-17 17:00:52.000000000 -0400
76170 +++ linux-2.6.32.46/net/ipv4/netfilter/ip_tables.c 2011-04-17 17:04:18.000000000 -0400
76171 @@ -1141,6 +1141,7 @@ static int get_info(struct net *net, voi
76172 private = &tmp;
76173 }
76174 #endif
76175 + memset(&info, 0, sizeof(info));
76176 info.valid_hooks = t->valid_hooks;
76177 memcpy(info.hook_entry, private->hook_entry,
76178 sizeof(info.hook_entry));
76179 diff -urNp linux-2.6.32.46/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-2.6.32.46/net/ipv4/netfilter/nf_nat_snmp_basic.c
76180 --- linux-2.6.32.46/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-03-27 14:31:47.000000000 -0400
76181 +++ linux-2.6.32.46/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-04-17 15:56:46.000000000 -0400
76182 @@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode(
76183
76184 *len = 0;
76185
76186 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
76187 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
76188 if (*octets == NULL) {
76189 if (net_ratelimit())
76190 printk("OOM in bsalg (%d)\n", __LINE__);
76191 diff -urNp linux-2.6.32.46/net/ipv4/raw.c linux-2.6.32.46/net/ipv4/raw.c
76192 --- linux-2.6.32.46/net/ipv4/raw.c 2011-03-27 14:31:47.000000000 -0400
76193 +++ linux-2.6.32.46/net/ipv4/raw.c 2011-08-14 11:46:51.000000000 -0400
76194 @@ -292,7 +292,7 @@ static int raw_rcv_skb(struct sock * sk,
76195 /* Charge it to the socket. */
76196
76197 if (sock_queue_rcv_skb(sk, skb) < 0) {
76198 - atomic_inc(&sk->sk_drops);
76199 + atomic_inc_unchecked(&sk->sk_drops);
76200 kfree_skb(skb);
76201 return NET_RX_DROP;
76202 }
76203 @@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk,
76204 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76205 {
76206 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76207 - atomic_inc(&sk->sk_drops);
76208 + atomic_inc_unchecked(&sk->sk_drops);
76209 kfree_skb(skb);
76210 return NET_RX_DROP;
76211 }
76212 @@ -724,16 +724,23 @@ static int raw_init(struct sock *sk)
76213
76214 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76215 {
76216 + struct icmp_filter filter;
76217 +
76218 + if (optlen < 0)
76219 + return -EINVAL;
76220 if (optlen > sizeof(struct icmp_filter))
76221 optlen = sizeof(struct icmp_filter);
76222 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76223 + if (copy_from_user(&filter, optval, optlen))
76224 return -EFAULT;
76225 + raw_sk(sk)->filter = filter;
76226 +
76227 return 0;
76228 }
76229
76230 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76231 {
76232 int len, ret = -EFAULT;
76233 + struct icmp_filter filter;
76234
76235 if (get_user(len, optlen))
76236 goto out;
76237 @@ -743,8 +750,9 @@ static int raw_geticmpfilter(struct sock
76238 if (len > sizeof(struct icmp_filter))
76239 len = sizeof(struct icmp_filter);
76240 ret = -EFAULT;
76241 - if (put_user(len, optlen) ||
76242 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76243 + filter = raw_sk(sk)->filter;
76244 + if (put_user(len, optlen) || len > sizeof filter ||
76245 + copy_to_user(optval, &filter, len))
76246 goto out;
76247 ret = 0;
76248 out: return ret;
76249 @@ -954,7 +962,13 @@ static void raw_sock_seq_show(struct seq
76250 sk_wmem_alloc_get(sp),
76251 sk_rmem_alloc_get(sp),
76252 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76253 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76254 + atomic_read(&sp->sk_refcnt),
76255 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76256 + NULL,
76257 +#else
76258 + sp,
76259 +#endif
76260 + atomic_read_unchecked(&sp->sk_drops));
76261 }
76262
76263 static int raw_seq_show(struct seq_file *seq, void *v)
76264 diff -urNp linux-2.6.32.46/net/ipv4/route.c linux-2.6.32.46/net/ipv4/route.c
76265 --- linux-2.6.32.46/net/ipv4/route.c 2011-08-16 20:37:25.000000000 -0400
76266 +++ linux-2.6.32.46/net/ipv4/route.c 2011-08-07 19:48:09.000000000 -0400
76267 @@ -269,7 +269,7 @@ static inline unsigned int rt_hash(__be3
76268
76269 static inline int rt_genid(struct net *net)
76270 {
76271 - return atomic_read(&net->ipv4.rt_genid);
76272 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76273 }
76274
76275 #ifdef CONFIG_PROC_FS
76276 @@ -889,7 +889,7 @@ static void rt_cache_invalidate(struct n
76277 unsigned char shuffle;
76278
76279 get_random_bytes(&shuffle, sizeof(shuffle));
76280 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76281 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76282 }
76283
76284 /*
76285 @@ -3357,7 +3357,7 @@ static __net_initdata struct pernet_oper
76286
76287 static __net_init int rt_secret_timer_init(struct net *net)
76288 {
76289 - atomic_set(&net->ipv4.rt_genid,
76290 + atomic_set_unchecked(&net->ipv4.rt_genid,
76291 (int) ((num_physpages ^ (num_physpages>>8)) ^
76292 (jiffies ^ (jiffies >> 7))));
76293
76294 diff -urNp linux-2.6.32.46/net/ipv4/tcp.c linux-2.6.32.46/net/ipv4/tcp.c
76295 --- linux-2.6.32.46/net/ipv4/tcp.c 2011-03-27 14:31:47.000000000 -0400
76296 +++ linux-2.6.32.46/net/ipv4/tcp.c 2011-05-16 21:46:57.000000000 -0400
76297 @@ -2085,6 +2085,8 @@ static int do_tcp_setsockopt(struct sock
76298 int val;
76299 int err = 0;
76300
76301 + pax_track_stack();
76302 +
76303 /* This is a string value all the others are int's */
76304 if (optname == TCP_CONGESTION) {
76305 char name[TCP_CA_NAME_MAX];
76306 @@ -2355,6 +2357,8 @@ static int do_tcp_getsockopt(struct sock
76307 struct tcp_sock *tp = tcp_sk(sk);
76308 int val, len;
76309
76310 + pax_track_stack();
76311 +
76312 if (get_user(len, optlen))
76313 return -EFAULT;
76314
76315 diff -urNp linux-2.6.32.46/net/ipv4/tcp_ipv4.c linux-2.6.32.46/net/ipv4/tcp_ipv4.c
76316 --- linux-2.6.32.46/net/ipv4/tcp_ipv4.c 2011-08-16 20:37:25.000000000 -0400
76317 +++ linux-2.6.32.46/net/ipv4/tcp_ipv4.c 2011-08-23 21:22:32.000000000 -0400
76318 @@ -85,6 +85,9 @@
76319 int sysctl_tcp_tw_reuse __read_mostly;
76320 int sysctl_tcp_low_latency __read_mostly;
76321
76322 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76323 +extern int grsec_enable_blackhole;
76324 +#endif
76325
76326 #ifdef CONFIG_TCP_MD5SIG
76327 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76328 @@ -1543,6 +1546,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
76329 return 0;
76330
76331 reset:
76332 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76333 + if (!grsec_enable_blackhole)
76334 +#endif
76335 tcp_v4_send_reset(rsk, skb);
76336 discard:
76337 kfree_skb(skb);
76338 @@ -1604,12 +1610,20 @@ int tcp_v4_rcv(struct sk_buff *skb)
76339 TCP_SKB_CB(skb)->sacked = 0;
76340
76341 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76342 - if (!sk)
76343 + if (!sk) {
76344 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76345 + ret = 1;
76346 +#endif
76347 goto no_tcp_socket;
76348 + }
76349
76350 process:
76351 - if (sk->sk_state == TCP_TIME_WAIT)
76352 + if (sk->sk_state == TCP_TIME_WAIT) {
76353 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76354 + ret = 2;
76355 +#endif
76356 goto do_time_wait;
76357 + }
76358
76359 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
76360 goto discard_and_relse;
76361 @@ -1651,6 +1665,10 @@ no_tcp_socket:
76362 bad_packet:
76363 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76364 } else {
76365 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76366 + if (!grsec_enable_blackhole || (ret == 1 &&
76367 + (skb->dev->flags & IFF_LOOPBACK)))
76368 +#endif
76369 tcp_v4_send_reset(NULL, skb);
76370 }
76371
76372 @@ -2238,7 +2256,11 @@ static void get_openreq4(struct sock *sk
76373 0, /* non standard timer */
76374 0, /* open_requests have no inode */
76375 atomic_read(&sk->sk_refcnt),
76376 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76377 + NULL,
76378 +#else
76379 req,
76380 +#endif
76381 len);
76382 }
76383
76384 @@ -2280,7 +2302,12 @@ static void get_tcp4_sock(struct sock *s
76385 sock_i_uid(sk),
76386 icsk->icsk_probes_out,
76387 sock_i_ino(sk),
76388 - atomic_read(&sk->sk_refcnt), sk,
76389 + atomic_read(&sk->sk_refcnt),
76390 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76391 + NULL,
76392 +#else
76393 + sk,
76394 +#endif
76395 jiffies_to_clock_t(icsk->icsk_rto),
76396 jiffies_to_clock_t(icsk->icsk_ack.ato),
76397 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76398 @@ -2308,7 +2335,13 @@ static void get_timewait4_sock(struct in
76399 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
76400 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76401 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76402 - atomic_read(&tw->tw_refcnt), tw, len);
76403 + atomic_read(&tw->tw_refcnt),
76404 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76405 + NULL,
76406 +#else
76407 + tw,
76408 +#endif
76409 + len);
76410 }
76411
76412 #define TMPSZ 150
76413 diff -urNp linux-2.6.32.46/net/ipv4/tcp_minisocks.c linux-2.6.32.46/net/ipv4/tcp_minisocks.c
76414 --- linux-2.6.32.46/net/ipv4/tcp_minisocks.c 2011-03-27 14:31:47.000000000 -0400
76415 +++ linux-2.6.32.46/net/ipv4/tcp_minisocks.c 2011-04-17 15:56:46.000000000 -0400
76416 @@ -26,6 +26,10 @@
76417 #include <net/inet_common.h>
76418 #include <net/xfrm.h>
76419
76420 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76421 +extern int grsec_enable_blackhole;
76422 +#endif
76423 +
76424 #ifdef CONFIG_SYSCTL
76425 #define SYNC_INIT 0 /* let the user enable it */
76426 #else
76427 @@ -672,6 +676,10 @@ listen_overflow:
76428
76429 embryonic_reset:
76430 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76431 +
76432 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76433 + if (!grsec_enable_blackhole)
76434 +#endif
76435 if (!(flg & TCP_FLAG_RST))
76436 req->rsk_ops->send_reset(sk, skb);
76437
76438 diff -urNp linux-2.6.32.46/net/ipv4/tcp_output.c linux-2.6.32.46/net/ipv4/tcp_output.c
76439 --- linux-2.6.32.46/net/ipv4/tcp_output.c 2011-03-27 14:31:47.000000000 -0400
76440 +++ linux-2.6.32.46/net/ipv4/tcp_output.c 2011-05-16 21:46:57.000000000 -0400
76441 @@ -2234,6 +2234,8 @@ struct sk_buff *tcp_make_synack(struct s
76442 __u8 *md5_hash_location;
76443 int mss;
76444
76445 + pax_track_stack();
76446 +
76447 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
76448 if (skb == NULL)
76449 return NULL;
76450 diff -urNp linux-2.6.32.46/net/ipv4/tcp_probe.c linux-2.6.32.46/net/ipv4/tcp_probe.c
76451 --- linux-2.6.32.46/net/ipv4/tcp_probe.c 2011-03-27 14:31:47.000000000 -0400
76452 +++ linux-2.6.32.46/net/ipv4/tcp_probe.c 2011-04-17 15:56:46.000000000 -0400
76453 @@ -200,7 +200,7 @@ static ssize_t tcpprobe_read(struct file
76454 if (cnt + width >= len)
76455 break;
76456
76457 - if (copy_to_user(buf + cnt, tbuf, width))
76458 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76459 return -EFAULT;
76460 cnt += width;
76461 }
76462 diff -urNp linux-2.6.32.46/net/ipv4/tcp_timer.c linux-2.6.32.46/net/ipv4/tcp_timer.c
76463 --- linux-2.6.32.46/net/ipv4/tcp_timer.c 2011-03-27 14:31:47.000000000 -0400
76464 +++ linux-2.6.32.46/net/ipv4/tcp_timer.c 2011-04-17 15:56:46.000000000 -0400
76465 @@ -21,6 +21,10 @@
76466 #include <linux/module.h>
76467 #include <net/tcp.h>
76468
76469 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76470 +extern int grsec_lastack_retries;
76471 +#endif
76472 +
76473 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76474 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76475 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76476 @@ -164,6 +168,13 @@ static int tcp_write_timeout(struct sock
76477 }
76478 }
76479
76480 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76481 + if ((sk->sk_state == TCP_LAST_ACK) &&
76482 + (grsec_lastack_retries > 0) &&
76483 + (grsec_lastack_retries < retry_until))
76484 + retry_until = grsec_lastack_retries;
76485 +#endif
76486 +
76487 if (retransmits_timed_out(sk, retry_until)) {
76488 /* Has it gone just too far? */
76489 tcp_write_err(sk);
76490 diff -urNp linux-2.6.32.46/net/ipv4/udp.c linux-2.6.32.46/net/ipv4/udp.c
76491 --- linux-2.6.32.46/net/ipv4/udp.c 2011-07-13 17:23:04.000000000 -0400
76492 +++ linux-2.6.32.46/net/ipv4/udp.c 2011-08-23 21:22:32.000000000 -0400
76493 @@ -86,6 +86,7 @@
76494 #include <linux/types.h>
76495 #include <linux/fcntl.h>
76496 #include <linux/module.h>
76497 +#include <linux/security.h>
76498 #include <linux/socket.h>
76499 #include <linux/sockios.h>
76500 #include <linux/igmp.h>
76501 @@ -106,6 +107,10 @@
76502 #include <net/xfrm.h>
76503 #include "udp_impl.h"
76504
76505 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76506 +extern int grsec_enable_blackhole;
76507 +#endif
76508 +
76509 struct udp_table udp_table;
76510 EXPORT_SYMBOL(udp_table);
76511
76512 @@ -371,6 +376,9 @@ found:
76513 return s;
76514 }
76515
76516 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76517 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76518 +
76519 /*
76520 * This routine is called by the ICMP module when it gets some
76521 * sort of error condition. If err < 0 then the socket should
76522 @@ -639,9 +647,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
76523 dport = usin->sin_port;
76524 if (dport == 0)
76525 return -EINVAL;
76526 +
76527 + err = gr_search_udp_sendmsg(sk, usin);
76528 + if (err)
76529 + return err;
76530 } else {
76531 if (sk->sk_state != TCP_ESTABLISHED)
76532 return -EDESTADDRREQ;
76533 +
76534 + err = gr_search_udp_sendmsg(sk, NULL);
76535 + if (err)
76536 + return err;
76537 +
76538 daddr = inet->daddr;
76539 dport = inet->dport;
76540 /* Open fast path for connected socket.
76541 @@ -945,6 +962,10 @@ try_again:
76542 if (!skb)
76543 goto out;
76544
76545 + err = gr_search_udp_recvmsg(sk, skb);
76546 + if (err)
76547 + goto out_free;
76548 +
76549 ulen = skb->len - sizeof(struct udphdr);
76550 copied = len;
76551 if (copied > ulen)
76552 @@ -1068,7 +1089,7 @@ static int __udp_queue_rcv_skb(struct so
76553 if (rc == -ENOMEM) {
76554 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76555 is_udplite);
76556 - atomic_inc(&sk->sk_drops);
76557 + atomic_inc_unchecked(&sk->sk_drops);
76558 }
76559 goto drop;
76560 }
76561 @@ -1338,6 +1359,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
76562 goto csum_error;
76563
76564 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76565 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76566 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76567 +#endif
76568 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76569
76570 /*
76571 @@ -1758,8 +1782,13 @@ static void udp4_format_sock(struct sock
76572 sk_wmem_alloc_get(sp),
76573 sk_rmem_alloc_get(sp),
76574 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76575 - atomic_read(&sp->sk_refcnt), sp,
76576 - atomic_read(&sp->sk_drops), len);
76577 + atomic_read(&sp->sk_refcnt),
76578 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76579 + NULL,
76580 +#else
76581 + sp,
76582 +#endif
76583 + atomic_read_unchecked(&sp->sk_drops), len);
76584 }
76585
76586 int udp4_seq_show(struct seq_file *seq, void *v)
76587 diff -urNp linux-2.6.32.46/net/ipv6/addrconf.c linux-2.6.32.46/net/ipv6/addrconf.c
76588 --- linux-2.6.32.46/net/ipv6/addrconf.c 2011-05-10 22:12:02.000000000 -0400
76589 +++ linux-2.6.32.46/net/ipv6/addrconf.c 2011-10-06 09:37:14.000000000 -0400
76590 @@ -2053,7 +2053,7 @@ int addrconf_set_dstaddr(struct net *net
76591 p.iph.ihl = 5;
76592 p.iph.protocol = IPPROTO_IPV6;
76593 p.iph.ttl = 64;
76594 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76595 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76596
76597 if (ops->ndo_do_ioctl) {
76598 mm_segment_t oldfs = get_fs();
76599 diff -urNp linux-2.6.32.46/net/ipv6/inet6_connection_sock.c linux-2.6.32.46/net/ipv6/inet6_connection_sock.c
76600 --- linux-2.6.32.46/net/ipv6/inet6_connection_sock.c 2011-03-27 14:31:47.000000000 -0400
76601 +++ linux-2.6.32.46/net/ipv6/inet6_connection_sock.c 2011-05-04 17:56:28.000000000 -0400
76602 @@ -152,7 +152,7 @@ void __inet6_csk_dst_store(struct sock *
76603 #ifdef CONFIG_XFRM
76604 {
76605 struct rt6_info *rt = (struct rt6_info *)dst;
76606 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76607 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76608 }
76609 #endif
76610 }
76611 @@ -167,7 +167,7 @@ struct dst_entry *__inet6_csk_dst_check(
76612 #ifdef CONFIG_XFRM
76613 if (dst) {
76614 struct rt6_info *rt = (struct rt6_info *)dst;
76615 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76616 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76617 sk->sk_dst_cache = NULL;
76618 dst_release(dst);
76619 dst = NULL;
76620 diff -urNp linux-2.6.32.46/net/ipv6/inet6_hashtables.c linux-2.6.32.46/net/ipv6/inet6_hashtables.c
76621 --- linux-2.6.32.46/net/ipv6/inet6_hashtables.c 2011-08-16 20:37:25.000000000 -0400
76622 +++ linux-2.6.32.46/net/ipv6/inet6_hashtables.c 2011-08-07 19:48:09.000000000 -0400
76623 @@ -119,7 +119,7 @@ out:
76624 }
76625 EXPORT_SYMBOL(__inet6_lookup_established);
76626
76627 -static int inline compute_score(struct sock *sk, struct net *net,
76628 +static inline int compute_score(struct sock *sk, struct net *net,
76629 const unsigned short hnum,
76630 const struct in6_addr *daddr,
76631 const int dif)
76632 diff -urNp linux-2.6.32.46/net/ipv6/ip6_tunnel.c linux-2.6.32.46/net/ipv6/ip6_tunnel.c
76633 --- linux-2.6.32.46/net/ipv6/ip6_tunnel.c 2011-08-09 18:35:30.000000000 -0400
76634 +++ linux-2.6.32.46/net/ipv6/ip6_tunnel.c 2011-08-24 18:52:25.000000000 -0400
76635 @@ -1466,7 +1466,7 @@ static int __init ip6_tunnel_init(void)
76636 {
76637 int err;
76638
76639 - err = register_pernet_device(&ip6_tnl_net_ops);
76640 + err = register_pernet_gen_device(&ip6_tnl_net_id, &ip6_tnl_net_ops);
76641 if (err < 0)
76642 goto out_pernet;
76643
76644 @@ -1487,7 +1487,7 @@ static int __init ip6_tunnel_init(void)
76645 out_ip6ip6:
76646 xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET);
76647 out_ip4ip6:
76648 - unregister_pernet_device(&ip6_tnl_net_ops);
76649 + unregister_pernet_gen_device(ip6_tnl_net_id, &ip6_tnl_net_ops);
76650 out_pernet:
76651 return err;
76652 }
76653 diff -urNp linux-2.6.32.46/net/ipv6/ipv6_sockglue.c linux-2.6.32.46/net/ipv6/ipv6_sockglue.c
76654 --- linux-2.6.32.46/net/ipv6/ipv6_sockglue.c 2011-03-27 14:31:47.000000000 -0400
76655 +++ linux-2.6.32.46/net/ipv6/ipv6_sockglue.c 2011-10-06 09:37:16.000000000 -0400
76656 @@ -130,6 +130,8 @@ static int do_ipv6_setsockopt(struct soc
76657 int val, valbool;
76658 int retv = -ENOPROTOOPT;
76659
76660 + pax_track_stack();
76661 +
76662 if (optval == NULL)
76663 val=0;
76664 else {
76665 @@ -881,6 +883,8 @@ static int do_ipv6_getsockopt(struct soc
76666 int len;
76667 int val;
76668
76669 + pax_track_stack();
76670 +
76671 if (ip6_mroute_opt(optname))
76672 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
76673
76674 @@ -922,7 +926,7 @@ static int do_ipv6_getsockopt(struct soc
76675 if (sk->sk_type != SOCK_STREAM)
76676 return -ENOPROTOOPT;
76677
76678 - msg.msg_control = optval;
76679 + msg.msg_control = (void __force_kernel *)optval;
76680 msg.msg_controllen = len;
76681 msg.msg_flags = 0;
76682
76683 diff -urNp linux-2.6.32.46/net/ipv6/netfilter/ip6_queue.c linux-2.6.32.46/net/ipv6/netfilter/ip6_queue.c
76684 --- linux-2.6.32.46/net/ipv6/netfilter/ip6_queue.c 2011-03-27 14:31:47.000000000 -0400
76685 +++ linux-2.6.32.46/net/ipv6/netfilter/ip6_queue.c 2011-08-21 18:43:32.000000000 -0400
76686 @@ -287,6 +287,9 @@ ipq_mangle_ipv6(ipq_verdict_msg_t *v, st
76687
76688 if (v->data_len < sizeof(*user_iph))
76689 return 0;
76690 + if (v->data_len > 65535)
76691 + return -EMSGSIZE;
76692 +
76693 diff = v->data_len - e->skb->len;
76694 if (diff < 0) {
76695 if (pskb_trim(e->skb, v->data_len))
76696 @@ -411,7 +414,8 @@ ipq_dev_drop(int ifindex)
76697 static inline void
76698 __ipq_rcv_skb(struct sk_buff *skb)
76699 {
76700 - int status, type, pid, flags, nlmsglen, skblen;
76701 + int status, type, pid, flags;
76702 + unsigned int nlmsglen, skblen;
76703 struct nlmsghdr *nlh;
76704
76705 skblen = skb->len;
76706 diff -urNp linux-2.6.32.46/net/ipv6/netfilter/ip6_tables.c linux-2.6.32.46/net/ipv6/netfilter/ip6_tables.c
76707 --- linux-2.6.32.46/net/ipv6/netfilter/ip6_tables.c 2011-04-17 17:00:52.000000000 -0400
76708 +++ linux-2.6.32.46/net/ipv6/netfilter/ip6_tables.c 2011-04-17 17:04:18.000000000 -0400
76709 @@ -1173,6 +1173,7 @@ static int get_info(struct net *net, voi
76710 private = &tmp;
76711 }
76712 #endif
76713 + memset(&info, 0, sizeof(info));
76714 info.valid_hooks = t->valid_hooks;
76715 memcpy(info.hook_entry, private->hook_entry,
76716 sizeof(info.hook_entry));
76717 diff -urNp linux-2.6.32.46/net/ipv6/raw.c linux-2.6.32.46/net/ipv6/raw.c
76718 --- linux-2.6.32.46/net/ipv6/raw.c 2011-03-27 14:31:47.000000000 -0400
76719 +++ linux-2.6.32.46/net/ipv6/raw.c 2011-08-14 11:48:20.000000000 -0400
76720 @@ -375,14 +375,14 @@ static inline int rawv6_rcv_skb(struct s
76721 {
76722 if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
76723 skb_checksum_complete(skb)) {
76724 - atomic_inc(&sk->sk_drops);
76725 + atomic_inc_unchecked(&sk->sk_drops);
76726 kfree_skb(skb);
76727 return NET_RX_DROP;
76728 }
76729
76730 /* Charge it to the socket. */
76731 if (sock_queue_rcv_skb(sk,skb)<0) {
76732 - atomic_inc(&sk->sk_drops);
76733 + atomic_inc_unchecked(&sk->sk_drops);
76734 kfree_skb(skb);
76735 return NET_RX_DROP;
76736 }
76737 @@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76738 struct raw6_sock *rp = raw6_sk(sk);
76739
76740 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76741 - atomic_inc(&sk->sk_drops);
76742 + atomic_inc_unchecked(&sk->sk_drops);
76743 kfree_skb(skb);
76744 return NET_RX_DROP;
76745 }
76746 @@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76747
76748 if (inet->hdrincl) {
76749 if (skb_checksum_complete(skb)) {
76750 - atomic_inc(&sk->sk_drops);
76751 + atomic_inc_unchecked(&sk->sk_drops);
76752 kfree_skb(skb);
76753 return NET_RX_DROP;
76754 }
76755 @@ -518,7 +518,7 @@ csum_copy_err:
76756 as some normal condition.
76757 */
76758 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
76759 - atomic_inc(&sk->sk_drops);
76760 + atomic_inc_unchecked(&sk->sk_drops);
76761 goto out;
76762 }
76763
76764 @@ -600,7 +600,7 @@ out:
76765 return err;
76766 }
76767
76768 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76769 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76770 struct flowi *fl, struct rt6_info *rt,
76771 unsigned int flags)
76772 {
76773 @@ -738,6 +738,8 @@ static int rawv6_sendmsg(struct kiocb *i
76774 u16 proto;
76775 int err;
76776
76777 + pax_track_stack();
76778 +
76779 /* Rough check on arithmetic overflow,
76780 better check is made in ip6_append_data().
76781 */
76782 @@ -916,12 +918,17 @@ do_confirm:
76783 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76784 char __user *optval, int optlen)
76785 {
76786 + struct icmp6_filter filter;
76787 +
76788 switch (optname) {
76789 case ICMPV6_FILTER:
76790 + if (optlen < 0)
76791 + return -EINVAL;
76792 if (optlen > sizeof(struct icmp6_filter))
76793 optlen = sizeof(struct icmp6_filter);
76794 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76795 + if (copy_from_user(&filter, optval, optlen))
76796 return -EFAULT;
76797 + raw6_sk(sk)->filter = filter;
76798 return 0;
76799 default:
76800 return -ENOPROTOOPT;
76801 @@ -934,6 +941,7 @@ static int rawv6_geticmpfilter(struct so
76802 char __user *optval, int __user *optlen)
76803 {
76804 int len;
76805 + struct icmp6_filter filter;
76806
76807 switch (optname) {
76808 case ICMPV6_FILTER:
76809 @@ -945,7 +953,8 @@ static int rawv6_geticmpfilter(struct so
76810 len = sizeof(struct icmp6_filter);
76811 if (put_user(len, optlen))
76812 return -EFAULT;
76813 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76814 + filter = raw6_sk(sk)->filter;
76815 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76816 return -EFAULT;
76817 return 0;
76818 default:
76819 @@ -1241,7 +1250,13 @@ static void raw6_sock_seq_show(struct se
76820 0, 0L, 0,
76821 sock_i_uid(sp), 0,
76822 sock_i_ino(sp),
76823 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76824 + atomic_read(&sp->sk_refcnt),
76825 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76826 + NULL,
76827 +#else
76828 + sp,
76829 +#endif
76830 + atomic_read_unchecked(&sp->sk_drops));
76831 }
76832
76833 static int raw6_seq_show(struct seq_file *seq, void *v)
76834 diff -urNp linux-2.6.32.46/net/ipv6/tcp_ipv6.c linux-2.6.32.46/net/ipv6/tcp_ipv6.c
76835 --- linux-2.6.32.46/net/ipv6/tcp_ipv6.c 2011-08-16 20:37:25.000000000 -0400
76836 +++ linux-2.6.32.46/net/ipv6/tcp_ipv6.c 2011-08-07 19:48:09.000000000 -0400
76837 @@ -89,6 +89,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
76838 }
76839 #endif
76840
76841 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76842 +extern int grsec_enable_blackhole;
76843 +#endif
76844 +
76845 static void tcp_v6_hash(struct sock *sk)
76846 {
76847 if (sk->sk_state != TCP_CLOSE) {
76848 @@ -1579,6 +1583,9 @@ static int tcp_v6_do_rcv(struct sock *sk
76849 return 0;
76850
76851 reset:
76852 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76853 + if (!grsec_enable_blackhole)
76854 +#endif
76855 tcp_v6_send_reset(sk, skb);
76856 discard:
76857 if (opt_skb)
76858 @@ -1656,12 +1663,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
76859 TCP_SKB_CB(skb)->sacked = 0;
76860
76861 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76862 - if (!sk)
76863 + if (!sk) {
76864 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76865 + ret = 1;
76866 +#endif
76867 goto no_tcp_socket;
76868 + }
76869
76870 process:
76871 - if (sk->sk_state == TCP_TIME_WAIT)
76872 + if (sk->sk_state == TCP_TIME_WAIT) {
76873 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76874 + ret = 2;
76875 +#endif
76876 goto do_time_wait;
76877 + }
76878
76879 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
76880 goto discard_and_relse;
76881 @@ -1701,6 +1716,10 @@ no_tcp_socket:
76882 bad_packet:
76883 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76884 } else {
76885 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76886 + if (!grsec_enable_blackhole || (ret == 1 &&
76887 + (skb->dev->flags & IFF_LOOPBACK)))
76888 +#endif
76889 tcp_v6_send_reset(NULL, skb);
76890 }
76891
76892 @@ -1916,7 +1935,13 @@ static void get_openreq6(struct seq_file
76893 uid,
76894 0, /* non standard timer */
76895 0, /* open_requests have no inode */
76896 - 0, req);
76897 + 0,
76898 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76899 + NULL
76900 +#else
76901 + req
76902 +#endif
76903 + );
76904 }
76905
76906 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76907 @@ -1966,7 +1991,12 @@ static void get_tcp6_sock(struct seq_fil
76908 sock_i_uid(sp),
76909 icsk->icsk_probes_out,
76910 sock_i_ino(sp),
76911 - atomic_read(&sp->sk_refcnt), sp,
76912 + atomic_read(&sp->sk_refcnt),
76913 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76914 + NULL,
76915 +#else
76916 + sp,
76917 +#endif
76918 jiffies_to_clock_t(icsk->icsk_rto),
76919 jiffies_to_clock_t(icsk->icsk_ack.ato),
76920 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76921 @@ -2001,7 +2031,13 @@ static void get_timewait6_sock(struct se
76922 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76923 tw->tw_substate, 0, 0,
76924 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76925 - atomic_read(&tw->tw_refcnt), tw);
76926 + atomic_read(&tw->tw_refcnt),
76927 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76928 + NULL
76929 +#else
76930 + tw
76931 +#endif
76932 + );
76933 }
76934
76935 static int tcp6_seq_show(struct seq_file *seq, void *v)
76936 diff -urNp linux-2.6.32.46/net/ipv6/udp.c linux-2.6.32.46/net/ipv6/udp.c
76937 --- linux-2.6.32.46/net/ipv6/udp.c 2011-07-13 17:23:04.000000000 -0400
76938 +++ linux-2.6.32.46/net/ipv6/udp.c 2011-07-13 17:23:27.000000000 -0400
76939 @@ -49,6 +49,10 @@
76940 #include <linux/seq_file.h>
76941 #include "udp_impl.h"
76942
76943 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76944 +extern int grsec_enable_blackhole;
76945 +#endif
76946 +
76947 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76948 {
76949 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76950 @@ -391,7 +395,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
76951 if (rc == -ENOMEM) {
76952 UDP6_INC_STATS_BH(sock_net(sk),
76953 UDP_MIB_RCVBUFERRORS, is_udplite);
76954 - atomic_inc(&sk->sk_drops);
76955 + atomic_inc_unchecked(&sk->sk_drops);
76956 }
76957 goto drop;
76958 }
76959 @@ -590,6 +594,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
76960 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76961 proto == IPPROTO_UDPLITE);
76962
76963 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76964 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76965 +#endif
76966 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
76967
76968 kfree_skb(skb);
76969 @@ -1209,8 +1216,13 @@ static void udp6_sock_seq_show(struct se
76970 0, 0L, 0,
76971 sock_i_uid(sp), 0,
76972 sock_i_ino(sp),
76973 - atomic_read(&sp->sk_refcnt), sp,
76974 - atomic_read(&sp->sk_drops));
76975 + atomic_read(&sp->sk_refcnt),
76976 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76977 + NULL,
76978 +#else
76979 + sp,
76980 +#endif
76981 + atomic_read_unchecked(&sp->sk_drops));
76982 }
76983
76984 int udp6_seq_show(struct seq_file *seq, void *v)
76985 diff -urNp linux-2.6.32.46/net/irda/ircomm/ircomm_tty.c linux-2.6.32.46/net/irda/ircomm/ircomm_tty.c
76986 --- linux-2.6.32.46/net/irda/ircomm/ircomm_tty.c 2011-03-27 14:31:47.000000000 -0400
76987 +++ linux-2.6.32.46/net/irda/ircomm/ircomm_tty.c 2011-04-17 15:56:46.000000000 -0400
76988 @@ -280,16 +280,16 @@ static int ircomm_tty_block_til_ready(st
76989 add_wait_queue(&self->open_wait, &wait);
76990
76991 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76992 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76993 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76994
76995 /* As far as I can see, we protect open_count - Jean II */
76996 spin_lock_irqsave(&self->spinlock, flags);
76997 if (!tty_hung_up_p(filp)) {
76998 extra_count = 1;
76999 - self->open_count--;
77000 + local_dec(&self->open_count);
77001 }
77002 spin_unlock_irqrestore(&self->spinlock, flags);
77003 - self->blocked_open++;
77004 + local_inc(&self->blocked_open);
77005
77006 while (1) {
77007 if (tty->termios->c_cflag & CBAUD) {
77008 @@ -329,7 +329,7 @@ static int ircomm_tty_block_til_ready(st
77009 }
77010
77011 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77012 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77013 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77014
77015 schedule();
77016 }
77017 @@ -340,13 +340,13 @@ static int ircomm_tty_block_til_ready(st
77018 if (extra_count) {
77019 /* ++ is not atomic, so this should be protected - Jean II */
77020 spin_lock_irqsave(&self->spinlock, flags);
77021 - self->open_count++;
77022 + local_inc(&self->open_count);
77023 spin_unlock_irqrestore(&self->spinlock, flags);
77024 }
77025 - self->blocked_open--;
77026 + local_dec(&self->blocked_open);
77027
77028 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77029 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77030 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77031
77032 if (!retval)
77033 self->flags |= ASYNC_NORMAL_ACTIVE;
77034 @@ -415,14 +415,14 @@ static int ircomm_tty_open(struct tty_st
77035 }
77036 /* ++ is not atomic, so this should be protected - Jean II */
77037 spin_lock_irqsave(&self->spinlock, flags);
77038 - self->open_count++;
77039 + local_inc(&self->open_count);
77040
77041 tty->driver_data = self;
77042 self->tty = tty;
77043 spin_unlock_irqrestore(&self->spinlock, flags);
77044
77045 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77046 - self->line, self->open_count);
77047 + self->line, local_read(&self->open_count));
77048
77049 /* Not really used by us, but lets do it anyway */
77050 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77051 @@ -511,7 +511,7 @@ static void ircomm_tty_close(struct tty_
77052 return;
77053 }
77054
77055 - if ((tty->count == 1) && (self->open_count != 1)) {
77056 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77057 /*
77058 * Uh, oh. tty->count is 1, which means that the tty
77059 * structure will be freed. state->count should always
77060 @@ -521,16 +521,16 @@ static void ircomm_tty_close(struct tty_
77061 */
77062 IRDA_DEBUG(0, "%s(), bad serial port count; "
77063 "tty->count is 1, state->count is %d\n", __func__ ,
77064 - self->open_count);
77065 - self->open_count = 1;
77066 + local_read(&self->open_count));
77067 + local_set(&self->open_count, 1);
77068 }
77069
77070 - if (--self->open_count < 0) {
77071 + if (local_dec_return(&self->open_count) < 0) {
77072 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77073 - __func__, self->line, self->open_count);
77074 - self->open_count = 0;
77075 + __func__, self->line, local_read(&self->open_count));
77076 + local_set(&self->open_count, 0);
77077 }
77078 - if (self->open_count) {
77079 + if (local_read(&self->open_count)) {
77080 spin_unlock_irqrestore(&self->spinlock, flags);
77081
77082 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77083 @@ -562,7 +562,7 @@ static void ircomm_tty_close(struct tty_
77084 tty->closing = 0;
77085 self->tty = NULL;
77086
77087 - if (self->blocked_open) {
77088 + if (local_read(&self->blocked_open)) {
77089 if (self->close_delay)
77090 schedule_timeout_interruptible(self->close_delay);
77091 wake_up_interruptible(&self->open_wait);
77092 @@ -1017,7 +1017,7 @@ static void ircomm_tty_hangup(struct tty
77093 spin_lock_irqsave(&self->spinlock, flags);
77094 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77095 self->tty = NULL;
77096 - self->open_count = 0;
77097 + local_set(&self->open_count, 0);
77098 spin_unlock_irqrestore(&self->spinlock, flags);
77099
77100 wake_up_interruptible(&self->open_wait);
77101 @@ -1369,7 +1369,7 @@ static void ircomm_tty_line_info(struct
77102 seq_putc(m, '\n');
77103
77104 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77105 - seq_printf(m, "Open count: %d\n", self->open_count);
77106 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77107 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77108 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77109
77110 diff -urNp linux-2.6.32.46/net/iucv/af_iucv.c linux-2.6.32.46/net/iucv/af_iucv.c
77111 --- linux-2.6.32.46/net/iucv/af_iucv.c 2011-03-27 14:31:47.000000000 -0400
77112 +++ linux-2.6.32.46/net/iucv/af_iucv.c 2011-05-04 17:56:28.000000000 -0400
77113 @@ -651,10 +651,10 @@ static int iucv_sock_autobind(struct soc
77114
77115 write_lock_bh(&iucv_sk_list.lock);
77116
77117 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77118 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77119 while (__iucv_get_sock_by_name(name)) {
77120 sprintf(name, "%08x",
77121 - atomic_inc_return(&iucv_sk_list.autobind_name));
77122 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77123 }
77124
77125 write_unlock_bh(&iucv_sk_list.lock);
77126 diff -urNp linux-2.6.32.46/net/key/af_key.c linux-2.6.32.46/net/key/af_key.c
77127 --- linux-2.6.32.46/net/key/af_key.c 2011-03-27 14:31:47.000000000 -0400
77128 +++ linux-2.6.32.46/net/key/af_key.c 2011-05-16 21:46:57.000000000 -0400
77129 @@ -2489,6 +2489,8 @@ static int pfkey_migrate(struct sock *sk
77130 struct xfrm_migrate m[XFRM_MAX_DEPTH];
77131 struct xfrm_kmaddress k;
77132
77133 + pax_track_stack();
77134 +
77135 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
77136 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
77137 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
77138 @@ -3660,7 +3662,11 @@ static int pfkey_seq_show(struct seq_fil
77139 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
77140 else
77141 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
77142 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77143 + NULL,
77144 +#else
77145 s,
77146 +#endif
77147 atomic_read(&s->sk_refcnt),
77148 sk_rmem_alloc_get(s),
77149 sk_wmem_alloc_get(s),
77150 diff -urNp linux-2.6.32.46/net/lapb/lapb_iface.c linux-2.6.32.46/net/lapb/lapb_iface.c
77151 --- linux-2.6.32.46/net/lapb/lapb_iface.c 2011-03-27 14:31:47.000000000 -0400
77152 +++ linux-2.6.32.46/net/lapb/lapb_iface.c 2011-08-05 20:33:55.000000000 -0400
77153 @@ -157,7 +157,7 @@ int lapb_register(struct net_device *dev
77154 goto out;
77155
77156 lapb->dev = dev;
77157 - lapb->callbacks = *callbacks;
77158 + lapb->callbacks = callbacks;
77159
77160 __lapb_insert_cb(lapb);
77161
77162 @@ -379,32 +379,32 @@ int lapb_data_received(struct net_device
77163
77164 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
77165 {
77166 - if (lapb->callbacks.connect_confirmation)
77167 - lapb->callbacks.connect_confirmation(lapb->dev, reason);
77168 + if (lapb->callbacks->connect_confirmation)
77169 + lapb->callbacks->connect_confirmation(lapb->dev, reason);
77170 }
77171
77172 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
77173 {
77174 - if (lapb->callbacks.connect_indication)
77175 - lapb->callbacks.connect_indication(lapb->dev, reason);
77176 + if (lapb->callbacks->connect_indication)
77177 + lapb->callbacks->connect_indication(lapb->dev, reason);
77178 }
77179
77180 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
77181 {
77182 - if (lapb->callbacks.disconnect_confirmation)
77183 - lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
77184 + if (lapb->callbacks->disconnect_confirmation)
77185 + lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
77186 }
77187
77188 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
77189 {
77190 - if (lapb->callbacks.disconnect_indication)
77191 - lapb->callbacks.disconnect_indication(lapb->dev, reason);
77192 + if (lapb->callbacks->disconnect_indication)
77193 + lapb->callbacks->disconnect_indication(lapb->dev, reason);
77194 }
77195
77196 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
77197 {
77198 - if (lapb->callbacks.data_indication)
77199 - return lapb->callbacks.data_indication(lapb->dev, skb);
77200 + if (lapb->callbacks->data_indication)
77201 + return lapb->callbacks->data_indication(lapb->dev, skb);
77202
77203 kfree_skb(skb);
77204 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
77205 @@ -414,8 +414,8 @@ int lapb_data_transmit(struct lapb_cb *l
77206 {
77207 int used = 0;
77208
77209 - if (lapb->callbacks.data_transmit) {
77210 - lapb->callbacks.data_transmit(lapb->dev, skb);
77211 + if (lapb->callbacks->data_transmit) {
77212 + lapb->callbacks->data_transmit(lapb->dev, skb);
77213 used = 1;
77214 }
77215
77216 diff -urNp linux-2.6.32.46/net/mac80211/cfg.c linux-2.6.32.46/net/mac80211/cfg.c
77217 --- linux-2.6.32.46/net/mac80211/cfg.c 2011-03-27 14:31:47.000000000 -0400
77218 +++ linux-2.6.32.46/net/mac80211/cfg.c 2011-04-17 15:56:46.000000000 -0400
77219 @@ -1369,7 +1369,7 @@ static int ieee80211_set_bitrate_mask(st
77220 return err;
77221 }
77222
77223 -struct cfg80211_ops mac80211_config_ops = {
77224 +const struct cfg80211_ops mac80211_config_ops = {
77225 .add_virtual_intf = ieee80211_add_iface,
77226 .del_virtual_intf = ieee80211_del_iface,
77227 .change_virtual_intf = ieee80211_change_iface,
77228 diff -urNp linux-2.6.32.46/net/mac80211/cfg.h linux-2.6.32.46/net/mac80211/cfg.h
77229 --- linux-2.6.32.46/net/mac80211/cfg.h 2011-03-27 14:31:47.000000000 -0400
77230 +++ linux-2.6.32.46/net/mac80211/cfg.h 2011-04-17 15:56:46.000000000 -0400
77231 @@ -4,6 +4,6 @@
77232 #ifndef __CFG_H
77233 #define __CFG_H
77234
77235 -extern struct cfg80211_ops mac80211_config_ops;
77236 +extern const struct cfg80211_ops mac80211_config_ops;
77237
77238 #endif /* __CFG_H */
77239 diff -urNp linux-2.6.32.46/net/mac80211/debugfs_key.c linux-2.6.32.46/net/mac80211/debugfs_key.c
77240 --- linux-2.6.32.46/net/mac80211/debugfs_key.c 2011-03-27 14:31:47.000000000 -0400
77241 +++ linux-2.6.32.46/net/mac80211/debugfs_key.c 2011-04-17 15:56:46.000000000 -0400
77242 @@ -211,9 +211,13 @@ static ssize_t key_key_read(struct file
77243 size_t count, loff_t *ppos)
77244 {
77245 struct ieee80211_key *key = file->private_data;
77246 - int i, res, bufsize = 2 * key->conf.keylen + 2;
77247 + int i, bufsize = 2 * key->conf.keylen + 2;
77248 char *buf = kmalloc(bufsize, GFP_KERNEL);
77249 char *p = buf;
77250 + ssize_t res;
77251 +
77252 + if (buf == NULL)
77253 + return -ENOMEM;
77254
77255 for (i = 0; i < key->conf.keylen; i++)
77256 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
77257 diff -urNp linux-2.6.32.46/net/mac80211/debugfs_sta.c linux-2.6.32.46/net/mac80211/debugfs_sta.c
77258 --- linux-2.6.32.46/net/mac80211/debugfs_sta.c 2011-03-27 14:31:47.000000000 -0400
77259 +++ linux-2.6.32.46/net/mac80211/debugfs_sta.c 2011-05-16 21:46:57.000000000 -0400
77260 @@ -124,6 +124,8 @@ static ssize_t sta_agg_status_read(struc
77261 int i;
77262 struct sta_info *sta = file->private_data;
77263
77264 + pax_track_stack();
77265 +
77266 spin_lock_bh(&sta->lock);
77267 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
77268 sta->ampdu_mlme.dialog_token_allocator + 1);
77269 diff -urNp linux-2.6.32.46/net/mac80211/ieee80211_i.h linux-2.6.32.46/net/mac80211/ieee80211_i.h
77270 --- linux-2.6.32.46/net/mac80211/ieee80211_i.h 2011-03-27 14:31:47.000000000 -0400
77271 +++ linux-2.6.32.46/net/mac80211/ieee80211_i.h 2011-04-17 15:56:46.000000000 -0400
77272 @@ -25,6 +25,7 @@
77273 #include <linux/etherdevice.h>
77274 #include <net/cfg80211.h>
77275 #include <net/mac80211.h>
77276 +#include <asm/local.h>
77277 #include "key.h"
77278 #include "sta_info.h"
77279
77280 @@ -635,7 +636,7 @@ struct ieee80211_local {
77281 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77282 spinlock_t queue_stop_reason_lock;
77283
77284 - int open_count;
77285 + local_t open_count;
77286 int monitors, cooked_mntrs;
77287 /* number of interfaces with corresponding FIF_ flags */
77288 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
77289 diff -urNp linux-2.6.32.46/net/mac80211/iface.c linux-2.6.32.46/net/mac80211/iface.c
77290 --- linux-2.6.32.46/net/mac80211/iface.c 2011-03-27 14:31:47.000000000 -0400
77291 +++ linux-2.6.32.46/net/mac80211/iface.c 2011-04-17 15:56:46.000000000 -0400
77292 @@ -166,7 +166,7 @@ static int ieee80211_open(struct net_dev
77293 break;
77294 }
77295
77296 - if (local->open_count == 0) {
77297 + if (local_read(&local->open_count) == 0) {
77298 res = drv_start(local);
77299 if (res)
77300 goto err_del_bss;
77301 @@ -196,7 +196,7 @@ static int ieee80211_open(struct net_dev
77302 * Validate the MAC address for this device.
77303 */
77304 if (!is_valid_ether_addr(dev->dev_addr)) {
77305 - if (!local->open_count)
77306 + if (!local_read(&local->open_count))
77307 drv_stop(local);
77308 return -EADDRNOTAVAIL;
77309 }
77310 @@ -292,7 +292,7 @@ static int ieee80211_open(struct net_dev
77311
77312 hw_reconf_flags |= __ieee80211_recalc_idle(local);
77313
77314 - local->open_count++;
77315 + local_inc(&local->open_count);
77316 if (hw_reconf_flags) {
77317 ieee80211_hw_config(local, hw_reconf_flags);
77318 /*
77319 @@ -320,7 +320,7 @@ static int ieee80211_open(struct net_dev
77320 err_del_interface:
77321 drv_remove_interface(local, &conf);
77322 err_stop:
77323 - if (!local->open_count)
77324 + if (!local_read(&local->open_count))
77325 drv_stop(local);
77326 err_del_bss:
77327 sdata->bss = NULL;
77328 @@ -420,7 +420,7 @@ static int ieee80211_stop(struct net_dev
77329 WARN_ON(!list_empty(&sdata->u.ap.vlans));
77330 }
77331
77332 - local->open_count--;
77333 + local_dec(&local->open_count);
77334
77335 switch (sdata->vif.type) {
77336 case NL80211_IFTYPE_AP_VLAN:
77337 @@ -526,7 +526,7 @@ static int ieee80211_stop(struct net_dev
77338
77339 ieee80211_recalc_ps(local, -1);
77340
77341 - if (local->open_count == 0) {
77342 + if (local_read(&local->open_count) == 0) {
77343 ieee80211_clear_tx_pending(local);
77344 ieee80211_stop_device(local);
77345
77346 diff -urNp linux-2.6.32.46/net/mac80211/main.c linux-2.6.32.46/net/mac80211/main.c
77347 --- linux-2.6.32.46/net/mac80211/main.c 2011-05-10 22:12:02.000000000 -0400
77348 +++ linux-2.6.32.46/net/mac80211/main.c 2011-05-10 22:12:34.000000000 -0400
77349 @@ -145,7 +145,7 @@ int ieee80211_hw_config(struct ieee80211
77350 local->hw.conf.power_level = power;
77351 }
77352
77353 - if (changed && local->open_count) {
77354 + if (changed && local_read(&local->open_count)) {
77355 ret = drv_config(local, changed);
77356 /*
77357 * Goal:
77358 diff -urNp linux-2.6.32.46/net/mac80211/mlme.c linux-2.6.32.46/net/mac80211/mlme.c
77359 --- linux-2.6.32.46/net/mac80211/mlme.c 2011-08-09 18:35:30.000000000 -0400
77360 +++ linux-2.6.32.46/net/mac80211/mlme.c 2011-08-09 18:34:01.000000000 -0400
77361 @@ -1438,6 +1438,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee
77362 bool have_higher_than_11mbit = false, newsta = false;
77363 u16 ap_ht_cap_flags;
77364
77365 + pax_track_stack();
77366 +
77367 /*
77368 * AssocResp and ReassocResp have identical structure, so process both
77369 * of them in this function.
77370 diff -urNp linux-2.6.32.46/net/mac80211/pm.c linux-2.6.32.46/net/mac80211/pm.c
77371 --- linux-2.6.32.46/net/mac80211/pm.c 2011-03-27 14:31:47.000000000 -0400
77372 +++ linux-2.6.32.46/net/mac80211/pm.c 2011-04-17 15:56:46.000000000 -0400
77373 @@ -107,7 +107,7 @@ int __ieee80211_suspend(struct ieee80211
77374 }
77375
77376 /* stop hardware - this must stop RX */
77377 - if (local->open_count)
77378 + if (local_read(&local->open_count))
77379 ieee80211_stop_device(local);
77380
77381 local->suspended = true;
77382 diff -urNp linux-2.6.32.46/net/mac80211/rate.c linux-2.6.32.46/net/mac80211/rate.c
77383 --- linux-2.6.32.46/net/mac80211/rate.c 2011-03-27 14:31:47.000000000 -0400
77384 +++ linux-2.6.32.46/net/mac80211/rate.c 2011-04-17 15:56:46.000000000 -0400
77385 @@ -287,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct
77386 struct rate_control_ref *ref, *old;
77387
77388 ASSERT_RTNL();
77389 - if (local->open_count)
77390 + if (local_read(&local->open_count))
77391 return -EBUSY;
77392
77393 ref = rate_control_alloc(name, local);
77394 diff -urNp linux-2.6.32.46/net/mac80211/tx.c linux-2.6.32.46/net/mac80211/tx.c
77395 --- linux-2.6.32.46/net/mac80211/tx.c 2011-03-27 14:31:47.000000000 -0400
77396 +++ linux-2.6.32.46/net/mac80211/tx.c 2011-04-17 15:56:46.000000000 -0400
77397 @@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct
77398 return cpu_to_le16(dur);
77399 }
77400
77401 -static int inline is_ieee80211_device(struct ieee80211_local *local,
77402 +static inline int is_ieee80211_device(struct ieee80211_local *local,
77403 struct net_device *dev)
77404 {
77405 return local == wdev_priv(dev->ieee80211_ptr);
77406 diff -urNp linux-2.6.32.46/net/mac80211/util.c linux-2.6.32.46/net/mac80211/util.c
77407 --- linux-2.6.32.46/net/mac80211/util.c 2011-03-27 14:31:47.000000000 -0400
77408 +++ linux-2.6.32.46/net/mac80211/util.c 2011-04-17 15:56:46.000000000 -0400
77409 @@ -1042,7 +1042,7 @@ int ieee80211_reconfig(struct ieee80211_
77410 local->resuming = true;
77411
77412 /* restart hardware */
77413 - if (local->open_count) {
77414 + if (local_read(&local->open_count)) {
77415 /*
77416 * Upon resume hardware can sometimes be goofy due to
77417 * various platform / driver / bus issues, so restarting
77418 diff -urNp linux-2.6.32.46/net/netfilter/Kconfig linux-2.6.32.46/net/netfilter/Kconfig
77419 --- linux-2.6.32.46/net/netfilter/Kconfig 2011-03-27 14:31:47.000000000 -0400
77420 +++ linux-2.6.32.46/net/netfilter/Kconfig 2011-04-17 15:56:46.000000000 -0400
77421 @@ -635,6 +635,16 @@ config NETFILTER_XT_MATCH_ESP
77422
77423 To compile it as a module, choose M here. If unsure, say N.
77424
77425 +config NETFILTER_XT_MATCH_GRADM
77426 + tristate '"gradm" match support'
77427 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77428 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77429 + ---help---
77430 + The gradm match allows to match on grsecurity RBAC being enabled.
77431 + It is useful when iptables rules are applied early on bootup to
77432 + prevent connections to the machine (except from a trusted host)
77433 + while the RBAC system is disabled.
77434 +
77435 config NETFILTER_XT_MATCH_HASHLIMIT
77436 tristate '"hashlimit" match support'
77437 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77438 diff -urNp linux-2.6.32.46/net/netfilter/Makefile linux-2.6.32.46/net/netfilter/Makefile
77439 --- linux-2.6.32.46/net/netfilter/Makefile 2011-03-27 14:31:47.000000000 -0400
77440 +++ linux-2.6.32.46/net/netfilter/Makefile 2011-04-17 15:56:46.000000000 -0400
77441 @@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRAC
77442 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
77443 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77444 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77445 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77446 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77447 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77448 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77449 diff -urNp linux-2.6.32.46/net/netfilter/ipvs/ip_vs_app.c linux-2.6.32.46/net/netfilter/ipvs/ip_vs_app.c
77450 --- linux-2.6.32.46/net/netfilter/ipvs/ip_vs_app.c 2011-03-27 14:31:47.000000000 -0400
77451 +++ linux-2.6.32.46/net/netfilter/ipvs/ip_vs_app.c 2011-05-17 19:26:34.000000000 -0400
77452 @@ -564,7 +564,7 @@ static const struct file_operations ip_v
77453 .open = ip_vs_app_open,
77454 .read = seq_read,
77455 .llseek = seq_lseek,
77456 - .release = seq_release,
77457 + .release = seq_release_net,
77458 };
77459 #endif
77460
77461 diff -urNp linux-2.6.32.46/net/netfilter/ipvs/ip_vs_conn.c linux-2.6.32.46/net/netfilter/ipvs/ip_vs_conn.c
77462 --- linux-2.6.32.46/net/netfilter/ipvs/ip_vs_conn.c 2011-03-27 14:31:47.000000000 -0400
77463 +++ linux-2.6.32.46/net/netfilter/ipvs/ip_vs_conn.c 2011-05-17 19:26:34.000000000 -0400
77464 @@ -453,10 +453,10 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
77465 /* if the connection is not template and is created
77466 * by sync, preserve the activity flag.
77467 */
77468 - cp->flags |= atomic_read(&dest->conn_flags) &
77469 + cp->flags |= atomic_read_unchecked(&dest->conn_flags) &
77470 (~IP_VS_CONN_F_INACTIVE);
77471 else
77472 - cp->flags |= atomic_read(&dest->conn_flags);
77473 + cp->flags |= atomic_read_unchecked(&dest->conn_flags);
77474 cp->dest = dest;
77475
77476 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
77477 @@ -723,7 +723,7 @@ ip_vs_conn_new(int af, int proto, const
77478 atomic_set(&cp->refcnt, 1);
77479
77480 atomic_set(&cp->n_control, 0);
77481 - atomic_set(&cp->in_pkts, 0);
77482 + atomic_set_unchecked(&cp->in_pkts, 0);
77483
77484 atomic_inc(&ip_vs_conn_count);
77485 if (flags & IP_VS_CONN_F_NO_CPORT)
77486 @@ -871,7 +871,7 @@ static const struct file_operations ip_v
77487 .open = ip_vs_conn_open,
77488 .read = seq_read,
77489 .llseek = seq_lseek,
77490 - .release = seq_release,
77491 + .release = seq_release_net,
77492 };
77493
77494 static const char *ip_vs_origin_name(unsigned flags)
77495 @@ -934,7 +934,7 @@ static const struct file_operations ip_v
77496 .open = ip_vs_conn_sync_open,
77497 .read = seq_read,
77498 .llseek = seq_lseek,
77499 - .release = seq_release,
77500 + .release = seq_release_net,
77501 };
77502
77503 #endif
77504 @@ -961,7 +961,7 @@ static inline int todrop_entry(struct ip
77505
77506 /* Don't drop the entry if its number of incoming packets is not
77507 located in [0, 8] */
77508 - i = atomic_read(&cp->in_pkts);
77509 + i = atomic_read_unchecked(&cp->in_pkts);
77510 if (i > 8 || i < 0) return 0;
77511
77512 if (!todrop_rate[i]) return 0;
77513 diff -urNp linux-2.6.32.46/net/netfilter/ipvs/ip_vs_core.c linux-2.6.32.46/net/netfilter/ipvs/ip_vs_core.c
77514 --- linux-2.6.32.46/net/netfilter/ipvs/ip_vs_core.c 2011-03-27 14:31:47.000000000 -0400
77515 +++ linux-2.6.32.46/net/netfilter/ipvs/ip_vs_core.c 2011-05-04 17:56:28.000000000 -0400
77516 @@ -485,7 +485,7 @@ int ip_vs_leave(struct ip_vs_service *sv
77517 ret = cp->packet_xmit(skb, cp, pp);
77518 /* do not touch skb anymore */
77519
77520 - atomic_inc(&cp->in_pkts);
77521 + atomic_inc_unchecked(&cp->in_pkts);
77522 ip_vs_conn_put(cp);
77523 return ret;
77524 }
77525 @@ -1357,7 +1357,7 @@ ip_vs_in(unsigned int hooknum, struct sk
77526 * Sync connection if it is about to close to
77527 * encorage the standby servers to update the connections timeout
77528 */
77529 - pkts = atomic_add_return(1, &cp->in_pkts);
77530 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77531 if (af == AF_INET &&
77532 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
77533 (((cp->protocol != IPPROTO_TCP ||
77534 diff -urNp linux-2.6.32.46/net/netfilter/ipvs/ip_vs_ctl.c linux-2.6.32.46/net/netfilter/ipvs/ip_vs_ctl.c
77535 --- linux-2.6.32.46/net/netfilter/ipvs/ip_vs_ctl.c 2011-03-27 14:31:47.000000000 -0400
77536 +++ linux-2.6.32.46/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-17 19:26:34.000000000 -0400
77537 @@ -792,7 +792,7 @@ __ip_vs_update_dest(struct ip_vs_service
77538 ip_vs_rs_hash(dest);
77539 write_unlock_bh(&__ip_vs_rs_lock);
77540 }
77541 - atomic_set(&dest->conn_flags, conn_flags);
77542 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77543
77544 /* bind the service */
77545 if (!dest->svc) {
77546 @@ -1888,7 +1888,7 @@ static int ip_vs_info_seq_show(struct se
77547 " %-7s %-6d %-10d %-10d\n",
77548 &dest->addr.in6,
77549 ntohs(dest->port),
77550 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77551 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77552 atomic_read(&dest->weight),
77553 atomic_read(&dest->activeconns),
77554 atomic_read(&dest->inactconns));
77555 @@ -1899,7 +1899,7 @@ static int ip_vs_info_seq_show(struct se
77556 "%-7s %-6d %-10d %-10d\n",
77557 ntohl(dest->addr.ip),
77558 ntohs(dest->port),
77559 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77560 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77561 atomic_read(&dest->weight),
77562 atomic_read(&dest->activeconns),
77563 atomic_read(&dest->inactconns));
77564 @@ -1927,7 +1927,7 @@ static const struct file_operations ip_v
77565 .open = ip_vs_info_open,
77566 .read = seq_read,
77567 .llseek = seq_lseek,
77568 - .release = seq_release_private,
77569 + .release = seq_release_net,
77570 };
77571
77572 #endif
77573 @@ -1976,7 +1976,7 @@ static const struct file_operations ip_v
77574 .open = ip_vs_stats_seq_open,
77575 .read = seq_read,
77576 .llseek = seq_lseek,
77577 - .release = single_release,
77578 + .release = single_release_net,
77579 };
77580
77581 #endif
77582 @@ -2292,7 +2292,7 @@ __ip_vs_get_dest_entries(const struct ip
77583
77584 entry.addr = dest->addr.ip;
77585 entry.port = dest->port;
77586 - entry.conn_flags = atomic_read(&dest->conn_flags);
77587 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77588 entry.weight = atomic_read(&dest->weight);
77589 entry.u_threshold = dest->u_threshold;
77590 entry.l_threshold = dest->l_threshold;
77591 @@ -2353,6 +2353,8 @@ do_ip_vs_get_ctl(struct sock *sk, int cm
77592 unsigned char arg[128];
77593 int ret = 0;
77594
77595 + pax_track_stack();
77596 +
77597 if (!capable(CAP_NET_ADMIN))
77598 return -EPERM;
77599
77600 @@ -2802,7 +2804,7 @@ static int ip_vs_genl_fill_dest(struct s
77601 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77602
77603 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77604 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77605 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77606 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77607 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77608 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77609 diff -urNp linux-2.6.32.46/net/netfilter/ipvs/ip_vs_sync.c linux-2.6.32.46/net/netfilter/ipvs/ip_vs_sync.c
77610 --- linux-2.6.32.46/net/netfilter/ipvs/ip_vs_sync.c 2011-03-27 14:31:47.000000000 -0400
77611 +++ linux-2.6.32.46/net/netfilter/ipvs/ip_vs_sync.c 2011-05-04 17:56:28.000000000 -0400
77612 @@ -438,7 +438,7 @@ static void ip_vs_process_message(const
77613
77614 if (opt)
77615 memcpy(&cp->in_seq, opt, sizeof(*opt));
77616 - atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
77617 + atomic_set_unchecked(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
77618 cp->state = state;
77619 cp->old_state = cp->state;
77620 /*
77621 diff -urNp linux-2.6.32.46/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.32.46/net/netfilter/ipvs/ip_vs_xmit.c
77622 --- linux-2.6.32.46/net/netfilter/ipvs/ip_vs_xmit.c 2011-03-27 14:31:47.000000000 -0400
77623 +++ linux-2.6.32.46/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-04 17:56:28.000000000 -0400
77624 @@ -875,7 +875,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
77625 else
77626 rc = NF_ACCEPT;
77627 /* do not touch skb anymore */
77628 - atomic_inc(&cp->in_pkts);
77629 + atomic_inc_unchecked(&cp->in_pkts);
77630 goto out;
77631 }
77632
77633 @@ -949,7 +949,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
77634 else
77635 rc = NF_ACCEPT;
77636 /* do not touch skb anymore */
77637 - atomic_inc(&cp->in_pkts);
77638 + atomic_inc_unchecked(&cp->in_pkts);
77639 goto out;
77640 }
77641
77642 diff -urNp linux-2.6.32.46/net/netfilter/nf_conntrack_netlink.c linux-2.6.32.46/net/netfilter/nf_conntrack_netlink.c
77643 --- linux-2.6.32.46/net/netfilter/nf_conntrack_netlink.c 2011-03-27 14:31:47.000000000 -0400
77644 +++ linux-2.6.32.46/net/netfilter/nf_conntrack_netlink.c 2011-04-17 15:56:46.000000000 -0400
77645 @@ -706,7 +706,7 @@ ctnetlink_parse_tuple_proto(struct nlatt
77646 static int
77647 ctnetlink_parse_tuple(const struct nlattr * const cda[],
77648 struct nf_conntrack_tuple *tuple,
77649 - enum ctattr_tuple type, u_int8_t l3num)
77650 + enum ctattr_type type, u_int8_t l3num)
77651 {
77652 struct nlattr *tb[CTA_TUPLE_MAX+1];
77653 int err;
77654 diff -urNp linux-2.6.32.46/net/netfilter/nfnetlink_log.c linux-2.6.32.46/net/netfilter/nfnetlink_log.c
77655 --- linux-2.6.32.46/net/netfilter/nfnetlink_log.c 2011-03-27 14:31:47.000000000 -0400
77656 +++ linux-2.6.32.46/net/netfilter/nfnetlink_log.c 2011-05-04 17:56:28.000000000 -0400
77657 @@ -68,7 +68,7 @@ struct nfulnl_instance {
77658 };
77659
77660 static DEFINE_RWLOCK(instances_lock);
77661 -static atomic_t global_seq;
77662 +static atomic_unchecked_t global_seq;
77663
77664 #define INSTANCE_BUCKETS 16
77665 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77666 @@ -493,7 +493,7 @@ __build_packet_message(struct nfulnl_ins
77667 /* global sequence number */
77668 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77669 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77670 - htonl(atomic_inc_return(&global_seq)));
77671 + htonl(atomic_inc_return_unchecked(&global_seq)));
77672
77673 if (data_len) {
77674 struct nlattr *nla;
77675 diff -urNp linux-2.6.32.46/net/netfilter/xt_gradm.c linux-2.6.32.46/net/netfilter/xt_gradm.c
77676 --- linux-2.6.32.46/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
77677 +++ linux-2.6.32.46/net/netfilter/xt_gradm.c 2011-04-17 15:56:46.000000000 -0400
77678 @@ -0,0 +1,51 @@
77679 +/*
77680 + * gradm match for netfilter
77681 + * Copyright © Zbigniew Krzystolik, 2010
77682 + *
77683 + * This program is free software; you can redistribute it and/or modify
77684 + * it under the terms of the GNU General Public License; either version
77685 + * 2 or 3 as published by the Free Software Foundation.
77686 + */
77687 +#include <linux/module.h>
77688 +#include <linux/moduleparam.h>
77689 +#include <linux/skbuff.h>
77690 +#include <linux/netfilter/x_tables.h>
77691 +#include <linux/grsecurity.h>
77692 +#include <linux/netfilter/xt_gradm.h>
77693 +
77694 +static bool
77695 +gradm_mt(const struct sk_buff *skb, const struct xt_match_param *par)
77696 +{
77697 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77698 + bool retval = false;
77699 + if (gr_acl_is_enabled())
77700 + retval = true;
77701 + return retval ^ info->invflags;
77702 +}
77703 +
77704 +static struct xt_match gradm_mt_reg __read_mostly = {
77705 + .name = "gradm",
77706 + .revision = 0,
77707 + .family = NFPROTO_UNSPEC,
77708 + .match = gradm_mt,
77709 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77710 + .me = THIS_MODULE,
77711 +};
77712 +
77713 +static int __init gradm_mt_init(void)
77714 +{
77715 + return xt_register_match(&gradm_mt_reg);
77716 +}
77717 +
77718 +static void __exit gradm_mt_exit(void)
77719 +{
77720 + xt_unregister_match(&gradm_mt_reg);
77721 +}
77722 +
77723 +module_init(gradm_mt_init);
77724 +module_exit(gradm_mt_exit);
77725 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77726 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77727 +MODULE_LICENSE("GPL");
77728 +MODULE_ALIAS("ipt_gradm");
77729 +MODULE_ALIAS("ip6t_gradm");
77730 diff -urNp linux-2.6.32.46/net/netlink/af_netlink.c linux-2.6.32.46/net/netlink/af_netlink.c
77731 --- linux-2.6.32.46/net/netlink/af_netlink.c 2011-03-27 14:31:47.000000000 -0400
77732 +++ linux-2.6.32.46/net/netlink/af_netlink.c 2011-05-04 17:56:28.000000000 -0400
77733 @@ -733,7 +733,7 @@ static void netlink_overrun(struct sock
77734 sk->sk_error_report(sk);
77735 }
77736 }
77737 - atomic_inc(&sk->sk_drops);
77738 + atomic_inc_unchecked(&sk->sk_drops);
77739 }
77740
77741 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77742 @@ -1964,15 +1964,23 @@ static int netlink_seq_show(struct seq_f
77743 struct netlink_sock *nlk = nlk_sk(s);
77744
77745 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d\n",
77746 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77747 + NULL,
77748 +#else
77749 s,
77750 +#endif
77751 s->sk_protocol,
77752 nlk->pid,
77753 nlk->groups ? (u32)nlk->groups[0] : 0,
77754 sk_rmem_alloc_get(s),
77755 sk_wmem_alloc_get(s),
77756 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77757 + NULL,
77758 +#else
77759 nlk->cb,
77760 +#endif
77761 atomic_read(&s->sk_refcnt),
77762 - atomic_read(&s->sk_drops)
77763 + atomic_read_unchecked(&s->sk_drops)
77764 );
77765
77766 }
77767 diff -urNp linux-2.6.32.46/net/netrom/af_netrom.c linux-2.6.32.46/net/netrom/af_netrom.c
77768 --- linux-2.6.32.46/net/netrom/af_netrom.c 2011-03-27 14:31:47.000000000 -0400
77769 +++ linux-2.6.32.46/net/netrom/af_netrom.c 2011-04-17 15:56:46.000000000 -0400
77770 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *soc
77771 struct sock *sk = sock->sk;
77772 struct nr_sock *nr = nr_sk(sk);
77773
77774 + memset(sax, 0, sizeof(*sax));
77775 lock_sock(sk);
77776 if (peer != 0) {
77777 if (sk->sk_state != TCP_ESTABLISHED) {
77778 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *soc
77779 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77780 } else {
77781 sax->fsa_ax25.sax25_family = AF_NETROM;
77782 - sax->fsa_ax25.sax25_ndigis = 0;
77783 sax->fsa_ax25.sax25_call = nr->source_addr;
77784 *uaddr_len = sizeof(struct sockaddr_ax25);
77785 }
77786 diff -urNp linux-2.6.32.46/net/packet/af_packet.c linux-2.6.32.46/net/packet/af_packet.c
77787 --- linux-2.6.32.46/net/packet/af_packet.c 2011-07-13 17:23:04.000000000 -0400
77788 +++ linux-2.6.32.46/net/packet/af_packet.c 2011-07-13 17:23:27.000000000 -0400
77789 @@ -2429,7 +2429,11 @@ static int packet_seq_show(struct seq_fi
77790
77791 seq_printf(seq,
77792 "%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
77793 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77794 + NULL,
77795 +#else
77796 s,
77797 +#endif
77798 atomic_read(&s->sk_refcnt),
77799 s->sk_type,
77800 ntohs(po->num),
77801 diff -urNp linux-2.6.32.46/net/phonet/af_phonet.c linux-2.6.32.46/net/phonet/af_phonet.c
77802 --- linux-2.6.32.46/net/phonet/af_phonet.c 2011-03-27 14:31:47.000000000 -0400
77803 +++ linux-2.6.32.46/net/phonet/af_phonet.c 2011-04-17 15:56:46.000000000 -0400
77804 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_pr
77805 {
77806 struct phonet_protocol *pp;
77807
77808 - if (protocol >= PHONET_NPROTO)
77809 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77810 return NULL;
77811
77812 spin_lock(&proto_tab_lock);
77813 @@ -402,7 +402,7 @@ int __init_or_module phonet_proto_regist
77814 {
77815 int err = 0;
77816
77817 - if (protocol >= PHONET_NPROTO)
77818 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77819 return -EINVAL;
77820
77821 err = proto_register(pp->prot, 1);
77822 diff -urNp linux-2.6.32.46/net/phonet/datagram.c linux-2.6.32.46/net/phonet/datagram.c
77823 --- linux-2.6.32.46/net/phonet/datagram.c 2011-03-27 14:31:47.000000000 -0400
77824 +++ linux-2.6.32.46/net/phonet/datagram.c 2011-05-04 17:56:28.000000000 -0400
77825 @@ -162,7 +162,7 @@ static int pn_backlog_rcv(struct sock *s
77826 if (err < 0) {
77827 kfree_skb(skb);
77828 if (err == -ENOMEM)
77829 - atomic_inc(&sk->sk_drops);
77830 + atomic_inc_unchecked(&sk->sk_drops);
77831 }
77832 return err ? NET_RX_DROP : NET_RX_SUCCESS;
77833 }
77834 diff -urNp linux-2.6.32.46/net/phonet/pep.c linux-2.6.32.46/net/phonet/pep.c
77835 --- linux-2.6.32.46/net/phonet/pep.c 2011-03-27 14:31:47.000000000 -0400
77836 +++ linux-2.6.32.46/net/phonet/pep.c 2011-05-04 17:56:28.000000000 -0400
77837 @@ -348,7 +348,7 @@ static int pipe_do_rcv(struct sock *sk,
77838
77839 case PNS_PEP_CTRL_REQ:
77840 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77841 - atomic_inc(&sk->sk_drops);
77842 + atomic_inc_unchecked(&sk->sk_drops);
77843 break;
77844 }
77845 __skb_pull(skb, 4);
77846 @@ -362,12 +362,12 @@ static int pipe_do_rcv(struct sock *sk,
77847 if (!err)
77848 return 0;
77849 if (err == -ENOMEM)
77850 - atomic_inc(&sk->sk_drops);
77851 + atomic_inc_unchecked(&sk->sk_drops);
77852 break;
77853 }
77854
77855 if (pn->rx_credits == 0) {
77856 - atomic_inc(&sk->sk_drops);
77857 + atomic_inc_unchecked(&sk->sk_drops);
77858 err = -ENOBUFS;
77859 break;
77860 }
77861 diff -urNp linux-2.6.32.46/net/phonet/socket.c linux-2.6.32.46/net/phonet/socket.c
77862 --- linux-2.6.32.46/net/phonet/socket.c 2011-03-27 14:31:47.000000000 -0400
77863 +++ linux-2.6.32.46/net/phonet/socket.c 2011-05-04 17:57:07.000000000 -0400
77864 @@ -482,8 +482,13 @@ static int pn_sock_seq_show(struct seq_f
77865 sk->sk_state,
77866 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77867 sock_i_uid(sk), sock_i_ino(sk),
77868 - atomic_read(&sk->sk_refcnt), sk,
77869 - atomic_read(&sk->sk_drops), &len);
77870 + atomic_read(&sk->sk_refcnt),
77871 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77872 + NULL,
77873 +#else
77874 + sk,
77875 +#endif
77876 + atomic_read_unchecked(&sk->sk_drops), &len);
77877 }
77878 seq_printf(seq, "%*s\n", 127 - len, "");
77879 return 0;
77880 diff -urNp linux-2.6.32.46/net/rds/Kconfig linux-2.6.32.46/net/rds/Kconfig
77881 --- linux-2.6.32.46/net/rds/Kconfig 2011-03-27 14:31:47.000000000 -0400
77882 +++ linux-2.6.32.46/net/rds/Kconfig 2011-04-17 15:56:46.000000000 -0400
77883 @@ -1,7 +1,7 @@
77884
77885 config RDS
77886 tristate "The RDS Protocol (EXPERIMENTAL)"
77887 - depends on INET && EXPERIMENTAL
77888 + depends on INET && EXPERIMENTAL && BROKEN
77889 ---help---
77890 The RDS (Reliable Datagram Sockets) protocol provides reliable,
77891 sequenced delivery of datagrams over Infiniband, iWARP,
77892 diff -urNp linux-2.6.32.46/net/rds/cong.c linux-2.6.32.46/net/rds/cong.c
77893 --- linux-2.6.32.46/net/rds/cong.c 2011-03-27 14:31:47.000000000 -0400
77894 +++ linux-2.6.32.46/net/rds/cong.c 2011-05-04 17:56:28.000000000 -0400
77895 @@ -77,7 +77,7 @@
77896 * finds that the saved generation number is smaller than the global generation
77897 * number, it wakes up the process.
77898 */
77899 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77900 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77901
77902 /*
77903 * Congestion monitoring
77904 @@ -232,7 +232,7 @@ void rds_cong_map_updated(struct rds_con
77905 rdsdebug("waking map %p for %pI4\n",
77906 map, &map->m_addr);
77907 rds_stats_inc(s_cong_update_received);
77908 - atomic_inc(&rds_cong_generation);
77909 + atomic_inc_unchecked(&rds_cong_generation);
77910 if (waitqueue_active(&map->m_waitq))
77911 wake_up(&map->m_waitq);
77912 if (waitqueue_active(&rds_poll_waitq))
77913 @@ -258,7 +258,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77914
77915 int rds_cong_updated_since(unsigned long *recent)
77916 {
77917 - unsigned long gen = atomic_read(&rds_cong_generation);
77918 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77919
77920 if (likely(*recent == gen))
77921 return 0;
77922 diff -urNp linux-2.6.32.46/net/rds/iw_rdma.c linux-2.6.32.46/net/rds/iw_rdma.c
77923 --- linux-2.6.32.46/net/rds/iw_rdma.c 2011-03-27 14:31:47.000000000 -0400
77924 +++ linux-2.6.32.46/net/rds/iw_rdma.c 2011-05-16 21:46:57.000000000 -0400
77925 @@ -181,6 +181,8 @@ int rds_iw_update_cm_id(struct rds_iw_de
77926 struct rdma_cm_id *pcm_id;
77927 int rc;
77928
77929 + pax_track_stack();
77930 +
77931 src_addr = (struct sockaddr_in *)&cm_id->route.addr.src_addr;
77932 dst_addr = (struct sockaddr_in *)&cm_id->route.addr.dst_addr;
77933
77934 diff -urNp linux-2.6.32.46/net/rds/tcp.c linux-2.6.32.46/net/rds/tcp.c
77935 --- linux-2.6.32.46/net/rds/tcp.c 2011-03-27 14:31:47.000000000 -0400
77936 +++ linux-2.6.32.46/net/rds/tcp.c 2011-10-06 09:37:16.000000000 -0400
77937 @@ -57,7 +57,7 @@ void rds_tcp_nonagle(struct socket *sock
77938 int val = 1;
77939
77940 set_fs(KERNEL_DS);
77941 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77942 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77943 sizeof(val));
77944 set_fs(oldfs);
77945 }
77946 diff -urNp linux-2.6.32.46/net/rds/tcp_send.c linux-2.6.32.46/net/rds/tcp_send.c
77947 --- linux-2.6.32.46/net/rds/tcp_send.c 2011-03-27 14:31:47.000000000 -0400
77948 +++ linux-2.6.32.46/net/rds/tcp_send.c 2011-10-06 09:37:16.000000000 -0400
77949 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *
77950
77951 oldfs = get_fs();
77952 set_fs(KERNEL_DS);
77953 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77954 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77955 sizeof(val));
77956 set_fs(oldfs);
77957 }
77958 diff -urNp linux-2.6.32.46/net/rxrpc/af_rxrpc.c linux-2.6.32.46/net/rxrpc/af_rxrpc.c
77959 --- linux-2.6.32.46/net/rxrpc/af_rxrpc.c 2011-03-27 14:31:47.000000000 -0400
77960 +++ linux-2.6.32.46/net/rxrpc/af_rxrpc.c 2011-05-04 17:56:28.000000000 -0400
77961 @@ -38,7 +38,7 @@ static const struct proto_ops rxrpc_rpc_
77962 __be32 rxrpc_epoch;
77963
77964 /* current debugging ID */
77965 -atomic_t rxrpc_debug_id;
77966 +atomic_unchecked_t rxrpc_debug_id;
77967
77968 /* count of skbs currently in use */
77969 atomic_t rxrpc_n_skbs;
77970 diff -urNp linux-2.6.32.46/net/rxrpc/ar-ack.c linux-2.6.32.46/net/rxrpc/ar-ack.c
77971 --- linux-2.6.32.46/net/rxrpc/ar-ack.c 2011-03-27 14:31:47.000000000 -0400
77972 +++ linux-2.6.32.46/net/rxrpc/ar-ack.c 2011-05-16 21:46:57.000000000 -0400
77973 @@ -174,7 +174,7 @@ static void rxrpc_resend(struct rxrpc_ca
77974
77975 _enter("{%d,%d,%d,%d},",
77976 call->acks_hard, call->acks_unacked,
77977 - atomic_read(&call->sequence),
77978 + atomic_read_unchecked(&call->sequence),
77979 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77980
77981 stop = 0;
77982 @@ -198,7 +198,7 @@ static void rxrpc_resend(struct rxrpc_ca
77983
77984 /* each Tx packet has a new serial number */
77985 sp->hdr.serial =
77986 - htonl(atomic_inc_return(&call->conn->serial));
77987 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77988
77989 hdr = (struct rxrpc_header *) txb->head;
77990 hdr->serial = sp->hdr.serial;
77991 @@ -401,7 +401,7 @@ static void rxrpc_rotate_tx_window(struc
77992 */
77993 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77994 {
77995 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77996 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77997 }
77998
77999 /*
78000 @@ -627,7 +627,7 @@ process_further:
78001
78002 latest = ntohl(sp->hdr.serial);
78003 hard = ntohl(ack.firstPacket);
78004 - tx = atomic_read(&call->sequence);
78005 + tx = atomic_read_unchecked(&call->sequence);
78006
78007 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78008 latest,
78009 @@ -840,6 +840,8 @@ void rxrpc_process_call(struct work_stru
78010 u32 abort_code = RX_PROTOCOL_ERROR;
78011 u8 *acks = NULL;
78012
78013 + pax_track_stack();
78014 +
78015 //printk("\n--------------------\n");
78016 _enter("{%d,%s,%lx} [%lu]",
78017 call->debug_id, rxrpc_call_states[call->state], call->events,
78018 @@ -1159,7 +1161,7 @@ void rxrpc_process_call(struct work_stru
78019 goto maybe_reschedule;
78020
78021 send_ACK_with_skew:
78022 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78023 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78024 ntohl(ack.serial));
78025 send_ACK:
78026 mtu = call->conn->trans->peer->if_mtu;
78027 @@ -1171,7 +1173,7 @@ send_ACK:
78028 ackinfo.rxMTU = htonl(5692);
78029 ackinfo.jumbo_max = htonl(4);
78030
78031 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78032 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78033 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78034 ntohl(hdr.serial),
78035 ntohs(ack.maxSkew),
78036 @@ -1189,7 +1191,7 @@ send_ACK:
78037 send_message:
78038 _debug("send message");
78039
78040 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78041 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78042 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78043 send_message_2:
78044
78045 diff -urNp linux-2.6.32.46/net/rxrpc/ar-call.c linux-2.6.32.46/net/rxrpc/ar-call.c
78046 --- linux-2.6.32.46/net/rxrpc/ar-call.c 2011-03-27 14:31:47.000000000 -0400
78047 +++ linux-2.6.32.46/net/rxrpc/ar-call.c 2011-05-04 17:56:28.000000000 -0400
78048 @@ -82,7 +82,7 @@ static struct rxrpc_call *rxrpc_alloc_ca
78049 spin_lock_init(&call->lock);
78050 rwlock_init(&call->state_lock);
78051 atomic_set(&call->usage, 1);
78052 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78053 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78054 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78055
78056 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78057 diff -urNp linux-2.6.32.46/net/rxrpc/ar-connection.c linux-2.6.32.46/net/rxrpc/ar-connection.c
78058 --- linux-2.6.32.46/net/rxrpc/ar-connection.c 2011-03-27 14:31:47.000000000 -0400
78059 +++ linux-2.6.32.46/net/rxrpc/ar-connection.c 2011-05-04 17:56:28.000000000 -0400
78060 @@ -205,7 +205,7 @@ static struct rxrpc_connection *rxrpc_al
78061 rwlock_init(&conn->lock);
78062 spin_lock_init(&conn->state_lock);
78063 atomic_set(&conn->usage, 1);
78064 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78065 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78066 conn->avail_calls = RXRPC_MAXCALLS;
78067 conn->size_align = 4;
78068 conn->header_size = sizeof(struct rxrpc_header);
78069 diff -urNp linux-2.6.32.46/net/rxrpc/ar-connevent.c linux-2.6.32.46/net/rxrpc/ar-connevent.c
78070 --- linux-2.6.32.46/net/rxrpc/ar-connevent.c 2011-03-27 14:31:47.000000000 -0400
78071 +++ linux-2.6.32.46/net/rxrpc/ar-connevent.c 2011-05-04 17:56:28.000000000 -0400
78072 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct
78073
78074 len = iov[0].iov_len + iov[1].iov_len;
78075
78076 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78077 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78078 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78079
78080 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78081 diff -urNp linux-2.6.32.46/net/rxrpc/ar-input.c linux-2.6.32.46/net/rxrpc/ar-input.c
78082 --- linux-2.6.32.46/net/rxrpc/ar-input.c 2011-03-27 14:31:47.000000000 -0400
78083 +++ linux-2.6.32.46/net/rxrpc/ar-input.c 2011-05-04 17:56:28.000000000 -0400
78084 @@ -339,9 +339,9 @@ void rxrpc_fast_process_packet(struct rx
78085 /* track the latest serial number on this connection for ACK packet
78086 * information */
78087 serial = ntohl(sp->hdr.serial);
78088 - hi_serial = atomic_read(&call->conn->hi_serial);
78089 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78090 while (serial > hi_serial)
78091 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78092 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78093 serial);
78094
78095 /* request ACK generation for any ACK or DATA packet that requests
78096 diff -urNp linux-2.6.32.46/net/rxrpc/ar-internal.h linux-2.6.32.46/net/rxrpc/ar-internal.h
78097 --- linux-2.6.32.46/net/rxrpc/ar-internal.h 2011-03-27 14:31:47.000000000 -0400
78098 +++ linux-2.6.32.46/net/rxrpc/ar-internal.h 2011-05-04 17:56:28.000000000 -0400
78099 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78100 int error; /* error code for local abort */
78101 int debug_id; /* debug ID for printks */
78102 unsigned call_counter; /* call ID counter */
78103 - atomic_t serial; /* packet serial number counter */
78104 - atomic_t hi_serial; /* highest serial number received */
78105 + atomic_unchecked_t serial; /* packet serial number counter */
78106 + atomic_unchecked_t hi_serial; /* highest serial number received */
78107 u8 avail_calls; /* number of calls available */
78108 u8 size_align; /* data size alignment (for security) */
78109 u8 header_size; /* rxrpc + security header size */
78110 @@ -346,7 +346,7 @@ struct rxrpc_call {
78111 spinlock_t lock;
78112 rwlock_t state_lock; /* lock for state transition */
78113 atomic_t usage;
78114 - atomic_t sequence; /* Tx data packet sequence counter */
78115 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78116 u32 abort_code; /* local/remote abort code */
78117 enum { /* current state of call */
78118 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78119 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(stru
78120 */
78121 extern atomic_t rxrpc_n_skbs;
78122 extern __be32 rxrpc_epoch;
78123 -extern atomic_t rxrpc_debug_id;
78124 +extern atomic_unchecked_t rxrpc_debug_id;
78125 extern struct workqueue_struct *rxrpc_workqueue;
78126
78127 /*
78128 diff -urNp linux-2.6.32.46/net/rxrpc/ar-key.c linux-2.6.32.46/net/rxrpc/ar-key.c
78129 --- linux-2.6.32.46/net/rxrpc/ar-key.c 2011-03-27 14:31:47.000000000 -0400
78130 +++ linux-2.6.32.46/net/rxrpc/ar-key.c 2011-04-17 15:56:46.000000000 -0400
78131 @@ -88,11 +88,11 @@ static int rxrpc_instantiate_xdr_rxkad(s
78132 return ret;
78133
78134 plen -= sizeof(*token);
78135 - token = kmalloc(sizeof(*token), GFP_KERNEL);
78136 + token = kzalloc(sizeof(*token), GFP_KERNEL);
78137 if (!token)
78138 return -ENOMEM;
78139
78140 - token->kad = kmalloc(plen, GFP_KERNEL);
78141 + token->kad = kzalloc(plen, GFP_KERNEL);
78142 if (!token->kad) {
78143 kfree(token);
78144 return -ENOMEM;
78145 @@ -730,10 +730,10 @@ static int rxrpc_instantiate(struct key
78146 goto error;
78147
78148 ret = -ENOMEM;
78149 - token = kmalloc(sizeof(*token), GFP_KERNEL);
78150 + token = kzalloc(sizeof(*token), GFP_KERNEL);
78151 if (!token)
78152 goto error;
78153 - token->kad = kmalloc(plen, GFP_KERNEL);
78154 + token->kad = kzalloc(plen, GFP_KERNEL);
78155 if (!token->kad)
78156 goto error_free;
78157
78158 diff -urNp linux-2.6.32.46/net/rxrpc/ar-local.c linux-2.6.32.46/net/rxrpc/ar-local.c
78159 --- linux-2.6.32.46/net/rxrpc/ar-local.c 2011-03-27 14:31:47.000000000 -0400
78160 +++ linux-2.6.32.46/net/rxrpc/ar-local.c 2011-05-04 17:56:28.000000000 -0400
78161 @@ -44,7 +44,7 @@ struct rxrpc_local *rxrpc_alloc_local(st
78162 spin_lock_init(&local->lock);
78163 rwlock_init(&local->services_lock);
78164 atomic_set(&local->usage, 1);
78165 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78166 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78167 memcpy(&local->srx, srx, sizeof(*srx));
78168 }
78169
78170 diff -urNp linux-2.6.32.46/net/rxrpc/ar-output.c linux-2.6.32.46/net/rxrpc/ar-output.c
78171 --- linux-2.6.32.46/net/rxrpc/ar-output.c 2011-03-27 14:31:47.000000000 -0400
78172 +++ linux-2.6.32.46/net/rxrpc/ar-output.c 2011-05-04 17:56:28.000000000 -0400
78173 @@ -680,9 +680,9 @@ static int rxrpc_send_data(struct kiocb
78174 sp->hdr.cid = call->cid;
78175 sp->hdr.callNumber = call->call_id;
78176 sp->hdr.seq =
78177 - htonl(atomic_inc_return(&call->sequence));
78178 + htonl(atomic_inc_return_unchecked(&call->sequence));
78179 sp->hdr.serial =
78180 - htonl(atomic_inc_return(&conn->serial));
78181 + htonl(atomic_inc_return_unchecked(&conn->serial));
78182 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78183 sp->hdr.userStatus = 0;
78184 sp->hdr.securityIndex = conn->security_ix;
78185 diff -urNp linux-2.6.32.46/net/rxrpc/ar-peer.c linux-2.6.32.46/net/rxrpc/ar-peer.c
78186 --- linux-2.6.32.46/net/rxrpc/ar-peer.c 2011-03-27 14:31:47.000000000 -0400
78187 +++ linux-2.6.32.46/net/rxrpc/ar-peer.c 2011-05-04 17:56:28.000000000 -0400
78188 @@ -86,7 +86,7 @@ static struct rxrpc_peer *rxrpc_alloc_pe
78189 INIT_LIST_HEAD(&peer->error_targets);
78190 spin_lock_init(&peer->lock);
78191 atomic_set(&peer->usage, 1);
78192 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78193 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78194 memcpy(&peer->srx, srx, sizeof(*srx));
78195
78196 rxrpc_assess_MTU_size(peer);
78197 diff -urNp linux-2.6.32.46/net/rxrpc/ar-proc.c linux-2.6.32.46/net/rxrpc/ar-proc.c
78198 --- linux-2.6.32.46/net/rxrpc/ar-proc.c 2011-03-27 14:31:47.000000000 -0400
78199 +++ linux-2.6.32.46/net/rxrpc/ar-proc.c 2011-05-04 17:56:28.000000000 -0400
78200 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(str
78201 atomic_read(&conn->usage),
78202 rxrpc_conn_states[conn->state],
78203 key_serial(conn->key),
78204 - atomic_read(&conn->serial),
78205 - atomic_read(&conn->hi_serial));
78206 + atomic_read_unchecked(&conn->serial),
78207 + atomic_read_unchecked(&conn->hi_serial));
78208
78209 return 0;
78210 }
78211 diff -urNp linux-2.6.32.46/net/rxrpc/ar-transport.c linux-2.6.32.46/net/rxrpc/ar-transport.c
78212 --- linux-2.6.32.46/net/rxrpc/ar-transport.c 2011-03-27 14:31:47.000000000 -0400
78213 +++ linux-2.6.32.46/net/rxrpc/ar-transport.c 2011-05-04 17:56:28.000000000 -0400
78214 @@ -46,7 +46,7 @@ static struct rxrpc_transport *rxrpc_all
78215 spin_lock_init(&trans->client_lock);
78216 rwlock_init(&trans->conn_lock);
78217 atomic_set(&trans->usage, 1);
78218 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78219 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78220
78221 if (peer->srx.transport.family == AF_INET) {
78222 switch (peer->srx.transport_type) {
78223 diff -urNp linux-2.6.32.46/net/rxrpc/rxkad.c linux-2.6.32.46/net/rxrpc/rxkad.c
78224 --- linux-2.6.32.46/net/rxrpc/rxkad.c 2011-03-27 14:31:47.000000000 -0400
78225 +++ linux-2.6.32.46/net/rxrpc/rxkad.c 2011-05-16 21:46:57.000000000 -0400
78226 @@ -210,6 +210,8 @@ static int rxkad_secure_packet_encrypt(c
78227 u16 check;
78228 int nsg;
78229
78230 + pax_track_stack();
78231 +
78232 sp = rxrpc_skb(skb);
78233
78234 _enter("");
78235 @@ -337,6 +339,8 @@ static int rxkad_verify_packet_auth(cons
78236 u16 check;
78237 int nsg;
78238
78239 + pax_track_stack();
78240 +
78241 _enter("");
78242
78243 sp = rxrpc_skb(skb);
78244 @@ -609,7 +613,7 @@ static int rxkad_issue_challenge(struct
78245
78246 len = iov[0].iov_len + iov[1].iov_len;
78247
78248 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78249 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78250 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78251
78252 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78253 @@ -659,7 +663,7 @@ static int rxkad_send_response(struct rx
78254
78255 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78256
78257 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78258 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78259 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78260
78261 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78262 diff -urNp linux-2.6.32.46/net/sctp/proc.c linux-2.6.32.46/net/sctp/proc.c
78263 --- linux-2.6.32.46/net/sctp/proc.c 2011-03-27 14:31:47.000000000 -0400
78264 +++ linux-2.6.32.46/net/sctp/proc.c 2011-04-17 15:56:46.000000000 -0400
78265 @@ -213,7 +213,12 @@ static int sctp_eps_seq_show(struct seq_
78266 sctp_for_each_hentry(epb, node, &head->chain) {
78267 ep = sctp_ep(epb);
78268 sk = epb->sk;
78269 - seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
78270 + seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ",
78271 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78272 + NULL, NULL,
78273 +#else
78274 + ep, sk,
78275 +#endif
78276 sctp_sk(sk)->type, sk->sk_state, hash,
78277 epb->bind_addr.port,
78278 sock_i_uid(sk), sock_i_ino(sk));
78279 @@ -320,7 +325,12 @@ static int sctp_assocs_seq_show(struct s
78280 seq_printf(seq,
78281 "%8p %8p %-3d %-3d %-2d %-4d "
78282 "%4d %8d %8d %7d %5lu %-5d %5d ",
78283 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78284 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78285 + NULL, NULL,
78286 +#else
78287 + assoc, sk,
78288 +#endif
78289 + sctp_sk(sk)->type, sk->sk_state,
78290 assoc->state, hash,
78291 assoc->assoc_id,
78292 assoc->sndbuf_used,
78293 diff -urNp linux-2.6.32.46/net/sctp/socket.c linux-2.6.32.46/net/sctp/socket.c
78294 --- linux-2.6.32.46/net/sctp/socket.c 2011-03-27 14:31:47.000000000 -0400
78295 +++ linux-2.6.32.46/net/sctp/socket.c 2011-04-23 12:56:11.000000000 -0400
78296 @@ -5802,7 +5802,6 @@ pp_found:
78297 */
78298 int reuse = sk->sk_reuse;
78299 struct sock *sk2;
78300 - struct hlist_node *node;
78301
78302 SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n");
78303 if (pp->fastreuse && sk->sk_reuse &&
78304 diff -urNp linux-2.6.32.46/net/socket.c linux-2.6.32.46/net/socket.c
78305 --- linux-2.6.32.46/net/socket.c 2011-03-27 14:31:47.000000000 -0400
78306 +++ linux-2.6.32.46/net/socket.c 2011-10-06 09:37:16.000000000 -0400
78307 @@ -87,6 +87,7 @@
78308 #include <linux/wireless.h>
78309 #include <linux/nsproxy.h>
78310 #include <linux/magic.h>
78311 +#include <linux/in.h>
78312
78313 #include <asm/uaccess.h>
78314 #include <asm/unistd.h>
78315 @@ -97,6 +98,21 @@
78316 #include <net/sock.h>
78317 #include <linux/netfilter.h>
78318
78319 +extern void gr_attach_curr_ip(const struct sock *sk);
78320 +extern int gr_handle_sock_all(const int family, const int type,
78321 + const int protocol);
78322 +extern int gr_handle_sock_server(const struct sockaddr *sck);
78323 +extern int gr_handle_sock_server_other(const struct sock *sck);
78324 +extern int gr_handle_sock_client(const struct sockaddr *sck);
78325 +extern int gr_search_connect(struct socket * sock,
78326 + struct sockaddr_in * addr);
78327 +extern int gr_search_bind(struct socket * sock,
78328 + struct sockaddr_in * addr);
78329 +extern int gr_search_listen(struct socket * sock);
78330 +extern int gr_search_accept(struct socket * sock);
78331 +extern int gr_search_socket(const int domain, const int type,
78332 + const int protocol);
78333 +
78334 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78335 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78336 unsigned long nr_segs, loff_t pos);
78337 @@ -298,7 +314,7 @@ static int sockfs_get_sb(struct file_sys
78338 mnt);
78339 }
78340
78341 -static struct vfsmount *sock_mnt __read_mostly;
78342 +struct vfsmount *sock_mnt __read_mostly;
78343
78344 static struct file_system_type sock_fs_type = {
78345 .name = "sockfs",
78346 @@ -1154,6 +1170,8 @@ static int __sock_create(struct net *net
78347 return -EAFNOSUPPORT;
78348 if (type < 0 || type >= SOCK_MAX)
78349 return -EINVAL;
78350 + if (protocol < 0)
78351 + return -EINVAL;
78352
78353 /* Compatibility.
78354
78355 @@ -1283,6 +1301,16 @@ SYSCALL_DEFINE3(socket, int, family, int
78356 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78357 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78358
78359 + if(!gr_search_socket(family, type, protocol)) {
78360 + retval = -EACCES;
78361 + goto out;
78362 + }
78363 +
78364 + if (gr_handle_sock_all(family, type, protocol)) {
78365 + retval = -EACCES;
78366 + goto out;
78367 + }
78368 +
78369 retval = sock_create(family, type, protocol, &sock);
78370 if (retval < 0)
78371 goto out;
78372 @@ -1415,6 +1443,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
78373 if (sock) {
78374 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
78375 if (err >= 0) {
78376 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78377 + err = -EACCES;
78378 + goto error;
78379 + }
78380 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78381 + if (err)
78382 + goto error;
78383 +
78384 err = security_socket_bind(sock,
78385 (struct sockaddr *)&address,
78386 addrlen);
78387 @@ -1423,6 +1459,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
78388 (struct sockaddr *)
78389 &address, addrlen);
78390 }
78391 +error:
78392 fput_light(sock->file, fput_needed);
78393 }
78394 return err;
78395 @@ -1446,10 +1483,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
78396 if ((unsigned)backlog > somaxconn)
78397 backlog = somaxconn;
78398
78399 + if (gr_handle_sock_server_other(sock->sk)) {
78400 + err = -EPERM;
78401 + goto error;
78402 + }
78403 +
78404 + err = gr_search_listen(sock);
78405 + if (err)
78406 + goto error;
78407 +
78408 err = security_socket_listen(sock, backlog);
78409 if (!err)
78410 err = sock->ops->listen(sock, backlog);
78411
78412 +error:
78413 fput_light(sock->file, fput_needed);
78414 }
78415 return err;
78416 @@ -1492,6 +1539,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
78417 newsock->type = sock->type;
78418 newsock->ops = sock->ops;
78419
78420 + if (gr_handle_sock_server_other(sock->sk)) {
78421 + err = -EPERM;
78422 + sock_release(newsock);
78423 + goto out_put;
78424 + }
78425 +
78426 + err = gr_search_accept(sock);
78427 + if (err) {
78428 + sock_release(newsock);
78429 + goto out_put;
78430 + }
78431 +
78432 /*
78433 * We don't need try_module_get here, as the listening socket (sock)
78434 * has the protocol module (sock->ops->owner) held.
78435 @@ -1534,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
78436 fd_install(newfd, newfile);
78437 err = newfd;
78438
78439 + gr_attach_curr_ip(newsock->sk);
78440 +
78441 out_put:
78442 fput_light(sock->file, fput_needed);
78443 out:
78444 @@ -1571,6 +1632,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct
78445 int, addrlen)
78446 {
78447 struct socket *sock;
78448 + struct sockaddr *sck;
78449 struct sockaddr_storage address;
78450 int err, fput_needed;
78451
78452 @@ -1581,6 +1643,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct
78453 if (err < 0)
78454 goto out_put;
78455
78456 + sck = (struct sockaddr *)&address;
78457 +
78458 + if (gr_handle_sock_client(sck)) {
78459 + err = -EACCES;
78460 + goto out_put;
78461 + }
78462 +
78463 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78464 + if (err)
78465 + goto out_put;
78466 +
78467 err =
78468 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78469 if (err)
78470 @@ -1882,6 +1955,8 @@ SYSCALL_DEFINE3(sendmsg, int, fd, struct
78471 int err, ctl_len, iov_size, total_len;
78472 int fput_needed;
78473
78474 + pax_track_stack();
78475 +
78476 err = -EFAULT;
78477 if (MSG_CMSG_COMPAT & flags) {
78478 if (get_compat_msghdr(&msg_sys, msg_compat))
78479 @@ -2022,7 +2097,7 @@ SYSCALL_DEFINE3(recvmsg, int, fd, struct
78480 * kernel msghdr to use the kernel address space)
78481 */
78482
78483 - uaddr = (__force void __user *)msg_sys.msg_name;
78484 + uaddr = (void __force_user *)msg_sys.msg_name;
78485 uaddr_len = COMPAT_NAMELEN(msg);
78486 if (MSG_CMSG_COMPAT & flags) {
78487 err = verify_compat_iovec(&msg_sys, iov,
78488 diff -urNp linux-2.6.32.46/net/sunrpc/sched.c linux-2.6.32.46/net/sunrpc/sched.c
78489 --- linux-2.6.32.46/net/sunrpc/sched.c 2011-08-09 18:35:30.000000000 -0400
78490 +++ linux-2.6.32.46/net/sunrpc/sched.c 2011-08-09 18:34:01.000000000 -0400
78491 @@ -234,10 +234,10 @@ static int rpc_wait_bit_killable(void *w
78492 #ifdef RPC_DEBUG
78493 static void rpc_task_set_debuginfo(struct rpc_task *task)
78494 {
78495 - static atomic_t rpc_pid;
78496 + static atomic_unchecked_t rpc_pid;
78497
78498 task->tk_magic = RPC_TASK_MAGIC_ID;
78499 - task->tk_pid = atomic_inc_return(&rpc_pid);
78500 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78501 }
78502 #else
78503 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78504 diff -urNp linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma.c linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma.c
78505 --- linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma.c 2011-03-27 14:31:47.000000000 -0400
78506 +++ linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma.c 2011-05-04 17:56:20.000000000 -0400
78507 @@ -59,15 +59,15 @@ unsigned int svcrdma_max_req_size = RPCR
78508 static unsigned int min_max_inline = 4096;
78509 static unsigned int max_max_inline = 65536;
78510
78511 -atomic_t rdma_stat_recv;
78512 -atomic_t rdma_stat_read;
78513 -atomic_t rdma_stat_write;
78514 -atomic_t rdma_stat_sq_starve;
78515 -atomic_t rdma_stat_rq_starve;
78516 -atomic_t rdma_stat_rq_poll;
78517 -atomic_t rdma_stat_rq_prod;
78518 -atomic_t rdma_stat_sq_poll;
78519 -atomic_t rdma_stat_sq_prod;
78520 +atomic_unchecked_t rdma_stat_recv;
78521 +atomic_unchecked_t rdma_stat_read;
78522 +atomic_unchecked_t rdma_stat_write;
78523 +atomic_unchecked_t rdma_stat_sq_starve;
78524 +atomic_unchecked_t rdma_stat_rq_starve;
78525 +atomic_unchecked_t rdma_stat_rq_poll;
78526 +atomic_unchecked_t rdma_stat_rq_prod;
78527 +atomic_unchecked_t rdma_stat_sq_poll;
78528 +atomic_unchecked_t rdma_stat_sq_prod;
78529
78530 /* Temporary NFS request map and context caches */
78531 struct kmem_cache *svc_rdma_map_cachep;
78532 @@ -105,7 +105,7 @@ static int read_reset_stat(ctl_table *ta
78533 len -= *ppos;
78534 if (len > *lenp)
78535 len = *lenp;
78536 - if (len && copy_to_user(buffer, str_buf, len))
78537 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78538 return -EFAULT;
78539 *lenp = len;
78540 *ppos += len;
78541 @@ -149,63 +149,63 @@ static ctl_table svcrdma_parm_table[] =
78542 {
78543 .procname = "rdma_stat_read",
78544 .data = &rdma_stat_read,
78545 - .maxlen = sizeof(atomic_t),
78546 + .maxlen = sizeof(atomic_unchecked_t),
78547 .mode = 0644,
78548 .proc_handler = &read_reset_stat,
78549 },
78550 {
78551 .procname = "rdma_stat_recv",
78552 .data = &rdma_stat_recv,
78553 - .maxlen = sizeof(atomic_t),
78554 + .maxlen = sizeof(atomic_unchecked_t),
78555 .mode = 0644,
78556 .proc_handler = &read_reset_stat,
78557 },
78558 {
78559 .procname = "rdma_stat_write",
78560 .data = &rdma_stat_write,
78561 - .maxlen = sizeof(atomic_t),
78562 + .maxlen = sizeof(atomic_unchecked_t),
78563 .mode = 0644,
78564 .proc_handler = &read_reset_stat,
78565 },
78566 {
78567 .procname = "rdma_stat_sq_starve",
78568 .data = &rdma_stat_sq_starve,
78569 - .maxlen = sizeof(atomic_t),
78570 + .maxlen = sizeof(atomic_unchecked_t),
78571 .mode = 0644,
78572 .proc_handler = &read_reset_stat,
78573 },
78574 {
78575 .procname = "rdma_stat_rq_starve",
78576 .data = &rdma_stat_rq_starve,
78577 - .maxlen = sizeof(atomic_t),
78578 + .maxlen = sizeof(atomic_unchecked_t),
78579 .mode = 0644,
78580 .proc_handler = &read_reset_stat,
78581 },
78582 {
78583 .procname = "rdma_stat_rq_poll",
78584 .data = &rdma_stat_rq_poll,
78585 - .maxlen = sizeof(atomic_t),
78586 + .maxlen = sizeof(atomic_unchecked_t),
78587 .mode = 0644,
78588 .proc_handler = &read_reset_stat,
78589 },
78590 {
78591 .procname = "rdma_stat_rq_prod",
78592 .data = &rdma_stat_rq_prod,
78593 - .maxlen = sizeof(atomic_t),
78594 + .maxlen = sizeof(atomic_unchecked_t),
78595 .mode = 0644,
78596 .proc_handler = &read_reset_stat,
78597 },
78598 {
78599 .procname = "rdma_stat_sq_poll",
78600 .data = &rdma_stat_sq_poll,
78601 - .maxlen = sizeof(atomic_t),
78602 + .maxlen = sizeof(atomic_unchecked_t),
78603 .mode = 0644,
78604 .proc_handler = &read_reset_stat,
78605 },
78606 {
78607 .procname = "rdma_stat_sq_prod",
78608 .data = &rdma_stat_sq_prod,
78609 - .maxlen = sizeof(atomic_t),
78610 + .maxlen = sizeof(atomic_unchecked_t),
78611 .mode = 0644,
78612 .proc_handler = &read_reset_stat,
78613 },
78614 diff -urNp linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78615 --- linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c 2011-03-27 14:31:47.000000000 -0400
78616 +++ linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c 2011-05-04 17:56:28.000000000 -0400
78617 @@ -495,7 +495,7 @@ next_sge:
78618 svc_rdma_put_context(ctxt, 0);
78619 goto out;
78620 }
78621 - atomic_inc(&rdma_stat_read);
78622 + atomic_inc_unchecked(&rdma_stat_read);
78623
78624 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78625 chl_map->ch[ch_no].count -= read_wr.num_sge;
78626 @@ -606,7 +606,7 @@ int svc_rdma_recvfrom(struct svc_rqst *r
78627 dto_q);
78628 list_del_init(&ctxt->dto_q);
78629 } else {
78630 - atomic_inc(&rdma_stat_rq_starve);
78631 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78632 clear_bit(XPT_DATA, &xprt->xpt_flags);
78633 ctxt = NULL;
78634 }
78635 @@ -626,7 +626,7 @@ int svc_rdma_recvfrom(struct svc_rqst *r
78636 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78637 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78638 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78639 - atomic_inc(&rdma_stat_recv);
78640 + atomic_inc_unchecked(&rdma_stat_recv);
78641
78642 /* Build up the XDR from the receive buffers. */
78643 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78644 diff -urNp linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_sendto.c linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78645 --- linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_sendto.c 2011-03-27 14:31:47.000000000 -0400
78646 +++ linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_sendto.c 2011-05-04 17:56:28.000000000 -0400
78647 @@ -328,7 +328,7 @@ static int send_write(struct svcxprt_rdm
78648 write_wr.wr.rdma.remote_addr = to;
78649
78650 /* Post It */
78651 - atomic_inc(&rdma_stat_write);
78652 + atomic_inc_unchecked(&rdma_stat_write);
78653 if (svc_rdma_send(xprt, &write_wr))
78654 goto err;
78655 return 0;
78656 diff -urNp linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_transport.c linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_transport.c
78657 --- linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_transport.c 2011-03-27 14:31:47.000000000 -0400
78658 +++ linux-2.6.32.46/net/sunrpc/xprtrdma/svc_rdma_transport.c 2011-05-04 17:56:28.000000000 -0400
78659 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rd
78660 return;
78661
78662 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78663 - atomic_inc(&rdma_stat_rq_poll);
78664 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78665
78666 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78667 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78668 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rd
78669 }
78670
78671 if (ctxt)
78672 - atomic_inc(&rdma_stat_rq_prod);
78673 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78674
78675 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78676 /*
78677 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rd
78678 return;
78679
78680 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78681 - atomic_inc(&rdma_stat_sq_poll);
78682 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78683 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78684 if (wc.status != IB_WC_SUCCESS)
78685 /* Close the transport */
78686 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rd
78687 }
78688
78689 if (ctxt)
78690 - atomic_inc(&rdma_stat_sq_prod);
78691 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78692 }
78693
78694 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78695 @@ -1260,7 +1260,7 @@ int svc_rdma_send(struct svcxprt_rdma *x
78696 spin_lock_bh(&xprt->sc_lock);
78697 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78698 spin_unlock_bh(&xprt->sc_lock);
78699 - atomic_inc(&rdma_stat_sq_starve);
78700 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78701
78702 /* See if we can opportunistically reap SQ WR to make room */
78703 sq_cq_reap(xprt);
78704 diff -urNp linux-2.6.32.46/net/sysctl_net.c linux-2.6.32.46/net/sysctl_net.c
78705 --- linux-2.6.32.46/net/sysctl_net.c 2011-03-27 14:31:47.000000000 -0400
78706 +++ linux-2.6.32.46/net/sysctl_net.c 2011-04-17 15:56:46.000000000 -0400
78707 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ct
78708 struct ctl_table *table)
78709 {
78710 /* Allow network administrator to have same access as root. */
78711 - if (capable(CAP_NET_ADMIN)) {
78712 + if (capable_nolog(CAP_NET_ADMIN)) {
78713 int mode = (table->mode >> 6) & 7;
78714 return (mode << 6) | (mode << 3) | mode;
78715 }
78716 diff -urNp linux-2.6.32.46/net/tipc/link.c linux-2.6.32.46/net/tipc/link.c
78717 --- linux-2.6.32.46/net/tipc/link.c 2011-03-27 14:31:47.000000000 -0400
78718 +++ linux-2.6.32.46/net/tipc/link.c 2011-10-06 09:37:16.000000000 -0400
78719 @@ -1418,7 +1418,7 @@ again:
78720
78721 if (!sect_rest) {
78722 sect_rest = msg_sect[++curr_sect].iov_len;
78723 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78724 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78725 }
78726
78727 if (sect_rest < fragm_rest)
78728 @@ -1437,7 +1437,7 @@ error:
78729 }
78730 } else
78731 skb_copy_to_linear_data_offset(buf, fragm_crs,
78732 - sect_crs, sz);
78733 + (const void __force_kernel *)sect_crs, sz);
78734 sect_crs += sz;
78735 sect_rest -= sz;
78736 fragm_crs += sz;
78737 diff -urNp linux-2.6.32.46/net/tipc/subscr.c linux-2.6.32.46/net/tipc/subscr.c
78738 --- linux-2.6.32.46/net/tipc/subscr.c 2011-03-27 14:31:47.000000000 -0400
78739 +++ linux-2.6.32.46/net/tipc/subscr.c 2011-10-06 09:37:16.000000000 -0400
78740 @@ -104,7 +104,7 @@ static void subscr_send_event(struct sub
78741 {
78742 struct iovec msg_sect;
78743
78744 - msg_sect.iov_base = (void *)&sub->evt;
78745 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78746 msg_sect.iov_len = sizeof(struct tipc_event);
78747
78748 sub->evt.event = htohl(event, sub->swap);
78749 diff -urNp linux-2.6.32.46/net/unix/af_unix.c linux-2.6.32.46/net/unix/af_unix.c
78750 --- linux-2.6.32.46/net/unix/af_unix.c 2011-05-10 22:12:02.000000000 -0400
78751 +++ linux-2.6.32.46/net/unix/af_unix.c 2011-07-18 18:17:33.000000000 -0400
78752 @@ -745,6 +745,12 @@ static struct sock *unix_find_other(stru
78753 err = -ECONNREFUSED;
78754 if (!S_ISSOCK(inode->i_mode))
78755 goto put_fail;
78756 +
78757 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78758 + err = -EACCES;
78759 + goto put_fail;
78760 + }
78761 +
78762 u = unix_find_socket_byinode(net, inode);
78763 if (!u)
78764 goto put_fail;
78765 @@ -765,6 +771,13 @@ static struct sock *unix_find_other(stru
78766 if (u) {
78767 struct dentry *dentry;
78768 dentry = unix_sk(u)->dentry;
78769 +
78770 + if (!gr_handle_chroot_unix(u->sk_peercred.pid)) {
78771 + err = -EPERM;
78772 + sock_put(u);
78773 + goto fail;
78774 + }
78775 +
78776 if (dentry)
78777 touch_atime(unix_sk(u)->mnt, dentry);
78778 } else
78779 @@ -850,11 +863,18 @@ static int unix_bind(struct socket *sock
78780 err = security_path_mknod(&nd.path, dentry, mode, 0);
78781 if (err)
78782 goto out_mknod_drop_write;
78783 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
78784 + err = -EACCES;
78785 + goto out_mknod_drop_write;
78786 + }
78787 err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
78788 out_mknod_drop_write:
78789 mnt_drop_write(nd.path.mnt);
78790 if (err)
78791 goto out_mknod_dput;
78792 +
78793 + gr_handle_create(dentry, nd.path.mnt);
78794 +
78795 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
78796 dput(nd.path.dentry);
78797 nd.path.dentry = dentry;
78798 @@ -2211,7 +2231,11 @@ static int unix_seq_show(struct seq_file
78799 unix_state_lock(s);
78800
78801 seq_printf(seq, "%p: %08X %08X %08X %04X %02X %5lu",
78802 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78803 + NULL,
78804 +#else
78805 s,
78806 +#endif
78807 atomic_read(&s->sk_refcnt),
78808 0,
78809 s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
78810 diff -urNp linux-2.6.32.46/net/wireless/core.h linux-2.6.32.46/net/wireless/core.h
78811 --- linux-2.6.32.46/net/wireless/core.h 2011-03-27 14:31:47.000000000 -0400
78812 +++ linux-2.6.32.46/net/wireless/core.h 2011-08-23 21:22:38.000000000 -0400
78813 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78814 struct mutex mtx;
78815
78816 /* rfkill support */
78817 - struct rfkill_ops rfkill_ops;
78818 + rfkill_ops_no_const rfkill_ops;
78819 struct rfkill *rfkill;
78820 struct work_struct rfkill_sync;
78821
78822 diff -urNp linux-2.6.32.46/net/wireless/wext.c linux-2.6.32.46/net/wireless/wext.c
78823 --- linux-2.6.32.46/net/wireless/wext.c 2011-03-27 14:31:47.000000000 -0400
78824 +++ linux-2.6.32.46/net/wireless/wext.c 2011-04-17 15:56:46.000000000 -0400
78825 @@ -816,8 +816,7 @@ static int ioctl_standard_iw_point(struc
78826 */
78827
78828 /* Support for very large requests */
78829 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78830 - (user_length > descr->max_tokens)) {
78831 + if (user_length > descr->max_tokens) {
78832 /* Allow userspace to GET more than max so
78833 * we can support any size GET requests.
78834 * There is still a limit : -ENOMEM.
78835 @@ -854,22 +853,6 @@ static int ioctl_standard_iw_point(struc
78836 }
78837 }
78838
78839 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78840 - /*
78841 - * If this is a GET, but not NOMAX, it means that the extra
78842 - * data is not bounded by userspace, but by max_tokens. Thus
78843 - * set the length to max_tokens. This matches the extra data
78844 - * allocation.
78845 - * The driver should fill it with the number of tokens it
78846 - * provided, and it may check iwp->length rather than having
78847 - * knowledge of max_tokens. If the driver doesn't change the
78848 - * iwp->length, this ioctl just copies back max_token tokens
78849 - * filled with zeroes. Hopefully the driver isn't claiming
78850 - * them to be valid data.
78851 - */
78852 - iwp->length = descr->max_tokens;
78853 - }
78854 -
78855 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78856
78857 iwp->length += essid_compat;
78858 diff -urNp linux-2.6.32.46/net/xfrm/xfrm_policy.c linux-2.6.32.46/net/xfrm/xfrm_policy.c
78859 --- linux-2.6.32.46/net/xfrm/xfrm_policy.c 2011-03-27 14:31:47.000000000 -0400
78860 +++ linux-2.6.32.46/net/xfrm/xfrm_policy.c 2011-05-04 17:56:20.000000000 -0400
78861 @@ -586,7 +586,7 @@ int xfrm_policy_insert(int dir, struct x
78862 hlist_add_head(&policy->bydst, chain);
78863 xfrm_pol_hold(policy);
78864 net->xfrm.policy_count[dir]++;
78865 - atomic_inc(&flow_cache_genid);
78866 + atomic_inc_unchecked(&flow_cache_genid);
78867 if (delpol)
78868 __xfrm_policy_unlink(delpol, dir);
78869 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78870 @@ -669,7 +669,7 @@ struct xfrm_policy *xfrm_policy_bysel_ct
78871 write_unlock_bh(&xfrm_policy_lock);
78872
78873 if (ret && delete) {
78874 - atomic_inc(&flow_cache_genid);
78875 + atomic_inc_unchecked(&flow_cache_genid);
78876 xfrm_policy_kill(ret);
78877 }
78878 return ret;
78879 @@ -710,7 +710,7 @@ struct xfrm_policy *xfrm_policy_byid(str
78880 write_unlock_bh(&xfrm_policy_lock);
78881
78882 if (ret && delete) {
78883 - atomic_inc(&flow_cache_genid);
78884 + atomic_inc_unchecked(&flow_cache_genid);
78885 xfrm_policy_kill(ret);
78886 }
78887 return ret;
78888 @@ -824,7 +824,7 @@ int xfrm_policy_flush(struct net *net, u
78889 }
78890
78891 }
78892 - atomic_inc(&flow_cache_genid);
78893 + atomic_inc_unchecked(&flow_cache_genid);
78894 out:
78895 write_unlock_bh(&xfrm_policy_lock);
78896 return err;
78897 @@ -1088,7 +1088,7 @@ int xfrm_policy_delete(struct xfrm_polic
78898 write_unlock_bh(&xfrm_policy_lock);
78899 if (pol) {
78900 if (dir < XFRM_POLICY_MAX)
78901 - atomic_inc(&flow_cache_genid);
78902 + atomic_inc_unchecked(&flow_cache_genid);
78903 xfrm_policy_kill(pol);
78904 return 0;
78905 }
78906 @@ -1477,7 +1477,7 @@ free_dst:
78907 goto out;
78908 }
78909
78910 -static int inline
78911 +static inline int
78912 xfrm_dst_alloc_copy(void **target, void *src, int size)
78913 {
78914 if (!*target) {
78915 @@ -1489,7 +1489,7 @@ xfrm_dst_alloc_copy(void **target, void
78916 return 0;
78917 }
78918
78919 -static int inline
78920 +static inline int
78921 xfrm_dst_update_parent(struct dst_entry *dst, struct xfrm_selector *sel)
78922 {
78923 #ifdef CONFIG_XFRM_SUB_POLICY
78924 @@ -1501,7 +1501,7 @@ xfrm_dst_update_parent(struct dst_entry
78925 #endif
78926 }
78927
78928 -static int inline
78929 +static inline int
78930 xfrm_dst_update_origin(struct dst_entry *dst, struct flowi *fl)
78931 {
78932 #ifdef CONFIG_XFRM_SUB_POLICY
78933 @@ -1537,7 +1537,7 @@ int __xfrm_lookup(struct net *net, struc
78934 u8 dir = policy_to_flow_dir(XFRM_POLICY_OUT);
78935
78936 restart:
78937 - genid = atomic_read(&flow_cache_genid);
78938 + genid = atomic_read_unchecked(&flow_cache_genid);
78939 policy = NULL;
78940 for (pi = 0; pi < ARRAY_SIZE(pols); pi++)
78941 pols[pi] = NULL;
78942 @@ -1680,7 +1680,7 @@ restart:
78943 goto error;
78944 }
78945 if (nx == -EAGAIN ||
78946 - genid != atomic_read(&flow_cache_genid)) {
78947 + genid != atomic_read_unchecked(&flow_cache_genid)) {
78948 xfrm_pols_put(pols, npols);
78949 goto restart;
78950 }
78951 diff -urNp linux-2.6.32.46/net/xfrm/xfrm_user.c linux-2.6.32.46/net/xfrm/xfrm_user.c
78952 --- linux-2.6.32.46/net/xfrm/xfrm_user.c 2011-03-27 14:31:47.000000000 -0400
78953 +++ linux-2.6.32.46/net/xfrm/xfrm_user.c 2011-05-16 21:46:57.000000000 -0400
78954 @@ -1169,6 +1169,8 @@ static int copy_to_user_tmpl(struct xfrm
78955 struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH];
78956 int i;
78957
78958 + pax_track_stack();
78959 +
78960 if (xp->xfrm_nr == 0)
78961 return 0;
78962
78963 @@ -1784,6 +1786,8 @@ static int xfrm_do_migrate(struct sk_buf
78964 int err;
78965 int n = 0;
78966
78967 + pax_track_stack();
78968 +
78969 if (attrs[XFRMA_MIGRATE] == NULL)
78970 return -EINVAL;
78971
78972 diff -urNp linux-2.6.32.46/samples/kobject/kset-example.c linux-2.6.32.46/samples/kobject/kset-example.c
78973 --- linux-2.6.32.46/samples/kobject/kset-example.c 2011-03-27 14:31:47.000000000 -0400
78974 +++ linux-2.6.32.46/samples/kobject/kset-example.c 2011-04-17 15:56:46.000000000 -0400
78975 @@ -87,7 +87,7 @@ static ssize_t foo_attr_store(struct kob
78976 }
78977
78978 /* Our custom sysfs_ops that we will associate with our ktype later on */
78979 -static struct sysfs_ops foo_sysfs_ops = {
78980 +static const struct sysfs_ops foo_sysfs_ops = {
78981 .show = foo_attr_show,
78982 .store = foo_attr_store,
78983 };
78984 diff -urNp linux-2.6.32.46/scripts/Makefile.build linux-2.6.32.46/scripts/Makefile.build
78985 --- linux-2.6.32.46/scripts/Makefile.build 2011-03-27 14:31:47.000000000 -0400
78986 +++ linux-2.6.32.46/scripts/Makefile.build 2011-08-23 20:45:11.000000000 -0400
78987 @@ -59,7 +59,7 @@ endif
78988 endif
78989
78990 # Do not include host rules unless needed
78991 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78992 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
78993 include scripts/Makefile.host
78994 endif
78995
78996 diff -urNp linux-2.6.32.46/scripts/Makefile.clean linux-2.6.32.46/scripts/Makefile.clean
78997 --- linux-2.6.32.46/scripts/Makefile.clean 2011-03-27 14:31:47.000000000 -0400
78998 +++ linux-2.6.32.46/scripts/Makefile.clean 2011-06-04 20:47:19.000000000 -0400
78999 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subd
79000 __clean-files := $(extra-y) $(always) \
79001 $(targets) $(clean-files) \
79002 $(host-progs) \
79003 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79004 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79005 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79006
79007 # as clean-files is given relative to the current directory, this adds
79008 # a $(obj) prefix, except for absolute paths
79009 diff -urNp linux-2.6.32.46/scripts/Makefile.host linux-2.6.32.46/scripts/Makefile.host
79010 --- linux-2.6.32.46/scripts/Makefile.host 2011-03-27 14:31:47.000000000 -0400
79011 +++ linux-2.6.32.46/scripts/Makefile.host 2011-06-04 20:48:22.000000000 -0400
79012 @@ -31,6 +31,7 @@
79013 # Note: Shared libraries consisting of C++ files are not supported
79014
79015 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79016 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79017
79018 # C code
79019 # Executables compiled from a single .c file
79020 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(hos
79021 # Shared libaries (only .c supported)
79022 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79023 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79024 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79025 # Remove .so files from "xxx-objs"
79026 host-cobjs := $(filter-out %.so,$(host-cobjs))
79027
79028 diff -urNp linux-2.6.32.46/scripts/basic/fixdep.c linux-2.6.32.46/scripts/basic/fixdep.c
79029 --- linux-2.6.32.46/scripts/basic/fixdep.c 2011-03-27 14:31:47.000000000 -0400
79030 +++ linux-2.6.32.46/scripts/basic/fixdep.c 2011-10-06 09:37:14.000000000 -0400
79031 @@ -162,7 +162,7 @@ static void grow_config(int len)
79032 /*
79033 * Lookup a value in the configuration string.
79034 */
79035 -static int is_defined_config(const char * name, int len)
79036 +static int is_defined_config(const char * name, unsigned int len)
79037 {
79038 const char * pconfig;
79039 const char * plast = str_config + len_config - len;
79040 @@ -199,7 +199,7 @@ static void clear_config(void)
79041 /*
79042 * Record the use of a CONFIG_* word.
79043 */
79044 -static void use_config(char *m, int slen)
79045 +static void use_config(char *m, unsigned int slen)
79046 {
79047 char s[PATH_MAX];
79048 char *p;
79049 @@ -222,9 +222,9 @@ static void use_config(char *m, int slen
79050
79051 static void parse_config_file(char *map, size_t len)
79052 {
79053 - int *end = (int *) (map + len);
79054 + unsigned int *end = (unsigned int *) (map + len);
79055 /* start at +1, so that p can never be < map */
79056 - int *m = (int *) map + 1;
79057 + unsigned int *m = (unsigned int *) map + 1;
79058 char *p, *q;
79059
79060 for (; m < end; m++) {
79061 @@ -371,7 +371,7 @@ static void print_deps(void)
79062 static void traps(void)
79063 {
79064 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79065 - int *p = (int *)test;
79066 + unsigned int *p = (unsigned int *)test;
79067
79068 if (*p != INT_CONF) {
79069 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79070 diff -urNp linux-2.6.32.46/scripts/gcc-plugin.sh linux-2.6.32.46/scripts/gcc-plugin.sh
79071 --- linux-2.6.32.46/scripts/gcc-plugin.sh 1969-12-31 19:00:00.000000000 -0500
79072 +++ linux-2.6.32.46/scripts/gcc-plugin.sh 2011-10-06 09:37:14.000000000 -0400
79073 @@ -0,0 +1,2 @@
79074 +#!/bin/sh
79075 +echo "#include \"gcc-plugin.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"
79076 diff -urNp linux-2.6.32.46/scripts/mod/file2alias.c linux-2.6.32.46/scripts/mod/file2alias.c
79077 --- linux-2.6.32.46/scripts/mod/file2alias.c 2011-03-27 14:31:47.000000000 -0400
79078 +++ linux-2.6.32.46/scripts/mod/file2alias.c 2011-10-06 09:37:14.000000000 -0400
79079 @@ -72,7 +72,7 @@ static void device_id_check(const char *
79080 unsigned long size, unsigned long id_size,
79081 void *symval)
79082 {
79083 - int i;
79084 + unsigned int i;
79085
79086 if (size % id_size || size < id_size) {
79087 if (cross_build != 0)
79088 @@ -102,7 +102,7 @@ static void device_id_check(const char *
79089 /* USB is special because the bcdDevice can be matched against a numeric range */
79090 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
79091 static void do_usb_entry(struct usb_device_id *id,
79092 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79093 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79094 unsigned char range_lo, unsigned char range_hi,
79095 struct module *mod)
79096 {
79097 @@ -151,7 +151,7 @@ static void do_usb_entry_multi(struct us
79098 {
79099 unsigned int devlo, devhi;
79100 unsigned char chi, clo;
79101 - int ndigits;
79102 + unsigned int ndigits;
79103
79104 id->match_flags = TO_NATIVE(id->match_flags);
79105 id->idVendor = TO_NATIVE(id->idVendor);
79106 @@ -368,7 +368,7 @@ static void do_pnp_device_entry(void *sy
79107 for (i = 0; i < count; i++) {
79108 const char *id = (char *)devs[i].id;
79109 char acpi_id[sizeof(devs[0].id)];
79110 - int j;
79111 + unsigned int j;
79112
79113 buf_printf(&mod->dev_table_buf,
79114 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79115 @@ -398,7 +398,7 @@ static void do_pnp_card_entries(void *sy
79116
79117 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79118 const char *id = (char *)card->devs[j].id;
79119 - int i2, j2;
79120 + unsigned int i2, j2;
79121 int dup = 0;
79122
79123 if (!id[0])
79124 @@ -424,7 +424,7 @@ static void do_pnp_card_entries(void *sy
79125 /* add an individual alias for every device entry */
79126 if (!dup) {
79127 char acpi_id[sizeof(card->devs[0].id)];
79128 - int k;
79129 + unsigned int k;
79130
79131 buf_printf(&mod->dev_table_buf,
79132 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79133 @@ -699,7 +699,7 @@ static void dmi_ascii_filter(char *d, co
79134 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79135 char *alias)
79136 {
79137 - int i, j;
79138 + unsigned int i, j;
79139
79140 sprintf(alias, "dmi*");
79141
79142 diff -urNp linux-2.6.32.46/scripts/mod/modpost.c linux-2.6.32.46/scripts/mod/modpost.c
79143 --- linux-2.6.32.46/scripts/mod/modpost.c 2011-03-27 14:31:47.000000000 -0400
79144 +++ linux-2.6.32.46/scripts/mod/modpost.c 2011-07-06 19:53:33.000000000 -0400
79145 @@ -835,6 +835,7 @@ enum mismatch {
79146 INIT_TO_EXIT,
79147 EXIT_TO_INIT,
79148 EXPORT_TO_INIT_EXIT,
79149 + DATA_TO_TEXT
79150 };
79151
79152 struct sectioncheck {
79153 @@ -920,6 +921,12 @@ const struct sectioncheck sectioncheck[]
79154 .fromsec = { "__ksymtab*", NULL },
79155 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79156 .mismatch = EXPORT_TO_INIT_EXIT
79157 +},
79158 +/* Do not reference code from writable data */
79159 +{
79160 + .fromsec = { DATA_SECTIONS, NULL },
79161 + .tosec = { TEXT_SECTIONS, NULL },
79162 + .mismatch = DATA_TO_TEXT
79163 }
79164 };
79165
79166 @@ -1024,10 +1031,10 @@ static Elf_Sym *find_elf_symbol(struct e
79167 continue;
79168 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
79169 continue;
79170 - if (sym->st_value == addr)
79171 - return sym;
79172 /* Find a symbol nearby - addr are maybe negative */
79173 d = sym->st_value - addr;
79174 + if (d == 0)
79175 + return sym;
79176 if (d < 0)
79177 d = addr - sym->st_value;
79178 if (d < distance) {
79179 @@ -1268,6 +1275,14 @@ static void report_sec_mismatch(const ch
79180 "Fix this by removing the %sannotation of %s "
79181 "or drop the export.\n",
79182 tosym, sec2annotation(tosec), sec2annotation(tosec), tosym);
79183 + case DATA_TO_TEXT:
79184 +/*
79185 + fprintf(stderr,
79186 + "The variable %s references\n"
79187 + "the %s %s%s%s\n",
79188 + fromsym, to, sec2annotation(tosec), tosym, to_p);
79189 +*/
79190 + break;
79191 case NO_MISMATCH:
79192 /* To get warnings on missing members */
79193 break;
79194 @@ -1495,7 +1510,7 @@ static void section_rel(const char *modn
79195 static void check_sec_ref(struct module *mod, const char *modname,
79196 struct elf_info *elf)
79197 {
79198 - int i;
79199 + unsigned int i;
79200 Elf_Shdr *sechdrs = elf->sechdrs;
79201
79202 /* Walk through all sections */
79203 @@ -1651,7 +1666,7 @@ void __attribute__((format(printf, 2, 3)
79204 va_end(ap);
79205 }
79206
79207 -void buf_write(struct buffer *buf, const char *s, int len)
79208 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79209 {
79210 if (buf->size - buf->pos < len) {
79211 buf->size += len + SZ;
79212 @@ -1863,7 +1878,7 @@ static void write_if_changed(struct buff
79213 if (fstat(fileno(file), &st) < 0)
79214 goto close_write;
79215
79216 - if (st.st_size != b->pos)
79217 + if (st.st_size != (off_t)b->pos)
79218 goto close_write;
79219
79220 tmp = NOFAIL(malloc(b->pos));
79221 diff -urNp linux-2.6.32.46/scripts/mod/modpost.h linux-2.6.32.46/scripts/mod/modpost.h
79222 --- linux-2.6.32.46/scripts/mod/modpost.h 2011-03-27 14:31:47.000000000 -0400
79223 +++ linux-2.6.32.46/scripts/mod/modpost.h 2011-04-17 15:56:46.000000000 -0400
79224 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *e
79225
79226 struct buffer {
79227 char *p;
79228 - int pos;
79229 - int size;
79230 + unsigned int pos;
79231 + unsigned int size;
79232 };
79233
79234 void __attribute__((format(printf, 2, 3)))
79235 buf_printf(struct buffer *buf, const char *fmt, ...);
79236
79237 void
79238 -buf_write(struct buffer *buf, const char *s, int len);
79239 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79240
79241 struct module {
79242 struct module *next;
79243 diff -urNp linux-2.6.32.46/scripts/mod/sumversion.c linux-2.6.32.46/scripts/mod/sumversion.c
79244 --- linux-2.6.32.46/scripts/mod/sumversion.c 2011-03-27 14:31:47.000000000 -0400
79245 +++ linux-2.6.32.46/scripts/mod/sumversion.c 2011-04-17 15:56:46.000000000 -0400
79246 @@ -455,7 +455,7 @@ static void write_version(const char *fi
79247 goto out;
79248 }
79249
79250 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79251 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79252 warn("writing sum in %s failed: %s\n",
79253 filename, strerror(errno));
79254 goto out;
79255 diff -urNp linux-2.6.32.46/scripts/package/mkspec linux-2.6.32.46/scripts/package/mkspec
79256 --- linux-2.6.32.46/scripts/package/mkspec 2011-03-27 14:31:47.000000000 -0400
79257 +++ linux-2.6.32.46/scripts/package/mkspec 2011-07-19 18:19:12.000000000 -0400
79258 @@ -70,7 +70,7 @@ echo 'mkdir -p $RPM_BUILD_ROOT/boot $RPM
79259 echo 'mkdir -p $RPM_BUILD_ROOT/lib/firmware'
79260 echo "%endif"
79261
79262 -echo 'INSTALL_MOD_PATH=$RPM_BUILD_ROOT make %{_smp_mflags} KBUILD_SRC= modules_install'
79263 +echo 'INSTALL_MOD_PATH=$RPM_BUILD_ROOT make %{?_smp_mflags} KBUILD_SRC= modules_install'
79264 echo "%ifarch ia64"
79265 echo 'cp $KBUILD_IMAGE $RPM_BUILD_ROOT'"/boot/efi/vmlinuz-$KERNELRELEASE"
79266 echo 'ln -s '"efi/vmlinuz-$KERNELRELEASE" '$RPM_BUILD_ROOT'"/boot/"
79267 diff -urNp linux-2.6.32.46/scripts/pnmtologo.c linux-2.6.32.46/scripts/pnmtologo.c
79268 --- linux-2.6.32.46/scripts/pnmtologo.c 2011-03-27 14:31:47.000000000 -0400
79269 +++ linux-2.6.32.46/scripts/pnmtologo.c 2011-04-17 15:56:46.000000000 -0400
79270 @@ -237,14 +237,14 @@ static void write_header(void)
79271 fprintf(out, " * Linux logo %s\n", logoname);
79272 fputs(" */\n\n", out);
79273 fputs("#include <linux/linux_logo.h>\n\n", out);
79274 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79275 + fprintf(out, "static unsigned char %s_data[] = {\n",
79276 logoname);
79277 }
79278
79279 static void write_footer(void)
79280 {
79281 fputs("\n};\n\n", out);
79282 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79283 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79284 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79285 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79286 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79287 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79288 fputs("\n};\n\n", out);
79289
79290 /* write logo clut */
79291 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79292 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79293 logoname);
79294 write_hex_cnt = 0;
79295 for (i = 0; i < logo_clutsize; i++) {
79296 diff -urNp linux-2.6.32.46/scripts/tags.sh linux-2.6.32.46/scripts/tags.sh
79297 --- linux-2.6.32.46/scripts/tags.sh 2011-03-27 14:31:47.000000000 -0400
79298 +++ linux-2.6.32.46/scripts/tags.sh 2011-06-07 18:06:04.000000000 -0400
79299 @@ -93,6 +93,11 @@ docscope()
79300 cscope -b -f cscope.out
79301 }
79302
79303 +dogtags()
79304 +{
79305 + all_sources | gtags -f -
79306 +}
79307 +
79308 exuberant()
79309 {
79310 all_sources | xargs $1 -a \
79311 @@ -164,6 +169,10 @@ case "$1" in
79312 docscope
79313 ;;
79314
79315 + "gtags")
79316 + dogtags
79317 + ;;
79318 +
79319 "tags")
79320 rm -f tags
79321 xtags ctags
79322 diff -urNp linux-2.6.32.46/security/Kconfig linux-2.6.32.46/security/Kconfig
79323 --- linux-2.6.32.46/security/Kconfig 2011-03-27 14:31:47.000000000 -0400
79324 +++ linux-2.6.32.46/security/Kconfig 2011-10-06 09:38:20.000000000 -0400
79325 @@ -4,6 +4,559 @@
79326
79327 menu "Security options"
79328
79329 +source grsecurity/Kconfig
79330 +
79331 +menu "PaX"
79332 +
79333 + config ARCH_TRACK_EXEC_LIMIT
79334 + bool
79335 +
79336 + config PAX_KERNEXEC_PLUGIN
79337 + bool
79338 +
79339 + config PAX_PER_CPU_PGD
79340 + bool
79341 +
79342 + config TASK_SIZE_MAX_SHIFT
79343 + int
79344 + depends on X86_64
79345 + default 47 if !PAX_PER_CPU_PGD
79346 + default 42 if PAX_PER_CPU_PGD
79347 +
79348 + config PAX_ENABLE_PAE
79349 + bool
79350 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79351 +
79352 +config PAX
79353 + bool "Enable various PaX features"
79354 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79355 + help
79356 + This allows you to enable various PaX features. PaX adds
79357 + intrusion prevention mechanisms to the kernel that reduce
79358 + the risks posed by exploitable memory corruption bugs.
79359 +
79360 +menu "PaX Control"
79361 + depends on PAX
79362 +
79363 +config PAX_SOFTMODE
79364 + bool 'Support soft mode'
79365 + select PAX_PT_PAX_FLAGS
79366 + help
79367 + Enabling this option will allow you to run PaX in soft mode, that
79368 + is, PaX features will not be enforced by default, only on executables
79369 + marked explicitly. You must also enable PT_PAX_FLAGS support as it
79370 + is the only way to mark executables for soft mode use.
79371 +
79372 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79373 + line option on boot. Furthermore you can control various PaX features
79374 + at runtime via the entries in /proc/sys/kernel/pax.
79375 +
79376 +config PAX_EI_PAX
79377 + bool 'Use legacy ELF header marking'
79378 + help
79379 + Enabling this option will allow you to control PaX features on
79380 + a per executable basis via the 'chpax' utility available at
79381 + http://pax.grsecurity.net/. The control flags will be read from
79382 + an otherwise reserved part of the ELF header. This marking has
79383 + numerous drawbacks (no support for soft-mode, toolchain does not
79384 + know about the non-standard use of the ELF header) therefore it
79385 + has been deprecated in favour of PT_PAX_FLAGS support.
79386 +
79387 + Note that if you enable PT_PAX_FLAGS marking support as well,
79388 + the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
79389 +
79390 +config PAX_PT_PAX_FLAGS
79391 + bool 'Use ELF program header marking'
79392 + help
79393 + Enabling this option will allow you to control PaX features on
79394 + a per executable basis via the 'paxctl' utility available at
79395 + http://pax.grsecurity.net/. The control flags will be read from
79396 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79397 + has the benefits of supporting both soft mode and being fully
79398 + integrated into the toolchain (the binutils patch is available
79399 + from http://pax.grsecurity.net).
79400 +
79401 + If your toolchain does not support PT_PAX_FLAGS markings,
79402 + you can create one in most cases with 'paxctl -C'.
79403 +
79404 + Note that if you enable the legacy EI_PAX marking support as well,
79405 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79406 +
79407 +choice
79408 + prompt 'MAC system integration'
79409 + default PAX_HAVE_ACL_FLAGS
79410 + help
79411 + Mandatory Access Control systems have the option of controlling
79412 + PaX flags on a per executable basis, choose the method supported
79413 + by your particular system.
79414 +
79415 + - "none": if your MAC system does not interact with PaX,
79416 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79417 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79418 +
79419 + NOTE: this option is for developers/integrators only.
79420 +
79421 + config PAX_NO_ACL_FLAGS
79422 + bool 'none'
79423 +
79424 + config PAX_HAVE_ACL_FLAGS
79425 + bool 'direct'
79426 +
79427 + config PAX_HOOK_ACL_FLAGS
79428 + bool 'hook'
79429 +endchoice
79430 +
79431 +endmenu
79432 +
79433 +menu "Non-executable pages"
79434 + depends on PAX
79435 +
79436 +config PAX_NOEXEC
79437 + bool "Enforce non-executable pages"
79438 + depends on (PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86)
79439 + help
79440 + By design some architectures do not allow for protecting memory
79441 + pages against execution or even if they do, Linux does not make
79442 + use of this feature. In practice this means that if a page is
79443 + readable (such as the stack or heap) it is also executable.
79444 +
79445 + There is a well known exploit technique that makes use of this
79446 + fact and a common programming mistake where an attacker can
79447 + introduce code of his choice somewhere in the attacked program's
79448 + memory (typically the stack or the heap) and then execute it.
79449 +
79450 + If the attacked program was running with different (typically
79451 + higher) privileges than that of the attacker, then he can elevate
79452 + his own privilege level (e.g. get a root shell, write to files for
79453 + which he does not have write access to, etc).
79454 +
79455 + Enabling this option will let you choose from various features
79456 + that prevent the injection and execution of 'foreign' code in
79457 + a program.
79458 +
79459 + This will also break programs that rely on the old behaviour and
79460 + expect that dynamically allocated memory via the malloc() family
79461 + of functions is executable (which it is not). Notable examples
79462 + are the XFree86 4.x server, the java runtime and wine.
79463 +
79464 +config PAX_PAGEEXEC
79465 + bool "Paging based non-executable pages"
79466 + 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)
79467 + select S390_SWITCH_AMODE if S390
79468 + select S390_EXEC_PROTECT if S390
79469 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79470 + help
79471 + This implementation is based on the paging feature of the CPU.
79472 + On i386 without hardware non-executable bit support there is a
79473 + variable but usually low performance impact, however on Intel's
79474 + P4 core based CPUs it is very high so you should not enable this
79475 + for kernels meant to be used on such CPUs.
79476 +
79477 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79478 + with hardware non-executable bit support there is no performance
79479 + impact, on ppc the impact is negligible.
79480 +
79481 + Note that several architectures require various emulations due to
79482 + badly designed userland ABIs, this will cause a performance impact
79483 + but will disappear as soon as userland is fixed. For example, ppc
79484 + userland MUST have been built with secure-plt by a recent toolchain.
79485 +
79486 +config PAX_SEGMEXEC
79487 + bool "Segmentation based non-executable pages"
79488 + depends on PAX_NOEXEC && X86_32
79489 + help
79490 + This implementation is based on the segmentation feature of the
79491 + CPU and has a very small performance impact, however applications
79492 + will be limited to a 1.5 GB address space instead of the normal
79493 + 3 GB.
79494 +
79495 +config PAX_EMUTRAMP
79496 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79497 + default y if PARISC
79498 + help
79499 + There are some programs and libraries that for one reason or
79500 + another attempt to execute special small code snippets from
79501 + non-executable memory pages. Most notable examples are the
79502 + signal handler return code generated by the kernel itself and
79503 + the GCC trampolines.
79504 +
79505 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79506 + such programs will no longer work under your kernel.
79507 +
79508 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79509 + utilities to enable trampoline emulation for the affected programs
79510 + yet still have the protection provided by the non-executable pages.
79511 +
79512 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79513 + your system will not even boot.
79514 +
79515 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79516 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79517 + for the affected files.
79518 +
79519 + NOTE: enabling this feature *may* open up a loophole in the
79520 + protection provided by non-executable pages that an attacker
79521 + could abuse. Therefore the best solution is to not have any
79522 + files on your system that would require this option. This can
79523 + be achieved by not using libc5 (which relies on the kernel
79524 + signal handler return code) and not using or rewriting programs
79525 + that make use of the nested function implementation of GCC.
79526 + Skilled users can just fix GCC itself so that it implements
79527 + nested function calls in a way that does not interfere with PaX.
79528 +
79529 +config PAX_EMUSIGRT
79530 + bool "Automatically emulate sigreturn trampolines"
79531 + depends on PAX_EMUTRAMP && PARISC
79532 + default y
79533 + help
79534 + Enabling this option will have the kernel automatically detect
79535 + and emulate signal return trampolines executing on the stack
79536 + that would otherwise lead to task termination.
79537 +
79538 + This solution is intended as a temporary one for users with
79539 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79540 + Modula-3 runtime, etc) or executables linked to such, basically
79541 + everything that does not specify its own SA_RESTORER function in
79542 + normal executable memory like glibc 2.1+ does.
79543 +
79544 + On parisc you MUST enable this option, otherwise your system will
79545 + not even boot.
79546 +
79547 + NOTE: this feature cannot be disabled on a per executable basis
79548 + and since it *does* open up a loophole in the protection provided
79549 + by non-executable pages, the best solution is to not have any
79550 + files on your system that would require this option.
79551 +
79552 +config PAX_MPROTECT
79553 + bool "Restrict mprotect()"
79554 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79555 + help
79556 + Enabling this option will prevent programs from
79557 + - changing the executable status of memory pages that were
79558 + not originally created as executable,
79559 + - making read-only executable pages writable again,
79560 + - creating executable pages from anonymous memory,
79561 + - making read-only-after-relocations (RELRO) data pages writable again.
79562 +
79563 + You should say Y here to complete the protection provided by
79564 + the enforcement of non-executable pages.
79565 +
79566 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79567 + this feature on a per file basis.
79568 +
79569 +config PAX_MPROTECT_COMPAT
79570 + bool "Use legacy/compat protection demoting (read help)"
79571 + depends on PAX_MPROTECT
79572 + default n
79573 + help
79574 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79575 + by sending the proper error code to the application. For some broken
79576 + userland, this can cause problems with Python or other applications. The
79577 + current implementation however allows for applications like clamav to
79578 + detect if JIT compilation/execution is allowed and to fall back gracefully
79579 + to an interpreter-based mode if it does not. While we encourage everyone
79580 + to use the current implementation as-is and push upstream to fix broken
79581 + userland (note that the RWX logging option can assist with this), in some
79582 + environments this may not be possible. Having to disable MPROTECT
79583 + completely on certain binaries reduces the security benefit of PaX,
79584 + so this option is provided for those environments to revert to the old
79585 + behavior.
79586 +
79587 +config PAX_ELFRELOCS
79588 + bool "Allow ELF text relocations (read help)"
79589 + depends on PAX_MPROTECT
79590 + default n
79591 + help
79592 + Non-executable pages and mprotect() restrictions are effective
79593 + in preventing the introduction of new executable code into an
79594 + attacked task's address space. There remain only two venues
79595 + for this kind of attack: if the attacker can execute already
79596 + existing code in the attacked task then he can either have it
79597 + create and mmap() a file containing his code or have it mmap()
79598 + an already existing ELF library that does not have position
79599 + independent code in it and use mprotect() on it to make it
79600 + writable and copy his code there. While protecting against
79601 + the former approach is beyond PaX, the latter can be prevented
79602 + by having only PIC ELF libraries on one's system (which do not
79603 + need to relocate their code). If you are sure this is your case,
79604 + as is the case with all modern Linux distributions, then leave
79605 + this option disabled. You should say 'n' here.
79606 +
79607 +config PAX_ETEXECRELOCS
79608 + bool "Allow ELF ET_EXEC text relocations"
79609 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79610 + select PAX_ELFRELOCS
79611 + default y
79612 + help
79613 + On some architectures there are incorrectly created applications
79614 + that require text relocations and would not work without enabling
79615 + this option. If you are an alpha, ia64 or parisc user, you should
79616 + enable this option and disable it once you have made sure that
79617 + none of your applications need it.
79618 +
79619 +config PAX_EMUPLT
79620 + bool "Automatically emulate ELF PLT"
79621 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79622 + default y
79623 + help
79624 + Enabling this option will have the kernel automatically detect
79625 + and emulate the Procedure Linkage Table entries in ELF files.
79626 + On some architectures such entries are in writable memory, and
79627 + become non-executable leading to task termination. Therefore
79628 + it is mandatory that you enable this option on alpha, parisc,
79629 + sparc and sparc64, otherwise your system would not even boot.
79630 +
79631 + NOTE: this feature *does* open up a loophole in the protection
79632 + provided by the non-executable pages, therefore the proper
79633 + solution is to modify the toolchain to produce a PLT that does
79634 + not need to be writable.
79635 +
79636 +config PAX_DLRESOLVE
79637 + bool 'Emulate old glibc resolver stub'
79638 + depends on PAX_EMUPLT && SPARC
79639 + default n
79640 + help
79641 + This option is needed if userland has an old glibc (before 2.4)
79642 + that puts a 'save' instruction into the runtime generated resolver
79643 + stub that needs special emulation.
79644 +
79645 +config PAX_KERNEXEC
79646 + bool "Enforce non-executable kernel pages"
79647 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79648 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79649 + select PAX_KERNEXEC_PLUGIN if X86_64
79650 + help
79651 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79652 + that is, enabling this option will make it harder to inject
79653 + and execute 'foreign' code in kernel memory itself.
79654 +
79655 + Note that on x86_64 kernels there is a known regression when
79656 + this feature and KVM/VMX are both enabled in the host kernel.
79657 +
79658 +config PAX_KERNEXEC_MODULE_TEXT
79659 + int "Minimum amount of memory reserved for module code"
79660 + default "4"
79661 + depends on PAX_KERNEXEC && X86_32 && MODULES
79662 + help
79663 + Due to implementation details the kernel must reserve a fixed
79664 + amount of memory for module code at compile time that cannot be
79665 + changed at runtime. Here you can specify the minimum amount
79666 + in MB that will be reserved. Due to the same implementation
79667 + details this size will always be rounded up to the next 2/4 MB
79668 + boundary (depends on PAE) so the actually available memory for
79669 + module code will usually be more than this minimum.
79670 +
79671 + The default 4 MB should be enough for most users but if you have
79672 + an excessive number of modules (e.g., most distribution configs
79673 + compile many drivers as modules) or use huge modules such as
79674 + nvidia's kernel driver, you will need to adjust this amount.
79675 + A good rule of thumb is to look at your currently loaded kernel
79676 + modules and add up their sizes.
79677 +
79678 +endmenu
79679 +
79680 +menu "Address Space Layout Randomization"
79681 + depends on PAX
79682 +
79683 +config PAX_ASLR
79684 + bool "Address Space Layout Randomization"
79685 + depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
79686 + help
79687 + Many if not most exploit techniques rely on the knowledge of
79688 + certain addresses in the attacked program. The following options
79689 + will allow the kernel to apply a certain amount of randomization
79690 + to specific parts of the program thereby forcing an attacker to
79691 + guess them in most cases. Any failed guess will most likely crash
79692 + the attacked program which allows the kernel to detect such attempts
79693 + and react on them. PaX itself provides no reaction mechanisms,
79694 + instead it is strongly encouraged that you make use of Nergal's
79695 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79696 + (http://www.grsecurity.net/) built-in crash detection features or
79697 + develop one yourself.
79698 +
79699 + By saying Y here you can choose to randomize the following areas:
79700 + - top of the task's kernel stack
79701 + - top of the task's userland stack
79702 + - base address for mmap() requests that do not specify one
79703 + (this includes all libraries)
79704 + - base address of the main executable
79705 +
79706 + It is strongly recommended to say Y here as address space layout
79707 + randomization has negligible impact on performance yet it provides
79708 + a very effective protection.
79709 +
79710 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79711 + this feature on a per file basis.
79712 +
79713 +config PAX_RANDKSTACK
79714 + bool "Randomize kernel stack base"
79715 + depends on X86_TSC && X86
79716 + help
79717 + By saying Y here the kernel will randomize every task's kernel
79718 + stack on every system call. This will not only force an attacker
79719 + to guess it but also prevent him from making use of possible
79720 + leaked information about it.
79721 +
79722 + Since the kernel stack is a rather scarce resource, randomization
79723 + may cause unexpected stack overflows, therefore you should very
79724 + carefully test your system. Note that once enabled in the kernel
79725 + configuration, this feature cannot be disabled on a per file basis.
79726 +
79727 +config PAX_RANDUSTACK
79728 + bool "Randomize user stack base"
79729 + depends on PAX_ASLR
79730 + help
79731 + By saying Y here the kernel will randomize every task's userland
79732 + stack. The randomization is done in two steps where the second
79733 + one may apply a big amount of shift to the top of the stack and
79734 + cause problems for programs that want to use lots of memory (more
79735 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79736 + For this reason the second step can be controlled by 'chpax' or
79737 + 'paxctl' on a per file basis.
79738 +
79739 +config PAX_RANDMMAP
79740 + bool "Randomize mmap() base"
79741 + depends on PAX_ASLR
79742 + help
79743 + By saying Y here the kernel will use a randomized base address for
79744 + mmap() requests that do not specify one themselves. As a result
79745 + all dynamically loaded libraries will appear at random addresses
79746 + and therefore be harder to exploit by a technique where an attacker
79747 + attempts to execute library code for his purposes (e.g. spawn a
79748 + shell from an exploited program that is running at an elevated
79749 + privilege level).
79750 +
79751 + Furthermore, if a program is relinked as a dynamic ELF file, its
79752 + base address will be randomized as well, completing the full
79753 + randomization of the address space layout. Attacking such programs
79754 + becomes a guess game. You can find an example of doing this at
79755 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79756 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79757 +
79758 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79759 + feature on a per file basis.
79760 +
79761 +endmenu
79762 +
79763 +menu "Miscellaneous hardening features"
79764 +
79765 +config PAX_MEMORY_SANITIZE
79766 + bool "Sanitize all freed memory"
79767 + help
79768 + By saying Y here the kernel will erase memory pages as soon as they
79769 + are freed. This in turn reduces the lifetime of data stored in the
79770 + pages, making it less likely that sensitive information such as
79771 + passwords, cryptographic secrets, etc stay in memory for too long.
79772 +
79773 + This is especially useful for programs whose runtime is short, long
79774 + lived processes and the kernel itself benefit from this as long as
79775 + they operate on whole memory pages and ensure timely freeing of pages
79776 + that may hold sensitive information.
79777 +
79778 + The tradeoff is performance impact, on a single CPU system kernel
79779 + compilation sees a 3% slowdown, other systems and workloads may vary
79780 + and you are advised to test this feature on your expected workload
79781 + before deploying it.
79782 +
79783 + Note that this feature does not protect data stored in live pages,
79784 + e.g., process memory swapped to disk may stay there for a long time.
79785 +
79786 +config PAX_MEMORY_STACKLEAK
79787 + bool "Sanitize kernel stack"
79788 + depends on X86
79789 + help
79790 + By saying Y here the kernel will erase the kernel stack before it
79791 + returns from a system call. This in turn reduces the information
79792 + that a kernel stack leak bug can reveal.
79793 +
79794 + Note that such a bug can still leak information that was put on
79795 + the stack by the current system call (the one eventually triggering
79796 + the bug) but traces of earlier system calls on the kernel stack
79797 + cannot leak anymore.
79798 +
79799 + The tradeoff is performance impact, on a single CPU system kernel
79800 + compilation sees a 1% slowdown, other systems and workloads may vary
79801 + and you are advised to test this feature on your expected workload
79802 + before deploying it.
79803 +
79804 + Note: full support for this feature requires gcc with plugin support
79805 + so make sure your compiler is at least gcc 4.5.0 (cross compilation
79806 + is not supported). Using older gcc versions means that functions
79807 + with large enough stack frames may leave uninitialized memory behind
79808 + that may be exposed to a later syscall leaking the stack.
79809 +
79810 +config PAX_MEMORY_UDEREF
79811 + bool "Prevent invalid userland pointer dereference"
79812 + depends on X86 && !UML_X86 && !XEN
79813 + select PAX_PER_CPU_PGD if X86_64
79814 + help
79815 + By saying Y here the kernel will be prevented from dereferencing
79816 + userland pointers in contexts where the kernel expects only kernel
79817 + pointers. This is both a useful runtime debugging feature and a
79818 + security measure that prevents exploiting a class of kernel bugs.
79819 +
79820 + The tradeoff is that some virtualization solutions may experience
79821 + a huge slowdown and therefore you should not enable this feature
79822 + for kernels meant to run in such environments. Whether a given VM
79823 + solution is affected or not is best determined by simply trying it
79824 + out, the performance impact will be obvious right on boot as this
79825 + mechanism engages from very early on. A good rule of thumb is that
79826 + VMs running on CPUs without hardware virtualization support (i.e.,
79827 + the majority of IA-32 CPUs) will likely experience the slowdown.
79828 +
79829 +config PAX_REFCOUNT
79830 + bool "Prevent various kernel object reference counter overflows"
79831 + depends on GRKERNSEC && (X86 || SPARC64)
79832 + help
79833 + By saying Y here the kernel will detect and prevent overflowing
79834 + various (but not all) kinds of object reference counters. Such
79835 + overflows can normally occur due to bugs only and are often, if
79836 + not always, exploitable.
79837 +
79838 + The tradeoff is that data structures protected by an overflowed
79839 + refcount will never be freed and therefore will leak memory. Note
79840 + that this leak also happens even without this protection but in
79841 + that case the overflow can eventually trigger the freeing of the
79842 + data structure while it is still being used elsewhere, resulting
79843 + in the exploitable situation that this feature prevents.
79844 +
79845 + Since this has a negligible performance impact, you should enable
79846 + this feature.
79847 +
79848 +config PAX_USERCOPY
79849 + bool "Harden heap object copies between kernel and userland"
79850 + depends on X86 || PPC || SPARC || ARM
79851 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79852 + help
79853 + By saying Y here the kernel will enforce the size of heap objects
79854 + when they are copied in either direction between the kernel and
79855 + userland, even if only a part of the heap object is copied.
79856 +
79857 + Specifically, this checking prevents information leaking from the
79858 + kernel heap during kernel to userland copies (if the kernel heap
79859 + object is otherwise fully initialized) and prevents kernel heap
79860 + overflows during userland to kernel copies.
79861 +
79862 + Note that the current implementation provides the strictest bounds
79863 + checks for the SLUB allocator.
79864 +
79865 + Enabling this option also enables per-slab cache protection against
79866 + data in a given cache being copied into/out of via userland
79867 + accessors. Though the whitelist of regions will be reduced over
79868 + time, it notably protects important data structures like task structs.
79869 +
79870 +
79871 + If frame pointers are enabled on x86, this option will also
79872 + restrict copies into and out of the kernel stack to local variables
79873 + within a single frame.
79874 +
79875 + Since this has a negligible performance impact, you should enable
79876 + this feature.
79877 +
79878 +endmenu
79879 +
79880 +endmenu
79881 +
79882 config KEYS
79883 bool "Enable access key retention support"
79884 help
79885 @@ -146,7 +699,7 @@ config INTEL_TXT
79886 config LSM_MMAP_MIN_ADDR
79887 int "Low address space for LSM to protect from user allocation"
79888 depends on SECURITY && SECURITY_SELINUX
79889 - default 65536
79890 + default 32768
79891 help
79892 This is the portion of low virtual memory which should be protected
79893 from userspace allocation. Keeping a user from writing to low pages
79894 diff -urNp linux-2.6.32.46/security/capability.c linux-2.6.32.46/security/capability.c
79895 --- linux-2.6.32.46/security/capability.c 2011-03-27 14:31:47.000000000 -0400
79896 +++ linux-2.6.32.46/security/capability.c 2011-04-17 15:56:46.000000000 -0400
79897 @@ -890,7 +890,7 @@ static void cap_audit_rule_free(void *ls
79898 }
79899 #endif /* CONFIG_AUDIT */
79900
79901 -struct security_operations default_security_ops = {
79902 +struct security_operations default_security_ops __read_only = {
79903 .name = "default",
79904 };
79905
79906 diff -urNp linux-2.6.32.46/security/commoncap.c linux-2.6.32.46/security/commoncap.c
79907 --- linux-2.6.32.46/security/commoncap.c 2011-03-27 14:31:47.000000000 -0400
79908 +++ linux-2.6.32.46/security/commoncap.c 2011-08-17 19:22:13.000000000 -0400
79909 @@ -27,7 +27,7 @@
79910 #include <linux/sched.h>
79911 #include <linux/prctl.h>
79912 #include <linux/securebits.h>
79913 -
79914 +#include <net/sock.h>
79915 /*
79916 * If a non-root user executes a setuid-root binary in
79917 * !secure(SECURE_NOROOT) mode, then we raise capabilities.
79918 @@ -50,9 +50,18 @@ static void warn_setuid_and_fcaps_mixed(
79919 }
79920 }
79921
79922 +#ifdef CONFIG_NET
79923 +extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk);
79924 +#endif
79925 +
79926 int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
79927 {
79928 +#ifdef CONFIG_NET
79929 + NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink(sk);
79930 +#else
79931 NETLINK_CB(skb).eff_cap = current_cap();
79932 +#endif
79933 +
79934 return 0;
79935 }
79936
79937 @@ -582,6 +591,9 @@ int cap_bprm_secureexec(struct linux_bin
79938 {
79939 const struct cred *cred = current_cred();
79940
79941 + if (gr_acl_enable_at_secure())
79942 + return 1;
79943 +
79944 if (cred->uid != 0) {
79945 if (bprm->cap_effective)
79946 return 1;
79947 diff -urNp linux-2.6.32.46/security/integrity/ima/ima.h linux-2.6.32.46/security/integrity/ima/ima.h
79948 --- linux-2.6.32.46/security/integrity/ima/ima.h 2011-03-27 14:31:47.000000000 -0400
79949 +++ linux-2.6.32.46/security/integrity/ima/ima.h 2011-04-17 15:56:46.000000000 -0400
79950 @@ -84,8 +84,8 @@ void ima_add_violation(struct inode *ino
79951 extern spinlock_t ima_queue_lock;
79952
79953 struct ima_h_table {
79954 - atomic_long_t len; /* number of stored measurements in the list */
79955 - atomic_long_t violations;
79956 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79957 + atomic_long_unchecked_t violations;
79958 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79959 };
79960 extern struct ima_h_table ima_htable;
79961 diff -urNp linux-2.6.32.46/security/integrity/ima/ima_api.c linux-2.6.32.46/security/integrity/ima/ima_api.c
79962 --- linux-2.6.32.46/security/integrity/ima/ima_api.c 2011-03-27 14:31:47.000000000 -0400
79963 +++ linux-2.6.32.46/security/integrity/ima/ima_api.c 2011-04-17 15:56:46.000000000 -0400
79964 @@ -74,7 +74,7 @@ void ima_add_violation(struct inode *ino
79965 int result;
79966
79967 /* can overflow, only indicator */
79968 - atomic_long_inc(&ima_htable.violations);
79969 + atomic_long_inc_unchecked(&ima_htable.violations);
79970
79971 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79972 if (!entry) {
79973 diff -urNp linux-2.6.32.46/security/integrity/ima/ima_fs.c linux-2.6.32.46/security/integrity/ima/ima_fs.c
79974 --- linux-2.6.32.46/security/integrity/ima/ima_fs.c 2011-03-27 14:31:47.000000000 -0400
79975 +++ linux-2.6.32.46/security/integrity/ima/ima_fs.c 2011-04-17 15:56:46.000000000 -0400
79976 @@ -27,12 +27,12 @@
79977 static int valid_policy = 1;
79978 #define TMPBUFLEN 12
79979 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79980 - loff_t *ppos, atomic_long_t *val)
79981 + loff_t *ppos, atomic_long_unchecked_t *val)
79982 {
79983 char tmpbuf[TMPBUFLEN];
79984 ssize_t len;
79985
79986 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79987 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79988 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79989 }
79990
79991 diff -urNp linux-2.6.32.46/security/integrity/ima/ima_queue.c linux-2.6.32.46/security/integrity/ima/ima_queue.c
79992 --- linux-2.6.32.46/security/integrity/ima/ima_queue.c 2011-03-27 14:31:47.000000000 -0400
79993 +++ linux-2.6.32.46/security/integrity/ima/ima_queue.c 2011-04-17 15:56:46.000000000 -0400
79994 @@ -78,7 +78,7 @@ static int ima_add_digest_entry(struct i
79995 INIT_LIST_HEAD(&qe->later);
79996 list_add_tail_rcu(&qe->later, &ima_measurements);
79997
79998 - atomic_long_inc(&ima_htable.len);
79999 + atomic_long_inc_unchecked(&ima_htable.len);
80000 key = ima_hash_key(entry->digest);
80001 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
80002 return 0;
80003 diff -urNp linux-2.6.32.46/security/keys/keyring.c linux-2.6.32.46/security/keys/keyring.c
80004 --- linux-2.6.32.46/security/keys/keyring.c 2011-03-27 14:31:47.000000000 -0400
80005 +++ linux-2.6.32.46/security/keys/keyring.c 2011-04-18 22:03:00.000000000 -0400
80006 @@ -214,15 +214,15 @@ static long keyring_read(const struct ke
80007 ret = -EFAULT;
80008
80009 for (loop = 0; loop < klist->nkeys; loop++) {
80010 + key_serial_t serial;
80011 key = klist->keys[loop];
80012 + serial = key->serial;
80013
80014 tmp = sizeof(key_serial_t);
80015 if (tmp > buflen)
80016 tmp = buflen;
80017
80018 - if (copy_to_user(buffer,
80019 - &key->serial,
80020 - tmp) != 0)
80021 + if (copy_to_user(buffer, &serial, tmp))
80022 goto error;
80023
80024 buflen -= tmp;
80025 diff -urNp linux-2.6.32.46/security/min_addr.c linux-2.6.32.46/security/min_addr.c
80026 --- linux-2.6.32.46/security/min_addr.c 2011-03-27 14:31:47.000000000 -0400
80027 +++ linux-2.6.32.46/security/min_addr.c 2011-04-17 15:56:46.000000000 -0400
80028 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG
80029 */
80030 static void update_mmap_min_addr(void)
80031 {
80032 +#ifndef SPARC
80033 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
80034 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
80035 mmap_min_addr = dac_mmap_min_addr;
80036 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
80037 #else
80038 mmap_min_addr = dac_mmap_min_addr;
80039 #endif
80040 +#endif
80041 }
80042
80043 /*
80044 diff -urNp linux-2.6.32.46/security/root_plug.c linux-2.6.32.46/security/root_plug.c
80045 --- linux-2.6.32.46/security/root_plug.c 2011-03-27 14:31:47.000000000 -0400
80046 +++ linux-2.6.32.46/security/root_plug.c 2011-04-17 15:56:46.000000000 -0400
80047 @@ -70,7 +70,7 @@ static int rootplug_bprm_check_security
80048 return 0;
80049 }
80050
80051 -static struct security_operations rootplug_security_ops = {
80052 +static struct security_operations rootplug_security_ops __read_only = {
80053 .bprm_check_security = rootplug_bprm_check_security,
80054 };
80055
80056 diff -urNp linux-2.6.32.46/security/security.c linux-2.6.32.46/security/security.c
80057 --- linux-2.6.32.46/security/security.c 2011-03-27 14:31:47.000000000 -0400
80058 +++ linux-2.6.32.46/security/security.c 2011-04-17 15:56:46.000000000 -0400
80059 @@ -24,7 +24,7 @@ static __initdata char chosen_lsm[SECURI
80060 extern struct security_operations default_security_ops;
80061 extern void security_fixup_ops(struct security_operations *ops);
80062
80063 -struct security_operations *security_ops; /* Initialized to NULL */
80064 +struct security_operations *security_ops __read_only; /* Initialized to NULL */
80065
80066 static inline int verify(struct security_operations *ops)
80067 {
80068 @@ -106,7 +106,7 @@ int __init security_module_enable(struct
80069 * If there is already a security module registered with the kernel,
80070 * an error will be returned. Otherwise %0 is returned on success.
80071 */
80072 -int register_security(struct security_operations *ops)
80073 +int __init register_security(struct security_operations *ops)
80074 {
80075 if (verify(ops)) {
80076 printk(KERN_DEBUG "%s could not verify "
80077 diff -urNp linux-2.6.32.46/security/selinux/hooks.c linux-2.6.32.46/security/selinux/hooks.c
80078 --- linux-2.6.32.46/security/selinux/hooks.c 2011-03-27 14:31:47.000000000 -0400
80079 +++ linux-2.6.32.46/security/selinux/hooks.c 2011-04-17 15:56:46.000000000 -0400
80080 @@ -131,7 +131,7 @@ int selinux_enabled = 1;
80081 * Minimal support for a secondary security module,
80082 * just to allow the use of the capability module.
80083 */
80084 -static struct security_operations *secondary_ops;
80085 +static struct security_operations *secondary_ops __read_only;
80086
80087 /* Lists of inode and superblock security structures initialized
80088 before the policy was loaded. */
80089 @@ -5457,7 +5457,7 @@ static int selinux_key_getsecurity(struc
80090
80091 #endif
80092
80093 -static struct security_operations selinux_ops = {
80094 +static struct security_operations selinux_ops __read_only = {
80095 .name = "selinux",
80096
80097 .ptrace_access_check = selinux_ptrace_access_check,
80098 @@ -5841,7 +5841,9 @@ int selinux_disable(void)
80099 avc_disable();
80100
80101 /* Reset security_ops to the secondary module, dummy or capability. */
80102 + pax_open_kernel();
80103 security_ops = secondary_ops;
80104 + pax_close_kernel();
80105
80106 /* Unregister netfilter hooks. */
80107 selinux_nf_ip_exit();
80108 diff -urNp linux-2.6.32.46/security/selinux/include/xfrm.h linux-2.6.32.46/security/selinux/include/xfrm.h
80109 --- linux-2.6.32.46/security/selinux/include/xfrm.h 2011-03-27 14:31:47.000000000 -0400
80110 +++ linux-2.6.32.46/security/selinux/include/xfrm.h 2011-05-18 20:09:37.000000000 -0400
80111 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct s
80112
80113 static inline void selinux_xfrm_notify_policyload(void)
80114 {
80115 - atomic_inc(&flow_cache_genid);
80116 + atomic_inc_unchecked(&flow_cache_genid);
80117 }
80118 #else
80119 static inline int selinux_xfrm_enabled(void)
80120 diff -urNp linux-2.6.32.46/security/selinux/ss/services.c linux-2.6.32.46/security/selinux/ss/services.c
80121 --- linux-2.6.32.46/security/selinux/ss/services.c 2011-03-27 14:31:47.000000000 -0400
80122 +++ linux-2.6.32.46/security/selinux/ss/services.c 2011-05-16 21:46:57.000000000 -0400
80123 @@ -1715,6 +1715,8 @@ int security_load_policy(void *data, siz
80124 int rc = 0;
80125 struct policy_file file = { data, len }, *fp = &file;
80126
80127 + pax_track_stack();
80128 +
80129 if (!ss_initialized) {
80130 avtab_cache_init();
80131 if (policydb_read(&policydb, fp)) {
80132 diff -urNp linux-2.6.32.46/security/smack/smack_lsm.c linux-2.6.32.46/security/smack/smack_lsm.c
80133 --- linux-2.6.32.46/security/smack/smack_lsm.c 2011-03-27 14:31:47.000000000 -0400
80134 +++ linux-2.6.32.46/security/smack/smack_lsm.c 2011-04-17 15:56:46.000000000 -0400
80135 @@ -3073,7 +3073,7 @@ static int smack_inode_getsecctx(struct
80136 return 0;
80137 }
80138
80139 -struct security_operations smack_ops = {
80140 +struct security_operations smack_ops __read_only = {
80141 .name = "smack",
80142
80143 .ptrace_access_check = smack_ptrace_access_check,
80144 diff -urNp linux-2.6.32.46/security/tomoyo/tomoyo.c linux-2.6.32.46/security/tomoyo/tomoyo.c
80145 --- linux-2.6.32.46/security/tomoyo/tomoyo.c 2011-03-27 14:31:47.000000000 -0400
80146 +++ linux-2.6.32.46/security/tomoyo/tomoyo.c 2011-04-17 15:56:46.000000000 -0400
80147 @@ -275,7 +275,7 @@ static int tomoyo_dentry_open(struct fil
80148 * tomoyo_security_ops is a "struct security_operations" which is used for
80149 * registering TOMOYO.
80150 */
80151 -static struct security_operations tomoyo_security_ops = {
80152 +static struct security_operations tomoyo_security_ops __read_only = {
80153 .name = "tomoyo",
80154 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80155 .cred_prepare = tomoyo_cred_prepare,
80156 diff -urNp linux-2.6.32.46/sound/aoa/codecs/onyx.c linux-2.6.32.46/sound/aoa/codecs/onyx.c
80157 --- linux-2.6.32.46/sound/aoa/codecs/onyx.c 2011-03-27 14:31:47.000000000 -0400
80158 +++ linux-2.6.32.46/sound/aoa/codecs/onyx.c 2011-04-17 15:56:46.000000000 -0400
80159 @@ -53,7 +53,7 @@ struct onyx {
80160 spdif_locked:1,
80161 analog_locked:1,
80162 original_mute:2;
80163 - int open_count;
80164 + local_t open_count;
80165 struct codec_info *codec_info;
80166
80167 /* mutex serializes concurrent access to the device
80168 @@ -752,7 +752,7 @@ static int onyx_open(struct codec_info_i
80169 struct onyx *onyx = cii->codec_data;
80170
80171 mutex_lock(&onyx->mutex);
80172 - onyx->open_count++;
80173 + local_inc(&onyx->open_count);
80174 mutex_unlock(&onyx->mutex);
80175
80176 return 0;
80177 @@ -764,8 +764,7 @@ static int onyx_close(struct codec_info_
80178 struct onyx *onyx = cii->codec_data;
80179
80180 mutex_lock(&onyx->mutex);
80181 - onyx->open_count--;
80182 - if (!onyx->open_count)
80183 + if (local_dec_and_test(&onyx->open_count))
80184 onyx->spdif_locked = onyx->analog_locked = 0;
80185 mutex_unlock(&onyx->mutex);
80186
80187 diff -urNp linux-2.6.32.46/sound/aoa/codecs/onyx.h linux-2.6.32.46/sound/aoa/codecs/onyx.h
80188 --- linux-2.6.32.46/sound/aoa/codecs/onyx.h 2011-03-27 14:31:47.000000000 -0400
80189 +++ linux-2.6.32.46/sound/aoa/codecs/onyx.h 2011-04-17 15:56:46.000000000 -0400
80190 @@ -11,6 +11,7 @@
80191 #include <linux/i2c.h>
80192 #include <asm/pmac_low_i2c.h>
80193 #include <asm/prom.h>
80194 +#include <asm/local.h>
80195
80196 /* PCM3052 register definitions */
80197
80198 diff -urNp linux-2.6.32.46/sound/core/oss/pcm_oss.c linux-2.6.32.46/sound/core/oss/pcm_oss.c
80199 --- linux-2.6.32.46/sound/core/oss/pcm_oss.c 2011-03-27 14:31:47.000000000 -0400
80200 +++ linux-2.6.32.46/sound/core/oss/pcm_oss.c 2011-10-06 09:37:16.000000000 -0400
80201 @@ -1395,7 +1395,7 @@ static ssize_t snd_pcm_oss_write1(struct
80202 }
80203 } else {
80204 tmp = snd_pcm_oss_write2(substream,
80205 - (const char __force *)buf,
80206 + (const char __force_kernel *)buf,
80207 runtime->oss.period_bytes, 0);
80208 if (tmp <= 0)
80209 goto err;
80210 @@ -1483,7 +1483,7 @@ static ssize_t snd_pcm_oss_read1(struct
80211 xfer += tmp;
80212 runtime->oss.buffer_used -= tmp;
80213 } else {
80214 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80215 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80216 runtime->oss.period_bytes, 0);
80217 if (tmp <= 0)
80218 goto err;
80219 diff -urNp linux-2.6.32.46/sound/core/pcm_compat.c linux-2.6.32.46/sound/core/pcm_compat.c
80220 --- linux-2.6.32.46/sound/core/pcm_compat.c 2011-08-09 18:35:30.000000000 -0400
80221 +++ linux-2.6.32.46/sound/core/pcm_compat.c 2011-10-06 09:37:16.000000000 -0400
80222 @@ -30,7 +30,7 @@ static int snd_pcm_ioctl_delay_compat(st
80223 int err;
80224
80225 fs = snd_enter_user();
80226 - err = snd_pcm_delay(substream, &delay);
80227 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
80228 snd_leave_user(fs);
80229 if (err < 0)
80230 return err;
80231 diff -urNp linux-2.6.32.46/sound/core/pcm_native.c linux-2.6.32.46/sound/core/pcm_native.c
80232 --- linux-2.6.32.46/sound/core/pcm_native.c 2011-03-27 14:31:47.000000000 -0400
80233 +++ linux-2.6.32.46/sound/core/pcm_native.c 2011-10-06 09:37:16.000000000 -0400
80234 @@ -2747,11 +2747,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_
80235 switch (substream->stream) {
80236 case SNDRV_PCM_STREAM_PLAYBACK:
80237 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
80238 - (void __user *)arg);
80239 + (void __force_user *)arg);
80240 break;
80241 case SNDRV_PCM_STREAM_CAPTURE:
80242 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
80243 - (void __user *)arg);
80244 + (void __force_user *)arg);
80245 break;
80246 default:
80247 result = -EINVAL;
80248 diff -urNp linux-2.6.32.46/sound/core/seq/seq_device.c linux-2.6.32.46/sound/core/seq/seq_device.c
80249 --- linux-2.6.32.46/sound/core/seq/seq_device.c 2011-03-27 14:31:47.000000000 -0400
80250 +++ linux-2.6.32.46/sound/core/seq/seq_device.c 2011-08-05 20:33:55.000000000 -0400
80251 @@ -63,7 +63,7 @@ struct ops_list {
80252 int argsize; /* argument size */
80253
80254 /* operators */
80255 - struct snd_seq_dev_ops ops;
80256 + struct snd_seq_dev_ops *ops;
80257
80258 /* registred devices */
80259 struct list_head dev_list; /* list of devices */
80260 @@ -332,7 +332,7 @@ int snd_seq_device_register_driver(char
80261
80262 mutex_lock(&ops->reg_mutex);
80263 /* copy driver operators */
80264 - ops->ops = *entry;
80265 + ops->ops = entry;
80266 ops->driver |= DRIVER_LOADED;
80267 ops->argsize = argsize;
80268
80269 @@ -462,7 +462,7 @@ static int init_device(struct snd_seq_de
80270 dev->name, ops->id, ops->argsize, dev->argsize);
80271 return -EINVAL;
80272 }
80273 - if (ops->ops.init_device(dev) >= 0) {
80274 + if (ops->ops->init_device(dev) >= 0) {
80275 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
80276 ops->num_init_devices++;
80277 } else {
80278 @@ -489,7 +489,7 @@ static int free_device(struct snd_seq_de
80279 dev->name, ops->id, ops->argsize, dev->argsize);
80280 return -EINVAL;
80281 }
80282 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
80283 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
80284 dev->status = SNDRV_SEQ_DEVICE_FREE;
80285 dev->driver_data = NULL;
80286 ops->num_init_devices--;
80287 diff -urNp linux-2.6.32.46/sound/drivers/mts64.c linux-2.6.32.46/sound/drivers/mts64.c
80288 --- linux-2.6.32.46/sound/drivers/mts64.c 2011-03-27 14:31:47.000000000 -0400
80289 +++ linux-2.6.32.46/sound/drivers/mts64.c 2011-04-17 15:56:46.000000000 -0400
80290 @@ -27,6 +27,7 @@
80291 #include <sound/initval.h>
80292 #include <sound/rawmidi.h>
80293 #include <sound/control.h>
80294 +#include <asm/local.h>
80295
80296 #define CARD_NAME "Miditerminal 4140"
80297 #define DRIVER_NAME "MTS64"
80298 @@ -65,7 +66,7 @@ struct mts64 {
80299 struct pardevice *pardev;
80300 int pardev_claimed;
80301
80302 - int open_count;
80303 + local_t open_count;
80304 int current_midi_output_port;
80305 int current_midi_input_port;
80306 u8 mode[MTS64_NUM_INPUT_PORTS];
80307 @@ -695,7 +696,7 @@ static int snd_mts64_rawmidi_open(struct
80308 {
80309 struct mts64 *mts = substream->rmidi->private_data;
80310
80311 - if (mts->open_count == 0) {
80312 + if (local_read(&mts->open_count) == 0) {
80313 /* We don't need a spinlock here, because this is just called
80314 if the device has not been opened before.
80315 So there aren't any IRQs from the device */
80316 @@ -703,7 +704,7 @@ static int snd_mts64_rawmidi_open(struct
80317
80318 msleep(50);
80319 }
80320 - ++(mts->open_count);
80321 + local_inc(&mts->open_count);
80322
80323 return 0;
80324 }
80325 @@ -713,8 +714,7 @@ static int snd_mts64_rawmidi_close(struc
80326 struct mts64 *mts = substream->rmidi->private_data;
80327 unsigned long flags;
80328
80329 - --(mts->open_count);
80330 - if (mts->open_count == 0) {
80331 + if (local_dec_return(&mts->open_count) == 0) {
80332 /* We need the spinlock_irqsave here because we can still
80333 have IRQs at this point */
80334 spin_lock_irqsave(&mts->lock, flags);
80335 @@ -723,8 +723,8 @@ static int snd_mts64_rawmidi_close(struc
80336
80337 msleep(500);
80338
80339 - } else if (mts->open_count < 0)
80340 - mts->open_count = 0;
80341 + } else if (local_read(&mts->open_count) < 0)
80342 + local_set(&mts->open_count, 0);
80343
80344 return 0;
80345 }
80346 diff -urNp linux-2.6.32.46/sound/drivers/opl4/opl4_lib.c linux-2.6.32.46/sound/drivers/opl4/opl4_lib.c
80347 --- linux-2.6.32.46/sound/drivers/opl4/opl4_lib.c 2011-03-27 14:31:47.000000000 -0400
80348 +++ linux-2.6.32.46/sound/drivers/opl4/opl4_lib.c 2011-08-05 20:33:55.000000000 -0400
80349 @@ -27,7 +27,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@
80350 MODULE_DESCRIPTION("OPL4 driver");
80351 MODULE_LICENSE("GPL");
80352
80353 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
80354 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
80355 {
80356 int timeout = 10;
80357 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
80358 diff -urNp linux-2.6.32.46/sound/drivers/portman2x4.c linux-2.6.32.46/sound/drivers/portman2x4.c
80359 --- linux-2.6.32.46/sound/drivers/portman2x4.c 2011-03-27 14:31:47.000000000 -0400
80360 +++ linux-2.6.32.46/sound/drivers/portman2x4.c 2011-04-17 15:56:46.000000000 -0400
80361 @@ -46,6 +46,7 @@
80362 #include <sound/initval.h>
80363 #include <sound/rawmidi.h>
80364 #include <sound/control.h>
80365 +#include <asm/local.h>
80366
80367 #define CARD_NAME "Portman 2x4"
80368 #define DRIVER_NAME "portman"
80369 @@ -83,7 +84,7 @@ struct portman {
80370 struct pardevice *pardev;
80371 int pardev_claimed;
80372
80373 - int open_count;
80374 + local_t open_count;
80375 int mode[PORTMAN_NUM_INPUT_PORTS];
80376 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80377 };
80378 diff -urNp linux-2.6.32.46/sound/isa/cmi8330.c linux-2.6.32.46/sound/isa/cmi8330.c
80379 --- linux-2.6.32.46/sound/isa/cmi8330.c 2011-03-27 14:31:47.000000000 -0400
80380 +++ linux-2.6.32.46/sound/isa/cmi8330.c 2011-08-23 21:22:32.000000000 -0400
80381 @@ -173,7 +173,7 @@ struct snd_cmi8330 {
80382
80383 struct snd_pcm *pcm;
80384 struct snd_cmi8330_stream {
80385 - struct snd_pcm_ops ops;
80386 + snd_pcm_ops_no_const ops;
80387 snd_pcm_open_callback_t open;
80388 void *private_data; /* sb or wss */
80389 } streams[2];
80390 diff -urNp linux-2.6.32.46/sound/oss/sb_audio.c linux-2.6.32.46/sound/oss/sb_audio.c
80391 --- linux-2.6.32.46/sound/oss/sb_audio.c 2011-03-27 14:31:47.000000000 -0400
80392 +++ linux-2.6.32.46/sound/oss/sb_audio.c 2011-04-17 15:56:46.000000000 -0400
80393 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
80394 buf16 = (signed short *)(localbuf + localoffs);
80395 while (c)
80396 {
80397 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80398 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80399 if (copy_from_user(lbuf8,
80400 userbuf+useroffs + p,
80401 locallen))
80402 diff -urNp linux-2.6.32.46/sound/oss/swarm_cs4297a.c linux-2.6.32.46/sound/oss/swarm_cs4297a.c
80403 --- linux-2.6.32.46/sound/oss/swarm_cs4297a.c 2011-03-27 14:31:47.000000000 -0400
80404 +++ linux-2.6.32.46/sound/oss/swarm_cs4297a.c 2011-04-17 15:56:46.000000000 -0400
80405 @@ -2577,7 +2577,6 @@ static int __init cs4297a_init(void)
80406 {
80407 struct cs4297a_state *s;
80408 u32 pwr, id;
80409 - mm_segment_t fs;
80410 int rval;
80411 #ifndef CONFIG_BCM_CS4297A_CSWARM
80412 u64 cfg;
80413 @@ -2667,22 +2666,23 @@ static int __init cs4297a_init(void)
80414 if (!rval) {
80415 char *sb1250_duart_present;
80416
80417 +#if 0
80418 + mm_segment_t fs;
80419 fs = get_fs();
80420 set_fs(KERNEL_DS);
80421 -#if 0
80422 val = SOUND_MASK_LINE;
80423 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80424 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80425 val = initvol[i].vol;
80426 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80427 }
80428 + set_fs(fs);
80429 // cs4297a_write_ac97(s, 0x18, 0x0808);
80430 #else
80431 // cs4297a_write_ac97(s, 0x5e, 0x180);
80432 cs4297a_write_ac97(s, 0x02, 0x0808);
80433 cs4297a_write_ac97(s, 0x18, 0x0808);
80434 #endif
80435 - set_fs(fs);
80436
80437 list_add(&s->list, &cs4297a_devs);
80438
80439 diff -urNp linux-2.6.32.46/sound/pci/ac97/ac97_codec.c linux-2.6.32.46/sound/pci/ac97/ac97_codec.c
80440 --- linux-2.6.32.46/sound/pci/ac97/ac97_codec.c 2011-03-27 14:31:47.000000000 -0400
80441 +++ linux-2.6.32.46/sound/pci/ac97/ac97_codec.c 2011-04-17 15:56:46.000000000 -0400
80442 @@ -1952,7 +1952,7 @@ static int snd_ac97_dev_disconnect(struc
80443 }
80444
80445 /* build_ops to do nothing */
80446 -static struct snd_ac97_build_ops null_build_ops;
80447 +static const struct snd_ac97_build_ops null_build_ops;
80448
80449 #ifdef CONFIG_SND_AC97_POWER_SAVE
80450 static void do_update_power(struct work_struct *work)
80451 diff -urNp linux-2.6.32.46/sound/pci/ac97/ac97_patch.c linux-2.6.32.46/sound/pci/ac97/ac97_patch.c
80452 --- linux-2.6.32.46/sound/pci/ac97/ac97_patch.c 2011-08-29 22:24:44.000000000 -0400
80453 +++ linux-2.6.32.46/sound/pci/ac97/ac97_patch.c 2011-08-29 22:25:07.000000000 -0400
80454 @@ -371,7 +371,7 @@ static int patch_yamaha_ymf743_build_spd
80455 return 0;
80456 }
80457
80458 -static struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
80459 +static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
80460 .build_spdif = patch_yamaha_ymf743_build_spdif,
80461 .build_3d = patch_yamaha_ymf7x3_3d,
80462 };
80463 @@ -455,7 +455,7 @@ static int patch_yamaha_ymf753_post_spdi
80464 return 0;
80465 }
80466
80467 -static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
80468 +static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
80469 .build_3d = patch_yamaha_ymf7x3_3d,
80470 .build_post_spdif = patch_yamaha_ymf753_post_spdif
80471 };
80472 @@ -502,7 +502,7 @@ static int patch_wolfson_wm9703_specific
80473 return 0;
80474 }
80475
80476 -static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
80477 +static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
80478 .build_specific = patch_wolfson_wm9703_specific,
80479 };
80480
80481 @@ -533,7 +533,7 @@ static int patch_wolfson_wm9704_specific
80482 return 0;
80483 }
80484
80485 -static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
80486 +static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
80487 .build_specific = patch_wolfson_wm9704_specific,
80488 };
80489
80490 @@ -555,7 +555,7 @@ static int patch_wolfson_wm9705_specific
80491 return 0;
80492 }
80493
80494 -static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
80495 +static const struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
80496 .build_specific = patch_wolfson_wm9705_specific,
80497 };
80498
80499 @@ -692,7 +692,7 @@ static int patch_wolfson_wm9711_specific
80500 return 0;
80501 }
80502
80503 -static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
80504 +static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
80505 .build_specific = patch_wolfson_wm9711_specific,
80506 };
80507
80508 @@ -886,7 +886,7 @@ static void patch_wolfson_wm9713_resume
80509 }
80510 #endif
80511
80512 -static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
80513 +static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
80514 .build_specific = patch_wolfson_wm9713_specific,
80515 .build_3d = patch_wolfson_wm9713_3d,
80516 #ifdef CONFIG_PM
80517 @@ -991,7 +991,7 @@ static int patch_sigmatel_stac97xx_speci
80518 return 0;
80519 }
80520
80521 -static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
80522 +static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
80523 .build_3d = patch_sigmatel_stac9700_3d,
80524 .build_specific = patch_sigmatel_stac97xx_specific
80525 };
80526 @@ -1038,7 +1038,7 @@ static int patch_sigmatel_stac9708_speci
80527 return patch_sigmatel_stac97xx_specific(ac97);
80528 }
80529
80530 -static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
80531 +static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
80532 .build_3d = patch_sigmatel_stac9708_3d,
80533 .build_specific = patch_sigmatel_stac9708_specific
80534 };
80535 @@ -1267,7 +1267,7 @@ static int patch_sigmatel_stac9758_speci
80536 return 0;
80537 }
80538
80539 -static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
80540 +static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
80541 .build_3d = patch_sigmatel_stac9700_3d,
80542 .build_specific = patch_sigmatel_stac9758_specific
80543 };
80544 @@ -1342,7 +1342,7 @@ static int patch_cirrus_build_spdif(stru
80545 return 0;
80546 }
80547
80548 -static struct snd_ac97_build_ops patch_cirrus_ops = {
80549 +static const struct snd_ac97_build_ops patch_cirrus_ops = {
80550 .build_spdif = patch_cirrus_build_spdif
80551 };
80552
80553 @@ -1399,7 +1399,7 @@ static int patch_conexant_build_spdif(st
80554 return 0;
80555 }
80556
80557 -static struct snd_ac97_build_ops patch_conexant_ops = {
80558 +static const struct snd_ac97_build_ops patch_conexant_ops = {
80559 .build_spdif = patch_conexant_build_spdif
80560 };
80561
80562 @@ -1575,7 +1575,7 @@ static void patch_ad1881_chained(struct
80563 }
80564 }
80565
80566 -static struct snd_ac97_build_ops patch_ad1881_build_ops = {
80567 +static const struct snd_ac97_build_ops patch_ad1881_build_ops = {
80568 #ifdef CONFIG_PM
80569 .resume = ad18xx_resume
80570 #endif
80571 @@ -1662,7 +1662,7 @@ static int patch_ad1885_specific(struct
80572 return 0;
80573 }
80574
80575 -static struct snd_ac97_build_ops patch_ad1885_build_ops = {
80576 +static const struct snd_ac97_build_ops patch_ad1885_build_ops = {
80577 .build_specific = &patch_ad1885_specific,
80578 #ifdef CONFIG_PM
80579 .resume = ad18xx_resume
80580 @@ -1689,7 +1689,7 @@ static int patch_ad1886_specific(struct
80581 return 0;
80582 }
80583
80584 -static struct snd_ac97_build_ops patch_ad1886_build_ops = {
80585 +static const struct snd_ac97_build_ops patch_ad1886_build_ops = {
80586 .build_specific = &patch_ad1886_specific,
80587 #ifdef CONFIG_PM
80588 .resume = ad18xx_resume
80589 @@ -1896,7 +1896,7 @@ static int patch_ad1981a_specific(struct
80590 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
80591 }
80592
80593 -static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
80594 +static const struct snd_ac97_build_ops patch_ad1981a_build_ops = {
80595 .build_post_spdif = patch_ad198x_post_spdif,
80596 .build_specific = patch_ad1981a_specific,
80597 #ifdef CONFIG_PM
80598 @@ -1952,7 +1952,7 @@ static int patch_ad1981b_specific(struct
80599 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
80600 }
80601
80602 -static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
80603 +static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {
80604 .build_post_spdif = patch_ad198x_post_spdif,
80605 .build_specific = patch_ad1981b_specific,
80606 #ifdef CONFIG_PM
80607 @@ -2091,7 +2091,7 @@ static int patch_ad1888_specific(struct
80608 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
80609 }
80610
80611 -static struct snd_ac97_build_ops patch_ad1888_build_ops = {
80612 +static const struct snd_ac97_build_ops patch_ad1888_build_ops = {
80613 .build_post_spdif = patch_ad198x_post_spdif,
80614 .build_specific = patch_ad1888_specific,
80615 #ifdef CONFIG_PM
80616 @@ -2140,7 +2140,7 @@ static int patch_ad1980_specific(struct
80617 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
80618 }
80619
80620 -static struct snd_ac97_build_ops patch_ad1980_build_ops = {
80621 +static const struct snd_ac97_build_ops patch_ad1980_build_ops = {
80622 .build_post_spdif = patch_ad198x_post_spdif,
80623 .build_specific = patch_ad1980_specific,
80624 #ifdef CONFIG_PM
80625 @@ -2255,7 +2255,7 @@ static int patch_ad1985_specific(struct
80626 ARRAY_SIZE(snd_ac97_ad1985_controls));
80627 }
80628
80629 -static struct snd_ac97_build_ops patch_ad1985_build_ops = {
80630 +static const struct snd_ac97_build_ops patch_ad1985_build_ops = {
80631 .build_post_spdif = patch_ad198x_post_spdif,
80632 .build_specific = patch_ad1985_specific,
80633 #ifdef CONFIG_PM
80634 @@ -2547,7 +2547,7 @@ static int patch_ad1986_specific(struct
80635 ARRAY_SIZE(snd_ac97_ad1985_controls));
80636 }
80637
80638 -static struct snd_ac97_build_ops patch_ad1986_build_ops = {
80639 +static const struct snd_ac97_build_ops patch_ad1986_build_ops = {
80640 .build_post_spdif = patch_ad198x_post_spdif,
80641 .build_specific = patch_ad1986_specific,
80642 #ifdef CONFIG_PM
80643 @@ -2652,7 +2652,7 @@ static int patch_alc650_specific(struct
80644 return 0;
80645 }
80646
80647 -static struct snd_ac97_build_ops patch_alc650_ops = {
80648 +static const struct snd_ac97_build_ops patch_alc650_ops = {
80649 .build_specific = patch_alc650_specific,
80650 .update_jacks = alc650_update_jacks
80651 };
80652 @@ -2804,7 +2804,7 @@ static int patch_alc655_specific(struct
80653 return 0;
80654 }
80655
80656 -static struct snd_ac97_build_ops patch_alc655_ops = {
80657 +static const struct snd_ac97_build_ops patch_alc655_ops = {
80658 .build_specific = patch_alc655_specific,
80659 .update_jacks = alc655_update_jacks
80660 };
80661 @@ -2916,7 +2916,7 @@ static int patch_alc850_specific(struct
80662 return 0;
80663 }
80664
80665 -static struct snd_ac97_build_ops patch_alc850_ops = {
80666 +static const struct snd_ac97_build_ops patch_alc850_ops = {
80667 .build_specific = patch_alc850_specific,
80668 .update_jacks = alc850_update_jacks
80669 };
80670 @@ -2978,7 +2978,7 @@ static int patch_cm9738_specific(struct
80671 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
80672 }
80673
80674 -static struct snd_ac97_build_ops patch_cm9738_ops = {
80675 +static const struct snd_ac97_build_ops patch_cm9738_ops = {
80676 .build_specific = patch_cm9738_specific,
80677 .update_jacks = cm9738_update_jacks
80678 };
80679 @@ -3069,7 +3069,7 @@ static int patch_cm9739_post_spdif(struc
80680 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
80681 }
80682
80683 -static struct snd_ac97_build_ops patch_cm9739_ops = {
80684 +static const struct snd_ac97_build_ops patch_cm9739_ops = {
80685 .build_specific = patch_cm9739_specific,
80686 .build_post_spdif = patch_cm9739_post_spdif,
80687 .update_jacks = cm9739_update_jacks
80688 @@ -3243,7 +3243,7 @@ static int patch_cm9761_specific(struct
80689 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
80690 }
80691
80692 -static struct snd_ac97_build_ops patch_cm9761_ops = {
80693 +static const struct snd_ac97_build_ops patch_cm9761_ops = {
80694 .build_specific = patch_cm9761_specific,
80695 .build_post_spdif = patch_cm9761_post_spdif,
80696 .update_jacks = cm9761_update_jacks
80697 @@ -3339,7 +3339,7 @@ static int patch_cm9780_specific(struct
80698 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
80699 }
80700
80701 -static struct snd_ac97_build_ops patch_cm9780_ops = {
80702 +static const struct snd_ac97_build_ops patch_cm9780_ops = {
80703 .build_specific = patch_cm9780_specific,
80704 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
80705 };
80706 @@ -3459,7 +3459,7 @@ static int patch_vt1616_specific(struct
80707 return 0;
80708 }
80709
80710 -static struct snd_ac97_build_ops patch_vt1616_ops = {
80711 +static const struct snd_ac97_build_ops patch_vt1616_ops = {
80712 .build_specific = patch_vt1616_specific
80713 };
80714
80715 @@ -3813,7 +3813,7 @@ static int patch_it2646_specific(struct
80716 return 0;
80717 }
80718
80719 -static struct snd_ac97_build_ops patch_it2646_ops = {
80720 +static const struct snd_ac97_build_ops patch_it2646_ops = {
80721 .build_specific = patch_it2646_specific,
80722 .update_jacks = it2646_update_jacks
80723 };
80724 @@ -3847,7 +3847,7 @@ static int patch_si3036_specific(struct
80725 return 0;
80726 }
80727
80728 -static struct snd_ac97_build_ops patch_si3036_ops = {
80729 +static const struct snd_ac97_build_ops patch_si3036_ops = {
80730 .build_specific = patch_si3036_specific,
80731 };
80732
80733 @@ -3914,7 +3914,7 @@ static int patch_ucb1400_specific(struct
80734 return 0;
80735 }
80736
80737 -static struct snd_ac97_build_ops patch_ucb1400_ops = {
80738 +static const struct snd_ac97_build_ops patch_ucb1400_ops = {
80739 .build_specific = patch_ucb1400_specific,
80740 };
80741
80742 diff -urNp linux-2.6.32.46/sound/pci/hda/hda_codec.h linux-2.6.32.46/sound/pci/hda/hda_codec.h
80743 --- linux-2.6.32.46/sound/pci/hda/hda_codec.h 2011-03-27 14:31:47.000000000 -0400
80744 +++ linux-2.6.32.46/sound/pci/hda/hda_codec.h 2011-08-23 21:22:32.000000000 -0400
80745 @@ -580,7 +580,7 @@ struct hda_bus_ops {
80746 /* notify power-up/down from codec to controller */
80747 void (*pm_notify)(struct hda_bus *bus);
80748 #endif
80749 -};
80750 +} __no_const;
80751
80752 /* template to pass to the bus constructor */
80753 struct hda_bus_template {
80754 @@ -675,6 +675,7 @@ struct hda_codec_ops {
80755 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
80756 #endif
80757 };
80758 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80759
80760 /* record for amp information cache */
80761 struct hda_cache_head {
80762 @@ -705,7 +706,7 @@ struct hda_pcm_ops {
80763 struct snd_pcm_substream *substream);
80764 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80765 struct snd_pcm_substream *substream);
80766 -};
80767 +} __no_const;
80768
80769 /* PCM information for each substream */
80770 struct hda_pcm_stream {
80771 @@ -760,7 +761,7 @@ struct hda_codec {
80772 const char *modelname; /* model name for preset */
80773
80774 /* set by patch */
80775 - struct hda_codec_ops patch_ops;
80776 + hda_codec_ops_no_const patch_ops;
80777
80778 /* PCM to create, set by patch_ops.build_pcms callback */
80779 unsigned int num_pcms;
80780 diff -urNp linux-2.6.32.46/sound/pci/hda/patch_atihdmi.c linux-2.6.32.46/sound/pci/hda/patch_atihdmi.c
80781 --- linux-2.6.32.46/sound/pci/hda/patch_atihdmi.c 2011-03-27 14:31:47.000000000 -0400
80782 +++ linux-2.6.32.46/sound/pci/hda/patch_atihdmi.c 2011-08-05 20:33:55.000000000 -0400
80783 @@ -177,7 +177,7 @@ static int patch_atihdmi(struct hda_code
80784 */
80785 spec->multiout.dig_out_nid = CVT_NID;
80786
80787 - codec->patch_ops = atihdmi_patch_ops;
80788 + memcpy((void *)&codec->patch_ops, &atihdmi_patch_ops, sizeof(atihdmi_patch_ops));
80789
80790 return 0;
80791 }
80792 diff -urNp linux-2.6.32.46/sound/pci/hda/patch_intelhdmi.c linux-2.6.32.46/sound/pci/hda/patch_intelhdmi.c
80793 --- linux-2.6.32.46/sound/pci/hda/patch_intelhdmi.c 2011-03-27 14:31:47.000000000 -0400
80794 +++ linux-2.6.32.46/sound/pci/hda/patch_intelhdmi.c 2011-08-05 20:33:55.000000000 -0400
80795 @@ -511,10 +511,10 @@ static void hdmi_non_intrinsic_event(str
80796 cp_ready);
80797
80798 /* TODO */
80799 - if (cp_state)
80800 - ;
80801 - if (cp_ready)
80802 - ;
80803 + if (cp_state) {
80804 + }
80805 + if (cp_ready) {
80806 + }
80807 }
80808
80809
80810 @@ -656,7 +656,7 @@ static int do_patch_intel_hdmi(struct hd
80811 spec->multiout.dig_out_nid = cvt_nid;
80812
80813 codec->spec = spec;
80814 - codec->patch_ops = intel_hdmi_patch_ops;
80815 + memcpy((void *)&codec->patch_ops, &intel_hdmi_patch_ops, sizeof(intel_hdmi_patch_ops));
80816
80817 snd_hda_eld_proc_new(codec, &spec->sink_eld);
80818
80819 diff -urNp linux-2.6.32.46/sound/pci/hda/patch_nvhdmi.c linux-2.6.32.46/sound/pci/hda/patch_nvhdmi.c
80820 --- linux-2.6.32.46/sound/pci/hda/patch_nvhdmi.c 2011-03-27 14:31:47.000000000 -0400
80821 +++ linux-2.6.32.46/sound/pci/hda/patch_nvhdmi.c 2011-08-05 20:33:55.000000000 -0400
80822 @@ -367,7 +367,7 @@ static int patch_nvhdmi_8ch(struct hda_c
80823 spec->multiout.max_channels = 8;
80824 spec->multiout.dig_out_nid = Nv_Master_Convert_nid;
80825
80826 - codec->patch_ops = nvhdmi_patch_ops_8ch;
80827 + memcpy((void *)&codec->patch_ops, &nvhdmi_patch_ops_8ch, sizeof(nvhdmi_patch_ops_8ch));
80828
80829 return 0;
80830 }
80831 @@ -386,7 +386,7 @@ static int patch_nvhdmi_2ch(struct hda_c
80832 spec->multiout.max_channels = 2;
80833 spec->multiout.dig_out_nid = Nv_Master_Convert_nid;
80834
80835 - codec->patch_ops = nvhdmi_patch_ops_2ch;
80836 + memcpy((void *)&codec->patch_ops, &nvhdmi_patch_ops_2ch, sizeof(nvhdmi_patch_ops_2ch));
80837
80838 return 0;
80839 }
80840 diff -urNp linux-2.6.32.46/sound/pci/hda/patch_sigmatel.c linux-2.6.32.46/sound/pci/hda/patch_sigmatel.c
80841 --- linux-2.6.32.46/sound/pci/hda/patch_sigmatel.c 2011-06-25 12:55:35.000000000 -0400
80842 +++ linux-2.6.32.46/sound/pci/hda/patch_sigmatel.c 2011-08-23 21:22:32.000000000 -0400
80843 @@ -5220,7 +5220,7 @@ again:
80844 snd_hda_codec_write_cache(codec, nid, 0,
80845 AC_VERB_SET_CONNECT_SEL, num_dacs);
80846
80847 - codec->patch_ops = stac92xx_patch_ops;
80848 + memcpy((void *)&codec->patch_ops, &stac92xx_patch_ops, sizeof(stac92xx_patch_ops));
80849
80850 codec->proc_widget_hook = stac92hd_proc_hook;
80851
80852 @@ -5294,7 +5294,7 @@ static int patch_stac92hd71bxx(struct hd
80853 return -ENOMEM;
80854
80855 codec->spec = spec;
80856 - codec->patch_ops = stac92xx_patch_ops;
80857 + memcpy((void *)&codec->patch_ops, &stac92xx_patch_ops, sizeof(stac92xx_patch_ops));
80858 spec->num_pins = STAC92HD71BXX_NUM_PINS;
80859 switch (codec->vendor_id) {
80860 case 0x111d76b6:
80861 diff -urNp linux-2.6.32.46/sound/pci/ice1712/ice1712.h linux-2.6.32.46/sound/pci/ice1712/ice1712.h
80862 --- linux-2.6.32.46/sound/pci/ice1712/ice1712.h 2011-03-27 14:31:47.000000000 -0400
80863 +++ linux-2.6.32.46/sound/pci/ice1712/ice1712.h 2011-08-05 20:33:55.000000000 -0400
80864 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80865 unsigned int mask_flags; /* total mask bits */
80866 struct snd_akm4xxx_ops {
80867 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80868 - } ops;
80869 + } __no_const ops;
80870 };
80871
80872 struct snd_ice1712_spdif {
80873 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80874 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80875 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80876 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80877 - } ops;
80878 + } __no_const ops;
80879 };
80880
80881
80882 diff -urNp linux-2.6.32.46/sound/pci/intel8x0m.c linux-2.6.32.46/sound/pci/intel8x0m.c
80883 --- linux-2.6.32.46/sound/pci/intel8x0m.c 2011-03-27 14:31:47.000000000 -0400
80884 +++ linux-2.6.32.46/sound/pci/intel8x0m.c 2011-04-23 12:56:12.000000000 -0400
80885 @@ -1264,7 +1264,7 @@ static struct shortname_table {
80886 { 0x5455, "ALi M5455" },
80887 { 0x746d, "AMD AMD8111" },
80888 #endif
80889 - { 0 },
80890 + { 0, },
80891 };
80892
80893 static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
80894 diff -urNp linux-2.6.32.46/sound/pci/ymfpci/ymfpci_main.c linux-2.6.32.46/sound/pci/ymfpci/ymfpci_main.c
80895 --- linux-2.6.32.46/sound/pci/ymfpci/ymfpci_main.c 2011-03-27 14:31:47.000000000 -0400
80896 +++ linux-2.6.32.46/sound/pci/ymfpci/ymfpci_main.c 2011-05-04 17:56:28.000000000 -0400
80897 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct sn
80898 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80899 break;
80900 }
80901 - if (atomic_read(&chip->interrupt_sleep_count)) {
80902 - atomic_set(&chip->interrupt_sleep_count, 0);
80903 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80904 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80905 wake_up(&chip->interrupt_sleep);
80906 }
80907 __end:
80908 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct s
80909 continue;
80910 init_waitqueue_entry(&wait, current);
80911 add_wait_queue(&chip->interrupt_sleep, &wait);
80912 - atomic_inc(&chip->interrupt_sleep_count);
80913 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80914 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80915 remove_wait_queue(&chip->interrupt_sleep, &wait);
80916 }
80917 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(
80918 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80919 spin_unlock(&chip->reg_lock);
80920
80921 - if (atomic_read(&chip->interrupt_sleep_count)) {
80922 - atomic_set(&chip->interrupt_sleep_count, 0);
80923 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80924 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80925 wake_up(&chip->interrupt_sleep);
80926 }
80927 }
80928 @@ -2369,7 +2369,7 @@ int __devinit snd_ymfpci_create(struct s
80929 spin_lock_init(&chip->reg_lock);
80930 spin_lock_init(&chip->voice_lock);
80931 init_waitqueue_head(&chip->interrupt_sleep);
80932 - atomic_set(&chip->interrupt_sleep_count, 0);
80933 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80934 chip->card = card;
80935 chip->pci = pci;
80936 chip->irq = -1;
80937 diff -urNp linux-2.6.32.46/sound/soc/soc-core.c linux-2.6.32.46/sound/soc/soc-core.c
80938 --- linux-2.6.32.46/sound/soc/soc-core.c 2011-03-27 14:31:47.000000000 -0400
80939 +++ linux-2.6.32.46/sound/soc/soc-core.c 2011-08-23 21:22:32.000000000 -0400
80940 @@ -609,7 +609,7 @@ static int soc_pcm_trigger(struct snd_pc
80941 }
80942
80943 /* ASoC PCM operations */
80944 -static struct snd_pcm_ops soc_pcm_ops = {
80945 +static snd_pcm_ops_no_const soc_pcm_ops = {
80946 .open = soc_pcm_open,
80947 .close = soc_codec_close,
80948 .hw_params = soc_pcm_hw_params,
80949 diff -urNp linux-2.6.32.46/sound/usb/usbaudio.c linux-2.6.32.46/sound/usb/usbaudio.c
80950 --- linux-2.6.32.46/sound/usb/usbaudio.c 2011-03-27 14:31:47.000000000 -0400
80951 +++ linux-2.6.32.46/sound/usb/usbaudio.c 2011-08-05 20:33:55.000000000 -0400
80952 @@ -963,12 +963,12 @@ static int snd_usb_pcm_playback_trigger(
80953 switch (cmd) {
80954 case SNDRV_PCM_TRIGGER_START:
80955 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
80956 - subs->ops.prepare = prepare_playback_urb;
80957 + *(void **)&subs->ops.prepare = prepare_playback_urb;
80958 return 0;
80959 case SNDRV_PCM_TRIGGER_STOP:
80960 return deactivate_urbs(subs, 0, 0);
80961 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
80962 - subs->ops.prepare = prepare_nodata_playback_urb;
80963 + *(void **)&subs->ops.prepare = prepare_nodata_playback_urb;
80964 return 0;
80965 default:
80966 return -EINVAL;
80967 @@ -985,15 +985,15 @@ static int snd_usb_pcm_capture_trigger(s
80968
80969 switch (cmd) {
80970 case SNDRV_PCM_TRIGGER_START:
80971 - subs->ops.retire = retire_capture_urb;
80972 + *(void **)&subs->ops.retire = retire_capture_urb;
80973 return start_urbs(subs, substream->runtime);
80974 case SNDRV_PCM_TRIGGER_STOP:
80975 return deactivate_urbs(subs, 0, 0);
80976 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
80977 - subs->ops.retire = retire_paused_capture_urb;
80978 + *(void **)&subs->ops.retire = retire_paused_capture_urb;
80979 return 0;
80980 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
80981 - subs->ops.retire = retire_capture_urb;
80982 + *(void **)&subs->ops.retire = retire_capture_urb;
80983 return 0;
80984 default:
80985 return -EINVAL;
80986 @@ -1542,7 +1542,7 @@ static int snd_usb_pcm_prepare(struct sn
80987 /* for playback, submit the URBs now; otherwise, the first hwptr_done
80988 * updates for all URBs would happen at the same time when starting */
80989 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
80990 - subs->ops.prepare = prepare_nodata_playback_urb;
80991 + *(void **)&subs->ops.prepare = prepare_nodata_playback_urb;
80992 return start_urbs(subs, runtime);
80993 } else
80994 return 0;
80995 @@ -2228,14 +2228,14 @@ static void init_substream(struct snd_us
80996 subs->direction = stream;
80997 subs->dev = as->chip->dev;
80998 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) {
80999 - subs->ops = audio_urb_ops[stream];
81000 + memcpy((void *)&subs->ops, &audio_urb_ops[stream], sizeof(subs->ops));
81001 } else {
81002 - subs->ops = audio_urb_ops_high_speed[stream];
81003 + memcpy((void *)&subs->ops, &audio_urb_ops_high_speed[stream], sizeof(subs->ops));
81004 switch (as->chip->usb_id) {
81005 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
81006 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
81007 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
81008 - subs->ops.retire_sync = retire_playback_sync_urb_hs_emu;
81009 + *(void **)&subs->ops.retire_sync = retire_playback_sync_urb_hs_emu;
81010 break;
81011 }
81012 }
81013 diff -urNp linux-2.6.32.46/tools/gcc/Makefile linux-2.6.32.46/tools/gcc/Makefile
81014 --- linux-2.6.32.46/tools/gcc/Makefile 1969-12-31 19:00:00.000000000 -0500
81015 +++ linux-2.6.32.46/tools/gcc/Makefile 2011-10-06 09:37:14.000000000 -0400
81016 @@ -0,0 +1,21 @@
81017 +#CC := gcc
81018 +#PLUGIN_SOURCE_FILES := pax_plugin.c
81019 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
81020 +GCCPLUGINS_DIR := $(shell $(HOSTCC) -print-file-name=plugin)
81021 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W
81022 +
81023 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include
81024 +
81025 +hostlibs-y := constify_plugin.so
81026 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
81027 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
81028 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
81029 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
81030 +
81031 +always := $(hostlibs-y)
81032 +
81033 +stackleak_plugin-objs := stackleak_plugin.o
81034 +constify_plugin-objs := constify_plugin.o
81035 +kallocstat_plugin-objs := kallocstat_plugin.o
81036 +kernexec_plugin-objs := kernexec_plugin.o
81037 +checker_plugin-objs := checker_plugin.o
81038 diff -urNp linux-2.6.32.46/tools/gcc/checker_plugin.c linux-2.6.32.46/tools/gcc/checker_plugin.c
81039 --- linux-2.6.32.46/tools/gcc/checker_plugin.c 1969-12-31 19:00:00.000000000 -0500
81040 +++ linux-2.6.32.46/tools/gcc/checker_plugin.c 2011-10-06 09:37:16.000000000 -0400
81041 @@ -0,0 +1,169 @@
81042 +/*
81043 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81044 + * Licensed under the GPL v2
81045 + *
81046 + * Note: the choice of the license means that the compilation process is
81047 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81048 + * but for the kernel it doesn't matter since it doesn't link against
81049 + * any of the gcc libraries
81050 + *
81051 + * gcc plugin to implement various sparse (source code checker) features
81052 + *
81053 + * TODO:
81054 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
81055 + *
81056 + * BUGS:
81057 + * - none known
81058 + */
81059 +#include "gcc-plugin.h"
81060 +#include "config.h"
81061 +#include "system.h"
81062 +#include "coretypes.h"
81063 +#include "tree.h"
81064 +#include "tree-pass.h"
81065 +#include "intl.h"
81066 +#include "plugin-version.h"
81067 +#include "tm.h"
81068 +#include "toplev.h"
81069 +#include "basic-block.h"
81070 +#include "gimple.h"
81071 +//#include "expr.h" where are you...
81072 +#include "diagnostic.h"
81073 +#include "rtl.h"
81074 +#include "emit-rtl.h"
81075 +#include "function.h"
81076 +#include "tree-flow.h"
81077 +#include "target.h"
81078 +
81079 +extern void c_register_addr_space (const char *str, addr_space_t as);
81080 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
81081 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
81082 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
81083 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
81084 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
81085 +
81086 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81087 +extern rtx emit_move_insn(rtx x, rtx y);
81088 +
81089 +int plugin_is_GPL_compatible;
81090 +
81091 +static struct plugin_info checker_plugin_info = {
81092 + .version = "201110031940",
81093 +};
81094 +
81095 +#define ADDR_SPACE_KERNEL 0
81096 +#define ADDR_SPACE_FORCE_KERNEL 1
81097 +#define ADDR_SPACE_USER 2
81098 +#define ADDR_SPACE_FORCE_USER 3
81099 +#define ADDR_SPACE_IOMEM 0
81100 +#define ADDR_SPACE_FORCE_IOMEM 0
81101 +#define ADDR_SPACE_PERCPU 0
81102 +#define ADDR_SPACE_FORCE_PERCPU 0
81103 +#define ADDR_SPACE_RCU 0
81104 +#define ADDR_SPACE_FORCE_RCU 0
81105 +
81106 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
81107 +{
81108 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
81109 +}
81110 +
81111 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
81112 +{
81113 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
81114 +}
81115 +
81116 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
81117 +{
81118 + return default_addr_space_valid_pointer_mode(mode, as);
81119 +}
81120 +
81121 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
81122 +{
81123 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
81124 +}
81125 +
81126 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
81127 +{
81128 + return default_addr_space_legitimize_address(x, oldx, mode, as);
81129 +}
81130 +
81131 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
81132 +{
81133 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
81134 + return true;
81135 +
81136 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
81137 + return true;
81138 +
81139 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
81140 + return true;
81141 +
81142 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
81143 + return true;
81144 +
81145 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
81146 + return true;
81147 +
81148 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
81149 + return true;
81150 +
81151 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
81152 + return true;
81153 +
81154 + return subset == superset;
81155 +}
81156 +
81157 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
81158 +{
81159 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
81160 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
81161 +
81162 + return op;
81163 +}
81164 +
81165 +static void register_checker_address_spaces(void *event_data, void *data)
81166 +{
81167 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
81168 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
81169 + c_register_addr_space("__user", ADDR_SPACE_USER);
81170 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
81171 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
81172 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
81173 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
81174 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
81175 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
81176 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
81177 +
81178 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
81179 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
81180 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
81181 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
81182 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
81183 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
81184 + targetm.addr_space.convert = checker_addr_space_convert;
81185 +}
81186 +
81187 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81188 +{
81189 + const char * const plugin_name = plugin_info->base_name;
81190 + const int argc = plugin_info->argc;
81191 + const struct plugin_argument * const argv = plugin_info->argv;
81192 + int i;
81193 +
81194 + if (!plugin_default_version_check(version, &gcc_version)) {
81195 + error(G_("incompatible gcc/plugin versions"));
81196 + return 1;
81197 + }
81198 +
81199 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
81200 +
81201 + for (i = 0; i < argc; ++i)
81202 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81203 +
81204 + if (TARGET_64BIT == 0)
81205 + return 0;
81206 +
81207 + register_callback (plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
81208 +
81209 + return 0;
81210 +}
81211 diff -urNp linux-2.6.32.46/tools/gcc/constify_plugin.c linux-2.6.32.46/tools/gcc/constify_plugin.c
81212 --- linux-2.6.32.46/tools/gcc/constify_plugin.c 1969-12-31 19:00:00.000000000 -0500
81213 +++ linux-2.6.32.46/tools/gcc/constify_plugin.c 2011-08-30 18:19:52.000000000 -0400
81214 @@ -0,0 +1,293 @@
81215 +/*
81216 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
81217 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
81218 + * Licensed under the GPL v2, or (at your option) v3
81219 + *
81220 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
81221 + *
81222 + * Homepage:
81223 + * http://www.grsecurity.net/~ephox/const_plugin/
81224 + *
81225 + * Usage:
81226 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81227 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81228 + */
81229 +
81230 +#include "gcc-plugin.h"
81231 +#include "config.h"
81232 +#include "system.h"
81233 +#include "coretypes.h"
81234 +#include "tree.h"
81235 +#include "tree-pass.h"
81236 +#include "intl.h"
81237 +#include "plugin-version.h"
81238 +#include "tm.h"
81239 +#include "toplev.h"
81240 +#include "function.h"
81241 +#include "tree-flow.h"
81242 +#include "plugin.h"
81243 +#include "diagnostic.h"
81244 +//#include "c-tree.h"
81245 +
81246 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81247 +
81248 +int plugin_is_GPL_compatible;
81249 +
81250 +static struct plugin_info const_plugin_info = {
81251 + .version = "20110826",
81252 + .help = "no-constify\tturn off constification\n",
81253 +};
81254 +
81255 +static void constify_type(tree type);
81256 +static bool walk_struct(tree node);
81257 +
81258 +static tree deconstify_type(tree old_type)
81259 +{
81260 + tree new_type, field;
81261 +
81262 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81263 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81264 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81265 + DECL_FIELD_CONTEXT(field) = new_type;
81266 + TYPE_READONLY(new_type) = 0;
81267 + C_TYPE_FIELDS_READONLY(new_type) = 0;
81268 + return new_type;
81269 +}
81270 +
81271 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81272 +{
81273 + tree type;
81274 +
81275 + *no_add_attrs = true;
81276 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81277 + error("%qE attribute does not apply to functions", name);
81278 + return NULL_TREE;
81279 + }
81280 +
81281 + if (TREE_CODE(*node) == VAR_DECL) {
81282 + error("%qE attribute does not apply to variables", name);
81283 + return NULL_TREE;
81284 + }
81285 +
81286 + if (TYPE_P(*node)) {
81287 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81288 + *no_add_attrs = false;
81289 + else
81290 + error("%qE attribute applies to struct and union types only", name);
81291 + return NULL_TREE;
81292 + }
81293 +
81294 + type = TREE_TYPE(*node);
81295 +
81296 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81297 + error("%qE attribute applies to struct and union types only", name);
81298 + return NULL_TREE;
81299 + }
81300 +
81301 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81302 + error("%qE attribute is already applied to the type", name);
81303 + return NULL_TREE;
81304 + }
81305 +
81306 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81307 + error("%qE attribute used on type that is not constified", name);
81308 + return NULL_TREE;
81309 + }
81310 +
81311 + if (TREE_CODE(*node) == TYPE_DECL) {
81312 + TREE_TYPE(*node) = deconstify_type(type);
81313 + TREE_READONLY(*node) = 0;
81314 + return NULL_TREE;
81315 + }
81316 +
81317 + return NULL_TREE;
81318 +}
81319 +
81320 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81321 +{
81322 + *no_add_attrs = true;
81323 + if (!TYPE_P(*node)) {
81324 + error("%qE attribute applies to types only", name);
81325 + return NULL_TREE;
81326 + }
81327 +
81328 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81329 + error("%qE attribute applies to struct and union types only", name);
81330 + return NULL_TREE;
81331 + }
81332 +
81333 + *no_add_attrs = false;
81334 + constify_type(*node);
81335 + return NULL_TREE;
81336 +}
81337 +
81338 +static struct attribute_spec no_const_attr = {
81339 + .name = "no_const",
81340 + .min_length = 0,
81341 + .max_length = 0,
81342 + .decl_required = false,
81343 + .type_required = false,
81344 + .function_type_required = false,
81345 + .handler = handle_no_const_attribute
81346 +};
81347 +
81348 +static struct attribute_spec do_const_attr = {
81349 + .name = "do_const",
81350 + .min_length = 0,
81351 + .max_length = 0,
81352 + .decl_required = false,
81353 + .type_required = false,
81354 + .function_type_required = false,
81355 + .handler = handle_do_const_attribute
81356 +};
81357 +
81358 +static void register_attributes(void *event_data, void *data)
81359 +{
81360 + register_attribute(&no_const_attr);
81361 + register_attribute(&do_const_attr);
81362 +}
81363 +
81364 +static void constify_type(tree type)
81365 +{
81366 + TYPE_READONLY(type) = 1;
81367 + C_TYPE_FIELDS_READONLY(type) = 1;
81368 +}
81369 +
81370 +static bool is_fptr(tree field)
81371 +{
81372 + tree ptr = TREE_TYPE(field);
81373 +
81374 + if (TREE_CODE(ptr) != POINTER_TYPE)
81375 + return false;
81376 +
81377 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
81378 +}
81379 +
81380 +static bool walk_struct(tree node)
81381 +{
81382 + tree field;
81383 +
81384 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
81385 + return false;
81386 +
81387 + if (TYPE_FIELDS(node) == NULL_TREE)
81388 + return false;
81389 +
81390 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
81391 + tree type = TREE_TYPE(field);
81392 + enum tree_code code = TREE_CODE(type);
81393 + if (code == RECORD_TYPE || code == UNION_TYPE) {
81394 + if (!(walk_struct(type)))
81395 + return false;
81396 + } else if (!is_fptr(field) && !TREE_READONLY(field))
81397 + return false;
81398 + }
81399 + return true;
81400 +}
81401 +
81402 +static void finish_type(void *event_data, void *data)
81403 +{
81404 + tree type = (tree)event_data;
81405 +
81406 + if (type == NULL_TREE)
81407 + return;
81408 +
81409 + if (TYPE_READONLY(type))
81410 + return;
81411 +
81412 + if (walk_struct(type))
81413 + constify_type(type);
81414 +}
81415 +
81416 +static unsigned int check_local_variables(void);
81417 +
81418 +struct gimple_opt_pass pass_local_variable = {
81419 + {
81420 + .type = GIMPLE_PASS,
81421 + .name = "check_local_variables",
81422 + .gate = NULL,
81423 + .execute = check_local_variables,
81424 + .sub = NULL,
81425 + .next = NULL,
81426 + .static_pass_number = 0,
81427 + .tv_id = TV_NONE,
81428 + .properties_required = 0,
81429 + .properties_provided = 0,
81430 + .properties_destroyed = 0,
81431 + .todo_flags_start = 0,
81432 + .todo_flags_finish = 0
81433 + }
81434 +};
81435 +
81436 +static unsigned int check_local_variables(void)
81437 +{
81438 + tree var;
81439 + referenced_var_iterator rvi;
81440 +
81441 +#if __GNUC__ == 4 && __GNUC_MINOR__ == 5
81442 + FOR_EACH_REFERENCED_VAR(var, rvi) {
81443 +#else
81444 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
81445 +#endif
81446 + tree type = TREE_TYPE(var);
81447 +
81448 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
81449 + continue;
81450 +
81451 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81452 + continue;
81453 +
81454 + if (!TYPE_READONLY(type))
81455 + continue;
81456 +
81457 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
81458 +// continue;
81459 +
81460 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
81461 +// continue;
81462 +
81463 + if (walk_struct(type)) {
81464 + error("constified variable %qE cannot be local", var);
81465 + return 1;
81466 + }
81467 + }
81468 + return 0;
81469 +}
81470 +
81471 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81472 +{
81473 + const char * const plugin_name = plugin_info->base_name;
81474 + const int argc = plugin_info->argc;
81475 + const struct plugin_argument * const argv = plugin_info->argv;
81476 + int i;
81477 + bool constify = true;
81478 +
81479 + struct register_pass_info local_variable_pass_info = {
81480 + .pass = &pass_local_variable.pass,
81481 + .reference_pass_name = "*referenced_vars",
81482 + .ref_pass_instance_number = 0,
81483 + .pos_op = PASS_POS_INSERT_AFTER
81484 + };
81485 +
81486 + if (!plugin_default_version_check(version, &gcc_version)) {
81487 + error(G_("incompatible gcc/plugin versions"));
81488 + return 1;
81489 + }
81490 +
81491 + for (i = 0; i < argc; ++i) {
81492 + if (!(strcmp(argv[i].key, "no-constify"))) {
81493 + constify = false;
81494 + continue;
81495 + }
81496 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81497 + }
81498 +
81499 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
81500 + if (constify) {
81501 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
81502 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
81503 + }
81504 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
81505 +
81506 + return 0;
81507 +}
81508 diff -urNp linux-2.6.32.46/tools/gcc/kallocstat_plugin.c linux-2.6.32.46/tools/gcc/kallocstat_plugin.c
81509 --- linux-2.6.32.46/tools/gcc/kallocstat_plugin.c 1969-12-31 19:00:00.000000000 -0500
81510 +++ linux-2.6.32.46/tools/gcc/kallocstat_plugin.c 2011-10-06 09:37:16.000000000 -0400
81511 @@ -0,0 +1,165 @@
81512 +/*
81513 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81514 + * Licensed under the GPL v2
81515 + *
81516 + * Note: the choice of the license means that the compilation process is
81517 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81518 + * but for the kernel it doesn't matter since it doesn't link against
81519 + * any of the gcc libraries
81520 + *
81521 + * gcc plugin to find the distribution of k*alloc sizes
81522 + *
81523 + * TODO:
81524 + *
81525 + * BUGS:
81526 + * - none known
81527 + */
81528 +#include "gcc-plugin.h"
81529 +#include "config.h"
81530 +#include "system.h"
81531 +#include "coretypes.h"
81532 +#include "tree.h"
81533 +#include "tree-pass.h"
81534 +#include "intl.h"
81535 +#include "plugin-version.h"
81536 +#include "tm.h"
81537 +#include "toplev.h"
81538 +#include "basic-block.h"
81539 +#include "gimple.h"
81540 +//#include "expr.h" where are you...
81541 +#include "diagnostic.h"
81542 +#include "rtl.h"
81543 +#include "emit-rtl.h"
81544 +#include "function.h"
81545 +
81546 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81547 +
81548 +int plugin_is_GPL_compatible;
81549 +
81550 +static const char * const kalloc_functions[] = {
81551 + "__kmalloc",
81552 + "kmalloc",
81553 + "kmalloc_large",
81554 + "kmalloc_node",
81555 + "kmalloc_order",
81556 + "kmalloc_order_trace",
81557 + "kmalloc_slab",
81558 + "kzalloc",
81559 + "kzalloc_node",
81560 +};
81561 +
81562 +static struct plugin_info kallocstat_plugin_info = {
81563 + .version = "201109121100",
81564 +};
81565 +
81566 +static unsigned int execute_kallocstat(void);
81567 +
81568 +static struct gimple_opt_pass kallocstat_pass = {
81569 + .pass = {
81570 + .type = GIMPLE_PASS,
81571 + .name = "kallocstat",
81572 + .gate = NULL,
81573 + .execute = execute_kallocstat,
81574 + .sub = NULL,
81575 + .next = NULL,
81576 + .static_pass_number = 0,
81577 + .tv_id = TV_NONE,
81578 + .properties_required = 0,
81579 + .properties_provided = 0,
81580 + .properties_destroyed = 0,
81581 + .todo_flags_start = 0,
81582 + .todo_flags_finish = 0
81583 + }
81584 +};
81585 +
81586 +static bool is_kalloc(const char *fnname)
81587 +{
81588 + size_t i;
81589 +
81590 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
81591 + if (!strcmp(fnname, kalloc_functions[i]))
81592 + return true;
81593 + return false;
81594 +}
81595 +
81596 +static unsigned int execute_kallocstat(void)
81597 +{
81598 + basic_block bb;
81599 +
81600 + // 1. loop through BBs and GIMPLE statements
81601 + FOR_EACH_BB(bb) {
81602 + gimple_stmt_iterator gsi;
81603 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81604 + // gimple match:
81605 + tree fndecl, size;
81606 + gimple call_stmt;
81607 + const char *fnname;
81608 +
81609 + // is it a call
81610 + call_stmt = gsi_stmt(gsi);
81611 + if (!is_gimple_call(call_stmt))
81612 + continue;
81613 + fndecl = gimple_call_fndecl(call_stmt);
81614 + if (fndecl == NULL_TREE)
81615 + continue;
81616 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
81617 + continue;
81618 +
81619 + // is it a call to k*alloc
81620 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
81621 + if (!is_kalloc(fnname))
81622 + continue;
81623 +
81624 + // is the size arg the result of a simple const assignment
81625 + size = gimple_call_arg(call_stmt, 0);
81626 + while (true) {
81627 + gimple def_stmt;
81628 + expanded_location xloc;
81629 + size_t size_val;
81630 +
81631 + if (TREE_CODE(size) != SSA_NAME)
81632 + break;
81633 + def_stmt = SSA_NAME_DEF_STMT(size);
81634 + if (!def_stmt || !is_gimple_assign(def_stmt))
81635 + break;
81636 + if (gimple_num_ops(def_stmt) != 2)
81637 + break;
81638 + size = gimple_assign_rhs1(def_stmt);
81639 + if (!TREE_CONSTANT(size))
81640 + continue;
81641 + xloc = expand_location(gimple_location(def_stmt));
81642 + if (!xloc.file)
81643 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
81644 + size_val = TREE_INT_CST_LOW(size);
81645 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
81646 + break;
81647 + }
81648 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81649 +//debug_tree(gimple_call_fn(call_stmt));
81650 +//print_node(stderr, "pax", fndecl, 4);
81651 + }
81652 + }
81653 +
81654 + return 0;
81655 +}
81656 +
81657 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81658 +{
81659 + const char * const plugin_name = plugin_info->base_name;
81660 + struct register_pass_info kallocstat_pass_info = {
81661 + .pass = &kallocstat_pass.pass,
81662 + .reference_pass_name = "ssa",
81663 + .ref_pass_instance_number = 0,
81664 + .pos_op = PASS_POS_INSERT_AFTER
81665 + };
81666 +
81667 + if (!plugin_default_version_check(version, &gcc_version)) {
81668 + error(G_("incompatible gcc/plugin versions"));
81669 + return 1;
81670 + }
81671 +
81672 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81673 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81674 +
81675 + return 0;
81676 +}
81677 diff -urNp linux-2.6.32.46/tools/gcc/kernexec_plugin.c linux-2.6.32.46/tools/gcc/kernexec_plugin.c
81678 --- linux-2.6.32.46/tools/gcc/kernexec_plugin.c 1969-12-31 19:00:00.000000000 -0500
81679 +++ linux-2.6.32.46/tools/gcc/kernexec_plugin.c 2011-10-06 09:37:16.000000000 -0400
81680 @@ -0,0 +1,273 @@
81681 +/*
81682 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81683 + * Licensed under the GPL v2
81684 + *
81685 + * Note: the choice of the license means that the compilation process is
81686 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81687 + * but for the kernel it doesn't matter since it doesn't link against
81688 + * any of the gcc libraries
81689 + *
81690 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81691 + *
81692 + * TODO:
81693 + *
81694 + * BUGS:
81695 + * - none known
81696 + */
81697 +#include "gcc-plugin.h"
81698 +#include "config.h"
81699 +#include "system.h"
81700 +#include "coretypes.h"
81701 +#include "tree.h"
81702 +#include "tree-pass.h"
81703 +#include "intl.h"
81704 +#include "plugin-version.h"
81705 +#include "tm.h"
81706 +#include "toplev.h"
81707 +#include "basic-block.h"
81708 +#include "gimple.h"
81709 +//#include "expr.h" where are you...
81710 +#include "diagnostic.h"
81711 +#include "rtl.h"
81712 +#include "emit-rtl.h"
81713 +#include "function.h"
81714 +#include "tree-flow.h"
81715 +
81716 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81717 +extern rtx emit_move_insn(rtx x, rtx y);
81718 +
81719 +int plugin_is_GPL_compatible;
81720 +
81721 +static struct plugin_info kernexec_plugin_info = {
81722 + .version = "201110032145",
81723 +};
81724 +
81725 +static unsigned int execute_kernexec_fptr(void);
81726 +static unsigned int execute_kernexec_retaddr(void);
81727 +static bool kernexec_cmodel_check(void);
81728 +
81729 +static struct gimple_opt_pass kernexec_fptr_pass = {
81730 + .pass = {
81731 + .type = GIMPLE_PASS,
81732 + .name = "kernexec_fptr",
81733 + .gate = kernexec_cmodel_check,
81734 + .execute = execute_kernexec_fptr,
81735 + .sub = NULL,
81736 + .next = NULL,
81737 + .static_pass_number = 0,
81738 + .tv_id = TV_NONE,
81739 + .properties_required = 0,
81740 + .properties_provided = 0,
81741 + .properties_destroyed = 0,
81742 + .todo_flags_start = 0,
81743 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81744 + }
81745 +};
81746 +
81747 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81748 + .pass = {
81749 + .type = RTL_PASS,
81750 + .name = "kernexec_retaddr",
81751 + .gate = kernexec_cmodel_check,
81752 + .execute = execute_kernexec_retaddr,
81753 + .sub = NULL,
81754 + .next = NULL,
81755 + .static_pass_number = 0,
81756 + .tv_id = TV_NONE,
81757 + .properties_required = 0,
81758 + .properties_provided = 0,
81759 + .properties_destroyed = 0,
81760 + .todo_flags_start = 0,
81761 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81762 + }
81763 +};
81764 +
81765 +static bool kernexec_cmodel_check(void)
81766 +{
81767 + tree section;
81768 +
81769 + if (ix86_cmodel != CM_KERNEL)
81770 + return false;
81771 +
81772 + section = lookup_attribute("__section__", DECL_ATTRIBUTES(current_function_decl));
81773 + if (!section || !TREE_VALUE(section))
81774 + return true;
81775 +
81776 + section = TREE_VALUE(TREE_VALUE(section));
81777 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81778 + return true;
81779 +
81780 + return false;
81781 +}
81782 +
81783 +/*
81784 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81785 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81786 + */
81787 +static void kernexec_instrument_fptr(gimple_stmt_iterator gsi)
81788 +{
81789 + gimple assign_intptr, assign_new_fptr, call_stmt;
81790 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81791 +
81792 + call_stmt = gsi_stmt(gsi);
81793 + old_fptr = gimple_call_fn(call_stmt);
81794 +
81795 + // create temporary unsigned long variable used for bitops and cast fptr to it
81796 + intptr = create_tmp_var(long_unsigned_type_node, NULL);
81797 + add_referenced_var(intptr);
81798 + mark_sym_for_renaming(intptr);
81799 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81800 + update_stmt(assign_intptr);
81801 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
81802 +
81803 + // apply logical or to temporary unsigned long and bitmask
81804 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81805 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81806 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81807 + update_stmt(assign_intptr);
81808 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
81809 +
81810 + // cast temporary unsigned long back to a temporary fptr variable
81811 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), NULL);
81812 + add_referenced_var(new_fptr);
81813 + mark_sym_for_renaming(new_fptr);
81814 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81815 + update_stmt(assign_new_fptr);
81816 + gsi_insert_before(&gsi, assign_new_fptr, GSI_SAME_STMT);
81817 +
81818 + // replace call stmt fn with the new fptr
81819 + gimple_call_set_fn(call_stmt, new_fptr);
81820 + update_stmt(call_stmt);
81821 +}
81822 +
81823 +/*
81824 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81825 + */
81826 +static unsigned int execute_kernexec_fptr(void)
81827 +{
81828 + basic_block bb;
81829 + gimple_stmt_iterator gsi;
81830 +
81831 + // 1. loop through BBs and GIMPLE statements
81832 + FOR_EACH_BB(bb) {
81833 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81834 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81835 + tree fn;
81836 + gimple call_stmt;
81837 +
81838 + // is it a call ...
81839 + call_stmt = gsi_stmt(gsi);
81840 + if (!is_gimple_call(call_stmt))
81841 + continue;
81842 + fn = gimple_call_fn(call_stmt);
81843 + if (TREE_CODE(fn) == ADDR_EXPR)
81844 + continue;
81845 + if (TREE_CODE(fn) != SSA_NAME)
81846 + gcc_unreachable();
81847 +
81848 + // ... through a function pointer
81849 + fn = SSA_NAME_VAR(fn);
81850 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81851 + continue;
81852 + fn = TREE_TYPE(fn);
81853 + if (TREE_CODE(fn) != POINTER_TYPE)
81854 + continue;
81855 + fn = TREE_TYPE(fn);
81856 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81857 + continue;
81858 +
81859 + kernexec_instrument_fptr(gsi);
81860 +
81861 +//debug_tree(gimple_call_fn(call_stmt));
81862 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81863 + }
81864 + }
81865 +
81866 + return 0;
81867 +}
81868 +
81869 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81870 +static void kernexec_instrument_retaddr(rtx insn)
81871 +{
81872 + rtx btsq;
81873 + rtvec argvec, constraintvec, labelvec;
81874 + int line;
81875 +
81876 + // create asm volatile("btsq $63,(%%rsp)":::)
81877 + argvec = rtvec_alloc(0);
81878 + constraintvec = rtvec_alloc(0);
81879 + labelvec = rtvec_alloc(0);
81880 + line = expand_location(RTL_LOCATION(insn)).line;
81881 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81882 + MEM_VOLATILE_P(btsq) = 1;
81883 + RTX_FRAME_RELATED_P(btsq) = 1;
81884 + emit_insn_before(btsq, insn);
81885 +}
81886 +
81887 +/*
81888 + * find all asm level function returns and forcibly set the highest bit of the return address
81889 + */
81890 +static unsigned int execute_kernexec_retaddr(void)
81891 +{
81892 + rtx insn;
81893 +
81894 + // 1. find function returns
81895 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81896 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81897 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81898 + rtx body;
81899 +
81900 + // is it a retn
81901 + if (!JUMP_P(insn))
81902 + continue;
81903 + body = PATTERN(insn);
81904 + if (GET_CODE(body) == PARALLEL)
81905 + body = XVECEXP(body, 0, 0);
81906 + if (GET_CODE(body) != RETURN)
81907 + continue;
81908 + kernexec_instrument_retaddr(insn);
81909 + }
81910 +
81911 +// print_simple_rtl(stderr, get_insns());
81912 +// print_rtl(stderr, get_insns());
81913 +
81914 + return 0;
81915 +}
81916 +
81917 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81918 +{
81919 + const char * const plugin_name = plugin_info->base_name;
81920 + const int argc = plugin_info->argc;
81921 + const struct plugin_argument * const argv = plugin_info->argv;
81922 + int i;
81923 + struct register_pass_info kernexec_fptr_pass_info = {
81924 + .pass = &kernexec_fptr_pass.pass,
81925 + .reference_pass_name = "ssa",
81926 + .ref_pass_instance_number = 0,
81927 + .pos_op = PASS_POS_INSERT_AFTER
81928 + };
81929 + struct register_pass_info kernexec_retaddr_pass_info = {
81930 + .pass = &kernexec_retaddr_pass.pass,
81931 + .reference_pass_name = "pro_and_epilogue",
81932 + .ref_pass_instance_number = 0,
81933 + .pos_op = PASS_POS_INSERT_AFTER
81934 + };
81935 +
81936 + if (!plugin_default_version_check(version, &gcc_version)) {
81937 + error(G_("incompatible gcc/plugin versions"));
81938 + return 1;
81939 + }
81940 +
81941 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81942 +
81943 + for (i = 0; i < argc; ++i)
81944 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81945 +
81946 + if (TARGET_64BIT == 0)
81947 + return 0;
81948 +
81949 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81950 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81951 +
81952 + return 0;
81953 +}
81954 diff -urNp linux-2.6.32.46/tools/gcc/stackleak_plugin.c linux-2.6.32.46/tools/gcc/stackleak_plugin.c
81955 --- linux-2.6.32.46/tools/gcc/stackleak_plugin.c 1969-12-31 19:00:00.000000000 -0500
81956 +++ linux-2.6.32.46/tools/gcc/stackleak_plugin.c 2011-10-06 09:37:14.000000000 -0400
81957 @@ -0,0 +1,251 @@
81958 +/*
81959 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81960 + * Licensed under the GPL v2
81961 + *
81962 + * Note: the choice of the license means that the compilation process is
81963 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81964 + * but for the kernel it doesn't matter since it doesn't link against
81965 + * any of the gcc libraries
81966 + *
81967 + * gcc plugin to help implement various PaX features
81968 + *
81969 + * - track lowest stack pointer
81970 + *
81971 + * TODO:
81972 + * - initialize all local variables
81973 + *
81974 + * BUGS:
81975 + * - none known
81976 + */
81977 +#include "gcc-plugin.h"
81978 +#include "config.h"
81979 +#include "system.h"
81980 +#include "coretypes.h"
81981 +#include "tree.h"
81982 +#include "tree-pass.h"
81983 +#include "intl.h"
81984 +#include "plugin-version.h"
81985 +#include "tm.h"
81986 +#include "toplev.h"
81987 +#include "basic-block.h"
81988 +#include "gimple.h"
81989 +//#include "expr.h" where are you...
81990 +#include "diagnostic.h"
81991 +#include "rtl.h"
81992 +#include "emit-rtl.h"
81993 +#include "function.h"
81994 +
81995 +int plugin_is_GPL_compatible;
81996 +
81997 +static int track_frame_size = -1;
81998 +static const char track_function[] = "pax_track_stack";
81999 +static bool init_locals;
82000 +
82001 +static struct plugin_info stackleak_plugin_info = {
82002 + .version = "201109112100",
82003 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
82004 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
82005 +};
82006 +
82007 +static bool gate_stackleak_track_stack(void);
82008 +static unsigned int execute_stackleak_tree_instrument(void);
82009 +static unsigned int execute_stackleak_final(void);
82010 +
82011 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
82012 + .pass = {
82013 + .type = GIMPLE_PASS,
82014 + .name = "stackleak_tree_instrument",
82015 + .gate = gate_stackleak_track_stack,
82016 + .execute = execute_stackleak_tree_instrument,
82017 + .sub = NULL,
82018 + .next = NULL,
82019 + .static_pass_number = 0,
82020 + .tv_id = TV_NONE,
82021 + .properties_required = PROP_gimple_leh | PROP_cfg,
82022 + .properties_provided = 0,
82023 + .properties_destroyed = 0,
82024 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
82025 + .todo_flags_finish = TODO_verify_stmts | TODO_dump_func
82026 + }
82027 +};
82028 +
82029 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
82030 + .pass = {
82031 + .type = RTL_PASS,
82032 + .name = "stackleak_final",
82033 + .gate = gate_stackleak_track_stack,
82034 + .execute = execute_stackleak_final,
82035 + .sub = NULL,
82036 + .next = NULL,
82037 + .static_pass_number = 0,
82038 + .tv_id = TV_NONE,
82039 + .properties_required = 0,
82040 + .properties_provided = 0,
82041 + .properties_destroyed = 0,
82042 + .todo_flags_start = 0,
82043 + .todo_flags_finish = TODO_dump_func
82044 + }
82045 +};
82046 +
82047 +static bool gate_stackleak_track_stack(void)
82048 +{
82049 + return track_frame_size >= 0;
82050 +}
82051 +
82052 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi, bool before)
82053 +{
82054 + gimple call;
82055 + tree fndecl, type;
82056 +
82057 + // insert call to void pax_track_stack(void)
82058 + type = build_function_type_list(void_type_node, NULL_TREE);
82059 + fndecl = build_fn_decl(track_function, type);
82060 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
82061 + call = gimple_build_call(fndecl, 0);
82062 + if (before)
82063 + gsi_insert_before(gsi, call, GSI_CONTINUE_LINKING);
82064 + else
82065 + gsi_insert_after(gsi, call, GSI_CONTINUE_LINKING);
82066 +}
82067 +
82068 +static unsigned int execute_stackleak_tree_instrument(void)
82069 +{
82070 + basic_block bb, entry_bb;
82071 + gimple_stmt_iterator gsi;
82072 + bool prologue_instrumented = false;
82073 +
82074 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
82075 +
82076 + // 1. loop through BBs and GIMPLE statements
82077 + FOR_EACH_BB(bb) {
82078 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82079 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
82080 + tree fndecl;
82081 + gimple stmt = gsi_stmt(gsi);
82082 +
82083 + if (!is_gimple_call(stmt))
82084 + continue;
82085 + fndecl = gimple_call_fndecl(stmt);
82086 + if (!fndecl)
82087 + continue;
82088 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
82089 + continue;
82090 + if (!DECL_BUILT_IN(fndecl))
82091 + continue;
82092 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
82093 + continue;
82094 + if (DECL_FUNCTION_CODE(fndecl) != BUILT_IN_ALLOCA)
82095 + continue;
82096 +
82097 + // 2. insert track call after each __builtin_alloca call
82098 + stackleak_add_instrumentation(&gsi, false);
82099 + if (bb == entry_bb)
82100 + prologue_instrumented = true;
82101 +// print_node(stderr, "pax", fndecl, 4);
82102 + }
82103 + }
82104 +
82105 + // 3. insert track call at the beginning
82106 + if (!prologue_instrumented) {
82107 + gsi = gsi_start_bb(entry_bb);
82108 + stackleak_add_instrumentation(&gsi, true);
82109 + }
82110 +
82111 + return 0;
82112 +}
82113 +
82114 +static unsigned int execute_stackleak_final(void)
82115 +{
82116 + rtx insn;
82117 +
82118 + if (cfun->calls_alloca)
82119 + return 0;
82120 +
82121 + // keep calls only if function frame is big enough
82122 + if (get_frame_size() >= track_frame_size)
82123 + return 0;
82124 +
82125 + // 1. find pax_track_stack calls
82126 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
82127 + // 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))
82128 + rtx body;
82129 +
82130 + if (!CALL_P(insn))
82131 + continue;
82132 + body = PATTERN(insn);
82133 + if (GET_CODE(body) != CALL)
82134 + continue;
82135 + body = XEXP(body, 0);
82136 + if (GET_CODE(body) != MEM)
82137 + continue;
82138 + body = XEXP(body, 0);
82139 + if (GET_CODE(body) != SYMBOL_REF)
82140 + continue;
82141 + if (strcmp(XSTR(body, 0), track_function))
82142 + continue;
82143 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
82144 + // 2. delete call
82145 + delete_insn_and_edges(insn);
82146 + }
82147 +
82148 +// print_simple_rtl(stderr, get_insns());
82149 +// print_rtl(stderr, get_insns());
82150 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
82151 +
82152 + return 0;
82153 +}
82154 +
82155 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82156 +{
82157 + const char * const plugin_name = plugin_info->base_name;
82158 + const int argc = plugin_info->argc;
82159 + const struct plugin_argument * const argv = plugin_info->argv;
82160 + int i;
82161 + struct register_pass_info stackleak_tree_instrument_pass_info = {
82162 + .pass = &stackleak_tree_instrument_pass.pass,
82163 +// .reference_pass_name = "tree_profile",
82164 + .reference_pass_name = "optimized",
82165 + .ref_pass_instance_number = 0,
82166 + .pos_op = PASS_POS_INSERT_AFTER
82167 + };
82168 + struct register_pass_info stackleak_final_pass_info = {
82169 + .pass = &stackleak_final_rtl_opt_pass.pass,
82170 + .reference_pass_name = "final",
82171 + .ref_pass_instance_number = 0,
82172 + .pos_op = PASS_POS_INSERT_BEFORE
82173 + };
82174 +
82175 + if (!plugin_default_version_check(version, &gcc_version)) {
82176 + error(G_("incompatible gcc/plugin versions"));
82177 + return 1;
82178 + }
82179 +
82180 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
82181 +
82182 + for (i = 0; i < argc; ++i) {
82183 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
82184 + if (!argv[i].value) {
82185 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82186 + continue;
82187 + }
82188 + track_frame_size = atoi(argv[i].value);
82189 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
82190 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82191 + continue;
82192 + }
82193 + if (!strcmp(argv[i].key, "initialize-locals")) {
82194 + if (argv[i].value) {
82195 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82196 + continue;
82197 + }
82198 + init_locals = true;
82199 + continue;
82200 + }
82201 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82202 + }
82203 +
82204 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
82205 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
82206 +
82207 + return 0;
82208 +}
82209 diff -urNp linux-2.6.32.46/usr/gen_init_cpio.c linux-2.6.32.46/usr/gen_init_cpio.c
82210 --- linux-2.6.32.46/usr/gen_init_cpio.c 2011-03-27 14:31:47.000000000 -0400
82211 +++ linux-2.6.32.46/usr/gen_init_cpio.c 2011-04-17 15:56:46.000000000 -0400
82212 @@ -299,7 +299,7 @@ static int cpio_mkfile(const char *name,
82213 int retval;
82214 int rc = -1;
82215 int namesize;
82216 - int i;
82217 + unsigned int i;
82218
82219 mode |= S_IFREG;
82220
82221 @@ -383,9 +383,10 @@ static char *cpio_replace_env(char *new_
82222 *env_var = *expanded = '\0';
82223 strncat(env_var, start + 2, end - start - 2);
82224 strncat(expanded, new_location, start - new_location);
82225 - strncat(expanded, getenv(env_var), PATH_MAX);
82226 - strncat(expanded, end + 1, PATH_MAX);
82227 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
82228 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
82229 strncpy(new_location, expanded, PATH_MAX);
82230 + new_location[PATH_MAX] = 0;
82231 } else
82232 break;
82233 }
82234 diff -urNp linux-2.6.32.46/virt/kvm/kvm_main.c linux-2.6.32.46/virt/kvm/kvm_main.c
82235 --- linux-2.6.32.46/virt/kvm/kvm_main.c 2011-03-27 14:31:47.000000000 -0400
82236 +++ linux-2.6.32.46/virt/kvm/kvm_main.c 2011-08-05 20:33:55.000000000 -0400
82237 @@ -2494,7 +2494,7 @@ asmlinkage void kvm_handle_fault_on_rebo
82238 if (kvm_rebooting)
82239 /* spin while reset goes on */
82240 while (true)
82241 - ;
82242 + cpu_relax();
82243 /* Fault while not rebooting. We want the trace. */
82244 BUG();
82245 }
82246 @@ -2714,7 +2714,7 @@ static void kvm_sched_out(struct preempt
82247 kvm_arch_vcpu_put(vcpu);
82248 }
82249
82250 -int kvm_init(void *opaque, unsigned int vcpu_size,
82251 +int kvm_init(const void *opaque, unsigned int vcpu_size,
82252 struct module *module)
82253 {
82254 int r;
82255 @@ -2767,15 +2767,17 @@ int kvm_init(void *opaque, unsigned int
82256 /* A kmem cache lets us meet the alignment requirements of fx_save. */
82257 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size,
82258 __alignof__(struct kvm_vcpu),
82259 - 0, NULL);
82260 + SLAB_USERCOPY, NULL);
82261 if (!kvm_vcpu_cache) {
82262 r = -ENOMEM;
82263 goto out_free_5;
82264 }
82265
82266 - kvm_chardev_ops.owner = module;
82267 - kvm_vm_fops.owner = module;
82268 - kvm_vcpu_fops.owner = module;
82269 + pax_open_kernel();
82270 + *(void **)&kvm_chardev_ops.owner = module;
82271 + *(void **)&kvm_vm_fops.owner = module;
82272 + *(void **)&kvm_vcpu_fops.owner = module;
82273 + pax_close_kernel();
82274
82275 r = misc_register(&kvm_dev);
82276 if (r) {